From clp2 at rebertia.com Mon Mar 1 01:30:45 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Feb 2010 22:30:45 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> References: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Message-ID: <50697b2c1002282230v2f421944u5866685a985fd904@mail.gmail.com> On Sun, Feb 28, 2010 at 10:39 PM, John Nagle wrote: > Patrick Maupin wrote: >> >> All: >> >> Finding .ini configuration files too limiting, JSON and XML to hard to >> manually edit, and YAML too complex to parse quickly, I have started >> work on a new configuration file parser. > > ? You're not supposed to edit those formats manually. Huh? True for XML /perhaps/, but for the others I quite disagree. Perhaps you could explain your reasoning? Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Mon Mar 1 01:39:56 2010 From: nagle at animats.com (John Nagle) Date: Sun, 28 Feb 2010 22:39:56 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Patrick Maupin wrote: > All: > > Finding .ini configuration files too limiting, JSON and XML to hard to > manually edit, and YAML too complex to parse quickly, I have started > work on a new configuration file parser. You're not supposed to edit those formats manually. John Nagle From rantingrick at gmail.com Mon Mar 1 01:41:26 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 28 Feb 2010 22:41:26 -0800 (PST) Subject: Sample code usable Tkinter listbox References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> Message-ID: <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> On Feb 28, 9:57?pm, "Alf P. Steinbach" wrote: > * rantingrick: I just hate overriding all the paths to each listbox method. How about just overideing the Listboxe's geomerty methods once an your done? #-- start script --# import Tkinter as tk from Tkconstants import * import tkMessageBox as MB class ScrolledList(tk.Listbox): def __init__(self, master, **kw): self.frame = tk.Frame(master) self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) self.hbar = tk.Scrollbar(self.frame, orient=HORIZONTAL) self.block = tk.Frame(self.frame, width=18, height=18) self.block.grid(row=1, column=1) self.vbar = tk.Scrollbar(self.frame, orient=VERTICAL) kw.setdefault('activestyle', 'none') kw.setdefault('highlightthickness', 0) if 'pack' in kw.keys() and kw.pop('pack') == 1: self.frame.pack(fill=BOTH, expand=1) tk.Listbox.__init__(self, self.frame, **kw) self.grid(row=0, column=0, sticky=N+S+E+W) self.hbar.configure(command=self.xview) self.vbar.configure(command=self.yview) self.config( yscrollcommand=self.vbar.set, xscrollcommand=self.hbar.set ) self.hbar.grid(row=1, column=0, sticky=W+E) self.vbar.grid(row=0, column=1, sticky=N+S) self.pack = lambda **kw: self.frame.pack(**kw) self.grid = lambda **kw: self.frame.grid(**kw) self.place = lambda **kw: self.frame.place(**kw) self.pack_config = lambda **kw: self.frame.pack_config(**kw) self.grid_config = lambda **kw: self.frame.grid_config(**kw) self.place_config = lambda **kw: self.frame.place_config(**kw) self.pack_configure = lambda **kw: self.frame.pack_config(**kw) self.grid_configure = lambda **kw: self.frame.grid_config(**kw) self.place_configure = lambda **kw: self.frame.place_config(**kw) def gets(self): return self.get(0, END) def sets(self, arg): self.delete(0, END) try: arg = arg.strip('\n').splitlines() except AttributeError: pass if hasattr(arg, '__getitem__'): for item in arg: self.insert(END, str(item)) else: raise TypeError("Scrolledlist.sets() requires a string of iterable of strings") if __name__ == '__main__': root = tk.Tk() listbox = ScrolledList(root, width=50, height=5, fg='green', selectmode='Extended', pack=1) #listbox.sets(1.25) #listbox.sets('1\n2\n3\n4\n5\n\n\n') listbox.sets(range(100)) root.mainloop() #-- end script --# From stefan_ml at behnel.de Mon Mar 1 02:46:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Mar 2010 08:46:04 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: References: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> Message-ID: Hal Styli, 01.03.2010 00:15: > Stefan, I was happy to see such concise code. > Your python worked with only very minor modifications. > > Hai's test xml data *without* the first and last line is close enough > to the data I am using: > > > > > > > > ... quirky. > > I get a large file given to me in this format. I believe it is > created by something like: > grep 'customer=' *.xml, where there are a large number of xml files. Try to get this fixed at the source. Exporting non-XML that looks like XML is not a good idea in general, and it means that everyone who wants to read the data has to adapt, instead of fixing the source once and for all. > I had to edit the data to include the first and last lines, > and , > to get the python code to work. It's not an arduous task(!), but can > you recommend a way to get it to work without > manually editing the data? Iff this cannot be fixed at the source, you can write a file-like wrapper around a file that simply returns the boundary tags before and after reading from the file itself. All you need is a .read(n) method, see the documentation of the file type. > One other thing, what's the Roland Mueller post above about (I'm > viewing htis in google groups)? What would the test.xsl file look > like? This is the XSLT script he posted: ============================ , , ============================ Stefan From steven.bethard at gmail.com Mon Mar 1 03:31:09 2010 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 1 Mar 2010 00:31:09 -0800 Subject: [ANN] argparse 1.1 - Command-line parsing library Message-ID: ======================= Announcing argparse 1.1 ======================= The argparse module provides an easy, declarative interface for creating command line tools, which knows how to: * parse the arguments and flags from sys.argv * convert arg strings into objects for your program * format and print informative help messages * and much more... The argparse module improves on the standard library optparse module in a number of ways including: * handling positional arguments * supporting sub-commands * allowing alternative option prefixes like + and / * handling zero-or-more and one-or-more style arguments * producing more informative usage messages * providing a much simpler interface for custom types and actions Download argparse ================= The argparse homepage has links for source, MSI and single file distributions of argparse: http://code.google.com/p/argparse/ About this release ================== This is the final release of argparse before its move to the Python 2.7 and 3.2 standard libraries. Major enhancements in this release: * ArgumentParser(..., version=XXX) is deprecated. Instead, you should use add_argument(..., action='version') which is more flexible and does not force you to accept -v/--version as your version flags. * Usage and help (but not version) messages are now written to stdout instead of stderr, consistent with most existing programs. * User defined types passed as a type= argument can now raise an ArgumentTypeError to provide a custom error message. * Namespace objects now support containment, e.g. "'foo' in args". Various bugs were also squashed, e.g. "from argparse import *" now works. See the news file for detailed information: http://argparse.googlecode.com/svn/tags/r11/NEWS.txt Enjoy! Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus From anthra.norell at bluewin.ch Mon Mar 1 04:17:59 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 01 Mar 2010 10:17:59 +0100 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: <4B8B8647.1040008@bluewin.ch> Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. > What compels you to write Python code without semicolons? Frederic From chris at simplistix.co.uk Mon Mar 1 04:38:13 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 01 Mar 2010 09:38:13 +0000 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <4B8B8B05.3060407@simplistix.co.uk> Aahz wrote: > In article <4b79e28c$0$4610$426a74cc at news.free.fr>, > News123 wrote: > >> Is there a python way to register new windows services. >> >> I am aware of the >> instsrv.exe program, which can be used to install services. >> I could use subprocess.Popen to call >> >> instsrv.exe "service_name" program.exe >> >> but wondered, whether there's already an existing function. > > Use the win32 package. Indeed, there's some intersting code in this area here: http://svn.zope.org/Zope/trunk/src/nt_svcutils/service.py?rev=104819&view=auto http://svn.zope.org/Zope/trunk/src/Zope2/Startup/zopectl.py?rev=105396&view=auto ...particularly in the do_install function in the latter... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From bartsmeets86 at gmail.com Mon Mar 1 04:48:05 2010 From: bartsmeets86 at gmail.com (Bart Smeets) Date: Mon, 1 Mar 2010 10:48:05 +0100 Subject: Detecting new removable drives in Linux Message-ID: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> Hello, I'm trying to write a script which detects when a new removable drive is connected to the computer. On #python I was advised to use the dbus-bindings. However the documentation on this is limited. Does anyone know of an example of how I can detect new removable drives? Thanks in advance! Regards, Bart -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 1 05:34:45 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Mar 2010 11:34:45 +0100 Subject: Docstrings considered too complicated In-Reply-To: <4B89D8BE.2040905@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> Message-ID: <4B8B9845.70604@sequans.com> MRAB wrote: > Gregory Ewing wrote: >> Mel wrote: >> >>> You could think of it as a not bad use of the design principle >>> "Clear The Simple Stuff Out Of The Way First". Destinations are >>> commonly a lot simpler than sources >> >> That's not usually true in assembly languages, though, >> where the source and destination are both very restricted >> and often about the same complexity. >> >> That's not to say that right-to-left is the wrong way >> to do it in an assembly language, but there are less >> misleading words than "move" that could be used. >> >> Z80 assembly language uses "load", which makes things >> considerably clearer: >> >> LD A, B ; load A with B >> > Some processors distinguish between "load" (memory to register) and > "store" (register to memory), and the destination and LHS operand of > binary operations might be the same register, for example: > > CLC ; clear the carry > LDA first ; accumulator := byte at first > ADCA second ; accumulator := accumulator + byte at second + carry > STA result ; byte at third := accumulator > Guys, you sound like people arguing about old school TV show / series like star treck :-) - "He was wearing a blue suit !" - "Check episode number 29, he appeared with a pink one!" I'm glad I'm too young to had to code in assembler, or to bear the vision of those unlikely space suits from the 70's ;-) JM From lucaberto at libero.it Mon Mar 1 05:48:34 2010 From: lucaberto at libero.it (luca72) Date: Mon, 1 Mar 2010 02:48:34 -0800 (PST) Subject: pythonpath Message-ID: <7b9322bb-0b63-44e4-94c5-324006adff8b@t23g2000yqt.googlegroups.com> Sorry for my stupid question if i have to load module from a folder i have to append it to the sys path the folder? ex: if my folder module is /home/lucak904/Scrivania/Luca/enigma2 i do this : import sys sys.path.append('/home/lucak904/Scrivania/Luca/enigma2') If this is correct why when i write: form enigma2 import * i get no module named enigma2 Thanks Luca I'm under linux From candide at free.invalid Mon Mar 1 05:58:57 2010 From: candide at free.invalid (candide) Date: Mon, 01 Mar 2010 11:58:57 +0100 Subject: Starting Python from the terminal with no welcome message In-Reply-To: References: <4b8afafa$0$28635$426a74cc@news.free.fr> Message-ID: <4b8b9df2$0$10478$426a74cc@news.free.fr> Tim Chase a ?crit : > > bash$ python -ic "" > > to get a python shell without the banner. > Works fine. thanks a lot. From nanyaks at googlemail.com Mon Mar 1 07:01:08 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:01:08 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On Feb 25, 12:21 pm, "Martin P. Hellwig" wrote: > On 02/25/10 10:26, simn_stv wrote: > > what i am concerned about is scalability and > > efficiency, well, as far as the 'core' is concerned. > > > would python be able to manage giving me a solid 'core' and will i be > > able to use python provide any API i would like to implement?... > > > Python isn't the most efficient language, the assembler provided by the > maker of your CPU probably is the best you can get, LOL...;), yeah right, the mere thought of writing assembler instructions is SCARY!! >everything after > that is a trade-off between performance and flexibility (flexible in the > most flexible sense of the word :-)). > > That being said, for me, Python (well actually any turing complete > programming language), is more like a box of lego with infinite amount > of pieces. > Scalability and API issues are the same as the shape and function of the > model your making with lego. > > Sure some type of pieces might be more suited than other types but since > you can simulate any type of piece with the ones that are already > present, you are more limited by your imagination than by the language. > > So in short, I don't see any serious problems using Python, I have used > it in Enterprise environments without any problems but than again I was > aware not to use it for numerical intensive parts without the use of 3rd > party libraries like numpy. Which for me resulted in not doing the > compression of a database delta's in pure python but to offload that to > a more suitable external program, still controlled from Python though. > > -- > mph From marduk at python.net Mon Mar 1 07:09:38 2010 From: marduk at python.net (Albert Hopkins) Date: Mon, 01 Mar 2010 07:09:38 -0500 Subject: Detecting new removable drives in Linux In-Reply-To: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> References: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> Message-ID: <1267445378.72674.3.camel@centar> On Mon, 2010-03-01 at 10:48 +0100, Bart Smeets wrote: > Hello, > > > I'm trying to write a script which detects when a new removable drive > is connected to the computer. On #python I was advised to use the > dbus-bindings. However the documentation on this is limited. Does > anyone know of an example of how I can detect new removable drives? The documentation does suck and, at least for the python bindings, is horribly outdated. Also, the python bindings for dbus are not as "pythonic" as they could be. I was working on a python/dbus program a while back and basically had to resort to looking at the source of a program that did, or almost did, what I wanted and using that as an example. You may even want to look at C sources as I don't think the python bindings are that much different. HTH, -a From lyh19901223 at gmail.com Mon Mar 1 07:10:55 2010 From: lyh19901223 at gmail.com (=?UTF-8?B?5YiY5a6H6L6J?=) Date: Mon, 1 Mar 2010 12:10:55 +0000 Subject: pythonpath Message-ID: >Sorry for my stupid question if i have to load module >from a folder ihave to append it to the sys path the >folder? >ex: >if my folder module is /home/lucak904/Scrivania/Luca/enigma2 >i do this : >import sys >sys.path.append('/home/lucak904/Scrivania/Luca/enigma2') >If this is correct why when i write: >form enigma2 import * >i get no module named enigma2 is the folder module /home/lucak904/Scrivania/Luca/enigma2.py? i think the extension is necessary . -- wolf python london -------------- next part -------------- An HTML attachment was scrubbed... URL: From nanyaks at googlemail.com Mon Mar 1 07:11:07 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:11:07 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On Feb 25, 5:18 pm, "D'Arcy J.M. Cain" wrote: > On Thu, 25 Feb 2010 15:29:34 +0000 > "Martin P. Hellwig" wrote: > > > On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > > > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > > > > > Our biggest problem was in > > > a network heavy element of the app and that was low level TCP/IP stuff > > > that rather than being Python's problem was something we used Python to > > > fix. > > > > Out off interest, could you elaborate on that? > > Somewhat - there is an NDA so I can't give exact details. It was > crucial to our app that we sync up databases in Canada and the US (later > Britain, Europe and Japan) in real time with those transactions. Our > problem was that even though our two server systems were on the > backbone, indeed with the same major carrier, we could not keep them in > sync. We were taking way to long to transact an update across the > network. > > The problem had to do with the way TCP/IP works, especially closer to > the core. Our provider was collecting data and sending it only after > filling a buffer or after a timeout. The timeout was short so it > wouldn't normally be noticed and in most cases (web pages e.g.) the > connection is opened, data is pushed and the connection is closed so > the buffer is flushed immediately. Our patterns were different so we > were hitting the timeout on every single transaction and there was no > way we would have been able to keep up. > > Our first crack at fixing this was to simply add garbage to the packet > we were sending. Making the packets an order of magnitude bigger sped > up the proccessing dramatically. That wasn't a very clean solution > though so we looked for a better way. > > That better way turned out to asynchronous update transactions. All we > did was keep feeding updates to the remote site and forget about ACKS. > We then had a second process which handled ACKS and tracked which > packets had been properly transferred. The system had IDs on each > update and retries happened if ACKS didn't happen soon enough. > Naturally we ignored ACKS that we had already processed. > > All of the above (and much more complexity not even discussed here) was > handled by Python code and database manipulation. There were a few > bumps along the way but overall it worked fine. If we were using C or > even assembler we would not have sped up anything and the solution we > came up with would have been horrendous to code. As it was I and my > chief programmer locked ourselves in the boardroom and had a working > solution before the day was out. sure it wouldnt have sped it up a bit, even a bit?; probably the development and maintenance time would be a nightmare but it should speed the app up a bit... > > Python wins again. > > -- > D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. seriously added to the reputation of python, from my own perspective...kudos python! From marduk at python.net Mon Mar 1 07:14:19 2010 From: marduk at python.net (Albert Hopkins) Date: Mon, 01 Mar 2010 07:14:19 -0500 Subject: pythonpath In-Reply-To: <7b9322bb-0b63-44e4-94c5-324006adff8b@t23g2000yqt.googlegroups.com> References: <7b9322bb-0b63-44e4-94c5-324006adff8b@t23g2000yqt.googlegroups.com> Message-ID: <1267445659.72674.8.camel@centar> On Mon, 2010-03-01 at 02:48 -0800, luca72 wrote: > Sorry for my stupid question if i have to load module from a folder i > have to append it to the sys path the folder? > ex: > if my folder module is /home/lucak904/Scrivania/Luca/enigma2 > i do this : > import sys > sys.path.append('/home/lucak904/Scrivania/Luca/enigma2') > If this is correct why when i write: > form enigma2 import * > i get no module named enigma2 There are two reasons for this: 1. enigma2 is not in your namespace. What's inside enigma is. For example, you can't say "from site-packages import *" because Python doesn't look at "site-packages". It looks at what's inside site-packages. If you wanted" enigma2" to be in your namespace, you should add /home/lucak904/Scrivania/Luca" to your system path. 2. Even if you did above, it may not work because enigma2 is a directory. Remember "from x import *" only works for modules and packages, so if you want "enigma2" to be a package, remember to add an (empty) __init__.py to the directory. Hope this helps. -a From alfps at start.no Mon Mar 1 07:19:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 13:19:32 +0100 Subject: Sample code usable Tkinter listbox In-Reply-To: <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> Message-ID: * rantingrick: > > kw.setdefault('activestyle', 'none') Hm, let me steal this line... Thanks! Cheers, - Alf From nanyaks at googlemail.com Mon Mar 1 07:27:12 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:27:12 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <79ff2083-bde8-4a60-854d-b90e3d944b94@y17g2000yqd.googlegroups.com> On Feb 25, 5:18 pm, "D'Arcy J.M. Cain" wrote: > On Thu, 25 Feb 2010 15:29:34 +0000 > "Martin P. Hellwig" wrote: > > > On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > > > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > > > > > Our biggest problem was in > > > a network heavy element of the app and that was low level TCP/IP stuff > > > that rather than being Python's problem was something we used Python to > > > fix. > > > > Out off interest, could you elaborate on that? > > Somewhat - there is an NDA so I can't give exact details. It was > crucial to our app that we sync up databases in Canada and the US (later > Britain, Europe and Japan) in real time with those transactions. Our > problem was that even though our two server systems were on the > backbone, indeed with the same major carrier, we could not keep them in > sync. We were taking way to long to transact an update across the > network. > > The problem had to do with the way TCP/IP works, especially closer to > the core. Our provider was collecting data and sending it only after > filling a buffer or after a timeout. The timeout was short so it > wouldn't normally be noticed and in most cases (web pages e.g.) the > connection is opened, data is pushed and the connection is closed so > the buffer is flushed immediately. Our patterns were different so we > were hitting the timeout on every single transaction and there was no > way we would have been able to keep up. > > Our first crack at fixing this was to simply add garbage to the packet > we were sending. Making the packets an order of magnitude bigger sped > up the proccessing dramatically. That wasn't a very clean solution > though so we looked for a better way. > > That better way turned out to asynchronous update transactions. All we > did was keep feeding updates to the remote site and forget about ACKS. > We then had a second process which handled ACKS and tracked which > packets had been properly transferred. The system had IDs on each > update and retries happened if ACKS didn't happen soon enough. > Naturally we ignored ACKS that we had already processed. > > All of the above (and much more complexity not even discussed here) was > handled by Python code and database manipulation. There were a few > bumps along the way but overall it worked fine. If we were using C or > even assembler we would not have sped up anything and the solution we > came up with would have been horrendous to code. As it was I and my > chief programmer locked ourselves in the boardroom and had a working > solution before the day was out. sure it wouldnt have sped it up a bit, even a bit?; probably the development and maintenance time would be a nightmare but it should speed the app up a bit... > > Python wins again. > > -- > D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. seriously added to the reputation of python, from my own perspective...kudos python! From nanyaks at googlemail.com Mon Mar 1 07:32:16 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:32:16 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> Message-ID: <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> On Feb 26, 10:32 am, mdipierro wrote: > 100,000 hits a day is not a low. I get that some day on my web server > without problem and without one request dropped. > > Most frameworks web2py, Django, Pylons can handle that kind of load > since Python is not the bottle neck. taking a look at django right now, doesnt look too bad from where im standing, maybe when i get into the code i'd run into some issues that would cause some headaches!! > You have to follow some tricks: > > 1) have the web server serve static pages directly and set the pragma > cache expire to one month > 2) cache all pages that do not have forms for at least few minutes > 3) avoid database joins but this would probably be to the detriment of my database design, which is a no-no as far as im concerned. The way the tables would be structured requires 'joins' when querying the db; or could you elaborate a little?? > 4) use a server with at least 512KB Ram. hmmm...!, still thinking about what you mean by this statement also. > 5) if you pages are large, use gzip compression > > If you develop your app with the web2py framework, you always have the > option to deploy on the Google App Engine. If you can live with their > constraints you should have no scalability problems. > > Massimo > > On Feb 25, 4:26 am, simn_stv wrote: > > > hello people, i have been reading posts on this group for quite some > > time now and many, if not all (actually not all!), seem quite > > interesting. > > i plan to build an application, a network based application that i > > estimate (and seriously hope) would get as many as 100, 000 hits a day > > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > > or anything like it, its mainly for a financial transactions which > > gets pretty busy... > > so my question is this would anyone have anything that would make > > python a little less of a serious candidate (cos it already is) and > > the options may be to use some other languages (maybe java, C (oh > > God))...i am into a bit of php and building API's in php would not be > > the hard part, what i am concerned about is scalability and > > efficiency, well, as far as the 'core' is concerned. > > > would python be able to manage giving me a solid 'core' and will i be > > able to use python provide any API i would like to implement?... > > > im sorry if my subject was not as clear as probably should be!. > > i guess this should be the best place to ask this sort of thing, hope > > im so right. > > > Thanks thanks for the feedback... From stefan_ml at behnel.de Mon Mar 1 07:46:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Mar 2010 13:46:22 +0100 Subject: Detecting new removable drives in Linux In-Reply-To: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> References: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> Message-ID: Bart Smeets, 01.03.2010 10:48: > I'm trying to write a script which detects when a new removable drive is > connected to the computer. On #python I was advised to use the > dbus-bindings. However the documentation on this is limited. Does anyone > know of an example of how I can detect new removable drives? You could execute a script from HAL, e.g. using halevt, and let the script communicate with your program. http://www.nongnu.org/halevt/ Stefan From wuwei23 at gmail.com Mon Mar 1 08:01:49 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 1 Mar 2010 05:01:49 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> Message-ID: <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> Andreas Waldenburger wrote: > But as I said: a) I am (we are) not in a position to impose this (We > don't work with the code, we just run the software). I personally believe that the end users have _every_ right to impose quality requirements on code used within their business...although I may not bring this up in front of them at meetings :) From usenot at geekmail.INVALID Mon Mar 1 08:09:43 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 14:09:43 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> Message-ID: <20100301140943.4edca16b@geekmail.INVALID> On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 wrote: > Andreas Waldenburger wrote: > > But as I said: a) I am (we are) not in a position to impose this (We > > don't work with the code, we just run the software). > > I personally believe that the end users have _every_ right to impose > quality requirements on code used within their business...although I > may not bring this up in front of them at meetings :) Huh? That's like demanding a certain type of truck or vehicle maintenance plan from a trucking company. Sure, you *could* do it, but that effectively only limits your options. I think there should be a clear separation of concerns here. /W -- INVALID? DE! From sayedjewel21 at gmail.com Mon Mar 1 08:26:31 2010 From: sayedjewel21 at gmail.com (sayed jewel21) Date: Mon, 1 Mar 2010 05:26:31 -0800 (PST) Subject: connect with me Message-ID: <3fc01795-acc4-4e9f-a683-a34293166899@d27g2000yqf.googlegroups.com> dear guys you can do subscribe with site easily- http://freelivestreamonlinepctv.blogspot.com/ From vinay_sajip at yahoo.co.uk Mon Mar 1 08:27:30 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 1 Mar 2010 05:27:30 -0800 (PST) Subject: ANN: A new version (0.2.4) of the Python module which wraps GnuPG has been released. Message-ID: <3188c3be-0ba5-48b6-a234-d5e41e034923@t23g2000yqt.googlegroups.com> A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor enhancement release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. The current version passes all tests on Windows (Python 2.4, 2.5, 2.6, 3.1, Jython 2.5.1) and Ubuntu (Python 2.4, 2.5, 2.6, 3.0, Jython 2.5.1). What Does It Do? ================ The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf ... -----END PGP MESSAGE-----\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' For more information, visit http://code.google.com/p/python-gnupg/ - as always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. From highcar at gmail.com Mon Mar 1 08:49:06 2010 From: highcar at gmail.com (elca) Date: Mon, 1 Mar 2010 05:49:06 -0800 (PST) Subject: python socket service related question! Message-ID: <27743609.post@talk.nabble.com> Hello,All im totally new to socket programming in python. i was read some tutorial and manual, but i didn't found what i want to make python related socket script in manual or tutorial. i want to make socket script which can send some info to server and also receive some info from server. For example, i want to send my login information to server, and want to receive result reply from server. but i have no idea..how to send my login information(id and password) to server. i was captured with wireshark, some process to send login info to server. and i was found port number is 5300 and server ip is 58.225.56.152 and i was send id is 'aaaaaaa' and password 'bbbbbbb' and i was received 'USER NOT FOUND' result from server. how can i make this kind of process with python socket ? if anyone help me some reference or some example or anything help much appreciate! 0000 00 50 56 f2 c8 cc 00 0c 29 a8 f8 c0 08 00 45 00 .PV.....).....E. 0010 00 e2 2a 19 40 00 80 06 d0 55 c0 a8 cb 85 3a e1 ..*. at ....U....:. 0020 38 98 05 f3 15 9a b9 86 62 7b 0d ab 0f ba 50 18 8.......b{....P. 0030 fa f0 26 14 00 00 50 54 3f 09 a2 91 7f 13 00 00 ..&...PT?....... 0040 00 1f 14 00 02 00 00 00 00 00 00 00 07 00 00 00 ................ 0050 61 61 61 61 61 61 61 50 54 3f 09 a2 91 7f 8b 00 aaaaaaaPT?...... 0060 00 00 1f 15 00 08 00 00 00 07 00 00 00 61 61 61 .............aaa 0070 61 61 61 61 07 00 00 00 62 62 62 62 62 62 62 01 aaaa....bbbbbbb. 0080 00 00 00 31 02 00 00 00 4b 52 0f 00 00 00 31 39 ...1....KR....19 0090 32 2e 31 36 38 2e 32 30 33 2e 31 33 33 30 00 00 2.168.203.1330.. 00a0 00 4d 69 63 72 6f 73 6f 66 74 20 57 69 6e 64 6f .Microsoft Windo 00b0 77 73 20 58 50 20 50 72 6f 66 65 73 73 69 6f 6e ws XP Profession 00c0 61 6c 20 53 65 72 76 69 63 65 20 50 61 63 6b 20 al Service Pack 00d0 32 14 00 00 00 31 30 30 31 33 30 30 35 33 31 35 2....10013005315 00e0 37 38 33 37 32 30 31 32 33 03 00 00 00 34 37 30 783720123....470 0000 00 0c 29 a8 f8 c0 00 50 56 f2 c8 cc 08 00 45 00 ..)....PV.....E. 0010 00 28 ae 37 00 00 80 06 8c f1 3a e1 38 98 c0 a8 .(.7......:.8... 0020 cb 85 15 9a 05 f3 0d ab 0f ba b9 86 63 35 50 10 ............c5P. 0030 fa f0 5f 8e 00 00 00 00 00 00 00 00 .._......... 0000 00 0c 29 a8 f8 c0 00 50 56 f2 c8 cc 08 00 45 00 ..)....PV.....E. 0010 00 4c ae 38 00 00 80 06 8c cc 3a e1 38 98 c0 a8 .L.8......:.8... 0020 cb 85 15 9a 05 f3 0d ab 0f ba b9 86 63 35 50 18 ............c5P. 0030 fa f0 3e 75 00 00 50 54 3f 09 a2 91 7f 16 00 00 ..>u..PT?....... 0040 00 1f 18 00 01 00 00 00 0e 00 00 00 55 73 65 72 ............User 0050 20 4e 6f 74 20 46 6f 75 6e 64 Not Found -- View this message in context: http://old.nabble.com/python-socket-service-related-question%21-tp27743609p27743609.html Sent from the Python - python-list mailing list archive at Nabble.com. From victorsubervi at gmail.com Mon Mar 1 09:02:56 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 1 Mar 2010 10:02:56 -0400 Subject: Permission Problem Message-ID: <4dc0cfea1003010602w755b52feu2e7f9dca710ff71@mail.gmail.com> Hi; I encountered and solved this problem before with the help of the list, but it's back, and I've reviewed and done everything I was shown to do last time, so I'm lost. Here's the script: #!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from login import login import MySQLdb import re, string import fpformat form = cgi.FieldStorage() width = form.getfirst('width') lines = ''' #!/usr/bin/python return %s''' % width f = 'width.py' try: os.remove(f) except OSError: pass f = open(f, 'w') f.writelines(lines) f.close() Simple enough. Here's the permissions: drwxrwxrwx 31 root root 4096 Feb 23 04:57 .. -rwxrwxrwx 1 root root 390 Mar 1 05:52 preload.py All loaded up deliberately to try and get it to work. Here's the error: /var/www/html/globalsolutionsgroup.vi/preload.py 21 except OSError: 22 pass 23 f = open(f, 'w') 24 f.writelines(lines) 25 f.close() f = 'width.py', builtin open = IOError: [Errno 13] Permission denied: 'width.py' args = (13, 'Permission denied') errno = 13 filename = 'width.py' strerror = 'Permission denied' What'd I do wrong? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From urbangabo at gmail.com Mon Mar 1 09:05:03 2010 From: urbangabo at gmail.com (Gabor Urban) Date: Mon, 1 Mar 2010 15:05:03 +0100 Subject: Class attributes / methods lost? Message-ID: Hi guys, I am building a nested data structure with the following compontens: <> class Item: def __init__(self, pId, pChange, pComment): self.ID = pId self.Delta = pChange self.Comment = pComment def PrintItem(self): str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) return str class Package: def __init__(self, pSerial, pDate, pOwner, pSchema): self.serial = pSerial self.date = pDate self.owner = pOwner self.schema = pSchema self.items = [] def insertItem(self, pItem): self.items.append(pItem) def printPackage(self): lines = [] str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) number = self.items.length for idx in xrange(number): line = '' istr = self.items[idx].PrintItem() line = str + ',' + istr lines.append(line) return lines <> The above structure is processed with next code: <> size = len(packages) package = None for index in xrange(size): logger.info('PrettyPrinting package id=%d',index) oplines = [] oplines = packages[index].printPackage() for i in xrange(oplines.length): data.append(oplines[i]) <> I've got the next error message: ' Traceback (most recent call last): File "XmlHistory_orig.py", line 203, in ? oplines = packages[index].printPackage() TypeError: unbound method printPackage() must be called with Package instance as first argument (got nothing instead) ' I did give a try to access the fields directly <> packages = [] data = [] size = len(packages) for index in xrange(size): str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) itemnum = len(packages[index].items) oplines = [] for itemIndx in xrange(itemnum): element = '%s,%s,%s'%(packages[index].items[itemIdx].ID,packages[index].items[itemIdx].Delta,packages[index].items[itemIdx].comment) oplines.append(str + ','+elemt) <> Error: Traceback (most recent call last): File "XmlHistory.py", line 204, in ? str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) AttributeError: class Package has no attribute 'serial' The strange in this issue for me, that I do not see why are the class methods and fields lost. Any idea is wellcome. Gabor -- Linux: Choice of a GNU Generation From __peter__ at web.de Mon Mar 1 09:24:37 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Mar 2010 15:24:37 +0100 Subject: Class attributes / methods lost? References: Message-ID: Gabor Urban wrote: > I am building a nested data structure with the following compontens: > Any idea is wellcome. The error messages suggest that you are using classes where you should be using class instances, but you don't provide the code where this problem originates. The code you do give looks like a very literal and incomplete conversion from Java. Rather than go into the details I suggest that you have a look at the Tutorial (and PEP 8) before you proceed. http://docs.python.org/tutorial/index.html http://www.python.org/dev/peps/pep-0008/ Peter From nanyaks at googlemail.com Mon Mar 1 09:42:28 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 06:42:28 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> <7upi0jFuapU2@mid.uni-berlin.de> Message-ID: <7f8b1651-69fc-4ae1-8f55-840ff9f9d1dc@15g2000yqa.googlegroups.com> On Feb 26, 10:19 am, "Diez B. Roggisch" wrote: > Am 26.02.10 05:01, schrieb D'Arcy J.M. Cain: > > > > > On Fri, 26 Feb 2010 01:12:00 +0100 > > "Diez B. Roggisch" wrote: > >>> That better way turned out to asynchronous update transactions. All we > >>> did was keep feeding updates to the remote site and forget about ACKS. > >>> We then had a second process which handled ACKS and tracked which > >>> packets had been properly transferred. The system had IDs on each > >>> update and retries happened if ACKS didn't happen soon enough. > >>> Naturally we ignored ACKS that we had already processed. > > >> sounds like using UDP to me, of course with a protocol on top (namely > >> the one you implemented). > > >> Any reason you sticked to TCP instead? > > > TCP does a great job of delivering a stream of data in order and > > handling the retries. The app really was connection oriented and we > > saw no reason to emulate that over an unconnected protocol. There were > > other wheels to reinvent that were more important. > > So when you talk about ACKs, you don't mean these on the TCP-level > (darn, whatever iso-level that is...), but on some higher level? > > Diez i think its on the TCP that he's referring to or is it?... if it is, that means he's doing some 'mean' network level scripting, impressive...but i never thought python could go that deep in network programming!... From darcy at druid.net Mon Mar 1 09:43:13 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 1 Mar 2010 09:43:13 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <20100301094313.e04eab06.darcy@druid.net> On Mon, 1 Mar 2010 04:11:07 -0800 (PST) simn_stv wrote: > > All of the above (and much more complexity not even discussed here) was > > handled by Python code and database manipulation. There were a few > > bumps along the way but overall it worked fine. If we were using C or > > even assembler we would not have sped up anything and the solution we > > came up with would have been horrendous to code. As it was I and my > > chief programmer locked ourselves in the boardroom and had a working > > solution before the day was out. > > sure it wouldnt have sped it up a bit, even a bit?; probably the > development and maintenance time would be a nightmare but it should > speed the app up a bit... What do you mean by "even a bit?" The bulk of the time is in sending bits on the wire. Computer time was always negligible in this situation. Yes, I can write all of my applications in assembler to get a 0.00000000000001% increase in speed but who cares? If you have decent algorithms in place then 99% of the time I/O will be your bottleneck and if it isn't then you have a compute heavy problem that assembler isn't going to fix. And even if I get a 100% increase in speed, I still lose. Computer time is cheaper than programmer time by so many orders of magnitude that it isn't even worh factoring in the speedup. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Mon Mar 1 10:02:15 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 1 Mar 2010 10:02:15 -0500 Subject: taking python enterprise level?... In-Reply-To: <7f8b1651-69fc-4ae1-8f55-840ff9f9d1dc@15g2000yqa.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> <7upi0jFuapU2@mid.uni-berlin.de> <7f8b1651-69fc-4ae1-8f55-840ff9f9d1dc@15g2000yqa.googlegroups.com> Message-ID: <20100301100215.a9387aa4.darcy@druid.net> On Mon, 1 Mar 2010 06:42:28 -0800 (PST) simn_stv wrote: > On Feb 26, 10:19 am, "Diez B. Roggisch" wrote: > > So when you talk about ACKs, you don't mean these on the TCP-level > > (darn, whatever iso-level that is...), but on some higher level? > > i think its on the TCP that he's referring to or is it?... No, I mean in our own application layer. > if it is, that means he's doing some 'mean' network level scripting, > impressive...but i never thought python could go that deep in network > programming!... What I meant was that we just keep sending packets which TCP/IP keeps in order for us by reassembling out-of-order and retransmitted packets. Asynchronously we sent back to our own application an ACK that our app level packet was finally received. It's a sliding window protocol. http://en.wikipedia.org/wiki/Sliding_Window_Protocol -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From victorsubervi at gmail.com Mon Mar 1 10:07:52 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 1 Mar 2010 11:07:52 -0400 Subject: Permission Problem In-Reply-To: <4dc0cfea1003010602w755b52feu2e7f9dca710ff71@mail.gmail.com> References: <4dc0cfea1003010602w755b52feu2e7f9dca710ff71@mail.gmail.com> Message-ID: <4dc0cfea1003010707j872922ckd30d62173e831c6e@mail.gmail.com> Never mind. I figured out my error. beno On Mon, Mar 1, 2010 at 10:02 AM, Victor Subervi wrote: > Hi; > I encountered and solved this problem before with the help of the list, but > it's back, and I've reviewed and done everything I was shown to do last > time, so I'm lost. Here's the script: > > #!/usr/bin/python > > import cgitb; cgitb.enable() > import cgi > import sys,os > sys.path.append(os.getcwd()) > from login import login > import MySQLdb > import re, string > import fpformat > > form = cgi.FieldStorage() > width = form.getfirst('width') > lines = ''' > #!/usr/bin/python > > return %s''' % width > f = 'width.py' > try: > os.remove(f) > except OSError: > pass > f = open(f, 'w') > f.writelines(lines) > f.close() > > Simple enough. Here's the permissions: > > drwxrwxrwx 31 root root 4096 Feb 23 04:57 .. > -rwxrwxrwx 1 root root 390 Mar 1 05:52 preload.py > > All loaded up deliberately to try and get it to work. Here's the error: > > /var/www/html/globalsolutionsgroup.vi/preload.py > 21 except OSError: > 22 pass > 23 f = open(f, 'w') > 24 f.writelines(lines) > 25 f.close() > f = 'width.py', builtin open = > IOError: [Errno 13] Permission denied: 'width.py' > args = (13, 'Permission denied') > errno = 13 > filename = 'width.py' > strerror = 'Permission denied' > > What'd I do wrong? > TIA, > beno > > -- > The Logos has come to bear > http://logos.13gems.com/ > -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 1 10:09:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Mar 2010 16:09:22 +0100 Subject: Class attributes / methods lost? In-Reply-To: References: Message-ID: <4B8BD8A2.40800@sequans.com> Gabor Urban wrote: > Hi guys, > > I am building a nested data structure with the following compontens: > > <> > > class Item: > def __init__(self, pId, pChange, pComment): > self.ID = pId > self.Delta = pChange > self.Comment = pComment > > def PrintItem(self): > str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) > return str > > class Package: > def __init__(self, pSerial, pDate, pOwner, pSchema): > self.serial = pSerial > self.date = pDate > self.owner = pOwner > self.schema = pSchema > self.items = [] > > def insertItem(self, pItem): > self.items.append(pItem) > > def printPackage(self): > lines = [] > str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) > number = self.items.length > for idx in xrange(number): > line = '' > istr = self.items[idx].PrintItem() > line = str + ',' + istr > lines.append(line) > return lines > > <> > > The above structure is processed with next code: > > <> > > size = len(packages) > package = None > for index in xrange(size): > logger.info('PrettyPrinting package id=%d',index) > oplines = [] > oplines = packages[index].printPackage() > for i in xrange(oplines.length): > data.append(oplines[i]) > <> > > I've got the next error message: > ' Traceback (most recent call last): > File "XmlHistory_orig.py", line 203, in ? > oplines = packages[index].printPackage() > TypeError: unbound method printPackage() must be called with Package > instance as first argument (got nothing instead) ' > > I did give a try to access the fields directly > > <> > packages = [] > data = [] > > size = len(packages) > for index in xrange(size): > str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) > itemnum = len(packages[index].items) > oplines = [] > for itemIndx in xrange(itemnum): > element = > '%s,%s,%s'%(packages[index].items[itemIdx].ID,packages[index].items[itemIdx].Delta,packages[index].items[itemIdx].comment) > oplines.append(str + ','+elemt) > > <> > > Error: > > Traceback (most recent call last): > File "XmlHistory.py", line 204, in ? > str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) > AttributeError: class Package has no attribute 'serial' > > The strange in this issue for me, that I do not see why are the class > methods and fields lost. > > Any idea is wellcome. > > Gabor > Ok here are some suggestions : 1/ do not name a method PrintItem if the method does not print anything (it does not) 2/ use the __str__ method to return a nice representation of your objects 3/ use pythonic iteration controls 4/ be consistant with your naming convention, your Item's attributes start with an Uppercase letter, Package's attributes with a lowercase one. (I suggest the lowercase) class Item(object): def __init__(self, pId, pChange, pComment): self.id = pId self.delta = pChange self.comment = pComment def __str__(self): return self.__class__.__name__ + ':' + str(self.__dict__) class Package(object): def __init__(self, pSerial, pDate, pOwner, pSchema): self.serial = pSerial self.date = pDate self.owner = pOwner self.schema = pSchema self.items = [] def insertItem(self, pItem): self.items.append(pItem) def __str__(self): _dict = self.__dict__.copy() _dict['items'] = [str(item) for item in self.items] return self.__class__.__name__ + ':' + str(_dict) i1 = Item('a', 'b', 'c') i2 = Item('foo', 'bar', 'baz') p = Package(1,2,3,4) p.insertItem(i1) p.insertItem(i2) packages = [p] for package in packages: print package >>> Package:{'date': 2, 'owner': 3, 'serial': 1, 'schema': 4, 'items': ["Item:{'comment': 'c', 'id': 'a', 'delta': 'b'}", "Item:{'comment': 'baz', 'id': 'foo', 'delta': 'bar'}"]} Regarding the error you get, it seems you've stored the class itself, instead instances. The error should be in the way you've built the package list, but you did not provide the code. JM From python at mrabarnett.plus.com Mon Mar 1 10:17:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Mar 2010 15:17:14 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4B8B9845.70604@sequans.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> Message-ID: <4B8BDA7A.3060600@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > MRAB wrote: >> Gregory Ewing wrote: >>> Mel wrote: >>> >>>> You could think of it as a not bad use of the design principle >>>> "Clear The Simple Stuff Out Of The Way First". Destinations are >>>> commonly a lot simpler than sources >>> >>> That's not usually true in assembly languages, though, >>> where the source and destination are both very restricted >>> and often about the same complexity. >>> >>> That's not to say that right-to-left is the wrong way >>> to do it in an assembly language, but there are less >>> misleading words than "move" that could be used. >>> >>> Z80 assembly language uses "load", which makes things >>> considerably clearer: >>> >>> LD A, B ; load A with B >>> >> Some processors distinguish between "load" (memory to register) and >> "store" (register to memory), and the destination and LHS operand of >> binary operations might be the same register, for example: >> >> CLC ; clear the carry >> LDA first ; accumulator := byte at first >> ADCA second ; accumulator := accumulator + byte at second + carry >> STA result ; byte at third := accumulator >> > Guys, you sound like people arguing about old school TV show / series > like star treck :-) > - "He was wearing a blue suit !" > - "Check episode number 29, he appeared with a pink one!" > > I'm glad I'm too young to had to code in assembler, or to bear the > vision of those unlikely space suits from the 70's ;-) > Ah, yes, Star Trek (the original series). If they transported down to a planet and there was a man in a red shirt who you'd never seen before, he'd be the one to die! :-) BTW, the first programming I did was in hexadecimal (C4xx was "LDI xx"). From greg.lindstrom at novasyshealth.com Mon Mar 1 10:19:57 2010 From: greg.lindstrom at novasyshealth.com (Greg Lindstrom) Date: Mon, 01 Mar 2010 09:19:57 -0600 Subject: Looking for an Application Message-ID: <4B8BDB1D.2050309@novasyshealth.com> A few months ago there was a post dealing with an application that would power scripts based on graphical snippets of the screen. Essentially, the script would "look" for a match with what you pasted into it. I don't recall the name of the application, but would like to try it. Does anyone remember what it is? Thanks, --greg From arjun.chennu at gmail.com Mon Mar 1 10:35:38 2010 From: arjun.chennu at gmail.com (Arjun Chennu) Date: Mon, 1 Mar 2010 16:35:38 +0100 Subject: How to end TCP socket data while using readline()? In-Reply-To: <20100227041115.GA24869@cskk.homeip.net> References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> <20100227041115.GA24869@cskk.homeip.net> Message-ID: Thanks for the feedback. Opening a separate file-obj for writing and for reading is just what I've been trying, but I don't seem to get it to work. I'm new to python and I'm not sure if I'm missing the intricacy of some command. Please help: Here is my server snippet: (conn, addr) = sock1.accept() # connected socket print 'Client (localhost) port: ', addr[1] cf = conn.makefile('r',0) # file obj for reading lf = open('ccs.txt','w') for linenum, line in enumerate(cf): # iterate over socket lines lf.write(line) #sys.stdout.write(line) print len(line) cf.close() stat = 'wrote %s lines to file.\n' %(linenum+1) cff = conn.makefile('w',0) # file obj for writing cff.writelines(stat) # cff.write(stat) does not work either!! cff.close() lf.close() conn.close() print stat, "DONE!" And here is the client that I have for it: (sfp is the local file object i read from) for line in sfp.readlines(): cf.write(line) print len(line) print 'done sending' cf.close() #writing ends here cff = s.makefile('r',0) # file obj for writing for line in cff.readlines(): print line cff.close() sfp.close() s.close() The execution sends all the lines (and prints out the len(line) ) and then stays waiting. THen when I manually terminate the client script, the server script happily types the "DONE!" output. Where is this protocol hanging up? Help much appreciated, with a small explanation. Cheers, Arjun On Sat, Feb 27, 2010 at 05:11, Cameron Simpson wrote: > On 26Feb2010 10:39, Arjun wrote: > | Hi, I have a small script that runs a TCP server. A client connects to > | this server and transmits a stored file line-by-line, and then waits > | for a confirmation "done". However, when I run them the first loop > | never really ends -- as the TCP server keeps expecting more data. I am > | using a file-like-object, and so somehow I have to communicate to the > | server that it is the end-of-file. > | > | here is some server code > | > | sock1.bind(('', port)) > | print "Listening at port: ", port > | sock1.listen(1) # listening socket > | (conn, addr) = sock1.accept() # connected socket > | print 'Client (localhost) port: ', addr[1] > | > | cf = conn.makefile('r',0) # file like obj for socket > [...] > | print 'close' > | cf.flush() > | cf.close() > | sfp.close() > [...] > > Too many files. It's not that hard! Or shouldn't be. > > | So what I am wondering is: > | > | 1. Using a file-like object means that the socket becomes uni- > | directional, until the mode of the file object is changed from 'r' to > | 'w' (or vice versa). This seems inefficient, and rather unPythonesque. > | Can somebody tell me if there is a more elegant way of receiving all > | the lines from the client, and then sending a "done" message to the > | client? > > Get the socket. It is a file descriptor (or in may be a python "socket" > object with a file descriptor inside). > > Open _two_ "file" objects on it using > from_file = os.fdopen(fd_of_socket, "r") > to_file = os.fdopen(fd_of_socket, "w"). > > Use the same: > print >>to_file, 'close' > to_file.flush() > method as you're using already. > Read from to_file as needed. > > The same scheme should work in both server and client: > > Don't look for EOF, watch the input line flow. > > You might need to use readline() instead of the file-by-line iteration > stuff, > which I seem to recall has some sort of problem handing out the "latest" > line. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > It's better, when you're riding with someone you don't know so well, to > stick > to the inside line - it's easier to avoid the bits... > - Barry Sheene > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arjun.chennu at gmail.com Mon Mar 1 10:53:10 2010 From: arjun.chennu at gmail.com (Arjun Chennu) Date: Mon, 1 Mar 2010 16:53:10 +0100 Subject: How to end TCP socket data while using readline()? In-Reply-To: References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> <20100227041115.GA24869@cskk.homeip.net> Message-ID: It DOES seem like only when the connection socket is closed via conn.close() that the data is flushed and the 'waiting' ends. So with the earlier suggestion that I open one file-obj for reading and one for writing, I still cannot acheive two-way communication because I need to close the connection for it to actually occur completely! My client waits after the "done sending" line indefinitely. Weird. A On Mon, Mar 1, 2010 at 16:35, Arjun Chennu wrote: > Thanks for the feedback. > > Opening a separate file-obj for writing and for reading is just what I've > been trying, but I don't seem to get it to work. I'm new to python and I'm > not sure if I'm missing the intricacy of some command. Please help: > > Here is my server snippet: > > > (conn, addr) = sock1.accept() # connected socket > print 'Client (localhost) port: ', addr[1] > > cf = conn.makefile('r',0) # file obj for reading > > lf = open('ccs.txt','w') > > for linenum, line in enumerate(cf): # iterate over socket > lines > lf.write(line) > #sys.stdout.write(line) > print len(line) > > cf.close() > > stat = 'wrote %s lines to file.\n' %(linenum+1) > cff = conn.makefile('w',0) # file obj for writing > cff.writelines(stat) # cff.write(stat) does not work > either!! > cff.close() > > lf.close() > conn.close() > print stat, "DONE!" > > And here is the client that I have for it: (sfp is the local file object i > read from) > > > for line in sfp.readlines(): > cf.write(line) > print len(line) > > print 'done sending' > cf.close() #writing ends here > > cff = s.makefile('r',0) # file obj for writing > for line in cff.readlines(): > print line > > cff.close() > > sfp.close() > s.close() > > The execution sends all the lines (and prints out the len(line) ) and then > stays waiting. THen when I manually terminate the client script, the server > script happily types the "DONE!" output. > > Where is this protocol hanging up? Help much appreciated, with a small > explanation. > > Cheers, > Arjun > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Mon Mar 1 11:08:35 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 08:08:35 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: Message-ID: On Feb 28, 9:18?pm, Steven D'Aprano > Wait a minute... if JSON is too hard to edit, and RSON is a *superset* of > JSON, that means by definition every JSON file is also a valid RSON file. > Since JSON is too hard to manually edit, so is RSON. Well, Python is essentially a superset of JSON, with string escape handling being ever so slightly different, and using True instead of true, False instead of false, and None instead of null. YMMV, but I find it possible, even probable, to write Python that is far easier to edit than JSON, and in fact, I have used Python for configuration files that are only to be edited by programmers or other technical types. > Come back when you actually have MANY users other than yourself using > this is real-world projects. Until then, it is too early to even consider > adding it the std library. Python comes with batteries included, but not > experimental batteries that aren't even built yet, let alone proven that > they work. I know that it is too early to be included in the library. But there is a chicken-and-egg problem. PEP 1 says you should circulate a design for discussion before writing code... I fully expect this sort of negative feedback, fully expect that it will be years (if ever) before the code makes it into the standard library, and yet I offer the design for your perusal, just on the slim chance that I might get a few constructive criticisms on the actual design to go along with all the silly strawmen reductio ad absurdum arguments by people who aren't even going to bother to read the thing. Best regards, Pat From qtrimble at gmail.com Mon Mar 1 11:15:19 2010 From: qtrimble at gmail.com (qtrimble) Date: Mon, 1 Mar 2010 08:15:19 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> <121bb934-6d62-482a-a5c2-848668ce237d@q16g2000yqq.googlegroups.com> Message-ID: On Feb 26, 6:19?pm, ru... at yahoo.com wrote: > On Feb 26, 2:21?pm, qtrimble wrote: > > > > > On Feb 26, 4:14?pm, OdarR wrote: > > > > > > below is just a sample. ?There are well over 500,000 lines that need > > > > processed. > > > > > wer1999001 > > > > ? ? ? 31.2234 ? ? ?82.2367 > > > > ? ? ? 37.9535 ? ? ?82.3456 > > > > wer1999002 > > > > ? ? ? 31.2234 ? ? ?82.2367 > > > > ? ? ? 37.9535 ? ? ?82.3456 > > > > did you try something as a working basis ? > > > > Olivier > > > Yes but it's very simple - > > > fileIN = open(r"C:\testing.txt", "r") > > > for line in fileIN: > > ? ? year = line[3:7] > > ? ? day = line[7:10] > > ? ? print year, day > > > This is good since i can get the year and day of year into a variable > > but I haven't gotten any further. > > How about something like (untested): > > ? for line in fileIN: > ? ? ? ?if line.startswith ("wer"): > ? ? ? ? ? ?year = line[3:7] > ? ? ? ? ? ?day = line[7:10] > ? ? ? ? else: > ? ? ? ? ? ?print "%s-%s %s" % (year, day, line.strip()) > > You can adjust the details as needed... Thanks to all of you for your suggestions. This is what I have now. It may not be the most efficient or well written script but it works! Thanks again! fileIN = open(r"C:\z_paul\ims1999.txt", "r") for line in fileIN: if line.startswith("ims"): year = line[3:7] day = line[7:10] newfile = file(r"C:\z_paul\output\ims" + year + day + ".txt", "wt") newfile.write("YEAR,DOY,Y_COORD,X_COORD,TYPE\n") else: temp = line.replace(' ',',') temp2 = temp.replace(', ',',') newfile.write(year + "," + day + temp2) newfile.close() From lie.1296 at gmail.com Mon Mar 1 11:18:30 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Mar 2010 03:18:30 +1100 Subject: Docstrings considered too complicated In-Reply-To: <20100301140943.4edca16b@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> Message-ID: <4b8be8f7$1@dnews.tpgi.com.au> On 03/02/10 00:09, Andreas Waldenburger wrote: > On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 > wrote: > >> Andreas Waldenburger wrote: >>> But as I said: a) I am (we are) not in a position to impose this (We >>> don't work with the code, we just run the software). >> >> I personally believe that the end users have _every_ right to impose >> quality requirements on code used within their business...although I >> may not bring this up in front of them at meetings :) > > Huh? That's like demanding a certain type of truck or vehicle > maintenance plan from a trucking company. Sure, you *could* do it, but > that effectively only limits your options. I think there should be a > clear separation of concerns here. If my truck contains food items that spoils quickly, I would want to make sure that the trucking company takes good care of their refrigeration system and that the truck have as little chance as possible for breakdown due to poor maintenance. From tibor.beck at hotmail.com Mon Mar 1 11:22:27 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Mon, 1 Mar 2010 08:22:27 -0800 (PST) Subject: AOP decorator? Message-ID: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> Hi, suppose my source code looks like: -------------------------------- import aspect_xy class Basic(object, aspect_xy.Basic): pass # basic attributes and methods ... -------------------------------- and the source code of aspect_xy.py is: -------------------------------- class Basic(object): pass # aspect extra attributes and methods ... -------------------------------- how can I write this with decorators? I want something like: ------------------------------- import aspect_xy @aspect_xy # extra attributes and methods ... class Basic(object): pass # basic attributes and methods ... ---------------------------------------------------------- I want to write class decorator function, which: 1. Takes the basic class as parameter 2. Find the same class name in aspect_xy.py 3. Inherit the found aspect class Is it possible? From pmaupin at gmail.com Mon Mar 1 11:27:34 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 08:27:34 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Message-ID: <445e1928-b312-4082-8987-494ad2641e5d@y17g2000yqd.googlegroups.com> On Mar 1, 12:39?am, John Nagle wrote: > Patrick Maupin wrote: > > All: > > > Finding .ini configuration files too limiting, JSON and XML to hard to > > manually edit, and YAML too complex to parse quickly, I have started > > work on a new configuration file parser. > > ? ? You're not supposed to edit those formats manually. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Opinions on that will vary, and as the saying goes, "everybody is entitled to his own opinions, but not his own facts." I submit as fact that there are many initialization files in each of these formats, and I would be willing to place a wager that the majority of the people on this list have used a text editor to modify at least one file in this category at least once. IOW, in my opinion (and it is only an opinion, not a fact), you are actually helping to make the case that a better format is needed. Regards, Pat From anand.shashwat at gmail.com Mon Mar 1 11:59:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 1 Mar 2010 22:29:52 +0530 Subject: Looking for an Application In-Reply-To: <4B8BDB1D.2050309@novasyshealth.com> References: <4B8BDB1D.2050309@novasyshealth.com> Message-ID: project sikuli : http://groups.csail.mit.edu/uid/sikuli/ On Mon, Mar 1, 2010 at 8:49 PM, Greg Lindstrom < greg.lindstrom at novasyshealth.com> wrote: > A few months ago there was a post dealing with an application that would > power scripts based on graphical snippets of the screen. Essentially, the > script would "look" for a match with what you pasted into it. I don't > recall the name of the application, but would like to try it. Does anyone > remember what it is? > > Thanks, > --greg > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From noamraph at gmail.com Mon Mar 1 12:07:15 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Mon, 1 Mar 2010 09:07:15 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> Message-ID: This is most probably a bug discovered in DreamPie 1.0 (See https://bugs.launchpad.net/dreampie/+bug/525652 ) Can you try to download DreamPie 1.0.1, and if it still happens, report a bug? Thanks! Noam From noamraph at gmail.com Mon Mar 1 12:08:28 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Mon, 1 Mar 2010 09:08:28 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: Can you try DreamPie 1.0.1 and say if it still happens? There's a bug report system at launchpad.net/dreampie. Thanks, Noam From robert.kern at gmail.com Mon Mar 1 12:13:37 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Mar 2010 11:13:37 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: On 2010-03-01 10:08 , Patrick Maupin wrote: > On Feb 28, 9:18 pm, Steven D'Aprano >> Come back when you actually have MANY users other than yourself using >> this is real-world projects. Until then, it is too early to even consider >> adding it the std library. Python comes with batteries included, but not >> experimental batteries that aren't even built yet, let alone proven that >> they work. > > I know that it is too early to be included in the library. But there > is a chicken-and-egg problem. PEP 1 says you should circulate a > design for discussion before writing code... Ignore it. That comment really doesn't apply to this case. That's for things that only make sense in the language or standard library, like context managers. For libraries like this, Steven's summary is correct. It needs to have a useful life as a third party package for a few years before you should propose it for inclusion into the standard library. By all means, distribute a design document for comment before you implement things; it's a reasonable practice. But don't bother with a PEP yet. -- 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 From arnodel at googlemail.com Mon Mar 1 12:15:23 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 01 Mar 2010 17:15:23 +0000 Subject: Looking for an Application References: Message-ID: Greg Lindstrom writes: > A few months ago there was a post dealing with an application that > would power scripts based on graphical snippets of the screen. > Essentially, the script would "look" for a match with what you pasted > into it. I don't recall the name of the application, but would like > to try it. Does anyone remember what it is? > > Thanks, > --greg Project SIKULI? http://groups.csail.mit.edu/uid/sikuli/ -- Arnaud From rantingrick at gmail.com Mon Mar 1 12:18:12 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 1 Mar 2010 09:18:12 -0800 (PST) Subject: Sample code usable Tkinter listbox References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> Message-ID: On Mar 1, 6:19?am, "Alf P. Steinbach" wrote: > > ? ? ? ? kw.setdefault('activestyle', 'none') > > Hm, let me steal this line... Thanks! Yes! the default activestyle is quite annoying! From mmitchell at transparent.com Mon Mar 1 12:20:30 2010 From: mmitchell at transparent.com (Matt Mitchell) Date: Mon, 1 Mar 2010 12:20:30 -0500 Subject: Is there a better way to do this? Message-ID: Hi, I wrote a python script that uses pysvn to export projects from an svn repo I have. The repo has hundreds of projects in it with a directory structure that is pretty uniform however it's not exactly uniform because of the capitalization. I.e.: \root \project English \Stuff \Stuff 2 \Project Spanish \Stuff 3 \Stuff 4 My svn repo is case sensitive so if I try to get \root\project Spanish\Stuff 3 I get an error. Fixing the capitalization is not an option for me. My initial idea was to make a list of all the different ways "project" has been capitalized in my repo and try each one. The code looks like this: import pysvn def getstuff(stuffiwant, languageiwantitin): projects = ("project %s/", "Project %s/", "pRojects %s/") c = pysvn.Client() for p in projects: exportme = p % languageiwantitin exportme = "http://localhost/" + exportme + stuffiwant try: c.export(exportme, "C:\\temp\\") break except pysvn.ClientError: print "Not the right capitalization." # do the rest of the stuff I need to do. This works, but to me it seems like there has to be a better way of doing it. Any feedback or suggestions would be appreciated. Thanks, Matt From usenot at geekmail.INVALID Mon Mar 1 12:22:55 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 18:22:55 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> Message-ID: <20100301182255.3de59bc6@geekmail.INVALID> On Tue, 02 Mar 2010 03:18:30 +1100 Lie Ryan wrote: > On 03/02/10 00:09, Andreas Waldenburger wrote: > > On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 > > wrote: > > > >> Andreas Waldenburger wrote: > >>> But as I said: a) I am (we are) not in a position to impose this > >>> (We don't work with the code, we just run the software). > >> > >> I personally believe that the end users have _every_ right to > >> impose quality requirements on code used within their > >> business...although I may not bring this up in front of them at > >> meetings :) > > > > Huh? That's like demanding a certain type of truck or vehicle > > maintenance plan from a trucking company. Sure, you *could* do it, > > but that effectively only limits your options. I think there should > > be a clear separation of concerns here. > > If my truck contains food items that spoils quickly, I would want to > make sure that the trucking company takes good care of their > refrigeration system and that the truck have as little chance as > possible for breakdown due to poor maintenance. My point was that it should not be any of your concern *how* they do it, only *that* they do it. Back in the software world: Those guys write code that works. It does what it's supposed to do. Why should we care where they put their comments? -- INVALID? DE! From pmaupin at gmail.com Mon Mar 1 12:34:47 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 09:34:47 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: Message-ID: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> On Mar 1, 11:13?am, Robert Kern wrote: > Ignore it. That comment really doesn't apply to this case. That's for things > that only make sense in the language or standard library, like context managers. > For libraries like this, Steven's summary is correct. It needs to have a useful > life as a third party package for a few years before you should propose it for > inclusion into the standard library. By all means, distribute a design document > for comment before you implement things; it's a reasonable practice. But don't > bother with a PEP yet. So, I went and re-read PEP 1, and in the fine print it directs me to PEP 2. Mea culpa -- I though I understood the PEP. Nonetheless, the fact that I created what I call a "PEP draft" seems to have had more read into it than I meant. I will bear this in mind when I start future projects. I have a couple of projects, and contribute to another, which in no way should wind up in the standard library. But I find the lack of a good, up-to-date, configuration reader in the library to be an issue, which is why I had the temerity to try to start a discussion on what a good standard configuration file reader should be. Yes, I would like to create something compelling enough to go into the standard library. No, I don't expect it to wind up there for a very long time, if ever. BUT, at the same time, following the PEP format is very valuable for my project. It forces me to think more deeply about the problem I am solving and it forces me to write down some documentation. Really, it's no more burdensome than any other similar useful template. Or, to put it another way, it is my goal (which I may or may not be smart enough to reach) to write a module that anybody would want to use; that is good enough to put into the standard library. Whether this happens or not, one useful tool to help the module down that path (and produce a better module for me and other users even if it never becomes part of the standard library) is to think about what it takes to get into the standard library. Part of this involves writing the PEP. Writing a PEP is a good exercise; the format itself helps me to focus on important issues. So I was writing the contents of the PEP anyway, just for me. The real question, then, is when to release the PEP (vs. the code). I've already got some coding done, but it is not yet good enough to share, and if there is anybody else out there grappling with the same issues at this time, I would prefer not to go into production with it until they have had a chance to look over the design and offer insights and criticisms. Best regards, Pat From robert.kern at gmail.com Mon Mar 1 12:42:16 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Mar 2010 11:42:16 -0600 Subject: Docstrings considered too complicated In-Reply-To: <20100301182255.3de59bc6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: On 2010-03-01 11:22 , Andreas Waldenburger wrote: > Back in the software world: Those guys write code that works. It does > what it's supposed to do. Why should we care where they put their > comments? Software usually needs to be maintained and extended over the course of its lifetime. The original team that wrote it may not be available in the future. Furthermore, docstrings are not comments. They become part of the function object and can be introspected at runtime. This is a very important tool when working with code at the interactive prompt and for the collection of API documentation. Comments are less useful than docstrings; the OP's complaint was that his programmers were putting the function documentation in other places than docstrings, rendering them less useful than they could have been. -- 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 From jeanmichel at sequans.com Mon Mar 1 12:42:17 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Mar 2010 18:42:17 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100301182255.3de59bc6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: <4B8BFC79.10103@sequans.com> Andreas Waldenburger wrote: > On Tue, 02 Mar 2010 03:18:30 +1100 Lie Ryan wrote: > > >> On 03/02/10 00:09, Andreas Waldenburger wrote: >> >>> On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 >>> wrote: >>> >>> >>>> Andreas Waldenburger wrote: >>>> >>>>> But as I said: a) I am (we are) not in a position to impose this >>>>> (We don't work with the code, we just run the software). >>>>> >>>> I personally believe that the end users have _every_ right to >>>> impose quality requirements on code used within their >>>> business...although I may not bring this up in front of them at >>>> meetings :) >>>> >>> Huh? That's like demanding a certain type of truck or vehicle >>> maintenance plan from a trucking company. Sure, you *could* do it, >>> but that effectively only limits your options. I think there should >>> be a clear separation of concerns here. >>> >> If my truck contains food items that spoils quickly, I would want to >> make sure that the trucking company takes good care of their >> refrigeration system and that the truck have as little chance as >> possible for breakdown due to poor maintenance. >> > > My point was that it should not be any of your concern *how* they do > it, only *that* they do it. > > Back in the software world: Those guys write code that works. It does > what it's supposed to do. Why should we care where they put their > comments? > > If you've bought the code and want to maintain it, you'd better make sure it's possible. By the way, the ISO 9001 standard ask for your out sourced processing to be compliant with your QA objectives, so if you care about your code, then you should care for the code you buy. JM From R.Brodie at rl.ac.uk Mon Mar 1 12:47:59 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 1 Mar 2010 17:47:59 -0000 Subject: Is there a better way to do this? References: Message-ID: "Matt Mitchell" wrote in message news:mailman.65.1267464765.23598.python-list at python.org... > My initial idea was to make a list of all the different > ways "project" has been capitalized in my repo and try each one. The > code looks like this: I would use pysvn.Client.list to get a list of files at whatever directory level you require. Then you can do a case insensitive compare or whatever else. From wolftracks at invalid.com Mon Mar 1 12:49:58 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 01 Mar 2010 09:49:58 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 In-Reply-To: References: Message-ID: On 2/23/2010 6:04 PM, Aahz wrote: > In article, > W. eWatson wrote: >> >> My claim is that if one creates a program in a folder that reads a file >> in the folder it and then copies it to another folder, it will read the >> data file in the first folder, and not a changed file in the new folder. >> I'd appreciate it if some w7 users could try this, and let me know what >> they find. >> >> My experience is that if one checks the properties of the copied file, >> it will point to the original py file and execute it and not the copy. > > I've no time to verify your specific claim and have no readily available > proof for mine, but I've seen similar issues on Win7. AFAIK, this has > nothing to do with Python. I've been away for several days and have no idea if anyone above figured this out. Likely not,since your post is at the end. Interesting about 'similar'. I'm pretty much done exploring every nook and cranny on this problem. It can be worked around. I will say that if I look at the properties of the copied file, it shows a shortcut tab that leads back to the original file. I have no recollection of making a shortcut, and always use Copy and Paste. Further, if I do create shortcut in W7, it adds "-shortcut to the file suffix. I do not ever recall seeing that anywhere. I just tried it in XP, and it puts it in front of the name. From joaopcf at gmail.com Mon Mar 1 12:54:20 2010 From: joaopcf at gmail.com (=?ISO-8859-1?Q?Jo=E3o?=) Date: Mon, 1 Mar 2010 09:54:20 -0800 (PST) Subject: [newbie] - python list into a sql query Message-ID: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> Hi. Can someone guide me into getting this to work? It's just really querying a DB of an Autodiscovery tool to have a bunch of updated dns files. (Thought I'm still building the first script steps) I was able to successfully query the DB against a single groupid, but am failing in passing a list of integers into the sql query. I'm failing miserably in, sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ( select hostid from hosts_groups WHERE groupid IN (' + ','.join(map(str, %s)) + ')''' % grp_range with _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1") I'll gladly accept any other code change suggestion #!/usr/bin/env python import MySQLdb import sys, os import code builder_path = '/opt/scripts/dns_builder' grp_range = range(10,15) try: db = MySQLdb.connect(host="localhost", user="tst",passwd="tst",db="tst_db" ) except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) cursor = db.cursor() sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ( select hostid from hosts_groups WHERE groupid IN (' + ','.join(map(str, %s)) + ')''' % grp_range cursor.execute(sql) f = open('%s/dns_unknown_list.txt', 'w+') % builder_path data = cursor.fetchall() for row in data: ip = row[0] host = row[1] dns = row[2] if host == dns: #tmn if ip[0][:10] in ('140.254.30','10.13.74.') group1_file = open('%s/group1.zone', 'w') % builder_path print >>group1_file, '''$ORIGIN group1 ''' print >>group1_file, '%s IN A %s' % (dns, ip) elif ip[0][:3] in ('8.128.46.','6.128.101') group2_file = open('%s/group2.zone', 'w') % builder_path print >>group2_file, '''$ORIGIN group2 ''' print >>group2_file, '%s IN A %s' % (dns, ip) else: print >>f, 'unknown IN A %s' % ip db.close() input_file.close() f.close() From no.email at nospam.invalid Mon Mar 1 13:03:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 10:03:33 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> Message-ID: <7xljebyl56.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > it is my goal (which I may or may not be smart enough to reach) to > write a module that anybody would want to use; But you are working on a solution in search of a problem. The really smart thing to do would be pick something more useful to work on. We don't need another configuration language. I can't even say "yet another" because there's already a "yet another" called yaml. From robert.kern at gmail.com Mon Mar 1 13:05:06 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Mar 2010 12:05:06 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> Message-ID: On 2010-03-01 11:34 , Patrick Maupin wrote: > On Mar 1, 11:13 am, Robert Kern wrote: >> Ignore it. That comment really doesn't apply to this case. That's for things >> that only make sense in the language or standard library, like context managers. >> For libraries like this, Steven's summary is correct. It needs to have a useful >> life as a third party package for a few years before you should propose it for >> inclusion into the standard library. By all means, distribute a design document >> for comment before you implement things; it's a reasonable practice. But don't >> bother with a PEP yet. > > So, I went and re-read PEP 1, and in the fine print it directs me to > PEP 2. Mea culpa -- I though I understood the PEP. > > Nonetheless, the fact that I created what I call a "PEP draft" seems > to have had more read into it than I meant. I will bear this in mind > when I start future projects. I have a couple of projects, and > contribute to another, which in no way should wind up in the standard > library. But I find the lack of a good, up-to-date, configuration > reader in the library to be an issue, which is why I had the temerity > to try to start a discussion on what a good standard configuration > file reader should be. > > Yes, I would like to create something compelling enough to go into the > standard library. No, I don't expect it to wind up there for a very > long time, if ever. BUT, at the same time, following the PEP format > is very valuable for my project. It forces me to think more deeply > about the problem I am solving and it forces me to write down some > documentation. Really, it's no more burdensome than any other similar > useful template. Certainly. The PEP format is a useful one. I've used it myself for some numpy design documents. But can you see why people might get confused about your intentions when you call it a draft PEP and post it to python-dev? If you stop calling it a PEP and stop talking about putting it in the standard library, people will stop being distracted by those issues. -- 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 From maygeo at netplus.ch Mon Mar 1 13:07:17 2010 From: maygeo at netplus.ch (Raphael Mayoraz) Date: Mon, 01 Mar 2010 10:07:17 -0800 Subject: Variable definition In-Reply-To: <4B887224.2080805@optimum.net> References: <4B885A0B.9040705@netplus.ch> <4B887224.2080805@optimum.net> Message-ID: <4B8C0255.3090509@netplus.ch> John Posner wrote: > On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >> Hello, >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >> for key, value in varDic.iteritems(): >> 'myPrefix' + key = value >> > > No trick, just swap a new key-value pair for each existing pair: > > for key, value in varDic.iteritems(): > varDic[myPrefix + key] = value > del varDict[key] > > Just make sure that *myPrefix* isn't an empty string! > > -John Thanks for your answer. However, your solution changes the key name in the dictionary. That's not what I want I need to do. What I want is to define a new variable which name is define as a string: 'myPrefx' + key. In the example I give, I would get 3 variables: myPrefixred = a myPrefixgreen = b myPrefixblue = c Raphael From fetchinson at googlemail.com Mon Mar 1 13:40:00 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Mar 2010 19:40:00 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7xljebyl56.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: >> it is my goal (which I may or may not be smart enough to reach) to >> write a module that anybody would want to use; > > But you are working on a solution in search of a problem. The really > smart thing to do would be pick something more useful to work on. We > don't need another configuration language. I can't even say "yet > another" because there's already a "yet another" called yaml. And in case you are new here let me assure you that Paul is saying this with his full intention of being helpful to you. I also would think that working on such a project might be fun and educational for you but completely useless if you have users other than yourself in mind. Again, I'm trying to be helpful here, so you can focus on a project that is both fun/educational for you and also potentially useful for others. This RSON business is not one of them. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at mrabarnett.plus.com Mon Mar 1 13:44:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Mar 2010 18:44:49 +0000 Subject: [newbie] - python list into a sql query In-Reply-To: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> References: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> Message-ID: <4B8C0B21.8010404@mrabarnett.plus.com> Jo?o wrote: > Hi. > > Can someone guide me into getting this to work? It's just really > querying a DB of an Autodiscovery tool to have a bunch of updated dns > files. > (Thought I'm still building the first script steps) I was able to > successfully query the DB against a single groupid, but am failing in > passing a list of integers into the sql query. > > I'm failing miserably in, > > sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN > ( > select hostid from hosts_groups WHERE groupid IN (' + > ','.join(map(str, %s)) + ')''' % grp_range > > > with > _mysql_exceptions.ProgrammingError: (1064, "You have an error in > your SQL syntax; check the manual that corresponds to your MySQL > server version for the right syntax to use near '' at line 1") > [snip] The triple-quoted string starts at: '''SELECT ... and ends at: ...)''' % grp_range which means that the part where you do the .join is _inside_ the string. From pmaupin at gmail.com Mon Mar 1 13:45:07 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 10:45:07 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> On Mar 1, 12:03?pm, Paul Rubin wrote: > But you are working on a solution in search of a problem. ?The really > smart thing to do would be pick something more useful to work on. ?We > don't need another configuration language. ?I can't even say "yet > another" because there's already a "yet another" called yaml. The only "in search of" here is that, instead of working on a point solution for my particular problem, I am "in search of" a solution that is a bit more elegant and general, and that might help solve other people's problems too. If you are not one of those that has this sort of problem at this point in time, then feel free to kill- file this thread. Thanks, Pat From leo.shklovskii at gmail.com Mon Mar 1 13:47:42 2010 From: leo.shklovskii at gmail.com (Leo) Date: Mon, 1 Mar 2010 10:47:42 -0800 (PST) Subject: python shell crashing on paste References: <1ede46e4-8ca1-4fe0-ad3f-7e781bbe1182@b36g2000pri.googlegroups.com> <4b84ca31$0$15832$ba4acef3@reader.news.orange.fr> Message-ID: <227e3061-db36-4188-a174-74019814af63@t31g2000prh.googlegroups.com> Thanks for responding Michel. It looks like its an issue with pyreadline - http://ipython.scipy.org/moin/PyReadline/Intro - causing the crash. I'm working with the author of it on trying to get the issue figured out. It's not related to UAC. -- --Leo On Feb 23, 10:41?pm, "Michel Claveau - MVP" wrote: > Hi! > > Where (directory) are you, when the problem come? > Have you try with UAC disabled? > > @+ > -- ? > MCI From rami.chowdhury at gmail.com Mon Mar 1 14:04:25 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 1 Mar 2010 11:04:25 -0800 Subject: [newbie] - python list into a sql query In-Reply-To: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> References: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> Message-ID: <201003011104.25211.rami.chowdhury@gmail.com> On Monday 01 March 2010 09:54:20 Jo?o wrote: > Hi. > > Can someone guide me into getting this to work? It's just really > querying a DB of an Autodiscovery tool to have a bunch of updated dns > files. I wouldn't be building SQL queries by hand if I could avoid it -- is this just a few one-off scripts or a project that could usefully benefit from a database abstraction layer (like SQLAlchemy: http://www.sqlalchemy.org)? > > sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN > ( > select hostid from hosts_groups WHERE groupid IN (' + > ','.join(map(str, %s)) + ')''' % grp_range > I'm not sure what you expect this to evaluate to? #>>> grp_range = [1, 2, 3] # dummy data #>>> sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ... ( ... SELECT hostid FROM hosts_groups WHERE groupid IN (' + ... ','.join(map(str, %s)) + ')''' % grp_range #>>> print sql SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ( SELECT hostid FROM hosts_groups WHERE groupid IN (' + ','.join(map(str, [1, 2, 3])) + ') Since the triple-quoted string only ends at the corresponding triple quote, you're including some Python code into the string instead of executing it. If you really want to splice the elements of grp_range into the query, you should do something like: #>>> sql = 'SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN (SELECT hostid FROM hosts_groups WHERE groupid IN (%s))' % ",".join(str(x) for x in grp_range) #>>> sql 'SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN (SELECT hostid FROM hosts_groups WHERE groupid IN (1,2,3))' Although, really, if you can, I'd parameterise the query (http://mysql- python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.BaseCursor- class.html#execute) at the very least... > > with > _mysql_exceptions.ProgrammingError: (1064, "You have an error in > your SQL syntax; check the manual that corresponds to your MySQL > server version for the right syntax to use near '' at line 1") > > > > I'll gladly accept any other code change suggestion > > > #!/usr/bin/env python > > import MySQLdb > import sys, os > import code > > builder_path = '/opt/scripts/dns_builder' > grp_range = range(10,15) > > try: > db = MySQLdb.connect(host="localhost", > user="tst",passwd="tst",db="tst_db" ) > except MySQLdb.Error, e: > print "Error %d: %s" % (e.args[0], e.args[1]) > > cursor = db.cursor() > > sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE > hostid IN ( > select hostid from hosts_groups WHERE groupid IN (' + > ','.join(map(str, %s)) + ')''' % grp_range > > cursor.execute(sql) > > f = open('%s/dns_unknown_list.txt', 'w+') % builder_path > data = cursor.fetchall() > > for row in data: > ip = row[0] > host = row[1] > dns = row[2] > if host == dns: > #tmn > if ip[0][:10] in ('140.254.30','10.13.74.') > group1_file = open('%s/group1.zone', 'w') % builder_path > print >>group1_file, '''$ORIGIN group1 > > ''' > print >>group1_file, '%s IN A %s' % (dns, ip) > elif ip[0][:3] in ('8.128.46.','6.128.101') > group2_file = open('%s/group2.zone', 'w') % builder_path > print >>group2_file, '''$ORIGIN group2 > > ''' > print >>group2_file, '%s IN A %s' % (dns, ip) > else: > print >>f, 'unknown IN A %s' % ip > > db.close() > input_file.close() > f.close() ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From pmaupin at gmail.com Mon Mar 1 14:18:20 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 11:18:20 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> Message-ID: <062d989e-27db-46b3-913f-0573bb70543f@y17g2000yqd.googlegroups.com> > > Certainly. The PEP format is a useful one. I've used it myself for some numpy > design documents. But can you see why people might get confused about your > intentions when you call it a draft PEP and post it to python-dev? If you stop > calling it a PEP and stop talking about putting it in the standard library, > people will stop being distracted by those issues. As I mentioned, I didn't see the fine print in PEP 1 about PEP 2 being the document for library modules. As I mentioned, mea culpa. It is painfully obvious that some don't like the way I have gone about describing the project. They obviously view me announcing this as premature, or presumptuous, or something, and they have some sort of visceral reaction to that. However, I do not believe that any people (other than me) were really confused in the process. I made my intentions clear, and some people reacted badly to that because I didn't follow the process (for which I apologize again). But calling it a draft PEP is a distraction (because of the visceral reaction), but is not really what I would call confusing. My intention actually is to try to build something that is worthy of the standard library, and to eventually try to get it accepted, because I perceive a hole there, with a lot of point solutions being done to solve a common problem, and I believe the pushback is coming from people who fully understood that intention from my posting. I will try to say "hey -- here's a hole in the library and a proposal for how to fix it" more diplomatically and in the correct forum in the future, but it would be disingenuous for me to disown my goal of getting a better configparser into the standard library. Regards, Pat From pmaupin at gmail.com Mon Mar 1 14:30:28 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 11:30:28 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> On Mar 1, 12:40?pm, Daniel Fetchinson wrote: > > But you are working on a solution in search of a problem. ?The really > > smart thing to do would be pick something more useful to work on. ?We > > don't need another configuration language. ?I can't even say "yet > > another" because there's already a "yet another" called yaml. > > And in case you are new here let me assure you that Paul is saying > this with his full intention of being helpful to you. I also would > think that working on such a project might be fun and educational for > you but completely useless if you have users other than yourself in > mind. Again, I'm trying to be helpful here, so you can focus on a > project that is both fun/educational for you and also potentially > useful for others. This RSON business is not one of them. OK, but I am a bit unclear on what you and/or Paul are claiming. It could be one of a number of things. For example: - There is a preexisting file format suitable for my needs, so I should not invent another one. - If I invent a file format suitable for my needs, it couldn't possibly be general enough for anybody else. - Even if it was general enough for somebody else, there would only be two of them. I've been known to waste time (or be accused of wasting time) on various endeavors, but I like to know exactly *why* it is perceived to be a waste. Regards, Pat From jjposner at optimum.net Mon Mar 1 14:34:53 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 01 Mar 2010 14:34:53 -0500 Subject: Variable definition In-Reply-To: <4B8C0255.3090509@netplus.ch> References: <4B885A0B.9040705@netplus.ch> <4B887224.2080805@optimum.net> <4B8C0255.3090509@netplus.ch> Message-ID: <4B8C16DD.40506@optimum.net> On 3/1/2010 1:07 PM, Raphael Mayoraz wrote: > John Posner wrote: >> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >>> Hello, >>> >>> I'd like to define variables with some specific name that has a common >>> prefix. >>> Something like this: >>> >>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >>> for key, value in varDic.iteritems(): >>> 'myPrefix' + key = value >>> >> >> No trick, just swap a new key-value pair for each existing pair: >> >> for key, value in varDic.iteritems(): >> varDic[myPrefix + key] = value >> del varDict[key] >> >> Just make sure that *myPrefix* isn't an empty string! >> >> -John > Thanks for your answer. > However, your solution changes the key name in the dictionary. > That's not what I want I need to do. What I want is to define a new > variable which name is define as a string: 'myPrefx' + key. In the example > I give, I would get 3 variables: > myPrefixred = a > myPrefixgreen = b > myPrefixblue = c Yes, I misinterpreted your request. I believe there's a consensus around here that you shouldn't even try to accomplish your goal. Instead of creating *myPrefixred* as a (module-)global name or a (function-)local name, you should just use the dictionary as-is: *varDict['red']*. Or maybe make the names into attributes of a class, as Alex Goretoy suggested. [1] Can you present a convincing argument as to why you really, really need to use the name *myPrefixred* ? -John [1] http://mail.python.org/pipermail/python-list/2010-February/1237736.html From helps4indian at gmail.com Mon Mar 1 14:37:03 2010 From: helps4indian at gmail.com (coolboy8) Date: Mon, 1 Mar 2010 11:37:03 -0800 (PST) Subject: Best auto insurance company // Best auto insurance company /// Best auto insurance company /// Message-ID: <795a705c-5564-4cf8-8b83-71d2aeae4a53@s36g2000prf.googlegroups.com> VISIT http://alturl.com/8xs8 From no.email at nospam.invalid Mon Mar 1 14:37:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 11:37:39 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> Message-ID: <7xhbozrfy4.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > - There is a preexisting file format suitable for my needs, so I > should not invent another one. There are in fact quite a few--json, yaml, .ini, xml, Python literals (http://code.activestate.com/recipes/364469-safe-eval/), s-expressions, actual Python code that the application can import, and so forth. The problem isn't that you're trying to invent a useless file format per se, but rather that in trying to get other people to learn it and use it, you're also trying to appropriate a chunk of the user community's scarce and precious brain cells without good justification. Newbie designers are often lured into that and they're unfortunately (i.e. to the community's detrimtent) often more successful than they really should be. Your one complaint about yaml is that it's slow to parse. Why do you care about the parsing speed of a config file? If the existing implementation is too slow, why not write a faster one instead of designing yayaml? Even yaml is excessive in my view. "Yet another" was an ok plan when Steve Johnson started the trope by writing Yacc 30 years ago. These days, don't do yet another without very convincing reasons for rejecting what is already there. From tjreedy at udel.edu Mon Mar 1 14:41:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Mar 2010 14:41:27 -0500 Subject: AOP decorator? In-Reply-To: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> References: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> Message-ID: On 3/1/2010 11:22 AM, gentlestone wrote: > Hi, > > suppose my source code looks like: > -------------------------------- > import aspect_xy > class Basic(object, aspect_xy.Basic): > pass # basic attributes and methods ... As a sidenote, this violates my understanding of aspect-oriented programming, which is to add aspects that go across several derived classes. But... > -------------------------------- > and the source code of aspect_xy.py is: > -------------------------------- > class Basic(object): > pass # aspect extra attributes and methods ... > -------------------------------- > how can I write this with decorators? I want something like: > ------------------------------- > import aspect_xy > @aspect_xy # extra attributes and methods ... > class Basic(object): > pass # basic attributes and methods ... > ---------------------------------------------------------- > I want to write class decorator function, which: > 1. Takes the basic class as parameter > 2. Find the same class name in aspect_xy.py > 3. Inherit the found aspect class > Is it possible? You would have to look at the difference between Basic with and without the explicit base class and patch the latter to look like the former. At minimum, you would have to fix .__bases__ and .__mro__, but I do not know if those are writable. To me, it seems easier to be explicit. tjr From joncle at googlemail.com Mon Mar 1 14:49:39 2010 From: joncle at googlemail.com (Jon Clements) Date: Mon, 1 Mar 2010 11:49:39 -0800 (PST) Subject: AOP decorator? References: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> Message-ID: <0d3daa47-cb27-4134-a6b5-be3824f5cf0b@f8g2000yqn.googlegroups.com> On Mar 1, 4:22?pm, gentlestone wrote: > Hi, > > suppose my source code looks like: > -------------------------------- > ? import aspect_xy > ? class Basic(object, aspect_xy.Basic): > ? ? pass # basic attributes and methods ... > -------------------------------- > and the source code of aspect_xy.py is: > -------------------------------- > ? class Basic(object): > ? ? pass ?# aspect extra attributes and methods ... > -------------------------------- > how can I write this with decorators? I want something like: > ------------------------------- > ? import aspect_xy > ? @aspect_xy # extra attributes and methods ... > ? class Basic(object): > ? ? pass # basic attributes and methods ... > ---------------------------------------------------------- > I want to write class decorator function, which: > 1. Takes the basic class as parameter > 2. Find the same class name in aspect_xy.py > 3. Inherit the found aspect class > Is it possible? Untested and written quickly, so all possible disclaimers apply ;) class BaseObject(object): pass def aspect_xy_dec(base): def wrapper(cls): return type(cls.__name__, (base, getattr(aspect_xy, cls.__name__)), {}) return wrapper @aspect_xy(BaseObject) class SomeObject: pass Cheers, Jon. From pmaupin at gmail.com Mon Mar 1 14:59:13 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 11:59:13 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> Message-ID: <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> On Mar 1, 1:37?pm, Paul Rubin wrote: > There are in fact quite a few--json, yaml, .ini, xml, Python literals > (http://code.activestate.com/recipes/364469-safe-eval/), s-expressions, > actual Python code that the application can import, and so forth. Yes, I know about those. > The problem isn't that you're trying to invent a useless file format per > se, but rather that in trying to get other people to learn it and use > it, you're also trying to appropriate a chunk of the user community's > scarce and precious brain cells without good justification. ?Newbie > designers are often lured into that and they're unfortunately (i.e. to > the community's detrimtent) often more successful than they really > should be. Can't disagree with the statement about newbie designers. On the flip side, sometimes things wind up being defacto standards, simply because nobody could be bothered to write a better one, and they have lots of little niggling warts that also collectively take up a lot of time and attention. There is obviously a good balance somewhere. > Your one complaint about yaml is that it's slow to parse. ?Why do you > care about the parsing speed of a config file? ?If the existing > implementation is too slow, why not write a faster one instead of > designing yayaml? ?Even yaml is excessive in my view. ?"Yet another" was > an ok plan when Steve Johnson started the trope by writing Yacc 30 years > ago. ?These days, don't do yet another without very convincing reasons > for rejecting what is already there. One of my complaints. If you had read the document you would have seen others. I actually have several complaints about YAML, but I tried to write a cogent summary. Regards, Pat From bdesth.quelquechose at free.quelquepart.fr Mon Mar 1 14:59:55 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 01 Mar 2010 20:59:55 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: Message-ID: <4b8c2a34$0$10470$426a74cc@news.free.fr> Michael Rudolf a ?crit : > Out of curiosity I tried this and it actually worked as expected: > >>>> class T(object): > x=[] > foo=x.append > def f(self): > return self.x > > >>>> t=T() >>>> t.f() > [] >>>> T.foo(1) >>>> t.f() > [1] >>>> > > At first I thought "hehe, always fun to play around with python. Might > be useful sometimes" - but then It really confused me what I did. I > mean: f is what we call a method, right? Wrong. It's a function. T.f is an unbound method (in python 2.x at least) and t.f is a bound method. > But was is foo? A bound method. Bound to x, of course. > It is not a > method and not a classmethod as it accepts no self and no cls. Yes it does. Else how would t.foo(4) (or T.foo(4)) append 4 to x ? > Perhaps this all does not matter, It does. > but now I am really confused about the > terminology. So: what makes a method a method? The right question is: what makes a function a method !-) > And of what type? Answer here: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 I really have to put this in the wiki :-/ From no.email at nospam.invalid Mon Mar 1 15:08:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 12:08:58 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> Message-ID: <7x635fdcth.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > One of my complaints. If you had read the document you would have > seen others. I actually have several complaints about YAML, but I > tried to write a cogent summary. Yaml sucks, but seems to have gotten some traction regardless. Therefore the Python principle of "there should be one and only one obvious way to do it" says: don't try to replace the existing thing if your new thing is only slightly better. Just deal with the existing thing's imperfections or make improvements to it. If you can make a really powerful case that your new thing is 1000x better than the old thing, that's different, but I don't think we're seeing that here. Also, XML is used for pretty much everything in the Java world. It sucks too, but it is highly standardized, it observably gets the job done, there are tons of structure editors for it, etc. Frankly I'd rather have stayed with it than deal with Yaml. There are too many of these damn formats. We should ban all but one of them (I don't much care which one). And making even more of them is not the answer. From usenot at geekmail.INVALID Mon Mar 1 15:24:13 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 21:24:13 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: <20100301212413.5694580e@geekmail.INVALID> On Mon, 01 Mar 2010 11:42:16 -0600 Robert Kern wrote: > On 2010-03-01 11:22 , Andreas Waldenburger wrote: > > > Back in the software world: Those guys write code that works. It > > does what it's supposed to do. Why should we care where they put > > their comments? > > Software usually needs to be maintained and extended over the course > of its lifetime. The original team that wrote it may not be available > in the future. > > Furthermore, docstrings are not comments. They become part of the > function object and can be introspected at runtime. This is a very > important tool when working with code at the interactive prompt and > for the collection of API documentation. Comments are less useful > than docstrings; the OP's complaint was that his programmers were > putting the function documentation in other places than docstrings, > rendering them less useful than they could have been. > No, the OP complained about those guys being idiots. I should know, because I posted it. /W -- INVALID? DE! From usenot at geekmail.INVALID Mon Mar 1 15:29:54 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 21:29:54 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: <20100301212954.7aa0b99d@geekmail.INVALID> On Mon, 01 Mar 2010 18:42:17 +0100 Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: > [snip] > > Back in the software world: Those guys write code that works. It > > does what it's supposed to do. Why should we care where they put > > their comments? > > > > > If you've bought the code and want to maintain it, you'd better make > sure it's possible. > Fair enough, but we don't want to maintain it. > By the way, the ISO 9001 standard ask for your out sourced processing > to be compliant with your QA objectives, so if you care about your > code, then you should care for the code you buy. > We did not buy code. If it were written in C or such, we would never get to see it. It's not our concern. /W -- INVALID? DE! From pmaupin at gmail.com Mon Mar 1 15:35:46 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 12:35:46 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <2804c8c0-ffe5-4dde-b076-3e0948c32021@g11g2000yqe.googlegroups.com> On Mar 1, 2:08?pm, Paul Rubin wrote: > Yaml sucks, but seems to have gotten some traction regardless. Yes, that's actually one of the reasons I want to do this. I've heard that some of the YAML people want that in the standard library, and IMHO that would be a huge mistake. > Therefore the Python principle of "there should be one and only one > obvious way to do it" says: don't try to replace the existing thing if > your new thing is only slightly better. But for my use-case, YAML is irretrievably broken. Sure, it looks reasonably nice, but it increases regression runtime unacceptably. Also, despite their current protestations that Yaml AIN'T markup language, the syntax still belies its markup roots. I'm looking for a configuration language, not a markup language. >?Just deal with the existing thing's imperfections or make improvements to it. Well, I've looked at the YAML parser and I can assure you that I will not be contributing to that project. > If you can make a really powerful case that your new thing is 1000x better than the old thing, that's different, but I don't think we're seeing that here. Well, there's no way I'm hitting three orders of magnitude, but I don't think the bar is really that high. We will see. > Also, XML is used for pretty much everything in the Java world. ?It > sucks too, but it is highly standardized, it observably gets the job > done, there are tons of structure editors for it, etc. ?Frankly > I'd rather have stayed with it than deal with Yaml. XML can certainly be made readable by humans. It's hard to make it writeable by (average) humans just using a regular text editor, and even though there are tons of structure editors, requiring non- technical people to find one of those and start using it is a non- starter in many cases. But I can't strongly disagree with the opinion that YAML doesn't offer all that much over it. > There are too many of these damn formats. ?We should ban all but one of > them (I don't much care which one). ?And making even more of them is not > the answer. Well, I think that XML and YAML both overreach by trying to be all things to all applications. So I'm aiming a lot lower than that. I just want to make really good configuration files that are easy to modify in a text editor. None of the existing formats are suitable. I may be the only one who feels that way. OTOH, if we never invented new things, then I wouldn't be enjoying restructured text, and I'd be missing out on a lot there... Regards, Pat From no.email at nospam.invalid Mon Mar 1 15:42:20 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 12:42:20 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <2804c8c0-ffe5-4dde-b076-3e0948c32021@g11g2000yqe.googlegroups.com> Message-ID: <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > But for my use-case, YAML is irretrievably broken. Sure, it looks > reasonably nice, but it increases regression runtime unacceptably. How big are the files that you want to parse with it? Sheesh. > Well, I've looked at the YAML parser and I can assure you that I will > not be contributing to that project. So write a new one that parses the same syntax, but cleaner and faster. > XML can certainly be made readable by humans. It's hard to make it > writeable by (average) humans just using a regular text editor, I do it all the time; it's a bit dreary but not difficult. And there is absolutely no way to get anything done in this field anymore without dealing with XML from time to time. So given that we all have some experience using it, it's sensible to stick with it. > None of the existing formats are suitable. I may be the only one who > feels that way. OTOH, if we never invented new things, then I > wouldn't be enjoying restructured text, and I'd be missing out on a > lot there... ReST is another abomination that should never have gotten off the ground. It is one of the reasons I react so negatively to your config format proposal. It just sounds like more of the same. From urbangabo at gmail.com Mon Mar 1 15:53:57 2010 From: urbangabo at gmail.com (Gabor Urban) Date: Mon, 1 Mar 2010 21:53:57 +0100 Subject: Class attributes / methods..... full Python script Message-ID: Hi guys, thanks for the ideas. Here you are the code. Not transcoded from Java for I do not know Java enough.. I am scanning an XML file, and have a large ammount of logging. Any ideas are wellcome as before.... Thnx Code:> #--------------------------------------------- ## Generate CSV from OEP History XML #--------------------------------------------- import sys import os from xml.dom.minidom import parse, parseString import xml.dom import logging versionStr = '0.01' class Item: def __init__(self, pId, pChange, pComment): self.ID = pId self.Delta = pChange self.Comment = pComment def PrintItem(self): str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) return str class Package: def __init__(self, pSerial, pDate, pOwner, pSchema): self.serial = pSerial self.date = pDate self.owner = pOwner self.schema = pSchema self.items = [] def insertItem(self, pItem): self.items.append(pItem) def printPackage(self): lines = [] str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) number = self.items.length for idx in xrange(number): line = '' istr = self.items[idx].PrintItem() line = str + ',' + istr lines.append(line) return lines def getItem(tracer, pkgItem, itemName): retval = -1 name = "" found = 0 str = "" tracer.info('Function getItem entry, name = %s',itemName) nItem = pkgItem.getElementsByTagName(itemName).item(0) for node in pkgItem.childNodes: if node.nodeType != xml.dom.Node.TEXT_NODE: tracer.debug('Scanning node name = %s',node.nodeName) if node.nodeName == itemName: tracer.debug('Pkg %s found',itemName) else: tracer.warning('Pkg %s is not found',itemName) continue for entity in node.childNodes: if entity.nodeType == xml.dom.Node.TEXT_NODE: retval = entity.nodeValue tracer.debug("Node value found %s",retval) found = 1 break if found == 1: break tracer.debug('Function getItem returns %s',retval) return retval logger = logging.getLogger('XmlHistory') handler = logging.FileHandler("Xmlhistory.trc",'a') ## handler = logging.StreamHandler(sys.stderr) logger.addHandler(handler) formatter = logging.Formatter("%(name)s %(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s") handler.setFormatter(formatter) logger.setLevel(2) fileName = "history.xml" output = 'history.csv' logger.info('Xml history generator version %s',versionStr) logger.info('Starting history generation on file:%s',fileName) packages = [] data = [] ## Start XML processing dataSource = parse(fileName) print dataSource.documentElement.tagName listCsomag = dataSource.getElementsByTagName("csomag") size = listCsomag.length logger.debug('Number of packages = %d',size) for idx in xrange(size): attrib = "" package = None serial = 0 date = "" owner = "" schema = "" flag = False logger.info('Parsing package id=%d',idx) attrib = getItem(logger, listCsomag.item(idx),'sorszam') if attrib <> "NUM" and attrib <> -1: serial = int(attrib) flag = True logger.debug('Package serial set to %d',serial) else: logger.debug("Template package found.") break attrib = "" attrib = getItem(logger,listCsomag.item(idx),"datum") if attrib <> -1: date = attrib flag = flag and True logger.debug('Package date set to %s',date) attrib = "" attrib = getItem(logger,listCsomag.item(idx),"ki") if attrib <> -1: owner = attrib flag = flag and True logger.debug('Package owner set to %s',owner) attrib = "" attrib = getItem(logger,listCsomag.item(idx),"sema") if attrib <> -1: schema = attrib flag = flag and True logger.debug('Package schema set to %s',schema) if flag <> True: logger.error('Package id=%d is inconsistent',idx) break else: logger.info('Package id=%d is ok',idx) package = Package(serial,date,owner,schema) listItem = listCsomag.item(idx).getElementsByTagName("item") itemSize = listItem.length logger.debug('Number of items = %d',itemSize) for num in xrange(itemSize): flag = False value = -1 listId = 0 change = "" comment = "" item = None logger.info('Parsing item id = %d',num) value = getItem(logger,listItem.item(num),"item_id") if value <> -1: listId = int(value) flag = True logger.debug('List id set to %d',listId) value = "" value = getItem(logger,listItem.item(num),"valtozas") if value <> -1: change = value flag = flag and True logger.debug('List change desc. set to "%s"',change) value = "" value = getItem(logger,listItem.item(num),"komment") if value <> -1: comment = value flag = flag and True logger.debug('List comment desc. set to "%s"',comment) if flag <> True: logger.error('Item id = %d inconsistent',num) break else: logger.info('Item id = %d is ok',num) item = Item(listId,change,comment) package.insertItem(item) packages.append(Package) logger.info('Processing Xml file %s is done',fileName) logger.info('Generating file %s is started',output) size = len(packages) package = None for index in xrange(size): logger.info('PrettyPrinting package id=%d',index) oplines = [] oplines = packages[index].printPackage() for i in xrange(oplines.length): data.append(oplines[i]) print data -- Linux: Choice of a GNU Generation From gh at ghaering.de Mon Mar 1 15:59:53 2010 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 01 Mar 2010 21:59:53 +0100 Subject: Building Python with Scons Message-ID: I'm setting up a third-party library project (similar to the one in Google Chromium) where I use SCons as build tool. Now I need to integrate Python, too. Has anybody written a Scons script for Python 2.x or 3.x, yet? -- Gerhard From philip at semanchuk.com Mon Mar 1 16:02:48 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 1 Mar 2010 16:02:48 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7x635fdcth.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <7E76CFE6-DBEA-491C-B636-338D378672C4@semanchuk.com> On Mar 1, 2010, at 3:08 PM, Paul Rubin wrote: > Patrick Maupin writes: >> One of my complaints. If you had read the document you would have >> seen others. I actually have several complaints about YAML, but I >> tried to write a cogent summary. > > Yaml sucks, but seems to have gotten some traction regardless. > Therefore the Python principle of "there should be one and only one > obvious way to do it" says: don't try to replace the existing thing if > your new thing is only slightly better. Just deal with the existing > thing's imperfections or make improvements to it. If you can make a > really powerful case that your new thing is 1000x better than the old > thing, that's different, but I don't think we're seeing that here. > > Also, XML is used for pretty much everything in the Java world. It > sucks too, but it is highly standardized, it observably gets the job > done, there are tons of structure editors for it, etc. Frankly > I'd rather have stayed with it than deal with Yaml. > > There are too many of these damn formats. We should ban all but one > of > them (I don't much care which one). And making even more of them is > not > the answer. I dunno, times change, needs change. We must invent new tools, be those computer languages or data formats. Otherwise we'd still be programming in COBOL and writing fixed-length records to 12 inch floppies.* If Mr. Maupin was a giant corporation trying to shove a proprietary format down our collective throats, I might object to RSON. But he's not. He appears willing for it live or die on its merits, so I say good luck to him. I don't want or need it, but someone else might. Cheers Philip * You had floppies? Bleddy luxury! We wrote our data on wood pulp we'd chewed ourselves and dried into paper, using drops of our own blood to represent 1s and 0s. From breamoreboy at yahoo.co.uk Mon Mar 1 16:09:39 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Mar 2010 21:09:39 +0000 Subject: Docstrings considered too complicated In-Reply-To: <20100301212954.7aa0b99d@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> Message-ID: Andreas Waldenburger wrote: > On Mon, 01 Mar 2010 18:42:17 +0100 Jean-Michel Pichavant > wrote: > >> Andreas Waldenburger wrote: >> [snip] >>> Back in the software world: Those guys write code that works. It >>> does what it's supposed to do. Why should we care where they put >>> their comments? >>> >>> >> If you've bought the code and want to maintain it, you'd better make >> sure it's possible. >> > Fair enough, but we don't want to maintain it. > > >> By the way, the ISO 9001 standard ask for your out sourced processing >> to be compliant with your QA objectives, so if you care about your >> code, then you should care for the code you buy. >> > We did not buy code. If it were written in C or such, we would never > get to see it. > > It's not our concern. > > /W > From your original post. a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: So what is the relationship between your company and this other company? When it gets down to pounds, shillings and pence (gosh, I'm old!:) it sure as hell could make a tremendous difference in the long term, given that usually maintainance costs are astronomical when compared to initial development costs. Regards. Mark Lawrence. From pmaupin at gmail.com Mon Mar 1 16:11:59 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 13:11:59 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <2804c8c0-ffe5-4dde-b076-3e0948c32021@g11g2000yqe.googlegroups.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Message-ID: <0417d443-2013-4f62-9158-b684e3be779c@u9g2000yqb.googlegroups.com> On Mar 1, 2:42?pm, Paul Rubin wrote: > Patrick Maupin writes: > > But for my use-case, YAML is irretrievably broken. ?Sure, it looks > > reasonably nice, but it increases regression runtime unacceptably. > > How big are the files that you want to parse with it? ?Sheesh. Tiny, but over and over. The rst2pdf testsuite can generate approximately 160 PDFs, totalling around 2.5 MB, in around 22 seconds on one of my machines. But if I replace the JSON parser with a YAML parser, that goes up to 55 seconds. Wait, maybe it's because JSON is optimized in C! Nope, using JSON but disabling the C scanner only takes it to 22.3 seconds... > > > Well, I've looked at the YAML parser and I can assure you that I will > > not be contributing to that project. > > So write a new one that parses the same syntax, but cleaner and faster. But there are already several parsers for YAML, and none of them agree! The syntax definition is a mess. The thing's been in development for 10 years now, and there is no one true way to do it. Seriously, YAML overreaches for what I want. > > XML can certainly be made readable by humans. ?It's hard to make it > > writeable by (average) humans just using a regular text editor, > > I do it all the time; it's a bit dreary but not difficult. ?And there is > absolutely no way to get anything done in this field anymore without > dealing with XML from time to time. ?So given that we all have some > experience using it, it's sensible to stick with it. But people "in this field" are not really my target audience. Well, I mean people in this field are the target audience for the library, but not for the writing of the actual text files. > ReST is another abomination that should never have gotten off the > ground. ?It is one of the reasons I react so negatively to your > config format proposal. ?It just sounds like more of the same. Well, that clarifies a lot. I guess we'll just have to agree to disagree :-) Regards, Pat From alfps at start.no Mon Mar 1 16:16:59 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 22:16:59 +0100 Subject: How to crash CPython 3.1.1 in Windows XP Message-ID: How to crash CPython 3.1.1 in Windows XP: python -c "import os; os.spawnl( os.P_WAIT, 'blah' )" I reported this as a bug, Workaround: it seems that spawnl is happy with an absolute path as second arg, followed by a third arg which should be the name of the program (repeated). Cheers, - Alf From __peter__ at web.de Mon Mar 1 17:12:33 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Mar 2010 23:12:33 +0100 Subject: Class attributes / methods..... full Python script References: Message-ID: Gabor Urban wrote: > thanks for the ideas. Here you are the code. Not transcoded from Java > for I do not know Java enough.. > > I am scanning an XML file, and have a large ammount of logging. > > Any ideas are wellcome as before.... > > Thnx > > Code:> > packages.append(Package) Replace Package (the class) with package (an instance). > for i in xrange(oplines.length): > data.append(oplines[i]) Python lists don't have a length attribute. You can determine their length with len(oplines). To iterate over the items of a list you need not know the list's length: for line in oplines: data.append(line) which can be simplified to data.extend(oplines) Peter PS: Rrread the tutorial From emile at fenx.com Mon Mar 1 17:12:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Mar 2010 14:12:56 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7E76CFE6-DBEA-491C-B636-338D378672C4@semanchuk.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7E76CFE6-DBEA-491C-B636-338D378672C4@semanchuk.com> Message-ID: On 3/1/2010 1:02 PM Philip Semanchuk said... > * You had floppies? Bleddy luxury! We wrote our data on wood pulp we'd > chewed ourselves and dried into paper, using drops of our own blood to > represent 1s and 0s. You had left-over blood?!! Emile :) From python at mrabarnett.plus.com Mon Mar 1 17:31:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Mar 2010 22:31:02 +0000 Subject: Class attributes / methods..... full Python script In-Reply-To: References: Message-ID: <4B8C4026.3010907@mrabarnett.plus.com> Gabor Urban wrote: > Hi guys, > > thanks for the ideas. Here you are the code. Not transcoded from Java > for I do not know Java enough.. > > I am scanning an XML file, and have a large ammount of logging. > > Any ideas are wellcome as before.... > > Thnx > > Code:> > > #--------------------------------------------- > ## Generate CSV from OEP History XML > #--------------------------------------------- > > import sys > import os > from xml.dom.minidom import parse, parseString > import xml.dom > import logging > > versionStr = '0.01' > > class Item: > def __init__(self, pId, pChange, pComment): > self.ID = pId > self.Delta = pChange > self.Comment = pComment > > def PrintItem(self): > str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) > return str > > class Package: > def __init__(self, pSerial, pDate, pOwner, pSchema): > self.serial = pSerial > self.date = pDate > self.owner = pOwner > self.schema = pSchema > self.items = [] > > def insertItem(self, pItem): > self.items.append(pItem) > > def printPackage(self): > lines = [] > str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) > number = self.items.length If this is meant to get the length of self.items, then it won't work. It should be: number = len(self.items) > for idx in xrange(number): > line = '' What's the purpose of this line? You're not using 'line' before you assign to it again. > istr = self.items[idx].PrintItem() > line = str + ',' + istr > lines.append(line) > return lines > > def getItem(tracer, pkgItem, itemName): > retval = -1 > name = "" > found = 0 > str = "" > tracer.info('Function getItem entry, name = %s',itemName) > nItem = pkgItem.getElementsByTagName(itemName).item(0) > for node in pkgItem.childNodes: > if node.nodeType != xml.dom.Node.TEXT_NODE: > tracer.debug('Scanning node name = %s',node.nodeName) > if node.nodeName == itemName: > tracer.debug('Pkg %s found',itemName) > else: > tracer.warning('Pkg %s is not found',itemName) > continue > for entity in node.childNodes: > if entity.nodeType == xml.dom.Node.TEXT_NODE: > retval = entity.nodeValue > tracer.debug("Node value found %s",retval) > found = 1 > break > if found == 1: > break > tracer.debug('Function getItem returns %s',retval) > return retval > > logger = logging.getLogger('XmlHistory') > handler = logging.FileHandler("Xmlhistory.trc",'a') > ## handler = logging.StreamHandler(sys.stderr) > logger.addHandler(handler) > formatter = logging.Formatter("%(name)s %(asctime)s %(filename)s > %(lineno)d %(levelname)s %(message)s") > handler.setFormatter(formatter) > logger.setLevel(2) > > fileName = "history.xml" > output = 'history.csv' > logger.info('Xml history generator version %s',versionStr) > logger.info('Starting history generation on file:%s',fileName) > > packages = [] > data = [] > > ## Start XML processing > > dataSource = parse(fileName) > print dataSource.documentElement.tagName > listCsomag = dataSource.getElementsByTagName("csomag") > size = listCsomag.length > logger.debug('Number of packages = %d',size) > for idx in xrange(size): > attrib = "" > package = None > serial = 0 > date = "" > owner = "" > schema = "" > flag = False > logger.info('Parsing package id=%d',idx) > attrib = getItem(logger, listCsomag.item(idx),'sorszam') > if attrib <> "NUM" and attrib <> -1: > serial = int(attrib) > flag = True > logger.debug('Package serial set to %d',serial) > else: > logger.debug("Template package found.") > break > attrib = "" What's the purpose of this line? You're not using 'attrib' before you assign to it again. You're doing this repeatedly in the code. > attrib = getItem(logger,listCsomag.item(idx),"datum") > if attrib <> -1: > date = attrib > flag = flag and True Whether 'flag' is False or True, this line won't change it. You're also doing this repeatedly in the code. > logger.debug('Package date set to %s',date) > attrib = "" > attrib = getItem(logger,listCsomag.item(idx),"ki") > if attrib <> -1: > owner = attrib > flag = flag and True > logger.debug('Package owner set to %s',owner) > attrib = "" > attrib = getItem(logger,listCsomag.item(idx),"sema") > if attrib <> -1: > schema = attrib > flag = flag and True > logger.debug('Package schema set to %s',schema) > > if flag <> True: Clearer as: if not flag: or even clearer if you picked a better name than 'flag'. > logger.error('Package id=%d is inconsistent',idx) > break > else: > logger.info('Package id=%d is ok',idx) > > package = Package(serial,date,owner,schema) > > listItem = listCsomag.item(idx).getElementsByTagName("item") > itemSize = listItem.length > logger.debug('Number of items = %d',itemSize) > for num in xrange(itemSize): > flag = False > value = -1 > listId = 0 > change = "" > comment = "" > item = None > logger.info('Parsing item id = %d',num) > value = getItem(logger,listItem.item(num),"item_id") > if value <> -1: > listId = int(value) > flag = True > logger.debug('List id set to %d',listId) > value = "" > value = getItem(logger,listItem.item(num),"valtozas") > if value <> -1: > change = value > flag = flag and True > logger.debug('List change desc. set to "%s"',change) > value = "" > value = getItem(logger,listItem.item(num),"komment") > if value <> -1: > comment = value > flag = flag and True > logger.debug('List comment desc. set to "%s"',comment) > > if flag <> True: > logger.error('Item id = %d inconsistent',num) > break > else: > logger.info('Item id = %d is ok',num) > > item = Item(listId,change,comment) > package.insertItem(item) > > packages.append(Package) > The instance is 'package', the class is 'Package'. You're using the wrong one. > logger.info('Processing Xml file %s is done',fileName) > logger.info('Generating file %s is started',output) > > size = len(packages) > package = None > for index in xrange(size): > logger.info('PrettyPrinting package id=%d',index) > oplines = [] > oplines = packages[index].printPackage() > for i in xrange(oplines.length): The length of a list, string, etc, is given by 'len', eg. len(oplines). > data.append(oplines[i]) > > print data > From ben+python at benfinney.id.au Mon Mar 1 17:48:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 02 Mar 2010 09:48:47 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> Message-ID: <87eik3zmi8.fsf@benfinney.id.au> Andreas Waldenburger writes: > On Mon, 01 Mar 2010 18:42:17 +0100 Jean-Michel Pichavant > wrote: > > > Andreas Waldenburger wrote: > > [snip] > > > Back in the software world: Those guys write code that works. It > > > does what it's supposed to do. Why should we care where they put > > > their comments? > > > > > If you've bought the code and want to maintain it, you'd better make > > sure it's possible. > > > Fair enough, but we don't want to maintain it. Do you want it maintained beyond the span of your agreement with the current developers? Do you want to have free choice in who will maintain it over the period that you need it maintained? I understood ?want to maintain it? in Jean-Michel's message to include the possibility to get someone else to maintain it on your terms. > It's not our concern. Then I don't see what that problem is. -- \ ?To save the world requires faith and courage: faith in reason, | `\ and courage to proclaim what reason shows to be true.? | _o__) ?Bertrand Russell | Ben Finney From jon.sneyers at gmail.com Mon Mar 1 17:55:44 2010 From: jon.sneyers at gmail.com (Jon Sneyers) Date: 1 Mar 2010 14:55:44 -0800 Subject: Call for Participation: CHR Summer School Message-ID: <8331b2f8-c9b7-4d23-923a-06e52cd75e19@z35g2000yqd.googlegroups.com> - Call for Participation - First International Summer School on CHR: Programming and Reasoning with Rules and Constraints August 30 - September 3 2010 Leuven, Belgium Website: http://www.cs.kuleuven.be/~dtai/CHR/summerschool **************************************************************************** * EARLY REGISTRATION DISCOUNT: When registering (including payment) before * * March 31, the registration fee will be reduced by 20 euro! * * * * Additional early registration incentive: * * The first 7 registrants get a FREE copy of the book * * "Constraint Handling Rules - Current Research Topics" * **************************************************************************** The aim of the summer school is to familiarize the participants with state-of-the-art high-level declarative programming with rules and constraints as well as providing insights into the analysis of programs based on these concepts. The courses cover a wide range from theory to practice. The summer school will be based on the advanced high-level rule-based formalism and programming language Constraint Handling Rules (CHR) http://constraint-handling-rules.org/ Intended Audience: The summer school provides courses at various levels. It is open to anyone interested. It aims at Phd. students, but also post-docs, interested researchers and master students as well as interested parties from industry. Besides a working knowledge of English, there are no prerequisites. A basic knowledge of logic and Prolog that is usually covered in undergraduate classes could be helpful. Lectures and Courses: The programming language CHR will be introduced by several lecturers on the first day of the summer school. - Slim Abdennadher, GUC, Egypt Analysis of CHR Solvers - Henning Christiansen, U. Roskilde, Denmark Abduction and language processing with CHR - Thom Fruehwirth, University Ulm, Germany CHR - a common platform for rule-based approaches - Jon Sneyers, K.U.Leuven, Belgium Computability and Complexity of CHR - Peter Van Weert, K.U.Leuven, Belgium Implementation of CHR Systems A final evaluation for each course is possible through a final exam or project as determined by the instructor. The daily schedule admits laboratory, recitation or working group activities to be organized in addition to lectures. Registration: The registration fee for the School is 300 euro and includes teaching material with book, as well as accomodation and coffee breaks. Meals are not included. Attendance is limited to 20 students and will be allocated on a first-come- first-served basis. Without accommodation the registration fee is reduced to 200 euro. Location: Leuven is a lively student town in Belgium with a very high density of pubs offering hundreds of types of local beers. Organization: Thom Fruehwirth, University of Ulm, Germany Jon Sneyers, K.U. Leuven, Belgium Peter Van Weert, K.U. Leuven, Belgium -- Looking for an H-912 (container). From g.bogle at auckland.no.spam.ac.nz Mon Mar 1 18:04:02 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 02 Mar 2010 12:04:02 +1300 Subject: PyQt4.7 and PyQwt5.2.0 References: Message-ID: Gib Bogle wrote: > I installed the latest PyQt (4.7-1), then PyQwt 5.2.0, which was built > with PyQt4.5.4. This line > > import PyQt4.Qwt5 as Qwt > > fails to load the DLL. Could this be the result of not using PyQt4 4.5.4? I guess I can answer my own question. As far as I can determine, PyQwt 5.2.0 needs PyQt 4.5.4 to work. From rhodri at wildebst.demon.co.uk Mon Mar 1 18:06:27 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 01 Mar 2010 23:06:27 -0000 Subject: Variable definition References: <4B885A0B.9040705@netplus.ch> <4B887224.2080805@optimum.net> Message-ID: On Mon, 01 Mar 2010 18:07:17 -0000, Raphael Mayoraz wrote: > Thanks for your answer. > However, your solution changes the key name in the dictionary. > That's not what I want I need to do. What I want is to define a new > variable which name is define as a string: 'myPrefx' + key. In the > example > I give, I would get 3 variables: > myPrefixred = a > myPrefixgreen = b > myPrefixblue = c I repeat my previous question: why? What problem do you think this will solve that will not be more easily solved working with the language rather than against it? -- Rhodri James *-* Wildebeeste Herder to the Masses From max at alcyone.com Mon Mar 1 18:30:55 2010 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Mar 2010 15:30:55 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: Daniel Fetchinson wrote: >>> it is my goal (which I may or may not be smart enough to reach) to >>> write a module that anybody would want to use; >> But you are working on a solution in search of a problem. The really >> smart thing to do would be pick something more useful to work on. We >> don't need another configuration language. I can't even say "yet >> another" because there's already a "yet another" called yaml. > > And in case you are new here let me assure you that Paul is saying > this with his full intention of being helpful to you. I also would > think that working on such a project might be fun and educational for > you but completely useless if you have users other than yourself in > mind. Again, I'm trying to be helpful here, so you can focus on a > project that is both fun/educational for you and also potentially > useful for others. This RSON business is not one of them. Agreed. Even YAML's acronym indicates that it is already a bridge too far; we don't need more. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis It's better to be quotable than to be honest. -- Tom Stoppard From max at alcyone.com Mon Mar 1 18:33:08 2010 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Mar 2010 15:33:08 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> Message-ID: Patrick Maupin wrote: > On Mar 1, 12:03 pm, Paul Rubin wrote: > >> But you are working on a solution in search of a problem. The really >> smart thing to do would be pick something more useful to work on. We >> don't need another configuration language. I can't even say "yet >> another" because there's already a "yet another" called yaml. > > The only "in search of" here is that, instead of working on a point > solution for my particular problem, I am "in search of" a solution > that is a bit more elegant and general, and that might help solve > other people's problems too. If you are not one of those that has > this sort of problem at this point in time, then feel free to kill- > file this thread. Psst. That you're allowed to present the idea that you think is good doesn't mean that other people aren't allowed to respond and point out that in their opinion it's not such a good idea. You don't own this or any other thread. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis It's better to be quotable than to be honest. -- Tom Stoppard From max at alcyone.com Mon Mar 1 18:57:42 2010 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Mar 2010 15:57:42 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: Patrick Maupin wrote: > On Feb 28, 9:18 pm, Steven D'Aprano > Wait a minute... if JSON is too > hard to edit, and RSON is a *superset* of >> JSON, that means by definition every JSON file is also a valid RSON file. >> Since JSON is too hard to manually edit, so is RSON. > > Well, Python is essentially a superset of JSON, with string escape > handling being ever so slightly different, and using True instead of > true, False instead of false, and None instead of null. YMMV, but I > find it possible, even probable, to write Python that is far easier to > edit than JSON, and in fact, I have used Python for configuration > files that are only to be edited by programmers or other technical > types. This not only seriously stretching the meaning of the term "superset" (as Python is most definitely not even remotely a superset of JSON), but still doesn't address the question. Is RSON and _actual_ superset of JSON, or are you just misusing the term there, as well? If it is, then your rationale for not using JSON makes no sense if you're making a new format that's merely a superset of it. Obviously JSON can't be that unreadable if you're _extending_ it to make your own "more readable" format. If JSON is unreadable, so must be RSON. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis It's better to be quotable than to be honest. -- Tom Stoppard From massimodipierro71 at gmail.com Mon Mar 1 19:20:06 2010 From: massimodipierro71 at gmail.com (mdipierro) Date: Mon, 1 Mar 2010 16:20:06 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> Message-ID: <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> On Mar 1, 6:32?am, simn_stv wrote: ... > > > You have to follow some tricks: > > > 1) have the web server serve static pages directly and set the pragma > > cache expire to one month > > 2) cache all pages that do not have forms for at least few minutes > > 3) avoid database joins > > but this would probably be to the detriment of my database design, > which is a no-no as far as im concerned. The way the tables would be > structured requires 'joins' when querying the db; or could you > elaborate a little?? Joins are the bottle neck of most web app that relay on relational databases. That is why non-relational databases such as Google App Engine, CouchDB, MongoDB do not even support Joins. You have to try to minimize joins as much as possible by using tricks such as de- normalization and caching. > > 4) use a server with at least 512KB Ram. > > hmmm...!, still thinking about what you mean by this statement also. I meant 512MB. The point is you need a lot of ram because you want to run multiple python instances, cache in ram as much as possible and also allow the database to buffer in ram as much as possible. You will see Ram usage tends to spike when you have lots of concurrent requests. From misceverything at gmail.com Mon Mar 1 19:41:57 2010 From: misceverything at gmail.com (T) Date: Mon, 1 Mar 2010 16:41:57 -0800 (PST) Subject: Py2exe - Bad File Descriptor References: <0c04902d-03e8-4b0e-8dd3-3bbdf7ea09b6@z11g2000yqz.googlegroups.com> Message-ID: On Feb 28, 10:00?pm, Dennis Lee Bieber wrote: > On Sun, 28 Feb 2010 13:22:19 -0800 (PST), T > declaimed the following in gmane.comp.python.general: > > > Sorry for the lack of code - yes, it does try to write to the > > console. ?From what I'm finding, this error may be due to the fact > > that there is no "console" to write to when I'm logged off. ?However, > > I would like to be able to print to screen if I run the EXE in debug > > mode (i.e. "myservice.exe debug"). ?Do you know of any way around > > this? ?Also, I need to get the output generated from an external EXE - > > will subprocess.Popen cause problems if I use stdout=PIPE? ?Thanks for > > your help! > > ? ? ? ? True services typically don't have interactive (console) type I/O... > What is more likely to work is to have an open socket waiting for > connections, and the use of a separate user-space client that connects > to the socket... > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ?HTTP://wlfraed.home.netcom.com/ So how would that work..would the program buffer all the "print" output, then send it to the client when it connects? Do you happen to know of any available code that utilizes this method, or something similar? Thanks for your help. From pmaupin at gmail.com Mon Mar 1 19:45:07 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 16:45:07 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> Message-ID: <2e244da6-7fdc-48a2-acd4-c8861c5d7c2f@q16g2000yqq.googlegroups.com> On Mar 1, 5:33?pm, Erik Max Francis wrote: > Psst. ?That you're allowed to present the idea that you think is good > doesn't mean that other people aren't allowed to respond and point out > that in their opinion it's not such a good idea. ?You don't own this or > any other thread. Absolutely, but I still do (and will always) express a clear preference for opinions that have at least a modicum of reasoning behind them. Regards, Pat From pmaupin at gmail.com Mon Mar 1 19:56:46 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 16:56:46 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: Message-ID: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> On Mar 1, 5:57?pm, Erik Max Francis wrote: > Patrick Maupin wrote: > This not only seriously stretching the meaning of the term "superset" > (as Python is most definitely not even remotely a superset of JSON), but Well, you are entitled to that opinion, but seriously, if I take valid JSON, replace unquoted true with True, unquoted false with False, replace unquoted null with None, and take the quoted strings and replace occurrences of \uXXXX with the appropriate unicode, then I do, in fact, have valid Python. But don't take my word for it -- try it out! But if you really want to be pedantic about it, JavaScript (rather than Python) is, in fact a superset of JSON, and, despite the disparagement JavaScript receives, in my opinion, it is possible to write much better looking JavaScript than JSON for many tasks. YAML, also, is a superset of JSON, and IMO, it is possible to write much better looking YAML than JSON. > still doesn't address the question. ?Is RSON and _actual_ superset of > JSON, or are you just misusing the term there, as well? Yes, the RSON definition, in fact, a superset of JSON, just like the YAML definition. But RSON is a much smaller grammar than YAML. ?If it is, then > your rationale for not using JSON makes no sense if you're making a new > format that's merely a superset of it. ?Obviously JSON can't be that > unreadable if you're _extending_ it to make your own "more readable" > format. ?If JSON is unreadable, so must be RSON. Well, we'll have to agree to disagree here. Bearing in mind that the definition of "unreadable" depends on the target application and user, obviously, it will be *possible* to write unreadable RSON, just as it is *possible* to write unreadable JavaScript or Python or YAML, but it will be *possible* to write better looking RSON than is possible to achieve with JSON, just as it is *possible* to write better looking JavaScript or YAML or Python than it is *possible* to achieve with pure JSON. Best regards, Pat From jjposner at optimum.net Mon Mar 1 20:07:37 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 01 Mar 2010 20:07:37 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8c2a34$0$10470$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> Message-ID: On 3/1/2010 2:59 PM, Bruno Desthuilliers wrote: > Answer here: > > http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 > > I really have to put this in the wiki :-/ Bruno, I performed a light copy-edit of your writeup and put in some reStructuredText (reST) markup. The result is at: http://cl1p.net/bruno_0301.rst/ The only sentence that I think needs work is: Having access to itself (of course), the instance (if there's one) and the class, it's easy for it to wrap all this into a **method** object. Maybe this? With the instance object (if any) and class object available, it's easy to create a method object that wraps the function object. Begging pardon for my presumptuousness, John From xi at gamma.dn.ua Mon Mar 1 20:07:39 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 20:07:39 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: <4B8C64DB.3010105@gamma.dn.ua> Erik Max Francis wrote: > Daniel Fetchinson wrote: >>>> it is my goal (which I may or may not be smart enough to reach) to >>>> write a module that anybody would want to use; >>> But you are working on a solution in search of a problem. The really >>> smart thing to do would be pick something more useful to work on. We >>> don't need another configuration language. I can't even say "yet >>> another" because there's already a "yet another" called yaml. >> >> And in case you are new here let me assure you that Paul is saying >> this with his full intention of being helpful to you. I also would >> think that working on such a project might be fun and educational for >> you but completely useless if you have users other than yourself in >> mind. Again, I'm trying to be helpful here, so you can focus on a >> project that is both fun/educational for you and also potentially >> useful for others. This RSON business is not one of them. > > Agreed. Even YAML's acronym indicates that it is already a bridge too > far; we don't need more. > Note that YA in the acronym doesn't mean Yet Another, YAML = YAML Ain't Markup Language. Thanks, Kirill From roy at panix.com Mon Mar 1 20:20:05 2010 From: roy at panix.com (Roy Smith) Date: Mon, 01 Mar 2010 20:20:05 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> Message-ID: In article , MRAB wrote: > Ah, yes, Star Trek (the original series). > > If they transported down to a planet and there was a man in a red shirt > who you'd never seen before, he'd be the one to die! :-) Of course. Everybody knows there's an endless supply of red shirts. From eman_no1 at yahoo.com Mon Mar 1 20:47:44 2010 From: eman_no1 at yahoo.com (Eman) Date: Mon, 1 Mar 2010 17:47:44 -0800 (PST) Subject: How to use python to register a service (an existing .exe file) References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <881a0df5-872f-4c19-a989-fe3ffe775655@k2g2000pro.googlegroups.com> On Feb 15, 4:10?pm, News123 wrote: > Hi, > > Is there a python way to register new windows services. > > I am aware of the > instsrv.exe program, which can be used to install services. > I could use subprocess.Popen to call > > instsrv.exe "service_name" program.exe > > but wondered, whether there's already an existing function. > > Thans in advance and bye > > N Try my favorite 3rd pary tools maker, Chilkatsoft.com. http://www.chilkatsoft.com/refdoc/pythonCkServiceRef.html Eman_No1 From xi at gamma.dn.ua Mon Mar 1 21:02:34 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 21:02:34 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: <4B8C71BA.9060106@gamma.dn.ua> Patrick Maupin wrote: > All: > > Finding .ini configuration files too limiting, JSON and XML to hard to > manually edit, and YAML too complex to parse quickly, I have started > work on a new configuration file parser. I'd like to note that with the optional libyaml bindings, the PyYAML parser is pretty fast. > I call the new format RSON (for "Readable Serial Object Notation"), > and it is designed to be a superset of JSON. > > I would love for it to be considered valuable enough to be a part of > the standard library, but even if that does not come to pass, I would > be very interested in feedback to help me polish the specification, > and then possibly help for implementation and testing. > > The documentation is in rst PEP form, at: > > http://rson.googlecode.com/svn/trunk/doc/draftpep.txt === cut === Because YAML does allow for highly readable configuration files, it is tempting to overlook its other flaws for the task. But a fully (or almost) compliant parser has to understand the whole YAML specification, and this is apparently expensive. Running the rst2pdf testsuite, without sphinx or most of the other optional packages, in "fast" mode (preloading all the modules, and then forking for every test) generates 161 smallish PDF files, totaling around 2.5 MB. On one test system this process takes 22 seconds. Disabling the _json C scanner and reading the configuration files using the json pure Python implementation adds about 0.3 seconds to the 22 seconds. But using pyyaml v. 3.09 instead of json adds 33 seconds to the 22 second process! It might seem that this is an edge case, but it makes it unacceptable to use YAML for this sort of testing, and taking 200 ms to read in 1000 lines of simple JSON will be unacceptable in many other application domains as well. === cut === I'd question your testing methodology. From your description, it looks like the _json speedup never was enabled. Also PyYAML provides optional bindings to libyaml, which makes parsing and emitting yaml much faster. In my tests, it parses a 10Mb file in 3 sec. === cut === RSON semantics are based on JSON. Like JSON, an RSON document represents either a single scalar object, or a DAG (Directed Acyclic Graph), which may contain only a few simple data types. === cut === JSON doesn't represent a DAG, at least, not an arbitrary DAG since each node in the document has no more than one parent. It would be more accurate to say that that it represents a tree-like structure. === cut === The YAML syntax for supporting back-references was considered and deemed unsatisfactory. A human user who wants to put identical information in a "ship to" and "bill to" address is much more likely to use cut and paste than he is to understand and use backreferences, so the additional overhead of supporting more complex document structures is unwarranted. The concept of a "merge" in YAML, where two sub-trees of data can be merged together (similar to a recursive Python dictionary update) is quite useful, though, and will be copied. This does not alter the outcome that parsing a RSON file will result in a DAG, but does give more flexibility in the syntax that can be used to achieve a particular output DAG. === cut === This paragraph assumes the reader is familiar with intricate details of the YAML grammar and semantics. I bet most of your audience are completely lost here. === cut === Enhanced example:: key1/key2a key3a = Some random string key3b = 42 key1/key2a key3c 1 2 {} key4a = anything key4b = something else [] a b c 3 4 key1/key2b = [1, 2, 3, 4] key5 = "" This is a multi-line string. It is dedented to the farthest left column that is indented from the line containing "". key6 = [""] This is an array of strings, one per line. Each string is dedented appropriately. === cut === Frankly, this is an example that only a mother could love. I'd suggest you to add some real-world examples, make sure they look nice and put them to the introductory part of the document. Examples is how the format will be evaluated by the readers, and yours don't stand a chance. Seriously, the only reason YAML enjoys its moderate popularity despite its overcomplicated grammar, chronic lack of manpower and deficient implementations is because it's so cute. Disclaimer: I'm the author of PyYAML and libyaml. Thanks, Kirill From axpbgj at terra.com Mon Mar 1 21:12:02 2010 From: axpbgj at terra.com (floatron) Date: 01 Mar 2010 23:12:02 -0300 Subject: ze Basta de cloro en su piscina Message-ID: <20100301231202.1A5E8DBF4FBCD983@terra.com> An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Mon Mar 1 21:19:34 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 20:19:34 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4B8C71BA.9060106@gamma.dn.ua> References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: Kirill: Thank you for your constructive criticism. This is the gem that made it worthwhile to post my document. I think all of your points are spot-on, and I will be fixing the documentation. I can well believe that the C implementation of YAML is much faster than the Python one, but I am aiming for something that will be reasonably quick in pure Python. I will double-check the JSON C test results, but something I probably did not make clear is that the 22 seconds is not spent parsing -- that is for the entire test, which involves reading restructured text and generating some 160 separate PDF files. Best regards, Pat On Mon, Mar 1, 2010 at 8:02 PM, Kirill Simonov wrote: > Patrick Maupin wrote: >> >> All: >> >> Finding .ini configuration files too limiting, JSON and XML to hard to >> manually edit, and YAML too complex to parse quickly, I have started >> work on a new configuration file parser. > > I'd like to note that with the optional libyaml bindings, the PyYAML parser > is pretty fast. > >> I call the new format RSON (for "Readable Serial Object Notation"), >> and it is designed to be a superset of JSON. >> >> I would love for it to be considered valuable enough to be a part of >> the standard library, but even if that does not come to pass, I would >> be very interested in feedback to help me polish the specification, >> and then possibly help for implementation and testing. >> >> The documentation is in rst PEP form, at: >> >> http://rson.googlecode.com/svn/trunk/doc/draftpep.txt > > === cut === > Because YAML does allow for highly readable configuration files, it > is tempting to overlook its other flaws for the task. ?But a fully > (or almost) compliant parser has to understand the whole YAML > specification, and this is apparently expensive. ?Running the rst2pdf > testsuite, without sphinx or most of the other optional packages, in > "fast" mode (preloading all the modules, and then forking for every > test) generates 161 smallish PDF files, totaling around 2.5 MB. ?On > one test system this process takes 22 seconds. ?Disabling the _json C > scanner and reading the configuration files using the json pure Python > implementation adds about 0.3 seconds to the 22 seconds. ?But using > pyyaml v. 3.09 instead of json adds 33 seconds to the 22 second process! > It might seem that this is an edge case, but it makes it unacceptable to > use YAML for this sort of testing, and taking 200 ms to read in 1000 > lines of simple JSON will be unacceptable in many other application > domains as well. > === cut === > > I'd question your testing methodology. ?From your description, it looks like > the _json speedup never was enabled. ?Also PyYAML provides optional bindings > to libyaml, which makes parsing and emitting yaml much faster. ?In my tests, > it parses a 10Mb file in 3 sec. > > === cut === > RSON semantics are based on JSON. ?Like JSON, an RSON document represents > either a single scalar object, or a DAG (Directed Acyclic Graph), which > may contain only a few simple data types. > === cut === > > JSON doesn't represent a DAG, at least, not an arbitrary DAG since each node > in the document has no more than one parent. ?It would be more accurate to > say that that it represents a tree-like structure. > > === cut === > The YAML syntax for supporting back-references was considered and deemed > unsatisfactory. A human user who wants to put identical information in a > "ship to" and "bill to" address is much more likely to use cut and paste > than he is to understand and use backreferences, so the additional overhead > of supporting more complex document structures is unwarranted. > > The concept of a "merge" in YAML, where two sub-trees of data can be > merged together (similar to a recursive Python dictionary update) > is quite useful, though, and will be copied. ?This does not alter the > outcome that parsing a RSON file will result in a DAG, but does give > more flexibility in the syntax that can be used to achieve a particular > output DAG. > === cut === > > This paragraph assumes the reader is familiar with intricate details of the > YAML grammar and semantics. ?I bet most of your audience are completely lost > here. > > === cut === > Enhanced example:: > > ? ?key1/key2a > ? ? ? ?key3a = Some random string > ? ? ? ?key3b = 42 > ? ?key1/key2a > ? ? ? ?key3c > ? ? ? ? ? ?1 > ? ? ? ? ? ?2 > ? ? ? ? ? ?{} > ? ? ? ? ? ? ? ?key4a = anything > ? ? ? ? ? ? ? ?key4b = something else > ? ? ? ? ? ?[] > ? ? ? ? ? ? ? ?a > ? ? ? ? ? ? ? ?b > ? ? ? ? ? ? ? ?c > ? ? ? ? ? ?3 > ? ? ? ? ? ?4 > ? ?key1/key2b = [1, 2, 3, 4] > ? ?key5 = "" > ? ? ? This is a multi-line string. ?It is > ? ? ? ? ?dedented to the farthest left > ? ? ? ? ?column that is indented from > ? ? ? ? ?the line containing "". > ? ?key6 = [""] > ? ? ? This is an array of strings, one per line. > ? ? ? Each string is dedented appropriately. > === cut === > > Frankly, this is an example that only a mother could love. ?I'd suggest you > to add some real-world examples, make sure they look nice and put them to > the introductory part of the document. ?Examples is how the format will be > evaluated by the readers, and yours don't stand a chance. > > Seriously, the only reason YAML enjoys its moderate popularity despite its > overcomplicated grammar, chronic lack of manpower and deficient > implementations is because it's so cute. > > > > Disclaimer: I'm the author of PyYAML and libyaml. > > Thanks, > Kirill > From pmaupin at gmail.com Mon Mar 1 21:21:37 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 20:21:37 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4B8C71BA.9060106@gamma.dn.ua> References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: On Mon, Mar 1, 2010 at 8:02 PM, Kirill Simonov wrote: BTW, congratulations on slogging through the YAML grammar to generate such a good working C library! That must have been a tremendous effort. Regards, Pat From nipukumar at gmail.com Mon Mar 1 21:39:54 2010 From: nipukumar at gmail.com (Niranjan Kumar Das) Date: Mon, 1 Mar 2010 18:39:54 -0800 Subject: New User Message-ID: Hello Group, I am starting to programme in python 1st time. Just thought i will ask the group members about some well known useful books. I am looking for books at two level. a) For beginers b) For Advaced user Appreciate your help and suggestion in the matter. Thanks, Niranjan -------------- next part -------------- An HTML attachment was scrubbed... URL: From xi at gamma.dn.ua Mon Mar 1 21:54:51 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 21:54:51 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: <4B8C7DFB.8000800@gamma.dn.ua> Patrick Maupin wrote: > Kirill: > > Thank you for your constructive criticism. This is the gem that made > it worthwhile to post my document. I think all of your points are > spot-on, and I will be fixing the documentation. You are welcome. Despite what others have been saying, I don't think this area is closed to innovations. > I can well believe that the C implementation of YAML is much faster > than the Python one, but I am aiming for something that will be > reasonably quick in pure Python. I will double-check the JSON C test > results, but something I probably did not make clear is that the 22 > seconds is not spent parsing -- that is for the entire test, which > involves reading restructured text and generating some 160 separate > PDF files. Yes, this makes more sense. It's quite possible that the pure-Python PyYAML parser is much slower than the pure-Python JSON parser. At the same time, semantically meaningful whitespaces will likely hinder the pure-Python performance. To make it fast, you'll need to convert the inner loops of the parser to regexps, and it is hard to support variable-length indentation with static regular expressions. Thanks, Kirill From xi at gamma.dn.ua Mon Mar 1 22:03:22 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 22:03:22 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: <4B8C7FFA.4080909@gamma.dn.ua> Patrick Maupin wrote: > On Mon, Mar 1, 2010 at 8:02 PM, Kirill Simonov wrote: > > BTW, congratulations on slogging through the YAML grammar to generate > such a good working C library! > > That must have been a tremendous effort. The trick was to completely ignore the grammar described in the specification. In fact, the syntax of YAML is pretty close the Python syntax and, with some effort, the Python scanner and parser could be adapted to parsing YAML. Once I realized it, I got a working parser in a week or so. Thanks, Kirill From anand.shashwat at gmail.com Mon Mar 1 22:35:16 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 2 Mar 2010 09:05:16 +0530 Subject: New User In-Reply-To: References: Message-ID: for beginners : http://openbookproject.net/thinkcs/python/english2e/index.html python cookbook - 2 by alex martelli is fantastic if you have your basics cleared. On Tue, Mar 2, 2010 at 8:09 AM, Niranjan Kumar Das wrote: > Hello Group, > I am starting to programme in python 1st time. Just thought i will ask the > group members about some well known useful books. I am looking for books at > two level. > > a) For beginers > b) For Advaced user > > Appreciate your help and suggestion in the matter. > > Thanks, > Niranjan > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Mar 1 23:27:41 2010 From: roy at panix.com (Roy Smith) Date: Mon, 1 Mar 2010 20:27:41 -0800 (PST) Subject: Adding to a module's __dict__? Message-ID: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> >From inside a module, I want to add a key-value pair to the module's __dict__. I know I can just do: FOO = 'bar' at the module top-level, but I've got 'FOO' as a string and what I really need to do is __dict__['Foo'] = 'bar' When I do that, I get "NameError: name '__dict__' is not defined". Is it possible to do what I'm trying to do? From tjreedy at udel.edu Mon Mar 1 23:55:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Mar 2010 23:55:25 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 3/1/2010 7:56 PM, Patrick Maupin wrote: > On Mar 1, 5:57 pm, Erik Max Francis wrote: >> Patrick Maupin wrote: >> This not only seriously stretching the meaning of the term "superset" >> (as Python is most definitely not even remotely a superset of JSON), but > > Well, you are entitled to that opinion, but seriously, if I take valid > JSON, replace unquoted true with True, unquoted false with False, > replace unquoted null with None, and take the quoted strings and > replace occurrences of \uXXXX with the appropriate unicode, then I do, > in fact, have valid Python. But don't take my word for it -- try it > out! To me this is so strained that I do not see why why you are arguing the point. So what? The resulting Python 'program' will be equivalent, I believe, to 'pass'. Ie, construct objects and then discard them with no computation or output. I suggest dropping this red-herring distraction. > But if you really want to be pedantic about it, JavaScript (rather > than Python) is, in fact a superset of JSON, and, despite the > disparagement JavaScript receives, in my opinion, it is possible to > write much better looking JavaScript than JSON for many tasks. > > YAML, also, is a superset of JSON, and IMO, it is possible to write > much better looking YAML than JSON. I agree that adding a bit of syntax to something can sometimes make it easier to write readable text. This is hardly a new idea and should not be controversial. That is why people developed 'macro assembley' as a superset of 'assembly' languages and why, for instance, Python added the 'with' statement. I read your proposal. I have not needed config files and have never written json or yaml and so cannot really evaluate your proposal for something 'in between'. It does seem plausible that it could be useful. While using the PEP format is great, calling your currently vaperware module proposal a 'standards track' PEP is somewhat off-putting and confusing. If Guido rejected it, would you simply drop the idea? If not, if you would continue it as a third-party module that would eventually be released and announced on PyPI, I seriously suggest renaming it to what it is. Terry Jan Reedy From clp2 at rebertia.com Tue Mar 2 00:38:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Mar 2010 21:38:34 -0800 Subject: Adding to a module's __dict__? In-Reply-To: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <50697b2c1003012138k1a0083d0r3fc12fdfe5bc5857@mail.gmail.com> On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: > >From inside a module, I want to add a key-value pair to the module's > __dict__. ?I know I can just do: > > FOO = 'bar' > > at the module top-level, but I've got 'FOO' as a string and what I > really need to do is > > __dict__['Foo'] = 'bar' > > When I do that, I get "NameError: name '__dict__' is not defined". ?Is > it possible to do what I'm trying to do? Yes; just modify the dict returned by the globals() built-in function instead. It's usually not wise to do this and is better to use a separate dict instead, but I'll assume you know what you're doing and have good reasons to disregard the standard advice due to your use-case. Cheers, Chris -- One should avoid using the Big Hammer unnecessarily, but sometimes you really do need it and it's nice that it's available for such cases. http://blog.rebertia.com From narkewoody at gmail.com Tue Mar 2 00:48:33 2010 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 2 Mar 2010 13:48:33 +0800 Subject: How to find an COM object in using of pywin32 Message-ID: Hi, I want to interactive with an OLE application with pywin32. The problem is I get totally no idea how to find the object in OLEView and how to figure out it's interface. With pywin32's example, I even don't understand that in the below statement, win32com.client.Dispatch('Excel.Application') that where the name 'Excel.Application' comes from? In OLEView (Microsoft's COM brower), I cannot find this name. Could you give me any help? Thanks -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke public key at http://subkeys.pgp.net:11371 (narkewoody at gmail.com) From vaidehi.pawar at yahoo.co.in Tue Mar 2 01:50:05 2010 From: vaidehi.pawar at yahoo.co.in (Vaidehi Pawar) Date: Tue, 2 Mar 2010 12:20:05 +0530 (IST) Subject: No subject Message-ID: <745414.12322.qm@web95110.mail.in2.yahoo.com> http://adimteknikhirdavat.com/James.html The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/ From darcy at druid.net Tue Mar 2 01:58:13 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Mar 2010 01:58:13 -0500 Subject: taking python enterprise level?... In-Reply-To: <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> Message-ID: <20100302015813.5397655e.darcy@druid.net> On Mon, 1 Mar 2010 16:20:06 -0800 (PST) mdipierro wrote: > Joins are the bottle neck of most web app that relay on relational > databases. That is why non-relational databases such as Google App > Engine, CouchDB, MongoDB do not even support Joins. You have to try to > minimize joins as much as possible by using tricks such as de- > normalization and caching. I keep seeing this statement but nothing to back it up. I have created many apps that run on Python with a PostgreSQL database with a fully normalized schema and I can assure you that database joins were never my problem unless I made a badly constructed query or left off a critical index. > I meant 512MB. The point is you need a lot of ram because you want to > run multiple python instances, cache in ram as much as possible and > also allow the database to buffer in ram as much as possible. You will > see Ram usage tends to spike when you have lots of concurrent > requests. Put as much memory as you can afford/fit into your database server. It's the cheapest performance boost you can get. If you have a serious application put at least 4GB into your dedicated database server. Swapping is your enemy. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From arnodel at googlemail.com Tue Mar 2 02:09:24 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 02 Mar 2010 07:09:24 +0000 Subject: Draft PEP on RSON configuration file format References: Message-ID: Erik Max Francis writes: > Patrick Maupin wrote: >> On Feb 28, 9:18 pm, Steven D'Aprano > Wait a minute... if JSON is too >> hard to edit, and RSON is a *superset* of >>> JSON, that means by definition every JSON file is also a valid RSON file. >>> Since JSON is too hard to manually edit, so is RSON. >> >> Well, Python is essentially a superset of JSON, with string escape >> handling being ever so slightly different, and using True instead of >> true, False instead of false, and None instead of null. YMMV, but I >> find it possible, even probable, to write Python that is far easier to >> edit than JSON, and in fact, I have used Python for configuration >> files that are only to be edited by programmers or other technical >> types. > > This not only seriously stretching the meaning of the term "superset" > (as Python is most definitely not even remotely a superset of JSON), > but still doesn't address the question. Is RSON and _actual_ superset > of JSON, or are you just misusing the term there, as well? If it is, > then your rationale for not using JSON makes no sense if you're making > a new format that's merely a superset of it. Obviously JSON can't be > that unreadable if you're _extending_ it to make your own "more > readable" format. If JSON is unreadable, so must be RSON. Your argument is utterly speculative as you are making clear you haven't read the OP's proposal. -- Arnaud From techupdater.admin at gmail.com Tue Mar 2 02:58:01 2010 From: techupdater.admin at gmail.com (Rishabh Verma) Date: Mon, 1 Mar 2010 23:58:01 -0800 (PST) Subject: OSSCamp Chandigarh April 2010 - Open Source Is The Future Message-ID: <9ca0e032-94d2-47f0-8f88-e8113f9ad795@z10g2000prh.googlegroups.com> Hello All, OSSCamp is again being organized in Chandigarh on April 10, 2010. This is another step ahead to foster the open source community in the city beautiful. This event is a purely community organized event by some of the open source evangelists of Chandigarh and it would be great if you guys join us to make this event a great success. At a Camp, we love to cross-talk, huddle together, raise some noise, celebrate technology, argue over the coolest OS, fight on our fav programming languages, discuss stuff, and what not! OSScamp Chandigarh April 2010 April 10, 2009 Venue: To Be Decided Time: 10AM - 6PM You can register for the event at : http://chd.osscamp.in/ Follow Us on Twitter : http://twitter.com/osscamp Facebook Event Page : http://www.facebook.com/event.php?eid=247304090115&ref=ts From alfps at start.no Tue Mar 2 03:42:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 09:42:46 +0100 Subject: How to find an COM object in using of pywin32 In-Reply-To: References: Message-ID: * Steven Woody: > Hi, > > I want to interactive with an OLE application with pywin32. The > problem is I get totally no idea how to find the object in OLEView and > how to figure out it's interface. > > With pywin32's example, I even don't understand that in the below statement, > > win32com.client.Dispatch('Excel.Application') > > that where the name 'Excel.Application' comes from? In OLEView > (Microsoft's COM brower), I cannot find this name. It's a "programmatic identifier" a.k.a. "progid". It identifies a COM class and it's used as a readable but more name-collision-prone alternative to the 128-bit UUID. You can find the programmatic identifiers in the Windows registry (use e.g. regedit); often they're not documented. Cheers, - Alf From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 2 03:57:52 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 02 Mar 2010 09:57:52 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> Message-ID: <4b8cd310$0$4604$426a34cc@news.free.fr> John Posner a ?crit : > On 3/1/2010 2:59 PM, Bruno Desthuilliers wrote: > >> Answer here: >> >> http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 >> >> >> I really have to put this in the wiki :-/ > > > Bruno, I performed a light copy-edit of your writeup and put in some > reStructuredText (reST) markup. The result is at: > > http://cl1p.net/bruno_0301.rst/ Cool. > > The only sentence that I think needs work is: > > Having access to itself (of course), the > instance (if there's one) and the class, it's easy for it > to wrap all this into a **method** object. > > Maybe this? > > With the instance object (if any) and class object available, > it's easy to create a method object that wraps the function object. That's perfect. But there's also a typo to fix in the Python implementation of the Method object: in the call method, it should inject self.im_self as first arg, not self.im_func. This had been spotted by someone named John Posner, IIRC !-) > > Begging pardon for my presumptuousness, Begging pardon for my laziness :-/ From groups_ads12 at yahoo.com Tue Mar 2 04:43:53 2010 From: groups_ads12 at yahoo.com (groups_ads12) Date: Tue, 02 Mar 2010 09:43:53 -0000 Subject: learn ajax Message-ID: ajax.learn.net.in afc ajax ajax ajax and php ajax and php building responsive web applications ajax application ajax applications ajax asp ajax c# ajax code ajax company ajax control ajax control toolkit ajax controls ajax data grid ajax design ajax design patterns ajax developer ajax developers ajax development ajax drag and drop ajax dropdown ajax example ajax examples ajax expert ajax fc ajax for web application developers ajax form tutorial ajax forms ajax forum ajax framework ajax frameworks ajax grid ajax grid control ajax http ajax jsp ajax libraries ajax library ajax net ajax net tutorial ajax photo ajax photo gallery ajax php ajax portal ajax program ajax programmer ajax programmers ajax programming ajax rails ajax request ajax sample ajax samples ajax script ajax scripts ajax soccer ajax soccer club ajax software ajax support ajax technology ajax test ajax tool ajax toolkit ajax toolkits ajax tools ajax training ajax training sessions ajax tutorial ajax tutorials ajax web ajax web 2.0 ajax web application ajax web applications ajax web design ajax web development ajax web hosting ajax web programming ajax webmail ajax website ajax windows ajax with php ajax xml ajax xmlhttp ajax xmlhttprequest asp.net ajax atlas ajax beginning ajax with php from novice to professional build your own ajax web applications coldfusion ajax dhtml ajax dojo ajax google ajax api jsf ajax jsf and ajax learn ajax microsoft ajax prototype ajax prototype ajax request prototype ajax tutorial prototype.js ajax struts ajax using ajax -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Mar 2 05:09:54 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Mar 2010 11:09:54 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> Message-ID: >> > But you are working on a solution in search of a problem. The really >> > smart thing to do would be pick something more useful to work on. We >> > don't need another configuration language. I can't even say "yet >> > another" because there's already a "yet another" called yaml. >> >> And in case you are new here let me assure you that Paul is saying >> this with his full intention of being helpful to you. I also would >> think that working on such a project might be fun and educational for >> you but completely useless if you have users other than yourself in >> mind. Again, I'm trying to be helpful here, so you can focus on a >> project that is both fun/educational for you and also potentially >> useful for others. This RSON business is not one of them. > > OK, but I am a bit unclear on what you and/or Paul are claiming. It > could be one of a number of things. For example: > > - There is a preexisting file format suitable for my needs, so I > should not invent another one. I suspect this to be true, if we mean the same thing by "configuration file format". Especially if RSON will be a superset of JSON. > - If I invent a file format suitable for my needs, it couldn't > possibly be general enough for anybody else. Quite possibly, the reason is that the already existing file formats have an ecosystem around them that make them attractive. Your file format will have to cope with this barrier to attract new users which I think will be very difficult, given the wide range of already existing formats, covering just about any use case. > - Even if it was general enough for somebody else, there would only be > two of them. See above. > I've been known to waste time (or be accused of wasting time) on > various endeavors, but I like to know exactly *why* it is perceived to > be a waste. Don't get me wrong, I also waste lot of time on hobby/fun/educational projects ("waste" in this case is only meant as "useless for others", not "useless for me") because it's, well, hobby and fun and educational :) It's just good to know if a given project is in this category or outside. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jeanmichel at sequans.com Tue Mar 2 05:29:33 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Mar 2010 11:29:33 +0100 Subject: Adding to a module's __dict__? In-Reply-To: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8CE88D.8030404@sequans.com> Roy Smith wrote: > >From inside a module, I want to add a key-value pair to the module's > __dict__. I know I can just do: > > FOO = 'bar' > > at the module top-level, but I've got 'FOO' as a string and what I > really need to do is > > __dict__['Foo'] = 'bar' > > When I do that, I get "NameError: name '__dict__' is not defined". Is > it possible to do what I'm trying to do? > test.py: import sys varName= 'foo' setattr(sys.modules[__name__], varName, 42) in a shell: import test print test.foo >>> 42 JM From no-spam at non-existing.invalid Tue Mar 2 06:11:10 2010 From: no-spam at non-existing.invalid (Robert) Date: Tue, 02 Mar 2010 12:11:10 +0100 Subject: (and about tests) Re: Pedantic pickling error after reload? In-Reply-To: <7uq299FrmfU1@mid.uni-berlin.de> References: <7uo1aqFitnU1@mid.uni-berlin.de> <7uq299FrmfU1@mid.uni-berlin.de> Message-ID: >> well, reloading is the thing which I do most in coding practice :-) >> For me its a basic thing like cell proliferation in biology. > > I simply never do it. It has subtle issues, one of them you found, > others you say you work around by introducing actual frameworks. But you > might well forget some corner-cases & suddently chase a chimera you deem > a bug, that in fact is just an unwanted side-effect of reloading. well, at dev time there is a different rule: the more bugs, the better (they can raise/indicate certain design and coding weaknesses) > > And all this extra complexity is only good for the process of actually > changing the code. It doesn't help you maintaining code quality. neither does a improved editor, interactive/debugging/reload scheme replace tests, nor do tests replace them the other way around. different dimensions. just the benefactions on all levels radiate recursively of course ... e.g. by a good reload scheme one can even work the tests out better (and debug more efficiently when the tests bump). that little reload support code is a rather constant small stub compared to the app size (unless with trivial 1-day apps maybe). Most 'utility' modules don't need extra care at all. Plus maybe 1 .. 5 extra lines per few frequently changed GUI classes (when well organized) and some 5..10 lines for preserving/re-fixing the few application data anchors. Thats all. No need to get it fully consistent, as serves its purpose when editing during runtime is possible in 'most cases'. And most edit cases during debug sessions are typically just small fixes and touches of function code. One fix revealing the next follow-up bug .. beautifying things .. as it is. critical data structure changes are very rare occasions. A general reload scheme ("edit at runtime") zeroes out most effectively a core time consumer while exploring, iterating, debugging, smoothing .. On the time scale of these tasks, this effect can in my opinion by far not be matched equivalently by setup code of whatever kind in non-trivial apps. (As I did/do this before or with less dynamic programming languages) >> I typically need just 1 full app reboot on 20..50 edit-run-cycles I >> guess. And just few unit test runs per release. Even for >> Cython/pyximport things I added support for this reload edit-run-cycle, >> because I cannot imagine to dev without this. > > Let me assure you - it works :) > > for example yesterday, I create a full CRUD-interface for a web-app > (which is the thing I work on mostly these days) without *once* taking a > look at the browser. I wrote actions, forms, HTML, and tests along, > developed the thing ready, asserted certain constraints and error-cases, > and once finished, fired up the browser - and he saw, it worked! > > Yes, I could have written that code on the fly, hitting F5 every few > seconds/minutes to see if things work out (instead of just running the > specific tests through nose) - and once I'd be finished, I didn't have > anything permanent that ensured the functionality over time. well in this 1-day example you coded a thing which obviously you had already done similarly several times. still I guess, you had some debug session too. some exploration of new things and new aspects. profiting e.g. particularly from the Python interactive / interactive debugger, post mortem etc. .. unless you type so perfect from scratch as that guy in Genesis 1 :-) >> this is a comfortable quasi religious theory raised often and easily >> here and there - impracticable and very slow on that fine grained code >> evolution level however. an interesting issue. > > To me, that's as much as an religious statement often heard by people > that aren't (really) into test-driven development. By which I personally > don't mean the variant where one writes tests first, and then code. I > always develop both in lock-step, sometimes introducing a new feauter > first in my test as e.g. new arguments, or new calls, and then > implementing them, but as often the other way round. > > The argument is always a variation of "my problem is to complicated, the > code-base to interviened to make it possible to test this". well, nothing against preaching about tests ;-) , unless its too much. like with every extreme there is also a threshold where you don't draw anymore at the bottom line by adding more tests. there are costs too. other bottle necks ... its not against test writing for testing/validating/stabilizing and other indirect high-level benefactions. there are simply other dimensions too, which are worth a thought or two. the question about a good reload scheme is more oriented towards the debugging/interactive/exploration/editing level. things, where particularly Python opens new dimensions by its superior dynamic and self-introspective nature. > I call this a bluff. You might work with a code-base that makes it > harder than needed to write tests for new functionality. But then, most > of the time this is a sign of lack of design. Writing with testability > in mind makes you think twice about how to proper componentize your > application, clearly separate logic from presentation, validates > API-design because using the API is immediatly done when writing the > tests you need, and so forth. yes, tests writing can also induce a better code modularization. a good editor, good debugging/reload scheme etc also radiate... the test runner can be connected to the post mortem debugger/interactive and so on. >> "Reload > pychecker/pylint > tests" works most effectively with Python >> in my opinion. >> And for GUI-development the difference is max. >> (min for math algorithms which are well away from data structures/OO) > > As I said, I mainly do web these days. Which can be considered GUIs as > well. Testing the HTTP-interface is obviously easier & possible, and > what I described earlier. > > But we also use selenium to test JS-driven interfaces, as now the > complexity of the interface rises, with all the bells & whistles of > ajaxiness and whatnot. (the CRUD approach on 'form handling IO level' as it is typically more simple regarding tests writing than GUI programming - because of the atomic operations and straight interface. similar like alg and I/O testing. While test writing for a flattery JS/CSS-heavy multi-language multi-state web GUIs (with subtle user interactions) is perhaps similar complex than doing it for a desktop GUI app I think. ) >> A rule that unit tests are used only near a release or a milestone is >> healthy in that sense I think. >> (And a quick edit-(real)run-interact cycle is good for speed) > > Nope, not in my opinion. Making tests an afterthought may well lead to > them being written carelessly, not capturing corner-cases you Anyway one can formulate/write tests on each error/problem/design question which one thinks is worth a test. A interesting question may be however: if the tests (both: unit tests and auto code checks) should be _run_ permanently - in order to lets say have a 'zero test dump status' overall every few minutes, at the time scale of editing/exploring/debugging ? I think that one doesn't loose on the savety net effect, but one wins on overall validation power of the tests, when one _uses_ the (new and old) tests not too often: more rarely/later/before the 'release'. because after many things are rewired in the code (incl. test code) for a milestone/release step or, each bump which arises fresh, lets you think/cure about the network effects and deeper effect of errors in common, similar contexts etc. While when one makes the code fit against the 'few artificial tests' (which are always very/too few!) too fast on the wrong time scale, its like in that example of quick antibiotica application/abuse: the cure for the bumps then tend to be too short sighted. symptom curing. while the clever bugs arise in background ... having fresh written tests unused for some time is no problem, because they will induce there own debug session sooner or later .. > Testing is no silver bullet. But it's a rather mighte sword.. :) > I'd say testing has its place amongst other things and dimensions like (incomplete): Editor: type, browse Language: formulate Interactive: inspect, try Debug: inspect, fix Reload: fix, iterate, explore, clean Design: organize Code checks: stabilize Unit tests: stabilize Feedback: realize Each issue can be improved. effective in overall speed. He saw: If you have no good editor there is some 1.5 .. 2 x less dev speed. If you have no Python (Ruby, Groovy...) there is some 1.5 .. 2 x less dev speed. If you have no good Interactive/Debugging there is some 1.5 .. 2 x less dev speed. If you have no improved reload scheme there is another 1.5 .. 2 x less dev speed. If you have no good design scheme there is another 1.5 .. 2 x less dev speed. If you have no good code checks there is another 1.5 .. 2 x less dev speed. If you have no good test scheme there is another 1.5 .. 2 x less dev speed. If you have no good bug report scheme there is another 1.5 .. 2 x less dev speed. ... A improved reload scheme may even speed up at the center of the development wheel: iteration. I guess I underrated... Robert From emannion at gmail.com Tue Mar 2 06:34:16 2010 From: emannion at gmail.com (enda man) Date: Tue, 2 Mar 2010 03:34:16 -0800 (PST) Subject: Call Signtool using python Message-ID: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Hi, I want to call the Windows signtool to sign a binary from a python script. Here is my script: // os.chdir('./Install/activex/cab') subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) // But I am getting this error: //// SignTool Error: The specified PFX password is not correct. Number of files successfully Signed: 0 Number of warnings: 0 Number of errors: 1 Finished building plugin installer scons: done building targets. //// This python script is called as part of a scons build, which is also python code. Anyone seen this before or can pass on any ideas. Tks, EM From wuwei23 at gmail.com Tue Mar 2 07:50:25 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 2 Mar 2010 04:50:25 -0800 (PST) Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: Message-ID: "W. eWatson" wrote: > My claim is that if one creates a program in a folder that reads a file > in the folder it and then copies it to another folder, it will read ?the > data file in the first folder, and not a changed file in the new folder. > I'd appreciate it if some w7 users could try this, and let me know what > they find. On a fresh install of Win7 Ultimate, I created your program & the text file in one folder, then copied the program both using ctrl-c/ctrl-v and later ctrl-drag-&-drop. In both cases, the copied program *did not* refer to the text file when executed: D:\projects>a Traceback (most recent call last): File "D:\projects\a.py", line 1, in track_file = open("verify.txt") IOError: [Errno 2] No such file or directory: 'verify.txt' Whatever you seem to think you did, you didn't, or you're not providing enough detail on what you did to repeat the behaviour. I do agree with the sentiment that this isn't a Python issue. From vriolk at gmail.com Tue Mar 2 08:12:37 2010 From: vriolk at gmail.com (coldpizza) Date: Tue, 2 Mar 2010 05:12:37 -0800 (PST) Subject: How to use python to register a service (an existing .exe file) References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <7655fe5a-3f37-4835-8fa2-cf95928ef124@q16g2000yqq.googlegroups.com> instsrv.exe does not come with Windows by default, but I guess it should be possible to add a service using the win32 built-in `sc` command line tool. Try `sc create` from a console. The app you want to install as a service will still have to be compliant with the win32 service interface, otherwise it will throw an error, although the app will still be started. On Feb 16, 2:10?am, News123 wrote: > Hi, > > Is there a python way to register new windows services. > > I am aware of the > instsrv.exe program, which can be used to install services. > I could use subprocess.Popen to call > > instsrv.exe "service_name" program.exe > > but wondered, whether there's already an existing function. > > Thans in advance and bye > > N From roy at panix.com Tue Mar 2 08:21:03 2010 From: roy at panix.com (Roy Smith) Date: Tue, 02 Mar 2010 08:21:03 -0500 Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: In article , Chris Rebert wrote: > On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: > > >From inside a module, I want to add a key-value pair to the module's > > __dict__. ??I know I can just do: > > > > FOO = 'bar' > > > > at the module top-level, but I've got 'FOO' as a string and what I > > really need to do is > > > > __dict__['Foo'] = 'bar' > > > > When I do that, I get "NameError: name '__dict__' is not defined". ??Is > > it possible to do what I'm trying to do? > > Yes; just modify the dict returned by the globals() built-in function > instead. Ah, cool. Thanks. > It's usually not wise to do this and is better to use a > separate dict instead, but I'll assume you know what you're doing and > have good reasons to disregard the standard advice due to your > use-case. Why is it unwise? The use case is I'm importing a bunch of #define constants from a C header file. I've got triples that I want to associate; the constant name, the value, and a string describing it. The idea is I want to put in the beginning of the module: declare('XYZ_FOO', 0, "The foo property") declare('XYZ_BAR', 1, "The bar property") declare('XYZ_BAZ', 2, "reserved for future use") and so on. I'm going to have hundreds of these, so ease of use, ease of maintenance, and niceness of presentation are important. My declare() function will not just set XYZ_FOO = 1 at module global scope, but also insert entries in a variety of dicts so I can look up the description string, map from a value back to the constant name, etc. I *could* do this in a separate dict, but the notational convenience of being able to have the original constant names globally available is pretty important. From steve at holdenweb.com Tue Mar 2 08:33:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 08:33:11 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8D1397.5050507@holdenweb.com> Roy Smith wrote: > In article , > Chris Rebert wrote: > >> On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: >>> >From inside a module, I want to add a key-value pair to the module's >>> __dict__. ? I know I can just do: >>> >>> FOO = 'bar' >>> >>> at the module top-level, but I've got 'FOO' as a string and what I >>> really need to do is >>> >>> __dict__['Foo'] = 'bar' >>> >>> When I do that, I get "NameError: name '__dict__' is not defined". ? Is >>> it possible to do what I'm trying to do? >> Yes; just modify the dict returned by the globals() built-in function >> instead. > > Ah, cool. Thanks. > >> It's usually not wise to do this and is better to use a >> separate dict instead, but I'll assume you know what you're doing and >> have good reasons to disregard the standard advice due to your >> use-case. > > Why is it unwise? > > The use case is I'm importing a bunch of #define constants from a C header > file. I've got triples that I want to associate; the constant name, the > value, and a string describing it. The idea is I want to put in the > beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > and so on. I'm going to have hundreds of these, so ease of use, ease of > maintenance, and niceness of presentation are important. > > My declare() function will not just set XYZ_FOO = 1 at module global scope, > but also insert entries in a variety of dicts so I can look up the > description string, map from a value back to the constant name, etc. > > I *could* do this in a separate dict, but the notational convenience of > being able to have the original constant names globally available is pretty > important. > And how important is it to make sure that whatever data your program processes doesn't overwrite the actual variable names you want to use to program the processing? If you use this technique you are effectively making your program a hostage to fortune, as you no longer control the namespace you are using for the programming. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 2 08:33:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 08:33:11 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8D1397.5050507@holdenweb.com> Roy Smith wrote: > In article , > Chris Rebert wrote: > >> On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: >>> >From inside a module, I want to add a key-value pair to the module's >>> __dict__. ? I know I can just do: >>> >>> FOO = 'bar' >>> >>> at the module top-level, but I've got 'FOO' as a string and what I >>> really need to do is >>> >>> __dict__['Foo'] = 'bar' >>> >>> When I do that, I get "NameError: name '__dict__' is not defined". ? Is >>> it possible to do what I'm trying to do? >> Yes; just modify the dict returned by the globals() built-in function >> instead. > > Ah, cool. Thanks. > >> It's usually not wise to do this and is better to use a >> separate dict instead, but I'll assume you know what you're doing and >> have good reasons to disregard the standard advice due to your >> use-case. > > Why is it unwise? > > The use case is I'm importing a bunch of #define constants from a C header > file. I've got triples that I want to associate; the constant name, the > value, and a string describing it. The idea is I want to put in the > beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > and so on. I'm going to have hundreds of these, so ease of use, ease of > maintenance, and niceness of presentation are important. > > My declare() function will not just set XYZ_FOO = 1 at module global scope, > but also insert entries in a variety of dicts so I can look up the > description string, map from a value back to the constant name, etc. > > I *could* do this in a separate dict, but the notational convenience of > being able to have the original constant names globally available is pretty > important. > And how important is it to make sure that whatever data your program processes doesn't overwrite the actual variable names you want to use to program the processing? If you use this technique you are effectively making your program a hostage to fortune, as you no longer control the namespace you are using for the programming. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jjposner at optimum.net Tue Mar 2 09:17:00 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 02 Mar 2010 09:17:00 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8cd310$0$4604$426a34cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> Message-ID: On 3/2/2010 3:57 AM, Bruno Desthuilliers wrote: >> >> With the instance object (if any) and class object available, >> it's easy to create a method object that wraps the function object. > > That's perfect. Fixed. > But there's also a typo to fix in the Python implementation of the > Method object: in the call method, it should inject self.im_self as > first arg, not self.im_func. This had been spotted by someone named John > Posner, IIRC !-) Fixed (oops!). I've updated the text at this location: > http://cl1p.net/bruno_0301.rst/ I think the ball is back in your court, Bruno. I'd be happy to help more -- feel free to contact me off-list, at jjposner at optimum.net. Best, John From marduk at python.net Tue Mar 2 09:24:58 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 09:24:58 -0500 Subject: os.fdopen() issue in Python 3.1? Message-ID: <1267539898.477222.7.camel@necropolis> I have a snippet of code that looks like this: pid, fd = os.forkpty() if pid == 0: subprocess.call(args) else: input = os.fdopen(fd).read() ... This seems to work find for CPython 2.5 and 2.6 on my Linux system. However, with CPython 3.1 I get: input = os.fdopen(fd).read() IOError: [Errno 5] Input/output error Is there something wrong in Python 3.1? Is this the correct way to do this (run a process in a pseudo-tty and read it's output) or is there another way I should/could be doing this? -a From mwilson at the-wire.com Tue Mar 2 09:26:06 2010 From: mwilson at the-wire.com (Mel) Date: Tue, 02 Mar 2010 09:26:06 -0500 Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: Roy Smith wrote: [ ... ] > Why is it unwise? > > The use case is I'm importing a bunch of #define constants from a C header > file. I've got triples that I want to associate; the constant name, the > value, and a string describing it. The idea is I want to put in the > beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > and so on. I'm going to have hundreds of these, so ease of use, ease of > maintenance, and niceness of presentation are important. As long as the header file says what you think it says, you're fine. If you encounter a file that does "#define sys", then the sys module is forever masked, and your module can't invoke it. A header file that contains "#define declare" will be fun. Mel. From mmitchell at transparent.com Tue Mar 2 09:46:21 2010 From: mmitchell at transparent.com (Matt Mitchell) Date: Tue, 2 Mar 2010 09:46:21 -0500 Subject: Call Signtool using python In-Reply-To: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> References: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Message-ID: I think you need to use the /p switch to pass signtool.exe a password when using the /f switch. Check out http://msdn.microsoft.com/en-us/library/8s9b9yaz%28VS.80%29.aspx for more info. ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of enda man Sent: Tuesday, March 02, 2010 6:34 AM To: python-list at python.org Subject: Call Signtool using python Hi, I want to call the Windows signtool to sign a binary from a python script. Here is my script: // os.chdir('./Install/activex/cab') subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) // But I am getting this error: //// SignTool Error: The specified PFX password is not correct. Number of files successfully Signed: 0 Number of warnings: 0 Number of errors: 1 Finished building plugin installer scons: done building targets. //// This python script is called as part of a scons build, which is also python code. Anyone seen this before or can pass on any ideas. Tks, EM -- http://mail.python.org/mailman/listinfo/python-list From lutz at learning-python.com Tue Mar 2 10:11:41 2010 From: lutz at learning-python.com (Mark Lutz) Date: Tue, 2 Mar 2010 07:11:41 -0800 (PST) Subject: Python training in Florida, April 27-29 Message-ID: <70339c5d-a874-4610-a528-787f18855a4c@y17g2000yqd.googlegroups.com> Tired of the Winter weather? Make your plans now to attend our upcoming Florida Python training seminar in April. This 3-day public class will be held on April 27-29, in Sarasota, Florida. It is open to both individual and group enrollments. For more details on the class, as well as registration instructions, please visit the class web page: http://learning-python.com/2010-public-classes.html Note that we have moved to a new domain name. If you are unable to attend in April, our next Sarasota class is already scheduled for July 13-15. Thanks, and we hope to see you at a Python class in sunny and warm Florida soon. --Mark Lutz at learning-python.com From roy at panix.com Tue Mar 2 10:19:56 2010 From: roy at panix.com (Roy Smith) Date: Tue, 2 Mar 2010 07:19:56 -0800 (PST) Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: On Mar 2, 8:33?am, Steve Holden wrote: > And how important is it to make sure that whatever data your program > processes doesn't overwrite the actual variable names you want to use to > program the processing? Oh, I see what you're saying. You're thinking I was going to machine- process the C header file and pattern-match the #define statements? Actually, I was just hand-copying the values, and was looking for a way to reduce typing. But, I suppose if I were to machine-process the header files, that would be a concern. I suppose in that case I would make sure I only inserted variables which matched a particular pattern (ie, "[A-Z]+_[A- Z][A-Z0-9]+"). In fact, now that you got me thinking in that direction... Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm manually re- typing the data out of that. Sigh. From victorsubervi at gmail.com Tue Mar 2 10:48:19 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 11:48:19 -0400 Subject: Email Script Message-ID: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> Hi; I have the following code: def my_mail(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor= database.cursor() ourEmail1 = 'marilyn at globalsolutionsgroup.vi' ourEmail1 = 'phil at globalsolutionsgroup.vi' ourEmail2 = 'benoismyname at gmail.com' form = cgi.FieldStorage() name = form.getfirst('name', '') email = form.getfirst('from', '') message = form.getfirst('message', '') message = 'Name: %s\nMessage: %s' % (name, message) subject = 'Message from Web Site' Email( from_address = email, to_address = ourEmail1, subject = subject, message = message ).send() Email( from_address = email, to_address = ourEmail2, subject = subject, message = message ).send() print 'Thank you, %s, we will get back to you shortly!
' % (name) This sends only the first of the two emails. Why doesn't it work to send the second? What do? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Tue Mar 2 10:53:10 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 11:53:10 -0400 Subject: Email Script In-Reply-To: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> Message-ID: <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi wrote: > Hi; > I have the following code: > > def my_mail(): > user, passwd, db, host = login() > database = MySQLdb.connect(host, user, passwd, db) > cursor= database.cursor() > ourEmail1 = 'marilyn at globalsolutionsgroup.vi' > ourEmail1 = 'phil at globalsolutionsgroup.vi' > ourEmail2 = 'benoismyname at gmail.com' > form = cgi.FieldStorage() > name = form.getfirst('name', '') > email = form.getfirst('from', '') > message = form.getfirst('message', '') > message = 'Name: %s\nMessage: %s' % (name, message) > subject = 'Message from Web Site' > Email( > from_address = email, > to_address = ourEmail1, > subject = subject, > message = message > ).send() > Email( > from_address = email, > to_address = ourEmail2, > subject = subject, > message = message > ).send() > print 'Thank you, %s, we will get back to you shortly!
' % (name) > > This sends only the first of the two emails. Why doesn't it work to send > the second? What do? > TIA, > beno > Should I put a timer between instances of Email? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 2 11:14:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 11:14:37 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: Roy Smith wrote: > On Mar 2, 8:33 am, Steve Holden wrote: > >> And how important is it to make sure that whatever data your program >> processes doesn't overwrite the actual variable names you want to use to >> program the processing? > > Oh, I see what you're saying. You're thinking I was going to machine- > process the C header file and pattern-match the #define statements? > Actually, I was just hand-copying the values, and was looking for a > way to reduce typing. > > But, I suppose if I were to machine-process the header files, that > would be a concern. I suppose in that case I would make sure I only > inserted variables which matched a particular pattern (ie, "[A-Z]+_[A- > Z][A-Z0-9]+"). In fact, now that you got me thinking in that > direction... > > Somewhat sadly, in my case, I can't even machine process the header > file. I don't, strictly speaking, have a header file. What I have is > a PDF which documents what's in the header file, and I'm manually re- > typing the data out of that. Sigh. > Don't worry. Now you have revealed the *real* problem you may well find there are c.l.py readers who can help! Python can read PDFs ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jjposner at optimum.net Tue Mar 2 11:18:02 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 02 Mar 2010 11:18:02 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8D3A3A.8030501@optimum.net> On 3/2/2010 10:19 AM, Roy Smith wrote: > > Somewhat sadly, in my case, I can't even machine process the header > file. I don't, strictly speaking, have a header file. What I have is > a PDF which documents what's in the header file, and I'm manually re- > typing the data out of that. Sigh. Here's an idea, perhaps too obvious, to minimize your keystrokes: 1. Create a text file with the essential data: XYZ_FOO 0 The foo property XYZ_BAR 1 The bar property XYZ_BAZ 2 reserved for future use 2. Use a Python script to convert this into the desired code: declare('XYZ_FOO', 0, "The foo property") declare('XYZ_BAR', 1, "The bar property") declare('XYZ_BAZ', 2, "reserved for future use") Note: >>> s 'XYZ_FOO 0 The foo property' >>> s.split(None, 2) ['XYZ_FOO', '0', 'The foo property'] HTH, John From aahz at pythoncraft.com Tue Mar 2 11:22:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 08:22:38 -0800 Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> Message-ID: In article , D'Arcy J.M. Cain wrote: > >Put as much memory as you can afford/fit into your database server. >It's the cheapest performance boost you can get. If you have a serious >application put at least 4GB into your dedicated database server. >Swapping is your enemy. Also, put your log/journal files on a different spindle from the database files. That makes a *huge* difference. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From michaelveloz at gmail.com Tue Mar 2 11:29:04 2010 From: michaelveloz at gmail.com (Veloz) Date: Tue, 2 Mar 2010 08:29:04 -0800 (PST) Subject: Queue peek? Message-ID: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Hi all I'm looking for a queue that I can use with multiprocessing, which has a peek method. I've seen some discussion about queue.peek but don't see anything in the docs about it. Does python have a queue class with peek semantics? Michael From a_jtim at bellsouth.net Tue Mar 2 11:31:16 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 2 Mar 2010 08:31:16 -0800 (PST) Subject: freebsd and multiprocessing Message-ID: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> Hi, I'm intending to use multiprocessing on a freebsd machine (6.3 release, quad core, 8cpus, amd64). I see in the doc that on this platform I can't use synchronize: ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770. As far as I can tell, I have no need to synchronize the processes--I have several processes run separately and I need to know when they're all finished; there's no communication between them and each owns its own log file for output. Is anyone using multiprocessing on FreeBSD and run into any other gotchas? thanks, --Tim Arnold From robert.kern at gmail.com Tue Mar 2 11:34:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Mar 2010 10:34:51 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 2010-03-01 22:55 PM, Terry Reedy wrote: > On 3/1/2010 7:56 PM, Patrick Maupin wrote: >> On Mar 1, 5:57 pm, Erik Max Francis wrote: >>> Patrick Maupin wrote: >>> This not only seriously stretching the meaning of the term "superset" >>> (as Python is most definitely not even remotely a superset of JSON), but >> >> Well, you are entitled to that opinion, but seriously, if I take valid >> JSON, replace unquoted true with True, unquoted false with False, >> replace unquoted null with None, and take the quoted strings and >> replace occurrences of \uXXXX with the appropriate unicode, then I do, >> in fact, have valid Python. But don't take my word for it -- try it >> out! > > To me this is so strained that I do not see why why you are arguing the > point. So what? The resulting Python 'program' will be equivalent, I > believe, to 'pass'. Ie, construct objects and then discard them with no > computation or output. Not if you eval() rather than exec(). It's reasonably well-accepted that JSON is very close to being a subset of Python's expression syntax with just a few modifications. -- 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 From robert.kern at gmail.com Tue Mar 2 11:37:55 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Mar 2010 10:37:55 -0600 Subject: Is this secure? In-Reply-To: References: <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-28 01:28 AM, Aahz wrote: > In article, > Robert Kern wrote: >> >> If you are storing the password instead of making your user remember >> it, most platforms have some kind of keychain secure password >> storage. I recommend reading up on the APIs available on your targeted >> platforms. > > Are you sure? I haven't done a lot of research, but my impression was > that Windows didn't have anything built in. You're right, not built-in, but Windows does provide enough crypto services for a cross-platform Python implementation to be built: http://pypi.python.org/pypi/keyring -- 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 From pavlovevidence at gmail.com Tue Mar 2 11:49:26 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Mar 2010 08:49:26 -0800 (PST) Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <8fa1b0d6-3f1b-4499-872c-e5854d289e9e@w27g2000pre.googlegroups.com> On Mar 2, 5:21?am, Roy Smith wrote: > In article , > ?Chris Rebert wrote: > > > > > On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: > > > >From inside a module, I want to add a key-value pair to the module's > > > __dict__. ?I know I can just do: > > > > FOO = 'bar' > > > > at the module top-level, but I've got 'FOO' as a string and what I > > > really need to do is > > > > __dict__['Foo'] = 'bar' > > > > When I do that, I get "NameError: name '__dict__' is not defined". ?Is > > > it possible to do what I'm trying to do? > > > Yes; just modify the dict returned by the globals() built-in function > > instead. > > Ah, cool. ?Thanks. > > > It's usually not wise to do this and is better to use a > > separate dict instead, but I'll assume you know what you're doing and > > have good reasons to disregard the standard advice due to your > > use-case. > > Why is it unwise? He didn't say it was unwise. He said it's usually not wise. Carl Banks From philip at semanchuk.com Tue Mar 2 11:52:13 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 2 Mar 2010 11:52:13 -0500 Subject: freebsd and multiprocessing In-Reply-To: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> Message-ID: <21D34712-C0F0-40E5-9D62-DB867962ED8A@semanchuk.com> On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: > Hi, > I'm intending to use multiprocessing on a freebsd machine (6.3 > release, quad core, 8cpus, amd64). I see in the doc that on this > platform I can't use synchronize: > > ImportError: This platform lacks a functioning sem_open > implementation, therefore, the required synchronization primitives > needed will not function, see issue 3770. > > As far as I can tell, I have no need to synchronize the processes--I > have several processes run separately and I need to know when they're > all finished; there's no communication between them and each owns its > own log file for output. > > Is anyone using multiprocessing on FreeBSD and run into any other > gotchas? Hi Tim, I don't use multiprocessing but I've written two low-level IPC packages, one for SysV IPC and the other for POSIX IPC. I think that multiprocessing prefers POSIX IPC (which is where sem_open() comes from). I don't know what it uses if that's not available, but SysV IPC seems a likely alternative. I must emphasize, however, that that's a guess on my part. FreeBSD didn't have POSIX IPC support until 7.0, and that was sort of broken until 7.2. As it happens, I was testing my POSIX IPC code against 7.2 last night and it works just fine. SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is the oldest I've tested). ISTR that by default each message queue is limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably tell you that and may even let you change it. Other than that I can't think of any SysV limitations that might bite you. HTH Philip From victorsubervi at gmail.com Tue Mar 2 11:56:58 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 12:56:58 -0400 Subject: Email Script In-Reply-To: <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> Message-ID: <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> On Tue, Mar 2, 2010 at 11:53 AM, Victor Subervi wrote: > On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> def my_mail(): >> user, passwd, db, host = login() >> database = MySQLdb.connect(host, user, passwd, db) >> cursor= database.cursor() >> ourEmail1 = 'marilyn at globalsolutionsgroup.vi' >> ourEmail1 = 'phil at globalsolutionsgroup.vi' >> ourEmail2 = 'benoismyname at gmail.com' >> form = cgi.FieldStorage() >> name = form.getfirst('name', '') >> email = form.getfirst('from', '') >> message = form.getfirst('message', '') >> message = 'Name: %s\nMessage: %s' % (name, message) >> subject = 'Message from Web Site' >> Email( >> from_address = email, >> to_address = ourEmail1, >> subject = subject, >> message = message >> ).send() >> Email( >> from_address = email, >> to_address = ourEmail2, >> subject = subject, >> message = message >> ).send() >> print 'Thank you, %s, we will get back to you shortly!
' % (name) >> >> This sends only the first of the two emails. Why doesn't it work to send >> the second? What do? >> TIA, >> beno >> > > Should I put a timer between instances of Email? > >> >> Adding a timer didn't work. Do I need to explicitly close the smtp connection before sending the next email? I don't understand why there's a problem. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Mar 2 12:26:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 17:26:18 +0000 Subject: Adding to a module's __dict__? In-Reply-To: <4B8D3A3A.8030501@optimum.net> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> <4B8D3A3A.8030501@optimum.net> Message-ID: <4B8D4A3A.90501@mrabarnett.plus.com> John Posner wrote: > On 3/2/2010 10:19 AM, Roy Smith wrote: >> >> Somewhat sadly, in my case, I can't even machine process the header >> file. I don't, strictly speaking, have a header file. What I have is >> a PDF which documents what's in the header file, and I'm manually re- >> typing the data out of that. Sigh. > > Here's an idea, perhaps too obvious, to minimize your keystrokes: > > 1. Create a text file with the essential data: > > XYZ_FOO 0 The foo property > XYZ_BAR 1 The bar property > XYZ_BAZ 2 reserved for future use > > 2. Use a Python script to convert this into the desired code: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > Note: > > >>> s > 'XYZ_FOO 0 The foo property' > >>> s.split(None, 2) > ['XYZ_FOO', '0', 'The foo property'] > You might be able to reduce your typing by copy-and-pasting the relevant text from the PDF into an editor and then editing it. From python at mrabarnett.plus.com Tue Mar 2 12:32:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 17:32:40 +0000 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <1267539898.477222.7.camel@necropolis> References: <1267539898.477222.7.camel@necropolis> Message-ID: <4B8D4BB8.8020909@mrabarnett.plus.com> Albert Hopkins wrote: > I have a snippet of code that looks like this: > > pid, fd = os.forkpty() > if pid == 0: > subprocess.call(args) > else: > input = os.fdopen(fd).read() > ... > > > This seems to work find for CPython 2.5 and 2.6 on my Linux system. > However, with CPython 3.1 I get: > > input = os.fdopen(fd).read() > IOError: [Errno 5] Input/output error > > Is there something wrong in Python 3.1? Is this the correct way to do > this (run a process in a pseudo-tty and read it's output) or is there > another way I should/could be doing this? > The documentation also mentions the 'pty' module. Have you tried that instead? From emannion at gmail.com Tue Mar 2 12:33:39 2010 From: emannion at gmail.com (enda man) Date: Tue, 2 Mar 2010 09:33:39 -0800 (PST) Subject: Call Signtool using python References: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Message-ID: On Mar 2, 2:46?pm, "Matt Mitchell" wrote: > I think you need to use the /p switch to pass signtool.exe a password > when using the /f switch. > Check outhttp://msdn.microsoft.com/en-us/library/8s9b9yaz%28VS.80%29.aspxfor > more info. > > ----------------------------------- > The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. > > -----Original Message----- > From: python-list-bounces+mmitchell=transparent.... at python.org > > [mailto:python-list-bounces+mmitchell=transparent.... at python.org] On > Behalf Of enda man > Sent: Tuesday, March 02, 2010 6:34 AM > To: python-l... at python.org > Subject: Call Signtool using python > > Hi, > > I want to call the Windows signtool to sign a binary from a python > script. > > Here is my script: > // > os.chdir('./Install/activex/cab') > subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", > "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) > // > > But I am getting this error: > //// > SignTool Error: The specified PFX password is not correct. > > Number of files successfully Signed: 0 > Number of warnings: 0 > Number of errors: 1 > Finished building plugin installer > scons: done building targets. > //// > > This python script is called as part of a scons build, which is also > python code. > > Anyone seen this before or can pass on any ideas. > Tks, > EM > > --http://mail.python.org/mailman/listinfo/python-list > > The same command works when run from the command line but when I run it from python using subprocess.call(...) it fails as described in my first post. I do not need to use the /p switch as the password is embedded in the pfx file. That is why I think it is something I am or am not doing in python. EM From usenot at geekmail.INVALID Tue Mar 2 12:35:27 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 18:35:27 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> Message-ID: <20100302183527.47c6e8f5@geekmail.INVALID> On Mon, 01 Mar 2010 21:09:39 +0000 Mark Lawrence wrote: > Andreas Waldenburger wrote: > > [snip] > > We did not buy code. If it were written in C or such, we would never > > get to see it. > > > > It's not our concern. > > > > /W > > > > From your original post. > > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > > So what is the relationship between your company and this other > company? They write a piece of software that we run as a component in a software ecosystem that we (and others) have developed. > When it gets down to pounds, shillings and pence (gosh, I'm > old!:) it sure as hell could make a tremendous difference in the long > term, given that usually maintainance costs are astronomical when > compared to initial development costs. > I totally agree, but as long as their software works, why should we care how their code looks? It's totally their responsibility. Why should we nanny every partner we have? Don't get me wrong; our whole system is more fragile than I find comfortable. But I guess getting 10ish different parties around the globe to work in complete unison is quite a feat, and I'm surprised it even works as it is. But it does, and I'm glad we don't have to micromanage other people's code. /W -- INVALID? DE! From tjreedy at udel.edu Tue Mar 2 12:38:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Mar 2010 12:38:55 -0500 Subject: Adding to a module's __dict__? In-Reply-To: <4B8D3A3A.8030501@optimum.net> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> <4B8D3A3A.8030501@optimum.net> Message-ID: On 3/2/2010 11:18 AM, John Posner wrote: > On 3/2/2010 10:19 AM, Roy Smith wrote: >> >> Somewhat sadly, in my case, I can't even machine process the header >> file. I don't, strictly speaking, have a header file. What I have is >> a PDF which documents what's in the header file, and I'm manually re- >> typing the data out of that. Sigh. There are Python modules to read/write pdf. > Here's an idea, perhaps too obvious, to minimize your keystrokes: > > 1. Create a text file with the essential data: > > XYZ_FOO 0 The foo property > XYZ_BAR 1 The bar property > XYZ_BAZ 2 reserved for future use > > 2. Use a Python script to convert this into the desired code: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > Note: > > >>> s > 'XYZ_FOO 0 The foo property' > >>> s.split(None, 2) > ['XYZ_FOO', '0', 'The foo property'] Given that set of triples is constant, I would think about having the Python script do the computation just once, instead of with every inport. In other words, the script should *call* the declare function and then write out the resulting set of dicts either to a .py or pickle file. tjr From usenot at geekmail.INVALID Tue Mar 2 12:40:56 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 18:40:56 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> Message-ID: <20100302184056.743a71e7@geekmail.INVALID> On Tue, 02 Mar 2010 09:48:47 +1100 Ben Finney wrote: > > It's not our concern. > > Then I don't see what that problem is. There is none. I was griping about how stupid they are. That is a personal problem I have with their *code* (not software), and I thought I'd just share my superiority complex with everyone. I had hoped that everyone just read it, went like "Oh geez.", smiled it off with a hint of lesson learned and got back to whatever it was they were doing. Alas, I was wrong ... and I'm sorry. /W -- INVALID? DE! From affdfsdfdsfsd at b.com Tue Mar 2 12:46:12 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 02 Mar 2010 17:46:12 GMT Subject: case do problem Message-ID: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> hi, i've to convert from Pascal this code: iterations=0; count=0; REPEAT; iterations = iterations+1; ... IF (genericCondition) THEN count=count+1; ... CASE count OF: 1: m = 1 2: m = 10 3: m = 100 UNTIL count = 4 OR iterations = 20 i do something like this: iterations = 0 count = 0 m_Switch = (1,10,100) while True: iterations +=1 ... if (genericCondition): count +=1 ... try: m = m_Switch[count-1] except: pass if count = 4 or iterations = 20 the problem is that when count = 4 m_Switch[4-1] have no value, so i use the try..except. Is there a better solution to solve this problem? and, generally speaking, the try..except block slow down the execution of the program or not? Thank you in advance Nico From mrkafk at gmail.com Tue Mar 2 12:46:22 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 18:46:22 +0100 Subject: conditional import into global namespace Message-ID: Hello everyone, I have a class that is dependent on subprocess functionality. I would like to make it self-contained in the sense that it would import subprocess if it's not imported yet. What is the best way to proceed with this? I see a few possibilities: 1. do a class level import, like: class TimeSync(object): import subprocess 2. do an import in init, which is worse bc it's ran every time an instance is created: def __init__(self, shiftsec, ntpserver): import subprocess Both of those methods have disadvantage in this context, though: they create 'subprocess' namespace in a class or instance, respectively. Is there anyway to make it a global import? Regards, mk From invalid at invalid.invalid Tue Mar 2 12:46:52 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Mar 2010 17:46:52 +0000 (UTC) Subject: Broken references in postings Message-ID: I've noticed recently that a lot of the "refernces" and "in-reply-to" headers in c.l.p are broken, resulting in the inability to move from a child to a parent in a tree. For example in a recent reply (subejct: os.fdopen() issue in Python 3.1?), the references and in-reply-to headers both contained: 1267539898.477222.7.camel at necropolis However, the article replied to has a message-ID header of mailman.110.1267539885.23598.python-list at python.org I don't see 1267539898.477222.7.camel at necropolis anywhere in the headers of the referrant. Is something broken in the mail<->news gateway? Or is it just individual news/mail clients that are broken? -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank! From affdfsdfdsfsd at b.com Tue Mar 2 12:50:45 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 02 Mar 2010 17:50:45 GMT Subject: case do problem References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <4b8d4ff5$0$1132$4fafbaef@reader1.news.tin.it> additional information: when count=4 i haven't to change the m value, so i have to do nothing or something like m = m Nico From tjreedy at udel.edu Tue Mar 2 12:59:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Mar 2010 12:59:00 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 3/2/2010 11:34 AM, Robert Kern wrote: > On 2010-03-01 22:55 PM, Terry Reedy wrote: >> On 3/1/2010 7:56 PM, Patrick Maupin wrote: >>> On Mar 1, 5:57 pm, Erik Max Francis wrote: >>>> Patrick Maupin wrote: >>>> This not only seriously stretching the meaning of the term "superset" >>>> (as Python is most definitely not even remotely a superset of JSON), >>>> but >>> >>> Well, you are entitled to that opinion, but seriously, if I take valid >>> JSON, replace unquoted true with True, unquoted false with False, >>> replace unquoted null with None, and take the quoted strings and >>> replace occurrences of \uXXXX with the appropriate unicode, then I do, >>> in fact, have valid Python. But don't take my word for it -- try it >>> out! >> >> To me this is so strained that I do not see why why you are arguing the >> point. So what? The resulting Python 'program' will be equivalent, I >> believe, to 'pass'. Ie, construct objects and then discard them with no >> computation or output. > > Not if you eval() rather than exec(). >>> eval(1) creates and objects and discards it, with a net result of 'pass'. What do you think I am missing. It's reasonably well-accepted that > JSON is very close to being a subset of Python's expression syntax with > just a few modifications. It is specifically JavaScript Object Notation, which is very similar to a subset of Python's object notation (number and string literals and list and dict displays (but not set displays), and three named constants). Without operators, it barely qualifies, to me, even as 'expression syntax'. To me, comparing object notation with programming language is not helpful to the OP's purpose. His main claim is that JSON can be usefully extended but that YAML is too much, so that perhaps he, with help, can find a 'sweet spot' in between. Terry Jan Reedy From a_jtim at bellsouth.net Tue Mar 2 12:59:10 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 2 Mar 2010 09:59:10 -0800 (PST) Subject: freebsd and multiprocessing References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> Message-ID: <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> On Mar 2, 11:52?am, Philip Semanchuk wrote: > On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: > > > > > > > Hi, > > I'm intending to use multiprocessing on a freebsd machine (6.3 > > release, quad core, 8cpus, amd64). I see in the doc that on this > > platform I can't use synchronize: > > > ImportError: This platform lacks a functioning sem_open > > implementation, therefore, the required synchronization primitives > > needed will not function, see issue 3770. > > > As far as I can tell, I have no need to synchronize the processes--I > > have several processes run separately and I need to know when they're > > all finished; there's no communication between them and each owns its > > own log file for output. > > > Is anyone using multiprocessing on FreeBSD and run into any other > > gotchas? > > Hi Tim, > I don't use multiprocessing but I've written two low-level IPC ? > packages, one for SysV IPC and the other for POSIX IPC. > > I think that multiprocessing prefers POSIX IPC (which is where ? > sem_open() comes from). I don't know what it uses if that's not ? > available, but SysV IPC seems a likely alternative. I must emphasize, ? > however, that that's a guess on my part. > > FreeBSD didn't have POSIX IPC support until 7.0, and that was sort of ? > broken until 7.2. As it happens, I was testing my POSIX IPC code ? > against 7.2 last night and it works just fine. > > SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is the ? > oldest I've tested). ISTR that by default each message queue is ? > limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably ? > tell you that and may even let you change it. Other than that I can't ? > think of any SysV limitations that might bite you. > > HTH > Philip Hi Philip, Thanks for that information. I wish I could upgrade the machine to 7.2! alas, out of my power. I get the following results from sysctl: % sysctl kern.ipc | grep msg kern.ipc.msgseg: 2048 kern.ipc.msgssz: 8 kern.ipc.msgtql: 40 kern.ipc.msgmnb: 2048 kern.ipc.msgmni: 40 kern.ipc.msgmax: 16384 I'll write some test programs using multiprocessing and see how they go before committing to rewrite my current code. I've also been looking at 'parallel python' although it may have the same issues. http://www.parallelpython.com/ thanks again, --Tim From clp2 at rebertia.com Tue Mar 2 12:59:22 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Mar 2010 09:59:22 -0800 Subject: Call Signtool using python In-Reply-To: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> References: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Message-ID: <50697b2c1003020959g33d31d45ge1a7b7986b7e5a45@mail.gmail.com> On Tue, Mar 2, 2010 at 3:34 AM, enda man wrote: > Hi, > > I want to call the Windows signtool to sign a binary from a python > script. > > Here is my script: > // > os.chdir('./Install/activex/cab') > subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", > "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) > // > > But I am getting this error: > //// > SignTool Error: The specified PFX password is not correct. > > Number of files successfully Signed: 0 > Number of warnings: 0 > Number of errors: 1 > Finished building plugin installer > scons: done building targets. > //// > > > This python script is called as part of a scons build, which is also > python code. > > Anyone seen this before or can pass on any ideas. Nothing looks obviously wrong (though I'm unfamiliar with signtool). Have you tried specifying an absolute path to webph.pfx? Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Tue Mar 2 13:00:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 19:00:09 +0100 Subject: case do problem In-Reply-To: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: * Tracubik: > hi, i've to convert from Pascal this code: > > iterations=0; > count=0; > REPEAT; > iterations = iterations+1; > ... > IF (genericCondition) THEN count=count+1; > ... > CASE count OF: > 1: m = 1 > 2: m = 10 > 3: m = 100 Uhm, is this syntactically valid Pascal? As I recall, every Pascal construct was delimited in some way. Once I had the complete Pascal syntax in my head, but alas, not anymore... > UNTIL count = 4 OR iterations = 20 > > i do something like this: > > iterations = 0 > count = 0 > > m_Switch = (1,10,100) > > while True: > iterations +=1 > ... > if (genericCondition): > count +=1 > ... > try: > m = m_Switch[count-1] > except: pass > if count = 4 or iterations = 20 > > the problem is that when count = 4 m_Switch[4-1] have no value, so i use > the try..except. iterations = 0 count = 0 while not( count == 4 or iterations == 20 ): iterations += 1 # ... if generic_condition: count += 1 # ... m = (1, 10, 100, 100)[count] > Is there a better solution to solve this problem? Define "better". Do you mean faster, more clear, shorter, using less memory, what? Above I've assumed that you want to get rid of the try block, since that's what you're asking about: > and, generally > speaking, the try..except block slow down the execution of the program or > not? Probably, but don't think about it. Python programming is at a level where that kind of efficiency doesn't count. Or, ideally it shouldn't count. Cheers & hth., - Alf From alfps at start.no Tue Mar 2 13:01:36 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 19:01:36 +0100 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: * Alf P. Steinbach: > * Tracubik: >> hi, i've to convert from Pascal this code: >> >> iterations=0; >> count=0; >> REPEAT; >> iterations = iterations+1; >> ... >> IF (genericCondition) THEN count=count+1; >> ... >> CASE count OF: >> 1: m = 1 >> 2: m = 10 >> 3: m = 100 > > Uhm, is this syntactically valid Pascal? As I recall, every Pascal > construct was delimited in some way. Once I had the complete Pascal > syntax in my head, but alas, not anymore... > > >> UNTIL count = 4 OR iterations = 20 >> >> i do something like this: >> >> iterations = 0 >> count = 0 >> >> m_Switch = (1,10,100) >> >> while True: >> iterations +=1 >> ... >> if (genericCondition): >> count +=1 >> ... >> try: >> m = m_Switch[count-1] >> except: pass >> if count = 4 or iterations = 20 >> >> the problem is that when count = 4 m_Switch[4-1] have no value, so i >> use the try..except. > > iterations = 0 > count = 0 > while not( count == 4 or iterations == 20 ): > iterations += 1 > # ... > if generic_condition: > count += 1 > # ... > m = (1, 10, 100, 100)[count] Add one extra 100 there. >> Is there a better solution to solve this problem? > > Define "better". Do you mean faster, more clear, shorter, using less > memory, what? > > Above I've assumed that you want to get rid of the try block, since > that's what you're asking about: > > >> and, generally speaking, the try..except block slow down the execution >> of the program or not? > > Probably, but don't think about it. Python programming is at a level > where that kind of efficiency doesn't count. Or, ideally it shouldn't > count. > > > Cheers & hth., > > - Alf From alfps at start.no Tue Mar 2 13:04:21 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 19:04:21 +0100 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: * Alf P. Steinbach: > * Alf P. Steinbach: >> * Tracubik: >>> hi, i've to convert from Pascal this code: >>> >>> iterations=0; >>> count=0; >>> REPEAT; >>> iterations = iterations+1; >>> ... >>> IF (genericCondition) THEN count=count+1; >>> ... >>> CASE count OF: >>> 1: m = 1 >>> 2: m = 10 >>> 3: m = 100 >> >> Uhm, is this syntactically valid Pascal? As I recall, every Pascal >> construct was delimited in some way. Once I had the complete Pascal >> syntax in my head, but alas, not anymore... >> >> >>> UNTIL count = 4 OR iterations = 20 >>> >>> i do something like this: >>> >>> iterations = 0 >>> count = 0 >>> >>> m_Switch = (1,10,100) >>> >>> while True: >>> iterations +=1 >>> ... >>> if (genericCondition): >>> count +=1 >>> ... >>> try: >>> m = m_Switch[count-1] >>> except: pass >>> if count = 4 or iterations = 20 >>> >>> the problem is that when count = 4 m_Switch[4-1] have no value, so i >>> use the try..except. >> >> iterations = 0 >> count = 0 >> while not( count == 4 or iterations == 20 ): >> iterations += 1 >> # ... >> if generic_condition: >> count += 1 >> # ... >> m = (1, 10, 100, 100)[count] > > Add one extra 100 there. Oh dear, it's one of those days. if 1 <= count <= 3: m = (1, 10, 100)[count - 1] >>> Is there a better solution to solve this problem? >> >> Define "better". Do you mean faster, more clear, shorter, using less >> memory, what? >> >> Above I've assumed that you want to get rid of the try block, since >> that's what you're asking about: >> >> >>> and, generally speaking, the try..except block slow down the >>> execution of the program or not? >> >> Probably, but don't think about it. Python programming is at a level >> where that kind of efficiency doesn't count. Or, ideally it shouldn't >> count. >> >> >> Cheers & hth., >> >> - Alf From jeanmichel at sequans.com Tue Mar 2 13:05:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Mar 2010 19:05:25 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100302184056.743a71e7@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> Message-ID: <4B8D5365.9060502@sequans.com> Andreas Waldenburger wrote: > On Tue, 02 Mar 2010 09:48:47 +1100 Ben Finney > wrote: > > >>> It's not our concern. >>> >> Then I don't see what that problem is. >> > > There is none. I was griping about how stupid they are. That is a > personal problem I have with their *code* (not software), and I thought > I'd just share my superiority complex with everyone. > > I had hoped that everyone just read it, went like "Oh geez.", smiled it > off with a hint of lesson learned and got back to whatever it was they > were doing. Alas, I was wrong ... and I'm sorry. > > /W > > There's something wrong saying that stupid people write working code that totally satisfies your needs. Don't you agree ? ;-) JM From python at rcn.com Tue Mar 2 13:18:54 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 2 Mar 2010 10:18:54 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Message-ID: On Mar 2, 8:29?am, Veloz wrote: > Hi all > I'm looking for a queue that I can use with multiprocessing, which has > a peek method. > > I've seen some discussion about queue.peek but don't see anything in > the docs about it. > > Does python have a queue class with peek semantics? Am curious about your use case? Why peek at something that could be gone by the time you want to use it. val = q.peek() if something_i_want(val): v2 = q.get() # this could be different than val Wouldn't it be better to just get() the value and return if you don't need it? val = q.peek() if not something_i_want(val): q.put(val) Raymond From python at mrabarnett.plus.com Tue Mar 2 13:21:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 18:21:02 +0000 Subject: conditional import into global namespace In-Reply-To: References: Message-ID: <4B8D570E.5070804@mrabarnett.plus.com> mk wrote: > Hello everyone, > > I have a class that is dependent on subprocess functionality. I would > like to make it self-contained in the sense that it would import > subprocess if it's not imported yet. > > What is the best way to proceed with this? > > I see a few possibilities: > > 1. do a class level import, like: > > class TimeSync(object): > > import subprocess > > > 2. do an import in init, which is worse bc it's ran every time an > instance is created: > > def __init__(self, shiftsec, ntpserver): > import subprocess > > > Both of those methods have disadvantage in this context, though: they > create 'subprocess' namespace in a class or instance, respectively. > > Is there anyway to make it a global import? > The simplest solution is just import it at the top of the module. From tjreedy at udel.edu Tue Mar 2 13:25:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Mar 2010 13:25:16 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <1267539898.477222.7.camel@necropolis> References: <1267539898.477222.7.camel@necropolis> Message-ID: On 3/2/2010 9:24 AM, Albert Hopkins wrote: > I have a snippet of code that looks like this: > > pid, fd = os.forkpty() > if pid == 0: > subprocess.call(args) > else: > input = os.fdopen(fd).read() > ... > > > This seems to work find for CPython 2.5 and 2.6 on my Linux system. To get help, or report a bug, for something like this, be as specific as possible. 'Linux' may be too generic. > However, with CPython 3.1 I get: > > input = os.fdopen(fd).read() > IOError: [Errno 5] Input/output error > > Is there something wrong in Python 3.1? Is this the correct way to do > this (run a process in a pseudo-tty and read it's output) or is there > another way I should/could be doing this? No idea, however, the first thing I would do is call the .fdopen and .read methods separately (on separate lines) to isolate which is raising the error. tjr From python at mrabarnett.plus.com Tue Mar 2 13:26:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 18:26:08 +0000 Subject: case do problem In-Reply-To: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <4B8D5840.4070601@mrabarnett.plus.com> Tracubik wrote: > hi, i've to convert from Pascal this code: > > iterations=0; > count=0; > REPEAT; > iterations = iterations+1; > ... > IF (genericCondition) THEN count=count+1; > ... > CASE count OF: > 1: m = 1 > 2: m = 10 > 3: m = 100 > UNTIL count = 4 OR iterations = 20 > > i do something like this: > > iterations = 0 > count = 0 > > m_Switch = (1,10,100) > > while True: > iterations +=1 > ... > if (genericCondition): > count +=1 > ... > try: > m = m_Switch[count-1] > except: pass > if count = 4 or iterations = 20 > > the problem is that when count = 4 m_Switch[4-1] have no value, so i use > the try..except. > > Is there a better solution to solve this problem? and, generally > speaking, the try..except block slow down the execution of the program or > not? > Use a dict: m_Switch = {1: 1, 2: 10, 3: 100} and then catch the KeyError. Don't use a bare 'except', catch the specific exception you want to catch, and don't worry about the speed unless you discover that it's real problem. From malaclypse2 at gmail.com Tue Mar 2 13:31:13 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 2 Mar 2010 13:31:13 -0500 Subject: conditional import into global namespace In-Reply-To: References: Message-ID: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> On Tue, Mar 2, 2010 at 12:46 PM, mk wrote: > Hello everyone, > > I have a class that is dependent on subprocess functionality. I would like > to make it self-contained in the sense that it would import subprocess if > it's not imported yet. > > What is the best way to proceed with this? Just import subprocess at the top of your module. If subprocess hasn't been imported yet, it will be imported when your module is loaded. If it's already been imported, your module will use the cached version that's already been imported. In other words, it sounds like Python already does what you want. You don't need to do anything special. -- Jerry From a_jtim at bellsouth.net Tue Mar 2 13:31:50 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 2 Mar 2010 10:31:50 -0800 (PST) Subject: freebsd and multiprocessing References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> Message-ID: <4079148c-3690-4c24-b3db-79f685bf8eab@q15g2000yqj.googlegroups.com> On Mar 2, 12:59?pm, Tim Arnold wrote: > On Mar 2, 11:52?am, Philip Semanchuk wrote: > > On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: > > > > Hi, > > > I'm intending to use multiprocessing on a freebsd machine (6.3 > > > release, quad core, 8cpus, amd64). I see in the doc that on this > > > platform I can't use synchronize: > > > > ImportError: This platform lacks a functioning sem_open > > > implementation, therefore, the required synchronization primitives > > > needed will not function, see issue 3770. > > > > As far as I can tell, I have no need to synchronize the processes--I > > > have several processes run separately and I need to know when they're > > > all finished; there's no communication between them and each owns its > > > own log file for output. > > > > Is anyone using multiprocessing on FreeBSD and run into any other > > > gotchas? > > > Hi Tim, > > I don't use multiprocessing but I've written two low-level IPC ? > > packages, one for SysV IPC and the other for POSIX IPC. > > > I think that multiprocessing prefers POSIX IPC (which is where ? > > sem_open() comes from). I don't know what it uses if that's not ? > > available, but SysV IPC seems a likely alternative. I must emphasize, ? > > however, that that's a guess on my part. > > > FreeBSD didn't have POSIX IPC support until 7.0, and that was sort of ? > > broken until 7.2. As it happens, I was testing my POSIX IPC code ? > > against 7.2 last night and it works just fine. > > > SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is the ? > > oldest I've tested). ISTR that by default each message queue is ? > > limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably ? > > tell you that and may even let you change it. Other than that I can't ? > > think of any SysV limitations that might bite you. > > > HTH > > Philip > > Hi Philip, > Thanks for that information. I wish I could upgrade the machine to > 7.2! alas, out of my power. ?I get the following results from sysctl: > % sysctl kern.ipc | grep msg > kern.ipc.msgseg: 2048 > kern.ipc.msgssz: 8 > kern.ipc.msgtql: 40 > kern.ipc.msgmnb: 2048 > kern.ipc.msgmni: 40 > kern.ipc.msgmax: 16384 > > I'll write some test programs using multiprocessing and see how they > go before committing to rewrite my current code. I've also been > looking at 'parallel python' although it may have the same issues.http://www.parallelpython.com/ > > thanks again, > --Tim Well that didn't work out well. I can't import either Queue or Pool from multiprocessing, so I'm back to the drawing board. I'll see now how parallel python does on freebsd. --Tim From mrkafk at gmail.com Tue Mar 2 13:33:31 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 19:33:31 +0100 Subject: Email Script In-Reply-To: <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> Message-ID: Where do you take class Email from? There's no info in your mail on this. Regards, mk From victorsubervi at gmail.com Tue Mar 2 13:37:43 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 14:37:43 -0400 Subject: Email Script In-Reply-To: <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> Message-ID: <4dc0cfea1003021037wb1a60a0y8966e00489954f48@mail.gmail.com> On Tue, Mar 2, 2010 at 12:56 PM, Victor Subervi wrote: > On Tue, Mar 2, 2010 at 11:53 AM, Victor Subervi wrote: > >> On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi wrote: >> >>> Hi; >>> I have the following code: >>> >>> def my_mail(): >>> user, passwd, db, host = login() >>> database = MySQLdb.connect(host, user, passwd, db) >>> cursor= database.cursor() >>> ourEmail1 = 'marilyn at globalsolutionsgroup.vi' >>> ourEmail1 = 'phil at globalsolutionsgroup.vi' >>> ourEmail2 = 'benoismyname at gmail.com' >>> form = cgi.FieldStorage() >>> name = form.getfirst('name', '') >>> email = form.getfirst('from', '') >>> message = form.getfirst('message', '') >>> message = 'Name: %s\nMessage: %s' % (name, message) >>> subject = 'Message from Web Site' >>> Email( >>> from_address = email, >>> to_address = ourEmail1, >>> subject = subject, >>> message = message >>> ).send() >>> Email( >>> from_address = email, >>> to_address = ourEmail2, >>> subject = subject, >>> message = message >>> ).send() >>> print 'Thank you, %s, we will get back to you shortly!
' % (name) >>> >>> This sends only the first of the two emails. Why doesn't it work to send >>> the second? What do? >>> TIA, >>> beno >>> >> >> Should I put a timer between instances of Email? >> >>> >>> Adding a timer didn't work. Do I need to explicitly close the smtp > connection before sending the next email? I don't understand why there's a > problem. > TIA, > beno > Seems like the problem was I had to import simplemail for each of the my_email functions. beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Mar 2 13:39:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Mar 2010 12:39:10 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 2010-03-02 11:59 AM, Terry Reedy wrote: > On 3/2/2010 11:34 AM, Robert Kern wrote: >> On 2010-03-01 22:55 PM, Terry Reedy wrote: >>> On 3/1/2010 7:56 PM, Patrick Maupin wrote: >>>> On Mar 1, 5:57 pm, Erik Max Francis wrote: >>>>> Patrick Maupin wrote: >>>>> This not only seriously stretching the meaning of the term "superset" >>>>> (as Python is most definitely not even remotely a superset of JSON), >>>>> but >>>> >>>> Well, you are entitled to that opinion, but seriously, if I take valid >>>> JSON, replace unquoted true with True, unquoted false with False, >>>> replace unquoted null with None, and take the quoted strings and >>>> replace occurrences of \uXXXX with the appropriate unicode, then I do, >>>> in fact, have valid Python. But don't take my word for it -- try it >>>> out! >>> >>> To me this is so strained that I do not see why why you are arguing the >>> point. So what? The resulting Python 'program' will be equivalent, I >>> believe, to 'pass'. Ie, construct objects and then discard them with no >>> computation or output. >> >> Not if you eval() rather than exec(). > > >>> eval(1) > > creates and objects and discards it, with a net result of 'pass'. > What do you think I am missing. x = eval('1') > It's reasonably well-accepted that >> JSON is very close to being a subset of Python's expression syntax with >> just a few modifications. > > It is specifically JavaScript Object Notation, which is very similar to > a subset of Python's object notation (number and string literals and > list and dict displays (but not set displays), and three named > constants). Without operators, it barely qualifies, to me, even as > 'expression syntax'. Literal expression syntax, then. -- 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 From albert at spenarnc.xs4all.nl Tue Mar 2 13:48:59 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 02 Mar 2010 18:48:59 GMT Subject: Writing an assembler in Python References: Message-ID: In article , Giorgos Tzampanakis wrote: >I'm implementing a CPU that will run on an FPGA. I want to have a >(dead) simple assembler that will generate the machine code for >me. I want to use Python for that. Are there any libraries that >can help me with the parsing of the assembly code? I have a pentium assembler in perl on my website below. (postit-fixup principle). You could borrow some idea's, if you can read perl. The main purpose is to have a very simple and straightforward assembler at the expense of ease of use. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From michaelveloz at gmail.com Tue Mar 2 14:02:08 2010 From: michaelveloz at gmail.com (Veloz) Date: Tue, 2 Mar 2010 11:02:08 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Message-ID: <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> On Mar 2, 1:18?pm, Raymond Hettinger wrote: > On Mar 2, 8:29?am, Veloz wrote: > > > Hi all > > I'm looking for a queue that I can use with multiprocessing, which has > > a peek method. > > > I've seen some discussion about queue.peek but don't see anything in > > the docs about it. > > > Does python have a queue class with peek semantics? > > Am curious about your use case? ?Why peek at something > that could be gone by the time you want to use it. > > ? val = q.peek() > ? if something_i_want(val): > ? ? ? ?v2 = q.get() ? ? ? ? # this could be different than val > > Wouldn't it be better to just get() the value and return if you don't > need it? > > ? val = q.peek() > ? if not something_i_want(val): > ? ? ? q.put(val) > > Raymond Yeah, I hear you. Perhaps queue is not the best solution. My highest level use case is this: The user visits a web page (my app is a Pylons app) and requests a "report" be created. The report takes too long to create and display on the spot, so the user expects to visit some url "later" and see if the specific report has completed, and if so, have it returned to them. At a lower level, I'm thinking of using some process workers to create these reports in the background; there'd be a request queue (into which requests for reports would go, each with an ID) and a completion queue, into which the workers would write an entry when a report was created, along with an ID matching the original request. The "peek" parts comes in when the user comes back later to see if their report has done. That is, in my page controller logic, I'd like to look through the complete queue and see if the specific report has been finished (I could tell by matching up the ID of the original request to the ID in the completed queue). If there was an item in the queue matching the ID, it would be removed. It's since occurred to me that perhaps a queue is not the best way to handle the completions. (We're ignoring the file system as a solution for the time being, and focusing on in-memory structures). I'm wondering now if a simple array of completed items wouldn't be better. Of course, all the access to the array would have to be thread/process- proof. As you pointed out, for example, multi-part operations such as "is such-and-such an ID in the list? If so, remove it and return in" would have to be treated atomically to avoid concurrency issues. Any thoughts on this design approach are welcomed :-) Michael From philip at semanchuk.com Tue Mar 2 14:28:57 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 2 Mar 2010 14:28:57 -0500 Subject: freebsd and multiprocessing In-Reply-To: <4079148c-3690-4c24-b3db-79f685bf8eab@q15g2000yqj.googlegroups.com> References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> <4079148c-3690-4c24-b3db-79f685bf8eab@q15g2000yqj.googlegroups.com> Message-ID: <83E70F2A-6024-4790-AA29-60908CB0CFC4@semanchuk.com> On Mar 2, 2010, at 1:31 PM, Tim Arnold wrote: > On Mar 2, 12:59 pm, Tim Arnold wrote: >> On Mar 2, 11:52 am, Philip Semanchuk wrote: >>> On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: >> >>>> Hi, >>>> I'm intending to use multiprocessing on a freebsd machine (6.3 >>>> release, quad core, 8cpus, amd64). I see in the doc that on this >>>> platform I can't use synchronize: >> >>>> ImportError: This platform lacks a functioning sem_open >>>> implementation, therefore, the required synchronization primitives >>>> needed will not function, see issue 3770. >> >>>> As far as I can tell, I have no need to synchronize the >>>> processes--I >>>> have several processes run separately and I need to know when >>>> they're >>>> all finished; there's no communication between them and each owns >>>> its >>>> own log file for output. >> >>>> Is anyone using multiprocessing on FreeBSD and run into any other >>>> gotchas? >> >>> Hi Tim, >>> I don't use multiprocessing but I've written two low-level IPC >>> packages, one for SysV IPC and the other for POSIX IPC. >> >>> I think that multiprocessing prefers POSIX IPC (which is where >>> sem_open() comes from). I don't know what it uses if that's not >>> available, but SysV IPC seems a likely alternative. I must >>> emphasize, >>> however, that that's a guess on my part. >> >>> FreeBSD didn't have POSIX IPC support until 7.0, and that was sort >>> of >>> broken until 7.2. As it happens, I was testing my POSIX IPC code >>> against 7.2 last night and it works just fine. >> >>> SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is >>> the >>> oldest I've tested). ISTR that by default each message queue is >>> limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably >>> tell you that and may even let you change it. Other than that I >>> can't >>> think of any SysV limitations that might bite you. >> >>> HTH >>> Philip >> >> Hi Philip, >> Thanks for that information. I wish I could upgrade the machine to >> 7.2! alas, out of my power. I get the following results from sysctl: >> % sysctl kern.ipc | grep msg >> kern.ipc.msgseg: 2048 >> kern.ipc.msgssz: 8 >> kern.ipc.msgtql: 40 >> kern.ipc.msgmnb: 2048 >> kern.ipc.msgmni: 40 >> kern.ipc.msgmax: 16384 >> >> I'll write some test programs using multiprocessing and see how they >> go before committing to rewrite my current code. I've also been >> looking at 'parallel python' although it may have the same issues.http://www.parallelpython.com/ >> >> thanks again, >> --Tim > > Well that didn't work out well. I can't import either Queue or Pool > from multiprocessing, so I'm back to the drawing board. I'll see now > how parallel python does on freebsd. Sorry to hear that didn't work for you. Should you need to get down to the nuts & bolts level, my module for SysV IPC is here: http://semanchuk.com/philip/sysv_ipc/ Good luck with Parallel Python, Philip From pmaupin at gmail.com Tue Mar 2 14:30:32 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 2 Mar 2010 11:30:32 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On Mar 2, 11:59?am, Terry Reedy wrote: > To me, comparing object notation with programming language is not > helpful to the OP's purpose. Yes, I agree, it was a distraction. I fell into the trap of responding to the ludicrous claim that "if X is a superset of Y, then X cannot possibly look better than Y" (a claim made by multiple people all thinking it was clever) by showing that Y has other supersets that do in fact look better than Y. In doing this, I made the mistake of choosing a superset of an analogue to Y, rather than to Y itself. When called out on it, I showed that, in fact, the actual X that IS a superset of Y can be used in a way that looks better. However, you are right that JSON is such a small subset of JS that it's really pretty ridiculous to even compare them, but that still makes the point that the original argument I was trying to refute is completely specious. In retrospect, though, I should have chosen a better way to make that point, because I let myself get caught up in making and then defending a flippant statement that I don't really care about one way or the other. > His main claim is that JSON can be usefully > extended but that YAML is too much, so that perhaps he, with help, can > find a 'sweet spot' in between. An excellent summary of my position. Thanks, Pat From python at mrabarnett.plus.com Tue Mar 2 14:44:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 19:44:53 +0000 Subject: Queue peek? In-Reply-To: <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: <4B8D6AB5.8010408@mrabarnett.plus.com> Veloz wrote: > On Mar 2, 1:18 pm, Raymond Hettinger wrote: >> On Mar 2, 8:29 am, Veloz wrote: >> >>> Hi all >>> I'm looking for a queue that I can use with multiprocessing, which has >>> a peek method. >>> I've seen some discussion about queue.peek but don't see anything in >>> the docs about it. >>> Does python have a queue class with peek semantics? >> Am curious about your use case? Why peek at something >> that could be gone by the time you want to use it. >> >> val = q.peek() >> if something_i_want(val): >> v2 = q.get() # this could be different than val >> >> Wouldn't it be better to just get() the value and return if you don't >> need it? >> >> val = q.peek() >> if not something_i_want(val): >> q.put(val) >> >> Raymond > > Yeah, I hear you. Perhaps queue is not the best solution. My highest > level use case is this: The user visits a web page (my app is a > Pylons app) and requests a "report" be created. The report takes too > long to create and display on the spot, so the user expects to visit > some url "later" and see if the specific report has completed, and if > so, have it returned to them. > > At a lower level, I'm thinking of using some process workers to create > these reports in the background; there'd be a request queue (into > which requests for reports would go, each with an ID) and a completion > queue, into which the workers would write an entry when a report was > created, along with an ID matching the original request. > > The "peek" parts comes in when the user comes back later to see if > their report has done. That is, in my page controller logic, I'd like > to look through the complete queue and see if the specific report has > been finished (I could tell by matching up the ID of the original > request to the ID in the completed queue). If there was an item in the > queue matching the ID, it would be removed. > > It's since occurred to me that perhaps a queue is not the best way to > handle the completions. (We're ignoring the file system as a solution > for the time being, and focusing on in-memory structures). I'm > wondering now if a simple array of completed items wouldn't be better. > Of course, all the access to the array would have to be thread/process- > proof. As you pointed out, for example, multi-part operations such as > "is such-and-such an ID in the list? If so, remove it and return in" > would have to be treated atomically to avoid concurrency issues. > > Any thoughts on this design approach are welcomed :-) > A set of completed reports, or a dict with the ID as the key? The advantage of a dict is that the value could contain several bits of information, such as when it was completed, the status (OK or failed), etc. You might want to wrap it in a class with locks (mutexes) to ensure it's threadsafe. From martin.hellwig at dcuktec.org Tue Mar 2 14:58:22 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 02 Mar 2010 19:58:22 +0000 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: On 03/02/10 19:44, MRAB wrote: > information, such as when it was completed, the status (OK or failed), > etc. You might want to wrap it in a class with locks (mutexes) to ensure > it's threadsafe. What actually happens if multiple threads at the same time, write to a shared dictionary (Not using the same key)? I would think that if the hashing part of the dictionary has some sort of serialization (please forgive me if I misuse a term) it should 'just work'(tm)? -- mph From marduk at python.net Tue Mar 2 15:22:27 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 15:22:27 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: References: <1267539898.477222.7.camel@necropolis> Message-ID: <1267561347.4507.5.camel@necropolis> On Tue, 2010-03-02 at 13:25 -0500, Terry Reedy wrote: > To get help, or report a bug, for something like this, be as specific as > possible. 'Linux' may be too generic. This is on Python on Gentoo Linux x64 with kernel 2.6.33. > > > However, with CPython 3.1 I get: > > > > input = os.fdopen(fd).read() > > IOError: [Errno 5] Input/output error > > > > Is there something wrong in Python 3.1? Is this the correct way to do > > this (run a process in a pseudo-tty and read it's output) or is there > > another way I should/could be doing this? > > No idea, however, the first thing I would do is call the .fdopen and > .read methods separately (on separate lines) to isolate which is raising > the error. The exception occurs on the read() method. From marduk at python.net Tue Mar 2 15:22:58 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 15:22:58 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <4B8D4BB8.8020909@mrabarnett.plus.com> References: <1267539898.477222.7.camel@necropolis> <4B8D4BB8.8020909@mrabarnett.plus.com> Message-ID: <1267561378.4507.6.camel@necropolis> On Tue, 2010-03-02 at 17:32 +0000, MRAB wrote: > The documentation also mentions the 'pty' module. Have you tried that > instead? I haven't but I'll give it a try. Thanks. -a From daniel at stutzbachenterprises.com Tue Mar 2 15:33:33 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Tue, 2 Mar 2010 14:33:33 -0600 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: On Tue, Mar 2, 2010 at 1:58 PM, Martin P. Hellwig < martin.hellwig at dcuktec.org> wrote: > What actually happens if multiple threads at the same time, write to a > shared dictionary (Not using the same key)? > All of Python's built-in types are thread safe. Both updates will happen. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Tue Mar 2 15:41:44 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 21:41:44 +0100 Subject: conditional import into global namespace In-Reply-To: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> References: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> Message-ID: Jerry Hill wrote: > Just import subprocess at the top of your module. If subprocess > hasn't been imported yet, it will be imported when your module is > loaded. If it's already been imported, your module will use the > cached version that's already been imported. > > In other words, it sounds like Python already does what you want. You > don't need to do anything special. Oh, thanks! Hmm it's different than dealing with packages I guess -- IIRC, in packages only code in package's __init__.py was executed? Regards, mk From popuser at christest2.dc.k12us.com Tue Mar 2 15:57:36 2010 From: popuser at christest2.dc.k12us.com (Pop User) Date: Tue, 02 Mar 2010 15:57:36 -0500 Subject: freebsd and multiprocessing In-Reply-To: <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> Message-ID: <4B8D7BC0.6010109@christest2.dc.k12us.com> On 3/2/2010 12:59 PM, Tim Arnold wrote: > > I'll write some test programs using multiprocessing and see how they > go before committing to rewrite my current code. I've also been > looking at 'parallel python' although it may have the same issues. > http://www.parallelpython.com/ > parallelpython works for me on FreeBSD 6.2. From matt at sidefx.com Tue Mar 2 15:59:15 2010 From: matt at sidefx.com (Matt Chaput) Date: Tue, 02 Mar 2010 15:59:15 -0500 Subject: Multiprocessing problem Message-ID: <4B8D7C23.7050905@sidefx.com> Hi, I'm having a problem with the multiprocessing package. I'm trying to use a simple pattern where a supervisor object starts a bunch of worker processes, instantiating them with two queues (a job queue for tasks to complete and an results queue for the results). The supervisor puts all the jobs in the "job" queue, then join()s the workers, and then pulls all the completed results off the "results" queue. (I don't think I can just use something like Pool.imap_unordered for this because the workers need to be objects with state.) Here's a simplified example: http://pastie.org/850512 The problem is that seemingly randomly, but almost always, the worker processes will deadlock at some point and stop working before they complete. This will leave the whole program stalled forever. This seems more likely the more work each worker does (to the point where adding the time.sleep(0.01) as seen in the example code above guarantees it). The problem seems to occur on both Windows and Mac OS X. I've tried many random variations of the code (e.g. using JoinableQueue, calling cancel_join_thread() on one or both queues even though I have no idea what it does, etc.) but keep having the problem. Am I just using multiprocessing wrong? Is this a bug? Any advice? Thanks, Matt From rfritz at u.washington.edu Tue Mar 2 16:14:50 2010 From: rfritz at u.washington.edu (R Fritz) Date: Tue, 2 Mar 2010 13:14:50 -0800 Subject: cpan for python? References: Message-ID: On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: > > On Feb 28, 2010, at 9:28 AM, Someone Something wrote: > >> Is there something like cpan for python? I like python's syntax, but >> Iuse perl because of cpan and the tremendous modules that it has. -- > > Please search the mailing list archives. > > This subject has been discussed to absolute death. But somehow the question is not in the FAQ, though the answer is. See: -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From ben+python at benfinney.id.au Tue Mar 2 16:22:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 08:22:40 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <20100302183527.47c6e8f5@geekmail.INVALID> Message-ID: <878waazae7.fsf@benfinney.id.au> Andreas Waldenburger writes: > Don't get me wrong; our whole system is more fragile than I find > comfortable. But I guess getting 10ish different parties around the > globe to work in complete unison is quite a feat, and I'm surprised it > even works as it is. But it does, and I'm glad we don't have to > micromanage other people's code. It's rather odd that you think of ?require general quality standards, independently measurable and testable? to be ?micromanaging?. I guess that when even the *customers* will resist implementing such quality expectations, it's little surprise that the vendors continue to push out such shoddy work on their customers. -- \ ?Why am I an atheist? I ask you: Why is anybody not an atheist? | `\ Everyone starts out being an atheist.? ?Andy Rooney, _Boston | _o__) Globe_ 1982-05-30 | Ben Finney From davea at ieee.org Tue Mar 2 16:23:34 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 02 Mar 2010 16:23:34 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> <4B8D3A3A.8030501@optimum.net> Message-ID: <4B8D81D6.4070001@ieee.org> Terry Reedy wrote: > On 3/2/2010 11:18 AM, John Posner wrote: >> On 3/2/2010 10:19 AM, Roy Smith wrote: >>> >>> Somewhat sadly, in my case, I can't even machine process the header >>> file. I don't, strictly speaking, have a header file. What I have is >>> a PDF which documents what's in the header file, and I'm manually re- >>> typing the data out of that. Sigh. > > There are Python modules to read/write pdf. > >> Here's an idea, perhaps too obvious, to minimize your keystrokes: >> >> 1. Create a text file with the essential data: >> >> XYZ_FOO 0 The foo property >> XYZ_BAR 1 The bar property >> XYZ_BAZ 2 reserved for future use >> >> 2. Use a Python script to convert this into the desired code: >> >> declare('XYZ_FOO', 0, "The foo property") >> declare('XYZ_BAR', 1, "The bar property") >> declare('XYZ_BAZ', 2, "reserved for future use") >> >> Note: >> >> >>> s >> 'XYZ_FOO 0 The foo property' >> >>> s.split(None, 2) >> ['XYZ_FOO', '0', 'The foo property'] > > Given that set of triples is constant, I would think about having the > Python script do the computation just once, instead of with every > inport. In other words, the script should *call* the declare function > and then write out the resulting set of dicts either to a .py or > pickle file. > > tjr > > There have been lots of good suggestions in this thread. Let me give you my take: 1) you shouldn't want to clutter up the global dictionary of your main processing module. There's too much risk of getting a collision, either with the functions you write, or with some builtin. That's especially true if you might later want to use a later version of that pdf file. Easiest solution for your purposes, make it a separate module. Give it a name like defines, and in your main module, you use import defines print defines.XYZ_FOO And if that's too much typing, you can do: import defines as I print I.XYZ_FOO Next problem is to parse that pdf file. One solution is to use a pdf library. But another is to copy/paste it into a text file, and parse that. Assuming it'll paste, and that the lines you want are recognizable (eg. they all begin as #define), the parsing should be pretty easy. The results of the parsing is a file defines.py Now, if the pdf ever changes, rerun your parsing program. But don't run it every time your application runs. If the pdf file were changing often, then I'd have a different answer: 2) define an empty class, just as a placeholder, and make one instance I Populate a class instance I with setattrib() calls, but access it with direct syntax, same as our first example. DaveA From ben+python at benfinney.id.au Tue Mar 2 16:25:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 08:25:13 +1100 Subject: Broken references in postings References: Message-ID: <874okyza9y.fsf@benfinney.id.au> Grant Edwards writes: > Or is it just individual news/mail clients that are broken? This, I believe. Many clients mess up the References and In-Reply-To fields, in the face of many years of complaint to the vendors. Most free-software clients get it right, AFAICT. -- \ ?Contentment is a pearl of great price, and whosoever procures | `\ it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.? ?J. Balguy | Ben Finney From dont.spam.holgerm1969 at gmx.de Tue Mar 2 16:26:59 2010 From: dont.spam.holgerm1969 at gmx.de (Holger Mueller) Date: Tue, 2 Mar 2010 22:26:59 +0100 Subject: Writing an assembler in Python References: Message-ID: Giorgos Tzampanakis wrote: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. I want to use Python for that. Are there any libraries that > can help me with the parsing of the assembly code? Why coding assembler if you can type in hexdumps... scnr Holger -- http://www.kati-und-holger.de/holgersblog.php From MLMDev at Comcast.net Tue Mar 2 16:48:08 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Tue, 2 Mar 2010 16:48:08 -0500 Subject: CGI, POST, and file uploads Message-ID: <5F601006-5DCE-4353-BD04-DFABDFA8C5D2@Comcast.net> Can someone tell me how to upload the contents of a (relatively small) file using an HTML form and CGI in Python 3.1? As far as I can tell from a half-day of experimenting, browsing, and searching the Python issue tracker, this is broken. Very simple example:



cgi-test.py: #!/usr/local/bin/python3 import cgi import sys form = cgi.FieldStorage() print(form.getfirst('contents'), file=sys.stderr) print('done') I run a CGI server with: #!/usr/bin/env python3 from http.server import HTTPServer, CGIHTTPRequestHandler HTTPServer(('', 9000), CGIHTTPRequestHandler).serve_forever() What happens is that the upload never stops. It works in 2.6. If I cancel the upload from the browser, I get the following output, so I know that basically things are working; the cgi script just never finishes reading the POST input: localhost - - [02/Mar/2010 16:37:36] "POST /cgi/cgi-test.py HTTP/1.1" 200 - <<>> ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 55779) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 307, in process_request self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 614, in __init__ self.handle() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 352, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 346, in handle_one_request method() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 868, in do_POST self.run_cgi() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 1045, in run_cgi if not self.rfile.read(1): File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socket.py", line 214, in readinto return self._sock.recv_into(b) socket.error: [Errno 54] Connection reset by peer ---------------------------------------- From usenot at geekmail.INVALID Tue Mar 2 16:51:56 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 22:51:56 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> Message-ID: <20100302225156.67171851@geekmail.INVALID> On Tue, 02 Mar 2010 19:05:25 +0100 Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: > > > > I had hoped that everyone just read it, went like "Oh geez.", > > smiled it off with a hint of lesson learned and got back to > > whatever it was they were doing. Alas, I was wrong ... and I'm > > sorry. > > > There's something wrong saying that stupid people write working code > that totally satisfies your needs. Don't you agree ? ;-) > No, in fact I don't. It works. They are supposed to make it work. And that's what they do. Whether or not they put their docstrings in the place they should does not change that their code works. Sorry, you guys drained all the funny out of me. /W -- INVALID? DE! From mrkafk at gmail.com Tue Mar 2 16:54:39 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 22:54:39 +0100 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: Daniel Stutzbach wrote: > On Tue, Mar 2, 2010 at 1:58 PM, Martin P. Hellwig > > wrote: > > What actually happens if multiple threads at the same time, write to > a shared dictionary (Not using the same key)? > All of Python's built-in types are thread safe. Both updates will happen. No need to use synchro primitives like locks? I know that it may work, but that strikes me as somehow wrong... I'm used to using things like Lock().acquire() and Lock().release() when accessing shared data structures, whatever they are. Although trying to do the "right thing" may indeed get one in trouble in case of deadlock caused by a bug in one's own program. Regards, mk From eike.welk at gmx.net Tue Mar 2 17:00:29 2010 From: eike.welk at gmx.net (Eike Welk) Date: Tue, 02 Mar 2010 23:00:29 +0100 Subject: Method / Functions - What are the differences? References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> Message-ID: John Posner wrote: > I've updated the text at this location: > > > http://cl1p.net/bruno_0301.rst/ I think this is a very useful writeup! It would be perfect with a little bit of introduction that says: 1. - What it is: "The rough details of method look-up"; 2. - which contains some of the questions that that made that authors write the text. This way people with similar questions can find it with Google. Additionally the link to the relevant section in the Python documentation would be great. I can't find it! A link to an article about the details of class creation and metaclasses would be good too. Thanks for writing this great little text, Eike. From jkrukoff at ltgc.com Tue Mar 2 17:08:43 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Tue, 02 Mar 2010 15:08:43 -0700 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: <1267567723.4101.28.camel@localhost.localdomain> On Tue, 2010-03-02 at 22:54 +0100, mk wrote: > No need to use synchro primitives like locks? > > I know that it may work, but that strikes me as somehow wrong... I'm > used to using things like Lock().acquire() and Lock().release() when > accessing shared data structures, whatever they are. This is one of those places where the GIL is a good thing, and makes your life simpler. You could consider it that the interpreter does the locking for you for such primitive operations, if you like. -- John Krukoff Land Title Guarantee Company From usenot at geekmail.INVALID Tue Mar 2 17:19:09 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 23:19:09 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <20100302183527.47c6e8f5@geekmail.INVALID> <878waazae7.fsf@benfinney.id.au> Message-ID: <20100302231909.6a5bad2d@geekmail.INVALID> On Wed, 03 Mar 2010 08:22:40 +1100 Ben Finney wrote: > Andreas Waldenburger writes: > > > Don't get me wrong; our whole system is more fragile than I find > > comfortable. But I guess getting 10ish different parties around the > > globe to work in complete unison is quite a feat, and I'm surprised > > it even works as it is. But it does, and I'm glad we don't have to > > micromanage other people's code. > > It's rather odd that you think of ?require general quality standards, > independently measurable and testable? to be ?micromanaging?. > I should know better than to argue these things, but I don't. Hmph. We demand testable quality standards, but not of their code. We demand it of their software. We say *what* we want, they decide *how* they'll do it. Noncompliance will be fined, by a contractually agreed amount. Everything beyond that is micromanaging and detracts workforce from the stuff *we* have to do. We are in exactly the same kind of bond with a company that buys our system (and support). I have yet to see any one of them demand to see how we write our code. Why should they care? (Rhetorical question, I refuse to discuss this any further.) > I guess that when even the *customers* will resist implementing such > quality expectations, it's little surprise that the vendors continue > to push out such shoddy work on their customers. > When I'm building bicycles I can go to the trouble of going by what method of galvanization my tires are produced. Or I save myself the trouble and just take the best offer and hold them responsible when they don't deliver on their promise. Both possible, both work, and both appropriate in certain situations. You can keep discussing if you want, I've said more than I was hoping to. /W -- INVALID? DE! From albert at spenarnc.xs4all.nl Tue Mar 2 17:38:11 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 02 Mar 2010 22:38:11 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: In article , Mel wrote: >Jean-Michel Pichavant wrote: >> Andreas Waldenburger wrote: >>> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >>> wrote: >>>> Reminiscent of: >>>> mov AX,BX ; Move the contents of BX into AX > >>> Well, there might be some confusion there as to what gets moved where, >>> wouldn't you say? I guess this goes away after a couple of months, >>> though. > >> I agree to that statement, I was surprised that mov AX,BX assumes that >> BX is the source, and AX the destination. I never programmed in >> assembler though. > >You could think of it as a not bad use of the design principle "Clear The >Simple Stuff Out Of The Way First". Destinations are commonly a lot simpler >than sources -- just as in Python assignment statements. So you can tell >more or less at a glance what's going to be changed, then get into the deep >analysis to find what it's going to be changed to. The real background is that a very long time ago at Intel the first guy that wrote an assembler, got it "wrong", i.e. violated the conventions established already at the time. No nothing clever, nothing conscious, just reinventing the wheel badly. Next time you tell me that the MSDOS "file" system was well thought out :-) > Mel. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From verace at bohlsenrestaurants.com Tue Mar 2 17:39:46 2010 From: verace at bohlsenrestaurants.com (Sugar Dining Den and Social Club) Date: Tue, 02 Mar 2010 14:39:46 -0800 Subject: Verace Hospitality Late Night Dinner Message-ID: An HTML attachment was scrubbed... URL: From tomf.sessile at gmail.com Tue Mar 2 17:47:36 2010 From: tomf.sessile at gmail.com (TomF) Date: Tue, 2 Mar 2010 14:47:36 -0800 Subject: cpan for python? References: Message-ID: <2010030214473616807-tomfsessile@gmailcom> On 2010-03-02 13:14:50 -0800, R Fritz said: > On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: >> >> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: >> >>> Is there something like cpan for python? I like python's syntax, but >>> Iuse perl because of cpan and the tremendous modules that it has. -- >> >> Please search the mailing list archives. >> >> This subject has been discussed to absolute death. > > But somehow the question is not in the FAQ, though the answer is. See: > > There > is also a program called cpan, distributed with Perl. It is used for searching, downloading, installing and testing modules from the CPAN repository. It's far more extensive than setuptools. AFAIK the python community has developed nothing like it. -Tom From aahz at pythoncraft.com Tue Mar 2 17:53:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 14:53:32 -0800 Subject: Broken references in postings References: Message-ID: In article , Grant Edwards wrote: > >I've noticed recently that a lot of the "refernces" and >"in-reply-to" headers in c.l.p are broken, resulting in the >inability to move from a child to a parent in a tree. One issue with the mail/news gateway is that (unless it's been fixed) In-Reply-To: does not get copied to References: (which is what most newsreaders need to thread properly). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Tue Mar 2 17:59:14 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 14:59:14 -0800 Subject: Is this secure? References: Message-ID: In article , Robert Kern wrote: >On 2010-02-28 01:28 AM, Aahz wrote: >> In article, >> Robert Kern wrote: >>> >>> If you are storing the password instead of making your user remember >>> it, most platforms have some kind of keychain secure password >>> storage. I recommend reading up on the APIs available on your targeted >>> platforms. >> >> Are you sure? I haven't done a lot of research, but my impression was >> that Windows didn't have anything built in. > >You're right, not built-in, but Windows does provide enough crypto >services for a cross-platform Python implementation to be built: > > http://pypi.python.org/pypi/keyring Thanks you! That's a big help! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Tue Mar 2 18:01:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 15:01:31 -0800 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> Message-ID: In article <20100302225156.67171851 at geekmail.INVALID>, Andreas Waldenburger wrote: > >Sorry, you guys drained all the funny out of me. Don't let a few nitpickers do that! I thought it was funny; after that, just remember that every Usenet thread drifts away from *your* point. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From matt at whoosh.ca Tue Mar 2 18:04:09 2010 From: matt at whoosh.ca (Matt Chaput) Date: Tue, 02 Mar 2010 18:04:09 -0500 Subject: Multiprocessing problem In-Reply-To: <4B8D7C23.7050905@sidefx.com> References: <4B8D7C23.7050905@sidefx.com> Message-ID: <4B8D9969.60801@whoosh.ca> On 3/2/2010 3:59 PM, Matt Chaput wrote: > I'm trying to use a simple pattern where a supervisor object starts a > bunch of worker processes, instantiating them with two queues (a job > queue for tasks to complete and an results queue for the results). The > supervisor puts all the jobs in the "job" queue, then join()s the > workers, and then pulls all the completed results off the "results" queue. > Here's a simplified example: > > http://pastie.org/850512 I should mention that if I change my code so the workers just pull things off the job queue but don't put any results on the result queue until after they see the None sentinel in the job queue and break out of the loop, I don't get the deadlock. So it's something about getting from one queue and putting to another queue in close proximity. Hopefully I'm making a simple mistake with how I'm using the library and it'll be easy to fix... Thanks, Matt From invalid at invalid.invalid Tue Mar 2 18:12:17 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Mar 2010 23:12:17 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: On 2010-03-02, Albert van der Horst wrote: > No nothing clever, nothing conscious, just reinventing the wheel > badly. > > Next time you tell me that the MSDOS "file" system was well thought > out :-) Just a mediocre copy of the CP/M filesystem, which was in turn copied from DEC's RSTS or RSX. -- Grant Edwards grant.b.edwards Yow! Kids, don't gross me at off ... "Adventures with gmail.com MENTAL HYGIENE" can be carried too FAR! From steve at holdenweb.com Tue Mar 2 18:24:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 18:24:51 -0500 Subject: Email Script In-Reply-To: <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi This sends only the first of the two emails. Why doesn't it work to > send the second? What do? > TIA, > beno > > > Should I put a timer between instances of Email? > > Np. http://en.wikipedia.org/wiki/Cargo_cult_programming regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Tue Mar 2 18:32:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Mar 2010 23:32:52 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> Message-ID: <4b8da024$0$8783$c3e8da3@news.astraweb.com> On Tue, 02 Mar 2010 22:51:56 +0100, Andreas Waldenburger wrote: > On Tue, 02 Mar 2010 19:05:25 +0100 Jean-Michel Pichavant > wrote: > >> Andreas Waldenburger wrote: >> > >> > I had hoped that everyone just read it, went like "Oh geez.", smiled >> > it off with a hint of lesson learned and got back to whatever it was >> > they were doing. Alas, I was wrong ... and I'm sorry. >> > >> There's something wrong saying that stupid people write working code >> that totally satisfies your needs. Don't you agree ? ;-) >> > No, in fact I don't. > > It works. They are supposed to make it work. And that's what they do. > Whether or not they put their docstrings in the place they should does > not change that their code works. > > Sorry, you guys drained all the funny out of me. Most of the customers I've worked for have insisted we follow best practices. Sometimes they even invent their own best practices that nobody has even heard of, and that's fun (not). You're the first one I've ever met that bitches publicly that your contractors don't follow best practice, but objects strenuously to the idea that you are right to care about that they don't. Wow. Just... wow. P.S. next time you want some not-quite-best-practice Python code written, send me an email off-list. I'll be more than happy to do not-quite-best- practice work for you. *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Mar 2 18:34:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Mar 2010 23:34:02 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <20100302183527.47c6e8f5@geekmail.INVALID> <878waazae7.fsf@benfinney.id.au> <20100302231909.6a5bad2d@geekmail.INVALID> Message-ID: <4b8da06a$0$8783$c3e8da3@news.astraweb.com> On Tue, 02 Mar 2010 23:19:09 +0100, Andreas Waldenburger wrote: > We demand testable quality standards, but not of their code. We demand > it of their software. We say *what* we want, they decide *how* they'll > do it. Noncompliance will be fined, by a contractually agreed amount. > Everything beyond that is micromanaging and detracts workforce from the > stuff *we* have to do. You specify the Functional Requirements but not the Design Requirements. Fair enough. > We are in exactly the same kind of bond with a company that buys our > system (and support). I have yet to see any one of them demand to see > how we write our code. Why should they care? (Rhetorical question, I > refuse to discuss this any further.) It is true that most people don't care how code is written. But they *should* care, because how it is written directly impacts the quality of the code. Saying "I don't care how it is written" is precisely the same as saying "I don't care how reliable, secure or efficient the code is". Of course people do this. People also inhale carcinogenic chemicals, vote bad laws into place, drive too fast, ingest noxious chemicals, and spend hours on Usenet debating the number of angels that can dance on the head of a pin. >> I guess that when even the *customers* will resist implementing such >> quality expectations, it's little surprise that the vendors continue to >> push out such shoddy work on their customers. >> > When I'm building bicycles I can go to the trouble of going by what > method of galvanization my tires are produced. Or I save myself the > trouble and just take the best offer and hold them responsible when they > don't deliver on their promise. Both possible, both work, and both > appropriate in certain situations. Many years ago, I assisted a professional building architect design a software system for specifying the requirements of major architectural works such as bridges and high-rise buildings. They specify *everything*, right down to the type of sand used in the concrete and the grade of steel used for the frame. When using the wrong type of sand could mean that the bridge collapses in 35 years, you soon learn that, yes, you damn well better care. -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Mar 2 18:36:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Mar 2010 23:36:21 GMT Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> On Tue, 02 Mar 2010 11:30:32 -0800, Patrick Maupin wrote: > On Mar 2, 11:59?am, Terry Reedy wrote: > >> To me, comparing object notation with programming language is not >> helpful to the OP's purpose. > > Yes, I agree, it was a distraction. I fell into the trap of responding > to the ludicrous claim that "if X is a superset of Y, then X cannot > possibly look better than Y" (a claim made by multiple people all > thinking it was clever) by showing that Y has other supersets that do in > fact look better than Y. It's not ludicrous. You claim that: (1) JSON is too hard to edit; (2) RSON is a superset of JSON (the PEP even explicitly says "All valid UTF-8 encoded JSON files are also valid RSON files"); (3) which implies that all JSON files are valid RSON files. If you reject the logical conclusion that RSON must therefore also be too hard to edit, then perhaps JSON isn't too hard to edit either. You seem to be taking the position that if you start with a config file config.json, it is "too hard to edit", but then by renaming it to config.rson it magically becomes easier to edit. That *is* ludicrous. Perhaps what you mean to say is that JSON *can be* (not is) too hard to edit, and RSON *can be* too hard to edit too, but RSON has additional benefits, including being easier to edit *sometimes*. So far you have done (in my opinion) a really poor job of explaining what those benefits are. You've bad-mouthed existing config formats, then tried to convince us that RSON is almost exactly the same as one of those formats apart from a couple of trivial changes of spelling (True for true, etc.). In my opinion, if you're going to get any traction with RSON, you need to demonstrate some examples of where JSON actually is hard to write, and show how RSON makes it easier. It's not good enough showing badly written JSON, it has to be examples that can't be written less badly given the constraints of JSON. -- Steven From ben+python at benfinney.id.au Tue Mar 2 18:42:04 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 10:42:04 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> Message-ID: <877hpuxpdf.fsf@benfinney.id.au> Andreas Waldenburger writes: > It works. They are supposed to make it work. And that's what they do. > Whether or not they put their docstrings in the place they should does > not change that their code works. No-one has been denying that. What the quality of their source code *does* affect, though, is its maintainability over time ? especially in the inevitable event that the relationship with you as their customer comes to an end. The arguments I've seen here in this sub-thread have been in favour of customers demanding that the code meets functional requirements *and* soruce code quality requirements. Just as customers should demand both that a building be built to do its job well, *and* that its architectural plans meet measurable, testable industry standards of quality for independent re-use at some indeterminate later date. If we don't demand such things as customers of program developers, we deserve what programs we get. -- \ ?Special today: no ice cream.? ?mountain inn, Switzerland | `\ | _o__) | Ben Finney From marduk at python.net Tue Mar 2 18:45:49 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 18:45:49 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <4B8D4BB8.8020909@mrabarnett.plus.com> References: <1267539898.477222.7.camel@necropolis> <4B8D4BB8.8020909@mrabarnett.plus.com> Message-ID: <1267573549.495250.0.camel@centar> On Tue, 2010-03-02 at 17:32 +0000, MRAB wrote: > The documentation also mentions the 'pty' module. Have you tried that > instead? I tried to use pty.fork() but it also produces the same error. I also tried passing 'r', and 'rb' to fdopen() but it didn't make any difference. -a From marduk at python.net Tue Mar 2 18:59:00 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 18:59:00 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <1267561347.4507.5.camel@necropolis> References: <1267539898.477222.7.camel@necropolis> <1267561347.4507.5.camel@necropolis> Message-ID: <1267574340.495250.4.camel@centar> This appears to be Issue 5380[1] which is still open. I've cc'ed myself to that issue. [1] http://bugs.python.org/issue5380 From marketing at rbcom.it Tue Mar 2 19:08:19 2010 From: marketing at rbcom.it (RBCOM MEDIA GROUP) Date: Wed, 3 Mar 2010 01:08:19 +0100 Subject: UNA VETRINA SUL MONDO Message-ID: <00e99839$40240$efd90474441088@raffaele-6a745d> ITALIA WEEKEND

Pregiatissima Azienda,
Sottoponiamo alla Vostra cortese attenzione la rivista di turismo, cultura, arte e spettacolo “ITALIA WEEKEND”.

Resa ancora più bella nella sua nuova veste grafica essa rappresenta un magazine completo da cui trarre idee, spunti e suggerimenti sugli innumerevoli itinerari d’arte, percorsi turistici ed enogastronomici del nostro Paese.

Le sue rubriche, redatte anche in lingua inglese, affrontano temi interessanti volti a soddisfare la curiosità delle lettrici e dei lettori che amano la nostra Penisola.

È distribuita gratuitamente su tutto il territorio nazionale e, in particolar modo nei luoghi più famosi d’Italia.

È presente, inoltre, nelle molteplici manifestazioni organizzate nel corso dell’anno nelle varie regioni italiane; in tali occasioni la rivista, è distribuita a tutto il pubblico presente, dando di conseguenza una maggiore visibilità agli inserzionisti.

La capillarità della distribuzione sul territorio italiano, supportata anche da una versione on line che raggiunge centinaia di migliaia di utenti anche all'estero, e la peculiarità della rivista volta a un settore strategico per l’intero Paese, continua a suscitare ampi consensi da parte di numerose aziende e operatori economici del settore turistico.

Il magazine, oltre ad avere i normali spazi pubblicitari, dà la possibilità agli inserzionisti di poter disporre, grazie alla cellofanatura esterna, d’ulteriori strumenti promozionali quali: brochure, dvd e così via.

Nella speranza di potervi annoverare tra i nostri inserzionisti, e ringraziandovi per l’attenzione prestataci, porgiamo i nostri più cordiali saluti.

ulteriori informazioni su www.italiainweekend.it/iwk
 

Ai sensi del D.Lgs 196/2003 informiamo che il Suo indirizzo e-mail è stato reperito attraverso
fonti di pubblico dominio o attraverso e-mail o adesioni da noi ricevute.
Tutti i destinatari della mail sono in copia nascosta (D.Lgs 196/2003). Qualora il messaggio pervenga
anche a persona non interessata, preghiamo volercelo cortesemente segnalare rispondendo
CANCELLAMI all'indirizzo cancellami at italiainweekend.it precisando l'indirizzo
che si desidera sia immediatamente rimosso dalla mailing list. Tendiamo ad
evitare fastidiosi MULTIPLI INVII, ma laddove ciò avvenisse preghiamo di
segnalarcelo e ce ne scusiamo sin d'ora. Grazie.
From news123 at free.fr Tue Mar 2 19:30:26 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 01:30:26 +0100 Subject: Image.frombuffer and warning Message-ID: <4b8dada2$0$6285$426a74cc@news.free.fr> Hi, I am using the PIL function from_buffer in python 2.6.4 I am having the line im2 = Image.frombuffer('L',(wx,wy),buf) I receive the warning: > ./pytest.py:63: RuntimeWarning: the frombuffer defaults may change in a future release; for portability, change the call to read: > frombuffer(mode, size, data, 'raw', mode, 0, 1) > im2 = Image.frombuffer('L',(wx,wy),buf) Naively I assumed, that changing my code to im2 = Image.frombuffer('L',(wx,wy),buf,'raw','L',0,1) should fix the issue: However I receive exactly the same error as before. What am I doing wrong? thanks a lot in advance and bye N From no.email at nospam.invalid Tue Mar 2 19:33:50 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 02 Mar 2010 16:33:50 -0800 Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: <7x4okyb5w1.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > (3) which implies that all JSON files are valid RSON files. > > If you reject the logical conclusion that RSON must therefore also be too > hard to edit, then perhaps JSON isn't too hard to edit either. I would say that JSON is hard to edit because, among other things, it has no comment syntax. It's quite difficult to maintain a hand-edited JSON file, or figure out what to edit into it, if it can't have any comments in it describing what it's doing. JSON is a serialization format for machine to machine communication, not intended for hand editing. Simply adding a comment syntax to JSON would go a long way towards making it easier to edit. From news123 at free.fr Tue Mar 2 19:38:21 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 01:38:21 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back Message-ID: <4b8daf7d$0$2868$426a74cc@news.free.fr> Hi, I created a grayscale image with PIL. Now I would like to write a C function, which reads a;most all pixels and will modify a few of them. My current approach is: - transform the image to a string() - create a byte array huge enough to contain the resulting image - call my c_function, which copies over the entire image in order to modify a few pixels How can I achieve this with the least amount of copies? ########## Python code snippet ################ im = Image.open('grayscalefile_onebyteperpixel') wx,wy = im.size # create a string in order to pass it to my function # I'm afraid this involves copying so want to get rid of it im_as_string = im.tostring() # create a byte array in order to store my result new_img_array = array.array('B', [0]*(wx*wy) ) # my function which should just change some pixels has # to copy all unmodified pixels my_extension.my_func(wx,wy,im_as_string,new_img_array) im = Image.frombuffer('L',(wx,wy),new_img_array) show(im2) ############ C wrapper code snippet ############### int wx,wy; Py_buffer img; Py_buffer new_img; Py_buffer table; unsigned char *img_ptr; unsigned char *new_img_ptr; int ok = PyArg_ParseTuple(args, "iis*w*",&wx,&wy,&img,&new_img); img_ptr = (unsigned char *) img.buf; new_img_ptr = (unsigned char *) new_img.buf; my_func(wx,wy,img_ptr,new_img_ptr); Thanks in advance for any suggestions to make this more efficient. bye N From python at mrabarnett.plus.com Tue Mar 2 19:53:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 00:53:22 +0000 Subject: Multiprocessing problem In-Reply-To: <4B8D7C23.7050905@sidefx.com> References: <4B8D7C23.7050905@sidefx.com> Message-ID: <4B8DB302.1010102@mrabarnett.plus.com> Matt Chaput wrote: > Hi, > > I'm having a problem with the multiprocessing package. > > I'm trying to use a simple pattern where a supervisor object starts a > bunch of worker processes, instantiating them with two queues (a job > queue for tasks to complete and an results queue for the results). The > supervisor puts all the jobs in the "job" queue, then join()s the > workers, and then pulls all the completed results off the "results" queue. > > (I don't think I can just use something like Pool.imap_unordered for > this because the workers need to be objects with state.) > > Here's a simplified example: > > http://pastie.org/850512 > > The problem is that seemingly randomly, but almost always, the worker > processes will deadlock at some point and stop working before they > complete. This will leave the whole program stalled forever. This seems > more likely the more work each worker does (to the point where adding > the time.sleep(0.01) as seen in the example code above guarantees it). > The problem seems to occur on both Windows and Mac OS X. > > I've tried many random variations of the code (e.g. using JoinableQueue, > calling cancel_join_thread() on one or both queues even though I have no > idea what it does, etc.) but keep having the problem. > > Am I just using multiprocessing wrong? Is this a bug? Any advice? > There's a difference between multithreading and multiprocessing. In multithreading the threads share the same address space, so objects can be passed between the threads simply by passing references to those objects. In multiprocessing, however, the process don't share an address space, so the objects themselves need to be transferred between the processes via pipes, but the pipes have a limited capacity. If the main process doesn't get the results from the queue until the worker processes terminate, and the worker processes don't terminate until they've put their results in the queue, and the pipe consequently fills up, then deadlock can result. From python at mrabarnett.plus.com Tue Mar 2 20:00:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 01:00:11 +0000 Subject: Queue peek? In-Reply-To: <1267567723.4101.28.camel@localhost.localdomain> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> Message-ID: <4B8DB49B.8070008@mrabarnett.plus.com> John Krukoff wrote: > On Tue, 2010-03-02 at 22:54 +0100, mk wrote: > >> No need to use synchro primitives like locks? >> >> I know that it may work, but that strikes me as somehow wrong... I'm >> used to using things like Lock().acquire() and Lock().release() when >> accessing shared data structures, whatever they are. > > > This is one of those places where the GIL is a good thing, and makes > your life simpler. You could consider it that the interpreter does the > locking for you for such primitive operations, if you like. I suppose it depends on the complexity of the data structure. A dict's methods are threadsafe, for example, but if you have a data structure where access leads to multiple method calls then collectively they need a lock. From matt at whoosh.ca Tue Mar 2 20:07:49 2010 From: matt at whoosh.ca (Matt Chaput) Date: Tue, 02 Mar 2010 20:07:49 -0500 Subject: Multiprocessing problem In-Reply-To: <4B8DB302.1010102@mrabarnett.plus.com> References: <4B8D7C23.7050905@sidefx.com> <4B8DB302.1010102@mrabarnett.plus.com> Message-ID: <4B8DB665.2080602@whoosh.ca> > If the main process doesn't get the results from the queue until the > worker processes terminate, and the worker processes don't terminate > until they've put their results in the queue, and the pipe consequently > fills up, then deadlock can result. The queue never fills up... on platforms with qsize() I can see this. I remove items from the results queue as I add to the job queue, and if I add timeouts everywhere the workers never raise Empty and the supervisor never raises Full. They just deadlock. I've rewritten the code so the worker threads don't push information back while they run, they just write to a temporary file which the supervisor can read, which avoids the issue. But if anyone can tell me what I was doing wrong for future reference, I'd greatly appreciate it. Thanks, Matt From jcb at iteris.com Tue Mar 2 20:45:31 2010 From: jcb at iteris.com (Metalone) Date: Tue, 2 Mar 2010 17:45:31 -0800 (PST) Subject: Multiprocessing.Pipe is not concurrently bi-directional (design flaw?) Message-ID: <7dbf688d-a86f-4e8d-a183-59673ed28f29@m35g2000prh.googlegroups.com> I wanted to use Multiprocessing.Pipe and Multiprocessing.Process to peform Actor style communication. However, I just can't get what I need done, and I think it is due to inherit problems with the design of Pipe. If I have a process like this def process1(conn): while True: msg = conn.recv() if msg == 'go': res = go() # this is a long running function conn.send(res) # send result back to caller elif msg == 'stop': stop() # this is intended to stop the go() function, for example using deciding to abort operation. In this code the 'stop' message cannot be received, because the code is in the long running go() function. So lets change it. def process1(conn): while True: msg = conn.recv() if msg == 'go': t = threading.Thread(target=go, args=(conn,)) t.start() elif msg == 'stop': stop() # this is intended to stop the go() function. Now the thread-1 is waiting on the blocking recv(). If the go() function completes on thread-2, it wants to send its result via the connection object, but it can't because the connection is in use. Trying to work around this gets complicated. For example, using a second process and a second connection object to read the 'stop' message, and then changing a shared memory flag to stop the go() function. Pipes not being concurrently bi-directional appears to be a design flaw to me. pyCSP appears to be an interesting approach, but it does not support communication across O.S. processes on Win32. From jcb at iteris.com Tue Mar 2 21:11:27 2010 From: jcb at iteris.com (Metalone) Date: Tue, 2 Mar 2010 18:11:27 -0800 (PST) Subject: Multiprocessing.Pipe is not concurrently bi-directional (design flaw?) References: <7dbf688d-a86f-4e8d-a183-59673ed28f29@m35g2000prh.googlegroups.com> Message-ID: <8f0cf159-bfb4-4def-82c7-9a99bd9cbebe@z10g2000prh.googlegroups.com> Well, I just realized that I could use a separate pipe to send the result back. This might work ok. From pmaupin at gmail.com Tue Mar 2 21:26:38 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 2 Mar 2010 18:26:38 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: On Mar 2, 5:36?pm, Steven D'Aprano wrote: > You seem to be taking the position that if you start with a config file > config.json, it is "too hard to edit", but then by renaming it to > config.rson it magically becomes easier to edit. That *is* ludicrous. No, but that seems to be the position you keep trying to ascribe to me: "Wait a minute... if JSON is too hard to edit, and RSON is a *superset* of JSON, that means by definition every JSON file is also a valid RSON file. Since JSON is too hard to manually edit, so is RSON." > Perhaps what you mean to say is that JSON *can be* (not is) too hard to > edit, and RSON *can be* too hard to edit too, but RSON has additional > benefits, including being easier to edit *sometimes*. I have said as much, in multiple prior postings on this thread, if you care to look. > So far you have done (in my opinion) a really poor job of explaining what > those benefits are. That's certainly a valid complaint, and I can certainly believe that's true (and I'm going to be working on the doc some more), but instead of making this complaint, you made the (still silly IMO) assertion that a superset has to be as unreadable as the base set. > You've bad-mouthed existing config formats, then > tried to convince us that RSON is almost exactly the same as one of those formats apart from a couple of trivial changes of spelling (True for true, etc.). This is conflating two different issues. In a lame attempt to show the silliness of the argument that the superset must be as bad as the subset, I was trying to explain that, if you make a very few changes, Python is a superset of JSON. However, my lame attempt at this was obviously as poorly thought out as some of the rest of my words, because it started an additional discussion that wasn't really germane to the real issues about configuration files. > In my opinion, if you're going to get any traction with RSON, you need to > demonstrate some examples of where JSON actually is hard to write, and > show how RSON makes it easier. It's not good enough showing badly written > JSON, it has to be examples that can't be written less badly given the > constraints of JSON. Agreed, and I will be working on that. Best regards, Pat From python at mrabarnett.plus.com Tue Mar 2 21:37:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 02:37:23 +0000 Subject: Multiprocessing.Pipe is not concurrently bi-directional (design flaw?) In-Reply-To: <8f0cf159-bfb4-4def-82c7-9a99bd9cbebe@z10g2000prh.googlegroups.com> References: <7dbf688d-a86f-4e8d-a183-59673ed28f29@m35g2000prh.googlegroups.com> <8f0cf159-bfb4-4def-82c7-9a99bd9cbebe@z10g2000prh.googlegroups.com> Message-ID: <4B8DCB63.80201@mrabarnett.plus.com> Metalone wrote: > Well, I just realized that I could use a separate pipe to send the > result back. This might work ok. Or you could call .poll on the pipe and sleep if there's no input yet. From victor.stinner at haypocalc.com Tue Mar 2 21:37:44 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Wed, 3 Mar 2010 03:37:44 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> Message-ID: <201003030337.44915.victor.stinner@haypocalc.com> Le dimanche 28 f?vrier 2010 23:40:59, Daniel Fetchinson a ?crit : > >>I guess they also have some kind of a sandbox if they let people run > >>python on their machines, I'm not sure if it's open source though. > > > > Thing is, I'm sure that Google uses a critical backstop to any > > Python-based sandbox: something like a chroot jail. The Python sandbox > > is mostly there to inform you about what you can and can't do; the real > > security is provided by the OS. > > I see, makes perfect sense. This then raises the question whether it's > important to have a 100% fool proof python sandbox without help from > the OS, or this goal is not only too ambitious but also not really a > useful one. This is just impossible :-) PHP tried that but it's too hard to write an exhaustive blacklist because too much code have to be modified. If you require a 100% fool proof sandbox, you have to use a sandbox between the Python process and the OS (and not inside the Python process). > One aspect might be that one might want to have a platform > independent way of sandboxing, perhaps. The problem have to be splitted in two parts: protect access to OS resources (files, network, etc.) and protect access to Python objects (eg. create a read only view of objects injected to the sandbox). An "OS sandbox" can not protect objects inside the Python object. And pysandbox cannot protect all access to OS resources (but I try to do that :-)). pysandbox is a possible solution to the second problem: control Python object space. -- Victor Stinner http://www.haypocalc.com/ From victor.stinner at haypocalc.com Tue Mar 2 21:42:51 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Wed, 3 Mar 2010 03:42:51 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002281743.07452.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> <201002281743.07452.victor.stinner@haypocalc.com> Message-ID: <201003030342.51801.victor.stinner@haypocalc.com> Le dimanche 28 f?vrier 2010 17:43:07, Victor Stinner a ?crit : > Yes, Google AppEngine has its Python sandbox and the source code is > available online. I don't know the license. I found 7 vulnerabilities in 1 > hour :-) I contacted Google security team. (...) There are other > differences, but I prefer to wait for the answer from > Google before telling you more :) Google answered me. I misunderstood AppEngine sandbox. It's not a Python sandbox. AppEngine sandbox is just a tool helping developers to test programs without the "real" (OS) sandbox. Their Python sandbox *emulates* the real sandbox, and so it's completly different to pysandbox. -- Victor Stinner http://www.haypocalc.com/ From alfps at start.no Tue Mar 2 21:54:20 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 03:54:20 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: * Patrick Maupin: > On Mar 2, 5:36 pm, Steven D'Aprano cybersource.com.au> wrote: >> You seem to be taking the position that if you start with a config file >> config.json, it is "too hard to edit", but then by renaming it to >> config.rson it magically becomes easier to edit. That *is* ludicrous. > > No, but that seems to be the position you keep trying to ascribe to > me: "Wait a minute... if JSON is too hard to edit, and RSON is a > *superset* of JSON, that means by definition every JSON file is also a > valid RSON file. Since JSON is too hard to manually edit, so is > RSON." Just a heads-up: IME it's next to impossible (maybe actually impossible) to convince Steven that your position is not the one he ascribes to you. At least not without an extremely lengthy debate veering off on multiple similar tangents plus some that one would never dream of. So I'd give up on that. Anyway, I agree with the sentiments expressed by many in this thread that what's important is the established "eco-culture", not the editability. Thus, even though XML isn't all that editable it's what I'd choose by default for rich configuration information, regardless of whether some simpler to edit alternative existed. Simply because there are so many XML tools out there, and people know about XML. It's like MS-DOS once became popular in spite of being extremely technically imperfect for its purpose, and then Windows... :-) Cheers, - Alf From ftp-wg-owner at hethmon.com Tue Mar 2 21:58:11 2010 From: ftp-wg-owner at hethmon.com (ftp-wg-owner at hethmon.com) Date: Wed, 3 Mar 2010 09:58:11 +0700 Subject: Xgyxkcxxpy Message-ID: <20100303025835.EE602EE9AB@mail.python.org> Dear user of python.org, We have received reports that your e-mail account was used to send a large amount of spam during this week. Most likely your computer was compromised and now contains a trojaned proxy server. We recommend you to follow instruction in order to keep your computer safe. Best wishes, python.org technical support team. -------------- next part -------------- A non-text attachment was scrubbed... Name: instruction.zip Type: application/octet-stream Size: 29356 bytes Desc: not available URL: From barry at python.org Tue Mar 2 22:17:44 2010 From: barry at python.org (Barry Warsaw) Date: Tue, 2 Mar 2010 22:17:44 -0500 Subject: Python 2.6.5 release candidate 1 now available Message-ID: <20100302221744.7ee4d3dd@heresy.wooz.org> Hello everyone, The source tarballs and Windows installer for Python 2.6.5 release candidate 1 are now available: http://www.python.org/download/releases/2.6.5/ Please download them, install them, and try to use them with your favorite projects and environments. If no regressions are found, we will do the final release on Monday March 15, 2010. Please test the release candidate as much as possible in the meantime, and help make 2.6.5 a rock solid release! Thanks, -Barry P.S. The Mac installer will hopefully be available soon. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From max at alcyone.com Tue Mar 2 22:20:34 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 02 Mar 2010 19:20:34 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: Patrick Maupin wrote: > On Mar 2, 5:36 pm, Steven D'Aprano cybersource.com.au> wrote: >> You seem to be taking the position that if you start with a config file >> config.json, it is "too hard to edit", but then by renaming it to >> config.rson it magically becomes easier to edit. That *is* ludicrous. > > No, but that seems to be the position you keep trying to ascribe to > me: "Wait a minute... if JSON is too hard to edit, and RSON is a > *superset* of JSON, that means by definition every JSON file is also a > valid RSON file. Since JSON is too hard to manually edit, so is > RSON." Huh? That's the argument being used against you, not the argument being ascribed to you. You're getting confused about something, somewhere. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis I wonder if heaven got a ghetto -- Tupac Shakur From prakash.stack at gmail.com Tue Mar 2 22:25:32 2010 From: prakash.stack at gmail.com (prakash jp) Date: Wed, 3 Mar 2010 08:55:32 +0530 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: <4b79e28c$0$4610$426a74cc@news.free.fr> References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <805f59d51003021925s27c8c489o9a25c23caef22fda@mail.gmail.com> Hi all, plz find the attachment, thats how u register services Pythonically: Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: services.bmp Type: image/bmp Size: 2107062 bytes Desc: not available URL: From pmaupin at gmail.com Tue Mar 2 22:35:20 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 2 Mar 2010 19:35:20 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> On Mar 2, 9:20?pm, Erik Max Francis wrote: > Patrick Maupin wrote: > > On Mar 2, 5:36 pm, Steven D'Aprano > cybersource.com.au> wrote: > >> You seem to be taking the position that if you start with a config file > >> config.json, it is "too hard to edit", but then by renaming it to > >> config.rson it magically becomes easier to edit. That *is* ludicrous. > > > No, but that seems to be the position you keep trying to ascribe to > > me: "Wait a minute... if JSON is too hard to edit, and RSON is a > > *superset* of JSON, that means by definition every JSON file is also a > > valid RSON file. ?Since JSON is too hard to manually edit, so is > > RSON." > > Huh? ?That's the argument being used against you, not the argument being > ascribed to you. ?You're getting confused about something, somewhere. > > -- > Erik Max Francis && m... at alcyone.com &&http://www.alcyone.com/max/ > ? San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis > ? ?I wonder if heaven got a ghetto > ? ? -- Tupac Shakur Yes, it is very confusing. Steven used that purported argument against me, and then since I disagreed with it, it apparently meant that I was arguing that changing the file extension type (which I've never even proposed or discussed, btw) from json to rson somehow magically makes a preexisting file all better. I have a headache now, and it will only get worse, so that's really all I have left to say about this issue. Best regards, Pat From prakash.stack at gmail.com Tue Mar 2 22:36:42 2010 From: prakash.stack at gmail.com (prakash jp) Date: Wed, 3 Mar 2010 09:06:42 +0530 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: <881a0df5-872f-4c19-a989-fe3ffe775655@k2g2000pro.googlegroups.com> References: <4b79e28c$0$4610$426a74cc@news.free.fr> <881a0df5-872f-4c19-a989-fe3ffe775655@k2g2000pro.googlegroups.com> Message-ID: <805f59d51003021936y53af0759q663fbd131c7fa432@mail.gmail.com> Code of SmallestService.py is at: http://book.opensourceproject.org.cn/lamp/python/pythonwin/ Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Tue Mar 2 22:51:52 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 03 Mar 2010 14:51:52 +1100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <4b8ddcf6$1@dnews.tpgi.com.au> On 02/25/2010 06:16 AM, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Out of curiosity: > > def gen_rand_string(length): > prng = random.SystemRandom() > chars = [] > for i in range(length): > chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) > return ''.join(chars) > > if __name__ == "__main__": > chardict = {} > for i in range(10000): > ## w = gen_rand_word(10) > w = gen_rand_string(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > > > s 3966 > d 3912 > g 3909 > h 3905 > a 3901 > u 3900 > q 3891 > m 3888 > k 3884 > b 3878 > x 3875 > v 3867 > w 3864 > y 3851 > l 3825 > z 3821 > c 3819 > e 3819 > r 3816 > n 3808 > o 3797 > f 3795 > t 3784 > p 3765 > j 3730 > i 3704 > > Better, although still not perfect. > I give you this: I give you this: import itertools def gen(): valid_chars = 'abcdefghijklmnopqrstuvwxyz' for char in itertools.repeat(valid_chars): yield char gen = gen() def gen_rand_string(length): chars = (next(gen) for i in range(length)) return ''.join(chars) since it gives me a perfect distribution of letters, it must be a very secure random password generation scheme. From lie.1296 at gmail.com Tue Mar 2 22:59:01 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 03 Mar 2010 14:59:01 +1100 Subject: cpan for python? In-Reply-To: <2010030214473616807-tomfsessile@gmailcom> References: <2010030214473616807-tomfsessile@gmailcom> Message-ID: <4b8ddea4$1@dnews.tpgi.com.au> On 03/03/2010 09:47 AM, TomF wrote: > On 2010-03-02 13:14:50 -0800, R Fritz said: > >> On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: >>> >>> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: >>> >>>> Is there something like cpan for python? I like python's syntax, but >>>> Iuse perl because of cpan and the tremendous modules that it has. -- >>> >>> Please search the mailing list archives. >>> >>> This subject has been discussed to absolute death. >> >> But somehow the question is not in the FAQ, though the answer is. See: >> >> >> > > There > is also a program called cpan, distributed with Perl. It is used for > searching, downloading, installing and testing modules from the CPAN > repository. It's far more extensive than setuptools. AFAIK the python > community has developed nothing like it. python have easy_install From john at castleamber.com Tue Mar 2 23:58:47 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Mar 2010 22:58:47 -0600 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> Message-ID: <87ljea9f20.fsf@castleamber.com> Lie Ryan writes: > On 03/03/2010 09:47 AM, TomF wrote: [..] >> There >> is also a program called cpan, distributed with Perl. It is used for >> searching, downloading, installing and testing modules from the CPAN >> repository. It's far more extensive than setuptools. AFAIK the python >> community has developed nothing like it. > > python have easy_install How easy is it to /remove/ something? ;-) (Last time I checked I read something like "manually remove the .egg"... -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 00:00:37 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 05:00:37 GMT Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> Message-ID: On Tue, 02 Mar 2010 19:35:20 -0800, Patrick Maupin wrote: > Yes, it is very confusing. Steven used that purported argument against > me, and then since I disagreed with it, it apparently meant that I was > arguing that changing the file extension type (which I've never even > proposed or discussed, btw) from json to rson My argument is *figurative*, not literal. > somehow magically makes a preexisting file all better. You might not have intended that ludicrous conclusion, but it was implied by some of your posts, particularly the early ones. Of course I don't think that you *actually* believe the conclusion. I believe that, whatever the real or imagined benefit of RSON over JSON, in this thread you have attempted to over-sell RSON while giving relatively little justification for it. I wish you every success in your project, but think that it is off-topic for a Python discussion group. -- Steven From ben+python at benfinney.id.au Wed Mar 3 00:17:16 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 16:17:16 +1100 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> Message-ID: <873a0ix9ur.fsf@benfinney.id.au> Lie Ryan writes: > On 03/03/2010 09:47 AM, TomF wrote: > > There is also a program called cpan, distributed with Perl. It is > > used for searching, downloading, installing and testing modules from > > the CPAN repository. It's far more extensive than setuptools. AFAIK > > the python community has developed nothing like it. > > python have easy_install Indeed. And that program is nothing like the Perl ?cpan? program. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard Stallman, 2002 | Ben Finney From greg.ewing at canterbury.ac.nz Wed Mar 3 00:18:28 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 18:18:28 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> Message-ID: <7v695nFa0fU1@mid.individual.net> MRAB wrote: > BTW, the first programming I did was in hexadecimal (C4xx was "LDI xx"). Hey, a SC/MP! That was my first programming language, too. What sort of machine was it in? -- Greg From greg.ewing at canterbury.ac.nz Wed Mar 3 00:30:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 18:30:00 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: <7v69rcFcmeU1@mid.individual.net> Grant Edwards wrote: > Just a mediocre copy of the CP/M filesystem, which was in turn > copied from DEC's RSTS or RSX. It was actually an improvement over CP/M's file system. CP/M didn't have hierarchical directories or timestamps and recorded file sizes in 128-byte blocks rather than bytes. -- Greg From max at alcyone.com Wed Mar 3 00:36:42 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 02 Mar 2010 21:36:42 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> Message-ID: <__adnWP-2__2aBDWnZ2dnUVZ_h2dnZ2d@giganews.com> Patrick Maupin wrote: > On Mar 2, 9:20 pm, Erik Max Francis wrote: >> Patrick Maupin wrote: >>> On Mar 2, 5:36 pm, Steven D'Aprano >> cybersource.com.au> wrote: >>>> You seem to be taking the position that if you start with a config file >>>> config.json, it is "too hard to edit", but then by renaming it to >>>> config.rson it magically becomes easier to edit. That *is* ludicrous. >>> No, but that seems to be the position you keep trying to ascribe to >>> me: "Wait a minute... if JSON is too hard to edit, and RSON is a >>> *superset* of JSON, that means by definition every JSON file is also a >>> valid RSON file. Since JSON is too hard to manually edit, so is >>> RSON." >> Huh? That's the argument being used against you, not the argument being >> ascribed to you. You're getting confused about something, somewhere. > > Yes, it is very confusing. Steven used that purported argument > against me, and then since I disagreed with it, it apparently meant > that I was arguing that changing the file extension type (which I've > never even proposed or discussed, btw) from json to rson somehow > magically makes a preexisting file all better. No, that was not the point he was making. You should reread more carefully (and be aware of sarcasm). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis Perfect situations must go wrong -- Florence, _Chess_ From greg.ewing at canterbury.ac.nz Wed Mar 3 00:40:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 18:40:00 +1300 Subject: Docstrings considered too complicated In-Reply-To: <877hpuxpdf.fsf@benfinney.id.au> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> Message-ID: <7v6ae4Ff37U1@mid.individual.net> Ben Finney wrote: > Just as customers should demand both that a building be built to do its > job well, *and* that its architectural plans meet measurable, testable > industry standards of quality for independent re-use at some > indeterminate later date. A problem is that it's very hard to come up with *measurable* standards of code quality. There's no equivalent in the software world of specifying a grade of steel or type of sand. The things that really matter are all subjective. -- Greg From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 00:48:49 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 05:48:49 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> Message-ID: On Wed, 03 Mar 2010 18:40:00 +1300, Gregory Ewing wrote: > Ben Finney wrote: > >> Just as customers should demand both that a building be built to do its >> job well, *and* that its architectural plans meet measurable, testable >> industry standards of quality for independent re-use at some >> indeterminate later date. > > A problem is that it's very hard to come up with *measurable* standards > of code quality. > > There's no equivalent in the software world of specifying a grade of > steel or type of sand. The things that really matter are all subjective. True, but one can look at "best practice", or even "standard practice". For Python coders, using docstrings is standard practice if not best practice. Using strings as comments is not. Or one can simply use *reason*: what justification is there for putting comments in strings at the top of the function? The only one I can see is if you are writing for an embedded device, you may want to remove doc strings to save memory -- and even that is implementation dependent. What justification is there for putting docstrings in functions? Code becomes self-documenting, you can run Python tools that extract and run doctests, standard tools in the standard library work, other coders will immediately understand what you have done, and (unlike the behaviour of string-comments) the behaviour of docstrings is guaranteed by the language. Unless you are writing for an embedded devise, there is NO objective reason for putting comments in strings above the function, and MANY objective reasons for putting them into docstrings. Okay, this isn't quite the same as measuring the strength of concrete under compression, but it's not a subjective choice like "tea or coffee?". -- Steven From greg.ewing at canterbury.ac.nz Wed Mar 3 01:14:41 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 19:14:41 +1300 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> Message-ID: <7v6cf4FnnrU1@mid.individual.net> MRAB wrote: > I suppose it depends on the complexity of the data structure. A dict's > methods are threadsafe, for example, but if you have a data structure > where access leads to multiple method calls then collectively they need > a lock. It also depends on the nature of the objects being used as dict keys. Dict operations invoke the hashing and comparison methods of the keys, which in general can execute arbitrary Python code. If the keys are elementary built-in types such as strings or ints, then dict operations will *probably* be atomic. But I think I'd use a lock anyway, to be on the safe side. -- Greg From groups at sonic.net Wed Mar 3 01:18:11 2010 From: groups at sonic.net (Isaac) Date: Tue, 2 Mar 2010 22:18:11 -0800 Subject: Need bluez/python ( PyBluez) method to access BlueZ data- Please Help! Message-ID: <4b8dff1e$0$22093$742ec2ed@news.sonic.net> Hi, I need to access data that is handled and stored in the BlueZ file system, but is, unfortunately, not available via the current BlueZ D-Bus API. That is, the data I need is parsed by BlueZ, but not provided in the current D-Bus signal. I need a method or interface that does not rely on the D-Bus API and can directly access the BlueZ file system to get this parsed data. Can PyBlueZ do this? If not, any suggestions would be immensely appreciated. Thanks! Isaac From greg.ewing at canterbury.ac.nz Wed Mar 3 01:23:27 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 19:23:27 +1300 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <7v6cviFq18U1@mid.individual.net> Alf P. Steinbach wrote: > * Tracubik: > >> iterations=0; >> count=0; >> REPEAT; >> iterations = iterations+1; >> ... >> IF (genericCondition) THEN count=count+1; >> ... >> CASE count OF: >> 1: m = 1 >> 2: m = 10 >> 3: m = 100 > > Uhm, is this syntactically valid Pascal? As I recall, every Pascal > construct was delimited in some way. I think it's okay. Pascal's control structures such as if-then and while-do mostly take single statements and didn't have an ending keyword. If you want multiple statements in the body you have to put begin-end around them. Putting a semicolon after REPEAT is stylistically a bit odd, but it's not wrong. -- Greg From timr at probo.com Wed Mar 3 01:34:29 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 02 Mar 2010 22:34:29 -0800 Subject: python 2.6: how to modify a PIL image from C without copying forth and back References: <4b8daf7d$0$2868$426a74cc@news.free.fr> Message-ID: <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> News123 wrote: > >I created a grayscale image with PIL. > >Now I would like to write a C function, which reads a;most all pixels >and will modify a few of them. > >My current approach is: >- transform the image to a string() >- create a byte array huge enough to contain the resulting image >- call my c_function, which copies over the entire image in order > to modify a few pixels >How can I achieve this with the least amount of copies? If it were me, I'd be tempted to go peek at the source code for PIL, then pass the Image object to my C routine and poke at the innards to find the buffer with the pixels. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From admin at mail.psa-software.com Wed Mar 3 01:41:53 2010 From: admin at mail.psa-software.com (EVZYN) Date: Wed, 3 Mar 2010 07:41:53 +0100 Subject: =?windows-1251?B?7+7x7O7y8OXy/CDv7vDt7iD06Ov87CDv8O4g6vPt6Ovo7ePz8Q==?= Message-ID: <828A25931378487BB0D14EA4A0EFFCE8@server> An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Wed Mar 3 01:52:02 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 19:52:02 +1300 Subject: Writing an assembler in Python In-Reply-To: References: Message-ID: <7v6el6F1ddU1@mid.individual.net> > In article , > Giorgos Tzampanakis wrote: > >>I'm implementing a CPU that will run on an FPGA. I want to have a >>(dead) simple assembler that will generate the machine code for >>me. I want to use Python for that. Are there any libraries that >>can help me with the parsing of the assembly code? I wrote a PIC assembler in Python once. I didn't bother with any parsing libraries. I used a regular expression to split the input into tokens, then wrote ad-hoc parsing code in Python. -- Greg From pankaj.kr at gmail.com Wed Mar 3 02:03:31 2010 From: pankaj.kr at gmail.com (Pankaj) Date: Tue, 2 Mar 2010 23:03:31 -0800 (PST) Subject: timeout restart in pexpect Message-ID: I am using pexpect to automate some procedures. My procedures are time cosuming, some messages coming out from that, in failure cases it will not output anything. So I would like to give small timeout value but when some message is received, it should restart the timeout, similar like "restart_timeout_upon_receive" in perl. Is it possible in Python using pexpect ? From i3enhamin at gmail.com Wed Mar 3 02:06:13 2010 From: i3enhamin at gmail.com (Ben Racine) Date: Tue, 2 Mar 2010 23:06:13 -0800 Subject: nonunique string replacements Message-ID: <6E340E6F-59D9-4E26-9491-F0891AD9B6F0@gmail.com> All, Say I have a string "l" ... l = 'PBUSH 201005 K 1. 1. 1. 1. 1. 1.' And I want to replace the first " 1." with a "500.2" and the second " 1." with " 5.2" ... What pythonic means would you all recommend? Note the whitespace is equal between the existing substring and the replacement string. Many thanks, Ben Racine i3enhamin at gmail.com From anand.shashwat at gmail.com Wed Mar 3 02:36:13 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 3 Mar 2010 13:06:13 +0530 Subject: nonunique string replacements In-Reply-To: <6E340E6F-59D9-4E26-9491-F0891AD9B6F0@gmail.com> References: <6E340E6F-59D9-4E26-9491-F0891AD9B6F0@gmail.com> Message-ID: >>> s = 'PBUSH 201005 K 500 1. 1. 1. 1. 1.' #Your original string here >>> l #Create your desired list ['500.2', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7'] >>> lsep = s.count(' 1.') #Count the occurrence of seperators >>> for i in range(lsep): #Replace all of them by values in list l, one by one ... f = s.find(' 1.') ... s = s[:f] + l[i] + s[f+3:] ... >>> s #Your final string 'PBUSH 201005 K 500 500.2 5.2 5.3 5.4 5.5' ~l0nwlf On Wed, Mar 3, 2010 at 12:36 PM, Ben Racine wrote: > All, > > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? > > Note the whitespace is equal between the existing substring and the > replacement string. > > Many thanks, > Ben Racine > i3enhamin at gmail.com > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Wed Mar 3 03:09:35 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 3 Mar 2010 09:09:35 +0100 Subject: case do problem In-Reply-To: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <6faf39c91003030009h10ad0737xec87012ec5f0395@mail.gmail.com> On Tue, Mar 2, 2010 at 6:46 PM, Tracubik wrote: > and, generally > speaking, the try..except block slow down the execution of the program or > not? Try...except tends to be slow when the exception does occur, fast when it does not. Apart from that, if these fraction-of-a-fraction-of-a-second gains are important to you, Python is not the programming language for you. In Python, it seems to be common to do optimization after rather than during the main coding, and then only when it is necessary and only where it matters. That is: 1. Program your solution without looking much at speed issues 2. Check if it is fast enough. If so, ready. 3. If not, see which parts of the program are being slow 4. Optimize only those parts of the program that have been identified in step 3 -- Andr? Engels, andreengels at gmail.com From tomf.sessile at gmail.com Wed Mar 3 03:23:16 2010 From: tomf.sessile at gmail.com (TomF) Date: Wed, 3 Mar 2010 00:23:16 -0800 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> Message-ID: <2010030300231675249-tomfsessile@gmailcom> On 2010-03-02 19:59:01 -0800, Lie Ryan said: > On 03/03/2010 09:47 AM, TomF wrote: >> On 2010-03-02 13:14:50 -0800, R Fritz said: >> >>> On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: >>>> >>>> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: >>>> >>>>> Is there something like cpan for python? I like python's syntax, but >>>>> Iuse perl because of cpan and the tremendous modules that it has. -- >>>> >>>> Please search the mailing list archives. >>>> >>>> This subject has been discussed to absolute death. >>> >>> But somehow the question is not in the FAQ, though the answer is. See: >>> >>> There >>> >> is also a program called cpan, distributed with Perl. It is used for >> searching, downloading, installing and testing modules from the CPAN >> repository. It's far more extensive than setuptools. AFAIK the python >> community has developed nothing like it. > > python have easy_install easy_install is part of setuptools. As I said, nothing like cpan. -Tom From lipun4u at gmail.com Wed Mar 3 03:33:17 2010 From: lipun4u at gmail.com (asit) Date: Wed, 3 Mar 2010 00:33:17 -0800 (PST) Subject: process mp3 file Message-ID: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> Somebody suggest me a python library for processing mp3 file. Here I don't want to play the file. Thank you From __peter__ at web.de Wed Mar 3 03:39:54 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Mar 2010 09:39:54 +0100 Subject: case do problem References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: Tracubik wrote: > hi, i've to convert from Pascal this code: program loop; function generic_condition: boolean; begin generic_condition := random > 0.7 end; procedure loop; var iterations, count, m: integer; begin iterations := 0; count := 0; m := 0; repeat iterations := iterations+1; (*...*) writeln(iterations:2, count:2, m:4); (*...*) if generic_condition then inc(count); (*...*) case count of 1: m := 1; 2: m := 10; 3: m := 100 end until (count = 4) or (iterations = 20) end; begin loop; writeln("That's all, folks") end. Hey, I have a Pascal compiler just one apt-get away ;) Here's how I'd translate the above, without trying to be too clever: from random import random def generic_condition(): return random() > 0.7 def loop(): count = 0 m = 0 lookup = {1: 1, 2: 10, 3: 100} for iterations in range(20): # off by one # ... print "%2d %1d %3d" % (iterations, count, m) # ... if generic_condition(): count += 1 # ... m = lookup.get(count, m) if count == 4: break if __name__ == "__main__": loop() print "That's all, folks" Something must be wrong with me today because I find the Pascal code /more/ readable... Peter From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 03:42:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 08:42:01 GMT Subject: nonunique string replacements References: Message-ID: On Tue, 02 Mar 2010 23:06:13 -0800, Ben Racine wrote: > All, > > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? l = l.replace(" 1.", "500.2", 1) l = l.replace(" 1.", "5.2", 1) -- Steven From news123 at free.fr Wed Mar 3 03:43:21 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 09:43:21 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> References: <4b8daf7d$0$2868$426a74cc@news.free.fr> <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> Message-ID: <4b8e2129$0$8262$426a34cc@news.free.fr> Hi Tim, Tim Roberts wrote: > News123 wrote: >> I created a grayscale image with PIL. >> >> Now I would like to write a C function, which reads a;most all pixels >> and will modify a few of them. >> >> My current approach is: >> - transform the image to a string() >> - create a byte array huge enough to contain the resulting image >> - call my c_function, which copies over the entire image in order >> to modify a few pixels >> How can I achieve this with the least amount of copies? > > If it were me, I'd be tempted to go peek at the source code for PIL, then > pass the Image object to my C routine and poke at the innards to find the > buffer with the pixels. Yes, this might be an option Somehow though it didn't feel right for me to depend on internal non documented data types, which might change between releases of PIL. N From __peter__ at web.de Wed Mar 3 03:49:38 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Mar 2010 09:49:38 +0100 Subject: nonunique string replacements References: Message-ID: Ben Racine wrote: > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? With regular expressions: >>> import re >>> replacements = iter(["one", "two", "three"]) >>> re.compile("replaceme").sub(lambda m: next(replacements), "foo replaceme bar replaceme baz replaceme bang") 'foo one bar two baz three bang' With string methods: >>> replacements = iter(["", "one", "two", "three"]) >>> "".join(a + b for a, b in zip(replacements, "foo replaceme bar replaceme baz replaceme bang".split("replaceme"))) 'foo one bar two baz three bang' Peter From __peter__ at web.de Wed Mar 3 04:05:02 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Mar 2010 10:05:02 +0100 Subject: Image.frombuffer and warning References: <4b8dada2$0$6285$426a74cc@news.free.fr> Message-ID: News123 wrote: > I am using the PIL function from_buffer in python 2.6.4 > > I am having the line > im2 = Image.frombuffer('L',(wx,wy),buf) > > > I receive the warning: >> ./pytest.py:63: RuntimeWarning: the frombuffer defaults may change in > a future release; for portability, change the call to read: >> frombuffer(mode, size, data, 'raw', mode, 0, 1) >> im2 = Image.frombuffer('L',(wx,wy),buf) > > > Naively I assumed, that changing my code to > > > im2 = Image.frombuffer('L',(wx,wy),buf,'raw','L',0,1) > > > should fix the issue: > > However I receive exactly the same error as before. > > What am I doing wrong? I cannot reproduce the problem: $ cat frombuffer.py import sys import Image wx = 3 wy = 2 buf = "a"*wx*wy if "--fixed" in sys.argv: Image.frombuffer("L", (wx, wy), buf, "raw", "L", 0, 1) else: Image.frombuffer("L", (wx, wy), buf) $ python frombuffer.py frombuffer.py:9: RuntimeWarning: the frombuffer defaults may change in a future release; for portability, change the call to read: frombuffer(mode, size, data, 'raw', mode, 0, 1) Image.frombuffer("L", (wx, wy), buf) $ python frombuffer.py --fixed $ python -c"import Image; print Image.VERSION" 1.1.6 $ python -V Python 2.6.4 Peter From stefan_ml at behnel.de Wed Mar 3 04:10:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 10:10:22 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: <4b8daf7d$0$2868$426a74cc@news.free.fr> References: <4b8daf7d$0$2868$426a74cc@news.free.fr> Message-ID: News123, 03.03.2010 01:38: > I created a grayscale image with PIL. > > Now I would like to write a C function, which reads a;most all pixels > and will modify a few of them. > > My current approach is: > - transform the image to a string() > - create a byte array huge enough to contain the resulting image > - call my c_function, which copies over the entire image in order > to modify a few pixels > How can I achieve this with the least amount of copies? Take a look at Cython instead, it will allow you to access PIL's image buffer directly, instead of copying the data. It will also simplify and speed up your C wrapper code. Stefan From deets at nospam.web.de Wed Mar 3 04:17:57 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Mar 2010 10:17:57 +0100 Subject: conditional import into global namespace In-Reply-To: References: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> Message-ID: <7v6nq5Ffv2U1@mid.uni-berlin.de> Am 02.03.10 21:41, schrieb mk: > Jerry Hill wrote: >> Just import subprocess at the top of your module. If subprocess >> hasn't been imported yet, it will be imported when your module is >> loaded. If it's already been imported, your module will use the >> cached version that's already been imported. >> >> In other words, it sounds like Python already does what you want. You >> don't need to do anything special. > > Oh, thanks! > > Hmm it's different than dealing with packages I guess -- IIRC, in > packages only code in package's __init__.py was executed? I don't understand this. But there is no difference regarding caching & execution between packages and modules. Importing a package will execute the __init__.py, yes. But only once. As will importing modules execute them, but only once. All subsequent imports will just return the created module-object. Unless you import something under a new name! That is, you can alter the sys.path and then import a package/module under a different name - python won't detect that. Simplest example ist this: ---- test.py ---- class Foo(object): pass if __name__ == "__main__": import test # import ourselves # this holds, because we have # __main__.Foo and test.Foo assert Foo is not test.Foo ---- test.py ---- However, unless you mess with python, this is none of your concern. Diez From orenelrad at gmail.com Wed Mar 3 04:27:16 2010 From: orenelrad at gmail.com (Oren Elrad) Date: Wed, 3 Mar 2010 04:27:16 -0500 Subject: Interest check in some delicious syntactic sugar for "except:pass" Message-ID: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Howdy all, longtime appreciative user, first time mailer-inner. I'm wondering if there is any support (tepid better than none) for the following syntactic sugar: silence: ........ block -------------------------> try: ........block except: ........pass The logic here is that there are a ton of "except: pass" statements[1] floating around in code that do not need to be there. Meanwhile, the potential keyword 'silence' does not appear to be in significant use as a variable[2], or an alternative keyword might be imagined ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of 'silence' since that is precisely what it does to the block (that is, you have to inflect it as a verb, not a noun -- you are telling the block to be silent). Finally, since this is the purest form of syntactic sugar, I cannot fathom any parsing, interpreting or other complications that would arise. I appreciate any feedback, including frank statements that you'd rather not trifle with such nonsense. ~Oren [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy From news123 at free.fr Wed Mar 3 04:37:43 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 10:37:43 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: References: <4b8daf7d$0$2868$426a74cc@news.free.fr> Message-ID: <4b8e2de8$0$21576$426a74cc@news.free.fr> Hi Stefan, Stefan Behnel wrote: > News123, 03.03.2010 01:38: >> I created a grayscale image with PIL. >> >> Now I would like to write a C function, which reads a;most all pixels >> and will modify a few of them. >> >> My current approach is: >> - transform the image to a string() >> - create a byte array huge enough to contain the resulting image >> - call my c_function, which copies over the entire image in order >> to modify a few pixels >> How can I achieve this with the least amount of copies? > > Take a look at Cython instead, it will allow you to access PIL's image > buffer directly, instead of copying the data. It will also simplify and > speed up your C wrapper code. > > Stefan > I don't know Cython. Having looked at the web site I'm not entirely sure, I understood your suggestion. Do you mean - to stay with Python 2.6 and to implement only my extension in Cython. This might be very attractive. If yes, can you recommend some url's / tutorials / etc. which might help to implement a cython extension for python2.6. which reads and modifies a pixel of a PIL image. or do you mean - to switch entirely from Python 2.6 to Cython. I would be reluctant to do so, as I have already a lot of existing code. and I do not have the time to check the entire code base for portability issues thanks in advance N From phil at freehackers.org Wed Mar 3 04:40:24 2010 From: phil at freehackers.org (BlueBird) Date: Wed, 3 Mar 2010 01:40:24 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Feb 24, 9:23?pm, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? If they are generating their doc with doxygen, I think it's the right choice. See: http://www.stack.nl/~dimitri/doxygen/docblocks.html#pythonblocks Oops, after a second look, doxygen needs comments before the function, not doc strings. Philippe From news123 at free.fr Wed Mar 3 04:44:26 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 10:44:26 +0100 Subject: Image.frombuffer and warning In-Reply-To: References: <4b8dada2$0$6285$426a74cc@news.free.fr> Message-ID: <4b8e2f7a$0$13729$426a74cc@news.free.fr> Hi Peter, Peter Otten wrote: > News123 wrote: > I cannot reproduce the problem: > > $ cat frombuffer.py > import sys > import Image > wx = 3 > wy = 2 > buf = "a"*wx*wy > if "--fixed" in sys.argv: > Image.frombuffer("L", (wx, wy), buf, "raw", "L", 0, 1) > else: > Image.frombuffer("L", (wx, wy), buf) > > $ python frombuffer.py > frombuffer.py:9: RuntimeWarning: the frombuffer defaults may change in a > future release; for portability, change the call to read: > frombuffer(mode, size, data, 'raw', mode, 0, 1) > Image.frombuffer("L", (wx, wy), buf) > $ python frombuffer.py --fixed > $ python -c"import Image; print Image.VERSION" > 1.1.6 > $ python -V > Python 2.6.4 > > Peter You're absolutely right. It was my error. I shouldn't do any lat night coding :-(. I fixed one frombuffer() statement, but overlooked a second one in my code :-( Apologies N From pankaj.kr at gmail.com Wed Mar 3 04:50:27 2010 From: pankaj.kr at gmail.com (Pankaj) Date: Wed, 3 Mar 2010 01:50:27 -0800 (PST) Subject: exp_internal in pexpect Message-ID: <4aa75aa4-e89b-40b9-b84a-c25ecf907815@l12g2000prg.googlegroups.com> how to enable expect log in pexpect ? (similar as exp_internal in expect) From stefan_ml at behnel.de Wed Mar 3 05:10:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 11:10:21 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: <4b8e2de8$0$21576$426a74cc@news.free.fr> References: <4b8daf7d$0$2868$426a74cc@news.free.fr> <4b8e2de8$0$21576$426a74cc@news.free.fr> Message-ID: News123, 03.03.2010 10:37: > Stefan Behnel wrote: >> Take a look at Cython instead, it will allow you to access PIL's image >> buffer directly, instead of copying the data. It will also simplify and >> speed up your C wrapper code. > > I don't know Cython. Having looked at the web site I'm not entirely > sure, I understood your suggestion. > > Do you mean > - to stay with Python 2.6 and to implement only my extension in Cython. Absolutely. > This might be very attractive. If yes, can you recommend some url's / > tutorials / etc. which might help to implement a cython extension for > python2.6. which reads and modifies a pixel of a PIL image. Check out the tutorial on the web site, and ask on the cython-users mailing list about integration with PIL. I'm sure you'll get some useful examples. Here's something closely related, although it doesn't really use PIL (but the mechanisms are the same): http://wiki.cython.org/examples/mandelbrot > or do you mean > - to switch entirely from Python 2.6 to Cython. I would be reluctant to > do so, as I have already a lot of existing code. and I do not have the > time to check the entire code base for portability issues The nice thing about Cython is that you always have a normal CPython interpreter running, so you can split your code between the interpreter and the compiler at any level of granularity. However, the advice was really to write your image processing algorithm in Cython, not your entire program. Stefan From geoff.bache at jeppesen.com Wed Mar 3 05:14:08 2010 From: geoff.bache at jeppesen.com (geoffbache) Date: Wed, 3 Mar 2010 02:14:08 -0800 (PST) Subject: PYTHONPATH and eggs Message-ID: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Hi all, I have a very simple problem that seems to have no simple solution. I have a module which is installed centrally and lives in a Python egg. I have experimented with some minor changes to it and would like to set my PYTHONPATH to pick up my local copy of it, but don't want to have to figure out how to build my own version of the "egg" if possible. Unfortunately, the location from PYTHONPATH ends up after the eggs in sys.path so I can't persuade Python to import my version. The only way I've found to fix it is to copy the main script and manually hack sys.path at the start of it which isn't really very nice. I wonder if there is any better way as I can't be the first person to want to do this, surely? I've seen this issue has been discussed elsewhere and flagged as a problem (e.g. http://mail.python.org/pipermail/distutils-sig/2009-January/010755.html) but I've been unable to find any suggestions for workarounds or indications whether this will be/has been fixed. Regards, Geoff Bache From clp2 at rebertia.com Wed Mar 3 05:25:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 02:25:02 -0800 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <50697b2c1003030225j28c18507r619cf15aeddb8c41@mail.gmail.com> On Wed, Mar 3, 2010 at 1:27 AM, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. So, why exactly should the language /encourage/ unnecessary error silencing? (which is what the proposed sugar would do) > I appreciate any feedback Applicable rules of The Zen[1] that the proposal arguably violates: *Special cases aren't special enough to break the rules. *There should be one-- and preferably only one --obvious way to do it. Cheers, Chris -- http://blog.rebertia.com [1]: http://www.python.org/dev/peps/pep-0020/ From clp2 at rebertia.com Wed Mar 3 05:25:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 02:25:42 -0800 Subject: process mp3 file In-Reply-To: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> Message-ID: <50697b2c1003030225p2b32662ct960ad477d9d3c8f5@mail.gmail.com> On Wed, Mar 3, 2010 at 12:33 AM, asit wrote: > Somebody suggest me a python library for processing mp3 file. ?Here I > don't want to play the file. Define "processing". Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Wed Mar 3 05:40:56 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 03 Mar 2010 05:40:56 -0500 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <4B8E3CB8.70302@ieee.org> Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. > > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. > > ~Oren > > [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en > [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy > > I presume you know that there's a feature freeze on for Python. So such an idea wouldn't be considered for at least a couple of years. But that shouldn't inhibit such discussions. I wonder if you're intending that silence: denotes a block in which all exceptions would be ignored. And that any calls made from there that threw exceptions would also be ignored. If so, it's a bad idea. Only if you could qualify it to a particular exception list might it be reasonable. As it stands, it's just as bad as the bare try/except that you were already given. Do you really want to ignore syntax errors, skip bad data, and ignore missing files, and generally plow down whatever execution path happens to result? Just my opinion. DaveA From lipun4u at gmail.com Wed Mar 3 05:43:38 2010 From: lipun4u at gmail.com (asit) Date: Wed, 3 Mar 2010 02:43:38 -0800 (PST) Subject: process mp3 file References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> Message-ID: <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> > Define "processing". getting the title, song name, etc of the file and updating in a database From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 05:56:03 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 11:56:03 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> Message-ID: <4b8e4041$0$17447$426a34cc@news.free.fr> Eike Welk a ?crit : > John Posner wrote: >> I've updated the text at this location: >> >> > http://cl1p.net/bruno_0301.rst/ > > I think this is a very useful writeup! > > It would be perfect with a little bit of introduction that says: > 1. - What it is: "The rough details of method look-up"; > 2. - which contains some of the questions that that made that authors write > the text. This way people with similar questions can find it with Google. > John, do you think you could something with the following ? """ "Is it a function ? is it a method ? No, it's... " - or : What's in a Python method ? Python newcomers often have hard time understanding the "magic" behind Python's methods - and truth is that Python's object model can be a bit peculiar when compared to most mainstream (or not-so-mainstream) OOPLs. As a matter of fact, there are quite a few threads on c.l.py with either direct or indirect questions about what makes a Python method, and I must have explained the whole mechanism at least 3 or 4 times there. The following text is an edited version of my last attempt, as edited, corrected and published by John Posner, MayHisNameBePraised(tm). This text isn't meant as a replacement for neither the official FineManual(tm)[XXX : relevant link] nor the very excellent - if somehow technical - 'Descriptors how-to' [XXX : relevant link]. It's mostly a brief but hopefully helpful overview of what exactly is a Python method, and how Python magically inserts the 'self' or 'cls' argument to method calls. """ Feel free to edit / amend / rewrite / trash at will - you're now officially in charge of publishing this text !-) From andreengels at gmail.com Wed Mar 3 06:02:32 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 3 Mar 2010 12:02:32 +0100 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <6faf39c91003030302l30105064n675b449b45ac1968@mail.gmail.com> On Wed, Mar 3, 2010 at 10:27 AM, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. > > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. I would be against this, because "except: pass" is a terrible code smell. Usage of exceptions can roughly be divided into two areas: 1. Cases where you do know quite well what might go wrong 2. Cases where all kind of stuff might go wrong, including things you perhaps did not think of, and want to deal with all of them In the first case, you should not use a blanket "except", but a more specific one, catching only the specific error or errors you are dealing with. In the second case, a blanket except might well be correct, but in that case, you should not want to pass over the error silently. Usually you will want to notify the user that an error has occurred. Even if that is not the case, you want to make some kind of logging of the error, so that you have the chance of finding it if it is indeed an unexpected (and therefore undoubtedly also unintended) error. Doing a pass over an exception is not a bad thing in itself, but one should only do it when one _knows_ that it is the right action to take. If you have a general exception, you don't know _what_ has gone wrong, so you sure as hell cannot be sure about what's the best action to take. Doing nothing might well be your best guess, but even in that case I want to know that your program has been guessing when I use it. -- Andr? Engels, andreengels at gmail.com From clp2 at rebertia.com Wed Mar 3 06:06:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 03:06:55 -0800 Subject: process mp3 file In-Reply-To: <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> Message-ID: <50697b2c1003030306g1939a4bbg799e4f158f99f4c4@mail.gmail.com> On Wed, Mar 3, 2010 at 2:43 AM, asit wrote: >> Define "processing". > > getting the title, song name, etc of the file and updating in a > database You'd want an ID3 tag library then. Here's one: http://eyed3.nicfit.net/ Cheers, Chris -- http://blog.rebertia.com From durumdara at gmail.com Wed Mar 3 06:12:12 2010 From: durumdara at gmail.com (durumdara at gmail.com) Date: Wed, 03 Mar 2010 12:12:12 +0100 Subject: easy install failed Message-ID: <4B8E440C.2070204@gmail.com> Hi! Windows, Py2.6. I read about Pyda and Spider. I used Pyscripter, Geany, ULIPAD, and COntext, and Netbeans with Python; but I want to try these products. But easy_install failed on get them: C:\Python26\Scripts>easy_install.exe pida Searching for pida Reading http://pypi.python.org/simple/pida/ Reading http://pida.co.uk/ Reading http://pida.co.uk/download/ Reading http://pida.vm.bytemark.co.uk/ Reading http://code.google.com/p/pida/downloads/list Reading http://pida.berlios.de Reading http://pida.berlios.de/index.php/PIDA:Downloads Reading http://pida.berlios.de/downloads/ Best match: pida 0.6beta3 Downloading http://pypi.python.org/packages/source/p/pida/pida-0.6beta3.tar.gz#m d5=ecd790f5dd6f77eb4ebfc719f8e26114 Processing pida-0.6beta3.tar.gz Running pida-0.6beta3\setup.py -q bdist_egg --dist-dir c:\docume~1\chris\locals~ 1\temp\easy_install-vd4hql\pida-0.6beta3\egg-dist-tmp-9zwwxx error: A rendszer nem tal?lja a megadott f?jlt {The system cannot found the file} Many of packages are not installed on my system, because of "file" or "path" not found. For example: C:\Python26\Scripts>easy_install.exe kiwi Searching for kiwi Reading http://pypi.python.org/simple/kiwi/ Reading http://www.ivy.fr/kiwi Best match: kiwi 0.8.6 Downloading http://www.ivy.fr/kiwi/kiwi-0.8.6.tar.gz Processing kiwi-0.8.6.tar.gz error: Couldn't find a setup script in c:\docume~1\chris\locals~1\temp\easy_inst all-dxia7w\kiwi-0.8.6.tar.gz May these packages not have "setup.py"? Or not working in Windows? Or they have binaries somewhere, like pywin32, and wxpython? THanks for your help: dd -------------- next part -------------- An HTML attachment was scrubbed... URL: From orenelrad at gmail.com Wed Mar 3 06:47:28 2010 From: orenelrad at gmail.com (Oren Elrad) Date: Wed, 3 Mar 2010 06:47:28 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" Message-ID: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> To all that responded, thanks for the prompt response folks, your criticisms are well taken. Coming from Cland, one is inculcated with the notion that if the programmer wants to shoot himself in the foot the language ought not to prevent that (or even should return him a loaded magnum with the safety off and the hair-trigger pulled). My apologies for not immediately grokking the cultural difference in pytown. With that said, let me at least offer a token defense of my position. By way of motivation, I wrote that email after copying/pasting the following a few times around a project until I wrote it into def SilentlyDelete() and its cousin SilentlyRmdir() """ code involving somefile """ try: ........os.remove(somefile) except: .......pass # The bloody search indexer has got the file and I can't delete it. Nothing to be done. Certainly the parade of horribles (bad files! corrupt data! syntax errors!) is a tad melodramatic. Either os.remove() succeeds or it doesn't and the execution path (in the estimation of this programmer, at least) is not at all impacted by whether it succeeds or fails. I know with certainty at compile time what exceptions might be raised and what the consequences of passing them are and there is no sense pestering the user or sweating over it. Nor can I see the logic, as was suggested, in writing "except OSError:" since (seems to me) mere surplusage -- it neither causes a semantic difference in the way the program runs nor provides anything useful to the reader. Now, perhaps this is a special case that is not nearly special enough to warrant its own syntactic sugar, I granted that much, but >30,000 examples in Google Code cannot be considered to be a complete corner case either. Briefly skimming those results, most of them seem to be of this flavor, not the insane programmer that wants to write "silence: CommitDBChangesEmailWifeAndAdjustBankAccount()" nor novices that aren't aware of what they might be ignoring. At any rate (and since this is far more words than I had intended), I want to reiterate that the criticism is well-taken as a cultural matter. I just don't want everyone to think I'm bloody insane or that I'm not aware this is playing with fire. Maybe we can put it in module "YesImSureJustBloodyDoItAlreadyGoddamnit" and prints an ASCII skull and crossbones to the console when imported? :-P ~ Oren PS. I did like Dave's suggestions that one might want to write "silence Type1 Type2:" which I suppose goes a long way towards alleviating the concern that the programmer doesn't know what he's missing. Doesn't quite meet my desire (both syntaxes would be nice, of course) to avoid the verbiage involved with explaining to the compiler (or the next reader) something that it knows well enough by now (or ought to know, at least). From tibor.beck at hotmail.com Wed Mar 3 06:57:13 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Wed, 3 Mar 2010 03:57:13 -0800 (PST) Subject: monkey patching with @classmethod Message-ID: Hi, is there some well-known problems with class method monkey patching? I've got this error message: unbound method get_pocet_neocislovanych() must be called with Pozemok instance as first argument (got Subjekt instance instead) The method is declared as: @classmethod @monkeypatch(Dokument) def get_pocet_neocislovanych(cls, subjekt): return cls.objects.filter(subjekt = subjekt, cislo__isnull = True).count() # or pass, this line is not important and the monkey patch decorator is declared as: def monkeypatch(cls): def decorator(func): setattr(cls, func.__name__, func) return func return decorator If I move the method to class declaration (whitout monkey patching), everything is ok, but only if I've restarted the server. From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 07:09:12 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 13:09:12 +0100 Subject: monkey patching with @classmethod In-Reply-To: References: Message-ID: <4b8e5161$0$23009$426a74cc@news.free.fr> gentlestone a ?crit : > Hi, is there some well-known problems with class method monkey > patching? > > I've got this error message: > > unbound method get_pocet_neocislovanych() must be called with Pozemok > instance as first argument (got Subjekt instance instead) > The method is declared as: > @classmethod > @monkeypatch(Dokument) > def get_pocet_neocislovanych(cls, subjekt): > return cls.objects.filter(subjekt = subjekt, cislo__isnull = > True).count() # or pass, this line is not important > > and the monkey patch decorator is declared as: > def monkeypatch(cls): > def decorator(func): > setattr(cls, func.__name__, func) > return func > return decorator The decorators are applied in order. So you first add the yet undecorated function as an attribute of the class, then pass the function to classmethod. FWIW, this monkeypatch decorator is IMHO a plain waste of time. The following code does the same thing and is (IMHO again) *much* more readable: def get_pocet_neocislovanych(cls, subjekt): return cls.objects.filter( subjekt=subjekt, cislo__isnull= True ).count() # or pass, this line is not important Dokument.get_pocet_neocislovanych=@classmethod(get_pocet_neocislovanych) Also, Django's BestPractice(tm) is to define such "query" methods on the model's manager, not as a classmethod of the model. My 2 cents From tibor.beck at hotmail.com Wed Mar 3 07:11:30 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Wed, 3 Mar 2010 04:11:30 -0800 (PST) Subject: monkey patching with @classmethod References: Message-ID: <1a134530-386e-47e4-9c63-385f8014c838@q15g2000yqj.googlegroups.com> On 3. Mar., 12:57 h., gentlestone wrote: > Hi, is there some well-known problems with class method monkey > patching? > > I've got this error message: > > unbound method get_pocet_neocislovanych() must be called with Pozemok > instance as first argument (got Subjekt instance instead) > > The method is declared as: > @classmethod > @monkeypatch(Dokument) > def get_pocet_neocislovanych(cls, subjekt): > ? ? return cls.objects.filter(subjekt = subjekt, cislo__isnull = > True).count() # or pass, this line is not important > > and the monkey patch decorator is declared as: > def monkeypatch(cls): > ? ? def decorator(func): > ? ? ? ? setattr(cls, func.__name__, func) > ? ? ? ? return func > ? ? return decorator > > If I move the method to class declaration (whitout monkey patching), > everything is ok, but only if I've restarted the server. for complexity, there is a code I call the method: def _application_menu(request, subjekt, aplikacia_url_name): return render_to_response('subjekty/aplikacia.html', { 'subjekt' : subjekt, 'aplikacia_url_name' : aplikacia_url_name, 'aplikacia_dictionary' : aplikacia_dictionary(aplikacia_url_name), 'listy' : [ (dokument_url_name, dict( get_verbose_name_plural = dokument.get_verbose_name_plural(), get_pocet_neocislovanych = dokument.get_pocet_neocislovanych(subjekt), get_pocet_celkom = dokument.get_pocet_celkom(subjekt), )) for dokument_url_name, dokument in aplikacia_dictionary(aplikacia_url_name)['listy'] ], }, context_instance = RequestContext(request)) unfortunately, sometimes it works, sometimes not, I cannot imagine the reason, why and when it works and not - even whitout monkey patching seems like some black magic From albert at spenarnc.xs4all.nl Wed Mar 3 07:43:34 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 03 Mar 2010 12:43:34 GMT Subject: Which mock library do you prefer? References: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: In article , Lacrima wrote: >On Feb 16, 10:30=A0pm, Ben Finney wrote: >> Lacrima writes: >> > And I have already refused to write totally isolated tests, because it >> > looks like a great waste of time. >> >> It only looks like that until you chase your tail in a long, fruitless >> debugging session because (you later realise) the behaviour of one test >> is being affected by another. Test isolation is essential to ensure that >> your tests are doing what you think they're doing. >> >> -- >> =A0\ =A0 =A0 =A0 =93A =91No=92 uttered from deepest conviction is better = >and greater | >> =A0 `\ =A0 =A0 =A0 than a =91Yes=92 merely uttered to please, or what is = >worse, to | >> _o__) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0avoid tr= >ouble.=94 =97Mohandas K. Gandhi | >> Ben Finney > >Hi! > >Right, isolation is essential. But I can't decide to which extent I >should propagate isolation. >For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, >author suggests that if you do unittesting you should isolate the >smallest units of code from each other. For example, if you have a >class: >Class SomeClass(object): > def method1(self): > return 5 > def method2(self): > return self.method1 + 10 > >According to the book, if you want to test method2, you should isolate >it from method1 and class instance('self'). >Other books are not so strict... > >And what should I follow as newbie? > >Currently, I don't create mocks of units if they are within the same >class with the unit under test. If that is not right approach, please, >explain what are best practices... I am just learning TDD.. Unit testing is a concept that goes well with functions without side effects. If you have classes, that doesn't work so well. For classes use cases are the way to go. Think about it. The whole state of an object can affect the way a method works. So effectively for a unit test you have to put the object in a whole special fully controlled state. The point of an object is that it can't have just any state, but only those attained by calling methods properly. So you may find yourself artificially imposing states on an object with great effort, and expecting error detection where the errors cannot in fact occur etc. etc. Not that coming up with good use cases is easy, but at least they are naturally related to your objects. > >with regards, >Maxim Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From olof.bjarnason at gmail.com Wed Mar 3 07:45:28 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 3 Mar 2010 13:45:28 +0100 Subject: Working group for Python CPAN-equivalence? Message-ID: Hi everybody! The "Where is CPAN for Python?" question keeps popping up, with answers ranging from "There is no CPAN for Python" and "We already have CPAN for Python" (confusing). I'm wondering - is there any work being done identifying .. (1) what is so good with CPAN? (2) how can it be brought to the Python world? Is there a working group/initiative for this? Web page? Discussion group? /Olof From stefan_ml at behnel.de Wed Mar 3 07:52:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 13:52:07 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: Message-ID: Olof Bjarnason, 03.03.2010 13:45: > The "Where is CPAN for Python?" question keeps popping up, with > answers ranging from "There is no CPAN for Python" and "We already > have CPAN for Python" (confusing). It confuses me that you call this "confusing". > I'm wondering - is there any work being done identifying .. > > (1) what is so good with CPAN? > (2) how can it be brought to the Python world? > > Is there a working group/initiative for this? Web page? Discussion group? I think the right place to discuss any deficiencies of PyPI compared to CPAN is the distutils-sig mailing list. Stefan From python.list at tim.thechases.com Wed Mar 3 07:55:54 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Mar 2010 06:55:54 -0600 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <4B8E5C5A.9020407@tim.thechases.com> Oren Elrad wrote: > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass The general response to "except: pass" from the Old Ones on the python list (and those younger ones who tend to prescribe good style) is a fairly immediate "don't use bare excepts". So endorsing this "silence" syntax would be tantamount to condoning bare excepts. I'm not sure you'll find much support. http://www.google.com/search?q=site%3Amail.python.org+%22bare+excepts%22 (I've had problems with Google finding all posts to c.l.p on m.p.o recently, so this may only be a recent representative sample) -tkc From stefan_ml at behnel.de Wed Mar 3 07:56:19 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 13:56:19 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: Message-ID: Stefan Behnel, 03.03.2010 13:52: > Olof Bjarnason, 03.03.2010 13:45: >> The "Where is CPAN for Python?" question keeps popping up, with >> answers ranging from "There is no CPAN for Python" and "We already >> have CPAN for Python" (confusing). > > It confuses me that you call this "confusing". > > >> I'm wondering - is there any work being done identifying .. >> >> (1) what is so good with CPAN? >> (2) how can it be brought to the Python world? >> >> Is there a working group/initiative for this? Web page? Discussion group? > > I think the right place to discuss any deficiencies of PyPI compared to > CPAN is the distutils-sig mailing list. Ah, and the catalog-sig, if it's really related to the index rather than packages and package distribution. Stefan From olof.bjarnason at gmail.com Wed Mar 3 07:59:00 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 3 Mar 2010 13:59:00 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: Message-ID: 2010/3/3 Stefan Behnel : > Olof Bjarnason, 03.03.2010 13:45: >> >> The "Where is CPAN for Python?" question keeps popping up, with >> answers ranging from "There is no CPAN for Python" and "We already >> have CPAN for Python" (confusing). > > It confuses me that you call this "confusing". How come? > > >> I'm wondering - is there any work being done identifying .. >> >> (1) what is so good with CPAN? >> (2) how can it be brought to the Python world? >> >> Is there a working group/initiative for this? Web page? Discussion group? > > I think the right place to discuss any deficiencies of PyPI compared to CPAN > is the distutils-sig mailing list. Thanks. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://olofb.wordpress.com From ben+python at benfinney.id.au Wed Mar 3 08:08:20 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 00:08:20 +1100 Subject: Which mock library do you prefer? References: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: <87wrxtv9h7.fsf@benfinney.id.au> Albert van der Horst writes: > Unit testing is a concept that goes well with functions without side > effects. If you have classes, that doesn't work so well. How so? Unit tests are ideal for testing classes, in my experience; they can be inspected and tested as a distinct unit of code. > For classes use cases are the way to go. That's a category error. Use cases are good for *functional* testing; that is, testing of the system as a whole, with the focus on specific uses to which the system needs to be put. They're quite orthogonal. Neither interferes with the other. It's best to have both. > Think about it. The whole state of an object can affect the way a > method works. So effectively for a unit test you have to put the > object in a whole special fully controlled state. That's right. This is called a ?test fixture?, and it's a central concept of unit testing. There is explicit support in xUnit-style unit test libraries (like Python's ?unittest?) for test fixtures. -- \ ?When I was a kid I used to pray every night for a new bicycle. | `\ Then I realised that the Lord doesn't work that way so I stole | _o__) one and asked Him to forgive me.? ?Emo Philips | Ben Finney From lie.1296 at gmail.com Wed Mar 3 08:09:20 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 04 Mar 2010 00:09:20 +1100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> Message-ID: <4b8e5f9f$1@dnews.tpgi.com.au> On 03/03/2010 04:48 PM, Steven D'Aprano wrote: > Or one can simply use *reason*: what justification is there for putting > comments in strings at the top of the function? The only one I can see is > if you are writing for an embedded device, you may want to remove doc > strings to save memory -- and even that is implementation dependent. Python already have a well-defined mechanism to remove docstrings with the -O flag; there is really no other reason but plain ignorance and inflexibility to think in other language than . From lie.1296 at gmail.com Wed Mar 3 08:19:56 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 04 Mar 2010 00:19:56 +1100 Subject: There should be one-- and preferably only one --obvious way to do it (was "Interest check in some delicious syntactic sugar for "except:pass"") In-Reply-To: References: Message-ID: <4b8e621b@dnews.tpgi.com.au> On 03/03/2010 08:27 PM, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ......... block > > -------------------------> > > try: > .........block > except: > .........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. Given that python HATE bare-except (and `pass`-block bare except is even worse) and given python's idiosyncrasies "There should be one-- and preferably only one --obvious way to do it", "Errors should never pass silently"; the chance for `silence` keyword is precisely zero. > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. There are lots of reason why bare-except is bad, one being is that it makes it way too easy to ignore errors that you don't actually want to silence; and given that bare-excepts would prevent Ctrl+C (Interrupt) from working. Sorry, but IMHO we shouldn't make syntax sugar for bad practices. From ben+python at benfinney.id.au Wed Mar 3 08:21:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 00:21:14 +1100 Subject: Working group for Python CPAN-equivalence? References: Message-ID: <87r5o1v8vp.fsf@benfinney.id.au> Olof Bjarnason writes: > Hi everybody! > > The "Where is CPAN for Python?" question keeps popping up, with > answers ranging from "There is no CPAN for Python" and "We already > have CPAN for Python" (confusing). Caused in no small measure by the fact that Perl people mean at least two distinct things by ?Where is CPAN for Python??: * The central package registry, CPAN, with metadata in a standard queryable format, and all registered packages redundantly mirrored and available for installation at user-specified versions. We have an equivalent in PyPI, though it's incomplete since many *registered* packages are not actually hosted *at* PyPI. * The command-line tool, ?cpan?, used for performing operations on the set of locally-installed Perl packages, and for package maintainers performing operations on the repository. We have nothing like this. The Distutils library does a small part of the job, and the third-party ?easy_install? program works for those which use the Setuptools extensions; but there's nothing at all equivalent to Perl's ?cpan? tool. Often, Perl people asking simply ?Where is CPAN for Python?? are asking about a third thing: * The unified, mature, actively-maintained, seamless combination of the CPAN repository and the ?cpan? tool, that work together as a single reliable system to such an extent that one can sensibly talk about them *both* as one thing, ?CPAN?. This one we're a *long* way from with Python, IMO. Much work has been going on over the last year or so, and it's encouraging to see; but so much of that work is dealing with the legacy burden of Distutils that I get weary seeing how far there is to go. -- \ ?A child of five could understand this. Fetch me a child of | `\ five.? ?Groucho Marx | _o__) | Ben Finney From zhushazang at yahoo.com.br Wed Mar 3 08:32:30 2010 From: zhushazang at yahoo.com.br (Zhu Sha Zang) Date: Wed, 03 Mar 2010 10:32:30 -0300 Subject: Eric4 vs Python3.1 Message-ID: <4B8E64EE.9040707@yahoo.com.br> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Someone using Eric4 to program with Python3/3.1? What can i do, because he insist to use only Python2.6.4. Att -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkuOZO4ACgkQ35zeJy7JhCjdFACfZrjVa+8O9fu/7FEPr6mVeaEg Rm0AmgM+XtuxFH1zUnfkaphF+MgPy3pf =MVeJ -----END PGP SIGNATURE----- From tibor.beck at hotmail.com Wed Mar 3 08:45:27 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Wed, 3 Mar 2010 05:45:27 -0800 (PST) Subject: monkey patching with @classmethod References: <4b8e5161$0$23009$426a74cc@news.free.fr> Message-ID: <0b3928bb-04e6-402a-9842-680b621ae256@x22g2000yqx.googlegroups.com> On 3. Mar., 13:09 h., Bruno Desthuilliers wrote: > gentlestone a ?crit : > > > > > Hi, is there some well-known problems with class method monkey > > patching? > > > I've got this error message: > > > unbound method get_pocet_neocislovanych() must be called with Pozemok > > instance as first argument (got Subjekt instance instead) > > The method is declared as: > > @classmethod > > @monkeypatch(Dokument) > > def get_pocet_neocislovanych(cls, subjekt): > > ? ? return cls.objects.filter(subjekt = subjekt, cislo__isnull = > > True).count() # or pass, this line is not important > > > and the monkey patch decorator is declared as: > > def monkeypatch(cls): > > ? ? def decorator(func): > > ? ? ? ? setattr(cls, func.__name__, func) > > ? ? ? ? return func > > ? ? return decorator > > The decorators are applied in order. So you first add the yet > undecorated function as an attribute of the class, then pass the > function to classmethod. > > FWIW, this monkeypatch decorator is IMHO a plain waste of time. The > following code does the same thing and is (IMHO again) *much* more readable: > > def get_pocet_neocislovanych(cls, subjekt): > ? ? ? return cls.objects.filter( > ? ? ? ? ?subjekt=subjekt, > ? ? ? ? ?cislo__isnull= True > ? ? ? ? ?).count() # or pass, this line is not important > > Dokument.get_pocet_neocislovanych=@classmethod(get_pocet_neocislovanych) > > Also, Django's BestPractice(tm) is to define such "query" methods on the > ? model's manager, not as a classmethod of the model. > > My 2 cents thx, I changed my definitions to manager style and have no more problems seems to be safe to use manager instead classmethod - do not know why :-) From benjamin.kaplan at case.edu Wed Mar 3 08:48:37 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Mar 2010 08:48:37 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: On Wed, Mar 3, 2010 at 6:47 AM, Oren Elrad wrote: > To all that responded, thanks for the prompt response folks, your > criticisms are well taken. Coming from Cland, one is inculcated with > the notion that if the programmer wants to shoot himself in the foot > the language ought not to prevent that (or even should return him a > loaded magnum with the safety off and the hair-trigger pulled). My > apologies for not immediately grokking the cultural difference in > pytown. > > With that said, let me at least offer a token defense of my position. > By way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. > > Certainly the parade of horribles (bad files! corrupt data! syntax > errors!) is a tad melodramatic. Either os.remove() succeeds or it > doesn't and the execution path (in the estimation of this programmer, > at least) is not at all impacted by whether it succeeds or fails. I > know with certainty at compile time what exceptions might be raised > and what the consequences of passing them are and there is no sense > pestering the user or sweating over it. Nor can I see the logic, as > was suggested, in writing "except OSError:" since (seems to me) mere > surplusage -- it neither causes a semantic difference in the way the > program runs nor provides anything useful to the reader. > > What if the user presses Ctrl-C to try to quit the program? Your bare except is catching the KeyboardInterrupts and ignoring them. -------------- next part -------------- An HTML attachment was scrubbed... URL: From desktopsbyduck at gmail.com Wed Mar 3 08:49:34 2010 From: desktopsbyduck at gmail.com (RICHARD MOORE) Date: Wed, 3 Mar 2010 05:49:34 -0800 (PST) Subject: RICHARD MOORE wants to stay in touch on LinkedIn Message-ID: <1313196773.7301341.1267624174377.JavaMail.app@ech3-cdn11.prod> LinkedIn ------------ I'd like to add you to my professional network on LinkedIn. - RICHARD MOORE Confirm that you know RICHARD MOORE https://www.linkedin.com/e/isd/1117171902/jlHq1JKw/EML-invg_56/ ------ (c) 2010, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From desktopsbyduck at gmail.com Wed Mar 3 08:50:07 2010 From: desktopsbyduck at gmail.com (RICHARD MOORE) Date: Wed, 3 Mar 2010 05:50:07 -0800 (PST) Subject: RICHARD MOORE wants to stay in touch on LinkedIn Message-ID: <1916304926.7302790.1267624207959.JavaMail.app@ech3-cdn11.prod> LinkedIn ------------ I'd like to add you to my professional network on LinkedIn. - RICHARD MOORE Confirm that you know RICHARD MOORE https://www.linkedin.com/e/isd/1117171902/jlHq1JKw/EML-invg_56/ ------ (c) 2010, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From yyfgv at yahoo.com.ar Wed Mar 3 09:00:16 2010 From: yyfgv at yahoo.com.ar (Publicidad para Todos) Date: 03 Mar 2010 11:00:16 -0300 Subject: Tu mailing llega ahora a todos lados Message-ID: <20100303105936.0C607419FF28A41A@yahoo.com.ar> An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Wed Mar 3 09:33:30 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 3 Mar 2010 15:33:30 +0100 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: > By way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. You just found the right solution: define a function for something that you do repeatedly. No need to change the language. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From subhakolkata1234 at gmail.com Wed Mar 3 09:36:23 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Wed, 3 Mar 2010 06:36:23 -0800 (PST) Subject: Few early questions on Class Message-ID: <24aeb097-6376-46b8-a3ff-df4a04d49a3c@y7g2000prc.googlegroups.com> Dear Group, I was practising some early example of class if you can kindly let me know where I was going wrong. I am pasting directly from IDLE. There may be slight indentation problem. I am using Python 2.6.4 on Windows XP Service Pack 3. The Code and the output: >>> class Student: def _init_(self,name): self.name=name self.attendance=0 self.marks=[] number_of_marks=len(self.marks) print number_of_marks >>> b=Student("Bobby") Traceback (most recent call last): File "", line 1, in b=Student("Bobby") TypeError: this constructor takes no arguments >>> Class Shape: SyntaxError: invalid syntax >>> class Shape: def _init_(self,x,y): self.x=x self.y=y description="This Shape is not been described Yet" author="Nobody has Claimed it Yet" def area(self): return self*x+self*y def perimeter(self): return 2*self.x+2*self*y >>> rectangle=Shape(100,45) Traceback (most recent call last): File "", line 1, in rectangle=Shape(100,45) TypeError: this constructor takes no arguments >>> rectangle=Shape() >>> print rectangle.area() Traceback (most recent call last): File "", line 1, in print rectangle.area() AttributeError: Shape instance has no attribute 'area' >>> Best Regards, Subhabrata. From pranav.choudhary at gmail.com Wed Mar 3 09:41:25 2010 From: pranav.choudhary at gmail.com (pranav) Date: Wed, 3 Mar 2010 06:41:25 -0800 (PST) Subject: save CRL to a file (M2Crypto.X509.CRL object) Message-ID: I do not see an option to save M2Crypto.X509.CRL object to a file. Am I overlooking something? Thanks From python at mrabarnett.plus.com Wed Mar 3 09:42:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 14:42:00 +0000 Subject: Docstrings considered too complicated In-Reply-To: <7v695nFa0fU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> Message-ID: <4B8E7538.2080003@mrabarnett.plus.com> Gregory Ewing wrote: > MRAB wrote: > >> BTW, the first programming I did was in hexadecimal (C4xx was "LDI xx"). > > Hey, a SC/MP! That was my first programming language, > too. What sort of machine was it in? > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment display, which I had to solder together, and also make my own power supply. I had the extra RAM and the I/O chip, so that's 256B (including the memory used by the monitor) + 256B additional RAM + 128B more in the I/O chip. From jmg3000 at gmail.com Wed Mar 3 09:42:24 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Wed, 3 Mar 2010 06:42:24 -0800 (PST) Subject: Few early questions on Class References: <24aeb097-6376-46b8-a3ff-df4a04d49a3c@y7g2000prc.googlegroups.com> Message-ID: <7277b1d5-e1b5-4afc-a9a4-9e45e9e4ff80@z11g2000yqz.googlegroups.com> Hi Subhabrata, s/_init_/__init__/ From python at mrabarnett.plus.com Wed Mar 3 09:45:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 14:45:06 +0000 Subject: case do problem In-Reply-To: <7v6cviFq18U1@mid.individual.net> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> <7v6cviFq18U1@mid.individual.net> Message-ID: <4B8E75F2.8090608@mrabarnett.plus.com> Gregory Ewing wrote: > Alf P. Steinbach wrote: >> * Tracubik: > > >>> iterations=0; >>> count=0; >>> REPEAT; >>> iterations = iterations+1; >>> ... >>> IF (genericCondition) THEN count=count+1; >>> ... >>> CASE count OF: >>> 1: m = 1 >>> 2: m = 10 >>> 3: m = 100 >> >> Uhm, is this syntactically valid Pascal? As I recall, every Pascal >> construct was delimited in some way. > > I think it's okay. Pascal's control structures such as > if-then and while-do mostly take single statements and > didn't have an ending keyword. If you want multiple > statements in the body you have to put begin-end around > them. > > Putting a semicolon after REPEAT is stylistically a > bit odd, but it's not wrong. > There shouldn't be a colon after the 'OF', and the cases themselves should be separated by semicolons (the case-statement itself ends with 'end'). From python.list at tim.thechases.com Wed Mar 3 09:49:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Mar 2010 08:49:27 -0600 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: <4B8E76F7.20809@tim.thechases.com> Oren Elrad wrote: > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. I admit there are times I've done something similar, usually with what I call my "int0" and "float0" utility functions which roughly translate to "give me a stinkin' int/float and if something goes wrong, give me 0, but the return result better darn well be an int/float!" functions. But as you describe and was later commended as a right-ish way to approach it, abstracting that off into a function with minimal code in the try: block is the right way to go. -tkc def int0(v): """converts v to a int, or returns 0 if it can't""" try: return int(v) except: # usually a ValueError but catch all cases try: # int("1.1") fails so try float()ing it first return int(round(float(v))) except: return 0 def float0(v): """converts v to a float, or returns 0 if it can't""" try: return float(v) except: return 0.0 From electriclightheads at gmail.com Wed Mar 3 09:50:09 2010 From: electriclightheads at gmail.com ('2+) Date: Wed, 3 Mar 2010 23:50:09 +0900 Subject: pyao makes the right sound but why? Message-ID: <1078018b1003030650g499e4a7bvfaab763be485755c@mail.gmail.com> with my soy.py tofu = soy.Bean() x = tofu.pattern(44100 * 3) creates x which is an array('h') and len(x) = 44100 * 6 this x is a stereo groove pattern that lasts 3 sec if samplerate is set to 44100 and since wave.py could save it to a_file.wav i was wondering if dev = ao.AudioDevice('alsa') dev.play(x) could launch me a semi realtime dj kinda sys luckily .. it does seem to be making the right sound but why? the default of the samplerate and that 16bit happened to match with my thing x? o but if i do dev.play(x, len(x)) it only plays the half of the pattern and dev.play(x, 2 * len(x)) does the right thing and the 2nd 4th 6th .. play gives me ALSA underrun, at least 0ms 3rd, 5th, 7th does it fine /usr/share/doc/python-pyao doesn't teach me the answer does somebody know more about pyao? -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From spamfresser at ch3ka.de Wed Mar 3 09:50:19 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 03 Mar 2010 15:50:19 +0100 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: References: Message-ID: Am 03.03.2010 12:47, schrieb Oren Elrad: > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. You don't know that what you stated in your comment is true. All you know is that there was an exception. To find the reason, you have to inspect the exception. You escpecially do NOT know whether the file is removed or not. OK, os.remove() might be a CPython builtin (not sure ATM), but in general all sort of crazy things can happen here, like ImportError raised by code in the lib or so. And of course: a bare except: also catches ^C or SystemExit. That is almost certainly *not* what you want, right? To your first question about a "silenced" keyword: you could emulate this with context managers I guess. Something like (untested, just a quick mockup how it could look): class silenced: def __init__(self, *silenced): self.exceptions=tuple(silenced) #just to be explicit def __enter__(self): return self #dito1 def __exit__(self, type, value, traceback): for ex in self.exceptions: if isinstance(value, ex): return True #supresses exception So: with silenced(os.Error): os.remove(somefile) Would translate to: try: os.remove(somefile) except os.Error: pass One nice thing about this approach would be that you can alias a set of exceptions with this: idontcareabouttheseerrors=silenced(TypeError, ValueError, PEBCAKError, SyntaxError, EndOfWorldError, 1D10T_Error) with idontcareabouttheseerrors: do_stuff() Regards, Michael From michaelveloz at gmail.com Wed Mar 3 09:57:56 2010 From: michaelveloz at gmail.com (Veloz) Date: Wed, 3 Mar 2010 06:57:56 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> <7v6cf4FnnrU1@mid.individual.net> Message-ID: <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> On Mar 3, 1:14?am, Gregory Ewing wrote: > MRAB wrote: > > I suppose it depends on the complexity of the data structure. A dict's > > methods are threadsafe, for example, but if you have a data structure > > where access leads to multiple method calls then collectively they need > > a lock. > > It also depends on the nature of the objects being used > as dict keys. Dict operations invoke the hashing and > comparison methods of the keys, which in general can > execute arbitrary Python code. > > If the keys are elementary built-in types such as > strings or ints, then dict operations will *probably* > be atomic. But I think I'd use a lock anyway, to be > on the safe side. > > -- > Greg Unless I missed where you guys were going, I think we got off the main point. The main question at hand was this: what's the best way (heck, any way) to implement a sort of "peek" whereby a number of processes can write results to some common "object" and some other process can "peek" into this object, looking for specific items they're interested in? I've tried doing this with a queue, as follows: children all write results to queue, each result has an identifier. Another interested party, which wants to know if identifier XXX has been placed in the queue, removes all the items, one by one from the queue, "keeps" the one matching the identifier (if found) and puts the rest of the items back on the queue, so other interested parties can also look through it. This is not a good solution, but it illustrates what I'm trying to achieve.. I'm looking at multiprocessing.Manager, ctypes, etc, but nothing's really jumped out. I also tried creating my own list class which uses locks to provide a "peek and remove" method, but I don't have a good way to share an instance of this object across processes. Any thoughts would be welcomed! Michael From jjposner at optimum.net Wed Mar 3 09:58:46 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 09:58:46 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8e4041$0$17447$426a34cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: On 3/3/2010 5:56 AM, Bruno Desthuilliers wrote: > Eike Welk a ?crit : >> John Posner wrote: >>> I've updated the text at this location: >>> >>> > http://cl1p.net/bruno_0301.rst/ >> >> I think this is a very useful writeup! >> It would be perfect with a little bit of introduction that says: >> 1. - What it is: "The rough details of method look-up"; >> 2. - which contains some of the questions that that made that authors >> write the text. This way people with similar questions can find it >> with Google. >> > > John, do you think you could something with the following ? Sure thing, Bruno. I'll incorporate/edit your new text below into a Python Wiki entry. The headings in the Documentation table of contents page (http://wiki.python.org/moin/Documentation) seem pretty sober, so I plan to use a straightforward title: FromFunctionsToMethods ... instead of the clearly superior ... ItsAFunctionItsAMethodItsAUseOfTheDescriptorProtocol Does this article belong in the "Advanced Topics" section of the page? I'm not sure, but I'll place it there for now. (Alternative suggestions welcome!) > > """ > "Is it a function ? is it a method ? No, it's... " - or : What's in a > Python method ? > > Python newcomers often have hard time understanding the "magic" behind > Python's methods - and truth is that Python's object model can be a bit > peculiar when compared to most mainstream (or not-so-mainstream) OOPLs. > As a matter of fact, there are quite a few threads on c.l.py with either > direct or indirect questions about what makes a Python method, and I > must have explained the whole mechanism at least 3 or 4 times there. The > following text is an edited version of my last attempt, as edited, > corrected and published by John Posner, MayHisNameBePraised(tm). > > This text isn't meant as a replacement for neither the official > FineManual(tm)[XXX : relevant link] nor the very excellent - if somehow > technical - 'Descriptors how-to' [XXX : relevant link]. It's mostly a > brief but hopefully helpful overview of what exactly is a Python method, > and how Python magically inserts the 'self' or 'cls' argument to method > calls. > """ > > Feel free to edit / amend / rewrite / trash at will - you're now > officially in charge of publishing this text !-) > Yow, the mantle of responsibility weighs heavily upon my poor shoulders! Film at 11, John From jmg3000 at gmail.com Wed Mar 3 10:04:08 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Wed, 3 Mar 2010 07:04:08 -0800 (PST) Subject: Working group for Python CPAN-equivalence? References: Message-ID: <67f0da3c-9c4d-4080-8821-3acbfada1d4f@o30g2000yqb.googlegroups.com> On Mar 3, 7:45?am, Olof Bjarnason wrote: > Hi everybody! > > The "Where is CPAN for Python?" question keeps popping up, with > answers ranging from "There is no CPAN for Python" and "We already > have CPAN for Python" (confusing). > > I'm wondering - is there any work being done identifying .. > > (1) what is so good with CPAN? > (2) how can it be brought to the Python world? > > Is there a working group/initiative for this? Web page? Discussion group? Hi Olof, Discussions about that often take place on the distutils-sig and catalog-sig MLs. People are currently working on making the Cheeseshop even better and the situation is improving. Have a look at [Tarek's blog](http:// tarekziade.wordpress.com/) for more info. ---John From invalid at invalid.invalid Wed Mar 3 10:05:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 15:05:54 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: On 2010-03-03, Gregory Ewing wrote: > Grant Edwards wrote: > >> Just a mediocre copy of the CP/M filesystem, which was in turn >> copied from DEC's RSTS or RSX. > > It was actually an improvement over CP/M's file > system. CP/M didn't have hierarchical directories Neither did the original MS-DOS filesystem. > or timestamps and recorded file sizes in 128-byte blocks > rather than bytes. I thought that was true of the original MS-DOS filesystem as well, but I wouldn't bet money on it. -- Grant Edwards grant.b.edwards Yow! I like the way ONLY at their mouths move ... They gmail.com look like DYING OYSTERS From jmg3000 at gmail.com Wed Mar 3 10:10:07 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Wed, 3 Mar 2010 07:10:07 -0800 (PST) Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> Message-ID: <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> On Mar 2, 11:58?pm, John Bokma wrote: > Lie Ryan writes: > > On 03/03/2010 09:47 AM, TomF wrote: > > [..] > > >> There > >> is also a program called cpan, distributed with Perl. ?It is used for > >> searching, downloading, installing and testing modules from the CPAN > >> repository. ?It's far more extensive than setuptools. ?AFAIK the python > >> community has developed nothing like it. > > > python have easy_install > > How easy is it to /remove/ something? ;-) (Last time I checked I read > something like "manually remove the .egg"... > Have a look at [pip](http://cheeseshop.python.org/pypi/pip). It should support uninstalling packages. ---John From alfps at start.no Wed Mar 3 10:10:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 16:10:26 +0100 Subject: A "scopeguard" for Python Message-ID: For C++ Petru Marginean once invented the "scope guard" technique (elaborated on by Andrei Alexandrescu, they published an article about it in DDJ) where all you need to do to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception, is to declare a ScopeGuard w/desired action. The C++ ScopeGuard was/is for those situations where you don't have proper classes with automatic cleanup, which happily is seldom the case in good C++ code, but languages like Java and Python don't support automatic cleanup and so the use case for something like ScopeGuard is ever present. For use with a 'with' statement and possibly suitable 'lambda' arguments: class Cleanup: def __init__( self ): self._actions = [] def call( self, action ): assert( is_callable( action ) ) self._actions.append( action ) def __enter__( self ): return self def __exit__( self, x_type, x_value, x_traceback ): while( len( self._actions ) != 0 ): try: self._actions.pop()() except BaseException as x: raise AssertionError( "Cleanup: exception during cleanup" ) from I guess the typical usage would be what I used it for, a case where the cleanup action (namely, changing back to an original directory) apparently didn't fit the standard library's support for 'with', like with Cleanup as at_cleanup: # blah blah chdir( somewhere ) at_cleanup.call( lambda: chdir( original_dir ) ) # blah blah Another use case might be where one otherwise would get into very deep nesting of 'with' statements with every nested 'with' at the end, like a degenerate tree that for all purposes is a list. Then the above, or some variant, can help to /flatten/ the structure. To get rid of that silly & annoying nesting. :-) Cheers, - Alf (just sharing, it's not seriously tested code) From spamfresser at ch3ka.de Wed Mar 3 10:15:27 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 03 Mar 2010 16:15:27 +0100 Subject: Is this secure? In-Reply-To: <4b8ddcf6$1@dnews.tpgi.com.au> References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> <4b8ddcf6$1@dnews.tpgi.com.au> Message-ID: Am 03.03.2010 04:51, schrieb Lie Ryan: > import itertools > def gen(): > valid_chars = 'abcdefghijklmnopqrstuvwxyz' > for char in itertools.repeat(valid_chars): > yield char > > gen = gen() > def gen_rand_string(length): > chars = (next(gen) for i in range(length)) > return ''.join(chars) > > since it gives me a perfect distribution of letters, It does not. Only if not (length(valid_chars) % length) Regards, Michael From redazione at italiainweekend.it Wed Mar 3 10:18:23 2010 From: redazione at italiainweekend.it (ItaliaWeekend) Date: Wed, 3 Mar 2010 16:18:23 +0100 Subject: PAGINE DI UNA ITALIA MERAVIGLIOSA Message-ID: <01f6f7b5$40240$efa56794340972@pavillon-pc> An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Mar 3 10:19:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 15:19:56 +0000 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <4B8E7E1C.7090002@mrabarnett.plus.com> Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. > > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. > > ~Oren > > [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en > [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy Bare excepts are a very bad idea. And you want syntactic sugar for them? Aargh! :-) From invalid at invalid.invalid Wed Mar 3 10:30:36 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 15:30:36 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: On 2010-03-03, Grant Edwards wrote: > On 2010-03-03, Gregory Ewing wrote: >> Grant Edwards wrote: >> >>> Just a mediocre copy of the CP/M filesystem, which was in turn >>> copied from DEC's RSTS or RSX. >> >> It was actually an improvement over CP/M's file system. CP/M >> didn't have hierarchical directories > > Neither did the original MS-DOS filesystem. > >> or timestamps and recorded file sizes in 128-byte blocks >> rather than bytes. > > I thought that was true of the original MS-DOS filesystem as > well, but I wouldn't bet money on it. I definitely remember that old MS-DOS programs would treat Ctrl-Z as an EOF marker when it was read from a text file and would terminate a text file with a Ctrl-Z when writing one. I don't know if that was because the underlying filesystem was still did everything in blocks or if it was because those MS-DOS programs were direct ports of CP/M programs. I would have sworn that the orignal MS-DOS file API was FCB based and worked almost exactly like CP/M. IIRC, the "byte stream" API showed up (in the OS) sever versions later. The byte stream API was implemented by many compiler vendor's C libraries on top of the block-oriented FCB API. -- Grant Edwards grant.b.edwards Yow! I had a lease on an at OEDIPUS COMPLEX back in gmail.com '81 ... From mrmakent at gmail.com Wed Mar 3 10:39:05 2010 From: mrmakent at gmail.com (Mike Kent) Date: Wed, 3 Mar 2010 07:39:05 -0800 (PST) Subject: A "scopeguard" for Python References: Message-ID: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup From efruttero at hotmail.com Wed Mar 3 10:40:48 2010 From: efruttero at hotmail.com (efruttero at hotmail.com) Date: Wed, 3 Mar 2010 07:40:48 -0800 (PST) Subject: Smalltalk-like categories for methods ? Message-ID: <8f66e5eb-3dda-4f7a-b607-cd7f2ea0e16b@c16g2000yqd.googlegroups.com> Hello, Is there an IDE that supports methods categories/classification, either through some comment convention, annotation, or any other mean ? Thanks in advance, Eric Fruttero From steve at holdenweb.com Wed Mar 3 10:42:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Mar 2010 10:42:20 -0500 Subject: Queue peek? In-Reply-To: <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> <7v6cf4FnnrU1@mid.individual.net> <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> Message-ID: Veloz wrote: > On Mar 3, 1:14 am, Gregory Ewing wrote: >> MRAB wrote: >>> I suppose it depends on the complexity of the data structure. A dict's >>> methods are threadsafe, for example, but if you have a data structure >>> where access leads to multiple method calls then collectively they need >>> a lock. >> It also depends on the nature of the objects being used >> as dict keys. Dict operations invoke the hashing and >> comparison methods of the keys, which in general can >> execute arbitrary Python code. >> >> If the keys are elementary built-in types such as >> strings or ints, then dict operations will *probably* >> be atomic. But I think I'd use a lock anyway, to be >> on the safe side. >> >> -- >> Greg > > Unless I missed where you guys were going, I think we got off the main > point. The main question at hand was this: what's the best way (heck, > any way) to implement a sort of "peek" whereby a number of processes > can write results to some common "object" and some other process can > "peek" into this object, looking for specific items they're interested > in? > > I've tried doing this with a queue, as follows: children all write > results to queue, each result has an identifier. Another interested > party, which wants to know if identifier XXX has been placed in the > queue, removes all the items, one by one from the queue, "keeps" the > one matching the identifier (if found) and puts the rest of the items > back on the queue, so other interested parties can also look through > it. > > This is not a good solution, but it illustrates what I'm trying to > achieve.. > > I'm looking at multiprocessing.Manager, ctypes, etc, but nothing's > really jumped out. > > I also tried creating my own list class which uses locks to provide a > "peek and remove" method, but I don't have a good way to share an > instance of this object across processes. > > Any thoughts would be welcomed! > Michael Sounds to me like you are using one queue when you should be using several. If a single process wants to distribute information to multiple clients, have a queue for each client. This makes it easy for each client to find out if it has work (if it does its queue is non-empty), Is this helpful, or a red herring? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mwilson at the-wire.com Wed Mar 3 10:43:25 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 03 Mar 2010 10:43:25 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: Tim Chase wrote: > I admit there are times I've done something similar, usually with > what I call my "int0" and "float0" utility functions which > roughly translate to "give me a stinkin' int/float and if > something goes wrong, give me 0, but the return result better > darn well be an int/float!" functions. But as you describe and > was later commended as a right-ish way to approach it, > abstracting that off into a function with minimal code in the > try: block is the right way to go. [ ... ] > def int0(v): > """converts v to a int, or returns 0 if it can't""" > try: > return int(v) > except: # usually a ValueError but catch all cases > try: > # int("1.1") fails so try float()ing it first > return int(round(float(v))) > except: > return 0 > > def float0(v): > """converts v to a float, or returns 0 if it can't""" > try: > return float(v) > except: > return 0.0 I think replacing `except:` with `except StandardError:` would work as well, and be correct, too. Mel. From mrkafk at gmail.com Wed Mar 3 10:46:37 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 16:46:37 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7x635fdcth.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Patrick Maupin writes: >> One of my complaints. If you had read the document you would have >> seen others. I actually have several complaints about YAML, but I >> tried to write a cogent summary. > Yaml sucks, but seems to have gotten some traction regardless. > Therefore the Python principle of "there should be one and only one > obvious way to do it" says: don't try to replace the existing thing if > your new thing is only slightly better. With all due respect, Paul, and with thanks for all the help you've given me, I have to disagree here: this is a really, really complicated matter and I think there is a case even for making things slightly better. I think this is a matter of "investment period", so to speak: is it short or long? In short term, it absolutely makes no sense to produce even slight improvement. But in the long run it will almost certainly pay off to switch to smth even somewhat better implementation (say, imaginary "20%" if you get my drift): suppose we stay with sucky format for 10 years. Wouldn't it make sense to implement a new one and be "in red" in terms of effort expended versus saved for 3 years, but then be "in black" for the following 7 years? > Just deal with the existing > thing's imperfections or make improvements to it. OK, but how? How would you make up e.g. for JSON's lack of comments? Producing accompanying ".json-comment" format and writing libraries that parse the comments and interleave them with JSON file for producing human-readable commented output? I think the effort required by all parties, both developers and users, before they produced smth like this and learned to use this widely and comprehensively, for this manner of improvement would be so high that it would be actually cheaper to dump the thing and develop smth new that has built-in support for comments. If you mean some other method of improving existing things like formats, well let's hear it; but I for one don't see any worth doing to significant extent really, other than dumping the thing or producing next, improved version at least. Improvement: other than making basic tools like parsing libraries editors, what improvements can you realistically make? And such improvements in and of themselves are not very expensive: my GPL Notepad++ has syntax highlighting for YAML (on top of gazillion other languages), and there are parsing libraries for it. So where's this terrible cost to it? OTOH, if YAML produces net benefit for as few as, say, 200 people in real world, the effort to make it has been well worth it. > If you can make a > really powerful case that your new thing is 1000x better than the old > thing, that's different, but I don't think we're seeing that here. Perhaps in ideal world we would be able to develop smth good or at least decent without long series of abominations preceding it. But I don't think we live in such world and I don't think it's possible to produce a decent format (or language) without decades of having to deal with abominations first. We learn as we go along, there's no way but to produce whatever works best at the moment, learning from it, dumping it and then doing smth better. I don't think e.g. Python could be produced without C, COBOL and Fortran preceding it: it's important not only to know how to do it, but also how (and why) not to do it, and learning that can't be done without producing some sort of abomination. I'd argue that abominations are inevitable price of progress and evolution. > Also, XML is used for pretty much everything in the Java world. It > sucks too, but it is highly standardized, it observably gets the job > done, there are tons of structure editors for it, etc. Frankly > I'd rather have stayed with it than deal with Yaml. http://myarch.com/why-xml-is-bad-for-humans http://www.ibm.com/developerworks/xml/library/x-sbxml.html Such reasons alone are enough to consider dumping XML for smth better. Today I had to hand-edit XML config files for two programs (no other option). The files were rather large, complicated and doing it frankly sucked. I also have to maintain a few applications that internally use XML as data format: while they are tolerable, they still leave smth to be desired, as those applications are really slow for larger datasets, their users systematically make errors (like forgetting to attach DTD before editing), and working across various versions of Windows is still not perfect. If somebody out there invents smth that is better than XML "only" by half, I'm all for it. > There are too many of these damn formats. We should ban all but one of > them (I don't much care which one). And making even more of them is not > the answer. I think this is a situation of "beware of what you wish for". Suppose those alternative formats disappeared and you'd have no tools, however imperfect, to use them: I think that in many, many contexts deficiencies of "the" format would be so painful that most developers would just write their own "private" ones, and everyone would be even worse off than they are now. I wouldn't worry too much about "stretching scarce resources thin" either: abominations completely unfit to live waste little in the way of resources, and we learn a deal off them too. There are demonstrable benefits to this too: I for one am happy that ReST is available for me and I don't have to learn a behemoth such as DocBook to write documentation. (imaginary dialog: Paul: "eat your greens and learn your DocBook!" Me: "but I don't like it and there's too much of it..." ;-) OK me off the soapbox. Regards, mk From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 10:48:43 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 16:48:43 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: <4b8e84d2$0$10157$426a74cc@news.free.fr> John Posner a ?crit : > On 3/3/2010 5:56 AM, Bruno Desthuilliers wrote: >> Eike Welk a ?crit : >>> John Posner wrote: >>>> I've updated the text at this location: >>>> >>>> > http://cl1p.net/bruno_0301.rst/ >>> >>> I think this is a very useful writeup! >>> It would be perfect with a little bit of introduction that says: >>> 1. - What it is: "The rough details of method look-up"; >>> 2. - which contains some of the questions that that made that authors >>> write the text. This way people with similar questions can find it >>> with Google. >>> >> >> John, do you think you could something with the following ? > > Sure thing, Bruno. I'll incorporate/edit your new text below into a > Python Wiki entry. The headings in the Documentation table of contents > page (http://wiki.python.org/moin/Documentation) seem pretty sober, so I > plan to use a straightforward title: > > FromFunctionsToMethods What about "TheMagicBehindMethods" ? Mmm, not sure, so do what you think is best. > ... instead of the clearly superior ... > > ItsAFunctionItsAMethodItsAUseOfTheDescriptorProtocol > > Does this article belong in the "Advanced Topics" section of the page? > I'm not sure, but I'll place it there for now. (Alternative suggestions > welcome!) I spotted this: http://www.python.org/doc/faq/programming/#what-is-a-method http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls Our text is probably a bit too long for a direct inclusion in the FAQ, so I'd say it should go in the AdvancedTopics, and be linked from the FAQ. > > Yow, the mantle of responsibility weighs heavily upon my poor shoulders! !-) Thanks for doing the grunt work. From alfps at start.no Wed Mar 3 10:56:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 16:56:25 +0100 Subject: A "scopeguard" for Python In-Reply-To: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Mike Kent: > What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup by the way, that's one advantage: a "with Cleanup" is difficult to get wrong, while a "try" is easy to get wrong, as you did here --- another general advantage is as for the 'with' statement generally > original_dir = os.getcwd() > try: > os.chdir(somewhere) > # Do other stuff also, the "do other stuff" can be a lot of code and also, with more than one action the try-else introduces a lot of nesting > finally: > os.chdir(original_dir) > # Do other cleanup cheers & hth., - alf From mrkafk at gmail.com Wed Mar 3 11:10:08 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 17:10:08 +0100 Subject: Queue peek? In-Reply-To: <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> <7v6cf4FnnrU1@mid.individual.net> <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> Message-ID: Veloz wrote: > Unless I missed where you guys were going, I think we got off the main > point. The main question at hand was this: what's the best way (heck, > any way) to implement a sort of "peek" whereby a number of processes > can write results to some common "object" and some other process can > "peek" into this object, looking for specific items they're interested > in? I have used threads so far and not multiprocessing (much), so I'll describe it using threads: If I were you, I'd do it the simplest possible way, with dictionary and lock, in the following way: 1. Have shared "queue" of tasks, say, a dictionary. 2. Each worker thread and central "queue manager" access the queue in the same manner: ...do your stuff, prepare yourself acquire a lock update or read value from queue ...don't do much here to be able release lock quickly release the lock ...process value If you had your dictionary simple, it could work like Daniel Stutzbach wrote, that updates are thread safe and perhaps you could even dispense with locks and just read the dictionary; and if you wanted to use locks, for "peek"ing you could write a function that could e.g. acquire a lock, do a copy of the queue, release the lock, and return the copy to the object wanting to examine the queue. I have used this approach (although with a list, not a dictionary -- I haven't had the need to do extensive searching by keys) and so far it has worked for me. Regards, mk From steve at REMOVE-THIS-cybersource.com.au Wed Mar 3 11:10:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 16:10:50 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <4b8e8a0a$0$27863$c3e8da3@news.astraweb.com> On Wed, 03 Mar 2010 15:30:36 +0000, Grant Edwards wrote: > I definitely remember that old MS-DOS programs would treat Ctrl-Z as an > EOF marker when it was read from a text file and would terminate a text > file with a Ctrl-Z when writing one. I believe that Windows (at least up to Windows XP) still supports using ctrl-Z as EOF when reading text files. -- Steven From darcy at druid.net Wed Mar 3 11:12:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 11:12:48 -0500 Subject: Docstrings considered too complicated In-Reply-To: <4B8E7538.2080003@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> Message-ID: <20100303111248.7f40d659.darcy@druid.net> On Wed, 03 Mar 2010 14:42:00 +0000 MRAB wrote: > Gregory Ewing wrote: > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment > display, which I had to solder together, and also make my own power > supply. I had the extra RAM and the I/O chip, so that's 256B (including > the memory used by the monitor) + 256B additional RAM + 128B more in the > I/O chip. In case some of you youngsters think that there is a typo in the above, no, he means a total of 640 bytes. In today's terms that would be approx 0.0000006GB. Makes me want to go down to the basement and fire up the Altair. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alfps at start.no Wed Mar 3 11:14:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 17:14:29 +0100 Subject: Docstrings considered too complicated In-Reply-To: <4b8e8a0a$0$27863$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> <4b8e8a0a$0$27863$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Wed, 03 Mar 2010 15:30:36 +0000, Grant Edwards wrote: > >> I definitely remember that old MS-DOS programs would treat Ctrl-Z as an >> EOF marker when it was read from a text file and would terminate a text >> file with a Ctrl-Z when writing one. > > I believe that Windows (at least up to Windows XP) still supports using > ctrl-Z as EOF when reading text files. It does, at least when the Ctrl Z is the sole contents of a "line". And it's a pain. :-( As a practical matter, when entering text in a console window the F6 key generates Ctrl Z. Cheers, - Alf From steve at REMOVE-THIS-cybersource.com.au Wed Mar 3 11:16:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 16:16:55 GMT Subject: Re Interest check in some delicious syntactic sugar for "except:pass" References: Message-ID: <4b8e8b77$0$27863$c3e8da3@news.astraweb.com> On Wed, 03 Mar 2010 06:47:28 -0500, Oren Elrad wrote: > With that said, let me at least offer a token defense of my position. By > way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I can't > delete it. Nothing to be done. Or: (1) you forgot to import the os module (2) the os module (or os.remove) was rebound or monkey-patched to something unexpected (3) you have a bug in your code and somefile=23 (say) instead of the filename you're expecting (4) the user hit the interrupt key just at that instance (5) somefile doesn't exist (6) somefile does exist, but you don't have write-permission for it (7) the disk is mounted read-only (8) you don't have a search indexer and something else has gone wrong Hiding all those different errors is, quite frankly, shoddy work. #1-3 certainly shouldn't be hidden, as they are bugs in your program. #4 shouldn't be hidden, ignoring the user's interrupt command is bad, and rude if it is deliberate. #5 probably shouldn't be hidden either, as it most likely indicates a program bug, but some rare applications may be okay with ignoring it. And #6-8 should be told to the user, so they can fix the problem. -- Steven From floris.bruynooghe at gmail.com Wed Mar 3 11:17:32 2010 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Wed, 3 Mar 2010 08:17:32 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Message-ID: <137d7aa5-a305-4091-a244-904b680d3b56@t41g2000yqt.googlegroups.com> On Mar 2, 6:18?pm, Raymond Hettinger wrote: > On Mar 2, 8:29?am, Veloz wrote: > > > Hi all > > I'm looking for a queue that I can use with multiprocessing, which has > > a peek method. > > > I've seen some discussion about queue.peek but don't see anything in > > the docs about it. > > > Does python have a queue class with peek semantics? > > Am curious about your use case? ?Why peek at something > that could be gone by the time you want to use it. > > ? val = q.peek() > ? if something_i_want(val): > ? ? ? ?v2 = q.get() ? ? ? ? # this could be different than val > > Wouldn't it be better to just get() the value and return if you don't > need it? > > ? val = q.peek() > ? if not something_i_want(val): > ? ? ? q.put(val) What I have found myself wanting when thinking of this pattern is a "q.put_at_front_of_queue(val)" method. I've never actually used this because of not having such a method. Not that it's that much of an issue as I've never been completely stuck and usually found a way to solve whatever I was trying to do without peeking, which could be argued as a better design in the first place. I was just wondering if other people ever missed the "q.put_at_front_of_queue()" method or if it is just me. Regards Floris PS: assuming "val = q.get()" on the first line From johnfilben at yahoo.com Wed Mar 3 11:19:08 2010 From: johnfilben at yahoo.com (John Filben) Date: Wed, 3 Mar 2010 08:19:08 -0800 (PST) Subject: Sort Big File Help Message-ID: <374400.23537.qm@web33805.mail.mud.yahoo.com> I am new to Python but have used many other (mostly dead) languages in the past.? I want to be able to process *.txt and *.csv files.? I can now read that and then change them as needed ? mostly just take a column and do some if-then to create a new variable.? My problem is sorting these files: 1.)??? How do I sort file1.txt by position and write out file1_sorted.txt; for example, if all the records are 100 bytes long and there is a three digit id in the position 0-2; here would be some sample data: a.?????? 001JohnFilben?? b.????? 002Joe? Smith?.. 2.)??? How do I sort file1.csv by column name; for example, if all the records have three column headings, ?id?, ?first_name?, ?last_name?; ?here would be some sample data: a.?????? Id, first_name,last_name b.????? 001,John,Filben c.?????? 002,Joe, Smith 3.)??? What about if I have millions of records and I am processing on a laptop with a large external drive ? basically, are there space considerations? What are the work arounds. Any help would be appreciated. Thank you. ?John Filben Cell Phone - 773.401.2822 Email - johnfilben at yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Wed Mar 3 11:22:06 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 3 Mar 2010 11:22:06 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <4eb0089f1003030822t2a7ec46au57a03de266a4d630@mail.gmail.com> On Wed, Mar 3, 2010 at 10:30 AM, Grant Edwards wrote: > On 2010-03-03, Grant Edwards wrote: > I definitely remember that old MS-DOS programs would treat > Ctrl-Z as an EOF marker when it was read from a text file and > would terminate a text file with a Ctrl-Z when writing one. Actually cmd.exe (at least on Windows XP) still treats Ctrl-Z as an EOF marker. From mrkafk at gmail.com Wed Mar 3 11:26:19 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 17:26:19 +0100 Subject: taking python enterprise level?... In-Reply-To: <20100302015813.5397655e.darcy@druid.net> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > I keep seeing this statement but nothing to back it up. I have created > many apps that run on Python with a PostgreSQL database with a fully > normalized schema and I can assure you that database joins were never > my problem unless I made a badly constructed query or left off a > critical index. I too have done that (Python/PGSQL), even adding a complicated layer of SQLAlchemy on top of it and have not had issue with this: when I profiled one of my apps, it turned out that it spent most of its computation time... rendering HTML. Completely unexpected: I expected DB to be bottleneck (although it might be that with huge datasets this might change). Having said that, re evidence that joins are bad: from what I've *heard* about Hibernate in Java from people who used it (I haven't used Hibernate apart from "hello world"), in case of complicated object hierarchies it supposedly generates a lot of JOINs and that supposedly kills DB performance. So there *may* be some evidence that joins are indeed bad in practice. If someone has smth specific/interesting on the subject, please post. Regards, mk From phil at freehackers.org Wed Mar 3 11:32:12 2010 From: phil at freehackers.org (BlueBird) Date: Wed, 3 Mar 2010 08:32:12 -0800 (PST) Subject: SOAP 1.2 Python client ? Message-ID: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Hi, I am looking for a SOAP 1.2 python client. To my surprise, it seems that this does not exist. Does anybody know about this ? The following clients seem to be both unmaintained and still supporting only SOAP 1.1 : - SUDS - zsi - SOAPy cheers, Philippe From jjposner at optimum.net Wed Mar 3 11:32:55 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 11:32:55 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: On 3/3/2010 9:58 AM, John Posner wrote: > Film at 11, > John > Done -- see http://wiki.python.org/moin/FromFunctionToMethod -John From showell30 at yahoo.com Wed Mar 3 11:37:54 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 3 Mar 2010 08:37:54 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <7071cfa0-0485-4192-b3ee-8e12d9f1fca2@f17g2000prh.googlegroups.com> On Mar 3, 7:46?am, mk wrote: > Paul Rubin wrote: > > Patrick Maupin writes: > >> One of my complaints. ?If you had read the document you would have > >> seen others. ?I actually have several complaints about YAML, but I > >> tried to write a cogent summary. > > Yaml sucks, but seems to have gotten some traction regardless. > > Therefore the Python principle of "there should be one and only one > > obvious way to do it" says: don't try to replace the existing thing if > > your new thing is only slightly better. ? > > With all due respect, Paul, and with thanks for all the help you've > given me, I have to disagree here: this is a really, really complicated > matter and I think there is a case even for making things slightly better. > > I think this is a matter of "investment period", so to speak: is it > short or long? In short term, it absolutely makes no sense to produce > even slight improvement. > > But in the long run it will almost certainly pay off to switch to smth > even somewhat better implementation (say, imaginary "20%" if you get my > drift): suppose we stay with sucky format for 10 years. Wouldn't it make > sense to implement a new one and be "in red" in terms of effort expended > versus saved for 3 years, but then be "in black" for the following 7 years? > I think ten years is about the right horizon to be looking down. Anything further than ten years is probably so speculative as to have lots of diminishing returns, although I admire people who have really BIG ideas and are starting on them now. (The particular context of this thread doesn't lead to big ideas, unless I just lack imagination.) I think it's wrong, though, only to look five years ahead. If the only goal was to make software development easier in 2015, then I'd say, by all means, let's pick the current best-of-breed tools and simply perfect them as much as we can. This is a worthwhile goal regardless of your ultimate time horizon, and that effort tends to happen anyway, since so many people rightly live in the here and now. Somewhere in the 2020s, though, I predict that a lot of technologies are either going to finally die off, or at least be restricted to the niches that they serve well. Take Java, for example. I think it will be still be used, and people will still even be writing new programs in it, but it will be rightly scorned in a lot of places where it is now embraced. Some of this won't actually be due to technological advances, but just changes in perception. For example, I predict lots of programs that people now write in Java will be written in Python, even if the core language of Python remains fairly stable. Beyond just changing mindsets, though, I think evolution is inevitable. Some subset of Python tools will almost certainly develop features that are more friendly to the Java mindset, but work in Python, and this will help move folks from Java to Python. I also think that Java will be supplanted for lots of use cases by some languages invented after 2000. Maybe Scala will become more mainstream. Maybe Go will turn into more of an enterprise-y platform. Who knows? With regard to XML, I think at a bare minimum, folks will stop using XML for use cases that YAML, JSON, and maybe even RSON serve better today. I bet that at least one of YAML and JSON survives in some form, and my money is on JSON, but I bet there will also be some new competing formats. I also think that we'll still have multiple formats that are only marginally better than each other for general use cases, but which people will still choose for specific reasons. Developers *love* good tools almost as much as they hate confusion-- there will always be tension between having too many choices and not enough. Going back to Paul's statement, I agree that "there should be one and only one obvious way to do it" in Python, but I don't think the philosophy applies to the greater ecosystem of software development. In our generation I think we have the live with the confusion and chaos that comes from a plethora of tools, and that's just part of progress. Ironically, I think the tools that survive will be very focused in their own right; it's just that we'll still have many to choose from. Going back to XML, I found myself using it last night for a completely inappropriate use case. It so happens that it would have been about 100% better if it had simply been written in JSON, so there was no compelling need for yet another alternative. But if the inventers of JSON had been complacent about XML, we wouldn't even have that as an option. And, of course, there is nothing radical at all about JSON--I am pretty sure it was just a common sense realization about the inadequacies of current technologies that led to its development, and I'm sure early versions of it were pretty raw. Without having looked into RSON, I am sure it's the same mindset that drives its invention-- current tools exist that can get the some done, but we can do better. Whether RSON is really an improvement or not is an orthogonal issue to whether we should strive for improvement. From michaelveloz at gmail.com Wed Mar 3 11:39:18 2010 From: michaelveloz at gmail.com (Veloz) Date: Wed, 3 Mar 2010 08:39:18 -0800 (PST) Subject: When to lock data items returned by multiprocessing.Manager? Message-ID: <4428d674-7fa7-4095-a93d-75ea31a81d9a@15g2000yqi.googlegroups.com> So I'm using a multiprocessing.Manager instance in my main app and asking it to create a dictionary, which I am providing to instances of the application that I'm forking off with Process. The Processes and main app will be reading/writing to the dictionary. It's not clear to me what I have to "lock" and what I don't have to lock. Any ideas? I'm thinking that what Manager brings to the table is the ability to share the dictionary but it may not provide anything to control concurrent access to it, and thus I should lock all operations I perform on it.. But I don't know this for a fact. Any input is welcomed on this!! Michael From thudfoo at opensuse.us Wed Mar 3 11:43:24 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Wed, 3 Mar 2010 08:43:24 -0800 Subject: Writing an assembler in Python In-Reply-To: <7v6el6F1ddU1@mid.individual.net> References: <7v6el6F1ddU1@mid.individual.net> Message-ID: <3d881a311003030843x14217f0aua4005dbe58caf630@mail.gmail.com> On Tue, Mar 2, 2010 at 10:52 PM, Gregory Ewing wrote: >> In article , >> Giorgos Tzampanakis ? wrote: >> >>> I'm implementing a CPU that will run on an FPGA. I want to have a >>> (dead) simple assembler that will generate the machine code for >>> me. I want to use Python for that. Are there any libraries that >>> can help me with the parsing of the assembly code? > > I wrote a PIC assembler in Python once. I didn't bother > with any parsing libraries. I used a regular expression > to split the input into tokens, then wrote ad-hoc > parsing code in Python. > > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > I used Plex. The lexer is here: http://pastebin.com/9Rm4rDfu The target for the assembler is a toy single-byte processor. From darcy at druid.net Wed Mar 3 11:46:03 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 11:46:03 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <20100303114603.7021e9ba.darcy@druid.net> On Wed, 3 Mar 2010 15:05:54 +0000 (UTC) Grant Edwards wrote: > > It was actually an improvement over CP/M's file > > system. CP/M didn't have hierarchical directories > > Neither did the original MS-DOS filesystem. I think that it always had a hierarchical file system although I am not sure about 86-DOS or QDOS on which is was based. > > or timestamps and recorded file sizes in 128-byte blocks > > rather than bytes. > > I thought that was true of the original MS-DOS filesystem as > well, but I wouldn't bet money on it. And that is why text files in MS-DOS and CP/M before it end with ^Z. They needed a way to tell where the end of the information was. Why they used ^Z (SUB - Substitute) instead of ^C (ETX - End of TeXt) or even ^D (EOT - End Of Transmission) is anyone's guess. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From robert.kern at gmail.com Wed Mar 3 12:00:04 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 11:00:04 -0600 Subject: A "scopeguard" for Python In-Reply-To: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 09:39 AM, Mike Kent wrote: > What's the compelling use case for this vs. a simple try/finally? > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup A custom-written context manager looks nicer and can be more readable. from contextlib import contextmanager import os @contextmanager def pushd(path): original_dir = os.getcwd() os.chdir(path) try: yield finally: os.chdir(original_dir) with pushd(somewhere): ... I don't think a general purpose ScopeGuard context manager has any such benefits over the try: finally:, though. -- 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 From jjposner at optimum.net Wed Mar 3 12:02:10 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 12:02:10 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8e84d2$0$10157$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e84d2$0$10157$426a74cc@news.free.fr> Message-ID: On 3/3/2010 10:48 AM, Bruno Desthuilliers wrote: > > I spotted this: > > http://www.python.org/doc/faq/programming/#what-is-a-method > http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls > > > Our text is probably a bit too long for a direct inclusion in the FAQ, > so I'd say it should go in the AdvancedTopics, and be linked from the FAQ. Linking from the FAQ means changing the official Python documentation, which requires lots of hoop-jumping-through. I suggest that we content ourselves with using the Wiki -- at least for now. > > Thanks for doing the grunt work. Pas de quoi. -John From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 12:03:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 18:03:37 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: <4b8e9660$0$21812$426a34cc@news.free.fr> John Posner a ?crit : > On 3/3/2010 9:58 AM, John Posner wrote: > >> Film at 11, >> John >> > > Done -- see http://wiki.python.org/moin/FromFunctionToMethod Done and well done !-) Thanks again for the good job John. PS : Do you think it could be possible to add link to this page from the relevant FAQ items ? http://www.python.org/doc/faq/programming/#what-is-a-method http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls From nagle at animats.com Wed Mar 3 12:05:44 2010 From: nagle at animats.com (John Nagle) Date: Wed, 03 Mar 2010 09:05:44 -0800 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <87r5o1v8vp.fsf@benfinney.id.au> References: <87r5o1v8vp.fsf@benfinney.id.au> Message-ID: <4b8e929d$0$1585$742ec2ed@news.sonic.net> Ben Finney wrote: > Olof Bjarnason writes: > >> Hi everybody! >> >> The "Where is CPAN for Python?" question keeps popping up, with >> answers ranging from "There is no CPAN for Python" and "We already >> have CPAN for Python" (confusing). > > Caused in no small measure by the fact that Perl people mean at least > two distinct things by ?Where is CPAN for Python??: > > * The central package registry, CPAN, with metadata in a standard > queryable format, and all registered packages redundantly mirrored and > available for installation at user-specified versions. > > We have an equivalent in PyPI, though it's incomplete since many > *registered* packages are not actually hosted *at* PyPI. CPAN is a repository. PyPi is an collection of links. CPAN has over 260 mirrors. PyPi has none. CPAN enforces standard organization on packages. PyPi does not. CPAN has quality control, with testers and a test reporting system. PyPi does not. John Nagle From emannion at gmail.com Wed Mar 3 12:05:47 2010 From: emannion at gmail.com (enda man) Date: Wed, 3 Mar 2010 09:05:47 -0800 (PST) Subject: using subprocess.Popen env parameter Message-ID: <47f5881a-a7bd-4a57-8e2d-ae27cfbf3a9a@x22g2000yqx.googlegroups.com> Hi, I want to use the env parameter to subprocess.Popen to pass in a path to a location the process needs to run, I do have a env variable already called MS_VC_PATH and I want to add to it, not set up more in the PATH variable. ///// ms_vc_path=os.environ['MS_VC_PATH'] cl_path = ms_vc_path + '\VC\bin' lib_vc_path = ms_vc_path + '\VC\lib' myenv = os.environ myenv["PATH"] = cl_path + ";" + lib_vc_path + ";" + myenv["PATH"] subprocess.Popen("midl /D \"_DEBUG\" /nologo /char signed /env win32 / Oicf /tlb \"ActivexPlugin.tlb\" /h \"ActivexPlugin_i.h\" /iid \"ActivexPlugin_i.c\" /proxy \"ActivexPlugin_p.c\" /error stub_data ActivexPlugin.idl", env=myenv) /// but it seems that midl can not see the new path I am sending to it using the env variable, am I using env correctly? here is my output: midl : command line error MIDL1005 : cannot find C preprocessor cl.exe Any help? EM From skylarking11 at gmail.com Wed Mar 3 12:06:27 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 3 Mar 2010 09:06:27 -0800 (PST) Subject: Installing Scrapy on Mac OS X 10.6 Message-ID: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> Has anyone successfully installed Scrapy ( http://scrapy.org ) on a Mac OS X machine running 10.6.x? The Documentaion says Mac OS X ships an libxml2 version too old to be used by Scrapy...But doesn't say which version of OS X.. I am wondering if the version of libxml2 is also not compatible.. From robert.kern at gmail.com Wed Mar 3 12:09:11 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 11:09:11 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: > * Mike Kent: >> What's the compelling use case for this vs. a simple try/finally? > > if you thought about it you would mean a simple "try/else". "finally" is > always executed. which is incorrect for cleanup Eh? Failed execution doesn't require cleanup? The example you gave is definitely equivalent to the try: finally: that Mike posted. The actions are always executed in your example, not just when an exception isn't raised. From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the try: finally: syntax is for. The with statement allows you to encapsulate repetitive boilerplate into context managers, but a general purpose context manager like your Cleanup class doesn't take advantage of this. -- 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 From alfps at start.no Wed Mar 3 12:09:53 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 18:09:53 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 09:39 AM, Mike Kent wrote: >> What's the compelling use case for this vs. a simple try/finally? >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup > > A custom-written context manager looks nicer and can be more readable. > > from contextlib import contextmanager > import os > > @contextmanager > def pushd(path): > original_dir = os.getcwd() > os.chdir(path) > try: > yield > finally: > os.chdir(original_dir) > > > with pushd(somewhere): > ... > > > I don't think a general purpose ScopeGuard context manager has any such > benefits over the try: finally:, though. I don't think that's a matter of opinion, since one is correct while the other is incorrect. Cheers, - ALf From invalid at invalid.invalid Wed Mar 3 12:15:02 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 17:15:02 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: On 2010-03-03, D'Arcy J.M. Cain wrote: > On Wed, 3 Mar 2010 15:05:54 +0000 (UTC) > Grant Edwards wrote: >> > It was actually an improvement over CP/M's file >> > system. CP/M didn't have hierarchical directories >> >> Neither did the original MS-DOS filesystem. > > I think that it always had a hierarchical file system The hierarchical file system wasn't introduced until MS-DOS 2.0. Versions prior to that were flat filesystem just like CP/M. >From http://en.wikipedia.org/wiki/File_Allocation_Table At the time FAT12 was introduced, DOS did not support hierarchical directories, and the maximum number of files was typically limited to a few dozen. Hierarchical directories were introduced in MS-DOS version 2.0. -- Grant Edwards grant.b.edwards Yow! I wonder if I could at ever get started in the gmail.com credit world? From alfps at start.no Wed Mar 3 12:18:44 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 18:18:44 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >> * Mike Kent: >>> What's the compelling use case for this vs. a simple try/finally? >> >> if you thought about it you would mean a simple "try/else". "finally" is >> always executed. which is incorrect for cleanup > > Eh? Failed execution doesn't require cleanup? The example you gave is > definitely equivalent to the try: finally: that Mike posted. Sorry, that's incorrect: it's not. With correct code (mine) cleanup for action A is only performed when action A succeeds. With incorrect code cleanup for action A is performed when A fails. > The actions > are always executed in your example, Sorry, that's incorrect. > [The actions are] not [executed] just when an exception isn't raised. Sorry, that's incorrect. > From your post, the scope guard technique is used "to ensure some > desired cleanup at the end of a scope, even when the scope is exited via > an exception." This is precisely what the try: finally: syntax is for. You'd have to nest it. That's ugly. And more importantly, now two people in this thread (namely you and Mike) have demonstrated that they do not grok the try functionality and manage to write incorrect code, even arguing that it's correct when informed that it's not, so it's a pretty fragile construct, like goto. > The with statement allows you to encapsulate repetitive boilerplate into > context managers, but a general purpose context manager like your > Cleanup class doesn't take advantage of this. I'm sorry but that's pretty meaningless. It's like: "A house allows you to encapsulate a lot of stinking garbage, but your house doesn't take advantage of that, it's disgustingly clean". Hello. Cheers & hth., - Alf From xahlee at gmail.com Wed Mar 3 12:36:26 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 3 Mar 2010 09:36:26 -0800 (PST) Subject: NoSQL Movement? Message-ID: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> recently i wrote a blog article on The NoSQL Movement at http://xahlee.org/comp/nosql.html i'd like to post it somewhere public to solicit opinions, but in the 20 min or so, i couldn't find a proper newsgroup, nor private list that my somewhat anti-NoSQL Movement article is fitting. So, i thought i'd post here to solicit some opinins from the programer community i know. Here's the plain text version ----------------------------- The NoSQL Movement Xah Lee, 2010-01-26 In the past few years, there's new fashionable thinking about anti relational database, now blessed with a rhyming term: NoSQL. Basically, it considers that relational database is outdated, and not ?horizontally? scalable. I'm quite dubious of these claims. According to Wikipedia Scalability article, verticle scalability means adding more resource to a single node, such as more cpu, memory. (You can easily do this by running your db server on a more powerful machine.), and ?Horizontal scalability? means adding more machines. (and indeed, this is not simple with sql databases, but again, it is the same situation with any software, not just database. To add more machines to run one single software, the software must have some sort of grid computing infrastructure built-in. This is not a problem of the software per se, it is just the way things are. It is not a problem of databases.) I'm quite old fashioned when it comes to computer technology. In order to convience me of some revolutionary new-fangled technology, i must see improvement based on math foundation. I am a expert of SQL, and believe that relational database is pretty much the gist of database with respect to math. Sure, a tight definition of relations of your data may not be necessary for many applications that simply just need store and retrieve and modify data without much concern about the relations of them. But still, that's what relational database technology do too. You just don't worry about normalizing when you design your table schema. The NoSQL movement is really about scaling movement, about adding more machines, about some so-called ?cloud computing? and services with simple interfaces. (like so many fashionable movements in the computing industry, often they are not well defined.) It is not really about anti relation designs in your data. It's more about adding features for practical need such as providing easy-to-user APIs (so you users don't have to know SQL or Schemas), ability to add more nodes, provide commercial interface services to your database, provide parallel systems that access your data. Of course, these needs are all done by any big old relational database companies such as Oracle over the years as they constantly adopt the changing industry's needs and cheaper computing power. If you need any relations in your data, you can't escape relational database model. That is just the cold truth of math. Importat data, such as used in the bank transactions, has relations. You have to have tight relational definitions and assurance of data integrity. Here's a second hand quote from Microsoft's Technical Fellow David Campbell. Source I've been doing this database stuff for over 20 years and I remember hearing that the object databases were going to wipe out the SQL databases. And then a little less than 10 years ago the XML databases were going to wipe out.... We actually ... you know... people inside Microsoft, [have said] 'let's stop working on SQL Server, let's go build a native XML store because in five years it's all going....' LOL. That's exactly my thought. Though, i'd have to have some hands on experience with one of those new database services to see what it's all about. -------------------- Amazon S3 and Dynamo Look at Structured storage. That seems to be what these nosql databases are. Most are just a key-value pair structure, or just storage of documents with no relations. I don't see how this differ from a sql database using one single table as schema. Amazon's Amazon S3 is another storage service, which uses Amazon's Dynamo (storage system), indicated by Wikipedia to be one of those NoSQL db. Looking at the S3 and Dynamo articles, it appears the db is just a Distributed hash table system, with added http access interface. So, basically, little or no relations. Again, i don't see how this is different from, say, MySQL with one single table of 2 columns, added with distributed infrastructure. (distributed database is often a integrated feature of commercial dbs, e.g. Wikipedia Oracle database article cites Oracle Real Application Clusters ) Here's a interesting quote on S3: Bucket names and keys are chosen so that objects are addressable using HTTP URLs: * http://s3.amazonaws.com/bucket/key * http://bucket.s3.amazonaws.com/key * http://bucket/key (where bucket is a DNS CNAME record pointing to bucket.s3.amazonaws.com) Because objects are accessible by unmodified HTTP clients, S3 can be used to replace significant existing (static) web hosting infrastructure. So this means, for example, i can store all my images in S3, and in my html document, the inline images are just normal img tags with normal urls. This applies to any other type of file, pdf, audio, but html too. So, S3 becomes the web host server as well as the file system. Here's Amazon's instruction on how to use it as image server. Seems quite simple: How to use Amazon S3 for hosting web pages and media files? Source -------------------- Google BigTable Another is Google's BigTable. I can't make much comment. To make a sensible comment, one must have some experience of actually implementing a database. For example, a file system is a sort of database. If i created a scheme that allows me to access my data as files in NTFS that are distributed over hundreds of PC, communicated thru http running Apache. This will let me access my files. To insert, delete, data, one can have cgi scripts on each machine. Would this be considered as a new fantastic NoNoSQL? --------------------- comments can also be posted to http://xahlee.blogspot.com/2010/01/nosql-movement.html Thanks. Xah ? http://xahlee.org/ ? From dragonx562 at googlemail.com Wed Mar 3 12:37:45 2010 From: dragonx562 at googlemail.com (luaisn haus) Date: Wed, 3 Mar 2010 09:37:45 -0800 (PST) Subject: =?ISO-8859-1?Q?kredit_haus_=2C_eigenheimzulage_einkommensgrenzen_=2C_fi?= =?ISO-8859-1?Q?nanzamt_eigenheimzulage_=2C_kredit_f=FCr_haus_kauf_=2C_kredit_auf?= =?ISO-8859-1?Q?_haus_=2C_immobilienkredit_ohne_=2C_finanzierung_eines_hauses_=2C?= Message-ID: <3b3b51d7-5963-4f78-b103-54ac7ce9f2ed@c16g2000yqd.googlegroups.com> kredit haus , eigenheimzulage einkommensgrenzen , finanzamt eigenheimzulage , kredit f?r haus kauf , kredit auf haus , immobilienkredit ohne , finanzierung eines hauses , + + +++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA IMMOBILIEN +++ + http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL + + + + kredit f?r haus kauf darlehen f?r immobilien finanzierung von immobilien hypotheken darlehen rechner zinskonditionen hypotheken hypothek zins eigenheimzulage vom staat hausfinanzierung im hausfinanzierung ?sterreich anschlussfinanzierung hypothek kredit f?r ein haus haus kaufen darlehen deutsche kreditbank f?r baufinanzierung zins f?r baufinanzierung immobilienkredit berechnung baufinanzierung lebensversicherung kreditrechner baufinanzierung zinstrend baufinanzierung eigenheimzulage beantragen k?ndigung bauspardarlehen g?nstige hypothekenkredite hypothekenkredit schweiz zinsen hausfinanzierung baufinanzierung ohne eigenkapital hartz iv eigenheimzulage eigenheimzulage 10e From affdfsdfdsfsd at b.com Wed Mar 3 12:38:19 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 03 Mar 2010 17:38:19 GMT Subject: case do problem References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <4b8e9e8b$0$1121$4fafbaef@reader3.news.tin.it> Il Wed, 03 Mar 2010 09:39:54 +0100, Peter Otten ha scritto: > Tracubik wrote: > >> hi, i've to convert from Pascal this code: > > program loop; > > function generic_condition: boolean; > begin > generic_condition := random > 0.7 > end; > > procedure loop; > var > iterations, count, m: integer; > begin > iterations := 0; > count := 0; > m := 0; > repeat > iterations := iterations+1; > (*...*) > writeln(iterations:2, count:2, m:4); > (*...*) > if generic_condition then > inc(count); > (*...*) > case count of > 1: m := 1; > 2: m := 10; > 3: m := 100 > end > until (count = 4) or (iterations = 20) > end; > > begin > loop; > writeln("That's all, folks") > end. > > Hey, I have a Pascal compiler just one apt-get away ;) > > Here's how I'd translate the above, without trying to be too clever: > > from random import random > > def generic_condition(): > return random() > 0.7 > > def loop(): > count = 0 > m = 0 > lookup = {1: 1, 2: 10, 3: 100} > for iterations in range(20): # off by one > # ... > print "%2d %1d %3d" % (iterations, count, m) # ... > if generic_condition(): > count += 1 > # ... > m = lookup.get(count, m) > if count == 4: > break > > if __name__ == "__main__": > loop() > print "That's all, folks" > > Something must be wrong with me today because I find the Pascal code > /more/ readable.. i was think the same, Pascal seem to generate a great more readable code. I'm a newbie, so my opinion is probably wrong, but i still think that don't have CASE OF and REPEAT UNTIL code block return in difficult-to- read code. > > Peter Nico From wanderer at dialup4less.com Wed Mar 3 12:39:48 2010 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 3 Mar 2010 09:39:48 -0800 (PST) Subject: Pylint Argument number differs from overridden method Message-ID: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Pylint W0221 gives the warning Argument number differs from overridden method. Why is this a problem? I'm overriding the method to add additional functionality. This def GetRays(self, angle, pt, lmbda = 0.6): """ """ angle, x, y, Rays, Power = self.ARefract(angle, pt[0], pt[1], lmbda) pt1 = (x, y) return Rays, Power, angle, pt1 def ARefract(self, angle, x, y, lmbda = 0.6): """ """ Nt = self.Mat.NtGet(lmbda) self.NtSet(Nt) angle, x, y, Rays, Power = self.Refract(angle, x, y) return angle, x, y, Rays, Power Over rides this def GetRays(self, angle, pt): """ """ angle, x, y, Rays, Power = self.Refract(angle, pt[0], pt[1]) pt1 = (x, y) return Rays, Power, angle, pt1 Thanks From gandalf at shopzeus.com Wed Mar 3 12:41:37 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 03 Mar 2010 18:41:37 +0100 Subject: Instance factory - am I doing this right? Message-ID: <4B8E9F51.1040203@shopzeus.com> This is just an interesting code pattern that I have recently used: class CacheStorage(object): """Generic cache storage class.""" @classmethod def get_factory(cls,*args,**kwargs): """Create factory for a given set of cache storage creation parameters.""" class CacheStorageFactory(cls): _construct_args = args _construct_kwargs = kwargs def __init__(self): cls.__init__(self, *self._construct_args,**self._construct_kwargs) return CacheStorageFactory Then, I can create subclasses like: class GdbmCacheStorage(CacheStorage): """Gdbm cache storage class. @param basedir: Base directory where gdbm files should be stored. @param basename: Base name for logging and creating gdbm files. """ def __init__(self,basedir,basename): ..... blablabla place initialization code here class MemoryCacheStorage(CacheStorage): """In-Memory cache storage class. Please note that keys and values are always mashal-ed. E.g. when you cache an object, it makes a deep copy. """ def __init__(self): ..... blablabla place initialization code here And the finally, I can create a factory that can create cache storage instances for storing data in gdbm in a given directory: cache_factory = GdbmCacheStorage.get_factory("~gandalf/db","test") print cache_factory # print cache_factory() OR I can create a factory that can create instances for storing data in memory: cache_factory = MemoryCacheStorage.get_factory() print cache_factory # print cache_factory() # <__main__.CacheStorageFactory object at 0x8250c6c> Now, here is my question. Am I right in doing this? Or are there better language tools to be used in Python for the same thing? This whole thing about creating factories looks a bit odd for me. Is it Pythonic enough? Thanks, Laszlo From larudwer at freenet.de Wed Mar 3 12:49:36 2010 From: larudwer at freenet.de (larudwer) Date: Wed, 3 Mar 2010 18:49:36 +0100 Subject: Multiprocessing problem References: Message-ID: Hello Matt I think the problem is here: for n in xrange(100000): outqueue.put(str(n)) <-- fill the queue with 100000 elements try: r = inqueue.get_nowait() <-- queue is still empty because processes need some time to start results.append(r) except Empty: pass <-- causing 100000 passes .... print "-" for task in tasks: outqueue.put(None) <-- put even more data in the queue ... # in the meantime the processes start to run and are trying to put data # in to the output queue. However this queue might fill up, and lock # all processes that try to write data in the already filled up queue print "joining" for task in tasks: task.join() <-- can never succeed because processes are waiting for someone reading the result queue print "joined" This example works: from Queue import Empty, Full from multiprocessing import Queue, Process from base64 import b64encode import time, random class Worker(Process): def __init__(self, inqueue, outqueue): Process.__init__(self) self.inqueue = inqueue self.outqueue = outqueue def run(self): inqueue = self.inqueue outqueue = self.outqueue c = 0 while True: arg = inqueue.get() if arg is None: break c += 1 b = b64encode(arg) outqueue.put(b) # Clean-up code goes here outqueue.put(c) class Supervisor(object): def __init__(self): pass def go(self): outqueue = Queue() inqueue = Queue() tasks = [Worker(outqueue, inqueue) for _ in xrange(4)] for task in tasks: task.start() results = [] print "*" for n in xrange(100000): outqueue.put(str(n)) print "-" for task in tasks: outqueue.put(None) print "emptying queue" try: while True: r = inqueue.get_nowait() results.append(r) except Empty: pass print "done" print len(results) print "joining" for task in tasks: task.join() print "joined" if __name__ == "__main__": s = Supervisor() s.go() From tim.wintle at teamrubber.com Wed Mar 3 12:50:02 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 03 Mar 2010 17:50:02 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: <1267638602.988.19.camel@localhost> On Wed, 2010-03-03 at 17:26 +0100, mk wrote: > > So there *may* be some evidence that joins are indeed bad in > practice. > If someone has smth specific/interesting on the subject, please post. I have found joins to cause problems in a few cases - I'm talking about relatively large tables though - roughly order 10^8 rows. I'm on Mysql normally, but that shouldn't make any difference - I've seen almost the same situation on Oracle consider this simple example: /* Table A */ CREATE TABLE TableA ( project_id BIGINT NOT NULL, cost INT, date DATETIME, PRIMARY KEY (project_id, date) ); /* Table projects */ CREATE TABLE projects ( client_id BIGINT NOT NULL, project_id BIGINT NOT NULL, INDEX(client_id) ); ... now the index on TableA has been optimised for queries against date ranges on specific project ids which should more or less be sequential (under a load of other assumptions) - but that reduces the efficiency of the query under a join with the table "projects". If you denormalise the table, and update the first index to be on (client_id, project_id, date) it can end up running far more quickly - assuming you can access the first mapping anyway - so you're still storing the first table, with stored procedures to ensure you still have correct data in all tables. I'm definitely glossing over the details - but I've definitely got situations where I've had to choose denormalisation over purity of data. Rolled-up data tables are other situations - where you know half your queries are grouping by field "A" it's sometimes a requirement to store that. Tim From mrkafk at gmail.com Wed Mar 3 12:52:41 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 18:52:41 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100303111248.7f40d659.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > Makes me want to go down to the basement and fire up the Altair. :-) Please don't, or else I fire up that univ Yugoslavian copy of VAX with Pascal compiler (where I wrote my first program) and I will start my first program of ping-pong. It was a few hundred lines but took 5 minutes to compile; "VAX" was theoretically multitasking, but when more than 3 people were trying to do smth on it simultaneously, it was basically seizing up. Regards, mk From e_d_k at yahoo.com Wed Mar 3 13:01:27 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 3 Mar 2010 10:01:27 -0800 (PST) Subject: Docstrings considered too complicated In-Reply-To: <20100303114603.7021e9ba.darcy@druid.net> Message-ID: <539252.91463.qm@web58904.mail.re1.yahoo.com> --- On Wed, 3/3/10, D'Arcy J.M. Cain wrote: > They needed a way to tell where the end of the information > was.? Why > they used ^Z (SUB - Substitute) instead of ^C (ETX - End of > TeXt) or > even ^D (EOT - End Of Transmission) is anyone's guess. That has always puzzled me to. ETX and EOT were well established, why no use one of them? I'd love to know what they were thinking. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From john at castleamber.com Wed Mar 3 13:04:39 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Mar 2010 12:04:39 -0600 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> Message-ID: <877hpt46yw.fsf@castleamber.com> John Gabriele writes: > On Mar 2, 11:58?pm, John Bokma wrote: >> Lie Ryan writes: >> > On 03/03/2010 09:47 AM, TomF wrote: >> >> [..] >> >> >> There >> >> is also a program called cpan, distributed with Perl. ?It is used for >> >> searching, downloading, installing and testing modules from the CPAN >> >> repository. ?It's far more extensive than setuptools. ?AFAIK the python >> >> community has developed nothing like it. >> >> > python have easy_install >> >> How easy is it to /remove/ something? ;-) (Last time I checked I read >> something like "manually remove the .egg"... >> > > Have a look at [pip](http://cheeseshop.python.org/pypi/pip). It should > support uninstalling packages. Thanks John. However: "Known exceptions include pure-distutils packages installed with python setup.py install" I want to remove something that I installed that way (because it's installation procedure seems to be broken; opensocial) I understand that this can't be blamed on pip, but it's odd that in this century it's still hard to install/uninstall modules :-( -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at holdenweb.com Wed Mar 3 13:14:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Mar 2010 13:14:18 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: mk wrote: > D'Arcy J.M. Cain wrote: >> I keep seeing this statement but nothing to back it up. I have created >> many apps that run on Python with a PostgreSQL database with a fully >> normalized schema and I can assure you that database joins were never >> my problem unless I made a badly constructed query or left off a >> critical index. > > I too have done that (Python/PGSQL), even adding a complicated layer of > SQLAlchemy on top of it and have not had issue with this: when I > profiled one of my apps, it turned out that it spent most of its > computation time... rendering HTML. Completely unexpected: I expected DB > to be bottleneck (although it might be that with huge datasets this > might change). > > Having said that, re evidence that joins are bad: from what I've *heard* > about Hibernate in Java from people who used it (I haven't used > Hibernate apart from "hello world"), in case of complicated object > hierarchies it supposedly generates a lot of JOINs and that supposedly > kills DB performance. > > So there *may* be some evidence that joins are indeed bad in practice. > If someone has smth specific/interesting on the subject, please post. > I suspect that this myth is propagated from the distributed database world: joining tables across two different servers can indeed be problematic from a performance point of view. However, the classic advice in database design is to start with a normalized design and then vary it only if you need to for performance reasons (which will also involve taking a hit on the coding side, especially if updates are involved). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at mrabarnett.plus.com Wed Mar 3 13:15:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 18:15:14 +0000 Subject: Docstrings considered too complicated In-Reply-To: <20100303114603.7021e9ba.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> <20100303114603.7021e9ba.darcy@druid.net> Message-ID: <4B8EA732.60408@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Wed, 3 Mar 2010 15:05:54 +0000 (UTC) > Grant Edwards wrote: >>> It was actually an improvement over CP/M's file >>> system. CP/M didn't have hierarchical directories >> Neither did the original MS-DOS filesystem. > > I think that it always had a hierarchical file system although I am not > sure about 86-DOS or QDOS on which is was based. > [snip] MS-DOS had a hierarchical file system from version 2.0. From mrkafk at gmail.com Wed Mar 3 13:20:00 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 19:20:00 +0100 Subject: Sort Big File Help In-Reply-To: <374400.23537.qm@web33805.mail.mud.yahoo.com> References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: John Filben wrote: > I am new to Python but have used many other (mostly dead) languages in > the past. I want to be able to process *.txt and *.csv files. I can > now read that and then change them as needed ? mostly just take a column > and do some if-then to create a new variable. My problem is sorting > these files: > > 1.) How do I sort file1.txt by position and write out > file1_sorted.txt; for example, if all the records are 100 bytes long and > there is a three digit id in the position 0-2; here would be some sample > data: > > a. 001JohnFilben?? > > b. 002Joe Smith?.. Use a dictionary: linedict = {} for line in f: key = line[:3] linedict[key] = line[3:] # or alternatively 'line' if you want to include key in the line anyway sortedlines = [] for key in linedict.keys().sort(): sortedlines.append(linedict[key]) (untested) This is the simplest, and probably inefficient approach. But it should work. > > 2.) How do I sort file1.csv by column name; for example, if all the > records have three column headings, ?id?, ?first_name?, ?last_name?; > here would be some sample data: > > a. Id, first_name,last_name > > b. 001,John,Filben > > c. 002,Joe, Smith This is more complicated: I would make a list of lines, where each line is a list split according to columns (like ['001', 'John', 'Filben']), and then I would sort this list using operator.itemgetter, like this: lines.sort(key = operator.itemgetter(num)) # where num is the number of column, starting with 0 of course Read up on operator.*, it's very useful. > > 3.) What about if I have millions of records and I am processing on a > laptop with a large external drive ? basically, are there space > considerations? What are the work arounds. The simplest is to use smth like SQLite: define a table, fill it up, and then do SELECT with ORDER BY. But with a million records I wouldn't worry about it, it should fit in RAM. Observe: >>> a={} >>> for i in range(1000000): ... a[i] = 'spam'*10 ... >>> sys.getsizeof(a) 25165960 So that's what, 25 MB? Although I have to note that TEMPORARY ram usage in Python process on my machine did go up to 113MB. Regards, mk From detlev at die-offenbachs.de Wed Mar 3 13:23:16 2010 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Wed, 03 Mar 2010 19:23:16 +0100 Subject: Eric4 vs Python3.1 References: Message-ID: Zhu Sha Zang wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Someone using Eric4 to program with Python3/3.1? > > What can i do, because he insist to use only Python2.6.4. You can tell it the file extension to use for Python3 files or better yet use eric5, which is the Python3 port of eric4 with enhancements. Detlev > > Att > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.14 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkuOZO4ACgkQ35zeJy7JhCjdFACfZrjVa+8O9fu/7FEPr6mVeaEg > Rm0AmgM+XtuxFH1zUnfkaphF+MgPy3pf > =MVeJ > -----END PGP SIGNATURE----- -- Detlev Offenbach detlev at die-offenbachs.de From R.Brodie at rl.ac.uk Wed Mar 3 13:29:06 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Wed, 3 Mar 2010 18:29:06 -0000 Subject: Docstrings considered too complicated References: Message-ID: "Ed Keith" wrote in message news:mailman.215.1267639293.23598.python-list at python.org... > That has always puzzled me to. ETX and EOT were well established, > why no use one of them? I'd love to know what they were thinking. It goes back to ancient PDP operating systems, so may well predate Unix, depending which exact OS was the first to use it. From python at mrabarnett.plus.com Wed Mar 3 13:34:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 18:34:51 +0000 Subject: Docstrings considered too complicated In-Reply-To: <20100303111248.7f40d659.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: <4B8EABCB.6050303@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Wed, 03 Mar 2010 14:42:00 +0000 > MRAB wrote: >> Gregory Ewing wrote: >> Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment >> display, which I had to solder together, and also make my own power >> supply. I had the extra RAM and the I/O chip, so that's 256B (including >> the memory used by the monitor) + 256B additional RAM + 128B more in the >> I/O chip. > > In case some of you youngsters think that there is a typo in the above, > no, he means a total of 640 bytes. In today's terms that would be > approx 0.0000006GB. > > Makes me want to go down to the basement and fire up the Altair. :-) > There was partial address decoding, so the blocks appeared at several different places in the address space, the blocks weren't contiguous (normal RAM at 0xFxx, extra at 0xBxx), and the external address bus was 12 bits. Not only that, I discovered that one of the bits in the extra RAM was faulty - stuck at 0 (or was it 1)? But I was still able to play Nim and Duck Shoot (after keying it in)! :-) From mrkafk at gmail.com Wed Mar 3 13:47:14 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 19:47:14 +0100 Subject: memory usage, temporary and otherwise Message-ID: Obviously, don't try this on low-memory machine: >>> a={} >>> for i in range(10000000): ... a[i]='spam'*10 ... >>> import sys >>> sys.getsizeof(a) 201326728 >>> id(a[1]) 3085643936L >>> id(a[100]) 3085713568L >>> ids={} >>> for i in range(len(a)): ... ids[id(a[i])]=True ... >>> len(ids.keys()) 10000000 Hm, apparently Python didn't spot that 'spam'*10 in a's values is really the same string, right? So sys.getsizeof returns some 200MB for this dictionary. But according to top RSS of the python process is 300MB. ps auxw says the same thing (more or less). Why the 50% overhead? (and I would swear that a couple of times RSS according to top grew to 800MB). Regards, mk From alfps at start.no Wed Mar 3 13:51:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 19:51:23 +0100 Subject: Sample code usable Tkinter listbox In-Reply-To: References: Message-ID: * Alf P. Steinbach: > In case Someone Else(TM) may need this. > > This code is just how it currently looks, what I needed for my code, so > it's not a full-fledged or even tested class. > > But it works. That code evolved a little to cover more Tk listbox quirks (thanks to Ratingrick for the "activestyle"): class UsableListbox( t.Frame ): def __init__( self, parent_widget ): t.Frame.__init__( self, parent_widget ) scrollbar = t.Scrollbar( self, orient = "vertical" ) self.lb = t.Listbox( self, exportselection = 0, activestyle = "none", selectmode = "browse", yscrollcommand = scrollbar.set ) scrollbar.config( command = self.lb.yview ) scrollbar.pack( side = "right", fill = "y" ) self.lb.pack( side = "left", fill = "both", expand = 1 ) def current_index( self ): indices = self.lb.curselection() assert( len( indices ) <= 1 ) # TODO: about multi-selection. return None if len( indices ) == 0 else int( indices[0] ) def item_at( self, i ): assert( 0 <= i < self.item_count() ) return "" if i is None else self.lb.get( i ) def current( self ): #return self.lb.get( "active" ) # Incorrect with mousing return self.item_at( self.current_index() ) def item_count( self ): return self.lb.size() def clear( self ): self.lb.delete( 0, "end" ) def append( self, item ): self.lb.insert( "end", item ) return self.item_count() - 1 def scroll_into_view( self, i ): self.lb.see( i ) def select_item( self, i ): assert( 0 <= i < self.item_count() ) old_i = self.current_index(); self.scroll_into_view( i ) if old_i is not None and old_i == i: return self.lb.selection_set( i ) if old_i is not None: self.lb.selection_clear( old_i ) def add_selection_event_handler( self, handler ): "An event handler takes one argument, a Tkinter Event" return self.lb.bind( "<>", handler ) Cheers, - Alf From robert.kern at gmail.com Wed Mar 3 13:51:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 12:51:34 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>> * Mike Kent: >>>> What's the compelling use case for this vs. a simple try/finally? >>> >>> if you thought about it you would mean a simple "try/else". "finally" is >>> always executed. which is incorrect for cleanup >> >> Eh? Failed execution doesn't require cleanup? The example you gave is >> definitely equivalent to the try: finally: that Mike posted. > > Sorry, that's incorrect: it's not. > > With correct code (mine) cleanup for action A is only performed when > action A succeeds. > > With incorrect code cleanup for action A is performed when A fails. Oh? $ cat cleanup.py class Cleanup: def __init__( self ): self._actions = [] def call( self, action ): assert( callable( action ) ) self._actions.append( action ) def __enter__( self ): return self def __exit__( self, x_type, x_value, x_traceback ): while( len( self._actions ) != 0 ): try: self._actions.pop()() except BaseException as x: raise AssertionError( "Cleanup: exception during cleanup" ) def print_(x): print x with Cleanup() as at_cleanup: at_cleanup.call(lambda: print_("Cleanup executed without an exception.")) with Cleanup() as at_cleanup: at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) raise RuntimeError() $ python cleanup.py Cleanup executed without an exception. Cleanup execute with an exception. Traceback (most recent call last): File "cleanup.py", line 28, in raise RuntimeError() RuntimeError >> The actions are always executed in your example, > > Sorry, that's incorrect. Looks like it to me. >> From your post, the scope guard technique is used "to ensure some >> desired cleanup at the end of a scope, even when the scope is exited >> via an exception." This is precisely what the try: finally: syntax is >> for. > > You'd have to nest it. That's ugly. And more importantly, now two people > in this thread (namely you and Mike) have demonstrated that they do not > grok the try functionality and manage to write incorrect code, even > arguing that it's correct when informed that it's not, so it's a pretty > fragile construct, like goto. Uh-huh. >> The with statement allows you to encapsulate repetitive boilerplate >> into context managers, but a general purpose context manager like your >> Cleanup class doesn't take advantage of this. > > I'm sorry but that's pretty meaningless. It's like: "A house allows you > to encapsulate a lot of stinking garbage, but your house doesn't take > advantage of that, it's disgustingly clean". Hello. No, I'm saying that your Cleanup class is about as ugly as the try: finally:. It just shifts the ugliness around. There is a way to use the with statement to make things look better and more readable in certain situations, namely where there is some boilerplate that you would otherwise repeat in many places using try: finally:. You can encapsulate that repetitive code into a class or a @contextmanager generator and just call the contextmanager. A generic context manager where you register callables doesn't replace any boilerplate. You still repeat all of the cleanup code everywhere. What's more, because you have to shove everything into a callable, you have significantly less flexibility than the try: finally:. I will admit that you can put the cleanup code closer to the code that needs to get cleaned up, but you pay a price for that. -- 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 From mrkafk at gmail.com Wed Mar 3 13:54:52 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 19:54:52 +0100 Subject: Generic singleton Message-ID: Hello, So I set out to write generic singleton, i.e. the one that would do a singleton with attributes of specified class. At first: class Singleton(object): instance = None def __new__(cls, impclass, *args, **kwargs): if cls.instance is None: cls.instance = impclass.__new__(impclass, *args, **kwargs) return cls.instance s1 = Singleton(dict) s2 = Singleton(dict) s1['spam']='wonderful' print s1, s2 print id(s1) == id(s2) Now, this works. But this obviously doesn't allow class of singleton to be changed, or a new singleton for another class to be created. So: class Singleton(object): instd = {} def __new__(cls, impclass, *args, **kwargs): impid = id(impclass) if not cls.instd.has_key(impid): cls.instd[impid] = impclass.__new__(impclass, *args, **kwargs) return cls.instd[impid] s1 = Singleton(dict) s2 = Singleton(dict) s1['spam']='wonderful' s3 = Singleton(list) s4 = Singleton(list) s3.append('eggs') print id(s1) == id(s2) print id(s3) == id(s4) print s1, s2, s3, s4 Questions: 1. Is this safe? That is, does every builtin class have unique id? I have found this in docs: hashable .. All of Python?s immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Well ok, hashable they're not; but apparently at least dict and list have id()? >>> id(list) 135709728 >>> id(dict) 135714560 >>> id(dict) 135714560 >>> c=dict >>> id(c) 135714560 2. Drawbacks? 3. Better/fancier way to do this? Regards, mk From python at mrabarnett.plus.com Wed Mar 3 14:09:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 19:09:18 +0000 Subject: NoSQL Movement? In-Reply-To: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <4B8EB3DE.8070003@mrabarnett.plus.com> Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > at http://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. > > So, i thought i'd post here to solicit some opinins from the programer > community i know. > [snip] Couldn't find a relevant newsgroup, so decided to inflict it on a number of others... From philip at semanchuk.com Wed Mar 3 14:15:26 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 14:15:26 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> On Mar 3, 2010, at 11:26 AM, mk wrote: > D'Arcy J.M. Cain wrote: >> I keep seeing this statement but nothing to back it up. I have >> created >> many apps that run on Python with a PostgreSQL database with a fully >> normalized schema and I can assure you that database joins were never >> my problem unless I made a badly constructed query or left off a >> critical index. > > I too have done that (Python/PGSQL), even adding a complicated layer > of SQLAlchemy on top of it and have not had issue with this: when I > profiled one of my apps, it turned out that it spent most of its > computation time... rendering HTML. Completely unexpected: I > expected DB to be bottleneck (although it might be that with huge > datasets this might change). > > Having said that, re evidence that joins are bad: from what I've > *heard* about Hibernate in Java from people who used it (I haven't > used Hibernate apart from "hello world"), in case of complicated > object hierarchies it supposedly generates a lot of JOINs and that > supposedly kills DB performance. > > So there *may* be some evidence that joins are indeed bad in > practice. If someone has smth specific/interesting on the subject, > please post. It's an unprovable assertion, or a meaningless one depending on how one defines the terms. You could also say "there *may* be some evidence that Python lists are bad in practice". Python lists and SQL JOINs are like any part of a language or toolkit. They're good tools for solving certain classes of problems. They can also be misapplied to problems that they're not so good at. Sometimes they're a performance bottleneck, even when solving the problems for which they're best. Sometimes the best way to solve a performance bottleneck is to redesign your app/system so you don't need to solve that kind of problem anymore (hence the join-less databases). Other times, the cure is worse than the disease and you're better off throwing hardware at the problem. My $.02 Philip From mrkafk at gmail.com Wed Mar 3 14:21:29 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:21:29 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7071cfa0-0485-4192-b3ee-8e12d9f1fca2@f17g2000prh.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7071cfa0-0485-4192-b3ee-8e12d9f1fca2@f17g2000prh.googlegroups.com> Message-ID: Steve Howell wrote: > Somewhere in the 2020s, though, I predict that a lot of technologies > are either going to finally die off, or at least be restricted to the > niches that they serve well. Take Java, for example. I think it will > be still be used, and people will still even be writing new programs > in it, but it will be rightly scorned in a lot of places where it is > now embraced. Some of this won't actually be due to technological > advances, but just changes in perception. For example, I predict lots > of programs that people now write in Java will be written in Python, > even if the core language of Python remains fairly stable. A friend of mine, and a good Java programmer, says caustically: "Java is COBOL of the future". Where I work we develop a huge application in Websphere (IBM Java-based application server). The problems with legacy code made project manager joke "perhaps we should rewrite this in Python". Perhaps some day it will not be a joke anymore? Personally, I chose to stay away from Java, even though it would temporarily help me: the amount of time & effort it takes to master the necessary toolset is *huge*, and my scarce time is better spent elsewhere, on more productive tools, and I really, really do not want lots of my limited time to go down the drain in a few years. Take EJB for example: even its creators realized they've overdone it with EJB 2 and simplified somewhat EJB 3 and switched to annotations instead of gazillion XML formats. But still I dread the thought of having to spend so much time learning it before I can do a few lines of productive work in it. In a way it's horrible: all this gargantuan effort in a few years will be completely wasted, down the drain. All those developer hours and dollars wasted.. In a way, C wasn't as bad as Java has been: at least many of C libs, with new bindings, still live on and do work. > Going back to Paul's statement, I agree that "there should be one and > only one obvious way to do it" in Python, but I don't think the > philosophy applies to the greater ecosystem of software development. +1 Note that when it comes to bigger tools or frameworks, even in the world of Python things are not "one obvious way", e.g. Django for quick and dirty and small apps, and Pylons for big and powerful apps. There may be "one obvious way to do it" in a very, very narrow context, but when contexts widen, like, say: "what is web framework I should choose?" the answers diverge, because answer has to be variation of "it depends on your situation". > Whether RSON is really an improvement or not is an orthogonal issue to > whether we should strive for improvement. +1 Regards, mk From alfps at start.no Wed Mar 3 14:32:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 20:32:25 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>> * Mike Kent: >>>>> What's the compelling use case for this vs. a simple try/finally? >>>> >>>> if you thought about it you would mean a simple "try/else". >>>> "finally" is >>>> always executed. which is incorrect for cleanup >>> >>> Eh? Failed execution doesn't require cleanup? The example you gave is >>> definitely equivalent to the try: finally: that Mike posted. >> >> Sorry, that's incorrect: it's not. >> >> With correct code (mine) cleanup for action A is only performed when >> action A succeeds. >> >> With incorrect code cleanup for action A is performed when A fails. > > Oh? > > $ cat cleanup.py > > class Cleanup: > def __init__( self ): > self._actions = [] > > def call( self, action ): > assert( callable( action ) ) > self._actions.append( action ) > > def __enter__( self ): > return self > > def __exit__( self, x_type, x_value, x_traceback ): > while( len( self._actions ) != 0 ): > try: > self._actions.pop()() > except BaseException as x: > raise AssertionError( "Cleanup: exception during cleanup" ) > > def print_(x): > print x > > with Cleanup() as at_cleanup: > at_cleanup.call(lambda: print_("Cleanup executed without an > exception.")) > > with Cleanup() as at_cleanup: *Here* is where you should 1) Perform the action for which cleanup is needed. 2) Let it fail by raising an exception. > at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) > raise RuntimeError() With an exception raised here cleanup should of course be performed. And just in case you didn't notice: the above is not a test of the example I gave. > $ python cleanup.py > Cleanup executed without an exception. > Cleanup execute with an exception. > Traceback (most recent call last): > File "cleanup.py", line 28, in > raise RuntimeError() > RuntimeError > >>> The actions are always executed in your example, >> >> Sorry, that's incorrect. > > Looks like it to me. I'm sorry, but you're 1) not testing my example which you're claiming that you're testing, and 2) not even showing anything about your earlier statements, which were just incorrect. You're instead showing that my code works as it should for the case that you're testing, which is a bit unnecessary since I knew that, but thanks anyway. I'm not sure what that shows, except that you haven't grokked this yet. >>> From your post, the scope guard technique is used "to ensure some >>> desired cleanup at the end of a scope, even when the scope is exited >>> via an exception." This is precisely what the try: finally: syntax is >>> for. >> >> You'd have to nest it. That's ugly. And more importantly, now two people >> in this thread (namely you and Mike) have demonstrated that they do not >> grok the try functionality and manage to write incorrect code, even >> arguing that it's correct when informed that it's not, so it's a pretty >> fragile construct, like goto. > > Uh-huh. Yeah. Consider that you're now for the third time failing to grasp the concept of cleanup for a successful operation. >>> The with statement allows you to encapsulate repetitive boilerplate >>> into context managers, but a general purpose context manager like your >>> Cleanup class doesn't take advantage of this. >> >> I'm sorry but that's pretty meaningless. It's like: "A house allows you >> to encapsulate a lot of stinking garbage, but your house doesn't take >> advantage of that, it's disgustingly clean". Hello. > > No, I'm saying that your Cleanup class is about as ugly as the try: > finally:. It just shifts the ugliness around. There is a way to use the > with statement to make things look better and more readable in certain > situations, namely where there is some boilerplate that you would > otherwise repeat in many places using try: finally:. You can encapsulate > that repetitive code into a class or a @contextmanager generator and > just call the contextmanager. A generic context manager where you > register callables doesn't replace any boilerplate. You still repeat all > of the cleanup code everywhere. What's more, because you have to shove > everything into a callable, you have significantly less flexibility than > the try: finally:. Sorry, but that's meaningless again. You're repeating that my house has no garbage in it. And you complain that it would be work to add garbage to it. Why do you want that garbage? I think it's nice without it! > I will admit that you can put the cleanup code closer to the code that > needs to get cleaned up, but you pay a price for that. Yes, that's an additional point, and important. I forgot to mention it. Thanks! Cheers & hth., - Alf From bthate at gmail.com Wed Mar 3 14:33:02 2010 From: bthate at gmail.com (Bart Thate) Date: Wed, 3 Mar 2010 11:33:02 -0800 (PST) Subject: GZRBOT 0.2 BETA1 released Message-ID: <9e26a4b7-cec6-4f73-bcd2-5fe95aa8647c@y17g2000yqd.googlegroups.com> Hello World ! Welcome to the world of Active API ;] Google released their new Wave API so i quickly ported GZRBOT to the new API. Now we can finally push to waves instead of using polling. This makes pushing feeds to waves possible, and this is one of the main things GZRBOT can do. We now use pubsubhubbub service provided by superfeedr.com to fetch our RSS and Atom feeds for us and have them pushed to the bot, which we then forward to the waves that have been subscribed ( or jabber clients for that matter) This release is BETA1 which doesnt mean the code is fixed yet as BETA2,3,4 and RC1, 2, 3 etc are still ahead before 0.2 is released. So this is kind of bleeding edge and you might want to wait for 0.2.1 or so ;] If you like to play around with wave/jabber bots on GAE then this is the bot for you. Code is at the mercurial repo: hg clone http://gzrbot.googlecode.com/hg Or download the tarball at http://gzrbot.googlecode.com Basic documentation is at http://gozerbot.org/gzrdoc and i made a wave available if you want to try the bot with me or have questions and such: https://wave.google.com/wave/#restored:wave:googlewave.com!w%252B51rssVscD Hope you enjoy it ! Bart about GZRBOT: GZRBOT is a general purpose bot for wave, web and xmpp. It uses a plugin structure to provide easy programming of commands and callbacks, allowing you to implement your own "killer plugin". GZRBOT comes with some plugins provided, for example: - Hubbub plugin that uses superfeedr.com to get RSS feed pushed instead of pulling them ourselves. This lowers the load on the bot considerably. A max of 1000 feeds is for free. - Watcher plugin that let you watch waves, get notified in jabber when your waves updates. (the bots sends the updated txt) - Wave plugin that provides help with wave management. I'm working on wave cloning after say x blips, so that larger conversations can be created in google wave. UNDER DEVELOPMENT - This is mostly needed for the last plugin i want to mention and that is the gozernet plugin. The plugin allows for relaying of events between GZRBOT (Wave/Web/XMPP) and GOZERBOT (IRC/Jabber). IRC and Wave can be bridged this way. UNDER DEVELOPMENT GZRBOT is free code (BSD) and can be cloned as needed ;] note: as of 0.2 GZRBOT uses the new v2 Wave API and thus needs registration with google. From robert.kern at gmail.com Wed Mar 3 14:33:43 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 13:33:43 -0600 Subject: Pylint Argument number differs from overridden method In-Reply-To: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Message-ID: On 2010-03-03 11:39 AM, Wanderer wrote: > Pylint W0221 gives the warning > Argument number differs from overridden method. > > Why is this a problem? I'm overriding the method to add additional > functionality. There are exceptions to every guideline. Doing this could easily be a mistake, so it's one of the many things that Pylint checks for. Silence the warning if you like. -- 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 From stefan_ml at behnel.de Wed Mar 3 14:35:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 20:35:01 +0100 Subject: SOAP 1.2 Python client ? In-Reply-To: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: BlueBird, 03.03.2010 17:32: > I am looking for a SOAP 1.2 python client. To my surprise, it seems > that this does not exist. Does anybody know about this ? SOAP may be an overly bloated protocol, but it's certainly not black magic. It's not hard to do manually if you really need to: http://effbot.org/zone/element-soap.htm Stefan From steve at holdenweb.com Wed Mar 3 14:38:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Mar 2010 14:38:16 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: mk wrote: > D'Arcy J.M. Cain wrote: > >> Makes me want to go down to the basement and fire up the Altair. :-) > > Please don't, or else I fire up that univ Yugoslavian copy of VAX with > Pascal compiler (where I wrote my first program) and I will start my > first program of ping-pong. > > It was a few hundred lines but took 5 minutes to compile; "VAX" was > theoretically multitasking, but when more than 3 people were trying to > do smth on it simultaneously, it was basically seizing up. > > Regards, > mk > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk on a VAX 11/750. The only bitmapped display we had available was a Three Rivers PERQ, connected by a 9600bps serial line. We left it running at seven o'clock one evening, and by nine am the next day it had brought up about two thirds of the initial VM loader screen ... You tell these young kids, and they just don't believe you! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mrkafk at gmail.com Wed Mar 3 14:39:35 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:39:35 +0100 Subject: taking python enterprise level?... In-Reply-To: <1267638602.988.19.camel@localhost> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> Message-ID: Hello Tim, Pardon the questions but I haven't had the need to use denormalization yet, so: Tim Wintle wrote: > /* Table A */ > CREATE TABLE TableA ( > project_id BIGINT NOT NULL, > cost INT, > date DATETIME, > PRIMARY KEY (project_id, date) > ); > > /* Table projects */ > CREATE TABLE projects ( > client_id BIGINT NOT NULL, > project_id BIGINT NOT NULL, > INDEX(client_id) > ); > > > .... now the index on TableA has been optimised for queries against date > ranges on specific project ids which should more or less be sequential > (under a load of other assumptions) - but that reduces the efficiency of > the query under a join with the table "projects". > > If you denormalise the table, and update the first index to be on > (client_id, project_id, date) it can end up running far more quickly - IOW you basically merged the tables like follows? CREATE TABLE projects ( client_id BIGINT NOT NULL, project_id BIGINT NOT NULL, cost INT, date DATETIME, INDEX(client_id, project_id, date) ); From what you write further in the mail I conclude that you have not eliminated the first table, just made table projects look like I wrote above, right? (and used stored procedures to make sure that both tables contain the relevant data for client_id and project_id columns in both tables) Have you had some other joins on denormalized keys? i.e. in example how the join of hypothetical TableB with projects on projects.client_id behave with such big tables? (bc I assume that you obviously can't denormalize absolutely everything, so this implies the need of doing some joins on denormalized columns like client_id). > assuming you can access the first mapping anyway - ? I'm not clear on what you mean here. > so you're still > storing the first table, with stored procedures to ensure you still have > correct data in all tables. Regards, mk From mrkafk at gmail.com Wed Mar 3 14:44:08 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:44:08 +0100 Subject: Docstrings considered too complicated In-Reply-To: <539252.91463.qm@web58904.mail.re1.yahoo.com> References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: Ed Keith wrote: > --- On Wed, 3/3/10, D'Arcy J.M. Cain wrote: > >> They needed a way to tell where the end of the information >> was. Why >> they used ^Z (SUB - Substitute) instead of ^C (ETX - End of >> TeXt) or >> even ^D (EOT - End Of Transmission) is anyone's guess. > > That has always puzzled me to. ETX and EOT were well established, why no use one of them? I'd love to know what they were thinking. Probably nothing: what many people do with confronted with a problem. It reminds me of why Windows uses backslashes for path separation instead of slashes: what I've *heard*, and do not know if it's true, it's because Gates fancied using / for options switch instead of -, and to hell with established practice. Regards, mk From arnodel at googlemail.com Wed Mar 3 14:44:41 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 03 Mar 2010 19:44:41 +0000 Subject: Generic singleton References: Message-ID: mk writes: [...] > hashable > .. > All of Python?s immutable built-in objects are hashable, while no > mutable containers (such as lists or dictionaries) are. > > Well ok, hashable they're not; but apparently at least dict and list > have id()? lists and dicts are not hashable, but their types are: >>> hash(dict) 4296155808 >>> hash(list) 4296151808 So just use the type as the key to the dictionary you maintain in your singleton. But the question is what you use your singleton for. -- Arnaud From mrkafk at gmail.com Wed Mar 3 14:46:24 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:46:24 +0100 Subject: cpan for python? In-Reply-To: <877hpt46yw.fsf@castleamber.com> References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> <877hpt46yw.fsf@castleamber.com> Message-ID: John Bokma wrote: > I want to remove something that I installed that way (because it's > installation procedure seems to be broken; opensocial) I understand that > this can't be blamed on pip, but it's odd that in this century it's > still hard to install/uninstall modules :-( Have you looked in a file easy-install.pth in site-packages? In my experience it's enough to delete the line for package from there and delete package's egg or directory. I agree that this is kind of backward, though. Regards, mk From MLMDev at Comcast.net Wed Mar 3 14:54:04 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Wed, 3 Mar 2010 14:54:04 -0500 Subject: CGI, POST, and file uploads In-Reply-To: References: Message-ID: <67C7A291-6790-4B10-8797-D95F8AD36F9C@Comcast.net> On Mar 2, 2010, at 4:48 PM, I wrote: > Can someone tell me how to upload the contents of a (relatively > small) file using an HTML form and CGI in Python 3.1? As far as I > can tell from a half-day of experimenting, browsing, and searching > the Python issue tracker, this is broken. followed by a detailed example demonstrating the problem. Having hear no response, let me clarify that this request was preliminary to filing a bug report -- I wanted to make sure I wasn't missing something here. If nothing else, this failure should be documented rather than the 3.1 library documentation continuing to describe how to upload file contents with POST. If someone thinks there is a way to make this work in 3.1, or that it isn't a bug because CGI is hopeless (i.e., non-WSGI-compliant), or that the documentation shouldn't be changed, please respond. I'd rather have this particular discussion here than in the bug tracking system. Meanwhile, let me heartily recommend the Bottle Web Framework (http://bottle.paws.de ) for its simplicity, flexibility, and power. Very cool stuff. To make it work in Python3.1, do the following: 1. run 2to3 on bottle.py (the only file there is to download) 2. copy or move the resulting bottle.py to the site-libs directory in your Python installation's library directory 3. don't use request.GET.getone or request.POST.getone -- instead of getone, use get (the protocol changed to that of the Mapping ABC from the collections module) 4. the contents of a file will be returned inside a cgi.FieldStorage object, so you need to add '.value' after the call to get in that case From drobinow at gmail.com Wed Mar 3 14:54:27 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 3 Mar 2010 14:54:27 -0500 Subject: Docstrings considered too complicated In-Reply-To: <539252.91463.qm@web58904.mail.re1.yahoo.com> References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: <4eb0089f1003031154j78cc7d22kf18ae339fe8c686@mail.gmail.com> On Wed, Mar 3, 2010 at 1:01 PM, Ed Keith wrote: > --- On Wed, 3/3/10, D'Arcy J.M. Cain ?wrote: > >> They needed a way to tell where the end of the information >> was.? Why >> they used ^Z (SUB - Substitute) instead of ^C (ETX - End of >> TeXt) or >> even ^D (EOT - End Of Transmission) is anyone's guess. > > That has always puzzled me to. ETX and EOT were well established, why no use one of them? I'd love to know what they were thinking. There were numerous incompatible and primitive transfer protocols in those days. They probably wanted to pick something that was NOT well established so it would pass through without, for example, causing End Of Transmission. From python at mrabarnett.plus.com Wed Mar 3 14:59:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 19:59:22 +0000 Subject: Sort Big File Help In-Reply-To: References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: <4B8EBF9A.6080603@mrabarnett.plus.com> mk wrote: > John Filben wrote: >> I am new to Python but have used many other (mostly dead) languages in >> the past. I want to be able to process *.txt and *.csv files. I can >> now read that and then change them as needed ? mostly just take a >> column and do some if-then to create a new variable. My problem is >> sorting these files: >> >> 1.) How do I sort file1.txt by position and write out >> file1_sorted.txt; for example, if all the records are 100 bytes long >> and there is a three digit id in the position 0-2; here would be some >> sample data: >> >> a. 001JohnFilben?? >> >> b. 002Joe Smith?.. > > Use a dictionary: > > linedict = {} > for line in f: > key = line[:3] > linedict[key] = line[3:] # or alternatively 'line' if you want to > include key in the line anyway > > sortedlines = [] > for key in linedict.keys().sort(): > sortedlines.append(linedict[key]) > > (untested) > > This is the simplest, and probably inefficient approach. But it should > work. > [snip] Simpler would be: lines = f.readlines() lines.sort(key=lambda line: line[ : 3]) or even: lines = sorted(f.readlines(), key=lambda line: line[ : 3])) From invalid at invalid.invalid Wed Mar 3 15:02:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 20:02:28 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: On 2010-03-03, mk wrote: >> That has always puzzled me to. ETX and EOT were well established, why >> no use one of them? I'd love to know what they were thinking. > > Probably nothing: what many people do with confronted with a problem. > > It reminds me of why Windows uses backslashes for path separation > instead of slashes: what I've *heard*, and do not know if it's true, > it's because Gates fancied using / for options switch instead of -, > and to hell with established practice. Using / for the option switch _was_ the established practice (if you came from a DEC background the way that CP/M and DOS did). -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From benjamin.kaplan at case.edu Wed Mar 3 15:12:31 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Mar 2010 15:12:31 -0500 Subject: Installing Scrapy on Mac OS X 10.6 In-Reply-To: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> References: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> Message-ID: On Wed, Mar 3, 2010 at 12:06 PM, Sky Larking wrote: > Has anyone successfully installed Scrapy ( http://scrapy.org ) on a > Mac OS X machine running 10.6.x? The Documentaion says > Mac OS X ships an libxml2 version too old to be used by Scrapy...But > doesn't say which version of OS X.. I am wondering if the version of > libxml2 is also not compatible.. > > > -- > http://mail.python.org/mailman/listinfo/python-list > Looks like it's shipping with 2.7.3. Scrappy requires 2.6.28 so it should work but I haven't tried. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Mar 3 15:18:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 15:18:26 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: On 3/3/2010 6:47 AM, Oren Elrad wrote: > With that said, let me at least offer a token defense of my position. > By way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. > > Certainly the parade of horribles (bad files! corrupt data! syntax > errors!) is a tad melodramatic. Either os.remove() succeeds or it > doesn't and the execution path (in the estimation of this programmer, > at least) is not at all impacted by whether it succeeds or fails. I > know with certainty at compile time what exceptions might be raised > and what the consequences of passing them are and there is no sense > pestering the user or sweating over it. Nor can I see the logic, as > was suggested, in writing "except OSError:" since (seems to me) mere > surplusage -- it neither causes a semantic difference in the way the > program runs nor provides anything useful to the reader. Suppose you misspell 'somefile' or 'remove' (or the file gets corrupted somehow -- which unfortunate can happen). Now you suppress the NameError or AttributeError, which is a mistake. Suppose someone copies your code into a context where 'os' is not imported or where 'os' is a variable (for bone type, for instance). More bad error suppression. Bare excepts seem ok for experimental, draft, or throwaway code, but somewhat dubious for production code. For anyone reading your code a few years from now, 'except OSError' would be clearer that that is all you mean to pass on. Wrapping the code in a function makes the overhead of adding 'OSError' trivial. It also makes it trivial to do something different, like adding the file to a collection to be retried later. It also reduces the points of possible corruption to one instead of many. Terry Jan Reedy From tjreedy at udel.edu Wed Mar 3 15:47:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 15:47:11 -0500 Subject: Which mock library do you prefer? In-Reply-To: References: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: On 3/3/2010 7:43 AM, Albert van der Horst wrote: >> Right, isolation is essential. But I can't decide to which extent I >> should propagate isolation. >> For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, >> author suggests that if you do unittesting you should isolate the >> smallest units of code from each other. For example, if you have a >> class: >> Class SomeClass(object): >> def method1(self): >> return 5 >> def method2(self): >> return self.method1 + 10 >> >> According to the book, if you want to test method2, you should isolate >> it from method1 and class instance('self'). >> Other books are not so strict... >> >> And what should I follow as newbie? Pretty much any test assumes that basic things other than the tested object work correctly. For instance, any test of method2 will assume that '+' works correctly. The dependency graph between methods in a class will nearly always be acyclic. So I would start with the 'leaf' methods and work up. In the above case, test method1 first and then method2. The dependence of the test of method2 on the correctness of method1 is hardly worse, to me, then its dependence on the correctness of int.__add__. It is just the the responsibility for the latter falls on the developers, and *their* suite of tests. Whenever any code test fails, there are two possibilities. The code itself is buggy, or something it depends on is buggy. I see two reasons for isolation and mock units: test resource saving (especially time) and independent development. If you are developing ClassA and someone else is developing ClassB, you might want to test ClassA even though it depends on ClassB and classB is not ready yet. This consideration is much less likely to apply to method2 versus method1 of a coherent class. My current opinions. Terry Jan Reedy From cartercc at gmail.com Wed Mar 3 15:54:53 2010 From: cartercc at gmail.com (ccc31807) Date: Wed, 3 Mar 2010 12:54:53 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: On Mar 3, 12:36?pm, Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > athttp://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. I only read the first two paragraphs of your article, so I can't respond to it. I've halfway followed the NoSQL movement. My day job is a database manager and I so SQL databases for a living, as well as Perl. I see a lot of abuse of relational databases in the Real World, as well as a lot of abuse for non-SQL alternatives, e.g., (mis)using Excel for a database. The big, enterprise database we have at work is built on IBM UniQuery, which is a non-SQL flat file database product, so I've had a lot of experience with big non-SQL database work. I've also developed a marked preference for plain text databases. For a lot of applications they are simpler, easier, and better. I've also had some experience with XML databases, and find that they are ideal for applications with 'ragged' data. As with anything else, you need to match the tool to the job. Yes, I feel that relational database technology has been much used, and much abused. However, one of my favorite applications is Postgres, and I think it's absolutely unbeatable where you have to store data and perform a large number of queries. Finally, with regard to Structured Query Language itself, I find that it's well suited to its purpose. I hand write a lot of SQL statements for various purposes, and while like any language you find it exceedingly difficult to express concepts that you can think, it mostly allows the expression of most of what you want to say. CC. From mrkafk at gmail.com Wed Mar 3 15:58:15 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 21:58:15 +0100 Subject: taking python enterprise level?... In-Reply-To: <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> Message-ID: Philip Semanchuk wrote: >> So there *may* be some evidence that joins are indeed bad in practice. >> If someone has smth specific/interesting on the subject, please post. > > It's an unprovable assertion, or a meaningless one depending on how one > defines the terms. You could also say "there *may* be some evidence that > Python lists are bad in practice". Python lists and SQL JOINs are like > any part of a language or toolkit. They're good tools for solving > certain classes of problems. They can also be misapplied to problems > that they're not so good at. Sometimes they're a performance bottleneck, > even when solving the problems for which they're best. Sometimes the > best way to solve a performance bottleneck is to redesign your > app/system so you don't need to solve that kind of problem anymore > (hence the join-less databases). Other times, the cure is worse than the > disease and you're better off throwing hardware at the problem. Look, I completely agree with what you're saying, but: that doesn't change the possibility that joins may be expensive in comparison to other SQL operations. This is the phrase I should have used perhaps; 'expensive in comparison with other SQL operations' instead of 'bad'. Example from my app, where I behaved "by the book" (I hope) and normalized my data: $ time echo "\c hrs; SELECT hosts.ip, reservation.start_date, architecture.architecture, os_kind.os_kind, os_rel.os_rel, os_version.os_version, project.project, email.email FROM hosts INNER JOIN project ON project.id = hosts.project_id INNER JOIN architecture ON hosts.architecture_id = architecture.id INNER JOIN os_kind ON os_kind.id = hosts.os_kind_id INNER JOIN os_rel ON hosts.os_rel_id = os_rel.id INNER JOIN os_version ON hosts.os_version_id = os_version.id INNER JOIN reservation_hosts ON hosts.id = reservation_hosts.host_id INNER JOIN reservation on reservation.id = reservation_hosts.reservation_id INNER JOIN email ON reservation.email_id = email.id ;" | psql > /dev/null real 0m0.099s user 0m0.015s sys 0m0.005s $ time echo "\c hrs; > SELECT hosts.ip FROM hosts; > SELECT reservation.start_date FROM reservation; > SELECT architecture.architecture FROM architecture; > SELECT os_rel.os_rel FROM os_rel; > SELECT os_version.os_version FROM os_version; > SELECT project.project FROM project; > SELECT email.email FROM email; > " | psql > /dev/null real 0m0.046s user 0m0.008s sys 0m0.004s Note: I've created indexes on those tables, both on data columns like hosts.ip and on .id columns. So yes, joins apparently are at least twice as expensive as simple selects without joins, on a small dataset. Not a drastic increase in cost, but smth definitely shows. It would be interesting to see what happens when row numbers increase to large numbers, but I have no such data. Regards, mk From arnodel at googlemail.com Wed Mar 3 15:58:39 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 03 Mar 2010 20:58:39 +0000 Subject: Sort Big File Help References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: MRAB writes: > mk wrote: >> John Filben wrote: >>> I am new to Python but have used many other (mostly dead) languages >>> in the past. I want to be able to process *.txt and *.csv files. >>> I can now read that and then change them as needed ? mostly just >>> take a column and do some if-then to create a new variable. My >>> problem is sorting these files: >>> >>> 1.) How do I sort file1.txt by position and write out >>> file1_sorted.txt; for example, if all the records are 100 bytes >>> long and there is a three digit id in the position 0-2; here would >>> be some sample data: >>> >>> a. 001JohnFilben?? >>> >>> b. 002Joe Smith?.. >> >> Use a dictionary: >> >> linedict = {} >> for line in f: >> key = line[:3] >> linedict[key] = line[3:] # or alternatively 'line' if you want >> to include key in the line anyway >> >> sortedlines = [] >> for key in linedict.keys().sort(): >> sortedlines.append(linedict[key]) >> >> (untested) >> >> This is the simplest, and probably inefficient approach. But it >> should work. >> > [snip] > Simpler would be: > > lines = f.readlines() > lines.sort(key=lambda line: line[ : 3]) > > or even: > > lines = sorted(f.readlines(), key=lambda line: line[ : 3])) Or even: lines = sorted(f) -- Arnaud From tjreedy at udel.edu Wed Mar 3 16:00:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 16:00:11 -0500 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <4b8e929d$0$1585$742ec2ed@news.sonic.net> References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: On 3/3/2010 12:05 PM, John Nagle wrote: >> We have an equivalent in PyPI, though it's incomplete since many >> *registered* packages are not actually hosted *at* PyPI. > > CPAN is a repository. PyPi is an collection of links. As Ben said, PyPI currently is also a respository and not just links to other repositories. > CPAN has over 260 mirrors. PyPi has none. A mirroring system has been or is being set up with at least a couple of mirrors for things that are hosted at PyPI. > CPAN enforces standard organization on packages. PyPi does not. > > CPAN has quality control, with testers and a test reporting system. > PyPi does not. People who are familiar with and like CPAN are free to help improve PyPI. Those of us not familiar with it may not know what we are missing, or have little idea about what works with CPAN. Terry Jan Reedy From malaclypse2 at gmail.com Wed Mar 3 16:02:02 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 3 Mar 2010 16:02:02 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <16651e81003031302s6aac798al2864c8b742d577c3@mail.gmail.com> On Wed, Mar 3, 2010 at 2:32 PM, Alf P. Steinbach wrote: > I'm not sure what that shows, except that you haven't grokked this yet. Maybe you could give us an example of how your code should be used, and how it differs from the other examples people have given? And maybe a quick example of why you would not want to clean up after a failed operation? I've been trying to follow along, and I don't get it either. I guess that makes me at least the third person that doesn't understand what you're trying to get across. -- Jerry From robert.kern at gmail.com Wed Mar 3 16:02:31 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 15:02:31 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>> * Mike Kent: >>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>> >>>>> if you thought about it you would mean a simple "try/else". >>>>> "finally" is >>>>> always executed. which is incorrect for cleanup >>>> >>>> Eh? Failed execution doesn't require cleanup? The example you gave is >>>> definitely equivalent to the try: finally: that Mike posted. >>> >>> Sorry, that's incorrect: it's not. >>> >>> With correct code (mine) cleanup for action A is only performed when >>> action A succeeds. >>> >>> With incorrect code cleanup for action A is performed when A fails. >> >> Oh? >> >> $ cat cleanup.py >> >> class Cleanup: >> def __init__( self ): >> self._actions = [] >> >> def call( self, action ): >> assert( callable( action ) ) >> self._actions.append( action ) >> >> def __enter__( self ): >> return self >> >> def __exit__( self, x_type, x_value, x_traceback ): >> while( len( self._actions ) != 0 ): >> try: >> self._actions.pop()() >> except BaseException as x: >> raise AssertionError( "Cleanup: exception during cleanup" ) >> >> def print_(x): >> print x >> >> with Cleanup() as at_cleanup: >> at_cleanup.call(lambda: print_("Cleanup executed without an exception.")) >> >> with Cleanup() as at_cleanup: > > *Here* is where you should > > 1) Perform the action for which cleanup is needed. > > 2) Let it fail by raising an exception. > > >> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >> raise RuntimeError() > > With an exception raised here cleanup should of course be performed. > > And just in case you didn't notice: the above is not a test of the > example I gave. > > >> $ python cleanup.py >> Cleanup executed without an exception. >> Cleanup execute with an exception. >> Traceback (most recent call last): >> File "cleanup.py", line 28, in >> raise RuntimeError() >> RuntimeError >> >>>> The actions are always executed in your example, >>> >>> Sorry, that's incorrect. >> >> Looks like it to me. > > I'm sorry, but you're > > 1) not testing my example which you're claiming that you're testing, and Then I would appreciate your writing a complete, runnable example that demonstrates the feature you are claiming. Because it's apparently not "ensur[ing] some desired cleanup at the end of a scope, even when the scope is exited via an exception" that you talked about in your original post. Your sketch of an example looks like mine: with Cleanup as at_cleanup: # blah blah chdir( somewhere ) at_cleanup.call( lambda: chdir( original_dir ) ) # blah blah The cleanup function gets registered immediately after the first chdir() and before the second "blah blah". Even if an exception is raised in the second "blah blah", then the cleanup function will still run. This would be equivalent to a try: finally: # blah blah #1 chdir( somewhere ) try: # blah blah #2 finally: chdir( original_dir ) and not a try: else: # blah blah #1 chdir( somewhere ) try: # blah blah #2 else: chdir( original_dir ) Now, I assumed that the behavior with respect to exceptions occurring in the first "blah blah" weren't what you were talking about because until the chdir(), there is nothing to clean up. There is no way that the example you gave translates to a try: else: as you claimed in your response to Mike Kent. > 2) not even showing anything about your earlier statements, which were > just incorrect. > > You're instead showing that my code works as it should for the case that > you're testing, which is a bit unnecessary since I knew that, but thanks > anyway. It's the case you seem to be talking about in your original post. You seem to have changed your mind about what you want to talk about. That's fine. We don't have to stick with the original topic, but I do ask you to acknowledge that you originally were talking about a feature that "ensure[s] some desired cleanup at the end of a scope, even when the scope is exited via an exception." Do you acknowledge this? > I'm not sure what that shows, except that you haven't grokked this yet. > > >>>> From your post, the scope guard technique is used "to ensure some >>>> desired cleanup at the end of a scope, even when the scope is exited >>>> via an exception." This is precisely what the try: finally: syntax is >>>> for. >>> >>> You'd have to nest it. That's ugly. And more importantly, now two people >>> in this thread (namely you and Mike) have demonstrated that they do not >>> grok the try functionality and manage to write incorrect code, even >>> arguing that it's correct when informed that it's not, so it's a pretty >>> fragile construct, like goto. >> >> Uh-huh. > > Yeah. Consider that you're now for the third time failing to grasp the > concept of cleanup for a successful operation. Oh, I do. But if I didn't want it to run on an exception, I'd just write the code without any try:s or with:s at all. # blah blah #1 chdir( somewhere ) # blah blah #2 chdir( original_dir ) >>>> The with statement allows you to encapsulate repetitive boilerplate >>>> into context managers, but a general purpose context manager like your >>>> Cleanup class doesn't take advantage of this. >>> >>> I'm sorry but that's pretty meaningless. It's like: "A house allows you >>> to encapsulate a lot of stinking garbage, but your house doesn't take >>> advantage of that, it's disgustingly clean". Hello. >> >> No, I'm saying that your Cleanup class is about as ugly as the try: >> finally:. It just shifts the ugliness around. There is a way to use >> the with statement to make things look better and more readable in >> certain situations, namely where there is some boilerplate that you >> would otherwise repeat in many places using try: finally:. You can >> encapsulate that repetitive code into a class or a @contextmanager >> generator and just call the contextmanager. A generic context manager >> where you register callables doesn't replace any boilerplate. You >> still repeat all of the cleanup code everywhere. What's more, because >> you have to shove everything into a callable, you have significantly >> less flexibility than the try: finally:. > > Sorry, but that's meaningless again. You're repeating that my house has > no garbage in it. No, I'm repeatedly saying that I think your solution stinks. I think it's ugly. I think it's restrictive. I think it does not improve on the available solutions. > And you complain that it would be work to add garbage > to it. Why do you want that garbage? I think it's nice without it! And you are entitled to that opinion. I am giving you mine. -- 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 From mrkafk at gmail.com Wed Mar 3 16:11:40 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:11:40 +0100 Subject: Generic singleton In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: > mk writes: > [...] >> hashable >> .. >> All of Python?s immutable built-in objects are hashable, while no >> mutable containers (such as lists or dictionaries) are. >> >> Well ok, hashable they're not; but apparently at least dict and list >> have id()? > > lists and dicts are not hashable, but their types are: Oh. >>>> hash(dict) > 4296155808 >>>> hash(list) > 4296151808 > > So just use the type as the key to the dictionary you maintain in your > singleton. Hmm I have tested it and it seems to work. > But the question is what you use your singleton for. Well, partly this was for sake of learning; but partially I was thinking whether singleton as such may be useful for implementing "global queue of tasks" for worker threads in a large program: instead of handing down over and over the same reference to the global queue of tasks, classes or functions could call Singleton() and be done with it. Or I could make my life simpler and use global variable. :-) I will soon need to write such program, with remote calls from pyro (most probably), many worker threads, short-running jobs and long-running jobs, etc. Regards, mk From wanderer at dialup4less.com Wed Mar 3 16:15:07 2010 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 3 Mar 2010 13:15:07 -0800 (PST) Subject: Pylint Argument number differs from overridden method References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Message-ID: <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> On Mar 3, 2:33?pm, Robert Kern wrote: > On 2010-03-03 11:39 AM, Wanderer wrote: > > > Pylint W0221 gives the warning > > Argument number differs from overridden method. > > > Why is this a problem? I'm overriding the method to add additional > > functionality. > > There are exceptions to every guideline. Doing this could easily be a mistake, > so it's one of the many things that Pylint checks for. Silence the warning if > you like. > > -- > 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 Thanks I was just wondering if I was overlooking something about inheritance. From tjreedy at udel.edu Wed Mar 3 16:17:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 16:17:11 -0500 Subject: Pylint Argument number differs from overridden method In-Reply-To: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Message-ID: On 3/3/2010 12:39 PM, Wanderer wrote: > Pylint W0221 gives the warning > Argument number differs from overridden method. > > Why is this a problem? It *could* indicate a mistake. Lint programs, by definition, are nitpicky, and flag things that are possible problems even though syntactically correct. I'm overriding the method to add additional > functionality. > > This > def GetRays(self, angle, pt, lmbda = 0.6): > """ > """ > > angle, x, y, Rays, Power = self.ARefract(angle, pt[0], pt[1], > lmbda) > pt1 = (x, y) > > return Rays, Power, angle, pt1 > > > def ARefract(self, angle, x, y, lmbda = 0.6): > """ > """ > > Nt = self.Mat.NtGet(lmbda) > self.NtSet(Nt) > angle, x, y, Rays, Power = self.Refract(angle, x, y) > > return angle, x, y, Rays, Power > > > > Over rides this > > def GetRays(self, angle, pt): > """ > """ > > angle, x, y, Rays, Power = self.Refract(angle, pt[0], pt[1]) > pt1 = (x, y) > > return Rays, Power, angle, pt1 > > > Thanks From mrkafk at gmail.com Wed Mar 3 16:19:04 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:19:04 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: Steve Holden wrote: > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk > on a VAX 11/750. The only bitmapped display we had available was a Three > Rivers PERQ, connected by a 9600bps serial line. We left it running at > seven o'clock one evening, and by nine am the next day it had brought up > about two thirds of the initial VM loader screen ... > > You tell these young kids, and they just don't believe you! For the uncouth yobs, err, culturally-challenged: http://www.youtube.com/watch?v=Xe1a1wHxTyo (Four Yorkshiremen) Regards, mk From nad at acm.org Wed Mar 3 16:22:59 2010 From: nad at acm.org (Ned Deily) Date: Wed, 03 Mar 2010 13:22:59 -0800 Subject: Installing Scrapy on Mac OS X 10.6 References: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> Message-ID: In article <9b08574f-0410-45bc-89af-0d3cf7d21819 at e7g2000yqf.googlegroups.com>, Sky Larking wrote: > Has anyone successfully installed Scrapy ( http://scrapy.org ) on a > Mac OS X machine running 10.6.x? The Documentaion says > Mac OS X ships an libxml2 version too old to be used by Scrapy...But > doesn't say which version of OS X.. I am wondering if the version of > libxml2 is also not compatible.. A similar question came up on Stack Overflow recently: http://stackoverflow.com/questions/2353957/do-i-need-32bit-libxml2-for-py thon-on-snow-leopard/ -- Ned Deily, nad at acm.org From darcy at druid.net Wed Mar 3 16:23:14 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 16:23:14 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> Message-ID: <20100303162314.a46484cf.darcy@druid.net> On Wed, 03 Mar 2010 20:39:35 +0100 mk wrote: > > If you denormalise the table, and update the first index to be on > > (client_id, project_id, date) it can end up running far more quickly - Maybe. Don't start with denormalization. Write it properly and only consider changing if profiling suggests that that is your bottleneck. With a decent database engine and proper design it will hardly ever be. > From what you write further in the mail I conclude that you have not > eliminated the first table, just made table projects look like I wrote > above, right? (and used stored procedures to make sure that both tables > contain the relevant data for client_id and project_id columns in both > tables) Note that rather than speeding things up this could actually slow things down depending on your usage. If you do lots of updates and you have to write extra information every time then that's worse than a few extra reads, especially since read data can be cached but written data must be pushed to disk immediately in an ACID database. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Wed Mar 3 16:29:29 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 16:29:29 -0500 Subject: Old farts playing with their toys (was: Docstrings...) In-Reply-To: <4B8EABCB.6050303@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> <4B8EABCB.6050303@mrabarnett.plus.com> Message-ID: <20100303162929.560a17d3.darcy@druid.net> On Wed, 03 Mar 2010 18:34:51 +0000 MRAB wrote: > But I was still able to play Nim and Duck Shoot (after keying it in)! Did you ever play Star Trek with sound effects? I was never able to get it to work but supposedly if you put an AM radio tuned to a specific frequency near the side with the I/O card it would generate static that was supposed to be the sound of explosions. Of course, the explosions were happening in a vaccum so maybe the silence was accurate. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From bdesth.quelquechose at free.quelquepart.fr Wed Mar 3 16:34:46 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 22:34:46 +0100 Subject: Generic singleton In-Reply-To: References: Message-ID: <4b8ee36f$0$22040$426a74cc@news.free.fr> mk a ?crit : > > does every builtin class have unique id? Classes are objects. And every object *within a python process* has it's own unique id. For a definition of "unique" being "unique amongst the objects living in the process at a given time" - IOW, if an object is garbage-collected, it's id can (and will) be reused. For the record, in CPython, the id value is the address of the (virtual) memory location where the object lives (not that you could do anything of this info from within Python - no pointers here). From alfps at start.no Wed Mar 3 16:35:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 22:35:09 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>> * Mike Kent: >>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>> >>>>>> if you thought about it you would mean a simple "try/else". >>>>>> "finally" is >>>>>> always executed. which is incorrect for cleanup >>>>> >>>>> Eh? Failed execution doesn't require cleanup? The example you gave is >>>>> definitely equivalent to the try: finally: that Mike posted. >>>> >>>> Sorry, that's incorrect: it's not. >>>> >>>> With correct code (mine) cleanup for action A is only performed when >>>> action A succeeds. >>>> >>>> With incorrect code cleanup for action A is performed when A fails. >>> >>> Oh? >>> >>> $ cat cleanup.py >>> >>> class Cleanup: >>> def __init__( self ): >>> self._actions = [] >>> >>> def call( self, action ): >>> assert( callable( action ) ) >>> self._actions.append( action ) >>> >>> def __enter__( self ): >>> return self >>> >>> def __exit__( self, x_type, x_value, x_traceback ): >>> while( len( self._actions ) != 0 ): >>> try: >>> self._actions.pop()() >>> except BaseException as x: >>> raise AssertionError( "Cleanup: exception during cleanup" ) >>> >>> def print_(x): >>> print x >>> >>> with Cleanup() as at_cleanup: >>> at_cleanup.call(lambda: print_("Cleanup executed without an >>> exception.")) >>> >>> with Cleanup() as at_cleanup: >> >> *Here* is where you should >> >> 1) Perform the action for which cleanup is needed. >> >> 2) Let it fail by raising an exception. >> >> >>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>> raise RuntimeError() >> >> With an exception raised here cleanup should of course be performed. >> >> And just in case you didn't notice: the above is not a test of the >> example I gave. >> >> >>> $ python cleanup.py >>> Cleanup executed without an exception. >>> Cleanup execute with an exception. >>> Traceback (most recent call last): >>> File "cleanup.py", line 28, in >>> raise RuntimeError() >>> RuntimeError >>> >>>>> The actions are always executed in your example, >>>> >>>> Sorry, that's incorrect. >>> >>> Looks like it to me. >> >> I'm sorry, but you're >> >> 1) not testing my example which you're claiming that you're testing, and > > Then I would appreciate your writing a complete, runnable example that > demonstrates the feature you are claiming. Because it's apparently not > "ensur[ing] some desired cleanup at the end of a scope, even when the > scope is exited via an exception" that you talked about in your original > post. > > Your sketch of an example looks like mine: > > with Cleanup as at_cleanup: > # blah blah > chdir( somewhere ) > at_cleanup.call( lambda: chdir( original_dir ) ) > # blah blah > > The cleanup function gets registered immediately after the first chdir() > and before the second "blah blah". Even if an exception is raised in the > second "blah blah", then the cleanup function will still run. This would > be equivalent to a try: finally: > > # blah blah #1 > chdir( somewhere ) > try: > # blah blah #2 > finally: > chdir( original_dir ) Yes, this is equivalent code. The try-finally that you earlier claimed was equivalent, was not. > and not a try: else: > > # blah blah #1 > chdir( somewhere ) > try: > # blah blah #2 > else: > chdir( original_dir ) This example is however meaningless except as misdirection. There are infinitely many constructs that include try-finally and try-else, that the with-Cleanup code is not equivalent to. It's dumb to show one such. Exactly what are you trying to prove here? Your earlier claims are still incorrect. > Now, I assumed that the behavior with respect to exceptions occurring in > the first "blah blah" weren't what you were talking about because until > the chdir(), there is nothing to clean up. > > There is no way that the example you gave translates to a try: else: as > you claimed in your response to Mike Kent. Of course there is. Note that Mike wrapped the action A within the 'try': original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup The 'finally' he used, shown above, yields incorrect behavior. Namely cleanup always, while 'else', in that code, can yield correct behavior /provided/ that it's coded correctly: original_dir = os.getcwd() try: os.chdir(somewhere) except Whatever: # whatever, e.g. logging raise else: try: # Do other stuff finally: os.chdir(original_dir) # Do other cleanup >> 2) not even showing anything about your earlier statements, which were >> just incorrect. >> >> You're instead showing that my code works as it should for the case that >> you're testing, which is a bit unnecessary since I knew that, but thanks >> anyway. > > It's the case you seem to be talking about in your original post. What's this "seems"? Are you unable to read that very short post? > You > seem to have changed your mind about what you want to talk about. That's > fine. And what's this claim about me changing any topic? > We don't have to stick with the original topic Why not stick with the original topic? >, but I do ask you > to acknowledge that you originally were talking about a feature that > "ensure[s] some desired cleanup at the end of a scope, even when the > scope is exited via an exception." Yes, that's what it does. Which is I why I wrote that. This should not be hard to grok. > Do you acknowledge this? This seems like pure noise, to cover up that you were sputing a lot of incorrect statements earlier. >> I'm not sure what that shows, except that you haven't grokked this yet. >> >> >>>>> From your post, the scope guard technique is used "to ensure some >>>>> desired cleanup at the end of a scope, even when the scope is exited >>>>> via an exception." This is precisely what the try: finally: syntax is >>>>> for. >>>> >>>> You'd have to nest it. That's ugly. And more importantly, now two >>>> people >>>> in this thread (namely you and Mike) have demonstrated that they do not >>>> grok the try functionality and manage to write incorrect code, even >>>> arguing that it's correct when informed that it's not, so it's a pretty >>>> fragile construct, like goto. >>> >>> Uh-huh. >> >> Yeah. Consider that you're now for the third time failing to grasp the >> concept of cleanup for a successful operation. > > Oh, I do. But if I didn't want it to run on an exception, I'd just write > the code without any try:s or with:s at all. > > # blah blah #1 > chdir( somewhere ) > # blah blah #2 > chdir( original_dir ) Yes, but what's that got to do with anything? >>>>> The with statement allows you to encapsulate repetitive boilerplate >>>>> into context managers, but a general purpose context manager like your >>>>> Cleanup class doesn't take advantage of this. >>>> >>>> I'm sorry but that's pretty meaningless. It's like: "A house allows you >>>> to encapsulate a lot of stinking garbage, but your house doesn't take >>>> advantage of that, it's disgustingly clean". Hello. >>> >>> No, I'm saying that your Cleanup class is about as ugly as the try: >>> finally:. It just shifts the ugliness around. There is a way to use >>> the with statement to make things look better and more readable in >>> certain situations, namely where there is some boilerplate that you >>> would otherwise repeat in many places using try: finally:. You can >>> encapsulate that repetitive code into a class or a @contextmanager >>> generator and just call the contextmanager. A generic context manager >>> where you register callables doesn't replace any boilerplate. You >>> still repeat all of the cleanup code everywhere. What's more, because >>> you have to shove everything into a callable, you have significantly >>> less flexibility than the try: finally:. >> >> Sorry, but that's meaningless again. You're repeating that my house has >> no garbage in it. > > No, I'm repeatedly saying that I think your solution stinks. I think > it's ugly. I think it's restrictive. I think it does not improve on the > available solutions. First you'd have to understand it, simple as it is. >> And you complain that it would be work to add garbage >> to it. Why do you want that garbage? I think it's nice without it! > > And you are entitled to that opinion. I am giving you mine. Well, I'm sorry, but while you are entitled to an opinion it's not an opinion that carries any weight: first you need to get your facts and claims straight. So far only this latest posting of yours has been free of directly incorrect statements. But you still have a lot of statements that just show total incomprehension, like your example of achieving no cleanup in the case of an exception. Cheers & hth., - Alf From darcy at druid.net Wed Mar 3 16:37:16 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 16:37:16 -0500 Subject: DOS Follies (Was: Docstrings...) In-Reply-To: References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: <20100303163716.d54a6e5d.darcy@druid.net> On Wed, 03 Mar 2010 20:44:08 +0100 mk wrote: > It reminds me of why Windows uses backslashes for path separation > instead of slashes: what I've *heard*, and do not know if it's true, > it's because Gates fancied using / for options switch instead of -, and > to hell with established practice. That was because CP/M used slashes for options and DOS copied that. By the time hierarchy was added it was too late to change. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From e_d_k at yahoo.com Wed Mar 3 16:43:13 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 3 Mar 2010 13:43:13 -0800 (PST) Subject: Docstrings considered too complicated In-Reply-To: <4eb0089f1003031154j78cc7d22kf18ae339fe8c686@mail.gmail.com> Message-ID: <720139.74191.qm@web58902.mail.re1.yahoo.com> --- On Wed, 3/3/10, David Robinow wrote: > From: David Robinow > Subject: Re: Docstrings considered too complicated > To: python-list at python.org > Date: Wednesday, March 3, 2010, 2:54 PM > On Wed, Mar 3, 2010 at 1:01 PM, Ed > Keith > wrote: > > --- On Wed, 3/3/10, D'Arcy J.M. Cain ?wrote: > > > >> They needed a way to tell where the end of the > information > >> was.? Why > >> they used ^Z (SUB - Substitute) instead of ^C (ETX > - End of > >> TeXt) or > >> even ^D (EOT - End Of Transmission) is anyone's > guess. > > > > That has always puzzled me to. ETX and EOT were well > established, why no use one of them? I'd love to know what > they were thinking. > > There were numerous incompatible and primitive transfer > protocols in > those days. They probably wanted to pick something that was > NOT well > established so it would pass through without, for example, > causing End > Of Transmission. That makes a lot of sense. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From python at mrabarnett.plus.com Wed Mar 3 16:45:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 21:45:46 +0000 Subject: Old farts playing with their toys In-Reply-To: <20100303162929.560a17d3.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> <4B8EABCB.6050303@mrabarnett.plus.com> <20100303162929.560a17d3.darcy@druid.net> Message-ID: <4B8ED88A.60502@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Wed, 03 Mar 2010 18:34:51 +0000 > MRAB wrote: >> But I was still able to play Nim and Duck Shoot (after keying it in)! > > Did you ever play Star Trek with sound effects? I was never able to > get it to work but supposedly if you put an AM radio tuned to a > specific frequency near the side with the I/O card it would generate > static that was supposed to be the sound of explosions. > > Of course, the explosions were happening in a vaccum so maybe the > silence was accurate. :-) > A computer with sound? Heresy! :-) There was some hardware that could be added to provide some sort of video output, IIRC. Aha, here it is: http://en.wikipedia.org/wiki/MK14 and also here: http://www.nvg.ntnu.no/sinclair/computers/mk14/mk14_photos.htm The top-left picture looks like it has all its chips, so is the fully-expanded version. Oh, I forgot about the red reset button! From bdesth.quelquechose at free.quelquepart.fr Wed Mar 3 16:46:08 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 22:46:08 +0100 Subject: memory usage, temporary and otherwise In-Reply-To: References: Message-ID: <4b8ee61a$0$26644$426a74cc@news.free.fr> mk a ?crit : > > Obviously, don't try this on low-memory machine: > >>>> a={} >>>> for i in range(10000000): Note that in Python 2, this will build a list of 10000000 int objects. You may want to use xrange instead... > ... a[i]='spam'*10 > ... >>>> import sys >>>> sys.getsizeof(a) > 201326728 >>>> id(a[1]) > 3085643936L >>>> id(a[100]) > 3085713568L > >>>> ids={} >>>> for i in range(len(a)): And this build yet another list of 10000000 int objects. > ... ids[id(a[i])]=True > ... >>>> len(ids.keys()) > 10000000 > > Hm, apparently Python didn't spot that 'spam'*10 in a's values is really > the same string, right? Seems not. FWIW, Python does some caching on some values of some immutable types (small ints, some strings etc), but this is implementation dependant so you shouldn't rely on it. > So sys.getsizeof returns some 200MB for this dictionary. But according > to top RSS of the python process is 300MB. ps auxw says the same thing > (more or less). > > Why the 50% overhead? (and I would swear that a couple of times RSS > according to top grew to 800MB). (overly simplified) When an object is garbage-collected, the memory is not necessarily "returned" to the system - and the system doesn't necessarily claim it back neither until it _really_ needs it. This avoid a _lot_ of possibly useless work for both the python interpreter (keeping already allocated memory costs less than immediatly returning it, just to try and allocate some more memory a couple instructions later) and the system (ditto - FWIW, how linux handles memory allocations is somewhat funny, if you ever programmed in C). HTH From mrkafk at gmail.com Wed Mar 3 16:46:53 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:46:53 +0100 Subject: Sort Big File Help In-Reply-To: References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: John, there's an error in my program, I forgot that list.sort() method doesn't return the list (it sorts in place). So it should look like: #!/usr/bin/python def sortit(fname): fo = open(fname) linedict = {} for line in fo: key = line[:3] linedict[key] = line sortedlines = [] keys = linedict.keys() keys.sort() for key in keys: sortedlines.append(linedict[key]) return sortedlines if __name__ == '__main__': sortit('testfile.txt') MRAB's solution is obviously better, provided you know about Python's lambda. Regards, mk From bdesth.quelquechose at free.quelquepart.fr Wed Mar 3 16:47:55 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 22:47:55 +0100 Subject: memory usage, temporary and otherwise In-Reply-To: <4b8ee61a$0$26644$426a74cc@news.free.fr> References: <4b8ee61a$0$26644$426a74cc@news.free.fr> Message-ID: <4b8ee685$0$26644$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > mk a ?crit : (snip) >> So sys.getsizeof returns some 200MB for this dictionary. But according >> to top RSS of the python process is 300MB. ps auxw says the same thing >> (more or less). >> >> Why the 50% overhead? Oh, and yes - the interpreter itself, the builtins, and all imported modules also eat some space... (snip) From mrkafk at gmail.com Wed Mar 3 16:52:35 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:52:35 +0100 Subject: Sort Big File Help In-Reply-To: <4B8EBF9A.6080603@mrabarnett.plus.com> References: <374400.23537.qm@web33805.mail.mud.yahoo.com> <4B8EBF9A.6080603@mrabarnett.plus.com> Message-ID: MRAB wrote: > [snip] > Simpler would be: > > lines = f.readlines() > lines.sort(key=lambda line: line[ : 3]) > > or even: > > lines = sorted(f.readlines(), key=lambda line: line[ : 3])) Sure, but a complete newbie (I have this impression about OP) doesn't have to know about lambda. I expected my solution to be slower, but it's not (on a file with 100,000 random string lines): # time ./sort1.py real 0m0.386s user 0m0.372s sys 0m0.014s # time ./sort2.py real 0m0.303s user 0m0.286s sys 0m0.017s sort1.py: #!/usr/bin/python def sortit(fname): lines = open(fname).readlines() lines.sort(key = lambda x: x[:3]) if __name__ == '__main__': sortit('testfile.txt') sort2.py: #!/usr/bin/python def sortit(fname): fo = open(fname) linedict = {} for line in fo: key = line[:3] linedict[key] = line sortedlines = [] keys = linedict.keys() keys.sort() for key in keys: sortedlines.append(linedict[key]) return sortedlines if __name__ == '__main__': sortit('testfile.txt') Any idea why? After all, I'm "manually" doing quite a lot: allocating key in a dict, then sorting dict's keys, then iterating over keys and accessing dict value. Regards, mk From toby at telegraphics.com.au Wed Mar 3 16:55:58 2010 From: toby at telegraphics.com.au (toby) Date: Wed, 3 Mar 2010 13:55:58 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> On Mar 3, 3:54?pm, ccc31807 wrote: > On Mar 3, 12:36?pm, Xah Lee wrote: > > > recently i wrote a blog article on The NoSQL Movement > > athttp://xahlee.org/comp/nosql.html > > > i'd like to post it somewhere public to solicit opinions, but in the > > 20 min or so, i couldn't find a proper newsgroup, nor private list > > that my somewhat anti-NoSQL Movement article is fitting. > > I only read the first two paragraphs of your article, so I can't > respond to it. > > I've halfway followed the NoSQL movement. My day job is a database > manager and I so SQL databases for a living, as well as Perl. I see a > lot of abuse of relational databases in the Real World, as well as a > lot of abuse for non-SQL alternatives, e.g., (mis)using Excel for a > database. The big, enterprise database we have at work is built on IBM > UniQuery, which is a non-SQL flat file database product, so I've had a > lot of experience with big non-SQL database work. > > I've also developed a marked preference for plain text databases. For > a lot of applications they are simpler, easier, and better. I've also > had some experience with XML databases, and find that they are ideal > for applications with 'ragged' data. > > As with anything else, you need to match the tool to the job. Yes, I > feel that relational database technology has been much used, and much > abused. However, one of my favorite applications is Postgres, and I > think it's absolutely unbeatable It is beatable outside of its sweetspot, like any system. NoSQL is not so much about "beating" relational databases, as simply a blanket term for useful non-relational technologies. There's not much point in reading Xah beyond the heading of his manifesto, as it is no more relevant to be "anti-NoSQL" as to be "anti-integers" because they don't store fractions. > where you have to store data and "relational data" > perform a large number of queries. Why does the number matter? > > Finally, with regard to Structured Query Language itself, I find that > it's well suited to its purpose. I hand write a lot of SQL statements > for various purposes, and while like any language you find it > exceedingly difficult to express concepts that you can think, it > mostly allows the expression of most of what you want to say. > > CC. From usenot at geekmail.INVALID Wed Mar 3 16:58:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 3 Mar 2010 22:58:40 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: <20100303225840.21bd3108@geekmail.INVALID> On Wed, 03 Mar 2010 22:19:04 +0100 mk wrote: > For the uncouth yobs, err, culturally-challenged: > > http://www.youtube.com/watch?v=Xe1a1wHxTyo > > (Four Yorkshiremen) > http://www.youtube.com/watch?v=-eDaSvRO9xA That's the definitive version. I mean, if you're going to talk vintage, talk vintage. /W -- INVALID? DE! From vinay_sajip at yahoo.co.uk Wed Mar 3 16:59:25 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 3 Mar 2010 13:59:25 -0800 (PST) Subject: Version 0.3.8 of the Python config module has been released. Message-ID: <9cc4c234-2c60-4f4e-b059-d8448ea8b8b4@d27g2000yqf.googlegroups.com> Version 0.3.8 of the Python config module has been released. What Does It Do? ================ The config module allows you to implement a hierarchical configuration scheme with support for mappings and sequences, cross-references between one part of the configuration and another, the ability to flexibly access real Python objects, facilities for configurations to include and cross-reference one another, simple expression evaluation and the ability to change, save, cascade and merge configurations. You can easily integrate with command line options using optparse. This module has been developed on python 2.3 but should work on version 2.2 or greater. A test suite using unittest is included in the distribution. A very simple configuration file (simple.cfg): # starts here message: Hello, world! #ends here a very simple program to use it: from config import Config cfg = Config(file('simple.cfg')) print cfg.message results in: Hello, world! Configuration files are key-value pairs, but the values can be containers that contain further values. A simple example - with the example configuration file: messages: [ { stream : `sys.stderr` message: 'Welcome' name: 'Harry' } { stream : `sys.stdout` message: 'Welkom' name: 'Ruud' } { stream : $messages[0].stream message: 'Bienvenue' name: Yves } ] a program to read the configuration would be: from config import Config f = file('simple.cfg') cfg = Config(f) for m in cfg.messages: s = '%s, %s' % (m.message, m.name) try: print >> m.stream, s except IOError, e: print e which, when run, would yield the console output: Welcome, Harry Welkom, Ruud Bienvenue, Yves The above example just scratches the surface. There's more information about this module available at http://www.red-dove.com/config-doc/ Comprehensive API documentation is available at http://www.red-dove.com/config/index.html As always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. Changes since the last release posted on comp.lang.python[.announce]: ===================================================== Fixed parsing bug which caused failure for negative numbers in sequences. Improved resolution logic. From jgardner at jonathangardner.net Wed Mar 3 17:16:24 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:16:24 -0800 Subject: Sort Big File Help In-Reply-To: <374400.23537.qm@web33805.mail.mud.yahoo.com> References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: <6cc20cea1003031416l2a16a5fdl2199aa379982983e@mail.gmail.com> On Wed, Mar 3, 2010 at 8:19 AM, John Filben wrote: > I am new to Python but have used many other (mostly dead) languages in the > past.? I want to be able to process *.txt and *.csv files.? I can now read > that and then change them as needed ? mostly just take a column and do some > if-then to create a new variable.? My problem is sorting these files: > > 1.)??? How do I sort file1.txt by position and write out file1_sorted.txt; > for example, if all the records are 100 bytes long and there is a three > digit id in the position 0-2; here would be some sample data: > > a.?????? 001JohnFilben?? > > b.????? 002Joe? Smith?.. > > 2.)??? How do I sort file1.csv by column name; for example, if all the > records have three column headings, ?id?, ?first_name?, ?last_name?; ?here > would be some sample data: > > a.?????? Id, first_name,last_name > > b.????? 001,John,Filben > > c.?????? 002,Joe, Smith > > 3.)??? What about if I have millions of records and I am processing on a > laptop with a large external drive ? basically, are there space > considerations? What are the work arounds. > > Any help would be appreciated. Thank you. > You may also want to look at the GNU tools "sort" and "cut". If your job is to process files, I'd recommend tools designed to process files for the task. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Wed Mar 3 17:17:24 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:17:24 -0800 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> On Wed, Mar 3, 2010 at 1:00 PM, Terry Reedy wrote: > > People who are familiar with and like CPAN are free to help improve PyPI. > Those of us not familiar with it may not know what we are missing, or have > little idea about what works with CPAN. > CPAN also covers up some deficiencies in Perl that Python doesn't suffer from. I am sure we could do well not to replicate those features. Regardless, Python's packages are distributed in a number of ways. PyPI is only one of them. Fedora and Ubuntu are two other ways. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Wed Mar 3 17:18:00 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:18:00 -0800 Subject: Generic singleton In-Reply-To: References: Message-ID: <6cc20cea1003031418w5ad6f59ah91562243a2cc4afb@mail.gmail.com> On Wed, Mar 3, 2010 at 1:11 PM, mk wrote: > > Or I could make my life simpler and use global variable. :-) > Ding ding ding! 90% of Design Patterns is making Java suck less. Other languages don't necessarily suffer from Java's design flaws. -- Jonathan Gardner jgardner at jonathangardner.net From ben+python at benfinney.id.au Wed Mar 3 17:21:32 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 09:21:32 +1100 Subject: There should be one-- and preferably only one --obvious way to do it References: <4b8e621b@dnews.tpgi.com.au> Message-ID: <87iq9dujv7.fsf@benfinney.id.au> Lie Ryan writes: > There are lots of reason why bare-except is bad, one being is that it > makes it way too easy to ignore errors that you don't actually want to > silence; and given that bare-excepts would prevent Ctrl+C (Interrupt) > from working. Sorry, but IMHO we shouldn't make syntax sugar for bad > practices. Right. Another way I've seen this expressed is ?It should be easy to do the right thing, and awkward to do the wrong thing?. -- \ ?Everyone is entitled to their own opinions, but they are not | `\ entitled to their own facts.? ?US Senator Pat Moynihan | _o__) | Ben Finney From jgardner at jonathangardner.net Wed Mar 3 17:23:25 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:23:25 -0800 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <6cc20cea1003031423v4410119dh767610e78ba3eb6e@mail.gmail.com> On Wed, Mar 3, 2010 at 12:54 PM, ccc31807 wrote: > > As with anything else, you need to match the tool to the job. Yes, I > feel that relational database technology has been much used, and much > abused. However, one of my favorite applications is Postgres, and I > think it's absolutely unbeatable where you have to store data and > perform a large number of queries. > Let me elaborate on this point for those who haven't experienced this for themselves. When you are starting a new project and you don't have a definitive picture of what the data is going to look like or how it is going to be queried, SQL databases (like PostgreSQL) will help you quickly formalize and understand what your data needs to do. In this role, these databases are invaluable. I can see no comparable tool in the wild, especially not OODBMS. As you grow in scale, you may eventually reach a point where the database can't keep up with you. Either you need to partition the data across machines or you need more specialized and optimized query plans. When you reach that point, there are a number of options that don't include an SQL database. I would expect your project to move those parts of the data away from an SQL database and towards a more specific solution. I see it as a sign of maturity with sufficiently scaled software that they no longer use an SQL database to manage their data. At some point in the project's lifetime, the data is understood well enough that the general nature of the SQL database is unnecessary. -- Jonathan Gardner jgardner at jonathangardner.net From ben+python at benfinney.id.au Wed Mar 3 17:30:35 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 09:30:35 +1100 Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: <87eik1ujg4.fsf@benfinney.id.au> Terry Reedy writes: > On 3/3/2010 12:05 PM, John Nagle wrote: > > CPAN is a repository. PyPi is an collection of links. > > As Ben said, PyPI currently is also a respository and not just links > to other repositories. It's a repository with holes. Just because a package is registered is no indication that the package is available from PyPI. > > CPAN has over 260 mirrors. PyPi has none. > > A mirroring system has been or is being set up with at least a couple > of mirrors for things that are hosted at PyPI. And that caveat is a big problem. Since PyPI allows registration of packages that are not themselves hosted at PyPI (often because their license terms are too restrictive for PyPI to redistribute the work), the mirror system will miss them. So there will be package-shaped holes in the PyPI mirror, meaning that even well-specified dependencies and a reliable mirror network will not be enough to make dependencies reliably satisfiable. > > CPAN enforces standard organization on packages. PyPi does not. This is, I think, something we don't need as much in Python; there is a fundamental difference between Perl's deeply nested namespace hierarchy and Python's inherently flat hierarchy. > > CPAN has quality control, with testers and a test reporting system. > > PyPi does not. > > People who are familiar with and like CPAN are free to help improve > PyPI. Those of us not familiar with it may not know what we are > missing, or have little idea about what works with CPAN. An important first step would be to reject from PyPI any package that isn't available for automated testing on the servers. That requires, AFAICT, rejecting any package without the source package uploaded. -- \ ?Oh, I realize it's a penny here and a penny there, but look at | `\ me: I've worked myself up from nothing to a state of extreme | _o__) poverty.? ?Groucho Marx | Ben Finney From ben+python at benfinney.id.au Wed Mar 3 17:32:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 09:32:21 +1100 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> <877hpt46yw.fsf@castleamber.com> Message-ID: <87aaupujd6.fsf@benfinney.id.au> John Bokma writes: > I want to remove something that I installed [with its Distutils build > system] (because it's installation procedure seems to be broken; > opensocial) I understand that this can't be blamed on pip, but it's > odd that in this century it's still hard to install/uninstall modules > :-( That's because of the last-century legacy of Distutils's design. -- \ ?Imagine a world without hypothetical situations.? ?anonymous | `\ | _o__) | Ben Finney From peter at www.pjb.com.au Wed Mar 3 17:37:02 2010 From: peter at www.pjb.com.au (Peter Billam) Date: 03 Mar 2010 22:37:02 GMT Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: On 2010-03-03, John Nagle wrote: > Ben Finney wrote: >> Olof Bjarnason writes: >>> The "Where is CPAN for Python?" question keeps popping up, with >>> answers ranging from "There is no CPAN for Python" and "We already >>> have CPAN for Python" (confusing). >> >> Caused in no small measure by the fact that Perl people mean at >> least two distinct things by ?Where is CPAN for Python??: >> * The central package registry, CPAN, with metadata in a standard >> queryable format, and all registered packages redundantly mirrored >> and available for installation at user-specified versions. >> We have an equivalent in PyPI, though it's incomplete since >> many *registered* packages are not actually hosted *at* PyPI. > > CPAN is a repository. PyPi is an collection of links. > CPAN has over 260 mirrors. PyPi has none. > CPAN enforces standard organization on packages. PyPi does not. > CPAN has quality control, with testers and a test reporting system. > PyPi does not. One important thing that CPAN does _not_ have is a formalised "I put this module up for adoption" mechanism. Debian has one, for example. It's necessary, because not having one leads to many (in the long run, all) modules becoming unmaintained and abandoned, even though they worked perfectly well and were very useful to people... It would also be nice to be able to get module download stats. A very important thing about CPAN modules is the consistent basic install method: perl Makefile.PL ; make ; make install I'm not sure if the Perl code that runs CPAN is free software... (?) Regards, (CPAN author) Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From philip at semanchuk.com Wed Mar 3 17:40:36 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 17:40:36 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> Message-ID: <0C9B223A-D32A-474C-80E3-7F912447170F@semanchuk.com> On Mar 3, 2010, at 3:58 PM, mk wrote: > Philip Semanchuk wrote: >>> So there *may* be some evidence that joins are indeed bad in >>> practice. If someone has smth specific/interesting on the subject, >>> please post. >> It's an unprovable assertion, or a meaningless one depending on how >> one defines the terms. You could also say "there *may* be some >> evidence that Python lists are bad in practice". Python lists and >> SQL JOINs are like any part of a language or toolkit. They're good >> tools for solving certain classes of problems. They can also be >> misapplied to problems that they're not so good at. Sometimes >> they're a performance bottleneck, even when solving the problems >> for which they're best. Sometimes the best way to solve a >> performance bottleneck is to redesign your app/system so you don't >> need to solve that kind of problem anymore (hence the join-less >> databases). Other times, the cure is worse than the disease and >> you're better off throwing hardware at the problem. > > Look, I completely agree with what you're saying, but: that doesn't > change the possibility that joins may be expensive in comparison to > other SQL operations. This is the phrase I should have used perhaps; > 'expensive in comparison with other SQL operations' instead of 'bad'. Well OK, but that's a very different argument. Yes, joins can be expensive. They're often still the best option, though. The first step people usually take to get away from joins is denormalization which can improve SELECT performance at the expense of slowing down INSERTs, UPDATEs, and DELETEs, not to mention complicating one's code and data model. Is that a worthwhile trade? Depends on the application. As I said, sometimes the cure is worse than the disease. Don't worry about joins until you know they're a problem. As Knuth said, premature optimization is the root of all evil. Good luck Philip PS - Looks like you're using Postgres -- excellent choice. I miss using it. From me at privacy.net Wed Mar 3 17:41:37 2010 From: me at privacy.net (Avid Fan) Date: Wed, 03 Mar 2010 22:41:37 GMT Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: Jonathan Gardner wrote: > > I see it as a sign of maturity with sufficiently scaled software that > they no longer use an SQL database to manage their data. At some point > in the project's lifetime, the data is understood well enough that the > general nature of the SQL database is unnecessary. > I am really struggling to understand this concept. Is it the normalised table structure that is in question or the query language? Could you give some sort of example of where SQL would not be the way to go. The only things I can think of a simple flat file databases. From drobinow at gmail.com Wed Mar 3 18:16:47 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 3 Mar 2010 18:16:47 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: <4eb0089f1003031516u473ce06ejb705feb85ece66a7@mail.gmail.com> On Wed, Mar 3, 2010 at 3:02 PM, Grant Edwards wrote: > On 2010-03-03, mk wrote: > >>> That has always puzzled me to. ETX and EOT were well established, why >>> no use one of them? I'd love to know what they were thinking. >> >> Probably nothing: what many people do with confronted with a problem. >> >> It reminds me of why Windows uses backslashes for path separation >> instead of slashes: what I've *heard*, and do not know if it's true, >> it's because Gates fancied using / for options switch instead of -, >> and to hell with established practice. > > Using / for the option switch _was_ the established practice (if you > came from a DEC background the way that CP/M and DOS did). Quite true. And the early DEC systems predated Unix (although not by much) From jml at mumak.net Wed Mar 3 18:25:36 2010 From: jml at mumak.net (Jonathan Lange) Date: Wed, 3 Mar 2010 23:25:36 +0000 Subject: Twisted 10.0.0 released Message-ID: On behalf of Twisted Matrix Laboratories, I am honored to announce the release of Twisted 10.0. Highlights include: * Improved documentation, including "Twisted Web in 60 seconds" * Faster Perspective Broker applications * A new Windows installer that ships without zope.interface * Twisted no longer supports Python 2.3 * Over one hundred closed tickets For more information, see the NEWS file. It's stable, backwards compatible, well tested and in every way an improvement. Download it now from: http://tmrc.mit.edu/mirror/twisted/Twisted/10.0/Twisted-10.0.0.tar.bz2 or http://tmrc.mit.edu/mirror/twisted/Twisted/10.0/Twisted-10.0.0.win32-py2.5.msi Many thanks to Jean-Paul Calderone and Chris Armstrong, whose work on release automation tools and answers to numerous questions made this possible. Thanks also to the supporters of the Twisted Software Foundation and to the many contributors for this release. jml From robert.kern at gmail.com Wed Mar 3 18:28:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 17:28:35 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>>> * Robert Kern: >>>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>>> * Mike Kent: >>>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>>> >>>>>>> if you thought about it you would mean a simple "try/else". >>>>>>> "finally" is >>>>>>> always executed. which is incorrect for cleanup >>>>>> >>>>>> Eh? Failed execution doesn't require cleanup? The example you gave is >>>>>> definitely equivalent to the try: finally: that Mike posted. >>>>> >>>>> Sorry, that's incorrect: it's not. >>>>> >>>>> With correct code (mine) cleanup for action A is only performed when >>>>> action A succeeds. >>>>> >>>>> With incorrect code cleanup for action A is performed when A fails. >>>> >>>> Oh? >>>> >>>> $ cat cleanup.py >>>> >>>> class Cleanup: >>>> def __init__( self ): >>>> self._actions = [] >>>> >>>> def call( self, action ): >>>> assert( callable( action ) ) >>>> self._actions.append( action ) >>>> >>>> def __enter__( self ): >>>> return self >>>> >>>> def __exit__( self, x_type, x_value, x_traceback ): >>>> while( len( self._actions ) != 0 ): >>>> try: >>>> self._actions.pop()() >>>> except BaseException as x: >>>> raise AssertionError( "Cleanup: exception during cleanup" ) >>>> >>>> def print_(x): >>>> print x >>>> >>>> with Cleanup() as at_cleanup: >>>> at_cleanup.call(lambda: print_("Cleanup executed without an >>>> exception.")) >>>> >>>> with Cleanup() as at_cleanup: >>> >>> *Here* is where you should >>> >>> 1) Perform the action for which cleanup is needed. >>> >>> 2) Let it fail by raising an exception. >>> >>> >>>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>>> raise RuntimeError() >>> >>> With an exception raised here cleanup should of course be performed. >>> >>> And just in case you didn't notice: the above is not a test of the >>> example I gave. >>> >>> >>>> $ python cleanup.py >>>> Cleanup executed without an exception. >>>> Cleanup execute with an exception. >>>> Traceback (most recent call last): >>>> File "cleanup.py", line 28, in >>>> raise RuntimeError() >>>> RuntimeError >>>> >>>>>> The actions are always executed in your example, >>>>> >>>>> Sorry, that's incorrect. >>>> >>>> Looks like it to me. >>> >>> I'm sorry, but you're >>> >>> 1) not testing my example which you're claiming that you're testing, and >> >> Then I would appreciate your writing a complete, runnable example that >> demonstrates the feature you are claiming. Because it's apparently not >> "ensur[ing] some desired cleanup at the end of a scope, even when the >> scope is exited via an exception" that you talked about in your >> original post. >> >> Your sketch of an example looks like mine: >> >> with Cleanup as at_cleanup: >> # blah blah >> chdir( somewhere ) >> at_cleanup.call( lambda: chdir( original_dir ) ) >> # blah blah >> >> The cleanup function gets registered immediately after the first >> chdir() and before the second "blah blah". Even if an exception is >> raised in the second "blah blah", then the cleanup function will still >> run. This would be equivalent to a try: finally: >> >> # blah blah #1 >> chdir( somewhere ) >> try: >> # blah blah #2 >> finally: >> chdir( original_dir ) > > Yes, this is equivalent code. > > The try-finally that you earlier claimed was equivalent, was not. Okay, but just because of the position of the chdir(), right? >> and not a try: else: >> >> # blah blah #1 >> chdir( somewhere ) >> try: >> # blah blah #2 >> else: >> chdir( original_dir ) > > This example is however meaningless except as misdirection. There are > infinitely many constructs that include try-finally and try-else, that > the with-Cleanup code is not equivalent to. It's dumb to show one such. > > Exactly what are you trying to prove here? I'm just showing you what I thought you meant when you told Mike that he should have used a try/else instead of try/finally. > Your earlier claims are still incorrect. > >> Now, I assumed that the behavior with respect to exceptions occurring >> in the first "blah blah" weren't what you were talking about because >> until the chdir(), there is nothing to clean up. >> >> There is no way that the example you gave translates to a try: else: >> as you claimed in your response to Mike Kent. > > Of course there is. > > Note that Mike wrapped the action A within the 'try': > > > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup > > > > The 'finally' he used, shown above, yields incorrect behavior. > > Namely cleanup always, while 'else', in that code, can yield correct > behavior /provided/ that it's coded correctly: > > > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > except Whatever: > # whatever, e.g. logging > raise > else: > try: > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup > Ah, okay. Now we're getting somewhere. Now, please note that you did not have any except: handling in your original example. So Mike made a try: finally: example to attempt to match the semantics of your code. When you tell him that he should 'mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup', can you understand why we might think that you were saying that try: finally: was wrong and that you were proposing that your code was equivalent to some try: except: else: suite? >>> 2) not even showing anything about your earlier statements, which were >>> just incorrect. >>> >>> You're instead showing that my code works as it should for the case that >>> you're testing, which is a bit unnecessary since I knew that, but thanks >>> anyway. >> >> It's the case you seem to be talking about in your original post. > > What's this "seems"? Are you unable to read that very short post? I say "seems" because my understandings of what you meant in your original post and your response to Mike disagreed with one another. Now I see that your later posts were talking about minor discrepancy about which errors you wanted caught by the finally: and which you didn't. I was confused because it seemed that you were saying that try: finally: was completely wrong and that "try/else" was right. It confused me and at least one other person. >> , but I do ask you to acknowledge that you originally were talking >> about a feature that "ensure[s] some desired cleanup at the end of a >> scope, even when the scope is exited via an exception." > > Yes, that's what it does. > > Which is I why I wrote that. > > This should not be hard to grok. > > >> Do you acknowledge this? > > This seems like pure noise, to cover up that you were sputing a lot of > incorrect statements earlier. No, I'm just trying to clarify what you are trying to say. The above statement did not appear to accord with your later statement: 'if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup.' It turns out that what you really meant was that it would be incorrect for cleanup to be executed when an error occurred in the chdir() itself. Now, I happen to disagree with that. There are a couple of ways to do this kind of cleanup depending on the situation. Basically, you have several different code blocks: # 1. Record original state. # 2. Modify state. # 3. Do stuff requiring the modified state. # 4. Revert to the original state. Depending on where errors are expected to occur, and how the state needs to get modified and restored, there are different ways of arranging these blocks. The one Mike showed: # 1. Record original state. try: # 2. Modify state. # 3. Do stuff requiring the modified state. finally: # 4. Revert to the original state. And the one you prefer: # 1. Record original state. # 2. Modify state. try: # 3. Do stuff requiring the modified state. finally: # 4. Revert to the original state. These differ in what happens when an error occurs in block #2, the modification of the state. In Mike's, the cleanup code runs; in yours, it doesn't. For chdir(), it really doesn't matter. Reverting to the original state is harmless whether the original chdir() succeeds or fails, and chdir() is essentially atomic so if it raises an exception, the state did not change and nothing needs to be cleaned up. However, not all block #2s are atomic. Some are going to fail partway through and need to be cleaned up even though they raised an exception. Fortunately, cleanup can frequently be written to not care whether the whole thing finished or not. Both formulations can be correct (and both work perfectly fine with the chdir() example being used). Sometimes one is better than the other, and sometimes not. You can achieve both ways with either your Cleanup class or with try: finally:. I am still of the opinion that Cleanup is not an improvement over try: finally: and has the significant ugliness of forcing cleanup code into callables. This significantly limits what you can do in your cleanup code. -- 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 From eike.welk at gmx.net Wed Mar 3 18:33:29 2010 From: eike.welk at gmx.net (Eike Welk) Date: Thu, 04 Mar 2010 00:33:29 +0100 Subject: Method / Functions - What are the differences? References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > John Posner a ?crit : >> Done -- see http://wiki.python.org/moin/FromFunctionToMethod > > Done and well done !-) > Thanks again for the good job John. I like it too, thanks to both of you! I have two small ideas for improvement: - Swap the first two paragraphs. First say what it is, and then give the motivation. - The section about the descriptor protocol is a bit difficult to understand. But judging from the official descriptor documentation, it seems to be hard to explain: The official documentation is nearly incomprehensible (IMHO). From philip at semanchuk.com Wed Mar 3 18:43:30 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 18:43:30 -0500 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> Message-ID: <882E7C2F-08E5-491A-A74C-572E37F333D1@semanchuk.com> On Mar 3, 2010, at 5:17 PM, Jonathan Gardner wrote: > On Wed, Mar 3, 2010 at 1:00 PM, Terry Reedy wrote: >> >> People who are familiar with and like CPAN are free to help improve >> PyPI. >> Those of us not familiar with it may not know what we are missing, >> or have >> little idea about what works with CPAN. >> > > > CPAN also covers up some deficiencies in Perl that Python doesn't > suffer from. I am sure we could do well not to replicate those > features. > > Regardless, Python's packages are distributed in a number of ways. > PyPI is only one of them. Fedora and Ubuntu are two other ways. Do Fedora & Ubuntu's package managers offer modules that appear in CPAN? In other words, if I was a Perl user under Ubuntu would I use the pkg manager to add a Perl module, or CPAN, or would both work? Thanks Philip From thewellsoliver at gmail.com Wed Mar 3 18:45:51 2010 From: thewellsoliver at gmail.com (Wells) Date: Wed, 3 Mar 2010 15:45:51 -0800 (PST) Subject: Question about typing: ints/floats Message-ID: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> This seems sort of odd to me: >>> a = 1 >>> a += 1.202 >>> a 2.202 Indicates that 'a' was an int that was implicitly casted to a float. But: >>> a = 1 >>> b = 3 >>> a / b 0 This does not implicitly do the casting, it treats 'a' and 'b' as integers, and the result as well. Changing 'b' to 3.0 will yield a float as a result (0.33333333333333331) Is there some way to explain the consistency here? Does python implicitly change the casting when you add variables of a different numeric type? Anyway, just curiosity more than anything else. Thanks! From zeeshan.quireshi at gmail.com Wed Mar 3 18:50:19 2010 From: zeeshan.quireshi at gmail.com (Zeeshan Quireshi) Date: Wed, 3 Mar 2010 15:50:19 -0800 (PST) Subject: Passing FILE * types using ctypes Message-ID: Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass it a FILE *pointer, how do i open a file in Python and convert it to a FILE *pointer. Or do i have to call the C library using ctypes first, get the pointer and then pass it to my function. Also, is there any automated way to convert c struct and enum definitions to ctypes data types. Zeeshan From zeeshan.quireshi at gmail.com Wed Mar 3 18:53:27 2010 From: zeeshan.quireshi at gmail.com (Zeeshan Quireshi) Date: Wed, 3 Mar 2010 15:53:27 -0800 (PST) Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Mar 3, 6:45?pm, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Does python > implicitly change the casting when you add variables of a different > numeric type? > > Anyway, just ?curiosity more than anything else. Thanks! Python, like most other languages performs only integer division when both the operands are ints. So only if one of the types is a flot or you explicitly cast your expression to be a double, then the value will be a fraction. otherwise you will the quotient. From rhodri at wildebst.demon.co.uk Wed Mar 3 18:56:00 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 03 Mar 2010 23:56:00 -0000 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: On Wed, 03 Mar 2010 19:38:16 -0000, Steve Holden wrote: > mk wrote: >> D'Arcy J.M. Cain wrote: >> >>> Makes me want to go down to the basement and fire up the Altair. :-) >> >> Please don't, or else I fire up that univ Yugoslavian copy of VAX with >> Pascal compiler (where I wrote my first program) and I will start my >> first program of ping-pong. >> >> It was a few hundred lines but took 5 minutes to compile; "VAX" was >> theoretically multitasking, but when more than 3 people were trying to >> do smth on it simultaneously, it was basically seizing up. >> >> Regards, >> mk >> > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk > on a VAX 11/750. The only bitmapped display we had available was a Three > Rivers PERQ, connected by a 9600bps serial line. We left it running at > seven o'clock one evening, and by nine am the next day it had brought up > about two thirds of the initial VM loader screen ... > > You tell these young kids, and they just don't believe you! There's old, and then there's old. http://sms.cam.ac.uk/media/739532 is a film of EDSAC being programmed in 1951, with a commentary added by Maurice Wilkes in 1976. Maybe just a bit before my time (by a decade or so :-) -- Rhodri James *-* Wildebeeste Herder to the Masses From jjposner at optimum.net Wed Mar 3 18:56:07 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 18:56:07 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> Message-ID: <4B8EF717.3070701@optimum.net> On 3/3/2010 6:33 PM, Eike Welk wrote: > > I have two small ideas for improvement: > - Swap the first two paragraphs. First say what it is, and then give the > motivation. No problem -- since this is a Wiki, you can perform the swap yourself! (If you haven't done it in a day or so, I'll do the deed.) > - The section about the descriptor protocol is a bit difficult to > understand. But judging from the official descriptor documentation, it seems > to be hard to explain: The official documentation is nearly incomprehensible > (IMHO). I empathize -- it took me a while to grok descriptors. I was thinking today about "doing a Bruno", and producing similar pieces on: * properties created with the @property decorator * the descriptor protocol I'll try to produce something over the next couple of days. -John From jgardner at jonathangardner.net Wed Mar 3 19:10:14 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 16:10:14 -0800 Subject: PYTHONPATH and eggs In-Reply-To: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> References: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Message-ID: <6cc20cea1003031610i6f79fd4fndac249ba27ca44c6@mail.gmail.com> On Wed, Mar 3, 2010 at 2:14 AM, geoffbache wrote: > > I have a very simple problem that seems to have no simple solution. > > I have a module which is installed centrally and lives in a Python > egg. I have experimented with some minor changes to it and would like > to set my PYTHONPATH to pick up my local copy of it, but don't want to > have to figure out how to build my own version of the "egg" if > possible. > > Unfortunately, the location from PYTHONPATH ends up after the eggs in > sys.path so I can't persuade Python to import my version. The only way > I've found to fix it is to copy the main script and manually hack > sys.path at the start of it which isn't really very nice. I wonder if > there is any better way as I can't be the first person to want to do > this, surely? > > I've seen this issue has been discussed elsewhere and flagged as a > problem (e.g. > http://mail.python.org/pipermail/distutils-sig/2009-January/010755.html) > > but I've been unable to find any suggestions for workarounds or > indications whether this will be/has been fixed. > Sounds like you might need to use virtualenv to setup python environments that you can control. -- Jonathan Gardner jgardner at jonathangardner.net From rhodri at wildebst.demon.co.uk Wed Mar 3 19:11:26 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 04 Mar 2010 00:11:26 -0000 Subject: Interest check in some delicious syntactic sugar for "except:pass" References: Message-ID: On Wed, 03 Mar 2010 09:27:16 -0000, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > silence: > ........ block > -------------------------> > try: > ........block > except: > ........pass -100 This catches Control-C interrupts, sys.exit(), subtle typos in the code, and sundry other errors that actually you *did* want to know about. Silence isn't so much golden as pyritic. -- Rhodri James *-* Wildebeeste Herder to the Masses From mensanator at aol.com Wed Mar 3 19:27:50 2010 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Mar 2010 16:27:50 -0800 (PST) Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Mar 3, 5:45?pm, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Not in Python 3.1: Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> a = 1 >>> b = 3 >>> a/b 0.3333333333333333 > Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Yes, use Python 3.1. > Does python > implicitly change the casting when you add variables of a different > numeric type? Sometimes. Floats and ints are compatible. But this doesn't work: >>> '3' + 1 Traceback (most recent call last): File "", line 1, in '3' + 1 TypeError: Can't convert 'int' object to str implicitly > > Anyway, just ?curiosity more than anything else. Thanks! From alfps at start.no Wed Mar 3 19:49:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 01:49:45 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>>>> * Robert Kern: >>>>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>>>> * Mike Kent: >>>>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>>>> >>>>>>>> if you thought about it you would mean a simple "try/else". >>>>>>>> "finally" is >>>>>>>> always executed. which is incorrect for cleanup >>>>>>> >>>>>>> Eh? Failed execution doesn't require cleanup? The example you >>>>>>> gave is >>>>>>> definitely equivalent to the try: finally: that Mike posted. >>>>>> >>>>>> Sorry, that's incorrect: it's not. >>>>>> >>>>>> With correct code (mine) cleanup for action A is only performed when >>>>>> action A succeeds. >>>>>> >>>>>> With incorrect code cleanup for action A is performed when A fails. >>>>> >>>>> Oh? >>>>> >>>>> $ cat cleanup.py >>>>> >>>>> class Cleanup: >>>>> def __init__( self ): >>>>> self._actions = [] >>>>> >>>>> def call( self, action ): >>>>> assert( callable( action ) ) >>>>> self._actions.append( action ) >>>>> >>>>> def __enter__( self ): >>>>> return self >>>>> >>>>> def __exit__( self, x_type, x_value, x_traceback ): >>>>> while( len( self._actions ) != 0 ): >>>>> try: >>>>> self._actions.pop()() >>>>> except BaseException as x: >>>>> raise AssertionError( "Cleanup: exception during cleanup" ) >>>>> >>>>> def print_(x): >>>>> print x >>>>> >>>>> with Cleanup() as at_cleanup: >>>>> at_cleanup.call(lambda: print_("Cleanup executed without an >>>>> exception.")) >>>>> >>>>> with Cleanup() as at_cleanup: >>>> >>>> *Here* is where you should >>>> >>>> 1) Perform the action for which cleanup is needed. >>>> >>>> 2) Let it fail by raising an exception. >>>> >>>> >>>>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>>>> raise RuntimeError() >>>> >>>> With an exception raised here cleanup should of course be performed. >>>> >>>> And just in case you didn't notice: the above is not a test of the >>>> example I gave. >>>> >>>> >>>>> $ python cleanup.py >>>>> Cleanup executed without an exception. >>>>> Cleanup execute with an exception. >>>>> Traceback (most recent call last): >>>>> File "cleanup.py", line 28, in >>>>> raise RuntimeError() >>>>> RuntimeError >>>>> >>>>>>> The actions are always executed in your example, >>>>>> >>>>>> Sorry, that's incorrect. >>>>> >>>>> Looks like it to me. >>>> >>>> I'm sorry, but you're >>>> >>>> 1) not testing my example which you're claiming that you're testing, >>>> and >>> >>> Then I would appreciate your writing a complete, runnable example that >>> demonstrates the feature you are claiming. Because it's apparently not >>> "ensur[ing] some desired cleanup at the end of a scope, even when the >>> scope is exited via an exception" that you talked about in your >>> original post. >>> >>> Your sketch of an example looks like mine: >>> >>> with Cleanup as at_cleanup: >>> # blah blah >>> chdir( somewhere ) >>> at_cleanup.call( lambda: chdir( original_dir ) ) >>> # blah blah >>> >>> The cleanup function gets registered immediately after the first >>> chdir() and before the second "blah blah". Even if an exception is >>> raised in the second "blah blah", then the cleanup function will still >>> run. This would be equivalent to a try: finally: >>> >>> # blah blah #1 >>> chdir( somewhere ) >>> try: >>> # blah blah #2 >>> finally: >>> chdir( original_dir ) >> >> Yes, this is equivalent code. >> >> The try-finally that you earlier claimed was equivalent, was not. > > Okay, but just because of the position of the chdir(), right? Yes, since it yields different results. >>> and not a try: else: >>> >>> # blah blah #1 >>> chdir( somewhere ) >>> try: >>> # blah blah #2 >>> else: >>> chdir( original_dir ) >> >> This example is however meaningless except as misdirection. There are >> infinitely many constructs that include try-finally and try-else, that >> the with-Cleanup code is not equivalent to. It's dumb to show one such. >> >> Exactly what are you trying to prove here? > > I'm just showing you what I thought you meant when you told Mike that he > should have used a try/else instead of try/finally. > >> Your earlier claims are still incorrect. >> >>> Now, I assumed that the behavior with respect to exceptions occurring >>> in the first "blah blah" weren't what you were talking about because >>> until the chdir(), there is nothing to clean up. >>> >>> There is no way that the example you gave translates to a try: else: >>> as you claimed in your response to Mike Kent. >> >> Of course there is. >> >> Note that Mike wrapped the action A within the 'try': >> >> >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup >> >> >> >> The 'finally' he used, shown above, yields incorrect behavior. >> >> Namely cleanup always, while 'else', in that code, can yield correct >> behavior /provided/ that it's coded correctly: >> >> >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> except Whatever: >> # whatever, e.g. logging >> raise >> else: >> try: >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup >> > > Ah, okay. Now we're getting somewhere. Now, please note that you did not > have any except: handling in your original example. So Mike made a try: > finally: example to attempt to match the semantics of your code. When > you tell him that he should 'mean a simple "try/else". "finally" is > always executed. which is incorrect for cleanup', can you understand why > we might think that you were saying that try: finally: was wrong and > that you were proposing that your code was equivalent to some try: > except: else: suite? No, not really. His code didn't match the semantics. Changing 'finally' to 'else' could make it equivalent. >>>> 2) not even showing anything about your earlier statements, which were >>>> just incorrect. >>>> >>>> You're instead showing that my code works as it should for the case >>>> that >>>> you're testing, which is a bit unnecessary since I knew that, but >>>> thanks >>>> anyway. >>> >>> It's the case you seem to be talking about in your original post. >> >> What's this "seems"? Are you unable to read that very short post? > > I say "seems" because my understandings of what you meant in your > original post and your response to Mike disagreed with one another. Now > I see that your later posts were talking about minor discrepancy about > which errors you wanted caught by the finally: and which you didn't. It's absolutely not a minor discrepancy whether some code is executed or not. It can have arbitrarily large effect. And from my point of view the discussion of that snippet has not been about what errors I "want" caught by the 'finally'; it's been about whether two snippets of code yield the same effect or not: Mike's code was incorrect not because it did something else, but because as code that did something else it was not an equivalent to the code that I posted. > I > was confused because it seemed that you were saying that try: finally: > was completely wrong and that "try/else" was right. It confused me and > at least one other person. > >>> , but I do ask you to acknowledge that you originally were talking >>> about a feature that "ensure[s] some desired cleanup at the end of a >>> scope, even when the scope is exited via an exception." >> >> Yes, that's what it does. >> >> Which is I why I wrote that. >> >> This should not be hard to grok. >> >> >>> Do you acknowledge this? >> >> This seems like pure noise, to cover up that you were sputing a lot of >> incorrect statements earlier. > > No, I'm just trying to clarify what you are trying to say. The above > statement did not appear to accord with your later statement: 'if you > thought about it you would mean a simple "try/else". "finally" is always > executed. which is incorrect for cleanup.' It turns out that what you > really meant was that it would be incorrect for cleanup to be executed > when an error occurred in the chdir() itself. > > Now, I happen to disagree with that. Well, I was pretty unclear, almost hint-like, sorry about that, mea culpa, but you have it slightly wrong. You wrote then "The example you gave is definitely equivalent to the try: finally: that Mike posted." And it isn't. > There are a couple of ways to do > this kind of cleanup depending on the situation. Basically, you have > several different code blocks: > > # 1. Record original state. > # 2. Modify state. > # 3. Do stuff requiring the modified state. > # 4. Revert to the original state. > > Depending on where errors are expected to occur, and how the state needs > to get modified and restored, there are different ways of arranging > these blocks. The one Mike showed: > > # 1. Record original state. > try: > # 2. Modify state. > # 3. Do stuff requiring the modified state. > finally: > # 4. Revert to the original state. > > And the one you prefer: > > # 1. Record original state. > # 2. Modify state. > try: > # 3. Do stuff requiring the modified state. > finally: > # 4. Revert to the original state. > > These differ in what happens when an error occurs in block #2, the > modification of the state. In Mike's, the cleanup code runs; in yours, > it doesn't. For chdir(), it really doesn't matter. Reverting to the > original state is harmless whether the original chdir() succeeds or > fails, and chdir() is essentially atomic so if it raises an exception, > the state did not change and nothing needs to be cleaned up. > > However, not all block #2s are atomic. Some are going to fail partway > through and need to be cleaned up even though they raised an exception. > Fortunately, cleanup can frequently be written to not care whether the > whole thing finished or not. Yeah, and there are some systematic ways to handle these things. You might look up Dave Abraham's levels of exception safety. Mostly his approach boils down to making operations effectively atomic so as to reduce the complexity: ideally, if an operation raises an exception, then it has undone any side effects. Of course it can't undo the launching of an ICBM, for example... But ideally, if it could, then it should. If you call the possibly failing operation "A", then that systematic approach goes like this: if A fails, then it has cleaned up its own mess, but if A succeeds, then it's the responsibility of the calling code to clean up if the higher level (multiple statements) operation that A is embedded in, fails. And that's what Marginean's original C++ ScopeGuard was designed for, and what the corresponding Python Cleanup class is designed for. > Both formulations can be correct (and both work perfectly fine with the > chdir() example being used). Sometimes one is better than the other, and > sometimes not. You can achieve both ways with either your Cleanup class > or with try: finally:. > > I am still of the opinion that Cleanup is not an improvement over try: > finally: and has the significant ugliness of forcing cleanup code into > callables. This significantly limits what you can do in your cleanup code. Uhm, not really. :-) As I see it. But for any given task one should use the most practical tool, and I'm certainly not claiming that Cleanup will always be that: it's just another weapon to employ in the correctness war -- although I think it's a powerful one. Cheers, - Alf From clp2 at rebertia.com Wed Mar 3 20:06:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 17:06:01 -0800 Subject: Question about typing: ints/floats In-Reply-To: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: <50697b2c1003031706l6043430fv14e72203d7915a4f@mail.gmail.com> On Wed, Mar 3, 2010 at 3:45 PM, Wells wrote: > This seems sort of odd to me: > >>>> a = 1 >>>> a += 1.202 >>>> a > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. Remember Python is dynamically typed. Values have types, but variables don't (I could do a = "foo" at the end of your code and Python won't complain). But yes, internally, Python converted the int to a float before doing the addition. > But: > >>>> a = 1 >>>> b = 3 >>>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) This has been fixed in Python v3.x You can request the new behavior in earlier versions using a magic import: >>> from __future__ import division >>> a = 1 >>> b = 3 >>> a / b 0.33333333333333331 Cheers, Chris -- http://blog.rebertia.com From anand.shashwat at gmail.com Wed Mar 3 20:06:54 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Mar 2010 06:36:54 +0530 Subject: Question about typing: ints/floats In-Reply-To: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: yes you can also try: >>> float(a)/b 0.33333333333333331 On Thu, Mar 4, 2010 at 5:15 AM, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Does python > implicitly change the casting when you add variables of a different > numeric type? > > Anyway, just curiosity more than anything else. Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Mar 3 20:13:50 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Mar 2010 20:13:50 -0500 Subject: Question about typing: ints/floats In-Reply-To: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Wed, Mar 3, 2010 at 6:45 PM, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Does python > implicitly change the casting when you add variables of a different > numeric type? > > Anyway, just curiosity more than anything else. Thanks! > -- > Python doesn't cast anything. Variable names in python do not have types. It's the objects bound to the names that have types. a += 1.202 does not change a in place. It is exactly the same thing as writing a = a + 1.202 In Python (like many other languages), int + float returns a float. That float is then assigned to the name "a". In Python 2, all operations with two int operands return an int, including division. This was changed in Python 3 so that 1 / 3 will return a float and 1 // 3 will do integer division. > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Mar 3 20:28:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Mar 2010 01:28:25 +0000 Subject: Question about typing: ints/floats In-Reply-To: References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: <4B8F0CB9.3070708@mrabarnett.plus.com> Zeeshan Quireshi wrote: > On Mar 3, 6:45 pm, Wells wrote: >> This seems sort of odd to me: >> >>>>> a = 1 >>>>> a += 1.202 >>>>> a >> 2.202 >> >> Indicates that 'a' was an int that was implicitly casted to a float. >> But: >> >>>>> a = 1 >>>>> b = 3 >>>>> a / b >> 0 >> >> This does not implicitly do the casting, it treats 'a' and 'b' as >> integers, and the result as well. Changing 'b' to 3.0 will yield a >> float as a result (0.33333333333333331) >> >> Is there some way to explain the consistency here? Does python >> implicitly change the casting when you add variables of a different >> numeric type? >> >> Anyway, just curiosity more than anything else. Thanks! > > Python, like most other languages performs only integer division when > both the operands are ints. So only if one of the types is a flot or > you explicitly cast your expression to be a double, then the value > will be a fraction. otherwise you will the quotient. int + int gives int float + float gives float int + float gives float float + int gives float Similarly for '-' and '*'. Division causes a problem because what is int / int? Should it behave like the others and give an int? That would mean that 1 / 2 == 0, which can be confusing for newbies. In older languages (Fortran, for example) integer divided by integer using the normal division operator '/' was integer, and this is what C and those influenced by it do. Newer languages return a float instead of an integer because it causes less confusion (1 / 2 == 0.5 is less confusing than 1 / 2 == 0), but also provide a special integer division operator. In Python v2.x '/' does integer division, but from Python v3.x '/' does float division and uses '//' for integer division. ('//' is also available in later versions of 2.x.) From chris.lieb at gmail.com Wed Mar 3 20:33:00 2010 From: chris.lieb at gmail.com (Chris Lieb) Date: Wed, 3 Mar 2010 17:33:00 -0800 (PST) Subject: Failure in test_hashlib.py and test_hmac.py Message-ID: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> I am building Python 2.6.4 on a shared server and am encountering test failures in test_hashlib.py and test_hmac.py, specifically concerning sha512. I recompiled Python with --with-pydebug and CLFAGS=CPPFLAGS="- g" and ran the tests in GDB and got the following results: ---------------------------------------------------------------------------- GNU gdb 6.6.50.20070726-cvs Copyright (C) 2007 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-suse-linux"... Using host libthread_db library "/lib64/libthread_db.so.1". (gdb) run test_hashlib.py Starting program: /export/users1/chris.lieb/packages/python/bin/ python2.6 test_hashlib.py test_case_md5_0 (__main__.HashLibTestCase) ... ok test_case_md5_1 (__main__.HashLibTestCase) ... ok test_case_md5_2 (__main__.HashLibTestCase) ... ok test_case_md5_huge (__main__.HashLibTestCase) ... ok test_case_md5_uintmax (__main__.HashLibTestCase) ... ok test_case_sha1_0 (__main__.HashLibTestCase) ... ok test_case_sha1_1 (__main__.HashLibTestCase) ... ok test_case_sha1_2 (__main__.HashLibTestCase) ... ok test_case_sha1_3 (__main__.HashLibTestCase) ... ok test_case_sha224_0 (__main__.HashLibTestCase) ... ok test_case_sha224_1 (__main__.HashLibTestCase) ... ok test_case_sha224_2 (__main__.HashLibTestCase) ... ok test_case_sha224_3 (__main__.HashLibTestCase) ... ok test_case_sha256_0 (__main__.HashLibTestCase) ... ok test_case_sha256_1 (__main__.HashLibTestCase) ... ok test_case_sha256_2 (__main__.HashLibTestCase) ... ok test_case_sha256_3 (__main__.HashLibTestCase) ... ok test_case_sha384_0 (__main__.HashLibTestCase) ... ok test_case_sha384_1 (__main__.HashLibTestCase) ... ok test_case_sha384_2 (__main__.HashLibTestCase) ... ok test_case_sha384_3 (__main__.HashLibTestCase) ... ok test_case_sha512_0 (__main__.HashLibTestCase) ... FAIL test_case_sha512_1 (__main__.HashLibTestCase) ... FAIL test_case_sha512_2 (__main__.HashLibTestCase) ... FAIL test_case_sha512_3 (__main__.HashLibTestCase) ... FAIL test_hexdigest (__main__.HashLibTestCase) ... Program received signal SIGSEGV, Segmentation fault. Cannot remove breakpoints because program is no longer writable. It might be running in another process. Further execution is probably impossible. 0x00002ba86ffbb463 in ?? () (gdb) bt #0 0x00002ba86ffbb463 in ?? () #1 0x000000000046993d in PyString_FromStringAndSize ( str=0x7fff71c67800 "???\203???5~??????T(P???m\200\a??? ???\005\vW \025???\203???!???l??????G??????<] \205 5?????? \203\030???\207~???/c???1???GAz\201???82z???'???>???x???q???\177", size=1054484473) at Objects/stringobject.c:90 #2 0x00002ba87030d59a in ?? () #3 0x0000000000000000 in ?? () ----------------------------------------------------------------------------------------- GNU gdb 6.6.50.20070726-cvs Copyright (C) 2007 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-suse-linux"... Using host libthread_db library "/lib64/libthread_db.so.1". (gdb) run test_hmac.py Starting program: /export/users1/chris.lieb/packages/python/bin/ python2.6 test_hmac.py test_legacy_block_size_warnings (__main__.TestVectorsTestCase) ... ok test_md5_vectors (__main__.TestVectorsTestCase) ... ok test_sha224_rfc4231 (__main__.TestVectorsTestCase) ... ok test_sha256_rfc4231 (__main__.TestVectorsTestCase) ... ok test_sha384_rfc4231 (__main__.TestVectorsTestCase) ... ok test_sha512_rfc4231 (__main__.TestVectorsTestCase) ... Program received signal SIGSEGV, Segmentation fault. Cannot remove breakpoints because program is no longer writable. It might be running in another process. Further execution is probably impossible. 0x00002b483844e4c7 in ?? () (gdb) bt #0 0x00002b483844e4c7 in ?? () #1 0x000000000046993d in PyString_FromStringAndSize ( str=0x7ffff84f6730 "\026C3D???\235D\t???\025??????[??????G??? \032bG????????~???\235\t\233aP", size=4108309188) at Objects/stringobject.c:90 #2 0x00002b48387e159a in ?? () #3 0x0000000000000000 in ?? () -------------------------------------------------------------------- In the case of test_hashlib.py, it segfaulted on the first sha512 test when I didn't have the debugging options enabled. Only after enabling debugging did I get FAIL's for the sha512 tests. Does anyone know what is causing these failures? From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 21:00:02 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Mar 2010 02:00:02 GMT Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Wed, 03 Mar 2010 15:45:51 -0800, Wells wrote: > But: > >>>> a = 1 >>>> b = 3 >>>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a float > as a result (0.33333333333333331) This is design flaw in older versions of Python, that the / operator for ints performs integer division rather than floating point division. In Python 2.5 and beyond, you can fix this by calling from __future__ import division at the top of your module, and then / will perform float division with int arguments, and you can use // for integer division. Or upgrade to Python 3.1, where this is the default behaviour and there is no need for the from __future__ call. -- Steven From debatem1 at gmail.com Wed Mar 3 21:04:32 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 3 Mar 2010 21:04:32 -0500 Subject: Passing FILE * types using ctypes In-Reply-To: References: Message-ID: On Wed, Mar 3, 2010 at 6:50 PM, Zeeshan Quireshi wrote: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. Or do i have to call the C library using ctypes first, > get the pointer and then pass it to my function. Something along these lines should work: class FILE(ctypes.structure): pass FILE_p = ctypes.POINTER(FILE) ...but I haven't tested it. You can also use a c_void_p. > Also, is there any automated way to convert c struct and enum > definitions to ctypes data types. for structures: http://code.activestate.com/recipes/576734-c-struct-decorator/?in=user-4170000 for functions: http://code.activestate.com/recipes/576731-c-function-decorator/?in=user-4170000 Geremy Condra From john at castleamber.com Wed Mar 3 21:11:25 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Mar 2010 20:11:25 -0600 Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> Message-ID: <871vg0bzua.fsf@castleamber.com> Philip Semanchuk writes: > Do Fedora & Ubuntu's package managers offer modules that appear in > CPAN? Yes, I've installed so far all Perl modules I need that way (sudo apt-get install ...) > In other words, if I was a Perl user under Ubuntu would I use > the pkg manager to add a Perl module, or CPAN, or would both work? Both would work, but I would make very sure to use a separate installation directory for modules installed via CPAN. AFAIK there are also programs that pack CPAN modules/bundles into something the package manager can use to install. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 21:14:18 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Mar 2010 02:14:18 GMT Subject: Generic singleton References: Message-ID: On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote: > Hello, > > So I set out to write generic singleton, i.e. the one that would do a > singleton with attributes of specified class. At first: Groan. What is it with the Singleton design pattern? It is one of the least useful design patterns, and yet it's *everywhere* in Java and C++ world. I suspect because it allows people to have all the bugs and difficulties of global variables, while still pretending to be virtuous for not using global variables. But maybe I'm cynical... There are a ton of recipes out there for Python Singletons. Don't forget to check out the Borg pattern, which gives more or less the same effect using a radically different approach. Then, my advice is to forget all about them. In my experience, I have never needed to code my own Singleton class in anything except toy examples. YMMV. > print id(s1) == id(s2) Or, more concisely: s1 is s2 > class Singleton(object): > > instd = {} > > def __new__(cls, impclass, *args, **kwargs): > impid = id(impclass) Yuck. Why are you using the id of the class as the key, instead of the class itself? class Singleton(object): instd = {} def __new__(cls, impclass, *args, **kwargs): if not impclass in cls.instd: cls.instd[impclass] = impclass.__new__( impclass, *args, **kwargs) return cls.instd[impclass] > Questions: > > 1. Is this safe? That is, does every builtin class have unique id? I > have found this in docs: Why are you limiting yourself to builtin classes? ALL objects, whether classes or builtins or strings or ints or instances of a class you built yourself, have a unique id that lasts for the lifespan of the object. But that is certainly not what you care about. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 21:18:23 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Mar 2010 02:18:23 GMT Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Wed, 03 Mar 2010 17:06:01 -0800, Chris Rebert wrote: > But yes, internally, Python converted the int to a float before doing > the addition. [pedantic] To be precise, Python created a *new* float from the int, leaving the original int alone. Because ints and floats are objects, if Python actually converted the int to a float, this would happen: >>> n = 1 >>> m = n >>> x = 2.0 + n >>> print x 3.0 >>> print n 1.0 >>> "abc"[m] Traceback (most recent call last): File "", line 1, in TypeError: string indices must be integers and the world would rapidly be destroyed. Fortunately this does not happen. [/pedantic] -- Steven From cournape at gmail.com Wed Mar 3 21:24:24 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 4 Mar 2010 11:24:24 +0900 Subject: PYTHONPATH and eggs In-Reply-To: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> References: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Message-ID: <5b8d13221003031824g6e26c9bbsc5a5fd52bbcd323e@mail.gmail.com> On Wed, Mar 3, 2010 at 7:14 PM, geoffbache wrote: > Unfortunately, the location from PYTHONPATH ends up after the eggs in > sys.path so I can't persuade Python to import my version. The only way > I've found to fix it is to copy the main script and manually hack > sys.path at the start of it which isn't really very nice. I wonder if > there is any better way as I can't be the first person to want to do > this, surely? One way is to never install things as eggs: I have a script hard_install which forces things to always install with --single-externally-managed blablabla. This has worked very well for me, but may not always be applicable (in particular if you are on a platform where building things from sources is difficult). cheers, David From roy at panix.com Wed Mar 3 21:28:03 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Mar 2010 21:28:03 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> Message-ID: In article , "D'Arcy J.M. Cain" wrote: > On Wed, 03 Mar 2010 14:42:00 +0000 > MRAB wrote: > > Gregory Ewing wrote: > > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment > > display, which I had to solder together, and also make my own power > > supply. I had the extra RAM and the I/O chip, so that's 256B (including > > the memory used by the monitor) + 256B additional RAM + 128B more in the > > I/O chip. > > In case some of you youngsters think that there is a typo in the above, > no, he means a total of 640 bytes. In today's terms that would be > approx 0.0000006GB. 640 bytes! Man, did you have it easy. When I was a kid, we had to walk 10 miles uphill to school in the snow, oh, wait, wrong story. When I was a kid, we had a D2 kit (http://tinyurl.com/yfgyq4u). We had 256 bytes of RAM. And we thought we were lucky! Some of the other kids, if they wanted to store a number, they had to scratch the bits into stone tablets with their bare hands... When's the last time you had a computer where the instruction manual warned you against wearing silk or nylon clothing? From srikrishnamohan at gmail.com Wed Mar 3 21:30:21 2010 From: srikrishnamohan at gmail.com (km) Date: Thu, 4 Mar 2010 11:30:21 +0900 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: Hi, this would be a good place to start http://en.wikipedia.org/wiki/NoSQL http://nosql-database.org/ HTH, Krishna On Thu, Mar 4, 2010 at 7:41 AM, Avid Fan wrote: > Jonathan Gardner wrote: > > >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is understood well enough that the >> general nature of the SQL database is unnecessary. >> >> > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the query > language? > > Could you give some sort of example of where SQL would not be the way to > go. The only things I can think of a simple flat file databases. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From falk at mauve.rahul.net Wed Mar 3 21:50:23 2010 From: falk at mauve.rahul.net (Edward A. Falk) Date: Thu, 4 Mar 2010 02:50:23 +0000 (UTC) Subject: DOS Follies (Was: Docstrings...) References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: In article , D'Arcy J.M. Cain wrote: >On Wed, 03 Mar 2010 20:44:08 +0100 >mk wrote: >> It reminds me of why Windows uses backslashes for path separation >> instead of slashes: what I've *heard*, and do not know if it's true, >> it's because Gates fancied using / for options switch instead of -, and >> to hell with established practice. > >That was because CP/M used slashes for options and DOS copied that. By >the time hierarchy was added it was too late to change. And CP/M got it from the various PDP-11 operating systems. I *think* that Tops-10 had it as well. In fact, I think using / to delimit commandline options goes back to the PDP-8. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From philip at semanchuk.com Wed Mar 3 21:53:19 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 21:53:19 -0500 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <161DBC13-9917-47E4-99FA-0D04AFC7DC44@semanchuk.com> On Mar 3, 2010, at 5:41 PM, Avid Fan wrote: > Jonathan Gardner wrote: > >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some >> point >> in the project's lifetime, the data is understood well enough that >> the >> general nature of the SQL database is unnecessary. > > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the > query language? > > Could you give some sort of example of where SQL would not be the > way to go. The only things I can think of a simple flat file > databases. Well, Zope is backed by an object database rather than a relational one. From jackdied at gmail.com Wed Mar 3 22:43:01 2010 From: jackdied at gmail.com (Jack Diederich) Date: Wed, 3 Mar 2010 22:43:01 -0500 Subject: NoSQL Movement? In-Reply-To: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: On Wed, Mar 3, 2010 at 12:36 PM, Xah Lee wrote: [snip] Xah Lee is a longstanding usenet troll. Don't feed the trolls. From jackdied at gmail.com Wed Mar 3 22:59:55 2010 From: jackdied at gmail.com (Jack Diederich) Date: Wed, 3 Mar 2010 22:59:55 -0500 Subject: Generic singleton In-Reply-To: <6cc20cea1003031418w5ad6f59ah91562243a2cc4afb@mail.gmail.com> References: <6cc20cea1003031418w5ad6f59ah91562243a2cc4afb@mail.gmail.com> Message-ID: On Wed, Mar 3, 2010 at 5:18 PM, Jonathan Gardner wrote: > On Wed, Mar 3, 2010 at 1:11 PM, mk wrote: >> >> Or I could make my life simpler and use global variable. :-) >> > > Ding ding ding! > > 90% of Design Patterns is making Java suck less. > > Other languages don't necessarily suffer from Java's design flaws. The original "Gang of Four" book was about C++ and not Java. The fact that you can casually assert that "Design Patterns" are about Java says something not entirely kosher about Java ;) -Jack From blueskykind02 at gmail.com Thu Mar 4 00:23:10 2010 From: blueskykind02 at gmail.com (yamamoto) Date: Wed, 3 Mar 2010 21:23:10 -0800 (PST) Subject: python SUDS library Message-ID: <28ed0127-8b71-4327-954c-c9100b4768de@v20g2000prb.googlegroups.com> Hi, I tried to make a simple script with SUD library for caching torrent files. it doenst work! [versions] suds: 0.4, python: 2.6.4 [code] from suds.client import Client import base64 path = 'sample.torrent' doc = open(path, 'rb').read() encoded_doc = base64.b64encode(doc) url = 'http://torrage.com/api/torrage.wsdl' client = Client(url, cache=None) print client hash = client.service.cacheTorrent(encoded_doc) print hash [result] Suds ( https://fedorahosted.org/suds/ ) version: 0.4 (beta) build: R663-20100303 Service ( CacheService ) tns="urn:Torrage" Prefixes (0) Ports (1): (CachePort) Methods (1): cacheTorrent(xs:string torrent, ) Types (0): Traceback (most recent call last): File "C:\Documents and Settings\yamamoto\workspace\python\console \extract.py", line 13, in result = client.service.cacheTorrent(encoded_doc) File "C:\Python26\lib\site-packages\suds\client.py", line 539, in __call__ return client.invoke(args, kwargs) File "C:\Python26\lib\site-packages\suds\client.py", line 598, in invoke result = self.send(msg) File "C:\Python26\lib\site-packages\suds\client.py", line 627, in send result = self.succeeded(binding, reply.message) File "C:\Python26\lib\site-packages\suds\client.py", line 659, in succeeded r, p = binding.get_reply(self.method, reply) File "C:\Python26\lib\site-packages\suds\bindings\binding.py", line 143, in get_reply replyroot = sax.parse(string=reply) File "C:\Python26\lib\site-packages\suds\sax\parser.py", line 136, in parse sax.parse(source) File "C:\Python26\lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python26\lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python26\lib\xml\sax\expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "C:\Python26\lib\xml\sax\handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :2:0: junk after document element this is a php code provided by torrage cacheTorrent(base64_encode(file_get_contents("my.torrent"))); ?> any suggestions? thanks in advance From waldemar.osuch at gmail.com Thu Mar 4 00:25:29 2010 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Wed, 3 Mar 2010 21:25:29 -0800 (PST) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: On Mar 3, 9:32?am, BlueBird wrote: > Hi, > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > that this does not exist. Does anybody know about this ? > > The following clients seem to be both unmaintained and still > supporting only SOAP 1.1 : > > - SUDS suds unmaintained? I beg to differ. > - zsi > - SOAPy > > cheers, > > Philippe From geoff.bache at jeppesen.com Thu Mar 4 03:20:57 2010 From: geoff.bache at jeppesen.com (geoffbache) Date: Thu, 4 Mar 2010 00:20:57 -0800 (PST) Subject: PYTHONPATH and eggs References: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Message-ID: On Mar 4, 3:24?am, David Cournapeau wrote: > On Wed, Mar 3, 2010 at 7:14 PM, geoffbache wrote: > > Unfortunately, the location from PYTHONPATH ends up after the eggs in > > sys.path so I can't persuade Python to import my version. The only way > > I've found to fix it is to copy the main script and manually hack > > sys.path at the start of it which isn't really very nice. I wonder if > > there is any better way as I can't be the first person to want to do > > this, surely? > > One way is to never install things as eggs: I have a script > hard_install which forces things to always install with > --single-externally-managed blablabla. This has worked very well for > me, but may not always be applicable (in particular if you are on a > platform where building things from sources is difficult). Thanks for the tips. Is your script generic at all? I wonder if you'd be prepared to share it? Figuring out virtualenv would also be an option, as would figuring out how to build my own egg, but both these solutions feel like overkill to me just to enable a small bit of tweaking. /Geoff From asimurzin at gmail.com Thu Mar 4 03:25:21 2010 From: asimurzin at gmail.com (=?UTF-8?B?0JDQvdC00YDQtdC5INCh0LjQvNGD0YDQt9C40L0=?=) Date: Thu, 4 Mar 2010 00:25:21 -0800 (PST) Subject: Don't work __getattr__ with __add__ Message-ID: It is object of the class A, in conteiner's class tmpA. Not all method from A are in the tmpA. So for exapmle: A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I can to call simple method, such as change(), bit __add__ - don't work. If to remove inheritance from object, the code work's. Help me, please #-------------------------------------- class A(object): def __init__( self, x, y ): self.x = x self.y = y pass #------- def __add__( self, arg ): tmp1 = self.x + arg.x tmp2 = self.y + arg.y return tmpA( A( tmp1, tmp2 ) ) def change( self, x, y ): self.x = x self.y = y pass pass #------------------------------------------ class tmpA( object ): def __init__( self, theA ): self.A = theA pass #------- def __call__( self ): return self.A #------- def __coerce__( self, *args ): return None #------- def __getattr__( self, *args ): name = args[ 0 ] try: attr = None exec "attr = self.__call__().%s" % name return attr except : raise AttributeError #-------------------------------------- class B( object ): def __init__( self, x, y): self.x = x self.y = y pass #------------------------------------- a=A( 1,2 ) b=B( 3,4 ) tmp_a = a + b #well tmp_a.change( 0, 0 ) # very well !!! v = tmp_a + b #TypeError: "unsupported operand type(s) for +: 'tmpA' and 'B'" From clp2 at rebertia.com Thu Mar 4 03:38:58 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Mar 2010 00:38:58 -0800 Subject: Don't work __getattr__ with __add__ In-Reply-To: References: Message-ID: <50697b2c1003040038l2d778448i7667d9b75a691dd@mail.gmail.com> On Thu, Mar 4, 2010 at 12:25 AM, ?????? ???????? wrote: > It is object of the class A, in conteiner's class tmpA. Not all method > from A are in the tmpA. So for exapmle: > A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I > can to call simple method, ?such as change(), bit __add__ - ?don't > work. If to remove inheritance from object, the code work's. Help me, > please Some clarity has been lost in translation, but I think I get what you're saying. __add__ and the other double-underscore special methods are not looked up using __getattr__ or __getattribute__, hence trying to do addition on tmpA, which does not define an __add__ method, fails. For a full explanation, read: http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes Cheers, Chris -- http://blog.rebertia.com From no.email at nospam.invalid Thu Mar 4 03:52:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 00:52:03 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <7xlje8lb9o.fsf@ruckus.brouhaha.com> mk writes: > OK, but how? How would you make up e.g. for JSON's lack of comments? Modify the JSON standard so that "JSON 2.0" allows comments. > OTOH, if YAML produces net benefit for as few as, say, 200 people in > real world, the effort to make it has been well worth it. Not if 200,000 other people have to deal with it but don't receive the benefit. > http://myarch.com/why-xml-is-bad-for-humans > http://www.ibm.com/developerworks/xml/library/x-sbxml.html You might like this one too: http://www.schnada.de/grapt/eriknaggum-xmlrant.html > > I also have to maintain a few applications that internally use XML as > data format: while they are tolerable, they still leave smth to be > desired, as those applications are really slow for larger datasets, I thought we were talking about configuration files, not "larger datasets". > There are demonstrable benefits to this too: I for one am happy that > ReST is available for me and I don't have to learn a behemoth such as > DocBook to write documentation. DocBook is so far off my radar I'd have never thought of it. I just now learned that it's not Windows-only. There is already POD, Pydoc, Texinfo, a billion or so flavors of wiki markup, vanilla LaTeX, and most straightforwardly of all, plain old ascii. ReST was another solution in search of a problem. From asimurzin at gmail.com Thu Mar 4 03:54:13 2010 From: asimurzin at gmail.com (Andrey Simurzin) Date: Thu, 4 Mar 2010 00:54:13 -0800 (PST) Subject: Don't work __getattr__ with __add__ References: Message-ID: On 4 ???, 11:38, Chris Rebert wrote: > On Thu, Mar 4, 2010 at 12:25 AM, ?????? ???????? wrote: > > It is object of the class A, in conteiner's class tmpA. Not all method > > from A are in the tmpA. So for exapmle: > > A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I > > can to call simple method, ?such as change(), bit __add__ - ?don't > > work. If to remove inheritance from object, the code work's. Help me, > > please > > Some clarity has been lost in translation, but I think I get what you're saying. > __add__ and the other double-underscore special methods are not looked > up using __getattr__ or __getattribute__, hence trying to do addition > on tmpA, which does not define an __add__ method, fails. > > For a full explanation, read:http://docs.python.org/reference/datamodel.html#special-method-lookup... > > Cheers, > Chris > --http://blog.rebertia.com Thank you very much From greg.ewing at canterbury.ac.nz Thu Mar 4 05:01:06 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:01:06 +1300 Subject: My four-yorkshireprogrammers contribution In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> Message-ID: <7v9e3rFl7mU1@mid.individual.net> MRAB wrote: > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment > display, which I had to solder together, and also make my own power > supply. I had the extra RAM and the I/O chip, so that's 256B (including > the memory used by the monitor) + 256B additional RAM + 128B more in the > I/O chip. Luxury! Mine was a Miniscamp, based on a design published in Electronics Australia in the 70s. 256 bytes RAM, 8 switches for input, 8 LEDs for output. No ROM -- program had to be toggled in each time. Looked something like this: http://oldcomputermuseum.com/mini_scamp.html except that mine wasn't built from a kit and didn't look quite as professional as that one. It got expanded in various ways, of course ("hacked" would be a more accurate word). Memory expanded to 1.5KB, hex keyboard and display (built into an old calculator case), cassette tape interface based on a circuit scrounged from another magazine article (never quite got it to work properly, wouldn't go at more than about 4 bytes/sec, probably because I used resistors and capacitors salvaged from old TV sets). Still no ROM, though. Had to toggle in a bootstrap to load the keyboard/display monitor (256 bytes) from tape. Somewhere along the way I replaced the CPU with a 6800 - much nicer instruction set! (Note for newtimers -- that's *two* zeroes, not three.) During that period, my holy grail was alphanumeric I/O. I was envious of people who wrote articles about hooking surplus teleprinters, paper tape equipment and other such cool hardware to their homebrew micros -- sadly, no such thing was available in NZ. Then one day a breakthrough came -- a relative who worked in the telephone business (government-owned in NZ at the time) managed to get me an old teleprinter. It was Baudot, not ASCII, which meant uppercase only, not much punctuation, and an annoyingly stateful protocol involving letters/figures shift characters, but it was heaps better than nothing. A bit of hackery, of both hardware and software varieties, and I got it working. It was as noisy as hell, but I could input and output ACTUAL LETTERS! It was AMAZING! As a proof of concept, I wrote an extremely small BASIC interpreter that used one-character keywords. The amount of room left over for a program was even smaller, making it completely useless. But it worked, and I had fun writing it. One thing I never really got a grip on with that computer was a decent means of program storage. Towards the end of it's life, I was experimenting with trying to turn an old 8-track cartridge player into a random access block storage device, using a tape loop. I actually got it to work, more or less, and wrote a small "TOS" (Tape Operating System) for it that could store and retrieve files. But it was never reliable enough to be practical. By that stage, umpteen layers of hackery using extremely dubious construction techniques had turned the machine into something of a Frankenstein monster. Calling it a bird's nest would have been an insult to most birds. I wish I'd taken some photos, they would have been good for scaring potential future grandchildren. My next computer was a Dick Smith Super 80 (*not* System 80, which would have been a much better machine), Z80-based, built from a kit. I had a lot of fun hacking around with that, too... but that's another story! -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:05:10 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:05:10 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <7v9ebdFmfiU1@mid.individual.net> D'Arcy J.M. Cain wrote: > And that is why text files in MS-DOS and CP/M before it end with ^Z. > They needed a way to tell where the end of the information was. Why > they used ^Z (SUB - Substitute) instead of ^C (ETX - End of TeXt) or > even ^D (EOT - End Of Transmission) is anyone's guess. Well, ^C is what people used for interrupting their BASIC programs. And ^D would have made it almost compatible with unix, which would have been far too sensible! My guess is that it was chosen for its mnemonic value -- end of alphabet, end of file. Also remember there were programs like Wordstar that used control key combinations for all manner of things. It might have been the only key left on the keyboard that wasn't used for anything else. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:09:01 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:09:01 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: Message-ID: <7v9eimFnnoU1@mid.individual.net> Richard Brodie wrote: > It goes back to ancient PDP operating systems, so may well > predate Unix, depending which exact OS was the first to use it. Yes, I think it was used in RT-11, which also had block-oriented disk files. There were two kinds of devices in RT-11, character and block, and the APIs for dealing with them were quite different. They hadn't fully got their heads around the concept of "device independent I/O" in those days, although they were trying. -- Greg From spamfresser at ch3ka.de Thu Mar 4 05:09:06 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 11:09:06 +0100 Subject: case do problem In-Reply-To: <4b8e9e8b$0$1121$4fafbaef@reader3.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> <4b8e9e8b$0$1121$4fafbaef@reader3.news.tin.it> Message-ID: Am 03.03.2010 18:38, schrieb Tracubik: > Il Wed, 03 Mar 2010 09:39:54 +0100, Peter Otten ha scritto: >> def loop(): >> count = 0 >> m = 0 >> lookup = {1: 1, 2: 10, 3: 100} >> for iterations in range(20): # off by one >> # ... >> print "%2d %1d %3d" % (iterations, count, m) # ... >> if generic_condition(): >> count += 1 >> # ... >> m = lookup.get(count, m) >> if count == 4: >> break >> >> if __name__ == "__main__": >> loop() >> print "That's all, folks" >> >> Something must be wrong with me today because I find the Pascal code >> /more/ readable.. > > i was think the same, Pascal seem to generate a great more readable code. > I'm a newbie, so my opinion is probably wrong, but i still think that > don't have CASE OF and REPEAT UNTIL code block return in difficult-to- > read code. That is probably a side-effect of literal code translation. No one would write something like you did when he writes in python the first place. >> Tracubik wrote: >> >>> hi, i've to convert from Pascal this code: >> >> program loop; >> >> function generic_condition: boolean; >> begin >> generic_condition := random> 0.7 >> end; >> >> procedure loop; >> var >> iterations, count, m: integer; >> begin >> iterations := 0; >> count := 0; >> m := 0; >> repeat >> iterations := iterations+1; >> (*...*) >> writeln(iterations:2, count:2, m:4); >> (*...*) >> if generic_condition then >> inc(count); >> (*...*) >> case count of >> 1: m := 1; >> 2: m := 10; >> 3: m := 100 >> end >> until (count = 4) or (iterations = 20) >> end; >> >> begin >> loop; >> writeln("That's all, folks") >> end. Hmmm lets see... We have somewhat obscure and complicated logic. If we cannot get rid of it, lets hide it: class Loop: def __init__(self, maxiterations=0, maxcount=1, m=0): assert generic_condition.__call__ self.maxiterations = maxiterations self.maxcount = maxcount self.m=m self.count=0 self.iterations=0 def __iter__(self): while True: yield self.next() def next(self): self.iterations+=1 if self.iterations > self.maxiterations: raise StopIteration if generic_condition(): self.count += 1 if self.count >= self.maxcount: raise StopIteration self.m = (None,1,10,100)[self.count] return self, self.m ##### So we have: #from complicatedlogic import Loop from random import random def generic_condition(): return random() > 0.7 if __name__ == '__main__': for loop, m in Loop(maxiterations=20, maxcount=4): print("%2d %1d %3d" % (loop.iterations, loop.count, m)) print("That's all, folks") better? worse? I honestly do not know. Note that while this is valid py3 and runs as intended, there might be some off-by-one or something left. Also, this is of course not production level code ;) Regards, Michael From greg.ewing at canterbury.ac.nz Thu Mar 4 05:15:23 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:15:23 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: <7v9eukFpu2U1@mid.individual.net> Steve Holden wrote: > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk > on a VAX 11/750. The only bitmapped display we had available was a Three > Rivers PERQ, connected by a 9600bps serial line. We left it running at > seven o'clock one evening, and by nine am the next day it had brought up > about two thirds of the initial VM loader screen ... A couple of my contemporary postgraduate students worked on getting Smalltalk to run on an Apple Lisa. Their first attempt at a VM implementation was written in Pascal, and it wasn't very efficient. I remember walking into their room one day and seeing one of them sitting there watching it boot, drawing stuff on the screen v...e...r...y... s...l...o...w...l...y... At least their display was wired directly to the machine running the code. I hate to think what bitmapped graphics at 9600 baud would be like! -- Greg From nanyaks at googlemail.com Thu Mar 4 05:30:15 2010 From: nanyaks at googlemail.com (simn_stv) Date: Thu, 4 Mar 2010 02:30:15 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> Message-ID: <81d62813-c768-4f9e-aa50-d6d007a9b1e6@19g2000yqu.googlegroups.com> till i think i absolutely need to trade-off easier and less complicated code, better db structure (from a relational perspective) and generally less "head aches" for speed, i think i'll stick with the joins for now!...;) the thought of denormalization really doesnt appeal to me... From karen.wang at avant-port.com.cn Thu Mar 4 05:38:08 2010 From: karen.wang at avant-port.com.cn (Karen Wang) Date: Thu, 4 Mar 2010 18:38:08 +0800 Subject: How to login https sever with inputing account name and password? Message-ID: <20100304103731.740AC40E@smtpcom.263xmail.com> Hi all, I want to use python to access to https server, like "https://212.218.229.10/chinatest/" If open it from IE, will see the pop-up login windows like this I tried several ways but always only get page for" HTTP Error 401.2 - Unauthorized" error. ( myusername and mypassword are all correct) Below is my code: import urllib2 values = { 'user' : "myusername", "pass' : "mypassword" } data = urllib2.urlencode(values) t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) print t.read() where I am wrong ? Thank you very much. Best Regards Karen Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 17890 bytes Desc: not available URL: From greg.ewing at canterbury.ac.nz Thu Mar 4 05:38:22 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:38:22 +1300 Subject: Old farts playing with their toys In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> <4B8EABCB.6050303@mrabarnett.plus.com> Message-ID: <7v9g9hF1hrU1@mid.individual.net> D'Arcy J.M. Cain wrote: > Did you ever play Star Trek with sound effects? Not on that machine, but I played a version on an Apple II that had normal speaker-generated sounds. I can still remember the sound that a photon torpedo (a # character IIRC) made as it lurched its way drunkenly across the sector and hit its target. Bwoop... bwoop... bwoop... bwoop... bwoop... bwoowoowoowoowoop! (Yes, a photon torpedo makes exactly five bwoops when it explodes. Apparently.) I carried a listing of it around with me for many years afterwards, and attempted to port it to various machines, with varying degrees of success. The most successful port was for a BBC Master that I picked up in a junk shop one day. But I couldn't get the sounds right, because the BBC's sound hardware was too intelligent. The Apple made sounds by directly twiddling the output bit connected to the loudspeaker, but you can't do that with a BBC -- you have to go through its fancy 3-voice waveform generating chip. And I couldn't get it to ramp up the pitch rapidly enough to make a proper photon-torpedo "bwoop" sound. :-( I also discovered that the lovely low-pitched beep that the original game used to make at the command prompt had a lot to do with the resonant properties of the Apple II's big plastic case. Playing a square wave through something too high-fidelity doesn't sound the same at all. > I was never able to > get it to work but supposedly if you put an AM radio tuned to a > specific frequency near the side with the I/O card it would generate > static that was supposed to be the sound of explosions. > > Of course, the explosions were happening in a vaccum so maybe the > silence was accurate. :-) Something like that might possibly happen for real. I could imagine an explosion in space radiating electromagnetic noise that would sound explosion-like if you picked it up on a radio. This might explain why the Enterprise crew could hear things exploding when they shot them. They were listening in at RF! -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:38:31 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:38:31 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> Message-ID: <7v9g9qF1nkU1@mid.individual.net> Steven D'Aprano wrote: > True, but one can look at "best practice", or even "standard practice". > For Python coders, using docstrings is standard practice if not best > practice. Using strings as comments is not. In that particular case, yes, it would be possible to objectively examine the code and determine whether docstrings were being used as opposed to above-the-function comments. However, that's only a very small part of what goes to make good code. Much more important are questions like: Are the comments meaningful and helpful? Is the code reasonably self-explanatory outside of the comments? Is it well modularised, and common functionality factored out where appropriate? Are couplings between different parts minimised? Does it make good use of library code instead of re-inventing things? Is it free of obvious security flaws? You can't *measure* these things. You can't objectively boil them down to a number and say things like "This code is 78.3% good; the customer requires it to be at least 75% good, so it meets the requirements in that area." That's the way in which I believe that software engineering is fundamentally different from hardware engineering. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:43:20 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:43:20 +1300 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <7v9girF3b8U1@mid.individual.net> Roy Smith wrote: > The idea is I want to put in the beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") Okay, that seems like a passable excuse. One thing to watch out for is that if your 'declare' function is defined in a different module, when it calls globals() it will get the globals of the module it's defined in, not the one it's being called from. There's a hackish way of getting around that, but it might be better to put all of these symbols in a module of their own and import them from it. The declare() function can then be defined in that same module so that it accesses the right globals. -- Greg From jeanmichel at sequans.com Thu Mar 4 05:45:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 11:45:19 +0100 Subject: Pylint Argument number differs from overridden method In-Reply-To: <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> Message-ID: <4B8F8F3F.8010501@sequans.com> Wanderer wrote: > On Mar 3, 2:33 pm, Robert Kern wrote: > >> On 2010-03-03 11:39 AM, Wanderer wrote: >> >> >>> Pylint W0221 gives the warning >>> Argument number differs from overridden method. >>> >>> Why is this a problem? I'm overriding the method to add additional >>> functionality. >>> >> There are exceptions to every guideline. Doing this could easily be a mistake, >> so it's one of the many things that Pylint checks for. Silence the warning if >> you like. >> >> -- >> 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 >> > > Thanks I was just wondering if I was overlooking something about > inheritance. > This is only my opinion but you get this warning because of 2 disctinct issues: 1/ you just made a basic mistake in your signature and need to correct it 2/ you did not make any mistake in the signature, but this warning may reveal a (small) flaw in your class design. I don't know the exact context for your code, but it's better to have a consistant interface over your methods and mask the implementation details from the user. In your case, the getRays method may always ask for the lambda parameters and just ignore it for one of its implementation. And don't write empty doctrings to trick pylint. Either write them, or remove this rule, you are loosing all the tool benefits. JM From jpiitula at ling.helsinki.fi Thu Mar 4 05:46:06 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Mar 2010 12:46:06 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml Message-ID: Dear group, I am observing weird semi-erratic behaviour that involves Python 3 and lxml, is extremely sensitive to changes in the input data, and only occurs when I name a partial result. I would like some help with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml version?) The test script regress/Tribug is at the end of this message, with a snippet to show the form of regress/tridata.py where the XML is. What I observe is this. Parsing an XML document (wrapped in BytesIO) with lxml.etree.parse and then extracting certain elements with xpath sometimes fails so that I get three times the correct number of elements. On the first run of the script, it fails in one way, and on each subsequent run in another way: subsequent runs are repeatable. Second, the bug only occurs when I give a name to the result from lxml.etree.parse! This is seen below in the lines labeled "name1" or "name2" that sometimes exhibit the bug, and lines labeled "nest1" or "nest2" that never do. That is, this fails in some complex way: result = etree.parse(BytesIO(body)) n = len(result.xpath(title)) This fails to fail: n = len(etree.parse(BytesIO(body)).xpath(title)) I have failed to observe the error interactively. I believe the erroneus result lists are of the form [x x x y y y z z z] when they should be [x y z] but I do not know if the x's are identical or copies. I will know more later, of course, when I have written more complex tests, unless somebody can lead me to a more profitable way of debugging this. Two versions of the test runs follow, before and after a trivial change to the test data. Since the numbers are repeated n's of the above snippets, they should all be the same: 5 observed 1000 times. A first run after removing regress/tridata.pyc: [1202] $ regress/Tribug name1: size 5 observed 969 times name1: size 15 observed 31 times name2: size 5 observed 1000 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times All subsequent runs, with regress/tridata.pyc recreated: [1203] $ regress/Tribug name1: size 5 observed 1000 times name2: size 5 observed 978 times name2: size 15 observed 22 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times Adding an empty comment to the XML document; a first run: [1207] $ regress/Tribug name1: size 5 observed 992 times name1: size 15 observed 8 times name2: size 5 observed 1000 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times And subsequent runs: [1208] $ regress/Tribug name1: size 5 observed 991 times name1: size 15 observed 9 times name2: size 5 observed 998 times name2: size 15 observed 2 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times ---start of regress/Tribug--- #! /bin/env python3 # -*- mode: Python; -*- from io import BytesIO from lxml import etree from tridata import body, title def naming(): sizes = dict() for k in range(0,1000): result = etree.parse(BytesIO(body)) n = len(result.xpath(title)) sizes[n] = 1 + sizes.get(n, 0) return sizes def nesting(): sizes = dict() for k in range(0,1000): n = len(etree.parse(BytesIO(body)).xpath(title)) sizes[n] = 1 + sizes.get(n, 0) return sizes def report(label, sizes): for size, count in sizes.items(): print('{}: size {} observed {} times' .format(label, size, count)) report('name1', naming()) report('name2', naming()) report('nest1', nesting()) report('nest2', nesting()) ---end of regress/Tribug--- The file regress/tridata.py contains only the two constants. I omit most of the XML. It would be several screenfuls. ---start of regress/tridata.py--- body = b''' References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <137d7aa5-a305-4091-a244-904b680d3b56@t41g2000yqt.googlegroups.com> Message-ID: <7v9gv5F3b8U2@mid.individual.net> Floris Bruynooghe wrote: > I was just wondering if > other people ever missed the "q.put_at_front_of_queue()" method or if > it is just me. Sounds like you don't want a queue, but a stack. Or maybe a double-ended queue. -- Greg From jeanmichel at sequans.com Thu Mar 4 05:50:06 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 11:50:06 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <4B8F905E.1090704@sequans.com> Alf P. Steinbach wrote: >> From your post, the scope guard technique is used "to ensure some >> desired cleanup at the end of a scope, even when the scope is exited >> via an exception." This is precisely what the try: finally: syntax is >> for. > > You'd have to nest it. That's ugly. And more importantly, now two > people in this thread (namely you and Mike) have demonstrated that > they do not grok the try functionality and manage to write incorrect > code, even arguing that it's correct when informed that it's not, so > it's a pretty fragile construct, like goto. You want to execute some cleanup when things go wrong, use try except. You want to do it when things go right, use try else. You want to cleanup no matter what happen, use try finally. There is no need of any Cleanup class, except for some technical alternative concern. JM From greg.ewing at canterbury.ac.nz Thu Mar 4 05:58:35 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:58:35 +1300 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <7v9hfeF8hsU1@mid.individual.net> Peter Otten wrote: > Something must be wrong with me today because I find the Pascal code /more/ > readable... Actually I don't find either of them very readable. The control flow is pretty convoluted either way. It might be better if it used real-life variable and function names to give some context, though. -- Greg From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 4 05:59:00 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Mar 2010 11:59:00 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> Message-ID: <4b8f9267$0$17832$426a74cc@news.free.fr> Eike Welk a ?crit : > Bruno Desthuilliers wrote: >> John Posner a ?crit : >>> Done -- see http://wiki.python.org/moin/FromFunctionToMethod >> Done and well done !-) >> Thanks again for the good job John. > > I like it too, thanks to both of you! > > I have two small ideas for improvement: > - Swap the first two paragraphs. First say what it is, and then give the > motivation. Mmm... As far as I'm concerned, I like it the way its. John ? > - The section about the descriptor protocol is a bit difficult to > understand. I may eventually try to rework it a bit when I'll have time (death march here currently, duh...) > But judging from the official descriptor documentation, it seems > to be hard to explain Not that easy, indeed. I once posted on c.l.py a longer explanation of the whole lookup rule stuff, that IIRC included a "naive python implementation" example. Might be worth trying to google for it and turning it into another "overview" article. >: The official documentation is nearly incomprehensible > (IMHO). I should probably have a look at it !-) From greg.ewing at canterbury.ac.nz Thu Mar 4 06:21:01 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 00:21:01 +1300 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: <7v9ipdFfcsU1@mid.individual.net> Peter Billam wrote: > A very important thing about CPAN modules is the consistent > basic install method: perl Makefile.PL ; make ; make install Well, we more or less have that with Python, too: python setup.py install It may not always work smoothly, but it's the one obvious thing to try when you've downloaded a Python package in source form. -- Greg From olof.bjarnason at gmail.com Thu Mar 4 06:45:39 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Thu, 4 Mar 2010 12:45:39 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <7v9ipdFfcsU1@mid.individual.net> References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <7v9ipdFfcsU1@mid.individual.net> Message-ID: 2010/3/4 Gregory Ewing : > Peter Billam wrote: > >> A very important thing about CPAN modules is the consistent >> basic install method: ? perl Makefile.PL ; make ; make install > > Well, we more or less have that with Python, too: > > ?python setup.py install > > It may not always work smoothly, but it's the > one obvious thing to try when you've downloaded > a Python package in source form. > > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > I want to say thanks to all that have given information regarding the original question - for example the blog mention was valuable, aswell as the disctintion between CPAN and cpan. It was definately *not* my intention to start another "Where is CPAN for Python?"-thread, but it seems we're already there. :) -- http://olofb.wordpress.com From mrkafk at gmail.com Thu Mar 4 06:50:45 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 12:50:45 +0100 Subject: Generic singleton In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > Groan. What is it with the Singleton design pattern? It is one of the > least useful design patterns, and yet it's *everywhere* in Java and C++ > world. It's useful when larking about in language internals for learning purposes, for instance. I don't recall ever actually having significant need for it. >> def __new__(cls, impclass, *args, **kwargs): >> impid = id(impclass) > > Yuck. Why are you using the id of the class as the key, instead of the > class itself? Bc I didn't know whether it was safe to do that: like Arnaud pointed out, the *type* of bultins is hashable. Regards, mk From mrkafk at gmail.com Thu Mar 4 06:56:17 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 12:56:17 +0100 Subject: memory usage, temporary and otherwise In-Reply-To: <4b8ee61a$0$26644$426a74cc@news.free.fr> References: <4b8ee61a$0$26644$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > mk a ?crit : >> Obviously, don't try this on low-memory machine: >> >>>>> a={} >>>>> for i in range(10000000): > Note that in Python 2, this will build a list of 10000000 int objects. > You may want to use xrange instead... Huh? I was under impression that some time after 2.0 range was made to work "under the covers" like xrange when used in a loop? Or is it 3.0 that does that? > And this build yet another list of 10000000 int objects. Well this explains much of the overhead. > (overly simplified) > > When an object is garbage-collected, the memory is not necessarily > "returned" to the system - and the system doesn't necessarily claim it > back neither until it _really_ needs it. > > This avoid a _lot_ of possibly useless work for both the python > interpreter (keeping already allocated memory costs less than immediatly > returning it, just to try and allocate some more memory a couple > instructions later) and the system (ditto - FWIW, how linux handles > memory allocations is somewhat funny, if you ever programmed in C). Ah! That explains a lot. Thanks to you, I have again expanded my knowledge of Python! Hmm I would definitely like to read smth on how CPython handles memory on Python wiki. Thanks for that doc on wiki on "functions & methods" to you and John Posner, I'm reading it every day like a bible. ;-) Regards, mk From ben+python at benfinney.id.au Thu Mar 4 06:57:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 22:57:30 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> <7v9g9qF1nkU1@mid.individual.net> Message-ID: <87ocj4ti39.fsf@benfinney.id.au> Gregory Ewing writes: > However, that's only a very small part of what goes to make good code. > Much more important are questions like: Are the comments meaningful > and helpful? Is the code reasonably self-explanatory outside of the > comments? Is it well modularised, and common functionality factored > out where appropriate? Are couplings between different parts > minimised? Does it make good use of library code instead of > re-inventing things? Is it free of obvious security flaws? > > You can't *measure* these things. You can't objectively boil them down > to a number and say things like "This code is 78.3% good; the customer > requires it to be at least 75% good, so it meets the requirements in > that area." That doesn't reduce the value of automating and testing those measures we *can* make. > That's the way in which I believe that software engineering is > fundamentally different from hardware engineering. Not at all. There are many quality issues in hardware engineering that defy simple measurement; that does not reduce the value of standardising quality minima for those measures that *can* be achieved simply. -- \ ?Spam will be a thing of the past in two years' time.? ?Bill | `\ Gates, 2004-01-24 | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 4 06:59:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Mar 2010 12:59:27 +0100 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: References: Message-ID: <4b8fa091$0$24833$426a74cc@news.free.fr> Oren Elrad a ?crit : > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > Hopefully not. > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. s/do not need to be/NEVER should have been at first/ From mrkafk at gmail.com Thu Mar 4 07:01:38 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 13:01:38 +0100 Subject: NoSQL Movement? In-Reply-To: <6cc20cea1003031423v4410119dh767610e78ba3eb6e@mail.gmail.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003031423v4410119dh767610e78ba3eb6e@mail.gmail.com> Message-ID: Jonathan Gardner wrote: > When you are starting a new project and you don't have a definitive > picture of what the data is going to look like or how it is going to > be queried, SQL databases (like PostgreSQL) will help you quickly > formalize and understand what your data needs to do. In this role, > these databases are invaluable. I can see no comparable tool in the > wild, especially not OODBMS. FWIW, I talked to my promoting professor about the subject, and he claimed that there's quite a number of papers on OODBMS that point to fundamental problems with constructing capable query languages for OODBMS. Sadly, I have not had time to get & read those sources. Regards, mk From duncan.booth at invalid.invalid Thu Mar 4 07:21:26 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 12:21:26 GMT Subject: Generic singleton References: Message-ID: Steven D'Aprano wrote: > On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote: > >> Hello, >> >> So I set out to write generic singleton, i.e. the one that would do a >> singleton with attributes of specified class. At first: > > Groan. What is it with the Singleton design pattern? It is one of the > least useful design patterns, and yet it's *everywhere* in Java and C++ > world. It is also *everywhere* in the Python world. Unlike Java and C++, Python even has its own built-in type for singletons. If you want a singleton in Python use a module. So the OP's original examples become: --- file singleton.py --- foo = {} bar = [] --- other.py --- from singleton import foo as s1 from singleton import foo as s2 from singleton import bar as s3 from singleton import bar as s4 ... and then use them as you wish. -- Duncan Booth http://kupuguy.blogspot.com From duncan.booth at invalid.invalid Thu Mar 4 07:24:52 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 12:24:52 GMT Subject: memory usage, temporary and otherwise References: Message-ID: mk wrote: > Hm, apparently Python didn't spot that 'spam'*10 in a's values is really > the same string, right? If you want it to spot that then give it a hint that it should be looking for identical strings: >>> a={} >>> for i in range(10000000): ... a[i]=intern('spam'*10) should reduce your memory use somewhat. -- Duncan Booth http://kupuguy.blogspot.com From J.Fine at open.ac.uk Thu Mar 4 07:30:12 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Thu, 04 Mar 2010 12:30:12 +0000 Subject: WANTED: A good name for the pair (args, kwargs) Message-ID: Hi We can call a function fn using val = fn(*args, **kwargs) I'm looking for a good name for the pair (args, kwargs). Any suggestions? Here's my use case: def doit(fn , wibble, expect): args, kwargs = wibble actual = fn(*args, **kwargs) if actual != expect: # Something has gone wrong. pass This is part of a test runner. For now I'll use argpair, but if anyone has a better idea, I'll use it. -- Jonathan From mrkafk at gmail.com Thu Mar 4 07:34:39 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 13:34:39 +0100 Subject: taking python enterprise level?... In-Reply-To: <0C9B223A-D32A-474C-80E3-7F912447170F@semanchuk.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> <0C9B223A-D32A-474C-80E3-7F912447170F@semanchuk.com> Message-ID: Philip Semanchuk wrote: > Well OK, but that's a very different argument. Yes, joins can be > expensive. They're often still the best option, though. The first step > people usually take to get away from joins is denormalization which can > improve SELECT performance at the expense of slowing down INSERTs, > UPDATEs, and DELETEs, not to mention complicating one's code and data > model. Is that a worthwhile trade? I'd say that in more than 99% of situations: NO. More than that: if I haven't normalized my data as it should have been normalized, I wouldn't be able to do complicated querying that I really, really have to be able to do due to business logic. A few of my queries have a few hundred lines each with many sub-queries and multiple many-to-many joins: I *dread the thought* what would happen if I had to reliably do it in a denormalized db and still ensure data integrity across all the business logic contexts. And performance is still more than good enough: so there's no point for me, as of the contexts I normally work in, to denormalize data at all. It's just interesting for me to see what happens in that <1% of situations. > Depends on the application. As I > said, sometimes the cure is worse than the disease. > > Don't worry about joins until you know they're a problem. As Knuth said, > premature optimization is the root of all evil. Sure -- the cost of joins is just interesting to me as a 'corner case'. I don't have datasets large enough for this to matter in the first place (and I probably won't have them that huge). > PS - Looks like you're using Postgres -- excellent choice. I miss using it. If you can, I'd recommend using SQLAlchemy layer on top of Oracle/Mysql/Sqlite, if that's what you have to use: this *largely* insulates you from the problems below and it does the job of translating into a peculiar dialect very well. For my purposes, SQLAlchemy worked wonderfully: it's very flexible, it has middle-level sql expression language if normal querying is not flexible enough (and normal querying is VERY flexible), it has a ton of nifty features like autoloading and rarely fails bc of some lower-level DB quirk AND its high-level object syntax is so similar to SQL that you quickly & intuitively grasp it. (and if you have to/prefer writing some query in "low-level" SQL, as I have done a few times, it's still easy to make SQLAlchemy slurp the result into objects provided you ensure there are all of the necessary columns in the query result) Regards, mk From spamfresser at ch3ka.de Thu Mar 4 07:41:22 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 13:41:22 +0100 Subject: How to login https sever with inputing account name and password? In-Reply-To: References: Message-ID: Am 04.03.2010 11:38, schrieb Karen Wang: > Hi all, > > I want to use python to access to https server, like > "https://212.218.229.10/chinatest/" > > If open it from IE, will see the pop-up login windows like this > > > > I tried several ways but always only get page for" HTTP Error 401.2 - > Unauthorized" error. ( myusername and mypassword are all correct) > > Below is my code: > > import urllib2 > > values = { > > 'user' : "myusername", > > "pass' : "mypassword" } > > data = urllib2.urlencode(values) > > t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) > > print t.read() > > where I am wrong ? AFAIR does urlopen() expect the password to be Base64-encoded, not urlencoded. You might also need to add an AUTH-Line. But this all does not matter, as there is more than one AUTH-Method you'd have to implement them all, but fortunately urllib2.HTTPBasicAuthHandler and urllib2.HTTPBasicAuthHandler exist. So use them: import urllib2 passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, theurl, username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) urllib2.install_opener(opener) pagehandle = urllib2.urlopen(theurl) (taken from http://www.voidspace.org.uk/python/articles/authentication.shtml ) Further reference: http://www.python.org/doc/2.5.2/lib/module-urllib2.html http://www.python.org/doc/2.5.2/lib/urllib2-examples.html HTH, Michael From william302888 at gmail.com Thu Mar 4 07:42:50 2010 From: william302888 at gmail.com (jack) Date: Thu, 4 Mar 2010 04:42:50 -0800 (PST) Subject: 15541 - Best, Cheapest Web-Hosting, Domain at $1.99! Message-ID: <0ec7cefa-ea65-43c0-8d2e-8bdb4b56fb7a@t17g2000prg.googlegroups.com> World's Cheapest Rate Hosting, 99.9% Uptime US Based Dedicated Server, Fast Customer Service Register Domain only at $1.99 per Year 3 Month Hosting Free with 1 year Package http://hostwebspaces.com/ From python.list at tim.thechases.com Thu Mar 4 07:50:14 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Mar 2010 06:50:14 -0600 Subject: WANTED: A good name for the pair (args, kwargs) In-Reply-To: References: Message-ID: <4B8FAC86.4020605@tim.thechases.com> Jonathan Fine wrote: > We can call a function fn using > val = fn(*args, **kwargs) > > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > For now I'll use argpair, but if anyone has a better idea, I'll use it. In the legacy of C and Java (okay, that doesn't carry _much_ weight with me), I'd go with "varargs" to refer to the pair of (args, kwargs) -tkc From anand.shashwat at gmail.com Thu Mar 4 07:54:27 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Mar 2010 18:24:27 +0530 Subject: How to login https sever with inputing account name and password? In-Reply-To: References: Message-ID: You may also want to look into mechanize module. On Thu, Mar 4, 2010 at 6:11 PM, Michael Rudolf wrote: > Am 04.03.2010 11:38, schrieb Karen Wang: > > Hi all, >> >> I want to use python to access to https server, like >> "https://212.218.229.10/chinatest/" >> >> If open it from IE, will see the pop-up login windows like this >> >> >> >> I tried several ways but always only get page for" HTTP Error 401.2 - >> Unauthorized" error. ( myusername and mypassword are all correct) >> >> Below is my code: >> >> import urllib2 >> >> values = { >> >> 'user' : "myusername", >> >> "pass' : "mypassword" } >> >> data = urllib2.urlencode(values) >> >> t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) >> >> print t.read() >> >> where I am wrong ? >> > > AFAIR does urlopen() expect the password to be Base64-encoded, not > urlencoded. > > You might also need to add an AUTH-Line. But this all does not matter, as > there is more than one AUTH-Method you'd have to implement them all, but > fortunately urllib2.HTTPBasicAuthHandler and urllib2.HTTPBasicAuthHandler > exist. > > So use them: > > import urllib2 > passman = urllib2.HTTPPasswordMgrWithDefaultRealm() > passman.add_password(None, theurl, username, password) > authhandler = urllib2.HTTPBasicAuthHandler(passman) > opener = urllib2.build_opener(authhandler) > urllib2.install_opener(opener) > pagehandle = urllib2.urlopen(theurl) > > (taken from > http://www.voidspace.org.uk/python/articles/authentication.shtml ) > > Further reference: > http://www.python.org/doc/2.5.2/lib/module-urllib2.html > http://www.python.org/doc/2.5.2/lib/urllib2-examples.html > > HTH, > Michael > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Mar 4 08:10:34 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 13:10:34 GMT Subject: NoSQL Movement? References: Message-ID: Avid Fan wrote: > Jonathan Gardner wrote: > >> >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is understood well enough that the >> general nature of the SQL database is unnecessary. >> > > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the query > language? > > Could you give some sort of example of where SQL would not be the way to > go. The only things I can think of a simple flat file databases. Probably one of the best known large non-sql databases is Google's bigtable. Xah Lee of course dismissed this as he decided to write how bad non-sql databases are without actually looking at the prime example. If you look at some of the uses of bigtable you may begin to understand the tradeoffs that are made with sql. When you use bigtable you have records with fields, and you have indices, but there are limitations on the kinds of queries you can perform: in particular you cannot do joins, but more subtly there is no guarantee that the index is up to date (so you might miss recent updates or even get data back from a query when the data no longer matches the query). By sacrificing some of SQL's power, Google get big benefits: namely updating data is a much more localised option. Instead of an update having to lock the indices while they are updated, updates to different records can happen simultaneously possibly on servers on the opposite sides of the world. You can have many, many servers all using the same data although they may not have identical or completely consistent views of that data. Bigtable impacts on how you store the data: for example you need to avoid reducing data to normal form (no joins!), its much better and cheaper just to store all the data you need directly in each record. Also aggregate values need to be at least partly pre-computed and stored in the database. Boiling this down to a concrete example, imagine you wanted to implement a system like twitter. Think carefully about how you'd handle a sufficiently high rate of new tweets reliably with a sql database. Now think how you'd do the same thing with bigtable: most tweets don't interact, so it becomes much easier to see how the load is spread across the servers: each user has the data relevant to them stored near the server they are using and index changes propagate gradually to the rest of the system. -- Duncan Booth http://kupuguy.blogspot.com From eric.brunel.pragmadev at gmail.com Thu Mar 4 08:20:43 2010 From: eric.brunel.pragmadev at gmail.com (eb303) Date: Thu, 4 Mar 2010 05:20:43 -0800 (PST) Subject: Instance factory - am I doing this right? References: Message-ID: On Mar 3, 6:41?pm, Laszlo Nagy wrote: > This is just an interesting code pattern that I have recently used: > > class CacheStorage(object): > ? ? """Generic cache storage class.""" > ? ? @classmethod > ? ? def get_factory(cls,*args,**kwargs): > ? ? ? ? """Create factory for a given set of cache storage creation > parameters.""" > ? ? ? ? class CacheStorageFactory(cls): > ? ? ? ? ? ? _construct_args = args > ? ? ? ? ? ? _construct_kwargs = kwargs > ? ? ? ? ? ? def __init__(self): > ? ? ? ? ? ? ? ? cls.__init__(self, > ? ? ? ? ? ? ? ? ? ? *self._construct_args,**self._construct_kwargs) > ? ? ? ? return CacheStorageFactory > > Then, I can create subclasses like: > > class GdbmCacheStorage(CacheStorage): > ? ? """Gdbm cache storage class. > > ? ? @param basedir: Base directory where gdbm files should be stored. > ? ? @param basename: Base name for logging and creating gdbm files. > ? ? """ > ? ? def __init__(self,basedir,basename): > ? ? ? ? ? ..... blablabla place initialization code here > > class MemoryCacheStorage(CacheStorage): > ? ? """In-Memory cache storage class. > > ? ? Please note that keys and values are always mashal-ed. > ? ? E.g. when you cache an object, it makes a deep copy. > ? ? """ > ? ? def __init__(self): > ? ? ? ? ? ..... blablabla place initialization code here > > And the finally, I can create a factory that can create cache storage > instances for storing data in gdbm in a given directory: > > cache_factory = GdbmCacheStorage.get_factory("~gandalf/db","test") > print cache_factory # > print cache_factory() > > OR I can create a factory that can create instances for storing data in > memory: > > cache_factory = MemoryCacheStorage.get_factory() > print cache_factory # > print cache_factory() # <__main__.CacheStorageFactory object at 0x8250c6c> > > Now, here is my question. Am I right in doing this? Or are there better > language tools to be used in Python for the same thing? This whole thing > about creating factories looks a bit odd for me. Is it Pythonic enough? > > Thanks, > > ? ?Laszlo Seems you try to reinvent functools: class GdbmCacheStorage(object): def __init__(self,basedir,basename): ... cache_factory = functools.partial(GdbmCacheStorage, "~gandalf/db", "test") print cache_factory() Is it what you're after? I didn't see the point in creating a "cached factory" for MemoryCacheStorage though, since it has no constructor parameters to cache anyway. So doing 'cache_factory = MemoryCacheStorage' in your example would do exactly the same thing as what you did. HTH - Eric - From phd at phd.pp.ru Thu Mar 4 08:34:05 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Thu, 4 Mar 2010 16:34:05 +0300 Subject: SQLObject 0.11.4 Message-ID: <20100304133404.GB4443@phd.pp.ru> Hello! I'm pleased to announce version 0.11.4, a minor bugfix release of 0.11 branch of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.11.4 News and changes: http://sqlobject.org/News.html What's New ========== News since 0.11.3 ----------------- * Fixed a bug in inheritance - if creation of the row failed and if the connection is not a transaction and is in autocommit mode - remove parent row(s). * Do not set _perConnection flag if get() or _init() is passed the same connection; this is often the case with select(). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jjposner at optimum.net Thu Mar 4 08:35:05 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 04 Mar 2010 08:35:05 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8f9267$0$17832$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4b8f9267$0$17832$426a74cc@news.free.fr> Message-ID: <4B8FB709.9080609@optimum.net> On 3/4/2010 5:59 AM, Bruno Desthuilliers wrote: >> >> I have two small ideas for improvement: - Swap the first two >> paragraphs. First say what it is, and then give the motivation. > > Mmm... As far as I'm concerned, I like it the way its. John ? I think it doesn't make very much difference. But in the end, I believe it's the student, not the teacher, who gets to decide what's comprehensible. What *does* make a difference, IMHO, is getting more people to participate in the process of shining lights into Python's darker corners. That's why I encouraged (and still encourage) Eike to roll up the sleeves and wade into these waters. Metaphor-mixingly yours, John From no.email at nospam.invalid Thu Mar 4 08:37:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 05:37:59 -0800 Subject: WANTED: A good name for the pair (args, kwargs) References: Message-ID: <7x8wa85hs8.fsf@ruckus.brouhaha.com> Jonathan Fine writes: > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > Here's my use case: > def doit(fn , wibble, expect): > args, kwargs = wibble > actual = fn(*args, **kwargs) I think this may have been broken in 3.x, but in 2.6 the compiler will unpack directly if you put a tuple structure in the arg list: def doit(fn, (args, kwargs), expect): actual = fn(*args, **kwargs) Otherwise I'd just say "all_args" or some such. Or just "args" which you unpack into "pos_args" (positional args) and "kw_args". From phd at phd.pp.ru Thu Mar 4 08:41:46 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Thu, 4 Mar 2010 16:41:46 +0300 Subject: SQLObject 0.12.2 Message-ID: <20100304134146.GF4443@phd.pp.ru> Hello! I'm pleased to announce version 0.12.2, a bugfix release of branch 0.12 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.12.2 News and changes: http://sqlobject.org/News.html What's New ========== News since 0.12.1 ----------------- * Fixed a bug in inheritance - if creation of the row failed and if the connection is not a transaction and is in autocommit mode - remove parent row(s). * Do not set _perConnection flag if get() or _init() is passed the same connection; this is often the case with select(). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bieffe62 at gmail.com Thu Mar 4 08:45:40 2010 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 4 Mar 2010 05:45:40 -0800 (PST) Subject: Passing FILE * types using ctypes References: Message-ID: On Mar 4, 12:50?am, Zeeshan Quireshi wrote: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. Or do i have to call the C library using ctypes first, > get the pointer and then pass it to my function. > > Also, is there any automated way to convert c struct and enum > definitions to ctypes data types. > > Zeeshan Python file objects have a method fileno() whic returns the 'C file descriptor', i.e. the number used by low level IO in python as well as in C. I would use this as interface between python and C and then in the C function using fdopen to get a FILE * for an already open file for which you have a file descriptor. If you don't want change the C interface, you could try using fdopen in python by loading the standard C library ang using ctypes to call the function. (I tried briefly but always get 0 from fdopen ). But if you can change the C code, why not to pass the file name? The idea of opening the file in python and manage it in C feels a bit icky ... Ciao ---- FB From cartercc at gmail.com Thu Mar 4 09:21:49 2010 From: cartercc at gmail.com (ccc31807) Date: Thu, 4 Mar 2010 06:21:49 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: On Mar 3, 4:55?pm, toby wrote: > > ?where you have to store data and > > "relational data" Data is neither relational nor unrelational. Data is data. Relationships are an artifact, something we impose on the data. Relations are for human convenience, not something inherent in the data itself. > > perform a large number of queries. > > Why does the number matter? Have you ever had to make a large number of queries to an XML database? In some ways, an XML database is the counterpart to a relational database in that the data descriptions constitute the relations. However, since the search is to the XML elements, and you can't construct indicies for XML databases in the same way you can with relational databases, a large search can take much longer that you might expect. CC. From jmg3000 at gmail.com Thu Mar 4 09:39:51 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Thu, 4 Mar 2010 06:39:51 -0800 (PST) Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> <871vg0bzua.fsf@castleamber.com> Message-ID: <8506d9dc-2e6d-4f66-9d55-8173f47f7d4e@i25g2000yqm.googlegroups.com> On Mar 3, 9:11?pm, John Bokma wrote: > Philip Semanchuk writes: > > > In other words, if I was a Perl user under Ubuntu would I use > > the pkg manager to add a Perl module, or CPAN, or would both work? > > Both would work, but I would make very sure to use a separate > installation directory for modules installed via CPAN. What's worked best for me is: use *only* the apt system to install modules into your system Perl (`/usr/bin/perl`) and use *only* cpan/ cpanp/cpanm to install modules into *your own* Perl (for example, you may have installed into `/opt`). > AFAIK there are also programs that pack CPAN modules/bundles into > something the package manager can use to install. Right. If you really want to install a module for which there's no Debian package, and you don't want to install your own Perl, this is a good route to take. Incidentally, this is the same way I recommend handling the situation with Python: Use only aptitude to install packages for your system Python, and use only pip to install packages into your own Python (which you built and installed elsewhere, ex., `/opt/py-2.6.4`). ---John From mrkafk at gmail.com Thu Mar 4 09:47:22 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 15:47:22 +0100 Subject: NoSQL Movement? In-Reply-To: References: Message-ID: Duncan Booth wrote: > If you look at some of the uses of bigtable you may begin to understand > the tradeoffs that are made with sql. When you use bigtable you have > records with fields, and you have indices, but there are limitations on > the kinds of queries you can perform: in particular you cannot do joins, > but more subtly there is no guarantee that the index is up to date (so > you might miss recent updates or even get data back from a query when > the data no longer matches the query). Hmm, I do understand that bigtable is used outside of traditional 'enterprisey' contexts, but suppose you did want to do an equivalent of join; is it at all practical or even possible? I guess when you're forced to use denormalized data, you have to simultaneously update equivalent columns across many tables yourself, right? Or is there some machinery to assist in that? > By sacrificing some of SQL's power, Google get big benefits: namely > updating data is a much more localised option. Instead of an update > having to lock the indices while they are updated, updates to different > records can happen simultaneously possibly on servers on the opposite > sides of the world. You can have many, many servers all using the same > data although they may not have identical or completely consistent views > of that data. And you still have the global view of the table spread across, say, 2 servers, one located in Australia, second in US? > Bigtable impacts on how you store the data: for example you need to > avoid reducing data to normal form (no joins!), its much better and > cheaper just to store all the data you need directly in each record. > Also aggregate values need to be at least partly pre-computed and stored > in the database. So you basically end up with a few big tables or just one big table really? Suppose on top of 'tweets' table you have 'dweebs' table, and tweets and dweebs sometimes do interact. How would you find such interacting pairs? Would you say "give me some tweets" to tweets table, extract all the dweeb_id keys from tweets and then retrieve all dweebs from dweebs table? > Boiling this down to a concrete example, imagine you wanted to implement > a system like twitter. Think carefully about how you'd handle a > sufficiently high rate of new tweets reliably with a sql database. Now > think how you'd do the same thing with bigtable: most tweets don't > interact, so it becomes much easier to see how the load is spread across > the servers: each user has the data relevant to them stored near the > server they are using and index changes propagate gradually to the rest > of the system. I guess that in a purely imaginary example, you could also combine two databases? Say, a tweet bigtable db contains tweet, but with column of classical customer_id key that is also a key in traditional RDBMS referencing particular customer? Regards, mk From tim.wintle at teamrubber.com Thu Mar 4 10:23:33 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 04 Mar 2010 15:23:33 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> Message-ID: <1267716213.23300.7.camel@localhost> On Wed, 2010-03-03 at 20:39 +0100, mk wrote: > Hello Tim, > > Pardon the questions but I haven't had the need to use denormalization > yet, so: > IOW you basically merged the tables like follows? > > CREATE TABLE projects ( > client_id BIGINT NOT NULL, > project_id BIGINT NOT NULL, > cost INT, > date DATETIME, > INDEX(client_id, project_id, date) > ); Yup > From what you write further in the mail I conclude that you have not > eliminated the first table, just made table projects look like I wrote > above, right? (and used stored procedures to make sure that both tables > contain the relevant data for client_id and project_id columns in both > tables) Yup > Have you had some other joins on denormalized keys? i.e. in example how > the join of hypothetical TableB with projects on projects.client_id > behave with such big tables? (bc I assume that you obviously can't > denormalize absolutely everything, so this implies the need of doing > some joins on denormalized columns like client_id). For these joins (for SELECT statements) this _can_ end up running faster - of course all of this depends on what kind of queries you normally end up getting and the distribution of data in the indexes. I've never written anything that started out with a schema like this, but several have ended up getting denormalised as the projects have matured and query behaviour has been tested > > assuming you can access the first mapping anyway - > > ? I'm not clear on what you mean here. I'm refering to not eliminating the first table as you concluded > > Regards, > mk > From tim.wintle at teamrubber.com Thu Mar 4 10:29:23 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 04 Mar 2010 15:29:23 +0000 Subject: taking python enterprise level?... In-Reply-To: <20100303162314.a46484cf.darcy@druid.net> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> <20100303162314.a46484cf.darcy@druid.net> Message-ID: <1267716563.23300.13.camel@localhost> On Wed, 2010-03-03 at 16:23 -0500, D'Arcy J.M. Cain wrote: > On Wed, 03 Mar 2010 20:39:35 +0100 > mk wrote: > > > If you denormalise the table, and update the first index to be on > > > (client_id, project_id, date) it can end up running far more quickly - > > Maybe. Don't start with denormalization. Write it properly and only > consider changing if profiling suggests that that is your bottleneck. Quite - and I'd add to cache reads as much in front end machines as is permissible in your use case before considering denormalisation. > With a decent database engine and proper design it will hardly ever be. I completely agree - I'm simply responding to the request for an example where denormalisation may be a good idea. Tim From jmg3000 at gmail.com Thu Mar 4 10:47:11 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Thu, 4 Mar 2010 07:47:11 -0800 (PST) Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <87eik1ujg4.fsf@benfinney.id.au> Message-ID: <1f9fcfb3-204c-48c6-8142-9f7c2607b917@t20g2000yqe.googlegroups.com> On Mar 3, 5:30?pm, Ben Finney wrote: > > Terry Reedy writes: > > > On 3/3/2010 12:05 PM, John Nagle wrote: > > > > CPAN enforces standard organization on packages. PyPi does not. > > This is, I think, something we don't need as much in Python; there is a > fundamental difference between Perl's deeply nested namespace hierarchy > and Python's inherently flat hierarchy. What do you think that difference is? Both use nested namespaces. My understanding is that if 2 different dists contain like-named packages, and if a user installs both of them, they all just go to the same place in the user's site-packages dir. One difference I see is that the CPAN has a *lot* of dist's which constitute a very large number of modules. Keeping them organized by a semi-agreed-upon hierarchy of packages seems like a great organizational tool. ---John From robert.kern at gmail.com Thu Mar 4 10:48:41 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 09:48:41 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >>>>> * Robert Kern: >>>>>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>>>>> * Robert Kern: >>>>>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>>>>> * Mike Kent: >>>>>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>>>>> >>>>>>>>> if you thought about it you would mean a simple "try/else". >>>>>>>>> "finally" is >>>>>>>>> always executed. which is incorrect for cleanup >>>>>>>> >>>>>>>> Eh? Failed execution doesn't require cleanup? The example you >>>>>>>> gave is >>>>>>>> definitely equivalent to the try: finally: that Mike posted. >>>>>>> >>>>>>> Sorry, that's incorrect: it's not. >>>>>>> >>>>>>> With correct code (mine) cleanup for action A is only performed when >>>>>>> action A succeeds. >>>>>>> >>>>>>> With incorrect code cleanup for action A is performed when A fails. >>>>>> >>>>>> Oh? >>>>>> >>>>>> $ cat cleanup.py >>>>>> >>>>>> class Cleanup: >>>>>> def __init__( self ): >>>>>> self._actions = [] >>>>>> >>>>>> def call( self, action ): >>>>>> assert( callable( action ) ) >>>>>> self._actions.append( action ) >>>>>> >>>>>> def __enter__( self ): >>>>>> return self >>>>>> >>>>>> def __exit__( self, x_type, x_value, x_traceback ): >>>>>> while( len( self._actions ) != 0 ): >>>>>> try: >>>>>> self._actions.pop()() >>>>>> except BaseException as x: >>>>>> raise AssertionError( "Cleanup: exception during cleanup" ) >>>>>> >>>>>> def print_(x): >>>>>> print x >>>>>> >>>>>> with Cleanup() as at_cleanup: >>>>>> at_cleanup.call(lambda: print_("Cleanup executed without an >>>>>> exception.")) >>>>>> >>>>>> with Cleanup() as at_cleanup: >>>>> >>>>> *Here* is where you should >>>>> >>>>> 1) Perform the action for which cleanup is needed. >>>>> >>>>> 2) Let it fail by raising an exception. >>>>> >>>>> >>>>>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>>>>> raise RuntimeError() >>>>> >>>>> With an exception raised here cleanup should of course be performed. >>>>> >>>>> And just in case you didn't notice: the above is not a test of the >>>>> example I gave. >>>>> >>>>> >>>>>> $ python cleanup.py >>>>>> Cleanup executed without an exception. >>>>>> Cleanup execute with an exception. >>>>>> Traceback (most recent call last): >>>>>> File "cleanup.py", line 28, in >>>>>> raise RuntimeError() >>>>>> RuntimeError >>>>>> >>>>>>>> The actions are always executed in your example, >>>>>>> >>>>>>> Sorry, that's incorrect. >>>>>> >>>>>> Looks like it to me. >>>>> >>>>> I'm sorry, but you're >>>>> >>>>> 1) not testing my example which you're claiming that you're >>>>> testing, and >>>> >>>> Then I would appreciate your writing a complete, runnable example that >>>> demonstrates the feature you are claiming. Because it's apparently not >>>> "ensur[ing] some desired cleanup at the end of a scope, even when the >>>> scope is exited via an exception" that you talked about in your >>>> original post. >>>> >>>> Your sketch of an example looks like mine: >>>> >>>> with Cleanup as at_cleanup: >>>> # blah blah >>>> chdir( somewhere ) >>>> at_cleanup.call( lambda: chdir( original_dir ) ) >>>> # blah blah >>>> >>>> The cleanup function gets registered immediately after the first >>>> chdir() and before the second "blah blah". Even if an exception is >>>> raised in the second "blah blah", then the cleanup function will still >>>> run. This would be equivalent to a try: finally: >>>> >>>> # blah blah #1 >>>> chdir( somewhere ) >>>> try: >>>> # blah blah #2 >>>> finally: >>>> chdir( original_dir ) >>> >>> Yes, this is equivalent code. >>> >>> The try-finally that you earlier claimed was equivalent, was not. >> >> Okay, but just because of the position of the chdir(), right? > > Yes, since it yields different results. > >>>> and not a try: else: >>>> >>>> # blah blah #1 >>>> chdir( somewhere ) >>>> try: >>>> # blah blah #2 >>>> else: >>>> chdir( original_dir ) >>> >>> This example is however meaningless except as misdirection. There are >>> infinitely many constructs that include try-finally and try-else, that >>> the with-Cleanup code is not equivalent to. It's dumb to show one such. >>> >>> Exactly what are you trying to prove here? >> >> I'm just showing you what I thought you meant when you told Mike that >> he should have used a try/else instead of try/finally. >> >>> Your earlier claims are still incorrect. >>> >>>> Now, I assumed that the behavior with respect to exceptions occurring >>>> in the first "blah blah" weren't what you were talking about because >>>> until the chdir(), there is nothing to clean up. >>>> >>>> There is no way that the example you gave translates to a try: else: >>>> as you claimed in your response to Mike Kent. >>> >>> Of course there is. >>> >>> Note that Mike wrapped the action A within the 'try': >>> >>> >>> >>> original_dir = os.getcwd() >>> try: >>> os.chdir(somewhere) >>> # Do other stuff >>> finally: >>> os.chdir(original_dir) >>> # Do other cleanup >>> >>> >>> >>> The 'finally' he used, shown above, yields incorrect behavior. >>> >>> Namely cleanup always, while 'else', in that code, can yield correct >>> behavior /provided/ that it's coded correctly: >>> >>> >>> >>> original_dir = os.getcwd() >>> try: >>> os.chdir(somewhere) >>> except Whatever: >>> # whatever, e.g. logging >>> raise >>> else: >>> try: >>> # Do other stuff >>> finally: >>> os.chdir(original_dir) >>> # Do other cleanup >>> >> >> Ah, okay. Now we're getting somewhere. Now, please note that you did >> not have any except: handling in your original example. So Mike made a >> try: finally: example to attempt to match the semantics of your code. >> When you tell him that he should 'mean a simple "try/else". "finally" >> is always executed. which is incorrect for cleanup', can you >> understand why we might think that you were saying that try: finally: >> was wrong and that you were proposing that your code was equivalent to >> some try: except: else: suite? > > No, not really. His code didn't match the semantics. Changing 'finally' > to 'else' could make it equivalent. Okay, please show me what you mean by "changing 'finally' to 'else'." I think you are being hinty again. It's not helpful. The most straightforward interpretation of those words means that you literally just want to remove the word 'finally' and replace it with 'else' in Mike's example. Obviously you don't mean that because it is a syntax error. try: else: is not a construct in Python. There is a try: except: else:, but there is no point to doing that if you don't have anything in the except: clause. Neither Mike's example nor your original one have any except: clause. Why do you think that we would interpret those words to mean that you wanted the example you give just above? >>>>> 2) not even showing anything about your earlier statements, which were >>>>> just incorrect. >>>>> >>>>> You're instead showing that my code works as it should for the case >>>>> that >>>>> you're testing, which is a bit unnecessary since I knew that, but >>>>> thanks >>>>> anyway. >>>> >>>> It's the case you seem to be talking about in your original post. >>> >>> What's this "seems"? Are you unable to read that very short post? >> >> I say "seems" because my understandings of what you meant in your >> original post and your response to Mike disagreed with one another. >> Now I see that your later posts were talking about minor discrepancy >> about which errors you wanted caught by the finally: and which you >> didn't. > > It's absolutely not a minor discrepancy whether some code is executed or > not. It can have arbitrarily large effect. And from my point of view the > discussion of that snippet has not been about what errors I "want" > caught by the 'finally'; it's been about whether two snippets of code > yield the same effect or not: Mike's code was incorrect not because it > did something else, but because as code that did something else it was > not an equivalent to the code that I posted. > > >> I was confused because it seemed that you were saying that try: >> finally: was completely wrong and that "try/else" was right. It >> confused me and at least one other person. >> >>>> , but I do ask you to acknowledge that you originally were talking >>>> about a feature that "ensure[s] some desired cleanup at the end of a >>>> scope, even when the scope is exited via an exception." >>> >>> Yes, that's what it does. >>> >>> Which is I why I wrote that. >>> >>> This should not be hard to grok. >>> >>> >>>> Do you acknowledge this? >>> >>> This seems like pure noise, to cover up that you were sputing a lot of >>> incorrect statements earlier. >> >> No, I'm just trying to clarify what you are trying to say. The above >> statement did not appear to accord with your later statement: 'if you >> thought about it you would mean a simple "try/else". "finally" is >> always executed. which is incorrect for cleanup.' It turns out that >> what you really meant was that it would be incorrect for cleanup to be >> executed when an error occurred in the chdir() itself. >> >> Now, I happen to disagree with that. > > Well, I was pretty unclear, almost hint-like, sorry about that, mea > culpa, but you have it slightly wrong. You wrote then "The example you > gave is definitely equivalent to the try: finally: that Mike posted." > And it isn't. I agree that it does behave differently with respect to when an exception is raised in chdir(). I was wrong on that point. I thought you were claiming that it behaved differently when there was an exception in the "# Do other stuff" block because you were being (and are still being) unclear. >> There are a couple of ways to do this kind of cleanup depending on the >> situation. Basically, you have several different code blocks: >> >> # 1. Record original state. >> # 2. Modify state. >> # 3. Do stuff requiring the modified state. >> # 4. Revert to the original state. >> >> Depending on where errors are expected to occur, and how the state >> needs to get modified and restored, there are different ways of >> arranging these blocks. The one Mike showed: >> >> # 1. Record original state. >> try: >> # 2. Modify state. >> # 3. Do stuff requiring the modified state. >> finally: >> # 4. Revert to the original state. >> >> And the one you prefer: >> >> # 1. Record original state. >> # 2. Modify state. >> try: >> # 3. Do stuff requiring the modified state. >> finally: >> # 4. Revert to the original state. >> >> These differ in what happens when an error occurs in block #2, the >> modification of the state. In Mike's, the cleanup code runs; in yours, >> it doesn't. For chdir(), it really doesn't matter. Reverting to the >> original state is harmless whether the original chdir() succeeds or >> fails, and chdir() is essentially atomic so if it raises an exception, >> the state did not change and nothing needs to be cleaned up. >> >> However, not all block #2s are atomic. Some are going to fail partway >> through and need to be cleaned up even though they raised an >> exception. Fortunately, cleanup can frequently be written to not care >> whether the whole thing finished or not. > > Yeah, and there are some systematic ways to handle these things. You > might look up Dave Abraham's levels of exception safety. Mostly his > approach boils down to making operations effectively atomic so as to > reduce the complexity: ideally, if an operation raises an exception, > then it has undone any side effects. > > Of course it can't undo the launching of an ICBM, for example... > > But ideally, if it could, then it should. I agree. Atomic operations like chdir() help a lot. But this is Python, and exceptions can happen in many different places. If you're not just calling an extension module function that makes a known-atomic system call, you run the risk of not having an atomic operation. > If you call the possibly failing operation "A", then that systematic > approach goes like this: if A fails, then it has cleaned up its own > mess, but if A succeeds, then it's the responsibility of the calling > code to clean up if the higher level (multiple statements) operation > that A is embedded in, fails. > > And that's what Marginean's original C++ ScopeGuard was designed for, > and what the corresponding Python Cleanup class is designed for. And try: finally:, for that matter. >> Both formulations can be correct (and both work perfectly fine with >> the chdir() example being used). Sometimes one is better than the >> other, and sometimes not. You can achieve both ways with either your >> Cleanup class or with try: finally:. >> >> I am still of the opinion that Cleanup is not an improvement over try: >> finally: and has the significant ugliness of forcing cleanup code into >> callables. This significantly limits what you can do in your cleanup >> code. > > Uhm, not really. :-) As I see it. Well, not being able to affect the namespace is a significant limitation. Sometimes you need to delete objects from the namespace in order to ensure that their refcounts go to zero and their cleanup code gets executed. Tracebacks will keep the namespace alive and all objects in it. -- 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 From alfps at start.no Thu Mar 4 10:48:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 16:48:41 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Jean-Michel Pichavant: > Alf P. Steinbach wrote: >>> From your post, the scope guard technique is used "to ensure some >>> desired cleanup at the end of a scope, even when the scope is exited >>> via an exception." This is precisely what the try: finally: syntax is >>> for. >> >> You'd have to nest it. That's ugly. And more importantly, now two >> people in this thread (namely you and Mike) have demonstrated that >> they do not grok the try functionality and manage to write incorrect >> code, even arguing that it's correct when informed that it's not, so >> it's a pretty fragile construct, like goto. > > You want to execute some cleanup when things go wrong, use try except. > You want to do it when things go right, use try else. You want to > cleanup no matter what happen, use try finally. > > There is no need of any Cleanup class, except for some technical > alternative concern. Have you considered that your argument applies to the "with" construct? You have probably not realized that. But let me force it on you: when would you use "with"? Check if that case is covered by your argument above. Now that you've been told about the "with" angle, don't you think it's a kind of weakness in your argument that it calls for removing "with" from the language? I recommend that you think about why your argument is invalid. Or, as I like to say, why your argument is completely bogus. Cheers & hth., - Alf From joe.hrbek at gmail.com Thu Mar 4 10:57:18 2010 From: joe.hrbek at gmail.com (Sneaky Wombat) Date: Thu, 4 Mar 2010 07:57:18 -0800 (PST) Subject: loop over list and process into groups Message-ID: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> [ {'vlan_or_intf': 'VLAN2021'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2022'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi7/33'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2051'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'}, {'vlan_or_intf': 'VLAN2052'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'},] I want it to be converted to: [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] I was going to write a def to loop through and look for certain pre- compiled regexs, and then put them in a new dictionary and append to a list, but I'm having trouble thinking of a good way to capture each dictionary. Each dictionary will have a key that is the vlan and the value will be a list of interfaces that participate in that vlan. Each list will be variable, many containing only one interface and some containing many interfaces. I thought about using itertools, but i only use that for fixed data. I don't know of a good way to loop over variably sized data. I was wondering if anyone had any ideas about a good way to convert this list or dictionary into the right format that I need. The solution I come up with will most likely be ugly and error prone, so I thought i'd ask this python list while I work. Hopefully I learn a better way to solve this problem. Thanks! I also have the data in a list, [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] From robert.kern at gmail.com Thu Mar 4 11:04:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 10:04:02 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: > * Jean-Michel Pichavant: >> Alf P. Steinbach wrote: >>>> From your post, the scope guard technique is used "to ensure some >>>> desired cleanup at the end of a scope, even when the scope is exited >>>> via an exception." This is precisely what the try: finally: syntax >>>> is for. >>> >>> You'd have to nest it. That's ugly. And more importantly, now two >>> people in this thread (namely you and Mike) have demonstrated that >>> they do not grok the try functionality and manage to write incorrect >>> code, even arguing that it's correct when informed that it's not, so >>> it's a pretty fragile construct, like goto. >> >> You want to execute some cleanup when things go wrong, use try except. >> You want to do it when things go right, use try else. You want to >> cleanup no matter what happen, use try finally. >> >> There is no need of any Cleanup class, except for some technical >> alternative concern. > > Have you considered that your argument applies to the "with" construct? > > You have probably not realized that. > > But let me force it on you: when would you use "with"? When there is a specific context manager that removes the need for boilerplate. > Check if that case is covered by your argument above. > > Now that you've been told about the "with" angle, don't you think it's a > kind of weakness in your argument that it calls for removing "with" from > the language? No, it only argues that "with Cleanup():" is supernumerary. -- 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 From python at mrabarnett.plus.com Thu Mar 4 11:14:01 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Mar 2010 16:14:01 +0000 Subject: My four-yorkshireprogrammers contribution In-Reply-To: <7v9e3rFl7mU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> Message-ID: <4B8FDC49.5070801@mrabarnett.plus.com> Gregory Ewing wrote: > MRAB wrote: > >> Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment >> display, which I had to solder together, and also make my own power >> supply. I had the extra RAM and the I/O chip, so that's 256B (including >> the memory used by the monitor) + 256B additional RAM + 128B more in the >> I/O chip. > > Luxury! Mine was a Miniscamp, based on a design published in > Electronics Australia in the 70s. 256 bytes RAM, 8 switches > for input, 8 LEDs for output. No ROM -- program had to be > toggled in each time. > > Looked something like this: > > http://oldcomputermuseum.com/mini_scamp.html > > except that mine wasn't built from a kit and didn't look > quite as professional as that one. > [snip] By the standards of just a few years later, that's not so much a microcomputer as a nanocomputer! I was actually interested in electronics at the time, and it was such things as Mk14 which lead me into computing. From jeanmichel at sequans.com Thu Mar 4 11:32:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 17:32:10 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <4B8FE08A.60005@sequans.com> Alf P. Steinbach wrote: > * Jean-Michel Pichavant: >> Alf P. Steinbach wrote: >>>> From your post, the scope guard technique is used "to ensure some >>>> desired cleanup at the end of a scope, even when the scope is >>>> exited via an exception." This is precisely what the try: finally: >>>> syntax is for. >>> >>> You'd have to nest it. That's ugly. And more importantly, now two >>> people in this thread (namely you and Mike) have demonstrated that >>> they do not grok the try functionality and manage to write incorrect >>> code, even arguing that it's correct when informed that it's not, so >>> it's a pretty fragile construct, like goto. >> >> You want to execute some cleanup when things go wrong, use try >> except. You want to do it when things go right, use try else. You >> want to cleanup no matter what happen, use try finally. >> >> There is no need of any Cleanup class, except for some technical >> alternative concern. > > Have you considered that your argument applies to the "with" construct? > > You have probably not realized that. > > But let me force it on you: when would you use "with"? > > Check if that case is covered by your argument above. > > Now that you've been told about the "with" angle, don't you think it's > a kind of weakness in your argument that it calls for removing "with" > from the language? > > I recommend that you think about why your argument is invalid. > > Or, as I like to say, why your argument is completely bogus. > > > Cheers & hth., > > - Alf I am using python 2.5, so I know nothing about the with statement, and it may possible my arguments apply to it, you could remove it from the language, it wouldn't bother me at all. I just don't see in what you've written (adding a class, with some __entry__, __exit__ protocol, using a with statement) what cannot be achieved with a try statement in its simpliest form. Try except may be lame and noobish, but it works, is easy to read and understood at first glance. It looks like to me that 'with' statements are like decorators: overrated. Sometimes people could write simple readable code, but yet they're tempted by the geek side of programming: using complex constructs when there's no need to. I myself cannot resist sometimes ;-) JM From steve at holdenweb.com Thu Mar 4 11:32:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 11:32:11 -0500 Subject: How to login https sever with inputing account name and password? In-Reply-To: <20100304103731.740AC40E@smtpcom.263xmail.com> References: <20100304103731.740AC40E@smtpcom.263xmail.com> Message-ID: Karen Wang wrote: > Hi all, > > I want to use python to access to https server, like > ?https://212.218.229.10/chinatest/? > > If open it from IE, will see the pop-up login windows like this > > I tried several ways but always only get page for? HTTP Error 401.2 ? > Unauthorized? error. ( myusername and mypassword are all correct) > > Below is my code: > > import urllib2 > > values = { > > 'user' : "myusername", > > ?pass' : "mypassword" } > > data = urllib2.urlencode(values) > > t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) > > print t.read() > > where I am wrong ? > Read the HTTP standard. The authentication data has to be send as HTTP headers, not as the data to a POST request. The dialog box you see is the browser attempting to collect the data it needs to put in the header. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at bdurham.com Thu Mar 4 11:37:31 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 04 Mar 2010 11:37:31 -0500 Subject: My four-yorkshireprogrammers contribution In-Reply-To: <4B8FDC49.5070801@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> <4B8FDC49.5070801@mrabarnett.plus.com> Message-ID: <1267720651.17005.1363119347@webmail.messagingengine.com> Not to out do you guys, but over here in the states, I started out with a Radio Shack 'computer' that consisted of 10 slideable switches and 10 flashlight bulbs. You ran wires betweens the slideable switches to create 'programs'. Wish I could remember what this thing was called - my google-fu fails me. This was approx 1976 when Popular Science's ELF-1 with 256 bytes was quite a sensation. Cheers, Malcolm From magnicida at gmail.com Thu Mar 4 11:51:21 2010 From: magnicida at gmail.com (Juan Pedro Bolivar Puente) Date: Thu, 04 Mar 2010 18:51:21 +0200 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: On 04/03/10 16:21, ccc31807 wrote: > On Mar 3, 4:55 pm, toby wrote: >>> where you have to store data and >> >> "relational data" > > Data is neither relational nor unrelational. Data is data. > Relationships are an artifact, something we impose on the data. > Relations are for human convenience, not something inherent in the > data itself. > No, relations are data. "Data is data" says nothing. Data is information. Actually, all data are relations: relating /values/ to /properties/ of /entities/. Relations as understood by the "relational model" is nothing else but assuming that properties and entities are first class values of the data system and the can also be related. JP From mrkafk at gmail.com Thu Mar 4 11:55:10 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 17:55:10 +0100 Subject: loop over list and process into groups In-Reply-To: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: Sneaky Wombat wrote: > I was going to write a def to loop through and look for certain pre- > compiled regexs, and then put them in a new dictionary and append to a > list, regexes are overkill in this case I think. > [ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] Why not construct an intermediate dictionary? elems = [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] def makeintermdict(elems): vd = {} vlan = None for el in elems: if el.startswith('VLAN'): vlan = el.replace('VLAN','') elif el == 'Interface': vd[vlan] = [] else: vd[vlan].append(el) return vd def makelist(interm): finlist = [] for k in interm.keys(): finlist.append({k:interm[k]}) return finlist if __name__ == "__main__": intermediate = makeintermdict(elems) print intermediate finlist = makelist(intermediate) print 'final', finlist {'4068': ['Gi9/6'], '4069': ['Gi9/6'], '4065': ['Gi9/6', 'Po2', 'Po3', 'Po306']} final [{'4068': ['Gi9/6']}, {'4069': ['Gi9/6']}, {'4065': ['Gi9/6', 'Po2', 'Po3', 'Po306']}] I hope this is not your homework. :-) Regards, mk From alfps at start.no Thu Mar 4 11:56:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 17:56:34 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >> * Robert Kern: [snip] >>> can you >>> understand why we might think that you were saying that try: finally: >>> was wrong and that you were proposing that your code was equivalent to >>> some try: except: else: suite? >> >> No, not really. His code didn't match the semantics. Changing 'finally' >> to 'else' could make it equivalent. > > Okay, please show me what you mean by "changing 'finally' to 'else'." I > think you are being hinty again. It's not helpful. [snip middle of this paragraph] > Why do you think that we would interpret those words > to mean that you wanted the example you give just above? There's an apparent discrepancy between your call for an example and your subsequent (in the same paragraph) reference to the example given. But as to why I assumed that that example, or a similar correct one, would be implied, it's the only meaningful interpretation. Adopting a meaningless interpretation when a meaningful exists is generally just adversarial, but in this case I was, as you pointed out, extremely unclear, and I'm sorry: I should have given such example up front. Will try to do so. [snip] > >>> There are a couple of ways to do this kind of cleanup depending on the >>> situation. Basically, you have several different code blocks: >>> >>> # 1. Record original state. >>> # 2. Modify state. >>> # 3. Do stuff requiring the modified state. >>> # 4. Revert to the original state. >>> >>> Depending on where errors are expected to occur, and how the state >>> needs to get modified and restored, there are different ways of >>> arranging these blocks. The one Mike showed: >>> >>> # 1. Record original state. >>> try: >>> # 2. Modify state. >>> # 3. Do stuff requiring the modified state. >>> finally: >>> # 4. Revert to the original state. >>> >>> And the one you prefer: >>> >>> # 1. Record original state. >>> # 2. Modify state. >>> try: >>> # 3. Do stuff requiring the modified state. >>> finally: >>> # 4. Revert to the original state. >>> >>> These differ in what happens when an error occurs in block #2, the >>> modification of the state. In Mike's, the cleanup code runs; in yours, >>> it doesn't. For chdir(), it really doesn't matter. Reverting to the >>> original state is harmless whether the original chdir() succeeds or >>> fails, and chdir() is essentially atomic so if it raises an exception, >>> the state did not change and nothing needs to be cleaned up. >>> >>> However, not all block #2s are atomic. Some are going to fail partway >>> through and need to be cleaned up even though they raised an >>> exception. Fortunately, cleanup can frequently be written to not care >>> whether the whole thing finished or not. >> >> Yeah, and there are some systematic ways to handle these things. You >> might look up Dave Abraham's levels of exception safety. Mostly his >> approach boils down to making operations effectively atomic so as to >> reduce the complexity: ideally, if an operation raises an exception, >> then it has undone any side effects. >> >> Of course it can't undo the launching of an ICBM, for example... >> >> But ideally, if it could, then it should. > > I agree. Atomic operations like chdir() help a lot. But this is Python, > and exceptions can happen in many different places. If you're not just > calling an extension module function that makes a known-atomic system > call, you run the risk of not having an atomic operation. > >> If you call the possibly failing operation "A", then that systematic >> approach goes like this: if A fails, then it has cleaned up its own >> mess, but if A succeeds, then it's the responsibility of the calling >> code to clean up if the higher level (multiple statements) operation >> that A is embedded in, fails. >> >> And that's what Marginean's original C++ ScopeGuard was designed for, >> and what the corresponding Python Cleanup class is designed for. > > And try: finally:, for that matter. Not to mention "with". Some other poster made the same error recently in this thread; it is a common fallacy in discussions about programming, to assume that since the same can be expressed using lower level constructs, those are all that are required. If adopted as true it ultimately means the removal of all control structures above the level of "if" and "goto" (except Python doesn't have "goto"). >>> Both formulations can be correct (and both work perfectly fine with >>> the chdir() example being used). Sometimes one is better than the >>> other, and sometimes not. You can achieve both ways with either your >>> Cleanup class or with try: finally:. >>> >>> I am still of the opinion that Cleanup is not an improvement over try: >>> finally: and has the significant ugliness of forcing cleanup code into >>> callables. This significantly limits what you can do in your cleanup >>> code. >> >> Uhm, not really. :-) As I see it. > > Well, not being able to affect the namespace is a significant > limitation. Sometimes you need to delete objects from the namespace in > order to ensure that their refcounts go to zero and their cleanup code > gets executed. Just a nit (I agree that a lambda can't do this, but as to what's required): assigning None is sufficient for that[1]. However, note that the current language doesn't guarantee such cleanup, at least as far as I know. So while it's good practice to support it, to do everything to let it happen, it's presumably bad practice to rely on it happening. > Tracebacks will keep the namespace alive and all objects > in it. Thanks!, I hadn't thought of connecting that to general cleanup actions. It limits the use of general "with" in the same way. Cheers, - Alf Notes: [1] An 'except' clause deletes variables, but since it has no knowledge of the code it's placed in the only alternatives would be a presumably costly check of prior existence, or letting it pollute the namespace. From robert.kern at gmail.com Thu Mar 4 12:00:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 11:00:32 -0600 Subject: A "scopeguard" for Python In-Reply-To: <4B8FE08A.60005@sequans.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <4B8FE08A.60005@sequans.com> Message-ID: On 2010-03-04 10:32 AM, Jean-Michel Pichavant wrote: > Alf P. Steinbach wrote: >> * Jean-Michel Pichavant: >>> Alf P. Steinbach wrote: >>>>> From your post, the scope guard technique is used "to ensure some >>>>> desired cleanup at the end of a scope, even when the scope is >>>>> exited via an exception." This is precisely what the try: finally: >>>>> syntax is for. >>>> >>>> You'd have to nest it. That's ugly. And more importantly, now two >>>> people in this thread (namely you and Mike) have demonstrated that >>>> they do not grok the try functionality and manage to write incorrect >>>> code, even arguing that it's correct when informed that it's not, so >>>> it's a pretty fragile construct, like goto. >>> >>> You want to execute some cleanup when things go wrong, use try >>> except. You want to do it when things go right, use try else. You >>> want to cleanup no matter what happen, use try finally. >>> >>> There is no need of any Cleanup class, except for some technical >>> alternative concern. >> >> Have you considered that your argument applies to the "with" construct? >> >> You have probably not realized that. >> >> But let me force it on you: when would you use "with"? >> >> Check if that case is covered by your argument above. >> >> Now that you've been told about the "with" angle, don't you think it's >> a kind of weakness in your argument that it calls for removing "with" >> from the language? >> >> I recommend that you think about why your argument is invalid. >> >> Or, as I like to say, why your argument is completely bogus. >> >> >> Cheers & hth., >> >> - Alf > I am using python 2.5, so I know nothing about the with statement, You can try it out using "from __future__ import with_statement". > and > it may possible my arguments apply to it, you could remove it from the > language, it wouldn't bother me at all. > I just don't see in what you've written (adding a class, with some > __entry__, __exit__ protocol, using a with statement) what cannot be > achieved with a try statement in its simpliest form. > > Try except may be lame and noobish, but it works, is easy to read and > understood at first glance. > It looks like to me that 'with' statements are like decorators: > overrated. Sometimes people could write simple readable code, but yet > they're tempted by the geek side of programming: using complex > constructs when there's no need to. I myself cannot resist sometimes ;-) PEP 343 is a good introduction to the real uses of the with: statement. http://www.python.org/dev/peps/pep-0343/ Basically, it allows you to package up your initialization and cleanup code into objects, stick them in your library, unit test them thoroughly, etc. so you don't have to repeat them everywhere and possibly get them wrong. It's DRY in action. Where Alf's Cleanup class goes wrong, in my opinion, is that it does not package up any code to avoid repetition. You still repeat the same cleanup code everywhere you use it, so it is no better than try: finally:. It is not a real use case of the with: statement. -- 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 From alfps at start.no Thu Mar 4 12:02:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 18:02:23 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: >> * Jean-Michel Pichavant: >>> Alf P. Steinbach wrote: >>>>> From your post, the scope guard technique is used "to ensure some >>>>> desired cleanup at the end of a scope, even when the scope is exited >>>>> via an exception." This is precisely what the try: finally: syntax >>>>> is for. >>>> >>>> You'd have to nest it. That's ugly. And more importantly, now two >>>> people in this thread (namely you and Mike) have demonstrated that >>>> they do not grok the try functionality and manage to write incorrect >>>> code, even arguing that it's correct when informed that it's not, so >>>> it's a pretty fragile construct, like goto. >>> >>> You want to execute some cleanup when things go wrong, use try except. >>> You want to do it when things go right, use try else. You want to >>> cleanup no matter what happen, use try finally. >>> >>> There is no need of any Cleanup class, except for some technical >>> alternative concern. >> >> Have you considered that your argument applies to the "with" construct? >> >> You have probably not realized that. >> >> But let me force it on you: when would you use "with"? > > When there is a specific context manager that removes the need for > boilerplate. That's "cleanup no matter what happen". >> Check if that case is covered by your argument above. >> >> Now that you've been told about the "with" angle, don't you think it's a >> kind of weakness in your argument that it calls for removing "with" from >> the language? > > No, it only argues that "with Cleanup():" is supernumerary. I don't know what "supernumerary" means, but to the degree that the argument says anything about a construct that is not 'finally', it says the same about general "with". So whatever you mean by supernumerary, you're saying that the argument implies that "with" is supernumerary. This is starting to look like some earlier discussions in this group, where even basic logic is denied. Cheers, - Alf From robert.kern at gmail.com Thu Mar 4 12:20:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 11:20:20 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >>> * Robert Kern: > [snip] >>>> can you >>>> understand why we might think that you were saying that try: finally: >>>> was wrong and that you were proposing that your code was equivalent to >>>> some try: except: else: suite? >>> >>> No, not really. His code didn't match the semantics. Changing 'finally' >>> to 'else' could make it equivalent. >> >> Okay, please show me what you mean by "changing 'finally' to 'else'." >> I think you are being hinty again. It's not helpful. > [snip middle of this paragraph] >> Why do you think that we would interpret those words to mean that you >> wanted the example you give just above? > > There's an apparent discrepancy between your call for an example and > your subsequent (in the same paragraph) reference to the example given. > > But as to why I assumed that that example, or a similar correct one, > would be implied, it's the only meaningful interpretation. > > Adopting a meaningless interpretation when a meaningful exists is > generally just adversarial, but in this case I was, as you pointed out, > extremely unclear, and I'm sorry: I should have given such example up > front. Will try to do so. Thank you. I appreciate it. > [snip] >> >>>> There are a couple of ways to do this kind of cleanup depending on the >>>> situation. Basically, you have several different code blocks: >>>> >>>> # 1. Record original state. >>>> # 2. Modify state. >>>> # 3. Do stuff requiring the modified state. >>>> # 4. Revert to the original state. >>>> >>>> Depending on where errors are expected to occur, and how the state >>>> needs to get modified and restored, there are different ways of >>>> arranging these blocks. The one Mike showed: >>>> >>>> # 1. Record original state. >>>> try: >>>> # 2. Modify state. >>>> # 3. Do stuff requiring the modified state. >>>> finally: >>>> # 4. Revert to the original state. >>>> >>>> And the one you prefer: >>>> >>>> # 1. Record original state. >>>> # 2. Modify state. >>>> try: >>>> # 3. Do stuff requiring the modified state. >>>> finally: >>>> # 4. Revert to the original state. >>>> >>>> These differ in what happens when an error occurs in block #2, the >>>> modification of the state. In Mike's, the cleanup code runs; in yours, >>>> it doesn't. For chdir(), it really doesn't matter. Reverting to the >>>> original state is harmless whether the original chdir() succeeds or >>>> fails, and chdir() is essentially atomic so if it raises an exception, >>>> the state did not change and nothing needs to be cleaned up. >>>> >>>> However, not all block #2s are atomic. Some are going to fail partway >>>> through and need to be cleaned up even though they raised an >>>> exception. Fortunately, cleanup can frequently be written to not care >>>> whether the whole thing finished or not. >>> >>> Yeah, and there are some systematic ways to handle these things. You >>> might look up Dave Abraham's levels of exception safety. Mostly his >>> approach boils down to making operations effectively atomic so as to >>> reduce the complexity: ideally, if an operation raises an exception, >>> then it has undone any side effects. >>> >>> Of course it can't undo the launching of an ICBM, for example... >>> >>> But ideally, if it could, then it should. >> >> I agree. Atomic operations like chdir() help a lot. But this is >> Python, and exceptions can happen in many different places. If you're >> not just calling an extension module function that makes a >> known-atomic system call, you run the risk of not having an atomic >> operation. >> >>> If you call the possibly failing operation "A", then that systematic >>> approach goes like this: if A fails, then it has cleaned up its own >>> mess, but if A succeeds, then it's the responsibility of the calling >>> code to clean up if the higher level (multiple statements) operation >>> that A is embedded in, fails. >>> >>> And that's what Marginean's original C++ ScopeGuard was designed for, >>> and what the corresponding Python Cleanup class is designed for. >> >> And try: finally:, for that matter. > > Not to mention "with". > > Some other poster made the same error recently in this thread; it is a > common fallacy in discussions about programming, to assume that since > the same can be expressed using lower level constructs, those are all > that are required. > > If adopted as true it ultimately means the removal of all control > structures above the level of "if" and "goto" (except Python doesn't > have "goto"). What I'm trying to explain is that the with: statement has a use even if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: does not mean that the with: statement doesn't improve on try: finally:. >>>> Both formulations can be correct (and both work perfectly fine with >>>> the chdir() example being used). Sometimes one is better than the >>>> other, and sometimes not. You can achieve both ways with either your >>>> Cleanup class or with try: finally:. >>>> >>>> I am still of the opinion that Cleanup is not an improvement over try: >>>> finally: and has the significant ugliness of forcing cleanup code into >>>> callables. This significantly limits what you can do in your cleanup >>>> code. >>> >>> Uhm, not really. :-) As I see it. >> >> Well, not being able to affect the namespace is a significant >> limitation. Sometimes you need to delete objects from the namespace in >> order to ensure that their refcounts go to zero and their cleanup code >> gets executed. > > Just a nit (I agree that a lambda can't do this, but as to what's > required): assigning None is sufficient for that[1]. Yes, but no callable is going to allow you to assign None to names in that namespace, either. Not without sys._getframe() hackery, in any case. > However, note that the current language doesn't guarantee such cleanup, > at least as far as I know. > > So while it's good practice to support it, to do everything to let it > happen, it's presumably bad practice to rely on it happening. > > >> Tracebacks will keep the namespace alive and all objects in it. > > Thanks!, I hadn't thought of connecting that to general cleanup actions. > > It limits the use of general "with" in the same way. Not really. It's easy to write context managers that do that. You put the initialization code in the __enter__() method, assign whatever objects you want to keep around through the with: clause as attributes on the manager, then delete those attributes in the __exit__(). Or, you use the @contextmanager decorator to turn a generator into a context manager, and you just assign to local variables and del them in the finally: clause. What you can't do is write a generic context manager where the initialization happens inside the with: clause and the cleanup actions are registered callables. That does not allow you to affect the namespace. -- 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 From lbolla at gmail.com Thu Mar 4 12:29:46 2010 From: lbolla at gmail.com (lbolla) Date: Thu, 4 Mar 2010 09:29:46 -0800 (PST) Subject: memory usage, temporary and otherwise References: Message-ID: <41c42ec5-1939-48f8-84e3-b8748161b524@g28g2000yqh.googlegroups.com> On Mar 4, 12:24?pm, Duncan Booth wrote: > > ?>>> a={} > ?>>> for i in range(10000000): > ... ? ? a[i]=intern('spam'*10) > "intern": another name borrowed from Lisp? From robert.kern at gmail.com Thu Mar 4 12:30:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 11:30:03 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 11:02 AM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: >>> * Jean-Michel Pichavant: >>>> Alf P. Steinbach wrote: >>>>>> From your post, the scope guard technique is used "to ensure some >>>>>> desired cleanup at the end of a scope, even when the scope is exited >>>>>> via an exception." This is precisely what the try: finally: syntax >>>>>> is for. >>>>> >>>>> You'd have to nest it. That's ugly. And more importantly, now two >>>>> people in this thread (namely you and Mike) have demonstrated that >>>>> they do not grok the try functionality and manage to write incorrect >>>>> code, even arguing that it's correct when informed that it's not, so >>>>> it's a pretty fragile construct, like goto. >>>> >>>> You want to execute some cleanup when things go wrong, use try except. >>>> You want to do it when things go right, use try else. You want to >>>> cleanup no matter what happen, use try finally. >>>> >>>> There is no need of any Cleanup class, except for some technical >>>> alternative concern. >>> >>> Have you considered that your argument applies to the "with" construct? >>> >>> You have probably not realized that. >>> >>> But let me force it on you: when would you use "with"? >> >> When there is a specific context manager that removes the need for >> boilerplate. > > That's "cleanup no matter what happen". For the "# Do stuff" block, yes. For the initialization block, you can write a context manager to do it either way, as necessary. >>> Check if that case is covered by your argument above. >>> >>> Now that you've been told about the "with" angle, don't you think it's a >>> kind of weakness in your argument that it calls for removing "with" from >>> the language? >> >> No, it only argues that "with Cleanup():" is supernumerary. > > I don't know what "supernumerary" means, http://www.merriam-webster.com/dictionary/supernumerary > but to the degree that the > argument says anything about a construct that is not 'finally', it says > the same about general "with". He's ignorant of the use cases of the with: statement, true. Given only your example of the with: statement, it is hard to fault him for thinking that try: finally: wouldn't suffice. -- 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 From joe.hrbek at gmail.com Thu Mar 4 12:41:45 2010 From: joe.hrbek at gmail.com (Sneaky Wombat) Date: Thu, 4 Mar 2010 09:41:45 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: On Mar 4, 10:55?am, mk wrote: > Sneaky Wombat wrote: > > I was going to write a def to loop through and look for certain pre- > > compiled regexs, and then put them in a new dictionary and append to a > > list, > > regexes are overkill in this case I think. > > > [ 'VLAN4065', > > ?'Interface', > > ?'Gi9/6', > > ?'Po2', > > ?'Po3', > > ?'Po306', > > ?'VLAN4068', > > ?'Interface', > > ?'Gi9/6', > > ?'VLAN4069', > > ?'Interface', > > ?'Gi9/6',] > > Why not construct an intermediate dictionary? > > elems = [ 'VLAN4065', > ? 'Interface', > ? 'Gi9/6', > ? 'Po2', > ? 'Po3', > ? 'Po306', > ? 'VLAN4068', > ? 'Interface', > ? 'Gi9/6', > ? 'VLAN4069', > ? 'Interface', > ? 'Gi9/6',] > > def makeintermdict(elems): > ? ? ?vd = {} > ? ? ?vlan = None > ? ? ?for el in elems: > ? ? ? ? ?if el.startswith('VLAN'): > ? ? ? ? ? ? ?vlan = el.replace('VLAN','') > ? ? ? ? ?elif el == 'Interface': > ? ? ? ? ? ? ?vd[vlan] = [] > ? ? ? ? ?else: > ? ? ? ? ? ? ?vd[vlan].append(el) > ? ? ?return vd > > def makelist(interm): > ? ? ?finlist = [] > ? ? ?for k in interm.keys(): > ? ? ? ? ?finlist.append({k:interm[k]}) > ? ? ?return finlist > > if __name__ == "__main__": > ? ? ?intermediate = makeintermdict(elems) > ? ? ?print intermediate > ? ? ?finlist = makelist(intermediate) > ? ? ?print 'final', finlist > > {'4068': ['Gi9/6'], '4069': ['Gi9/6'], '4065': ['Gi9/6', 'Po2', 'Po3', > 'Po306']} > final [{'4068': ['Gi9/6']}, {'4069': ['Gi9/6']}, {'4065': ['Gi9/6', > 'Po2', 'Po3', 'Po306']}] > > I hope this is not your homework. :-) > > Regards, > mk Thanks mk, My approach was a lot more complex than yours, but your's is better. I like itertools and was using islice to create tuples for (start,end) string slicing. Too much work though. Thanks! -j From gneuner2 at comcast.net Thu Mar 4 12:44:23 2010 From: gneuner2 at comcast.net (George Neuner) Date: Thu, 04 Mar 2010 12:44:23 -0500 Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: <6iqvo5hvlnpci5oi5rgs1ohpj085s12o6n@4ax.com> On Thu, 04 Mar 2010 18:51:21 +0200, Juan Pedro Bolivar Puente wrote: >On 04/03/10 16:21, ccc31807 wrote: >> On Mar 3, 4:55 pm, toby wrote: >>>> where you have to store data and >>> >>> "relational data" >> >> Data is neither relational nor unrelational. Data is data. >> Relationships are an artifact, something we impose on the data. >> Relations are for human convenience, not something inherent in the >> data itself. >> > >No, relations are data. "Data is data" says nothing. Data is >information. Actually, all data are relations: relating /values/ to >/properties/ of /entities/. Relations as understood by the "relational >model" is nothing else but assuming that properties and entities are >first class values of the data system and the can also be related. Well ... sort of. Information is not data but rather the understanding of something represented by the data. The term "information overload" is counter-intuitive ... it really means an excess of data for which there is little understanding. Similarly, at the level to which you are referring, a relation is not data but simply a theoretical construct. At this level testable properties or instances of the relation are data, but the relation itself is not. The relation may be data at a higher level. George From spamfresser at ch3ka.de Thu Mar 4 12:50:32 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 18:50:32 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Am 04.03.2010 18:20, schrieb Robert Kern: > > What I'm trying to explain is that the with: statement has a use even if > Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: > does not mean that the with: statement doesn't improve on try: finally:. Yes, the with-statement rocks :) I suggested such a thing a few days ago in another thread, where OP wanted a "silent" keyword like: silent: do_stuff() would be equivalent to: try: do_stuff() except: pass Of course catching *all* exceptions was a bad idea, so I came up with the code below and now I actually like it and use it myself :) ---------snip--------- To your first question about a "silenced" keyword: you could emulate this with context managers I guess. Something like (untested, just a quick mockup how it could look): class silenced: def __init__(self, *silenced): self.exceptions=tuple(silenced) #just to be explicit def __enter__(self): return self #dito def __exit__(self, type, value, traceback): for ex in self.exceptions: if isinstance(value, ex): return True #supresses exception So: with silenced(os.Error): os.remove(somefile) Would translate to: try: os.remove(somefile) except os.Error: pass One nice thing about this approach would be that you can alias a set of exceptions with this: idontcareabouttheseerrors=silenced(TypeError, ValueError, PEBCAKError, SyntaxError, EndOfWorldError, 1D10T_Error) with idontcareabouttheseerrors: do_stuff() Regards, Michael From cartercc at gmail.com Thu Mar 4 12:52:06 2010 From: cartercc at gmail.com (ccc31807) Date: Thu, 4 Mar 2010 09:52:06 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: <7bfeffcd-722e-4df4-8455-7710207d9c7e@a18g2000yqc.googlegroups.com> On Mar 4, 11:51?am, Juan Pedro Bolivar Puente wrote: > No, relations are data. This depends on your definition of 'data.' I would say that relationships is information gleaned from the data. > "Data is data" says nothing. Data is > information. To me, data and information are not the same thing, and in particular, data is NOT information. To me, information consists of the sifting, sorting, filtering, and rearrangement of data that can be useful in completing some task. As an illustration, consider some very large collection of ones and zeros -- the information it contains depends on whether it's views as a JPEG, an EXE, XML, WAV, or other sort of information processing device. Whichever way it's processed, the 'data' (the ones and zeros) stay the same, and do not constitute 'information' in their raw state. > Actually, all data are relations: relating /values/ to > /properties/ of /entities/. Relations as understood by the "relational > model" is nothing else but assuming that properties and entities are > first class values of the data system and the can also be related. Well, this sort of illustrates my point. The 'values' of 'properties' relating to specific 'entities' depends on how one processes the data, which can be processed various ways. For example, 10000001 can either be viewed as the decimal number 65 or the alpha character 'A' but the decision as to how to view this value isn't inherent in the data itself, but only as an artifact of our use of the data to turn it into information. CC. From spamfresser at ch3ka.de Thu Mar 4 12:55:18 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 18:55:18 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Am 04.03.2010 17:32, schrieb Jean-Michel Pichavant: > It looks like to me that 'with' statements are like decorators: overrated. Oh no, you just insulted my favourite two python features, followed immediately by generators, iterators and list comprehensions / generator expressions :p No, really: they *are* great ;D Regards, Michael From gnewsg at gmail.com Thu Mar 4 12:57:40 2010 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 4 Mar 2010 09:57:40 -0800 (PST) Subject: ANN: psutil 0.1.3 released Message-ID: <39a8f505-2caa-4592-a359-9731e20002eb@y17g2000yqd.googlegroups.com> Hi, I'm pleased to announce the 0.1.3 release of psutil: http://code.google.com/p/psutil === About === psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by tools like ps, top and Windows task manager. It currently supports Linux, OS X, FreeBSD and Windows with Python versions from 2.4 to 3.1 by using a unique code base. === Major enhancements === * Python 3 support * per-process username * suspend / resume process * per-process current working directory (Windows and Linux only) * added support for Windows 7 and FreeBSD 64 bit === Links === * Home page: http://code.google.com/p/psutil * Mailing list: http://groups.google.com/group/psutil/topics * Source tarball: http://psutil.googlecode.com/files/psutil-0.1.3.tar.gz * OS X installer: http://psutil.googlecode.com/files/psutil-0.1.3-py2.6-macosx10.4.dmg * Windows Installer (Python 2.6): http://psutil.googlecode.com/files/psutil-0.1.3.win32-py2.6.exe * Windows Installer (Python 3.1): http://psutil.googlecode.com/files/psutil-0.1.3.win32-py3.1.exe * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Thanks --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ From lbolla at gmail.com Thu Mar 4 12:59:21 2010 From: lbolla at gmail.com (lbolla) Date: Thu, 4 Mar 2010 09:59:21 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> On Mar 4, 3:57?pm, Sneaky Wombat wrote: > [ {'vlan_or_intf': 'VLAN2021'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Po1'}, > ?{'vlan_or_intf': 'Po306'}, > ?{'vlan_or_intf': 'VLAN2022'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Gi7/33'}, > ?{'vlan_or_intf': 'Po1'}, > ?{'vlan_or_intf': 'Po306'}, > ?{'vlan_or_intf': 'VLAN2051'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Gi9/6'}, > ?{'vlan_or_intf': 'VLAN2052'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Gi9/6'},] > > I want it to be converted to: > > [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] > > I was going to write a def to loop through and look for certain pre- > compiled regexs, and then put them in a new dictionary and append to a > list, but I'm having trouble thinking of a good way to capture each > dictionary. ?Each dictionary will have a key that is the vlan and the > value will be a list of interfaces that participate in that vlan. > Each list will be variable, many containing only one interface and > some containing many interfaces. > > I thought about using itertools, but i only use that for fixed data. > I don't know of a good way to loop over variably sized data. ?I was > wondering if anyone had any ideas about a good way to convert this > list or dictionary into the right format that I need. ?The solution I > come up with will most likely be ugly and error prone, so I thought > i'd ask this python list while I work. ?Hopefully I learn a better way > to solve this problem. > > Thanks! > > I also have the data in a list, > > [ 'VLAN4065', > ?'Interface', > ?'Gi9/6', > ?'Po2', > ?'Po3', > ?'Po306', > ?'VLAN4068', > ?'Interface', > ?'Gi9/6', > ?'VLAN4069', > ?'Interface', > ?'Gi9/6',] =================================== from itertools import groupby data = \ [ {'vlan_or_intf': 'VLAN2021'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2022'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi7/33'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2051'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'}, {'vlan_or_intf': 'VLAN2052'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'},] def clean_up(lst): return [d.values()[0] for d in data if d.values()[0] != 'Interface'] out = {} for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): if k: key = list(g)[0].replace('VLAN','') else: out[key] = list(g) print out =================================== hth, L. From tjreedy at udel.edu Thu Mar 4 13:03:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Mar 2010 13:03:29 -0500 Subject: memory usage, temporary and otherwise In-Reply-To: References: <4b8ee61a$0$26644$426a74cc@news.free.fr> Message-ID: On 3/4/2010 6:56 AM, mk wrote: > Bruno Desthuilliers wrote: > Huh? I was under impression that some time after 2.0 range was made to > work "under the covers" like xrange when used in a loop? Or is it 3.0 > that does that? 3.0. From john at castleamber.com Thu Mar 4 13:06:15 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Mar 2010 12:06:15 -0600 Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <87eik1ujg4.fsf@benfinney.id.au> Message-ID: <87zl2oufl4.fsf@castleamber.com> Ben Finney writes: > Terry Reedy writes: > >> On 3/3/2010 12:05 PM, John Nagle wrote: >> > CPAN is a repository. PyPi is an collection of links. >> >> As Ben said, PyPI currently is also a respository and not just links >> to other repositories. [..] >> > CPAN enforces standard organization on packages. PyPi does not. > > This is, I think, something we don't need as much in Python; there is a > fundamental difference between Perl's deeply nested namespace hierarchy > and Python's inherently flat hierarchy. Perl's hierarchy is 2 (e.g. Text::Balanced) or 3 levels deep (e.g. Text::Ngram::LanguageDetermine), rarely deeper (Text::Editor::Vip::Buffer::Plugins::Display). Which is in general most likely just one level deeper than Python. Perl is not Java. And I think that one additional level (or more) is a /must/ when you have 17,530 (at the time of writing) modules. If Python wants it's own CPAN it might be a good first move to not have modules named "xmlrpclib", "wave", "keyword", "zlib", etc. But I don't see that happen soon :-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at holdenweb.com Thu Mar 4 13:07:33 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 13:07:33 -0500 Subject: memory usage, temporary and otherwise In-Reply-To: References: Message-ID: Duncan Booth wrote: > mk wrote: > >> Hm, apparently Python didn't spot that 'spam'*10 in a's values is really >> the same string, right? > > If you want it to spot that then give it a hint that it should be looking > for identical strings: > > >>> a={} > >>> for i in range(10000000): > ... a[i]=intern('spam'*10) > > should reduce your memory use somewhat. > Better still, hoist the constant value out of the loop: >>> a={} >>> const = 'spam'*10 >>> for i in range(10000000): ... a[i] = const regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Mar 4 13:14:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 13:14:35 -0500 Subject: WANTED: A good name for the pair (args, kwargs) In-Reply-To: References: Message-ID: Jonathan Fine wrote: > Hi > > We can call a function fn using > val = fn(*args, **kwargs) > > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > Here's my use case: > def doit(fn , wibble, expect): > args, kwargs = wibble > actual = fn(*args, **kwargs) > if actual != expect: > # Something has gone wrong. > pass > > This is part of a test runner. > > For now I'll use argpair, but if anyone has a better idea, I'll use it. > Not being able to find any existing names I called *args the sequence-parameter and **kwarg the dict-parameter. For your use, though, you might choose something like the "generic parameter pair). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Thu Mar 4 13:22:32 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 19:22:32 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <4B8FFA68.20000@sequans.com> Michael Rudolf wrote: > Am 04.03.2010 17:32, schrieb Jean-Michel Pichavant: >> It looks like to me that 'with' statements are like decorators: >> overrated. > > Oh no, you just insulted my favourite two python features, followed > immediately by generators, iterators and list comprehensions / > generator expressions :p > > No, really: they *are* great ;D > > Regards, > Michael They are great, and because of that greatness some of us, including me, tend to use them where there's no point doing so. I would never state that decorators are useless anyway, not in this list, I value my life too much :-) (I'll give it a try in the perl list) JM From alfps at start.no Thu Mar 4 13:37:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 19:37:23 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] >>> >>>> If you call the possibly failing operation "A", then that systematic >>>> approach goes like this: if A fails, then it has cleaned up its own >>>> mess, but if A succeeds, then it's the responsibility of the calling >>>> code to clean up if the higher level (multiple statements) operation >>>> that A is embedded in, fails. >>>> >>>> And that's what Marginean's original C++ ScopeGuard was designed for, >>>> and what the corresponding Python Cleanup class is designed for. >>> >>> And try: finally:, for that matter. >> >> Not to mention "with". >> >> Some other poster made the same error recently in this thread; it is a >> common fallacy in discussions about programming, to assume that since >> the same can be expressed using lower level constructs, those are all >> that are required. >> >> If adopted as true it ultimately means the removal of all control >> structures above the level of "if" and "goto" (except Python doesn't >> have "goto"). > > What I'm trying to explain is that the with: statement has a use even if > Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: > does not mean that the with: statement doesn't improve on try: finally:. That's a different argument, essentially that you see no advantage for your current coding patterns. It's unconnected to the argument I responded to. The argument that I responded to, that the possibility of expressing things at the level of try:finally: means that a higher level construct is superfluous, is still meaningless. >>>>> Both formulations can be correct (and both work perfectly fine with >>>>> the chdir() example being used). Sometimes one is better than the >>>>> other, and sometimes not. You can achieve both ways with either your >>>>> Cleanup class or with try: finally:. >>>>> >>>>> I am still of the opinion that Cleanup is not an improvement over try: >>>>> finally: and has the significant ugliness of forcing cleanup code into >>>>> callables. This significantly limits what you can do in your cleanup >>>>> code. >>>> >>>> Uhm, not really. :-) As I see it. >>> >>> Well, not being able to affect the namespace is a significant >>> limitation. Sometimes you need to delete objects from the namespace in >>> order to ensure that their refcounts go to zero and their cleanup code >>> gets executed. >> >> Just a nit (I agree that a lambda can't do this, but as to what's >> required): assigning None is sufficient for that[1]. > > Yes, but no callable is going to allow you to assign None to names in > that namespace, either. Not without sys._getframe() hackery, in any case. > >> However, note that the current language doesn't guarantee such cleanup, >> at least as far as I know. >> >> So while it's good practice to support it, to do everything to let it >> happen, it's presumably bad practice to rely on it happening. >> >> >>> Tracebacks will keep the namespace alive and all objects in it. >> >> Thanks!, I hadn't thought of connecting that to general cleanup actions. >> >> It limits the use of general "with" in the same way. > > Not really. Sorry, it limits general 'with' in /exactly/ the same way. > It's easy to write context managers that do that [delete objects from the namespace]. Sorry, no can do, as far as I know; your following example quoted below is an example of /something else/. And adding on top of irrelevancy, for the pure technical aspect it can be accomplished in the same way using Cleanup (I provide an example below). However, doing that would generally be worse than pointless since with good coding practices the objects would become unreferenced anyway. > You put > the initialization code in the __enter__() method, assign whatever > objects you want to keep around through the with: clause as attributes > on the manager, then delete those attributes in the __exit__(). Analogously, if one were to do this thing, then it could be accomplished using a Cleanup context manager as follows: foo = lambda: None foo.x = create_some_object() at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) ... except that 1) for a once-only case this is less code :-) 2) it is a usage that I wouldn't recommend; instead I recommend adopting good coding practices where object references aren't kept around. > Or, you > use the @contextmanager decorator to turn a generator into a context > manager, and you just assign to local variables and del them in the > finally: clause. Uhm, you don't need a 'finally' clause when you define a context manager. Additionally, you don't need to 'del' the local variables in @contextmanager decorated generator. The local variables cease to exist automatically. > What you can't do is write a generic context manager where the > initialization happens inside the with: clause and the cleanup actions > are registered callables. That does not allow you to affect the namespace. If you mean that you can't introduce direct local variables and have them deleted by "registered callables" in a portable way, then right. But I can't think of any example where that would be relevant; in particular what matters for supporting on-destruction cleanup is whether you keep any references or not, not whether you have a local variable of any given name. And I think "with" is quite useful even with that restriction. Cheers, - Alf From pemerson at gmail.com Thu Mar 4 13:39:30 2010 From: pemerson at gmail.com (Pete Emerson) Date: Thu, 4 Mar 2010 10:39:30 -0800 (PST) Subject: Evaluate my first python script, please Message-ID: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is "perlesque" This script parses /etc/hosts for hostnames, and based on terms given on the command line (argv), either prints the list of hostnames that match all the criteria, or uses ssh to connect to the host if the number of matches is unique. I am looking for advice along the lines of "an easier way to do this" or "a more python way" (I'm sure that's asking for trouble!) or "people commonly do this instead" or "here's a slick trick" or "oh, interesting, here's my version to do the same thing". I am aware that there are performance improvements and error checking that could be made, such as making sure the file exists and is readable and precompiling the regular expressions and not calculating how many sys.argv arguments there are more than once. I'm not hyper concerned with performance or idiot proofing for this particular script. Thanks in advance. ######################################################## #!/usr/bin/python import sys, fileinput, re, os filename = '/etc/hosts' hosts = [] for line in open(filename, 'r'): match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) if match is None or re.search('^(?:float|localhost)\.', line): continue hostname = match.group(1) count = 0 for arg in sys.argv[1:]: for section in hostname.split('.'): if section == arg: count = count + 1 break if count == len(sys.argv) - 1: hosts.append(hostname) if len(hosts) == 1: os.system("ssh -A " + hosts[0]) else: print '\n'.join(hosts) From as at sci.fi Thu Mar 4 13:43:19 2010 From: as at sci.fi (Anssi Saari) Date: Thu, 04 Mar 2010 20:43:19 +0200 Subject: pyao makes the right sound but why? References: Message-ID: "'2+" writes: > dev = ao.AudioDevice('alsa') > dev.play(x) > > could launch me a semi realtime dj kinda sys > luckily .. it does seem to be making the right sound > but why? > the default of the samplerate and that 16bit happened to match with my thing x? Yes, that seems to be the case from help(ao). But I couldn't run tofu = soy.Bean() since it seems to want tit01.wav. Do you make that available somewhere? From tim.wintle at teamrubber.com Thu Mar 4 14:07:24 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 04 Mar 2010 19:07:24 +0000 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <1267729644.11093.11.camel@localhost> On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". (1) I would wrap it all in a function def main(): # your code here if __name__ == "__main__": main() (2) PEP8 (python style guidelines) suggests one import per line (3) I'd use four spaces as tab width (4) I'd change this: > for arg in sys.argv[1:]: > for section in hostname.split('.'): > if section == arg: > count = count + 1 > break to something more like: for section in hostname.split("."): if section in sys.argv[1:]: count += 1 (although as you suggested I'd only calculate sys.argv[1:] once) ... or you could replace whole section between the for loop and hosts.append with: if sorted(hostname.split(".")) == sorted(sys.argv[1:]): host.append(hostname) , at a slight loss of clarity - but I think I'd stick with the more verbose version personally. Tim From stefan_ml at behnel.de Thu Mar 4 14:10:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Mar 2010 20:10:47 +0100 Subject: Partly erratic wrong behaviour, Python 3, lxml In-Reply-To: References: Message-ID: Jussi Piitulainen, 04.03.2010 11:46: > I am observing weird semi-erratic behaviour that involves Python 3 and > lxml, is extremely sensitive to changes in the input data, and only > occurs when I name a partial result. I would like some help with this, > please. (Python 3.1.1; GNU/Linux; how do I find lxml version?) Here's how to find the version: http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do I'll give your test code a try when I get to it. However, note that the best place to discuss this is the lxml mailing list: http://codespeak.net/mailman/listinfo/lxml-dev Stefan From duncan.booth at invalid.invalid Thu Mar 4 14:15:42 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 19:15:42 GMT Subject: NoSQL Movement? References: Message-ID: mk wrote: > Duncan Booth wrote: > >> If you look at some of the uses of bigtable you may begin to >> understand the tradeoffs that are made with sql. When you use >> bigtable you have records with fields, and you have indices, but >> there are limitations on the kinds of queries you can perform: in >> particular you cannot do joins, but more subtly there is no guarantee >> that the index is up to date (so you might miss recent updates or >> even get data back from a query when the data no longer matches the >> query). > > Hmm, I do understand that bigtable is used outside of traditional > 'enterprisey' contexts, but suppose you did want to do an equivalent > of join; is it at all practical or even possible? > > I guess when you're forced to use denormalized data, you have to > simultaneously update equivalent columns across many tables yourself, > right? Or is there some machinery to assist in that? Or you avoid having to do that sort of update at all. There are many applications which simply wouldn't be applicable to bigtable. My point was that to make best use of bigtable you may have to make different decisions when designing the software. > >> By sacrificing some of SQL's power, Google get big benefits: namely >> updating data is a much more localised option. Instead of an update >> having to lock the indices while they are updated, updates to >> different records can happen simultaneously possibly on servers on >> the opposite sides of the world. You can have many, many servers all >> using the same data although they may not have identical or >> completely consistent views of that data. > > And you still have the global view of the table spread across, say, 2 > servers, one located in Australia, second in US? > More likely spread across a few thousand servers. The data migrates round the servers as required. As I understand it records are organised in groups: when you create a record you can either make it a root record or you can give it a parent record. So for example you might make all the data associated with a specific user live with the user record as a parent (or ancestor). When you access any of that data then all of it is copied onto a server near the application as all records under a common root are always stored together. >> Bigtable impacts on how you store the data: for example you need to >> avoid reducing data to normal form (no joins!), its much better and >> cheaper just to store all the data you need directly in each record. >> Also aggregate values need to be at least partly pre-computed and >> stored in the database. > > So you basically end up with a few big tables or just one big table > really? One. Did I mention that bigtable doesn't require you to have the same columns in every record? The main use of bigtable (outside of Google's internal use) is Google App Engine and that apparently uses one table. Not one table per application, one table total. It's a big table. > > Suppose on top of 'tweets' table you have 'dweebs' table, and tweets > and dweebs sometimes do interact. How would you find such interacting > pairs? Would you say "give me some tweets" to tweets table, extract > all the dweeb_id keys from tweets and then retrieve all dweebs from > dweebs table? If it is one tweet to many dweebs? Dweeb.all().filter("tweet =", tweet.key()) or: GqlQuery("SELECT * FROM Dweeb WHERE tweet = :tweet", tweet=tweet) or just make the tweet the ancestor of all its dweebs. Columns may be scalars or lists, so if it is some tweets to many dweebs you can do basically the same thing. Dweeb.all().filter("tweets =", tweet.key()) but if there are too many tweets in the list that could be a problem. If you want dweebs for several tweets you could select with "tweet IN " the list of tweets or do a separate query for each (not much difference, as I understand it the IN operator just expands into several queries internally anyway). From pruebauno at latinmail.com Thu Mar 4 14:18:49 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 4 Mar 2010 11:18:49 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> Message-ID: <865d59ab-585b-4908-be0d-e891d0a0a08b@t23g2000yqt.googlegroups.com> lbolla wrote: > On Mar 4, 3:57?pm, Sneaky Wombat wrote: > > [ {'vlan_or_intf': 'VLAN2021'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Po1'}, > > ?{'vlan_or_intf': 'Po306'}, > > ?{'vlan_or_intf': 'VLAN2022'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Gi7/33'}, > > ?{'vlan_or_intf': 'Po1'}, > > ?{'vlan_or_intf': 'Po306'}, > > ?{'vlan_or_intf': 'VLAN2051'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Gi9/6'}, > > ?{'vlan_or_intf': 'VLAN2052'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Gi9/6'},] > > > > I want it to be converted to: > > > > [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] > > > > I was going to write a def to loop through and look for certain pre- > > compiled regexs, and then put them in a new dictionary and append to a > > list, but I'm having trouble thinking of a good way to capture each > > dictionary. ?Each dictionary will have a key that is the vlan and the > > value will be a list of interfaces that participate in that vlan. > > Each list will be variable, many containing only one interface and > > some containing many interfaces. > > > > I thought about using itertools, but i only use that for fixed data. > > I don't know of a good way to loop over variably sized data. ?I was > > wondering if anyone had any ideas about a good way to convert this > > list or dictionary into the right format that I need. ?The solution I > > come up with will most likely be ugly and error prone, so I thought > > i'd ask this python list while I work. ?Hopefully I learn a better way > > to solve this problem. > > > > Thanks! > > > > I also have the data in a list, > > > > [ 'VLAN4065', > > ?'Interface', > > ?'Gi9/6', > > ?'Po2', > > ?'Po3', > > ?'Po306', > > ?'VLAN4068', > > ?'Interface', > > ?'Gi9/6', > > ?'VLAN4069', > > ?'Interface', > > ?'Gi9/6',] > > > > =================================== > > from itertools import groupby > > data = \ > [ {'vlan_or_intf': 'VLAN2021'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Po1'}, > {'vlan_or_intf': 'Po306'}, > {'vlan_or_intf': 'VLAN2022'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Gi7/33'}, > {'vlan_or_intf': 'Po1'}, > {'vlan_or_intf': 'Po306'}, > {'vlan_or_intf': 'VLAN2051'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Gi9/6'}, > {'vlan_or_intf': 'VLAN2052'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Gi9/6'},] > > def clean_up(lst): > return [d.values()[0] for d in data if d.values()[0] != 'Interface'] > > out = {} > for k, g in groupby(clean_up(data) , key=lambda s: > s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') > else: > out[key] = list(g) > > print out > =================================== > > hth, > L. Good use of groupby. Here is what I ended up coming up: from itertools import groupby laninfo=[ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] def splitgrp(s, f=[False]): f[0]^=s.startswith('VLAN') return f[0] lanlst=(list(g) for k,g in groupby(laninfo,key=splitgrp)) out={item[0][4:]:item[2:] for item in lanlst} print(out) From db3l.net at gmail.com Thu Mar 4 14:21:58 2010 From: db3l.net at gmail.com (David Bolen) Date: Thu, 04 Mar 2010 14:21:58 -0500 Subject: Generic singleton References: Message-ID: Duncan Booth writes: > It is also *everywhere* in the Python world. Unlike Java and C++, Python > even has its own built-in type for singletons. > > If you want a singleton in Python use a module. > > So the OP's original examples become: > > --- file singleton.py --- > foo = {} > bar = [] > > --- other.py --- > from singleton import foo as s1 > from singleton import foo as s2 > from singleton import bar as s3 > from singleton import bar as s4 > > ... and then use them as you wish. In the event you do use a module as a singleton container, I would advocate sticking with fully qualified names, avoiding the use of "from" imports or any other local namespace caching of references. Other code sharing the module may not update things as expected, e.g.: import singleton singleton.foo = {} at which point you've got two objects around - one in the singleton.py module namespace, and the s1/s2 referenced object in other.py. If you're confident of the usage pattern of all the using code, it may not be critical. But consistently using "singleton.foo" (or an import alias like s.foo) is a bit more robust, sticking with only one namespace to reach the singleton. -- David From python at mrabarnett.plus.com Thu Mar 4 14:30:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Mar 2010 19:30:55 +0000 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <4B900A6F.40104@mrabarnett.plus.com> Pete Emerson wrote: > I've written my first python program, and would love suggestions for > improvement. > > I'm a perl programmer and used a perl version of this program to guide > me. So in that sense, the python is "perlesque" > > This script parses /etc/hosts for hostnames, and based on terms given > on the command line (argv), either prints the list of hostnames that > match all the criteria, or uses ssh to connect to the host if the > number of matches is unique. > > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". > > I am aware that there are performance improvements and error checking > that could be made, such as making sure the file exists and is > readable and precompiling the regular expressions and not calculating > how many sys.argv arguments there are more than once. I'm not hyper > concerned with performance or idiot proofing for this particular > script. > > Thanks in advance. > > ######################################################## > #!/usr/bin/python > > import sys, fileinput, re, os > > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) Use 'raw' strings for regular expressions. 'Normal' Python string literals use backslashes in escape sequences (eg, '\n'), but so do regular expressions, and regular expressions are passed to the 're' module in strings, so that can lead to a profusion of backslashes! You could either escape the backslashes: match = re.search('\\d+\\.\\d+\\.\\d+\\.\\d+\s+(\\S+)', line) or use a raw string: match = re.search(r'\d+\.\d+\.\d+\.\d+\s+(\S+)', line) A raw string literal is just like a normal string literal, except that backslashes aren't special. > if match is None or re.search('^(?:float|localhost)\.', line): > continue It would be more 'Pythonic' to say "not match". if not match or re.search(r'^(?:float|localhost)\.', line): > hostname = match.group(1) > count = 0 > for arg in sys.argv[1:]: > for section in hostname.split('.'): > if section == arg: > count = count + 1 Shorter is: count += 1 > break > if count == len(sys.argv) - 1: > hosts.append(hostname) > > if len(hosts) == 1: > os.system("ssh -A " + hosts[0]) > else: > print '\n'.join(hosts) You're splitting the hostname repeatedly. You could split it just once, outside the outer loop, and maybe make it into a set. You could then have: host_parts = set(hostname.split('.')) count = 0 for arg in sys.argv[1:]: if arg in host_parts: count += 1 Incidentally, the re module contains a cache, so the regular expressions won't be recompiled every time (unless you have a lot of them and the re module flushes the cache). From robert.kern at gmail.com Thu Mar 4 14:37:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 13:37:29 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: > [snippety] >>>> >>>>> If you call the possibly failing operation "A", then that systematic >>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>> mess, but if A succeeds, then it's the responsibility of the calling >>>>> code to clean up if the higher level (multiple statements) operation >>>>> that A is embedded in, fails. >>>>> >>>>> And that's what Marginean's original C++ ScopeGuard was designed for, >>>>> and what the corresponding Python Cleanup class is designed for. >>>> >>>> And try: finally:, for that matter. >>> >>> Not to mention "with". >>> >>> Some other poster made the same error recently in this thread; it is a >>> common fallacy in discussions about programming, to assume that since >>> the same can be expressed using lower level constructs, those are all >>> that are required. >>> >>> If adopted as true it ultimately means the removal of all control >>> structures above the level of "if" and "goto" (except Python doesn't >>> have "goto"). >> >> What I'm trying to explain is that the with: statement has a use even >> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >> finally: does not mean that the with: statement doesn't improve on >> try: finally:. > > That's a different argument, essentially that you see no advantage for > your current coding patterns. > > It's unconnected to the argument I responded to. > > The argument that I responded to, that the possibility of expressing > things at the level of try:finally: means that a higher level construct > is superfluous, is still meaningless. I am attacking your premise that the "with Cleanup():" construct is higher level than try: finally:. It isn't. It provides the same level of abstraction as try: finally:. This is distinct from the accepted uses of the with: statement which *are* higher level than try: finally: and which do confer practical benefits over using try: finally: despite being syntactical sugar for try: finally:. >>>>>> Both formulations can be correct (and both work perfectly fine with >>>>>> the chdir() example being used). Sometimes one is better than the >>>>>> other, and sometimes not. You can achieve both ways with either your >>>>>> Cleanup class or with try: finally:. >>>>>> >>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>> try: >>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>> into >>>>>> callables. This significantly limits what you can do in your cleanup >>>>>> code. >>>>> >>>>> Uhm, not really. :-) As I see it. >>>> >>>> Well, not being able to affect the namespace is a significant >>>> limitation. Sometimes you need to delete objects from the namespace in >>>> order to ensure that their refcounts go to zero and their cleanup code >>>> gets executed. >>> >>> Just a nit (I agree that a lambda can't do this, but as to what's >>> required): assigning None is sufficient for that[1]. >> >> Yes, but no callable is going to allow you to assign None to names in >> that namespace, either. Not without sys._getframe() hackery, in any case. >> >>> However, note that the current language doesn't guarantee such cleanup, >>> at least as far as I know. >>> >>> So while it's good practice to support it, to do everything to let it >>> happen, it's presumably bad practice to rely on it happening. >>> >>> >>>> Tracebacks will keep the namespace alive and all objects in it. >>> >>> Thanks!, I hadn't thought of connecting that to general cleanup actions. >>> >>> It limits the use of general "with" in the same way. >> >> Not really. > > Sorry, it limits general 'with' in /exactly/ the same way. > >> It's easy to write context managers that do that [delete objects from >> the namespace]. > > Sorry, no can do, as far as I know; your following example quoted below > is an example of /something else/. Okay, so what do you mean by 'the use of general "with"'? I'm talking about writing a context manager or using the @contextmanager decorator to do some initialization and then later cleaning up that initialization. That cleaning up may entail deleting an object. You are correct that the context manager can't affect the namespace of the with: clause, but that's not the initialization that it would need to clean up. Yes, you can write code with a with: statement where you try to clean up stuff that happened inside of the clause (you did), but that's not how the with: statement was ever intended to be used nor is it good practice to do so because of that limitation. Context managers are designed to initialize specific things, then clean them up. I thought you were talking about the uses of the with: statement as described in PEP-343, not every possible misuse of the with: statement. > And adding on top of irrelevancy, for the pure technical aspect it can > be accomplished in the same way using Cleanup (I provide an example below). > > However, doing that would generally be worse than pointless since with > good coding practices the objects would become unreferenced anyway. > > >> You put the initialization code in the __enter__() method, assign >> whatever objects you want to keep around through the with: clause as >> attributes on the manager, then delete those attributes in the >> __exit__(). > > Analogously, if one were to do this thing, then it could be accomplished > using a Cleanup context manager as follows: > > foo = lambda: None > foo.x = create_some_object() > at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) > > ... except that > > 1) for a once-only case this is less code :-) Not compared to a try: finally:, it isn't. > 2) it is a usage that I wouldn't recommend; instead I recommend adopting > good > coding practices where object references aren't kept around. Many of the use cases of the with: statement involve creating an object (like a lock or a transaction object), keeping it around for the duration of the "# Do stuff" block, and then finalizing it. >> Or, you use the @contextmanager decorator to turn a generator into a >> context manager, and you just assign to local variables and del them >> in the finally: clause. > > Uhm, you don't need a 'finally' clause when you define a context manager. When you use the @contextmanager decorator, you almost always do. See the Examples section of PEP 343: http://www.python.org/dev/peps/pep-0343/ > Additionally, you don't need to 'del' the local variables in > @contextmanager decorated generator. > > The local variables cease to exist automatically. True. >> What you can't do is write a generic context manager where the >> initialization happens inside the with: clause and the cleanup actions >> are registered callables. That does not allow you to affect the >> namespace. > > If you mean that you can't introduce direct local variables and have > them deleted by "registered callables" in a portable way, then right. > > But I can't think of any example where that would be relevant; in > particular what matters for supporting on-destruction cleanup is whether > you keep any references or not, not whether you have a local variable of > any given name. Well, local variables keep references to objects. Variable assignment followed by deletion is a very readable way to keep an object around for a while then remove it later. If you have to go through less readable contortions to keep the object around when it needs to be and clean it up later, then that is a mark against your approach. -- 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 From steve at holdenweb.com Thu Mar 4 14:49:27 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 14:49:27 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Robert Kern: [...] >> No, it only argues that "with Cleanup():" is supernumerary. > > I don't know what "supernumerary" means, but to the degree that the > argument says anything about a construct that is not 'finally', it says > the same about general "with". > So rather than look up the meaning if a word you aren't familiar with you will argue against its use in generic style? > So whatever you mean by supernumerary, you're saying that the argument > implies that "with" is supernumerary. > > This is starting to look like some earlier discussions in this group, > where even basic logic is denied. > Why not just stick to the facts and forget about the earlier discussions? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From pruebauno at latinmail.com Thu Mar 4 14:54:55 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 4 Mar 2010 11:54:55 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <9b598cad-3069-49a9-b2d0-378e973a8ce2@x22g2000yqx.googlegroups.com> On Mar 4, 2:30?pm, MRAB wrote: > Pete Emerson wrote: > > I've written my first python program, and would love suggestions for > > improvement. > > > I'm a perl programmer and used a perl version of this program to guide > > me. So in that sense, the python is "perlesque" > > > This script parses /etc/hosts for hostnames, and based on terms given > > on the command line (argv), either prints the list of hostnames that > > match all the criteria, or uses ssh to connect to the host if the > > number of matches is unique. > > > I am looking for advice along the lines of "an easier way to do this" > > or "a more python way" (I'm sure that's asking for trouble!) or > > "people commonly do this instead" or "here's a slick trick" or "oh, > > interesting, here's my version to do the same thing". > > > I am aware that there are performance improvements and error checking > > that could be made, such as making sure the file exists and is > > readable and precompiling the regular expressions and not calculating > > how many sys.argv arguments there are more than once. I'm not hyper > > concerned with performance or idiot proofing for this particular > > script. > > > Thanks in advance. > > > ######################################################## > > #!/usr/bin/python > > > import sys, fileinput, re, os > > > filename = '/etc/hosts' > > > hosts = [] > > > for line in open(filename, 'r'): > > ? ?match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > > Use 'raw' strings for regular expressions. > > 'Normal' Python string literals use backslashes in escape sequences (eg, > '\n'), but so do regular expressions, and regular expressions are passed > to the 're' module in strings, so that can lead to a profusion of > backslashes! > > You could either escape the backslashes: > > ? ? ? ? match = re.search('\\d+\\.\\d+\\.\\d+\\.\\d+\s+(\\S+)', line) > > or use a raw string: > > ? ? ? ? match = re.search(r'\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > > A raw string literal is just like a normal string literal, except that > backslashes aren't special. > > > ? ?if match is None or re.search('^(?:float|localhost)\.', line): > > continue > > It would be more 'Pythonic' to say "not match". > > ? ? ? ? if not match or re.search(r'^(?:float|localhost)\.', line): > > > ? ?hostname = match.group(1) > > ? ?count = 0 > > ? ?for arg in sys.argv[1:]: > > ? ? ? ? ? ?for section in hostname.split('.'): > > ? ? ? ? ? ? ? ? ? ?if section == arg: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?count = count + 1 > > Shorter is: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? count += 1 > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?break > > ? ?if count == len(sys.argv) - 1: > > ? ? ? ? ? ?hosts.append(hostname) > > > if len(hosts) == 1: > > ? ?os.system("ssh -A " + hosts[0]) > > else: > > ? ?print '\n'.join(hosts) > > You're splitting the hostname repeatedly. You could split it just once, > outside the outer loop, and maybe make it into a set. You could then > have: > > ? ? ? ? ?host_parts = set(hostname.split('.')) > ? ? ? ? count = 0 > ? ? ? ? for arg in sys.argv[1:]: > ? ? ? ? ? ? ? ? if arg in host_parts: > ? ? ? ? ? ? ? ? ? ? ? ? count += 1 > > Incidentally, the re module contains a cache, so the regular expressions > won't be recompiled every time (unless you have a lot of them and the re > module flushes the cache). I think that you really just need a set intersection for the count part and this should work: host_parts = set(hostname.split('.')) count = len(host_parts.intersection(sys.argv[1:])) From knipknap at gmail.com Thu Mar 4 14:55:21 2010 From: knipknap at gmail.com (knipknap) Date: Thu, 4 Mar 2010 11:55:21 -0800 (PST) Subject: ANNOUNCE: Exscript 2.0 Message-ID: <18ffe924-0068-42dc-ad36-da3c0ba07308@z35g2000yqd.googlegroups.com> Introduction ------------- Exscript is a Python module and template processor for automating Telnet or SSH sessions. Exscript supports a wide range of features, such as parallelization, AAA authentication methods, TACACS, and a very simple template language. Please refer to the project page for updated documentation (see the links at the bottom of this announcement). New since 0.9.16 ------------------ Exscript 2.0 is without a doubt the most awesome release of Exscript ever. It is well tested and has already proven to be robust, so use in a production environment is encouraged. Changes in this release: * Exscript's Python API has been completely overhauled and made a lot simpler. The new API is well documented [1][2]. * Countless utilities for network administrators using Python were added. For example, it is now trivial to generate reports and emails, logging is more configurable, new functions for reading and writing input and output files were added, and user interaction was simplified. * The number of dependencies was reduced to make the installation easier. * Exscript is now almost 100% unit tested. That means greatly enhanced stability and reliability. * Support for threading was improved, leading to better performance when using a large number of parallel connections. * The SSH support was greatly improved. * Exscript now includes some useful Tkinter widgets for monitoring the Exscript Queue. * Support for Pseudo devices: It is now possible to emulate a fake device that behaves like a router. This can come in handy for testing. * Of course, a huge number of bugs was also fixed. I expect this release to be the most stable one to date. It was also well tested in production and has handled hundreds of thousands of Telnet connections in the past few months. Dependencies ------------- * Python 2.2 or greater * Python-crypto * paramiko (optional, for SSH2 support) * Python-pexpect (optional, for SSH1 support) * OpenSSH (optional, for SSH1 support) Download Exscript ------------------ Release: http://github.com/knipknap/exscript/downloads Git: http://code.google.com/p/exscript/source Links ------ [1] Exscript Documentation: http://wiki.github.com/knipknap/exscript/documentation [2] Exscript Python API: http://knipknap.github.com/exscript/api/ [3] Installation Guide: http://wiki.github.com/knipknap/exscript/installation-guide [4] Exscript home page: http://wiki.github.com/knipknap/exscript/ [5] Mailing list: http://groups.google.com/group/exscript [6] Bug tracker: http://github.com/knipknap/exscript/issues [7] Browse the source: http://github.com/knipknap/exscript From mrmakent at gmail.com Thu Mar 4 15:48:30 2010 From: mrmakent at gmail.com (Mike Kent) Date: Thu, 4 Mar 2010 12:48:30 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <915588d0-e4fd-42d0-b5b5-3506700924ae@q16g2000yqq.googlegroups.com> On Mar 3, 10:56?am, "Alf P. Steinbach" wrote: > * Mike Kent: > > > What's the compelling use case for this vs. a simple try/finally? > > if you thought about it you would mean a simple "try/else". "finally" is always > executed. which is incorrect for cleanup > > by the way, that's one advantage: > > a "with Cleanup" is difficult to get wrong, while a "try" is easy to get wrong, > as you did here > > ? ?--- > > another general advantage is as for the 'with' statement generally > > > ? ?original_dir = os.getcwd() > > ? ?try: > > ? ? ? ?os.chdir(somewhere) > > ? ? ? ?# Do other stuff > > also, the "do other stuff" can be a lot of code > > and also, with more than one action the try-else introduces a lot of nesting > > > ? ?finally: > > ? ? ? ?os.chdir(original_dir) > > ? ? ? ?# Do other cleanup > > cheers & hth., > > - alf Wrong? In what way is my example wrong? It cleanly makes sure that the current working directory is the same after the try/finally as it was before it. Suboptimal, perhaps, in that the chdir in the finally part is always executed, even if the chdir in the try part failed to change the working directory. That is a clear advantage to the code you presented, in that you have the ability to register an 'undo' function only if the 'do' code succeeded. Your code also avoids a problem with many nested try/ finally blocks. But for the simple chdir example you gave, I think 'wrong' isn't the word you were looking for regarding the try/finally example I gave. Anyway, I'll keep your code in mind the next time I want to avoid a bunch of nested try/finally blocks. From wanderer at dialup4less.com Thu Mar 4 15:49:08 2010 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 4 Mar 2010 12:49:08 -0800 (PST) Subject: Pylint Argument number differs from overridden method References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> Message-ID: On Mar 4, 5:45?am, Jean-Michel Pichavant wrote: > Wanderer wrote: > > On Mar 3, 2:33 pm, Robert Kern wrote: > > >> On 2010-03-03 11:39 AM, Wanderer wrote: > > >>> Pylint W0221 gives the warning > >>> Argument number differs from overridden method. > > >>> Why is this a problem? I'm overriding the method to add additional > >>> functionality. > > >> There are exceptions to every guideline. Doing this could easily be a mistake, > >> so it's one of the many things that Pylint checks for. Silence the warning if > >> you like. > > >> -- > >> 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 > > > Thanks I was just wondering if I was overlooking something about > > inheritance. > > This is only my opinion but you get this warning because of 2 disctinct > issues: > 1/ you just made a basic mistake in your signature and need to correct it > 2/ you did not make any mistake in the signature, but this warning may > reveal a (small) flaw in your class design. > > I don't know the exact context for your code, but it's better to have a > consistant interface over your methods and mask the implementation > details from the user. > In your case, the getRays method may always ask for the lambda > parameters and just ignore it for one of its implementation. > > And don't write empty doctrings to trick pylint. Either write them, or > remove this rule, you are loosing all the tool benefits. > > JM Okay different example. I'm not really using inheritance here but its the same idea. The wx.SpinCtrl is annoyingly integer. I want decimal values. so I created dSpinCtrl. It adds the argument places. It's a drop in replacement for SpinCtrl. (okay its not, because I didn't create all the members). If you replace SpinCtrl with dSpinCtrl the program should work the same because the new argument places has a default value. I don't see a problem with more arguments. Less arguments would be a problem. Expanding functionality from a base class is what I thought inheritance is about. class dSpinCtrl(): """Adds decimal values to SpinCtrl. Almost a drop in replacement for SpinCtrl. Adds 'places' variable for number of places after decimal point """ def __init__ (self, parent, iD = ID_SPIN, value = wx.EmptyString, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.SP_ARROW_KEYS, dmin = -100.0, dmax = 100.0, dinitial = 0.0, places = 0): From sccolbert at gmail.com Thu Mar 4 16:00:02 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 4 Mar 2010 16:00:02 -0500 Subject: loop over list and process into groups In-Reply-To: <865d59ab-585b-4908-be0d-e891d0a0a08b@t23g2000yqt.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> <865d59ab-585b-4908-be0d-e891d0a0a08b@t23g2000yqt.googlegroups.com> Message-ID: <7f014ea61003041300j98500a2y89f414878753b397@mail.gmail.com> Man, deja-vu, I could have sworn I read this thread months ago... On Thu, Mar 4, 2010 at 2:18 PM, nn wrote: > > > lbolla wrote: > > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > > [ {'vlan_or_intf': 'VLAN2021'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Po1'}, > > > {'vlan_or_intf': 'Po306'}, > > > {'vlan_or_intf': 'VLAN2022'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Gi7/33'}, > > > {'vlan_or_intf': 'Po1'}, > > > {'vlan_or_intf': 'Po306'}, > > > {'vlan_or_intf': 'VLAN2051'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Gi9/6'}, > > > {'vlan_or_intf': 'VLAN2052'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Gi9/6'},] > > > > > > I want it to be converted to: > > > > > > [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] > > > > > > I was going to write a def to loop through and look for certain pre- > > > compiled regexs, and then put them in a new dictionary and append to a > > > list, but I'm having trouble thinking of a good way to capture each > > > dictionary. Each dictionary will have a key that is the vlan and the > > > value will be a list of interfaces that participate in that vlan. > > > Each list will be variable, many containing only one interface and > > > some containing many interfaces. > > > > > > I thought about using itertools, but i only use that for fixed data. > > > I don't know of a good way to loop over variably sized data. I was > > > wondering if anyone had any ideas about a good way to convert this > > > list or dictionary into the right format that I need. The solution I > > > come up with will most likely be ugly and error prone, so I thought > > > i'd ask this python list while I work. Hopefully I learn a better way > > > to solve this problem. > > > > > > Thanks! > > > > > > I also have the data in a list, > > > > > > [ 'VLAN4065', > > > 'Interface', > > > 'Gi9/6', > > > 'Po2', > > > 'Po3', > > > 'Po306', > > > 'VLAN4068', > > > 'Interface', > > > 'Gi9/6', > > > 'VLAN4069', > > > 'Interface', > > > 'Gi9/6',] > > > > > > > > =================================== > > > > from itertools import groupby > > > > data = \ > > [ {'vlan_or_intf': 'VLAN2021'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Po1'}, > > {'vlan_or_intf': 'Po306'}, > > {'vlan_or_intf': 'VLAN2022'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Gi7/33'}, > > {'vlan_or_intf': 'Po1'}, > > {'vlan_or_intf': 'Po306'}, > > {'vlan_or_intf': 'VLAN2051'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Gi9/6'}, > > {'vlan_or_intf': 'VLAN2052'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Gi9/6'},] > > > > def clean_up(lst): > > return [d.values()[0] for d in data if d.values()[0] != > 'Interface'] > > > > out = {} > > for k, g in groupby(clean_up(data) , key=lambda s: > > s.startswith('VLAN')): > > if k: > > key = list(g)[0].replace('VLAN','') > > else: > > out[key] = list(g) > > > > print out > > =================================== > > > > hth, > > L. > > Good use of groupby. Here is what I ended up coming up: > > from itertools import groupby > laninfo=[ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] > > def splitgrp(s, f=[False]): > f[0]^=s.startswith('VLAN') > return f[0] > lanlst=(list(g) for k,g in groupby(laninfo,key=splitgrp)) > out={item[0][4:]:item[2:] for item in lanlst} > print(out) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at gmail.com Thu Mar 4 16:12:01 2010 From: mrmakent at gmail.com (Mike Kent) Date: Thu, 4 Mar 2010 13:12:01 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> On Mar 4, 12:30?pm, Robert Kern wrote: > He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. > Given only your > example of the with: statement, it is hard to fault him for thinking that try: > finally: wouldn't suffice. Damn me with faint praise, will you? I'm kinda amazed at the drama my innocent request for the use case elicited. From what I've gotten so far from this thread, for the actual example Mr. Steinbach used, the only disadvantage to my counter- example using try/finally is that the chdir in the finally part will always be executed, even if the chdir in the try part did not succeed. I concede that, and was aware of it when I wrote it. For the simple example given, I did not consider it compelling. A more complex example, that would have required multiple, nested try/finally blocks, would show the advantages of Mr Steinbach's recipe more clearly. However, I fail to understand his response that I must have meant try/ else instead, as this, as Mr. Kern pointed out, is invalid syntax. Perhaps Mr. Steinbach would like to give an example? From jjposner at optimum.net Thu Mar 4 16:17:20 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 04 Mar 2010 16:17:20 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4B8EF717.3070701@optimum.net> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> Message-ID: <4b902338$0$31260$607ed4bc@cv.net> On 3/3/2010 6:56 PM, John Posner wrote: > > ... I was thinking > today about "doing a Bruno", and producing similar pieces on: > > * properties created with the @property decorator > > * the descriptor protocol > > I'll try to produce something over the next couple of days. > Starting to think about a writeup on Python properties, I've discovered that the official Glossary [1] lacks an entry for "property" -- it's missing in both Py2 and Py3! Here's a somewhat long-winded definition -- comments, please: --------------------------------------------- An attribute, *a*, of an object, *obj*, is said to be implemented as a property if the standard ways of accessing the attribute: * evaluation: print obj.a * assignment: obj.a = 42 * deletion: del obj.a ... cause methods of a user-defined *property object* to be invoked. The attribute is created as a class attribute, not an instance attribute. Example: class Widget: # create "color" as class attribute, not within __init__() color = <> def __init__(self, ...): # do not define "self.color" instance attribute The property object can be created with the built-in function property(), which in some cases can be coded as a decorator: @property. The property object can also be an instance of a class that implements the descriptor protocol. --------------------------------------------- Tx, John [1] http://docs.python.org/glossary.html From mrmakent at gmail.com Thu Mar 4 16:19:44 2010 From: mrmakent at gmail.com (Mike Kent) Date: Thu, 4 Mar 2010 13:19:44 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On Mar 3, 12:00?pm, Robert Kern wrote: > On 2010-03-03 09:39 AM, Mike Kent wrote: > > > What's the compelling use case for this vs. a simple try/finally? > > > ? ? original_dir = os.getcwd() > > ? ? try: > > ? ? ? ? os.chdir(somewhere) > > ? ? ? ? # Do other stuff > > ? ? finally: > > ? ? ? ? os.chdir(original_dir) > > ? ? ? ? # Do other cleanup > > A custom-written context manager looks nicer and can be more readable. > > from contextlib import contextmanager > import os > > @contextmanager > def pushd(path): > ? ? ?original_dir = os.getcwd() > ? ? ?os.chdir(path) > ? ? ?try: > ? ? ? ? ?yield > ? ? ?finally: > ? ? ? ? ?os.chdir(original_dir) > > with pushd(somewhere): > ? ? ?... Robert, I like the way you think. That's a perfect name for that context manager! However, you can clear one thing up for me... isn't the inner try/finally superfluous? My understanding was that there was an implicit try/finally already done which will insure that everything after the yield statement was always executed. From news123 at free.fr Thu Mar 4 16:24:59 2010 From: news123 at free.fr (News123) Date: Thu, 04 Mar 2010 22:24:59 +0100 Subject: _winreg and access registry settings of another user Message-ID: <4b90252b$0$17806$426a34cc@news.free.fr> Hi, I habe administrator privilege on a window host and would like to write a script setting some registry entries for other users. There are potentially at least two wo ways of doing this: 1.) start a subprocess as other user and change the regitrey for CURRENT_USER However I don't know how to start a process (or ideally just a thread) as another user with python. 2.) Load the 'hive' of the othe user and chnage the registry. It seems, that one has to load the 'hive' of a different user in order to have access to somebody eleses registry entries. I did not find any documetnation of how to load a 'hive' wit the library _winreg or another python library/ Did anybody else try already something similiar? thanks in advance for pointers bye N From jpiitula at ling.helsinki.fi Thu Mar 4 16:40:39 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Mar 2010 23:40:39 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml References: Message-ID: Stefan Behnel writes: > Jussi Piitulainen, 04.03.2010 11:46: > > I am observing weird semi-erratic behaviour that involves Python 3 > > and lxml, is extremely sensitive to changes in the input data, and > > only occurs when I name a partial result. I would like some help > > with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml > > version?) > > Here's how to find the version: > > http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do Ok, thank you. Here's the results: >>> print(et.LXML_VERSION, et.LIBXML_VERSION, ... et.LIBXML_COMPILED_VERSION, et.LIBXSLT_VERSION, ... et.LIBXSLT_COMPILED_VERSION) (2, 2, 4, 0) (2, 6, 26) (2, 6, 26) (1, 1, 17) (1, 1, 17) > I'll give your test code a try when I get to it. However, note that > the best place to discuss this is the lxml mailing list: > > http://codespeak.net/mailman/listinfo/lxml-dev Thank you. Two things, however. First, I snipped out most of the XML document in that post, so it won't be runnable as is. As I think I said, my attempts to edit it down to size made the bug hide itself. Second, it's very sensitive to any changes in that XML. Oh, and a third thing. I'm not at all sure yet that the bug is in lxml. It seems to me that Python itself does impossible things - I hope I'm just being blind to something obvious, really. But if you like to try it out, I'll post the full test data as a followup to this. It's just bogus test data. From deets at nospam.web.de Thu Mar 4 16:43:12 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Mar 2010 22:43:12 +0100 Subject: python SUDS library In-Reply-To: <28ed0127-8b71-4327-954c-c9100b4768de@v20g2000prb.googlegroups.com> References: <28ed0127-8b71-4327-954c-c9100b4768de@v20g2000prb.googlegroups.com> Message-ID: <7vanrgF97hU1@mid.uni-berlin.de> Am 04.03.10 06:23, schrieb yamamoto: > Hi, > I tried to make a simple script with SUD library for caching torrent > files. it doenst work! > > [versions] > suds: 0.4, python: 2.6.4 > > [code] > from suds.client import Client > import base64 > > path = 'sample.torrent' > doc = open(path, 'rb').read() > encoded_doc = base64.b64encode(doc) > url = 'http://torrage.com/api/torrage.wsdl' > client = Client(url, cache=None) > print client > hash = client.service.cacheTorrent(encoded_doc) > print hash > > [result] > > Suds ( https://fedorahosted.org/suds/ ) version: 0.4 (beta) build: > R663-20100303 > > Service ( CacheService ) tns="urn:Torrage" > Prefixes (0) > Ports (1): > (CachePort) > Methods (1): > cacheTorrent(xs:string torrent, ) > Types (0): > > Traceback (most recent call last): > File "C:\Documents and Settings\yamamoto\workspace\python\console > \extract.py", line 13, in > result = client.service.cacheTorrent(encoded_doc) > File "C:\Python26\lib\site-packages\suds\client.py", line 539, in > __call__ > return client.invoke(args, kwargs) > File "C:\Python26\lib\site-packages\suds\client.py", line 598, in > invoke > result = self.send(msg) > File "C:\Python26\lib\site-packages\suds\client.py", line 627, in > send > result = self.succeeded(binding, reply.message) > File "C:\Python26\lib\site-packages\suds\client.py", line 659, in > succeeded > r, p = binding.get_reply(self.method, reply) > File "C:\Python26\lib\site-packages\suds\bindings\binding.py", line > 143, in get_reply > replyroot = sax.parse(string=reply) > File "C:\Python26\lib\site-packages\suds\sax\parser.py", line 136, > in parse > sax.parse(source) > File "C:\Python26\lib\xml\sax\expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "C:\Python26\lib\xml\sax\xmlreader.py", line 123, in parse > self.feed(buffer) > File "C:\Python26\lib\xml\sax\expatreader.py", line 211, in feed > self._err_handler.fatalError(exc) > File "C:\Python26\lib\xml\sax\handler.py", line 38, in fatalError > raise exception > xml.sax._exceptions.SAXParseException::2:0: junk after > document element > > > this is a php code provided by torrage > $client = new SoapClient("http://torrage.com/api/ > torrage.wsdl"); > $infoHash = $client- >> cacheTorrent(base64_encode(file_get_contents("my.torrent"))); > ?> > > any suggestions? Looks like the XML is malformed. Can you post it? You can insert print-statements into the library to do so, eg in line 143 of suds.bindings.binding. Diez Diez From jpiitula at ling.helsinki.fi Thu Mar 4 16:47:49 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Mar 2010 23:47:49 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml References: Message-ID: This is the full data file on which my regress/Tribug exhibits the behaviour that I find incomprehensible, described in the first post in this thread. The comment in the beginning of the file below was written before I commented out some records in the data, so the actual numbers now are not ten expected, thirty sometimes observed, but the wrong number is always the correct number tripled (5 and 15, I think). ---regress/tridata.py follows--- # Exercise lxml.etree.parse(body).xpath(title) # which I think should always return a list of # ten elements but sometimes returns thirty, # with each of the ten in triplicate. And this # seems impossible to me. Yet I see it happening. body = b''' 2010-03-02T09:38:47Z http://localhost/pmh/que
jrc32003R0055-pl.xml/2/0 2004-08-15T19:45:00Z pl
Rozporządzenie
jrc32003R0055-pl.xml/3/1 2004-08-15T19:45:00Z pl
dnia
jrc32003R0055-pl.xml/3/2 2004-08-15T19:45:00Z pl
13
jrc32003R0055-pl.xml/3/3 2004-08-15T19:45:00Z pl
stycznia
jrc32003R0055-pl.xml/3/4 2004-08-15T19:45:00Z pl
2003
''' title = '//*[name()="record"]//*[name()="dc:title"]' From jgardner at jonathangardner.net Thu Mar 4 16:54:45 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 4 Mar 2010 13:54:45 -0800 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <6cc20cea1003041354s3cb5011cmbbaf39eefed7a4e4@mail.gmail.com> On Thu, Mar 4, 2010 at 10:39 AM, Pete Emerson wrote: > > #!/usr/bin/python > More common: #!/usr/bin/env python > import sys, fileinput, re, os > > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > ? ? ? ?match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > ? ? ? ?if match is None or re.search('^(?:float|localhost)\.', line): > continue > ? ? ? ?hostname = match.group(1) In Python, we use REs as a last resort. See "dir("")" or "help("")" for why we don't use REs if we can avoid them. The above is better represented with: try: ipaddr, hostnames = line.split(None, 1) except IndexError: continue if line.find('float') >=0 or line.find('localhost') >= 0: continue > ? ? ? ?count = 0 > ? ? ? ?for arg in sys.argv[1:]: > ? ? ? ? ? ? ? ?for section in hostname.split('.'): > ? ? ? ? ? ? ? ? ? ? ? ?if section == arg: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?count = count + 1 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?break > ? ? ? ?if count == len(sys.argv) - 1: > ? ? ? ? ? ? ? ?hosts.append(hostname) > You can use the "else" in a "for". as well. for arg in sys.argv[1:]: for section in hostname.split('.'): if section == arg: break else: # Run only if for completes naturally hosts.append(hostname) It may be clearer to do set arithmetic as well. > if len(hosts) == 1: > ? ? ? ?os.system("ssh -A " + hosts[0]) You probably want one of the os.exec* methods instead, since you aren't going to do anything after this. > else: > ? ? ? ?print '\n'.join(hosts) Rather, the idiom is usually: for host in hosts: print host -- Jonathan Gardner jgardner at jonathangardner.net From mensanator at aol.com Thu Mar 4 17:21:16 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Mar 2010 14:21:16 -0800 (PST) Subject: _winreg and access registry settings of another user References: <4b90252b$0$17806$426a34cc@news.free.fr> Message-ID: <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> On Mar 4, 3:24?pm, News123 wrote: > Hi, > > I habe administrator privilege ?on a window host and would like to write > a script setting some registry entries for other users. Why? Are you writing a virus? > > There are potentially at least two wo ways of doing this: > > 1.) start a subprocess as other user and change the regitrey for > CURRENT_USER > > However I don't know how to start a process (or ideally just a thread) > as another user with python. > > 2.) Load the 'hive' of the othe user and chnage the registry. > > It seems, that one has to load the 'hive' of a different user in order > to have access to somebody eleses registry entries. > > I did not find any documetnation of how to load a 'hive' wit the library > _winreg or another python library/ > > Did anybody else try already something similiar? > > thanks in advance for pointers > > bye > > N From fabiofz at gmail.com Thu Mar 4 17:25:20 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 4 Mar 2010 19:25:20 -0300 Subject: Pydev 1.5.5 Released Message-ID: Hi All, Pydev 1.5.5 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Predefined completions available for code completion: * Predefined completions may be created for use when sources are not available * Can also be used for providing better completions for compiled modules (e.g.: PyQt, wx, etc.) * Defined in .pypredef files (which are plain Python code) * Provides a way for generating those from a QScintilla .api file (experimental) * See Predefined Completions in manual for more info * Pydev Package Explorer: * Showing the contents of the PYTHONPATH from the interpreter for each project * Shows the folder containing the python interpreter executable (to browse for docs, scripts, etc) * Allows opening files in the interpreter PYTHONPATH (even inside zip files) * Editor options: * Find/replace dialog has option to search in currently opened editors * Move line up/down can move considering Python indentation (not default) * Simple token completions can have a space or a space and colon added when applied. E.g.: print, if, etc (not default) * Refactoring: * Fixed InvalidThreadAccess on refactoring * Fixed problem doing refactoring on external files (no file was found) * Globals Browser (Ctrl+Shift+T): * No longer throwing NullPointerException when the interpreter is no longer available for a previously found token * General: * When creating a new pydev project, the user will be asked before changing to the pydev perspective * Only files under source folders are analyzed (files in the external source folders would be analyzed if they happened to be in the Eclipse workspace) * Interactive console now works properly on non-english systems * Hover working over tokens from compiled modules (e.g.: file, file.readlines) * JYTHONPATH environment variable is set on Jython (previously only the PYTHONPATH was set) * Fixed path translation issues when using remote debugger * Fixed issue finding definition for a method of a locally created token What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/python Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From alfps at start.no Thu Mar 4 17:27:03 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 23:27:03 +0100 Subject: A "scopeguard" for Python In-Reply-To: <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: * Mike Kent: > On Mar 4, 12:30 pm, Robert Kern wrote: > >> He's ignorant of the use cases of the with: statement, true. > > Ouch! Ignorant of the use cases of the with statement, am I? > Odd, I use it all the time. > >> Given only your >> example of the with: statement, it is hard to fault him for thinking that try: >> finally: wouldn't suffice. > > Damn me with faint praise, will you? > > I'm kinda amazed at the drama my innocent request for the use case > elicited. From what I've gotten so far from this thread, for the > actual example Mr. Steinbach used, the only disadvantage to my counter- > example using try/finally is that the chdir in the finally part will > always be executed, even if the chdir in the try part did not > succeed. I concede that, and was aware of it when I wrote it. For > the simple example given, I did not consider it compelling. Uhm, well. My example was: with Cleanup as at_cleanup: # blah blah chdir( somewhere ) at_cleanup.call( lambda: chdir( original_dir ) ) # blah blah It was not intended to compel, rather just to illustrate usage. :-) And you asked about comparing that with ... original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup .. which does something different, namely, always executing the os.chdir(original_dir) or more generally the action-specific cleanup. The action-specific cleanup might be much more costly than a chdir, and/or, in the case where the action failed, incorrect. In the same number of lines and with fewer keystrokes you could have written code that was equivalent to the code I posted and that you wanted to compare with, e.g. ... original_dir = os.getcwd() os.chdir(somewhere) try: # Do other stuff finally: os.chdir(original_dir) # Do other cleanup ... so given how easy it is to write such an equivalent code snippet, I assumed that the different behavior was /not/ intended, that instead, you'd attempted to write equivalent code but made a slight error in the translation to lower level construct -- but impossible to say exactly what. Now you write that you were "aware of [the different behavior] when I wrote it", and that just baffles me: why not then, as a basis of sound comparision, write the equivalent code shown above, the same number of lines as what you wrote? > A more > complex example, that would have required multiple, nested try/finally > blocks, would show the advantages of Mr Steinbach's recipe more > clearly. > > However, I fail to understand his response that I must have meant try/ > else instead, as this, as Mr. Kern pointed out, is invalid syntax. > Perhaps Mr. Steinbach would like to give an example? OK. Assuming that you wanted the chdir to be within a try block (which it was in your code), then to get code equivalent to my code, for the purpose of a comparision of codes that do the same, you'd have to write something like ... original_dir = os.getcwd() try: os.chdir(somewhere) except Whatever: # E.g. log it. raise else: try: # Do other stuff finally: os.chdir(original_dir) # Do other cleanup ... which would be a more general case. I've also given this example in response to Robert earlier in the thread. Although I haven't tried it I believe it's syntactically valid. If not, then the relevant typo should just be fixed. :-) I have no idea which construct Robert thought was syntactically invalid. I think that if he's written that, then it must have been something he thought of. Cheers & hth., - Alf From sjdevnull at yahoo.com Thu Mar 4 17:55:07 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 4 Mar 2010 14:55:07 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <692c83be-0075-470f-a970-8e5c5c301eb0@g7g2000yqe.googlegroups.com> On Mar 4, 1:39?pm, Pete Emerson wrote: > I've written my first python program, and would love suggestions for > improvement. > > I'm a perl programmer and used a perl version of this program to guide > me. So in that sense, the python is "perlesque" > > This script parses /etc/hosts for hostnames, and based on terms given > on the command line (argv), either prints the list of hostnames that > match all the criteria, or uses ssh to connect to the host if the > number of matches is unique. > > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". > > I am aware that there are performance improvements and error checking > that could be made, such as making sure the file exists and is > readable and precompiling the regular expressions and not calculating > how many sys.argv arguments there are more than once. I'm not hyper > concerned with performance or idiot proofing for this particular > script. > > Thanks in advance. > > ######################################################## > #!/usr/bin/python > > import sys, fileinput, re, os 'Some people, when confronted with a problem, think "I know, I?ll use regular expressions." Now they have two problems.' ? Jamie Zawinski Seriously, regexes can be very useful but there's no need for them here. Simpler is usually better, and easier to understand. > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > ? ? ? ? match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > ? ? ? ? if match is None or re.search('^(?:float|localhost)\.', line): > continue > ? ? ? ? hostname = match.group(1) I find this much clearer without regexes: try: ip, hostname = line.strip().split(None, 1) except IndexError: continue # I think this is equivalent to your re, but I'm not sure it's what # you actually meant... #if line.startswith("float.") or line.startswith("localhost."): # continue # I'm going with: if hostname.startswith("float.") or hostname.startswith("localhost"): continue > ? ? ? ? count = 0 > ? ? ? ? for arg in sys.argv[1:]: > ? ? ? ? ? ? ? ? for section in hostname.split('.'): > ? ? ? ? ? ? ? ? ? ? ? ? if section == arg: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? count = count + 1 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break > ? ? ? ? if count == len(sys.argv) - 1: > ? ? ? ? ? ? ? ? hosts.append(hostname) A perfect application of sets. #initialize at program outset args = set(sys.argv[1:]) ... hostparts = set(hostname.split(".")) if hostparts & args: hosts.append(hostname) Full program: import sys import os filename = '/etc/hosts' hosts = [] args = set(sys.argv[1:]) for line in open(filename, 'r'): # Parse line into ip address and hostname, skipping bogus lines try: ipaddr, hostname = line.strip().split(None, 1) except ValueError: continue if hostname.startswith("float.") or hostname.startswith("localhost."): continue # Add to hosts if it matches at least one argument hostparts = set(hostname.split(".")) if hostparts & args: hosts.append(hostname) # If there's only one match, ssh to it--otherwise print out the matches if len(hosts) == 1: os.system("ssh -A %s"%hosts[0]) else: for host in hosts: print host From python at bdurham.com Thu Mar 4 18:10:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 04 Mar 2010 18:10:06 -0500 Subject: Looking for the mysterious zlib.py* files in Python 2.6.4 (32-bit) for Windows In-Reply-To: <1267743672.16774.1363182565@webmail.messagingengine.com> References: <1267743672.16774.1363182565@webmail.messagingengine.com> Message-ID: <1267744206.18232.1363186281@webmail.messagingengine.com> In the process of building an EXE with py2exe, I noticed that there's no physical zlib files anywhere on my workstation. I can import zlib and use this module's features without problem. But when I query zlib.__file__, I get back an empty string. Where does the zlib code live? Is zlib a in 2.6? The reason I question its '' status is that when analyzing my 2.6 based Py2exe produced executables with DependencyWalker, I see references to a zlib.pyd file that doesn't exist anywhere on my system. I wonder if this is something I should be concerned about? Can someone explain this mystery to me? Thank you, Malcolm From alfps at start.no Thu Mar 4 18:52:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 00:52:04 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >> [snippety] >>>>> >>>>>> If you call the possibly failing operation "A", then that systematic >>>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>>> mess, but if A succeeds, then it's the responsibility of the calling >>>>>> code to clean up if the higher level (multiple statements) operation >>>>>> that A is embedded in, fails. >>>>>> >>>>>> And that's what Marginean's original C++ ScopeGuard was designed for, >>>>>> and what the corresponding Python Cleanup class is designed for. >>>>> >>>>> And try: finally:, for that matter. >>>> >>>> Not to mention "with". >>>> >>>> Some other poster made the same error recently in this thread; it is a >>>> common fallacy in discussions about programming, to assume that since >>>> the same can be expressed using lower level constructs, those are all >>>> that are required. >>>> >>>> If adopted as true it ultimately means the removal of all control >>>> structures above the level of "if" and "goto" (except Python doesn't >>>> have "goto"). >>> >>> What I'm trying to explain is that the with: statement has a use even >>> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >>> finally: does not mean that the with: statement doesn't improve on >>> try: finally:. >> >> That's a different argument, essentially that you see no advantage for >> your current coding patterns. >> >> It's unconnected to the argument I responded to. >> >> The argument that I responded to, that the possibility of expressing >> things at the level of try:finally: means that a higher level construct >> is superfluous, is still meaningless. > > I am attacking your premise that the "with Cleanup():" construct is > higher level than try: finally:. It isn't. It provides the same level of > abstraction as try: finally:. > > This is distinct from the accepted uses of the with: statement which > *are* higher level than try: finally: and which do confer practical > benefits over using try: finally: despite being syntactical sugar for > try: finally:. > >>>>>>> Both formulations can be correct (and both work perfectly fine with >>>>>>> the chdir() example being used). Sometimes one is better than the >>>>>>> other, and sometimes not. You can achieve both ways with either your >>>>>>> Cleanup class or with try: finally:. >>>>>>> >>>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>>> try: >>>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>>> into >>>>>>> callables. This significantly limits what you can do in your cleanup >>>>>>> code. >>>>>> >>>>>> Uhm, not really. :-) As I see it. >>>>> >>>>> Well, not being able to affect the namespace is a significant >>>>> limitation. Sometimes you need to delete objects from the namespace in >>>>> order to ensure that their refcounts go to zero and their cleanup code >>>>> gets executed. >>>> >>>> Just a nit (I agree that a lambda can't do this, but as to what's >>>> required): assigning None is sufficient for that[1]. >>> >>> Yes, but no callable is going to allow you to assign None to names in >>> that namespace, either. Not without sys._getframe() hackery, in any >>> case. >>> >>>> However, note that the current language doesn't guarantee such cleanup, >>>> at least as far as I know. >>>> >>>> So while it's good practice to support it, to do everything to let it >>>> happen, it's presumably bad practice to rely on it happening. >>>> >>>> >>>>> Tracebacks will keep the namespace alive and all objects in it. >>>> >>>> Thanks!, I hadn't thought of connecting that to general cleanup >>>> actions. >>>> >>>> It limits the use of general "with" in the same way. >>> >>> Not really. >> >> Sorry, it limits general 'with' in /exactly/ the same way. >> >>> It's easy to write context managers that do that [delete objects from >>> the namespace]. >> >> Sorry, no can do, as far as I know; your following example quoted below >> is an example of /something else/. > > Okay, so what do you mean by 'the use of general "with"'? I'm talking > about writing a context manager or using the @contextmanager decorator > to do some initialization and then later cleaning up that > initialization. That cleaning up may entail deleting an object. You are > correct that the context manager can't affect the namespace of the with: > clause, but that's not the initialization that it would need to clean up. > > Yes, you can write code with a with: statement where you try to clean up > stuff that happened inside of the clause (you did), but that's not how > the with: statement was ever intended to be used nor is it good practice > to do so because of that limitation. Context managers are designed to > initialize specific things, then clean them up. I thought you were > talking about the uses of the with: statement as described in PEP-343, > not every possible misuse of the with: statement. I'm not the one talking about removing variables or that "it's easy to write context managers that do that". You are the one talking about that. So I have really not much to add. It seems that you're now agreeing with me that former is not good practice and that the latter is impossible to do portably, but you now argue against your earlier stand as if that was something that I had put forward. It's a bit confusing when you argue against your own statements. >> And adding on top of irrelevancy, for the pure technical aspect it can >> be accomplished in the same way using Cleanup (I provide an example >> below). >> >> However, doing that would generally be worse than pointless since with >> good coding practices the objects would become unreferenced anyway. >> >> >>> You put the initialization code in the __enter__() method, assign >>> whatever objects you want to keep around through the with: clause as >>> attributes on the manager, then delete those attributes in the >>> __exit__(). >> >> Analogously, if one were to do this thing, then it could be accomplished >> using a Cleanup context manager as follows: >> >> foo = lambda: None >> foo.x = create_some_object() >> at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) >> >> ... except that >> >> 1) for a once-only case this is less code :-) > > Not compared to a try: finally:, it isn't. Again, this context shifting is bewildering. As you can see, quoted above, you were talking about a situation where you would have defined a context manager, presumably because a 'try' would not in your opinion be simpler for whatever it was that you had in mind. But you are responding to the code I offered as if it was an alternative to something where you would find a 'try' to be simplest. >> 2) it is a usage that I wouldn't recommend; instead I recommend adopting >> good >> coding practices where object references aren't kept around. > > Many of the use cases of the with: statement involve creating an object > (like a lock or a transaction object), keeping it around for the > duration of the "# Do stuff" block, and then finalizing it. > >>> Or, you use the @contextmanager decorator to turn a generator into a >>> context manager, and you just assign to local variables and del them >>> in the finally: clause. >> >> Uhm, you don't need a 'finally' clause when you define a context manager. > > When you use the @contextmanager decorator, you almost always do. See > the Examples section of PEP 343: > > http://www.python.org/dev/peps/pep-0343/ > >> Additionally, you don't need to 'del' the local variables in >> @contextmanager decorated generator. >> >> The local variables cease to exist automatically. > > True. > >>> What you can't do is write a generic context manager where the >>> initialization happens inside the with: clause and the cleanup actions >>> are registered callables. That does not allow you to affect the >>> namespace. >> >> If you mean that you can't introduce direct local variables and have >> them deleted by "registered callables" in a portable way, then right. >> >> But I can't think of any example where that would be relevant; in >> particular what matters for supporting on-destruction cleanup is whether >> you keep any references or not, not whether you have a local variable of >> any given name. > > Well, local variables keep references to objects. Variable assignment > followed by deletion is a very readable way to keep an object around for > a while then remove it later. If you have to go through less readable > contortions to keep the object around when it needs to be and clean it > up later, then that is a mark against your approach. Sorry, as with the places noted above, I can't understand what you're trying to say here. I don't recommend coding practices where you keep object references around, and you have twice quoted that above. I don't have any clue what "contortions" you are talking about, it must be something that you imagine. Cheers, - Alf (three times baffled) From mentifex at myuw.net Thu Mar 4 18:52:36 2010 From: mentifex at myuw.net (Forthminder) Date: Thu, 4 Mar 2010 15:52:36 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <5b3da248-0ccb-4451-a322-0fcabe744b41@k5g2000pra.googlegroups.com> Google AI Challenge post-mortem report by the winner is at http://a1k0n.net/blah/archives/2010/03/index.html#e2010-03-04T14_00_21.txt Mentifex -- http://cyborg.blogspot.com http://code.google.com/p/mindforth/wiki/AiHasBeenSolved From pengyu.ut at gmail.com Thu Mar 4 18:57:35 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 4 Mar 2010 15:57:35 -0800 (PST) Subject: highlight words by regex in pdf files using python Message-ID: I don't find a general pdf library in python that can do any operations on pdfs. I want to automatically highlight certain words (using regex) in a pdf. Could somebody let me know if there is a tool to do so in python? From pemerson at gmail.com Thu Mar 4 18:59:58 2010 From: pemerson at gmail.com (Pete Emerson) Date: Thu, 4 Mar 2010 15:59:58 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <692c83be-0075-470f-a970-8e5c5c301eb0@g7g2000yqe.googlegroups.com> Message-ID: Great responses, thank you all very much. I read Jonathan Gardner's solution first and investigated sets. It's clearly superior to my first cut. I love the comment about regular expressions. In perl, I've reached for regexes WAY too much. That's a big lesson learned too, and from my point of view not because of performance (although that's most likely a bonus) but because of code readability. Here's the version I have now. It looks quite similar to sjdevnull's. Further comments appreciated, and thanks again. #!/usr/bin/env python import sys, fileinput, os filename = '/etc/hosts' hosts = [] search_terms = set(sys.argv[1:]) for line in open(filename, 'r'): if line.startswith('#'): continue try: hostname = line.strip().split('\t')[2] # The host I want is always at the 3rd tab. except IndexError: continue if hostname.startswith('float.') or hostname.startswith('localhost.'): continue if search_terms <= set(hostname.split('.')): # same as if search_terms.issubset(hostname.split('.')): hosts.append(hostname) if len(hosts) == 1: os.execl("/usr/bin/ssh", '-A', hosts[0]) else: for host in hosts: print host From nobody at nowhere.com Thu Mar 4 19:05:10 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Mar 2010 00:05:10 +0000 Subject: Challenge: escape from the pysandbox References: <201002261329.33740.victor.stinner@haypocalc.com> Message-ID: On Wed, 03 Mar 2010 03:37:44 +0100, Victor Stinner wrote: >> I see, makes perfect sense. This then raises the question whether it's >> important to have a 100% fool proof python sandbox without help from >> the OS, or this goal is not only too ambitious but also not really a >> useful one. > > This is just impossible :-) PHP tried that but it's too hard to write an > exhaustive blacklist because too much code have to be modified. If you > require a 100% fool proof sandbox, you have to use a sandbox between the > Python process and the OS (and not inside the Python process). It's entirely feasible to implement a perfect sandbox at the language level. But you have to design this in from the beginning. If you try to retro-fit it, you end up either failing or with an entirely different language. A black-list approach won't work; you have to deny by default then white-list "safe" functionality. From nobody at nowhere.com Thu Mar 4 19:09:39 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Mar 2010 00:09:39 +0000 Subject: using subprocess.Popen env parameter References: <47f5881a-a7bd-4a57-8e2d-ae27cfbf3a9a@x22g2000yqx.googlegroups.com> Message-ID: On Wed, 03 Mar 2010 09:05:47 -0800, enda man wrote: > cl_path = ms_vc_path + '\VC\bin' The backslash is used as an escape character within string literals. Either use raw strings: cl_path = ms_vc_path + r'\VC\bin' or escape the backslashes: cl_path = ms_vc_path + '\\VC\\bin' or use os.path.join(): cl_path = os.path.join(ms_vc_path, 'VC', 'bin') From strombrg at gmail.com Thu Mar 4 19:25:30 2010 From: strombrg at gmail.com (Dan Stromberg) Date: Thu, 4 Mar 2010 16:25:30 -0800 (PST) Subject: Fast GUI pipemeter: gprog References: <619ab895-87a9-4b40-b45e-b12299304b38@z1g2000prc.googlegroups.com> <1686070.lZ2vcFHjTE@xkzjympik> Message-ID: On Mar 4, 1:15?pm, pk wrote: > Dan Stromberg wrote: > > In case you're interested, I've put a fast GUI pipemeter (measures how > > fast data is moving through a pipe or redirect and gives two estimates > > of time-to-completion - one based on the entire transfer so far, and > > one based on a user-specifiable number of blocks) up at: > > >http://stromberg.dnsalias.org/~dstromberg/gprog/ > > > It uses a dual process design (to make things a bit faster on dual > > core or better systems) with a cache oblivious algorithm (to self-tune > > block sizes for good performance) - I've seen it sustain over 2 > > gigabits/second, and that despite Linux' /dev/zero insisting on a tiny > > blocksize. ?I wasn't able to construct a RAM disk large enough to get > > anything like a sustained result with larger blocksizes than what > > Linux' /dev/zero likes - that is, not without springing for a new > > machine with a huge amount of RAM. ?IOW, your disk or network will > > very likely be the bottleneck, not the tool. > > > I hope it helps someone. > > This sounds similar to "pv", although pv does not have a GUI. Um, yes, pv is similar and has a pretty nice character cell GUI as it were. I suppose I'd neglected to mention that I put a list of similar tools at the beginning of the gprog page, including pv. Thanks for making sure we were aware of pv. Interesting that pv seems to be successfully getting 128K blocks out of /dev/zero. For some reason, gprog always gets back 16K blocks from /dev/zero, even when requesting blocks of sizes substantially larger. gprog automatically detects this and just starts asking for 16K. Python folk: Any guesses why a simple file.read(blocksize) would have such an affinity for returning 16K when redirected from /dev/zero? If I run the program against a file on disk, it gets larger blocksizes fine. From hwmeder at alumni.unc.edu Thu Mar 4 19:45:47 2010 From: hwmeder at alumni.unc.edu (Harold Meder) Date: Thu, 4 Mar 2010 19:45:47 -0500 Subject: Python Opportunity at OPNET Message-ID: <3a102d3b1003041645o54bb6823k7f3c66ab3c49eaef@mail.gmail.com> I stumbled across this Job Postingat OPNET. I hope that it is acceptable to post this type of info on this mailing list. I do not know any further information regarding this opportunity. Harold Meder. -------------- next part -------------- An HTML attachment was scrubbed... URL: From electriclightheads at gmail.com Thu Mar 4 19:48:19 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 5 Mar 2010 09:48:19 +0900 Subject: pyao makes the right sound but why? In-Reply-To: References: Message-ID: <1078018b1003041648v1060ddd6ibc482b22ab4c0b2d@mail.gmail.com> omg! u r actually testin my dirty code?! tnx that's great! to create an instance soy.py depends on(needs all of em): http://sarigama.namaste.jp/oil/tit01.wav http://sarigama.namaste.jp/oil/tit02.wav http://sarigama.namaste.jp/oil/tit03.wav http://sarigama.namaste.jp/oil/tit04.wav http://sarigama.namaste.jp/oil/tit05.wav http://sarigama.namaste.jp/oil/tit06.wav http://sarigama.namaste.jp/oil/tit07.wav and the easiest way to get the pattern is instance.pattern(howmanyframes) the object updates itself with .sing() and can affect each other with .jam_with(other_instance) this design is to (in the future) create somethang together with someone who would upload a short.wav on his site (to contrubute .. or maybe without willin to ;)) have to study urllib(?) for things to come have to experiment more with picklin aspects too but this is my attempt to beat the "listenin to mp3s" culture btw. where's that help(ao)? On Fri, Mar 5, 2010 at 3:43 AM, Anssi Saari wrote: > "'2+" writes: > >> dev = ao.AudioDevice('alsa') >> dev.play(x) >> >> could launch me a semi realtime dj kinda sys >> luckily .. it does seem to be making the right sound >> but why? >> the default of the samplerate and that 16bit happened to match with my thing x? > > Yes, that seems to be the case from help(ao). But I couldn't run > tofu = soy.Bean() since it seems to want tit01.wav. Do you make that > available somewhere? > -- > http://mail.python.org/mailman/listinfo/python-list > -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From howe.steven at gmail.com Thu Mar 4 19:55:24 2010 From: howe.steven at gmail.com (Steven Howe) Date: Thu, 04 Mar 2010 16:55:24 -0800 Subject: Python Opportunity at OPNET In-Reply-To: <3a102d3b1003041645o54bb6823k7f3c66ab3c49eaef@mail.gmail.com> References: <3a102d3b1003041645o54bb6823k7f3c66ab3c49eaef@mail.gmail.com> Message-ID: <4B90567C.7010305@gmail.com> On 03/04/2010 04:45 PM, Harold Meder wrote: > I stumbled across this Job Posting > at > OPNET. > I hope that it is acceptable to post this type of info on this mailing > list. > I do not know any further information regarding this opportunity. > > Harold Meder. Harold, Thats just a net looking to scoop up people. There's no job there. Just a staffing house looking for resumes in expectation for the job market to pickup. Staffing houses rip tech people off. sph -------------- next part -------------- An HTML attachment was scrubbed... URL: From electriclightheads at gmail.com Thu Mar 4 19:58:14 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 5 Mar 2010 09:58:14 +0900 Subject: pyao makes the right sound but why? In-Reply-To: <1078018b1003041648v1060ddd6ibc482b22ab4c0b2d@mail.gmail.com> References: <1078018b1003041648v1060ddd6ibc482b22ab4c0b2d@mail.gmail.com> Message-ID: <1078018b1003041658h786c2b6s29f5588bc65cb944@mail.gmail.com> o .. but u can use ur own tits.wav if it is 44100 mono 16bit and picklin n uploading the tofu n having lots of those on the net 2 increase vegetrians is what soy.py wanted to mean On Fri, Mar 5, 2010 at 9:48 AM, '2+ wrote: > omg! u r actually testin my dirty code?! > tnx that's great! > to create an instance > soy.py depends on(needs all of em): > > http://sarigama.namaste.jp/oil/tit01.wav > http://sarigama.namaste.jp/oil/tit02.wav > http://sarigama.namaste.jp/oil/tit03.wav > http://sarigama.namaste.jp/oil/tit04.wav > http://sarigama.namaste.jp/oil/tit05.wav > http://sarigama.namaste.jp/oil/tit06.wav > http://sarigama.namaste.jp/oil/tit07.wav > > and the easiest way to get the pattern is instance.pattern(howmanyframes) > the object updates itself with .sing() > and can affect each other with .jam_with(other_instance) > > this design is to (in the future) create somethang together > with someone who would upload a short.wav on his site (to contrubute > .. or maybe without willin to ;)) > have to study urllib(?) for things to come > have to experiment more with picklin aspects too > but this is my attempt to beat the > "listenin to mp3s" culture > > btw. where's that help(ao)? > > On Fri, Mar 5, 2010 at 3:43 AM, Anssi Saari wrote: >> "'2+" writes: >> >>> dev = ao.AudioDevice('alsa') >>> dev.play(x) >>> >>> could launch me a semi realtime dj kinda sys >>> luckily .. it does seem to be making the right sound >>> but why? >>> the default of the samplerate and that 16bit happened to match with my thing x? >> >> Yes, that seems to be the case from help(ao). But I couldn't run >> tofu = soy.Bean() since it seems to want tit01.wav. Do you make that >> available somewhere? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > SaRiGaMa's Oil Vending Orchestra > is podcasting: > http://sarigama.namaste.jp/podcast/rss.xml > -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From robert.kern at gmail.com Thu Mar 4 20:04:30 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 19:04:30 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 15:19 PM, Mike Kent wrote: > On Mar 3, 12:00 pm, Robert Kern wrote: >> On 2010-03-03 09:39 AM, Mike Kent wrote: >> >>> What's the compelling use case for this vs. a simple try/finally? >> >>> original_dir = os.getcwd() >>> try: >>> os.chdir(somewhere) >>> # Do other stuff >>> finally: >>> os.chdir(original_dir) >>> # Do other cleanup >> >> A custom-written context manager looks nicer and can be more readable. >> >> from contextlib import contextmanager >> import os >> >> @contextmanager >> def pushd(path): >> original_dir = os.getcwd() >> os.chdir(path) >> try: >> yield >> finally: >> os.chdir(original_dir) >> >> with pushd(somewhere): >> ... > > Robert, I like the way you think. That's a perfect name for that > context manager! However, you can clear one thing up for me... isn't > the inner try/finally superfluous? My understanding was that there > was an implicit try/finally already done which will insure that > everything after the yield statement was always executed. No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. This raises the exception inside the generator at the yield statement. -- 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 From alfps at start.no Thu Mar 4 20:59:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 02:59:31 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Robert Kern: > [...] >>> No, it only argues that "with Cleanup():" is supernumerary. >> I don't know what "supernumerary" means, but to the degree that the >> argument says anything about a construct that is not 'finally', it says >> the same about general "with". >> > So rather than look up the meaning if a word you aren't familiar with > you will argue against its use in generic style? I haven't argued against the use of the word. I haven't done so in generic style, and I haven't argued against generic style use of the word, whatever it is you're trying to say. And I see that you're out trolling again, Steve Holden, implying all sorts of things that are untrue, as is evidently still your style. >> So whatever you mean by supernumerary, you're saying that the argument >> implies that "with" is supernumerary. >> >> This is starting to look like some earlier discussions in this group, >> where even basic logic is denied. >> > Why not just stick to the facts and forget about the earlier discussions? For yet another example, here you are implying that I'm not sticking to facts, which, again, is untrue, a technique that you should be ashamed of, Steve Holden. And since you're now injecting some Steve Holden'sk noise into this debate, chances are that in your points- and win/lose fixation you think I have scored a point immediately upthread, something which you think needs drowning in noise. Cheers, - Alf From breamoreboy at yahoo.co.uk Thu Mar 4 21:01:37 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 05 Mar 2010 02:01:37 +0000 Subject: Looking for the mysterious zlib.py* files in Python 2.6.4 (32-bit) for Windows In-Reply-To: <1267744206.18232.1363186281@webmail.messagingengine.com> References: <1267743672.16774.1363182565@webmail.messagingengine.com> <1267744206.18232.1363186281@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: > In the process of building an EXE with py2exe, I noticed that > there's no physical zlib files anywhere on my workstation. > > I can import zlib and use this module's features without problem. > But when I query zlib.__file__, I get back an empty string. > > Where does the zlib code live? Is zlib a in 2.6? > > The reason I question its '' status is that when > analyzing my 2.6 based Py2exe produced executables with > DependencyWalker, I see references to a zlib.pyd file that > doesn't exist anywhere on my system. I wonder if this is > something I should be concerned about? > > Can someone explain this mystery to me? > > Thank you, > Malcolm c:\Users\Mark>python Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import zlib >>> help(zlib) Help on built-in module zlib: NAME zlib FILE (built-in) [snip the rest of the help output] IIRC a pyd file is really a DLL, but for a built-in its included into in this case python26.dll. HTH. Mark Lawrence From dsblizzard at gmail.com Thu Mar 4 21:10:59 2010 From: dsblizzard at gmail.com (DSblizzard) Date: Thu, 4 Mar 2010 18:10:59 -0800 (PST) Subject: Problem with modules reloading Message-ID: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> I have had already following question: "How to use *.py modules instead of *.pyc?" Last time I when asked that question I resolved problem by using one big .py file. And answers doesn't work in my case. Now I ought to use several files and almost the same problem arises again. Admit I have 2 modules: m2.py and m1.py in m2.py: from m1.py import * def foo2(): foo1() foo2() in m1.py: # empty After copying m2.py contents directly to python.exe: "NameError: global name 'foo1' is not defined" Then I define foo1 in m1 and copy following lines to python.exe: from m1.py import * foo2() Nothing changes, the same error, and .pyc files, if I have deleted them doesn't created again. What is the solution? From timx at nospam.dev.null Thu Mar 4 21:20:02 2010 From: timx at nospam.dev.null (Tim X) Date: Fri, 05 Mar 2010 13:20:02 +1100 Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: <87sk8f1pd9.fsf@lion.rapttech.com.au> ccc31807 writes: > On Mar 3, 4:55?pm, toby wrote: >> > ?where you have to store data and >> >> "relational data" > > Data is neither relational nor unrelational. Data is data. > Relationships are an artifact, something we impose on the data. > Relations are for human convenience, not something inherent in the > data itself. > >> > perform a large number of queries. >> >> Why does the number matter? > > Have you ever had to make a large number of queries to an XML > database? In some ways, an XML database is the counterpart to a > relational database in that the data descriptions constitute the > relations. However, since the search is to the XML elements, and you > can't construct indicies for XML databases in the same way you can > with relational databases, a large search can take much longer that > you might expect. > Most XML databases are just a re-vamp of hierarchical databases, which are one of the two common formats that came before relational databases. Hierarchical, network and relational databases all have their uses. Some 'xml' databases, like existsdb have some pretty powerful indexing technologies. while they are different to relational db indexing because they are based around hierarchies rather than relations, they do provide the ability to do fast queries in the same way that indexes in relational databases allow fast queries over relations. Both solutions can do fast queries, they are just optimised for different types of queries. Likewise, other database technologies that tend to fall into this category, such as couch and mungo are aimed at applications and problems that aren't suitable for the relational db model and are better suited to the types of applications they have been designed for. As usual, Xah's rantings are of little substance here. Yes, he is right that 'nosql' is essentially just another buzzword like 'web 2.0', but so what? This is an industry that loves its buzzwords.Often its just marketing hype or some convenience holder for a vague 'concept' some journalist, consultant or blogger wants to wank on about. You cannot hate or love 'nosql' without defining exactly what you mean by the term. Xah starts by acknowledging the term is ill defined and then goes on to say how he doesn't like it because it lacks the mathematical precision of the relational algebra that underpins the relational model. It seems somewhat ironic to put forward an argument focusing on the importance of precision when you fail to be precise regarding the thing your arguing against. His point is further weakened by the failure to realise that SQL and the relational model and relational algebra are different things. Not having SQL doesn't automatically mean you cannot have a relational model or operations that are based on relational algebra. SQL is just the convenient query language and while it has succeeded where other languages have not, its just one way of interacting with a relational database. As a language SQL isn't even 'pure' in that it has operations that don't fit with the relational algebra that he claims is so important and includes facillities that are really business convenience operations that actually corrupt the mathematical model and purity that is the basis of his poorly formed argument. He also overlooks the fact that none of the successful relational databases have remained true to either the relational model or the underlying theory. All of the major RDMS have corrupted things for marketing, performance or maintenance reasons. Only a very few vendors have stayed true to the relational model and none of them have achieved much in the way of market share, I wonder why? All Xah is doing is being the nets equivalent of radios 'shock jock'. He searches for some topical issue, identifies a stance that he feels will elicit the greatest number of emotional responses and lobs it into the crowd. He rarely hangs around to debate his claims. When he does, he tends to just yell and shout and more often than not, uses personal attack to defend his statements rather than arguing the topic. His analysis is usually shallow and based on popularism If someone disagrees, they are a moron or a fool and if they agree, they are a genius just like him. Just like true radio shock jocks, some willl love him and some will hate him. The only things we can be certain about are that reaction is a much hier motivator for his posts than conviction, there is probably an inverse relationship between IQ and support for his arguments and that his opinion probably has the same longevity as the term nosql. Now if we can just get back to debating important topics like why medical reform is the start of communism, how single mothers are leeching of tax payers, the positive aspects of slavery, why blacks are all criminals, how governments are evil, the holocaust conspiricy, why all muslims are terrorists, the benefits of global warming, the bad science corrupting our children's innocence and stop wasting time debating this technology stuff and please people, listen to your harts and follow your gut - don't let your intellect or so called facts get in the way, trust your emotions. Tim -- tcross (at) rapttech dot com dot au From python at bdurham.com Thu Mar 4 21:24:57 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 04 Mar 2010 21:24:57 -0500 Subject: Looking for the mysterious zlib.py* files in Python 2.6.4 (32-bit) for Windows In-Reply-To: References: <1267743672.16774.1363182565@webmail.messagingengine.com><1267744206.18232.1363186281@webmail.messagingengine.com> Message-ID: <1267755897.13084.1363210547@webmail.messagingengine.com> > IIRC a pyd file is really a DLL, but for a built-in its included into in this case python26.dll. Mystery solved! Thanks Mark! Regards, Malcolm From steve at REMOVE-THIS-cybersource.com.au Thu Mar 4 21:55:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 02:55:46 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> <7v9g9qF1nkU1@mid.individual.net> Message-ID: <4b9072b2$0$27863$c3e8da3@news.astraweb.com> On Thu, 04 Mar 2010 23:38:31 +1300, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> True, but one can look at "best practice", or even "standard practice". >> For Python coders, using docstrings is standard practice if not best >> practice. Using strings as comments is not. > > In that particular case, yes, it would be possible to objectively > examine the code and determine whether docstrings were being used as > opposed to above-the-function comments. > > However, that's only a very small part of what goes to make good code. > Much more important are questions like: Are the comments meaningful and > helpful? Is the code reasonably self-explanatory outside of the > comments? Is it well modularised, and common functionality factored out > where appropriate? Are couplings between different parts minimised? Does > it make good use of library code instead of re-inventing things? Is it > free of obvious security flaws? > > You can't *measure* these things. You can't objectively boil them down > to a number and say things like "This code is 78.3% good; the customer > requires it to be at least 75% good, so it meets the requirements in > that area." > > That's the way in which I believe that software engineering is > fundamentally different from hardware engineering. You are conflating two independent questions: (a) Can we objectively judge the goodness of code, or is it subjective? (b) Is goodness of code quantitative, or is it qualitative? You can turn any qualitative measurement into a quantitative measurement by turning it into a score from 0 to 10 (say). Instead of "best/good/ average/poor/crap" just rate it from 1 through 5, and now you have a measurement that can be averaged and compared with other measurements. The hard part is turning subjective judgements ("are these comments useful, or are they pointless or misleading?") into objective judgements. It may be that there is no entirely objective way to measure such things. But we can make quasi-objective judgements, by averaging out all the individual quirks of subjective judgement: (1) Take 10 independent judges who are all recognised as good Python coders by their peers, and ask them to give a score of 1-5 for the quality of the comments, where 1 means "really bad" and 5 means "really good". If the average score is 4 or higher, gain a point. If the average score is 3 or lower, lose a point. (2) Take 10 independent judges, as above, and rate the code on how self- explanatory it is. An average score of 3 or higher gives a point; an average of under 2 loses a point. (Note that I'm more forgiving of non-self-explanatory code than I am of bad comments. Better to have no comments than bad ones!) And so on, through all the various metrics you want to measure. If the total number of points exceeds some threshold, the software passes, otherwise it fails, and you have a nice list of all the weak areas that need improvement. You can do fancy things too, like discard the highest and lowest score from the ten judges (to avoid an unusually strict, or unusually slack, judge from distorting the scores). If this all seems too expensive, then you can save money by having fewer judges, perhaps even as few as a single code reviewer who is trusted to meet whatever standards you are hoping to apply. Or have the judges rate randomly selected parts of the code rather than all of it. This will severely penalise code that isn't self-explanatory and modular, as the judges will not be able to understand it and consequently give it a low score. Of course, there is still a subjective component to this. But it is a replicable metric: any group of ten judges should give quite similar scores, up to whatever level of confidence you want, and one can perform all sorts of objective statistical tests on them to determine whether deviations are due by chance or not. To do all this on the cheap, you could even pass it through something like PyLint, which gives you an objective (but not very complete) measurement of code quality. The real problem isn't that defining code quality can't be done, but that it can't be done *cheaply*. There are cheap methods, but they aren't very good, and good methods, but they're very expensive. -- Steven From weasle182222 at googlemail.com Thu Mar 4 22:09:57 2010 From: weasle182222 at googlemail.com (lucky-villa) Date: Thu, 4 Mar 2010 19:09:57 -0800 (PST) Subject: baufinanzierung berechnung , eigentumswohnungen finanzieren , eigenheimzulage verdienstgrenze , eigenheimzulage unentgeltliche , bauspardarlehen in anspruch nehmen , immobilienfinanzierung von , eigenheimzulage ab 2009 , Message-ID: baufinanzierung berechnung , eigentumswohnungen finanzieren , eigenheimzulage verdienstgrenze , eigenheimzulage unentgeltliche , bauspardarlehen in anspruch nehmen , immobilienfinanzierung von , eigenheimzulage ab 2009 , + + +++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA IMMOBILIEN +++ + http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL + + + + haus finanzierung online die eigenheimzulage g?nstiges bauspardarlehen einer immobilienfinanzierung haus finanzieren in bauspardarlehen schw?bisch hall eigenheimzulage forum forderungsentkleidete hypothek immobilienkredit rechner erststellige hypothek immobilienfinanzierung dr hall bauspardarlehen eigenheimzulage ?berweisungstermin zins?bersicht baufinanzierung hypothek formel eigenheimzulage pdf hypothekenkredit schweiz immobilienkredite vergleich eigenheimzulage berlin baufinanzierung ?sterreich immobilien finanzierung ohne eigenkapital bauspardarlehen raika immobilienkredit test immobilien krediten eigenheimzulage 15 baufinanzierung vergleich From rami.chowdhury at gmail.com Thu Mar 4 22:11:39 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 4 Mar 2010 19:11:39 -0800 Subject: Problem with modules reloading In-Reply-To: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> References: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> Message-ID: On Mar 4, 2010, at 18:10 , DSblizzard wrote: > I have had already following question: > "How to use *.py modules instead of *.pyc?" > > Last time I when asked that question I resolved problem by using one > big .py file. And answers doesn't work in my case. Now I ought to use > several files and almost the same problem arises again. Admit I have 2 > modules: m2.py and m1.py > > in m2.py: > from m1.py import * > > def foo2(): > foo1() > > foo2() > > in m1.py: > > # empty > > After copying m2.py contents directly to python.exe: > "NameError: global name 'foo1' is not defined" > > Then I define foo1 in m1 and copy following lines to python.exe: > from m1.py import * > foo2() > When you execute the import statement again, Python checks to see which module you are importing from, sees that you have already imported that module, and doesn't reload it. So nothing changes. If you need to reload m1, then use the reload() function: reload(m1) It's generally a good idea to avoid statements like "from m1 import *", to avoid confusion and keep your namespaces separate. So if you had defined m2.py like this... import m1 def foo2(): m1.foo1() ...then "reload(m1)" would solve your problem straight away. > Nothing changes, the same error, and .pyc files, if I have deleted > them doesn't created again. > > What is the solution? > -- > http://mail.python.org/mailman/listinfo/python-list From hawccer at gmail.com Thu Mar 4 22:30:17 2010 From: hawccer at gmail.com (Adhitya Jiwa Pratama) Date: Fri, 5 Mar 2010 10:30:17 +0700 Subject: No subject Message-ID: From steve at REMOVE-THIS-cybersource.com.au Thu Mar 4 22:32:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 03:32:46 GMT Subject: Generic singleton References: Message-ID: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> On Thu, 04 Mar 2010 12:21:26 +0000, Duncan Booth wrote: > Steven D'Aprano wrote: > >> On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote: >> >>> Hello, >>> >>> So I set out to write generic singleton, i.e. the one that would do a >>> singleton with attributes of specified class. At first: >> >> Groan. What is it with the Singleton design pattern? It is one of the >> least useful design patterns, and yet it's *everywhere* in Java and C++ >> world. > > It is also *everywhere* in the Python world. Unlike Java and C++, Python > even has its own built-in type for singletons. > > If you want a singleton in Python use a module. I was wondering who would be the first to point that out :) You are, of course, correct that the preferred way to solve the Singleton problem is with a module. (The other preferred way is with the Borg pattern, which is kind of a reverse-Singleton.) Using classes works too: so long as you do not instantiate it, but use it as an object in its own right, a class is also a singleton. However, I don't think it's quite right to say that modules *are* Singletons, although I accept that this is now getting into a tedious argument about terminology. A singleton is an instance of a class which can only have a single instance. This is not true of modules: >>> import string, math >>> type(string) is type(math) True >>> string is math False Wikipedia points out that the Singleton pattern is normally understood to exclude static structures which merely happen to be created once: "Note the distinction between a simple static instance of a class and a singleton..." http://en.wikipedia.org/wiki/Singleton_pattern Each individual module is a static instance of the module class which merely happens to be instantiated once. (You can subvert Python's import machinery to create multiple copies of a module, but normally this doesn't happen.) So *technically* modules are not singletons, although they behave just like them and give all the benefits, and disadvantages, of such. And as you say, the preferred Pythonic solution to the requirement for a Singleton is usually a module. Python does have it's own singletons, like None, True and False. For some reason, they behave quite differently: NoneType fails if you try to instantiate it again, while bool returns the appropriate existing singleton: >>> NoneType = type(None) >>> NoneType() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances >>> bool(45) True I wonder why NoneType doesn't just return None? -- Steven From robert.kern at gmail.com Thu Mar 4 22:35:13 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 21:35:13 -0600 Subject: A "scopeguard" for Python In-Reply-To: <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: On 2010-03-04 15:12 , Mike Kent wrote: > On Mar 4, 12:30 pm, Robert Kern wrote: > >> He's ignorant of the use cases of the with: statement, true. > > Ouch! Ignorant of the use cases of the with statement, am I? > Odd, I use it all the time. No, I was referring to Jean-Michel, who was not familiar with the with: statement. >> Given only your >> example of the with: statement, it is hard to fault him for thinking that try: >> finally: wouldn't suffice. > > Damn me with faint praise, will you? Also talking about Jean-Michel. :-) -- 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 From robert.kern at gmail.com Thu Mar 4 22:42:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 21:42:32 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: On 2010-03-04 16:27 , Alf P. Steinbach wrote: > * Mike Kent: >> However, I fail to understand his response that I must have meant try/ >> else instead, as this, as Mr. Kern pointed out, is invalid syntax. >> Perhaps Mr. Steinbach would like to give an example? > > OK. > > Assuming that you wanted the chdir to be within a try block (which it > was in your code), then to get code equivalent to my code, for the > purpose of a comparision of codes that do the same, you'd have to write > something like ... > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > except Whatever: > # E.g. log it. > raise > else: > try: > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup > > ... which would be a more general case. > > I've also given this example in response to Robert earlier in the > thread. Although I haven't tried it I believe it's syntactically valid. > If not, then the relevant typo should just be fixed. :-) > > I have no idea which construct Robert thought was syntactically invalid. > I think that if he's written that, then it must have been something he > thought of. I was just trying to interpret what you meant by "Changing 'finally' to 'else' could make it equivalent." As far as I can tell, that has only one possible interpretation going by the plain meaning of the words, and it isn't yours. Since you always seem to refer to "try/else" as if it were an independent construct and not part of "try: except: else:" and no one else introduced except: clause, I must reiterate that your communications have been fabulously misleading. -- 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 From timr at probo.com Thu Mar 4 22:44:34 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 04 Mar 2010 19:44:34 -0800 Subject: python 2.6: how to modify a PIL image from C without copying forth and back References: <4b8daf7d$0$2868$426a74cc@news.free.fr> <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> <4b8e2129$0$8262$426a34cc@news.free.fr> Message-ID: News123 wrote: > >Yes, this might be an option >Somehow though it didn't feel right for me to depend on internal non >documented data types, which might change between releases of PIL. That's absolutely true. If performance is a priority, somethimes you have to do things that are "dirty". Just include lots of comments saying what you did and why. Personally, because so much of PIL is in C, I would judge internal changes to be unlikely. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVE-THIS-cybersource.com.au Thu Mar 4 23:01:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 04:01:21 GMT Subject: Problem with modules reloading References: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> Message-ID: <4b908210$0$27863$c3e8da3@news.astraweb.com> On Thu, 04 Mar 2010 18:10:59 -0800, DSblizzard wrote: > I have had already following question: "How to use *.py modules instead > of *.pyc?" > > Last time I when asked that question I resolved problem by using one big > .py file. I think you are confused. .pyc files are Python compiled byte-code files. You don't use them, Python does. When you import a module, Python *automatically* compiles it and creates a .pyc file, which is then used to speed up loading next time you run Python and import the same module. If you delete the .pyc file, it is quietly recreated next time you import the module again. Using "one big .py file" or not, this has nothing to do with whether Python loads the module from source-code or byte-code. Just ignore the .pyc files. > And answers doesn't work in my case. Now I ought to use > several files and almost the same problem arises again. Admit I have 2 > modules: m2.py and m1.py > > in m2.py: > from m1.py import * That won't work, because Python looks for a package called "m1" which contains a module called "py". The only way that line can succeed is if you have a directory called "m1" containing two files called "__init__.py" and "py.py", like this: m1/ m1/__init__.py m1/py.py Python will then load __init__.py, then load py.py. Since I'm pretty sure you don't have that directory, the above line cannot possible work. > What is the solution? Don't use "from module import *", it is confusing and doesn't work with reload(module) at all. You shouldn't use reload(module) except for experimentation in the interactive interpreter. You should work through the part of the tutorial that talks about modules and imports. http://docs.python.org/tutorial/ http://docs.python.org/tutorial/modules.html Good luck! -- Steven From robert.kern at gmail.com Thu Mar 4 23:01:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 22:01:44 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 17:52 , Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>>>> * Robert Kern: >>>>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >>> [snippety] >>>>>> >>>>>>> If you call the possibly failing operation "A", then that systematic >>>>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>>>> mess, but if A succeeds, then it's the responsibility of the calling >>>>>>> code to clean up if the higher level (multiple statements) operation >>>>>>> that A is embedded in, fails. >>>>>>> >>>>>>> And that's what Marginean's original C++ ScopeGuard was designed >>>>>>> for, >>>>>>> and what the corresponding Python Cleanup class is designed for. >>>>>> >>>>>> And try: finally:, for that matter. >>>>> >>>>> Not to mention "with". >>>>> >>>>> Some other poster made the same error recently in this thread; it is a >>>>> common fallacy in discussions about programming, to assume that since >>>>> the same can be expressed using lower level constructs, those are all >>>>> that are required. >>>>> >>>>> If adopted as true it ultimately means the removal of all control >>>>> structures above the level of "if" and "goto" (except Python doesn't >>>>> have "goto"). >>>> >>>> What I'm trying to explain is that the with: statement has a use even >>>> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >>>> finally: does not mean that the with: statement doesn't improve on >>>> try: finally:. >>> >>> That's a different argument, essentially that you see no advantage for >>> your current coding patterns. >>> >>> It's unconnected to the argument I responded to. >>> >>> The argument that I responded to, that the possibility of expressing >>> things at the level of try:finally: means that a higher level construct >>> is superfluous, is still meaningless. >> >> I am attacking your premise that the "with Cleanup():" construct is >> higher level than try: finally:. It isn't. It provides the same level >> of abstraction as try: finally:. >> >> This is distinct from the accepted uses of the with: statement which >> *are* higher level than try: finally: and which do confer practical >> benefits over using try: finally: despite being syntactical sugar for >> try: finally:. >> >>>>>>>> Both formulations can be correct (and both work perfectly fine with >>>>>>>> the chdir() example being used). Sometimes one is better than the >>>>>>>> other, and sometimes not. You can achieve both ways with either >>>>>>>> your >>>>>>>> Cleanup class or with try: finally:. >>>>>>>> >>>>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>>>> try: >>>>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>>>> into >>>>>>>> callables. This significantly limits what you can do in your >>>>>>>> cleanup >>>>>>>> code. >>>>>>> >>>>>>> Uhm, not really. :-) As I see it. >>>>>> >>>>>> Well, not being able to affect the namespace is a significant >>>>>> limitation. Sometimes you need to delete objects from the >>>>>> namespace in >>>>>> order to ensure that their refcounts go to zero and their cleanup >>>>>> code >>>>>> gets executed. >>>>> >>>>> Just a nit (I agree that a lambda can't do this, but as to what's >>>>> required): assigning None is sufficient for that[1]. >>>> >>>> Yes, but no callable is going to allow you to assign None to names in >>>> that namespace, either. Not without sys._getframe() hackery, in any >>>> case. >>>> >>>>> However, note that the current language doesn't guarantee such >>>>> cleanup, >>>>> at least as far as I know. >>>>> >>>>> So while it's good practice to support it, to do everything to let it >>>>> happen, it's presumably bad practice to rely on it happening. >>>>> >>>>> >>>>>> Tracebacks will keep the namespace alive and all objects in it. >>>>> >>>>> Thanks!, I hadn't thought of connecting that to general cleanup >>>>> actions. >>>>> >>>>> It limits the use of general "with" in the same way. >>>> >>>> Not really. >>> >>> Sorry, it limits general 'with' in /exactly/ the same way. >>> >>>> It's easy to write context managers that do that [delete objects from >>>> the namespace]. >>> >>> Sorry, no can do, as far as I know; your following example quoted below >>> is an example of /something else/. >> >> Okay, so what do you mean by 'the use of general "with"'? I'm talking >> about writing a context manager or using the @contextmanager decorator >> to do some initialization and then later cleaning up that >> initialization. That cleaning up may entail deleting an object. You >> are correct that the context manager can't affect the namespace of the >> with: clause, but that's not the initialization that it would need to >> clean up. >> >> Yes, you can write code with a with: statement where you try to clean >> up stuff that happened inside of the clause (you did), but that's not >> how the with: statement was ever intended to be used nor is it good >> practice to do so because of that limitation. Context managers are >> designed to initialize specific things, then clean them up. I thought >> you were talking about the uses of the with: statement as described in >> PEP-343, not every possible misuse of the with: statement. > > I'm not the one talking about removing variables or that "it's easy to > write context managers that do that". > > You are the one talking about that. > > So I have really not much to add. > > It seems that you're now agreeing with me that former is not good > practice and that the latter is impossible to do portably, but you now > argue against your earlier stand as if that was something that I had put > forward. No, I'm still saying that sometimes you do need to remove variables that you initialized in the initialization section. Writing a purpose-built context manager which encapsulates the initialization and finalization allows you to do this easily. Putting the initialization section inside the with: clause, as you do, and requiring cleanup code to be put into callables makes this hard. > It's a bit confusing when you argue against your own statements. > >>> And adding on top of irrelevancy, for the pure technical aspect it can >>> be accomplished in the same way using Cleanup (I provide an example >>> below). >>> >>> However, doing that would generally be worse than pointless since with >>> good coding practices the objects would become unreferenced anyway. >>> >>> >>>> You put the initialization code in the __enter__() method, assign >>>> whatever objects you want to keep around through the with: clause as >>>> attributes on the manager, then delete those attributes in the >>>> __exit__(). >>> >>> Analogously, if one were to do this thing, then it could be accomplished >>> using a Cleanup context manager as follows: >>> >>> foo = lambda: None >>> foo.x = create_some_object() >>> at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) >>> >>> ... except that >>> >>> 1) for a once-only case this is less code :-) >> >> Not compared to a try: finally:, it isn't. > > Again, this context shifting is bewildering. As you can see, quoted > above, you were talking about a situation where you would have defined a > context manager, presumably because a 'try' would not in your opinion be > simpler for whatever it was that you had in mind. But you are responding > to the code I offered as if it was an alternative to something where you > would find a 'try' to be simplest. I have consistently put forward that for once-only cases, try: finally: is a preferable construct to "with Cleanup():". I also put forward that for repetitive cases, a purpose-built context manager is preferable. I note that for both try: finally: and a purpose-built context manager, modifying the namespace is easy to do while it is difficult and less readable to do with "with Cleanup():". Since you were claiming that the "generic with:" would have the same problem as "with Cleanup():" I was trying to explain for why all of the intended use cases of the with: statement (the purpose-built context managers), there is no problem. Capisce? >>> 2) it is a usage that I wouldn't recommend; instead I recommend adopting >>> good >>> coding practices where object references aren't kept around. >> >> Many of the use cases of the with: statement involve creating an >> object (like a lock or a transaction object), keeping it around for >> the duration of the "# Do stuff" block, and then finalizing it. >> >>>> Or, you use the @contextmanager decorator to turn a generator into a >>>> context manager, and you just assign to local variables and del them >>>> in the finally: clause. >>> >>> Uhm, you don't need a 'finally' clause when you define a context >>> manager. >> >> When you use the @contextmanager decorator, you almost always do. See >> the Examples section of PEP 343: >> >> http://www.python.org/dev/peps/pep-0343/ >> >>> Additionally, you don't need to 'del' the local variables in >>> @contextmanager decorated generator. >>> >>> The local variables cease to exist automatically. >> >> True. >> >>>> What you can't do is write a generic context manager where the >>>> initialization happens inside the with: clause and the cleanup actions >>>> are registered callables. That does not allow you to affect the >>>> namespace. >>> >>> If you mean that you can't introduce direct local variables and have >>> them deleted by "registered callables" in a portable way, then right. >>> >>> But I can't think of any example where that would be relevant; in >>> particular what matters for supporting on-destruction cleanup is whether >>> you keep any references or not, not whether you have a local variable of >>> any given name. >> >> Well, local variables keep references to objects. Variable assignment >> followed by deletion is a very readable way to keep an object around >> for a while then remove it later. If you have to go through less >> readable contortions to keep the object around when it needs to be and >> clean it up later, then that is a mark against your approach. > > Sorry, as with the places noted above, I can't understand what you're > trying to say here. I don't recommend coding practices where you keep > object references around, Then how do you clean up locks and transaction objects and similar things if you don't keep them around during the code suite? Creating an object, keeping it around while executing a specific chunk of code, and finalizing it safely is a prime use case for these kinds of constructs. > and you have twice quoted that above. I don't > have any clue what "contortions" you are talking about, it must be > something that you imagine. These are the contortions: foo = lambda: None foo.x = create_some_object() at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) -- 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 From chris.lieb at gmail.com Thu Mar 4 23:07:12 2010 From: chris.lieb at gmail.com (Chris Lieb) Date: Thu, 4 Mar 2010 20:07:12 -0800 (PST) Subject: Failure in test_hashlib.py and test_hmac.py References: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> Message-ID: <545b8abb-72a3-4527-b290-d937cfce5470@t23g2000yqt.googlegroups.com> On Mar 3, 8:33?pm, Chris Lieb wrote: > I am building Python 2.6.4 on a shared server and am encountering test > failures in test_hashlib.py and test_hmac.py, specifically concerning > sha512. ?I recompiled Python with --with-pydebug and CLFAGS=CPPFLAGS="- > g" and ran the tests in GDB and got the following results: > > ---------------------------------------------------------------------------- > > GNU gdb 6.6.50.20070726-cvs > Copyright (C) 2007 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and > you are > welcome to change it and/or distribute copies of it under certain > conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. ?Type "show warranty" for > details. > This GDB was configured as "x86_64-suse-linux"... > Using host libthread_db library "/lib64/libthread_db.so.1". > (gdb) run test_hashlib.py > Starting program: /export/users1/chris.lieb/packages/python/bin/ > python2.6 test_hashlib.py > test_case_md5_0 (__main__.HashLibTestCase) ... ok > test_case_md5_1 (__main__.HashLibTestCase) ... ok > test_case_md5_2 (__main__.HashLibTestCase) ... ok > test_case_md5_huge (__main__.HashLibTestCase) ... ok > test_case_md5_uintmax (__main__.HashLibTestCase) ... ok > test_case_sha1_0 (__main__.HashLibTestCase) ... ok > test_case_sha1_1 (__main__.HashLibTestCase) ... ok > test_case_sha1_2 (__main__.HashLibTestCase) ... ok > test_case_sha1_3 (__main__.HashLibTestCase) ... ok > test_case_sha224_0 (__main__.HashLibTestCase) ... ok > test_case_sha224_1 (__main__.HashLibTestCase) ... ok > test_case_sha224_2 (__main__.HashLibTestCase) ... ok > test_case_sha224_3 (__main__.HashLibTestCase) ... ok > test_case_sha256_0 (__main__.HashLibTestCase) ... ok > test_case_sha256_1 (__main__.HashLibTestCase) ... ok > test_case_sha256_2 (__main__.HashLibTestCase) ... ok > test_case_sha256_3 (__main__.HashLibTestCase) ... ok > test_case_sha384_0 (__main__.HashLibTestCase) ... ok > test_case_sha384_1 (__main__.HashLibTestCase) ... ok > test_case_sha384_2 (__main__.HashLibTestCase) ... ok > test_case_sha384_3 (__main__.HashLibTestCase) ... ok > test_case_sha512_0 (__main__.HashLibTestCase) ... FAIL > test_case_sha512_1 (__main__.HashLibTestCase) ... FAIL > test_case_sha512_2 (__main__.HashLibTestCase) ... FAIL > test_case_sha512_3 (__main__.HashLibTestCase) ... FAIL > test_hexdigest (__main__.HashLibTestCase) ... > Program received signal SIGSEGV, Segmentation fault. > Cannot remove breakpoints because program is no longer writable. > It might be running in another process. > Further execution is probably impossible. > 0x00002ba86ffbb463 in ?? () > (gdb) bt > #0 ?0x00002ba86ffbb463 in ?? () > #1 ?0x000000000046993d in PyString_FromStringAndSize ( > ? ? str=0x7fff71c67800 " \203 5~? T(P m\200\a \005\vW > \025 \203 ! l G <] > \205 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?5 > \203\030 \207~ /c 1 GAz\201 82z ' > x q \177", > size=1054484473) > ? ? at Objects/stringobject.c:90 > #2 ?0x00002ba87030d59a in ?? () > #3 ?0x0000000000000000 in ?? () > > ----------------------------------------------------------------------------------------- > > GNU gdb 6.6.50.20070726-cvs > Copyright (C) 2007 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and > you are > welcome to change it and/or distribute copies of it under certain > conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. ?Type "show warranty" for > details. > This GDB was configured as "x86_64-suse-linux"... > Using host libthread_db library "/lib64/libthread_db.so.1". > (gdb) run test_hmac.py > Starting program: /export/users1/chris.lieb/packages/python/bin/ > python2.6 test_hmac.py > test_legacy_block_size_warnings (__main__.TestVectorsTestCase) ... ok > test_md5_vectors (__main__.TestVectorsTestCase) ... ok > test_sha224_rfc4231 (__main__.TestVectorsTestCase) ... ok > test_sha256_rfc4231 (__main__.TestVectorsTestCase) ... ok > test_sha384_rfc4231 (__main__.TestVectorsTestCase) ... ok > test_sha512_rfc4231 (__main__.TestVectorsTestCase) ... > Program received signal SIGSEGV, Segmentation fault. > Cannot remove breakpoints because program is no longer writable. > It might be running in another process. > Further execution is probably impossible. > 0x00002b483844e4c7 in ?? () > (gdb) bt > #0 ?0x00002b483844e4c7 in ?? () > #1 ?0x000000000046993d in PyString_FromStringAndSize ( > ? ? str=0x7ffff84f6730 "\026C3D \235D\t \025 [ G > \032bG? ~ \235\t\233aP", > ? ? size=4108309188) at Objects/stringobject.c:90 > #2 ?0x00002b48387e159a in ?? () > #3 ?0x0000000000000000 in ?? () > > -------------------------------------------------------------------- > > In the case of test_hashlib.py, it segfaulted on the first sha512 test > when I didn't have the debugging options enabled. ?Only after enabling > debugging did I get FAIL's for the sha512 tests. > > Does anyone know what is causing these failures? Does anyone have any tips or insights for trying to debug this issue? Any help is greatly appreciated. -- Chris Lieb From showell30 at yahoo.com Thu Mar 4 23:14:42 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 20:14:42 -0800 (PST) Subject: Generic singleton References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> Message-ID: <866ef5a6-119d-4962-bf99-57915d3a59d5@g28g2000prb.googlegroups.com> On Mar 4, 7:32?pm, Steven D'Aprano wrote: > > Python does have it's own singletons, like None, True and False. For some > reason, they behave quite differently: NoneType fails if you try to > instantiate it again, while bool returns the appropriate existing > singleton: > > >>> NoneType = type(None) > >>> NoneType() > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: cannot create 'NoneType' instances>>> bool(45) > > True > > I wonder why NoneType doesn't just return None? > It's an interesting question. Just to elaborate on your example: >>> type(None)() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances >>> type(True)(False) False >>> type(False)(True) True I suspect that the answer is just that None is special. There is probably just no compelling use case where you want to clone None in a one-liner. To make None work like True/False in certain use cases you'd want something like this: def clone(val): if val is None: return None else: return type(val)(val) The same method would work against some non-singletons as well, although I'm not sure what the desired semantics would actually be: for value in [None, False, True, 42, [1, 2, 3]]: print clone(value) From showell30 at yahoo.com Thu Mar 4 23:37:50 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 20:37:50 -0800 (PST) Subject: A "scopeguard" for Python References: Message-ID: On Mar 3, 7:10?am, "Alf P. Steinbach" wrote: > For C++ Petru Marginean once invented the "scope guard" technique (elaborated on > by Andrei Alexandrescu, they published an article about it in DDJ) where all you > need to do to ensure some desired cleanup at the end of a scope, even when the > scope is exited via an exception, is to declare a ScopeGuard w/desired action. > > The C++ ScopeGuard was/is for those situations where you don't have proper > classes with automatic cleanup, which happily is seldom the case in good C++ > code, but languages like Java and Python don't support automatic cleanup and so > the use case for something like ScopeGuard is ever present. > > For use with a 'with' statement and possibly suitable 'lambda' arguments: > > > class Cleanup: > ? ? ?def __init__( self ): > ? ? ? ? ?self._actions = [] > > ? ? ?def call( self, action ): > ? ? ? ? ?assert( is_callable( action ) ) > ? ? ? ? ?self._actions.append( action ) > > ? ? ?def __enter__( self ): > ? ? ? ? ?return self > > ? ? ?def __exit__( self, x_type, x_value, x_traceback ): > ? ? ? ? ?while( len( self._actions ) != 0 ): > ? ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ? ?self._actions.pop()() > ? ? ? ? ? ? ?except BaseException as x: > ? ? ? ? ? ? ? ? ?raise AssertionError( "Cleanup: exception during cleanup" ) from > > > I guess the typical usage would be what I used it for, a case where the cleanup > action (namely, changing back to an original directory) apparently didn't fit > the standard library's support for 'with', like > > ? ?with Cleanup as at_cleanup: > ? ? ? ?# blah blah > ? ? ? ?chdir( somewhere ) > ? ? ? ?at_cleanup.call( lambda: chdir( original_dir ) ) > ? ? ? ?# blah blah > > Another use case might be where one otherwise would get into very deep nesting > of 'with' statements with every nested 'with' at the end, like a degenerate tree > that for all purposes is a list. Then the above, or some variant, can help to > /flatten/ the structure. To get rid of that silly & annoying nesting. :-) > > Cheers, > > - Alf (just sharing, it's not seriously tested code) Hi Alf, I think I understand the notion you're going after here. You have multiple cleanup steps that you want to defer till the end, and there is some possibility that things will go wrong along the way, but you want to clean up as much as you can. And, of course, flatter is better. Is this sort of what you are striving for? class Cleanup: def __init__( self ): self._actions = [] def call( self, action ): self._actions.append( action ) def __enter__( self ): return self def __exit__( self, x_type, x_value, x_traceback ): while( len( self._actions ) != 0 ): try: self._actions.pop()() except BaseException as x: raise AssertionError( "Cleanup: exception during cleanup" ) def clean_the_floor(): print('clean the floor') def carouse(num_bottles, accident): with Cleanup() as at_cleanup: at_cleanup.call(clean_the_floor) for i in range(num_bottles): def take_down(i=i): print('take one down', i) at_cleanup.call(take_down) if i == accident: raise Exception('oops!') print ('put bottle on wall', i) carouse(10, None) carouse(5, 3) From showell30 at yahoo.com Fri Mar 5 00:12:17 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 21:12:17 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> Message-ID: On Mar 4, 12:52?am, Paul Rubin wrote: > mk writes: > > OK, but how? How would you make up e.g. for JSON's lack of comments? > > Modify the JSON standard so that "JSON 2.0" allows comments. If you don't control the JSON standard, providing a compelling alternative to JSON might be the best way to force JSON to accomodate a wider audience. It might just be that the people behind JSON deliberately avoid comments, because it's not in the scope of the problem they are trying to solve. Hence another need for alternatives. > > OTOH, if YAML produces net benefit for as few as, say, 200 people in > > real world, the effort to make it has been well worth it. > > Not if 200,000 other people have to deal with it but don't receive the > benefit. > How many hundreds of thousands of people have had to deal with XML without receiving its benefits? Do well-established standards get an exemption from the rule that software is not allowed to annoy non- willing users of it? From ken at seehart.com Fri Mar 5 00:33:26 2010 From: ken at seehart.com (Ken Seehart) Date: Thu, 04 Mar 2010 21:33:26 -0800 Subject: IMAP mail filters tool Message-ID: <4B9097A6.2050600@seehart.com> I'm thinking of possibly making a simple client-agnostic tool for filtering and processing IMAP email. I'm a Thunderbird user, but I'm interested in a tool that is not client software specific. So I am is checking for prior art. Does anyone know of a filter tool with most of these features? * Written and customizable with python * IMAP based * Runs on client (i.e. without installing anything on the server) * Runs completely independent of client software (though could be launched from any email client that can support it) * Automatically suggests new rules based on manual movement of emails into folders (based on comparison of all header data across all existing folders) * Take arbitrary actions in response to rules (e.g. universally denying access to spam senders to all online cheese shops) * Capable of serving as a prototyping framework for things like spam filtering * General filtering functionality, not particularly focused on spam * Posts and updates rules to server via IMAP (i.e. by sending and automagically processing a special email message). Typical work-flow would be aimed at users who like to automatically sort their email prior to reading it. The goal is to have nearly all email sorted into folders so that most mail remaining in the Inbox is likely to be leftover spam missed by whatever spam filters are being used. In other words, the filters tend to effectively serve as white lists. Examples of unusual rules that don't seem to be supported by most email clients: * When you send an email, add the recipient to a filter such that email from that recipient goes to a "Unfiltered Replies" folder if it does not match any other filter. * Receiving email with certain fields matching certain regular expressions could automatically create a new folder and filter e.g.: o List-Id: "SF Bay Area Python group " yields a new folder "Lists/SF Bay Area Python group" with a corresponding rule o X-Launchpad-Bug: "product=phatch; milestone=..." yields a new folder "Bugs/Phatch" with a corresponding rule o X-Bugzilla-Product: "Shrubbery" yields a new folder "Bugs/Shrubbery" with a corresponding rule Thanks, Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Fri Mar 5 00:36:06 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 18:36:06 +1300 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7xlje8lb9o.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> Message-ID: <7vbiuqF4utU1@mid.individual.net> Paul Rubin wrote: > ReST was another solution in search of a problem. I think the basic idea behind ReST is quite good, i.e. understanding as markup various typographical conventions that make sense in plain text, such as underlined headings, bullets, numbered paragraphs. Unfortunately it went overboard with a slew of cryptic codes for footnotes, hyperlinks, etc. that nobody would naturally think to use in a plain text document. -- Greg From showell30 at yahoo.com Fri Mar 5 00:36:51 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 21:36:51 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> Message-ID: <696158a0-dccf-4fa2-b6ab-bb1c4cb2e219@m35g2000prh.googlegroups.com> On Mar 4, 9:36?pm, Gregory Ewing wrote: > Paul Rubin wrote: > > ReST was another solution in search of a problem. > > I think the basic idea behind ReST is quite good, i.e. > understanding as markup various typographical conventions > that make sense in plain text, such as underlined > headings, bullets, numbered paragraphs. > > Unfortunately it went overboard with a slew of cryptic > codes for footnotes, hyperlinks, etc. that nobody would > naturally think to use in a plain text document. > The same thing happened with YAML to a certain extent, from my perspective. YAML was never meant to be an exact alternative to XML, but its basic premise was sound--use indentation for more elegant syntax, and model its semantics more toward how data actually gets used internally by scripting languages in particular. But there is also some featuritis with YAML that makes it hard to digest and needlessly cumbersome to implement. JSON is not perfect by any means, but I consider it to be a more useful descendant of XML and YAML, even if it did not directly borrow from either. (YAML and JSON are certainly similar, but that could be a coincidental convergence.) Even if YAML itself has not been a resounding success, it set the bar to a certain degree. From aahz at pythoncraft.com Fri Mar 5 01:00:50 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Mar 2010 22:00:50 -0800 Subject: WANTED: A good name for the pair (args, kwargs) References: Message-ID: In article , Tim Chase wrote: >Jonathan Fine wrote: >> >> We can call a function fn using >> val = fn(*args, **kwargs) >> >> I'm looking for a good name for the pair (args, kwargs). Any suggestions? >> >> For now I'll use argpair, but if anyone has a better idea, I'll use it. > >In the legacy of C and Java (okay, that doesn't carry _much_ weight >with me), I'd go with "varargs" to refer to the pair of (args, kwargs) Ditto -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From nagle at animats.com Fri Mar 5 01:35:45 2010 From: nagle at animats.com (John Nagle) Date: Thu, 04 Mar 2010 22:35:45 -0800 Subject: NoSQL Movement? In-Reply-To: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <4b90a1f8$0$1629$742ec2ed@news.sonic.net> Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > at http://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. Too much rant, not enough information. There is an argument against using full relational databases for some large-scale applications, ones where the database is spread over many machines. If the database can be organized so that each transaction only needs to talk to one database machine, the locking problems become much simpler. That's what BigTable is really about. For many web applications, each user has more or less their own data, and most database activity is related to a single user. Such applications can easily be scaled up with a system that doesn't have inter-user links. There can still be inter-user references, but without a consistency guarantee. They may lead to dead data, like Unix/Linux symbolic links. This is a mechanism adequate for most "social networking" sites. There are also some "consistent-eventually" systems, where a query can see old data. For non-critical applications, those can be very useful. This isn't a SQL/NoSQL thing; MySQL asynchronous replication is a "consistent-eventually" system. Wikipedia uses that for the "special" pages which require database lookups. If you allow general joins across any tables, you have to have all the very elaborate interlocking mechanisms of a distributed database. The serious database systems (MySQL Cluster and Oracle, for example) do offer that, but there are usually substantial complexity penalties, and the databases have to be carefully organized to avoid excessive cross-machine locking. If you don't need general joins, a system which doesn't support them is far simpler. John Nagle From greg.ewing at canterbury.ac.nz Fri Mar 5 01:54:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 19:54:48 +1300 Subject: NoSQL Movement? In-Reply-To: References: Message-ID: <7vbnieFovtU1@mid.individual.net> Duncan Booth wrote: > Did I mention that bigtable doesn't require you to have the same > columns in every record? The main use of bigtable (outside of Google's > internal use) is Google App Engine and that apparently uses one table. > > Not one table per application, one table total. It's a big table. Seems to me in that situation the term "table" ceases to have any meaning. If every record can have its own unique structure, and data from completely unrelated applications can all be thrown in together, there's no more reason to call it a "table" than, say, "file", "database" or "big pile of data". -- Greg From news123 at free.fr Fri Mar 5 02:21:30 2010 From: news123 at free.fr (News123) Date: Fri, 05 Mar 2010 08:21:30 +0100 Subject: _winreg and accessing registry settings of another user In-Reply-To: <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> References: <4b90252b$0$17806$426a34cc@news.free.fr> <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> Message-ID: <4b90b0fa$0$8332$426a74cc@news.free.fr> Mensanator wrote: > On Mar 4, 3:24 pm, News123 wrote: >> Hi, >> >> I have administrator privilege on a window host and would like to write >> a script setting some registry entries for other users. > > Why? Are you writing a virus? > Writing a virus in python???? Why not? though I didn't think about it as ideal choice of implementing viruses. For my script to run I have to run it explicitly as administrator (as being required by Vista / Win7). My script shall be part of installing and configuring a PC with some default settings with the minimal amount of human administrator interactions. The steps: - install windows - install python - setup one admin account and one or more user accounts (without admin privileges) - run a script, that preconfigures registry settings for some users. As mentioned before I see at least two possible ways and achieving this but lack information for either. 1.) run a sub process or thread as another user (the user wouldn't even have a password during the installation phase) and change the registry from this thread. I have no experience of running 'suid' under windows. 2.) being able to load the 'hive' of another user into the registry and be therefore able to change his settings. I didn't find a function allowing _winreg to load additional 'hives' bye N From greg.ewing at canterbury.ac.nz Fri Mar 5 02:33:44 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 20:33:44 +1300 Subject: Generic singleton In-Reply-To: References: Message-ID: <7vbprcF49gU1@mid.individual.net> mk wrote: > Or I could make my life simpler and use global variable. :-) Indeed. You actually *have* a global variable already, you've just hidden it inside another object. That doesn't make it any less global, though. If you want to defer creation of the object until the first time it's used, use a function that creates an instance the first time it's called. Your Singleton class is really just an overly elaborate way of implementing such a function. -- Greg From no.email at nospam.invalid Fri Mar 5 02:46:46 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 23:46:46 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> Message-ID: <7xvddbqkgp.fsf@ruckus.brouhaha.com> Steve Howell writes: >> Modify the JSON standard so that "JSON 2.0" allows comments. > > If you don't control the JSON standard, providing a compelling > alternative to JSON might be the best way to force JSON to accomodate > a wider audience. Ehh, either the JSON standardizers care about this issue or else they don't. JSON (as currently defined) is a machine-to-machine serialization format and just isn't that good a choice for handwritten files. Adding a comment specification is a small perturbation that might be accepted into the standard, but a big departure like RSON is a whole nother creature. > How many hundreds of thousands of people have had to deal with XML > without receiving its benefits? Do well-established standards get an > exemption from the rule that software is not allowed to annoy non- > willing users of it? We already have to deal with XML. So using XML for config files doesn't require anyone to deal with any lousy formats that they didn't have to deal with before. So the basic answer to your question about well-established standards is yes: one annoying but standardized format is better than multiple annoying unstandardized ones. From no.email at nospam.invalid Fri Mar 5 02:50:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 23:50:15 -0800 Subject: Failure in test_hashlib.py and test_hmac.py References: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> Message-ID: <7xr5nzqkaw.fsf@ruckus.brouhaha.com> Chris Lieb writes: > I am building Python 2.6.4 on a shared server and am encountering test > failures in test_hashlib.py and test_hmac.py, You should certainly file a bug report (bugs.python.org). If you want to debug it yourself and include a patch, that's great. Otherwise, just file the report. In the case of test_hashlib.py, it segfaulted on the first sha512 test when I didn't have the debugging options enabled. Only after enabling debugging did I get FAIL's for the sha512 tests. Does anyone know what is causing these failures? Please be precise about the hw and compiler versions. From stefan_ml at behnel.de Fri Mar 5 03:03:36 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 05 Mar 2010 09:03:36 +0100 Subject: Partly erratic wrong behaviour, Python 3, lxml In-Reply-To: References: Message-ID: Jussi Piitulainen, 04.03.2010 22:40: > Stefan Behnel writes: >> Jussi Piitulainen, 04.03.2010 11:46: >>> I am observing weird semi-erratic behaviour that involves Python 3 >>> and lxml, is extremely sensitive to changes in the input data, and >>> only occurs when I name a partial result. I would like some help >>> with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml >>> version?) >> >> Here's how to find the version: >> >> http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do > > Ok, thank you. Here's the results: > > >>> print(et.LXML_VERSION, et.LIBXML_VERSION, > ... et.LIBXML_COMPILED_VERSION, et.LIBXSLT_VERSION, > ... et.LIBXSLT_COMPILED_VERSION) > (2, 2, 4, 0) (2, 6, 26) (2, 6, 26) (1, 1, 17) (1, 1, 17) I can't reproduce this with the latest lxml trunk (and Py3.2 trunk) and libxml2 2.7.6, even after running your test script for quite a while. I'd try to upgrade the libxml2 version. Stefan From lipun4u at gmail.com Fri Mar 5 03:04:13 2010 From: lipun4u at gmail.com (asit) Date: Fri, 5 Mar 2010 00:04:13 -0800 (PST) Subject: indentation error Message-ID: Consider the following code import stat, sys, os, string, commands try: pattern = raw_input("Enter the file pattern to search for :\n") commandString = "find " + pattern commandOutput = commands.getoutput(commandString) findResults = string.split(commandOutput, "\n") print "Files : " print commandOutput print "=============================" for file in findResults: mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE]) print "\nPermissions for file", file, ":" for level in "USR", "GRP", "OTH": for perm in "R", "W", "X": if mode & getattr(stat,"S_I"+perm+level): print level, " has ", perm, " permission" else: print level, " does NOT have ", perm, " permission" except: print "There was a problem - check the message above" According to me, indentation is ok. but the python interpreter gives an indentation error [asit ~/py] $ python search.py File "search.py", line 7 findResults = string.split(commandOutput, "\n") ^ IndentationError: unindent does not match any outer indentation level From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 03:05:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 08:05:16 GMT Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> Message-ID: <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 18:36:06 +1300, Gregory Ewing wrote: > Paul Rubin wrote: >> ReST was another solution in search of a problem. > > I think the basic idea behind ReST is quite good, i.e. understanding as > markup various typographical conventions that make sense in plain text, > such as underlined headings, bullets, numbered paragraphs. > > Unfortunately it went overboard with a slew of cryptic codes for > footnotes, hyperlinks, etc. that nobody would naturally think to use in > a plain text document. I use footnotes all the time[1] in plain text documents and emails. I don't think there's anything bizarre about it at all. [1] When I say "all the time", I actually mean occasionally. -- Steven From jimgardener at gmail.com Fri Mar 5 03:05:18 2010 From: jimgardener at gmail.com (jimgardener) Date: Fri, 5 Mar 2010 00:05:18 -0800 (PST) Subject: comparing two lists Message-ID: hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst=['jon','arya','ned','bran'] newlst=['jaime','jon','cersei'] newlyadded=set(newlst)-set(oldlst) removed=set(oldlst)-set(newlst) unchanged=set(oldlst)& set(newlst) print '%d were newly added= %s'%(len(newlyadded),list(newlyadded)) print '%d were removed=%s'%(len(removed),list(removed)) print '%d were unchanged=%s'%(len(unchanged),list(unchanged)) this produces the output -------------- 2 were newly added= ['jaime', 'cersei'] 3 were removed=['ned', 'arya', 'bran'] 1 were unchanged=['jon'] From greg.ewing at canterbury.ac.nz Fri Mar 5 03:10:01 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 21:10:01 +1300 Subject: Passing FILE * types using ctypes In-Reply-To: References: Message-ID: <7vbrveFegeU1@mid.individual.net> Francesco Bochicchio wrote: > Python file objects have a method fileno() whic returns the 'C file > descriptor', i.e. the number used by low level IO in python as well as > in C. > I would use this as interface between python and C and then in the C > function using fdopen to get a FILE * for an already open file for > which you have a file descriptor. But note that this will be a *new* stdio file buffer attached to the same file descriptor, not the same one that the Python file object is using. This may or may not be a problem depending on what you're trying to do. If you need the same FILE * that Python is using, you may need to use ctypes to extract it out of the file object. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 5 03:25:47 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 21:25:47 +1300 Subject: Docstrings considered too complicated In-Reply-To: <4b9072b2$0$27863$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> <7v9g9qF1nkU1@mid.individual.net> <4b9072b2$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vbssvFjgcU1@mid.individual.net> Steven D'Aprano wrote: > (a) Can we objectively judge the goodness of code, or is it subjective? > > (b) Is goodness of code quantitative, or is it qualitative? Yes, I'm not really talking about numeric vs. non-numeric, but objective vs. subjective. The measurement doesn't have to yield a numeric result, it just has to be doable by some objective procedure. If you can build a machine to do it, then it's objective. If you have to rely on the judgement of a human, then it's subjective. > But we can make quasi-objective judgements, by averaging out all the > individual quirks of subjective judgement: > > (1) Take 10 independent judges who are all recognised as good Python > coders by their peers, and ask them to give a score of 1-5 for the > quality of the comments... Yes, but this is an enormous amount of effort to go to, and at the end of the day, the result is only reliable in a statistical sense. This still seems to me to be qualitatively different from something like testing the tensile strength of a piece of steel. You can apply a definite procedure and obtain a definite result, and no human judgement is required at all. -- Greg From mjoachimiak at gmail.com Fri Mar 5 03:30:49 2010 From: mjoachimiak at gmail.com (Michael Joachimiak) Date: Fri, 5 Mar 2010 10:30:49 +0200 Subject: ImportError: No module named glib Message-ID: <7c857e8c1003050030x39b75c98veace4ef8eebe606a@mail.gmail.com> I am too new to python. If anybody has an idea what to do please help. when I use import glib in my code I get this: >>> import glib Traceback (most recent call last): File "", line 1, in ImportError: No module named glib :~$ python -V Python 2.6.4 /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version 2.18.0-0ubuntu2 :~$ pkg-config glib-2.0 --cflags --libs -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 From eckhardt at satorlaser.com Fri Mar 5 03:32:17 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 05 Mar 2010 09:32:17 +0100 Subject: indentation error References: Message-ID: asit wrote: > pattern = raw_input("Enter the file pattern to search for :\n") > commandString = "find " + pattern > commandOutput = commands.getoutput(commandString) > findResults = string.split(commandOutput, "\n") > print "Files : " > print commandOutput > print "=============================" > for file in findResults: > mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE]) > print "\nPermissions for file", file, ":" > for level in "USR", "GRP", "OTH": > for perm in "R", "W", "X": > if mode & getattr(stat,"S_I"+perm+level): > print level, " has ", perm, " permission" > else: > print level, " does NOT have ", perm, " > permission" [...] > According to me, indentation is ok. but the python interpreter gives > an indentation error > > [asit ~/py] $ python search.py > File "search.py", line 7 > findResults = string.split(commandOutput, "\n") > ^ > IndentationError: unindent does not match any outer indentation level Hard to tell, since your posting was already line-broken which already changes the correctness. In any case, watch for tabs/spaces, many editors have an option to display whitespace. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From r1chardj0n3s at gmail.com Fri Mar 5 03:39:49 2010 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Fri, 5 Mar 2010 19:39:49 +1100 Subject: 10th Python Game Programming Challenge in three weeks Message-ID: <249b6faa1003050039n17e16b0p80ef8474c2d94167@mail.gmail.com> The 10th Python Game Programming Challenge (http://pyweek.org/) will run from the 28th of March to the 4th of April. The PyWeek challenge: - Invites entrants to write a game in one week from scratch either as an individual or in a team, - Is intended to be challenging and fun, - Will hopefully increase the public body of game tools, code and expertise, - Will let a lot of people actually finish a game, and - May inspire new projects (with ready made teams!) Come along and play, it's lots of fun :) Richard From gh at ghaering.de Fri Mar 5 03:40:50 2010 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 5 Mar 2010 09:40:50 +0100 Subject: [ANN] pysqlite 2.6.0 released Message-ID: <496f9fbb1003050040k7c057e2s1941d216eb46ce5b@mail.gmail.com> pysqlite 2.6.0 released ======================= Release focus: Synchronize with sqlite3 module in Python trunk. pysqlite is a DB-API 2.0-compliant database interface for SQLite. SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. Go to http://pysqlite.googlecode.com/ for downloads, online documentation and for reporting bugs. Changes ======= - pysqlite can now be built against Python versions without thread support - PyDict_SetItem is now checked so you cannot shoot yourself in the foot, even if you try to - More checks for closed connections were added to avoid possible segfaults Compatibility ============= Warning: pysqlite is not supported for Python < 2.5 any longer. This release still builds against Python 2.3 and 2.4, but I won't bother with these in the future. From vlastimil.brom at gmail.com Fri Mar 5 03:50:03 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 5 Mar 2010 09:50:03 +0100 Subject: comparing two lists In-Reply-To: References: Message-ID: <9fdb569a1003050050y5705dd4bi6e757e59adb40d66@mail.gmail.com> 2010/3/5 jimgardener : > hi > I have two lists of names.I need to find the difference between these > two lists.I tried to do it using sets.But I am wondering if there is a > better way to do it.Please tell me if there is a more elegant way. > thanks, > jim > > my code snippet follows.. > > oldlst=['jon','arya','ned','bran'] > newlst=['jaime','jon','cersei'] > > newlyadded=set(newlst)-set(oldlst) > removed=set(oldlst)-set(newlst) > unchanged=set(oldlst)& set(newlst) > print '%d were newly added= %s'%(len(newlyadded),list(newlyadded)) > print '%d were removed=%s'%(len(removed),list(removed)) > print '%d were unchanged=%s'%(len(unchanged),list(unchanged)) > > this produces the output > -------------- > 2 were newly added= ['jaime', 'cersei'] > 3 were removed=['ned', 'arya', 'bran'] > 1 were unchanged=['jon'] > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I guess for lists with unique items and order insignificant this is just fine; you may also check difflib, if it suits your needs; there are multiple comparing and displaying possibilities, e.g.: >>> import difflib >>> print "\n".join(difflib.unified_diff(['jon','arya','ned','bran'], ['jaime','jon','cersei'])) --- +++ @@ -1,4 +1,3 @@ +jaime jon -arya -ned -bran +cersei >>> hth, vbr From duncan.booth at invalid.invalid Fri Mar 5 04:07:49 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2010 09:07:49 GMT Subject: NoSQL Movement? References: <7vbnieFovtU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > Duncan Booth wrote: >> Did I mention that bigtable doesn't require you to have the same >> columns in every record? The main use of bigtable (outside of Google's >> internal use) is Google App Engine and that apparently uses one table. >> >> Not one table per application, one table total. It's a big table. > > Seems to me in that situation the term "table" ceases to > have any meaning. If every record can have its own unique > structure, and data from completely unrelated applications > can all be thrown in together, there's no more reason to > call it a "table" than, say, "file", "database" or "big > pile of data". > I think it depends on how you look at things. AppEngine uses a programming model which behaves very much as though you do have multiple tables: you use Django's programming model to wrap each record in a class, or you can use Gql query languages which looks very similar to SQL and again the class names appear in the place of table names. So conceptually thinking of it as separate tables make a lot of sense, but the underlying implementation is apparently a single table where records simply have a type field that is used to instantiate the proper class on the Python side (and another hidden application field to prevent you accessing another application's data). Also of course records with the same type still may not all have the same columns if you change the class definition between runs, so even at this level they aren't tables in the strict SQL sense. There may of course be other applications using bigtable where the bigtable(s) look much more like ordinary tables, but I don't know what they are. >From your suggested terms, I'd agree you could call it a database rather than a table but I think it's too structured for "file" or "big pile of data" to be appropriate. -- Duncan Booth http://kupuguy.blogspot.com From magnicida at gmail.com Fri Mar 5 04:37:04 2010 From: magnicida at gmail.com (Juan Pedro Bolivar Puente) Date: Fri, 05 Mar 2010 11:37:04 +0200 Subject: NoSQL Movement? In-Reply-To: <7bfeffcd-722e-4df4-8455-7710207d9c7e@a18g2000yqc.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> <7bfeffcd-722e-4df4-8455-7710207d9c7e@a18g2000yqc.googlegroups.com> Message-ID: <4B90D0C0.7020508@gmail.com> On 04/03/10 19:52, ccc31807 wrote: > On Mar 4, 11:51 am, Juan Pedro Bolivar Puente > wrote: >> No, relations are data. > > This depends on your definition of 'data.' I would say that > relationships is information gleaned from the data. > >> "Data is data" says nothing. Data is >> information. > > To me, data and information are not the same thing, and in particular, > data is NOT information. To me, information consists of the sifting, > sorting, filtering, and rearrangement of data that can be useful in > completing some task. As an illustration, consider some very large > collection of ones and zeros -- the information it contains depends on > whether it's views as a JPEG, an EXE, XML, WAV, or other sort of > information processing device. Whichever way it's processed, the > 'data' (the ones and zeros) stay the same, and do not constitute > 'information' in their raw state. > >> Actually, all data are relations: relating /values/ to >> /properties/ of /entities/. Relations as understood by the "relational >> model" is nothing else but assuming that properties and entities are >> first class values of the data system and the can also be related. > > Well, this sort of illustrates my point. The 'values' of 'properties' > relating to specific 'entities' depends on how one processes the data, > which can be processed various ways. For example, 10000001 can either > be viewed as the decimal number 65 or the alpha character 'A' but the > decision as to how to view this value isn't inherent in the data > itself, but only as an artifact of our use of the data to turn it into > information. > Well, it depends as you said on the definition of information; actually your definition of data fits into the information-theorical definition of information as sequence of symbols... But I understand that in other context /information/ can also mean the next level of abstraction on top of /data/, in the same way as /knowledge/ is the next level of abstraction on top of information; lets ground or basis on that. In any case, your definition and George's still support my point of view where relations are data: they are stored in the computer as a sequence of ones and zeroes and is indistinguishable from any other thing in the data space in that sense. Of course, it is a key data to be able to recover information and specially to add new information consistently to the data storage... That SQL includes special syntax for manipulating relations should not hide this fact; and one can still query the relational information in the same way one would query non-relational data in most DBMS anyway... Anyway I'm sorry for drifting the conversation away... Going back to the main topic, I agree with the general view on this thread that relational databases (information-bases ? ;) and non-relational ones are there to do some different jobs. It is just by carefully examining a problem that we can define which one fits it better; with relational databases having the clear advantage that is mathematically grounded basis makes its fitness for most problems quite clear, while the preference for non-relational systems is a more technical and empirical problem of the trade-offs of consistency vs scalability and so on. JP From no.email at nospam.invalid Fri Mar 5 04:45:54 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Mar 2010 01:45:54 -0800 Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> Message-ID: <7xhbov2jal.fsf@ruckus.brouhaha.com> lbolla writes: > for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') This is the nicest solution, I think. Mine was more cumbersome. From mail at timgolden.me.uk Fri Mar 5 04:59:17 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 05 Mar 2010 09:59:17 +0000 Subject: _winreg and accessing registry settings of another user In-Reply-To: <4b90b0fa$0$8332$426a74cc@news.free.fr> References: <4b90252b$0$17806$426a34cc@news.free.fr> <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> <4b90b0fa$0$8332$426a74cc@news.free.fr> Message-ID: <4B90D5F5.4040802@timgolden.me.uk> On 05/03/2010 07:21, News123 wrote: > My script shall be part of installing and configuring a PC with some > default settings with the minimal amount of human administrator > interactions. > > The steps: > - install windows > - install python > - setup one admin account and one or more user accounts (without admin > privileges) > - run a script, that preconfigures registry settings for some users. > 2.) being able to load the 'hive' of another user into the registry and > be therefore able to change his settings. I didn't find a function > allowing _winreg to load additional 'hives' You can use a combination of the win32security, win32api and win32profile modules from the pywin32 package for this: import win32security import win32api import win32profile username = "USERNAME" domain = "DOMAIN" password = "PASSWORD" hUser = win32security.LogonUser ( username, domain, password, win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT ) hReg = win32profile.LoadUserProfile ( hUser, {"UserName" : "fozrestore"} ) try: print win32api.RegEnumKeyExW (hReg) finally: win32profile.UnloadUserProfile (hUser, hReg) TJG From phil at freehackers.org Fri Mar 5 05:01:06 2010 From: phil at freehackers.org (BlueBird) Date: Fri, 5 Mar 2010 02:01:06 -0800 (PST) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: On 3 mar, 20:35, Stefan Behnel wrote: > BlueBird, 03.03.2010 17:32: > > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > > that this does not exist. Does anybody know about this ? > > SOAP may be an overly bloated protocol, but it's certainly not black magic. > It's not hard to do manually if you really need to: > > http://effbot.org/zone/element-soap.htm But this requires a goog knowloedge of SOAP, in order to parse everything correctly. The reason I want to use a ready-made client is that I have about zero knowledge about SOAP, and even more in the differences between SOAP 1.1 and 1.2 . cheers, Philippe From aurelien.gourrier at yahoo.fr Fri Mar 5 05:35:42 2010 From: aurelien.gourrier at yahoo.fr (=?iso-8859-1?Q?Aur=E9_Gourrier?=) Date: Fri, 5 Mar 2010 10:35:42 +0000 (GMT) Subject: Proper way to return an instance of a class from a class method ? Message-ID: <918065.487.qm@web23104.mail.ird.yahoo.com> Dear all, I have what will probably sound as stupid questions for experienced Python users... which I am not, hence my seeking for some help. ------------ QUESTION 1: I've implemeted a class which defines a container with 2 lists of data (with some specific format). Some of the methods simply transform these data and therefore return a new container of 2 lists. I want to be able to use these results without having to re-instanciate them, so I return them as instances of the class: class MyClass: def __init__(self, data): #various checks for the format and content of data (data = [x,y] where x and y are 2 lists of floats) self.data = data def transformdata(self): newdata = transform(data) return MyClass(newdata) In this way I can do: x = list1 y = list2 data = MyClass([x,y]) moddata = data.transformdata() moddata2 = moddata.transformdata() Is that the correct way to go (i.e. is this pythonic) ? What I want to avoid is: moddata = data.transformdata() moddata2 = MyClass(moddata).transformdata() ------------ QUESTION 2: If I go this way, I have a second problem: if I create a new class which inherits from the previous, I would expect/like the methods from the initial class to return instances from the new class: class MyClass2(MyClass): def othermethods(self): return MyClass2(whatever) Then I get: x = list1 y = list2 data = MyClass2([x,y]) finaldata = data.transformdata() My problem is that finaldata is (of course) an instance of MyClass and not MyClass2. How do I deal with this ? All help will be much appreciated... Cheers, Aur? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Mar 5 05:44:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 11:44:57 +0100 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <4B90E0A9.6000600@sequans.com> Pete Emerson wrote: > I've written my first python program, and would love suggestions for > improvement. > > I'm a perl programmer and used a perl version of this program to guide > me. So in that sense, the python is "perlesque" > > This script parses /etc/hosts for hostnames, and based on terms given > on the command line (argv), either prints the list of hostnames that > match all the criteria, or uses ssh to connect to the host if the > number of matches is unique. > > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". > > I am aware that there are performance improvements and error checking > that could be made, such as making sure the file exists and is > readable and precompiling the regular expressions and not calculating > how many sys.argv arguments there are more than once. I'm not hyper > concerned with performance or idiot proofing for this particular > script. > > Thanks in advance. > > ######################################################## > #!/usr/bin/python > > import sys, fileinput, re, os > > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > if match is None or re.search('^(?:float|localhost)\.', line): > continue > hostname = match.group(1) > count = 0 > for arg in sys.argv[1:]: > for section in hostname.split('.'): > if section == arg: > count = count + 1 > break > if count == len(sys.argv) - 1: > hosts.append(hostname) > > if len(hosts) == 1: > os.system("ssh -A " + hosts[0]) > else: > print '\n'.join(hosts) > You've already been given good advices. Unlike some of those, I don't think using regexp an issue in any way. Yes they are not readable, for sure, I 100% agree to that statement, but you can make them readable very easily. # not readable match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # readable match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # match '192.168.200.1 (foo123)' I gladly understand ppl that are not willing to use regexp (or as last resort), but for a perl guy, that should not be an issue. JM From bruno.42.desthuilliers at websiteburo.invalid Fri Mar 5 05:54:28 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Mar 2010 11:54:28 +0100 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <4b90e2d0$0$10096$426a34cc@news.free.fr> Philip Semanchuk a ?crit : > > On Mar 3, 2010, at 5:41 PM, Avid Fan wrote: > >> Jonathan Gardner wrote: >> >>> I see it as a sign of maturity with sufficiently scaled software that >>> they no longer use an SQL database to manage their data. At some point >>> in the project's lifetime, the data is understood well enough that the >>> general nature of the SQL database is unnecessary. >> >> I am really struggling to understand this concept. >> >> Is it the normalised table structure that is in question or the query >> language? >> >> Could you give some sort of example of where SQL would not be the way >> to go. The only things I can think of a simple flat file databases. > > Well, Zope is backed by an object database rather than a relational one. And it ended up being a *major* PITA on all Zope projects I've worked on... From mblume at socha.net Fri Mar 5 05:54:49 2010 From: mblume at socha.net (mblume) Date: 05 Mar 2010 10:54:49 GMT Subject: ImportError: No module named glib References: Message-ID: <4b90e2f9$0$4046$5402220f@news.sunrise.ch> Am Fri, 05 Mar 2010 10:30:49 +0200 schrieb Michael Joachimiak: > I am too new to python. > If anybody has an idea what to do please help. when I use > > import glib > > in my code I get this: > >>>> import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib > Shot in the dark: maybe "import pyglib"? Hint: you can look around in /usr/lib/python to see what files can be imported. HTH Martin From azt113 at gmail.com Fri Mar 5 06:39:54 2010 From: azt113 at gmail.com (Ines T) Date: Fri, 5 Mar 2010 11:39:54 +0000 (UTC) Subject: Selecting MAX from a list Message-ID: I need to select a maximum number from a list and then call the variable that identifies that number, for example: x1,x2=1, y1,y2=4, z1,z2=3 So I need first to find 4 and then to take y to do additional operations as y-z. I will appreciate your SOON help! From santhosh.vkumar at gmail.com Fri Mar 5 06:41:00 2010 From: santhosh.vkumar at gmail.com (Santhosh Kumar) Date: Fri, 5 Mar 2010 17:11:00 +0530 Subject: Speech to Text Message-ID: <404c076d1003050341w327ceec7x63cfb0c01469d35d@mail.gmail.com> Hi All, I am trying to find is there is any way to covert "speech to Text" with Python in UBUNTU. I googled whr I found Many Text to speech. Some one please assist me. -- With Regards, Never Say No, Santhosh V.Kumar +919840411410 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Mar 5 06:46:54 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Mar 2010 12:46:54 +0100 Subject: ImportError: No module named glib References: Message-ID: Michael Joachimiak wrote: > I am too new to python. > If anybody has an idea what to do please help. > when I use > > import glib > > in my code I get this: > >>>> import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib > > :~$ python -V > Python 2.6.4 > > /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version > 2.18.0-0ubuntu2 > > :~$ pkg-config glib-2.0 --cflags --libs > -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 After the following random walk through my system $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import glib >>> glib.__file__ '/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.pyc' In the above __init__.py: ... from glib._glib import * _PyGLib_API = _glib._PyGLib_API del _glib ... >>> import sys >>> sys.modules["glib._glib"] >>> $ dpkg -S _glib.so python-gobject: /usr/lib/pyshared/python2.5/gtk-2.0/glib/_glib.so python-gobject: /usr/lib/pyshared/python2.6/gtk-2.0/glib/_glib.so $ ... I believe that you have to install the python-gobject package. Peter From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 06:48:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 11:48:35 GMT Subject: indentation error References: Message-ID: <4b90ef93$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 00:04:13 -0800, asit wrote: > Consider the following code [snip] > According to me, indentation is ok. but the python interpreter gives an > indentation error You can trust the interpreter. There *is* an indentation error. Most likely you have mixed spaces and tabs. Try: python -t -t search.py instead. (Yes, -t twice.) On an unrelated note, your code snippet shows a very poor coding style. Firstly, bare "except" clauses are VERY bad practice: it will mask bugs in your code. Secondly, you should wrap the smallest amount of code in the try block as you need. Something like this is probably better: pattern = raw_input("Enter the file pattern to search for :\n") commandString = "find " + pattern commandOutput = commands.getoutput(commandString) findResults = string.split(commandOutput, "\n") print "Files : " print commandOutput print "=============================" for file in findResults: try: mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE]) except (IOError, OSError): # Print a useless error message so your users will hate you. print "There was a problem with %s" % file continue print "\nPermissions for file", file, ":" for level in "USR", "GRP", "OTH": for perm in "R", "W", "X": if mode & getattr(stat,"S_I"+perm+level): print level, " has ", perm, " permission" else: print level, " does NOT have ", perm, "permission" -- Steven From anand.shashwat at gmail.com Fri Mar 5 06:54:19 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Mar 2010 17:24:19 +0530 Subject: Selecting MAX from a list In-Reply-To: References: Message-ID: On Fri, Mar 5, 2010 at 5:09 PM, Ines T wrote: > I need to select a maximum number from a list use max() > and then call the variable that > identifies that number, for example: > x1,x2=1, y1,y2=4, z1,z2=3 > you mean x1 = y1 = 1 or x1, y1 = 1, 1 right ? > So I need first to find 4 and then to take y to do additional operations as > y-z. > Well, I guess you got the idea > I will appreciate your SOON help! > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Fri Mar 5 06:56:34 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 12:56:34 +0100 Subject: NoSQL Movement? In-Reply-To: <4b90e2d0$0$10096$426a34cc@news.free.fr> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90e2d0$0$10096$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> Well, Zope is backed by an object database rather than a relational one. > > And it ended up being a *major* PITA on all Zope projects I've worked on... Care to write a few sentences on nature of problems with zodb? I was flirting with the thought of using it on some project. Regards, mk From clp2 at rebertia.com Fri Mar 5 07:01:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 04:01:32 -0800 Subject: Proper way to return an instance of a class from a class method ? In-Reply-To: <918065.487.qm@web23104.mail.ird.yahoo.com> References: <918065.487.qm@web23104.mail.ird.yahoo.com> Message-ID: <50697b2c1003050401h466d7f36t63b5f713d5271e4f@mail.gmail.com> On Fri, Mar 5, 2010 at 2:35 AM, Aur? Gourrier wrote: > QUESTION 2: > If I go this way, I have a second problem: if I create a new class which > inherits from the previous, I would expect/like the methods from the initial > class to return instances from the new class: > > class MyClass2(MyClass): > > ??? def othermethods(self): > ??? ??? return MyClass2(whatever) > > Then I get: > > x = list1 > y = list2 > data = MyClass2([x,y]) > finaldata = data.transformdata() > > My problem is that finaldata is (of course) an instance of MyClass and not > MyClass2. How do I deal with this ? Get the object's actual class at runtime and use that. #in MyClass def transformdata(self): newdata = transform(data) return self.__class__(newdata) When called on an instance of the subclass, self.__class__ will be MyClass2 and everything will work out. Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Fri Mar 5 07:15:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Mar 2010 13:15:59 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: <4b902338$0$31260$607ed4bc@cv.net> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> Message-ID: <4b90f5eb$0$9148$426a74cc@news.free.fr> John Posner a ?crit : > On 3/3/2010 6:56 PM, John Posner wrote: >> >> ... I was thinking >> today about "doing a Bruno", and producing similar pieces on: >> >> * properties created with the @property decorator >> >> * the descriptor protocol >> >> I'll try to produce something over the next couple of days. >> > > Starting to think about a writeup on Python properties, I've discovered > that the official Glossary [1] lacks an entry for "property" -- it's > missing in both Py2 and Py3! > > Here's a somewhat long-winded definition -- comments, please: > > --------------------------------------------- > An attribute, *a*, of an object, *obj*, is said to be implemented as a > property if the standard ways of accessing the attribute: > > * evaluation: print obj.a > * assignment: obj.a = 42 > * deletion: del obj.a > > ... cause methods of a user-defined *property object* to be invoked. Hmmm... a couple remarks: 1/ "property" is actually the name of a Python builtin type. It's also pretty much used in general OO litterature for what we name "attributes". So I think it would be better to avoid confusion between "property" as the builtin type, "property" as synonym for attribute, and "property" as the more specific concept of "computed attribute" - which is what you're describing here. As far as I'm concerned, I prefer to stick to "computed attribute" for the generic case, and only use "property" when the computed attribute is actually implemented using the builtin property type. 2/ depending on how the computed attribute is implemented, the computation needs not happen on ALL get/set/del access - you can have non-binding descriptors (that is, not implementing __set__). Also, the "standard" access also include getattr(), setattr() and delattr() (might be worth a note). > The > attribute /attribute/user-defined object/ here ? > is created as a class attribute, not an instance attribute. > Example: > > class Widget: > # create "color" as class attribute, not within __init__() > color = <> > > def __init__(self, ...): > # do not define "self.color" instance attribute Yes you can, and it's even actually pretty common: # example.py from somewhere import RGBColor class Foo(object): def _get_color(self): return str(self._color) def _set_color(self, val): self._color = RGBColor.from_string(val) color = property(fget=_get_color, fset=_set_color) def __init__(self, colorvalue): self.color = colorvalue > The property object can be created with the built-in function > property(), It's actually a type, not a function. > which in some cases can be coded as a decorator: @property. > The property object can also be an instance of a class that implements > the descriptor protocol. The "property object" IS an instance of a class that implements the descriptor protocol. The property type is just a "generic" descriptor: # naive (and incomplete) python implementation of the property type class property(object): def __init__(self, fget, fset=None, fdel=None) self._fget = fget self._fset = fset self._fdel = fdel def __get__(self, instance, cls): if instance is None: return self return self._fget(instance) def __set__(self, instance, value): if not self._fset: raise AttributeError("can't set attribute") self._fset(instance, value) def __del__(self): if not self._fdel: raise AttributeError("can't delete attribute") self._fdel(instance) As far as I'm concerned, I'd "plan" such a paper as: """ What's a property ? It's a computed attribute implemented using the builtin "property" type. Ok, so far it doesn't help much. So 1/ what's a computed attribute, and 2/ what is the property type ? 1/ your above explanation about what's a computed attribute in general, then a brief explanation of how computed attributes are implemented in python -> IOW, the descriptor protocol 2/ my above snippet !-) """ I think the way you started explaining computed attributes wrt/ attribute access could be a pretty good way to explain the descriptor protocol, since the mapping from get/set/del access to __get__, __set__, and __del__ magic methods is then pretty obvious. But YMMV of course, so by all mean feel free to discard all or parts of the above remarks !-) HTH From lbolla at gmail.com Fri Mar 5 07:19:23 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 5 Mar 2010 04:19:23 -0800 (PST) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: <13753751-d0af-48df-b78d-5b371109e05c@t41g2000yqt.googlegroups.com> On Mar 5, 10:01?am, BlueBird wrote: > On 3 mar, 20:35, Stefan Behnel wrote: > > > BlueBird, 03.03.2010 17:32: > > > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > > > that this does not exist. Does anybody know about this ? > > > SOAP may be an overly bloated protocol, but it's certainly not black magic. > > It's not hard to do manually if you really need to: > > >http://effbot.org/zone/element-soap.htm > > But this requires a goog knowloedge of SOAP, in order to parse > everything correctly. The reason I want to use a ready-made client is > that I have about zero knowledge about SOAP, and even more in the > differences between SOAP 1.1 and 1.2 . > > cheers, > > Philippe I use a thin custom-made python wrapper around gSoap[1], which is tens of times faster than ZSI. L. [1] http://www.cs.fsu.edu/~engelen/soapdoc2.html From jeanmichel at sequans.com Fri Mar 5 07:20:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 13:20:04 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: <4B90F6F4.5010202@sequans.com> Robert Kern wrote: > On 2010-03-04 15:12 , Mike Kent wrote: >> On Mar 4, 12:30 pm, Robert Kern wrote: >> >>> He's ignorant of the use cases of the with: statement, true. >> >> Ouch! Ignorant of the use cases of the with statement, am I? >> Odd, I use it all the time. > > No, I was referring to Jean-Michel, who was not familiar with the > with: statement. > >>> Given only your >>> example of the with: statement, it is hard to fault him for thinking >>> that try: >>> finally: wouldn't suffice. >> >> Damn me with faint praise, will you? > > Also talking about Jean-Michel. :-) > I confirm, I am the ignoramus (what a strange word) in this story :-) JM From lbolla at gmail.com Fri Mar 5 07:24:51 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 5 Mar 2010 04:24:51 -0800 (PST) Subject: Selecting MAX from a list References: Message-ID: On Mar 5, 11:39?am, Ines T wrote: > I need to select a maximum number from a list and then call the variable that > identifies that number, for example: > x1,x2=1, y1,y2=4, z1,z2=3 > So I need first to find 4 and then to take y to do additional operations as y-z. It's not clear what you are supposed to do, but wouldn't a combination of "max" and "index" do? x = [3,2,1,4,5,2,3] max(x) # 5 x.index(5) # 4 > I will appreciate your SOON help! And, by the way, politeness is free! From alfps at start.no Fri Mar 5 08:06:55 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 14:06:55 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 17:52 , Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>>>>> * Robert Kern: >>>>>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >>>> [snippety] >>>>>>> >>>>>>>> If you call the possibly failing operation "A", then that >>>>>>>> systematic >>>>>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>>>>> mess, but if A succeeds, then it's the responsibility of the >>>>>>>> calling >>>>>>>> code to clean up if the higher level (multiple statements) >>>>>>>> operation >>>>>>>> that A is embedded in, fails. >>>>>>>> >>>>>>>> And that's what Marginean's original C++ ScopeGuard was designed >>>>>>>> for, >>>>>>>> and what the corresponding Python Cleanup class is designed for. >>>>>>> >>>>>>> And try: finally:, for that matter. >>>>>> >>>>>> Not to mention "with". >>>>>> >>>>>> Some other poster made the same error recently in this thread; it >>>>>> is a >>>>>> common fallacy in discussions about programming, to assume that since >>>>>> the same can be expressed using lower level constructs, those are all >>>>>> that are required. >>>>>> >>>>>> If adopted as true it ultimately means the removal of all control >>>>>> structures above the level of "if" and "goto" (except Python doesn't >>>>>> have "goto"). >>>>> >>>>> What I'm trying to explain is that the with: statement has a use even >>>>> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >>>>> finally: does not mean that the with: statement doesn't improve on >>>>> try: finally:. >>>> >>>> That's a different argument, essentially that you see no advantage for >>>> your current coding patterns. >>>> >>>> It's unconnected to the argument I responded to. >>>> >>>> The argument that I responded to, that the possibility of expressing >>>> things at the level of try:finally: means that a higher level construct >>>> is superfluous, is still meaningless. >>> >>> I am attacking your premise that the "with Cleanup():" construct is >>> higher level than try: finally:. It isn't. It provides the same level >>> of abstraction as try: finally:. >>> >>> This is distinct from the accepted uses of the with: statement which >>> *are* higher level than try: finally: and which do confer practical >>> benefits over using try: finally: despite being syntactical sugar for >>> try: finally:. >>> >>>>>>>>> Both formulations can be correct (and both work perfectly fine >>>>>>>>> with >>>>>>>>> the chdir() example being used). Sometimes one is better than the >>>>>>>>> other, and sometimes not. You can achieve both ways with either >>>>>>>>> your >>>>>>>>> Cleanup class or with try: finally:. >>>>>>>>> >>>>>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>>>>> try: >>>>>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>>>>> into >>>>>>>>> callables. This significantly limits what you can do in your >>>>>>>>> cleanup >>>>>>>>> code. >>>>>>>> >>>>>>>> Uhm, not really. :-) As I see it. >>>>>>> >>>>>>> Well, not being able to affect the namespace is a significant >>>>>>> limitation. Sometimes you need to delete objects from the >>>>>>> namespace in >>>>>>> order to ensure that their refcounts go to zero and their cleanup >>>>>>> code >>>>>>> gets executed. >>>>>> >>>>>> Just a nit (I agree that a lambda can't do this, but as to what's >>>>>> required): assigning None is sufficient for that[1]. >>>>> >>>>> Yes, but no callable is going to allow you to assign None to names in >>>>> that namespace, either. Not without sys._getframe() hackery, in any >>>>> case. >>>>> >>>>>> However, note that the current language doesn't guarantee such >>>>>> cleanup, >>>>>> at least as far as I know. >>>>>> >>>>>> So while it's good practice to support it, to do everything to let it >>>>>> happen, it's presumably bad practice to rely on it happening. >>>>>> >>>>>> >>>>>>> Tracebacks will keep the namespace alive and all objects in it. >>>>>> >>>>>> Thanks!, I hadn't thought of connecting that to general cleanup >>>>>> actions. >>>>>> >>>>>> It limits the use of general "with" in the same way. >>>>> >>>>> Not really. >>>> >>>> Sorry, it limits general 'with' in /exactly/ the same way. >>>> >>>>> It's easy to write context managers that do that [delete objects from >>>>> the namespace]. >>>> >>>> Sorry, no can do, as far as I know; your following example quoted below >>>> is an example of /something else/. >>> >>> Okay, so what do you mean by 'the use of general "with"'? I'm talking >>> about writing a context manager or using the @contextmanager decorator >>> to do some initialization and then later cleaning up that >>> initialization. That cleaning up may entail deleting an object. You >>> are correct that the context manager can't affect the namespace of the >>> with: clause, but that's not the initialization that it would need to >>> clean up. >>> >>> Yes, you can write code with a with: statement where you try to clean >>> up stuff that happened inside of the clause (you did), but that's not >>> how the with: statement was ever intended to be used nor is it good >>> practice to do so because of that limitation. Context managers are >>> designed to initialize specific things, then clean them up. I thought >>> you were talking about the uses of the with: statement as described in >>> PEP-343, not every possible misuse of the with: statement. >> >> I'm not the one talking about removing variables or that "it's easy to >> write context managers that do that". >> >> You are the one talking about that. >> >> So I have really not much to add. >> >> It seems that you're now agreeing with me that former is not good >> practice and that the latter is impossible to do portably, but you now >> argue against your earlier stand as if that was something that I had put >> forward. > > No, I'm still saying that sometimes you do need to remove variables that > you initialized in the initialization section. Writing a purpose-built > context manager which encapsulates the initialization and finalization > allows you to do this easily. Putting the initialization section inside > the with: clause, as you do, and requiring cleanup code to be put into > callables makes this hard. > >> It's a bit confusing when you argue against your own statements. >> >>>> And adding on top of irrelevancy, for the pure technical aspect it can >>>> be accomplished in the same way using Cleanup (I provide an example >>>> below). >>>> >>>> However, doing that would generally be worse than pointless since with >>>> good coding practices the objects would become unreferenced anyway. >>>> >>>> >>>>> You put the initialization code in the __enter__() method, assign >>>>> whatever objects you want to keep around through the with: clause as >>>>> attributes on the manager, then delete those attributes in the >>>>> __exit__(). >>>> >>>> Analogously, if one were to do this thing, then it could be >>>> accomplished >>>> using a Cleanup context manager as follows: >>>> >>>> foo = lambda: None >>>> foo.x = create_some_object() >>>> at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) >>>> >>>> ... except that >>>> >>>> 1) for a once-only case this is less code :-) >>> >>> Not compared to a try: finally:, it isn't. >> >> Again, this context shifting is bewildering. As you can see, quoted >> above, you were talking about a situation where you would have defined a >> context manager, presumably because a 'try' would not in your opinion be >> simpler for whatever it was that you had in mind. But you are responding >> to the code I offered as if it was an alternative to something where you >> would find a 'try' to be simplest. > > I have consistently put forward that for once-only cases, try: finally: > is a preferable construct to "with Cleanup():". I also put forward that > for repetitive cases, a purpose-built context manager is preferable. I > note that for both try: finally: and a purpose-built context manager, > modifying the namespace is easy to do while it is difficult and less > readable to do with "with Cleanup():". Since you were claiming that the > "generic with:" would have the same problem as "with Cleanup():" I was > trying to explain for why all of the intended use cases of the with: > statement (the purpose-built context managers), there is no problem. > Capisce? > >>>> 2) it is a usage that I wouldn't recommend; instead I recommend >>>> adopting >>>> good >>>> coding practices where object references aren't kept around. >>> >>> Many of the use cases of the with: statement involve creating an >>> object (like a lock or a transaction object), keeping it around for >>> the duration of the "# Do stuff" block, and then finalizing it. >>> >>>>> Or, you use the @contextmanager decorator to turn a generator into a >>>>> context manager, and you just assign to local variables and del them >>>>> in the finally: clause. >>>> >>>> Uhm, you don't need a 'finally' clause when you define a context >>>> manager. >>> >>> When you use the @contextmanager decorator, you almost always do. See >>> the Examples section of PEP 343: >>> >>> http://www.python.org/dev/peps/pep-0343/ >>> >>>> Additionally, you don't need to 'del' the local variables in >>>> @contextmanager decorated generator. >>>> >>>> The local variables cease to exist automatically. >>> >>> True. >>> >>>>> What you can't do is write a generic context manager where the >>>>> initialization happens inside the with: clause and the cleanup actions >>>>> are registered callables. That does not allow you to affect the >>>>> namespace. >>>> >>>> If you mean that you can't introduce direct local variables and have >>>> them deleted by "registered callables" in a portable way, then right. >>>> >>>> But I can't think of any example where that would be relevant; in >>>> particular what matters for supporting on-destruction cleanup is >>>> whether >>>> you keep any references or not, not whether you have a local >>>> variable of >>>> any given name. >>> >>> Well, local variables keep references to objects. Variable assignment >>> followed by deletion is a very readable way to keep an object around >>> for a while then remove it later. If you have to go through less >>> readable contortions to keep the object around when it needs to be and >>> clean it up later, then that is a mark against your approach. >> >> Sorry, as with the places noted above, I can't understand what you're >> trying to say here. I don't recommend coding practices where you keep >> object references around, > > Then how do you clean up locks and transaction objects and similar > things if you don't keep them around during the code suite? Creating an > object, keeping it around while executing a specific chunk of code, and > finalizing it safely is a prime use case for these kinds of constructs. Where you need a scope, create a scope. That is, put the logic in a routine. However, most objects aren't of the sort the requiring to become unreferenced. Those that require cleanup can be cleaned up and left as zombies, like calling 'close' on a file. And so in the general case what you're discussing, how to get rid of object references, is a non-issue -- irrelevant. >> and you have twice quoted that above. I don't >> have any clue what "contortions" you are talking about, it must be >> something that you imagine. > > These are the contortions: > > foo = lambda: None > foo.x = create_some_object() > at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) That's code that demonstrates something very different, in response to your description of doing this. Since I half suspected that it could be taken out of context I followed that immediately with 2) it is a usage that I wouldn't recommend; instead I recommend adopting good coding practices where object references aren't kept around. I'm sorry but I don't know how to make that more clear. Cheers & hth., - Alf From alfps at start.no Fri Mar 5 08:09:08 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 14:09:08 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 16:27 , Alf P. Steinbach wrote: >> * Mike Kent: > >>> However, I fail to understand his response that I must have meant try/ >>> else instead, as this, as Mr. Kern pointed out, is invalid syntax. >>> Perhaps Mr. Steinbach would like to give an example? >> >> OK. >> >> Assuming that you wanted the chdir to be within a try block (which it >> was in your code), then to get code equivalent to my code, for the >> purpose of a comparision of codes that do the same, you'd have to write >> something like ... >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> except Whatever: >> # E.g. log it. >> raise >> else: >> try: >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup >> >> ... which would be a more general case. >> >> I've also given this example in response to Robert earlier in the >> thread. Although I haven't tried it I believe it's syntactically valid. >> If not, then the relevant typo should just be fixed. :-) >> >> I have no idea which construct Robert thought was syntactically invalid. >> I think that if he's written that, then it must have been something he >> thought of. > > I was just trying to interpret what you meant by "Changing 'finally' to > 'else' could make it equivalent." Oh yes, in the article where I gave the example of that, shown above. Hey, discussing previous discussion is silly. Cheers, - ALf From mrkafk at gmail.com Fri Mar 5 08:26:13 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 14:26:13 +0100 Subject: loop over list and process into groups In-Reply-To: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <4B910675.60909@gmail.com> Sneaky Wombat wrote: > [ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] Hey, I just invented a cute ;-) two-liner using list comprehensions: # alist = list above tmp, dk = [], {} [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) for x in alist if x != 'Interface'] No need to use a nuke like itertools to kill a fly. ;-) Regards, mk From raghavendra.gv.vanam at gmail.com Fri Mar 5 08:32:21 2010 From: raghavendra.gv.vanam at gmail.com (vanam) Date: Fri, 5 Mar 2010 05:32:21 -0800 (PST) Subject: process mp3 file References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> Message-ID: On Mar 3, 3:43?pm, asit wrote: > > Define "processing". > > getting the title, song name, etc of the file and updating in a > database Other possibility can be passing out the extension of the file and directory where the files are present, using os.walk we can extract the file name by filtering the .mp3 extension. From duncan.booth at invalid.invalid Fri Mar 5 08:38:51 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2010 13:38:51 GMT Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: Jean-Michel Pichavant wrote: > You've already been given good advices. > Unlike some of those, I don't think using regexp an issue in any way. > Yes they are not readable, for sure, I 100% agree to that statement, but > you can make them readable very easily. > > # not readable > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > > > # readable > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # match > '192.168.200.1 (foo123)' > > I gladly understand ppl that are not willing to use regexp (or as last > resort), but for a perl guy, that should not be an issue. The problem with your comment is that just by existing it means people will be misled into thinking the regex is being used to match strings like '192.168.200.1 (foo123)' when in fact the OP is expecting to match strings like '192.168.200.1 foo123' i.e. you may mislead some people into thinking the parentheses are part of what is being matched when they're actually grouping within the regex. Another problem with either regular expression line is that it makes it less easy to see that it doesn't do what the OP wanted. /etc/hosts contains lines with an IP address followed by multiple hostnames. It may also contain comments either as complete lines or at the end of lines. The code given will miss hostnames after the first and will include hostnames in commented out lines. -- Duncan Booth http://kupuguy.blogspot.com From mehgcap at gmail.com Fri Mar 5 08:41:37 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 5 Mar 2010 08:41:37 -0500 Subject: python on a thumb drive? Message-ID: Hello all, My name is Alex. I am pretty new to Python, but I really like it. I am trying to put my python and pythonw executables on my thumb drive, along with packages, using Moveable Python, but I cannot figure out how to run scripts using it. I would rather use a shell than the script runner gui since it does not seem to work. Any suggestions? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From jeanmichel at sequans.com Fri Mar 5 09:28:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 15:28:49 +0100 Subject: Evaluate my first python script, please In-Reply-To: References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <4B911521.20302@sequans.com> Duncan Booth wrote: > Jean-Michel Pichavant wrote: > > >> You've already been given good advices. >> Unlike some of those, I don't think using regexp an issue in any way. >> Yes they are not readable, for sure, I 100% agree to that statement, but >> you can make them readable very easily. >> >> # not readable >> match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) >> >> >> # readable >> match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # match >> '192.168.200.1 (foo123)' >> >> I gladly understand ppl that are not willing to use regexp (or as last >> resort), but for a perl guy, that should not be an issue. >> > > The problem with your comment is that just by existing it means people will > be misled into thinking the regex is being used to match strings like > '192.168.200.1 (foo123)' > when in fact the OP is expecting to match strings like > '192.168.200.1 foo123' > > i.e. you may mislead some people into thinking the parentheses are part of > what is being matched when they're actually grouping within the regex. > > Another problem with either regular expression line is that it makes it > less easy to see that it doesn't do what the OP wanted. /etc/hosts contains > lines with an IP address followed by multiple hostnames. It may also > contain comments either as complete lines or at the end of lines. The code > given will miss hostnames after the first and will include hostnames in > commented out lines. > > And tell me how not using regexp will ensure the /etc/hosts processing is correct ? The non regexp solutions provided in this thread did not handled what you rightfully pointed out about host list and commented lines. And FYI, the OP pattern does match '192.168.200.1 (foo123)' ... Ok that's totally unfair :D You're right I made a mistake. Still the comment is absolutely required (provided it's correct). JM From jpiitula at ling.helsinki.fi Fri Mar 5 09:43:47 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 05 Mar 2010 16:43:47 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml References: Message-ID: Stefan Behnel writes: > Jussi Piitulainen, 04.03.2010 22:40: > > Stefan Behnel writes: > >> Jussi Piitulainen, 04.03.2010 11:46: > >>> I am observing weird semi-erratic behaviour that involves Python 3 > >>> and lxml, is extremely sensitive to changes in the input data, and > >>> only occurs when I name a partial result. I would like some help > >>> with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml > >>> version?) > >> > >> Here's how to find the version: > >> > >> http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do > > > > Ok, thank you. Here's the results: > > > > >>> print(et.LXML_VERSION, et.LIBXML_VERSION, > > ... et.LIBXML_COMPILED_VERSION, et.LIBXSLT_VERSION, > > ... et.LIBXSLT_COMPILED_VERSION) > > (2, 2, 4, 0) (2, 6, 26) (2, 6, 26) (1, 1, 17) (1, 1, 17) > > I can't reproduce this with the latest lxml trunk (and Py3.2 trunk) > and libxml2 2.7.6, even after running your test script for quite a > while. I'd try to upgrade the libxml2 version. Thank you much. I suppose that is good news. It's a big server with many users - I will ask the administrators to consider an upgrade when I get around to it. Turns out that lxml documentation warns not to use libxml2 version 2.6.27 if I want to use xpath, and that is just a bit newer than we have. On that cue, I seem to have found a workaround: I replaced the xpath expression with findall(titlef) where titlef = ( '//{http://www.openarchives.org/OAI/2.0/}record' '//{http://purl.org/dc/elements/1.1}title' ) In the previously broken naming() function I now have: result = etree.parse(BytesIO(body)) n = len(result.findall(titlef)) And in the previously working nesting() function: n = len(etree.parse(BytesIO(body)).findall(titlef)) With these changes, the test script gives consistently the result that I expect, and the more complicated real test script where I first met the problem also appears to work without a hitch. So, this works. The other, broken behaviour is totally scary, though. From duncan.booth at invalid.invalid Fri Mar 5 10:00:07 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2010 15:00:07 GMT Subject: Evaluate my first python script, please References: Message-ID: Jean-Michel Pichavant wrote: > And tell me how not using regexp will ensure the /etc/hosts processing > is correct ? The non regexp solutions provided in this thread did not > handled what you rightfully pointed out about host list and commented > lines. It won't make is automatically correct, but I'd guess that written without being so dependent on regexes might have made someone point out those deficiencies sooner. The point being that casual readers of the code won't take the time to decode the regex, they'll glance over it and assume it does something or other sensible. If I was writing that code, I'd read each line, strip off comments and leading whitespace (so you can use re.match instead of re.search), split on whitespace and take all but the first field. I might check that the field I'm ignoring it something like a numeric ip address, but if I did want to do then I'd include range checking for valid octets so still no regex. The whole of that I'd wrap in a generator so what you get back is a sequence of host names. However that's just me. I'm not averse to regular expressions, I've written some real mammoths from time to time, but I do avoid them when there are simpler clearer alternatives. > And FYI, the OP pattern does match '192.168.200.1 (foo123)' > ... > Ok that's totally unfair :D You're right I made a mistake. Still the > comment is absolutely required (provided it's correct). > Yes, the comment would have been good had it been correct. I'd also go for a named group as that provides additional context within the regex. Also if there are several similar regular expressions in the code, or if they get too complex I'd build them up in parts. e.g. OCTET = r'(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])' ADDRESS = (OCTET + r'\.') * 3 + OCTET HOSTNAME = r'[-a-zA-Z0-9]+(?:\.[-a-zA-Z0-9]+)*' # could use \S+ but my Linux manual says # alphanumeric, dash and dots only ... and so on ... which provides another way of documenting the intentions of the regex. BTW, I'm not advocating that here, the above patterns would be overkill, but in more complex situations thats what I'd do. -- Duncan Booth http://kupuguy.blogspot.com From jjposner at optimum.net Fri Mar 5 10:10:51 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Mar 2010 10:10:51 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b90f5eb$0$9148$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> Message-ID: <4b911ee0$0$4988$607ed4bc@cv.net> On 3/5/2010 7:15 AM, Bruno Desthuilliers wrote: > John Posner a ?crit : >> On 3/3/2010 6:56 PM, John Posner wrote: >>> >>> ... I was thinking >>> today about "doing a Bruno", and producing similar pieces on: >>> >>> * properties created with the @property decorator >>> >>> * the descriptor protocol >>> >>> I'll try to produce something over the next couple of days. >>> >> >> Starting to think about a writeup on Python properties, I've >> discovered that the official Glossary [1] lacks an entry for >> "property" -- it's missing in both Py2 and Py3! >> >> Here's a somewhat long-winded definition -- comments, please: >> >> --------------------------------------------- >> An attribute, *a*, of an object, *obj*, is said to be implemented as a >> property if the standard ways of accessing the attribute: >> >> * evaluation: print obj.a >> * assignment: obj.a = 42 >> * deletion: del obj.a >> >> ... cause methods of a user-defined *property object* to be invoked. > > Hmmm... a couple remarks: > > 1/ "property" is actually the name of a Python builtin type. It's also > pretty much used in general OO litterature for what we name > "attributes". So I think it would be better to avoid confusion between > "property" as the builtin type, "property" as synonym for attribute, and > "property" as the more specific concept of "computed attribute" - which > is what you're describing here. > > As far as I'm concerned, I prefer to stick to "computed attribute" for > the generic case, and only use "property" when the computed attribute is > actually implemented using the builtin property type. Yes, I had already decided that the first sentence of the glossary definition needs to be, "A property is a computed attribute". > > 2/ depending on how the computed attribute is implemented, the > computation needs not happen on ALL get/set/del access - you can have > non-binding descriptors (that is, not implementing __set__). Yes, but IMHO that information belongs in the full writeup, not in the glossary definition. I've added the phrase "some or all" in the glossary definition (see below). > Also, the "standard" access also include getattr(), setattr() and > delattr() (might be worth a note). > >> The attribute > > /attribute/user-defined object/ here ? > >> is created as a class attribute, not an instance attribute. Example: >> >> class Widget: >> # create "color" as class attribute, not within __init__() >> color = <> >> >> def __init__(self, ...): >> # do not define "self.color" instance attribute > > Yes you can, and it's even actually pretty common: Of course -- and I realize that I was introducing confusion, rather than enlightenment, with my example. I think the point is too subtle for a (necessarily short) glossary definition, so I'm removing the example from the definition. > > # example.py > from somewhere import RGBColor > > class Foo(object): > def _get_color(self): > return str(self._color) > def _set_color(self, val): > self._color = RGBColor.from_string(val) > color = property(fget=_get_color, fset=_set_color) > > def __init__(self, colorvalue): > self.color = colorvalue [OFF-TOPIC] Wow, Thunderbird 3.0.2 nuked the indentation in the code above. :-( > > >> The property object can be created with the built-in function property(), > > It's actually a type, not a function. Ah, yes. Thanks. > >> which in some cases can be coded as a decorator: @property. The >> property object can also be an instance of a class that implements the >> descriptor protocol. > > The "property object" IS an instance of a class that implements the > descriptor protocol. The property type is just a "generic" descriptor: > > # naive (and incomplete) python implementation of the property type > > class property(object): > def __init__(self, fget, fset=None, fdel=None) > self._fget = fget > self._fset = fset > self._fdel = fdel > > def __get__(self, instance, cls): > if instance is None: > return self > return self._fget(instance) > > def __set__(self, instance, value): > if not self._fset: > raise AttributeError("can't set attribute") > self._fset(instance, value) > > def __del__(self): > if not self._fdel: > raise AttributeError("can't delete attribute") > self._fdel(instance) Good stuff for the full writeup on properties. > As far as I'm concerned, I'd "plan" such a paper as: > > """ > What's a property ? It's a computed attribute implemented using the > builtin "property" type. > > Ok, so far it doesn't help much. So > 1/ what's a computed attribute, and > 2/ what is the property type ? > > 1/ your above explanation about what's a computed attribute in general, > then a brief explanation of how computed attributes are implemented in > python -> IOW, the descriptor protocol > > 2/ my above snippet !-) I agree. I'm not sure whether the "brief explanation of how computed attributes are implemented in Python" belongs in the *properties* writeup or the *descriptors* writeup. (I think they should be separate, to avoid making readers brains explode.) I'll make the (initial) call when/if I get that far! > > """ > > I think the way you started explaining computed attributes wrt/ > attribute access could be a pretty good way to explain the descriptor > protocol, since the mapping from get/set/del access to __get__, __set__, > and __del__ magic methods is then pretty obvious. > > But YMMV of course, so by all mean feel free to discard all or parts of > the above remarks !-) > > HTH Here's my leaner, meaner glossary definition of *property*: ------------------- A property is a computed attribute: an attribute, a, of an object, obj, is said to be implemented as a property if some or all of the standard ways of accessing the attribute: * evaluation: result = obj.a * assignment: obj.a = 42 * deletion: del obj.a ... cause methods of another user-defined object to be invoked. This other object can be an instance of the built-in type *property*, or as an instance of a class that implements the descriptor protocol. ------------------- Many thanks, Bruno -- again! -John From J.Fine at open.ac.uk Fri Mar 5 10:19:45 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Fri, 05 Mar 2010 15:19:45 +0000 Subject: WANTED: A good name for the pair (args, kwargs) In-Reply-To: References: Message-ID: Jonathan Fine wrote: > Hi > > We can call a function fn using > val = fn(*args, **kwargs) > > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > Here's my use case: > def doit(fn , wibble, expect): > args, kwargs = wibble > actual = fn(*args, **kwargs) > if actual != expect: > # Something has gone wrong. > pass > > This is part of a test runner. > > For now I'll use argpair, but if anyone has a better idea, I'll use it. Thank you, Tim, Paul, Steve and Aahz for your suggestions. I'm now preferring: def test_apply(object, argv, valv): args, kwargs = argv expect, exceptions = valv # Inside try: except: actual = object(*args, **kwargs) # Check against expect, exceptions. best regards Jonathan From pemerson at gmail.com Fri Mar 5 10:53:06 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 07:53:06 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Thanks for your response, further questions inline. On Mar 4, 11:07?am, Tim Wintle wrote: > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > I am looking for advice along the lines of "an easier way to do this" > > or "a more python way" (I'm sure that's asking for trouble!) or > > "people commonly do this instead" or "here's a slick trick" or "oh, > > interesting, here's my version to do the same thing". > > (1) I would wrap it all in a function > > def main(): > ? ? # your code here > > if __name__ == "__main__": > ? ? main() Is this purely aesthetic reasons, or will I appreciate this when I write my own modules, or something else? > > (2) PEP8 (python style guidelines) suggests one import per line > > (3) I'd use four spaces as tab width > > (4) > I'd change this: > > > ? ? for arg in sys.argv[1:]: > > ? ? ? ? for section in hostname.split('.'): > > ? ? ? ? ? ? if section == arg: > > ? ? ? ? ? ? ? ? count = count + 1 > > ? ? ? ? ? ? ? ? break > > to something more like: > > ? ? for section in hostname.split("."): > ? ? ? ? if section in sys.argv[1:]: > ? ? ? ? ? ? count += 1 Ah, yes, I like that. It moves towards the set notation I've wound up with. Definitely more readable to me. > > (although as you suggested I'd only calculate sys.argv[1:] once) > > ... or you could replace whole section between the for loop and > hosts.append with: > > ? ? if sorted(hostname.split(".")) == sorted(sys.argv[1:]): > ? ? ? ? host.append(hostname) This doesn't actually work, because I'm not looking for a one to one mapping of args to sections of hostname, but rather a subset. So passing in 'prod sfo' would register a match for '001.webapp.prod.sfo'. From pemerson at gmail.com Fri Mar 5 10:55:00 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 07:55:00 -0800 (PST) Subject: Evaluate my first python script, please References: Message-ID: <6c76b898-9137-49d7-94a0-efd63fc82aed@c37g2000prb.googlegroups.com> On Mar 5, 7:00?am, Duncan Booth wrote: > Jean-Michel Pichavant wrote: > > And tell me how not using regexp will ensure the /etc/hosts processing > > is correct ? The non regexp solutions provided in this thread did not > > handled what you rightfully pointed out about host list and commented > > lines. > > It won't make is automatically correct, but I'd guess that written without > being so dependent on regexes might have made someone point out those > deficiencies sooner. The point being that casual readers of the code won't > take the time to decode the regex, they'll glance over it and assume it > does something or other sensible. > > If I was writing that code, I'd read each line, strip off comments and > leading whitespace (so you can use re.match instead of re.search), split on > whitespace and take all but the first field. I might check that the field > I'm ignoring it something like a numeric ip address, but if I did want to > do then I'd include range checking for valid octets so still no regex. > > The whole of that I'd wrap in a generator so what you get back is a > sequence of host names. > > However that's just me. I'm not averse to regular expressions, I've written > some real mammoths from time to time, but I do avoid them when there are > simpler clearer alternatives. > > > And FYI, the OP pattern does match '192.168.200.1 (foo123)' > > ... > > Ok that's totally unfair :D You're right I made a mistake. ?Still the > > comment is absolutely required (provided it's correct). > > Yes, the comment would have been good had it been correct. I'd also go for > a named group as that provides additional context within the regex. > > Also if there are several similar regular expressions in the code, or if > they get too complex I'd build them up in parts. e.g. > > OCTET = r'(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])' > ADDRESS = (OCTET + r'\.') * 3 + OCTET > HOSTNAME = r'[-a-zA-Z0-9]+(?:\.[-a-zA-Z0-9]+)*' > ? # could use \S+ but my Linux manual says > ? # alphanumeric, dash and dots only > ... and so on ... > > which provides another way of documenting the intentions of the regex. > > BTW, I'm not advocating that here, the above patterns would be overkill, > but in more complex situations thats what I'd do. > > -- > Duncan Boothhttp://kupuguy.blogspot.com All good comments here. The takeaway for my lazy style of regexes (which makes it harder for non-regex fiends to read, regardless of the language) is that there are ways to make regexes much more readable to the untrained eye. Duncan, I like your method of defining sections of the regex outside the regex itself, even if it's a one time use. From john at castleamber.com Fri Mar 5 10:55:11 2010 From: john at castleamber.com (John Bokma) Date: Fri, 05 Mar 2010 09:55:11 -0600 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> Message-ID: <87sk8ercf4.fsf@castleamber.com> Steven D'Aprano writes: > On Fri, 05 Mar 2010 18:36:06 +1300, Gregory Ewing wrote: > >> Paul Rubin wrote: >>> ReST was another solution in search of a problem. >> >> I think the basic idea behind ReST is quite good, i.e. understanding as >> markup various typographical conventions that make sense in plain text, >> such as underlined headings, bullets, numbered paragraphs. >> >> Unfortunately it went overboard with a slew of cryptic codes for >> footnotes, hyperlinks, etc. that nobody would naturally think to use in >> a plain text document. > > I use footnotes all the time[1] in plain text documents and emails. I > don't think there's anything bizarre about it at all. http://docutils.sourceforge.net/docs/user/rst/quickref.html#footnotes [#]_. .. [#] the keyword is ReST. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From showell30 at yahoo.com Fri Mar 5 11:01:12 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 5 Mar 2010 08:01:12 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7xvddbqkgp.fsf@ruckus.brouhaha.com> Message-ID: On Mar 4, 11:46?pm, Paul Rubin wrote: > > Ehh, either the JSON standardizers care about this issue or else they > don't. ?JSON (as currently defined) is a machine-to-machine > serialization format and just isn't that good a choice for handwritten > files. ?Adding a comment specification is a small perturbation that > might be accepted into the standard, but a big departure like RSON is a > whole nother creature. > > > How many hundreds of thousands of people have had to deal with XML > > without receiving its benefits? ?Do well-established standards get an > > exemption from the rule that software is not allowed to annoy non- > > willing users of it? > > We already have to deal with XML. ?So using XML for config files doesn't > require anyone to deal with any lousy formats that they didn't have to > deal with before. ?So the basic answer to your question about > well-established standards is yes: one annoying but standardized format > is better than multiple annoying unstandardized ones. Does this mean we should stick with XML until the end of time? From tim.wintle at teamrubber.com Fri Mar 5 11:07:22 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 05 Mar 2010 16:07:22 +0000 Subject: Evaluate my first python script, please In-Reply-To: <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Message-ID: <1267805242.29768.7.camel@localhost> On Fri, 2010-03-05 at 07:53 -0800, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07 am, Tim Wintle wrote: > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a more python way" (I'm sure that's asking for trouble!) or > > > "people commonly do this instead" or "here's a slick trick" or "oh, > > > interesting, here's my version to do the same thing". > > > > (1) I would wrap it all in a function > > > > def main(): > > # your code here > > > > if __name__ == "__main__": > > main() > > Is this purely aesthetic reasons, or will I appreciate this when I > write my own modules, or something else? It's for when you reuse this code. Consider it's in "mymodule.py" (so run with ./mymodule.py) - if you then make a "tests.py" (for example) you can "import mymodule" without it automatically running your code. re-writing it def main(args): #your code if __name__ == "__main__": main(sys.argv[1:]) would obviously be more sensible for actually writing tests. > > ... or you could replace whole section between the for loop and > > hosts.append with: > > > > if sorted(hostname.split(".")) == sorted(sys.argv[1:]): > > host.append(hostname) > > This doesn't actually work, because I'm not looking for a one to one > mapping of args to sections of hostname, but rather a subset. So > passing in 'prod sfo' would register a match for '001.webapp.prod.sfo'. Ah - good point - I guess the the set intersection technique someone else mentioned is best in that case. Tim From chris.lieb at gmail.com Fri Mar 5 11:08:56 2010 From: chris.lieb at gmail.com (Chris Lieb) Date: Fri, 5 Mar 2010 08:08:56 -0800 (PST) Subject: Failure in test_hashlib.py and test_hmac.py References: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> <7xr5nzqkaw.fsf@ruckus.brouhaha.com> Message-ID: On Mar 5, 2:50?am, Paul Rubin wrote: > Chris Lieb writes: > > I am building Python 2.6.4 on a shared server and am encountering test > > failures in test_hashlib.py and test_hmac.py, > > You should certainly file a bug report (bugs.python.org). ?If you want > to debug it yourself and include a patch, that's great. ?Otherwise, just > file the report. > > ? ? In the case of test_hashlib.py, it segfaulted on the first sha512 test > ? ? when I didn't have the debugging options enabled. ?Only after enabling > ? ? debugging did I get FAIL's for the sha512 tests. > > ? ? Does anyone know what is causing these failures? > > Please be precise about the hw and compiler versions. I have created this as bug 8073 [http://bugs.python.org/issue8073] From python.list at tim.thechases.com Fri Mar 5 11:28:41 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Mar 2010 10:28:41 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7xvddbqkgp.fsf@ruckus.brouhaha.com> Message-ID: <4B913139.7000704@tim.thechases.com> Steve Howell wrote: > On Mar 4, 11:46 pm, Paul Rubin wrote: >> We already have to deal with XML. So using XML for config files doesn't >> require anyone to deal with any lousy formats that they didn't have to >> deal with before. So the basic answer to your question about >> well-established standards is yes: one annoying but standardized format >> is better than multiple annoying unstandardized ones. > > > Does this mean we should stick with XML until the end of time? > One word: COBOL :-) -tkc From mrmakent at gmail.com Fri Mar 5 11:29:59 2010 From: mrmakent at gmail.com (Mike Kent) Date: Fri, 5 Mar 2010 08:29:59 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On Mar 4, 8:04?pm, Robert Kern wrote: > No, the try: finally: is not implicit. See the source for > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > with: block, it will push it into the generator using its .throw() method. This > raises the exception inside the generator at the yield statement. Wow, I just learned something new. My understanding of context managers was that the __exit__ method was guaranteed to be executed regardless of how the context was left. I have often written my own context manager classes, giving them the __enter__ and __exit__ methods. I had mistakenly assumed that the @contextmanager decorator turned a generator function into a context manager with the same behavior as the equivalent context manager class. Now I learn that, no, in order to have the 'undo' code executed in the presence of an exception, you must write your own try/finally block in the generator function. This raises the question in my mind: What's the use case for using @contextmanager rather than wrapping your code in a context manager class that defines __enter__ and __exit__, if you still have to manager your own try/finally block? From showell30 at yahoo.com Fri Mar 5 11:38:27 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 5 Mar 2010 08:38:27 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <38c910f9-0ab5-44cf-8cdc-128d5720324c@f17g2000prh.googlegroups.com> On Mar 5, 8:29?am, Mike Kent wrote: > On Mar 4, 8:04?pm, Robert Kern wrote: > > > No, the try: finally: is not implicit. See the source for > > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > > with: block, it will push it into the generator using its .throw() method. This > > raises the exception inside the generator at the yield statement. > > Wow, I just learned something new. ?My understanding of context > managers was that the __exit__ method was guaranteed to be executed > regardless of how the context was left. ?I have often written my own > context manager classes, giving them the __enter__ and __exit__ > methods. ?I had mistakenly assumed that the @contextmanager decorator > turned a generator function into a context manager with the same > behavior as the equivalent context manager class. ?Now I learn that, > no, in order to have the 'undo' code executed in the presence of an > exception, you must write your own try/finally block in the generator > function. > > This raises the question in my mind: What's the use case for using > @contextmanager rather than wrapping your code in a context manager > class that defines __enter__ and __exit__, if you still have to > manager your own try/finally block? Unless I am misunderstanding the question, the use case is that you still only have to write the context manager once, and you might get multiple uses out of it where the with-enclosed code blocks work at a higher level of abstraction. I actually don't use @contextmanager yet, mainly because I did not know it existed until recently, but also because I find the __enter__/ __exit__ paradigm straightforward enough to just hand code them that way. From pruebauno at latinmail.com Fri Mar 5 11:41:24 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 5 Mar 2010 08:41:24 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <7a1d6fe9-d2c8-4c7e-8173-1e6b4d010f6a@g26g2000yqn.googlegroups.com> mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > 'Interface', > > 'Gi9/6', > > 'Po2', > > 'Po3', > > 'Po306', > > 'VLAN4068', > > 'Interface', > > 'Gi9/6', > > 'VLAN4069', > > 'Interface', > > 'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > > # alist = list above > > tmp, dk = [], {} > [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or > (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) for x in alist > if x != 'Interface'] > > No need to use a nuke like itertools to kill a fly. ;-) > > Regards, > mk Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) [(dk.setdefault(x,[]) or tmp.append(x)) if x.startswith('VLAN') else dk[tmp[-1]].append(x) for x in alist if x != 'Interface'] From showell30 at yahoo.com Fri Mar 5 11:49:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 5 Mar 2010 08:49:41 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On Mar 4, 5:04?pm, Robert Kern wrote: > On 2010-03-04 15:19 PM, Mike Kent wrote: > > > > > On Mar 3, 12:00 pm, Robert Kern ?wrote: > >> On 2010-03-03 09:39 AM, Mike Kent wrote: > > >>> What's the compelling use case for this vs. a simple try/finally? > > >>> ? ? ?original_dir = os.getcwd() > >>> ? ? ?try: > >>> ? ? ? ? ?os.chdir(somewhere) > >>> ? ? ? ? ?# Do other stuff > >>> ? ? ?finally: > >>> ? ? ? ? ?os.chdir(original_dir) > >>> ? ? ? ? ?# Do other cleanup > > >> A custom-written context manager looks nicer and can be more readable. > > >> from contextlib import contextmanager > >> import os > > >> @contextmanager > >> def pushd(path): > >> ? ? ? original_dir = os.getcwd() > >> ? ? ? os.chdir(path) > >> ? ? ? try: > >> ? ? ? ? ? yield > >> ? ? ? finally: > >> ? ? ? ? ? os.chdir(original_dir) > > >> with pushd(somewhere): > >> ? ? ? ... > > > Robert, I like the way you think. ?That's a perfect name for that > > context manager! ?However, you can clear one thing up for me... isn't > > the inner try/finally superfluous? ?My understanding was that there > > was an implicit try/finally already done which will insure that > > everything after the yield statement was always executed. > > No, the try: finally: is not implicit. See the source for > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > with: block, it will push it into the generator using its .throw() method. This > raises the exception inside the generator at the yield statement. > See also: http://docs.python.org/library/contextlib.html The closing() helper can be used to automatically call thing.close() even after an exception. If you do not use the closing() helper and take on the responsibility yourself of doing try/finally within your generator, I think you still gain some overall simplicity: 1) You don't need to do try/finally in your with blocks, of course. 2) The generator itself probably reads more straightforwardly then a hand-coded class with __enter__ and __exit__. For point #2, I think there are probably different aesthetics. Generators are more concise, but they are also a bit mind-bending. From tjreedy at udel.edu Fri Mar 5 11:57:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 11:57:13 -0500 Subject: Generic singleton In-Reply-To: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 3/4/2010 10:32 PM, Steven D'Aprano wrote: > Python does have it's own singletons, like None, True and False. True and False are not singletons. > For some reason, they behave quite differently: Because they are quite different. > NoneType fails if you try to instantiate it again, Because trying 'type(None)()' was probably judged to be more likely to be a bug than something useful. > while bool returns the appropriate existing singleton: [sic] Branching on boolean values (which are no more singletons than 0, 1, ...) is basic to computing. > I wonder why NoneType doesn't just return None? What would you have NoneType(x) do? Or the special case NoneType(None)? The issue has come up as to whether object(x) should ignore or raise. In 3.x, it raises. TypeError: object.__new__() takes no parameters but I believe this is changed from at least some 2.x versions that ignored (apparently by 'accident'). Terry Jan Reedy From robert.kern at gmail.com Fri Mar 5 12:00:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 11:00:22 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-05 10:29 AM, Mike Kent wrote: > On Mar 4, 8:04 pm, Robert Kern wrote: > >> No, the try: finally: is not implicit. See the source for >> contextlib.GeneratorContextManager. When __exit__() gets an exception from the >> with: block, it will push it into the generator using its .throw() method. This >> raises the exception inside the generator at the yield statement. > > Wow, I just learned something new. My understanding of context > managers was that the __exit__ method was guaranteed to be executed > regardless of how the context was left. It is. @contextmanager turns a specially-written generator into a context manager with an __exit__ that does different things depending on whether or not and exception was raised. By pushing the exception into the generator, it lets the author decide what to do. It may catch a subset of exceptions, or no exceptions, or use a finally:. They all have use cases although finally: is the usual one. > I have often written my own > context manager classes, giving them the __enter__ and __exit__ > methods. I had mistakenly assumed that the @contextmanager decorator > turned a generator function into a context manager with the same > behavior as the equivalent context manager class. Basically, it does. __exit__() is given the exception information. When you write such a class, you can decide what to do with the exception. You can silence it, immediately reraise it, conditionally reraise it, log it and then reraise it, etc. Pushing the exception into the generator keeps this flexibility and the equivalence. If it removed that choice, then it would not be equivalent. > Now I learn that, > no, in order to have the 'undo' code executed in the presence of an > exception, you must write your own try/finally block in the generator > function. > > This raises the question in my mind: What's the use case for using > @contextmanager rather than wrapping your code in a context manager > class that defines __enter__ and __exit__, if you still have to > manager your own try/finally block? The @contextmanager generator implementations are often shorter and easier to read, in my opinion, partly because they use the try: finally: syntax that most of us are very familiar with. I have to think less when I read it because it looks so similar to the equivalent code that you would normally write. The point of context managers isn't to remove the use of try: finally: entirely, but to implement it once so that it can be reused cleanly. You only have to write the one try: finally: in the generator and reuse it simply with the with: statement in many places. -- 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 From lbolla at gmail.com Fri Mar 5 12:09:08 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 5 Mar 2010 09:09:08 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <8de6ccfb-c096-4f16-ad99-1bce5dfb12d0@j27g2000yqn.googlegroups.com> On Mar 5, 1:26?pm, mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > ?'Interface', > > ?'Gi9/6', > > ?'Po2', > > ?'Po3', > > ?'Po306', > > ?'VLAN4068', > > ?'Interface', > > ?'Gi9/6', > > ?'VLAN4069', > > ?'Interface', > > ?'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > > # alist = list above > > tmp, dk = [], {} > [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or > (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) ? ?for x in alist > if x != 'Interface'] > > No need to use a nuke like itertools to kill a fly. ;-) > > Regards, > mk It looks like Perl ;-) From mrkafk at gmail.com Fri Mar 5 12:10:54 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 18:10:54 +0100 Subject: loop over list and process into groups In-Reply-To: <7a1d6fe9-d2c8-4c7e-8173-1e6b4d010f6a@g26g2000yqn.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <7a1d6fe9-d2c8-4c7e-8173-1e6b4d010f6a@g26g2000yqn.googlegroups.com> Message-ID: nn wrote: > Oh my! You could have at least used some "if else" to make it a little > bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk From mrkafk at gmail.com Fri Mar 5 12:14:16 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 18:14:16 +0100 Subject: isinstance(False, int) Message-ID: >>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Regards, mk From mrkafk at gmail.com Fri Mar 5 12:16:12 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 18:16:12 +0100 Subject: loop over list and process into groups In-Reply-To: <8de6ccfb-c096-4f16-ad99-1bce5dfb12d0@j27g2000yqn.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <8de6ccfb-c096-4f16-ad99-1bce5dfb12d0@j27g2000yqn.googlegroups.com> Message-ID: lbolla wrote: > It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regards, mk From tjreedy at udel.edu Fri Mar 5 12:17:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 12:17:43 -0500 Subject: comparing two lists In-Reply-To: References: Message-ID: On 3/5/2010 3:05 AM, jimgardener wrote: > hi > I have two lists of names.I need to find the difference between these > two lists.I tried to do it using sets.But I am wondering if there is a > better way to do it.Please tell me if there is a more elegant way. > thanks, > jim > > my code snippet follows.. > > oldlst=['jon','arya','ned','bran'] > newlst=['jaime','jon','cersei'] > > newlyadded=set(newlst)-set(oldlst) > removed=set(oldlst)-set(newlst) > unchanged=set(oldlst)& set(newlst) Except for the duplicate calls to set, this is fine. If order and duplication are irrelevant (and hashability is guaranteed), use sets to start with. > print '%d were newly added= %s'%(len(newlyadded),list(newlyadded)) > print '%d were removed=%s'%(len(removed),list(removed)) > print '%d were unchanged=%s'%(len(unchanged),list(unchanged)) > > this produces the output > -------------- > 2 were newly added= ['jaime', 'cersei'] > 3 were removed=['ned', 'arya', 'bran'] > 1 were unchanged=['jon'] From tjreedy at udel.edu Fri Mar 5 12:26:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 12:26:00 -0500 Subject: ImportError: No module named glib In-Reply-To: <7c857e8c1003050030x39b75c98veace4ef8eebe606a@mail.gmail.com> References: <7c857e8c1003050030x39b75c98veace4ef8eebe606a@mail.gmail.com> Message-ID: On 3/5/2010 3:30 AM, Michael Joachimiak wrote: > I am too new to python. > If anybody has an idea what to do please help. > when I use > > import glib > > in my code I get this: > >>>> import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib glib is not in Python's stdlib so it must be loaded somewhere the interpreter can find it. Do >>> import sys >>> sys.path and see if it is in any of the listed directories. Perhaps you need to import pyglib? Terry Jan Reedy > :~$ python -V > Python 2.6.4 > > /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version 2.18.0-0ubuntu2 > > :~$ pkg-config glib-2.0 --cflags --libs > -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 From kamil at lucem.pl Fri Mar 5 12:44:02 2010 From: kamil at lucem.pl (Kamil Wasilewski) Date: Fri, 5 Mar 2010 18:44:02 +0100 Subject: Escaping variable names Message-ID: <11910654174.20100305184402@lucem.pl> Hi, Ive got an issue where a variable name needs to have a minus sign (-) in it. #Python 2.6 from SOAPpy import WSDL wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl" server = WSDL.Proxy(wsdlFile) server.soapproxy.config.argsOrdering = {'doGetCountries': ['country-code', 'webapi-key'] } server.doGetCountries(country-code=COUNTRYID}, webapi-key=WEBAPIKEY) The above method allows me to specify the order and name of variables being sent, but i have a problem since the variables have a "-" sign in the middle, is there a way to escape it in the variable name or get around the problem? Thanks! From steve at holdenweb.com Fri Mar 5 13:00:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Mar 2010 13:00:09 -0500 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: mk wrote: >>>> isinstance(False, int) > True >>>> >>>> isinstance(True, int) > True > > Huh? > >>>> >>>> issubclass(bool, int) > True > > Huh?! > >>> 3+True 4 >>> 3+False 3 >>> Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it would be a good ideal for Booleans to be a subclass of integers. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:01:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:01:11 GMT Subject: Generic singleton References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4b9146e6$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: > On 3/4/2010 10:32 PM, Steven D'Aprano wrote: > >> Python does have it's own singletons, like None, True and False. > > True and False are not singletons. Duotons? Doubletons? >>> t1 = bool(1) >>> t2 = bool(1) >>> t1 is t2 True >>> t1 is t2 is bool("this is also true") is bool(['so', 'is', 'this']) True They're described as singletons in the PEP, so if you want to argue with Guido, go right ahead... *grin* http://www.python.org/dev/peps/pep-0285/ > > For some reason, they behave quite differently: > > Because they are quite different. Well, list("hello world") and list("goodbye now") are quite different too, but they behave very similarly. > > NoneType fails if you try to instantiate it again, > > Because trying 'type(None)()' was probably judged to be more likely to > be a bug than something useful. Obviously people are unlikely to write type(None)(), but they are likely to do something like: result = call_some_function(args) more_code_here() blah_blah_blah() new_obj = type(result)() do_something_with(new_obj) If result happens to end up being None, I'm not convinced that the caller would rather have an exception than get the obvious None. If result happened to be 0, wouldn't you rather get 0 than have it blow up? I don't see why None should be any different. > > while bool returns the appropriate existing singleton: [sic] > > Branching on boolean values (which are no more singletons than 0, 1, > ...) is basic to computing. What does that have to do with the price of fish? I didn't mention anything about branching on bools. Once a singleton class has been instantiated the first time, you have a choice if the user tries to instantiate it again. You can do what NoneType does, and raise an error. Or you can do what bool does, and return the existing instance. Obviously, the behaviour of bool is far more useful. So I wonder why NoneType doesn't do the same. >> I wonder why NoneType doesn't just return None? > > What would you have NoneType(x) do? The same thing any function of zero arguments does when it gets called with one argument. > Or the special case NoneType(None)? Why would that be a special case? If NoneType takes no arguments, and you supply an argument, then it is an error regardless of what that argument happens to be. -- Steven From peloko45 at gmail.com Fri Mar 5 13:01:40 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 5 Mar 2010 10:01:40 -0800 (PST) Subject: Slicing [N::-1] Message-ID: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> What does a slice as [N::-1] ? It looks that in the first it reverses the slice and then it shows only N items, right? Could you add an example to get the same result without use `::` to see it more clear? Thanks in advance From arnodel at googlemail.com Fri Mar 5 13:03:49 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Mar 2010 18:03:49 +0000 Subject: isinstance(False, int) References: Message-ID: mk writes: >>>> isinstance(False, int) > True >>>> >>>> isinstance(True, int) > True > > Huh? > >>>> >>>> issubclass(bool, int) > True > > Huh?! > > Regards, > mk Yes, and: >>> True + False 1 In fact: >>> 1 == True True >>> 0 == False True So what's your question? -- Arnaud From apt.shansen at gmail.com Fri Mar 5 13:06:15 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 5 Mar 2010 10:06:15 -0800 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <7a9c25c21003051006q571c5e45r49c47e82fe2a2f7f@mail.gmail.com> On Fri, Mar 5, 2010 at 9:14 AM, mk wrote: > >>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? > > >>> > >>> issubclass(bool, int) > True > > Huh?! > Huh, what? http://www.python.org/dev/peps/pep-0285/ --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:07:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:07:29 GMT Subject: isinstance(False, int) References: Message-ID: <4b914860$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: >>>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? Yes. Do you have an actual question? > >>> issubclass(bool, int) > True > > Huh?! Exactly. Bools are a late-comer to Python. For historical and implementation reasons, they are a subclass of int, because it was normal for people to use 0 and 1 as boolean flags, and so making False == 0 and True == 1 was the least likely to break code. E.g. back in the day, you would have something like: {2:None}.has_key(2) -> 1 So folks would do: print "The key is", ["missing", "present"][d.has_key(key)] Which still works even now that has_key returns True or False rather than 1 or 0. -- Steven From arnodel at googlemail.com Fri Mar 5 13:12:05 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Mar 2010 18:12:05 +0000 Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: Joan Miller writes: > What does a slice as [N::-1] ? > > It looks that in the first it reverses the slice and then it shows > only N items, right? > > Could you add an example to get the same result without use `::` to > see it more clear? > > Thanks in advance >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] >>> [l[i] for i in range(7, -1, -1)] [7, 6, 5, 4, 3, 2, 1, 0] -- Arnaud From jeanmichel at sequans.com Fri Mar 5 13:14:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 19:14:30 +0100 Subject: Escaping variable names In-Reply-To: <11910654174.20100305184402@lucem.pl> References: <11910654174.20100305184402@lucem.pl> Message-ID: <4B914A06.8010204@sequans.com> Kamil Wasilewski wrote: > Hi, > > Ive got an issue where a variable name needs to have a minus sign (-) in it. > > #Python 2.6 > from SOAPpy import WSDL > wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl" > server = WSDL.Proxy(wsdlFile) > server.soapproxy.config.argsOrdering = {'doGetCountries': ['country-code', 'webapi-key'] } > server.doGetCountries(country-code=COUNTRYID}, webapi-key=WEBAPIKEY) > > The above method allows me to specify the order and name of variables being sent, but i have a problem since the variables have a "-" sign in the middle, is there a way to escape it in the variable name or get around the problem? > > Thanks! > > def foo(*args, **kwargs): print kwargs['country-code'] params = {'country-code': 'hello word'} foo(**params) JM From sjdevnull at yahoo.com Fri Mar 5 13:19:37 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Fri, 5 Mar 2010 10:19:37 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Message-ID: On Mar 5, 10:53?am, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07?am, Tim Wintle wrote: > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a more python way" (I'm sure that's asking for trouble!) or > > > "people commonly do this instead" or "here's a slick trick" or "oh, > > > interesting, here's my version to do the same thing". > > > (1) I would wrap it all in a function > > > def main(): > > ? ? # your code here > > > if __name__ == "__main__": > > ? ? main() > > Is this purely aesthetic reasons, or will I appreciate this when I > write my own modules, or something else? Suppose the above code is in mymodule.py. By wrapping main() you can: 1. Have another module do: import mymodule ... (so some stuff, perhaps munge sys.argv) mymodule.main() 2. If mymodule has a small function in it, someone else can import it and call that function 3. You can run pylint, pychecker and other source-code checkers that need to be able to import your module to check it (I wouldn't be surprised if recent versions of one or the other of those don't require imports, and some checkers like pyflakes certainly don't). 4. You can easily have a unit tester call into the module etc. > > (2) PEP8 (python style guidelines) suggests one import per line > > > (3) I'd use four spaces as tab width +1 on both; it's good to get into the habit of writing standard- looking Python code. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:22:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:22:59 GMT Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: <4b914c02$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 10:01:40 -0800, Joan Miller wrote: > What does a slice as [N::-1] ? Why don't you try it? >>> s = "abcdefgh" >>> s[4::-1] 'edcba' The rules for extended slicing are not explained very well in the docs, and can be confusing. In my experience, apart from [::-1] it is best to always use a positive stride (the third number). -- Steven From darkrho at gmail.com Fri Mar 5 13:27:48 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 5 Mar 2010 14:27:48 -0400 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4eca3f41003051027nb22f3daxc418eeda3ad0a83b@mail.gmail.com> On Fri, Mar 5, 2010 at 2:00 PM, Steve Holden wrote: [...] > > Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it > would be a good ideal for Booleans to be a subclass of integers. > I would never figured out >>> bool.__bases__ (,) Doesn't have side effects not knowing that False/True are ints? Regards, Rolando From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:28:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:28:06 GMT Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: <4b914d35$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: >>>> l = range(10) >>>> l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>> l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] >>>> [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] Where does the first -1 come from? Slices are supposed to have default values of 0 and len(seq): >>> l[7::1] [7, 8, 9] >>> [l[i] for i in range(7, len(l), 1)] [7, 8, 9] >>> [l[i] for i in range(7, len(l), -1)] [] I don't believe the actual behaviour is documented anywhere. -- Steven From python at mrabarnett.plus.com Fri Mar 5 13:30:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Mar 2010 18:30:06 +0000 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4B914DAE.60209@mrabarnett.plus.com> mk wrote: > >>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? > > >>> > >>> issubclass(bool, int) > True > > Huh?! > Python didn't have Booleans originally, 0 and 1 were used instead. When bool was introduced it was made a subclass of int so that existing code wouldn't break. From mrkafk at gmail.com Fri Mar 5 13:32:32 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 19:32:32 +0100 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: >>>> 1 == True > True >>>> 0 == False > True > > So what's your question? Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, but not in Python.. Although I can understand the rationale after skimming PEP 285, I still don't like it very much. Regards, mk From anand.shashwat at gmail.com Fri Mar 5 13:33:21 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 6 Mar 2010 00:03:21 +0530 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: On Fri, Mar 5, 2010 at 11:42 PM, Arnaud Delobelle wrote: > Joan Miller writes: > > > What does a slice as [N::-1] ? > > > > It looks that in the first it reverses the slice and then it shows > > only N items, right? > > > > Could you add an example to get the same result without use `::` to > > see it more clear? > > > > Thanks in advance > > >>> l = range(10) > >>> l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] > >>> [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] > >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] >>> list(reversed(l))[-8:] [7, 6, 5, 4, 3, 2, 1, 0] ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Fri Mar 5 13:33:46 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 10:33:46 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: <464239a8-d78f-4d64-97ba-539f5c8cca26@g11g2000yqe.googlegroups.com> On Mar 5, 12:01?pm, Joan Miller wrote: > What does a slice as [N::-1] ? Starts at position N and returns all items to the start of the list in reverse order. > > It looks that in the first it reverses the slice and then it shows > only N items, right? Wrong. It shows N+1 items. Remember, counting starts from 0. > > Could you add an example to get the same result without use `::` to > see it more clear? for i in range(8,-1,-1):print(a[i],end=' ') although I doubt this is more clear. > > Thanks in advance From pemerson at gmail.com Fri Mar 5 13:50:31 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 10:50:31 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Message-ID: On Mar 5, 10:19?am, "sjdevn... at yahoo.com" wrote: > On Mar 5, 10:53?am, Pete Emerson wrote: > > > > > > > Thanks for your response, further questions inline. > > > On Mar 4, 11:07?am, Tim Wintle wrote: > > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > > I am looking for advice along the lines of "an easier way to do this" > > > > or "a more python way" (I'm sure that's asking for trouble!) or > > > > "people commonly do this instead" or "here's a slick trick" or "oh, > > > > interesting, here's my version to do the same thing". > > > > (1) I would wrap it all in a function > > > > def main(): > > > ? ? # your code here > > > > if __name__ == "__main__": > > > ? ? main() > > > Is this purely aesthetic reasons, or will I appreciate this when I > > write my own modules, or something else? > > Suppose the above code is in mymodule.py. ?By wrapping main() you can: > 1. Have another module do: > import mymodule > ... (so some stuff, perhaps munge sys.argv) > mymodule.main() > 2. If mymodule has a small function in it, someone else can import it > and call that function > 3. You can run pylint, pychecker and other source-code checkers that > need to be able to import your module to check it (I wouldn't be > surprised if recent versions of one or the other of those don't > require imports, and some checkers like pyflakes certainly don't). > 4. You can easily have a unit tester call into the module > > etc. > > > > (2) PEP8 (python style guidelines) suggests one import per line > > > > (3) I'd use four spaces as tab width > > +1 on both; it's good to get into the habit of writing standard- > looking Python code. Agreed, noted, and appreciated, with the caveat that using spaces instead of tabs might border on an emacs vs. vi flamewar in some circles. I personally will use spaces going forward. From mensanator at aol.com Fri Mar 5 13:52:28 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 10:52:28 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Mar 5, 12:28?pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: > >>>> l = range(10) > >>>> l > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>>> l[7::-1] > > [7, 6, 5, 4, 3, 2, 1, 0] > >>>> [l[i] for i in range(7, -1, -1)] > > [7, 6, 5, 4, 3, 2, 1, 0] > > Where does the first -1 come from? Slices are supposed to have default > values of 0 and len(seq): The only way to get a 0 from a reverse range() is to have a bound of -1. > > >>> l[7::1] > [7, 8, 9] > >>> [l[i] for i in range(7, len(l), 1)] > [7, 8, 9] > >>> [l[i] for i in range(7, len(l), -1)] > > [] > > I don't believe the actual behaviour is documented anywhere. Well, it's implied. If the stopping bound in a reverse range() is greater than the starting bound, you get an empty return. > > -- > Steven From jeanmichel at sequans.com Fri Mar 5 13:54:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 19:54:10 +0100 Subject: isinstance(False, int) In-Reply-To: <4b914860$0$27863$c3e8da3@news.astraweb.com> References: <4b914860$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4B915352.8010709@sequans.com> Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: > > >>>>> isinstance(False, int) >>>>> >> True >> >>> >> >>> isinstance(True, int) >> True >> >> Huh? >> > > Yes. Do you have an actual question? > > > >> >>> issubclass(bool, int) >> True >> >> Huh?! >> > > Exactly. > > Bools are a late-comer to Python. For historical and implementation > reasons, they are a subclass of int, because it was normal for people to > use 0 and 1 as boolean flags, and so making False == 0 and True == 1 was > the least likely to break code. > > E.g. back in the day, you would have something like: > > {2:None}.has_key(2) -> 1 > > So folks would do: > > print "The key is", ["missing", "present"][d.has_key(key)] > > Which still works even now that has_key returns True or False rather than > 1 or 0. > > > Despite there are good reasons for bool to be int, the newcomer 'wtf' reaction at first glance is legitimate. Starting python from scratch, booleans would have not been a subclass of int (just guessing though), 'cause it makes no sense from a design POV. Booleans are not ints, 0 does not *mean* False and veracity is not quantification. JM From darkrho at gmail.com Fri Mar 5 14:01:23 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 5 Mar 2010 15:01:23 -0400 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4eca3f41003051101q4d2c6debo1c2701d924769b31@mail.gmail.com> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: > Arnaud Delobelle wrote: > >>>>> 1 == True >> >> True >>>>> >>>>> 0 == False >> >> True >> >> So what's your question? > > Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, > but not in Python.. Although I can understand the rationale after skimming > PEP 285, I still don't like it very much. > So, the pythonic way to check for True/False should be: >>> 1 is True False >>> 0 is False False instead of ==, right? Regards, Rolando From robert.kern at gmail.com Fri Mar 5 14:10:18 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 13:10:18 -0600 Subject: Slicing [N::-1] In-Reply-To: <4b914d35$0$27863$c3e8da3@news.astraweb.com> References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 12:28 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: > >>>>> l = range(10) >>>>> l >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>>> l[7::-1] >> [7, 6, 5, 4, 3, 2, 1, 0] >>>>> [l[i] for i in range(7, -1, -1)] >> [7, 6, 5, 4, 3, 2, 1, 0] > > Where does the first -1 come from? Slices are supposed to have default > values of 0 and len(seq): Rather, they have 0 and len(seq), respectively, when the step is positive, and len(seq)-1 and -1 when the step is negative. >>>> l[7::1] > [7, 8, 9] >>>> [l[i] for i in range(7, len(l), 1)] > [7, 8, 9] >>>> [l[i] for i in range(7, len(l), -1)] > [] > > > I don't believe the actual behaviour is documented anywhere. True, I don't think it is. -- 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 From alfps at start.no Fri Mar 5 14:13:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 20:13:23 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Mike Kent: > On Mar 4, 8:04 pm, Robert Kern wrote: > >> No, the try: finally: is not implicit. See the source for >> contextlib.GeneratorContextManager. When __exit__() gets an exception from the >> with: block, it will push it into the generator using its .throw() method. This >> raises the exception inside the generator at the yield statement. > > Wow, I just learned something new. My understanding of context > managers was that the __exit__ method was guaranteed to be executed > regardless of how the context was left. I have often written my own > context manager classes, giving them the __enter__ and __exit__ > methods. I had mistakenly assumed that the @contextmanager decorator > turned a generator function into a context manager with the same > behavior as the equivalent context manager class. Now I learn that, > no, in order to have the 'undo' code executed in the presence of an > exception, you must write your own try/finally block in the generator > function. > > This raises the question in my mind: What's the use case for using > @contextmanager rather than wrapping your code in a context manager > class that defines __enter__ and __exit__, if you still have to > manager your own try/finally block? Robert Kern and Steve Howell have already given given good answers. As it happened this was news to me also, because I'm not that well-versed in Python and it seems contrary to the purpose of providing a simpler way to write a simple init-cleanup wrapper. But additionally, if you want that, then you can define it, e.g. # Py3 def simplecleanup( generator_func ): class SimpleCleanup: def __init__( self, *args, **kwargs ): self.generator = generator_func( *args, **kwargs ) def __enter__( self ): self.generator.send( None ) return self def __exit__( self, x_type, x_obj, x_traceback ): try: self.generator.send( x_obj ) # x_obj is None if no exception except StopIteration: pass # Expected return SimpleCleanup @simplecleanup def hello_goodbye( name ): print( "Hello, {}!".format( name ) ) yield print( "Goodbye {}!".format( name ) ) try: with hello_goodbye( "Mary" ): print( "Talk talk talk..." ) raise RuntimeError( "Offense" ) except: pass print() @simplecleanup def sensitive_hello_goodbye( name ): print( "Hello, {}!".format( name ) ) x = yield if x is not None: print( "Uh oh, {}!".format( x ) ) print( "Good day {}!".format( name ) ) else: print( "C u, {}!".format( name ) ) try: with sensitive_hello_goodbye( "Jane" ): print( "Talk talk talk..." ) raise RuntimeError( "Offense" ) except: pass Cheers, - Alf From wongjoekmeu at yahoo.com Fri Mar 5 14:21:32 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Fri, 5 Mar 2010 11:21:32 -0800 (PST) Subject: start function in new process Message-ID: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Hello all, I would like to run a python function completely in a new process. For example I have a parent process. That parent process needs to start a child process in which the function is called. After the child process is finished however I want that the child process should stop and then only the parent process remain. When I start the function I want to pass arguments also which include a function reference. I tried os.fork() as I need to write it in linux. However it seems like the child process remain alive. I discovered this when I loop through the function. I see that the child process continue with the loop and starts again a new grand child untill the loop is finished. See code snippet. f() is the function I want to run in a new process. It got as one of the input a refence to a function c(). Function g() I called in a loop for 3 times. Now it seems that when child process get started in the function g() it return to the loop and it calls g() itself and starts itself a nwe child process. I do not want thant. I want the child process to perform the function f() and just finished. Does anyone know how I can achieve this ? def c(): print "function c" def f(a,b, d): # function I want to run in a new child process print a, b d() def g(): pidID = os.fork() if pidID == 0: # child do something here f(2,3,c) else: # parent do something here print "Parent for i in range(3): g() From pemerson at gmail.com Fri Mar 5 14:24:44 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 11:24:44 -0800 (PST) Subject: Conditional based on whether or not a module is being used Message-ID: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? Suppose I have the following: import foo import foobar print foo() print foobar() ########### foo.py def foo: return 'foo' ########### foobar.py def foobar: if foo.has_been_loaded(): # This is not right! return foo() + 'bar' # This might need to be foo.foo() ? else: return 'bar' If someone is using foo module, I want to take advantage of its features and use it in foobar, otherwise, I want to do something else. In other words, I don't want to create a dependency of foobar on foo. My failed search for solving this makes me wonder if I'm approaching this all wrong. Thanks in advance, Pete From alfps at start.no Fri Mar 5 14:34:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 20:34:00 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: Message-ID: * Steve Howell: > On Mar 3, 7:10 am, "Alf P. Steinbach" wrote: >> For C++ Petru Marginean once invented the "scope guard" technique (elaborated on >> by Andrei Alexandrescu, they published an article about it in DDJ) where all you >> need to do to ensure some desired cleanup at the end of a scope, even when the >> scope is exited via an exception, is to declare a ScopeGuard w/desired action. >> >> The C++ ScopeGuard was/is for those situations where you don't have proper >> classes with automatic cleanup, which happily is seldom the case in good C++ >> code, but languages like Java and Python don't support automatic cleanup and so >> the use case for something like ScopeGuard is ever present. >> >> For use with a 'with' statement and possibly suitable 'lambda' arguments: >> >> >> class Cleanup: >> def __init__( self ): >> self._actions = [] >> >> def call( self, action ): >> assert( is_callable( action ) ) >> self._actions.append( action ) >> >> def __enter__( self ): >> return self >> >> def __exit__( self, x_type, x_value, x_traceback ): >> while( len( self._actions ) != 0 ): >> try: >> self._actions.pop()() >> except BaseException as x: >> raise AssertionError( "Cleanup: exception during cleanup" ) from >> >> >> I guess the typical usage would be what I used it for, a case where the cleanup >> action (namely, changing back to an original directory) apparently didn't fit >> the standard library's support for 'with', like >> >> with Cleanup as at_cleanup: >> # blah blah >> chdir( somewhere ) >> at_cleanup.call( lambda: chdir( original_dir ) ) >> # blah blah >> >> Another use case might be where one otherwise would get into very deep nesting >> of 'with' statements with every nested 'with' at the end, like a degenerate tree >> that for all purposes is a list. Then the above, or some variant, can help to >> /flatten/ the structure. To get rid of that silly & annoying nesting. :-) >> >> Cheers, >> >> - Alf (just sharing, it's not seriously tested code) > > Hi Alf, I think I understand the notion you're going after here. You > have multiple cleanup steps that you want to defer till the end, and > there is some possibility that things will go wrong along the way, but > you want to clean up as much as you can. And, of course, flatter is > better. > > Is this sort of what you are striving for? > > class Cleanup: > def __init__( self ): > self._actions = [] > > def call( self, action ): > self._actions.append( action ) > > def __enter__( self ): > return self > > def __exit__( self, x_type, x_value, x_traceback ): > while( len( self._actions ) != 0 ): > try: > self._actions.pop()() > except BaseException as x: > raise AssertionError( "Cleanup: exception during > cleanup" ) > > def clean_the_floor(): > print('clean the floor') > > def carouse(num_bottles, accident): > with Cleanup() as at_cleanup: > at_cleanup.call(clean_the_floor) > for i in range(num_bottles): > def take_down(i=i): > print('take one down', i) > at_cleanup.call(take_down) > if i == accident: > raise Exception('oops!') > print ('put bottle on wall', i) > > carouse(10, None) > carouse(5, 3) He he. I think you meant: > def carouse(num_bottles, accident): > with Cleanup() as at_cleanup: > at_cleanup.call(clean_the_floor) > for i in range(num_bottles): > def take_down(i=i): > print('take one down', i) > if i == accident: > raise Exception('oops!') > print ('put bottle on wall', i) > at_cleanup.call(take_down) I'm not sure. It's interesting & fun. But hey, it's Friday evening. Regarding the "clean the floor", Marginean's original ScopeGuard has a 'dismiss' method (great for e.g. implementing transactions). There's probably also much other such functionality that can be added. The original use case for Cleanup, I just posted this in case people could find it useful, was a harness for testing that C++ code /fails/ as it should, , where Cleanup is used at line 479. Some discussion of that in Usenet message and associated thread , "Unit testing of expected failures -- what do you use?" in [comp.lang.c++]. Another similar approach was discussed by Carlo Milanesi in , but he supplied this reference after I'd done the above. Mainly the difference is that he defines a custom mark-up language with corresponding source preprocessing, while I use the ordinary C++ preprocessor. There are advantages and disadvantages to both approaches. Cheers, - Alf From pemerson at gmail.com Fri Mar 5 14:39:41 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 11:39:41 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <63c618d8-3088-48fc-abbb-9eb06bb4eb54@f17g2000prh.googlegroups.com> On Mar 5, 11:24?am, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > ? ? return 'foo' > > ########### foobar.py > def foobar: > ? ? if foo.has_been_loaded(): # This is not right! > ? ? ? ? return foo() + 'bar' ? ? ?# This might need to be foo.foo() ? > ? ? else: > ? ? ? ? return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > > Thanks in advance, > Pete Aha, progress. Comments appreciated. Perhaps there's a different and more conventional way of doing it than this? def foobar(): import sys if 'foomodule' in sys.modules.keys(): import foomodule return foomodule.foo() + 'bar' else: return 'bar' From martin.hellwig at dcuktec.org Fri Mar 5 14:40:25 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 19:40:25 +0000 Subject: start function in new process In-Reply-To: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Message-ID: On 03/05/10 19:21, wongjoekmeu at yahoo.com wrote: Any specific reason why threading.Thread or multiprocessing is not suitable to solve your problem? -- mph From wongjoekmeu at yahoo.com Fri Mar 5 14:45:53 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Fri, 5 Mar 2010 11:45:53 -0800 (PST) Subject: start function in new process References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Message-ID: <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> On 5 mrt, 20:40, "Martin P. Hellwig" wrote: > On 03/05/10 19:21, wongjoek... at yahoo.com wrote: > > Any specific reason why threading.Thread or multiprocessing is not > suitable to solve your problem? > > -- > mph Because I got a memory leak in my function f(). It uses scipy, numpy, pylab, and I am not planning to solve the memory leak because its too complicated. So I thought of just calling the function then when it is finished the process is gone and all memory is released. With threading I don't think I would solve this problem. I am not sure though. From mrkafk at gmail.com Fri Mar 5 14:46:43 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 20:46:43 +0100 Subject: isinstance(False, int) In-Reply-To: <4eca3f41003051027nb22f3daxc418eeda3ad0a83b@mail.gmail.com> References: <4eca3f41003051027nb22f3daxc418eeda3ad0a83b@mail.gmail.com> Message-ID: Rolando Espinoza La Fuente wrote: > Doesn't have side effects not knowing that False/True are ints? It does, in fact I was wondering why my iterator didn't work until I figured issubclass(bool, int) is true. Regards, mk From steve at holdenweb.com Fri Mar 5 14:51:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Mar 2010 14:51:39 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > return 'foo' > > ########### foobar.py > def foobar: > if foo.has_been_loaded(): # This is not right! > return foo() + 'bar' # This might need to be foo.foo() ? > else: > return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > > Thanks in advance, > Pete One way would be if "foo" in sys.modules: # foo was imported However that won't get you all the way, since sys.modules["foo"] will be set even if the importing statement was from foo import this, that, the_other So you might want to add foo = sys.modules["foo"] inside the function. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Mar 5 14:52:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Mar 2010 14:52:46 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > By the way, the above statements are never going to work, because modules aren't callable. Maybe you want print foo.foo() print foobar.foobar() regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 14:53:43 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 19:53:43 GMT Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <4b916146$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 11:24:44 -0800, Pete Emerson wrote: > In a module, how do I create a conditional that will do something based > on whether or not another module has been loaded? try: import foo except ImportError: foo = None def function(): if foo: return foo.func() else: do_something_else() Or, alternatively: try: import foo except ImportError: import alternative_foo as foo # This better succeed! def function(): return foo.func() -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 14:54:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 19:54:22 GMT Subject: isinstance(False, int) References: Message-ID: <4b91616d$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >> Arnaud Delobelle wrote: >> >>>>>> 1 == True >>> >>> True >>>>>> >>>>>> 0 == False >>> >>> True >>> >>> So what's your question? >> >> Well nothing I'm just kind of bewildered: I'd expect smth like that in >> Perl, but not in Python.. Although I can understand the rationale after >> skimming PEP 285, I still don't like it very much. >> >> > So, the pythonic way to check for True/False should be: > >>>> 1 is True > False Why do you need to check for True/False? But if you need to, yes, that is one way. Another would be: isinstance(flag, bool) But generally, you can use any object as a flag without caring if it is actually True or False. -- Steven From mrkafk at gmail.com Fri Mar 5 14:55:14 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 20:55:14 +0100 Subject: imap vs map Message-ID: Hello everyone, I re-wrote more "slowly" an example at the end of http://wordaligned.org/articles/essential-python-reading-list This example finds anagrams in the text file. ==== from itertools import groupby, imap from operator import itemgetter from string import ascii_lowercase, ascii_uppercase, punctuation, maketrans, translate data = open(r"c:\temp\words.txt", "rt").read() trtable = maketrans(ascii_uppercase, ascii_lowercase) words = translate(data, trtable, deletions = punctuation) words = list(set(words.split())) sw = sorted(words, key=sorted) gb = groupby(sw, sorted) print map(list, imap(itemgetter(1), gb)) === words.txt: === Word Aligned three space sensitive programming Feed Logo tins Essential Python post Reading List stop course there times isnt capes === Now, when I execute above, it works: [['capes', 'space'], ['aligned'], ['reading'], ['essential'], ['programming'], ['course'], ['feed'], ['word'], ['there', 'three'], ['sensitive'], ['times'], ['logo'], ['python'], ['list'], ['isnt', 'tins'], ['stop', 'post']] However, when I change the last line to: print map(list, map(itemgetter(1), gb)) It stops working: [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ['post']] Why? I was under impression that the only difference between map and imap is that imap returns iterator allowing to produce a list, while map returns equivalent list? Regards, mk From python at mrabarnett.plus.com Fri Mar 5 14:57:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Mar 2010 19:57:34 +0000 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <4B91622E.5000208@mrabarnett.plus.com> Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > return 'foo' > > ########### foobar.py > def foobar: > if foo.has_been_loaded(): # This is not right! > return foo() + 'bar' # This might need to be foo.foo() ? > else: > return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > Look for its name in sys.modules, for example: 'foo' in sys.modules From martin.hellwig at dcuktec.org Fri Mar 5 15:02:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 20:02:34 +0000 Subject: start function in new process In-Reply-To: <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> Message-ID: On 03/05/10 19:45, wongjoekmeu at yahoo.com wrote: > On 5 mrt, 20:40, "Martin P. Hellwig" > wrote: >> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: >> >> Any specific reason why threading.Thread or multiprocessing is not >> suitable to solve your problem? >> >> -- >> mph > > Because I got a memory leak in my function f(). It uses scipy, numpy, > pylab, and I am not planning to solve the memory leak because its too > complicated. So I thought of just calling the function then when it is > finished the process is gone and all memory is released. With > threading I don't think I would solve this problem. I am not sure > though. I would be surprised if you can't do the same with subprocess/multiprocessing, since you seem to know how to identify the memory leak it shouldn't be a problem scripting out a test to see if it works this way. I would be interested though in your findings. -- mph From martin.hellwig at dcuktec.org Fri Mar 5 15:06:09 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 20:06:09 +0000 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: On 03/05/10 19:24, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > > Thanks in advance, > Pete Hmm how about the module is available, just not imported yet, I would assume that you still would like to use the module then. Perhaps playing around with the imp module might get you what you mean instead of what you say? -- mph From wongjoekmeu at yahoo.com Fri Mar 5 15:09:39 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Fri, 5 Mar 2010 12:09:39 -0800 (PST) Subject: start function in new process References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> Message-ID: <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> On 5 mrt, 21:02, "Martin P. Hellwig" wrote: > On 03/05/10 19:45, wongjoek... at yahoo.com wrote: > > > > > On 5 mrt, 20:40, "Martin P. Hellwig" > > wrote: > >> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: > >> > >> Any specific reason why threading.Thread or multiprocessing is not > >> suitable to solve your problem? > > >> -- > >> mph > > > Because I got a memory leak in my function f(). It uses scipy, numpy, > > pylab, and I am not planning to solve the memory leak because its too > > complicated. So I thought of just calling the function then when it is > > finished the process is gone and all memory is released. With > > threading I don't think I would solve this problem. I am not sure > > though. > > I would be surprised if you can't do the same with > subprocess/multiprocessing, since you seem to know how to identify the > memory leak it shouldn't be a problem scripting out a test to see if it > works this way. I would be interested though in your findings. > > -- > mph I can't use multiprocessing module since it comes only with python 2.6 and I am bound to python2.4. But subprocess does exist in python2.4, but the question now is, how do I achieve that ? Any example ? From clp2 at rebertia.com Fri Mar 5 15:17:58 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 12:17:58 -0800 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> On 3/5/10, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > return 'foo' > > ########### foobar.py > def foobar: > if foo.has_been_loaded(): # This is not right! > return foo() + 'bar' # This might need to be foo.foo() ? > else: > return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. Just try importing foo, and then catch the exception if it's not installed. #foobar.py try: import foo except ImportError: FOO_PRESENT = False else: FOO_PRESENT = True if FOO_PRESENT: def foobar(): return foo.foo() + 'bar' else: def foobar(): return 'bar' You could alternately do the `if FOO_PRESENT` check inside the function body rather than defining separate versions of the function. Cheers, Chris -- http://blog.rebertia.com From earnmoney9421 at gmail.com Fri Mar 5 15:20:23 2010 From: earnmoney9421 at gmail.com (Google Adsense) Date: Fri, 5 Mar 2010 12:20:23 -0800 (PST) Subject: Buy Genuine Google Adsense Account only for Rs.200/- for indian people. For more details visit http://www.buygoogleadsense.tk/ We also provide procedure for creating unlimited google adsense account trick . Message-ID: <4074fe88-d923-4383-81df-a8b22a0766a6@g28g2000yqh.googlegroups.com> Buy Genuine Google Adsense Account only for Rs.200/- for indian people. For more details visit http://www.buygoogleadsense.tk/ We also provide procedure for creating unlimited google adsense account trick . From pemerson at gmail.com Fri Mar 5 15:25:37 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 12:25:37 -0800 Subject: Conditional based on whether or not a module is being used In-Reply-To: <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> Message-ID: <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > On 3/5/10, Pete Emerson wrote: >> In a module, how do I create a conditional that will do something >> based on whether or not another module has been loaded? >> >> Suppose I have the following: >> >> import foo >> import foobar >> >> print foo() >> print foobar() >> >> ########### foo.py >> def foo: >> ? ?return 'foo' >> >> ########### foobar.py >> def foobar: >> ? ?if foo.has_been_loaded(): # This is not right! >> ? ? ? ?return foo() + 'bar' ? ? ?# This might need to be foo.foo() ? >> ? ?else: >> ? ? ? ?return 'bar' >> >> If someone is using foo module, I want to take advantage of its >> features and use it in foobar, otherwise, I want to do something else. >> In other words, I don't want to create a dependency of foobar on foo. >> >> My failed search for solving this makes me wonder if I'm approaching >> this all wrong. > > Just try importing foo, and then catch the exception if it's not installed. > > #foobar.py > try: > ? ?import foo > except ImportError: > ? ?FOO_PRESENT = False > else: > ? ?FOO_PRESENT = True > > if FOO_PRESENT: > ? ?def foobar(): > ? ? ? ?return foo.foo() + 'bar' > else: > ? ?def foobar(): > ? ? ? ?return 'bar' > > > You could alternately do the `if FOO_PRESENT` check inside the > function body rather than defining separate versions of the function. > > Cheers, > Chris > -- > http://blog.rebertia.com > Except I want to use the module only if the main program is using it too, not just if it's available for use. I think that I found a way in my follow-up post to my own message, but not sure it's the best way or conventional. Pete From pemerson at gmail.com Fri Mar 5 15:31:16 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 12:31:16 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <9769b00a-8d85-43ed-98e9-f921dc71c217@s36g2000prh.googlegroups.com> On Mar 5, 12:06?pm, "Martin P. Hellwig" wrote: > On 03/05/10 19:24, Pete Emerson wrote: > > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > > If someone is using foo module, I want to take advantage of its > > features and use it in foobar, otherwise, I want to do something else. > > In other words, I don't want to create a dependency of foobar on foo. > > > My failed search for solving this makes me wonder if I'm approaching > > this all wrong. > > > Thanks in advance, > > Pete > > Hmm how about the module is available, just not imported yet, I would > assume that you still would like to use the module then. > Perhaps playing around with the imp module might get you what you mean > instead of what you say? > > -- > mph I can certainly see why one might want to use it if it's available but not yet imported. In that case I could do a try / exception block. But in this case, I actually don't want to use the module unless the main program is doing it too. But you've got me thinking, I need to make sure that's really the desired behavior. Pete From pemerson at gmail.com Fri Mar 5 15:31:40 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 12:31:40 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: On Mar 5, 11:57?am, MRAB wrote: > Pete Emerson wrote: > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > Suppose I have the following: > > > import foo > > import foobar > > > print foo() > > print foobar() > > > ########### foo.py > > def foo: > > ? ? return 'foo' > > > ########### foobar.py > > def foobar: > > ? ? if foo.has_been_loaded(): # This is not right! > > ? ? ? ? return foo() + 'bar' ? ? ?# This might need to be foo.foo() ? > > ? ? else: > > ? ? ? ? return 'bar' > > > If someone is using foo module, I want to take advantage of its > > features and use it in foobar, otherwise, I want to do something else. > > In other words, I don't want to create a dependency of foobar on foo. > > > My failed search for solving this makes me wonder if I'm approaching > > this all wrong. > > Look for its name in sys.modules, for example: > > ? ? ?'foo' in sys.modules Excellent, this is what I finally discovered, although I was looking for 'foo' in sys.modules.keys(), which apparently isn't necessary. From jgardner at jonathangardner.net Fri Mar 5 15:39:58 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 5 Mar 2010 12:39:58 -0800 Subject: start function in new process In-Reply-To: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Message-ID: <6cc20cea1003051239h2983a3cbw68f54bcf547367a8@mail.gmail.com> You're really close. See inline comment below. On Fri, Mar 5, 2010 at 11:21 AM, wongjoekmeu at yahoo.com wrote: > > def c(): > ? ?print "function c" > > def f(a,b, d): > ? ?# function I want to run in a new child process > ? ?print a, b > ? ?d() > > def g(): > ? ?pidID = os.fork() > ? ?if pidID == 0: > ? ? ? ?# child do something here > ? ? ? ?f(2,3,c) You'll need to exit here -- not return. http://docs.python.org/library/os.html#os._exit > ? ?else: > ? ? ? ?# parent do something here > ? ? ? ?print "Parent > > for i in range(3): > ? ?g() > -- Jonathan Gardner jgardner at jonathangardner.net From martin.hellwig at dcuktec.org Fri Mar 5 15:40:55 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 20:40:55 +0000 Subject: start function in new process In-Reply-To: <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> Message-ID: On 03/05/10 20:09, wongjoekmeu at yahoo.com wrote: > On 5 mrt, 21:02, "Martin P. Hellwig" > wrote: >> On 03/05/10 19:45, wongjoek... at yahoo.com wrote: >> >> >> >>> On 5 mrt, 20:40, "Martin P. Hellwig" >>> wrote: >>>> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: >>>> >>>> Any specific reason why threading.Thread or multiprocessing is not >>>> suitable to solve your problem? >> >>>> -- >>>> mph >> >>> Because I got a memory leak in my function f(). It uses scipy, numpy, >>> pylab, and I am not planning to solve the memory leak because its too >>> complicated. So I thought of just calling the function then when it is >>> finished the process is gone and all memory is released. With >>> threading I don't think I would solve this problem. I am not sure >>> though. >> >> I would be surprised if you can't do the same with >> subprocess/multiprocessing, since you seem to know how to identify the >> memory leak it shouldn't be a problem scripting out a test to see if it >> works this way. I would be interested though in your findings. >> >> -- >> mph > > I can't use multiprocessing module since it comes only with python 2.6 > and I am bound to python2.4. But subprocess does exist in python2.4, > but the question now is, how do I achieve that ? Any example ? Sure, for example if I want to check the openssl version (didn't specify I need to provide a useful example :-) I would normally do on the command line: [martin at aspire8930 /usr/home/martin/Desktop]$ /usr/bin/openssl version OpenSSL 0.9.8k 25 Mar 2009 The python subprocess equivalent is: [martin at aspire8930 /usr/home/martin/Desktop]$ python Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess as _sp >>> ssl_version = _sp.Popen(['/usr/bin/openssl', 'version'], stdout=_sp.PIPE) >>> print(ssl_version.stdout.readlines()) ['OpenSSL 0.9.8k 25 Mar 2009\n'] >>> quit() [martin at aspire8930 /usr/home/martin/Desktop]$ If you get any error in the Popen part, you probably did not use the full path or an illegal parameter. If you get a long wait in the readlines part, this usually means that there is either nothing written to stdout or something is still being written (I am not sure about this part though, it has been a while). hth -- mph From robert.kern at gmail.com Fri Mar 5 15:49:40 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 14:49:40 -0600 Subject: start function in new process In-Reply-To: <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> Message-ID: On 2010-03-05 14:09 PM, wongjoekmeu at yahoo.com wrote: > I can't use multiprocessing module since it comes only with python 2.6 > and I am bound to python2.4. It is available as a third party package for Python 2.4: http://pypi.python.org/pypi/multiprocessing -- 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 From jackdied at gmail.com Fri Mar 5 15:58:01 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 5 Mar 2010 15:58:01 -0500 Subject: isinstance(False, int) In-Reply-To: <4b91616d$0$27863$c3e8da3@news.astraweb.com> References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > >> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >>> Arnaud Delobelle wrote: >>> >>>>>>> 1 == True >>>> >>>> True >>>>>>> >>>>>>> 0 == False >>>> >>>> True >>>> >>>> So what's your question? >>> >>> Well nothing I'm just kind of bewildered: I'd expect smth like that in >>> Perl, but not in Python.. Although I can understand the rationale after >>> skimming PEP 285, I still don't like it very much. >>> >>> >> So, the pythonic way to check for True/False should be: >> >>>>> 1 is True >> False > > Why do you need to check for True/False? > You should never check for "is" False/True but always check for equality. The reason is that many types support the equality (__eq__) and boolen (__bool__ in 3x) protocols. If you check equality these will be invoked, if you check identity ("is") they won't. -Jack From info at wingware.com Fri Mar 5 16:00:48 2010 From: info at wingware.com (Wingware) Date: Fri, 05 Mar 2010 16:00:48 -0500 Subject: ANN: Wing IDE 3.2.5 Released Message-ID: <4B917100.9000401@wingware.com> Hi, Wingware has released version 3.2.5 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional code editor with vi, emacs, and other configurable key bindings, auto-completion, call tips, a powerful graphical debugger, integrated version control and unit testing, search, and many other features. The IDE runs on Windows, Linux, and OS X and can be used to develop Python code for web, GUI, and embedded scripting applications. This release includes the following minor features and improvements: * Several vi and brief keyboard mode fixes (see change log for details) * Support recent git versions * Fixed output buffering on OS X for debug process and in OS Commands * Fixed debugger support for Stackless 3.0 and 3.1 * Improve input() handling and other debugger support for Python 3.x * Iterator support for sys.stdin * Avoid losing focus on Debug Probe when stepping in debugger * Fix potential for crashing debug process on certain file names * Don't crash when copying non-ascii text in OS command output * Added delete, duplicate, and swap line operations to Source menu * Added rename-current-file command * Many other minor features and bug fixes; See the change log at http://wingware.com/pub/wingide/3.2.5/CHANGELOG.txt for details *Wing 3.2 Highlights* Versions 3.2.x of Wing IDE include the following new features not present in version 3.1: * Support for Python 3.0 and 3.1 * Rewritten version control integration with support for Subversion, CVS, Bazaar, git, Mercurial, and Perforce (*) * Added 64-bit Debian, RPM, and tar file installers for Linux * File management in Project view (**) * Auto-completion in the editor obtains completion data from live runtime when the debugger is active (**) * Perspectives: Create and save named GUI layouts and optionally automatically transition when debugging is started (*) * Improved support for Cython and Pyrex (*.pyx files) * Added key binding documentation to the manual * Added Restart Debugging item in Debug menu and tool bar (**) * Improved OS Commands and Bookmarks tools (*) * Support for debugging 64-bit Python on OS X (*)'d items are available in Wing IDE Professional only. (**)'d items are available in Wing IDE Personal and Professional only. The release also contains many other minor features and bug fixes; see the change log for details: http://wingware.com/pub/wingide/3.2.5/CHANGELOG.txt *Downloads* Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial license can be obtained directly from the product when launched. Wing IDE 101 can be used free of charge. Wing IDE Pro 3.2.5 http://wingware.com/downloads/wingide/3.2 Wing IDE Personal 3.2.5 http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 3.2.5 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment for the Python programming language. It provides powerful debugging, editing, code intelligence, testing, version control, and search capabilities that reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE 3.2 supports Python versions 2.0.x through 3.1.x. *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Version 2.x licenses cost 1/2 the normal price to upgrade. Upgrade a 2.x license: https://wingware.com/store/upgrade Purchase a 3.x license: https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From clp2 at rebertia.com Fri Mar 5 16:14:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 13:14:53 -0800 Subject: Conditional based on whether or not a module is being used In-Reply-To: <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: <50697b2c1003051314p6d69eb41hbc407f7cf7e8866@mail.gmail.com> On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: >> On 3/5/10, Pete Emerson wrote: >>> In a module, how do I create a conditional that will do something >>> based on whether or not another module has been loaded? >>> If someone is using foo module, I want to take advantage of its >>> features and use it in foobar, otherwise, I want to do something else. >>> In other words, I don't want to create a dependency of foobar on foo. >>> >>> My failed search for solving this makes me wonder if I'm approaching >>> this all wrong. >> >> Just try importing foo, and then catch the exception if it's not installed. > Except I want to use the module only if the main program is using it > too, not just if it's available for use. I think that I found a way in > my follow-up post to my own message, but not sure it's the best way or > conventional. What is your use case for this behavior exactly? You've piqued my curiosity. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Fri Mar 5 16:25:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:25:46 -0500 Subject: Generic singleton In-Reply-To: <4b9146e6$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 3/5/2010 1:01 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: > >> On 3/4/2010 10:32 PM, Steven D'Aprano wrote: >> >>> Python does have it's own singletons, like None, True and False. >> >> True and False are not singletons. > > Duotons? Doubletons? The latter is what I use. > >>>> t1 = bool(1) >>>> t2 = bool(1) >>>> t1 is t2 > True >>>> t1 is t2 is bool("this is also true") is bool(['so', 'is', 'this']) > True > > They're described as singletons in the PEP, so if you want to argue with > Guido, go right ahead... *grin* > http://www.python.org/dev/peps/pep-0285/ Guido already made the argument ;-) when he followed 'The values False and True will be singletons, like None.' with 'Because the type has two values, perhaps these should be called "doubletons"? '. I agree with him here. By 'singleton', I believe he meant 'keyword constants' with guaranteed 'isness'. Ie, "True is True' and 'False is False', like 'None is None', are guaranteed in the language def to be true (True) whereas '0 is 0' and "'' is ''" and '() is ()' are not, even if they happen to be in a particular implementation. None of this determine the behavior of the respective null and boolean classes. If Python had the strict bools that some wanted, bool(x) would not be legal. >> > For some reason, they behave quite differently: >> >> Because they are quite different. > > Well, list("hello world") and list("goodbye now") are quite different > too, but they behave very similarly. > > >> > NoneType fails if you try to instantiate it again, >> >> Because trying 'type(None)()' was probably judged to be more likely to >> be a bug than something useful. > Obviously people are unlikely to write type(None)(), but they are likely > to do something like: > > result = call_some_function(args) > more_code_here() > blah_blah_blah() > new_obj = type(result)() > do_something_with(new_obj) > > If result happens to end up being None, I'm not convinced that the caller > would rather have an exception than get the obvious None. If result > happened to be 0, wouldn't you rather get 0 than have it blow up? I don't > see why None should be any different. This is your strongest argument. It has nothing to do in particular with (the dubious analogy with) bool. Here is a draft of what you might post to python-ideas list, or even the tracker. " Make type(None) return None The built-in classes of CPython nearly all follow the (undocumented?) design rule that if class C has a null instance, C() returns that (usually unique) null (False) instance. Hence, for instance, one can write nulls = [type(x)() for x in obs] to map the objects in obs to their null counterparts. This works for object of at least the following classes: bool, int, float, complex, str, bytes, bytearray, tuple, list, set, frozenset, dict, decimal.Decimal, fractions.Fraction, collections.deque, and collections.defaultdict. The one glaring exception is type(None), which raises a TypeError instead of returning the null value None. This anomaly could be easily corrected, and the rule documented in, for instance, Lib Ref 5.1. Truth Value Testing. Possible objection 1: None is a special singleton. Answer 1: False is special too, and 'bool() is False' is true. Possible objection 2: code that depends on no return would break. Answer 2: at least one other class was changed during the 2.x series to conform to the rule. (xxx which?) " I am pretty sure other classes *were* changed, but cannot specifically remember which. I would look a bit at the tracker and archives for any negative pronouncements between posting. >> > while bool returns the appropriate existing singleton: [sic] >> >> Branching on boolean values (which are no more singletons than 0, 1, >> ...) is basic to computing. > > What does that have to do with the price of fish? I didn't mention > anything about branching on bools. Every use of 'if', 'and', and 'or' implicitly calls bool, and people often call it explicitly. There is almost no use case, other than such as the above, for calling the type of None. > Once a singleton class has been instantiated the first time, you have a > choice if the user tries to instantiate it again. You can do what > NoneType does, and raise an error. Or you can do what bool does, and > return the existing instance. > > Obviously, the behaviour of bool is far more useful. The behavior of bool is necessary. > So I wonder why NoneType doesn't do the same. It predated bool by at least a decade. The choice was pretty inconsequential, especially then, either way. >>> I wonder why NoneType doesn't just return None? >> >> What would you have NoneType(x) do? > > The same thing any function of zero arguments does when it gets called > with one argument. > >> Or the special case NoneType(None)? > > Why would that be a special case? If NoneType takes no arguments, and you > supply an argument, then it is an error regardless of what that argument > happens to be. I agree. I asked because there were objections to correcting object(x) to raise instead of ignore. Terry Jan Reedy From tjreedy at udel.edu Fri Mar 5 16:27:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:27:56 -0500 Subject: isinstance(False, int) In-Reply-To: <4B914DAE.60209@mrabarnett.plus.com> References: <4B914DAE.60209@mrabarnett.plus.com> Message-ID: On 3/5/2010 1:30 PM, MRAB wrote: > mk wrote: >> >>> isinstance(False, int) >> True >> >>> >> >>> isinstance(True, int) >> True >> >> Huh? >> >> >>> >> >>> issubclass(bool, int) >> True >> >> Huh?! >> > Python didn't have Booleans originally, 0 and 1 were used instead. When > bool was introduced it was made a subclass of int so that existing code > wouldn't break. And because it is useful to make it so. Terry Jan Reedy From pemerson at gmail.com Fri Mar 5 16:29:48 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 13:29:48 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: On Mar 5, 1:14?pm, Chris Rebert wrote: > On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > >> On 3/5/10, Pete Emerson wrote: > >>> In a module, how do I create a conditional that will do something > >>> based on whether or not another module has been loaded? > > >>> If someone is using foo module, I want to take advantage of its > >>> features and use it in foobar, otherwise, I want to do something else. > >>> In other words, I don't want to create a dependency of foobar on foo. > > >>> My failed search for solving this makes me wonder if I'm approaching > >>> this all wrong. > > >> Just try importing foo, and then catch the exception if it's not installed. > > > Except I want to use the module only if the main program is using it > > too, not just if it's available for use. I think that I found a way in > > my follow-up post to my own message, but not sure it's the best way or > > conventional. > > What is your use case for this behavior exactly? You've piqued my curiosity. > > Cheers, > Chris > --http://blog.rebertia.com I have written my first module called "logger" that logs to syslog via the syslog module but also allows for logging to STDOUT in debug mode at multiple levels (to increase verbosity depending on one's need), or both. I've looked at the logging module and while it might suit my needs, it's overkill for me right now (I'm still *very* much a python newbie). I want to write other modules, and my thinking is that it makes sense for those modules to use the "logger" module to do the logging, if and only if the parent using the other modules is also using the logger module. In other words, I don't want to force someone to use the "logger" module just so they can use my other modules, even if the "logger" module is installed ... but I also want to take advantage of it if I'm using it. Now that I've written that, I'm not sure that makes a whole lot of sense. It seems like I could say, "hey, this person has the 'logger' module available, let's use it!". Thoughts? From p.c.j.kleiweg at rug.nl Fri Mar 5 16:34:00 2010 From: p.c.j.kleiweg at rug.nl (Peter Kleiweg) Date: Fri, 5 Mar 2010 22:34:00 +0100 Subject: How to send utf-8 mail in Python 3? Message-ID: I try to send e-mail from Python 3.1.1 Encoding as iso-8859-1 goes fine. But encoding as utf-8 doesn't work. What am I doing wrong? Python 3.1.1 (r311:74480, Oct 2 2009, 11:50:52) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from email.mime.text import MIMEText >>> text = 'H\u00e9' >>> msg = MIMEText(text, 'plain', 'iso-8859-1') >>> print(msg.as_string()) Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable H=E9 >>> msg = MIMEText(text, 'plain', 'utf-8') Traceback (most recent call last): File "/my/opt/Python-3/lib/python3.1/email/message.py", line 269, in set_charset cte(self) TypeError: 'str' object is not callable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/my/opt/Python-3/lib/python3.1/email/mime/text.py", line 30, in __init__ self.set_payload(_text, _charset) File "/my/opt/Python-3/lib/python3.1/email/message.py", line 234, in set_payload self.set_charset(charset) File "/my/opt/Python-3/lib/python3.1/email/message.py", line 271, in set_charset self._payload = charset.body_encode(self._payload) File "/my/opt/Python-3/lib/python3.1/email/charset.py", line 380, in body_encode return email.base64mime.body_encode(string) File "/my/opt/Python-3/lib/python3.1/email/base64mime.py", line 94, in body_encode enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii") TypeError: must be bytes or buffer, not str >>> -- Peter Kleiweg From gherron at islandtraining.com Fri Mar 5 16:42:01 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Mar 2010 13:42:01 -0800 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4B917AA9.7070207@islandtraining.com> Mensanator wrote: > On Mar 5, 12:28 pm, Steven D'Aprano cybersource.com.au> wrote: > >> On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: >> >>>>>> l = range(10) >>>>>> l >>>>>> >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> >>>>>> l[7::-1] >>>>>> >>> [7, 6, 5, 4, 3, 2, 1, 0] >>> >>>>>> [l[i] for i in range(7, -1, -1)] >>>>>> >>> [7, 6, 5, 4, 3, 2, 1, 0] >>> >> Where does the first -1 come from? Slices are supposed to have default >> values of 0 and len(seq): >> > > The only way to get a 0 from a reverse range() is to have a bound of > -1. > Not quite. An empty second bound goes all the way to the zero index: >>> range(9)[2::-1] [2, 1, 0] Gary Herron > >>>>> l[7::1] >>>>> >> [7, 8, 9] >> >>>>> [l[i] for i in range(7, len(l), 1)] >>>>> >> [7, 8, 9] >> >>>>> [l[i] for i in range(7, len(l), -1)] >>>>> >> [] >> >> I don't believe the actual behaviour is documented anywhere. >> > > Well, it's implied. If the stopping bound in a reverse range() > is greater than the starting bound, you get an empty return. > > >> -- >> Steven >> > > From nyamatongwe+thunder at gmail.com Fri Mar 5 16:45:54 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 05 Mar 2010 21:45:54 GMT Subject: Passing FILE * types using ctypes In-Reply-To: References: Message-ID: Zeeshan Quireshi: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. For this to work, your library should have been compiled with the same compiler as Python and possibly the same compiler options such as choice of runtime library. Otherwise, they may differ in the content and layout of FILE and also in behaviour. On Unix, this may not be a problem because of the shared runtime but on Windows it can cause crashes. Neil From tjreedy at udel.edu Fri Mar 5 16:46:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:46:23 -0500 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 3/5/2010 2:10 PM, Robert Kern wrote: > Rather, they have 0 and len(seq), respectively, when the step is > positive, and len(seq)-1 and -1 when the step is negative. >> I don't believe the actual behaviour is documented anywhere. > > True, I don't think it is. There are at least two open issues. http://bugs.python.org/issue1446619 http://bugs.python.org/issue7460 From tjreedy at udel.edu Fri Mar 5 16:51:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:51:25 -0500 Subject: isinstance(False, int) In-Reply-To: <4B915352.8010709@sequans.com> References: <4b914860$0$27863$c3e8da3@news.astraweb.com> <4B915352.8010709@sequans.com> Message-ID: On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: > Despite there are good reasons for bool to be int, the newcomer 'wtf' > reaction at first glance is legitimate. > Starting python from scratch, booleans would have not been a subclass of > int (just guessing though), 'cause it makes no sense from a design POV. You are just guessing. I would argue for what we have. An example of its usefulness: >>> scores =[True, False, True, True, False] >>> score = sum(scores) >>> score 3 Bools are also usefully used as sequence indexes. Terry Jan Reedy From arnodel at googlemail.com Fri Mar 5 17:00:16 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Mar 2010 22:00:16 +0000 Subject: imap vs map References: Message-ID: mk writes: > Hello everyone, > > I re-wrote more "slowly" an example at the end of > http://wordaligned.org/articles/essential-python-reading-list > > > This example finds anagrams in the text file. > > ==== > from itertools import groupby, imap > from operator import itemgetter > > from string import ascii_lowercase, ascii_uppercase, punctuation, > maketrans, translate > > data = open(r"c:\temp\words.txt", "rt").read() > > trtable = maketrans(ascii_uppercase, ascii_lowercase) > > words = translate(data, trtable, deletions = punctuation) > > words = list(set(words.split())) > > sw = sorted(words, key=sorted) > > gb = groupby(sw, sorted) > > print map(list, imap(itemgetter(1), gb)) > === > > words.txt: > === > Word Aligned > three > space sensitive programming > Feed Logo tins > Essential Python post Reading List > stop course there > times isnt > capes > === > > Now, when I execute above, it works: > > [['capes', 'space'], ['aligned'], ['reading'], ['essential'], > ['programming'], ['course'], ['feed'], ['word'], ['there', 'three'], > ['sensitive'], ['times'], ['logo'], ['python'], ['list'], ['isnt', > tins'], ['stop', 'post']] > > > However, when I change the last line to: > > print map(list, map(itemgetter(1), gb)) > > It stops working: > > [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ['post']] > > Why? I was under impression that the only difference between map and > imap is that imap returns iterator allowing to produce a list, while > map returns equivalent list? > > Regards, > mk >From the itertools docs [1]: The returned group is itself an iterator that shares the underlying iterable with groupby(). Because the source is shared, when the groupby() object is advanced, the previous group is no longer visible. So, if that data is needed later, it should be stored as a list: (example follows) So when you use: print map(list, imap(itemgetter(1), gb)) each group is stored as a list *before* the groupby() object is advanced, so that's ok. However, when you use: print map(list, map(itemgetter(1), gb)) the groupby() object is advanced to the end *before* each group is stored as a list. According the the docs quoted above, this renders each group no longer visible. It is for the same reason that the following are different: >>> def foo(): ... for i in range(5): ... yield lambda: i ... >>> map(lambda f: f(), imap(lambda x: x, foo())) [0, 1, 2, 3, 4] >>> map(lambda f: f(), map(lambda x: x, foo())) [4, 4, 4, 4, 4] Although looking back at it, I don't know if this will help you :) [1] http://docs.python.org/library/itertools.html#itertools.groupby -- Arnaud From robert.kern at gmail.com Fri Mar 5 17:09:17 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 16:09:17 -0600 Subject: isinstance(False, int) In-Reply-To: References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 14:58 PM, Jack Diederich wrote: > On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano > wrote: >> On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: >> >>> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >>>> Arnaud Delobelle wrote: >>>> >>>>>>>> 1 == True >>>>> >>>>> True >>>>>>>> >>>>>>>> 0 == False >>>>> >>>>> True >>>>> >>>>> So what's your question? >>>> >>>> Well nothing I'm just kind of bewildered: I'd expect smth like that in >>>> Perl, but not in Python.. Although I can understand the rationale after >>>> skimming PEP 285, I still don't like it very much. >>>> >>>> >>> So, the pythonic way to check for True/False should be: >>> >>>>>> 1 is True >>> False >> >> Why do you need to check for True/False? >> > > You should never check for "is" False/True but always check for > equality. The reason is that many types support the equality (__eq__) > and boolen (__bool__ in 3x) protocols. If you check equality these > will be invoked, if you check identity ("is") they won't. It depends on what you're doing. mk seems to want to distinguish booleans from other objects from some reason. -- 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 From robert.kern at gmail.com Fri Mar 5 17:12:39 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 16:12:39 -0600 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 13:10 PM, Robert Kern wrote: > On 2010-03-05 12:28 PM, Steven D'Aprano wrote: >> On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: >> >>>>>> l = range(10) >>>>>> l >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>>>> l[7::-1] >>> [7, 6, 5, 4, 3, 2, 1, 0] >>>>>> [l[i] for i in range(7, -1, -1)] >>> [7, 6, 5, 4, 3, 2, 1, 0] >> >> Where does the first -1 come from? Slices are supposed to have default >> values of 0 and len(seq): > > Rather, they have 0 and len(seq), respectively, when the step is > positive, and len(seq)-1 and -1 when the step is negative. Well, not entirely true. [N:-1:-1] obviously doesn't work for this. Rather, leaving the second argument in the slice empty means "go to the end if step > 0 or go to the beginning if step < 0". There is no explicit translation of the latter because there is no numerical index for the element before the first element. -- 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 From tjreedy at udel.edu Fri Mar 5 17:16:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 17:16:00 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: On 3/5/2010 4:29 PM, Pete Emerson wrote: > On Mar 5, 1:14 pm, Chris Rebert wrote: > I want to write other modules, and my thinking is that it makes sense > for those modules to use the "logger" module to do the logging, if and > only if the parent using the other modules is also using the logger > module. > > In other words, I don't want to force someone to use the "logger" > module just so they can use my other modules, even if the "logger" > module is installed ... but I also want to take advantage of it if I'm > using it. > > Now that I've written that, I'm not sure that makes a whole lot of > sense. It seems like I could say, "hey, this person has the 'logger' > module available, let's use it!". Except in unusual cases, where merely importing a modules uses substantial resources, I would say that if it is available, use it. From aahz at pythoncraft.com Fri Mar 5 17:45:34 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Mar 2010 14:45:34 -0800 Subject: Draft PEP on RSON configuration file format References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274 <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwrxv4vv7.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >ReST is another abomination that should never have gotten off the >ground. It is one of the reasons I react so negatively to your >config format proposal. It just sounds like more of the same. Really? What should we use instead of reST? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 18:07:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 23:07:52 GMT Subject: Generic singleton References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4b918ec8$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 16:25:46 -0500, Terry Reedy wrote: > On 3/5/2010 1:01 PM, Steven D'Aprano wrote: >> On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: >> >>> On 3/4/2010 10:32 PM, Steven D'Aprano wrote: >>> >>>> Python does have it's own singletons, like None, True and False. >>> >>> True and False are not singletons. >> >> Duotons? Doubletons? > > The latter is what I use. The Wikipedia article on Singleton states that it is acceptable to generalise "Singleton" to allow multiple instances. http://en.wikipedia.org/wiki/Singleton_pattern While Doubleton or even Tripleton sound cute, once you get to large counts it all starts getting ugly and horrible. "Polyton"? Blah. [...] > This is your strongest argument. It has nothing to do in particular with > (the dubious analogy with) bool. Here is a draft of what you might post > to python-ideas list, or even the tracker. Oh, you have misunderstood me. I'm not particularly concerned about NoneType's behaviour, and certainly not concerned enough to champion the change against any opposition (let alone through the moratorium!). I wanted to understand why the difference existed. Python has at least two other singletons, Ellipsis and NotImplemented, and both behave like None. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 18:09:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 23:09:58 GMT Subject: isinstance(False, int) References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4b918f46$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: >>> So, the pythonic way to check for True/False should be: >>> >>>>>> 1 is True >>> False >> >> Why do you need to check for True/False? >> >> > You should never check for "is" False/True but always check for > equality. The reason is that many types support the equality (__eq__) > and boolen (__bool__ in 3x) protocols. If you check equality these will > be invoked, if you check identity ("is") they won't. Never say never. If you specifically want to test for True or False themselves, accepting no substitutes, then using "is" is the obvious way, and using "==" is clearly and obviously wrong because it does accept substitutes: >>> 1.0 == True True >>> decimal.Decimal(0, 1) == False True -- Steven From jackdied at gmail.com Fri Mar 5 18:48:39 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 5 Mar 2010 18:48:39 -0500 Subject: isinstance(False, int) In-Reply-To: <4b918f46$0$27863$c3e8da3@news.astraweb.com> References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> <4b918f46$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: > >>>> So, the pythonic way to check for True/False should be: >>>> >>>>>>> 1 is True >>>> False >>> >>> Why do you need to check for True/False? >>> >>> >> You should never check for "is" False/True but always check for >> equality. ?The reason is that many types support the equality (__eq__) >> and boolen (__bool__ in 3x) protocols. ?If you check equality these will >> be invoked, if you check identity ("is") they won't. > > Never say never. > > If you specifically want to test for True or False themselves, accepting > no substitutes, then using "is" is the obvious way, and using "==" is > clearly and obviously wrong because it does accept substitutes: > >>>> 1.0 == True > True >>>> decimal.Decimal(0, 1) == False > True Yes, obviously if you _really_ mean to test if something has the object identity of True or False then an "is" test is the way to go. I'm just not sure why you would ever do that. Also, I'm not sure how your assertion matches up with the examples; The examples test for equality with a float that returns true for __eq__ and a Decimal that returns false for __eq__. Both "1.0" and "Decimal(0, 1)" will return False if the test is "is True" or "is False." -Jack From clp2 at rebertia.com Fri Mar 5 18:59:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 15:59:39 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> On Fri, Mar 5, 2010 at 2:45 PM, Aahz wrote: > In article <7xwrxv4vv7.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: >> >>ReST is another abomination that should never have gotten off the >>ground. It is one of the reasons I react so negatively to your >>config format proposal. It just sounds like more of the same. > > Really? What should we use instead of reST? Markdown, Textile, or possibly Creole; reST has so little use outside of Python as to be nearly Python-specific. It'd be nice not to have to learn yet another markup language without good reason. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Fri Mar 5 19:09:06 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 16:09:06 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Mar 5, 3:42?pm, Gary Herron wrote: > Mensanator wrote: > > > The only way to get a 0 from a reverse range() is to have a bound of > > -1. > > Not quite. ?An empty second bound goes all the way to the zero index: Not the same thing. You're using the bounds of the slice index. I was refering to the bounds of the range() function. >>> for a in range(9,-9,-1):print(a,end=' ') 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 To get that to stop at 0, you use a -1 as the bounds: >>> for a in range(9,-1,-1):print(a,end=' ') 9 8 7 6 5 4 3 2 1 0 Your slice notation only works if the last (first?) number in the range happens to be 0. What if the range bounds were variables? You may still want to force the range's last number to be 0 by using a constant like range(a,-1,-1) rather than just take the last number of range(a,b,-1) by using slice notation. > > ?>>> range(9)[2::-1] > [2, 1, 0] > > Gary Herron From clp2 at rebertia.com Fri Mar 5 19:18:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 16:18:29 -0800 Subject: isinstance(False, int) In-Reply-To: References: <4b914860$0$27863$c3e8da3@news.astraweb.com> <4B915352.8010709@sequans.com> Message-ID: <50697b2c1003051618n7b37aee6t74bd8f9edc5d21f5@mail.gmail.com> On Fri, Mar 5, 2010 at 1:51 PM, Terry Reedy wrote: > On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote: >> Steven D'Aprano wrote: > >> Despite there are good reasons for bool to be int, the newcomer 'wtf' >> reaction at first glance is legitimate. >> Starting python from scratch, booleans would have not been a subclass of >> int (just guessing though), 'cause it makes no sense from a design POV. > > You are just guessing. I would argue for what we have. An example of its > usefulness: > >>>> scores =[True, False, True, True, False] >>>> score = sum(scores) >>>> score > 3 > > Bools are also usefully used as sequence indexes. Arguably, these sorts of uses only require bool to be /convertible/ to int, not to necessarily be a /subclass/ of int. Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Fri Mar 5 19:34:26 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Mar 2010 16:34:26 -0800 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4B91A312.9060608@islandtraining.com> Mensanator wrote: > On Mar 5, 3:42 pm, Gary Herron wrote: > >> Mensanator wrote: >> >> >>> The only way to get a 0 from a reverse range() is to have a bound of >>> -1. >>> >> Not quite. An empty second bound goes all the way to the zero index: >> > > Not the same thing. You're using the bounds of the slice index. > I was refering to the bounds of the range() function. > > >>>> for a in range(9,-9,-1):print(a,end=' ') >>>> > 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 > > To get that to stop at 0, you use a -1 as the bounds: > > >>>> for a in range(9,-1,-1):print(a,end=' ') >>>> > 9 8 7 6 5 4 3 2 1 0 > > Your slice notation only works if the last (first?) number in > the range happens to be 0. What if the range bounds were variables? > You may still want to force the range's last number to be 0 by > using a constant like range(a,-1,-1) rather than just take > the last number of range(a,b,-1) by using slice notation. > All true and valid of course, but I was just contridicting the "the ONLY way to get a 0" (emphasis mine) part of the statement. Gary Herron > >> >>> range(9)[2::-1] >> [2, 1, 0] >> >> Gary Herron >> From greg.ewing at canterbury.ac.nz Fri Mar 5 20:06:37 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:06:37 +1300 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vdnhhFo9jU1@mid.individual.net> Steven D'Aprano wrote: > I use footnotes all the time[1] in plain text documents and emails. I > don't think there's anything bizarre about it at all. It's not the use of footnotes I'm talking about, it's the cryptic character sequences used to mark them up in ReST. Nobody would come up with them on their own without having read the fine print of an ReST manual. -- Greg From robert.kern at gmail.com Fri Mar 5 20:08:01 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 19:08:01 -0600 Subject: isinstance(False, int) In-Reply-To: References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> <4b918f46$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 17:48 PM, Jack Diederich wrote: > On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano > wrote: >> On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: >> >>>>> So, the pythonic way to check for True/False should be: >>>>> >>>>>>>> 1 is True >>>>> False >>>> >>>> Why do you need to check for True/False? >>>> >>>> >>> You should never check for "is" False/True but always check for >>> equality. The reason is that many types support the equality (__eq__) >>> and boolen (__bool__ in 3x) protocols. If you check equality these will >>> be invoked, if you check identity ("is") they won't. >> >> Never say never. >> >> If you specifically want to test for True or False themselves, accepting >> no substitutes, then using "is" is the obvious way, and using "==" is >> clearly and obviously wrong because it does accept substitutes: >> >>>>> 1.0 == True >> True >>>>> decimal.Decimal(0, 1) == False >> True > > > Yes, obviously if you _really_ mean to test if something has the > object identity of True or False then an "is" test is the way to go. > I'm just not sure why you would ever do that. Also, I'm not sure how > your assertion matches up with the examples; The examples test for > equality with a float that returns true for __eq__ and a Decimal that > returns false for __eq__. No, both comparisons return True. Decimal(0,1) is equal in value to 0 (and thus False). Comparing it to False using __eq__ returns True. > Both "1.0" and "Decimal(0, 1)" will return > False if the test is "is True" or "is False." Yes. That is exactly what he is asserting. -- 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 From no.email at nospam.invalid Fri Mar 5 20:10:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Mar 2010 17:10:14 -0800 Subject: Draft PEP on RSON configuration file format References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> Message-ID: <7xocj2fe6h.fsf@ruckus.brouhaha.com> Robert Kern writes: >> Markdown, Textile, or possibly Creole;... > I believe ReST predates all of those mentioned. Texinfo and POD are certainly older than ReST. I'm not sure about MediaWiki markup, but it's gotten so much traction that Markdown should probably be abandoned in its favor even if Markdown is older. From robert.kern at gmail.com Fri Mar 5 20:15:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 19:15:46 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> Message-ID: On 2010-03-05 17:59 PM, Chris Rebert wrote: > On Fri, Mar 5, 2010 at 2:45 PM, Aahz > wrote: > > In article <7xwrxv4vv7.fsf at ruckus.brouhaha.com > >, > > Paul Rubin wrote: > >> > >>ReST is another abomination that should never have gotten off the > >>ground. It is one of the reasons I react so negatively to your > >>config format proposal. It just sounds like more of the same. > > > > Really? What should we use instead of reST? > > Markdown, Textile, or possibly Creole; reST has so little use outside of > Python as to be nearly Python-specific. > It'd be nice not to have to learn yet another markup language without > good reason. I believe ReST predates all of those mentioned. -- 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 From greg.ewing at canterbury.ac.nz Fri Mar 5 20:19:03 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:19:03 +1300 Subject: My four-yorkshireprogrammers contribution In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> Message-ID: <7vdo8sFrelU1@mid.individual.net> MRAB wrote: > By the standards of just a few years later, that's not so much a > microcomputer as a nanocomputer! Although not quite as nano as another design published in EA a couple of years earlier, the EDUC-8: http://www.sworld.com.au/steven/educ-8/ It had a *maximum* of 256 bytes -- due to the architecture, there was no way of addressing any more. Also it was divided into 16-byte pages, with indirect addressing required to access anything in a different page from the instruction. Programming for it must have been rather challenging. As far as I know, the EDUC-8 is unique in being the only computer design ever published in a hobby magazine that *wasn't* based on a microprocessor -- it was all built out of 9000 and 7400 series TTL logic chips! -- Greg From pemerson at gmail.com Fri Mar 5 20:22:14 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 17:22:14 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? Message-ID: I've been wrestling with dicts. I hope at the very least what I discovered helps someone else out, but I'm interested in hearing from more learned python users. I found out that adding a two dimensional element without defining first dimension existing doesn't work: >>> data = {} >>> data['one']['two'] = 'three' Traceback (most recent call last): File "", line 1, in KeyError: 'one' >>> data['one'] = {} >>> data['one']['two'] = 'three' >>> print data {'one': {'two': 'three'}} And through some research, I discovered collections.defaultdict (new in Python 2.5, FWIW): >>> import collections >>> data = collections.defaultdict(dict) >>> data['one']['two'] = 'three' >>> print data defaultdict(, {'one': {'two': 'three'}}) Why isn't the behavior of collections.defaultdict the default for a dict? Am I just revelling in my bad perl habits by not wanting to declare a previous level first? Is this sort of "more rigid" way of doing things common throughout python, and is it best that I not fight it, but embrace it? Your thoughts and comments are very much appreciated. I think my brain already knows some of the answers, but my heart ... well, perl and I go way back. Loving python so far, though. Pete From greg.ewing at canterbury.ac.nz Fri Mar 5 20:39:25 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:39:25 +1300 Subject: Generic singleton In-Reply-To: <4b9146e6$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vdpf2FqgU1@mid.individual.net> I think the important difference between None and booleans wrt singleton behaviour is that things are often compared with None using "is", so it's quite important that there only be one instance of NoneType around, and it makes sense not to give people the false impression that they can create another one. Re-using predefined True and False instances is more of a performance optimisation, however -- they're not usually compared for identity, or even compared at all for that matter. So there's no particular reason to disallow calling bool(). In fact, there's an excellent reason to *allow* calling it: not only is bool a type, it's also often used as a function to coerce things to a boolean value: >>> bool(['hello']) True There's no equivalent reason to make NoneType callable, as coercing something to None makes very little sense. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 5 20:45:58 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:45:58 +1300 Subject: Generic singleton In-Reply-To: <4b918ec8$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> <4b918ec8$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vdpraF2glU1@mid.individual.net> Steven D'Aprano wrote: > While Doubleton or even Tripleton sound cute, once you get to large > counts it all starts getting ugly and horrible. "Polyton"? Blah. Tupleton? -- Greg From usenot at geekmail.INVALID Fri Mar 5 21:02:58 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 6 Mar 2010 03:02:58 +0100 Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <20100306030258.01d324b7@geekmail.INVALID> On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > > >>> data = {} > >>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "", line 1, in > KeyError: 'one' Yeah, because that key 'one' indexes what exactly? > [snip] > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > > [snip] > > Why isn't the behavior of collections.defaultdict the default for a > dict? Because explicit is better than implicit. How should Python know what you want to fill your dict with? It could be anything that takes string indices. Only two lines of code remove all the guesswork. > Am I just revelling in my bad perl habits by not wanting to declare a > previous level first? Yes. Python pretty much never guesses (not that I knew of anyway). I think that is good, because it's just too easy to overlook some magic the language does and spend an hour trying to understand why that Toyota hit that wall. > Is this sort of "more rigid" way of doing things common throughout > python, and is it best that I not fight it, but embrace it? > Seriously, what answer do you expect? ;) When has fighting a language ever brought about something really cool. (I'm really looking forward to the geeky humorous replies this is bound to sprout.) > Your thoughts and comments are very much appreciated. I think my brain > already knows some of the answers, but my heart ... well, perl and I > go way back. Loving python so far, though. > Welcome on board. Have you typed "import this" in the command prompt yet? -- INVALID? DE! From mensanator at aol.com Fri Mar 5 21:09:59 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 18:09:59 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: <83e3ccd0-29d6-4aec-8590-a38e6daba56d@g26g2000yqn.googlegroups.com> On Mar 5, 6:34?pm, Gary Herron wrote: > Mensanator wrote: > > On Mar 5, 3:42 pm, Gary Herron wrote: > > >> Mensanator wrote: > > >>> The only way to get a 0 from a reverse range() is to have a bound of > >>> -1. > > >> Not quite. ?An empty second bound goes all the way to the zero index: > > > Not the same thing. You're using the bounds of the slice index. > > I was refering to the bounds of the range() function. > > >>>> for a in range(9,-9,-1):print(a,end=' ') > > > 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 > > > To get that to stop at 0, you use a -1 as the bounds: > > >>>> for a in range(9,-1,-1):print(a,end=' ') > > > 9 8 7 6 5 4 3 2 1 0 > > > Your slice notation only works if the last (first?) number in > > the range happens to be 0. What if the range bounds were variables? > > You may still want to force the range's last number to be 0 by > > using a constant like range(a,-1,-1) rather than just take > > the last number of range(a,b,-1) by using slice notation. > > All true ?and valid of course, but I was just contridicting the "the > ONLY way to get a 0" (emphasis mine) part of the statement. Does it still contradict if you do not use the '::' as the OP requested? > > Gary Herron > > > > > > >> ?>>> range(9)[2::-1] > >> [2, 1, 0] > > >> Gary Herron- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - From usenot at geekmail.INVALID Fri Mar 5 21:10:03 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 6 Mar 2010 03:10:03 +0100 Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <20100306031003.1018aab2@geekmail.INVALID> On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson wrote: > [snip] > >>> data['one'] = {} > >>> data['one']['two'] = 'three' > >>> print data > {'one': {'two': 'three'}} > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > > >>> import collections > >>> data = collections.defaultdict(dict) > >>> data['one']['two'] = 'three' > >>> print data > defaultdict(, {'one': {'two': 'three'}}) > > [snip] > Your thoughts and comments are very much appreciated. I think my brain > already knows some of the answers, but my heart ... well, perl and I > go way back. Loving python so far, though. > Oh, by the way: That defaultdict route is a pretty solid solution. Not sure what problem you're trying to solve -- depending on your usecase, there might be a better approach. If you're just asking hypothetically and you're trying to apply a Perl idiom to Python, there probably *is* a better solution. /W -- INVALID? DE! From ckaynor at zindagigames.com Fri Mar 5 21:20:42 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 5 Mar 2010 18:20:42 -0800 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: References: Message-ID: On Fri, Mar 5, 2010 at 5:22 PM, Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > > >>> data = {} > >>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "", line 1, in > KeyError: 'one' > >>> data['one'] = {} > >>> data['one']['two'] = 'three' > >>> print data > {'one': {'two': 'three'}} > > Perhaps a better idiom for what you are doing would be to use tuples as the keys: (I don't have a handy Python interpreter, so untested) data = {} data[('one', 'two')] = 'three' -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Mar 5 21:26:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Mar 2010 02:26:39 +0000 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: References: Message-ID: <4B91BD5F.1020304@mrabarnett.plus.com> Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > >>>> data = {} >>>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "", line 1, in > KeyError: 'one' >>>> data['one'] = {} >>>> data['one']['two'] = 'three' >>>> print data > {'one': {'two': 'three'}} > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > >>>> import collections >>>> data = collections.defaultdict(dict) >>>> data['one']['two'] = 'three' >>>> print data > defaultdict(, {'one': {'two': 'three'}}) > > Why isn't the behavior of collections.defaultdict the default for a > dict? > Am I just revelling in my bad perl habits by not wanting to declare a > previous level first? > Is this sort of "more rigid" way of doing things common throughout > python, and is it best that I not fight it, but embrace it? > > Your thoughts and comments are very much appreciated. I think my brain > already knows some of the answers, but my heart ... well, perl and I > go way back. Loving python so far, though. > Someone once wrote about a case where he was porting a frontend from Perl to Python. It called a backend and parsed the result. Sometimes converting one of the fields to a number would raise a ValueError because it would contain "ERR" instead of a number, which Perl, of course, would silently convert to 0! Python is all about refusing to guess, and complaining if there's an error. :-) From pemerson at gmail.com Fri Mar 5 21:30:47 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 18:30:47 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? References: <20100306031003.1018aab2@geekmail.INVALID> Message-ID: <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> On Mar 5, 6:10?pm, Andreas Waldenburger wrote: > On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson > > > > > > wrote: > > [snip] > > >>> data['one'] = {} > > >>> data['one']['two'] = 'three' > > >>> print data > > {'one': {'two': 'three'}} > > > And through some research, I discovered collections.defaultdict (new > > in Python 2.5, FWIW): > > > >>> import collections > > >>> data = collections.defaultdict(dict) > > >>> data['one']['two'] = 'three' > > >>> print data > > defaultdict(, {'one': {'two': 'three'}}) > > > [snip] > > Your thoughts and comments are very much appreciated. I think my brain > > already knows some of the answers, but my heart ... well, perl and I > > go way back. Loving python so far, though. > > Oh, by the way: That defaultdict route is a pretty solid solution. Not > sure what problem you're trying to solve -- depending on your usecase, > there might be a better approach. > > If you're just asking hypothetically and you're trying to apply a > Perl idiom to Python, there probably *is* a better solution. > > /W > > -- > INVALID? DE! I found out about the need to declare the higher level as I was reading in a JSON struct into a dict and then adding a new entry at a lower level. Mostly just proof of concept stuff as I'm learning python. I'm not sure that the use of defaultdict is really warranted for me anywhere just yet. Mostly, I don't want to convert my perl to python, that seems very counterproductive. Thank you very much for your insight. I was a little frightened of doing "import this" ("Hey, kid, run rm - rf / and see what happens!"), but did, and the words are wise. :) Pete From alfps at start.no Fri Mar 5 21:32:48 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Mar 2010 03:32:48 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 09:39 AM, Mike Kent wrote: >> What's the compelling use case for this vs. a simple try/finally? >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup > > A custom-written context manager looks nicer and can be more readable. > > from contextlib import contextmanager > import os > > @contextmanager > def pushd(path): > original_dir = os.getcwd() > os.chdir(path) > try: > yield > finally: > os.chdir(original_dir) > > > with pushd(somewhere): > ... > > > I don't think a general purpose ScopeGuard context manager has any such > benefits over the try: finally:, though. class pushd( Cleanup ): def __init__( self, path ): original_dir = os.getcwd() os.chdir( path ) self._actions.append( lambda: os.chdir( original_dir ) ) Disclaimer: haven't tested this, but it just occurred to me that for such small init/cleanup wrappers the Cleanup class provides a nice alternative to @contextmanager, as above: fewer lines, and perhaps even more clear code. :-) Cheers, - Alf From no.email at nospam.invalid Fri Mar 5 21:53:46 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Mar 2010 18:53:46 -0800 Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <7xlje6rwhx.fsf@ruckus.brouhaha.com> Pete Emerson writes: > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > >>>> data = {} >>>> data['one']['two'] = 'three' You can use a tuple as a subscript if you want: data = {} data['one','two'] = 'three' From gherron at islandtraining.com Fri Mar 5 22:05:20 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Mar 2010 19:05:20 -0800 Subject: Slicing [N::-1] In-Reply-To: <83e3ccd0-29d6-4aec-8590-a38e6daba56d@g26g2000yqn.googlegroups.com> References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> <83e3ccd0-29d6-4aec-8590-a38e6daba56d@g26g2000yqn.googlegroups.com> Message-ID: <4B91C670.3060305@islandtraining.com> Mensanator wrote: > On Mar 5, 6:34 pm, Gary Herron wrote: > >> Mensanator wrote: >> >>> On Mar 5, 3:42 pm, Gary Herron wrote: >>> >>>> Mensanator wrote: >>>> >>>>> The only way to get a 0 from a reverse range() is to have a bound of >>>>> -1. >>>>> >>>> Not quite. An empty second bound goes all the way to the zero index: >>>> >>> Not the same thing. You're using the bounds of the slice index. >>> I was refering to the bounds of the range() function. >>> >>>>>> for a in range(9,-9,-1):print(a,end=' ') >>>>>> >>> 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 >>> >>> To get that to stop at 0, you use a -1 as the bounds: >>> >>>>>> for a in range(9,-1,-1):print(a,end=' ') >>>>>> >>> 9 8 7 6 5 4 3 2 1 0 >>> >>> Your slice notation only works if the last (first?) number in >>> the range happens to be 0. What if the range bounds were variables? >>> You may still want to force the range's last number to be 0 by >>> using a constant like range(a,-1,-1) rather than just take >>> the last number of range(a,b,-1) by using slice notation. >>> >> All true and valid of course, but I was just contridicting the "the >> ONLY way to get a 0" (emphasis mine) part of the statement. >> > > Does it still contradict if you do not use the '::' as the OP > requested? > Not to my knowledge... I believe your statement is true in all cases which explicitly state the stop value. > >> Gary Herron >> >> >> >> >> >> >>>> >>> range(9)[2::-1] >>>> [2, 1, 0] >>>> >>>> Gary Herron- Hide quoted text - >>>> >> - Show quoted text -- Hide quoted text - >> >> - Show quoted text - >> > > From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 23:24:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Mar 2010 04:24:32 GMT Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <4b91d900$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > Why isn't the behavior of collections.defaultdict the default for a > dict? Why would it be? If you look up a key in a dict: addressbook['Barney Rubble'] and you don't actually have Barney's address, should Python guess and make something up? In general, looking up a missing key is an error, and errors should never pass silently unless explicitly silenced. And for those cases where missing keys are not errors, you're spoiled for choice: dict.get dict.setdefault collections.defaultdict try: dict[key] except KeyError: do something else Or even: if key in dict: dict[key] else: do something else -- Steven From pemerson at gmail.com Sat Mar 6 00:36:39 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 21:36:39 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? References: <4b91d900$0$27863$c3e8da3@news.astraweb.com> Message-ID: <6048eb76-9dca-4509-ad7e-f65040128ebb@b36g2000pri.googlegroups.com> On Mar 5, 8:24?pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > > Why isn't the behavior of collections.defaultdict the default for a > > dict? > > Why would it be? > > If you look up a key in a dict: > > addressbook['Barney Rubble'] > > and you don't actually have Barney's address, should Python guess and > make something up? > > In general, looking up a missing key is an error, and errors should never > pass silently unless explicitly silenced. > > And for those cases where missing keys are not errors, you're spoiled for > choice: > > dict.get > dict.setdefault > collections.defaultdict > > try: > ? ? dict[key] > except KeyError: > ? ? do something else > > Or even: > > if key in dict: > ? ? dict[key] > else: > ? ? do something else > > -- > Steven My frame of reference for the past 10 < N < 15 years has been doing this sort of assignment in perl: $hash{key1}{key2} = value I definitely agree that looking up a missing key should give an error. The lazy perl programmer in me just wants to make an assignment to a missing second key without defining the first key first. I'm not saying it's right, I'm saying that it's something I'm trying to unlearn, as I'm being convinced that it's the "best way" to do it in python. I'll take a look at dict.get and dict.setdefault, thank you for those. I'm learning, and you're all very helpful, and I appreciate it! Pete From pemerson at gmail.com Sat Mar 6 00:42:37 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 21:42:37 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: On Mar 5, 6:26?pm, MRAB wrote: > Pete Emerson wrote: > > I've been wrestling with dicts. I hope at the very least what I > > discovered helps someone else out, but I'm interested in hearing from > > more learned python users. > > > I found out that adding a two dimensional element without defining > > first dimension existing doesn't work: > > >>>> data = {} > >>>> data['one']['two'] = 'three' > > Traceback (most recent call last): > > ? File "", line 1, in > > KeyError: 'one' > >>>> data['one'] = {} > >>>> data['one']['two'] = 'three' > >>>> print data > > {'one': {'two': 'three'}} > > > And through some research, I discovered collections.defaultdict (new > > in Python 2.5, FWIW): > > >>>> import collections > >>>> data = collections.defaultdict(dict) > >>>> data['one']['two'] = 'three' > >>>> print data > > defaultdict(, {'one': {'two': 'three'}}) > > > Why isn't the behavior of collections.defaultdict the default for a > > dict? > > Am I just revelling in my bad perl habits by not wanting to declare a > > previous level first? > > Is this sort of "more rigid" way of doing things common throughout > > python, and is it best that I not fight it, but embrace it? > > > Your thoughts and comments are very much appreciated. I think my brain > > already knows some of the answers, but my heart ... well, perl and I > > go way back. Loving python so far, though. > > Someone once wrote about a case where he was porting a frontend from > Perl to Python. It called a backend and parsed the result. Sometimes > converting one of the fields to a number would raise a ValueError > because it would contain "ERR" instead of a number, which Perl, of > course, would silently convert to 0! > > Python is all about refusing to guess, and complaining if there's an > error. :-) Perl is quite an amazing language, but it also definitely allows for sloppy habits and poor coding behaviors, particularly for someone such as me whose perl is completely self taught. I think that's why this time around with python I'm trying to learn my prior experience and seek help in areas where I suspect there is improvement to be made. I'm really liking the rigid flexibility I'm experiencing with python so far. I'm thinking it's time for me to get a python reference or two, just to kill a few trees. If anyone has any strong feelings about what belongs in a "beginner but already learning quickly" library, please toss them my way. I'll grep around the 'net for opinions on it, too. Pete From darcy at druid.net Sat Mar 6 01:55:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 6 Mar 2010 01:55:48 -0500 Subject: My four-yorkshireprogrammers contribution In-Reply-To: <7vdo8sFrelU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> <7vdo8sFrelU1@mid.individual.net> Message-ID: <20100306015548.4e510039.darcy@druid.net> On Sat, 06 Mar 2010 14:19:03 +1300 Gregory Ewing wrote: > MRAB wrote: > > By the standards of just a few years later, that's not so much a > > microcomputer as a nanocomputer! > > Although not quite as nano as another design published > in EA a couple of years earlier, the EDUC-8: Byte Magazine once published plans for building a computer that had one instruction. I believe it was a six bit address so that would make it a max of 64 bytes. If I recall, the single instruction was "SUBTRACT AND JUMP ON CARRY." Now that's nano! -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From pmaupin at gmail.com Sat Mar 6 02:21:45 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Fri, 5 Mar 2010 23:21:45 -0800 (PST) Subject: Initial RSON prototype parser in subversion References: Message-ID: I have not yet added indentation sensitivity to the parser (although the tokenizer saves the indentation information for the parser), but the initial prototype parses all of JSON plus a lot of syntax enhancements (comments, hex/binary/octal numbers, relaxed quoting requirements for strings, trailing comments allowed, triple-quoted strings, etc.) I have also started the rson-discuss group on google for further discussions on the actual syntax and initial implementation, if anyone is interested, and have posted a message there with a bit more information about the prototype status. The project page is at http://code.google.com/p/rson/ Best regards, Pat From strombrg at gmail.com Sat Mar 6 03:21:59 2010 From: strombrg at gmail.com (Dan Stromberg) Date: Sat, 6 Mar 2010 00:21:59 -0800 (PST) Subject: Fast GUI pipemeter: gprog References: <619ab895-87a9-4b40-b45e-b12299304b38@z1g2000prc.googlegroups.com> <1686070.lZ2vcFHjTE@xkzjympik> Message-ID: <44626216-1aeb-491b-9ee4-c0ed79a7ab88@b9g2000pri.googlegroups.com> On Mar 4, 4:25?pm, Dan Stromberg wrote: > Python folk: Any guesses why a simple file.read(blocksize) would have > such an affinity for returning 16K when redirected from /dev/zero? ?If > I run the program against a file on disk, it gets larger blocksizes > fine. Never mind - it was a bug in my code. Now on a slower machine, it runs about 2.5 times faster than it did on the faster machine. From wongjoekmeu at yahoo.com Sat Mar 6 04:45:46 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Sat, 6 Mar 2010 01:45:46 -0800 (PST) Subject: start function in new process References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> Message-ID: <04188082-bc7f-4b65-bfde-dc7abe5e8123@t41g2000yqt.googlegroups.com> On 5 mrt, 21:40, "Martin P. Hellwig" wrote: > On 03/05/10 20:09, wongjoek... at yahoo.com wrote: > > > > > On 5 mrt, 21:02, "Martin P. Hellwig" > > wrote: > >> On 03/05/10 19:45, wongjoek... at yahoo.com wrote: > > >>> On 5 mrt, 20:40, "Martin P. Hellwig" > >>> wrote: > >>>> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: > >>>> > >>>> Any specific reason why threading.Thread or multiprocessing is not > >>>> suitable to solve your problem? > > >>>> -- > >>>> mph > > >>> Because I got a memory leak in my function f(). It uses scipy, numpy, > >>> pylab, and I am not planning to solve the memory leak because its too > >>> complicated. So I thought of just calling the function then when it is > >>> finished the process is gone and all memory is released. With > >>> threading I don't think I would solve this problem. I am not sure > >>> though. > > >> I would be surprised if you can't do the same with > >> subprocess/multiprocessing, since you seem to know how to identify the > >> memory leak it shouldn't be a problem scripting out a test to see if it > >> works this way. I would be interested though in your findings. > > >> -- > >> mph > > > I can't use multiprocessing module since it comes only with python 2.6 > > and I am bound to python2.4. But subprocess does exist in python2.4, > > but the question now is, how do I achieve that ? Any example ? > > Sure, for example if I want to check the openssl version (didn't specify > I need to provide a useful example :-) > > I would normally do on the command line: > [martin at aspire8930 /usr/home/martin/Desktop]$ /usr/bin/openssl version > OpenSSL 0.9.8k 25 Mar 2009 > > The python subprocess equivalent is: > [martin at aspire8930 /usr/home/martin/Desktop]$ python > Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) > [GCC 4.2.1 20070719 ?[FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import subprocess as _sp > ?>>> ssl_version = _sp.Popen(['/usr/bin/openssl', 'version'], > stdout=_sp.PIPE) > ?>>> print(ssl_version.stdout.readlines()) > ['OpenSSL 0.9.8k 25 Mar 2009\n'] > ?>>> quit() > [martin at aspire8930 /usr/home/martin/Desktop]$ > > If you get any error in the Popen part, you probably did not use the > full path or an illegal parameter. > > If you get a long wait in the readlines part, this usually means that > there is either nothing written to stdout or something is still being > written (I am not sure about this part though, it has been a while). > > hth > -- > mph Yes, I saw this example also before. HOwever what I want is to call an internal function which gets a reference of another internal function as input and not calling an external program. Do you have any example on that with subprocess module ? Thanks. From isso.moh at gmail.com Sat Mar 6 05:39:09 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Sat, 6 Mar 2010 11:39:09 +0100 Subject: compiler with python Message-ID: hey, How can I construct a compiler with python just for informatiom ., I have habit to construct it with C language, sorry for my english ;-) -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From acm at muc.de Sat Mar 6 06:20:11 2010 From: acm at muc.de (Alan Mackenzie) Date: Sat, 6 Mar 2010 11:20:11 +0000 (UTC) Subject: Building Python-2.6.4 on G/L: can't build in _ssl support. Message-ID: Hi, Python! I build Python-2.6.4 on my GNU/Linux (Debian Sarge) box. I get a warning message "Failed to find the necessary bits to build these modules: .... _ssl ... RTFS to find out what!". I need _ssl for an application. So, I look at setup.py in the top directory. It seems that _ssl needs to find certain .h files, but is looking in /usr/local/ssl and /usr/contrib (or subdirectories thereof). These look like highly non-standard directories. Either something is hugely amiss, or I'm missing some vital nugget of information (possibly through not being a Python hacker). Would somebody please give me a tip to get this sorted out? Thanks! -- Alan Mackenzie (Nuremberg, Germany). From davea at ieee.org Sat Mar 6 06:37:12 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Mar 2010 06:37:12 -0500 Subject: compiler with python In-Reply-To: References: Message-ID: <4B923E68.1000104@ieee.org> mohamed issolah wrote: > hey, > > How can I construct a compiler with python just for informatiom ., I have > habit to construct it with C language, > > sorry for my english ;-) > You need to tell us what you're really trying to do, what tools you're willing to use, and probably why you want it. And if you're not sure about your English, keep the sentence structure straightforward. Let me make a couple of wild guesses: You want to design and build a compiler that takes xml information as its source code, and compiles those xml files into Intel x86 machine code. The compiler and the resulting executable needs to run on an x86 Linux machine. Your previous experience was in doing this sort of thing in C, but you want to try it with Python instead. You want to do it without using the lxml libraries. You want to build a python compiler, that takes python source code and produces Java byte code files. You'd like to do this in C, but don't want to use any of the available existing CPython or Jython source code. Your goal is not to make a commercially viable product, but to learn as much as possible in the process. DaveA From python at hope.cz Sat Mar 6 06:53:53 2010 From: python at hope.cz (Johny) Date: Sat, 6 Mar 2010 03:53:53 -0800 (PST) Subject: Import problem Message-ID: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> I have this directory structure C: \A __init__.py amodule.py \B __init__.py bmodule.py \D __init__.py dmodule.py and I want to import bmodule.py C:\>cd \ C:\>python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> from A.B import bmodule I am bmodule >>> C:\> so far so good. Now I would like to import bmodule but if the current directory is \D subdirectory. C:> cd \A\B\D C:\A\B\D> C:\A\B\D>python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append('C:\\A') >>> from A.B import bmodule Traceback (most recent call last): File "", line 1, in ImportError: No module named A.B C:\> so I can not import a module from the parent directory? Or where did I make an error? Thanks for help L. From martin.hellwig at dcuktec.org Sat Mar 6 07:28:25 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 06 Mar 2010 12:28:25 +0000 Subject: start function in new process In-Reply-To: <04188082-bc7f-4b65-bfde-dc7abe5e8123@t41g2000yqt.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> <04188082-bc7f-4b65-bfde-dc7abe5e8123@t41g2000yqt.googlegroups.com> Message-ID: On 03/06/10 09:45, wongjoekmeu at yahoo.com wrote: > > Yes, I saw this example also before. HOwever what I want is to call an > internal function which gets a reference of another internal function > as input and not calling an external program. Do you have any example > on that with subprocess module ? > Thanks. Well yes that is possible but you would more or less be just reinventing parts of the multiprocessing module, so I would use that one (at the location Robert Kern suggested). -- mph From isso.moh at gmail.com Sat Mar 6 08:07:30 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Sat, 6 Mar 2010 14:07:30 +0100 Subject: compiler with python Message-ID: hey, I want to create a compiler which transform a code like pascal code (that what I do in C) to "quad" In C, I use BISON and FLEX tools. -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From kse.listed.co1 at gmail.com Sat Mar 6 08:33:34 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Sat, 6 Mar 2010 05:33:34 -0800 (PST) Subject: "olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" " Message-ID: "olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" " From steve at REMOVE-THIS-cybersource.com.au Sat Mar 6 09:48:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Mar 2010 14:48:24 GMT Subject: Import problem References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4b926b37$0$27829$c3e8da3@news.astraweb.com> On Sat, 06 Mar 2010 03:53:53 -0800, Johny wrote: >>>> import sys >>>> sys.path.append('C:\\A') >>>> from A.B import bmodule > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named A.B The current directory is irrelevant, except that it is automatically added to the PYTHONPATH. That's why you can import A.B when the current directory is C. You are trying to import module B from package A *inside* directory C:\A, but there is no such package A inside C:\A. You need to add C to the path, and then it should work. -- Steven From bdesth.quelquechose at free.quelquepart.fr Sat Mar 6 10:04:53 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 06 Mar 2010 16:04:53 +0100 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: References: Message-ID: <4b927c8e$0$10093$426a74cc@news.free.fr> Pete Emerson a ?crit : (snip) > I'm really liking the rigid flexibility I'm experiencing with python > so far. "rigid flexibility" !-) +1 QOTW - and welcome on board BTW. From ijcsorgeditor at gmail.com Sat Mar 6 10:31:48 2010 From: ijcsorgeditor at gmail.com (editor ijcs) Date: Sat, 6 Mar 2010 07:31:48 -0800 (PST) Subject: Call for Paper The International Journal of Computer Science (IJCS) Message-ID: <50313c59-a5bf-4f12-8c6f-e0c413c68084@k18g2000prf.googlegroups.com> Call for Paper The International Journal of Computer Science (IJCS) publishes original papers on all subjects relevant to computer science, communication network, and information systems. The highest priority will be given to those contributions concerned with a discussion of the background of a practical problem, the establishment of an appropriate model, the determination of a solution, approximate or exact, analytical or numerical, and a discussion of the relevance of the results when applied to the real-life problem. Paper submissions are invited in the area of computer science, in particular the technological advances and research results in the fields of theoretical, experimental, applied electronics, computer science, communication network and Information technology. Topics of interest include but are not limited to the following: Computer Science * Parallel Processing and Distributed Computing * Foundations of High-performance Computing * Graph Theory and Analysis of Algorithms * Artificial Intelligences and Pattern/Image Recognitions * Neural Networks and Biomedical Simulations * Virtual Visions and Virtual Simulations * Data Mining, Web Image Mining and Applications * Data Base Management & Information Retrievals Adaptive Systems * Bifurcation, Biocybernetics & Bioinformatics * Blind Systems, Neural Networks &Control Systems * Cryptosystems &Data Compression * Evolutional Computation &Fuzzy Systems * Image Processing and Image Recognition, Modeling & Optimization * Speech Processing, Speech Synthesis & Speech Recognition * Video Signal Processing, Watermarking & Wavelet Transform * All topics related Computer Science Communication Network * Quantum Computing & Coding * Error Controls Agent Computing & Multi-Agents Systems * Defining Spectrum Rights and Open Spectrum Solutions * Quality of Services and Communication Protocols * Satellite and Optical Communication Systems * 3G/4G Network Evolutions & CDMA/GSM Communication Protocols * Mobile Computing, Transmission/Switching/Distribution technologies * Communication Theory & Signal Processing for Communications * Wireless Communications, Wireless & Mobile Networking * Optical Networks and Systems &Next-Generation Networking and Internet * Communication QoS &Reliability and Modeling * Ad-hoc, Sensor & Mesh Networking * Multimedia Services, Communication Software & Services * Communication and Information System Security * System control and network/service management * Network and Internet protocols and standards * Client-server, distributed & Web-based communication systems * Broadband and multimedia systems & applications * Trials of advanced systems and services * Any topics related Communication Network Information and Systems * Cryptography and Foundation of Computer Security * Authentication/Authorization Issues * IDS/Firewall, Anti-Spam mail & Anti-virus issues * Biometric authentication & algorithms * Fingerprint /Hand/Biometrics Recognitions and Technologies * IC-card Security, OTP & Key Management Issues * E-commerce, Ubiquitous & RFID Applications * Metadata, Meta Modeling, XML & Data Management * Knowledge Management, Web Security & Privacy * Cyber Threats, Web Services & Web Engineering * Web Intelligence, Protocols & Standards * Proxies and Servers * Multimedia Applications * Ontology and the Semantic Web * B2B, B2C and C2C * E-Business System Design and Development, E-Payment * Portal Strategies, Social Networks and Information Systems * Social and Legal Issues and Digital Ecology * E-Governance, E-Learning and Virtual Classrooms * E-Entertainment, E-Journalism * Any topics related Information systems Electronics * Circuits & Devices * Communication Networks & Systems * Communications & Information Processing * Digital Signal Processing & Electrical Engineering Communications * Electromagnetics & Microwaves * Instrumentation * Measurement & Testing * Nanoscience & Nanotechnology * Optics & Optoelectronic Effects * Devices, Systems &Semiconductors * Systems & Control Engineering * Telecommunications * Any topics related Electronics International Journal of Computer Science (IJCS) ISSN: 1884-9083 Website: https://sites.google.com/site/ijcsorg/ Manuscript submission to: ijcsorgeditor at gmail.com All submitted papers will be judged based on their quality by the technical committee and reviewers. Papers that describe research and experimentation are encouraged. All paper submissions will be handled electronically and detailed instructions on submission procedure are available on IJCS web pages. Researchers and authors are invited to participate in the peer-review process of IJCS papers if your research interest matches with the themes of Call for Papers. For other information, please contact IJCS Managing Editor. From jaihindharjun at gmail.com Sat Mar 6 10:40:19 2010 From: jaihindharjun at gmail.com (karan arjun) Date: Sat, 6 Mar 2010 07:40:19 -0800 (PST) Subject: intersting datt with girls.......sign in to this website Message-ID: RE U WANT RUSSIAN GIRL FRIENDS... WEBPAGE ---> http://123maza.com/hashan/ From davea at ieee.org Sat Mar 6 10:56:19 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Mar 2010 10:56:19 -0500 Subject: compiler with python In-Reply-To: References: <4B923E68.1000104@ieee.org> Message-ID: <4B927B23.2090009@ieee.org> mohamed issolah wrote: > > 2010/3/6 Dave Angel > > >> mohamed issolah wrote: >> >> >>> hey, >>> >>> How can I construct a compiler with python just for informatiom ., I have >>> habit to construct it with C language, >>> >>> sorry for my english ;-) >>> >>> >>> >> You need to tell us what you're really trying to do, what tools you're >> willing to use, and probably why you want it. And if you're not sure about >> your English, keep the sentence structure straightforward. >> >> Let me make a couple of wild guesses: >> >> > > > >> You want to design and build a compiler that takes xml information as its >> source code, and compiles those xml files into Intel x86 machine code. The >> compiler and the resulting executable needs to run on an x86 Linux machine. >> Your previous experience was in doing this sort of thing in C, but you want >> to try it with Python instead. You want to do it without using the lxml >> libraries. >> >> You want to build a python compiler, that takes python source code and >> produces Java byte code files. You'd like to do this in C, but don't want >> to use any of the available existing CPython or Jython source code. Your >> goal is not to make a commercially viable product, but to learn as much as >> possible in the process. >> >> >> DaveA >> >> > > hey, > > I want to create a compiler which transform a code like pascal code (that > what I do in C) to "quad" > In C, I use BISON and FLEX tools. > > > I've forwarded your message to the list, and fixed your top-posting by moving your response to the bottom. I don't have a clue what "quad" is, unless it's a synonym for Forth. You haven't specified the OS you'll be using to run the compiler, nor the one you're targeting, so some of these choices may not be useful. For example, the first one is Linux only. http://www.freenet.org.nz/python/pybison/ PyBison - Python binding for Bison/Flex http://freshmeat.net/projects/yeanpypa/ http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ Or you could go here, which has links to (most of) these and others. http://wiki.python.org/moin/LanguageParsing DaveA From soniyaa1111 at gmail.com Sat Mar 6 11:15:22 2010 From: soniyaa1111 at gmail.com (soniyaa 1111) Date: Sat, 6 Mar 2010 08:15:22 -0800 (PST) Subject: Shop online without credit card Message-ID: Shop online without credit card. It?s only @ http://www.shoppingreps.com?SourceId=1259 Membership is absolutely free. Join and enjoy your shopping. For more details visit http://www.shoppingreps.com?SourceId=1259 From as at sci.fi Sat Mar 6 11:24:24 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 06 Mar 2010 18:24:24 +0200 Subject: Building Python-2.6.4 on G/L: can't build in _ssl support. References: Message-ID: Alan Mackenzie writes: > Hi, Python! > > I build Python-2.6.4 on my GNU/Linux (Debian Sarge) box. I get a warning > message "Failed to find the necessary bits to build these modules: .... > _ssl ... RTFS to find out what!". At a guess, you're missing libssl-dev. You might consider installing python2.6 or python2.6-minimal from unstable or testing too. > I need _ssl for an application. So, I look at setup.py in the top > directory. It seems that _ssl needs to find certain .h files, but is > looking in /usr/local/ssl and /usr/contrib (or subdirectories thereof). > These look like highly non-standard directories. Looks to me like it looks in those non-standard directories, but in addition to normal /usr/include. From peloko45 at gmail.com Sat Mar 6 13:33:17 2010 From: peloko45 at gmail.com (Joan Miller) Date: Sat, 6 Mar 2010 10:33:17 -0800 (PST) Subject: Escape curly bracket together to a variable extension Message-ID: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> How to escape the first '}' in the next string? s = "}\n{0}".format('foo') From alfps at start.no Sat Mar 6 13:38:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Mar 2010 19:38:23 +0100 Subject: Escape curly bracket together to a variable extension In-Reply-To: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> References: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> Message-ID: * Joan Miller: > How to escape the first '}' in the next string? > > s = "}\n{0}".format('foo') s = "}}\n{0}".format('foo') Cheers & hth., - Alf From gherron at islandtraining.com Sat Mar 6 13:41:44 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 06 Mar 2010 10:41:44 -0800 Subject: Escape curly bracket together to a variable extension In-Reply-To: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> References: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> Message-ID: <4B92A1E8.8020407@islandtraining.com> Joan Miller wrote: > How to escape the first '}' in the next string? > > s = "}\n{0}".format('foo') > >>> "}}\n{0}".format('foo') '}\nfoo' Gary Herron From helps4indian at gmail.com Sat Mar 6 15:47:39 2010 From: helps4indian at gmail.com (coolboy8) Date: Sat, 6 Mar 2010 12:47:39 -0800 (PST) Subject: Cash for structured settlement Message-ID: <9a25f256-c9fd-41a2-a0b2-933c42c95d8c@p3g2000pra.googlegroups.com> Visit Here http://alturl.com/vz8b From howe.steven at gmail.com Sat Mar 6 16:13:19 2010 From: howe.steven at gmail.com (Steven Howe) Date: Sat, 06 Mar 2010 13:13:19 -0800 Subject: compiler with python In-Reply-To: <4B927B23.2090009@ieee.org> References: <4B923E68.1000104@ieee.org> <4B927B23.2090009@ieee.org> Message-ID: <4B92C56F.60407@gmail.com> Is it possible he's talking about a 'quad core'? as in a CPU? In that case I think he wants to optimize a python program for a multiprocessor core with four processors. sph On 03/06/2010 07:56 AM, Dave Angel wrote: > mohamed issolah wrote: >> >> 2010/3/6 Dave Angel >> >>> mohamed issolah wrote: >>> >>>> hey, >>>> >>>> How can I construct a compiler with python just for informatiom ., >>>> I have >>>> habit to construct it with C language, >>>> >>>> sorry for my english ;-) >>>> >>>> >>> You need to tell us what you're really trying to do, what tools you're >>> willing to use, and probably why you want it. And if you're not >>> sure about >>> your English, keep the sentence structure straightforward. >>> >>> Let me make a couple of wild guesses: >>> >> >> >>> You want to design and build a compiler that takes xml information >>> as its >>> source code, and compiles those xml files into Intel x86 machine >>> code. The >>> compiler and the resulting executable needs to run on an x86 Linux >>> machine. >>> Your previous experience was in doing this sort of thing in C, but >>> you want >>> to try it with Python instead. You want to do it without using the >>> lxml >>> libraries. >>> >>> You want to build a python compiler, that takes python source code and >>> produces Java byte code files. You'd like to do this in C, but >>> don't want >>> to use any of the available existing CPython or Jython source code. >>> Your >>> goal is not to make a commercially viable product, but to learn as >>> much as >>> possible in the process. >>> >>> >>> DaveA >>> >> >> hey, >> >> I want to create a compiler which transform a code like pascal code >> (that >> what I do in C) to "quad" >> In C, I use BISON and FLEX tools. >> >> > I've forwarded your message to the list, and fixed your top-posting by > moving your response to the bottom. I don't have a clue what "quad" > is, unless it's a synonym for Forth. > > You haven't specified the OS you'll be using to run the compiler, nor > the one you're targeting, so some of these choices may not be useful. > For example, the first one is Linux only. > > http://www.freenet.org.nz/python/pybison/ > PyBison - Python binding for Bison/Flex > > http://freshmeat.net/projects/yeanpypa/ > http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html > > http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ > > Or you could go here, which has links to (most of) these and others. > http://wiki.python.org/moin/LanguageParsing > > DaveA From alfps at start.no Sat Mar 6 16:29:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Mar 2010 22:29:04 +0100 Subject: compiler with python In-Reply-To: References: <4B923E68.1000104@ieee.org> <4B927B23.2090009@ieee.org> Message-ID: Since Mohamed is talking about compilation I think it's more likely he's talking about an intermediate program represention based on quad tuples like (OP, DESTINATION, ARG1, ARG2) Cheers, - Alf * Steven Howe: > Is it possible he's talking about a 'quad core'? as in a CPU? In that > case I think he wants > to optimize a python program for a multiprocessor core with four > processors. > > sph > > > On 03/06/2010 07:56 AM, Dave Angel wrote: >> mohamed issolah wrote: >>> >>> 2010/3/6 Dave Angel >>> >>>> mohamed issolah wrote: >>>> >>>>> hey, >>>>> >>>>> How can I construct a compiler with python just for informatiom ., >>>>> I have >>>>> habit to construct it with C language, >>>>> >>>>> sorry for my english ;-) >>>>> >>>>> >>>> You need to tell us what you're really trying to do, what tools you're >>>> willing to use, and probably why you want it. And if you're not >>>> sure about >>>> your English, keep the sentence structure straightforward. >>>> >>>> Let me make a couple of wild guesses: >>>> >>> >>> >>>> You want to design and build a compiler that takes xml information >>>> as its >>>> source code, and compiles those xml files into Intel x86 machine >>>> code. The >>>> compiler and the resulting executable needs to run on an x86 Linux >>>> machine. >>>> Your previous experience was in doing this sort of thing in C, but >>>> you want >>>> to try it with Python instead. You want to do it without using the >>>> lxml >>>> libraries. >>>> >>>> You want to build a python compiler, that takes python source code and >>>> produces Java byte code files. You'd like to do this in C, but >>>> don't want >>>> to use any of the available existing CPython or Jython source code. >>>> Your >>>> goal is not to make a commercially viable product, but to learn as >>>> much as >>>> possible in the process. >>>> >>>> >>>> DaveA >>>> >>> >>> hey, >>> >>> I want to create a compiler which transform a code like pascal code >>> (that >>> what I do in C) to "quad" >>> In C, I use BISON and FLEX tools. >>> >>> >> I've forwarded your message to the list, and fixed your top-posting by >> moving your response to the bottom. I don't have a clue what "quad" >> is, unless it's a synonym for Forth. >> >> You haven't specified the OS you'll be using to run the compiler, nor >> the one you're targeting, so some of these choices may not be useful. >> For example, the first one is Linux only. >> >> http://www.freenet.org.nz/python/pybison/ >> PyBison - Python binding for Bison/Flex >> >> http://freshmeat.net/projects/yeanpypa/ >> http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html >> >> http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ >> >> Or you could go here, which has links to (most of) these and others. >> http://wiki.python.org/moin/LanguageParsing >> >> DaveA From isso.moh at gmail.com Sat Mar 6 17:00:44 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Sat, 6 Mar 2010 23:00:44 +0100 Subject: compiler with python Message-ID: hey, yes quad = quad tuple like ("+",x1,x2,temp) I work in linux example : my parser with flex : -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: token.l Type: application/octet-stream Size: 1196 bytes Desc: not available URL: From benjamin at python.org Sat Mar 6 17:13:46 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Mar 2010 16:13:46 -0600 Subject: [RELEASED] Python 3.1.2 release candidate Message-ID: <1afaf6161003061413k646e972eta515d9322793e208@mail.gmail.com> On behalf of the Python development team, I'm pleased to announce a release candidate for the second bugfix release of the Python 3.1 series, Python 3.1.2. This bug fix release fixes numerous issues found in 3.1.1. This release candidate has been released to solicit testing and feedback over an possible regressions from 3.1.1. Please consider testing it with your library or application and reporting an bugs you encounter. This will help make the final 3.1.2 release, planned in 2 weeks time, all the more stable. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.2rc1 visit: http://www.python.org/download/releases/3.1.2/ A list of changes in 3.1.2rc1 can be found here: http://svn.python.org/projects/python/tags/r312rc1/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.2's contributors) From vinay_sajip at yahoo.co.uk Sat Mar 6 17:38:57 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 6 Mar 2010 14:38:57 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> On Mar 5, 9:29?pm, Pete Emerson wrote: > > I have written my first module called "logger" that logs to syslog via > the syslog module but also allows forloggingto STDOUT in debug mode > at multiple levels (to increase verbosity depending on one's need), or > both. I've looked at theloggingmodule and while it might suit my > needs, it's overkill for me right now (I'm still *very* much a python > newbie). > Overkill in what sense? You just need to write a few lines of code to be able to use the logging package which comes with Python: import logging, logging.handlers, sys logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) logging.getLogger().addHandler(logging.handlers.SysLogHandler()) # default logs to syslog at (localhost, 514) with facility LOG_USER # you can change the default to use e.g. Unix domain sockets and a different facility So you're experienced enough and have time enough to write your own logger module, but too much of a newbie to use a module which is part of Python's included batteries? If you're writing something like logging to learn about it and what the issues are, that's fair enough. But I can't see what you mean by overkill, exactly. The three lines above (or thereabouts) will, I believe, let you log to syslog and to stdout...which is what you say you want to do. > I want to write other modules, and my thinking is that it makes sense > for those modules to use the "logger" module to do thelogging, if and > only if the parent using the other modules is also using the logger > module. > > In other words, I don't want to force someone to use the "logger" > module just so they can use my other modules, even if the "logger" > module is installed ... but I also want to take advantage of it if I'm > using it. > > Now that I've written that, I'm not sure that makes a whole lot of > sense. It seems like I could say, "hey, this person has the 'logger' > module available, let's use it!". > > Thoughts? Well, the logging package is available in Python and ready for use and pretty much battle tested, so why not use that? Are you planning to use third-party libraries in your Python work, or write everything yourself? If you are planning to use third party libraries, how would their logging be hooked into your logger module? And if not, is it good to have two logging systems in parallel? Of course as the maintainer of Python's logging package, you'd expect me to be biased in favour of it. You maybe shouldn't let that sway you ;-) Regards, Vinay Sajip From benjamin at python.org Sat Mar 6 17:41:33 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Mar 2010 16:41:33 -0600 Subject: [RELEASED] Python 2.7 alpha 4 Message-ID: <1afaf6161003061441j5621bbe7jdb8ba4c22f81f46e@mail.gmail.com> On behalf of the Python development team, I'm overjoyed to announce the fourth alpha release of Python 2.7. Python 2.7 is scheduled (by Guido and Python-dev) to be the last major version in the 2.x series. Though more major releases have not been absolutely ruled out, it's likely that the 2.7 release will an extended period of maintenance for the 2.x series. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7 visit: http://www.python.org/download/releases/2.7/ Please note that this is a development release, intended as a preview of new features for the community, and is thus not suitable for production use. The 2.7 documentation can be found at: http://docs.python.org/2.7 Please consider trying Python 2.7 with your code and reporting any bugs you may notice to: http://bugs.python.org Enjoy! -- Benjamin Peterson 2.7 Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From rantingrick at gmail.com Sat Mar 6 17:46:29 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 6 Mar 2010 14:46:29 -0800 (PST) Subject: Sample code usable Tkinter listbox References: Message-ID: <95cc4ed4-20fa-4198-a354-d6734083c2d7@g11g2000yqe.googlegroups.com> Opps: found a few errors in that last ScrolledListbox class, try this one... import Tkinter as tk from Tkconstants import * class ScrolledList(tk.Listbox): def __init__(self, master, **kw): self.frame = tk.Frame(master) self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) self.hbar = tk.Scrollbar(self.frame, orient=HORIZONTAL) self.block = tk.Frame(self.frame, width=18, height=18) self.block.grid(row=1, column=1) self.vbar = tk.Scrollbar(self.frame, orient=VERTICAL) kw.setdefault('activestyle', 'none') kw.setdefault('highlightthickness', 0) kw.setdefault('pack', 0) if kw.pop('pack') == 1: self.frame.pack(fill=BOTH, expand=1) tk.Listbox.__init__(self, self.frame, **kw) self.grid(row=0, column=0, sticky=N+S+E+W) self.hbar.configure(command=self.xview) self.vbar.configure(command=self.yview) self.config( yscrollcommand=self.vbar.set, xscrollcommand=self.hbar.set ) self.hbar.grid(row=1, column=0, sticky=W+E) self.vbar.grid(row=0, column=1, sticky=N+S) self.pack = lambda **kw: self.frame.pack(**kw) self.grid = lambda **kw: self.frame.grid(**kw) self.place = lambda **kw: self.frame.place(**kw) self.pack_config = lambda **kw: self.frame.pack_config(**kw) self.grid_config = lambda **kw: self.frame.grid_config(**kw) self.place_config = lambda **kw: self.frame.place_config(**kw) self.pack_configure = lambda **kw: self.frame.pack_config(**kw) self.grid_configure = lambda **kw: self.frame.grid_config(**kw) self.place_configure = lambda **kw: self.frame.place_config(**kw) def gets(self): return self.get(0, END) def sets(self, arg): self.delete(0, END) try: arg = arg.strip('\n').splitlines() except AttributeError: pass if hasattr(arg, '__getitem__'): for item in arg: self.insert(END, str(item)) else: raise TypeError("Scrolledlist.sets() requires a string or iterable of strings") if __name__ == '__main__': root = tk.Tk() listbox = ScrolledList(root, width=50, height=10, pack=1) #listbox.sets(1.25) #listbox.sets('1\n2\n3\n4\n5\n\n\n') listbox.sets(range(100)) #listbox.grid(row=0, column=0) root.mainloop() From pemerson at gmail.com Sat Mar 6 18:13:33 2010 From: pemerson at gmail.com (Pete Emerson) Date: Sat, 6 Mar 2010 15:13:33 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> Message-ID: <9c6a8d26-b71e-4cb8-92d0-49af8728bec4@u15g2000prd.googlegroups.com> On Mar 6, 2:38?pm, Vinay Sajip wrote: > On Mar 5, 9:29?pm, Pete Emerson wrote: > > > > > I have written my first module called "logger" that logs to syslog via > > the syslog module but also allows forloggingto STDOUT in debug mode > > at multiple levels (to increase verbosity depending on one's need), or > > both. I've looked at theloggingmodule and while it might suit my > > needs, it's overkill for me right now (I'm still *very* much a python > > newbie). > > Overkill in what sense? You just need to write a few lines of code to > be able to use the logging package which comes with Python: > > import logging, logging.handlers, sys > logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) > logging.getLogger().addHandler(logging.handlers.SysLogHandler()) > # default logs to syslog at (localhost, 514) with facility LOG_USER > # you can change the default to use e.g. Unix domain sockets and a > different facility > > So you're experienced enough and have time enough to write your own > logger module, but too much of a newbie to use a module which is part > of Python's included batteries? If you're writing something like > logging to learn about it and what the issues are, that's fair enough. > But I can't see what you mean by overkill, exactly. The three lines > above (or thereabouts) will, I believe, let you log to syslog and to > stdout...which is what you say you want to do. > > > I want to write other modules, and my thinking is that it makes sense > > for those modules to use the "logger" module to do thelogging, if and > > only if the parent using the other modules is also using the logger > > module. > > > In other words, I don't want to force someone to use the "logger" > > module just so they can use my other modules, even if the "logger" > > module is installed ... but I also want to take advantage of it if I'm > > using it. > > > Now that I've written that, I'm not sure that makes a whole lot of > > sense. It seems like I could say, "hey, this person has the 'logger' > > module available, let's use it!". > > > Thoughts? > > Well, the logging package is available in Python and ready for use and > pretty much battle tested, so why not use that? Are you planning to > use third-party libraries in your Python work, or write everything > yourself? If you are planning to use third party libraries, how would > their logging be hooked into your logger module? And if not, is it > good to have two logging systems in parallel? > > Of course as the maintainer of Python's logging package, you'd expect > me to be biased in favour of it. You maybe shouldn't let that sway > you ;-) > > Regards, > > Vinay Sajip Thanks for your insights, Vinay, and thank you also for writing packages such as logging. The word 'overkill' was a poor choice on my part! I should have said, "I don't quite understand the logging module yet, but I am comfortable with the syslog module's two functions, openlog and syslog". I wrote my own logger module *partly* to gain the experience, and partly to do the following: 1) In debug mode, send what would have gone to syslog to STDOUT or STDERR 2) In non-debug mode, use /dev/log or localhost:514 depending on what is set 3) Allow for multiple levels of logging beyond INFO, WARNING, CRIT ... essentially allow multiple levels of INFO depending on how much detail is desired. A high level of messaging when programs are running poorly is desired, but when programs are running smoothly, I don't need to send as much to syslog. I started in with your logging package, but I think I simply got ahead of myself. I definitely agree that writing my own wrappers around syslog to do what I want might be a duplication of effort. At this point I think I'm ready to go back to your logging package and see what I can do; if you have words of advice regarding 1-3 above, I'd certainly appreciate it. Now I'll go to your example above and see what it does. Thank you! Pete From igouy2 at yahoo.com Sat Mar 6 18:53:25 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 15:53:25 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? Message-ID: At the command prompt: python b.py 8 works fine on both XP and Vista python b.python 8 works on XP (and Linux) but on Vista python b.python 8 ImportError: No module named b ? From news123 at free.fr Sat Mar 6 18:53:39 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 00:53:39 +0100 Subject: async notification handling w/o threads/polling (similiar to kill -hup)? Message-ID: <4b92eb03$0$22022$426a74cc@news.free.fr> Hi, I'd like to notify python processes asynchronously. at notification time a callback should be called The solution should be working on linux and Windows. I could add a wrapper to switch between a windows / linux implementation though If possible I'd like to avoid - having to poll for an external event - having to add a thread. - changing my existing code I thought about using signal and os.kill() However windows does not to have SIGHUP , SIGUSR1 or SIGUSR2. So I'm not sure, which signal I could use with windows. Apart from that there's one minor problem with signals which might speak against using signal All blocking io calls might be interrupted, which is not desirable in my case. Do you have any suggestions for Linux / WIndows or both? #### example code with signals ################# #### a blocking io call here reading a named pipe #### would be interrupted import signal a = 0 def handler(signum,frame): global a a += 1 signal.signal(signal.SIGUSR1,handler) print "hi" p = open("namedpipe") while True: v = p.read(2) print "V:",a,len(v) if len(v) != 2: break print "var a changed, but read() was interrupted :-(" bye N From clp2 at rebertia.com Sat Mar 6 19:02:43 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Mar 2010 16:02:43 -0800 Subject: python b.python 8 works on XP but not on Vista? In-Reply-To: References: Message-ID: <50697b2c1003061602y31e26526q878f0c5a9e5573c5@mail.gmail.com> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > At the command prompt: > > ? python b.py 8 > works fine on both XP and Vista > > ? python b.python 8 > works on XP (and Linux) > > but on Vista > > ? python b.python 8 > > ImportError: No module named b > > ? Code please. Also, .python is not a standard extension for Python files, so why are you using it anyway? Cheers, Chris -- http://blog.rebertia.com From news123 at free.fr Sat Mar 6 19:17:25 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 01:17:25 +0100 Subject: async notification handling w/o threads/polling (similiar to kill -hup)? In-Reply-To: <4b92eb03$0$22022$426a74cc@news.free.fr> References: <4b92eb03$0$22022$426a74cc@news.free.fr> Message-ID: <4b92f095$0$20648$426a74cc@news.free.fr> News123 wrote: > Hi, > > I'd like to notify python processes asynchronously. > at notification time a callback should be called > > The solution should be working on linux and Windows. > > I could add a wrapper to switch between a windows / linux implementation > though > > If possible I'd like to avoid > - having to poll for an external event > - having to add a thread. Well having a blocking thread would be fine though. what I'd really want to avoid is any polling. > - changing my existing code > > I thought about using signal and os.kill() > However windows does not to have SIGHUP , SIGUSR1 or SIGUSR2. > So I'm not sure, which signal I could use with windows. > > > Apart from that there's one minor problem with signals > which might speak against using signal > All blocking io calls might be interrupted, which is not desirable in my > case. > > Do you have any suggestions for > Linux / WIndows or both? > > > #### example code with signals ################# > #### a blocking io call here reading a named pipe > #### would be interrupted > import signal > a = 0 > def handler(signum,frame): > global a > a += 1 > > signal.signal(signal.SIGUSR1,handler) > print "hi" > p = open("namedpipe") > while True: > v = p.read(2) > print "V:",a,len(v) > if len(v) != 2: break > > print "var a changed, but read() was interrupted :-(" > > > bye > > > N From igouy2 at yahoo.com Sat Mar 6 19:42:42 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 16:42:42 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? References: Message-ID: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> On Mar 6, 4:02?pm, Chris Rebert wrote: > On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > > At the command prompt: > > > ? python b.py 8 > > works fine on both XP and Vista > > > ? python b.python 8 > > works on XP (and Linux) > > > but on Vista > > > ? python b.python 8 > > > ImportError: No module named b > > > ? > > Code please. It's the same code in both cases, I simply renamed "b.python" as "b.py" as a test. > Also, .python is not a standard extension for Python > files, so why are you using it anyway? Because it's useful for what I'm doing. Given python 2.6.4 has no problem with a non-standard extension on MS XP and Linux - why does python 2.6.4 have this problem with a non- standard extension on MS Vista? From timr at probo.com Sat Mar 6 19:49:33 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Mar 2010 16:49:33 -0800 Subject: indentation error References: Message-ID: asit wrote: > >According to me, indentation is ok. but the python interpreter gives >an indentation error > >[asit ~/py] $ python search.py > File "search.py", line 7 > findResults = string.split(commandOutput, "\n") > ^ >IndentationError: unindent does not match any outer indentation level The most likely cause is mixing spaces with tabs. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clp2 at rebertia.com Sat Mar 6 19:53:30 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Mar 2010 16:53:30 -0800 Subject: python b.python 8 works on XP but not on Vista? In-Reply-To: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> Message-ID: <50697b2c1003061653g14a3584if8358500149a2715@mail.gmail.com> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: > On Mar 6, 4:02?pm, Chris Rebert wrote: >> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: >> > At the command prompt: >> >> > ? python b.py 8 >> > works fine on both XP and Vista >> >> > ? python b.python 8 >> > works on XP (and Linux) >> >> > but on Vista >> >> > ? python b.python 8 >> >> > ImportError: No module named b >> >> > ? >> >> Code please. > > > It's the same code in both cases, I simply renamed "b.python" as > "b.py" as a test. The code in b.py matters. I /suspect/ it's importing itself somehow (probably indirectly), and Python doesn't look for ".python" files when importing, so it fails with an ImportError. But since you haven't shown the code, I can only guess. For that matter, the full exception Traceback would be more helpful than the code; please include it as well. Cheers, Chris -- http://blog.rebertia.com From igouy2 at yahoo.com Sat Mar 6 20:23:37 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 17:23:37 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> Message-ID: <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> On Mar 6, 4:53?pm, Chris Rebert wrote: > On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: > > On Mar 6, 4:02?pm, Chris Rebert wrote: > >> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > >> > At the command prompt: > > >> > ? python b.py 8 > >> > works fine on both XP and Vista > > >> > ? python b.python 8 > >> > works on XP (and Linux) > > >> > but on Vista > > >> > ? python b.python 8 > > >> > ImportError: No module named b > > >> > ? > > >> Code please. > > > It's the same code in both cases, I simply renamed "b.python" as > > "b.py" as a test. > > The code in b.py matters. I /suspect/ it's importing itself somehow > (probably indirectly), and Python doesn't look for ".python" files > when importing, so it fails with an ImportError. But since you haven't > shown the code, I can only guess. Yes the code in b.py matters. Why it matters is that there was another difference between XP and Vista - the XP machine was single core but the Vista machine was multi core - and the code behaves differently in each case. Thanks. From ssteinerx at gmail.com Sat Mar 6 21:10:02 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 6 Mar 2010 21:10:02 -0500 Subject: python b.python 8 works on XP but not on Vista? In-Reply-To: <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> Message-ID: On Mar 6, 2010, at 8:23 PM, Isaac Gouy wrote: > On Mar 6, 4:53 pm, Chris Rebert wrote: >> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: >>> On Mar 6, 4:02 pm, Chris Rebert wrote: >>>> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: >>>>> At the command prompt: >> >>>>> python b.py 8 >>>>> works fine on both XP and Vista >> >>>>> python b.python 8 >>>>> works on XP (and Linux) >> >>>>> but on Vista >> >>>>> python b.python 8 >> >>>>> ImportError: No module named b >> >>>>> ? >> >>>> Code please. >> >>> It's the same code in both cases, I simply renamed "b.python" as >>> "b.py" as a test. >> >> The code in b.py matters. I /suspect/ it's importing itself somehow >> (probably indirectly), and Python doesn't look for ".python" files >> when importing, so it fails with an ImportError. But since you haven't >> shown the code, I can only guess. > > Yes the code in b.py matters. > > Why it matters is that there was another difference between XP and > Vista - the XP machine was single core but the Vista machine was multi > core - and the code behaves differently in each case. Yes, and the XP machine's case was blue, therefore case color is important, too. S From steve at REMOVE-THIS-cybersource.com.au Sat Mar 6 21:50:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 02:50:02 GMT Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> Message-ID: <4b93145a$0$8816$c3e8da3@news.astraweb.com> On Sat, 06 Mar 2010 21:10:02 -0500, ssteinerX at gmail.com wrote: > On Mar 6, 2010, at 8:23 PM, Isaac Gouy wrote: > >> On Mar 6, 4:53 pm, Chris Rebert wrote: >>> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: >>>> On Mar 6, 4:02 pm, Chris Rebert wrote: >>>>> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: >>>>>> At the command prompt: >>> >>>>>> python b.py 8 >>>>>> works fine on both XP and Vista >>> >>>>>> python b.python 8 >>>>>> works on XP (and Linux) >>> >>>>>> but on Vista >>> >>>>>> python b.python 8 >>> >>>>>> ImportError: No module named b >>> >>>>>> ? >>> >>>>> Code please. >>> >>>> It's the same code in both cases, I simply renamed "b.python" as >>>> "b.py" as a test. >>> >>> The code in b.py matters. I /suspect/ it's importing itself somehow >>> (probably indirectly), and Python doesn't look for ".python" files >>> when importing, so it fails with an ImportError. But since you haven't >>> shown the code, I can only guess. >> >> Yes the code in b.py matters. >> >> Why it matters is that there was another difference between XP and >> Vista - the XP machine was single core but the Vista machine was multi >> core - and the code behaves differently in each case. > > Yes, and the XP machine's case was blue, therefore case color is > important, too. Don't forget that the XP machine was on the left hand side of the desk, and the Vista machine on the right. I suspect Isaac needs to physically move the Vista machine to the left side, and it will work perfectly. Either that, or stop pissing around and show us the actual stack trace so we can actually help. Isaac, stop *guessing* what the problem is. If you have to guess, try to make your guesses realistic. It's not likely anything to do with the CPU. If anything, Python's search path is different on your Vista and XP machines. -- Steven From igouy2 at yahoo.com Sat Mar 6 22:04:56 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 19:04:56 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> <4b93145a$0$8816$c3e8da3@news.astraweb.com> Message-ID: On Mar 6, 6:50?pm, Steven D'Aprano wrote: > On Sat, 06 Mar 2010 21:10:02 -0500, sstein... at gmail.com wrote: > > On Mar 6, 2010, at 8:23 PM, Isaac Gouy wrote: > > >> On Mar 6, 4:53 pm, Chris Rebert wrote: > >>> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: > >>>> On Mar 6, 4:02 pm, Chris Rebert wrote: > >>>>> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > >>>>>> At the command prompt: > > >>>>>> ? python b.py 8 > >>>>>> works fine on both XP and Vista > > >>>>>> ? python b.python 8 > >>>>>> works on XP (and Linux) > > >>>>>> but on Vista > > >>>>>> ? python b.python 8 > > >>>>>> ImportError: No module named b > > >>>>>> ? > > >>>>> Code please. > > >>>> It's the same code in both cases, I simply renamed "b.python" as > >>>> "b.py" as a test. > > >>> The code in b.py matters. I /suspect/ it's importing itself somehow > >>> (probably indirectly), and Python doesn't look for ".python" files > >>> when importing, so it fails with an ImportError. But since you haven't > >>> shown the code, I can only guess. > > >> Yes the code in b.py matters. > > >> Why it matters is that there was another difference between XP and > >> Vista - the XP machine was single core but the Vista machine was multi > >> core - and the code behaves differently in each case. > > > Yes, and the XP machine's case was blue, therefore case color is > > important, too. > > Don't forget that the XP machine was on the left hand side of the desk, > and the Vista machine on the right. I suspect Isaac needs to physically > move the Vista machine to the left side, and it will work perfectly. > > Either that, or stop pissing around and show us the actual stack trace so > we can actually help. Isaac, stop *guessing* what the problem is. > > If you have to guess, try to make your guesses realistic. It's not likely > anything to do with the CPU. If anything, Python's search path is > different on your Vista and XP machines. > > -- > Steven That was "Thanks." as in problem solved. When the code switches on multiprocessing.cpu_count() - single core vs multicore matters. From sumerc at gmail.com Sat Mar 6 22:51:38 2010 From: sumerc at gmail.com (k3xji) Date: Sat, 6 Mar 2010 19:51:38 -0800 (PST) Subject: yappi v0.42 released Message-ID: <4795dfc3-e852-4466-bfe6-c39ef4a900ce@q15g2000yqj.googlegroups.com> Hi all, yappi(yet another python profiler with multithreading support) released. See: http://code.google.com/p/yappi/ Thanks, From steve at REMOVE-THIS-cybersource.com.au Sat Mar 6 23:23:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 04:23:13 GMT Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> <4b93145a$0$8816$c3e8da3@news.astraweb.com> Message-ID: <4b932a30$0$8816$c3e8da3@news.astraweb.com> On Sat, 06 Mar 2010 19:04:56 -0800, Isaac Gouy wrote: > That was "Thanks." as in problem solved. > > When the code switches on multiprocessing.cpu_count() - single core vs > multicore matters. I'm glad you solved your problem. Out of curiosity, what was the fault? Not the condition that leads to the fault, but the actual fault? My guess is that it was a difference in sys.path, leading to the b module not being found. Am I close? -- Steven From ping.nsr.yeh at gmail.com Sun Mar 7 01:53:40 2010 From: ping.nsr.yeh at gmail.com (Ping) Date: Sat, 6 Mar 2010 22:53:40 -0800 (PST) Subject: Asynchronous HTTP client Message-ID: Hi, I'm trying to find a way to create an asynchronous HTTP client so I can get responses from web servers in a way like async_http_open('http://example.com/', callback_func) # immediately continues, and callback_func is called with response as arg when it is ready It seems twisted can do it, but I hesitate to bring in such a big package as a dependency because my client should be light. Asyncore and asynchat are lighter but they don't speak HTTP. The asynchttp project on sourceforge is a fusion between asynchat and httplib, but it hasn't been updated since 2001 and is seriously out of sync with httplib. I'd appreciate it if anyone can shed some lights on this. Thanks, Ping From breamoreboy at yahoo.co.uk Sun Mar 7 04:33:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Mar 2010 09:33:22 +0000 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> References: <20100306031003.1018aab2@geekmail.INVALID> <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> Message-ID: Pete Emerson wrote: > On Mar 5, 6:10 pm, Andreas Waldenburger > wrote: >> On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson >> >> >> >> >> >> wrote: >>> [snip] >>>>>> data['one'] = {} >>>>>> data['one']['two'] = 'three' >>>>>> print data >>> {'one': {'two': 'three'}} >>> And through some research, I discovered collections.defaultdict (new >>> in Python 2.5, FWIW): >>>>>> import collections >>>>>> data = collections.defaultdict(dict) >>>>>> data['one']['two'] = 'three' >>>>>> print data >>> defaultdict(, {'one': {'two': 'three'}}) >>> [snip] >>> Your thoughts and comments are very much appreciated. I think my brain >>> already knows some of the answers, but my heart ... well, perl and I >>> go way back. Loving python so far, though. >> Oh, by the way: That defaultdict route is a pretty solid solution. Not >> sure what problem you're trying to solve -- depending on your usecase, >> there might be a better approach. >> >> If you're just asking hypothetically and you're trying to apply a >> Perl idiom to Python, there probably *is* a better solution. >> >> /W >> >> -- >> INVALID? DE! > > I found out about the need to declare the higher level as I was > reading in a JSON struct into a dict and then adding a new entry at a > lower level. Mostly just proof of concept stuff as I'm learning > python. I'm not sure that the use of defaultdict is really warranted > for me anywhere just yet. Mostly, I don't want to convert my perl to > python, that seems very counterproductive. Thank you very much for > your insight. > > I was a little frightened of doing "import this" ("Hey, kid, run rm - > rf / and see what happens!"), but did, and the words are wise. :) > > Pete After reading the words of wisdom try "import this" a second time and watch what happens, it's quite interesting if you're not expecting the output. Mark Lawrence. From contact at xavierho.com Sun Mar 7 04:59:00 2010 From: contact at xavierho.com (Xavier Ho) Date: Sun, 7 Mar 2010 19:59:00 +1000 Subject: Curiosity stirkes me on 'import this'. Message-ID: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> I took a look at the 'this' module to see where the file is stored. This is probably old news to some people, but was new to me. print this.s Gur Mra bs Clguba, ol Gvz Crgref Ornhgvshy vf orggre guna htyl. Rkcyvpvg vf orggre guna vzcyvpvg. Fvzcyr vf orggre guna pbzcyrk. Pbzcyrk vf orggre guna pbzcyvpngrq. Syng vf orggre guna arfgrq. Fcnefr vf orggre guna qrafr. Ernqnovyvgl pbhagf. Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf. Nygubhtu cenpgvpnyvgl orngf chevgl. Reebef fubhyq arire cnff fvyragyl. Hayrff rkcyvpvgyl fvyraprq. Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff. Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg. Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu. Abj vf orggre guna arire. Nygubhtu arire vf bsgra orggre guna *evtug* abj. Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn. Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn. Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr! And some other attributes in 'this' module as well, that decodes the string. I'm curious. Was this encoded purely for fun? *grins* Cheers, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: contact at xavierho.com Website: http://xavierho.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From peloko45 at gmail.com Sun Mar 7 05:32:28 2010 From: peloko45 at gmail.com (Joan Miller) Date: Sun, 7 Mar 2010 02:32:28 -0800 (PST) Subject: Problem with regular expression Message-ID: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> I would to convert the first string to upper case. But this regular expression is not matching the first string between quotes. re.sub("'(?P\w+)': [^{]", "\gFOO", str) # string to non-matching 'foo': { # strings to matching 'bar': 'bar2' 'bar': None 'bar': 0 'bar': True So, i.e., from the first string I would to get: 'BAR': 'bar2' Any help? please Thanks in advance From steve at holdenweb.com Sun Mar 7 07:34:41 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Mar 2010 07:34:41 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> Message-ID: Vinay Sajip wrote: [...] > Well, the logging package is available in Python and ready for use and > pretty much battle tested, so why not use that? Are you planning to > use third-party libraries in your Python work, or write everything > yourself? If you are planning to use third party libraries, how would > their logging be hooked into your logger module? And if not, is it > good to have two logging systems in parallel? > > Of course as the maintainer of Python's logging package, you'd expect > me to be biased in favour of it. You maybe shouldn't let that sway > you ;-) > Vinay: My own impression of the logging module, formed from trying to use its documentation in the past, is that it's somewhat unapproachable, and difficult to use for simple purposes. I am happy to say that now I see the current (3.1) documentation it has improved to the point where I would be happy to try using it again. Thanks for your long-term maintenance of this package. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From news123 at free.fr Sun Mar 7 07:52:13 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 13:52:13 +0100 Subject: Problem with regular expression In-Reply-To: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: <4b93a17d$0$22009$426a74cc@news.free.fr> Hi Joan, Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > > re.sub("'(?P\w+)': [^{]", "\gFOO", str) > > # string to non-matching > 'foo': { > > # strings to matching > 'bar': 'bar2' > 'bar': None > 'bar': 0 > 'bar': True > > So, i.e., from the first string I would to get: > 'BAR': 'bar2' > I'm a little slow today and don't exactly understand your question. Could you perhaps add some examples of input lines and what you would like to extract? example: input = "first word to Upper" output = "FIRST word to Upper" bye N > > Any help? please > Thanks in advance From steve at holdenweb.com Sun Mar 7 08:03:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Mar 2010 08:03:08 -0500 Subject: Problem with regular expression In-Reply-To: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > > re.sub("'(?P\w+)': [^{]", "\gFOO", str) > > # string to non-matching > 'foo': { > > # strings to matching > 'bar': 'bar2' > 'bar': None > 'bar': 0 > 'bar': True > > So, i.e., from the first string I would to get: > 'BAR': 'bar2' > > > Any help? please > Thanks in advance Well your pattern is identifying the right bits, but re.sub() replaces everything it matches: >>> import re >>> strings = """\ ... 'bar': 'bar2' ... 'bar': None ... 'bar': 0 ... 'bar': True""".split("\n") >>> for s in strings: ... print re.sub("'(?P\w+)': [^{]", "\gFOO", s) ... barFOObar2' barFOOone barFOO barFOOrue >>> What you need to fix is the replacement. Take a look at the documentation for re.sub: you will need to provide a function to apply the upper-case transformation, and the example there should show you how. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From lie.1296 at gmail.com Sun Mar 7 08:12:23 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 08 Mar 2010 00:12:23 +1100 Subject: Asynchronous HTTP client In-Reply-To: References: Message-ID: <4b93a660$1@dnews.tpgi.com.au> On 03/07/2010 05:53 PM, Ping wrote: > Hi, > > I'm trying to find a way to create an asynchronous HTTP client so I > can get responses from web servers in a way like > > async_http_open('http://example.com/', callback_func) > # immediately continues, and callback_func is called with response > as arg when it is ready > > It seems twisted can do it, but I hesitate to bring in such a big > package as a dependency because my client should be light. Asyncore > and asynchat are lighter but they don't speak HTTP. The asynchttp > project on sourceforge is a fusion between asynchat and httplib, but > it hasn't been updated since 2001 and is seriously out of sync with > httplib. > > I'd appreciate it if anyone can shed some lights on this. If you want something quite lightweight, you can spawn a thread for the call: import threading, urllib class AsyncOpen(threading.Thread): def __init__(self, url, callback): super(AsyncOpen, self).__init__() self.url = url self.callback = callback def run(self): # of course change urllib to httplib-something-something content = urllib.urlopen(self.url).read() self.callback(content) def asyncopen(url, callback): AsyncOpen(url, callback).start() def cb(content): print content asyncopen('http://www.google.com', cb) From exarkun at twistedmatrix.com Sun Mar 7 08:16:04 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 07 Mar 2010 13:16:04 -0000 Subject: Asynchronous HTTP client In-Reply-To: References: Message-ID: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> On 06:53 am, ping.nsr.yeh at gmail.com wrote: >Hi, > >I'm trying to find a way to create an asynchronous HTTP client so I >can get responses from web servers in a way like > > async_http_open('http://example.com/', callback_func) > # immediately continues, and callback_func is called with response >as arg when it is ready > >It seems twisted can do it, but I hesitate to bring in such a big >package as a dependency because my client should be light. Asyncore >and asynchat are lighter but they don't speak HTTP. The asynchttp >project on sourceforge is a fusion between asynchat and httplib, but >it hasn't been updated since 2001 and is seriously out of sync with >httplib. Why should it be "light"? In what way would using Twisted cause problems for you? Jean-Paul From python.list at tim.thechases.com Sun Mar 7 08:35:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Mar 2010 07:35:31 -0600 Subject: Problem with regular expression In-Reply-To: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: <4B93ABA3.7090608@tim.thechases.com> Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > > re.sub("'(?P\w+)': [^{]", "\gFOO", str) Well, my first thought is that you're not using raw strings, so you're not using the regexps and replacements you think you are. r"'(?P\w+)': [^{]" will match the lines of interest. The replacement will eat the opening & closing single-quote, colon, and first character. > # string to non-matching > 'foo': { > > # strings to matching > 'bar': 'bar2' > 'bar': None > 'bar': 0 > 'bar': True > > So, i.e., from the first string I would to get: > 'BAR': 'bar2' I think you'd have to use a function/lambda to do the case-conversion: re.sub( r"'(?P\w+)(?=': [^{])", lambda m: "'" + m.group('id').upper(), string_of_interest ) Or you could just forgo regexps and use regular string functions like split(), startswith(), and upper() -tkc From googler.1.webmaster at spamgourmet.com Sun Mar 7 08:50:59 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sun, 7 Mar 2010 05:50:59 -0800 (PST) Subject: time_struct Message-ID: <23dbe409-60ed-4f6f-bd38-4336e4f1b3d0@f8g2000yqn.googlegroups.com> Hi, can anyone tell me how to return a time_struct from the timemodule in my own C-Module? Is that possible? I can just find one function in timefuncs.h, but it doesnt return any PyObject. Thanks in advance. moerchendiser2k3 From ptmcg at austin.rr.com Sun Mar 7 09:10:55 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sun, 7 Mar 2010 06:10:55 -0800 (PST) Subject: Problem with regular expression References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: <2694479f-fce9-48ff-9264-fa35fdf103b3@z35g2000yqd.googlegroups.com> On Mar 7, 4:32?am, Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > Is using pyparsing overkill? Probably. But your time is valuable, and pyparsing let's you knock this out in less time than it probably took to write your original post. Use pyparsing's pre-defined expression sglQuotedString to match your entry key in quotes: key = sglQuotedString Add a parse action to convert to uppercase: key.setParseAction(lambda tokens:tokens[0].upper()) Now define the rest of your entry value (be sure to add the negative lookahead so we *don't* match your foo entry): entry = key + ":" + ~Literal("{") If I put your original test cases into a single string named 'data', I can now use transformString to convert all of your keys that don't point to '{'ed values: print entry.transformString(data) Giving me: # string to non-matching 'foo': { # strings to matching 'BAR': 'bar2' 'BAR': None 'BAR': 0 'BAR': True Here's the whole script: from pyparsing import sglQuotedString, Literal key = sglQuotedString key.setParseAction(lambda tokens:tokens[0].upper()) entry = key + ":" + ~Literal("{") print entry.transformString(data) And I'll bet that if you come back to this code in 3 months, you'll still be able to figure out what it does! -- Paul From ping.nsr.yeh at gmail.com Sun Mar 7 09:40:36 2010 From: ping.nsr.yeh at gmail.com (pingooo) Date: Sun, 7 Mar 2010 22:40:36 +0800 Subject: Asynchronous HTTP client In-Reply-To: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> References: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> Message-ID: <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> 2010/3/7 > On 06:53 am, ping.nsr.yeh at gmail.com wrote: > >> Hi, >> >> I'm trying to find a way to create an asynchronous HTTP client so I >> can get responses from web servers in a way like >> >> async_http_open('http://example.com/', callback_func) >> # immediately continues, and callback_func is called with response >> as arg when it is ready >> >> It seems twisted can do it, but I hesitate to bring in such a big >> package as a dependency because my client should be light. Asyncore >> and asynchat are lighter but they don't speak HTTP. The asynchttp >> project on sourceforge is a fusion between asynchat and httplib, but >> it hasn't been updated since 2001 and is seriously out of sync with >> httplib. >> > > Why should it be "light"? In what way would using Twisted cause problems > for you? > > Jean-Paul > I'm writing an open source python client for a web service. The client may be used in all kinds of environments - Linux, Mac OS X, Windows, web hosting, etc by others. It is not impossible to have twisted as a dependency, but that makes deployment a larger job than simply uploading a Python file. I'm willing to use twisted, but I'd like to explore lighter alternatives first. Thanks, Ping -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun Mar 7 09:57:02 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 07 Mar 2010 15:57:02 +0100 Subject: compiler with python In-Reply-To: References: Message-ID: mohamed issolah, 06.03.2010 14:07: > I want to create a compiler which transform a code like pascal code (that > what I do in C) to "quad" > In C, I use BISON and FLEX tools. Hi, please stop starting new threads for the same topic. Instead, reply to responses you get. Stefan From exarkun at twistedmatrix.com Sun Mar 7 09:57:07 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 07 Mar 2010 14:57:07 -0000 Subject: Asynchronous HTTP client In-Reply-To: <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> References: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> Message-ID: <20100307145707.2792.1316685222.divmod.xquotient.1369@localhost.localdomain> On 02:40 pm, ping.nsr.yeh at gmail.com wrote: >2010/3/7 >>On 06:53 am, ping.nsr.yeh at gmail.com wrote: >>>Hi, >>> >>>I'm trying to find a way to create an asynchronous HTTP client so I >>>can get responses from web servers in a way like >>> >>> async_http_open('http://example.com/', callback_func) >>> # immediately continues, and callback_func is called with response >>>as arg when it is ready >>> >>>It seems twisted can do it, but I hesitate to bring in such a big >>>package as a dependency because my client should be light. Asyncore >>>and asynchat are lighter but they don't speak HTTP. The asynchttp >>>project on sourceforge is a fusion between asynchat and httplib, but >>>it hasn't been updated since 2001 and is seriously out of sync with >>>httplib. >> >>Why should it be "light"? In what way would using Twisted cause >>problems >>for you? >> >>Jean-Paul > >I'm writing an open source python client for a web service. The client >may >be used in all kinds of environments - Linux, Mac OS X, Windows, web >hosting, etc by others. It is not impossible to have twisted as a >dependency, but that makes deployment a larger job than simply >uploading a >Python file. Twisted is packaged for many Linux distributions (perhaps most of them). Many web hosts provide it. It's also shipped with OS X. Windows may be an issue, but note that there's a binary Windows installer (as of 10.0, an MSI, so installation can be easily automated). >I'm willing to use twisted, but I'd like to explore lighter >alternatives >first. Jean-Paul From vicente.soler at gmail.com Sun Mar 7 10:05:26 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 07:05:26 -0800 (PST) Subject: a simple def how-to Message-ID: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Hello, My script starts like this: book=readFromExcelRange('book') house=readFromExcelRange('house') table=readFromExcelRange('table') read=readFromExcelRange('read') ... But I would like to have something equivalent, like... ranges=['book','house','table','read'] for i in ranges: var[i]=readFromExcelRange(i) which does not work. I assume I should be using globals() instead of var, but I do not know how to write my script. Can anybody help? From breamoreboy at yahoo.co.uk Sun Mar 7 10:16:25 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Mar 2010 15:16:25 +0000 Subject: compiler with python In-Reply-To: References: <4B923E68.1000104@ieee.org> <4B927B23.2090009@ieee.org> Message-ID: Alf and Steven Howe, please don't top post, it makes it all but impossible to follow a thread. Darn!:) Mark Lawrence. Alf P. Steinbach wrote: > Since Mohamed is talking about compilation I think it's more likely he's > talking about an intermediate program represention based on quad tuples > like > > (OP, DESTINATION, ARG1, ARG2) > > Cheers, > > - Alf > > > * Steven Howe: >> Is it possible he's talking about a 'quad core'? as in a CPU? In that >> case I think he wants >> to optimize a python program for a multiprocessor core with four >> processors. >> >> sph >> >> >> On 03/06/2010 07:56 AM, Dave Angel wrote: >>> mohamed issolah wrote: >>>> >>>> 2010/3/6 Dave Angel >>>> >>>>> mohamed issolah wrote: >>>>> >>>>>> hey, >>>>>> >>>>>> How can I construct a compiler with python just for informatiom ., >>>>>> I have >>>>>> habit to construct it with C language, >>>>>> >>>>>> sorry for my english ;-) >>>>>> >>>>>> >>>>> You need to tell us what you're really trying to do, what tools you're >>>>> willing to use, and probably why you want it. And if you're not >>>>> sure about >>>>> your English, keep the sentence structure straightforward. >>>>> >>>>> Let me make a couple of wild guesses: >>>>> >>>> >>>> >>>>> You want to design and build a compiler that takes xml information >>>>> as its >>>>> source code, and compiles those xml files into Intel x86 machine >>>>> code. The >>>>> compiler and the resulting executable needs to run on an x86 Linux >>>>> machine. >>>>> Your previous experience was in doing this sort of thing in C, but >>>>> you want >>>>> to try it with Python instead. You want to do it without using the >>>>> lxml >>>>> libraries. >>>>> >>>>> You want to build a python compiler, that takes python source code and >>>>> produces Java byte code files. You'd like to do this in C, but >>>>> don't want >>>>> to use any of the available existing CPython or Jython source >>>>> code. Your >>>>> goal is not to make a commercially viable product, but to learn as >>>>> much as >>>>> possible in the process. >>>>> >>>>> >>>>> DaveA >>>>> >>>> >>>> hey, >>>> >>>> I want to create a compiler which transform a code like pascal code >>>> (that >>>> what I do in C) to "quad" >>>> In C, I use BISON and FLEX tools. >>>> >>>> >>> I've forwarded your message to the list, and fixed your top-posting >>> by moving your response to the bottom. I don't have a clue what >>> "quad" is, unless it's a synonym for Forth. >>> >>> You haven't specified the OS you'll be using to run the compiler, nor >>> the one you're targeting, so some of these choices may not be >>> useful. For example, the first one is Linux only. >>> >>> http://www.freenet.org.nz/python/pybison/ >>> PyBison - Python binding for Bison/Flex >>> >>> http://freshmeat.net/projects/yeanpypa/ >>> http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html >>> >>> http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ >>> >>> >>> Or you could go here, which has links to (most of) these and others. >>> http://wiki.python.org/moin/LanguageParsing >>> >>> DaveA From jjposner at optimum.net Sun Mar 7 10:23:35 2010 From: jjposner at optimum.net (John Posner) Date: Sun, 07 Mar 2010 10:23:35 -0500 Subject: a simple def how-to In-Reply-To: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: <4b93c4ce$0$31278$607ed4bc@cv.net> On 3/7/2010 10:05 AM, vsoler wrote: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) > > which does not work. I assume I should be using globals() instead of > var, but I do not know how to write my script. > > Can anybody help? var = [] # create empty list for i in ranges: var.append(readFromExcelRange(i)) -or- var = [ readFromExcelRange(i) for i in ranges ] -or- var = map(readFromExcelRange, ranges) -John From usenot at geekmail.INVALID Sun Mar 7 10:23:48 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 7 Mar 2010 16:23:48 +0100 Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: <20100307162348.0995f801@geekmail.INVALID> On Sun, 7 Mar 2010 07:05:26 -0800 (PST) vsoler wrote: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) > > which does not work. I assume I should be using globals() instead of > var, but I do not know how to write my script. > > Can anybody help? One additional line, and it works (all the following code is untested, I might have goofed it up somewhere, but you get the idea): ranges=['book','house','table','read'] var = {} for i in ranges: var[i]=readFromExcelRange(i) Or, more succinctly: var = dict((i, readFromExcelRange(i)) for i in ranges) although that looks a bit crowded. Perhaps rd = readFromExcelRange var = dict((i, rd(i)) for i in ranges) looks better, but not by much, IMO. In Python 3 you can also just say var = {i:readFromExcelRange(i) for i in ranges} (I think. I don't have Python 3.) This looks comparatively neat, because there are no nesting parens. And just in case you think it's a good idea to meddle with globals and create actual "variables": it's not. You absolutely want dictionaries here. It's basically a bad idea to create names *implicitly* that you're going to use *explicitly*. (That is, it is in Python anyway, because it does not provide a clean and clear way of doing this. Other languages might provide that sort of thing, and it might be awesome, but in Python, no sir.) /W -- INVALID? DE! From vicente.soler at gmail.com Sun Mar 7 10:57:30 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 07:57:30 -0800 (PST) Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> <20100307162348.0995f801@geekmail.INVALID> Message-ID: <9c89873d-15a4-42bc-b30d-572a7111263d@t23g2000yqt.googlegroups.com> On 7 mar, 16:23, Andreas Waldenburger wrote: > On Sun, 7 Mar 2010 07:05:26 -0800 (PST) vsoler > > > > wrote: > > Hello, > > > My script starts like this: > > > book=readFromExcelRange('book') > > house=readFromExcelRange('house') > > table=readFromExcelRange('table') > > read=readFromExcelRange('read') > > ... > > > But I would like to have something equivalent, like... > > > ranges=['book','house','table','read'] > > for i in ranges: > > ? ? var[i]=readFromExcelRange(i) > > > which does not work. I assume I should be using globals() instead of > > var, but I do not know how to write my script. > > > Can anybody help? > > One additional line, and it works (all the following code is untested, > I might have goofed it up somewhere, but you get the idea): > > ranges=['book','house','table','read'] > var = {} > for i in ranges: > ? ? var[i]=readFromExcelRange(i) > > Or, more succinctly: > > var = dict((i, readFromExcelRange(i)) for i in ranges) > > although that looks a bit crowded. Perhaps > > rd = readFromExcelRange > var = dict((i, rd(i)) for i in ranges) > > looks better, but not by much, IMO. > > In Python 3 you can also just say > > var = {i:readFromExcelRange(i) for i in ranges} > > (I think. I don't have Python 3.) This looks comparatively neat, > because there are no nesting parens. > > And just in case you think it's a good idea to meddle with globals and > create actual "variables": it's not. You absolutely want dictionaries > here. It's basically a bad idea to create names *implicitly* that > you're going to use *explicitly*. (That is, it is in Python anyway, > because it does not provide a clean and clear way of doing this. Other > languages might provide that sort of thing, and it might be awesome, > but in Python, no sir.) > > /W > > -- > INVALID? DE! Thank you Andreas. Your comprehensive answer makes a lot of sense to me. From vicente.soler at gmail.com Sun Mar 7 10:59:30 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 07:59:30 -0800 (PST) Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> <4b93c4ce$0$31278$607ed4bc@cv.net> Message-ID: <63b9d9e5-cd46-4e96-b8e5-e791ad6e9a1e@i25g2000yqm.googlegroups.com> On 7 mar, 16:23, John Posner wrote: > On 3/7/2010 10:05 AM, vsoler wrote: > > > > > Hello, > > > My script starts like this: > > > book=readFromExcelRange('book') > > house=readFromExcelRange('house') > > table=readFromExcelRange('table') > > read=readFromExcelRange('read') > > ... > > > But I would like to have something equivalent, like... > > > ranges=['book','house','table','read'] > > for i in ranges: > > ? ? ?var[i]=readFromExcelRange(i) > > > which does not work. I assume I should be using globals() instead of > > var, but I do not know how to write my script. > > > Can anybody help? > > var = [] ? ?# create empty list > for i in ranges: > ? ? ?var.append(readFromExcelRange(i)) > > ? -or- > > var = [ readFromExcelRange(i) for i in ranges ] > > ? -or- > > var = map(readFromExcelRange, ranges) > > -John John, Thank you for your help. Perhaps the solution you are suggesting is not exactly what I was looking for, but helped anyway. From jjposner at optimum.net Sun Mar 7 11:16:36 2010 From: jjposner at optimum.net (John Posner) Date: Sun, 07 Mar 2010 11:16:36 -0500 Subject: a simple def how-to In-Reply-To: <63b9d9e5-cd46-4e96-b8e5-e791ad6e9a1e@i25g2000yqm.googlegroups.com> References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> <4b93c4ce$0$31278$607ed4bc@cv.net> <63b9d9e5-cd46-4e96-b8e5-e791ad6e9a1e@i25g2000yqm.googlegroups.com> Message-ID: <4B93D164.3060309@optimum.net> On 3/7/2010 10:59 AM, vsoler wrote: > > Thank you for your help. Perhaps the solution you are suggesting is > not exactly what I was looking for, but helped anyway. Oops, I was thinking list, not dict. Too fast, and not enough coffee! -John From vicente.soler at gmail.com Sun Mar 7 11:23:13 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 08:23:13 -0800 (PST) Subject: Duplicate keys in dict? Message-ID: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Hello, My code snippet reads data from excel ranges. First row and first column are column headers and row headers respectively. After reding the range I build a dict. ................'A'..............'B' 'ab'............3................5 'cd'............7................2 'cd'............9................1 'ac'............7................2 d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... However, as you can see there are two rows that start with 'cd', and dicts, AFAIK do not accept duplicates. What is the best workaround for this? Should I discard dicts? Should I somehow have under 'cd'... a list of values? One of the difficulties I find here is that I want to be able to easily sum all the values for each row key: 'ab', 'cd' and 'ac'. However, using lists inside dicts makes it a difficult issue for me. What is the best approach for this problem? Can anybody help? From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 11:42:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 16:42:59 GMT Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: <4b93d793$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 07:05:26 -0800, vsoler wrote: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) > > which does not work. I assume I should be using globals() instead of > var, but I do not know how to write my script. > > Can anybody help? Yes. Use a dict instead. ranges=['book','house','table','read'] data = {} for name in ranges: data[name] = readFromExcelRange(name) # and later... item = 'table' print "The range '%s' is %s" % (item, data[item]) -- Steven From news123 at free.fr Sun Mar 7 11:46:02 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 17:46:02 +0100 Subject: Duplicate keys in dict? In-Reply-To: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Message-ID: <4b93d84b$0$10084$426a74cc@news.free.fr> vsoler wrote: > Hello, > > My code snippet reads data from excel ranges. First row and first > column are column headers and row headers respectively. After reding > the range I build a dict. > > ................'A'..............'B' > 'ab'............3................5 > 'cd'............7................2 > 'cd'............9................1 > 'ac'............7................2 > > d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... > > However, as you can see there are two rows that start with 'cd', and > dicts, AFAIK do not accept duplicates. Normall dicts are used if you want to access your data at a later point in time by the key name. Do you want to be able to do this? Then what would you expect to receive for d[('cd','A')] ? The first value? the second value? both values? Could you perhaps change further occurences of 'cd' with 'cd1' , 'cd2' , 'cd3', ... ? Not knowing your exact context makes it difficult to suggest solutions? perhaps you could switch to a list containing a tuple of (rowname,rowdict) l = [ ('ab', { 'A': 3 , 'B': 5 } ), 'cd', { 'A': 7 , 'B': 2 } ), 'cd', { 'A': 9 , 'B': 1 } ), 'ac', { ... } ] bye N > > What is the best workaround for this? Should I discard dicts? Should I > somehow have under 'cd'... a list of values? > > One of the difficulties I find here is that I want to be able to > easily sum all the values for each row key: 'ab', 'cd' and 'ac'. > However, using lists inside dicts makes it a difficult issue for me. > > What is the best approach for this problem? Can anybody help? From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 11:53:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 16:53:55 GMT Subject: Duplicate keys in dict? References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Message-ID: <4b93da23$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 08:23:13 -0800, vsoler wrote: > Hello, > > My code snippet reads data from excel ranges. First row and first column > are column headers and row headers respectively. After reding the range > I build a dict. > > ................'A'..............'B' > 'ab'............3................5 > 'cd'............7................2 > 'cd'............9................1 > 'ac'............7................2 > > d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... > > However, as you can see there are two rows that start with 'cd', and > dicts, AFAIK do not accept duplicates. > One of the difficulties I find here is that I want to be able to easily > sum all the values for each row key: 'ab', 'cd' and 'ac'. However, > using lists inside dicts makes it a difficult issue for me. Given the sample above, what answer do you expect for summing the 'cd' row? There are four reasonable answers: 7 + 2 = 9 9 + 1 = 10 7 + 2 + 9 + 1 = 19 Error You need to decide what you want to do before asking how to do it. -- Steven From vicente.soler at gmail.com Sun Mar 7 12:13:13 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 09:13:13 -0800 (PST) Subject: Duplicate keys in dict? References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> <4b93da23$0$8836$c3e8da3@news.astraweb.com> Message-ID: <70b3224d-a8d1-4182-8609-0b96270fa13e@33g2000yqj.googlegroups.com> On 7 mar, 17:53, Steven D'Aprano wrote: > On Sun, 07 Mar 2010 08:23:13 -0800, vsoler wrote: > > Hello, > > > My code snippet reads data from excel ranges. First row and first column > > are column headers and row headers respectively. After reding the range > > I build a dict. > > > ................'A'..............'B' > > 'ab'............3................5 > > 'cd'............7................2 > > 'cd'............9................1 > > 'ac'............7................2 > > > d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... > > > However, as you can see there are two rows that start with 'cd', and > > dicts, AFAIK do not accept duplicates. > > One of the difficulties I find here is that I want to be able to easily > > sum all the values for each row key: ?'ab', 'cd' and 'ac'. However, > > using lists inside dicts makes it a difficult issue for me. > > Given the sample above, what answer do you expect for summing the 'cd' > row? There are four reasonable answers: > > 7 + 2 = 9 > 9 + 1 = 10 > 7 + 2 + 9 + 1 = 19 > Error > > You need to decide what you want to do before asking how to do it. > > -- > Steven Steven, What I need is that sum(('cd','A')) gives me 16, sum(('cd','B')) gives me 3. I apologize for not having made it clear. From rjngrj2010 at gmail.com Sun Mar 7 12:16:04 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 7 Mar 2010 09:16:04 -0800 (PST) Subject: importerror: module Gnuplot missing Message-ID: Hi, I need help. I am trying to follow examples from a book "Python Scripting for Computational Science" and the examples are all plotted using Gnuplot. When I run the programs I get error saying "importerror Gnuplot module missing". I have installed Gnuplot in C:\My Programs\gnuplot directory (running on WinME). I have installed python 2.5 and Gnuplot 4.2. I have also installed Gnuplot-py-1.8 in Python's site-packages. All paths are correctly set as I can see from sys.path argument i.e., path for gnuplot is set and so also the python path and scripting path which is where book examples reside. Many examples did run well until it came down to plotting... I also ran 'python test.py' from Gnuplot-py-1.8 directory and strangely it runs and then asks me to press return to see result. The screen then freezes and the computer hangs. I have to reboot it again. Some one suggested in the old archives that I should change in the utils the code import Gnuplot,utils to import utils from _Gnuplot import Gnuplot I have tried it but same result. Window freezes and my "C:\Windows\ " directory gets filled with fff #...tmp files. I have no idea what are those. My other attempts: 1. Is there an issue how one names the directory - gnuplot versus Gnuplot etc... 2. I have done things like >>> from numpy import oldnumeric. And the test runs fine. 3. "python setup.py" install for installing Gnuplot-py-1.8 also ran fine. 4. I could from "\gnuplot\bin" directory open wgnuplot and in the Gnuplot window could plot sinx/x. 5. I also have a pgnuplot application 6. Is the gnuplot version incompatible with Python 2.5 and its associated older numpy versions.. I have seen several similar "missing Gnuplot" reports in the archive but did not find any resolution to those. I will appreciate any help, Thanks gujax From stefan_ml at behnel.de Sun Mar 7 12:17:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 07 Mar 2010 18:17:01 +0100 Subject: a simple def how-to In-Reply-To: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: vsoler, 07.03.2010 16:05: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) Note that the name "i" is rather badly chosen as it generally implies a totally different thing (integer) than what you use it for (names of ranges). "ranges" seems to fall into the same bucket, but I guess that's just because I can't extract the meaning from your code snippet (which is not a good sign). Try to use expressive names in your code, so that people who look at it for the first time get an idea about what it does with what kind of data. Stefan From karun.madhan at gmail.com Sun Mar 7 13:09:47 2010 From: karun.madhan at gmail.com (madhan) Date: Sun, 7 Mar 2010 10:09:47 -0800 (PST) Subject: click me Message-ID: please clic it it will be usefull to you http://123maza.com/78/healthyfitness/ From miraclesoul at hotmail.com Sun Mar 7 13:55:24 2010 From: miraclesoul at hotmail.com (Fahad Ahmad) Date: Sun, 7 Mar 2010 18:55:24 +0000 Subject: Calculating very large exponents in python Message-ID: Dear All, i am writing my crytographic scheme in python, i am just a new user to it. I have written the complete code, the only point i am stuck it is that i am using 256 exponentiation which is normal in crytography but python just hangs on it. g**x [where both g and x are 256 bit numbers , in decimal they are around 77] after reading several forums, i just come to know it can be done using numpy, i have installed python(x,y) has has both numpy and scipy installed but i am not able to make it happen. any idea which library, module, or piece of code can solve this mystery :S sorry for bad english "People come and go no one remembers them for life but it is the time spent with them that become Sweet memories that are remembered for life hope I leave some memories behind " _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. http://clk.atdmt.com/GBL/go/201469229/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Mar 7 14:11:18 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Mar 2010 13:11:18 -0600 Subject: Duplicate keys in dict? In-Reply-To: <70b3224d-a8d1-4182-8609-0b96270fa13e@33g2000yqj.googlegroups.com> References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> <4b93da23$0$8836$c3e8da3@news.astraweb.com> <70b3224d-a8d1-4182-8609-0b96270fa13e@33g2000yqj.googlegroups.com> Message-ID: <4B93FA56.20100@tim.thechases.com> vsoler wrote: > On 7 mar, 17:53, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 07 Mar 2010 08:23:13 -0800, vsoler wrote: >>> Hello, >>> My code snippet reads data from excel ranges. First row and first column >>> are column headers and row headers respectively. After reding the range >>> I build a dict. >>> ................'A'..............'B' >>> 'ab'............3................5 >>> 'cd'............7................2 >>> 'cd'............9................1 >>> 'ac'............7................2 >>> d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... >>> However, as you can see there are two rows that start with 'cd', and >>> dicts, AFAIK do not accept duplicates. >>> One of the difficulties I find here is that I want to be able to easily >>> sum all the values for each row key: 'ab', 'cd' and 'ac'. However, >>> using lists inside dicts makes it a difficult issue for me. > > What I need is that sum(('cd','A')) gives me 16, sum(('cd','B')) gives > me 3. But you really *do* want lists inside the dict if you want to be able to call sum() on them. You want to map the tuple ('cd','A') to the list [7,9] so you can sum the results. And if you plan to sum the results, it's far easier to have one-element lists and just sum them, instead of having to special case "if it's a list, sum it, otherwise, return the value". So I'd use something like import csv f = file(INFILE, 'rb') r = csv.reader(f, ...) headers = r.next() # discard the headers d = defaultdict(list) for (label, a, b) in r: d[(label, 'a')].append(int(a)) d[(label, 'b')].append(int(b)) # ... for (label, col), value in d.iteritems(): print label, col, 'sum =', sum(value) Alternatively, if you don't need to store the intermediate values, and just want to store the sums, you can accrue them as you go along: d = defaultdict(int) for (label, a, b) in r: d[(label, 'a')] += int(a) d[(label, 'b')] += int(b) # ... for (label, col), value in d.iteritems(): print label, col, 'sum =', value Both are untested, but I'm pretty sure they're both viable, modulo my sleep-deprived eyes. -tkc From python at rgbaz.eu Sun Mar 7 14:26:57 2010 From: python at rgbaz.eu (PythonAB) Date: Sun, 7 Mar 2010 20:26:57 +0100 Subject: Bluetooth Message-ID: Hello, I'm writing a script that has to connect a bluetooth device with a 3D application. On my search for a bluetooth module i ran into this: http://www.python.org/download/releases/2.4/notes/ where it says: "The socket module now supports Bluetooth sockets, if the system has " Yet I can't find anything at all in the socket manuals nor anywhere else on the site... Does the socket module really support Bluetooth out of the box? I've used socket before but never read anything about bluetooth... Maybe I need to get the bluetooth.h file, but i have no idea what I am supposed to do with it... Can anyone shed some light on this for me please? thanks in advance, gr Arno -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Sun Mar 7 15:40:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 7 Mar 2010 15:40:59 -0500 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad wrote: > Dear All, > > i am writing my crytographic scheme in python, i am just a new user to it. > I have written the complete code, the only point i am stuck it is that i am > using 256 exponentiation which is normal in crytography but python just > hangs on it. > > g**x? [where both g and x are 256 bit numbers , in decimal they are around > 77] > > after reading several forums, i just come to know it can be done using > numpy, i have installed python(x,y) has has both numpy and scipy installed > but i am not able to make it happen. > > any idea which library, module, or piece of code can solve this mystery :S > > sorry for bad english A couple of things: 1) if you're working with modular exponentiation, remember that pow() takes three arguments, ie: a = 222222222222222222222222222 b = 5555555555555555555555555555 pow(a, b, 1200) will calculate the correct answer (768) very quickly, while a**b % 1200 has not terminated in the time it took me to compose this email. 2) sage has a lot of excellent tools for crypto/cryptanalysis that you may want to take a look at. 3) not saying you don't know what you're doing, but be careful when rolling your own cryptosystems- even very good cryptographers make implementation mistakes! Geremy Condra From vlastimil.brom at gmail.com Sun Mar 7 16:04:42 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 7 Mar 2010 22:04:42 +0100 Subject: negative "counts" in collections.Counter? Message-ID: <9fdb569a1003071304x7265b331o58dc407c2a51307d@mail.gmail.com> Hi all, I'd like to ask about the possibility of negative "counts" in collections.Counter (using Python 3.1); I believe, my usecase is rather trivial, basically I have the word frequencies of two texts and I want do compare them (e.g. to see what was added and removed between different versions of a text). This is simple enough to do with own code, but I thought, this would be exactly the case for Counter... However, as the Counter only returns positive counts, one has to get the difference in both directions and combine them afterwards, maybe something like: >>> c1=collections.Counter("aabcddd") >>> c2=collections.Counter("abbbd") >>> added_c2 = c2-c1 >>> removed_c2 = c1-c2 >>> negative_added_c2 = dict((k, v*-1) for (k, v) in removed_c2.items()) >>> changed_c2 = dict(added_c2) >>> changed_c2.update(negative_added_c2) >>> changed_c2 {'a': -1, 'c': -1, 'b': 2, 'd': -2} >>> It seems to me, that with negative counts allowed in Counter, this would simply be the matter of a single difference: changed_c2 = c2 - c1 Is there a possibility to make the Counter work this way (other than replacing its methods in a subclass, which might be comparable to writing the naive counting class itself)? Are there maybe some reasons I missed to disable negative counts here? (As I could roughly understand, the Counter isn't quite limited to the mathematical notion of multiset; it seems to accept negative counts, but its methods only output the positive part). Is this kind of task - a comparison in both directions - an unusual one, or is it simply not the case for Counter? Thanks in advance, vbr From news123 at free.fr Sun Mar 7 16:08:39 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:08:39 +0100 Subject: killing own process in windows Message-ID: <4b9415d7$0$19558$426a74cc@news.free.fr> Hi, How can I kill my own process? Some multithreaded programs, that I have are unable to stop when ctrl-C is pressed. Some can't be stopped with sys.exit() So I'd just like to terminate my own program. Examples of non killable (not killable with CTRL-C) programs: - A program, that started an XMLRPC server with serve_forever - a program, that started a multiprocessing.Manager with serve_forever thanks in advance for some ideas. N From news123 at free.fr Sun Mar 7 16:26:41 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:26:41 +0100 Subject: stopping a multiprocessing.managers.BaseManager nicely (looks like a hack) Message-ID: <4b941a11$0$23919$426a74cc@news.free.fr> Hi, I have following program from multiprocessing.managers import BaseManager def myfunc(): return 3 class MyManager(BaseManager): pass MyManager.register('myfunc',callable = myfunc) m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') server = m.get_server() server.serve_forever() I'd like to replace server.serve_forever() with something, which is abortable. After digging in the sources I came up with following (in my opinion) inelegant, but working solution. I just copied the Server.serve_forever() function from multiprocessing/managers.py and changed two lines. Does anybody have a better idea than this: # ------------------------------------------------ import multiprocessing.managers from multiprocessing.managers import BaseManager def serve_till_stop(self): ''' Run the server forever ''' #current_process()._manager_server = self # this lin removed multiprocessing.managers.current_process()._manager_server = self # this line added try: try: #while 1: # this line removed while self.running: # this line added try: c = self.listener.accept() except (OSError, IOError): continue t = threading.Thread(target=self.handle_request, args=(c,)) t.daemon = True t.start() except (KeyboardInterrupt, SystemExit): pass finally: self.stop = 999 self.listener.close() def myfunc(): return 3 def stopme(): server.running = False class MyManager(BaseManager): pass MyManager.register('myfunc',callable = myfunc) m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') server = m.get_server() server.running = True serve_till_stop(server) thanks in advance and bye N From martin.hellwig at dcuktec.org Sun Mar 7 16:28:16 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 07 Mar 2010 21:28:16 +0000 Subject: killing own process in windows In-Reply-To: <4b9415d7$0$19558$426a74cc@news.free.fr> References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: On 03/07/10 21:08, News123 wrote: > Hi, > > > How can I kill my own process? > > Some multithreaded programs, that I have are unable to stop when ctrl-C > is pressed. > Some can't be stopped with sys.exit() > > So I'd just like to terminate my own program. > > > Examples of non killable (not killable with CTRL-C) programs: > - A program, that started an XMLRPC server with serve_forever > - a program, that started a multiprocessing.Manager with serve_forever > > > thanks in advance for some ideas. > > > N If it is just the xml rpc server you want to kill, there might be better ways. For example look at: http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py with perhaps special interest at the comment on lines 172-174. -- mph From news123 at free.fr Sun Mar 7 16:47:51 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:47:51 +0100 Subject: stopping a multiprocessing.managers.BaseManager nicely (looks like a hack) In-Reply-To: <4b941a11$0$23919$426a74cc@news.free.fr> References: <4b941a11$0$23919$426a74cc@news.free.fr> Message-ID: <4b941f07$0$14923$426a34cc@news.free.fr> My fix has certain problems: News123 wrote: > Hi, > > > I have following program > > from multiprocessing.managers import BaseManager > def myfunc(): return 3 > class MyManager(BaseManager): pass > MyManager.register('myfunc',callable = myfunc) > m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') > server = m.get_server() > server.serve_forever() > > > I'd like to replace server.serve_forever() with something, which is > abortable. > > After digging in the sources I came up with following (in my opinion) > inelegant, but working solution. > > I just copied the Server.serve_forever() function from > multiprocessing/managers.py and changed two lines. > > > Does anybody have a better idea than this: > # ------------------------------------------------ > import multiprocessing.managers > from multiprocessing.managers import BaseManager > def serve_till_stop(self): > ''' > Run the server forever > ''' > #current_process()._manager_server = self # this lin removed > multiprocessing.managers.current_process()._manager_server = self # > this line added > try: > try: > #while 1: # this line removed > while self.running: # this line added > try: > c = self.listener.accept() > except (OSError, IOError): > continue > t = threading.Thread(target=self.handle_request, args=(c,)) > t.daemon = True > t.start() > except (KeyboardInterrupt, SystemExit): > pass > finally: > self.stop = 999 > self.listener.close() Problems will now occur on he client side. The server terminates now immediately after the function stopme has been called. The client however wants still to perform a few requests, before it considers calling of stopme done. So I still don't have a solution :-( > > > def myfunc(): return 3 > def stopme(): server.running = False > class MyManager(BaseManager): pass > MyManager.register('myfunc',callable = myfunc) > m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') > server = m.get_server() > server.running = True > serve_till_stop(server) > > thanks in advance and bye > > > N > > From news123 at free.fr Sun Mar 7 16:54:28 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:54:28 +0100 Subject: killing own process in windows In-Reply-To: References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: <4b942094$0$25784$426a74cc@news.free.fr> Hi Martin. Hellwig wrote: > On 03/07/10 21:08, News123 wrote: >> Hi, >> >> >> How can I kill my own process? >> >> Some multithreaded programs, that I have are unable to stop when ctrl-C >> is pressed. >> Some can't be stopped with sys.exit() >> >> So I'd just like to terminate my own program. >> >> >> Examples of non killable (not killable with CTRL-C) programs: >> - A program, that started an XMLRPC server with serve_forever >> - a program, that started a multiprocessing.Manager with serve_forever >> >> > If it is just the xml rpc server you want to kill, there might be better > ways. For example look at: > http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py > > with perhaps special interest at the comment on lines 172-174. I Thanks. this looks like a good solution for an XMLRPC server. However when playing with different server modules I fall over and over again over code, that can't be shutdown nicely. Currently I'm still struggling with multiprocessing.managers,BaseManager bye N From arnodel at googlemail.com Sun Mar 7 17:21:27 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 07 Mar 2010 22:21:27 +0000 Subject: negative "counts" in collections.Counter? References: Message-ID: Vlastimil Brom writes: > Hi all, > I'd like to ask about the possibility of negative "counts" in > collections.Counter (using Python 3.1); > I believe, my usecase is rather trivial, basically I have the word > frequencies of two texts and I want do compare them (e.g. to see what > was added and removed between different versions of a text). > > This is simple enough to do with own code, but I thought, this would > be exactly the case for Counter... > However, as the Counter only returns positive counts, one has to get > the difference in both directions and combine them afterwards, maybe > something like: > >>>> c1=collections.Counter("aabcddd") >>>> c2=collections.Counter("abbbd") >>>> added_c2 = c2-c1 >>>> removed_c2 = c1-c2 >>>> negative_added_c2 = dict((k, v*-1) for (k, v) in removed_c2.items()) >>>> changed_c2 = dict(added_c2) >>>> changed_c2.update(negative_added_c2) >>>> changed_c2 > {'a': -1, 'c': -1, 'b': 2, 'd': -2} >>>> > > It seems to me, that with negative counts allowed in Counter, this > would simply be the matter of a single difference: > changed_c2 = c2 - c1 > > Is there a possibility to make the Counter work this way (other than > replacing its methods in a subclass, which might be comparable to > writing the naive counting class itself)? > Are there maybe some reasons I missed to disable negative counts here? > (As I could roughly understand, the Counter isn't quite limited to the > mathematical notion of multiset; it seems to accept negative counts, > but its methods only output the positive part). > Is this kind of task - a comparison in both directions - an unusual > one, or is it simply not the case for Counter? Every time I have needed something like collections.Counter, I have wanted the behaviour you require too. As a result, I have never used collections.Counter. Instead I have used plain dictionaries or my own class. I don't understand why the Counter's + and - operators behave as they do. Here is an example from the docs: >>> c = Counter(a=3, b=1) >>> d = Counter(a=1, b=2) >>> c + d # add two counters together: c[x] + d[x] Counter({'a': 4, 'b': 3}) >>> c - d # subtract (keeping only positive counts) Counter({'a': 2}) >>> c & d # intersection: min(c[x], d[x]) Counter({'a': 1, 'b': 1}) >>> c | d # union: max(c[x], d[x]) Counter({'a': 3, 'b': 2}) If + and - just added or subtracted the multiplicities of elements, keeping negative multiplicites, we would get: >>> c - d Counter({'a':2, 'b':-1}) Which I think is useful in many cases. But we could still get the result of current c - d very simply: >>> (c - d) | Counter() # | Counter() removes negative multiplicities Counter({'a':2}) Altogether more versatile and coherent IMHO. -- Arnaud From martin.hellwig at dcuktec.org Sun Mar 7 17:27:48 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 07 Mar 2010 22:27:48 +0000 Subject: killing own process in windows In-Reply-To: <4b942094$0$25784$426a74cc@news.free.fr> References: <4b9415d7$0$19558$426a74cc@news.free.fr> <4b942094$0$25784$426a74cc@news.free.fr> Message-ID: On 03/07/10 21:54, News123 wrote: > Hi Martin. > Hellwig wrote: >> On 03/07/10 21:08, News123 wrote: >>> Hi, >>> >>> >>> How can I kill my own process? >>> >>> Some multithreaded programs, that I have are unable to stop when ctrl-C >>> is pressed. >>> Some can't be stopped with sys.exit() >>> >>> So I'd just like to terminate my own program. >>> >>> >>> Examples of non killable (not killable with CTRL-C) programs: >>> - A program, that started an XMLRPC server with serve_forever >>> - a program, that started a multiprocessing.Manager with serve_forever >>> >>> >> If it is just the xml rpc server you want to kill, there might be better >> ways. For example look at: >> http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py >> >> with perhaps special interest at the comment on lines 172-174. > I > > > > Thanks. this looks like a good solution for an XMLRPC server. > However when playing with different server modules I fall over and over > again over code, that can't be shutdown nicely. > > Currently I'm still struggling with multiprocessing.managers,BaseManager > > bye > > N I haven't used the multiprocessing module yet, but generally speaking I believe that everything in python that is server-like inherits from SocketServer BaseServer. Probably for you to have all servers behave in a way you expect, is to override functionality there, for example in: http://docs.python.org/library/socketserver.html?highlight=baseserver#SocketServer.BaseServer the function: handle_request Though from looking at the source the function serve_forever is just an while loop over handle request (blocking or no-blocking), so might be a better candidate to replace. But you still might find that some tcp connections remain open, so unless you want to go down to the socket level and explicit close the socket, there is not much you can do about that. For the client side, socket timeout is you enemy, I found something rather long as default (300 seconds in the xml-rpc client) but yours might be different (it is probably a Python defined standard default, but I haven't checked that). Sounds to me like you will be busy reading up on it now :-) Oh and just a word to prevent over-engineering, if both the server and client is written by you, a lot of problems you anticipate will probably never occur because that would require a rogue server or client. Unless of course you like making rogue server/clients :-) -- mph From lists at cheimes.de Sun Mar 7 17:36:54 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 07 Mar 2010 23:36:54 +0100 Subject: killing own process in windows In-Reply-To: <4b9415d7$0$19558$426a74cc@news.free.fr> References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: News123 wrote: > Hi, > > > How can I kill my own process? > > Some multithreaded programs, that I have are unable to stop when ctrl-C > is pressed. > Some can't be stopped with sys.exit() You have to terminate the XMP-RPC server or the manager first. Check the docs! You can terminate a Python process with os._exit() but I recommend that you find another way. os._exit() is a hard termination. It kills the process without running any cleanup code like atexit handlers and Python's internal cleanups. Open files aren't flushed to disk etc. Christian From news123 at free.fr Sun Mar 7 18:01:39 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 00:01:39 +0100 Subject: killing own process in windows In-Reply-To: References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: <4b943053$0$25136$426a74cc@news.free.fr> Hi Cristian, Christian Heimes wrote: > News123 wrote: >> Hi, >> >> >> How can I kill my own process? >> >> Some multithreaded programs, that I have are unable to stop when ctrl-C >> is pressed. >> Some can't be stopped with sys.exit() > > You have to terminate the XMP-RPC server or the manager first. Check the > docs! > > You can terminate a Python process with os._exit() but I recommend that > you find another way. os._exit() is a hard termination. It kills the > process without running any cleanup code like atexit handlers and > Python's internal cleanups. Open files aren't flushed to disk etc. > This is exactly the problem: Neither the XMLRPC server nor the manager can be stopped both serve forever. The doc doesn't really help. For the XMLRPC server there are tricks to subclass it and to change the behaviour, as indicated by Martin. for the manager I did not find a clean solution (Plese see my other thread "stopping a multiprocessing.manage.....") I'm surprised, that there are no 'canned' solution to stop servers remotely or just by pressing ctrl-C I consider this being quite useful for certain kinds of applications. I prefer to ask a server to shutdown, than to just kill him. Am interactive program, which also acts like a server should be able to shutdown its server thread from the main thread in order to quit nicely. Baseserver has even a shutdown method(), but it cannot be called if were started with serve_forever(). N From googler.1.webmaster at spamgourmet.com Sun Mar 7 18:29:42 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sun, 7 Mar 2010 15:29:42 -0800 (PST) Subject: time_struct References: <23dbe409-60ed-4f6f-bd38-4336e4f1b3d0@f8g2000yqn.googlegroups.com> Message-ID: any ideas? From rjngrj2010 at gmail.com Sun Mar 7 18:33:16 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 7 Mar 2010 15:33:16 -0800 (PST) Subject: Window crash/freeze after "python test.py" in \Gnuplot Message-ID: <3d586615-f79c-4657-bcaf-58287d5c8917@g11g2000yqe.googlegroups.com> Hi, My computer OS is Win ME, and I am running a Py2.5 version. Gnuplot is v4.2, Gnuplot_py is v1.8. However, whenever I give a command "python test.py" to test Gnuplot_py, I sometimes get message " #Gnuplot.................for enjoyment #press return to open a window >.. >clear terminal ....#####test function####### and then computer hangs. I never see any windows appearing. A blue screen appears with request for cntrl-alt-del. I cannot exactly determine the messages because the crash occurs relatively fast therefore some sentences above may not be accurate. I have tried this with many scripts which use Gnuplot for plotting but it results in same crashes e.g. demo.py in gnuplot_py. I really have no clue what should be my next step. Any help will be appreicated. I however, can run Gnuplot by typing "pgnuplot" or "wgnuplot" in the command shell and it opens a Gnuplot window. Therefore, it looks like some incompatibility between gnuplot_py, python2.5? Thanks, gujax From floaiza2 at gmail.com Sun Mar 7 18:55:14 2010 From: floaiza2 at gmail.com (floaiza) Date: Sun, 7 Mar 2010 15:55:14 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <182de09d-417b-4ad7-8351-23a44e26fea6@15g2000yqi.googlegroups.com> I don't think there is any doubt about the value of relational databases, particularly on the Internet. The issue in my mind is how to leverage all the information that resides in the "deep web" using strictly the relational database paradigm. Because that paradigm imposes a tight and rigid coupling between semantics and syntax when you attempt to efficiently "merge" or "federate" data from disparate sources you can find yourself spending a lot of time and money building mappings and maintaining translators. That's why approaches that try to separate syntax from the semantics are now becoming so popular, but, again, as others have said, it is not a matter of replacing one with the other, but of figuring out how best to exploit what each technology offers. I base my remarks on some initial explorations I have made on the use of RDF Triple Stores, which, by the way, use RDBMSs to persist the triples, but which offer a really high degree of flexibility WRT the merging and federating of data from different semantic spaces. The way I hope things will move forward is that eventually it will become inexpensive and easy to "expose" as RDF triples all the relevant data that now sits in special-purpose databases. (just an opinion) Francisco On Mar 3, 12:36?pm, Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > athttp://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. > > So, i thought i'd post here to solicit some opinins from the programer > community i know. > > Here's the plain text version > > ----------------------------- > The NoSQL Movement > > Xah Lee, 2010-01-26 > > In the past few years, there's new fashionable thinking about anti > relational database, now blessed with a rhyming term: NoSQL. > Basically, it considers that relational database is outdated, and not > ?horizontally? scalable. I'm quite dubious of these claims. > > According to Wikipedia Scalability article, verticle scalability means > adding more resource to a single node, such as more cpu, memory. (You > can easily do this by running your db server on a more powerful > machine.), and ?Horizontal scalability? means adding more machines. > (and indeed, this is not simple with sql databases, but again, it is > the same situation with any software, not just database. To add more > machines to run one single software, the software must have some sort > of grid computing infrastructure built-in. This is not a problem of > the software per se, it is just the way things are. It is not a > problem of databases.) > > I'm quite old fashioned when it comes to computer technology. In order > to convience me of some revolutionary new-fangled technology, i must > see improvement based on math foundation. I am a expert of SQL, and > believe that relational database is pretty much the gist of database > with respect to math. Sure, a tight definition of relations of your > data may not be necessary for many applications that simply just need > store and retrieve and modify data without much concern about the > relations of them. But still, that's what relational database > technology do too. You just don't worry about normalizing when you > design your table schema. > > The NoSQL movement is really about scaling movement, about adding more > machines, about some so-called ?cloud computing? and services with > simple interfaces. (like so many fashionable movements in the > computing industry, often they are not well defined.) It is not really > about anti relation designs in your data. It's more about adding > features for practical need such as providing easy-to-user APIs (so > you users don't have to know SQL or Schemas), ability to add more > nodes, provide commercial interface services to your database, provide > parallel systems that access your data. Of course, these needs are all > done by any big old relational database companies such as Oracle over > the years as they constantly adopt the changing industry's needs and > cheaper computing power. If you need any relations in your data, you > can't escape relational database model. That is just the cold truth of > math. > > Importat data, such as used in the bank transactions, has relations. > You have to have tight relational definitions and assurance of data > integrity. > > Here's a second hand quote from Microsoft's Technical Fellow David > Campbell. Source > > ? ? I've been doing this database stuff for over 20 years and I > ? ? remember hearing that the object databases were going to wipe out > ? ? the SQL databases. And then a little less than 10 years ago the > ? ? XML databases were going to wipe out.... We actually ... you > ? ? know... people inside Microsoft, [have said] 'let's stop working > ? ? on SQL Server, let's go build a native XML store because in five > ? ? years it's all going....' > > LOL. That's exactly my thought. > > Though, i'd have to have some hands on experience with one of those > new database services to see what it's all about. > > -------------------- > Amazon S3 and Dynamo > > Look at Structured storage. That seems to be what these nosql > databases are. Most are just a key-value pair structure, or just > storage of documents with no relations. I don't see how this differ > from a sql database using one single table as schema. > > Amazon's Amazon S3 is another storage service, which uses Amazon's > Dynamo (storage system), indicated by Wikipedia to be one of those > NoSQL db. Looking at the S3 and Dynamo articles, it appears the db is > just a Distributed hash table system, with added http access > interface. So, basically, little or no relations. Again, i don't see > how this is different from, say, MySQL with one single table of 2 > columns, added with distributed infrastructure. (distributed database > is often a integrated feature of commercial dbs, e.g. Wikipedia Oracle > database article cites Oracle Real Application Clusters ) > > Here's a interesting quote on S3: > > ? ? Bucket names and keys are chosen so that objects are addressable > ? ? using HTTP URLs: > > ? ? ? ? *http://s3.amazonaws.com/bucket/key > ? ? ? ? *http://bucket.s3.amazonaws.com/key > ? ? ? ? *http://bucket/key(where bucket is a DNS CNAME record > pointing to bucket.s3.amazonaws.com) > > ? ? Because objects are accessible by unmodified HTTP clients, S3 can > ? ? be used to replace significant existing (static) web hosting > ? ? infrastructure. > > So this means, for example, i can store all my images in S3, and in my > html document, the inline images are just normal img tags with normal > urls. This applies to any other type of file, pdf, audio, but html > too. So, S3 becomes the web host server as well as the file system. > > Here's Amazon's instruction on how to use it as image server. Seems > quite simple: How to use Amazon S3 for hosting web pages and media > files? Source > > -------------------- > Google BigTable > > Another is Google's BigTable. I can't make much comment. To make a > sensible comment, one must have some experience of actually > implementing a database. For example, a file system is a sort of > database. If i created a scheme that allows me to access my data as > files in NTFS that are distributed over hundreds of PC, communicated > thru http running Apache. This will let me access my files. To insert, > delete, data, one can have cgi scripts on each machine. Would this be > considered as a new fantastic NoNoSQL? > > --------------------- > > comments can also be posted tohttp://xahlee.blogspot.com/2010/01/nosql-movement.html > > Thanks. > > ? Xah > ?http://xahlee.org/ > > ? From moc.liamg at synabp.reverse_the_string Sun Mar 7 19:18:13 2010 From: moc.liamg at synabp.reverse_the_string (=?UTF-8?B?UGF3ZcWCIEJhbnnFmw==?=) Date: Mon, 08 Mar 2010 01:18:13 +0100 Subject: running a program on many processors Message-ID: Hello, I have already read about Python and multiprocessing which allows using many processors. The idea is to split a program into separate tasks and run each of them on a separate processor. However I want to run a Python program doing a single simple task on many processors so that their cumulative power is available to the program as if there was one huge CPU instead of many separate ones. Is it possible? How can it be achieved? Best regards, Pawe? From deets at nospam.web.de Sun Mar 7 19:28:48 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 08 Mar 2010 01:28:48 +0100 Subject: running a program on many processors In-Reply-To: References: Message-ID: <7vium2FgvmU1@mid.uni-berlin.de> Am 08.03.10 01:18, schrieb Pawe? Bany?: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? That's impossible to answer without knowing anything about your actual task. Not everything is parallelizable, or algorithms suffer from penalties if parallelization is overdone. So in essence, what you've read already covers it: if your "simple task" is dividable in several, independent sub-tasks that don't need serialization, multiprocessing is your friend. Diez From g.bogle at auckland.no.spam.ac.nz Sun Mar 7 19:49:07 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 08 Mar 2010 13:49:07 +1300 Subject: running a program on many processors References: Message-ID: Pawe? Bany? wrote: ... How can it be achieved? Very carefully. From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 20:08:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 01:08:32 GMT Subject: running a program on many processors References: Message-ID: <4b944e10$0$8836$c3e8da3@news.astraweb.com> On Mon, 08 Mar 2010 01:18:13 +0100, Pawe? Bany? wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be > achieved? Try Parallel Python. http://www.parallelpython.com/ I haven't used it, but it looks interesting. However, the obligatory warning against premature optimization: any sort of parallel execution (including even lightweight threads) is hard to build and much harder to debug. You should make sure that the potential performance benefits are worth the pain before you embark on the job: are you sure that the naive, single process version isn't fast enough? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 20:14:43 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 01:14:43 GMT Subject: best practices: is collections.defaultdict my friend or not? References: <20100306031003.1018aab2@geekmail.INVALID> <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> Message-ID: <4b944f83$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 09:33:22 +0000, Mark Lawrence wrote: >> I was a little frightened of doing "import this" ("Hey, kid, run rm - >> rf / and see what happens!"), but did, and the words are wise. >> >> Pete > > After reading the words of wisdom try "import this" a second time and > watch what happens, it's quite interesting if you're not expecting the > output. You weren't expecting to get the Python prompt? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 20:46:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 01:46:28 GMT Subject: negative "counts" in collections.Counter? References: Message-ID: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 22:21:27 +0000, Arnaud Delobelle wrote: > Vlastimil Brom writes: > >> Hi all, >> I'd like to ask about the possibility of negative "counts" in >> collections.Counter (using Python 3.1); I believe, my usecase is rather >> trivial, basically I have the word frequencies of two texts and I want >> do compare them (e.g. to see what was added and removed between >> different versions of a text). [...] > Every time I have needed something like collections.Counter, I have > wanted the behaviour you require too. As a result, I have never used > collections.Counter. Instead I have used plain dictionaries or my own > class. Vlastimil and Arnaud, It looks like Counter already has negative counts in Python 3.1: >>> import collections >>> c = collections.Counter({'red': 2, 'green': 0, 'blue': -5}) >>> c['blue'] -= 1 >>> c Counter({'red': 2, 'green': 0, 'blue': -6}) >>> c['blue'] += 1 >>> c Counter({'red': 2, 'green': 0, 'blue': -5}) But the + and - operators destroy negative and zero counts: >>> c + collections.Counter({'blue': 1}) Counter({'red': 2}) I can't imagine what the use-case for that behaviour is. Given that Counter supports negative counts, it looks to me that the behaviour of __add__ and __sub__ is fundamentally flawed. You should raise a bug report (feature enhancement) on the bug tracker. http://bugs.python.org/ Given that this will change the documented behaviour, it will help if you give a short, simple idiom for removing zero and negative elements, Arnaud's trick with | Counter(). When you raise the report, please post an update here. -- Steven From gagsl-py2 at yahoo.com.ar Sun Mar 7 21:00:41 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Mar 2010 23:00:41 -0300 Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach escribi?: > Sorry, as with the places noted above, I can't understand what you're > trying to say here. Regarding your posts, neither can I. All the time. Sorry, deciphering your posts would force me to spend much more time than available and I can't afford that - so I'm blocking your messages from now on. -- Gabriel Genellina From martin.hellwig at dcuktec.org Sun Mar 7 21:08:39 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 02:08:39 +0000 Subject: running a program on many processors In-Reply-To: References: Message-ID: On 03/08/10 00:18, Pawe? Bany? wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? > > Best regards, > > Pawe? As far as I know, the Python VM (cpython) will not analyze your code and automatically spread parts over different processing units. I did read, two years or so ago, that AMD was looking in to something that does just what you say on a cpu level, that is present itself as one logical cpu but underneath there are multiple physical ones. I wouldn't hold my breath though waiting for it. -- mph From monkey at joemoney.net Sun Mar 7 21:10:00 2010 From: monkey at joemoney.net (monkeys paw) Date: Sun, 07 Mar 2010 21:10:00 -0500 Subject: write to remote ile Message-ID: I can xfer a file from a remote server using: import urllib2 as u x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') for line in x: print line How can i write a file to the remote server? I tried: x = u.url.open('http://joemoney.net/somefile.txt', 'w') but that does not work From martin.hellwig at dcuktec.org Sun Mar 7 21:20:20 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 02:20:20 +0000 Subject: write to remote ile In-Reply-To: References: Message-ID: On 03/08/10 02:10, monkeys paw wrote: > I can xfer a file from a remote server using: > > import urllib2 as u > x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') > > for line in x: > print line > > > How can i write a file to the remote server? > > I tried: > > x = u.url.open('http://joemoney.net/somefile.txt', 'w') > > but that does not work How do you normally (i.e. without python) put files on a remote server? -- mph From jmheralds at gmail.com Sun Mar 7 21:32:08 2010 From: jmheralds at gmail.com (James Heralds) Date: Sun, 7 Mar 2010 18:32:08 -0800 (PST) Subject: Call for papers: SETP-10, USA, July 2010 Message-ID: <84762688-eaf6-4e4e-a903-791e7e2bc2c7@j27g2000yqn.googlegroups.com> It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Call for papers: SETP-10, USA, July 2010 The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. ? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) ? International Conference on Automation, Robotics and Control Systems (ARCS-10) ? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) ? International Conference on Computer Communications and Networks (CCN-10) ? International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) ? International Conference on High Performance Computing Systems (HPCS-10) ? International Conference on Information Security and Privacy (ISP-10) ? International Conference on Image and Video Processing and Computer Vision (IVPCV-10) ? International Conference on Software Engineering Theory and Practice (SETP-10) ? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World? Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining ? all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. Sincerely James Heralds From python at bdurham.com Sun Mar 7 21:41:30 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 07 Mar 2010 21:41:30 -0500 Subject: Best practice way to detect internet connectivity under Python 2.6/Windows Message-ID: <1268016090.13219.1363604225@webmail.messagingengine.com> Is the best pratice way to detect internet connectivity under Windows (using Python 2.6) simply to attempt to access a known internet website using urllib or urlib2 wrapped in a try/except construct? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From monkey at joemoney.net Sun Mar 7 21:51:22 2010 From: monkey at joemoney.net (monkeys paw) Date: Sun, 07 Mar 2010 21:51:22 -0500 Subject: write to remote ile In-Reply-To: References: Message-ID: On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: > On 03/08/10 02:10, monkeys paw wrote: >> I can xfer a file from a remote server using: >> >> import urllib2 as u >> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >> >> for line in x: >> print line >> >> >> How can i write a file to the remote server? >> >> I tried: >> >> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >> >> but that does not work > > How do you normally (i.e. without python) put files on a remote server? > Using FTP, i'm really having a brain cramp here, but i'm new to python From martin.hellwig at dcuktec.org Sun Mar 7 21:53:46 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 02:53:46 +0000 Subject: write to remote ile In-Reply-To: References: Message-ID: On 03/08/10 02:51, monkeys paw wrote: > On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: >> On 03/08/10 02:10, monkeys paw wrote: >>> I can xfer a file from a remote server using: >>> >>> import urllib2 as u >>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >>> >>> for line in x: >>> print line >>> >>> >>> How can i write a file to the remote server? >>> >>> I tried: >>> >>> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >>> >>> but that does not work >> >> How do you normally (i.e. without python) put files on a remote server? >> > Using FTP, i'm really having a brain cramp here, but i'm new to python We all been there, in some for or other ;-), anyway you might want to have a look at this: http://docs.python.org/library/ftplib.html -- mph From missive at hotmail.com Sun Mar 7 22:01:02 2010 From: missive at hotmail.com (Lee Harr) Date: Mon, 8 Mar 2010 07:31:02 +0430 Subject: [ANNC] pynguin-0.2 (python turtle graphics application) Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues adding basic functionality and ??? corrects some annoyances. If you are interested, ??? please take a look and let me know what you think. Pynguin is tested with Python 2.6.4 and uses PyQt (4.6) ??? for its GUI elements. Pynguin is released under GPLv3. Changes in pynguin-0.2: ??? - added fill mode ??? - added basic auto-indent in editor ??? - added quick links to recent documents ??? - added quick links to example files ??? - even out speeds when drawing short line segments ??? - added animated circle drawing ??? - now exports entire drawing, even if not visible on screen ??? - fixed initial drawing speed to match menu ??? - fixed-width fonts in editor and interactive interpreter ??? - added classic turtle image ??? - file browser now starts in user's home directory ??? - removed scrollbars on graphic view ??? - now extends lines when animating _________________________________________________________________ Hotmail: Trusted email with Microsoft?s powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 From greg.ewing at canterbury.ac.nz Sun Mar 7 22:09:12 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 08 Mar 2010 16:09:12 +1300 Subject: Reverse engineering CRC? Message-ID: <7vj7fdFnnjU1@mid.individual.net> Given some known data/crc pairs, how feasible is it to figure out the polynomial being used to generate the crc? In the case I'm looking at, it appears that the crc size may be at least 24 bits, so just trying all possible polynomials probably isn't doable. An article I found hints at the possibility of using GCDs to make the search more efficient, but doesn't go into any details. Anyone know of any literature about this? If it helps, I have the ability to generate test cases with known message contents to some extent, although I don't have complete control over the contents. Also it's a manual process, so generating large numbers of them automatically isn't an option. -- Greg From python at bdurham.com Sun Mar 7 22:09:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 07 Mar 2010 22:09:44 -0500 Subject: IMAP mail filters tool In-Reply-To: <4B9097A6.2050600@seehart.com> References: <4B9097A6.2050600@seehart.com> Message-ID: <1268017784.16962.1363607281@webmail.messagingengine.com> Ken, Check out Zed Shaw's very cool Lamson project. http://lamsonproject.org/ Malcolm ----- Original message ----- From: "Ken Seehart" To: python-list at python.org Date: Thu, 04 Mar 2010 21:33:26 -0800 Subject: IMAP mail filters tool I'm thinking of possibly making a simple client-agnostic tool for filtering and processing IMAP email. I'm a Thunderbird user, but I'm interested in a tool that is not client software specific. So I am is checking for prior art. Does anyone know of a filter tool with most of these features? * Written and customizable with python * IMAP based * Runs on client (i.e. without installing anything on the server) * Runs completely independent of client software (though could be launched from any email client that can support it) * Automatically suggests new rules based on manual movement of emails into folders (based on comparison of all header data across all existing folders) * Take arbitrary actions in response to rules (e.g. universally denying access to spam senders to all online cheese shops) * Capable of serving as a prototyping framework for things like spam filtering * General filtering functionality, not particularly focused on spam * Posts and updates rules to server via IMAP (i.e. by sending and automagically processing a special email message). Typical work-flow would be aimed at users who like to automatically sort their email prior to reading it. The goal is to have nearly all email sorted into folders so that most mail remaining in the Inbox is likely to be leftover spam missed by whatever spam filters are being used. In other words, the filters tend to effectively serve as white lists. Examples of unusual rules that don't seem to be supported by most email clients: * When you send an email, add the recipient to a filter such that email from that recipient goes to a "Unfiltered Replies" folder if it does not match any other filter. * Receiving email with certain fields matching certain regular expressions could automatically create a new folder and filter e.g.: + List-Id: "SF Bay Area Python group " yields a new folder "Lists/SF Bay Area Python group" with a corresponding rule + X-Launchpad-Bug: "product=phatch; milestone=..." yields a new folder "Bugs/Phatch" with a corresponding rule + X-Bugzilla-Product: "Shrubbery" yields a new folder "Bugs/Shrubbery" with a corresponding rule Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 22:41:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 03:41:35 GMT Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <4b9471ee$0$8836$c3e8da3@news.astraweb.com> On Mon, 08 Mar 2010 16:09:12 +1300, Gregory Ewing wrote: > Given some known data/crc pairs, how feasible is it to figure out the > polynomial being used to generate the crc? Can you just ask the application developer what CRC is being used? Or look at the source code? Disassemble the binary? > In the case I'm looking at, it appears that the crc size may be at least > 24 bits, so just trying all possible polynomials probably isn't doable. "At least"? Can't you tell by looking at them? A good place to start is here: http://en.wikipedia.org/wiki/Cyclic_redundancy_check http://en.wikipedia.org/wiki/List_of_checksum_algorithms You can at least eliminate known CRCs. There doesn't appear to be any 24- bit CRCs in common use, and very few other 24-bit checksums either, so you're probably looking at a custom CRC. > An article I found hints at the possibility of using GCDs to make the > search more efficient, but doesn't go into any details. Anyone know of > any literature about this? If you're reduced to trying to determine the polynomial from a sample of checksums, that's a curve fitting problem. There are various ways to fit polynomials through a set of known points, but as far as I know none of them are designed for reverse-engineering CRCs. You may be able to find something about curve-fitting using discrete maths (i.e. where all values are limited to integers) or with constraints. You should probably take this to somewhere like sci.crypt. Here's a thread from a few years back which might give you some hints: http://www.derkeiler.com/Newsgroups/sci.crypt/2008-07/msg00035.html Or here: http://stackoverflow.com/questions/401231/determining-crc-algorithm-from- data-crc-embedded-application -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 22:44:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 03:44:24 GMT Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <4b947298$0$8836$c3e8da3@news.astraweb.com> On Mon, 08 Mar 2010 16:09:12 +1300, Gregory Ewing wrote: > Given some known data/crc pairs, how feasible is it to figure out the > polynomial being used to generate the crc? Google is your friend: http://www.woodmann.com/fravia/crctut1.htm -- Steven From satishgroups1 at gmail.com Sun Mar 7 23:43:09 2010 From: satishgroups1 at gmail.com (satish groups) Date: Sun, 7 Mar 2010 20:43:09 -0800 (PST) Subject: Evaluating Income Property Message-ID: <3b8d2ac9-5e77-4910-9774-203cf1c6cd29@s25g2000prd.googlegroups.com> Income property is becoming more attractive to investors looking for a better return on their money. With today's low interest rates, income- producing properties such as apartments and duplexes can produce exciting returns. As with any type of property, the value of income property is what someone is willing to pay for it. But, the main determinant of value for income property is the net income it will produce. As we'll see later, the income approach should closely correlate with the market value under normal market conditions. Buyers of residential income property will want to know the answers to several questions not normally asked by home buyers. First, what is the amount of cash flow the property will generate? Second, how much actual net income will it produce? Third, are the tax benefits that the property will provide the investor? Cash flow can be described as the amount of money collected as rental income each month. http://greatincomeproperties.com/ From dr.cg at 126.com Mon Mar 8 00:08:56 2010 From: dr.cg at 126.com (CHEN Guang) Date: Mon, 8 Mar 2010 13:08:56 +0800 (CST) Subject: The C language like the Python, by the Python and for the Python --- PythoidC Message-ID: <1f91f2e.86f9.1273c2d0993.Coremail.dr.cg@126.com> Hi, if you are interested in C-Python mixed programming, please take a look at: http://pythoidc.googlecode.com PythoidC is the C language like the Python, by the Python and for the Python import c c.include(c.h.stdio) c.include(c.h.stdlib) '''Annotation is free!''' int fib(int n): if(n<=2): return1 else: return fib(n-1)+ fib(n-2) int main(int argc,char**argv): int n //C style annotation n=c.stdlib.atoi(argv[1]) c.stdio.printf('fibonacci(%d)=%d\n', n, fib(n)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Mon Mar 8 01:31:00 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 7 Mar 2010 22:31:00 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: On Mar 7, 5:46?pm, Steven D'Aprano wrote: > Given that Counter supports negative counts, it looks to me that the > behaviour of __add__ and __sub__ is fundamentally flawed. You should > raise a bug report (feature enhancement) on the bug tracker. It isn't a bug. I designed it that way. There were several possible design choices, each benefitting different use cases. FWIW, here is the reasoning behind the design. The basic approach to Counter() is to be a dict subclass that supplies zero for missing values. This approach places almost no restrictions on what can be stored in it. You can store floats, decimals, fractions, etc. Numbers can be positive, negative, or zero. This design leaves users with a good deal of flexibility, but more importantly it keeps the API very close to regular dictionaries (thus lowering the learning curve). It also makes basic counter operations very fast. The update() method differs from regular dictionaries because dict.update() isn't very helpful in a counter context. Instead, it allows one counter to update another. Like the other basic counter operations, it places no restrictions on type (i.e. it works on with ints, floats, decimals, fractions, etc). or on sign (positive, negative, or zero). The only requirement is that the values support addition. The basic API also adds some convenience methods. The most_common() method tries to not be restrictive. It only requires the count values be orderable. For obvious reasons, the elements() method *does* have restrictions and won't work with float values and won't emit entries with non-positive counts. Beyond the basic API listed above which is straight-forward, the area where there were more interesting design choices were the Counter-to-Counter operations (__add__, __sub__, __or__, and __and__). One possible choice (the one preferred by the OP) was to has addition and subtraction be straight adds and subtracts without respect to sign and to not support __and__ and __or__. Straight addition was already supported via the update() method. But no direct support was provided for straight subtractions that leave negative values. Sorry about that. Instead the choice was to implement the four methods as multiset operations. As such, they need to correspond to regular set operations. For example, with sets: set('abc') - set('cde') # gives set('ab') Notice how subtracting 'e' did not produce a negative result? Now with multisets, we want the same result: Counter({'a':1, 'b':1, 'c':1'}) - Counter({'c':1, 'd':1, 'e':1}) So the design decision was to support multiset operations that produces only results with positive counts. These multiset-style mathematical operations are discussed in: Knuth's TAOCP Volume II section 4.6.3 exercise 19 and at http://en.wikipedia.org/wiki/Multiset . Also C++ has multisets that support only positive counts. So, there you have it. There design tries to be as unrestrictive as possible. When a choice had to be made, it favored multisets over behaviors supporting negative values. Fortunately, it is trivially easy to extend the class to add any behavior you want. class MyCounter(Counter): def __sub__(self, other): result = self.copy() for elem, cnt in other.items(): result[elem] -= cnt Hopes this gives you some insight into the design choices. Raymond Hettinger From stefan_ml at behnel.de Mon Mar 8 02:08:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Mar 2010 08:08:35 +0100 Subject: The C language like the Python, by the Python and for the Python --- PythoidC In-Reply-To: <1f91f2e.86f9.1273c2d0993.Coremail.dr.cg@126.com> References: <1f91f2e.86f9.1273c2d0993.Coremail.dr.cg@126.com> Message-ID: CHEN Guang, 08.03.2010 06:08: > Hi, if you are interested in C-Python mixed programming, please take a look at: > http://pythoidc.googlecode.com > PythoidC is the C language like the Python, by the Python and for the Python It looks a bit dangerous to me to parse C header files only with regular expressions. For Cython, some people seem to be using gcc-xml instead, and some have reported that clang is really nice to play with. However, none of those has made its way into Cython yet, mostly due to the dependency it would add. I don't know if tcc (which you seem to depend on) has anything comparable, but I doubt it. Just out of curiosity, is this syntax converter actually used for any real projects? Stefan From miraclesoul at hotmail.com Mon Mar 8 02:15:18 2010 From: miraclesoul at hotmail.com (Fahad Ahmad) Date: Mon, 8 Mar 2010 07:15:18 +0000 Subject: Calculating very large exponents in python In-Reply-To: References: , Message-ID: Thanks Geremy, That has been an absolute bump........... GOD i cant sit on my chair, it has worked even on 512 bit number and with no time.......... superb i would say. lastly, i am using the code below to calculate Largest Prime factor of a number: print ('''===============================================================================''' ''' CALCULATE HIGHEST PRIME FACTOR ''' '''===============================================================================''') #!/usr/bin/env python def highest_prime_factor(n): if isprime(n): return n for x in xrange(2,n ** 0.5 + 1): if not n % x: return highest_prime_factor(n/x) def isprime(n): for x in xrange(2,n ** 0.5 + 1): if not n % x: return False return True if __name__ == "__main__": import time start = time.time() print highest_prime_factor(1238162376372637826) print time.time() - start the code works with a bit of delay on the number : "1238162376372637826" but extending it to (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) makes python go crazy. Is there any way just like above, i can have it calculated it in no time. thanks for the support. > Date: Sun, 7 Mar 2010 15:40:59 -0500 > Subject: Re: Calculating very large exponents in python > From: debatem1 at gmail.com > To: miraclesoul at hotmail.com > CC: python-list at python.org > > On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad wrote: > > Dear All, > > > > i am writing my crytographic scheme in python, i am just a new user to it. > > I have written the complete code, the only point i am stuck it is that i am > > using 256 exponentiation which is normal in crytography but python just > > hangs on it. > > > > g**x [where both g and x are 256 bit numbers , in decimal they are around > > 77] > > > > after reading several forums, i just come to know it can be done using > > numpy, i have installed python(x,y) has has both numpy and scipy installed > > but i am not able to make it happen. > > > > any idea which library, module, or piece of code can solve this mystery :S > > > > sorry for bad english > > A couple of things: > > 1) if you're working with modular exponentiation, remember that pow() takes > three arguments, ie: > > a = 222222222222222222222222222 > b = 5555555555555555555555555555 > pow(a, b, 1200) > > will calculate the correct answer (768) very quickly, while > > a**b % 1200 > > has not terminated in the time it took me to compose this > email. > > 2) sage has a lot of excellent tools for crypto/cryptanalysis that you > may want to take a look at. > > 3) not saying you don't know what you're doing, but be careful when > rolling your own cryptosystems- even very good cryptographers make > implementation mistakes! > > Geremy Condra _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. http://clk.atdmt.com/GBL/go/201469230/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Mon Mar 8 02:38:55 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Mar 2010 08:38:55 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Gabriel Genellina: > En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach > escribi?: > >> Sorry, as with the places noted above, I can't understand what you're >> trying to say here. > > Regarding your posts, neither can I. All the time. Sorry, deciphering > your posts would force me to spend much more time than available and I > can't afford that - so I'm blocking your messages from now on. You could just ask if there was anything you didn't understand. Even with as little you quote readers can see my approach to that problem: asking. But your response, both the out of context quoting and your comment, seems solely designed to convey a negative impression instead of addressing any technical issue. Cheers, - Alf From stefan_ml at behnel.de Mon Mar 8 02:42:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Mar 2010 08:42:38 +0100 Subject: running a program on many processors In-Reply-To: References: Message-ID: Martin P. Hellwig, 08.03.2010 03:08: > I did read, two years or so ago, that AMD was looking in to something > that does just what you say on a cpu level, that is present itself as > one logical cpu but underneath there are multiple physical ones. I > wouldn't hold my breath though waiting for it. Many (desktop/server) CPUs actually do the opposite today - they present themselves as one physical CPU per core with more than one (commonly two) logical CPUs. This was introduced because modern CPUs have so many independent parts (integer arithmetic, floating point, SSE, memory access) that it's hard to keep all of them busy with a single process (which usually does either integer arithmetic *or* floating point, for example, rarely both in parallel). With multiple processes running on the same core, it becomes a lot easier to find independent operations that can be sent to different parts of the core in parallel. Automatically splitting single-threaded code over multiple cores is something that compilers (that see the full source code) should be able to do a lot better than hardware (which only sees a couple of basic operations at a time). http://en.wikipedia.org/wiki/Vectorization_%28computer_science%29 Expecting this to work for an interpreted Python program is somewhat unrealistic, IMHO. If you need data parallel execution, use something like map-reduce or Copperhead instead of relying on the CPU to figure out what's happening inside of a virtual machine. http://fperez.org/py4science/ucb/talks/20091118_copperhead_bcatanzaro.pdf Stefan From taskinoor.hasan at csebuet.org Mon Mar 8 02:48:00 2010 From: taskinoor.hasan at csebuet.org (Taskinoor Hasan) Date: Mon, 8 Mar 2010 13:48:00 +0600 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: <79153a2e1003072348r16fd4427i7ea2b3fbdd626c91@mail.gmail.com> First of all, you simply can't use this straight approach of primality testing for very very big numbers. There are a number of algorithms, both deterministic and random. Please Google for them (and don't forget to check Wikipedia too). Study the random algorithms to check whether they can be applied in your situation, since they are faster. And another implementation issue. Try to avoid many recursive calls. It's always possible to convert a recursive function to a non-recursive one and that will be faster if your recursion is too long. Hope it helps. Regards Taskinoor Hasan (Sajid) On Mon, Mar 8, 2010 at 1:15 PM, Fahad Ahmad wrote: > Thanks Geremy, > > That has been an absolute bump........... GOD i cant sit on my chair, it > has worked even on 512 bit number and with no time.......... > superb i would say. > > lastly, i am using the code below to calculate Largest Prime factor of a > number: > > print > ('''===============================================================================''' > ''' CALCULATE HIGHEST PRIME > FACTOR ''' > > '''===============================================================================''') > > #!/usr/bin/env python > def highest_prime_factor(n): > if isprime(n): > return n > for x in xrange(2,n ** 0.5 + 1): > if not n % x: > return highest_prime_factor(n/x) > def isprime(n): > for x in xrange(2,n ** 0.5 + 1): > if not n % x: > return False > return True > if __name__ == "__main__": > import time > start = time.time() > print highest_prime_factor(1238162376372637826) > print time.time() - start > > the code works with a bit of delay on the number : "1238162376372637826" > but extending it to > (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) > makes python go crazy. Is there any way just like above, i can have it > calculated it in no time. > > > thanks for the support. > > > > > > Date: Sun, 7 Mar 2010 15:40:59 -0500 > > Subject: Re: Calculating very large exponents in python > > From: debatem1 at gmail.com > > To: miraclesoul at hotmail.com > > CC: python-list at python.org > > > > > On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad > wrote: > > > Dear All, > > > > > > i am writing my crytographic scheme in python, i am just a new user to > it. > > > I have written the complete code, the only point i am stuck it is that > i am > > > using 256 exponentiation which is normal in crytography but python just > > > hangs on it. > > > > > > g**x [where both g and x are 256 bit numbers , in decimal they are > around > > > 77] > > > > > > after reading several forums, i just come to know it can be done using > > > numpy, i have installed python(x,y) has has both numpy and scipy > installed > > > but i am not able to make it happen. > > > > > > any idea which library, module, or piece of code can solve this mystery > :S > > > > > > sorry for bad english > > > > A couple of things: > > > > 1) if you're working with modular exponentiation, remember that pow() > takes > > three arguments, ie: > > > > a = 222222222222222222222222222 > > b = 5555555555555555555555555555 > > pow(a, b, 1200) > > > > will calculate the correct answer (768) very quickly, while > > > > a**b % 1200 > > > > has not terminated in the time it took me to compose this > > email. > > > > 2) sage has a lot of excellent tools for crypto/cryptanalysis that you > > may want to take a look at. > > > > 3) not saying you don't know what you're doing, but be careful when > > rolling your own cryptosystems- even very good cryptographers make > > implementation mistakes! > > > > Geremy Condra > > ------------------------------ > Hotmail: Powerful Free email with security by Microsoft. Get it now. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.cg at 126.com Mon Mar 8 03:49:15 2010 From: dr.cg at 126.com (CHEN Guang) Date: Mon, 8 Mar 2010 16:49:15 +0800 (CST) Subject: The C language like the Python, by the Python and for the Python--- PythoidC In-Reply-To: References: Message-ID: <195722f.da8d.1273cf6bb23.Coremail.dr.cg@126.com> Dear Stefan, Thanks a lot for your interest in PythoidC. Yes, PythoidC takes regular expression to parse C header files, but there is no danger at all, because, the parsed result is only used for introspecting and auto-completion, has noting to do with syntax converting and compiling. I just improved PythoidC to a satisfying version for me, up to now, all the projects with PythoidC are experimental or educational. PythoidC is mainly used to deal with simple but time consuming tasks in Python project, as you see, PythoidC file can be imported the same any Python files. Oliver ( ChenGuang ) ? CHEN Guang, 08.03.2010 06:08: > Hi, if you are interested in C-Python mixed programming, please take a look at: > http://pythoidc.googlecode.com > PythoidC is the C language like the Python, by the Python and for the Python It looks a bit dangerous to me to parse C header files only with regular expressions. For Cython, some people seem to be using gcc-xml instead, and some have reported that clang is really nice to play with. However, none of those has made its way into Cython yet, mostly due to the dependency it would add. I don't know if tcc (which you seem to depend on) has anything comparable, but I doubt it. Just out of curiosity, is this syntax converter actually used for any real projects? Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 8 03:53:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 08 Mar 2010 09:53:47 +0100 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4b94baf3$0$20649$426a74cc@news.free.fr> Rolando Espinoza La Fuente a ?crit : > On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >> Arnaud Delobelle wrote: >> >>>>>> 1 == True >>> True >>>>>> 0 == False >>> True >>> >>> So what's your question? >> Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, >> but not in Python.. Although I can understand the rationale after skimming >> PEP 285, I still don't like it very much. >> > > So, the pythonic way to check for True/False should be: > >>>> 1 is True > False > >>>> 0 is False > False > > instead of ==, right? Nope. The pythonic way is to check for truth value - not for True or False -, and to only use the identity test when wanting to test for identity. From fox.joe87 at gmail.com Mon Mar 8 03:59:14 2010 From: fox.joe87 at gmail.com (Mahesh) Date: Mon, 8 Mar 2010 00:59:14 -0800 (PST) Subject: libc Sleep api performs a busy waiting Message-ID: Hi, I am having a problem while using sleep function from libc , the thread in which i am calling it is getting struck and not allowing other threads to execute. Here is a simple code that i am trying to exeute import threading import time import dl def dummy1(): a=dl.open('/lib/libc.so.6') print "in thread 1 Start" a.call('sleep',2) #time.sleep(2) print "in thread 1 End" def dummy2(): print "in thread 2 Start" time.sleep(1) print "in thread 2 End" newThread1=threading.Thread(None,dummy1) newThread2=threading.Thread(None,dummy2) newThread1.start() newThread2.start() print "in main" The out put of this program is (In this case thread 1 even though i am calling a sleep function its not allowing other threads to execute, other threads execute only after the completion of first thread) in thread 1 Start in thread 1 End in thread 2 Start in main in thread 2 End where as if i use time.sleep instead of a.call(sleep) the out put is (which i guess is right behaviour, because it start the threads and suspends them because the have sleep , and continue executing the main thread) in thread 1 Start in thread 2 Start in main in thread 2 End in thread 1 End From processor.dev1l at gmail.com Mon Mar 8 04:26:58 2010 From: processor.dev1l at gmail.com (Processor-Dev1l) Date: Mon, 8 Mar 2010 01:26:58 -0800 (PST) Subject: running a program on many processors References: Message-ID: <112ea184-1e81-45aa-b5ed-73d6ded7a460@d2g2000yqa.googlegroups.com> On Mar 8, 1:18?am, Pawe? Bany? wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? > > Best regards, > > Pawe? I can suggest you to try some .NET language (like c#, Boo <-- python- like, or maybe even IronPython). Reason is that .NET languages do analyze the code and split them into logical parts that run across threads. From fox.joe87 at gmail.com Mon Mar 8 04:30:45 2010 From: fox.joe87 at gmail.com (Joe Fox) Date: Mon, 8 Mar 2010 15:00:45 +0530 Subject: libc Sleep api performs a busy waiting Message-ID: <27e52ad11003080130v7664d951p3ba92bd692efe0ad@mail.gmail.com> Hi , I am having a problem while using sleep function from libc , the thread in which i am calling it is getting struck and not allowing other threads to execute. Here is a simple code that i am trying to exeute import threading import time import dl def dummy1(): a=dl.open('/lib/libc.so.6') print "in thread 1 Start" a.call('sleep',2) #time.sleep(2) print "in thread 1 End" def dummy2(): print "in thread 2 Start" time.sleep(1) print "in thread 2 End" newThread1=threading.Thread(None,dummy1) newThread2=threading.Thread(None,dummy2) newThread1.start() newThread2.start() print "in main" The out put of this program is (In this case thread 1 even though i am calling a sleep function its not allowing other threads to execute, other threads execute only after the completion of first thread) in thread 1 Start in thread 1 End in thread 2 Start in main in thread 2 End where as if i use time.sleep instead of a.call(sleep) the out put is (which i guess is right behaviour, because it start the threads and suspends them because the have sleep , and continue executing the main thread) in thread 1 Start in thread 2 Start in main in thread 2 End in thread 1 End Can any of you point me how to over come this.? Thanks Mahesh -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Mon Mar 8 05:13:09 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Mar 2010 05:13:09 -0500 Subject: Reverse engineering CRC? In-Reply-To: <4b947298$0$8836$c3e8da3@news.astraweb.com> References: <7vj7fdFnnjU1@mid.individual.net> <4b947298$0$8836$c3e8da3@news.astraweb.com> Message-ID: <4B94CDB5.9010506@ieee.org> Steven D'Aprano wrote: > On Mon, 08 Mar 2010 16:09:12 +1300, Gregory Ewing wrote: > > >> Given some known data/crc pairs, how feasible is it to figure out the >> polynomial being used to generate the crc? >> > > Google is your friend: > > http://www.woodmann.com/fravia/crctut1.htm > > That page was interesting to read, especially since I've implemented the three algorithms - CRC16, CRC32, and the reversed version of CRC16, all in the long-distant past. However, if there's anything in there about how to derive the polynomial algorithm from (a few) samples I missed it entirely. Instead, what it calls reverse engineering is figuring out how to modify a message to force it to have a desired CRC value (when the CRC polynomial is already known). DaveA From mail at timgolden.me.uk Mon Mar 8 05:38:52 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Mar 2010 10:38:52 +0000 Subject: Best practice way to detect internet connectivity under Python 2.6/Windows In-Reply-To: <1268016090.13219.1363604225@webmail.messagingengine.com> References: <1268016090.13219.1363604225@webmail.messagingengine.com> Message-ID: <4B94D3BC.8040808@timgolden.me.uk> On 08/03/2010 02:41, python at bdurham.com wrote: > Is the best pratice way to detect internet connectivity under > Windows (using Python 2.6) simply to attempt to access a known > internet website using urllib or urlib2 wrapped in a try/except > construct? Well, in theory you could use the Internet API: http://msdn.microsoft.com/en-us/library/aa383996%28VS.85%29.aspx which is exposed via the win32inet module: http://timgolden.me.uk/pywin32-docs/win32inet.html but I'd just do a socket connection to port 80 (or some known port on some known server) with a reasonable timeout. TJG From fetchinson at googlemail.com Mon Mar 8 05:53:25 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 8 Mar 2010 11:53:25 +0100 Subject: Curiosity stirkes me on 'import this'. In-Reply-To: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> References: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> Message-ID: > I took a look at the 'this' module to see where the file is stored. This is > probably old news to some people, but was new to me. > > print this.s > Gur Mra bs Clguba, ol Gvz Crgref > > Ornhgvshy vf orggre guna htyl. > Rkcyvpvg vf orggre guna vzcyvpvg. > Fvzcyr vf orggre guna pbzcyrk. > Pbzcyrk vf orggre guna pbzcyvpngrq. > Syng vf orggre guna arfgrq. > Fcnefr vf orggre guna qrafr. > Ernqnovyvgl pbhagf. > Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf. > Nygubhtu cenpgvpnyvgl orngf chevgl. > Reebef fubhyq arire cnff fvyragyl. > Hayrff rkcyvpvgyl fvyraprq. > Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff. > Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg. > Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu. > Abj vf orggre guna arire. > Nygubhtu arire vf bsgra orggre guna *evtug* abj. > Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn. > Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn. > Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr! > > And some other attributes in 'this' module as well, that decodes the string. > I'm curious. Was this encoded purely for fun? Yes. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From greg.ewing at canterbury.ac.nz Mon Mar 8 06:06:36 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Mar 2010 00:06:36 +1300 Subject: Reverse engineering CRC? In-Reply-To: <4b9471ee$0$8836$c3e8da3@news.astraweb.com> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> Message-ID: <7vk3eiFtivU1@mid.individual.net> Steven D'Aprano wrote: > Can you just ask the application developer what CRC is being used? Or > look at the source code? Disassemble the binary? There's no source, and the binary is enormous. I could ask, but I wouldn't hold out much hope of them being willing to tell me. >>it appears that the crc size may be at least >>24 bits, so just trying all possible polynomials probably isn't doable. > > "At least"? Can't you tell by looking at them? It's not entirely clear exactly which bytes are part of the CRC. There are 3 adjacent bytes in the header of the file that change when I modify the contents, which led me to think it was a 24-bit CRC. But I now believe that one of them is not part of the CRC, and it's actually 16 bits. Using pycrc, I've now tried all possible 16-bit polynomials, with various combinations of bit and byte reversal, but I haven't found one that works consistently, so I'm wondering whether it's using some non-standard algorithm. -- Greg From vlastimil.brom at gmail.com Mon Mar 8 06:13:31 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 8 Mar 2010 12:13:31 +0100 Subject: negative "counts" in collections.Counter? In-Reply-To: References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <9fdb569a1003080313mf6c8d9cr932678c11c4e80e4@mail.gmail.com> 2010/3/8 Raymond Hettinger : > On Mar 7, 5:46?pm, Steven D'Aprano cybersource.com.au> wrote: >> Given that Counter supports negative counts, it looks to me that the >> behaviour of __add__ and __sub__ is fundamentally flawed. You should >> raise a bug report (feature enhancement) on the bug tracker. > > It isn't a bug. ?I designed it that way. > There were several possible design choices, > each benefitting different use cases. >... > One possible choice (the one preferred by the OP) was to > has addition and subtraction be straight adds and subtracts > without respect to sign and to not support __and__ and __or__. > Straight addition was already supported via the update() method. > But no direct support was provided for straight subtractions > that leave negative values. ?Sorry about that. > > Instead the choice was to implement the four methods as > multiset operations. ?As such, they need to correspond > to regular set operations. ?For example, with sets: > >... > Hopes this gives you some insight into the design choices. > > > Raymond Hettinger > Thank you very much for the exhaustive explanation Raymond! I very much suspected, there would be some exact reasoning behind it, as these negative counts are explicitly handled in the code of these methods. I just happened to expect the straightforward addition and subtraction and possibly the zero truncation or an exception in incompatible cases (like elements() with floats, currently). This way also the negative part would be available and the truncation possible. I am by far not able to follow all of the mathematical background, but even for zero-truncating multiset, I would expect the truncation on input rather than on output of some operations. E.g. the following seems surprising to me in context of the discarded negatives by addition or subtraction: >>> c1=collections.Counter({'a': -11, 'b': -8}) >>> c2=collections.Counter({'a': 3}) >>> c2-c1 Counter({'a': 14, 'b': 8}) >>> Probably a kind of negative_update() or some better named method will be handy, like the one you supplied or simply the current module code without the newcount > 0: ... condition. Or would it be an option to have a keyword argument like zero_truncate=False which would influence this behaviour? Or is some other method than elements() incompatible with negative counts? (I actually can imagine comparing negative counts on both sides. e.g. in a secondary comparison of two wordlists with specific removed items - comparing to the "master" list.) Additionally, were issubset and issuperset considered for this interface (not sure whether symmetric_difference would be applicable)? Anyway, I recognise, that I can easily use a custom class for these tasks, if these usecases are rare or non-standard for this general collection object. Thanks again, vbr From kshipras at packtpub.com Mon Mar 8 06:25:07 2010 From: kshipras at packtpub.com (Kshipra Singh) Date: Mon, 8 Mar 2010 16:55:07 +0530 Subject: Opportunity to author Python books- Packt Publishing. Message-ID: Hi All, I am writing to you for Packt Publishing, the publishers computer related books. We are planning to extend our catalogue of cookbooks and are currently inviting "Python" fanatics interested in writing a cookbook. So, if you love "Python" and are interested in writing a cookbook, please contact us with your book ideas at author at packtpub.com. Even if you do not have a book idea and are simply interested in authoring a cookbook, we are keen to hear from you. More details about the opportunity are available at: http://authors.packtpub.com/content/python-fanatics-invited-write-packt Thanks Kshipra Singh Author Relationship Manager Packt Publishing www.PacktPub.com Skype: kshiprasingh15 Twitter: http://twitter.com/kshipras Interested in becoming an author? Visit http://authors.packtpub.com for all the information you need about writing for Packt. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Mar 8 06:34:11 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 08 Mar 2010 22:34:11 +1100 Subject: Curiosity stirkes me on 'import this'. References: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> Message-ID: <871vfv11zg.fsf@benfinney.id.au> Daniel Fetchinson writes: > > I'm curious. Was this encoded purely for fun? > > Yes. For some more fun, try measuring the ?this? module source code against the principles in the Zen. -- \ ?Leave nothing to chance. Overlook nothing. Combine | `\ contradictory observations. Allow yourself enough time.? | _o__) ?Hippocrates | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Mon Mar 8 07:21:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 12:21:18 GMT Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 22:31:00 -0800, Raymond Hettinger wrote: > On Mar 7, 5:46?pm, Steven D'Aprano cybersource.com.au> wrote: >> Given that Counter supports negative counts, it looks to me that the >> behaviour of __add__ and __sub__ is fundamentally flawed. You should >> raise a bug report (feature enhancement) on the bug tracker. > > It isn't a bug. I designed it that way. There were several possible > design choices, each benefitting different use cases. Thanks for the explanation Raymond. A few comments follow: > FWIW, here is the reasoning behind the design. > > The basic approach to Counter() is to be a dict subclass that supplies > zero for missing values. This approach places almost no restrictions > on what can be stored in it. You can store floats, decimals, fractions, > etc. Numbers can be positive, negative, or zero. Another way of using default values in a dict. That's five that I know of: dict.get, dict.setdefault, dict.pop, collections.defaultdict, and collections.Counter. And the Perl people criticise Python for having "only one way to do it" *wink* (That's not meant as a criticism, merely an observation.) [...] > One possible choice (the one preferred by the OP) was to has addition > and subtraction be straight adds and subtracts without respect to sign > and to not support __and__ and __or__. Straight addition was already > supported via the update() method. But no direct support was provided > for straight subtractions that leave negative values. Sorry about that. Would you consider a feature enhancement adding an additional method, analogous to update(), to perform subtractions? I recognise that it's easy to subclass and do it yourself, but there does seem to be some demand for it, and it is an obvious feature given that Counter does support negative counts. > Instead the choice was to implement the four methods as multiset > operations. As such, they need to correspond to regular set operations. Personally, I think the behaviour of + and - would be far less surprising if the class was called Multiset. Intuitively, one would expect counters to be limited to ints, and to support negative counts when adding and subtracting. In hindsight, do you think that Multiset would have been a better name? -- Steven From steve at holdenweb.com Mon Mar 8 07:28:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Mar 2010 07:28:06 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Gabriel Genellina: >> En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach >> escribi?: >> >>> Sorry, as with the places noted above, I can't understand what you're >>> trying to say here. >> >> Regarding your posts, neither can I. All the time. Sorry, deciphering >> your posts would force me to spend much more time than available and I >> can't afford that - so I'm blocking your messages from now on. > > > You could just ask if there was anything you didn't understand. > > Even with as little you quote readers can see my approach to that > problem: asking. > > But your response, both the out of context quoting and your comment, > seems solely designed to convey a negative impression instead of > addressing any technical issue. > This isn't an isolated case, Alf. Physician, heal thyself. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Mar 8 07:33:57 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Mar 2010 07:33:57 -0500 Subject: libc Sleep api performs a busy waiting In-Reply-To: References: Message-ID: Mahesh wrote: > Hi, > > I am having a problem while using sleep function from libc , the > thread in which i am calling it is getting struck and not allowing > other threads to execute. Here is a simple code that i am trying to > exeute > > import threading > import time > import dl > > > def dummy1(): > a=dl.open('/lib/libc.so.6') > print "in thread 1 Start" > a.call('sleep',2) > #time.sleep(2) > print "in thread 1 End" > > def dummy2(): > print "in thread 2 Start" > time.sleep(1) > print "in thread 2 End" > newThread1=threading.Thread(None,dummy1) > newThread2=threading.Thread(None,dummy2) > newThread1.start() > newThread2.start() > > print "in main" > > > > The out put of this program is (In this case thread 1 even though i > am calling a sleep function its not allowing other threads to execute, > other threads execute only after the completion of first thread) > > in thread 1 Start > in thread 1 End > in thread 2 Start > in main > in thread 2 End > > > where as if i use time.sleep instead of a.call(sleep) the out put is > (which i guess is right behaviour, because it start the threads and > suspends them because the have sleep , and continue executing the main > thread) > in thread 1 Start > in thread 2 Start > in main > in thread 2 End > in thread 1 End > > Why not just use the time module's sleep function? Unlike the libc code it releases Python's GIL (global interpreter lock), thus allowing other threads to run. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Mon Mar 8 08:02:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Mar 2010 14:02:46 +0100 Subject: Conditional based on whether or not a module is being used In-Reply-To: References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: <4B94F576.6050708@sequans.com> Pete Emerson wrote: > On Mar 5, 1:14 pm, Chris Rebert wrote: > >> On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: >> >>> On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: >>> >>>> On 3/5/10, Pete Emerson wrote: >>>> >>>>> In a module, how do I create a conditional that will do something >>>>> based on whether or not another module has been loaded? >>>>> >> >> >>>>> If someone is using foo module, I want to take advantage of its >>>>> features and use it in foobar, otherwise, I want to do something else. >>>>> In other words, I don't want to create a dependency of foobar on foo. >>>>> >>>>> My failed search for solving this makes me wonder if I'm approaching >>>>> this all wrong. >>>>> >>>> Just try importing foo, and then catch the exception if it's not installed. >>>> >> >> >>> Except I want to use the module only if the main program is using it >>> too, not just if it's available for use. I think that I found a way in >>> my follow-up post to my own message, but not sure it's the best way or >>> conventional. >>> >> What is your use case for this behavior exactly? You've piqued my curiosity. >> >> Cheers, >> Chris >> --http://blog.rebertia.com >> > > I have written my first module called "logger" that logs to syslog via > the syslog module but also allows for logging to STDOUT in debug mode > at multiple levels (to increase verbosity depending on one's need), or > both. I've looked at the logging module and while it might suit my > needs, it's overkill for me right now (I'm still *very* much a python > newbie). > > I want to write other modules, and my thinking is that it makes sense > for those modules to use the "logger" module to do the logging, if and > only if the parent using the other modules is also using the logger > module. > > In other words, I don't want to force someone to use the "logger" > module just so they can use my other modules, even if the "logger" > module is installed ... but I also want to take advantage of it if I'm > using it. > > Now that I've written that, I'm not sure that makes a whole lot of > sense. It seems like I could say, "hey, this person has the 'logger' > module available, let's use it!". > > Thoughts? > The logging module is not overkill, use it. It can be simple if you want it to be, and can be more complex if you need advanced logging features. All the "what if the application is not using my logger module" is dealt with by the logging module. And I'm not its designer in any way, so my advice is completely objective :-) It's definitely worth spending some time ramping up with it. JM From davea at ieee.org Mon Mar 8 08:07:27 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Mar 2010 08:07:27 -0500 Subject: Reverse engineering CRC? In-Reply-To: <7vk3eiFtivU1@mid.individual.net> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> Message-ID: <4B94F68F.3000100@ieee.org> Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Can you just ask the application developer what CRC is being used? Or >> look at the source code? Disassemble the binary? > > There's no source, and the binary is enormous. I could ask, > but I wouldn't hold out much hope of them being willing to > tell me. > >>> it appears that the crc size may be at least >>> 24 bits, so just trying all possible polynomials probably isn't doable. >> >> "At least"? Can't you tell by looking at them? > > It's not entirely clear exactly which bytes are part of the > CRC. There are 3 adjacent bytes in the header of the file > that change when I modify the contents, which led me to > think it was a 24-bit CRC. But I now believe that one of > them is not part of the CRC, and it's actually 16 bits. > > Using pycrc, I've now tried all possible 16-bit polynomials, > with various combinations of bit and byte reversal, but I > haven't found one that works consistently, so I'm wondering > whether it's using some non-standard algorithm. > Or even some other standard algorithm. If you know so little about the value, how do you even know it's a CRC ? Could it be a ones-complement sum, such as used in Ethernet? Is the problem really worth it? The possibilities are practically unbounded. And if the developer is really determined to make it difficult, they could be doing multiple passes over the data, in which case probably disassembly (or subtle debug tracing) may be your best bet. DaveA Dave From jeanmichel at sequans.com Mon Mar 8 08:10:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Mar 2010 14:10:48 +0100 Subject: Import problem In-Reply-To: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4B94F758.9080101@sequans.com> Johny wrote: > I have this directory structure > > C: > \A > __init__.py > amodule.py > > \B > __init__.py > bmodule.py > > \D > __init__.py > dmodule.py > > and I want to import bmodule.py > C:\>cd \ > > C:\>python > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> from A.B import bmodule >>>> > I am bmodule > > C:\> > > so far so good. Now I would like to import bmodule but if the current > directory is \D subdirectory. > > C:> cd \A\B\D > C:\A\B\D> > C:\A\B\D>python > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sys >>>> sys.path.append('C:\\A') >>>> from A.B import bmodule >>>> > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named A.B > > C:\> > > so I can not import a module from the parent directory? Or where did I > make an error? > Thanks for help > > L. > try import sys sys.path.append('C:\\') from A.B import bmodule JM From earnmoney9421 at gmail.com Mon Mar 8 08:40:03 2010 From: earnmoney9421 at gmail.com (Google Adsense) Date: Mon, 8 Mar 2010 05:40:03 -0800 (PST) Subject: What to do if anything bites. Message-ID: What to do if anything bites. Check our bites treatment at http://108ambulance.blogspot.com/2010/03/108-ambulance-home-page.html From aotto1968 at users.sourceforge.net Mon Mar 8 08:43:46 2010 From: aotto1968 at users.sourceforge.net (Andreas Otto) Date: Mon, 08 Mar 2010 14:43:46 +0100 Subject: ANNOUNCE: Major Feature Release - NHI1-0.7, PLMK-1.6 and libmsgque-4.5 Message-ID: Dear User, ANNOUNCE: Major Feature Release ==================================== libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, TCL, PERL, PYTHON, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 SUMMARY ======= This is a 'major-feature-release' to add 'longtime-transaction' support. A 'longtime-transaction' is a transaction with a possible infinite time period between the start and the end. A 'longtime-transaction' is always a 'persistent-transaction' too. The 'persistent' support is available as an in-memory solution on the 'application-server' or in an additional 'bidirectional-filter' available for the next release. A typical scenario for a 'longtime-transaction' is: * A user with a client connect to the server and start a 'longtime-transaction' job. After a while the user shutdown the client and leave the office. At the next morning the user start the client again and the results are send from the server to the client. * On a space mission the time-overhead between transaction start and end is large. It is usually not possible to keep the client-server-connection open all the time. * On a military action-system the enemy try to interrupted the client-server-connection to disable data communication. To use a 'longtime-transaction' the results are send to a 'client-service' registered with MqServiceCreate. This service and addtional data (I call this data 'local-context-data') have to be added to the 'longterm-transaction' package to be available in the result. On the 'link-target' the 'local-context-data' is initial stripped from the 'data-package' and is later added to the results again. The 'local-context-data' is added to the 'data-package' with MqSendT_START and MqSendT_END. The 'local-context-data' is read from the 'data-package' with MqReadT_START and MqReadT_END. LINKS ===== libmsgque: > http://nhi1.berlios.de/theLink/index.htm NHI1: > http://nhi1.berlios.de/ DOWNLOAD: > http://developer.berlios.de/projects/nhi1/ mfg Andreas Otto (aotto1968) From ssteinerx at gmail.com Mon Mar 8 09:03:21 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 8 Mar 2010 09:03:21 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <759A6420-DC8E-4282-8667-6C851D5E0AC8@gmail.com> On Mar 8, 2010, at 7:28 AM, Steve Holden wrote: >> >> But your response, both the out of context quoting and your comment, >> seems solely designed to convey a negative impression instead of >> addressing any technical issue. >> > This isn't an isolated case, Alf. Physician, heal thyself. As far as I can tell, this happens on every thread Alf is involved in at one point or another. I'm sure it's "everyone else." S From xahlee at gmail.com Mon Mar 8 10:12:05 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 8 Mar 2010 07:12:05 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> Message-ID: <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> many people mentioned scalibility... though i think it is fruitful to talk about at what size is the NoSQL databases offer better scalability than SQL databases. For example, consider, if you are within world's top 100th user of database in terms of database size, such as Google, then it may be that the off-the-shelf tools may be limiting. But how many users really have such massive size of data? note that google's need for database today isn't just a seach engine. It's db size for google search is probably larger than all the rest of search engine company's sizes combined. Plus, there's youtube (vid hosting), gmail, google code (source code hosting), google blog, orkut (social networking), picasa (photo hosting), etc, each are all ranked within top 5 or so with respective competitors in terms of number of accounts... so, google's datasize is probably number one among the world's user of databases, probably double or triple than the second user with the most large datasize. At that point, it seems logical that they need their own db, relational or not. Xah ? http://xahlee.org/ ? On Mar 4, 10:35?pm, John Nagle wrote: > Xah Lee wrote: > > recently i wrote a blog article on The NoSQL Movement > > athttp://xahlee.org/comp/nosql.html > > > i'd like to post it somewhere public to solicit opinions, but in the > > 20 min or so, i couldn't find a proper newsgroup, nor private list > > that my somewhat anti-NoSQL Movement article is fitting. > > ? ? Too much rant, not enough information. > > ? ? There is an argument against using full relational databases for > some large-scale applications, ones where the database is spread over > many machines. ?If the database can be organized so that each transaction > only needs to talk to one database machine, the locking problems become > much simpler. ?That's what BigTable is really about. > > ? ? For many web applications, each user has more or less their own data, > and most database activity is related to a single user. ?Such > applications can easily be scaled up with a system that doesn't > have inter-user links. ?There can still be inter-user references, > but without a consistency guarantee. ?They may lead to dead data, > like Unix/Linux symbolic links. ?This is a mechanism adequate > for most "social networking" sites. > > ? ? There are also some "consistent-eventually" systems, where a query > can see old data. ?For non-critical applications, those can be > very useful. ?This isn't a SQL/NoSQL thing; MySQL asynchronous > replication is a "consistent-eventually" system. ?Wikipedia uses > that for the "special" pages which require database lookups. > > ? ? If you allow general joins across any tables, you have to have all > the very elaborate interlocking mechanisms of a distributed database. > The serious database systems (MySQL Cluster and Oracle, for example) > do offer that, but there are usually > substantial complexity penalties, and the databases have to be carefully > organized to avoid excessive cross-machine locking. ?If you don't need > general joins, a system which doesn't support them is far simpler. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From rolf.oltmans at gmail.com Mon Mar 8 10:36:13 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 8 Mar 2010 07:36:13 -0800 (PST) Subject: Converting HTML to PDF using Python? Message-ID: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> Hi Python superstars, Guys, any ideas on how to convert HTML files to PDF files? Or as an alternative, how to convert HTML files to an image file(jpeg/png/etc)? Ideally, the converted PDF/Image file should like exactly like the way HTML file looks in the browser. I really have no idea about this so I will really appreciate all the help. Thanks in advance and kindly pardon my ignorance. Thanks, Oltmans From clp2 at rebertia.com Mon Mar 8 11:16:45 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Mar 2010 08:16:45 -0800 Subject: negative "counts" in collections.Counter? In-Reply-To: <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> Message-ID: <50697b2c1003080816m46752277of34e9bf4bd9670d6@mail.gmail.com> On Mon, Mar 8, 2010 at 4:21 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sun, 07 Mar 2010 22:31:00 -0800, Raymond Hettinger wrote: >> On Mar 7, 5:46 pm, Steven D'Aprano > cybersource.com.au> wrote: >>> Given that Counter supports negative counts, it looks to me that the >>> behaviour of __add__ and __sub__ is fundamentally flawed. You should >>> raise a bug report (feature enhancement) on the bug tracker. >> >> It isn't a bug. I designed it that way. There were several possible >> design choices, each benefitting different use cases. >> Instead the choice was to implement the four methods as multiset >> operations. As such, they need to correspond to regular set operations. > > Personally, I think the behaviour of + and - would be far less surprising > if the class was called Multiset. Intuitively, one would expect counters > to be limited to ints, and to support negative counts when adding and > subtracting. In hindsight, do you think that Multiset would have been a > better name? Of course I'm not Raymond, but I'd encourage reading the original announcement thread where that and related issues were discussed: http://mail.python.org/pipermail/python-list/2009-January/1189466.html To summarize the arguments against "Multiset": * the API is primarily dict-like, not set-like ** related to this, len() and .items() don't behave in what is arguably an "intuitive" way for multisets * the API allows for negative counts; sets don't normally allow negative multiplicities The same pretty much also goes for why "Bag" wouldn't be an appropriate name. Finally, it leaves the names available for when a proper Bag/Multiset is added. :) Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanelson at gmail.com Mon Mar 8 12:06:25 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Mon, 8 Mar 2010 17:06:25 +0000 Subject: Trouble with quotes Message-ID: Hi, I've written some (primitive) code to parse some apache logfies and establish if apache has appended a session cookie to the end. We're finding that some browsers don't and apache doesn't just append a "-" - it just omits it. It's working fine, but for an edge case: Couldn't match 192.168.1.107 - - [24/Feb/2010:20:30:44 +0100] "GET http://sekrit.com/node/175523 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:31:15 +0100] "GET http://sekrit.com/node/175521 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:32:07 +0100] "GET http://sekrit.com/node/175520 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:32:33 +0100] "GET http://sekrit.com/node/175522 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:33:01 +0100] "GET http://sekrit.com/node/175527 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [25/Feb/2010:17:01:54 +0100] "GET http://sekrit.com/search/results/ HTTP/1.0" 200 - "http://sekrit.com/search/results/"guideline%20grids"&page=1" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" Couldn't match 192.168.1.107 - - [25/Feb/2010:17:02:15 +0100] "GET http://sekrit.com/search/results/ HTTP/1.0" 200 - "http://sekrit.com/search/results/"guideline%20grids"&page=1" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" If there are " " inside the request string, my regex breaks. Here's the code: #!/usr/bin/env python import re pattern = r'(?P^(-|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(, [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})*){1}) (?P(\S*)) (?P(\S*)) (?P(\[[^\]]+\])) (?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?) (?P(\S*)) (?P(\S*)) (?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?) (?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?)( )?(?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?)' regex = re.compile(pattern) lines = 0 no_cookies = 0 unmatched = 0 for line in open('/home/stephen/scratch/test-data.txt'): lines +=1 line = line.strip() match = regex.match(line) if match: data = match.groupdict() if data['SiteIntelligenceCookie'] == '': no_cookies +=1 else: print "Couldn't match ", line unmatched +=1 print "I analysed %s lines." % (lines,) print "There were %s lines with missing Site Intelligence cookies." % (no_cookies,) print "I was unable to process %s lines." % (unmatched,) How can I make the regex a bit more resilient so it doesn't break when " " is embedded? -- Stephen Nelson-Smith Technical Director Atalanta Systems Ltd www.atalanta-systems.com From martin.hellwig at dcuktec.org Mon Mar 8 12:40:07 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 17:40:07 +0000 Subject: Trouble with quotes In-Reply-To: References: Message-ID: On 03/08/10 17:06, Stephen Nelson-Smith wrote: > Hi, > > I've written some (primitive) code to parse some apache logfies and > establish if apache has appended a session cookie to the end. We're > finding that some browsers don't and apache doesn't just append a "-" > - it just omits it. > > It's working fine, but for an edge case: > > Couldn't match 192.168.1.107 - - [24/Feb/2010:20:30:44 +0100] "GET > http://sekrit.com/node/175523 HTTP/1.1" 200 - > "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 > (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" I didn't try to mentally parse the regex pattern (I like to keep reasonably sane). However from the sounds of it the script barfs when there is a quoted part in the second URL part. So how about doing a simple string.replace('/"','') & string.replace('" ','') before doing your re foo? -- mph From cmpython at gmail.com Mon Mar 8 12:51:51 2010 From: cmpython at gmail.com (CM) Date: Mon, 8 Mar 2010 09:51:51 -0800 (PST) Subject: Converting HTML to PDF using Python? References: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> Message-ID: <4bd454b4-1f00-425a-aa37-cd3a63f7fe8f@z4g2000yqa.googlegroups.com> On Mar 8, 10:36?am, Oltmans wrote: > Hi Python superstars, > > Guys, any ideas on how to convert HTML files to PDF files? Or as an > alternative, how to convert HTML files to an image file(jpeg/png/etc)? > Ideally, the converted PDF/Image file should like exactly like the way > HTML file looks in the browser. > > I really have no idea about this so I will really appreciate all the > help. Thanks in advance and kindly pardon my ignorance. > > Thanks, > Oltmans http://lmgtfy.com/?q=python+html+to+pdf From dinov at microsoft.com Mon Mar 8 13:44:37 2010 From: dinov at microsoft.com (Dino Viehland) Date: Mon, 8 Mar 2010 18:44:37 +0000 Subject: ssl, v23 client, v3 server... Message-ID: <1A472770E042064698CB5ADC83A12ACD393F30FD@TK5EX14MBXC118.redmond.corp.microsoft.com> In the ssl module docs (and in the tests) it says that if you have a client specifying PROTOCOL_SSLv23 (so it'll use v2 or v3) and a server specifying PROTOCOL_SSLv3 (so it'll only use v3) that you cannot connect between the two. Why doesn't this end up using SSL v3 for the communication? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Mar 8 13:48:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Mar 2010 13:48:01 -0500 Subject: Converting HTML to PDF using Python? In-Reply-To: <4bd454b4-1f00-425a-aa37-cd3a63f7fe8f@z4g2000yqa.googlegroups.com> References: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> <4bd454b4-1f00-425a-aa37-cd3a63f7fe8f@z4g2000yqa.googlegroups.com> Message-ID: On 3/8/2010 12:51 PM, CM wrote: > On Mar 8, 10:36 am, Oltmans wrote: >> Hi Python superstars, >> >> Guys, any ideas on how to convert HTML files to PDF files? Or as an >> alternative, how to convert HTML files to an image file(jpeg/png/etc)? >> Ideally, the converted PDF/Image file should like exactly like the way >> HTML file looks in the browser. How an HTML file looks in *a* (not *the*) browser depends on the browser, its settings, and window size. That is both a virtue and a reason for the invention of pdf format. >> I really have no idea about this so I will really appreciate all the >> help. Thanks in advance and kindly pardon my ignorance. >> >> Thanks, >> Oltmans > > http://lmgtfy.com/?q=python+html+to+pdf From debatem1 at gmail.com Mon Mar 8 14:05:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Mar 2010 14:05:34 -0500 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > Thanks Geremy, > > That has been an absolute bump........... GOD i cant sit on my chair, it has > worked even on 512 bit number and with no time.......... > superb i would say. > > lastly, i am using the code below to calculate Largest Prime factor of a > number: > > print > ('''===============================================================================''' > ?????? '''????????????? CALCULATE? HIGHEST PRIME > FACTOR????????????????????????????????? ''' > > '''===============================================================================''') > > #!/usr/bin/env python > def highest_prime_factor(n): > ?? if isprime(n): > ????? return n > ?? for x in xrange(2,n ** 0.5 + 1): > ????? if not n % x: > ???????? return highest_prime_factor(n/x) > def isprime(n): > ?? for x in xrange(2,n ** 0.5 + 1): > ????? if not n % x: > ???????? return False > ?? return True > if? __name__ == "__main__": > ?? import time > ?? start = time.time() > ?? print highest_prime_factor(1238162376372637826) > ?? print time.time() - start > > the code works with a bit of delay on the number : "1238162376372637826" but > extending it to > (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) > ?makes python go crazy. Is there any way just like above, i can have it > calculated it in no time. > > > thanks for the support. If you're just looking for the largest prime factor I would suggest using a fermat factorization attack. In the example you gave, it returns nearly immediately. Geremy Condra From debatem1 at gmail.com Mon Mar 8 14:08:48 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Mar 2010 14:08:48 -0500 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: On Mon, Mar 8, 2010 at 2:05 PM, geremy condra wrote: > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: >> Thanks Geremy, >> >> That has been an absolute bump........... GOD i cant sit on my chair, it has >> worked even on 512 bit number and with no time.......... >> superb i would say. >> >> lastly, i am using the code below to calculate Largest Prime factor of a >> number: >> >> print >> ('''===============================================================================''' >> ?????? '''????????????? CALCULATE? HIGHEST PRIME >> FACTOR????????????????????????????????? ''' >> >> '''===============================================================================''') >> >> #!/usr/bin/env python >> def highest_prime_factor(n): >> ?? if isprime(n): >> ????? return n >> ?? for x in xrange(2,n ** 0.5 + 1): >> ????? if not n % x: >> ???????? return highest_prime_factor(n/x) >> def isprime(n): >> ?? for x in xrange(2,n ** 0.5 + 1): >> ????? if not n % x: >> ???????? return False >> ?? return True >> if? __name__ == "__main__": >> ?? import time >> ?? start = time.time() >> ?? print highest_prime_factor(1238162376372637826) >> ?? print time.time() - start >> >> the code works with a bit of delay on the number : "1238162376372637826" but >> extending it to >> (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) >> ?makes python go crazy. Is there any way just like above, i can have it >> calculated it in no time. >> >> >> thanks for the support. > > If you're just looking for the largest prime factor I would suggest using > a fermat factorization attack. In the example you gave, it returns > nearly immediately. > > Geremy Condra > Allow me to add a very important caveat to my previous statement: a fermat factorization is primarily useful if you know that your number is a large semiprime, such as an RSA modulus, which I assume you are. Otherwise, make sure and test for primality. Geremy Con From duncan.booth at invalid.invalid Mon Mar 8 14:14:37 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Mar 2010 19:14:37 GMT Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: Xah Lee wrote: > For example, consider, if you are within world's top 100th user of > database in terms of database size, such as Google, then it may be > that the off-the-shelf tools may be limiting. But how many users > really have such massive size of data? You've totally missed the point. It isn't the size of the data you have today that matters, it's the size of data you could have in several years' time. Maybe today you've got 10 users each with 10 megabytes of data, but you're aspiring to become the next twitter/facebook or whatever. It's a bit late as you approach 100 million users (and a petabyte of data) to discover that your system isn't scalable: scalability needs to be built in from day one. From bob.aalsma at aalsmacons.nl Mon Mar 8 14:15:32 2010 From: bob.aalsma at aalsmacons.nl (BobAalsma) Date: Mon, 8 Mar 2010 11:15:32 -0800 (PST) Subject: Newbie question: python versions differ per user? Message-ID: <8a04bbfd-9c48-4397-8c81-c159dc1b8977@33g2000yqj.googlegroups.com> I'm on Mac OS X 10.5.8 and downloaded 2.6.4 Mac Installer Disk Image as/in(?) the sys admin user. For this user Pyhton 2.6.4 is now the current version. I want to use Python outside the sys asdmin user. However, all other users still use Python 2.5.1 (Apple delivered). The sys admin user looks in /Library/Frameworks/Python.framework/ Versions/2.6/lib/... The other users look in /System/Library/Frameworks/ Python.framework/Version/2.5/lib/... I could not find any questions on this matter, so am I the only one? Did I do something wrong? I assumed the paths for all users would be modified - too easy? From dickinsm at gmail.com Mon Mar 8 14:21:14 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 8 Mar 2010 11:21:14 -0800 (PST) Subject: Calculating very large exponents in python References: Message-ID: [Replying to Geremy's reply because the OP's post didn't show up in my newsreader.] On Mar 7, 8:40?pm, geremy condra wrote: > On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad wrote: > > Dear All, > > > i am writing my crytographic scheme in python, i am just a new user to it. > > I have written the complete code, the only point i am stuck it is that i am > > using 256 exponentiation which is normal in crytography but python just > > hangs on it. > > > g**x? [where both g and x are 256 bit numbers , in decimal they are around > > 77] No library can solve this problem. If g and x are both 256-bit numbers then the result of g**x will have on the order of 10**79 bits, which matches estimates of the number of particles in the universe. I can only imagine that you actually want g**x % m for some m, in which case three-argument pow is your friend, as Geremy pointed out. -- Mark From python at rcn.com Mon Mar 8 14:24:02 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Mar 2010 11:24:02 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> Message-ID: <06ddd3cf-d3dd-4e5d-9789-53a4f8a4bced@b5g2000prd.googlegroups.com> [Steven D'Aprano] > Thanks for the explanation Raymond. A few comments follow: You're welcome :-) > Would you consider a feature enhancement adding an additional method, > analogous to update(), to perform subtractions? I recognise that it's > easy to subclass and do it yourself, but there does seem to be some > demand for it, and it is an obvious feature given that Counter does > support negative counts. Will continue to mull it over. Instinct says that conflating two models can be worse for usability than just picking one of the models and excluding the other. If I had it to do over, there is a reasonable case that elementwise vector methods (__add__, __sub__, and __mul__) may have been a more useful choice than multiset methods (__add__, __sub__, __and__, __or__). That being said, the multiset approach was the one that was chosen. It was indicated for people who have experience with bags or multisets in other languages. It was also consistent with the naming of the class as tool for counting things (i.e. it handles counting numbers right out of the box). No explicit support is provided for negative values, but it isn't actively hindered either. For applications needing elementwise vector operations and signed arithmetic, arguably they should be using a more powerful toolset, perhaps supporting a full-range of elementwise binary and unary operations and a dotproduct() method. Someone should write that class and post it to the ASPN Cookbook to see if there is any uptake. > Personally, I think the behaviour of + and - would be far less surprising > if the class was called Multiset. Intuitively, one would expect counters > to be limited to ints, and to support negative counts when adding and > subtracting. In hindsight, do you think that Multiset would have been a > better name? The primary use case for Counter() is to count things (using the counting numbers). The term Multiset is more obscure and only applies to the four operations that eliminate non-positive results. So, I'm somewhat happy with the current name. FWIW, the notion of "what is surprising" often depends on the observer's background and on the problem they are currently trying to solve. If you need negative counts, then Counter.__sub__() is surprising. If your app has no notion of a negative count, then it isn't. The docs, examples, and docstrings are very clear about the behavior, so the "surprise" is really about wanting it to do something other than what it currently does ;-) Raymond From daniel at stutzbachenterprises.com Mon Mar 8 15:30:23 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Mon, 8 Mar 2010 14:30:23 -0600 Subject: negative "counts" in collections.Counter? In-Reply-To: <06ddd3cf-d3dd-4e5d-9789-53a4f8a4bced@b5g2000prd.googlegroups.com> References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> <06ddd3cf-d3dd-4e5d-9789-53a4f8a4bced@b5g2000prd.googlegroups.com> Message-ID: On Mon, Mar 8, 2010 at 1:24 PM, Raymond Hettinger wrote: > Instinct says that conflating two models can be worse for usability > than just picking one of the models and excluding the other. > Toward that end, shouldn't Counter do one (and only one) of the follow? 1) Disallow non-positive counts (like a Multiset/Bag) 2) Allow them when subtracting In other words, to avoid conflating two models the following two examples should produce the same output: >>> c = Counter({'red': 1}) >>> c['red'] -= 2 >>> c Counter({'red': -1}) >>> c = Counter({'red': 1}) >>> c2 = Counter({'red': 2}) >>> c - c2 Counter() -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From monkey at joemoney.net Mon Mar 8 15:30:39 2010 From: monkey at joemoney.net (monkeys paw) Date: Mon, 08 Mar 2010 15:30:39 -0500 Subject: write to remote ile In-Reply-To: References: Message-ID: On 3/7/2010 9:53 PM, Martin P. Hellwig wrote: > On 03/08/10 02:51, monkeys paw wrote: >> On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: >>> On 03/08/10 02:10, monkeys paw wrote: >>>> I can xfer a file from a remote server using: >>>> >>>> import urllib2 as u >>>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >>>> >>>> for line in x: >>>> print line >>>> >>>> >>>> How can i write a file to the remote server? >>>> >>>> I tried: >>>> >>>> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >>>> >>>> but that does not work >>> >>> How do you normally (i.e. without python) put files on a remote server? >>> >> Using FTP, i'm really having a brain cramp here, but i'm new to python > > We all been there, in some for or other ;-), anyway you might want to > have a look at this: > http://docs.python.org/library/ftplib.html > Tried this, the storlines doesn't work, everything else OK from ftplib import FTP ftp = FTP('joemoney.net') ftp.login('secret','pw') ftp.retrlines('LIST') # list directory contents ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error> File "ftp.py", line 5, in ftp.storlines('STOR', 'sf.xml') File "C:\Python26\lib\ftplib.py", line 470, in storlines conn = self.transfercmd(cmd) File "C:\Python26\lib\ftplib.py", line 356, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "C:\Python26\lib\ftplib.py", line 327, in ntransfercmd resp = self.sendcmd(cmd) File "C:\Python26\lib\ftplib.py", line 243, in sendcmd return self.getresp() File "C:\Python26\lib\ftplib.py", line 218, in getresp raise error_perm, resp ftplib.error_perm: 501 No file name The file exists in the same directory as ftp.py From python at rcn.com Mon Mar 8 16:44:34 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Mar 2010 13:44:34 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: [Vlastimil Brom] > Thank you very much for the exhaustive explanation Raymond! You're welcome. > I am by far not able to follow all of the mathematical background, but > even for zero-truncating multiset, I would expect the truncation on > input rather than on output of some operations. I debated about this and opted for be-loose-in-receiving-and-strict-on- output. One thought is that use cases for multisets would have real multisets as inputs (no negative counts) and as outputs. The user controls the inputs, and the method only has a say in what its outputs are. Also, truncating input would complicate the mathematical definition of what is happening. Compare: r = a[x] - b[x] if r > 0: emit(r) vs. r = max(0, a[x]) - max(0, b[x]) if r > 0: emit(r) Also, the design parallels what is done in the decimal module where rounding is applied only to the results of operations, not to the inputs. > Probably a kind of negative_update() ?or some better named method will > be handy, like the one you supplied or simply the current module code > without the newcount > 0: ... condition. See my other post on this subject. There is no doubt that such a method would be handy for signed arithmetic. The question is whether conflating two different models hurts the API more than it helps. Right now, the Counter() class has no explicit support for negative values. It is designed around natural numbers and counting numbers. > Or would it be an option to > have a keyword argument like zero_truncate=False which would influence > this behaviour? Guido's thoughts on behavior flags is that they are usually a signal that you need two different classes. That is why itertools has ifilter() and ifilterfalse() or izip() and izip_longest() instead of having behavior flags. In this case, we have an indication that what you really want is a separate class supporting elementwise binary and unary operations on vectors (where the vector fields are accessed by a dictionary key instead of a positional value). > Additionally, were issubset and issuperset considered for this > interface (not sure whether symmetric_difference would be applicable)? If the need arises, these could be included. Right now, you can get the same result with: "if a - b: ..." FWIW, I never liked those two method names. Can't remember whether a.issubset(b) means "a is a subset of b" or "b issubset of a'. Raymond From news123 at free.fr Mon Mar 8 17:06:34 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:06:34 +0100 Subject: Import problem In-Reply-To: <4b926b37$0$27829$c3e8da3@news.astraweb.com> References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b926b37$0$27829$c3e8da3@news.astraweb.com> Message-ID: <4b9574ea$0$435$426a74cc@news.free.fr> Hi Steven, Steven D'Aprano wrote: > On Sat, 06 Mar 2010 03:53:53 -0800, Johny wrote: > >>>>> import sys >>>>> sys.path.append('C:\\A') >>>>> from A.B import bmodule >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named A.B > > The current directory is irrelevant, except that it is automatically > added to the PYTHONPATH. That's why you can import A.B when the current > directory is C. Minor currection: It doesn't seem to be the current directory, but the directory, where the script is located in, which is auto-appended to the pythonpath Please see following example: $ python -V Python 2.6.4 $ mkdir A $ touch A/__init__ $ # create A/blla.py an A/blo.py $ cat A/bla.py print "I am bla" import A.blo print "and I found blo",dir(A.blo) $ cat A/blo.py avar = 3 print "I am blo" $ python A/bla.py I am bla Traceback (most recent call last): File "A/bla.py", line 2, in import A.blo ImportError: No module named A.blo However: $ cat alternative_bla.py import sys sys.path.append(".") print "I am bla" import A.blo print "and I found blo",dir(A.blo) $ python A/alternativ_bla.py I am bla I am blo and I found blo ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'avar'] bye N From greg.ewing at canterbury.ac.nz Mon Mar 8 17:16:24 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Mar 2010 11:16:24 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> Message-ID: <7vlameF7goU1@mid.individual.net> Dave Angel wrote: > If you know so little about the > value, how do you even know it's a CRC ? Could it be a ones-complement > sum, such as used in Ethernet? I'm going by the fact that the application reports a "CRC mismatch" when it's wrong. I can't be sure that what it calls a "CRC" is really a true CRC, but it's more than a simple sum, because changing one bit in the file results in a completely different value. > Is the problem really worth it? Probably not -- it looks like fixing the problem I'm trying to fix by hand will be faster in the long run. I just thought it might turn out to be a solved problem and someone could point me to an algorithm for it, but it seems not. -- Greg From news123 at free.fr Mon Mar 8 17:21:08 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:21:08 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4B957854.3070201@free.fr> Jean-Michel Pichavant wrote: > Johny wrote: >> I have this directory structure >> >> C: >> \A >> __init__.py >> amodule.py >> >> \B >> __init__.py >> bmodule.py >> >> \D >> __init__.py >> dmodule.py >> >> and I want to import bmodule.py >> C:\>cd \ >> >> C:\>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> from A.B import bmodule >>>>> >> I am bmodule >> C:\> >> >> so far so good. Now I would like to import bmodule but if the current >> directory is \D subdirectory. >> >> C:> cd \A\B\D >> C:\A\B\D> >> C:\A\B\D>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import sys >>>>> sys.path.append('C:\\A') >>>>> from A.B import bmodule >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named A.B >> >> C:\> >> >> so I can not import a module from the parent directory? Or where did I >> make an error? >> Thanks for help >> >> L. >> > try > > import sys > sys.path.append('C:\\') > from A.B import bmodule > is there any 'automatic' way of finding the top level directory?basically the 'top level directory is the first directory going upwards, that doesn't contain a __init__.py file. of course you could do this 'manually' by doing: # assume, that this module is A.amodule import sys import os # I'd love to have a similiar automatic construct if __name__ == "__main__": level = 1 # or function locating how far to go up before # finding a dir, whcih does not contain a __init__.py mydir = os.path.split(__file__)[0] topdir = os.path.join( mydir,*(("..",)*level)) abstop = os.path.abspath(topdir) sys.path.append(abstop) ## now you can import with the normal module paths import A.blo print "and I found blo",dir(A.blo) bye N From news123 at free.fr Mon Mar 8 17:21:26 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:21:26 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4b957866$0$17135$426a34cc@news.free.fr> Jean-Michel Pichavant wrote: > Johny wrote: >> I have this directory structure >> >> C: >> \A >> __init__.py >> amodule.py >> >> \B >> __init__.py >> bmodule.py >> >> \D >> __init__.py >> dmodule.py >> >> and I want to import bmodule.py >> C:\>cd \ >> >> C:\>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> from A.B import bmodule >>>>> >> I am bmodule >> C:\> >> >> so far so good. Now I would like to import bmodule but if the current >> directory is \D subdirectory. >> >> C:> cd \A\B\D >> C:\A\B\D> >> C:\A\B\D>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import sys >>>>> sys.path.append('C:\\A') >>>>> from A.B import bmodule >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named A.B >> >> C:\> >> >> so I can not import a module from the parent directory? Or where did I >> make an error? >> Thanks for help >> >> L. >> > try > > import sys > sys.path.append('C:\\') > from A.B import bmodule > is there any 'automatic' way of finding the top level directory?basically the 'top level directory is the first directory going upwards, that doesn't contain a __init__.py file. of course you could do this 'manually' by doing: # assume, that this module is A.amodule import sys import os # I'd love to have a similiar automatic construct if __name__ == "__main__": level = 1 # or function locating how far to go up before # finding a dir, whcih does not contain a __init__.py mydir = os.path.split(__file__)[0] topdir = os.path.join( mydir,*(("..",)*level)) abstop = os.path.abspath(topdir) sys.path.append(abstop) ## now you can import with the normal module paths import A.blo print "and I found blo",dir(A.blo) bye N From greg.ewing at canterbury.ac.nz Mon Mar 8 17:22:28 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Mar 2010 11:22:28 +1300 Subject: negative "counts" in collections.Counter? In-Reply-To: References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <7vlb1qF9jaU1@mid.individual.net> Raymond Hettinger wrote: > Instead the choice was to implement the four methods as > multiset operations. As such, they need to correspond > to regular set operations. Seems to me you're trying to make one data type do the work of two, and ending up with something inconsistent. I think you should be providing two types: one is a multiset, which disallows negative counts altogether; the other behaves like a sparse vector with appropriate arithmetic operations. -- Greg From vlastimil.brom at gmail.com Mon Mar 8 17:24:43 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 8 Mar 2010 23:24:43 +0100 Subject: negative "counts" in collections.Counter? In-Reply-To: References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <9fdb569a1003081424j405d2bdblc2dc96a5ae6fa910@mail.gmail.com> 2010/3/8 Raymond Hettinger : ... [snip detailed explanations] >... > In this case, we have an indication that what you really want is > a separate class supporting elementwise binary and unary operations > on vectors (where the vector fields are accessed by a dictionary > key instead of a positional value). > > >> Additionally, were issubset and issuperset considered for this >> interface (not sure whether symmetric_difference would be applicable)? > > If the need arises, these could be included. ?Right now, you > can get the same result with: ?"if a - b: ..." > > FWIW, I never liked those two method names. ?Can't remember whether > a.issubset(b) means "a is a subset of b" or "b issubset of a'. > > > Raymond > -- > Thanks for the further remarks Raymond, initially I thought while investigating new features of python 3, this would be a case for replacing the "home made" solutions with the standard module functionality. Now I can see, it probably wouldn't be an appropriate decision in this case, as the expected usage of Counter with its native methods is different. As for the issubset, issuperset method names, I am glad, a far more skilled person has the same problem like me :-) In this case the operators appear to be clearer than the method names... regards, vbr From news123 at free.fr Mon Mar 8 17:25:24 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:25:24 +0100 Subject: libc Sleep api performs a busy waiting In-Reply-To: References: Message-ID: <4b957954$0$17135$426a34cc@news.free.fr> Hi Steve, Steve Holden wrote: > Mahesh wrote: >> Hi, >> >> I am having a problem while using sleep function from libc , the >> thread in which i am calling it is getting struck and not allowing >> other threads to execute. Here is a simple code that i am trying to >> exeute >> >> import threading >> import time >> import dl >> >> >> def dummy1(): >> a=dl.open('/lib/libc.so.6') >> print "in thread 1 Start" >> a.call('sleep',2) >> #time.sleep(2) >> print "in thread 1 End" >> >> def dummy2(): >> print "in thread 2 Start" >> time.sleep(1) >> print "in thread 2 End" >> newThread1=threading.Thread(None,dummy1) >> newThread2=threading.Thread(None,dummy2) >> newThread1.start() >> newThread2.start() >> >> print "in main" >> >> >> >> The out put of this program is (In this case thread 1 even though i >> am calling a sleep function its not allowing other threads to execute, >> other threads execute only after the completion of first thread) >> >> in thread 1 Start >> in thread 1 End >> in thread 2 Start >> in main >> in thread 2 End >> >> >> where as if i use time.sleep instead of a.call(sleep) the out put is >> (which i guess is right behaviour, because it start the threads and >> suspends them because the have sleep , and continue executing the main >> thread) >> in thread 1 Start >> in thread 2 Start >> in main >> in thread 2 End >> in thread 1 End >> >> > Why not just use the time module's sleep function? Unlike the libc code > it releases Python's GIL (global interpreter lock), thus allowing other > threads to run. > I fully agree for the given example. Especcially time.sleep allows even sub second sleeps. Out of curiousity though: Is there any way to perform a call(), that releases the GIL before calling the function? It would avoid writing a wrapper? bye N From news123 at free.fr Mon Mar 8 17:26:32 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:26:32 +0100 Subject: What to do if anything bites. In-Reply-To: References: Message-ID: <4b957998$0$17135$426a34cc@news.free.fr> Google Adsense wrote: > What to do if anything bites. > > Check our bites treatment at > > http://108ambulance.blogspot.com/2010/03/108-ambulance-home-page.html Pythons don't bite From dimitri.pater at gmail.com Mon Mar 8 17:34:06 2010 From: dimitri.pater at gmail.com (dimitri pater - serpia) Date: Mon, 8 Mar 2010 23:34:06 +0100 Subject: related lists mean value Message-ID: Hi, I have two related lists: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] what I need is a list representing the mean value of 'a', 'b' and 'c' while maintaining the number of items (len): w = [1.5, 1.5, 8, 4, 4, 4] I have looked at iter(tools) and next(), but that did not help me. I'm a bit stuck here, so your help is appreciated! thanks! Dimitri From python at rcn.com Mon Mar 8 17:44:38 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Mar 2010 14:44:38 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <7vlb1qF9jaU1@mid.individual.net> Message-ID: <34e15f30-8f7c-4f0f-82b7-6a65fe91ec88@w27g2000pre.googlegroups.com> [Gregory Ewing] > I think you should be providing two types: one is a > multiset, which disallows negative counts altogether; > the other behaves like a sparse vector with appropriate > arithmetic operations. That is pretty close to what I said above: """ In this case, we have an indication that what you really want is a separate class supporting elementwise binary and unary operations on vectors (where the vector fields are accessed by a dictionary key instead of a positional value). """ The first and foremost goal of the class was to provide a simple counting capability along the lines of: class Counter(dict): def __init__(self, iterable=()): for elem in iterable: self[elem] += 1 def __missing__(self, key): return 0 Note, there is no "disallowing negatives" or even any insistence that the "counts" are actually numbers. In that respect, it was a consenting adults class from the start. It is short, simple, and fast. The other methods were mostly just "extras" to make the tool more useful. Each adds its own minimal restrictions: elements() requires integer counts most_common() requires that counts be orderable multiset operations are defined for non-negative values We could have kept this same design and wrapped every dictionary method so that it would raise an exception for any count that was not a positive integer. That would have slowed down the class, increased the code volume, and precluded some uses that are currently possible. IMO, that would not have been a win and it would not have helped the OP who was seeking a more vector-like tool for signed-number operations. Anyway, it is what it is. The tool is released and most users seem to be happy with what we have. Raymond From python at mrabarnett.plus.com Mon Mar 8 17:48:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Mar 2010 22:48:13 +0000 Subject: write to remote ile In-Reply-To: References: Message-ID: <4B957EAD.7070304@mrabarnett.plus.com> monkeys paw wrote: > On 3/7/2010 9:53 PM, Martin P. Hellwig wrote: >> On 03/08/10 02:51, monkeys paw wrote: >>> On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: >>>> On 03/08/10 02:10, monkeys paw wrote: >>>>> I can xfer a file from a remote server using: >>>>> >>>>> import urllib2 as u >>>>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >>>>> >>>>> for line in x: >>>>> print line >>>>> >>>>> >>>>> How can i write a file to the remote server? >>>>> >>>>> I tried: >>>>> >>>>> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >>>>> >>>>> but that does not work >>>> >>>> How do you normally (i.e. without python) put files on a remote server? >>>> >>> Using FTP, i'm really having a brain cramp here, but i'm new to python >> >> We all been there, in some for or other ;-), anyway you might want to >> have a look at this: >> http://docs.python.org/library/ftplib.html >> > > Tried this, the storlines doesn't work, everything else OK > > from ftplib import FTP > ftp = FTP('joemoney.net') > ftp.login('secret','pw') > ftp.retrlines('LIST') # list directory contents > ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error> > The documentation says: FTP.storlines(cmd, file, callback=None) where 'cmd' is the FTP command, 'STOR sf.xml' ('sf.xl' is the path of the file on the server) and 'file' is the open (local) source file. From invalid at invalid.invalid Mon Mar 8 18:06:35 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Mar 2010 23:06:35 +0000 (UTC) Subject: Converting HTML to PDF using Python? References: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> Message-ID: On 2010-03-08, Oltmans wrote: > Guys, any ideas on how to convert HTML files to PDF files? os.system("w3m -dump %s | a2ps -B --borders=no -o - | ps2pdf - %s" % (infile,outfile)) -- Grant Edwards grant.b.edwards Yow! Am I accompanied by a at PARENT or GUARDIAN? gmail.com From python at mrabarnett.plus.com Mon Mar 8 18:15:44 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Mar 2010 23:15:44 +0000 Subject: related lists mean value In-Reply-To: References: Message-ID: <4B958520.8000701@mrabarnett.plus.com> dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! > Try doing it in 2 passes. First pass: count the number of times each string occurs in 'y' and the total for each (zip/izip and defaultdict are useful for these). Second pass: create the result list containing the mean values. From clp2 at rebertia.com Mon Mar 8 18:22:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Mar 2010 15:22:39 -0800 Subject: related lists mean value In-Reply-To: References: Message-ID: <50697b2c1003081522p565ed44fxd68761c0b19bcfc7@mail.gmail.com> On Mon, Mar 8, 2010 at 2:34 PM, dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! from __future__ import division def group(keys, values): #requires None not in keys groups = [] cur_key = None cur_vals = None for key, val in zip(keys, values): if key != cur_key: if cur_key is not None: groups.append((cur_key, cur_vals)) cur_vals = [val] cur_key = key else: cur_vals.append(val) groups.append((cur_key, cur_vals)) return groups def average(lst): return sum(lst) / len(lst) def process(x, y): result = [] for key, vals in group(y, x): avg = average(vals) for i in xrange(len(vals)): result.append(avg) return result x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] print process(x, y) #=> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] It could be tweaked to use itertools.groupby(), but it would probably be less efficient/clear. Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Mon Mar 8 18:24:07 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Mar 2010 18:24:07 -0500 Subject: Reverse engineering CRC? In-Reply-To: <7vlameF7goU1@mid.individual.net> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: <4B958717.7040708@ieee.org> Gregory Ewing wrote: >
Dave > Angel wrote: >> If you know so little about the value, how do you even know it's a >> CRC ? Could it be a ones-complement sum, such as used in Ethernet? > > I'm going by the fact that the application reports a > "CRC mismatch" when it's wrong. I can't be sure that what > it calls a "CRC" is really a true CRC, but it's more than > a simple sum, because changing one bit in the file results > in a completely different value. > >> Is the problem really worth it? > > Probably not -- it looks like fixing the problem I'm trying > to fix by hand will be faster in the long run. I just thought > it might turn out to be a solved problem and someone could > point me to an algorithm for it, but it seems not. > If you assume it's done in a single pass, and you know which byte is the end of the buffer, I'd think you could learn a lot by just tweaking that last byte. But I still think you'd want to automate your testing, presumably by some keystroke-stuffer. DaveA From mensanator at aol.com Mon Mar 8 18:32:14 2010 From: mensanator at aol.com (Mensanator) Date: Mon, 8 Mar 2010 15:32:14 -0800 (PST) Subject: Python 3.1.2 release candidate References: Message-ID: <90da6fb8-e555-4a74-bf13-14878f60f5d4@g11g2000yqe.googlegroups.com> On Mar 6, 4:13?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm pleased to announce a release > candidate for the second bugfix release of the Python 3.1 series, Python 3.1.2. > > This bug fix release fixes numerous issues found in 3.1.1. ?This release > candidate has been released to solicit testing and feedback over an possible > regressions from 3.1.1. ?Please consider testing it with your library or > application and reporting an bugs you encounter. ?This will help make the final > 3.1.2 release, planned in 2 weeks time, all the more stable. > > The Python 3.1 version series focuses on the stabilization and optimization of > the features and changes that Python 3.0 introduced. ?For example, the new I/O > system has been rewritten in C for speed. ?File system APIs that use unicode > strings now handle paths with undecodable bytes in them. Other features include > an ordered dictionary implementation, a condensed syntax for nested with > statements, and support for ttk Tile in Tkinter. ?For a more extensive list of > changes in 3.1, seehttp://doc.python.org/3.1/whatsnew/3.1.htmlor Misc/NEWS in > the Python distribution. > > To download Python 3.1.2rc1 visit: > > ? ? ?http://www.python.org/download/releases/3.1.2/ > > A list of changes in 3.1.2rc1 can be found here: > > ? ? ?http://svn.python.org/projects/python/tags/r312rc1/Misc/NEWS > > The 3.1 documentation can be found at: > > ? ? ?http://docs.python.org/3.1 > > Bugs can always be reported to: > > ? ? ?http://bugs.python.org Hey, it finally let me register. Turned out the e-mail to confirm registry was getting marked Spam. I pulled it out of the Spam box and completed the registration. Of course, the reason I needed to register is because IDLE will *still* not end a process properly in Windows. see issue 8093 > > Enjoy! > > -- > Benjamin Peterson > Release Manager > benjamin at python.org > (on behalf of the entire python-dev team and 3.1.2's contributors) From dimitri.pater at gmail.com Mon Mar 8 18:47:12 2010 From: dimitri.pater at gmail.com (dimitri pater - serpia) Date: Tue, 9 Mar 2010 00:47:12 +0100 Subject: related lists mean value In-Reply-To: <50697b2c1003081522p565ed44fxd68761c0b19bcfc7@mail.gmail.com> References: <50697b2c1003081522p565ed44fxd68761c0b19bcfc7@mail.gmail.com> Message-ID: thanks Chris and MRAB! Looks good, I'll try it out On Tue, Mar 9, 2010 at 12:22 AM, Chris Rebert wrote: > On Mon, Mar 8, 2010 at 2:34 PM, dimitri pater - serpia > wrote: >> Hi, >> >> I have two related lists: >> x = [1 ,2, 8, 5, 0, 7] >> y = ['a', 'a', 'b', 'c', 'c', 'c' ] >> >> what I need is a list representing the mean value of 'a', 'b' and 'c' >> while maintaining the number of items (len): >> w = [1.5, 1.5, 8, 4, 4, 4] >> >> I have looked at iter(tools) and next(), but that did not help me. I'm >> a bit stuck here, so your help is appreciated! > > from __future__ import division > > def group(keys, values): > ? ?#requires None not in keys > ? ?groups = [] > ? ?cur_key = None > ? ?cur_vals = None > ? ?for key, val in zip(keys, values): > ? ? ? ?if key != cur_key: > ? ? ? ? ? ?if cur_key is not None: > ? ? ? ? ? ? ? ?groups.append((cur_key, cur_vals)) > ? ? ? ? ? ?cur_vals = [val] > ? ? ? ? ? ?cur_key = key > ? ? ? ?else: > ? ? ? ? ? ?cur_vals.append(val) > ? ?groups.append((cur_key, cur_vals)) > ? ?return groups > > def average(lst): > ? ?return sum(lst) / len(lst) > > def process(x, y): > ? ?result = [] > ? ?for key, vals in group(y, x): > ? ? ? ?avg = average(vals) > ? ? ? ?for i in xrange(len(vals)): > ? ? ? ? ? ?result.append(avg) > ? ?return result > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > print process(x, y) > #=> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > > It could be tweaked to use itertools.groupby(), but it would probably > be less efficient/clear. > > Cheers, > Chris > -- > http://blog.rebertia.com > -- --- You can't have everything. Where would you put it? -- Steven Wright --- please visit www.serpia.org From aahz at pythoncraft.com Mon Mar 8 20:47:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Mar 2010 17:47:58 -0800 Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: In article <58f61382-ac79-46fb-8612-a3c9fde297dc at c16g2000yqd.googlegroups.com>, Veloz wrote: > >The "peek" parts comes in when the user comes back later to see if >their report has done. That is, in my page controller logic, I'd like >to look through the complete queue and see if the specific report has >been finished (I could tell by matching up the ID of the original >request to the ID in the completed queue). If there was an item in the >queue matching the ID, it would be removed. Here's the question: what happens when the user refreshes the "report done" page? The problem with the way you're doing it is that checking for report done is a one-shot operation. You probably want to use a database to cache this and have some kind of cache expiration. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From jjposner at optimum.net Mon Mar 8 21:39:59 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 08 Mar 2010 21:39:59 -0500 Subject: related lists mean value In-Reply-To: References: Message-ID: <4B95B4FF.1070407@optimum.net> On 3/8/2010 5:34 PM, dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! Nobody expects object-orientation (or the Spanish Inquisition): #------------------------- from collections import defaultdict class Tally: def __init__(self, id=None): self.id = id self.total = 0 self.count = 0 x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c'] # gather data tally_dict = defaultdict(Tally) for i in range(len(x)): obj = tally_dict[y[i]] obj.id = y[i] obj.total += x[i] obj.count += 1 # process data result_list = [] for key in sorted(tally_dict): obj = tally_dict[key] mean = 1.0 * obj.total / obj.count result_list.extend([mean] * obj.count) print result_list #------------------------- -John From jjposner at optimum.net Mon Mar 8 21:43:58 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 08 Mar 2010 21:43:58 -0500 Subject: related lists mean value In-Reply-To: <4B95B4FF.1070407@optimum.net> References: <4B95B4FF.1070407@optimum.net> Message-ID: <4B95B5EE.90302@optimum.net> On 3/8/2010 9:39 PM, John Posner wrote: > # gather data > tally_dict = defaultdict(Tally) > for i in range(len(x)): > obj = tally_dict[y[i]] > obj.id = y[i] <--- statement redundant, remove it > obj.total += x[i] > obj.count += 1 -John From jjposner at optimum.net Mon Mar 8 21:53:41 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 08 Mar 2010 21:53:41 -0500 Subject: related lists mean value In-Reply-To: <4B95B5EE.90302@optimum.net> References: <4B95B4FF.1070407@optimum.net> <4B95B5EE.90302@optimum.net> Message-ID: <4B95B835.4050805@optimum.net> On 3/8/2010 9:43 PM, John Posner wrote: > On 3/8/2010 9:39 PM, John Posner wrote: > > >> obj.id = y[i] <--- statement redundant, remove it Sorry for the thrashing! It's more correct to say that the Tally class doesn't require an "id" attribute at all. So the code becomes: #--------- from collections import defaultdict class Tally: def __init__(self): self.total = 0 self.count = 0 x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c'] # gather data tally_dict = defaultdict(Tally) for i in range(len(x)): obj = tally_dict[y[i]] obj.total += x[i] obj.count += 1 # process data result_list = [] for key in sorted(tally_dict): obj = tally_dict[key] mean = 1.0 * obj.total / obj.count result_list.extend([mean] * obj.count) print result_list #--------- -John From df.trash at gmail.com Mon Mar 8 22:35:50 2010 From: df.trash at gmail.com (tdan) Date: Mon, 8 Mar 2010 19:35:50 -0800 (PST) Subject: remove element with ElementTree Message-ID: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> I have been using ElementTree to write an app, and would like to simply remove an element. But in ElementTree, you must know both the parent and the child element to do this. There is no getparent() function, so I am stuck if I only have an element. I am iterating over a table and getting all tags, checking their text, and conditionally deleting them: def RemoveElementWithText( topEl, subEl, text ): for el in topEl.getiterator( subEl ): if el.text = text: break else: el = None return el RemoveElementWithText( table, 'td', 'sometext' ) My table is like so: ...
... Is there any way to do this in ElementTree? I see lxml.etree does this nicely, but I want to use python's standard library. From fox.joe87 at gmail.com Mon Mar 8 23:13:58 2010 From: fox.joe87 at gmail.com (Joe Fox) Date: Tue, 9 Mar 2010 09:43:58 +0530 Subject: libc Sleep api performs a busy waiting In-Reply-To: References: Message-ID: <27e52ad11003082013h658cf7deu761e7d14198af9f1@mail.gmail.com> Hi, actually i have simplified my scenario a lot here , In my actual case , i have to call a C-api which blocks on c select , in a separate thread. my thread is getting struck in that api , and thus blocking all the other threads. Can you point to something which will help me call this blocking C-api call without my thread getting struck. Thanks Mahesh On Mon, Mar 8, 2010 at 6:03 PM, Steve Holden wrote: > Mahesh wrote: > > Hi, > > > > I am having a problem while using sleep function from libc , the > > thread in which i am calling it is getting struck and not allowing > > other threads to execute. Here is a simple code that i am trying to > > exeute > > > > import threading > > import time > > import dl > > > > > > def dummy1(): > > a=dl.open('/lib/libc.so.6') > > print "in thread 1 Start" > > a.call('sleep',2) > > #time.sleep(2) > > print "in thread 1 End" > > > > def dummy2(): > > print "in thread 2 Start" > > time.sleep(1) > > print "in thread 2 End" > > newThread1=threading.Thread(None,dummy1) > > newThread2=threading.Thread(None,dummy2) > > newThread1.start() > > newThread2.start() > > > > print "in main" > > > > > > > > The out put of this program is (In this case thread 1 even though i > > am calling a sleep function its not allowing other threads to execute, > > other threads execute only after the completion of first thread) > > > > in thread 1 Start > > in thread 1 End > > in thread 2 Start > > in main > > in thread 2 End > > > > > > where as if i use time.sleep instead of a.call(sleep) the out put is > > (which i guess is right behaviour, because it start the threads and > > suspends them because the have sleep , and continue executing the main > > thread) > > in thread 1 Start > > in thread 2 Start > > in main > > in thread 2 End > > in thread 1 End > > > > > Why not just use the time module's sleep function? Unlike the libc code > it releases Python's GIL (global interpreter lock), thus allowing other > threads to run. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mehgcap at gmail.com Mon Mar 8 23:22:27 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 8 Mar 2010 23:22:27 -0500 Subject: imported var not being updated Message-ID: Hello all: I have a project with many pyw files. One file holds a variable and a function that I find myself using across many other pyw files, so I called it helpers.pyw. The variable is "mostRecent", which is a string and is meant to hold a string so I know what the program most recently output; in all the other pyw files, every time the program outputs something, I include the line helpers.mostRecent=output where output is a string and helpers has been imported. The problem is that mostRecent does not seem to be updated at all, and I cannot figure out why. I declare it with empty quotes initially, but the program should keep updating it. Everytime I go to see what its value is, though, it is still apparently empty. Here is a basic sample: randomFile.pyw --- import helpers def something(): output="I am the most recently output string!" helpers.mostRecent=output #end def file2.pyw --- from helpers import mostRecent print(mostRecent) #prints nothing Any thoughts on what I am doing wrong? Thanks!! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gherron at islandtraining.com Mon Mar 8 23:55:01 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Mar 2010 20:55:01 -0800 Subject: imported var not being updated In-Reply-To: References: Message-ID: <4B95D4A5.6050504@islandtraining.com> Alex Hall wrote: > Hello all: > I have a project with many pyw files. One file holds a variable and a > function that I find myself using across many other pyw files, so I > called it helpers.pyw. The variable is "mostRecent", which is a string > and is meant to hold a string so I know what the program most recently > output; in all the other pyw files, every time the program outputs > something, I include the line > helpers.mostRecent=output > where output is a string and helpers has been imported. > > The problem is that mostRecent does not seem to be updated at all, and > I cannot figure out why. I declare it with empty quotes initially, but > the program should keep updating it. Everytime I go to see what its > value is, though, it is still apparently empty. Here is a basic > sample: > > randomFile.pyw > --- > import helpers > > def something(): > output="I am the most recently output string!" > helpers.mostRecent=output > #end def > > file2.pyw > --- > from helpers import mostRecent > > print(mostRecent) #prints nothing > > Any thoughts on what I am doing wrong? Thanks!! > The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. Rebinding the var in a different module does not affect this. It's similar to this: a = 'string' b = a a = 'another string' won't affect b's value. What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent That will work as you hope. Gary Herron From mehgcap at gmail.com Mon Mar 8 23:59:00 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 8 Mar 2010 23:59:00 -0500 Subject: imported var not being updated In-Reply-To: <4B95D4A5.6050504@islandtraining.com> References: <4B95D4A5.6050504@islandtraining.com> Message-ID: Thanks, it worked as expected. I guess I figured that Python would read my mind and realize that I wanted mostRecent to act globally for the program, imported as a copy or accessed in its own namespace (right term?) Oh well, the day computers can read thoughts like that is the day programmers are out of a job... Thanks again. On 3/8/10, Gary Herron wrote: > Alex Hall wrote: >> Hello all: >> I have a project with many pyw files. One file holds a variable and a >> function that I find myself using across many other pyw files, so I >> called it helpers.pyw. The variable is "mostRecent", which is a string >> and is meant to hold a string so I know what the program most recently >> output; in all the other pyw files, every time the program outputs >> something, I include the line >> helpers.mostRecent=output >> where output is a string and helpers has been imported. >> >> The problem is that mostRecent does not seem to be updated at all, and >> I cannot figure out why. I declare it with empty quotes initially, but >> the program should keep updating it. Everytime I go to see what its >> value is, though, it is still apparently empty. Here is a basic >> sample: >> >> randomFile.pyw >> --- >> import helpers >> >> def something(): >> output="I am the most recently output string!" >> helpers.mostRecent=output >> #end def >> >> file2.pyw >> --- >> from helpers import mostRecent >> >> print(mostRecent) #prints nothing >> >> Any thoughts on what I am doing wrong? Thanks!! >> > > The form of import you are using > from helpers import mostRecent > makes a *new* binding to the value in the module that's doing the > import. Rebinding the var in a different module does not affect this. > It's similar to this: > > a = 'string' > b = a > a = 'another string' > > won't affect b's value. > > What you can do, is not make a separate binding, but reach into the > helpers module to get the value there. Like this: > > import helpers > print helpers.mostRecent > > That will work as you hope. > > Gary Herron > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gagsl-py2 at yahoo.com.ar Tue Mar 9 01:03:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Mar 2010 03:03:36 -0300 Subject: How to determine if threads are active in an application? References: <1267222230.24180.1362126901@webmail.messagingengine.com> Message-ID: En Fri, 26 Feb 2010 19:10:30 -0300, escribi?: > Is there technique to determine if threads are active in a Python > application? > > The only technique I can think of is to check sys.modules for > thread and threading. But this will only show whether these > modules were imported - not whether there are actually background > threads running. I've just read your post. Look at threading.activeCount() - this returns only those threads created using the threading module. If that's not enough, you'll have to use some OS-specific functions. -- Gabriel Genellina From see at sig.for.address Tue Mar 9 01:14:37 2010 From: see at sig.for.address (Victor Eijkhout) Date: Tue, 9 Mar 2010 00:14:37 -0600 Subject: scipy sparse matrix question Message-ID: <1jf28jr.7abra61nwu04pN%see@sig.for.address> I can't find any detailed information about scipy.sparse. My specific question: what does "for x in A" give me when A is a sparse matrix? It seems to yield all nonzero locations, but in what kind of form? Very specifically: how do I get the (i,j) coordinates and the value from x? Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From casevh at gmail.com Tue Mar 9 01:39:30 2010 From: casevh at gmail.com (casevh) Date: Mon, 8 Mar 2010 22:39:30 -0800 (PST) Subject: Calculating very large exponents in python References: Message-ID: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> [also replying to Geremy since the OP's message doesn't appear...] On Mar 8, 11:05?am, geremy condra wrote: > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > > Thanks Geremy, > > > That has been an absolute bump........... GOD i cant sit on my chair, it has > > worked even on 512 bit number and with no time.......... > > superb i would say. > > > lastly, i am using the code below to calculate Largest Prime factor of a > > number: > > > print > > ('''=======================================================================?========''' > > ?????? '''????????????? CALCULATE? HIGHEST PRIME > > FACTOR????????????????????????????????? ''' > > > '''========================================================================?=======''') > > > #!/usr/bin/env python > > def highest_prime_factor(n): > > ?? if isprime(n): > > ????? return n > > ?? for x in xrange(2,n ** 0.5 + 1): > > ????? if not n % x: > > ???????? return highest_prime_factor(n/x) > > def isprime(n): > > ?? for x in xrange(2,n ** 0.5 + 1): > > ????? if not n % x: > > ???????? return False > > ?? return True > > if? __name__ == "__main__": > > ?? import time > > ?? start = time.time() > > ?? print highest_prime_factor(1238162376372637826) > > ?? print time.time() - start > > > the code works with a bit of delay on the number : "1238162376372637826" but > > extending it to > > (10902610991329142436630551158108608965062811746392577675456004845499113044?304710902610991329142436630551158108608965062811746392577675456004845499113?0443047) > > ?makes python go crazy. Is there any way just like above, i can have it > > calculated it in no time. > > > thanks for the support. > > If you're just looking for the largest prime factor I would suggest using > a fermat factorization attack. In the example you gave, it returns > nearly immediately. > > Geremy Condra- Hide quoted text - > > - Show quoted text - For a Python-based solution, you might want to look at pyecm (http:// sourceforge.net/projects/pyecm/) On a system with gmpy installed also, pyecm found the following factors: 101, 521, 3121, 9901, 36479, 300623, 53397071018461, 1900381976777332243781 There still is a 98 digit unfactored composite: 60252507174568243758911151187828438446814447653986842279796823262165159406500174226172705680274911 Factoring this remaining composite using ECM may not be practical. casevh From faheem_imt at yahoo.com Tue Mar 9 02:51:57 2010 From: faheem_imt at yahoo.com (Faheem) Date: Mon, 8 Mar 2010 23:51:57 -0800 (PST) Subject: How to detect C Function block using python Message-ID: <769249.71022.qm@web62401.mail.re1.yahoo.com> Hey All, I'm new in this community. I am?writing?a static?analyzer?for validating C Code using python and for that?I'm looking for a python module/API that will detect Function block of a given C-File.?I know simple function can be detected using push "{" and poping it if character "}" is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Thanks!Faheem -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Tue Mar 9 03:17:51 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 9 Mar 2010 00:17:51 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> Message-ID: <42062deb-785a-4955-9ce0-d9fb7a26455d@j27g2000yqn.googlegroups.com> On Mar 7, 12:34?pm, Steve Holden wrote: > My own impression of theloggingmodule, formed from trying to use its > documentation in the past, is that it's somewhat unapproachable, and > difficult to use for simple purposes. > > I am happy to say that now I see the current (3.1) documentation it has > improved to the point where I would be happy to try using it again. > Thanks for your long-term maintenance of this package. > Hi Steve, Thanks for the positive feedback. The initial documentation for the logging package, because it lives in the library section of the overall documentation, was focused more on completeness of coverage for reference usage, rather than a more tutorial-based approach. Thanks to work by Doug Hellmann and others, the documentation has grown, over time, more accessible to Python novices. It's still not perfect, and I hope to be able to improve its clarity in the future, by getting help where possible from people who are better at technical writing than I am. I'm reviewing the documentation at the moment, as it happens, and it still seems hard to be able to put together a structure which is good for everyone. A full treatment, it seems to me, would talk a little about the detail of why things work as they do; but a lot of the time, people are just interested in getting going with the package, and less interested in the whys and wherefores. But for people trying to do more than the basics, that deeper understanding is sometimes necessary. The hard part is satisfying all audiences in one document! Regards, Vinay Sajip From stephane at harobed.org Tue Mar 9 03:30:05 2010 From: stephane at harobed.org (KLEIN =?iso-8859-1?q?St=E9phane?=) Date: Tue, 9 Mar 2010 08:30:05 +0000 (UTC) Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? Message-ID: Hi, Today, I've show this static web site generating tools writed in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane From kishoreinme at gmail.com Tue Mar 9 03:39:15 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 00:39:15 -0800 (PST) Subject: pyserial script doesnt execute properly Message-ID: hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately ////file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' "Some Data found" and "Header received" the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever can anyone help? thanks in advance From vinay_sajip at yahoo.co.uk Tue Mar 9 03:54:03 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 9 Mar 2010 00:54:03 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> <9c6a8d26-b71e-4cb8-92d0-49af8728bec4@u15g2000prd.googlegroups.com> Message-ID: <80645b57-b586-400e-8a8d-0ec97f3c8455@b30g2000yqd.googlegroups.com> On Mar 6, 11:13 pm, Pete Emerson wrote: > > 1) In debug mode, send what would have gone to syslog to STDOUT or > STDERR > 2) In non-debug mode, use /dev/log or localhost:514 depending on what > is set > 3) Allow for multiple levels ofloggingbeyond INFO, WARNING, CRIT ... > essentially allow multiple levels of INFO depending on how much detail > is desired. A high level of messaging when programs are running > poorly is desired, but when programs are running smoothly, I don't > need to send as much to syslog. By "debug mode", do you mean the value of the __debug__ variable, or something else (e.g. a flag in your application)? You could certainly do something like (in your logging initialization code): if __debug__: handler = logging.StreamHandler() else: #use domain socket, UDP, etc. handler = logging.handlers.SocketHandler(...) logger.addHandler(handler) where logger is the root logger or some other high-level logger in your application. By the way, are you aware that accessing syslog via openlog etc. may not thread-safe, at least in some environments? Search the Web for "syslog openlog thread" for more info. You can certainly add additional levels to logging (see addLevelName), but I'm not sure that's what you really need. Generally, I find that when there are problems to be debugged, I get more benefits from using the logger hierarchy: I keep the level at logging.DEBUG but just log different things to different loggers. Just as a fr'instance, if I were logging the parsing of HTTP requests, I might use loggers named 'request', 'request.headers', 'request.headers.cookies', 'request.body', 'request.body.multipart' etc. When everything is working well, I have the verbosity of these loggers turned low by e.g. setting the level for the 'request' logger to WARNING or higher; when I want to debug header processing in more detail I might set the level of the 'request.headers' logger to DEBUG, which would output events from request header processing (but not the body), or just turn up the 'request.headers.cookies' level to look in more detail at what's happening during processing "Cookie:" headers. Regards, Vinay Sajip From stephane at harobed.org Tue Mar 9 03:57:32 2010 From: stephane at harobed.org (KLEIN =?ISO-8859-1?Q?St=E9phane?=) Date: Tue, 09 Mar 2010 09:57:32 +0100 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? Message-ID: <1268125052.7405.1.camel@stephane-macbook> Hi, Today, I've show this static web site generating tools write in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane -- St?phane Klein Blog : http://harobed.org Jabber : stephane.klein at jabber.fr From news123 at free.fr Tue Mar 9 04:19:56 2010 From: news123 at free.fr (News123) Date: Tue, 09 Mar 2010 10:19:56 +0100 Subject: pyserial script doesnt execute properly In-Reply-To: References: Message-ID: <4b9612bc$0$6059$426a74cc@news.free.fr> Hi, kishore wrote: > hello there > > Iam using python 2.5.4 > pyserial 2.4 > pywin32-214 > > on windows 7 > > > i hav a small test script written to query a serial device (arduino) > and get back reply appropriately > > > > ////file: test.py > > import serial > print 'hi' > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > ser.close() > ser.open() > ser.write('1') > ser.readline() > ser.readline() > ser.close() > > > > the device waits for '1' through its serial interface and print two > lines if it gets '1' > > "Some Data found" and "Header received" > > > the script works on IDLE well when given one line at a time > > but when given in command line as python test.py it prints hi and wait > forever > Unfortunately I don't remember exacty, but try following: close IDLE and try then to start the script from the command line. I remember having had a problem with idle, that it did not always close the UART port (especially, when an error (e.g. syntax) occured before the close statement) bye N From justin.mailinglists at gmail.com Tue Mar 9 04:34:52 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Tue, 9 Mar 2010 01:34:52 -0800 (PST) Subject: remove element with ElementTree References: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> Message-ID: <8ad6319f-97f1-46b7-b89e-d455bd89ad03@b9g2000pri.googlegroups.com> On Mar 9, 11:35?am, tdan wrote: > I have been using ElementTree to write an app, and would like to > simply remove an element. > But in ElementTree, you must know both the parent and the child > element to do this. > There is no getparent() function, so I am stuck if I only have an > element. > see http://effbot.org/zone/element.htm#accessing-parents From dorzey at googlemail.com Tue Mar 9 05:21:49 2010 From: dorzey at googlemail.com (dorzey) Date: Tue, 9 Mar 2010 02:21:49 -0800 (PST) Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? References: Message-ID: <058ebe77-de1b-4814-917a-57e6e65e2d03@t23g2000yqt.googlegroups.com> On Mar 9, 8:57?am, KLEIN St?phane wrote: > Hi, > > Today, I've show this static web site generating tools write in ruby : > > ?*http://webgen.rubyforge.org/index.html > ?*http://nanoc.stoneship.org/about/ > ?*http://webby.rubyforge.org/tutorial/ > > I like this tools, I'm wonder if there are similar tools in Python ? > > I know Sphinx, but this tools is oriented documentation. > > Thanks for your information, > Stephane I'm only aware of Hyde (http://ringce.com/hyde) Paul From spamfresser at ch3ka.de Tue Mar 9 05:30:26 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 09 Mar 2010 11:30:26 +0100 Subject: related lists mean value In-Reply-To: References: Message-ID: Am 08.03.2010 23:34, schrieb dimitri pater - serpia: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] This kinda looks like you used the wrong data structure. Maybe you should have used a dict, like: {'a': [1, 2], 'c': [5, 0, 7], 'b': [8]} ? > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! As said, I'd have used a dict in the first place, so lets transform this straight forward into one: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] # initialize dict d={} for idx in set(y): d[idx]=[] #collect values for i, idx in enumerate(y): d[idx].append(x[i]) print("d is now a dict of lists: %s" % d) #calculate average for key, values in d.items(): d[key]=sum(values)/len(values) print("d is now a dict of averages: %s" % d) # build the final list w = [ d[key] for key in y ] print("w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) Output is: d is now a dict of lists: {'a': [1, 2], 'c': [5, 0, 7], 'b': [8]} d is now a dict of averages: {'a': 1.5, 'c': 4.0, 'b': 8.0} w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Could have used a defaultdict to avoid dict initialisation, though. Or write a custom class: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] class A: def __init__(self): self.store={} def add(self, key, number): if key in self.store: self.store[key].append(number) else: self.store[key] = [number] a=A() # collect data for idx, val in zip(y,x): a.add(idx, val) # build the final list: w = [ sum(a.store[key])/len(a.store[key]) for key in y ] print("w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) Produces same output, of course. Note that those solutions are both not very efficient, but who cares ;) > thanks! No Problem, Michael From javier.collado at gmail.com Tue Mar 9 05:43:05 2010 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 9 Mar 2010 11:43:05 +0100 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: <058ebe77-de1b-4814-917a-57e6e65e2d03@t23g2000yqt.googlegroups.com> References: <058ebe77-de1b-4814-917a-57e6e65e2d03@t23g2000yqt.googlegroups.com> Message-ID: > I'm only aware of Hyde (http://ringce.com/hyde) There are also jekyll and cyrax: http://github.com/mojombo/jekyll/ http://pypi.python.org/pypi/cyrax/0.1.5 I haven't tried any of them, but it looks like cyrax is in active development and its design was inspired in both jekyll and hyde. Best regards, Javier From spamfresser at ch3ka.de Tue Mar 9 06:11:35 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 09 Mar 2010 12:11:35 +0100 Subject: related lists mean value (golfed) In-Reply-To: References: Message-ID: OK, I golfed it :D Go ahead and kill me ;) x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(a,b,v={}): try: v[a].append(b) except: v[a]=[b] def g(a): return sum(v[a])/len(v[a]) return g w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]] print("w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) Output: w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Regards, Michael From steve at holdenweb.com Tue Mar 9 06:18:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Mar 2010 06:18:06 -0500 Subject: What to do if anything bites. In-Reply-To: <4b957998$0$17135$426a34cc@news.free.fr> References: <4b957998$0$17135$426a34cc@news.free.fr> Message-ID: News123 wrote: > Google Adsense wrote: >> What to do if anything bites. >> >> Check our bites treatment at >> >> http://... > > Pythons don't bite First, if you have to respond to spam please omit the URL that the spammer is trying to bring to Google's attention as well as direct readers. Secondly, do you realise you are posting from an address that has been "suspended due to inactivity"? Otherwise you would have received this message privately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bob at leaddevice.com Tue Mar 9 06:23:59 2010 From: bob at leaddevice.com (BobAalsma) Date: Tue, 9 Mar 2010 03:23:59 -0800 (PST) Subject: Newbie question: python versions differ per user? References: <8a04bbfd-9c48-4397-8c81-c159dc1b8977@33g2000yqj.googlegroups.com> Message-ID: On Mar 8, 8:15?pm, BobAalsma wrote: > I'm on Mac OS X 10.5.8 and downloaded 2.6.4 Mac Installer Disk Image > as/in(?) the sys admin user. For this user Pyhton 2.6.4 is now the > current version. > I want to use Python outside the sys asdmin user. However, all other > users still use Python 2.5.1 (Apple delivered). > > The sys admin user looks in /Library/Frameworks/Python.framework/ > Versions/2.6/lib/... > The other users look in ? ? ? ?/System/Library/Frameworks/ > Python.framework/Version/2.5/lib/... > > I could not find any questions on this matter, so am I the only one? > Did I do something wrong? > I assumed the paths for all users would be modified - too easy? OK, sorry, found out. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Mar 9 06:28:23 2010 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 9 Mar 2010 11:28:23 +0000 (UTC) Subject: Are there in Python some static web site generating tools like?webgen, nanoc or webby in Ruby ? References: Message-ID: KLEIN St?phane wrote: > Hi, > > Today, I've show this static web site generating tools write in ruby : > > * http://webgen.rubyforge.org/index.html > * http://nanoc.stoneship.org/about/ > * http://webby.rubyforge.org/tutorial/ > > I like this tools, I'm wonder if there are similar tools in Python ? > rst2web -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From __peter__ at web.de Tue Mar 9 07:02:12 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Mar 2010 13:02:12 +0100 Subject: related lists mean value (golfed) References: Message-ID: Michael Rudolf wrote: > OK, I golfed it :D > Go ahead and kill me ;) > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > def f(a,b,v={}): > try: v[a].append(b) > except: v[a]=[b] > def g(a): return sum(v[a])/len(v[a]) > return g > w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]] > > print("w is now the list of averages, corresponding with y:\n \ > \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) > > Output: > w is now the list of averages, corresponding with y: > > x: [1, 2, 8, 5, 0, 7] > y: ['a', 'a', 'b', 'c', 'c', 'c'] > w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] >>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Peter From dr.cg at 126.com Tue Mar 9 07:19:22 2010 From: dr.cg at 126.com (CHEN Guang) Date: Tue, 9 Mar 2010 20:19:22 +0800 (CST) Subject: How to detect C Function block using python Message-ID: <19912fa.87bc.12742dd77f8.Coremail.dr.cg@126.com> In the source code of PythoidC ( http://pythoidc.googlecode.com ), I wrote a Parser for C header files with Python regular expression, not only functions but also structs macros. May be of some help. Hey All, I'm new in this community. I am writing a static analyzer for validating C Code using python and for that I'm looking for a python module/API that will detect Function block of a given C-File. I know simple function can be detected using push "{" and poping it if character "}" is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Thanks! Faheem -------------- next part -------------- An HTML attachment was scrubbed... URL: From yinon.me at gmail.com Tue Mar 9 07:27:59 2010 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 9 Mar 2010 04:27:59 -0800 (PST) Subject: Duplicate keys in dict? References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Message-ID: <98e3cd64-063c-47e1-b671-04fd3fa16c71@z11g2000yqz.googlegroups.com> On Mar 7, 6:23?pm, vsoler wrote: > Hello, > > My code snippet reads data from excel ranges. First row and first > column are column headers and row headers respectively. After reding > the range I build a dict. > > What is the best approach for this problem? Can anybody help? Have you tried xlread ? (http://www.python-excel.org/) Best, -- Yinon From efiish at gmail.com Tue Mar 9 08:51:05 2010 From: efiish at gmail.com (Lan Qing) Date: Tue, 9 Mar 2010 21:51:05 +0800 Subject: a newbie's question Message-ID: Hi all, I'm a newbie of python programming language. I have used c/c++ for 5 years, and one year experience in Lua programming language. Can any one give me some advice on learning python. Think you for any help!! best regards!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From casevh at gmail.com Tue Mar 9 08:54:15 2010 From: casevh at gmail.com (casevh) Date: Tue, 9 Mar 2010 05:54:15 -0800 (PST) Subject: Calculating very large exponents in python References: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> Message-ID: On Mar 8, 10:39?pm, casevh wrote: > [also replying to Geremy since the OP's message doesn't appear...] > > On Mar 8, 11:05?am, geremy condra wrote: > > > > > > > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > > > Thanks Geremy, > > > > That has been an absolute bump........... GOD i cant sit on my chair, it has > > > worked even on 512 bit number and with no time.......... > > > superb i would say. > > > > lastly, i am using the code below to calculate Largest Prime factor of a > > > number: > > > > print > > > ('''=======================================================================??========''' > > > ?????? '''????????????? CALCULATE? HIGHEST PRIME > > > FACTOR????????????????????????????????? ''' > > > > '''========================================================================??=======''') > > > > #!/usr/bin/env python > > > def highest_prime_factor(n): > > > ?? if isprime(n): > > > ????? return n > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return highest_prime_factor(n/x) > > > def isprime(n): > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return False > > > ?? return True > > > if? __name__ == "__main__": > > > ?? import time > > > ?? start = time.time() > > > ?? print highest_prime_factor(1238162376372637826) > > > ?? print time.time() - start > > > > the code works with a bit of delay on the number : "1238162376372637826" but > > > extending it to > > > (10902610991329142436630551158108608965062811746392577675456004845499113044??30471090261099132914243663055115810860896506281174639257767545600484549911?3?0443047) > > > ?makes python go crazy. Is there any way just like above, i can have it > > > calculated it in no time. > > > > thanks for the support. > > > If you're just looking for the largest prime factor I would suggest using > > a fermat factorization attack. In the example you gave, it returns > > nearly immediately. > > > Geremy Condra- Hide quoted text - > > > - Show quoted text - > > For a Python-based solution, you might want to look at pyecm (http:// > sourceforge.net/projects/pyecm/) > > On a system with gmpy installed also, pyecm found the following > factors: > > 101, 521, 3121, 9901, 36479, 300623, 53397071018461, > 1900381976777332243781 > > There still is a 98 digit unfactored composite: > > 602525071745682437589111511878284384468144476539868422797968232621651594065?00174226172705680274911 > > Factoring this remaining composite using ECM may not be practical. > > casevh- Hide quoted text - > > - Show quoted text - After a few hours, the remaining factors are 6060517860310398033985611921721 and 9941808367425935774306988776021629111399536914790551022447994642391 casevh From mehgcap at gmail.com Tue Mar 9 08:55:39 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 9 Mar 2010 08:55:39 -0500 Subject: odd error Message-ID: Hi all, In the same program I wrote about yesterday, I have a dictionary of keystrokes which are captured. I just tried adding a new one, bringing the total to 11. Here are entries 10 and 11; 10 has been working fine for months. 10 : (57, win32con.MOD_CONTROL), 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) Now, though, when I press ctrl-shift-c (keystroke 11), nothing happens. Pressing any other keystroke after that will crash the program with some sort of Python internal com server exception that I have never seen before. When set to a keystroke I already use, such as #10, the function called by #11 works just fine. Does anyone see a problem with the above syntax? The trouble almost definitely has to be there; again, using an already-working keystroke instead of making a new one works perfectly, it is just when I add this new one that things break. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From simon at brunningonline.net Tue Mar 9 09:00:42 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 9 Mar 2010 14:00:42 +0000 Subject: a newbie's question In-Reply-To: References: Message-ID: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> On 9 March 2010 13:51, Lan Qing wrote: > Hi all, > ?? ? ?I'm a newbie of python programming language. Welcome! > I have used c/c++ for 5 > years, and one year experience in Lua programming language. Can any one give > me some advice on learning python. Think you for any help!! You'll find some useful starting points here - . -- Cheers, Simon B. From ssteinerx at gmail.com Tue Mar 9 09:04:53 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 9 Mar 2010 09:04:53 -0500 Subject: Opportunity to author Python books- Packt Publishing. In-Reply-To: References: Message-ID: <8E3C96A7-D2AF-4E5F-89CB-74E2F92668D0@gmail.com> On Mar 8, 2010, at 6:25 AM, Kshipra Singh wrote: I would be delighted to write a cookbook on the stuff I use every day: python for administering cloud servers. Thanks, S aka/Steve Steiner aka/ssteinerX > Hi All, > > I am writing to you for Packt Publishing, the publishers computer related books. > > We are planning to extend our catalogue of cookbooks and are currently inviting "Python" fanatics interested in writing a cookbook. So, if you love "Python" and are interested in writing a cookbook, please contact us with your book ideas atauthor at packtpub.com. Even if you do not have a book idea and are simply interested in authoring a cookbook, we are keen to hear from you. > > More details about the opportunity are available at: http://authors.packtpub.com/content/python-fanatics-invited-write-packt > > Thanks > Kshipra Singh > Author Relationship Manager > Packt Publishing > www.PacktPub.com > > Skype: kshiprasingh15 > Twitter: http://twitter.com/kshipras > > Interested in becoming an author? Visit http://authors.packtpub.com for all the information you need about writing for Packt. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Mar 9 09:09:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 09 Mar 2010 09:09:01 -0500 Subject: Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime Message-ID: <1268143741.31835.1363885481@webmail.messagingengine.com> We've decided to build a re-usable *general purpose* PY2EXE "runtime" that can be shared by a number of scripts vs. distributing a monolithic EXE for each of our scripts. A list of the Python 2.6.4 compatible modules/packages we decided to include (and exclude) in our "runtime" follows my signature. Any suggestions on additions or deletions appreciated. Thanks, Malcolm 3rd party modules/packages: - jsonpickle - win32api - winshell We've included all modules from the Python standard library EXCEPT the following: http://www.python.org/doc/2.6.4/modindex.html - aifc - audioop - bsddb - Carbon - dbhash - distutils - dumbdbm - netrc - plistlib - robotparser - ScrolledText - shelve - sunau - tabnanny - Tix - Tkinter - turtle - whichdb -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Tue Mar 9 09:18:42 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Mar 2010 09:18:42 -0500 Subject: imported var not being updated In-Reply-To: References: Message-ID: <4B9658C2.1040707@optimum.net> On 3/8/2010 11:55 PM, Gary Herron wrote: > > The form of import you are using > from helpers import mostRecent > makes a *new* binding to the value in the module that's doing the > import. > What you can do, is not make a separate binding, but reach into the > helpers module to get the value there. Like this: > > import helpers > print helpers.mostRecent > Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name "x" will be bound to different objects? Tx, John From xahlee at gmail.com Tue Mar 9 09:24:42 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 9 Mar 2010 06:24:42 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: <13c167f4-5e37-48a0-a480-3494c212035c@k5g2000pra.googlegroups.com> On Mar 8, 11:14?am, Duncan Booth wrote: > Xah Lee wrote: > > For example, consider, if you are within world's top 100th user of > > database in terms of database size, such as Google, then it may be > > that the off-the-shelf tools may be limiting. But how many users > > really have such massive size of data? > > You've totally missed the point. It isn't the size of the data you have > today that matters, it's the size of data you could have in several years' > time. so, you saying, in several years, we'd all become the world's top 100 database users in terms of size, like Google? Xah ? http://xahlee.org/ ? From benjamin.kaplan at case.edu Tue Mar 9 09:25:38 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 9 Mar 2010 09:25:38 -0500 Subject: imported var not being updated In-Reply-To: <4B9658C2.1040707@optimum.net> References: <4B9658C2.1040707@optimum.net> Message-ID: On Tue, Mar 9, 2010 at 9:18 AM, John Posner wrote: > On 3/8/2010 11:55 PM, Gary Herron wrote: > > > >> The form of import you are using >> from helpers import mostRecent >> makes a *new* binding to the value in the module that's doing the >> import. >> > > > > > What you can do, is not make a separate binding, but reach into the >> helpers module to get the value there. Like this: >> >> import helpers >> print helpers.mostRecent >> >> > Gary, are you asserting that in these separate situations: > > one.py: > > from helpers import mostRecent > x = mostRecent > > two.py: > > import helpers > x = helpers.mostRecent > > > ... the name "x" will be bound to different objects? > > Tx, > John > > No. the name x will be bound to the same object. It's the other way that gives a problem from helpers import mostRecent works like import helpers mostRecent = helpers.mostRecent del helpers so when you do mostRecent = x it rebinds "mostRecent" in the current scope but doesn't affect helpers.mostRecent, the name in the "helpers" module. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Mar 9 09:27:49 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 09 Mar 2010 09:27:49 -0500 Subject: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime In-Reply-To: <1268143741.31835.1363885481@webmail.messagingengine.com> References: <1268143741.31835.1363885481@webmail.messagingengine.com> Message-ID: <1268144869.2338.1363892987@webmail.messagingengine.com> We've decided to build a re-usable *general purpose* PY2EXE "runtime" that can be shared by a number of scripts vs. distributing a monolithic EXE for each of our scripts. A list of the Python 2.6.4 compatible modules/packages we decided to include (and exclude) in our "runtime" follows my signature. Any suggestions on additions or deletions appreciated. Thanks, Malcolm 3rd party modules/packages: - jsonpickle - wmi <--- forgot this one in my original post - win32api - winshell We've included all modules from the Python standard library EXCEPT the following: http://www.python.org/doc/2.6.4/modindex.html - aifc - audioop - bsddb - Carbon - dbhash - distutils - dumbdbm - netrc - plistlib - robotparser - ScrolledText - shelve - sunau - tabnanny - Tix - Tkinter - turtle - whichdb From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 9 09:48:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Mar 2010 15:48:59 +0100 Subject: imported var not being updated In-Reply-To: <4B9658C2.1040707@optimum.net> References: <4B9658C2.1040707@optimum.net> Message-ID: <4b965fde$0$14410$426a74cc@news.free.fr> John Posner a ?crit : > On 3/8/2010 11:55 PM, Gary Herron wrote: > >> >> The form of import you are using >> from helpers import mostRecent >> makes a *new* binding to the value in the module that's doing the >> import. > > > >> What you can do, is not make a separate binding, but reach into the >> helpers module to get the value there. Like this: >> >> import helpers >> print helpers.mostRecent >> > > Gary, are you asserting that in these separate situations: > > one.py: > > from helpers import mostRecent > x = mostRecent > > two.py: > > import helpers > x = helpers.mostRecent > > > ... the name "x" will be bound to different objects? Nope. What he's saying is that one.x and two.x are two different names - each living in it's own namespace - that happen to be bound to the same object. Now rebiding one.x to a different object will _of course_ have no impact on the object two.x is bound to. That's exactly the same as: one = dict() two = dict() # one['x'] and two['x'] refer to the same object one['x'] = two['x'] = ["foo", "bar"] print one['x'], two['x'], one['x'] is two['x'] # mutating one['x'], visible in two['x'] # (of course since it's the same object) one['x'].append("baaz") print one['x'], two['x'], one['x'] is two['x'] # now rebind one['x'] one['x'] = 42 # obvious result: one['x'] and two['x'] now refer to 2 different objects print one['x'], two['x'], one['x'] is two['x'] If in doubt about namespaces, think dicts. Namespaces are like dicts - and are often nothing else that a plain old dict FWIW. HTH From spamfresser at ch3ka.de Tue Mar 9 10:00:00 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 09 Mar 2010 16:00:00 +0100 Subject: related lists mean value (golfed) In-Reply-To: References: Message-ID: Am 09.03.2010 13:02, schrieb Peter Otten: >>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] > [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > Peter ... pwned. Should be the fastest and shortest way to do it. I tried to do something like this, but my brain hurt while trying to visualize list comprehension evaluation orders ;) Regards, Michael From kishoreinme at gmail.com Tue Mar 9 10:01:22 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 07:01:22 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: On Mar 9, 2:19?pm, News123 wrote: > Hi, > > > > kishore wrote: > > hello there > > > Iam using python 2.5.4 > > pyserial ?2.4 > > pywin32-214 > > > on windows 7 > > > i hav a small test script written to query a serial device (arduino) > > and get back reply appropriately > > > ////file: test.py > > > import serial > > print 'hi' > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > ser.close() > > ser.open() > > ser.write('1') > > ser.readline() > > ser.readline() > > ser.close() > > > the device waits for '1' through its serial interface and print two > > lines if it gets '1' > > > "Some Data found" and "Header received" > > > the script works on IDLE well when given one line at a time > > > but when given in command line as python test.py it prints hi and wait > > forever > > Unfortunately I don't remember exacty, but try following: > > close IDLE and try then to start the script from the command line. > I remember having had a problem with idle, that it did not always close > the UART port > (especially, when an error (e.g. syntax) occured before the close statement) > > bye > > N Thanks for your response i tried closing idle and the following code prints port opened Write failed code: import serial import time ser=serial.Serial(port='\\.\COM2', baudrate=9600) if ser: print 'port opened' ser.open() if ser.write('1'): print 'Write success' else: print 'write failed' time.sleep(1) a=ser.readline() time.sleep(1) b=ser.readline() print b ser.close() I believe this might be a serial port access error. how to solve this? Any suggestions? From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 9 10:02:04 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Mar 2010 16:02:04 +0100 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90e2d0$0$10096$426a34cc@news.free.fr> Message-ID: <4b9662ee$0$9131$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: >>> Well, Zope is backed by an object database rather than a relational one. >> >> And it ended up being a *major* PITA on all Zope projects I've worked >> on... > > Care to write a few sentences on nature of problems with zodb? I was > flirting with the thought of using it on some project. Would require more than a few sentences. But mostly, it's about the very nature of the Zodb : it's a giant graph of Python objects. So : 1/ your "data" are _very_ tightly dependant on the language and applicative code 2/ you have to hand-write each and every graph traversal 3/ accessing a given object usually loads quite a few others in memory I once thought the Zodb was cool. From stefan_ml at behnel.de Tue Mar 9 10:07:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Mar 2010 16:07:54 +0100 Subject: remove element with ElementTree In-Reply-To: <8ad6319f-97f1-46b7-b89e-d455bd89ad03@b9g2000pri.googlegroups.com> References: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> <8ad6319f-97f1-46b7-b89e-d455bd89ad03@b9g2000pri.googlegroups.com> Message-ID: Justin Ezequiel, 09.03.2010 10:34: > On Mar 9, 11:35 am, tdan wrote: >> I have been using ElementTree to write an app, and would like to >> simply remove an element. >> But in ElementTree, you must know both the parent and the child >> element to do this. >> There is no getparent() function, so I am stuck if I only have an >> element. > > see http://effbot.org/zone/element.htm#accessing-parents Also note that there is an independent ElementTree implementation called lxml.etree, which has parent pointers. Stefan From showell30 at yahoo.com Tue Mar 9 10:21:15 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 07:21:15 -0800 (PST) Subject: related lists mean value References: <4B95B4FF.1070407@optimum.net> Message-ID: <5574554b-1d62-4faf-bb89-34cb431741cd@q2g2000pre.googlegroups.com> On Mar 8, 6:39?pm, John Posner wrote: > On 3/8/2010 5:34 PM, dimitri pater - serpia wrote: > > > Hi, > > > I have two related lists: > > x = [1 ,2, 8, 5, 0, 7] > > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > > what I need is a list representing the mean value of 'a', 'b' and 'c' > > while maintaining the number of items (len): > > w = [1.5, 1.5, 8, 4, 4, 4] > > > I have looked at iter(tools) and next(), but that did not help me. I'm > > a bit stuck here, so your help is appreciated! > > Nobody expects object-orientation (or the Spanish Inquisition): > Heh. Yep, I avoided OO for this. Seems like a functional problem. My solution is functional on the outside, imperative on the inside. You could add recursion here, but I don't think it would be as straightforward. def num_dups_at_head(lst): assert len(lst) > 0 val = lst[0] i = 1 while i < len(lst) and lst[i] == val: i += 1 return i def smooth(x, y): result = [] while x: cnt = num_dups_at_head(y) avg = sum(x[:cnt]) * 1.0 / cnt result += [avg] * cnt x = x[cnt:] y = y[cnt:] return result > #------------------------- > from collections import defaultdict > > class Tally: > ? ? ?def __init__(self, id=None): > ? ? ? ? ?self.id = id > ? ? ? ? ?self.total = 0 > ? ? ? ? ?self.count = 0 > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c'] > > # gather data > tally_dict = defaultdict(Tally) > for i in range(len(x)): > ? ? ?obj = tally_dict[y[i]] > ? ? ?obj.id = y[i] > ? ? ?obj.total += x[i] > ? ? ?obj.count += 1 > > # process data > result_list = [] > for key in sorted(tally_dict): > ? ? ?obj = tally_dict[key] > ? ? ?mean = 1.0 * obj.total / obj.count > ? ? ?result_list.extend([mean] * obj.count) > print result_list > #------------------------- From kishoreinme at gmail.com Tue Mar 9 10:30:32 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 07:30:32 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: <6596caf4-8d36-40b4-8e8d-a5ed2a18f245@z1g2000prc.googlegroups.com> On Mar 9, 8:01?pm, kishore wrote: > On Mar 9, 2:19?pm, News123 wrote: > > > > > Hi, > > > kishore wrote: > > > hello there > > > > Iam using python 2.5.4 > > > pyserial ?2.4 > > > pywin32-214 > > > > on windows 7 > > > > i hav a small test script written to query a serial device (arduino) > > > and get back reply appropriately > > > > ////file: test.py > > > > import serial > > > print 'hi' > > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > > ser.close() > > > ser.open() > > > ser.write('1') > > > ser.readline() > > > ser.readline() > > > ser.close() > > > > the device waits for '1' through its serial interface and print two > > > lines if it gets '1' > > > > "Some Data found" and "Header received" > > > > the script works on IDLE well when given one line at a time > > > > but when given in command line as python test.py it prints hi and wait > > > forever > > > Unfortunately I don't remember exacty, but try following: > > > close IDLE and try then to start the script from the command line. > > I remember having had a problem with idle, that it did not always close > > the UART port > > (especially, when an error (e.g. syntax) occured before the close statement) > > > bye > > > N > > Thanks for your response > i tried closing idle and the following code prints > port opened > Write failed > > code: > > import serial > import time > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > if ser: > ? ? ? ? print 'port opened' > ser.open() > if ser.write('1'): > ? ? ? ? print 'Write success' > else: > ? ? ? ? print 'write failed' > > time.sleep(1) > > a=ser.readline() > time.sleep(1) > b=ser.readline() > print b > ser.close() > > I believe this might be a serial port access error. > how to solve this? > Any suggestions? have found one more person with same problem but no solution http://mail.python.org/pipermail/python-win32/2009-January/008613.html From eckhardt at satorlaser.com Tue Mar 9 10:40:59 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 09 Mar 2010 16:40:59 +0100 Subject: odd error References: Message-ID: Alex Hall wrote: > Now, though, when I press ctrl-shift-c (keystroke 11), nothing > happens. Control-C sends a special signal to the console, like Control-Break. > Pressing any other keystroke after that will crash the program > with some sort of Python internal com server exception that I > have never seen before. Neither do I, in particular since you don't share that rare gem with us. ;) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From kishoreinme at gmail.com Tue Mar 9 10:42:21 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 07:42:21 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: <2c849953-6556-4f5b-b88c-1fae6e4f27ce@t20g2000yqe.googlegroups.com> On Mar 9, 8:01?pm, kishore wrote: > On Mar 9, 2:19?pm, News123 wrote: > > > > > Hi, > > > kishore wrote: > > > hello there > > > > Iam using python 2.5.4 > > > pyserial ?2.4 > > > pywin32-214 > > > > on windows 7 > > > > i hav a small test script written to query a serial device (arduino) > > > and get back reply appropriately > > > > ////file: test.py > > > > import serial > > > print 'hi' > > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > > ser.close() > > > ser.open() > > > ser.write('1') > > > ser.readline() > > > ser.readline() > > > ser.close() > > > > the device waits for '1' through its serial interface and print two > > > lines if it gets '1' > > > > "Some Data found" and "Header received" > > > > the script works on IDLE well when given one line at a time > > > > but when given in command line as python test.py it prints hi and wait > > > forever > > > Unfortunately I don't remember exacty, but try following: > > > close IDLE and try then to start the script from the command line. > > I remember having had a problem with idle, that it did not always close > > the UART port > > (especially, when an error (e.g. syntax) occured before the close statement) > > > bye > > > N > > Thanks for your response > i tried closing idle and the following code prints > port opened > Write failed > > code: > > import serial > import time > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > if ser: > ? ? ? ? print 'port opened' > ser.open() > if ser.write('1'): > ? ? ? ? print 'Write success' > else: > ? ? ? ? print 'write failed' > > time.sleep(1) > > a=ser.readline() > time.sleep(1) > b=ser.readline() > print b > ser.close() > > I believe this might be a serial port access error. > how to solve this? > Any suggestions? have found one more person with same problem but no solution http://mail.python.org/pipermail/python-win32/2009-January/008613.html From stefan_ml at behnel.de Tue Mar 9 10:45:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Mar 2010 16:45:48 +0100 Subject: remove element with ElementTree In-Reply-To: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> References: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> Message-ID: tdan, 09.03.2010 04:35: > I have been using ElementTree to write an app, and would like to > simply remove an element. > But in ElementTree, you must know both the parent and the child > element to do this. > There is no getparent() function, so I am stuck if I only have an > element. > > I am iterating over a table and getting all tags, checking their > text, and conditionally deleting them: > > def RemoveElementWithText( topEl, subEl, text ): Note that all-camel-case names are rather unusual for function names and rather used for class names. See PEP 8 for a style guide. > for el in topEl.getiterator( subEl ): > if el.text = text: > break > else: > el = None > return el > > RemoveElementWithText( table, 'td', 'sometext' ) > > My table is like so: > > > ... > # I need to grab this number only # I need to grab this number only # I need to grab this number only """[/CODE] From gagsl-py2 at yahoo.com.ar Fri Mar 19 23:09:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Mar 2010 00:09:46 -0300 Subject: Simple lock References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> <4BA4337B.6050301@mrabarnett.plus.com> Message-ID: En Fri, 19 Mar 2010 23:31:23 -0300, MRAB escribi?: > moerchendiser2k3 wrote: >> class SetPointer >> { >> private: >> void *ptr; >> MY_LOCK lock; >> public: >> void SetPointer(void *p) >> { >> Lock(this->lock); >> this->ptr = p; >> } > 3. You're locking, but never unlocking. The sequence should be: lock, do > stuff, unlock. Just FYI: C++ doesn't have try/finally, and such behavior is usually emulated using a local object. When it goes out of scope, it is automatically destroyed, meaning that the object destructor is called. Whatever you would write in a "finally" clause, in C++ goes into a destructor. Of course C++ guys would never say they're "emulating" try/finally, instead they declare RAII as *the* Only and Right Way :) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Fri Mar 19 23:20:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 03:20:38 GMT Subject: Tuples vs. variable-length argument lists References: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> Message-ID: <4ba43f05$0$27838$c3e8da3@news.astraweb.com> On Fri, 19 Mar 2010 17:20:31 -0700, Spencer Pearson wrote: > Hi! > > This might be more of a personal-preference question than anything, but > here goes: when is it appropriate for a function to take a list or tuple > as input, and when should it allow a varying number of arguments? That depends on the function as well as your personal preference. Of course, you can also follow the lead of max and min and accept both: >>> max(1, 2, 3, 4) == max([1, 2, 3, 4]) True You need to consider which is more "natural" for the semantics of the function. > It seems as though the two are always interchangeable. Not always. Consider sum(a, b, c, d). Should that be "sum the sequence [a, b, c, d]" or "sum the sequence [a, b, c] with initial value d"? You might ask what difference it makes, but it may make a big difference: * if a...d are floats, there may be differences in rounding errors between a+b+c+d and d+a+b+c * if a...d are lists, the order that you do the addition matters: ["a", "b", "c"] + ["d"] != ["d"] + ["a", "b", "c"] * even if a...d are integers, it may make a big difference for performance. Perhaps not for a mere four arguments, but watch: >>> n = 10**1000000 >>> seq = [n] + range(10001) >>> from timeit import Timer >>> t1 = Timer("sum(seq)", "from __main__ import n, seq; seq.append(-n)") >>> t2 = Timer("sum(seq, -n)", "from __main__ import n, seq") >>> min(t1.repeat(number=1)) 6.1270790100097656 >>> min(t2.repeat(number=1)) 0.012988805770874023 In the first case, all the intermediate calculations are done using a million digit long int, in the second case it is not. [...] > I can't think > of any situation where you couldn't convert from one form to the other > with just a star or a pair of parentheses. Of course you can convert, but consider that this is doing a conversion. Perhaps that's unnecessary work for your specific function? You are packing and unpacking a sequence into a tuple. Whether this is a good thing or a bad thing depends on the function. > Is there a generally accepted convention for which method to use? Is > there ever actually a big difference between the two that I'm not > seeing? If you think of the function as operating on a single argument which is a sequence of arbitrary length, then it is best written to take a single sequence argument. If you think of the function as operating on an arbitrary number of arguments, then it is best written to take an arbitrary number of arguments. If you think it doesn't matter, then choose whichever model is less work for you. If neither seems better than the other, then choose arbitrarily. If you don't like the idea of making an arbitrary choice, or if your users complain, then support both models (if possible). -- Steven From gagsl-py2 at yahoo.com.ar Fri Mar 19 23:21:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Mar 2010 00:21:44 -0300 Subject: Best Way to extract Numbers from String References: Message-ID: En Sat, 20 Mar 2010 00:04:08 -0300, Jimbo escribi?: > I am trying to grab some numbers from a string containing HTML text. > Can you suggest any good functions that I could use to do this? What > would be the easiest way to extract the following numbers from this > string... > > My String has this layout & I have commented what I want to grab: > [CODE] """ > > > > # > I need to grab this number only > > # > I need to grab this number only I'd use BeautifulSoup [1] to handle bad formed HTML like that. [1] http://www.crummy.com/software/BeautifulSoup/ -- Gabriel Genellina From python at mrabarnett.plus.com Fri Mar 19 23:38:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Mar 2010 03:38:27 +0000 Subject: Simple lock In-Reply-To: References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> <4BA4337B.6050301@mrabarnett.plus.com> Message-ID: <4BA44333.8010308@mrabarnett.plus.com> Gabriel Genellina wrote: > En Fri, 19 Mar 2010 23:31:23 -0300, MRAB > escribi?: >> moerchendiser2k3 wrote: > >>> class SetPointer >>> { >>> private: >>> void *ptr; >>> MY_LOCK lock; >>> public: >>> void SetPointer(void *p) >>> { >>> Lock(this->lock); >>> this->ptr = p; >>> } > >> 3. You're locking, but never unlocking. The sequence should be: lock, do >> stuff, unlock. > > Just FYI: C++ doesn't have try/finally, and such behavior is usually > emulated using a local object. When it goes out of scope, it is > automatically destroyed, meaning that the object destructor is called. > Whatever you would write in a "finally" clause, in C++ goes into a > destructor. > > Of course C++ guys would never say they're "emulating" try/finally, > instead they declare RAII as *the* Only and Right Way :) > Lock() doesn't look like a declaration, but a function call (although it's been a while since I last did C++!). In the past I've written some C++ code where try..finally... would've been useful... *sigh* From alfps at start.no Sat Mar 20 00:15:08 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 20 Mar 2010 05:15:08 +0100 Subject: Simple lock In-Reply-To: References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> <4BA4337B.6050301@mrabarnett.plus.com> Message-ID: * MRAB: > Gabriel Genellina wrote: >> En Fri, 19 Mar 2010 23:31:23 -0300, MRAB >> escribi?: >>> moerchendiser2k3 wrote: >> >>>> class SetPointer >>>> { >>>> private: >>>> void *ptr; >>>> MY_LOCK lock; >>>> public: >>>> void SetPointer(void *p) >>>> { >>>> Lock(this->lock); >>>> this->ptr = p; >>>> } >> >>> 3. You're locking, but never unlocking. The sequence should be: lock, do >>> stuff, unlock. >> >> Just FYI: C++ doesn't have try/finally, and such behavior is usually >> emulated using a local object. When it goes out of scope, it is >> automatically destroyed, meaning that the object destructor is called. >> Whatever you would write in a "finally" clause, in C++ goes into a >> destructor. >> >> Of course C++ guys would never say they're "emulating" try/finally, >> instead they declare RAII as *the* Only and Right Way :) >> > Lock() doesn't look like a declaration, but a function call (although > it's been a while since I last did C++!). Right. But the OP is clearly a beginner who has yet to learn conventions (like all uppercase reserved for macros) and good versus bad programming constructs (like using void*), and who is even confusing C++ with Python. So it might just be that 'Lock' is a macro, and then it can expand to anything. > In the past I've written some C++ code where try..finally... would've > been useful... *sigh* Check out Marginean and Alexandrescu's ScopeGuard. Old DDJ-article. For MSVC you may want to change use of __LINE__ in that code, to MS-specific __COUNTER__. Fwiw. I can't remember ever needing 'finally' in C++ code. It indicates a lack of encapsulation of entitites that should clean up themselves. Simple smart pointers etc. can help. E.g., check out Boost library. Cheers & hth., even if a little off-topic, - Alf From kse.listed.co1 at gmail.com Sat Mar 20 00:18:15 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Fri, 19 Mar 2010 21:18:15 -0700 (PDT) Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" Message-ID: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" From aahz at pythoncraft.com Sat Mar 20 00:39:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Mar 2010 21:39:38 -0700 Subject: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime References: <1268143741.31835.1363885481@webmail.messagingengine.com> Message-ID: In article , wrote: > >We've decided to build a re-usable *general purpose* PY2EXE "runtime" >that can be shared by a number of scripts vs. distributing a monolithic >EXE for each of our scripts. It's not clear what the purpose of this is. You can build several scripts against the same py2exe backend. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From Brian.Mingus at Colorado.EDU Sat Mar 20 00:41:42 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Fri, 19 Mar 2010 22:41:42 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> On Fri, Mar 19, 2010 at 10:18 PM, Naeem wrote: > "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY > FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY > RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" > "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" > "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" > -- > http://mail.python.org/mailman/listinfo/python-list > Guys, I know it is a lot of work to moderate a large mailing list. But still, with so many of us surely we can pull it off? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 02:23:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 06:23:14 GMT Subject: Writing tests for the Python bug tracker Message-ID: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> I have two reported bugs in the bug tracker waiting on tests: http://bugs.python.org/issue8128 http://bugs.python.org/issue4037 Are there any guidelines for writing tests for the standard library and language? I've googled, but found nothing useful: lots of guidelines for writing tests, and of course I've read PEP 8, but I'm not sure if there are conventions for tests I'm missing. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 02:52:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 06:52:08 GMT Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4ba47098$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 06:23:14 +0000, Steven D'Aprano wrote: > Are there any guidelines for writing tests for the standard library and > language? I've googled, but found nothing useful: lots of guidelines for > writing tests, and of course I've read PEP 8, but I'm not sure if there > are conventions for tests I'm missing. I've found this: http://docs.python.org/library/test.html and I've written a small test: $ cat test_unicode_interpolation.py # For testing http://bugs.python.org/issue8128 import test.test_support import unittest class K(unicode): def __str__(self): return "Surprise!" class UnicodeInterpolationTest(unittest.TestCase): def test_interpolation(self): self.assertEquals(u'%s' % K('some text'), 'Surprise!') def test_main(): test.test_support.run_unittest(UnicodeInterpolationTest) if __name__ == "__main__": test_main() but when I try running the test, I get an error: $ python test_unicode_interpolation.py Options: {'delimiter': None} str of options.delimiter = None repr of options.delimiter = None len of options.delimiter Traceback (most recent call last): File "test_unicode_interpolation.py", line 3, in import test.test_support File "/home/steve/python/test.py", line 8, in print "len of options.delimiter", len(options.delimiter) TypeError: object of type 'NoneType' has no len() What am I doing wrong? (By the way, I'm expecting the unit test above to fail.) -- Steven From exarkun at twistedmatrix.com Sat Mar 20 03:07:58 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sat, 20 Mar 2010 07:07:58 -0000 Subject: Writing tests for the Python bug tracker In-Reply-To: <4ba47098$0$27838$c3e8da3@news.astraweb.com> References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> <4ba47098$0$27838$c3e8da3@news.astraweb.com> Message-ID: <20100320070758.2792.893406088.divmod.xquotient.1775@localhost.localdomain> On 06:52 am, steve at remove-this-cybersource.com.au wrote: > >but when I try running the test, I get an error: > >$ python test_unicode_interpolation.py >Options: {'delimiter': None} >str of options.delimiter = None >repr of options.delimiter = None >len of options.delimiter >Traceback (most recent call last): > File "test_unicode_interpolation.py", line 3, in > import test.test_support > File "/home/steve/python/test.py", line 8, in > print "len of options.delimiter", len(options.delimiter) >TypeError: object of type 'NoneType' has no len() > > >What am I doing wrong? Take a careful look at the stack being reported. Then, think of a better name than "test" for your file. Jean-Paul From greg.ewing at canterbury.ac.nz Sat Mar 20 03:32:23 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 20 Mar 2010 20:32:23 +1300 Subject: to pass self or not to pass self In-Reply-To: References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: <80jbd2Fhd3U1@mid.individual.net> Patrick Maupin wrote: > Actually, I think I overstated my case -- there is some special logic > for len and built-in objects, I think. Yes, len() invokes the C-level sq_len slot of the type object, which for built-in types points directly to the C function implementing the len() operation for that type. So len() on a string doesn't involve looking up a __len__ attribute or creating a bound method at all. The only reason a __len__ attribute exists at all for built-in types is to give Python code the illusion that C-coded and Python-coded classes work the same way. Most of the time it's never used. If you try the same test using a method that doesn't have a corresponding type slot (basically anything without a double_underscore name) you will probably see a small improvement. -- Greg From __peter__ at web.de Sat Mar 20 04:36:22 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Mar 2010 09:36:22 +0100 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Jean-Michel Pichavant wrote: > You are still accessing the private attribute of the module logging. Just reading it is a significantly more conservative approach than setting it to an object with an unusual notion of equality ;) > My previous remark was misleading, in fact there's nothing you can do > about it. How about replacing logging._srcfile with fixname(logging.__file__)? > _srcfile is not meant to be used elsewhere than in the logging module > itself. > However, I don't wanna sound like I'm rejecting this solution, 1st the > OP is satisified with it and since this solution is working, it is still > more helpful than anyone noticing that you've accessed a private > attribute (some will successfully argue that python allows to do so). Yeah, I had hoped that I could get away without drawing the "consenting adults" wildcard... > At the very begining of this thread I've provided a complete different > approach, instead of using the builtin 'filename' and 'lineno' field of > the logging, use custom fileds with the extra parameter. > > It has also some drawbacks but could be a possible alternative. Having two filename/lineno sets ist likely to confuse. Peter From hawat.thufir at gmail.com Sat Mar 20 05:17:14 2010 From: hawat.thufir at gmail.com (Thufir) Date: Sat, 20 Mar 2010 09:17:14 GMT Subject: google token Message-ID: I'd like to acquire a token, as below, but from Java: def get_token(self,force=False) : '''Return a tokey. A token is a special string that is used like a session identification, but that expire rather quickly.''' if ( force or (self._token == None) ) : feedurl = CONST.URI_PREFIXE_API + CONST.API_TOKEN + '? client=' + CONST.AGENT # print feedurl self._token = self._web.get(feedurl) return self._token http://pyrfeed.googlecode.com/svn/trunk/lib/GoogleReader/reader.py Basically, that's just a GET on a particular URL, and the returned string is saved as _token? thanks, Thufir From stefan_ml at behnel.de Sat Mar 20 05:44:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Mar 2010 10:44:39 +0100 Subject: C-API PyObject_Call In-Reply-To: <7597f6a5-5fe0-4a69-9f9b-f0d96f4499d1@g26g2000yqn.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> <7597f6a5-5fe0-4a69-9f9b-f0d96f4499d1@g26g2000yqn.googlegroups.com> Message-ID: moerchendiser2k3, 20.03.2010 03:01: > Yes, the user is able to set a file which contains a function that > does what the user wants. > But in a case, I expect a special return value of this function. Ah, ok, that was the important piece of information that you omitted from your previous posts. So what you actually do is call a user provided function and you want to report errors back to the user if the function does not behave as expected by the (plugin) interface, and not only when it raises an exception itself. You might want to read this: http://catb.org/~esr/faqs/smart-questions.html > So, I need to tell him, in which file/line the error occured, > otherwise he dont know where to look. > > Imagine he set 20 files, and all of them have implemented a special > function. So he wouldnt know where to check for the error. Well, you can easily get at the module file path and the function name through introspection of the function, just as you would in Python. That should be enough information to present to the user. I don't see why you would want to add the exact line number of the return statement. The inner workings of the user function you call are up to the user, after all. Again, take a look at Cython, where you can do the introspection in Python code. Stefan From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 05:53:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 09:53:33 GMT Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> <4ba47098$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4ba49b1d$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 07:07:58 +0000, exarkun wrote: >>What am I doing wrong? > > Take a careful look at the stack being reported. Then, think of a > better name than "test" for your file. Doh! *face-palm* I was shadowing the test package with a long forgotten test module. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 06:12:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 10:12:40 GMT Subject: google token References: Message-ID: <4ba49f98$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 09:17:14 +0000, Thufir wrote: > I'd like to acquire a token, as below, but from Java: Perhaps you should be asking a Java discussion group? This group is for discussing Python. -- Steven From dickinsm at gmail.com Sat Mar 20 06:56:51 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Mar 2010 03:56:51 -0700 (PDT) Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> Message-ID: <556adeb4-ac03-4dfe-92a5-814821fd5bfb@z4g2000yqa.googlegroups.com> On Mar 20, 6:23?am, Steven D'Aprano wrote: > I have two reported bugs in the bug tracker waiting on tests: > > http://bugs.python.org/issue8128http://bugs.python.org/issue4037 > > Are there any guidelines for writing tests for the standard library and > language? Not that I can think of, beyond those you've already mentioned. I mostly just copy the style of existing tests (though there are definitely some test_*** files that aren't particularly well written). For quick questions, you might get good answers by asking on the #python-dev freenode IRC channel: a good few of the people interested in testing (esp. Michael Foord, Ezio Melotti) can often be found there. -- Mark From dickinsm at gmail.com Sat Mar 20 07:00:31 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Mar 2010 04:00:31 -0700 (PDT) Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> <4ba47098$0$27838$c3e8da3@news.astraweb.com> Message-ID: <218770fd-9928-4dfd-9c9c-6fdecbafbaee@k17g2000yqb.googlegroups.com> On Mar 20, 6:52?am, Steven D'Aprano wrote: > I've found this: > > http://docs.python.org/library/test.html > > and I've written a small test: > > $ cat test_unicode_interpolation.py > # For testinghttp://bugs.python.org/issue8128 > > import test.test_support > import unittest > > class K(unicode): > ? ? def __str__(self): return "Surprise!" > > class UnicodeInterpolationTest(unittest.TestCase): > ? ? def test_interpolation(self): > ? ? ? ? self.assertEquals(u'%s' % K('some text'), 'Surprise!') > > def test_main(): > ? ? test.test_support.run_unittest(UnicodeInterpolationTest) > > if __name__ == "__main__": > ? ? test_main() This looks like a fine start to me. I have a feeling that the current fashion is for assertEqual rather than assertEquals, but I might be wrong. :) -- Mark From chambon.pascal at gmail.com Sat Mar 20 07:31:47 2010 From: chambon.pascal at gmail.com (Pascal Chambon) Date: Sat, 20 Mar 2010 12:31:47 +0100 Subject: Precedence of py, pyd, so, egg, and folder modules/packages when importing Message-ID: <4BA4B223.90207@gmail.com> Hello, I've run into a slight issue when turning my package hierarchy into a parallel hierarchy of compiled cython extensions. Fue to the compilation process, pure python and C modules must have the basename, and they're located in the same folders. Is there any way for me to ensure that, if both modules sets are installed by an user, the compiled, faster module will ALWAYS be imported instead of the pure python one ? Or am I forced to remove pure-python sources when cython ones must be used ? More generally, is there any certainty about the precedence of the misc. module types, when several of them are in the same path ? I have found nothing about it online. Thanks for the attention, regards, Pascal From news1234 at free.fr Sat Mar 20 08:16:08 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 13:16:08 +0100 Subject: accessing variable of the __main__ module Message-ID: <4ba4bc88$0$29961$426a74cc@news.free.fr> Hi, I wondered about the best way, that a module's function could determine the existance and value of variables in the __main__ module. What I came up with is: ########### main.py ########## import mod A = 4 if __name__ == "__main__": mod.f() ########### mod.py ########## def f(): try: from __main__ import A except ImportError as e: A = "does not exist" print "__main__.A" ,A Is there anything better / more pythonic? Thanks in advance and bye N From python at bdurham.com Sat Mar 20 08:46:49 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 20 Mar 2010 08:46:49 -0400 Subject: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime In-Reply-To: References: <1268143741.31835.1363885481@webmail.messagingengine.com> Message-ID: <1269089209.14921.1365809185@webmail.messagingengine.com> Aahz, >> We've decided to build a re-usable *general purpose* PY2EXE "runtime" >> that can be shared by a number of scripts vs. distributing a monolithic >> EXE for each of our scripts. > It's not clear what the purpose of this is. You can build several > scripts against the same py2exe backend. Yes you can, but with our technique we only build and distribute our py2exe backend *once*. Our goal was to build a custom Python runtime that we could build and deploy once and then augment with the many scripts we distribute and update. By including the full Python standard library (minus non-Windows and certain deprecated modules) and a few additional 3rd party modules/packages (win32, wmi, jsonpickle, etc) our script distribution has become significantly easier, faster and more robust - especially for scripts that may make dynamic module imports missed by py2exe. Script updates are incredibly fast because our clients only download the scripts themselves (packaged as standalone zip files). Not that disk space is a concern any more, but our client footprint is significantly smaller without every script being a single file exe. I recognize that this technique might not work for everyone, but it has worked out extremely well for us. Malcolm ----- Original message ----- From: "Aahz" To: python-list at python.org Date: 19 Mar 2010 21:39:38 -0700 Subject: Re: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime In article , wrote: > >We've decided to build a re-usable *general purpose* PY2EXE "runtime" >that can be shared by a number of scripts vs. distributing a monolithic >EXE for each of our scripts. It's not clear what the purpose of this is. You can build several scripts against the same py2exe backend. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer -- http://mail.python.org/mailman/listinfo/python-list From alfps at start.no Sat Mar 20 08:47:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 20 Mar 2010 13:47:41 +0100 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4bc88$0$29961$426a74cc@news.free.fr> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> Message-ID: * News123: > > I wondered about the best way, that a module's function could determine > the existance and value of variables in the __main__ module. > > > What I came up with is: > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": mod.f() > ########### mod.py ########## > def f(): > try: > from __main__ import A > except ImportError as e: > A = "does not exist" > print "__main__.A" ,A > > Is there anything better / more pythonic? I don't know if this is what you're after, because it's design level instead of technical-Python level. But consider the knowledge distribution above. I see it as like a doctor (main program) telling a nurse (mod.f) to please do something for which the nurse would require some ImportantFact, which the good doctor absent-mindedly forgets to tell the nurse. Trying to do as told the nurse discovers that she needs the ImportantFact, and knowing that it might be available in one of the doctor's files she breaks into his office, finds the PC up and running with the doctor logged in, hurray!, and starts looking... I think the doctor should just give the nurse the ImportantFact right away, not be so absent-minded and unavailable for query later. And I think that if the nurse isn't told the ImportantFact and discovers that she needs it to do what she's told, then the proper thing to do is not to break into the doctor's office and go browsing in his files to possibly find what she needs. For example, she might instead raise an exception. Don't know how they do that in hospitals, though. Cheers & hth., - Alf From luismgz at gmail.com Sat Mar 20 08:51:25 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sat, 20 Mar 2010 05:51:25 -0700 (PDT) Subject: Best Way to extract Numbers from String References: Message-ID: On Mar 20, 12:04?am, Jimbo wrote: > Hello > > I am trying to grab some numbers from a string containing HTML text. > Can you suggest any good functions that I could use to do this? What > would be the easiest way to extract the following numbers from this > string... > > My String has this layout & I have commented what I want to grab: > [CODE] """ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > I need to grab this number only > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > I need to grab this number only > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I need to > grab this number only > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? """[/CODE] You should use BeautifulSoup or perhaps regular expressions. Or if you are not very smart, lik me, just try a brute force approach: >>> for i in s.split('>'): for e in i.split(): if '.' in e and e[0].isdigit(): print (e) 43.200 0.040 43.150 43.200 43.130 43.290 43.100 >>> From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 09:05:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 13:05:41 GMT Subject: accessing variable of the __main__ module References: <4ba4bc88$0$29961$426a74cc@news.free.fr> Message-ID: <4ba4c824$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 13:16:08 +0100, News123 wrote: > Hi, > > > I wondered about the best way, that a module's function could determine > the existance and value of variables in the __main__ module. > > > What I came up with is: > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": mod.f() > ########### mod.py ########## > def f(): > try: > from __main__ import A > except ImportError as e: > A = "does not exist" > print "__main__.A" ,A > > Is there anything better / more pythonic? First problem: You try to import from "__main__", but the other module is called "main". __main__ is a special name, which Python understands as meaning "this module that you are in now". For example: $ cat test_main.py x = "something special" import __main__ # magic alias for this module print __main__.x $ python test_main.py something special So inside "mod.py", the line "from __main__ import A" tries to import A from mod.py, not from main.py. You need to say "from main import A" instead. But if you do this, it creates a second problem: you have a circular import, which is generally considered a Bad Thing. The problem is that: (1) module main tries to import module mod (2) module mod tries to import module main (3) but main is still waiting for mod to be imported Now, in your case you escape that trap, because the import is inside a function, so it doesn't occur until you call the function. But it is still considered poor practice: it is best to avoid circular imports unless you really, really need them. The question is, why does module mod.py care what is happening in main.py? It is better for mod.py to be self-contained, and not care about main.py at all. If it needs A, let the caller pass A to it: ########### main.py ########## import mod A = 4 if __name__ == "__main__": mod.f(__name__, A) ########### mod.py ########## def f(caller, A): print "%s.A: %s" % (caller, A) -- Steven From news1234 at free.fr Sat Mar 20 09:32:03 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 14:32:03 +0100 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4c824$0$27838$c3e8da3@news.astraweb.com> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> <4ba4c824$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4ba4ce53$0$28677$426a34cc@news.free.fr> Hi Steven, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 13:16:08 +0100, News123 wrote: > >> Hi, >> >> >> I wondered about the best way, that a module's function could determine >> the existance and value of variables in the __main__ module. >> >> >> What I came up with is: >> ########### main.py ########## >> import mod >> A = 4 >> if __name__ == "__main__": mod.f() >> ########### mod.py ########## >> def f(): >> try: >> from __main__ import A >> except ImportError as e: >> A = "does not exist" >> print "__main__.A" ,A >> >> Is there anything better / more pythonic? > > > First problem: > > You try to import from "__main__", but the other module is called "main". > __main__ is a special name, which Python understands as meaning "this > module that you are in now". For example: My choice of names was perhaps not very smart. I could have called main.py also mytoplevel.py > > $ cat test_main.py > x = "something special" > import __main__ # magic alias for this module > print __main__.x > > $ python test_main.py > something special > > So inside "mod.py", the line "from __main__ import A" tries to import A > from mod.py, not from main.py. You need to say "from main import A" > instead. > I think you're wrong, my above code seems to work. __main__ refers not to the current module, but to the urrent 'top-level-module' so from __main__ import A tries to import from the top level module which is in my case main.py. > But if you do this, it creates a second problem: you have a circular > import, which is generally considered a Bad Thing. The problem is that: > > (1) module main tries to import module mod > (2) module mod tries to import module main > (3) but main is still waiting for mod to be imported > > Now, in your case you escape that trap, because the import is inside a > function, so it doesn't occur until you call the function. But it is > still considered poor practice: it is best to avoid circular imports > unless you really, really need them. > > > The question is, why does module mod.py care what is happening in > main.py? It is better for mod.py to be self-contained, and not care about > main.py at all. If it needs A, let the caller pass A to it: The reason is pure lazyness. I would like to 'try' something quickly. I have a module used by many different python programs. In case the __main__ module contains a certain object I'd like to extract information from this object if not not. This is for debug, not for 'production'. I'd prefer to change only one file and not many. > > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": > mod.f(__name__, A) > > ########### mod.py ########## > def f(caller, A): > print "%s.A: %s" % (caller, A) > > > N From news1234 at free.fr Sat Mar 20 09:38:43 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 14:38:43 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port Message-ID: <4ba4cfe3$0$7060$426a74cc@news.free.fr> I'm having a small multiprocessing manager: # ########################## import socket,sys from multiprocessing.managers import BaseManager mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') try: srvr = mngr.get_server() except socket.error as e: print "probably address already in use" sys.exit() print "serving" srvr.serve_forever() Under linux this script can only be run once. The second call will raise an exception, as the previous program is already listening to pot 8089. Under Windows however the program can be started twice. and will print twice "serving". This surprises me Howver only one of them will successfully listen and respond to connections, but I don't get an exception. Is this to be expected? I'd like to be sure, that the manager is only started once and that it can be started anytime it's not up. N From gatoygata2 at gmail.com Sat Mar 20 09:54:53 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sat, 20 Mar 2010 06:54:53 -0700 (PDT) Subject: How User-defined method objects are created? Message-ID: I'm trying to understand the description of method object creation in the python 2.6 language reference (3.2. The standard type hierarchy) with little success. The points knocking me are: "User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object, an unbound user-defined method object, or a class method object. When the attribute is a user-defined method object, a new method object is only created if the class from which it is being retrieved is the same as, or a derived class of, the class stored in the original method object; otherwise, the original method object is used as it is." It is a bit of a tongue-twister for me. What the last sentence means? Please, I beg for a simple example of the different objects (user defined function, user defined method, class method) refered. Are maybe the refered objects exemplified by : #python 3.1 class Klass(): def met(self): print('method') def func(): print('function') @classmethod def kmet(klass): print('classmethod') or it is talking about another thing? What is the difference with python 3 where there is no mention to the unbound user-defined method object (same section in python 3 language reference): "User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object or a class method object." I'm trying to learn, however the task is revealing as an enormous undertaking :-) JA From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 10:04:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 14:04:41 GMT Subject: accessing variable of the __main__ module References: <4ba4bc88$0$29961$426a74cc@news.free.fr> <4ba4c824$0$27838$c3e8da3@news.astraweb.com> <4ba4ce53$0$28677$426a34cc@news.free.fr> Message-ID: <4ba4d5f9$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 14:32:03 +0100, News123 wrote: >> You try to import from "__main__", but the other module is called >> "main". __main__ is a special name, which Python understands as meaning >> "this module that you are in now". For example: > > My choice of names was perhaps not very smart. I could have called > main.py also mytoplevel.py [...] > I think you're wrong, my above code seems to work. __main__ refers not > to the current module, but to the urrent 'top-level-module' > so > from __main__ import A tries to import from the top level module which > is in my case main.py. Hmmm... it looks like you are correct and I made a mistake. This isn't something that the documentation is clear about, but here are a set of test files: $ cat A.py import __main__ import B print __main__, B, B.__main__ $ cat B.py import __main__ $ python A.py Here is the documentation: http://docs.python.org/library/__main__.html which is pretty sparse. -- Steven From irmen.NOSPAM at xs4all.nl Sat Mar 20 10:17:50 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 20 Mar 2010 15:17:50 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: <4ba4cfe3$0$7060$426a74cc@news.free.fr> References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> Message-ID: <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> On 20-3-2010 14:38, News123 wrote: > I'm having a small multiprocessing manager: > > # ########################## > import socket,sys > from multiprocessing.managers import BaseManager > > mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') > try: > srvr = mngr.get_server() > except socket.error as e: > print "probably address already in use" > sys.exit() > print "serving" > srvr.serve_forever() > > > Under linux this script can only be run once. > The second call will raise an exception, as the previous program is > already listening to pot 8089. > > > Under Windows however the program can be started twice. > and will print twice "serving". This surprises me My guess is that somewhere in the multiprocessing package the SO_REUSEADDR option is used on the socket. And that option has different semantics on Windows than it has on other operating systems. At least one of them being the possibility of multiple bindings on the same port without getting an error. See http://bugs.python.org/issue2550. Also see the code comments to bind_port in Lib/test/test_support.py, that suggests using SO_EXCLUSIVEADDRUSE instead under Windows, but that is not much use to you unless you monkeypatch the multiprocessing package code. Hope this helps -irmen From davea at ieee.org Sat Mar 20 10:50:17 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Mar 2010 09:50:17 -0500 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4ce53$0$28677$426a34cc@news.free.fr> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> <4ba4c824$0$27838$c3e8da3@news.astraweb.com> <4ba4ce53$0$28677$426a34cc@news.free.fr> Message-ID: <4BA4E0A9.3050804@ieee.org> News123 wrote: > > Steven D'Aprano wrote: > >> >> Now, in your case you escape that trap, because the import is inside a >> function, so it doesn't occur until you call the function. But it is >> still considered poor practice: it is best to avoid circular imports >> unless you really, really need them. >> >> >> The question is, why does module mod.py care what is happening in >> main.py? It is better for mod.py to be self-contained, and not care about >> main.py at all. If it needs A, let the caller pass A to it: >> > > > The reason is pure lazyness. > I would like to 'try' something quickly. > > I have a module used by many different python programs. > > In case the __main__ module contains a certain object I'd like to > extract information from this object if not not. > > This is for debug, not for 'production'. > > I'd prefer to change only one file and not many. > > > First, the practical response: yes, it'll work, and if this is really for debug, it's fine. However, realize that many times "debug things" make it into the wild. Any time recursion of imports occurs, it's a sign of trouble. And doing it right isn't usually much harder than studying the hazards of the recursion. In the particular case you're doing, I think there are at least three better solutions: 1) Pass A as an argument to a function call, for example f(A). 2) Put A into a separate module that both main.py and mod.py import 3) Explicitly add A to mod.py's global space. mod.A = A written in main.py, before calling the function mod.x(). HTH DaveA From news1234 at free.fr Sat Mar 20 10:52:05 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 15:52:05 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> Message-ID: <4ba4e115$0$18400$426a74cc@news.free.fr> Hi Irmen, Irmen de Jong wrote: > On 20-3-2010 14:38, News123 wrote: >> I'm having a small multiprocessing manager: >> >> # ########################## >> import socket,sys >> from multiprocessing.managers import BaseManager >> >> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') >> try: >> srvr = mngr.get_server() >> except socket.error as e: >> print "probably address already in use" >> sys.exit() >> print "serving" >> srvr.serve_forever() >> >> Under Windows however the program can be started twice. >> and will print twice "serving". This surprises me > > > My guess is that somewhere in the multiprocessing package the > SO_REUSEADDR option is used on the socket. And that option has different > semantics on Windows than it has on other operating systems. At least > one of them being the possibility of multiple bindings on the same port > without getting an error. > See http://bugs.python.org/issue2550. > Also see the code comments to bind_port in Lib/test/test_support.py, > that suggests using SO_EXCLUSIVEADDRUSE instead under Windows, but that > is not much use to you unless you monkeypatch the multiprocessing > package code. > Yes this might be. Then I think, that I should report it either as bug / enhancement request. However I am not at all aware of the issue reporting process concerning python. (special site / module developer, PEP . . . ) For the short term: I wonder now how to solve my problem that only one manager is started and the second one should just aborts. Some days ago I started a discussion in the thread "how to start a python script only once". I hoped, that the listening socket of the manager would just take care of the issue. N From duncan.booth at invalid.invalid Sat Mar 20 12:24:37 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Mar 2010 16:24:37 GMT Subject: How User-defined method objects are created? References: Message-ID: Joaquin Abian wrote: > "User-defined method objects may be created when getting an attribute > of a class (perhaps via an instance of that class), if that attribute > is a user-defined function object, an unbound user-defined method > object, or a class method object. When the attribute is a user-defined > method object, a new method object is only created if the class from > which it is being retrieved is the same as, or a derived class of, the > class stored in the original method object; otherwise, the original > method object is used as it is." > > It is a bit of a tongue-twister for me. What the last sentence means? > Please, I beg for a simple example of the different objects (user > defined function, user defined method, class method) refered. >>> class A(object): def foo(self): pass >>> class B(object): def bar(self): pass >>> B.baz = B.bar >>> B.foo = A.foo >>> instance = B() >>> B.foo >>> B.bar >>> B.baz >>> instance.foo >>> instance.bar > >>> instance.baz > >>> B.__dict__['bar'] >>> B.__dict__['baz'] >>> B.__dict__['foo'] So, we have a function 'bar' stored in B's dict. When you access the function as the attribute B.bar Python 2.x will create an unbound method object. When you access the function through instance.bar Python creates a bound method. Note that every time you access instance.bar it creates another new method object: >>> instance.bar is instance.bar False B.baz is an unbound method stored directly in B's dict. When you access instance.baz you get a new bound method object (it's at the same memory location as the previous one but that's only because the lifetimes don't overlap). Somewhat suprisingly the same also happens if you access B.baz: it creates a new unbound method from the existing unbound method: >>> B.bar is B.__dict__['bar'] False B.foo is an unbound method stored directly in B's dict, but it is a method of an A and B doesn't subclass A, so when you try to access B.foo you just get the stored unbound method it isn't converted into a new object. From tjreedy at udel.edu Sat Mar 20 12:33:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Mar 2010 12:33:01 -0400 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: <4ba4e115$0$18400$426a74cc@news.free.fr> References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> <4ba4e115$0$18400$426a74cc@news.free.fr> Message-ID: On 3/20/2010 10:52 AM, News123 wrote: > Hi Irmen, > > > Irmen de Jong wrote: >> On 20-3-2010 14:38, News123 wrote: >>> I'm having a small multiprocessing manager: >>> >>> # ########################## >>> import socket,sys >>> from multiprocessing.managers import BaseManager >>> >>> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') >>> try: >>> srvr = mngr.get_server() >>> except socket.error as e: >>> print "probably address already in use" >>> sys.exit() >>> print "serving" >>> srvr.serve_forever() >>> >>> Under Windows however the program can be started twice. >>> and will print twice "serving". This surprises me >> >> >> My guess is that somewhere in the multiprocessing package the >> SO_REUSEADDR option is used on the socket. And that option has different >> semantics on Windows than it has on other operating systems. At least >> one of them being the possibility of multiple bindings on the same port >> without getting an error. >> See http://bugs.python.org/issue2550. >> Also see the code comments to bind_port in Lib/test/test_support.py, >> that suggests using SO_EXCLUSIVEADDRUSE instead under Windows, but that >> is not much use to you unless you monkeypatch the multiprocessing >> package code. >> > > Yes this might be. > > > Then I think, that I should report it either as bug / enhancement I agree. I would guess that the difference is not intentional. > request. However I am not at all aware of the issue reporting process > concerning python. (special site / module developer, PEP . . . ) bugs.python.org Terry Jan Reedy From tjreedy at udel.edu Sat Mar 20 12:39:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Mar 2010 12:39:44 -0400 Subject: How User-defined method objects are created? In-Reply-To: References: Message-ID: On 3/20/2010 9:54 AM, Joaquin Abian wrote: > I'm trying to understand the description of method object creation in > the python 2.6 language reference (3.2. The standard type hierarchy) > with little success. The points knocking me are: > > "User-defined method objects may be created when getting an attribute > of a class (perhaps via an instance of that class), if that attribute > is a user-defined function object, an unbound user-defined method > object, or a class method object. When the attribute is a user-defined > method object, a new method object is only created if the class from > which it is being retrieved is the same as, or a derived class of, the > class stored in the original method object; otherwise, the original > method object is used as it is." > > It is a bit of a tongue-twister for me. What the last sentence means? > Please, I beg for a simple example of the different objects (user > defined function, user defined method, class method) refered. > Are maybe the refered objects exemplified by : > > #python 3.1 > class Klass(): > > def met(self): > print('method') > > def func(): > print('function') > > @classmethod > def kmet(klass): > print('classmethod') > > or it is talking about another thing? > What is the difference with python 3 where there is no mention to the > unbound user-defined method object (same section in python 3 language > reference): Python3 does not have unbound method objects. Klass.met above is just a function.l > "User-defined method objects may be created when getting an attribute > of a class (perhaps via an instance of that class), if that attribute > is a user-defined function object or a class method object." > > I'm trying to learn, however the task is revealing as an enormous > undertaking :-) One can successfully use the language in the normal way without understanding every detail of every oddball corner case. Recent 2.x is complicated by duplication (two user object systems) and back-compatibility constraints. Most new users do not need to bother with obsolete complications. Terry Jan Reedy From waugustynski at gmail.com Sat Mar 20 13:00:47 2010 From: waugustynski at gmail.com (waugust) Date: Sat, 20 Mar 2010 10:00:47 -0700 (PDT) Subject: Ubuntu install problems Message-ID: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever I apt-get install anything It ends with a series of python (dependency?) errors. Anybody got any idea? > aptget libgcj-common Reading package lists... Done Building dependency tree Reading state information... Done libgcj-common is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded. 26 not fully installed or removed. After this operation, 0B of additional disk space will be used. Setting up libgcj-common (1:4.4.1-1ubuntu2) ... Compiling /usr/lib/python3.1/dist-packages/ aotcompile.py ... File "/usr/lib/python3.1/dist-packages/aotcompile.py", line 115 raise Error, "nothing to do" ^ SyntaxError: invalid syntax Compiling /usr/lib/python3.1/dist-packages/classfile.py ... File "/usr/lib/python3.1/dist-packages/classfile.py", line 30 raise TypeError, type(arg) ^ SyntaxError: invalid syntax pycentral: pycentral pkginstall: error byte-compiling files (2) pycentral pkginstall: error byte-compiling files (2) dpkg: error processing libgcj-common (--configure): subprocess installed post-installation script returned error exit status 1 dpkg: dependency problems prevent configuration of libgcj10: libgcj10 depends on libgcj-common (>= 1:4.1.1-21); however: Package libgcj-common is not configured yet. dpkg: error processing libgcj10 (-- configure): dependency problems - leaving unconfigured dpkg: dependency problems prevent configuration of libgcj-bc: It snowballs down from there for: No apport report written because MaxReports is reached already Errors were encountered while processing: libgcj-common libgcj10 libgcj-bc ant-gcj ant-optional-gcj python-transaction python-zconfig python-zdaemon python-zope.exceptions python-zope.testing python-zope.proxy python-zodb python-zope.component gaphor gcj-4.4-jre-lib python-speechd python-pyatspi gnome-orca python-configglue python-telepathy python-ubuntuone-storageprotocol python-ubuntuone-client telepathy-butterfly ubuntuone-client ubuntuone-client-gnome python-zope.hookable E: Sub-process /usr/bin/dpkg returned an error code (1) From news1234 at free.fr Sat Mar 20 13:11:25 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 18:11:25 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> <4ba4e115$0$18400$426a74cc@news.free.fr> Message-ID: <4ba501bd$0$7193$426a74cc@news.free.fr> Terry Reedy wrote: > On 3/20/2010 10:52 AM, News123 wrote: >> Hi Irmen, >> >> >> Irmen de Jong wrote: >>> On 20-3-2010 14:38, News123 wrote: >>>> I'm having a small multiprocessing manager: >>>> >>>> # ########################## >>>> import socket,sys >>>> from multiprocessing.managers import BaseManager >>>> >>>> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') >>>> try: >>>> srvr = mngr.get_server() >>>> except socket.error as e: >>>> print "probably address already in use" >>>> sys.exit() >>>> print "serving" >>>> srvr.serve_forever() >>>> >>>> Under Windows however the program can be started twice. >>>> and will print twice "serving". This surprises me >>> . . . >> >> Then I think, that I should report it either as bug / enhancement > > I agree. I would guess that the difference is not intentional. > >> request. However I am not at all aware of the issue reporting process >> concerning python. (special site / module developer, PEP . . . ) > > bugs.python.org > Thanks, I created an account and submitted the issue N From benjamin.kaplan at case.edu Sat Mar 20 13:15:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 20 Mar 2010 13:15:16 -0400 Subject: Ubuntu install problems In-Reply-To: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> Message-ID: On Sat, Mar 20, 2010 at 1:00 PM, waugust wrote: > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. > Whenever I apt-get install anything It ends with a series of python > (dependency?) errors. Anybody got any idea? > > aptget libgcj-common > Reading package lists... > Done > Building dependency > tree > Reading state information... > Done > libgcj-common is already the newest > version. > 0 upgraded, 0 newly installed, 0 to remove and 6 not > upgraded. > 26 not fully installed or > removed. > After this operation, 0B of additional disk space will be > used. > Setting up libgcj-common > (1:4.4.1-1ubuntu2) ... > Compiling /usr/lib/python3.1/dist-packages/ > aotcompile.py ... > File "/usr/lib/python3.1/dist-packages/aotcompile.py", line > 115 > raise Error, "nothing to > do" > > ^ > SyntaxError: invalid > syntax > > Compiling /usr/lib/python3.1/dist-packages/classfile.py ... > File "/usr/lib/python3.1/dist-packages/classfile.py", line 30 > raise TypeError, type(arg) > ^ > SyntaxError: invalid syntax > > Did you set /usr/bin/python to Python 3.1? It needs to stay as the system default Python (in this case 2.6) or else lots of stuff breaks. You're getting those syntax errors because of the difference between Python 2.x (which the scripts were written for) and Python 3.x (which is being run) -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sat Mar 20 13:24:45 2010 From: aahz at pythoncraft.com (Aahz) Date: 20 Mar 2010 10:24:45 -0700 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: In article <4B9E0C1F.9020003 at canterbury.ac.nz>, Gregory Ewing wrote: > >It turned out to be a very standard CRC algorithm, complicated >by the presence of a few extra bytes of data being checked that >didn't appear explicitly in the file anywhere. > >In the process I developed some very general techniques for >solving this kind of problem, which I've written about here >if anyone's interested: > >http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html Excellent essay! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 13:25:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 17:25:03 GMT Subject: Ubuntu install problems References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> Message-ID: <4ba504ef$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 10:00:47 -0700, waugust wrote: > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever > I apt-get install anything It ends with a series of python (dependency?) > errors. Anybody got any idea? It looks like apt-get is supposed to be using 2.6 or 2.5, but somehow is running 3.1 instead. If you run "python -V", what does it say? -- Steven From python at mrabarnett.plus.com Sat Mar 20 13:26:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Mar 2010 17:26:58 +0000 Subject: Ubuntu install problems In-Reply-To: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> Message-ID: <4BA50562.1010600@mrabarnett.plus.com> waugust wrote: > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. > Whenever I apt-get install anything It ends with a series of python > (dependency?) errors. Anybody got any idea? >> aptget libgcj-common > Reading package lists... > Done > Building dependency > tree > Reading state information... > Done > libgcj-common is already the newest > version. > 0 upgraded, 0 newly installed, 0 to remove and 6 not > upgraded. > 26 not fully installed or > removed. > After this operation, 0B of additional disk space will be > used. > Setting up libgcj-common > (1:4.4.1-1ubuntu2) ... > Compiling /usr/lib/python3.1/dist-packages/ > aotcompile.py ... > File "/usr/lib/python3.1/dist-packages/aotcompile.py", line > 115 > raise Error, "nothing to > do" > > ^ > SyntaxError: invalid > syntax > > Compiling /usr/lib/python3.1/dist-packages/classfile.py ... > File "/usr/lib/python3.1/dist-packages/classfile.py", line 30 > raise TypeError, type(arg) > ^ > SyntaxError: invalid syntax > [snip] In Python 2 an exception can be raised with the old-style: raise Error, "nothing to do" or the new-style: raise Error("nothing to do") In Python 3 the old style is not supported (it was abandoned as part of the general clean-up). Another related change is that the old-style: except Error, e: in Python 2 has been completely replaced by the new-style: except Error as e: in Python 3 (also available in Python 2.6). From waugustynski at gmail.com Sat Mar 20 13:40:08 2010 From: waugustynski at gmail.com (waugust) Date: Sat, 20 Mar 2010 10:40:08 -0700 (PDT) Subject: Ubuntu install problems References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> <4ba504ef$0$27838$c3e8da3@news.astraweb.com> Message-ID: <658a97c1-02d0-4158-a3b0-b82f1e66254a@q26g2000prh.googlegroups.com> On Mar 20, 10:25?am, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 10:00:47 -0700, waugust wrote: > > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever > > I apt-get install anything It ends with a series of python (dependency?) > > errors. ?Anybody got any idea? > > It looks like apt-get is supposed to be using 2.6 or 2.5, but somehow is > running 3.1 instead. > > If you run "python -V", what does it say? > > -- > Steven >python -V Python 2.6.4 odd..yeah, I uninstalled all of the listed packages and started to install again and got the same problem... From saimapk81 at gmail.com Sat Mar 20 14:03:00 2010 From: saimapk81 at gmail.com (saima81) Date: Sat, 20 Mar 2010 11:03:00 -0700 (PDT) Subject: "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ Message-ID: <9df66e21-4011-447c-9816-fc7f79416c4b@a37g2000prd.googlegroups.com> "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ V From agoretoy at gmail.com Sat Mar 20 14:55:26 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 20 Mar 2010 12:55:26 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: what do i do to remove this crap? how do i moderate it? why not gpg sign messages on python-list that way you know your authorized to post and spammers will have one more vector to deal with, there in stopping the not so leet -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From Brian.Mingus at Colorado.EDU Sat Mar 20 15:27:10 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 20 Mar 2010 13:27:10 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Moderating this stuff requires moderating all messages. It would take a team of volunteers. On Sat, Mar 20, 2010 at 12:55 PM, alex goretoy wrote: > what do i do to remove this crap? how do i moderate it? > > why not gpg sign messages on python-list that way you know your authorized > to post and spammers will have one more vector to deal with, there in > stopping the not so leet > -Alex Goretoy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sat Mar 20 15:37:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 20 Mar 2010 15:37:48 -0400 Subject: "EURO GIRLS" "MISS EUROPE" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: <20100320153748.95f9cb49.darcy@druid.net> On Sat, 20 Mar 2010 12:55:26 -0600 alex goretoy wrote: > what do i do to remove this crap? how do i moderate it? First, please remove spam URLs when following up. You left them in the subject. Maybe it's time to stop gatewaying the newsgroup to the mailing list. As a test I have moved all Python posts from gmail.com with a Newsgroup header into a separate folder and so far 99% of the spam lands there. Once you do that you can also enforce that posts can only come from subscribed addresses. I find that that cuts out almost 100% of the spam. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From agoretoy at gmail.com Sat Mar 20 15:54:18 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 20 Mar 2010 13:54:18 -0600 Subject: "EURO GIRLS" "MISS EUROPE" In-Reply-To: <20100320153748.95f9cb49.darcy@druid.net> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <20100320153748.95f9cb49.darcy@druid.net> Message-ID: On Sat, Mar 20, 2010 at 1:37 PM, D'Arcy J.M. Cain wrote: > aybe it's time to stop gatewaying the newsgroup to the mailing list. > As a test I have moved all Python posts from gmail.com with a > Newsgroup header into > ok thx, I'm learning as I go along -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmanns at gmx.net Sat Mar 20 17:30:09 2010 From: mmanns at gmx.net (Martin Manns) Date: Sat, 20 Mar 2010 22:30:09 +0100 Subject: [ANN] Pyspread 0.1 released Message-ID: Pyspread 0.1 released ===================== After a long and eventful Alpha period, pyspread has finally reached Beta stage. I thank all contributors and testers who have helped getting pyspread to this point. About: ------ Pyspread is a cross-platform Python spreadsheet application. It is based on and written in the programming language Python. Instead of spreadsheet formulas, Python expressions are entered into the spreadsheet cells. Each expression returns a Python object that can be accessed from other cells. These objects can represent anything including lists or matrices. Stability and compatibility --------------------------- Pyspread runs pretty stable in CPython. Please note that old save files are not compatible. Load them in the old version and copy the code to a new version of pyspread via the clipboard. Being in Beta means increased code stability. Save files are now going to be downwards compatible. However, major beta releases (e. g. 0.1 to 0.2) may still break compatibility. Such a change may occur only after being announced in the previous major beta release. New features ------------ * New macro editor dialog. * Macros can now contain any Python code. * Macros load and save files are now plain text files. * Macros are now saved within the pys-file. * Macros files are now signed and included in the trusted file concept. Bug fixes --------- * Cells can now be correctly accessed with negative index (BUG 2965144) Homepage -------- http://pyspread.sourceforge.net Enjoy Martin From gatoygata2 at gmail.com Sat Mar 20 17:32:40 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sat, 20 Mar 2010 14:32:40 -0700 (PDT) Subject: How User-defined method objects are created? References: Message-ID: On Mar 20, 5:39?pm, Terry Reedy wrote: > On 3/20/2010 9:54 AM, Joaquin Abian wrote: > > > > > I'm trying to understand the description of method object creation in > > the python 2.6 language reference (3.2. The standard type hierarchy) > > with little success. The points knocking me are: > > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object, an unbound user-defined method > > object, or a class method object. When the attribute is a user-defined > > method object, a new method object is only created if the class from > > which it is being retrieved is the same as, or a derived class of, the > > class stored in the original method object; otherwise, the original > > method object is used as it is." > > > It is a bit of a tongue-twister for me. What the last sentence means? > > Please, I beg for a simple example of the different objects (user > > defined function, user defined method, class method) refered. > > Are maybe the refered objects exemplified by : > > > #python 3.1 > > class Klass(): > > > ? ?def met(self): > > ? ? ? ? ? ?print('method') > > > ? ? ? ? def func(): > > ? ? ? ? ? ?print('function') > > > ? ? ? ? @classmethod > > ? ?def kmet(klass): > > ? ? ? ? ? ?print('classmethod') > > > or it is talking about another thing? > > What is the difference with python 3 where there is no mention to the > > unbound user-defined method object (same section in python 3 language > > reference): > > Python3 does not have unbound method objects. Klass.met above is just a > function.l > > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object or a class method object." > > > I'm trying to learn, however the task is revealing as an enormous > > undertaking :-) > > One can successfully use the language in the normal way without > understanding every detail of every oddball corner case. Recent 2.x is > complicated by duplication (two user object systems) and > back-compatibility constraints. Most new users do not need to bother > with obsolete complications. > > Terry Jan Reedy Terry, Right, I was just reading about this difference in 2 vs 3 in Lutz's book. Well, in fact in my case I'm not a newcomer to python (neither a professional). I have been programming for more than 4 years in python mainly medium size scientific data management applications. Currently I can write at a moderate speed and Im familiar with properties, decorators, etc. That's why it is so frustrating went I get lost in the language reference manual in a matter I wrongly though was a simple stuff. Thanks for your helpful comments. JA From gatoygata2 at gmail.com Sat Mar 20 17:41:36 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sat, 20 Mar 2010 14:41:36 -0700 (PDT) Subject: How User-defined method objects are created? References: Message-ID: <6e791682-f44c-43f1-948f-44e59e78c9f9@z4g2000yqa.googlegroups.com> On Mar 20, 5:24?pm, Duncan Booth wrote: > Joaquin Abian wrote: > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object, an unbound user-defined method > > object, or a class method object. When the attribute is a user-defined > > method object, a new method object is only created if the class from > > which it is being retrieved is the same as, or a derived class of, the > > class stored in the original method object; otherwise, the original > > method object is used as it is." > > > It is a bit of a tongue-twister for me. What the last sentence means? > > Please, I beg for a simple example of the different objects (user > > defined function, user defined method, class method) refered. > >>> class A(object): > > ? ? ? ? def foo(self): pass > > >>> class B(object): > > ? ? ? ? def bar(self): pass > > >>> B.baz = B.bar > >>> B.foo = A.foo > >>> instance = B() > >>> B.foo > > >>> B.bar > > >>> B.baz > > >>> instance.foo > > >>> instance.bar > > >>>> instance.baz > > >>>> B.__dict__['bar'] > > >>> B.__dict__['baz'] > > >>> B.__dict__['foo'] > > > > So, we have a function 'bar' stored in B's dict. When you access the > function as the attribute B.bar Python 2.x will create an unbound method > object. When you access the function through instance.bar Python creates a > bound method. Note that every time you access instance.bar it creates > another new method object: > > >>> instance.bar is instance.bar > > False > > B.baz is an unbound method stored directly in B's dict. When you access > instance.baz you get a new bound method object (it's at the same memory > location as the previous one but that's only because the lifetimes don't > overlap). Somewhat suprisingly the same also happens if you access B.baz: > it creates a new unbound method from the existing unbound method: > > >>> B.bar is B.__dict__['bar'] > > False > > B.foo is an unbound method stored directly in B's dict, but it is a method > of an A and B doesn't subclass A, so when you try to access B.foo you just > get the stored unbound method it isn't converted into a new object. Thanks Duncan, I think I got the idea. Your explanation together with the comment from Terry about the absence of unbound method objects in python 3 cleared some dust from my neuron(s) Thanks! JA From no.email at please.post Sat Mar 20 18:15:54 2010 From: no.email at please.post (kj) Date: Sat, 20 Mar 2010 22:15:54 +0000 (UTC) Subject: How to automate accessor definition? Message-ID: I need to create a class solely for the purpose of encapsulating a large number of disparate data items. At the moment I have no plans for any methods for this class other than the bazillion accessors required to access these various instance variables. (In case it matters, this class is meant to be a private helper class internal to a module, and it won't be subclassed.) What is "best practice" for implementing this sort of class *succinctly* (i.e. without a lot of repetitive accessor code)? Also, one more question concerning syntax. Suppose that i represents an instance of this class. Is it possible to define the class to support this syntax val = i.field i.field += 6 ...rather than this one val = i.get_field() i.set_field(i.get_field() + 6) ? TIA! ~K From nilly16 at yahoo.com Sat Mar 20 18:39:30 2010 From: nilly16 at yahoo.com (Jimbo) Date: Sat, 20 Mar 2010 15:39:30 -0700 (PDT) Subject: Best Way to extract Numbers from String References: Message-ID: <61a6901b-40ce-4b7e-aa90-19696fcb9303@h35g2000pri.googlegroups.com> On Mar 20, 11:51?pm, Luis M. Gonz?lez wrote: > On Mar 20, 12:04?am, Jimbo wrote: > > > > > > > Hello > > > I am trying to grab some numbers from a string containing HTML text. > > Can you suggest any good functions that I could use to do this? What > > would be the easiest way to extract the following numbers from this > > string... > > > My String has this layout & I have commented what I want to grab: > > [CODE] """ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > > I need to grab this number only > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > > I need to grab this number only > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I need to > > grab this number only > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? """[/CODE] > > You should use BeautifulSoup or perhaps regular expressions. > Or if you are not very smart, lik me, just try a brute force approach: > > >>> for i in s.split('>'): > > ? ? ? ? for e in i.split(): > ? ? ? ? ? ? ? ? if '.' in e and e[0].isdigit(): > ? ? ? ? ? ? ? ? ? ? ? ? print (e) > > 43.200 > 0.040 > 43.150 > 43.200 > 43.130 > 43.290 > 43.100 > > > > - Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Thanks very much, I'm going to look at regular expressions but that for your code, it shows me how I can do it iwth standard python :) From clp2 at rebertia.com Sat Mar 20 18:54:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Mar 2010 15:54:20 -0700 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: <50697b2c1003201554v3294b545sd2c53bd203111e5@mail.gmail.com> On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: > I need to create a class solely for the purpose of encapsulating > a large number of disparate data items. ?At the moment I have no > plans for any methods for this class other than the bazillion > accessors required to access these various instance variables. > (In case it matters, this class is meant to be a private helper > class internal to a module, and it won't be subclassed.) If it's just a completely dumb struct-like class, you might consider something like: http://docs.python.org/library/collections.html#collections.namedtuple > What is "best practice" for implementing this sort of class > *succinctly* (i.e. without a lot of repetitive accessor code)? Is there any good reason you can't just use straight instance variables? Python ain't Java; vanilla, boilerplate accessor methods should almost always be avoided. > Also, one more question concerning syntax. ?Suppose that i represents > an instance of this class. ?Is it possible to define the class to > support this syntax > > ?val = i.field > ?i.field += 6 > > ...rather than this one > > ?val = i.get_field() > ?i.set_field(i.get_field() + 6) > > ? Yes, using the magic of the property() function: http://docs.python.org/library/functions.html#property Cheers, Chris -- http://blog.rebertia.com From waugustynski at gmail.com Sat Mar 20 19:32:51 2010 From: waugustynski at gmail.com (waugust) Date: Sat, 20 Mar 2010 16:32:51 -0700 (PDT) Subject: Ubuntu install problems References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> <4ba504ef$0$27838$c3e8da3@news.astraweb.com> <658a97c1-02d0-4158-a3b0-b82f1e66254a@q26g2000prh.googlegroups.com> Message-ID: On Mar 20, 10:40?am, waugust wrote: > On Mar 20, 10:25?am, Steven D'Aprano > cybersource.com.au> wrote: > > On Sat, 20 Mar 2010 10:00:47 -0700, waugust wrote: > > > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever > > > I apt-get install anything It ends with a series of python (dependency?) > > > errors. ?Anybody got any idea? > > > It looks like apt-get is supposed to be using 2.6 or 2.5, but somehow is > > running 3.1 instead. > > > If you run "python -V", what does it say? > > > -- > > Steven > >python -V > > Python 2.6.4 > > odd..yeah, I uninstalled all of the listed packages and started to > install again and got the same problem... So I put this up to the Ubuntu (lunchpad, apt) community support board: https://answers.launchpad.net/ubuntu/+source/apt/+question/105025 Possible bug with the python-central package (Ubuntu x86 9.10)?? dunno. From fordhaivat at gmail.com Sat Mar 20 20:51:44 2010 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 20 Mar 2010 20:51:44 -0400 Subject: Best Way to extract Numbers from String In-Reply-To: References: Message-ID: Its an extremely bad idea to use regex for HTML. You want to change one tiny little thing and you have to write the regex all over again. if its a throwaway script, then go ahead. 2010/3/20 Luis M. Gonz?lez > On Mar 20, 12:04 am, Jimbo wrote: > > Hello > > > > I am trying to grab some numbers from a string containing HTML text. > > Can you suggest any good functions that I could use to do this? What > > would be the easiest way to extract the following numbers from this > > string... > > > > My String has this layout & I have commented what I want to grab: > > [CODE] """ > > > > > > > > # > > I need to grab this number only > > > > # > > I need to grab this number only > > > # I need to > > grab this number only > > > > > > > > > > > > > > > > """[/CODE] > > > You should use BeautifulSoup or perhaps regular expressions. > Or if you are not very smart, lik me, just try a brute force approach: > > >>> for i in s.split('>'): > for e in i.split(): > if '.' in e and e[0].isdigit(): > print (e) > > > 43.200 > 0.040 > 43.150 > 43.200 > 43.130 > 43.290 > 43.100 > >>> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fordhaivat at gmail.com Sat Mar 20 20:53:45 2010 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 20 Mar 2010 20:53:45 -0400 Subject: How to automate accessor definition? In-Reply-To: <50697b2c1003201554v3294b545sd2c53bd203111e5@mail.gmail.com> References: <50697b2c1003201554v3294b545sd2c53bd203111e5@mail.gmail.com> Message-ID: Just initialize everything in the constructor, unless you have *really *good reason not to do that. On Sat, Mar 20, 2010 at 6:54 PM, Chris Rebert wrote: > On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: > > I need to create a class solely for the purpose of encapsulating > > a large number of disparate data items. At the moment I have no > > plans for any methods for this class other than the bazillion > > accessors required to access these various instance variables. > > (In case it matters, this class is meant to be a private helper > > class internal to a module, and it won't be subclassed.) > > If it's just a completely dumb struct-like class, you might consider > something like: > http://docs.python.org/library/collections.html#collections.namedtuple > > > What is "best practice" for implementing this sort of class > > *succinctly* (i.e. without a lot of repetitive accessor code)? > > Is there any good reason you can't just use straight instance > variables? Python ain't Java; vanilla, boilerplate accessor methods > should almost always be avoided. > > > Also, one more question concerning syntax. Suppose that i represents > > an instance of this class. Is it possible to define the class to > > support this syntax > > > > val = i.field > > i.field += 6 > > > > ...rather than this one > > > > val = i.get_field() > > i.set_field(i.get_field() + 6) > > > > ? > > Yes, using the magic of the property() function: > http://docs.python.org/library/functions.html#property > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 22:31:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Mar 2010 02:31:32 GMT Subject: How to automate accessor definition? References: Message-ID: <4ba58503$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 22:15:54 +0000, kj wrote: > I need to create a class solely for the purpose of encapsulating a large > number of disparate data items. There's a built-in for that. It's called "dict". Syntax for item access is a tiny bit different, but still very common: data['foo'] instead of data.foo If you need to customize item access, you need to modify __getitem__, __setitem__ and __delitem__ instead of __getattr__ etc., but otherwise they are nearly identical. Ignoring a few complications due to slots and inheritance, attribute access is built on top of item access, so you won't notice any performance hit (and you might see a tiny performance benefit). > At the moment I have no plans for any > methods for this class other than the bazillion accessors required to > access these various instance variables. Huh? If you have instance variables, why don't you refer to them by name? x = MyClass() # create an instance y = MyClass() # another variable bound to an instance z = MyClass() # etc. print x, y, z > (In case it matters, this class > is meant to be a private helper class internal to a module, and it won't > be subclassed.) > > What is "best practice" for implementing this sort of class *succinctly* > (i.e. without a lot of repetitive accessor code)? Leave the repetitive accessor code out. Python isn't Java. http://dirtsimple.org/2004/12/python-is-not-java.html > Also, one more question concerning syntax. Suppose that i represents an > instance of this class. Is it possible to define the class to support > this syntax > > val = i.field > i.field += 6 Classes already support that. >>> class C(object): ... pass ... >>> i = C() >>> i.field = 42 >>> val = i.field >>> i.field += 6 >>> print (val, i.field) 42 48 > ...rather than this one > > val = i.get_field() > i.set_field(i.get_field() + 6) > > ? Good grief! No wonder Java coders are so unproductive :( -- Steven From gregory.j.baker at gmail.com Sat Mar 20 23:37:53 2010 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Sat, 20 Mar 2010 20:37:53 -0700 (PDT) Subject: Best Way to extract Numbers from String References: <61a6901b-40ce-4b7e-aa90-19696fcb9303@h35g2000pri.googlegroups.com> Message-ID: Regular expression are very powerful, and I use them a lot in my paying job (unfortunately not with Python). You are however, basically using a second programing language, which can be difficult to master. Does this give you the desired result? import re matches = re.findall('', code) for match in matches: print match resulting in this output: 43.150 43.200 43.130 43.290 43.100 7,450,447 From renws1990 at gmail.com Sun Mar 21 03:23:26 2010 From: renws1990 at gmail.com (Ren Wenshan) Date: Sun, 21 Mar 2010 00:23:26 -0700 (PDT) Subject: How to keep effects of image filters going for some seconds? Message-ID: Hello, every pythoner. Firstly, I want to mention that English is my second language, so maybe there are some sentences which makes you confused, sorry. I have been learning Panda3D, an open source 3D engine, these days. Now, I'm trying to write a small game for fun and practice. However, I've ran into a problem. I want to make some speical effects and there is my code: def ventose(self): global potato_HP if potato_HP[0] == 1 and potato_HP[1] == 0: if random() > .30: self.filters.setCartoonInk(separation = 0.8) self.robotVincent.resetHead.start() self.decreaseVincentHP() Wait(3) self.fliters.delCartoonInk() However, it doesn't work, the CartoonInk effect will never been shown in my game and I don't want my game to wait three seconds, what I need is to keep the effect for a period of time while the game run as well. Besides that, I also want to show a counting back like "3", then "2", then "1", finally "Go". As a beginner, I don't know how to do them properly. Please give me some directions, thank you. ----------------------------- Vincent Ren From jah.alarm at gmail.com Sun Mar 21 06:11:05 2010 From: jah.alarm at gmail.com (Jah_Alarm) Date: Sun, 21 Mar 2010 03:11:05 -0700 (PDT) Subject: nonuniform sampling with replacement Message-ID: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> I've got a vector length n of integers (some of them are repeating), and I got a selection probability vector of the same length. How will I sample with replacement k (<=n) values with the probabilty vector. In Matlab this function is randsample. I couldn't find anything to this extent in Scipy or Numpy. thanks for the help Alex From donn.ingle at gmail.com Sun Mar 21 07:08:07 2010 From: donn.ingle at gmail.com (donn) Date: Sun, 21 Mar 2010 13:08:07 +0200 Subject: How to keep effects of image filters going for some seconds? In-Reply-To: References: Message-ID: <4BA5FE17.20909@gmail.com> On 21/03/2010 09:23, Ren Wenshan wrote: > I have been learning Panda3D, an open source 3D engine, Ask on the Panda3D forums, you will get good help there. \d From alfps at start.no Sun Mar 21 08:03:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 21 Mar 2010 13:03:00 +0100 Subject: nonuniform sampling with replacement In-Reply-To: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: * Jah_Alarm: > I've got a vector length n of integers (some of them are repeating), > and I got a selection probability vector of the same length. How will > I sample with replacement k (<=n) values with the probabilty vector. > In Matlab this function is randsample. I couldn't find anything to > this extent in Scipy or Numpy. #Py3 import operator # itemgetter import random from collections import defaultdict def normalized_to_sum( s, v ): current_s = sum( v ) c = s/current_s return [c*x for x in v] class ValueSampler: def __init__( self, values, probabilities ): assert len( values ) == len( probabilities ) get2nd = operator.itemgetter( 1 ) v_p = sorted( zip( values, probabilities ), key = get2nd, reverse = True ) v_ap = []; sum = 0; for (v, p) in v_p: v_ap.append( (v, p + sum) ); sum += p self._data = v_ap def __call__( self, p ): return self.choice( p ) def choice( self, p ): data = self._data; i_v = 0; i_p = 1; assert 0 <= p <= 1 assert len( data ) > 0, "Sampler: Sampling from empty value set" low = 0; high = len( data ) - 1; if p > data[high][i_p]: return data[high][i_p] # Float values workaround. while low != high: mid = (low + high)//2 if p > data[mid][i_p]: low = mid + 1 else: high = mid return data[low][i_v] def main(): v = [3, 1, 4, 1, 5, 9, 2, 6, 5, 4]; p = normalized_to_sum( 1, [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] ) sampler = ValueSampler( v, p ) probabilities = defaultdict( lambda: 0.0 ) for (i, value) in enumerate( v ): probabilities[value] += p[i] print( probabilities ) print() frequencies = defaultdict( lambda: 0.0 ) n = 100000 for i in range( n ): value = sampler( random.random() ) frequencies[value] += 1/n print( frequencies ) main() Cheers & hth., - Alf Disclaimer: I just cooked it up and just cooked up binary searches usually have bugs. They usually need to be exercised and fixed. But I think you get the idea. Note also that division differs in Py3 and Py2. This is coded for Py3. From __peter__ at web.de Sun Mar 21 08:27:44 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 21 Mar 2010 13:27:44 +0100 Subject: nonuniform sampling with replacement References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: Jah_Alarm wrote: > I've got a vector length n of integers (some of them are repeating), > and I got a selection probability vector of the same length. How will > I sample with replacement k (<=n) values with the probabilty vector. > In Matlab this function is randsample. I couldn't find anything to > this extent in Scipy or Numpy. If all else fails you can do it yourself: import random import bisect def iter_sample_with_replacement(values, weights): _random = random.random _bisect = bisect.bisect acc_weights = [] sigma = 0 for w in weights: sigma += w acc_weights.append(sigma) while 1: yield values[_bisect(acc_weights, _random()*sigma)] def sample_with_replacement(k, values, weights): return list(islice(iter_sample_with_replacement(values, weights), k)) if __name__ == "__main__": from itertools import islice N = 10**6 values = range(4) weights = [2, 3, 4, 1] histo = [0] * len(values) for v in islice(iter_sample_with_replacement(values, weights), N): histo[v] += 1 print histo print sample_with_replacement(30, values, weights) Peter From alfps at start.no Sun Mar 21 08:28:15 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 21 Mar 2010 13:28:15 +0100 Subject: nonuniform sampling with replacement In-Reply-To: References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: * Alf P. Steinbach: > * Jah_Alarm: >> I've got a vector length n of integers (some of them are repeating), >> and I got a selection probability vector of the same length. How will >> I sample with replacement k (<=n) values with the probabilty vector. >> In Matlab this function is randsample. I couldn't find anything to >> this extent in Scipy or Numpy. > > [snip] > > > > Disclaimer: I just cooked it up and just cooked up binary searches > usually have bugs. They usually need to be exercised and fixed. But I > think you get the idea. Note also that division differs in Py3 and Py2. > This is coded for Py3. Sorry, I realized this just now: the name "p" in the choice() method is utterly misleading, which you can see from the call; it's a random number not a probability. I guess my fingers just repeated what they typed earlier. Cheeers, - Alf (repeat typist) From slais-www at ucl.ac.uk Sun Mar 21 10:29:58 2010 From: slais-www at ucl.ac.uk (djc) Date: Sun, 21 Mar 2010 14:29:58 +0000 Subject: should writing Unicode files be so slow In-Reply-To: References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: Antoine Pitrou wrote: > Le Fri, 19 Mar 2010 17:18:17 +0000, djc a ?crit : >> changing >> with open(filename, 'rU') as tabfile: to >> with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as >> tabfile: >> >> and >> with open(outfile, 'wt') as out_part: to >> with codecs.open(outfile, 'w', 'utf-8') as out_part: >> >> causes a program that runs in >> 43 seconds to take 4 minutes to process the same data. > > codecs.open() (and the object it returns) is slow as it is written in > pure Python. > > Accelerated reading and writing of unicode files is available in Python > 2.7 and 3.1, using the new `io` module. Thank you, for a clear and to the point explanation. I shall concentrate on finding an optimal time to upgrade from Python 2.6. -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From ra21vi at gmail.com Sun Mar 21 10:43:27 2010 From: ra21vi at gmail.com (Ravi Kumar) Date: Sun, 21 Mar 2010 14:43:27 +0000 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: <9a63e8921003210743t30fac328oed4a5b336ebcda19@mail.gmail.com> On Sat, Mar 20, 2010 at 7:27 PM, Brian J Mingus wrote: > Moderating this stuff requires moderating all messages. It would take a > team of volunteers. > You are right... Form the team of volunteers. More people in it, better it would be - since no one would have to be dedicated. -- -=Ravi=- -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sun Mar 21 11:02:45 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Mar 2010 08:02:45 -0700 (PDT) Subject: Clearing memory (namespace) before running code Message-ID: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> Hi, Is there a way to erase/delete/clear memory before a piece of code is run? Otherwise, the objects of the previous run are re-usable, and may bring confusion to the tester. Thank you From steve at holdenweb.com Sun Mar 21 11:11:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 11:11:18 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: Brian J Mingus wrote: > [... duplicating the spam and thereby lending it further Google juice ...] > -- > http://mail.python.org/mailman/listinfo/python-list > > Guys, I know it is a lot of work to moderate a large mailing list. But > still, with so many of us surely we can pull it off? > It's actually not as easy as you might think. If someone can propose a *practical* scheme for moderation of this high-volume list the PSF might consider such a proposal, but there would need to be considerable evidence that the scheme would work without delaying traffic. Since the spam that's getting through actually represents a tiny fraction of one percent of the spam that the list is bombarded with I personally feel that there would be very little positive return for a relatively large investment of effort, and that any volunteer time would be better spent making other contributions to the Python community. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Mar 21 11:13:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 11:13:44 -0400 Subject: Clearing memory (namespace) before running code In-Reply-To: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> References: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> Message-ID: vsoler wrote: > Hi, > > Is there a way to erase/delete/clear memory before a piece of code is > run? > > Otherwise, the objects of the previous run are re-usable, and may > bring confusion to the tester. > > Thank you You mean clear a *namespace*? That might be possible if you have access to the specific module whose namespace you want to clear. I presume this is related to earlier questions about reloading modules? This is yet another reason why you might want to consider running each module in its own process each time the user submits it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From joncle at googlemail.com Sun Mar 21 11:18:01 2010 From: joncle at googlemail.com (Jon Clements) Date: Sun, 21 Mar 2010 08:18:01 -0700 (PDT) Subject: Clearing memory (namespace) before running code References: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> Message-ID: <42678333-5b0f-43bb-9488-7e127d078083@l25g2000yqd.googlegroups.com> On 21 Mar, 15:02, vsoler wrote: > Hi, > > Is there a way to erase/delete/clear memory before a piece of code is > run? > > Otherwise, the objects of the previous run are re-usable, and may > bring confusion to the tester. > > Thank you I'm guessing you're using some sort of IDE? For instance, in IDLE if the [Python Shell] window is not closed, the session is kept. However, there is a menu option 'Shell' which has 'Restart Shell'. If you don't see a 'Shell' menu option, then make sure IDLE isn't being started with the -n option. However I would have thought the 'tester' would be running from a terminal/command line/double click jobby, so that a single Python session is executed and just runs -- rather than want to use it interactively afterwards. hth Jon. From deets at nospam.web.de Sun Mar 21 12:08:58 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: 21 Mar 2010 16:08:58 GMT Subject: How to automate accessor definition? References: Message-ID: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> kj wrote: > > > > > > > I need to create a class solely for the purpose of encapsulating > a large number of disparate data items. At the moment I have no > plans for any methods for this class other than the bazillion > accessors required to access these various instance variables. > (In case it matters, this class is meant to be a private helper > class internal to a module, and it won't be subclassed.) > > What is "best practice" for implementing this sort of class > *succinctly* (i.e. without a lot of repetitive accessor code)? > > Also, one more question concerning syntax. Suppose that i represents > an instance of this class. Is it possible to define the class to > support this syntax > > val = i.field > i.field += 6 > > ...rather than this one > > val = i.get_field() > i.set_field(i.get_field() + 6) > > ? You don't. Python is not Java. So just use instance attributes, and if you need bhavior when accessing an attribute, introduce a property. Diez From zookog at gmail.com Sun Mar 21 12:55:41 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Sun, 21 Mar 2010 10:55:41 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus wrote: > Moderating this stuff requires moderating all messages. Not quite. GNU Mailman comes with nice features to ease this task. You can configure it so that everyone who is currently subscribed can post freely, but new subscribers get a "moderated" bit set on them. The first time this new subscriber attempts to post to the list, a human moderator has to inspect their message and decide whether to approve it or deny it. If they human moderator approves it, they can also on the same web form remove the "moderated" bit from that poster. Therefore, the volunteer work required would be inspecting the *first* post from each *new* subscriber to see if that post is spam. Regards, Zooko From no.email at please.post Sun Mar 21 12:57:40 2010 From: no.email at please.post (kj) Date: Sun, 21 Mar 2010 16:57:40 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: In <639908184290880449.447600deets-nospam.web.de at news.hansenet.de> Diez B. Roggisch writes: >You don't. Python is not Java. So just use instance attributes, and if >you need bhavior when accessing an attribute, introduce a property. Just accessing attributes looks a bit dangerous to me, due to bugs like typing i.typo = 'foo' when what you meant is i.type = 'foo' I tried fixing this by mucking with __setattr__, but I didn't hit on a satisfactory solution (basically, I couldn't find a good, self-maintaining, way to specify the attributes that were OK to set from those that weren't). Is there anything built-in? Regarding properties, is there a built-in way to memoize them? For example, suppose that the value of a property is obtained by parsing the contents of a file (specified in another instance attribute). It would make no sense to do this parsing more than once. Is there a standard idiom for memoizing the value once it is determined for the first time? Thanks! ~K From no.email at please.post Sun Mar 21 13:02:30 2010 From: no.email at please.post (kj) Date: Sun, 21 Mar 2010 17:02:30 +0000 (UTC) Subject: How to automate accessor definition? References: Message-ID: In Chris Rebert writes: >On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: >> I need to create a class solely for the purpose of encapsulating >> a large number of disparate data items. =C2=A0At the moment I have no >> plans for any methods for this class other than the bazillion >> accessors required to access these various instance variables. >> (In case it matters, this class is meant to be a private helper >> class internal to a module, and it won't be subclassed.) >If it's just a completely dumb struct-like class, you might consider >something like: >http://docs.python.org/library/collections.html#collections.namedtuple Very cool. Thanks! The class I have in mind is *almost* that dumb, but performance is a consideration in this case, which may rule out namedtuple. But I'm glad to learn about it; there are many places where I can put them to good use. ~K From benjamin at python.org Sun Mar 21 13:12:08 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 21 Mar 2010 12:12:08 -0500 Subject: [RELEASED] Python 3.1.2 Message-ID: <1afaf6161003211012r30bc0e77ub5dfe9f248668525@mail.gmail.com> On behalf of the Python development team, I'm joyful to announce the second bugfix release of the Python 3.1 series, Python 3.1.2. This bug fix release fixes numerous issues found in 3.1.1, and is considered a production release. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.2 visit: http://www.python.org/download/releases/3.1.2/ A list of changes in 3.1.2 can be found here: http://svn.python.org/projects/python/tags/r312/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.2's contributors) From steve at holdenweb.com Sun Mar 21 13:12:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 13:12:23 -0400 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: kj wrote: > In Chris Rebert writes: > >> On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: >>> I need to create a class solely for the purpose of encapsulating >>> a large number of disparate data items. =C2=A0At the moment I have no >>> plans for any methods for this class other than the bazillion >>> accessors required to access these various instance variables. >>> (In case it matters, this class is meant to be a private helper >>> class internal to a module, and it won't be subclassed.) > >> If it's just a completely dumb struct-like class, you might consider >> something like: >> http://docs.python.org/library/collections.html#collections.namedtuple > > Very cool. Thanks! The class I have in mind is *almost* that > dumb, but performance is a consideration in this case, which may > rule out namedtuple. But I'm glad to learn about it; there are > many places where I can put them to good use. > You may well find that namedtuple is faster than what you put together yourself, as the collections module is implemented in C. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at please.post Sun Mar 21 13:25:08 2010 From: no.email at please.post (kj) Date: Sun, 21 Mar 2010 17:25:08 +0000 (UTC) Subject: How to automate accessor definition? References: <4ba58503$0$27838$c3e8da3@news.astraweb.com> Message-ID: In <4ba58503$0$27838$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >On Sat, 20 Mar 2010 22:15:54 +0000, kj wrote: >> I need to create a class solely for the purpose of encapsulating a large >> number of disparate data items. >There's a built-in for that. It's called "dict". Syntax for item access >is a tiny bit different, but still very common: >data['foo'] >instead of >data.foo I find the latter more readable than the former. All those extra elements (the brackets and the quotes, vs the single dot) add Perl-like visual noise to the code, IMHO. And dicts are vulnerable to this sort of bug: data['typo'] = type(foobar) Also, AFAIK, initialization of a dictionary is never as simple as i = myclass(*fields) But in a sense you're right: aside from these objections, *functionality-wise* what I'm looking for is not very different from a dictionary, or a C struct. >> At the moment I have no plans for any >> methods for this class other than the bazillion accessors required to >> access these various instance variables. >Huh? If you have instance variables, why don't you refer to them by name? I'm sorry, I used the wrong terminology. I see now that the correct term is "(instance) attribute", not "instance variable". >Leave the repetitive accessor code out. Python isn't Java. >http://dirtsimple.org/2004/12/python-is-not-java.html Thanks for the link! The bit about "Guido's time machine" is pretty funny. ~K From benjamin.kaplan at case.edu Sun Mar 21 13:38:42 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 21 Mar 2010 13:38:42 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: On Sun, Mar 21, 2010 at 12:55 PM, Zooko O'Whielacronx wrote: > On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus > wrote: >> Moderating this stuff requires moderating all messages. > > Not quite. GNU Mailman comes with nice features to ease this task. You > can configure it so that everyone who is currently subscribed can post > freely, but new subscribers get a "moderated" bit set on them. The > first time this new subscriber attempts to post to the list, a human > moderator has to inspect their message and decide whether to approve > it or deny it. If they human moderator approves it, they can also on > the same web form remove the "moderated" bit from that poster. > > Therefore, the volunteer work required would be inspecting the *first* > post from each *new* subscriber to see if that post is spam. > > Regards, > > Zooko The spam isn't coming through the mailing list. It's coming through the Google Groups mirror of the Usenet newsgroup. I don't think Mailman can do anything about that. From pmaupin at gmail.com Sun Mar 21 13:42:34 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 21 Mar 2010 10:42:34 -0700 (PDT) Subject: RSON 0.06 released Message-ID: <0b40fdf6-3fdd-4962-9994-c7c0936c588a@x12g2000yqx.googlegroups.com> I am pleased to announce the release of RSON 0.06. The goal of the RSON project is to create a file format that is easy to edit, diff, and version control, that is a superset of JSON and smaller than YAML. I consider this release to be feature complete on the file format, and I believe the pure Python 2.x decoder (parser) to be production worthy (for users who do not need the speed of a C based decoder). The project is at: http://rson.googlecode.com/ The manual with syntax examples is at: http://rson.googlecode.com/files/rson_0_06_manual.pdf Discussions at: http://groups.google.com/group/rson-discuss From ale.marino78 at gmail.com Sun Mar 21 14:12:18 2010 From: ale.marino78 at gmail.com (Alessandro Marino) Date: Sun, 21 Mar 2010 19:12:18 +0100 Subject: Regexp problem when parsing a string Message-ID: <9b9cf8321003211112q2333fb74h29e9a805053d1a13@mail.gmail.com> I'm a beginner and I was trying to write a program to parse recursively all file names in a directory specified as parameter. The problem is that I get a "None" printed to stdout when a file is positively matched. While when the file name doesn't match the regexp the output seems ok. C:\>c:\python.exe g:\a.py sample ====> foo - bar.txt , first part is: foo None skipping: foo.txt Instead I expect an output like this one: C:\>c:\python.exe g:\a.py sample ====> foo - bar.txt , first part is: foo None skipping: foo.txt Could anyone help me to figure out why "None" appears in the putput? Thanks and regards, Ale -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: a.py Type: application/octet-stream Size: 448 bytes Desc: not available URL: From andrej.mitrovich at gmail.com Sun Mar 21 14:14:16 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sun, 21 Mar 2010 11:14:16 -0700 (PDT) Subject: Python Documentation website layout changed? References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> <4BA120A9.3060001@holdenweb.com> Message-ID: <3116d122-3a7e-47d6-9bc9-574825ac7391@q23g2000yqd.googlegroups.com> On Mar 20, 12:32?am, Steve Holden wrote: > Steve Holden wrote: > > Andrej Mitrovic wrote: > >> On Mar 17, 6:41 pm, Andrej Mitrovic > >> wrote: > >>> Hi, > > >>> What happened to the sidebar on the left of the documentation website? > >>> It seems to be gone: > > >>>http://docs.python.org/py3k/index.html > > >>> I found it quite useful since I can quickly swap between Python2/3 > >>> documentation, and between other parts of the documentation as well. > >> Edit: It looks like only the Python 3 pages are affected, the Python 2 > >> pages are the same as before: > > >>http://docs.python.org/index.html > > >> Might be a bug? > > > I'll ask. Georg - is this known behavior or a temporary problem? > > It's a bug. Georg is on it. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > See PyCon Talks from Atlanta 2010 ?http://pycon.blip.tv/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ Looks like it's fixed now. Thanks Georg & Steve! From steve at REMOVE-THIS-cybersource.com.au Sun Mar 21 14:18:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Mar 2010 18:18:57 GMT Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: <4ba66311$0$27838$c3e8da3@news.astraweb.com> On Sun, 21 Mar 2010 16:57:40 +0000, kj wrote: > Just accessing attributes looks a bit dangerous to me, due to bugs like > typing > > i.typo = 'foo' > > when what you meant is > > i.type = 'foo' That's the price you pay for using a dynamic language like Python with no declarations. But honestly, the price isn't very high, particularly if you use an editor or IDE with auto-completion. I can't think of the last time I had an error due to the above sort of mistake. Besides, is that error really so much more likely than this? i.type = 'fpo' when you meant 'foo'? The compiler can't protect you from that error, not in any language. > I tried fixing this by mucking with __setattr__, but I didn't hit on a > satisfactory solution (basically, I couldn't find a good, > self-maintaining, way to specify the attributes that were OK to set from > those that weren't). Is there anything built-in? No. You could abuse __slots__, but it really is abuse: __slots__ are a memory optimization, not a typo-checker. In Python 3.x, you can (untested) replace the class __dict__ with a custom type that has more smarts. At the cost of performance. This doesn't work in 2.x though, as the class __dict__ is always a regular dictionary. Something like this might work, at some minor cost of performance: # Untested def __setattr__(self, name, value): if hasattr(self, name): super(MyClassName, self).__setattr__(name, value) else: raise TypeError('cannot create new attributes') Then, in your __init__ method, to initialise an attribute use: self.__dict__['attr'] = value to bypass the setattr. Or you can use something like PyChecker or PyLint to analyse your code and warm about likely typos. But really, it's not a common form of error. YMMV. > Regarding properties, is there a built-in way to memoize them? For > example, suppose that the value of a property is obtained by parsing the > contents of a file (specified in another instance attribute). It would > make no sense to do this parsing more than once. Is there a standard > idiom for memoizing the value once it is determined for the first time? Google for "Python memoization cookbook". This will get you started: http://code.activestate.com/recipes/52201/ Then just apply the memoize decorator to the property getter. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 21 14:26:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Mar 2010 18:26:59 GMT Subject: Regexp problem when parsing a string References: Message-ID: <4ba664f3$0$27838$c3e8da3@news.astraweb.com> On Sun, 21 Mar 2010 19:12:18 +0100, Alessandro Marino wrote: > Could anyone help me to figure out why "None" appears in the putput? I get: "Attachment not shown: MIME type application/octet-stream; filename a.py" Posting attachments to Usenet is tricky. Many newsgroups filter out anything they think isn't text, or even any attachment at all. Some news clients do the same thing. If you have too much code to include directly in your post, then you should put it up on a website somewhere and just include the link. Without looking at your code, I'd guess that using regular expressions is the wrong approach. Perhaps you should look at the glob module, and possibly os.walk. -- Steven From python at mrabarnett.plus.com Sun Mar 21 14:31:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Mar 2010 18:31:31 +0000 Subject: Regexp problem when parsing a string In-Reply-To: <9b9cf8321003211112q2333fb74h29e9a805053d1a13@mail.gmail.com> References: <9b9cf8321003211112q2333fb74h29e9a805053d1a13@mail.gmail.com> Message-ID: <4BA66603.1010303@mrabarnett.plus.com> Alessandro Marino wrote: > I'm a beginner and I was trying to write a program to > parse recursively all file names in a directory specified as parameter. > The problem is that I get a "None" printed to stdout when a file is > positively matched. While when the file name doesn't match the regexp > the output seems ok. > > C:\>c:\python.exe g:\a.py sample > ====> foo - bar.txt , first part is: foo > None > skipping: foo.txt > > Instead I expect an output like this one: > > C:\>c:\python.exe g:\a.py sample > ====> foo - bar.txt , first part is: foo > None > skipping: foo.txt > > Could anyone help me to figure out why "None" appears in the putput? > > Thanks and regards, > Ale > It's caused by: print saveData(file, m) The function saveData() returns None, which is then printed. From lists at cheimes.de Sun Mar 21 14:37:03 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Mar 2010 19:37:03 +0100 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: Steve Holden wrote: > You may well find that namedtuple is faster than what you put together > yourself, as the collections module is implemented in C. But namedtuple isn't, Steve. Namedtuple is a class generator that creates fast and efficient classes. From pmaupin at gmail.com Sun Mar 21 14:40:42 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 21 Mar 2010 11:40:42 -0700 (PDT) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: <7938941f-8d42-4b46-8b68-8f28c95df0c7@e1g2000yqh.googlegroups.com> On Mar 21, 11:57?am, kj wrote: > > Just accessing attributes looks a bit dangerous to me, due to bugs > like typing > > ? i.typo = 'foo' > > when what you meant is > > ? i.type = 'foo' > > I tried fixing this by mucking with __setattr__, but I didn't hit > on a satisfactory solution (basically, I couldn't find a good, > self-maintaining, way to specify the attributes that were OK to > set from those that weren't). ?Is there anything built-in? > If you *really* want static typing and validation for attributes in Python, you might check out enthought traits: http://code.enthought.com/projects/traits/ Regards, Pat From steve at holdenweb.com Sun Mar 21 14:47:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 14:47:32 -0400 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: Christian Heimes wrote: > Steve Holden wrote: >> You may well find that namedtuple is faster than what you put together >> yourself, as the collections module is implemented in C. > > But namedtuple isn't, Steve. Namedtuple is a class generator that > creates fast and efficient classes. > Ah, right, thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From aonlazio at gmail.com Sun Mar 21 14:52:36 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Sun, 21 Mar 2010 14:52:36 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: Relax guys, let have fun once in a while On Sat, Mar 20, 2010 at 12:18 AM, Naeem wrote: > "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY > FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY > RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" > "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" > "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" > -- > http://mail.python.org/mailman/listinfo/python-list > -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Mar 21 15:01:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 15:01:53 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: AON LAZIO wrote: > Relax guys, let have fun once in a while > [further repetition of the spamming URLs] facepalm. > > > -- > Passion is my style > Style? You call that style? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From Brian.Mingus at Colorado.EDU Sun Mar 21 15:11:29 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sun, 21 Mar 2010 13:11:29 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: <9839a05c1003211211u2fd34964i33f8328b61bab3e8@mail.gmail.com> On Sun, Mar 21, 2010 at 10:55 AM, Zooko O'Whielacronx wrote: > On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus > wrote: > > Moderating this stuff requires moderating all messages. > > Not quite. GNU Mailman comes with nice features to ease this task. You > can configure it so that everyone who is currently subscribed can post > freely, but new subscribers get a "moderated" bit set on them. The > first time this new subscriber attempts to post to the list, a human > moderator has to inspect their message and decide whether to approve > it or deny it. If they human moderator approves it, they can also on > the same web form remove the "moderated" bit from that poster. > > Therefore, the volunteer work required would be inspecting the *first* > post from each *new* subscriber to see if that post is spam. > > Regards, > > Zooko > I like this approach, but I like even better simply disabling the usenet gateway. I can't find the message now but someone mentioned it would almost completely get rid of the spam problem. I disagree with Steve Holden that since it's only ~1% we should just ignore it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Mar 21 15:57:50 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Mar 2010 12:57:50 -0700 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: <50697b2c1003211257i3b674a20ib3d335d465e9639@mail.gmail.com> On Sun, Mar 21, 2010 at 12:01 PM, Steve Holden wrote: > AON LAZIO wrote: >> Relax guys, let have fun once in a while >> > [further repetition of the spamming URLs] > > facepalm. Fortunately, Google has now shut down the spam blog anyway. Cheers, Chris From omrihsan at gmail.com Sun Mar 21 16:44:49 2010 From: omrihsan at gmail.com (Omer Ihsan) Date: Sun, 21 Mar 2010 13:44:49 -0700 (PDT) Subject: device identification Message-ID: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> i have installed pyusb now and run the sample usbenum.py....i have 3 usb ports on my PC but the results show 6 outputs to dev.filename..they are numbers like 001 or 005 etc.... and they changed when i plugged in devices...(i am no good with the usb standards)....i just want to identify each device/port... what parameter in the example would help me.... From darcy at druid.net Sun Mar 21 17:00:06 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 21 Mar 2010 17:00:06 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <50697b2c1003211257i3b674a20ib3d335d465e9639@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <50697b2c1003211257i3b674a20ib3d335d465e9639@mail.gmail.com> Message-ID: <20100321170006.03056484.darcy@druid.net> On Sun, 21 Mar 2010 12:57:50 -0700 Chris Rebert wrote: > Fortunately, Google has now shut down the spam blog anyway. Until next time. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From aahz at pythoncraft.com Sun Mar 21 17:34:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 21 Mar 2010 14:34:28 -0700 Subject: Method / Functions - What are the differences? References: <4B8EF717.3070701@optimum.net> < Message-ID: In article , John Posner wrote: > >Bruno (and anyone else interested) -- > >As I promised/threatened, here's the *start* of a write-up on >properties, aimed at non-advanced Python programmers: > > http://www.jjposner.net/media/python-properties-0310.pdf I'm interested, but not interested enough to download a PDF and fire up a PDF reader. Are you really using features that require PDF instead of just writing a web page? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From tjreedy at udel.edu Sun Mar 21 18:00:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 18:00:59 -0400 Subject: How to keep effects of image filters going for some seconds? In-Reply-To: References: Message-ID: On 3/21/2010 3:23 AM, Ren Wenshan wrote: > Hello, every pythoner. > > Firstly, I want to mention that English is my second language, so > maybe there are some sentences which makes you confused, sorry. > > I have been learning Panda3D, an open source 3D engine, these days. > Now, I'm trying to write a small game for fun and practice. However, > I've ran into a problem. > > I want to make some speical effects and there is my code: > > def ventose(self): > > global potato_HP > > if potato_HP[0] == 1 and potato_HP[1] == 0: > if random()> .30: > self.filters.setCartoonInk(separation = 0.8) > self.robotVincent.resetHead.start() > self.decreaseVincentHP() > Wait(3) > self.fliters.delCartoonInk() > > However, it doesn't work, the CartoonInk effect will never been shown > in my game and I don't want my game to wait three seconds, what I need > is to keep the effect for a period of time while the game run as well. The generic answer is to turn CartoonInk on and set a timed event for now+ 3 secs to turn it off. You will have to understand how to interact with the Panda event loop. For a more specific answer, follow Donn's advice -- Panda forum. I know there was one when I looked at Panda a year ago. > Besides that, I also want to show a counting back like "3", then "2", > then "1", finally "Go". Ok, instead to events set 1 sec in future. Terry Jan Reedy From tjreedy at udel.edu Sun Mar 21 18:06:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 18:06:05 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: On 3/21/2010 12:55 PM, Zooko O'Whielacronx wrote: > On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus > wrote: >> Moderating this stuff requires moderating all messages. > > Not quite. GNU Mailman comes with nice features to ease this task. You > can configure it so that everyone who is currently subscribed can post > freely, but new subscribers get a "moderated" bit set on them. The > first time this new subscriber attempts to post to the list, a human > moderator has to inspect their message and decide whether to approve > it or deny it. If they human moderator approves it, they can also on > the same web form remove the "moderated" bit from that poster. > > Therefore, the volunteer work required would be inspecting the *first* > post from each *new* subscriber to see if that post is spam. The first time I post to *any* mailing list from gmane, gmane holds the message until I respond to an email. So python-list could pass new posts from gmane while at least auto-querying anything from google. From tjreedy at udel.edu Sun Mar 21 18:10:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 18:10:44 -0400 Subject: [RELEASED] Python 3.1.2 In-Reply-To: <1afaf6161003211012r30bc0e77ub5dfe9f248668525@mail.gmail.com> References: <1afaf6161003211012r30bc0e77ub5dfe9f248668525@mail.gmail.com> Message-ID: On 3/21/2010 1:12 PM, Benjamin Peterson wrote: > On behalf of the Python development team, I'm joyful to announce the second > bugfix release of the Python 3.1 series, Python 3.1.2. Thanks for the work. > This bug fix release fixes numerous issues found in 3.1.1, and is considered a > production release. > > The Python 3.1 version series focuses on the stabilization and optimization of > the features and changes that Python 3.0 introduced. For example, the new I/O > system has been rewritten in C for speed. File system APIs that use unicode > strings now handle paths with undecodable bytes in them. Other features include > an ordered dictionary implementation, a condensed syntax for nested with > statements, and support for ttk Tile in Tkinter. For a more extensive list of > changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in > the Python distribution. > > To download Python 3.1.2 visit: > > http://www.python.org/download/releases/3.1.2/ > > A list of changes in 3.1.2 can be found here: > > http://svn.python.org/projects/python/tags/r312/Misc/NEWS There seem to be about a hundred fixes. > The 3.1 documentation can be found at: > > http://docs.python.org/3.1 > > Bugs can always be reported to: > > http://bugs.python.org From steve at holdenweb.com Sun Mar 21 18:44:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 18:44:11 -0400 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4B8EF717.3070701@optimum.net> < Message-ID: Aahz wrote: > In article , > John Posner wrote: >> Bruno (and anyone else interested) -- >> >> As I promised/threatened, here's the *start* of a write-up on >> properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested, but not interested enough to download a PDF and fire up > a PDF reader. Are you really using features that require PDF instead of > just writing a web page? For us standard browser users it's a single click, of course. Are you really forced to use an environment that can't start a PDF reader by clicking on a link? I appreciate that some people are disabled in ways that rule out reading a PDF, but since John has gone to some personal trouble to write this document he's surely entitled to choose his medium ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From janssen at parc.xerox.com Sun Mar 21 18:50:13 2010 From: janssen at parc.xerox.com (Bill Janssen) Date: Sun, 21 Mar 2010 15:50:13 PDT Subject: using Python distutils bdist_msi to create installer for large complicated package Message-ID: <61250.1269211813@parc.com> Martin, I've been re-thinking the UpLib Windows installer technology, and it occurred to me to wonder why I can't just use the nice bdist_msi module in Python to build my packages. I took a look, and it seems almost doable. Presumably you wrote it? UpLib is a big package, with lots of Python and Java and C programs, and for Windows I package it with lots of other programs like those from xpdf. All of this is installed in C:\Program Files\UpLib\VERSION\, in bin, lib, share, and so forth subdirectories. If I autogenerated a setup.py file which described everything as "data_files", it should be simple to package everything up in a Cab, and bdist_msi apparently also provides the ability to add pre- and post-install scripts. Everything I need, really. There are a couple of Python-specific options in the code: the "Product Name" is prefixed with the python version, and in the GUI, the default location is the location of a Python distro. If the package had a "--non-python" option which would defeat these, and perhaps also set "no-target-optimize" and "no-target-compile" to True, it would be a simple but pretty general-purpose packager module. I'll subclass it and play around a bit. Bill From ben+python at benfinney.id.au Sun Mar 21 18:50:58 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 22 Mar 2010 09:50:58 +1100 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: <87bpehthkd.fsf@benfinney.id.au> djc writes: > I shall concentrate on finding an optimal time to upgrade from Python > 2.6. Note that Python 2.7, though nearly ready, is not yet released . -- \ ?? Nature ? is seen to do all things Herself and through | `\ herself of own accord, rid of all gods.? ?Titus Lucretius | _o__) Carus, c. 40 BCE | Ben Finney From martin at v.loewis.de Sun Mar 21 19:00:30 2010 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 22 Mar 2010 00:00:30 +0100 Subject: using Python distutils bdist_msi to create installer for large complicated package In-Reply-To: <61250.1269211813@parc.com> References: <61250.1269211813@parc.com> Message-ID: <4BA6A50E.9060108@v.loewis.de> > I've been re-thinking the UpLib Windows installer technology, and it > occurred to me to wonder why I can't just use the nice bdist_msi module > in Python to build my packages. I took a look, and it seems almost > doable. Presumably you wrote it? Correct. > UpLib is a big package, with lots of Python and Java and C programs, and > for Windows I package it with lots of other programs like those from > xpdf. All of this is installed in C:\Program Files\UpLib\VERSION\, in > bin, lib, share, and so forth subdirectories. If I autogenerated a > setup.py file which described everything as "data_files", it should be > simple to package everything up in a Cab, and bdist_msi apparently also > provides the ability to add pre- and post-install scripts. Everything > I need, really. > > There are a couple of Python-specific options in the code: the "Product > Name" is prefixed with the python version, and in the GUI, the default > location is the location of a Python distro. If the package had a > "--non-python" option which would defeat these, and perhaps also set > "no-target-optimize" and "no-target-compile" to True, it would be a > simple but pretty general-purpose packager module. I'd rather recommend to base this off msilib directly, instead of trying to subvert bdist_msi to do what you want. There is actually quite a lot python-specifics in bdist_msi. If you find this too tedious to use, please propose *base classes* that could become part of msilib, rather than trying to create *subclasses* of the bdist_msi classes. Regards, Martin From john at castleamber.com Sun Mar 21 19:10:01 2010 From: john at castleamber.com (John Bokma) Date: Sun, 21 Mar 2010 17:10:01 -0600 Subject: Method / Functions - What are the differences? References: <4B8EF717.3070701@optimum.net> Message-ID: <87pr2xjmpi.fsf@castleamber.com> aahz at pythoncraft.com (Aahz) writes: > In article , > John Posner wrote: >> >>Bruno (and anyone else interested) -- >> >>As I promised/threatened, here's the *start* of a write-up on >>properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested, but not interested enough to download a PDF and fire up > a PDF reader. Are you really using features that require PDF instead of > just writing a web page? http://docs.google.com/viewer?url=http%3A%2F%2Fwww.jjposner.net%2Fmedia%2Fpython-properties-0310.pdf Hth, -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From hjgdjfdkjhdfkhjkl at gmail.com Sun Mar 21 19:28:08 2010 From: hjgdjfdkjhdfkhjkl at gmail.com (jhghjg jhgjh) Date: Sun, 21 Mar 2010 16:28:08 -0700 (PDT) Subject: sell:nike shoes$32,ed hardy(items),jean$30,handbag$35 Message-ID: http://www.etootoo.com free shipping competitive price

wholesale nikeshoes
nike wholesale
china wholesale jordan sneakers
wholesale jordans
cheap jordans
authentic jordans
wholesale Nike dunks
cheap nike dunks
nike dunk for cheap
discount nike dunks
cheap nike air force one sneaker in u.sl
cheap wholesale air force one
air force 1s 25th wholesale
cheap air force ls,air force ones wholesale
cheap wholesale nike air max,wholesale nike shox
r3,shox r4,shox r5,shox oz,shox nz,shox tl3
cheap wholesale bape shoes
cheap jeans wholesale
bags wholesale
From jjposner at optimum.net Sun Mar 21 19:28:43 2010 From: jjposner at optimum.net (John Posner) Date: Sun, 21 Mar 2010 19:28:43 -0400 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4B8EF717.3070701@optimum.net> < Message-ID: <4BA6ABAB.5060807@optimum.net> On 3/21/2010 5:34 PM, Aahz wrote: > In article, > John Posner wrote: >> >> Bruno (and anyone else interested) -- >> >> As I promised/threatened, here's the *start* of a write-up on >> properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested, but not interested enough to download a PDF and fire up > a PDF reader. Are you really using features that require PDF instead of > just writing a web page? No, I compose text using a WYSIWYG editor, and I assumed that PDF was a convenient format for others. I've been working on the writeup, and marking it up for use on the Python Wiki. So I've gone ahead and published it: http://wiki.python.org/moin/ComputedAttributesUsingPropertyObjects For good measure, I've also been working on an updated writeup for "property" in the "Built-in Functions" section of the official Python docs. A draft is in HTML format at: http://cl1p.net/jjp_python_property_ref.html/ Thanks for your interest! All comments are most welcome. -John From ldo at geek-central.gen.new_zealand Sun Mar 21 19:36:35 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Mar 2010 12:36:35 +1300 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: In message , Terry Reedy wrote: > No one has discovered a setting > of the internal tuning parameters for which there are no bad patterns > and I suspect there are not any such. This does not negate Xavier's > suggestion that a code change might also solve your problem. Could it be that for implementing a structure like a trie as the OP is, where a lot of CPU cycles can be spent manipulating the structure, a high- level language like Python, Perl or Ruby just gets in the way? My feeling would be, try to get the language to do as much of the work for you as possible. If you can?t do that, then you might be better off with a lower-level language. From twentyqstns at gmail.com Sun Mar 21 19:47:59 2010 From: twentyqstns at gmail.com (twenty questions) Date: Sun, 21 Mar 2010 16:47:59 -0700 (PDT) Subject: add an entry to twentyquestions.org (please) Message-ID: <73490ec3-5d3f-417a-b0fc-c697cd0fb08a@30g2000yqi.googlegroups.com> add an entry to http://www.twentyquestions.org (please) From rasky at develer.com Sun Mar 21 19:50:00 2010 From: rasky at develer.com (Giovanni Bajo) Date: Mon, 22 Mar 2010 00:50:00 +0100 Subject: [ANN] PyInstaller 1.4 Message-ID: <1269215400.3170.12.camel@ozzu> Hello, I'm happy to announce PyInstaller 1.4, the first formal release after several years of quiet development. http://www.pyinstaller.org === What it is === PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. It's similar to py2exe/py2app, but it is multiplatform and with many advanced features. The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. === Features === * Packaging of Python programs into standard executables, that work on computers without Python installed. * Multiplatform: works under Windows, Linux and Irix. Experimental Mac OS X support available. * Multiversion: works under any version of Python from 1.5 up to 2.6. NOTE: Support for Python 2.6+ on Windows is not included in this release yet. Please see this page for a working patch: http://www.pyinstaller.org/wiki/Python26Win * Flexible packaging mode: * Single directory: build a directory containing an executable plus all the external binary modules (.dll, .pyd, .so) used by the program. * Single file: build a single executable file, totally self-contained, which runs without any external dependency. * Custom: you can automate PyInstaller to do whatever packaging mode you want through a simple script file in Python. * Explicit intelligent support for many 3rd-packages (for hidden imports, external data files, etc.), to make them work with PyInstaller out-of-the-box. * Full single-file EGG support: .egg files are automatically packaged by PyInstaller as-is, so that all features are supported at runtime as well (entry points, etc.). * Automatic support for binary libraries used through ctypes (see http://www.pyinstaller.org/wiki/CtypesDependencySupport for details). * Support for automatic binary packing through the well-known UPX compressor. * Support for code-signing executables on Windows. * Optional console mode (see standard output and standard error at runtime). * Selectable executable icon (Windows only). * Fully configurable version resource section in executable (Windows only). * Support for building COM servers (Windows only). === ChangeLog === For those already using older versions of PyInstaller, the full changelog for this release can be found here: http://www.pyinstaller.org/browser/tags/1.4/doc/CHANGES.txt === Feedback === We're eager to listent to your feedback on using PyInstaller: Ticketing system: http://www.pyinstaller.org/newticket Mailing list: http://groups-beta.google.com/group/PyInstaller -- Giovanni Bajo :: Develer S.r.l. rasky at develer.com :: http://www.develer.com Blog: http://giovanni.bajo.it Last post: ctypes support in PyInstaller From janssen at parc.com Sun Mar 21 19:52:35 2010 From: janssen at parc.com (Bill Janssen) Date: Sun, 21 Mar 2010 16:52:35 PDT Subject: using Python distutils bdist_msi to create installer for large complicated package In-Reply-To: <4BA6A50E.9060108@v.loewis.de> References: <61250.1269211813@parc.com> <4BA6A50E.9060108@v.loewis.de> Message-ID: <63771.1269215555@parc.com> Martin v. L?wis wrote: > > I've been re-thinking the UpLib Windows installer technology, and it > > occurred to me to wonder why I can't just use the nice bdist_msi module > > in Python to build my packages. I took a look, and it seems almost > > doable. Presumably you wrote it? > > Correct. > > > UpLib is a big package, with lots of Python and Java and C programs, and > > for Windows I package it with lots of other programs like those from > > xpdf. All of this is installed in C:\Program Files\UpLib\VERSION\, in > > bin, lib, share, and so forth subdirectories. If I autogenerated a > > setup.py file which described everything as "data_files", it should be > > simple to package everything up in a Cab, and bdist_msi apparently also > > provides the ability to add pre- and post-install scripts. Everything > > I need, really. > > > > There are a couple of Python-specific options in the code: the "Product > > Name" is prefixed with the python version, and in the GUI, the default > > location is the location of a Python distro. If the package had a > > "--non-python" option which would defeat these, and perhaps also set > > "no-target-optimize" and "no-target-compile" to True, it would be a > > simple but pretty general-purpose packager module. > > I'd rather recommend to base this off msilib directly, instead of trying > to subvert bdist_msi to do what you want. Yes, that was the first thing I looked at. But as you've pointed out in the past, it requires a lot of MSI know-how to use that library directly. For a variety of applications, you've already embedded most if not all of that know-how in the bdist_msi class. And subclassing is the indicated way to build on distutils, isn't it? > There is actually quite a lot python-specifics in bdist_msi. Well, sort of. If a setup only references "data_files" -- no Python packages, no extensions -- it's pretty generic. The "add_find_python" method seems the most python-specific. I'd remove a lot of that in the generic case. And, of course, modify "run" so that the product name isn't prefixed with "Python x.y". > If you find this too tedious to use, > please propose *base classes* that could become part of msilib, rather > than trying to create *subclasses* of the bdist_msi classes. Yes, good idea. For example, all those panels that are in get_ui could be added by a InstallerBaseGUI class of some sort. But still, just a few mods to bdist_msi could go a long way. For instance, you've already pulled out "get_installer_filename". I'd add a similar method, "get_product_name", which would typically just return the user-specific name, but in the default case could prefix the product name with Python 2.6. Bill From mailers at oranged.to Sun Mar 21 20:12:00 2010 From: mailers at oranged.to (Jimmy Stewpot) Date: Mon, 22 Mar 2010 00:12:00 +0000 (UTC) Subject: Best practise for dual stack programming in python Message-ID: <58492962.583.1269216720829.JavaMail.root@poops.oranged.to> Hello, The organisation that I currently work for has a large number of 'legacy' tools and scripts which rely entirely on IPv4. Many of them have been written and not documented etc. The organisation is in the process of moving to a dual stack environment over the next 3 months. With that in mind many of our scripts need to be rewritten and documented. I have been looking at moving from a mix of languages over to a standard which at this point is looking like it will be Python (because I am most familiar with it). I have never done any dual stack coding so I am interested to know if there are any good resources for developing dual stack python code? I have had a look around and have found very little on the python web page which makes me worry. Does anyone have any recommendations on web pages to read or books to look at? Any additional advice would be really appreciated. Regards, Jimmy Stewpot. From no.email at please.post Sun Mar 21 21:36:19 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 01:36:19 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba66311$0$27838$c3e8da3@news.astraweb.com> Message-ID: In <4ba66311$0$27838$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >Then, in your __init__ method, to initialise an attribute use: > self.__dict__['attr'] = value >to bypass the setattr. Ah, that's the trick! Thanks! ~K From ben+python at benfinney.id.au Sun Mar 21 21:46:07 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 22 Mar 2010 12:46:07 +1100 Subject: add an entry to twentyquestions.org (please) References: <73490ec3-5d3f-417a-b0fc-c697cd0fb08a@30g2000yqi.googlegroups.com> Message-ID: <8739ztt9gg.fsf@benfinney.id.au> twenty questions writes: > add an entry to http://www.twentyquestions.org (please) Don't spam groups with your off-topic begging for a closed database silo (please) -- \ ?Our nylons cost more than common, but you'll find that they | `\ are best in the long run.? ?shop, Tokyo | _o__) | Ben Finney From agoretoy at gmail.com Sun Mar 21 22:04:15 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 21 Mar 2010 20:04:15 -0600 Subject: execute bash builtins in python In-Reply-To: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: Thank you for the great suggestions. Steve Holden that is a good one, I will try to adapt my application to your suggestion. This way I don't have to source .bashrc when it could do all that for me including other things that it does in the background. Thank you so much. Nobody, I was not aware of that shell arg thing, thank you. Ipython is ok, but in this case I would have to force another dependency, which I'm trying to keep those as low as possible for such a small application. In fact, I'm gonna remove desktopcouch (couchdb) as one of the deps in the next release of courtesyflush. Expect the next release sometime late next week, if you interested in the app. find it on launchpad. :) Enjoy. Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Mar 21 22:39:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 22:39:44 -0400 Subject: Best practise for dual stack programming in python In-Reply-To: <58492962.583.1269216720829.JavaMail.root@poops.oranged.to> References: <58492962.583.1269216720829.JavaMail.root@poops.oranged.to> Message-ID: On 3/21/2010 8:12 PM, Jimmy Stewpot wrote: > Hello, > > The organisation that I currently work for has a large number of > 'legacy' tools and scripts which rely entirely on IPv4. Many of them > have been written and not documented etc. The organisation is in the > process of moving to a dual stack environment over the next 3 months. > With that in mind many of our scripts need to be rewritten and > documented. I have been looking at moving from a mix of languages > over to a standard which at this point is looking like it will be > Python (because I am most familiar with it). I have never done any > dual stack coding so I am interested to know if there are any good > resources for developing dual stack python code? I have had a look > around and have found very little on the python web page which makes > me worry. Does anyone have any recommendations on web pages to read > or books to look at? There are at least 2 ip address libraries which handle both ip4 and ip6. One is Google's package, http://pypi.python.org/pypi/ipaddr/2.0.0 I forget the name of the other, which covers a bit more than the above with a slightly different conceptual model. Would these help. Terry Jan Reedy From sam at tregar.com Sun Mar 21 23:08:36 2010 From: sam at tregar.com (Sam Tregar) Date: Sun, 21 Mar 2010 23:08:36 -0400 Subject: [ANN] onlinepayment v1.0.0 released In-Reply-To: References: Message-ID: onlinepayment v1.0.0 - a generic Python API for making online payments This module provides an API wrapper around a variety of payment providers. Using this module you can write code that will work the same regardless of the payment provider in use. Examples:: from onlinepayment import OnlinePayment # connect to authorize.net, setup auth with login and key auth= { 'login': 'YOUR LOGIN HERE', 'key': 'YOUR KEY HERE' } op = OnlinePayment('authnet', test_mode=True, auth=auth) # or for paypal, setup auth with user, pass, vendor and product: auth= { 'username': 'YOUR USERNAME HERE', 'password': 'YOUR PASSWORD HERE', 'vendor': 'YOUR VENDOR HERE', 'product': 'YOUR PRODUCT HERE' } # connect to PayPal op = OnlinePayment('paypal', test_mode=True, auth=auth) # charge a card try: result = op.sale(first_name = 'Joe', last_name = 'Example', address = '100 Example Ln.', city = 'Exampleville', state = 'NY', zip = '10001', amount = '2.00', card_num = '4007000000027', exp_date = '0530', card_code = '1234') except conn.TransactionDeclined: # do something when the transaction fails except conn.CardExpired: # tell the user their card is expired except conn.ProcessorException: # handle all other possible processor-generated exceptions generically # examine result, the values returned here are processor-specific success = result.success code = result.code message = result.message trans_id = result.trans_id # you can get the raw data returned by the underlying processor too orig = result.orig Installation ============ Before you can use this module you must install one or more payment processors. To install the PayPal payflowpro package:: # easy_install pytz # easy_install python-payflowpro To install the zc.authorizedotnet package and the authorize package (for recurring support):: # easy_install zc.authorizedotnet # easy_install authorize If you want authorize.net support you'll need to install a patched version of zc.ssl. Hopefully someday this will be released by the Zope devs, but so far I haven't heard anything back. Download the zc.ssl source package from http://pypi.python.org/pypi/zc.ssl/, then unpack:: # tar zxvf zc.ssl-1.1.tar.gz # cd zc.ssl-1.1 Now download and apply my zc-ssl-timeout.patch:: # wget http://python-onlinepayment.googlecode.com/svn/trunk/zc-ssl-timeout.patch # patch -p1 < /zc-ssl-timeout.patch And install the patched module:: # python setup.py install (You may also need to edit setup.py and remove the 'ssl-for-setuptools' dependecy. I did, although it may be a quirk of my Python install rather than a general problem.) Once you have a payment processor you can install this module:: # easy_install onlinepayment For more information see: http://pypi.python.org/pypi/onlinepayment/1.0.0 -------------- next part -------------- An HTML attachment was scrubbed... URL: From maymunbeyin at gmail.com Sun Mar 21 23:45:51 2010 From: maymunbeyin at gmail.com (kuru) Date: Sun, 21 Mar 2010 20:45:51 -0700 (PDT) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <3c11d8e6-ea2d-43d6-a9c9-5c23a52fba8f@l25g2000yqd.googlegroups.com> Thanks for the shell. It is nice alternative , however I am not ready to give up Ipython :) If the code ends with a comment line your shell is giving an error. Feature request: It would be nice to have numbered lines in the code section, it makes it hard to find problem line Feature request: Loading an actual Python file rather than copy pasting keep up the good work From zookog at gmail.com Mon Mar 22 01:09:46 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Sun, 21 Mar 2010 23:09:46 -0600 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: Folks: I failed to make something sufficiently clear in my original message about StringChain. The use case that I am talking about is not simply that you need to accumulate a sequence of incoming chunks of data, concatenate them together, and then process the entire result. If that is all you need to do then indeed you can accumulate the incoming strings in a list and then run ''.join(thelist) when you have received all of them and are ready to process them. But the use case that I am talking about is where you need to accumulate new incoming strings into your buffer while alternately processing leading prefixes of the buffer. The typical example is that sequences of bytes are arriving on your TCP socket and you are processing the stream incrementally. You need to process the leading prefixes of the stream as soon as you can (e.g. as soon as a line followed by a newline has accumulated, or as soon as another complete element in your data format has accumulated, etc.); you can't simply wait until the bytes stop coming and then concatenate the entire collection together at once. This is exactly the current situation in foolscap [1] which is causing a performance problem in Tahoe-LAFS [2]. To illustrate what I mean I cooked up some benchmarks showing the task of "accumulate a bunch of things then consume them in a single gulp" versus the task of "alternate between accumulating and consuming" (with accumulation going faster than consumption until the input stream runs dry). I implemented a few data structures for benchmarking: StringChain, the naive "accumulatorstr += newstr" approach (named "Stringy" in the benchmarks), one based on cStringIO (named "StringIOy"), one based on accumulating the new strings into a list and then doing ''.join(accumulatorlist) whenever you need to consume a leading prefix (called "SimplerStringChain"). Below are the abbreviated results of the benchmark. You can easily run this benchmark yourself by following the README.txt in the StringChain source package [3]. These results show that for the load imposed by this benchmark StringChain is the only one of the four that scales and that it is also nice and fast. The left-hand column is the total number of bytes that were run through it. The results are shown in nanoseconds per byte in exponential notation. ("e+01" means times 10, "e+02" means times 100, and "e+03" means times 1000, etc.) Each result is the best of 10 tries, or of 5 tries for the tasks which were taking too long to run it 10 times. Regards, Zooko [1] http://foolscap.lothar.com/trac/ticket/149 [2] http://allmydata.org/pipermail/tahoe-dev/2010-March/004181.html [3] http://tahoe-lafs.org/trac/stringchain impl: StringChain task: _accumulate_then_one_gulp 10000 best: 2.694e+00 50000 best: 2.742e+00 100000 best: 2.310e+00 500000 best: 2.040e+00 1000000 best: 1.988e+00 5000000 best: 2.193e+00 task: _alternate_str 10000 best: 6.509e+00 50000 best: 4.559e+00 100000 best: 4.308e+00 500000 best: 4.070e+00 1000000 best: 3.991e+00 5000000 best: 4.000e+00 impl: SimplerStringChain task: _accumulate_then_one_gulp 10000 best: 1.407e+00 50000 best: 2.317e+00 100000 best: 2.012e+00 500000 best: 1.902e+00 1000000 best: 1.897e+00 5000000 best: 2.104e+00 task: _alternate_str 10000 best: 4.888e+00 50000 best: 5.198e+00 100000 best: 1.750e+01 500000 best: 6.233e+01 1000000 best: 1.134e+02 5000000 best: 7.599e+02 impl: StringIOy task: _accumulate_then_one_gulp 10000 best: 4.196e+00 50000 best: 5.522e+00 100000 best: 4.499e+00 500000 best: 3.756e+00 1000000 best: 4.176e+00 5000000 best: 5.414e+00 task: _alternate_str 10000 best: 5.484e+00 50000 best: 7.863e+00 100000 best: 2.126e+01 500000 best: 6.972e+01 1000000 best: 1.219e+02 5000000 best: 9.463e+02 task: _accumulate_then_one_gulp 10000 best: 1.502e+00 50000 best: 1.420e+01 100000 best: 2.245e+01 500000 best: 8.577e+01 1000000 best: 2.295e+02 5000000 best: 1.326e+03 task: _alternate_str 10000 best: 3.290e+00 50000 best: 4.220e+00 100000 best: 1.665e+01 500000 best: 6.281e+01 1000000 best: 1.127e+02 5000000 best: 7.626e+02 From mws42262 at yahoo.com Mon Mar 22 01:29:57 2010 From: mws42262 at yahoo.com (sam) Date: Sun, 21 Mar 2010 22:29:57 -0700 (PDT) Subject: ------->>>FREE MAC<<<------- Message-ID: <26c5c978-e176-4ff4-afb5-68eef6c466b7@33g2000yqj.googlegroups.com> http://michellemichaeldiscounts.com/16801.html From aram1980 at gmail.com Mon Mar 22 03:22:01 2010 From: aram1980 at gmail.com (Aram Ter-Sarkissov) Date: Mon, 22 Mar 2010 00:22:01 -0700 (PDT) Subject: nonuniform sampling with replacement References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: On 22 ???, 01:28, "Alf P. Steinbach" wrote: > * Alf P. Steinbach: > > > > > * Jah_Alarm: > >> I've got a vector length n of integers (some of them are repeating), > >> and I got a selection probability vector of the same length. How will > >> I sample with replacement k (<=n) values with the probabilty vector. > >> In Matlab this function is randsample. I couldn't find anything to > >> this extent in Scipy or Numpy. > > > > [snip] > > > > > Disclaimer: I just cooked it up and just cooked up binary searches > > usually have bugs. They usually need to be exercised and fixed. But I > > think you get the idea. Note also that division differs in Py3 and Py2. > > This is coded for Py3. > > Sorry, I realized this just now: the name "p" in the choice() method is utterly > misleading, which you can see from the call; it's a random number not a > probability. I guess my fingers just repeated what they typed earlier. > > Cheeers, > > - Alf (repeat typist) thanks a lot alex From aram1980 at gmail.com Mon Mar 22 03:24:16 2010 From: aram1980 at gmail.com (Aram Ter-Sarkissov) Date: Mon, 22 Mar 2010 00:24:16 -0700 (PDT) Subject: nonuniform sampling with replacement References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: On 22 ???, 01:27, Peter Otten <__pete... at web.de> wrote: > Jah_Alarm wrote: > > I've got a vector length n of integers (some of them are repeating), > > and I got a selection probability vector of the same length. How will > > I sample with replacement k (<=n) values with the probabilty vector. > > In Matlab this function is randsample. I couldn't find anything to > > this extent in Scipy or Numpy. > > If all else fails you can do it yourself: > > import random > import bisect > > def iter_sample_with_replacement(values, weights): > ? ? _random = random.random > ? ? _bisect = bisect.bisect > > ? ? acc_weights = [] > ? ? sigma = 0 > ? ? for w in weights: > ? ? ? ? sigma += w > ? ? ? ? acc_weights.append(sigma) > ? ? while 1: > ? ? ? ? yield values[_bisect(acc_weights, _random()*sigma)] > > def sample_with_replacement(k, values, weights): > ? ? return list(islice(iter_sample_with_replacement(values, weights), k)) > > if __name__ == "__main__": > ? ? from itertools import islice > ? ? N = 10**6 > ? ? values = range(4) > ? ? weights = [2, 3, 4, 1] > > ? ? histo = [0] * len(values) > ? ? for v in islice(iter_sample_with_replacement(values, weights), N): > ? ? ? ? histo[v] += 1 > ? ? print histo > ? ? print sample_with_replacement(30, values, weights) > > Peter thanks a lot, Alex From agoretoy at gmail.com Mon Mar 22 03:32:36 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Mar 2010 01:32:36 -0600 Subject: execute bash builtins in python In-Reply-To: References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: I do have a problem however that I don't know how to solve. My application dies abruptly at random times because of this and I get this output error in the terminal: bash: line 0: declare: write error: Broken pipe and sometimes it crashes and I get this output error; this one maybe gtk related, yes? *** glibc detected *** /usr/bin/python: double free or corruption (fasttop): 0xb650fa78 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0x17aff1] /lib/tls/i686/cmov/libc.so.6[0x17c6f2] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x17f7cd] /lib/libglib-2.0.so.0(g_free+0x36)[0x7a3196] /usr/lib/libgdk-x11-2.0.so.0[0x27faba] /usr/lib/libgdk-x11-2.0.so.0(gdk_region_union+0x8e)[0x28129e] /usr/lib/libgdk-x11-2.0.so.0[0x28e26c] /usr/lib/libgdk-x11-2.0.so.0(gdk_window_invalidate_maybe_recurse+0x243)[0x28eb33] /usr/lib/libgdk-x11-2.0.so.0(gdk_window_invalidate_maybe_recurse+0x206)[0x28eaf6] /usr/lib/libgtk-x11-2.0.so.0[0x28b5893] /usr/lib/libgtk-x11-2.0.so.0[0x28b6cff] /usr/lib/libgtk-x11-2.0.so.0(gtk_widget_queue_resize+0x75)[0x28bcaa5] /usr/lib/libgtk-x11-2.0.so.0[0x288b557] /usr/lib/libgobject-2.0.so.0(g_cclosure_marshal_VOID__BOXED+0x88)[0x320068] /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x1b2)[0x313072] /usr/lib/libgobject-2.0.so.0[0x3287a8] /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x7bd)[0x329b2d] /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x26)[0x329fb6] /usr/lib/libgtk-x11-2.0.so.0(gtk_tree_model_row_deleted+0x9a)[0x28751da] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_remove+0x114)[0x278e9e4] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_clear+0x90)[0x278eab0] /usr/lib/pymodules/python2.6/gtk-2.0/gtk/_gtk.so[0x10b64a1] /usr/bin/python(PyEval_EvalFrameEx+0x4175)[0x80dbfd5] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python(PyEval_EvalCodeEx+0x7d2)[0x80dddf2] /usr/bin/python[0x816014c] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python[0x80684ac] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python(PyEval_CallObjectWithKeywords+0x42)[0x80d6ef2] /usr/bin/python(PyObject_CallObject+0x20)[0x80612a0] /usr/lib/pymodules/python2.6/gtk-2.0/gobject/_gobject.so[0xd4503e] /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x1b2)[0x313072] /usr/lib/libgobject-2.0.so.0[0x3287a8] /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x7bd)[0x329b2d] /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x26)[0x329fb6] /usr/lib/libgtk-x11-2.0.so.0[0x26fb8dc] /usr/lib/libgobject-2.0.so.0(g_cclosure_marshal_VOID__BOXED+0x88)[0x320068] /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x1b2)[0x313072] /usr/lib/libgobject-2.0.so.0[0x3287a8] /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x7bd)[0x329b2d] /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x26)[0x329fb6] /usr/lib/libgtk-x11-2.0.so.0(gtk_tree_model_row_deleted+0x9a)[0x28751da] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_remove+0x114)[0x278e9e4] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_clear+0x90)[0x278eab0] /usr/lib/pymodules/python2.6/gtk-2.0/gtk/_gtk.so[0x10b64a1] /usr/bin/python(PyEval_EvalFrameEx+0x4175)[0x80dbfd5] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python[0x815de2f] /usr/bin/python(PyEval_EvalFrameEx+0x95f)[0x80d87bf] /usr/bin/python(PyEval_EvalCodeEx+0x7d2)[0x80dddf2] /usr/bin/python[0x816022f] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python(PyEval_EvalFrameEx+0x30b9)[0x80daf19] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python(PyEval_EvalCodeEx+0x7d2)[0x80dddf2] /usr/bin/python[0x816014c] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python[0x80684ac] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python(PyEval_CallObjectWithKeywords+0x42)[0x80d6ef2] /usr/bin/python[0x8107d88] ======= Memory map: ======== 00110000-0024e000 r-xp 00000000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 0024e000-0024f000 ---p 0013e000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 0024f000-00251000 r--p 0013e000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 00251000-00252000 rw-p 00140000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 00252000-00255000 rw-p 00000000 00:00 0 00255000-002e7000 r-xp 00000000 08:06 198090 /usr/lib/libgdk-x11-2.0.so.0.1800.3 002e7000-002e9000 r--p 00092000 08:06 198090 /usr/lib/libgdk-x11-2.0.so.0.1800.3 002e9000-002ea000 rw-p 00094000 08:06 198090 /usr/lib/libgdk-x11-2.0.so.0.1800.3 002ea000-00305000 r-xp 00000000 08:06 198967 /usr/lib/libatk-1.0.so.0.2809.1 00305000-00306000 r--p 0001b000 08:06 198967 /usr/lib/libatk-1.0.so.0.2809.1 00306000-00307000 rw-p 0001c000 08:06 198967 /usr/lib/libatk-1.0.so.0.2809.1 00307000-00308000 rwxp 00000000 00:00 0 00308000-00344000 r-xp 00000000 08:06 196888 /usr/lib/libgobject-2.0.so.0.2200.3 00344000-00345000 r--p 0003b000 08:06 196888 /usr/lib/libgobject-2.0.so.0.2200.3 00345000-00346000 rw-p 0003c000 08:06 196888 /usr/lib/libgobject-2.0.so.0.2200.3 00346000-00351000 r-xp 00000000 08:06 199652 /usr/lib/libpangocairo-1.0.so.0.2600.0 00351000-00352000 r--p 0000a000 08:06 199652 /usr/lib/libpangocairo-1.0.so.0.2600.0 00352000-00353000 rw-p 0000b000 08:06 199652 /usr/lib/libpangocairo-1.0.so.0.2600.0 00353000-003e6000 r-xp 00000000 08:06 197035 /usr/lib/libgio-2.0.so.0.2200.3 003e6000-003e7000 r--p 00092000 08:06 197035 /usr/lib/libgio-2.0.so.0.2200.3 003e7000-003e8000 rw-p 00093000 08:06 197035 /usr/lib/libgio-2.0.so.0.2200.3 003e8000-003e9000 rw-p 00000000 00:00 0 003e9000-003eb000 r-xp 00000000 08:06 198888 /usr/lib/libXcomposite.so.1.0.0 003eb000-003ec000 r--p 00001000 08:06 198888 /usr/lib/libXcomposite.so.1.0.0 003ec000-003ed000 rw-p 00002000 08:06 198888 /usr/lib/libXcomposite.so.1.0.0 003ed000-003ef000 r-xp 00000000 08:06 198892 /usr/lib/libXdamage.so.1.1.0 003ef000-003f0000 rw-p 00001000 08:06 198892 /usr/lib/libXdamage.so.1.1.0 003f0000-003f4000 r-xp 00000000 08:06 198898 /usr/lib/libXfixes.so.3.1.0 003f4000-003f5000 r--p 00003000 08:06 198898 /usr/lib/libXfixes.so.3.1.0 003f5000-003f6000 rw-p 00004000 08:06 198898 /usr/lib/libXfixes.so.3.1.0 003f6000-00404000 r-xp 00000000 08:06 198896 /usr/lib/libXext.so.6.4.0 00404000-00405000 r--p 0000d000 08:06 198896 /usr/lib/libXext.so.6.4.0 00405000-00406000 rw-p 0000e000 08:06 198896 /usr/lib/libXext.so.6.4.0 00406000-0040e000 r-xp 00000000 08:06 198918 /usr/lib/libXrender.so.1.3.0 0040e000-0040f000 r--p 00007000 08:06 198918 /usr/lib/libXrender.so.1.3.0 0040f000-00410000 rw-p 00008000 08:06 198918 /usr/lib/libXrender.so.1.3.0 00410000-00425000 r-xp 00000000 08:06 688141 /lib/tls/i686/cmov/ libpthread-2.10.1.so 00425000-00426000 r--p 00014000 08:06 688141 /lib/tls/i686/cmov/ libpthread-2.10.1.so 00426000-00427000 rw-p 00015000 08:06 688141 /lib/tls/i686/cmov/ libpthread-2.10.1.so 00427000-00429000 rw-p 00000000 00:00 0 00429000-0042b000 r-xp 00000000 08:06 198906 /usr/lib/libXinerama.so.1.0.0 0042b000-0042c000 rw-p 00001000 08:06 198906 /usr/lib/libXinerama.so.1.0.0 0042c000-00435000 r-xp 00000000 08:06 198904 /usr/lib/libXi.so.6.0.0 00435000-00436000 r--p 00008000 08:06 198904 /usr/lib/libXi.so.6.0.0 00436000-00437000 rw-p 00009000 08:06 198904 /usr/lib/libXi.so.6.0.0 00437000-00440000 r-xp 00000000 08:06 198890 /usr/lib/libXcursor.so.1.0.2 00440000-00441000 r--p 00008000 08:06 198890 /usr/lib/libXcursor.so.1.0.2 00441000-00442000 rw-p 00009000 08:06 198890 /usr/lib/libXcursor.so.1.0.2 00442000-00452000 r-xp 00000000 08:06 688142 /lib/tls/i686/cmov/ libresolv-2.10.1.so 00452000-00453000 r--p 00010000 08:06 688142 /lib/tls/i686/cmov/ libresolv-2.10.1.so 00453000-00454000 rw-p 00011000 08:06 688142 /lib/tls/i686/cmov/ libresolv-2.10.1.so 00454000-00456000 rw-p 00000000 00:00 0 00456000-0045e000 r-xp 00000000 08:06 199193 /usr/lib/libfusion-1.2.so.0.7.0 0045e000-0045f000 r--p 00007000 08:06 199193 /usr/lib/libfusion-1.2.so.0.7.0 0045f000-00460000 rw-p 00008000 08:06 199193 /usr/lib/libfusion-1.2.so.0.7.0 00460000-00463000 r-xp 00000000 08:06 199911 /usr/lib/libxcb-render-util.so.0.0.0 00463000-00464000 r--p 00002000 08:06 199911 /usr/lib/libxcb-render-util.so.0.0.0 00464000-00465000 rw-p 00003000 08:06 199911 /usr/lib/libxcb-render-util.so.0.0.0 00465000-0046c000 r-xp 00000000 08:06 199913 /usr/lib/libxcb-render.so.0.0.0 0046c000-0046d000 r--p 00007000 08:06 199913 /usr/lib/libxcb-render.so.0.0.0 0046d000-0046e000 rw-p 00008000 08:06 199913 /usr/lib/libxcb-render.so.0.0.0 0046e000-00486000 r-xp 00000000 08:06 198092 /usr/lib/libgdk_pixbuf-2.0.so.0.1800.3 00486000-00487000 r--p 00017000 08:06 198092 /usr/lib/libgdk_pixbuf-2.0.so.0.1800.3 00487000-00488000 rw-p 00018000 08:06 198092 /usr/lib/libgdk_pixbuf-2.0.so.0.1800.3 00488000-004ff000 r-xp 00000000 08:06 196251 /usr/lib/libcairo.so.2.10800.8 004ff000-00501000 r--p 00076000 08:06 196251 /usr/lib/libcairo.so.2.10800.8 00501000-00502000 rw-p 00078000 08:06 196251 /usr/lib/libcairo.so.2.10800.8 00502000-00548000 r-xp 00000000 08:06 199650 /usr/lib/libpango-1.0.so.0.2600.0 00548000-00549000 r--p 00045000 08:06 199650 /usr/lib/libpango-1.0.so.0.2600.0 00549000-0054a000 rw-p 00046000 08:06 199650 /usr/lib/libpango-1.0.so.0.2600.0 0054a000-0054e000 r-xp 00000000 08:06 198894 /usr/lib/libXdmcp.so.6.0.0 0054e000-0054f000 rw-p 00003000 08:06 198894 /usr/lib/libXdmcp.so.6.0.0 0054f000-00550000 r-xp 00000000 08:06 230770 /usr/lib/gtk-2.0/2.10.0/loaders/svg_loader.so 00550000-00551000 r--p 00001000 08:06 230770 /usr/lib/gtk-2.0/2.10.0/loaders/svg_loader.so 00551000-00552000 rw-p 00002000 08:06 230770 /usr/lib/gtk-2.0/2.10.0/loaders/svg_loader.so 00552000-00566000 r-xp 00000000 08:06 670607 /lib/libz.so.1.2.3.3 00566000-00567000 r--p 00013000 08:06 670607 /lib/libz.so.1.2.3.3 00567000-00568000 rw-p 00014000 08:06 670607 /lib/libz.so.1.2.3.3 00568000-00581000 r-xp 00000000 08:06 670575 /lib/libselinux.so.1 00581000-00582000 r--p 00018000 08:06 670575 /lib/libselinux.so.1 00582000-00583000 rw-p 00019000 08:06 670575 /lib/libselinux.so.1 00583000-005c7000 r-xp 00000000 08:06 199680 /usr/lib/libpixman-1.so.0.14.0 005c7000-005c9000 r--p 00043000 08:06 199680 /usr/lib/libpixman-1.so.0.14.0 005c9000-005ca000 rw-p 00045000 08:06 199680 /usr/lib/libpixman-1.so.0.14.0 005ca000-005e0000 r-xp 00000000 08:06 199106 /usr/lib/libdirect-1.2.so.0.7.0 Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Mar 22 03:42:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 22 Mar 2010 08:42:07 +0100 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: Lawrence D'Oliveiro, 22.03.2010 00:36: > Terry Reedy wrote: >> No one has discovered a setting >> of the internal tuning parameters for which there are no bad patterns >> and I suspect there are not any such. This does not negate Xavier's >> suggestion that a code change might also solve your problem. > > Could it be that for implementing a structure like a trie as the OP is, > where a lot of CPU cycles can be spent manipulating the structure, a high- > level language like Python, Perl or Ruby just gets in the way? I would rather say that the specific problem of the trie data structure is that it has extremely little benefit over other available data structures. There may still be a couple of niches where it makes sense to consider it as an alternative, but given that dicts are so heavily optimised in Python, it'll be hard for tries to compete even when written in a low-level language. Remember that the original use case was to load a dictionary from a text file. For this use case, a trie can be very wasteful in terms of memory and rather CPU cache unfriendly on traversal, whereas hash values are a) rather fast to calculate for a string, and b) often just calculated once and then kept alive in the string object for later reuse. > My feeling would be, try to get the language to do as much of the work for > you as possible. If you can?t do that, then you might be better off with a > lower-level language. I agree with the first sentence, but I'd like to underline the word 'might' in the second. As this newsgroup shows, very often it's enough to look for a better algorithmic approach first. Stefan From agoretoy at gmail.com Mon Mar 22 04:01:15 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Mar 2010 02:01:15 -0600 Subject: execute bash builtins in python In-Reply-To: References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: for the broken pipe error, perhaps theres a different way I can get shell output other than using subprocess? I need the output of alias command into a string and output of declare command into a string as well, I would like to also avoid creating of a single liner script to make this happen if at all possible Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Mar 22 04:07:49 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Mar 2010 08:07:49 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Sun, 21 Mar 2010 23:09:46 -0600, Zooko O'Whielacronx wrote: > But the use case that I am talking about is where you need to accumulate > new incoming strings into your buffer while alternately processing > leading prefixes of the buffer. [...] > Below are the abbreviated results of the benchmark. You can easily run > this benchmark yourself by following the README.txt in the StringChain > source package [3]. These results show that for the load imposed by this > benchmark StringChain is the only one of the four that scales and that > it is also nice and fast. I was reading this email, and thinking "Why do you need this StringChain data structure, from the description it sounds like a job for collections.deque?" And funnily enough, following the links you supplied I came across this: "You can get the package from http://pypi.python.org/pypi/stringchain or with darcs get http://tahoe-lafs.org/source/stringchain/trunk. It has unit tests. It is in pure Python (it uses collections.deque and string)." http://tahoe-lafs.org/trac/stringchain Perhaps you should have said that it was a wrapper around deque giving richer functionality, rather than giving the impression that it was a brand new data structure invented by you. People are naturally going to be more skeptical about a newly invented data structure than one based on a reliable, component like deque. In any case, it looks to me that the StringChain data structure itself is a little too application specific for me to be personally interested in it. Maybe you should consider linking to it on PyPI and seeing if there is any interest from others? Regards, Steven From agoretoy at gmail.com Mon Mar 22 06:15:29 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Mar 2010 04:15:29 -0600 Subject: execute bash builtins in python In-Reply-To: References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: actually using the -i param in the command to subprocess doesn't seem to work as well as setting PS1 to some garbage, it starts a new interactive shell therein kicking me out of python. :/ Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 22 06:35:21 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Mar 2010 11:35:21 +0100 Subject: Tuples vs. variable-length argument lists In-Reply-To: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> References: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> Message-ID: <4BA747E9.5020009@sequans.com> Spencer Pearson wrote: > Hi! > > This might be more of a personal-preference question than anything, > but here goes: when is it appropriate for a function to take a list or > tuple as input, and when should it allow a varying number of > arguments? It seems as though the two are always interchangeable. For > a simple example... > > def subtract( x, nums ): > return x - sum( nums ) > > ... works equally well if you define it as "subtract( x, *nums )" and > put an asterisk in front of any lists/tuples you pass it. I can't > think of any situation where you couldn't convert from one form to the > other with just a star or a pair of parentheses. > > Is there a generally accepted convention for which method to use? Is > there ever actually a big difference between the two that I'm not > seeing? > FYI some linters report the usage of * as bad practice, I don't know the reason though. Pylint reports it as using 'magic'. Anyway the form without * is commonly used. JM From ldo at geek-central.gen.new_zealand Mon Mar 22 07:00:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Mar 2010 00:00:30 +1300 Subject: What is pkg-config for ? References: Message-ID: In message , Gabriel Genellina wrote: > I fail to see how is this relevant to Python... Well, so many of the questions in this noisegroup seem to be about Windows problems, not Python ones... :) From jeanmichel at sequans.com Mon Mar 22 07:01:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Mar 2010 12:01:00 +0100 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4bc88$0$29961$426a74cc@news.free.fr> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> Message-ID: <4BA74DEC.90006@sequans.com> News123 wrote: > Hi, > > > I wondered about the best way, that a module's function could determine > the existance and value of variables in the __main__ module. > > > What I came up with is: > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": mod.f() > ########### mod.py ########## > def f(): > try: > from __main__ import A > except ImportError as e: > A = "does not exist" > print "__main__.A" ,A > > Is there anything better / more pythonic? > > Thanks in advance and bye > > > N > The 'was I imported from that module' is usually some sign of bad design. I can't detail more wihtout further detail of what you're trying to achieve. Bud since what you have is working, I would'nt bother more than that cause no matter what you try, it will be ugly :o). JM From newton10471 at gmail.com Mon Mar 22 09:26:45 2010 From: newton10471 at gmail.com (newton10471) Date: Mon, 22 Mar 2010 06:26:45 -0700 (PDT) Subject: chroot fails with mount point passed to subprocess.Popen? Message-ID: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Hi, I'm trying to use subprocess.Popen() to do a Linux chroot to a mount point passed in as a parameter to the following function: def getInstalledKernelVersion(mountPoint): linuxFsRoot = mountPoint + "/root" print "type of linuxFsRoot is %s" % type(linuxFsRoot) installedKernelVersionResult = subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) return installedKernelVersionResult and it dies with the following: type of linuxFsRoot is chroot: cannot change root directory to /storage/mounts/ mnt_3786314034939740895.mnt/root: No such file or directory When I explicitly set linuxFsRoot = "/storage/mounts/ mnt_3786314034939740895.mnt/root", it works fine. I also tried this to concatenate the mountpoint + /root, and it failed in the same way: linuxFsRoot = ("%s/root") % mountPoint Anyone know what might be happening here? Thanks in advance, Matt Newton From alfps at start.no Mon Mar 22 09:33:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 22 Mar 2010 14:33:31 +0100 Subject: chroot fails with mount point passed to subprocess.Popen? In-Reply-To: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> References: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Message-ID: * newton10471: > Hi, > > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount > point passed in as a parameter to the following function: > > def getInstalledKernelVersion(mountPoint): > linuxFsRoot = mountPoint + "/root" > print "type of linuxFsRoot is %s" % type(linuxFsRoot) > installedKernelVersionResult = > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) > return installedKernelVersionResult > > and it dies with the following: > > type of linuxFsRoot is > chroot: cannot change root directory to /storage/mounts/ > mnt_3786314034939740895.mnt/root: No such file or directory > > When I explicitly set linuxFsRoot = "/storage/mounts/ > mnt_3786314034939740895.mnt/root", it works fine. > > I also tried this to concatenate the mountpoint + /root, and it failed > in the same way: > > linuxFsRoot = ("%s/root") % mountPoint Use the os.path functions. > Anyone know what might be happening here? Since the computed and literal paths /look/ identical and same type, the only thing I can imagine is that there is some invisible character. Try comparing the computed and literal path character by character. Print the difference or if they're identical, that they are. Possibly you have GIGO problem. Cheers & hth., - Alf From no.email at please.post Mon Mar 22 09:54:27 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 13:54:27 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: In Dennis Lee Bieber writes: >On Sun, 21 Mar 2010 16:57:40 +0000 (UTC), kj >declaimed the following in gmane.comp.python.general: >> Regarding properties, is there a built-in way to memoize them? For >> example, suppose that the value of a property is obtained by parsing >> the contents of a file (specified in another instance attribute). >> It would make no sense to do this parsing more than once. Is there >> a standard idiom for memoizing the value once it is determined for >> the first time? >> > Pickle, Shelve? Maybe in conjunction with SQLite3... I was thinking of something less persistent; in-memory, that is. Maybe something in the spirit of: @property def foo(self): # up for some "adaptive auto-redefinition"? self.foo = self._some_time_consuming_operation() return self.foo ...except that that assignment won't work! It bombs with "AttributeError: can't set attribute". ~K PS: BTW, this is not the first time that attempting to set an attribute (in a class written by me even) blows up on me. It's situations like these that rattle my grasp of attributes, hence my original question about boring, plodding, verbose Java-oid accessors. For me these Python attributes are still waaay too mysterious and unpredictable to rely on. Sometimes one can set them, sometimes not, and I can't quite tell the two situations apart. It's all very confusing to the Noob. (I'm sure this is all documented *somewhere*, but this does not make using attributes any more intuitive or straightforward. I'm also sure that *eventually*, with enough Python experience under one's belt, this all becomes second nature. My point is that Python attributes are not as transparent and natural to the uninitiated as some of you folks seem to think.) From alfps at start.no Mon Mar 22 10:22:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 22 Mar 2010 15:22:02 +0100 Subject: How to automate accessor definition? In-Reply-To: References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: * kj: > In Dennis Lee Bieber writes: > >> On Sun, 21 Mar 2010 16:57:40 +0000 (UTC), kj >> declaimed the following in gmane.comp.python.general: > >>> Regarding properties, is there a built-in way to memoize them? For >>> example, suppose that the value of a property is obtained by parsing >>> the contents of a file (specified in another instance attribute). >>> It would make no sense to do this parsing more than once. Is there >>> a standard idiom for memoizing the value once it is determined for >>> the first time? >>> >> Pickle, Shelve? Maybe in conjunction with SQLite3... > > I was thinking of something less persistent; in-memory, that is. > Maybe something in the spirit of: > > @property > def foo(self): > # up for some "adaptive auto-redefinition"? > self.foo = self._some_time_consuming_operation() > return self.foo > > ...except that that assignment won't work! It bombs with "AttributeError: > can't set attribute". Since foo is a read only property you can assign to it. But it doesn't matter: if it worked technically it wouldn't give you what you're after, the once-only evaluation. A simple way to do that, in the sense of copying code and having it work, is to use a generator that, after evaluating the expensive op, loops forever yielding the resulting value. A probably more efficient way, and anyway one perhaps more easy to understand, is as follows: from __future__ import print_function class LazyEval: def __init__( self, f ): self._f = f self._computed = False @property def value( self ): if not self._computed: self._value = self._f() self._computed = True return self._value class HiHo: def _expensive_op( self ): print( "Expensive op!" ) return 42 def __init__( self ): self._foo = LazyEval( self._expensive_op ) @property def foo( self ): return self._foo.value o = HiHo() for i in range( 5 ): print( o.foo ) Cheers & hth., - Alf From albert at spenarnc.xs4all.nl Mon Mar 22 10:26:10 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Mar 2010 14:26:10 GMT Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: In article <56597268-3472-4fd9-a829-6d9cf51cf093 at e7g2000yqf.googlegroups.com>, Joel Pendery wrote: >So I am trying to write a bit of code and a simple numerical >subtraction > >y_diff = y_diff-H > >is giving me the error > >Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no >encoding declared. > >Even though I have deleted some lines before it and this line is no >longer line 70, I am still getting the error every time. I have tried >to change the encoding of the file to utf-8 but to no avail, I still >am having this issue. Any ideas? Make a hex-dump of your file. How does line 70 look? If you see 0900 66 66 96 48 0A -- ff.H. you know you are doing something illegal. > >Thanks in advance Groetjes Albert P.S. With all due respect, error messages come not any clearer than that! -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From no.email at please.post Mon Mar 22 10:45:22 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 14:45:22 +0000 (UTC) Subject: short-circuiting any/all ? Message-ID: I have a list of items L, and a test function is_invalid that checks the validity of each item. To check that there are no invalid items in L, I could check the value of any(map(is_invalid, L)). But this approach is suboptimal in the sense that, no matter what L is, is_invalid will be executed for all elements of L, even though the value returned by any() is fully determined by the first True in its argument. In other words, all calls to is_invalid after the first one to return True are superfluous. Is there a short-circuiting counterpart to any(map(is_invalid, L)) that avoids these superfluous calls? OK, there's this one, of course: def _any_invalid(L): for i in L: if is_invalid(i): return True return False But is there anything built-in? (I imagine that a lazy version of map *may* do the trick, *if* any() will let it be lazy.) TIA! ~K From john at castleamber.com Mon Mar 22 10:47:09 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Mar 2010 08:47:09 -0600 Subject: add an entry to twentyquestions.org (please) References: <73490ec3-5d3f-417a-b0fc-c697cd0fb08a@30g2000yqi.googlegroups.com> <8739ztt9gg.fsf@benfinney.id.au> Message-ID: <87bpeg8lci.fsf@castleamber.com> Ben Finney writes: > twenty questions writes: > >> add an entry to http:// > > Don't spam groups with your off-topic begging for a closed database silo > (please) Don't repeat spam -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mail at timgolden.me.uk Mon Mar 22 10:57:38 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Mar 2010 14:57:38 +0000 Subject: short-circuiting any/all ? In-Reply-To: References: Message-ID: <4BA78562.3070802@timgolden.me.uk> On 22/03/2010 14:45, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. In other words, all calls to is_invalid after > the first one to return True are superfluous. Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > for i in L: > if is_invalid(i): > return True > return False > > But is there anything built-in? (I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) Have I missed the point of your question, perhaps? This seems to work as lazily as you'd like... def less_than_five (x): print "testing", x return x < 5 L = range (10) print any (less_than_five (i) for i in L) print all (less_than_five (i) for i in L) # for symmetry TJG From jeanmichel at sequans.com Mon Mar 22 11:08:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Mar 2010 16:08:49 +0100 Subject: short-circuiting any/all ? In-Reply-To: References: Message-ID: <4BA78801.3040605@sequans.com> kj wrote: > > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. In other words, all calls to is_invalid after > the first one to return True are superfluous. Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > for i in L: > if is_invalid(i): > return True > return False > > But is there anything built-in? (I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) > > TIA! > > ~K > Sounds like unnecessary optimization. Just write def _any_valid(L): return bool([i for i in L if is_valid(i)]) If you really care about speed, meaning if the user experiences some execution duration increase, then the solution you proposed is fine. JM From tim.wintle at teamrubber.com Mon Mar 22 11:12:52 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 22 Mar 2010 15:12:52 +0000 Subject: short-circuiting any/all ? In-Reply-To: References: Message-ID: <1269270772.2407.1.camel@localhost> On Mon, 2010-03-22 at 14:45 +0000, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, any( is_invalid(a) for a in L ) ... generator expression will be lazily computed. Tim From pruebauno at latinmail.com Mon Mar 22 11:17:03 2010 From: pruebauno at latinmail.com (nn) Date: Mon, 22 Mar 2010 08:17:03 -0700 (PDT) Subject: short-circuiting any/all ? References: Message-ID: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. In other words, all calls to is_invalid after > the first one to return True are superfluous. Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > for i in L: > if is_invalid(i): > return True > return False > > But is there anything built-in? (I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) > > TIA! > > ~K If you are in Python 3 "any(map(is_invalid, L))" should short circuit. If you are in Python 2 use "from itertools import imap; any(imap(is_invalid, L))" From robert.kern at gmail.com Mon Mar 22 11:22:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 22 Mar 2010 10:22:29 -0500 Subject: nonuniform sampling with replacement In-Reply-To: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: On 2010-03-21 05:11 AM, Jah_Alarm wrote: > I've got a vector length n of integers (some of them are repeating), I recommend reducing it down to unique integers first. > and I got a selection probability vector of the same length. How will > I sample with replacement k (<=n) values with the probabilty vector. > In Matlab this function is randsample. I couldn't find anything to > this extent in Scipy or Numpy. In [19]: from scipy.stats import rv_discrete In [20]: p = rv_discrete(name='adhoc', values=([0, 1, 2], [0.5, 0.25, 0.25])) In [21]: p.rvs(size=100) Out[21]: array([0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 2, 2, 2, 1, 0, 0, 2, 0, 0, 1, 0, 0, 2, 2, 0, 1, 2, 1, 0, 0, 2, 1, 1, 1, 1, 1, 2, 1, 2, 0, 2, 0, 2, 0, 0, 2, 0, 1, 0, 2, 2, 1, 0, 0, 1, 0, 2, 1, 0, 0, 1, 0, 2, 1, 2, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 2, 0, 1, 2, 1, 1, 0, 0, 0, 1, 0]) -- 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 From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 22 11:44:01 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Mar 2010 16:44:01 +0100 Subject: How to automate accessor definition? In-Reply-To: References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: <4ba79040$0$22397$426a74cc@news.free.fr> kj a ?crit : > In Dennis Lee Bieber writes: > >> On Sun, 21 Mar 2010 16:57:40 +0000 (UTC), kj >> declaimed the following in gmane.comp.python.general: > >>> Regarding properties, is there a built-in way to memoize them? For >>> example, suppose that the value of a property is obtained by parsing >>> the contents of a file (specified in another instance attribute). >>> It would make no sense to do this parsing more than once. Is there >>> a standard idiom for memoizing the value once it is determined for >>> the first time? >>> >> Pickle, Shelve? Maybe in conjunction with SQLite3... > > I was thinking of something less persistent; in-memory, that is. > Maybe something in the spirit of: > > @property > def foo(self): > # up for some "adaptive auto-redefinition"? > self.foo = self._some_time_consuming_operation() > return self.foo > > ...except that that assignment won't work! It bombs with "AttributeError: > can't set attribute". > > ~K > > PS: BTW, this is not the first time that attempting to set an > attribute (in a class written by me even) blows up on me. It's > situations like these that rattle my grasp of attributes, hence my > original question about boring, plodding, verbose Java-oid accessors. > For me these Python attributes are still waaay too mysterious and > unpredictable to rely on. Somehow simplified, here's what you have to know: 1/ there are instance attributes and class attributes. Instance attributes lives in the instance's __dict__, class attributes lives in the class's __dict__ or in a parent's class __dict__. 2/ when looking up an attribute on an instance, the rules are * first, check if there's a key by that name in the instance's __dict__. If yes, return the associated value * else, check if there's a class or parent class attribute by that name. * if yes ** if the attribute has a '__get__' method, call the __get__ method with class and instance as arguments, and return the result (this is known as the "descriptor protocol" and provides support for computed attributes (including methods and properties) ** else return the attribute itself * else (if nothing has been found yet), look for a __getattr__ method in the class and it's parents. If found, call this __getattr__ method with the attribute name and return the result * else, give up and raise an AttributeError 3/ When binding an attribute on an instance, the rules are: * first, check if there's a class (or parent class) attribute by that name that has a '__set__' method. If yes, call this class attribute's __set__ method with instance and value as arguments. This is the second part part of the "descriptor protocol", as used by the property type. * else, add the attribute's name and value in the instance's __dict__ As I said, this is a somehow simplified description of the process - I skipped the parts about __slots__, __getattribute__ and __setattr__, as well as the part about how function class attributes become methods. But this should be enough to get an idea of what's going on. In your above case, you defined a "foo" property class attribute. The property type implements both __get__ and __set__, but you only defined a callback for the __get__ method (the function you decorated with 'property'), so when you try to rebind "foo", the default property type's __set__ implementation is invoked, which behaviour is to forbid setting the attribute. If you want a settable property, you have to provide a setter too. Now if you want a "replaceable" property-like attribute, you could define your own computed attribute (aka "descriptor") type _without_ a __set__ method: class replaceableprop(object): def __init__(self, fget): self._fget = fget def __get__(self, instance, cls): if instance is None: return self return self._fget(instance) @replaceableprop def foo(self): # will add 'foo' into self.__dict__, s self.foo = self._some_time_consuming_operation() return self.foo Another (better IMHO) solution is to use a plain property, and store the computed value as an implementation attribute : @property def foo(self): cached = self.__dict__.get('_foo_cache') if cached is None: self._foo_cache = cached = self._some_time_consuming_operation() return cached > Sometimes one can set them, sometimes > not, and I can't quite tell the two situations apart. It's all > very confusing to the Noob. (I'm sure this is all documented > *somewhere*, but this does not make using attributes any more > intuitive or straightforward. I'm also sure that *eventually*, > with enough Python experience under one's belt, this all becomes > second nature. My point is that Python attributes are not as > transparent and natural to the uninitiated as some of you folks > seem to think.) I agree that the introduction of the descriptor protocol added some more complexity to an already somehow unusual model object. HTH. From jjposner at optimum.net Mon Mar 22 13:36:34 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 22 Mar 2010 13:36:34 -0400 Subject: How to automate accessor definition? In-Reply-To: <4ba79040$0$22397$426a74cc@news.free.fr> References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba79040$0$22397$426a74cc@news.free.fr> Message-ID: <4ba7aa87$0$4974$607ed4bc@cv.net> On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote: > Another (better IMHO) solution is to use a plain property, and store the > computed value as an implementation attribute : > > @property > def foo(self): > cached = self.__dict__.get('_foo_cache') > if cached is None: > self._foo_cache = cached = self._some_time_consuming_operation() > return cached > There's no need to access __dict__ directly. I believe this is equivalent (and clearer): @property def foo(self): try: cached = self._foo_cache except AttributeError: self._foo_cache = cached = self._time_consuming_op() return cached -John From luismgz at gmail.com Mon Mar 22 13:59:07 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Mon, 22 Mar 2010 10:59:07 -0700 (PDT) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <15025fc0-c697-4085-81a0-160882767540@15g2000yqi.googlegroups.com> On Feb 21, 6:40?pm, Mensanator wrote: > On Feb 21, 12:14?pm, Paul Boddie wrote: > > > > > > > On 21 Feb, 17:32, Mensanator wrote: > > > > On Feb 21, 10:30 am, Mensanator wrote: > > > > > What versions of Python does it suuport? > > > > What OS are supported? > > > From the Web site referenced in the announcement (http:// > > dreampie.sourceforge.net/): > > > """ > > # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and > > Python 3.1. > > # Works on Windows and Linux. > > """ > > Yeah, I saw that. Funny that something important like that wasn't part > of the > announcement. I notice no mention of Mac OS, so visiting the website > was a complete > waste of time on my part, wasn't it? > > > > > Paul Geez... someone spends many hours (or days or even months) writing a program to be offered for free to the world, and you get annoyed by losing two seconds while checking it out? From chambon.pascal at wanadoo.fr Mon Mar 22 14:20:39 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Mon, 22 Mar 2010 19:20:39 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> Message-ID: <4BA7B4F7.6080404@wanadoo.fr> Gabriel Genellina a ?crit : > > En Wed, 17 Mar 2010 09:42:06 -0300, Pascal Chambon > escribi?: > >> traceback functions indeed allow the manipulation of exception >> tracebacks, >> but the root problem is that anyway, since that traceback is incomplete, >> your "traceback.format_exc().splitlines()" will only provide frames for >> callee (downward) functions, not caller (upward) ones, starting from the >> exception catching frame. > > Either I don't understand what you mean, or I can't reproduce it: > > Allright, here is more concretely the problem : import logging def a(): return b() def b(): return c() def c(): try: return d() except: logging.exception("An error") def d(): raise ValueError def main(): logging.basicConfig(level=logging.DEBUG) a() main() OUTPUT: >>> ERROR:root:An error Traceback (most recent call last): File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c return d() File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d def d(): raise ValueError ValueError >>> As you see, the traceback only starts from function c, which handles the exception. It doesn't show main(), a() and b(), which might however be (and are, in my case) critical to diagnose the severity of the problem (since many different paths would lead to calling c()). So the question is : is that possible to enforce, by a way or another, the retrieval of the FULL traceback at exception raising point, instead of that incomplete one ? Thank you for your help, regards, Pascal From python at rcn.com Mon Mar 22 14:27:57 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 22 Mar 2010 11:27:57 -0700 (PDT) Subject: short-circuiting any/all ? References: Message-ID: On Mar 22, 7:45?am, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. ?To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. ?In other words, all calls to is_invalid after > the first one to return True are superfluous. ?Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > ? ? for i in L: > ? ? ? ? if is_invalid(i): > ? ? ? ? ? ? return True > ? ? return False ? > > But is there anything built-in? ?(I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) Yes, that will work: from itertools import imap # lazy version of map any(imap(is_invalid, L) # short-circuits on first True Yet another approach (slightly faster): from itertools import ifilter any(ifilter(is_invalid, L)) Raymond From no.email at please.post Mon Mar 22 14:30:34 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 18:30:34 +0000 (UTC) Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: In <291d82b7-b13b-4f49-901c-8194f3e07598 at e7g2000yqf.googlegroups.com> nn writes: >If you are in Python 3 "any(map(is_invalid, L))" should short circuit. >If you are in Python 2 use "from itertools import imap; >any(imap(is_invalid, L))" Thanks! I'm glad to know that one can get the short circuiting using a map-type idiom. (I prefer map over comprehensions when I don't need to define a function just for the purpose of passing it to it.) And thanks also to the other repliers for pointing out that the comprehension version does what I was asking for. ~K From mail at timgolden.me.uk Mon Mar 22 14:43:07 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Mar 2010 18:43:07 +0000 Subject: short-circuiting any/all ? In-Reply-To: References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: <4BA7BA3B.2000006@timgolden.me.uk> On 22/03/2010 18:30, kj wrote: > Thanks! I'm glad to know that one can get the short circuiting > using a map-type idiom. (I prefer map over comprehensions when I > don't need to define a function just for the purpose of passing it > to it.) In what way does "map" over "comprehensions" save you defining a function? any (map (is_invalid, L)) any (is_invalid (i) for i in L) TJG From krister.svanlund at gmail.com Mon Mar 22 17:19:49 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 22 Mar 2010 22:19:49 +0100 Subject: Problem with sys.path when embedding Python3 in C Message-ID: <2cf430a61003221419t2192c9aajd3c2d2922b1d7f12@mail.gmail.com> Hi, I've recently begun experimenting with embedding python and i got a small problem. This is my current testing code (basically all from python docs): > int main(int argc, char *argv[]) > > { > > PyObject *pModuleName, *pTestModule, *pTestFunc, *pTestResult, *pTestArgs; > > PyImport_AppendInittab("node", &PyInit_node); > > Py_Initialize(); The following line here is the ugly-hack I had to do to make it work, nothing else I know of makes it possible to import modules from startup directory. So my question is: Is there a prettier way to do this? > PyRun_SimpleString("import sys\nsys.path.append(\"\")"); > > PyRun_SimpleString("import sys\nprint(sys.path)"); > > pModuleName = PyUnicode_FromString("stuff"); > > pTestModule = PyImport_Import(pModuleName); > > Py_DECREF(pModuleName); > > if (pTestModule != NULL) > > { ... The whole code is here: http://pastebin.com/805BSY8f You only need a file in the same directory called stuff.py containing a function def for a function called do_stuff From zookog at gmail.com Mon Mar 22 17:19:49 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Mon, 22 Mar 2010 15:19:49 -0600 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: My apologies; I left out the heading on the last of the four structures in the benchmark results. Here are those results again with the missing heading (Stringy) inserted: Regards, Zooko - Hide quoted text - On Sun, Mar 21, 2010 at 11:09 PM, Zooko O'Whielacronx wrote: > > impl: StringChain > task: _accumulate_then_one_gulp > 10000 best: 2.694e+00 > 50000 best: 2.742e+00 > 100000 best: 2.310e+00 > 500000 best: 2.040e+00 > 1000000 best: 1.988e+00 > 5000000 best: 2.193e+00 > > task: _alternate_str > 10000 best: 6.509e+00 > 50000 best: 4.559e+00 > 100000 best: 4.308e+00 > 500000 best: 4.070e+00 > 1000000 best: 3.991e+00 > 5000000 best: 4.000e+00 > > impl: SimplerStringChain > task: _accumulate_then_one_gulp > 10000 best: 1.407e+00 > 50000 best: 2.317e+00 > 100000 best: 2.012e+00 > 500000 best: 1.902e+00 > 1000000 best: 1.897e+00 > 5000000 best: 2.104e+00 > > task: _alternate_str > 10000 best: 4.888e+00 > 50000 best: 5.198e+00 > 100000 best: 1.750e+01 > 500000 best: 6.233e+01 > 1000000 best: 1.134e+02 > 5000000 best: 7.599e+02 > > impl: StringIOy > task: _accumulate_then_one_gulp > 10000 best: 4.196e+00 > 50000 best: 5.522e+00 > 100000 best: 4.499e+00 > 500000 best: 3.756e+00 > 1000000 best: 4.176e+00 > 5000000 best: 5.414e+00 > > task: _alternate_str > 10000 best: 5.484e+00 > 50000 best: 7.863e+00 > 100000 best: 2.126e+01 > 500000 best: 6.972e+01 > 1000000 best: 1.219e+02 > 5000000 best: 9.463e+02 > impl: Stringy - Hide quoted text - > task: _accumulate_then_one_gulp > 10000 best: 1.502e+00 > 50000 best: 1.420e+01 > 100000 best: 2.245e+01 > 500000 best: 8.577e+01 > 1000000 best: 2.295e+02 > 5000000 best: 1.326e+03 > > task: _alternate_str > 10000 best: 3.290e+00 > 50000 best: 4.220e+00 > 100000 best: 1.665e+01 > 500000 best: 6.281e+01 > 1000000 best: 1.127e+02 > 5000000 best: 7.626e+02 > From zookog at gmail.com Mon Mar 22 17:21:53 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Mon, 22 Mar 2010 15:21:53 -0600 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Mon, Mar 22, 2010 at 2:07 AM, Steven D'Aprano wrote: > > Perhaps you should have said that it was a wrapper around deque giving > richer functionality, rather than giving the impression that it was a > brand new data structure invented by you. People are naturally going to > be more skeptical about a newly invented data structure than one based on > a reliable, component like deque. The fact that StringChain uses deque to hold the queue of strings isn't that important. I just benchmarked it by swapping in the deque for a list and using the list costs about one third of a nanosecond per byte at the scales that the benchmark exercises (namely 10,000,000 bytes in about 10,000 strings). A third of a nanosecond per byte is about 4% of the runtime. I also implemented and benchmarked a simpler deque-based scheme which puts all the actual bytes from the strings into a deque with self.d.extend(newstr). As you would expect, this shows good asymptotic performance but the constants are relatively bad so that at all of the actual loads measured it was three orders of magnitude worse than StringChain and than String-Chain-with-a-list-instead-of-a-deque. Moral: the constants matter! Those benchmarks are appended. You can run the benchmarks yourself per the README.txt. But anyway, I take your point and I updated the StringChain README to explain that it is a pretty simple data structure that holds a list (actually a deque) of strings and isn't anything too clever or novel. By the way, we could further micro-optimize this kind of thing if ''.join() would accept either strings or buffers instead of requiring strings: >>> ''.join([buffer("abc"), "def"]) Traceback (most recent call last): File "", line 1, in TypeError: sequence item 0: expected string, buffer found Then whenever StringChain needs to slice a string into leading and trailing parts, it could construct a buffer() viewing each part instead of making a copy of each part. > it. Maybe you should consider linking to it on PyPI and seeing if there > is any interest from others? http://pypi.python.org/pypi/stringchain Regards, Zooko impl: StringChain task: _accumulate_then_one_gulp 10000 best: 5.698e+00, 3th-best: 7.486e+00, mean: 7.758e+00, 100000 best: 4.640e+00, 3th-best: 4.690e+00, mean: 7.674e+00, 1000000 best: 3.789e+00, 3th-best: 3.806e+00, mean: 3.995e+00, 10000000 best: 4.095e+00, 1th-best: 4.095e+00, mean: 4.095e+00, task: _alternate_str 10000 best: 1.378e+01, 3th-best: 1.390e+01, mean: 1.500e+01, 100000 best: 9.198e+00, 3th-best: 9.248e+00, mean: 9.385e+00, 1000000 best: 8.715e+00, 3th-best: 8.755e+00, mean: 8.808e+00, 10000000 best: 8.738e+00, 1th-best: 8.738e+00, mean: 8.738e+00, impl: StringChainWithList task: _accumulate_then_one_gulp 10000 best: 3.600e+00, 3th-best: 3.695e+00, mean: 4.129e+00, 100000 best: 4.070e+00, 3th-best: 4.079e+00, mean: 4.162e+00, 1000000 best: 3.662e+00, 3th-best: 3.688e+00, mean: 3.721e+00, 10000000 best: 3.902e+00, 1th-best: 3.902e+00, mean: 3.902e+00, 1th-worst: 3.902e+00, worst: 3.902e+00 (of 1) task: _alternate_str 10000 best: 1.369e+01, 3th-best: 1.380e+01, mean: 1.442e+01, 100000 best: 9.251e+00, 3th-best: 9.289e+00, mean: 9.416e+00, 1000000 best: 8.809e+00, 3th-best: 8.876e+00, mean: 8.943e+00, 10000000 best: 9.095e+00, 1th-best: 9.095e+00, mean: 9.095e+00, impl: Dequey task: _accumulate_then_one_gulp 10000 best: 2.772e+02, 3th-best: 2.785e+02, mean: 2.911e+02, 100000 best: 2.314e+02, 3th-best: 2.334e+02, mean: 2.422e+02, 1000000 best: 2.282e+02, 3th-best: 2.288e+02, mean: 2.370e+02, 10000000 best: 2.587e+02, 1th-best: 2.587e+02, mean: 2.587e+02, task: _alternate_str 10000 best: 1.576e+03, 3th-best: 1.580e+03, mean: 1.608e+03, 100000 best: 1.301e+03, 3th-best: 1.303e+03, mean: 1.306e+03, 1000000 best: 1.275e+03, 3th-best: 1.276e+03, mean: 1.278e+03, 10000000 best: 1.280e+03, 1th-best: 1.280e+03, mean: 1.280e+03, From no.email at please.post Mon Mar 22 18:16:09 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 22:16:09 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba79040$0$22397$426a74cc@news.free.fr> Message-ID: In <4ba79040$0$22397$426a74cc at news.free.fr> Bruno Desthuilliers writes: >kj a ?crit : >> PS: BTW, this is not the first time that attempting to set an >> attribute (in a class written by me even) blows up on me. It's >> situations like these that rattle my grasp of attributes, hence my >> original question about boring, plodding, verbose Java-oid accessors. >> For me these Python attributes are still waaay too mysterious and >> unpredictable to rely on. >Somehow simplified, here's what you have to know: ... >As I said, this is a somehow simplified description of the process - I >skipped the parts about __slots__, __getattribute__ and __setattr__, as >well as the part about how function class attributes become methods. >this should be enough to get an idea of what's going on. Thank you, sir! That was quite the education. (Someday I really should read carefully the official documentation for the stuff you described, assuming it exists.) Thanks also for your code suggestions. ~K From no.email at please.post Mon Mar 22 18:19:57 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 22:19:57 +0000 (UTC) Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: In Tim Golden writes: >On 22/03/2010 18:30, kj wrote: >> Thanks! I'm glad to know that one can get the short circuiting >> using a map-type idiom. (I prefer map over comprehensions when I >> don't need to define a function just for the purpose of passing it >> to it.) >In what way does "map" over "comprehensions" save you defining a function? >any (map (is_invalid, L)) >any (is_invalid (i) for i in L) I was talking in the *general* case. map at the very least requires a lambda expression, which is a one-time function defintion. ~K From steve at holdenweb.com Mon Mar 22 19:17:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Mar 2010 19:17:00 -0400 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <15025fc0-c697-4085-81a0-160882767540@15g2000yqi.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <15025fc0-c697-4085-81a0-160882767540@15g2000yqi.googlegroups.com> Message-ID: Luis M. Gonz?lez wrote: > On Feb 21, 6:40 pm, Mensanator wrote: >> On Feb 21, 12:14 pm, Paul Boddie wrote: >> >> >> >> >> >>> On 21 Feb, 17:32, Mensanator wrote: >>>> On Feb 21, 10:30 am, Mensanator wrote: >>>>> What versions of Python does it suuport? >>>> What OS are supported? >>> From the Web site referenced in the announcement (http:// >>> dreampie.sourceforge.net/): >>> """ >>> # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and >>> Python 3.1. >>> # Works on Windows and Linux. >>> """ >> Yeah, I saw that. Funny that something important like that wasn't part >> of the >> announcement. I notice no mention of Mac OS, so visiting the website >> was a complete >> waste of time on my part, wasn't it? >> >> >> >>> Paul > > Geez... someone spends many hours (or days or even months) writing a > program to be offered for free to the world, and you get annoyed by > losing two seconds while checking it out? And if it's open source there's always the possibility of doing a Mac port and contributing the code back. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tan at nowhere.land Mon Mar 22 19:40:16 2010 From: tan at nowhere.land (tan) Date: Mon, 22 Mar 2010 23:40:16 GMT Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: In article , Stefan Behnel wrote: >Lawrence D'Oliveiro, 22.03.2010 00:36: >> Terry Reedy wrote: >>> No one has discovered a setting >>> of the internal tuning parameters for which there are no bad patterns >>> and I suspect there are not any such. This does not negate Xavier's >>> suggestion that a code change might also solve your problem. >> >> Could it be that for implementing a structure like a trie as the OP is, >> where a lot of CPU cycles can be spent manipulating the structure, a high- >> level language like Python, Perl or Ruby just gets in the way? > >I would rather say that the specific problem of the trie data structure is >that it has extremely little benefit over other available data structures. Not true. >There may still be a couple of niches where it makes sense to consider it >as an alternative, but given that dicts are so heavily optimised in Python, >it'll be hard for tries to compete even when written in a low-level language. It depends. If your data is not in nearly sorted order, trees are some of the best mechanisms available. >Remember that the original use case was to load a dictionary from a text >file. For this use case, a trie can be very wasteful in terms of memory and >rather CPU cache unfriendly on traversal, whereas hash values are a) rather >fast to calculate for a string, and b) often just calculated once and then >kept alive in the string object for later reuse. You still have to walk the bucket in a hash map/table. Performance may be orders of magnitude worse than for trees. >> My feeling would be, try to get the language to do as much of the work for >> you as possible. If you can???t do that, then you might be better off with a >> lower-level language. > >I agree with the first sentence, but I'd like to underline the word 'might' >in the second. As this newsgroup shows, very often it's enough to look for >a better algorithmic approach first. > >Stefan > -- You want to know who you are? http://oshosearch.net/Convert/search.php Most Osho books on line: http://oshosearch.net From vlastimil.brom at gmail.com Mon Mar 22 20:19:04 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 23 Mar 2010 01:19:04 +0100 Subject: individually updating unicodedata db? Message-ID: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Hi all, I just tried to find some information about the unicodedata database and the possibilities of updating it to the latest version of the unicode standards (currently 5.2, while python supports 5.1 in the latest versions). An option to update this database individually might be useful as the unicode standard updates seem to be more frequent than the official python releases (and not every release is updated to the latest available unicode db version either). Am I right, that this is not possible without recompiling python from source? I eventually found the promissing file ...Python-src--2.6.5\Python-2.6.5\Tools\unicode\makeunicodedata.py which required the following files from the unicode database to be in the same folder: EastAsianWidth-3.2.0.txt UnicodeData-3.2.0.txt CompositionExclusions-3.2.0.txt UnicodeData.txt EastAsianWidth.txt CompositionExclusions.txt and also Modules/unicodedata_db.h Modules/unicodename_db.h, Objects/unicodetype_db.h After a minor correction - addig the missing "import re" - the script was able to run and recreate the above h files. I guess, I am stuck here, as I use the precompiled version supplied in the windows installer and can't compile python from source to obtain the needed unicodedata.pyd. Or are there any possibilities I missed to individually upgrade the unicodedata databese? (Using Python 2.6.5, Win XPh SP3) Thanks in advance for any hints, vbr From hawat.thufir at gmail.com Mon Mar 22 20:23:27 2010 From: hawat.thufir at gmail.com (Thufir) Date: Mon, 22 Mar 2010 17:23:27 -0700 (PDT) Subject: google token References: <4ba49f98$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4f5d2017-8d64-4d4c-b013-b49b4c199005@v20g2000prc.googlegroups.com> On Mar 20, 3:12 am, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 09:17:14 +0000, Thufir wrote: > > I'd like to acquire a token, as below, but from Java: > > Perhaps you should be asking a Java discussion group? This group is for > discussing Python. > > -- > Steven What I meant to ask is, how is that token being acquired? Is that just a GET? thanks, Thufir From python at mrabarnett.plus.com Mon Mar 22 21:27:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Mar 2010 01:27:28 +0000 Subject: individually updating unicodedata db? In-Reply-To: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> References: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Message-ID: <4BA81900.6000505@mrabarnett.plus.com> Vlastimil Brom wrote: > Hi all, > I just tried to find some information about the unicodedata database > and the possibilities of updating it to the latest version of the > unicode standards (currently 5.2, while python supports 5.1 in the > latest versions). > An option to update this database individually might be useful as the > unicode standard updates seem to be more frequent than the official > python releases (and not every release is updated to the latest > available unicode db version either). > Am I right, that this is not possible without recompiling python from source? > I eventually found the promissing file > ...Python-src--2.6.5\Python-2.6.5\Tools\unicode\makeunicodedata.py > which required the following files from the unicode database to be in > the same folder: > EastAsianWidth-3.2.0.txt > UnicodeData-3.2.0.txt > CompositionExclusions-3.2.0.txt > UnicodeData.txt > EastAsianWidth.txt > CompositionExclusions.txt > > and also > Modules/unicodedata_db.h > Modules/unicodename_db.h, > Objects/unicodetype_db.h > > After a minor correction - addig the missing "import re" - the script > was able to run and recreate the above h files. > I guess, I am stuck here, as I use the precompiled version supplied in > the windows installer and can't compile python from source to obtain > the needed unicodedata.pyd. > Or are there any possibilities I missed to individually upgrade the > unicodedata databese? (Using Python 2.6.5, Win XPh SP3) > > Thanks in advance for any hints, > vbr From the look of it the Unicode data is compiled into the DLL, but I don't see any reason, other than speed, why preprocessed data couldn't be read from a file at startup by the DLL, provided that the format hasn't changed, eg new fields added, without affecting the DLL's interface to the rest of Python. From steven at REMOVE.THIS.cybersource.com.au Mon Mar 22 21:30:37 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Mar 2010 01:30:37 GMT Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: On Mon, 22 Mar 2010 22:19:57 +0000, kj wrote: > In Tim Golden > writes: > >>On 22/03/2010 18:30, kj wrote: >>> Thanks! I'm glad to know that one can get the short circuiting using >>> a map-type idiom. (I prefer map over comprehensions when I don't need >>> to define a function just for the purpose of passing it to it.) > >>In what way does "map" over "comprehensions" save you defining a >>function? > >>any (map (is_invalid, L)) >>any (is_invalid (i) for i in L) > > I was talking in the *general* case. map at the very least requires a > lambda expression, which is a one-time function defintion. But keep in mind that instead of this: map(lambda x,y: x+y, somelist) you can do this: import operator map(operator.add, somelist) In any case, the once-off cost of creating or importing a function is usually quite cheap. As usual, the best advise is not to worry about optimization until you have profiled the code and learned where the actual bottlenecks are. Write what reads best, not what you guess might be faster, until you really know you need the speed and that it is an optimization and not a pessimation. -- Steven From solipsis at pitrou.net Mon Mar 22 22:11:57 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 23 Mar 2010 02:11:57 +0000 (UTC) Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: Le Mon, 22 Mar 2010 23:40:16 +0000, tan a ?crit?: > >>Remember that the original use case was to load a dictionary from a text >>file. For this use case, a trie can be very wasteful in terms of memory >>and rather CPU cache unfriendly on traversal, whereas hash values are a) >>rather fast to calculate for a string, and b) often just calculated once >>and then kept alive in the string object for later reuse. > > You still have to walk the bucket in a hash map/table. Performance may > be orders of magnitude worse than for trees. "walk the bucket" shouldn't be a significant cost factor here, especially if you are doing meaningful work with the traversed items. In the CPython implementation the total hash table size is less than a constant times the number of actual items. Moreover, it's a linear scan over an array rather than having to dereference pointers as in tree. "Orders of magnitude worse", in any case, sounds very exaggerated. (and, of course, as the OP said, there's the major difference that the dict type is implemented in C, which makes constant factors an order of magnitude smaller than for a Python trie implementation) From no.email at please.post Mon Mar 22 22:26:20 2010 From: no.email at please.post (kj) Date: Tue, 23 Mar 2010 02:26:20 +0000 (UTC) Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: In Steven D'Aprano writes: >On Mon, 22 Mar 2010 22:19:57 +0000, kj wrote: >In any case, the once-off cost of creating or importing a function is >usually quite cheap. As usual, the best advise is not to worry about >optimization until you have profiled the code and learned where the >actual bottlenecks are. Write what reads best, not what you guess might >be faster, until you really know you need the speed and that it is an >optimization and not a pessimation. My preference for map in this case is not due to performance considerations, but to avoid unnecessary code-clutter. I just find, e.g., x = map(int, y) slightly easier on the eyes than x = [int(z) for z in y] This tiny improvement in readability gets negated if one needs to define a function in order to use map. Hence, e.g., I prefer x = [_[0] for _ in y] over x = map(lambda _: _[0], y) and certainly over def _first(seq): return seq[0] x = map(_first, y) Arguably, Knuth's "premature optimization is the root of all evil" applies even to readability (e.g. "what's the point of making code optimally readable if one is going to change it completely next day?") If there were the equivalent of a profiler for code clutter, I guess I could relax my readability standards a bit... ~K From rami.chowdhury at gmail.com Mon Mar 22 22:59:18 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 22 Mar 2010 19:59:18 -0700 Subject: google token In-Reply-To: <4f5d2017-8d64-4d4c-b013-b49b4c199005@v20g2000prc.googlegroups.com> References: <4ba49f98$0$27838$c3e8da3@news.astraweb.com> <4f5d2017-8d64-4d4c-b013-b49b4c199005@v20g2000prc.googlegroups.com> Message-ID: <201003221959.19307.rami.chowdhury@gmail.com> On Monday 22 March 2010 17:23:27 Thufir wrote: > On Mar 20, 3:12 am, Steven D'Aprano > cybersource.com.au> wrote: > > On Sat, 20 Mar 2010 09:17:14 +0000, Thufir wrote: > > > I'd like to acquire a token, as below, but from Java: > > Perhaps you should be asking a Java discussion group? This group is for > > discussing Python. > > > > -- > > Steven > > What I meant to ask is, how is that token being acquired? Is that > just a GET? > Looks like it -- a urllib2 request, anyway -- the self._web object is defined here: http://pyrfeed.googlecode.com/svn/trunk/lib/web/web.py > > > thanks, > > Thufir ---- Rami Chowdhury "Any sufficiently advanced incompetence is indistinguishable from malice." -- Grey's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From timr at probo.com Tue Mar 23 00:22:28 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Mar 2010 21:22:28 -0700 Subject: device identification References: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> Message-ID: <46ggq59e49qpna7f9ae6q8ftobhot351un@4ax.com> Omer Ihsan wrote: > >i have installed pyusb now and run the sample usbenum.py....i have 3 >usb ports on my PC but the results show 6 outputs to >dev.filename..they are numbers like 001 or 005 etc.... and they >changed when i plugged in devices...(i am no good with the usb >standards)....i just want to identify each device/port... what >parameter in the example would help me.... You can't identify the ports.[1] What good would it do you? The ports on your PC are not numbered. You certainly CAN identify the devices, by their VID and PID (or idVendor and idProduct). You identify by function, not by location. When you plug in a USB drive, you don't want to worry about where it's plugged in. === [1]: OK, technically, it is not impossible to identify the port numbers, but it is quite tedious. You need to chase through the sysfs expansion of your buses hub/port tree and find a match for your device. It's not worth the trouble. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From no.email at nospam.invalid Tue Mar 23 01:05:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Mar 2010 22:05:40 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Antoine Pitrou writes: > "Orders of magnitude worse", in any case, sounds very exaggerated. The worst case can lose orders of magnitude if a lot of values hash to the same bucket. From gagsl-py2 at yahoo.com.ar Tue Mar 23 02:12:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Mar 2010 03:12:54 -0300 Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> Message-ID: En Mon, 22 Mar 2010 15:20:39 -0300, Pascal Chambon escribi?: > > Allright, here is more concretely the problem : > > ERROR:root:An error > Traceback (most recent call last): > File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c > return d() > File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d > def d(): raise ValueError > ValueError > >>> > > As you see, the traceback only starts from function c, which handles the > exception. > It doesn't show main(), a() and b(), which might however be (and are, in > my case) critical to diagnose the severity of the problem (since many > different paths would lead to calling c()). > > So the question is : is that possible to enforce, by a way or another, > the retrieval of the FULL traceback at exception raising point, instead > of that incomplete one ? Thanks for bringing this topic! I learned a lot trying to understand what happens. The exception traceback (what sys.exc_info()[2] returns) is *not* a complete stack trace. The sys module documentation is wrong [1] when it says "...encapsulates the call stack at the point where the exception originally occurred." The Language Reference is more clear [2]: "Traceback objects represent a stack trace of an exception. A traceback object is created when an exception occurs. When the search for an exception handler unwinds the execution stack, at each unwound level a traceback object is inserted in front of the current traceback. When an exception handler is entered, the stack trace is made available to the program." That is, a traceback holds only the *forward* part of the stack: the frames already exited when looking for an exception handler. Frames going from the program starting point up to the current execution point are *not* included. Conceptually, it's like having two lists: stack and traceback. The complete stack trace is always stack+traceback. At each step (when unwinding the stack, looking for a frame able to handle the current exception) an item is popped from the top of the stack (last item) and inserted at the head of the traceback. The traceback holds the "forward" path (from the current execution point, to the frame where the exception was actually raised). It's a linked list, its tb_next attribute holds a reference to the next item; None marks the last one. The "back" path (going from the current execution point to its caller and all the way to the program entry point) is a linked list of frames; the f_back attribute points to the previous one, or None. In order to show a complete stack trace, one should combine both. The traceback module contains several useful functions: extract_stack() + extract_tb() are a starting point. The simplest way I could find to make the logging module report a complete stack is to monkey patch logging.Formatter.formatException so it uses format_exception() and format_stack() combined (in fact it is simpler than the current implementation using a StringIO object): import logging import traceback def formatException(self, ei): """ Format and return the specified exception information as a string. This implementation builds the complete stack trace, combining traceback.format_exception and traceback.format_stack. """ lines = traceback.format_exception(*ei) if ei[2]: lines[1:1] = traceback.format_stack(ei[2].tb_frame.f_back) return ''.join(lines) # monkey patch the logging module logging.Formatter.formatException = formatException def a(): return b() def b(): return c() def c(): try: return d() except: logging.exception("An error") raise def d(): raise ValueError def main(): a() main() Output: ERROR:root:An error Traceback (most recent call last): File "test_logging.py", line 32, in main() File "test_logging.py", line 30, in main a() File "test_logging.py", line 19, in a def a(): return b() File "test_logging.py", line 20, in b def b(): return c() File "test_logging.py", line 23, in c return d() File "test_logging.py", line 27, in d def d(): raise ValueError ValueError Traceback (most recent call last): File "test_logging.py", line 32, in main() File "test_logging.py", line 30, in main a() File "test_logging.py", line 19, in a def a(): return b() File "test_logging.py", line 20, in b def b(): return c() File "test_logging.py", line 23, in c return d() File "test_logging.py", line 27, in d def d(): raise ValueError ValueError Note that both tracebacks are identical: the first comes from the patched logging module, the second is the standard Python one. [1] http://docs.python.org/library/sys.html#sys.exc_info [2] http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Mar 23 02:32:13 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Mar 2010 06:32:13 GMT Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 22 Mar 2010 22:05:40 -0700, Paul Rubin wrote: > Antoine Pitrou writes: >> "Orders of magnitude worse", in any case, sounds very exaggerated. > > The worst case can lose orders of magnitude if a lot of values hash to > the same bucket. Well, perhaps one order of magnitude. >>> for i in xrange(100): ... n = 32*i+1 ... assert hash(2**n) == hash(2) ... >>> d1 = dict.fromkeys(xrange(100)) >>> d2 = dict.fromkeys([2**(32*i+1) for i in xrange(100)]) >>> >>> from timeit import Timer >>> setup = "from __main__ import d1, d2" >>> t1 = Timer("for k in d1.keys(): x = d1[k]", setup) >>> t2 = Timer("for k in d2.keys(): x = d2[k]", setup) >>> >>> min(t1.repeat(number=1000, repeat=5)) 0.026707887649536133 >>> min(t2.repeat(number=1000, repeat=5)) 0.33103203773498535 -- Steven From gagsl-py2 at yahoo.com.ar Tue Mar 23 03:07:47 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Mar 2010 04:07:47 -0300 Subject: Problem with sys.path when embedding Python3 in C References: <2cf430a61003221419t2192c9aajd3c2d2922b1d7f12@mail.gmail.com> Message-ID: En Mon, 22 Mar 2010 18:19:49 -0300, Krister Svanlund escribi?: > Hi, I've recently begun experimenting with embedding python and i got > a small problem. > > The following line here is the ugly-hack I had to do to make it work, > nothing else I know of makes it possible to import modules from > startup directory. So my question is: Is there a prettier way to do > this? The startup directory is not included in the module search path - neither in your embedded version, nor in the standard interpreter (it's only included when running in interactive mode). >> PyRun_SimpleString("import sys\nsys.path.append(\"\")"); If you really want the current directory in sys.path, use the getcwd function to obtain it. But make sure this is what you want - the directory containing the executable might be a better choice (at least more predictable). Note that Python already provides lots of ways to add directories to sys.path (the default search path (see site.py), per-user site directories (see PEP370), .pth files, the PYTHONPATH and PYTHONHOME environment variables, the Windows registry, other ways I forgot...) So I'd ask why do you want to add a non-standard one. In C code, you can alter the initial search path by setting Py_SetProgramName and Py_SetPythonHome. And you may even completely replace getpathp.c source file with your own. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 23 03:22:59 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Mar 2010 04:22:59 -0300 Subject: individually updating unicodedata db? References: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Message-ID: En Mon, 22 Mar 2010 21:19:04 -0300, Vlastimil Brom escribi?: > I guess, I am stuck here, as I use the precompiled version supplied in > the windows installer and can't compile python from source to obtain > the needed unicodedata.pyd. You can recompile Python from source, on Windows, using the free Microsoft? Visual C++? 2008 Express Edition. http://www.microsoft.com/express/Windows/ Fetch the required dependencies using Tools\buildbot\external.bat, and then execute PCbuild\env.bat and build.bat. See readme.txt in that directory for details. It should build cleanly. -- Gabriel Genellina From vinay_sajip at yahoo.co.uk Tue Mar 23 04:10:36 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 23 Mar 2010 01:10:36 -0700 (PDT) Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: On Mar 20, 8:36?am, Peter Otten <__pete... at web.de> wrote: > Jean-Michel Pichavant wrote: > > You are still accessing the private attribute of the ?modulelogging. > > Just reading it is a significantly more conservative approach than setting > it to an object with an unusual notion of equality ;) > > > My previous remark was misleading, in fact there's nothing you can do > > about it. > > How about replacinglogging._srcfile with fixname(logging.__file__)? > > > _srcfile is not meant to be used elsewhere than in theloggingmodule > > itself. > > However, I don't wanna sound like I'm rejecting this solution, 1st the > > OP is satisified with it and since this solution is working, it is still > > more helpful than anyone noticing that you've accessed a private > > attribute (some will successfully argue that python allows to do so). > > Yeah, I had hoped that I could get away without drawing the "consenting > adults" wildcard... > > > At the very begining of this thread I've provided a complete different > > approach, instead of using the builtin 'filename' and 'lineno' field of > > thelogging, use custom fileds with the extra parameter. > > > It has also some drawbacks but could be a possible alternative. > > Having two filename/lineno sets ist likely to confuse. > > Peter Guys, Sorry I'm a little late to this discussion. I could add a _findCaller function to the module (not part of the public API, but replaceable by someone who really needs to) which does the heavy lifting, and Logger.findCaller just calls it. Then those who need to can implement their own strategy, without needing to jump through hoops. Does that approach sound helpful? Regards, Vinay Sajip From no.email at nospam.invalid Tue Mar 23 04:17:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Mar 2010 01:17:32 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: <7xr5nbwixv.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Well, perhaps one order of magnitude. >>>> for i in xrange(100): > ... n = 32*i+1 > ... assert hash(2**n) == hash(2) Try with much more than 100 items (you might want to construct the entries a little more intricately to avoid such big numbers). The point is that access becomes O(N) instead of O(1). See: http://www.cs.rice.edu/~scrosby/hash/ for the consequences. http://cr.yp.to/critbit.html discusses the issue a little more. From __peter__ at web.de Tue Mar 23 04:43:54 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Mar 2010 09:43:54 +0100 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > On Mon, 22 Mar 2010 22:05:40 -0700, Paul Rubin wrote: > >> Antoine Pitrou writes: >>> "Orders of magnitude worse", in any case, sounds very exaggerated. >> >> The worst case can lose orders of magnitude if a lot of values hash to >> the same bucket. > > > Well, perhaps one order of magnitude. > > >>>> for i in xrange(100): > ... n = 32*i+1 > ... assert hash(2**n) == hash(2) > ... >>>> d1 = dict.fromkeys(xrange(100)) >>>> d2 = dict.fromkeys([2**(32*i+1) for i in xrange(100)]) >>>> >>>> from timeit import Timer >>>> setup = "from __main__ import d1, d2" >>>> t1 = Timer("for k in d1.keys(): x = d1[k]", setup) >>>> t2 = Timer("for k in d2.keys(): x = d2[k]", setup) >>>> >>>> min(t1.repeat(number=1000, repeat=5)) > 0.026707887649536133 >>>> min(t2.repeat(number=1000, repeat=5)) > 0.33103203773498535 But the ratio grows with the number of collisions: $ python extrapolate.py 10 0.00120401382446 0.00753307342529 ratio: 6.25663366337 100 0.00542402267456 0.316139936447 ratio: 58.2851428571 1000 0.00553417205811 3.36690688133 ratio: 608.384930209 $ cat extrapolate.py from timeit import Timer class Item(object): def __init__(self, value, hash=None): self.value = value self.hash = value if hash is None else hash def __eq__(self, other): return self.value == other.value def __hash__(self): return self.hash setup = "from __main__ import d" bench = "for k in d: x = d[k]" for n, number in (10,100), (100,100), (1000,10): print n d1 = dict.fromkeys(Item(i) for i in xrange(n)) d2 = dict.fromkeys(Item(i, 0) for i in xrange(n)) ab = [] for d in d1, d2: t = Timer(bench, setup) ab.append(min(t.repeat(number=number, repeat=3))) print ab[-1] print "ratio:", ab[1]/ab[0] print See also http://xkcd.com/605/ Peter From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 23 05:13:05 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 23 Mar 2010 10:13:05 +0100 Subject: How to automate accessor definition? In-Reply-To: <4ba7aa87$0$4974$607ed4bc@cv.net> References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba79040$0$22397$426a74cc@news.free.fr> <4ba7aa87$0$4974$607ed4bc@cv.net> Message-ID: <4ba8861b$0$17824$426a74cc@news.free.fr> John Posner a ?crit : > On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote: > > > >> Another (better IMHO) solution is to use a plain property, and store the >> computed value as an implementation attribute : >> >> @property >> def foo(self): >> cached = self.__dict__.get('_foo_cache') >> if cached is None: >> self._foo_cache = cached = self._some_time_consuming_operation() >> return cached >> > > There's no need to access __dict__ directly. Nope, inded. I guess I wrote it that way to make clear that we were looking for an instance attribute (as a sequel of my previous writing on attribute lookup rules). > I believe this is > equivalent (and clearer): > > @property > def foo(self): > try: > cached = self._foo_cache > except AttributeError: > self._foo_cache = cached = self._time_consuming_op() > return cached > This is functionally _almost_ equivalent - won't work the same if there's a class attribute "_foo_cache", which might or not be a good thing !-) Will possibly be a bit faster after the first access - IIRC setting up an error handler is by itself cheaper than doing a couple attribute access and a method call - but I'd timeit before worrying about it. From krister.svanlund at gmail.com Tue Mar 23 05:23:53 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 23 Mar 2010 10:23:53 +0100 Subject: Problem with sys.path when embedding Python3 in C In-Reply-To: References: <2cf430a61003221419t2192c9aajd3c2d2922b1d7f12@mail.gmail.com> Message-ID: <2cf430a61003230223i32c06f01je20e698c119b1bb1@mail.gmail.com> On Tue, Mar 23, 2010 at 8:07 AM, Gabriel Genellina wrote: > En Mon, 22 Mar 2010 18:19:49 -0300, Krister Svanlund > escribi?: > >> Hi, I've recently begun experimenting with embedding python and i got >> a small problem. >> >> The following line here is the ugly-hack I had to do to make it work, >> nothing else I know of makes it possible to import modules from >> startup directory. So my question is: Is there a prettier way to do >> this? > > The startup directory is not included in the module search path - neither in > your embedded version, nor in the standard interpreter (it's only included > when running in interactive mode). > >>> PyRun_SimpleString("import sys\nsys.path.append(\"\")"); > > If you really want the current directory in sys.path, use the getcwd > function to obtain it. But make sure this is what you want - the directory > containing the executable might be a better choice (at least more > predictable). > Note that Python already provides lots of ways to add directories to > sys.path (the default search path (see site.py), per-user site directories > (see PEP370), .pth files, the PYTHONPATH and PYTHONHOME environment > variables, the Windows registry, other ways I forgot...) So I'd ask why do > you want to add a non-standard one. > > In C code, you can alter the initial search path by setting > ?Py_SetProgramName and Py_SetPythonHome. And you may even completely replace > getpathp.c source file with your own. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > The thing is that I want the application to be able to import modules I've written, but yeah, the applications directory is what I want rather than the cwd. I have tried Py_SetProgramName but haven't gotten it to work or cause any change at all to the import behaviour. Could you possibly provide som sort of example? From no.email at nospam.invalid Tue Mar 23 05:57:56 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Mar 2010 02:57:56 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: <7xpr2v2wd7.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > While this is theoretically true, and it's good to be aware of this > possibility, common string hash functions make it so rare in practice > that a hash table will almost always outperform a trie for exact > lookups. If it happens, it will either show up clearly enough in > benchmarks or not be worth bothering. It is unlikely to happen by accident. You might care that it can happen on purpose. See: http://www.cs.rice.edu/~scrosby/hash/ that I cited in another post. The article shows some sample attacks on Python cgi's. From stefan_ml at behnel.de Tue Mar 23 06:05:36 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Mar 2010 11:05:36 +0100 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: <7xwrx3mxuj.fsf@ruckus.brouhaha.com> References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 23.03.2010 06:05: > Antoine Pitrou writes: >> "Orders of magnitude worse", in any case, sounds very exaggerated. > > The worst case can lose orders of magnitude if a lot of values hash > to the same bucket. While this is theoretically true, and it's good to be aware of this possibility, common string hash functions make it so rare in practice that a hash table will almost always outperform a trie for exact lookups. If it happens, it will either show up clearly enough in benchmarks or not be worth bothering. Stefan From python at hope.cz Tue Mar 23 06:48:38 2010 From: python at hope.cz (Johny) Date: Tue, 23 Mar 2010 03:48:38 -0700 (PDT) Subject: How to find the best solution ? Message-ID: I have a text and would like to split the text into smaller parts, say into 100 characters each. But if the 100th character is not a blank ( but word) this must be less than 100 character.That means the word itself can not be split. These smaller parts must contains only whole( not split) words. I was thinking about RegEx but do not know how to find the correct Regular Expression. Can anyone help? Thanks L. From mail at timgolden.me.uk Tue Mar 23 06:54:33 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 10:54:33 +0000 Subject: How to find the best solution ? In-Reply-To: References: Message-ID: <4BA89DE9.5080001@timgolden.me.uk> On 23/03/2010 10:48, Johny wrote: > I have a text and would like to split the text into smaller parts, > say into 100 characters each. But if the 100th character is not a > blank ( but word) this must be less than 100 character.That means the > word itself can not be split. > These smaller parts must contains only whole( not split) words. > I was thinking about RegEx but do not know how to find the correct > Regular Expression. > Can anyone help? > Thanks > L. Have a look at the textwrap module TJG From alfps at start.no Tue Mar 23 06:54:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Mar 2010 11:54:45 +0100 Subject: Some silly code for Easter holiday Message-ID: This program simulates some colored balls moving around, changing color according to certain rules. I think the most interesting is perhaps to not look at this code but just try to run it and figure out the color changing rules from observing the effect (extra mystery: why I wrote this). Sort of like an Easter holiday mystery. # Py3 # Copyright 2010 Alf P. Steinbach import tkinter as tk from collections import namedtuple import random Point = namedtuple( "Point", "x, y" ) Size = namedtuple( "Size", "x, y" ) RGB = namedtuple( "RGB", "r, g, b" ) def generator( g ): assert isinstance( g, type( (i for i in ()) ) ) return g def tk_internal_bbox_from( bbox: tuple ): return ((bbox[0], bbox[1], bbox[2]+2, bbox[3]+2)) def tk_new_ellipse( canvas, bbox: tuple, **kwargs ): return canvas.create_oval( tk_internal_bbox_from( bbox ), **kwargs ) class TkTimer: def __init__( self, widget, msecs: int, action, start_running: bool = True ): self._widget = widget self._msecs = msecs self._action = action self._id = None if start_running: self.start() def start( self ): self._id = self._widget.after( self._msecs, self._on_timer ) def stop( self ): id = self._id; self._id = None self._widget.after_cancel( id ) # Try to cancel last event. def _on_timer( self ): if self._id is not None: self._action() self.start() class TkEllipse: def __init__( self, canvas, bbox: tuple, **kwargs ): self._canvas = canvas self._id = tk_new_ellipse( canvas, bbox, **kwargs ) @property # id def id( self ): return self._id @property # fill def fill( self ): return self._canvas.itemcget( self._id, "fill" ) @fill.setter def fill( self, color_representation: str ): self._canvas.itemconfigure( self._id, fill = color_representation ) @property # internal_bbox def internal_bbox( self ): return tuple( self._canvas.coords( self._id ) ) @property # position def position( self ): bbox = self.internal_bbox return Point( bbox[0], bbox[1] ) @position.setter def position( self, new_pos: Point ): bbox = self.internal_bbox (dx, dy) = (new_pos.x - bbox[0], new_pos.y - bbox[1]) self._canvas.move( self._id, dx, dy ) #assert self.position == new_pos class Color: def __init__( self, rgb_or_name ): if isinstance( rgb_or_name, RGB ): name = None rgb = rgb_or_name else: assert isinstance( rgb_or_name, str ) name = rgb_or_name rgb = None self._name = name self._rgb = rgb @property def representation( self ): if self._name is not None: return self._name else: rgb = self._rgb return "#{:02X}{:02X}{:02X}".format( rgb.r, rgb.g, rgb.b ) def __str__( self ): return self.representation def __hash__( self ): return hash( self.representation ) class Rectangle: def __init__( self, width : int, height : int, upper_left : Point = Point( 0, 0 ) ): self._left = upper_left.x self._right = upper_left.x + width self._top = upper_left.y self._bottom = upper_left.y + height @property # left def left( self ): return self._left @property # top def top( self ): return self._top @property # right def right( self ): return self._right @property # bottom def bottom( self ): return self._bottom @property # width def width( self ): return self._right - self._left @property # height def height( self ): return self._bottom - self._top @property # size def size( self ): return Size( self.width, self.height ) class Ball: def __init__( self, color : Color, position : Point = Point( 0, 0 ), velocity : Point = Point( 0, 0 ) ): self.color = color self.position = position self.velocity = velocity def squared_distance_to( self, other ): p1 = self.position p2 = other.position return (p2.x - p1.x)**2 + (p2.y - p1.y)**2 class BallSim: def __init__( self, rect : Rectangle, n_balls : int = 1 ): def random_pos(): return Point( random.randrange( rect.left, rect.right ), random.randrange( rect.top, rect.bottom ) ) def random_velocity(): return Point( random.randint( -10, 10 ), random.randint( -10, 10 ) ) def balls( color ): return generator( Ball( color, random_pos(), random_velocity() ) for i in range( n_balls ) ) self._rect = rect self._kind_1_color = Color( "blue" ) self._kind_2_color = Color( "orange" ) self._balls = tuple( balls( self._kind_1_color ) ) self._is_close_distance = 20; @property # rect def rect( self ): return self._rect @property # interaction_radius def interaction_radius( self ): return self._is_close_distance @property # n_balls def n_balls( self ): return len( self._balls ) def ball( self, i ): return self._balls[i] def balls( self ): return self._balls def _update_positions_and_velocities( self ): rect = self._rect for ball in self._balls: pos = ball.position; v = ball.velocity; pos = Point( pos.x + v.x, pos.y + v.y ) if pos.x < 0: pos = Point( -pos.x, pos.y ) v = Point( -v.x, v.y ) if pos.x >= rect.width: pos = Point( 2*rect.width - pos.x, pos.y ) v = Point( -v.x, v.y ) if pos.y < 0: pos = Point( pos.x, -pos.y ) v = Point( v.x, -v.y ) if pos.y >= rect.height: pos = Point( pos.x, 2*rect.height - pos.y ) v = Point( v.x, -v.y ) ball.position = pos ball.velocity = v def _balls_possibly_close_to( self, ball ): max_d_squared = self._is_close_distance**2 result = [] for other in self._balls: if other is ball: continue if ball.squared_distance_to( other ) <= max_d_squared: result.append( other ) return result def _update_kinds( self ): max_d_squared = self._is_close_distance**2 for ball in self._balls: if ball.color == self._kind_1_color: for other_ball in self._balls_possibly_close_to( ball ): if ball.squared_distance_to( other_ball ) <= max_d_squared: if other_ball.color == self._kind_1_color: ball.color = self._kind_2_color other_ball.color = self._kind_2_color break else: if random.random() < 0.01: ball.color = self._kind_1_color def evolve( self ): self._update_positions_and_velocities() self._update_kinds() class View: def _create_widgets( self, parent_widget, sim: BallSim ): self.widget = tk.Frame( parent_widget ) if True: canvas = tk.Canvas( self.widget, bg = "white", width = sim.rect.width, height = sim.rect.height ) canvas.pack() self._canvas = canvas self._circles = [] radius = sim.interaction_radius // 2 self._ball_radius = radius for ball in sim.balls(): (x, y) = (ball.position.x, ball.position.y) bbox = (x - radius, y - radius, x + radius, y + radius) ellipse = TkEllipse( canvas, bbox, fill = ball.color.representation ) self._circles.append( ellipse ) pass def __init__( self, parent_widget, sim: BallSim ): self._create_widgets( parent_widget, sim ) self._sim = sim def update( self ): sim = self._sim r = self._ball_radius for (i, ball) in enumerate( sim.balls() ): center_pos = ball.position self._circles[i].position = Point( center_pos.x - r, center_pos.y - r ) self._circles[i].fill = ball.color class Controller: def __init__( self, main_window ): self._window = main_window self._model = BallSim( Rectangle( 600, 500 ), n_balls = 20 ) self._view = view = View( main_window, self._model ) view.widget.place( relx = 0.5, rely = 0.5, anchor="center" ) self._timer = TkTimer( main_window, msecs = 42, action = self._on_timer ) def _on_timer( self ): self._model.evolve() self._view.update() def main(): window = tk.Tk() window.title( "Sim 1 -- Chameleon Balls" ) window.geometry( "640x510" ) controller = Controller( window ) window.mainloop() main() Cheers, - Alf From jeanmichel at sequans.com Tue Mar 23 06:55:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 23 Mar 2010 11:55:16 +0100 Subject: short-circuiting any/all ? In-Reply-To: References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: <4BA89E14.3050507@sequans.com> kj wrote: > Arguably, Knuth's "premature optimization is the root of all evil" > applies even to readability (e.g. "what's the point of making code > optimally readable if one is going to change it completely next > day?") The guy who will change it will have to read it. The only waste would be if the code would never be read again. > If there were the equivalent of a profiler for code clutter, > I guess I could relax my readability standards a bit... > > ~K > Don't relax, just keep up :o) JM From alexandre.fayolle at logilab.fr Tue Mar 23 07:48:44 2010 From: alexandre.fayolle at logilab.fr (Alexandre Fayolle) Date: Tue, 23 Mar 2010 12:48:44 +0100 Subject: ANN: Pylint bug day, 2nd edition In-Reply-To: <201003221838.07672.alexandre.fayolle@logilab.fr> References: <201003221838.07672.alexandre.fayolle@logilab.fr> Message-ID: <201003231248.44408.alexandre.fayolle@logilab.fr> On Monday 22 March 2010 18:38:07 Alexandre Fayolle wrote: > .. _pylint bugs day: https://www.logilab.net/elo/blogentry/18781 Correct link is : http://www.logilab.org/blogentry/18781 Sorry for the inconvenience. -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, CubicWeb, Debian : http://www.logilab.fr/formations D?veloppement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique: http://www.logilab.fr/science From phil at freehackers.org Tue Mar 23 08:38:37 2010 From: phil at freehackers.org (BlueBird) Date: Tue, 23 Mar 2010 05:38:37 -0700 (PDT) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> <13753751-d0af-48df-b78d-5b371109e05c@t41g2000yqt.googlegroups.com> Message-ID: On 5 mar, 13:19, lbolla wrote: > On Mar 5, 10:01?am, BlueBird wrote: > > > > > > > On 3 mar, 20:35, Stefan Behnel wrote: > > > > BlueBird, 03.03.2010 17:32: > > > > > I am looking for aSOAP1.2 python client. To my surprise, it seems > > > > that this does not exist. Does anybody know about this ? > > > >SOAPmay be an overly bloated protocol, but it's certainly not black magic. > > > It's not hard to do manually if you really need to: > > > >http://effbot.org/zone/element-soap.htm > > > But this requires a goog knowloedge ofSOAP, in order to parse > > everything correctly. The reason I want to use a ready-made client is > > that I have about zero knowledge aboutSOAP, and even more in the > > differences betweenSOAP1.1 and 1.2 . > > > cheers, > > > Philippe > > I use a thin custom-made python wrapper around gSoap[1], which is tens > of times faster than ZSI. I looked at gSoap and the solution seemed really nice. They can generate C that I can call with ctypes. The only problem is that I am working on a closed source software and their licensing cost for close source were too expensive for my company. After much much digging, we found out the problem and managed to solve it with SUDS. When calling a .NET service, you should not reference the soap envelope spec with 'http://schemas.xmlsoap.org/soap/ envelope/' but with 'http://schemas.xmlsoap.org/soap/envelope' . The .NET server implementation seems to be very picky about the last / . Yeah for SUDS and oooooh for .NET cheers, Philippe From saimapk81 at gmail.com Tue Mar 23 08:54:01 2010 From: saimapk81 at gmail.com (saima81) Date: Tue, 23 Mar 2010 05:54:01 -0700 (PDT) Subject: "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ Message-ID: <3214acd7-f057-4444-9ff8-d6402d7a4b30@u5g2000prd.googlegroups.com> "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ From vlastimil.brom at gmail.com Tue Mar 23 10:18:17 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 23 Mar 2010 15:18:17 +0100 Subject: individually updating unicodedata db? In-Reply-To: References: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Message-ID: <9fdb569a1003230718u37d2e2dem944e4141def631b0@mail.gmail.com> 2010/3/23 Gabriel Genellina : > En Mon, 22 Mar 2010 21:19:04 -0300, Vlastimil Brom > escribi?: > >> I guess, I am stuck here, as I use the precompiled version supplied in >> the windows installer and can't compile python from source to obtain >> the needed unicodedata.pyd. > > You can recompile Python from source, on Windows, using the free Microsoft? > Visual C++? 2008 Express Edition. > http://www.microsoft.com/express/Windows/ > > Fetch the required dependencies using Tools\buildbot\external.bat, and then > execute PCbuild\env.bat and build.bat. See readme.txt in that directory for > details. It should build cleanly. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the hints; i probably screwed some steps up in some way, but the result seem to be working for the most part; I'll try to summarise it just for the record (also hoping to get further suggestions): I used the official source tarball for python 2.6.5 from: http://www.python.org/download/ In the unpacked sources, I edited the file: ...\Python-2.6.5-src\Tools\unicode\makeunicodedata.py import re # added ... # UNIDATA_VERSION = "5.1.0" # changed to: UNIDATA_VERSION = "5.2.0" Furthermore the following text files were copied to the same directory like makeunicodedata.py CompositionExclusions-3.2.0.txt EastAsianWidth-3.2.0.txt UnicodeData-3.2.0.txt UnicodeData.txt EastAsianWidth.txt CompositionExclusions.txt from http://unicode.org/Public/3.2-Update/ and http://unicode.org/Public/5.2.0/ucd/ furthermore there are some files in the subdirectories needed: ...\Python-2.6.5-src\Tools\unicode\Objects\unicodetype_db.h ...\Python-2.6.5-src\Tools\unicode\Modules\unicodedata_db.h ...\Python-2.6.5-src\Tools\unicode\Modules\unicodename_db.h After running makeunicodedata.py, the above headers are recreated from the new unicode database and can be copied to the original locations in the source ...\Python-2.6.5-src\Objects\unicodetype_db.h ...\Python-2.6.5-src\Modules\unicodedata_db.h ...\Python-2.6.5-src\Modules\unicodename_db.h (while keeping the backups) Trying to run ...\Python-2.6.5-src\Tools\buildbot\external.bat and other bat files, I got quite a few path mismatches resulting in file ... not found errors; However, I was able to just open the solution file in Visual C++ 2008 Express: C:\install\Python-2.6.5-src\PCbuild\pcbuild.sln set the build configuration to "release" and try to build the sources. There were some errors in particular modules (which might be due to my mistakes or ommissions, as this maybe shouldn't happen normally), but the wanted ...\Python-2.6.5-src\PCbuild\unicodedata.pyd was generated and can be used in the original python installation: C:\Python26\DLLs\unicodedata.pyd the newly added characters, cf.: http://www.unicode.org/Public/UNIDATA/DerivedAge.txt seem to be available ? (dec.: 8528) (hex.: 0x2150) # ? VULGAR FRACTION ONE SEVENTH (Number, Other) ? (dec.: 68352) (hex.: 0x10b00) # ? AVESTAN LETTER A (Letter, Other) but some are not present; I noticed this for the new CJK block - CJK Unified Ideographs Extension C (U+2A700..U+2B73F). Probably this new range isn't taken into account for some reason. All in all, I am happy to have the current version of the unicode database available; I somehow expected this to be more complicated, but on the other hand I can't believe this is the standard way of preparing the built versions (with all the copying,checking and and replacing the files); it might be possible, that the actual distribution is built using some different tools (the trivial missing import in makeunicodedata.py would be found immediately, I guess). I also wanted to ask, whether the missing characters might be a result of my error in updating the unicode database, or could it be a problem with the makeunicodedata.py itself? Thanks in advance and sorry for this long post. vbr From peter at psantoro.net Tue Mar 23 10:38:20 2010 From: peter at psantoro.net (peter at psantoro.net) Date: 23 Mar 2010 07:38:20 -0700 Subject: RELEASED Python 2.6.5 References: Message-ID: Thank you everyone for all the work that went into this update, but there may be a small problem with the Windows x86 installer. I've built and used python 2.6.5 on linux without any apparent problems, but the Windows x86 binary installer stops after compiling a few python source files. I've tried the Windows x86 installer on two differently configured Windows XP PCs (SP3 with patches), but I get the following errors during the advanced compiling of python source files: "There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor." "Python 2.6.5 Installer ended prematurely ..." The md5sum of the Windows x86 installer matched the published value. I did not try not using the advanced option. I reinstalled python 2.6.4 on both of the PCs without any problems and used the advanced compile option. Is anyone else having trouble with the 2.6.5 Windows x86 installer? Peter From omrihsan at gmail.com Tue Mar 23 10:49:08 2010 From: omrihsan at gmail.com (Omer Ihsan) Date: Tue, 23 Mar 2010 07:49:08 -0700 (PDT) Subject: device identification References: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> <46ggq59e49qpna7f9ae6q8ftobhot351un@4ax.com> Message-ID: <57c86289-85e7-4c9f-b7ed-787687d9a5b6@x23g2000prd.googlegroups.com> On Mar 23, 9:22?am, Tim Roberts wrote: > Omer Ihsan wrote: > > >i have installed pyusb now and run the sample usbenum.py....i have 3 > >usb ports on my PC but the results show 6 outputs to > >dev.filename..they are numbers like 001 or 005 etc.... and they > >changed when i plugged in devices...(i am no good with the usb > >standards)....i just want to identify each device/port... what > >parameter in the example would help me.... > > You can't identify the ports.[1] ?What good would it do you? ?The ports on > your PC are not numbered. > > You certainly CAN identify the devices, by their VID and PID (or idVendor > and idProduct). ?You identify by function, not by location. ?When you plug > in a USB drive, you don't want to worry about where it's plugged in. > === > [1]: OK, technically, it is not impossible to identify the port numbers, > but it is quite tedious. ?You need to chase through the sysfs expansion of > your buses hub/port tree and find a match for your device. ?It's not worth > the trouble. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. VID and PID is fair enough. now what i want is that i have a threaded code that threads two functions to run at the same time. i want each function to run seperate devices. the problem is if it doesnt identify the attached devices it might run the code on a single device which isnt what is required. how will i be able to run a code on a device of my choice???....you can leave away the threading part for now. From alley at dragoncreativeworks.net Tue Mar 23 12:04:21 2010 From: alley at dragoncreativeworks.net (Allan Davis) Date: Tue, 23 Mar 2010 11:04:21 -0500 Subject: RELEASED Python 2.6.5 In-Reply-To: References: Message-ID: <61c507641003230904w41a028dbl21e83fc4399dc6cf@mail.gmail.com> I just downloaded the installer and tested it on my win xp machine. The installer worked fine. -------------------------------------------------------------- Allan Davis Member of NetBeans Dream Team http://wiki.netbeans.org/NetBeansDreamTeam Lead Developer, nbPython http://wiki.netbeans.org/Python http://codesnakes.blogspot.com (my blog) Co-Chair, CajunJUG http://www.cajunjug.org On Tue, Mar 23, 2010 at 9:38 AM, wrote: > Thank you everyone for all the work that went into this update, but there > may be > a small problem with the Windows x86 installer. > > I've built and used python 2.6.5 on linux without any apparent problems, > but the > Windows x86 binary installer stops after compiling a few python source > files. > > I've tried the Windows x86 installer on two differently configured Windows > XP > PCs (SP3 with patches), but I get the following errors during the advanced > compiling of python source files: > > "There is a problem with this Windows Installer package. A program run as > part > of the setup did not finish as expected. Contact your support personnel or > package vendor." > > "Python 2.6.5 Installer ended prematurely ..." > > The md5sum of the Windows x86 installer matched the published value. I did > not > try not using the advanced option. I reinstalled python 2.6.4 on both of > the > PCs without any problems and used the advanced compile option. > > Is anyone else having trouble with the 2.6.5 Windows x86 installer? > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosymonijasmine at gmail.com Tue Mar 23 12:05:42 2010 From: rosymonijasmine at gmail.com (Jasmine Rose) Date: Tue, 23 Mar 2010 09:05:42 -0700 (PDT) Subject: Stop the Heat from Sun Rays! Message-ID: <37e5dd24-c8a4-494f-8cf1-1577cf247401@u15g2000prd.googlegroups.com> Stop the Heat! Stop UV Damage! Save Money! - More Details : http://www.suntechglasstinting.com/welcome.php From solipsis at pitrou.net Tue Mar 23 12:53:34 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 23 Mar 2010 16:53:34 +0000 (UTC) Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> <7xpr2v2wd7.fsf@ruckus.brouhaha.com> Message-ID: Le Tue, 23 Mar 2010 02:57:56 -0700, Paul Rubin a ?crit?: > > It is unlikely to happen by accident. You might care that it can happen > on purpose. See: http://www.cs.rice.edu/~scrosby/hash/ that I cited in > another post. The article shows some sample attacks on Python cgi's. Certainly interesting in a purely academic point of view, but in real life if you want to cause a denial of service by overwhelming a server, there are far more obvious options than trying to guess the server's use of hash tables and trying to cause lots of collisions in them. From jfernand57 at gmail.com Tue Mar 23 12:55:30 2010 From: jfernand57 at gmail.com (Jose Manuel) Date: Tue, 23 Mar 2010 09:55:30 -0700 (PDT) Subject: Python is cool!! Message-ID: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> I have been learning Python, and it is amazing .... I am using the tutorial that comes with the official distribution. At the end my goal is to develop applied mathematic in engineering applications to be published on the Web, specially on app. oriented to simulations and control systems, I was about to start learning Java but I found Python which seems easier to learn that Java. Would it be easy to integrate Python in Web pages with HTML? I have read many info on Internet saying it is, and I hope so .... Any opinion From mehgcap at gmail.com Tue Mar 23 13:01:21 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 23 Mar 2010 13:01:21 -0400 Subject: using message loop for hotkey capturing Message-ID: Hi all, but mainly Tim Golden: Tim, I am using your wonderful message loop for keyboard input, the one on your site that you pointed me to a few months ago. It has been working perfectly as long as I had only one dictionary of keys mapping to one dictionary of functions, but now I want two of each. My program has different modes, which may have varying keystrokes, and I also have some global keystrokes which are the same across all modes, like exiting or switching modes. I cannot figure out how to make the message loop look in two dictionaries at onc. I tried using an if, saying that if action_to_take was not set in the mode-specific dictionary then look at the global dictionary, but it is like it is never looking in the global dictionary at all. I get no syntax errors or problems when running the program, so it has to be something in my logic. Go to http://www.gateway2somewhere.com/sw/main.pyw to see what I mean; the problem code is near the very bottom of the file. Thanks for any suggestions. Oh, please note that I indent one space per indentation level. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From vinay_sajip at yahoo.co.uk Tue Mar 23 13:06:43 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 23 Mar 2010 10:06:43 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() References: mailman.1078.1269324766.23598.python-list@python.org Message-ID: <54e357f4-705f-40a8-ac6c-e5ae84f814f7@t23g2000yqt.googlegroups.com> On Mar 23, 6:12?am, "Gabriel Genellina" wrote: > En Mon, 22 Mar 2010 15:20:39 -0300, Pascal Chambon ? > escribi???: > > > > > > > Allright, here is more concretely the problem : > > > ERROR:root:An error > > Traceback (most recent call last): > > ? File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c > > ? ? return d() > > ? File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d > > ? ? def d(): raise ValueError > > ValueError > > > As you see, the traceback only starts from function c, which handles the ? > > exception. > > It doesn't show main(), a() and b(), which might however be (and are, in ? > > my case) critical to diagnose the severity of the problem (since many ? > > different paths would lead to calling c()). > > > So the question is : is that possible to enforce, by a way or another, ? > > the retrieval of the FULL traceback at exception raising point, instead ? > > of that incomplete one ? > > Thanks for bringing this topic! I learned a lot trying to understand what ? > happens. > > The exception traceback (what sys.exc_info()[2] returns) is *not* a ? > complete stack trace. The sys module documentation is wrong [1] when it ? > says "...encapsulates the call stack at the point where the exception ? > originally occurred." > > The Language Reference is more clear [2]: "Traceback objects represent a ? > stack trace of an exception. A traceback object is created when an ? > exception occurs. When the search for an exception handler unwinds the ? > execution stack, at each unwound level a traceback object is inserted in ? > front of the current traceback. When an exception handler is entered, the ? > stack trace is made available to the program." > > That is, a traceback holds only the *forward* part of the stack: the ? > frames already exited when looking for an exception handler. Frames going ? > ?from the program starting point up to the current execution point are ? > *not* included. > > Conceptually, it's like having two lists: stack and traceback. The ? > complete stack trace is always stack+traceback. At each step (when ? > unwinding the stack, looking for a frame able to handle the current ? > exception) an item is popped from the top of the stack (last item) and ? > inserted at the head of the traceback. > > The traceback holds the "forward" path (from the current execution point, ? > to the frame where the exception was actually raised). It's a linked list, ? > its tb_next attribute holds a reference to the next item; None marks the ? > last one. > > The "back" path (going from the current execution point to its caller and ? > all the way to the program entry point) is a linked list of frames; the ? > f_back attribute points to the previous one, or None. > > In order to show a complete stack trace, one should combine both. The ? > traceback module contains several useful functions: extract_stack() + ? > extract_tb() are a starting point. The simplest way I could find to make ? > theloggingmodule report a complete stack is to monkey patch ?logging.Formatter.formatException so it uses format_exception() and ? > format_stack() combined (in fact it is simpler than the current ? > implementation using a StringIO object): > > > importlogging > import traceback > > def formatException(self, ei): > ? ? ?""" > ? ? ?Format and return the specified exception information as a string. > > ? ? ?This implementation builds the complete stack trace, combining > ? ? ?traceback.format_exception and traceback.format_stack. > ? ? ?""" > ? ? ?lines = traceback.format_exception(*ei) > ? ? ?if ei[2]: > ? ? ? ? ?lines[1:1] = traceback.format_stack(ei[2].tb_frame.f_back) > ? ? ?return ''.join(lines) > > # monkey patch theloggingmodulelogging.Formatter.formatException = formatException > > def a(): return b() > def b(): return c() > def c(): > ? ? ?try: > ? ? ? ?return d() > ? ? ?except: > ? ? ? ?logging.exception("An error") > ? ? ? ?raise > def d(): raise ValueError > > def main(): > ? ?a() > > main() > > > Output: > > ERROR:root:An error > Traceback (most recent call last): > ? ?File "test_logging.py", line 32, in > ? ? ?main() > ? ?File "test_logging.py", line 30, in main > ? ? ?a() > ? ?File "test_logging.py", line 19, in a > ? ? ?def a(): return b() > ? ?File "test_logging.py", line 20, in b > ? ? ?def b(): return c() > ? ?File "test_logging.py", line 23, in c > ? ? ?return d() > ? ?File "test_logging.py", line 27, in d > ? ? ?def d(): raise ValueError > ValueError > > Traceback (most recent call last): > ? ?File "test_logging.py", line 32, in > ? ? ?main() > ? ?File "test_logging.py", line 30, in main > ? ? ?a() > ? ?File "test_logging.py", line 19, in a > ? ? ?def a(): return b() > ? ?File "test_logging.py", line 20, in b > ? ? ?def b(): return c() > ? ?File "test_logging.py", line 23, in c > ? ? ?return d() > ? ?File "test_logging.py", line 27, in d > ? ? ?def d(): raise ValueError > ValueError > > Note that both tracebacks are identical: the first comes from the patched ?loggingmodule, the second is the standard Python one. > > [1]http://docs.python.org/library/sys.html#sys.exc_info > [2] ?http://docs.python.org/reference/datamodel.html#the-standard-type-hie... > > -- > Gabriel Genellina Good catch, Gabriel. There should be no need to monkey-patch the logging module - it's better if I include the change in the module itself. The only remaining question is that of backward compatibility, but I can do this for Python 2.7/3.2 only so that won't be an issue. It's probably a good idea to log an issue on the bug tracker, though, so we have some history for the change - do you want to do that, or shall I? Regards, Vinay Sajip From mail at timgolden.me.uk Tue Mar 23 13:07:57 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 17:07:57 +0000 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4BA8F56D.6060305@timgolden.me.uk> On 23/03/2010 16:55, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... You probably want to be looking at IronPython and Silverlight. In fact, the prolific Michael Foord has already produced an example of this, which gives you the Python tutorial online! http://trypython.org TJG From mail at timgolden.me.uk Tue Mar 23 13:09:36 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 17:09:36 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: Message-ID: <4BA8F5D0.7080502@timgolden.me.uk> On 23/03/2010 17:01, Alex Hall wrote: > Hi all, but mainly Tim Golden: > Tim, I am using your wonderful message loop for keyboard input, the > one on your site that you pointed me to a few months ago. It has been > working perfectly as long as I had only one dictionary of keys mapping > to one dictionary of functions, but now I want two of each. My program > has different modes, which may have varying keystrokes, and I also > have some global keystrokes which are the same across all modes, like > exiting or switching modes. I cannot figure out how to make the > message loop look in two dictionaries at onc. I tried using an if, > saying that if action_to_take was not set in the mode-specific > dictionary then look at the global dictionary, but it is like it is > never looking in the global dictionary at all. I get no syntax errors > or problems when running the program, so it has to be something in my > logic. Go to > http://www.gateway2somewhere.com/sw/main.pyw Happy to look, Alex, but that link's giving me a 404 at the moment TJG From mehgcap at gmail.com Tue Mar 23 13:29:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 23 Mar 2010 13:29:05 -0400 Subject: using message loop for hotkey capturing In-Reply-To: <4BA8F5D0.7080502@timgolden.me.uk> References: <4BA8F5D0.7080502@timgolden.me.uk> Message-ID: Sorry about that, it is fixed now. On 3/23/10, Tim Golden wrote: > On 23/03/2010 17:01, Alex Hall wrote: >> Hi all, but mainly Tim Golden: >> Tim, I am using your wonderful message loop for keyboard input, the >> one on your site that you pointed me to a few months ago. It has been >> working perfectly as long as I had only one dictionary of keys mapping >> to one dictionary of functions, but now I want two of each. My program >> has different modes, which may have varying keystrokes, and I also >> have some global keystrokes which are the same across all modes, like >> exiting or switching modes. I cannot figure out how to make the >> message loop look in two dictionaries at onc. I tried using an if, >> saying that if action_to_take was not set in the mode-specific >> dictionary then look at the global dictionary, but it is like it is >> never looking in the global dictionary at all. I get no syntax errors >> or problems when running the program, so it has to be something in my >> logic. Go to >> http://www.gateway2somewhere.com/sw/main.pyw > > > Happy to look, Alex, but that link's giving me a 404 at the moment > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From python.list at tim.thechases.com Tue Mar 23 13:31:09 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Mar 2010 12:31:09 -0500 Subject: How to find the best solution ? In-Reply-To: References: Message-ID: <4BA8FADD.5070709@tim.thechases.com> Johny wrote: > I have a text and would like to split the text into smaller parts, > say into 100 characters each. But if the 100th character is not a > blank ( but word) this must be less than 100 character.That means the > word itself can not be split. > These smaller parts must contains only whole( not split) words. > I was thinking about RegEx but do not know how to find the correct > Regular Expression. While I suspect you can come close with a regular expression: import re, random size = 100 r = re.compile(r'.{1,%i}\b' % size) # generate a random text string with a mix of word-lengths words = ['a', 'an', 'the', 'four', 'fives', 'sixsix'] data = ' '.join(random.choice(words) for _ in range(200)) # for each chunk of 100 characters (or fewer # if on a word-boundary), do something for bit in r.finditer(data): chunk = bit.group(0) print "%i: [%s]" % (len(chunk), chunk) it may have an EOF fencepost error, so you might have to clean up the last item. My simple test seemed to show it worked without cleanup though. -tkc From pruebauno at latinmail.com Tue Mar 23 13:33:33 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 10:33:33 -0700 (PDT) Subject: Unicode blues in Python3 Message-ID: I know that unicode is the way to go in Python 3.1, but it is getting in my way right now in my Unix scripts. How do I write a chr(253) to a file? #nntst2.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) print(mychar) > ./nntst2.py ISO8859-1 ? > ./nntst2.py >nnout2 Traceback (most recent call last): File "./nntst2.py", line 5, in print(mychar) UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 0: ordinal not in range(128) > cat nnout2 ascii ..Oh great! ok lets try this: #nntst3.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) print(mychar.encode('latin1')) > ./nntst3.py ISO8859-1 b'\xfd' > ./nntst3.py >nnout3 > cat nnout3 ascii b'\xfd' ..Eh... not what I want really. #nntst4.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) sys.stdout=codecs.getwriter("latin1")(sys.stdout) print(mychar) > ./nntst4.py ISO8859-1 Traceback (most recent call last): File "./nntst4.py", line 6, in print(mychar) File "Python-3.1.2/Lib/codecs.py", line 356, in write self.stream.write(data) TypeError: must be str, not bytes ..OK, this is not working either. Is there any way to write a value 253 to standard output? From python at mrabarnett.plus.com Tue Mar 23 13:54:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Mar 2010 17:54:58 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: Message-ID: <4BA90072.9060305@mrabarnett.plus.com> Alex Hall wrote: > Hi all, but mainly Tim Golden: > Tim, I am using your wonderful message loop for keyboard input, the > one on your site that you pointed me to a few months ago. It has been > working perfectly as long as I had only one dictionary of keys mapping > to one dictionary of functions, but now I want two of each. My program > has different modes, which may have varying keystrokes, and I also > have some global keystrokes which are the same across all modes, like > exiting or switching modes. I cannot figure out how to make the > message loop look in two dictionaries at onc. I tried using an if, > saying that if action_to_take was not set in the mode-specific > dictionary then look at the global dictionary, but it is like it is > never looking in the global dictionary at all. I get no syntax errors > or problems when running the program, so it has to be something in my > logic. Go to > http://www.gateway2somewhere.com/sw/main.pyw > to see what I mean; the problem code is near the very bottom of the > file. Thanks for any suggestions. Oh, please note that I indent one > space per indentation level. > "msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc, not ints. Incidentally, you might want to change: if(not action_to_take): to: if action_to_take is None: in case any of the values happen to be 0 (if not now, then possibly at some time in the future). From rami.chowdhury at gmail.com Tue Mar 23 14:00:09 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 23 Mar 2010 11:00:09 -0700 Subject: Unicode blues in Python3 In-Reply-To: References: Message-ID: <201003231100.10103.rami.chowdhury@gmail.com> On Tuesday 23 March 2010 10:33:33 nn wrote: > I know that unicode is the way to go in Python 3.1, but it is getting > in my way right now in my Unix scripts. How do I write a chr(253) to a > file? > > #nntst2.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar) The following code works for me: $ cat nnout5.py #!/usr/bin/python3.1 import sys mychar = chr(253) sys.stdout.write(mychar) $ echo $(cat nnout) ? Can I ask why you're using print() in the first place, rather than writing directly to a file? Python 3.x, AFAIK, distinguishes between text and binary files and will let you specify the encoding you want for strings you write. Hope that helps, Rami > > > ./nntst2.py > > ISO8859-1 > ? > > > ./nntst2.py >nnout2 > > Traceback (most recent call last): > File "./nntst2.py", line 5, in > print(mychar) > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > position 0: ordinal not in range(128) > > > cat nnout2 > > ascii > > ..Oh great! > > ok lets try this: > #nntst3.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar.encode('latin1')) > > > ./nntst3.py > > ISO8859-1 > b'\xfd' > > > ./nntst3.py >nnout3 > > > > cat nnout3 > > ascii > b'\xfd' > > ..Eh... not what I want really. > > #nntst4.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > print(mychar) > > > ./nntst4.py > > ISO8859-1 > Traceback (most recent call last): > File "./nntst4.py", line 6, in > print(mychar) > File "Python-3.1.2/Lib/codecs.py", line 356, in write > self.stream.write(data) > TypeError: must be str, not bytes > > ..OK, this is not working either. > > Is there any way to write a value 253 to standard output? ---- Rami Chowdhury "Ninety percent of everything is crap." -- Sturgeon's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From mehgcap at gmail.com Tue Mar 23 14:04:15 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 23 Mar 2010 14:04:15 -0400 Subject: using message loop for hotkey capturing In-Reply-To: <4BA90072.9060305@mrabarnett.plus.com> References: <4BA90072.9060305@mrabarnett.plus.com> Message-ID: On 3/23/10, MRAB wrote: > Alex Hall wrote: >> Hi all, but mainly Tim Golden: >> Tim, I am using your wonderful message loop for keyboard input, the >> one on your site that you pointed me to a few months ago. It has been >> working perfectly as long as I had only one dictionary of keys mapping >> to one dictionary of functions, but now I want two of each. My program >> has different modes, which may have varying keystrokes, and I also >> have some global keystrokes which are the same across all modes, like >> exiting or switching modes. I cannot figure out how to make the >> message loop look in two dictionaries at onc. I tried using an if, >> saying that if action_to_take was not set in the mode-specific >> dictionary then look at the global dictionary, but it is like it is >> never looking in the global dictionary at all. I get no syntax errors >> or problems when running the program, so it has to be something in my >> logic. Go to >> http://www.gateway2somewhere.com/sw/main.pyw >> to see what I mean; the problem code is near the very bottom of the >> file. Thanks for any suggestions. Oh, please note that I indent one >> space per indentation level. >> > "msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc, > not ints. That did it. I originally used 1-4 like I did for the mode dictionaries, not realizing that the ints were so important; I figured they were just keys in the dictionary and that they could be anything, it was just easier to use ints. Now, I have changed my globals to 20-23 and everything seems to be going well. Thanks!! > Incidentally, you might want to change: > > if(not action_to_take): > > to: > > if action_to_take is None: > > in case any of the values happen to be 0 (if not now, then possibly at > some time in the future). Sorry, could you explain why you suggested this? I do not follow. Because of the if statement "if action_to_take:", I figured it was saying "if action_to_take was successfully set" or something else having a boolean value. Guess not? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From pruebauno at latinmail.com Tue Mar 23 14:09:45 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 11:09:45 -0700 (PDT) Subject: Unicode blues in Python3 References: Message-ID: Rami Chowdhury wrote: > On Tuesday 23 March 2010 10:33:33 nn wrote: > > I know that unicode is the way to go in Python 3.1, but it is getting > > in my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > #nntst2.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar) > > The following code works for me: > > $ cat nnout5.py > #!/usr/bin/python3.1 > > import sys > mychar = chr(253) > sys.stdout.write(mychar) > $ echo $(cat nnout) > ? > > Can I ask why you're using print() in the first place, rather than writing > directly to a file? Python 3.x, AFAIK, distinguishes between text and binary > files and will let you specify the encoding you want for strings you write. > > Hope that helps, > Rami > > > > > ./nntst2.py > > > > ISO8859-1 > > ? > > > > > ./nntst2.py >nnout2 > > > > Traceback (most recent call last): > > File "./nntst2.py", line 5, in > > print(mychar) > > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > > position 0: ordinal not in range(128) > > > > > cat nnout2 > > > > ascii > > > > ..Oh great! > > > > ok lets try this: > > #nntst3.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar.encode('latin1')) > > > > > ./nntst3.py > > > > ISO8859-1 > > b'\xfd' > > > > > ./nntst3.py >nnout3 > > > > > > cat nnout3 > > > > ascii > > b'\xfd' > > > > ..Eh... not what I want really. > > > > #nntst4.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > > print(mychar) > > > > > ./nntst4.py > > > > ISO8859-1 > > Traceback (most recent call last): > > File "./nntst4.py", line 6, in > > print(mychar) > > File "Python-3.1.2/Lib/codecs.py", line 356, in write > > self.stream.write(data) > > TypeError: must be str, not bytes > > > > ..OK, this is not working either. > > > > Is there any way to write a value 253 to standard output? > #nntst5.py import sys mychar=chr(253) sys.stdout.write(mychar) > ./nntst5.py >nnout5 Traceback (most recent call last): File "./nntst5.py", line 4, in sys.stdout.write(mychar) UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 0: ordinal not in range(128) equivalent to print. I use print so I can do tests and debug runs to the screen or pipe it to some other tool and then configure the production bash script to write the final output to a file of my choosing. From gherron at islandtraining.com Tue Mar 23 14:11:15 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 23 Mar 2010 11:11:15 -0700 Subject: Unicode blues in Python3 In-Reply-To: References: Message-ID: <4BA90443.6060307@islandtraining.com> nn wrote: > I know that unicode is the way to go in Python 3.1, but it is getting > in my way right now in my Unix scripts. How do I write a chr(253) to a > file? > Python3 make a distinction between bytes and string(i.e., unicode) types, and you are still thinking in the Python2 mode that does *NOT* make such a distinction. What you appear to want is to write a particular byte to a file -- so use the bytes type and a file open in binary mode: >>> b=bytes([253]) >>> f = open("abc", 'wb') >>> f.write(b) 1 >>> f.close() On unix (at least), the "od" program can verify the contents is correct: > od abc -d 0000000 253 0000001 Hope that helps. Gary Herron > #nntst2.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar) > > > ./nntst2.py > ISO8859-1 > ? > > > ./nntst2.py >nnout2 > Traceback (most recent call last): > File "./nntst2.py", line 5, in > print(mychar) > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > position 0: ordinal not in range(128) > > >> cat nnout2 >> > ascii > > ..Oh great! > > ok lets try this: > #nntst3.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar.encode('latin1')) > > >> ./nntst3.py >> > ISO8859-1 > b'\xfd' > > >> ./nntst3.py >nnout3 >> > > >> cat nnout3 >> > ascii > b'\xfd' > > ..Eh... not what I want really. > > #nntst4.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > print(mychar) > > > ./nntst4.py > ISO8859-1 > Traceback (most recent call last): > File "./nntst4.py", line 6, in > print(mychar) > File "Python-3.1.2/Lib/codecs.py", line 356, in write > self.stream.write(data) > TypeError: must be str, not bytes > > ..OK, this is not working either. > > Is there any way to write a value 253 to standard output? > From pruebauno at latinmail.com Tue Mar 23 14:46:33 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 11:46:33 -0700 (PDT) Subject: Unicode blues in Python3 References: Message-ID: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Gary Herron wrote: > nn wrote: > > I know that unicode is the way to go in Python 3.1, but it is getting > > in my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > Python3 make a distinction between bytes and string(i.e., unicode) > types, and you are still thinking in the Python2 mode that does *NOT* > make such a distinction. What you appear to want is to write a > particular byte to a file -- so use the bytes type and a file open in > binary mode: > > >>> b=bytes([253]) > >>> f = open("abc", 'wb') > >>> f.write(b) > 1 > >>> f.close() > > On unix (at least), the "od" program can verify the contents is correct: > > od abc -d > 0000000 253 > 0000001 > > > Hope that helps. > > Gary Herron > > > > > #nntst2.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar) > > > > > ./nntst2.py > > ISO8859-1 > > ? > > > > > ./nntst2.py >nnout2 > > Traceback (most recent call last): > > File "./nntst2.py", line 5, in > > print(mychar) > > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > > position 0: ordinal not in range(128) > > > > > >> cat nnout2 > >> > > ascii > > > > ..Oh great! > > > > ok lets try this: > > #nntst3.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar.encode('latin1')) > > > > > >> ./nntst3.py > >> > > ISO8859-1 > > b'\xfd' > > > > > >> ./nntst3.py >nnout3 > >> > > > > > >> cat nnout3 > >> > > ascii > > b'\xfd' > > > > ..Eh... not what I want really. > > > > #nntst4.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > > print(mychar) > > > > > ./nntst4.py > > ISO8859-1 > > Traceback (most recent call last): > > File "./nntst4.py", line 6, in > > print(mychar) > > File "Python-3.1.2/Lib/codecs.py", line 356, in write > > self.stream.write(data) > > TypeError: must be str, not bytes > > > > ..OK, this is not working either. > > > > Is there any way to write a value 253 to standard output? > > Actually what I want is to write a particular byte to standard output, and I want this to work regardless of where that output gets sent to. I am aware that I could do open('nnout','w',encoding='latin1').write(mychar) but I am porting a python2 program and don't want to rewrite everything that uses that script. From iamforufriends at gmail.com Tue Mar 23 15:21:50 2010 From: iamforufriends at gmail.com (MARRY) Date: Tue, 23 Mar 2010 12:21:50 -0700 (PDT) Subject: DRUNK MOM AND BOY... HOT CLIP..... Message-ID: <1ff5a046-d2c3-40d2-a1f7-7e3b20d30dd2@a37g2000prd.googlegroups.com> DRUNK MOM AND BOY... HOT CLIP..... http://123sex4u.blogspot.com/ http://123sex4u.blogspot.com/ http://123sex4u.blogspot.com/ http://123sex4u.blogspot.com/ From python at mrabarnett.plus.com Tue Mar 23 15:37:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Mar 2010 19:37:51 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: <4BA90072.9060305@mrabarnett.plus.com> Message-ID: <4BA9188F.407@mrabarnett.plus.com> Alex Hall wrote: > On 3/23/10, MRAB wrote: [snip] >> Incidentally, you might want to change: >> >> if(not action_to_take): >> >> to: >> >> if action_to_take is None: >> >> in case any of the values happen to be 0 (if not now, then possibly at >> some time in the future). > Sorry, could you explain why you suggested this? I do not follow. > Because of the if statement "if action_to_take:", I figured it was > saying "if action_to_take was successfully set" or something else > having a boolean value. Guess not? > The code: globalFuncs.get (msg.wParam) returns None if the key isn't in the dict. 'if' and 'while' statements treat other objects than just True as True, in fact anything for which bool() returns True. For example: bool(100) returns True bool([1, 2, 3]) returns True bool('some text') returns True but: bool(0) returns False bool([]) returns False bool('') returns False bool(None) returns False I also just noticed that you don't give action_to_take a default value before checking whether it's a hotkey. Suppose that "msg.message == win32con.WM_HOTKEY" was False: if msg.message == win32con.WM_HOTKEY: action_to_take=globalFuncs.get (msg.wParam) if(not action_to_take): It would get to "if(not action_to_take):" and either find that action_to_take wasn't defined, or use the value from the previous pass through the loop. From bahesanhak at gmail.com Tue Mar 23 15:48:19 2010 From: bahesanhak at gmail.com (=?UTF-8?B?2YXYpNmF2YYg2YXYtdmE2K0=?=) Date: Tue, 23 Mar 2010 12:48:19 -0700 (PDT) Subject: Miracles of the devil and beat of the revolution of religious reform Message-ID: <16ec4cd6-a68d-4ba4-a55f-8d75d93358ca@b7g2000yqd.googlegroups.com> Follow what god revealed to the Almighty Peace be upon you Those who wish to familiarized themselves after you click on the link please wait a little until it opens the link Miracles of the devil and beat of the revolution of religious reform http://www.ushaaqallah.com/forum/viewtopic.php?f=22&t=19225&sid=49b706e316461bcd768accfb7ccf031c Peace be upon you From stefan_ml at behnel.de Tue Mar 23 15:57:32 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Mar 2010 20:57:32 +0100 Subject: Unicode blues in Python3 In-Reply-To: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: nn, 23.03.2010 19:46: > Actually what I want is to write a particular byte to standard output, > and I want this to work regardless of where that output gets sent to. > I am aware that I could do > open('nnout','w',encoding='latin1').write(mychar) but I am porting a > python2 program and don't want to rewrite everything that uses that > script. Are you writing text or binary data to stdout? Stefan From debatem1 at gmail.com Tue Mar 23 16:04:55 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 23 Mar 2010 16:04:55 -0400 Subject: Python is cool!! In-Reply-To: <4BA8F56D.6060305@timgolden.me.uk> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> Message-ID: On Tue, Mar 23, 2010 at 1:07 PM, Tim Golden wrote: > On 23/03/2010 16:55, Jose Manuel wrote: >> >> I have been learning Python, and it is amazing .... I am using the >> tutorial that comes with the official distribution. >> >> At the end my goal is to develop applied mathematic in engineering >> applications to be published on the Web, specially on app. oriented to >> simulations and control systems, I was about to start learning Java >> but I found Python which seems easier to learn that Java. >> >> Would it be easy to integrate Python in Web pages with HTML? I have >> read many info on Internet saying it is, and I hope so .... > > You probably want to be looking at IronPython and Silverlight. > In fact, the prolific Michael Foord has already produced an > example of this, which gives you the Python tutorial online! > > ?http://trypython.org > > TJG Granted that I know next to nothing about webwork, but is there a reason why you recommended a competing, nonstandard technology rather than simply pointing him towards more standards compliant tools that exist to do exactly what he asked for? Seems a bit dodgy to advocate a closed solution when the alternative has 100% market share. Geremy Condra From mail at timgolden.me.uk Tue Mar 23 16:12:27 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 20:12:27 +0000 Subject: Python is cool!! In-Reply-To: References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> Message-ID: <4BA920AB.2070206@timgolden.me.uk> On 23/03/2010 20:04, geremy condra wrote: > On Tue, Mar 23, 2010 at 1:07 PM, Tim Golden wrote: >> On 23/03/2010 16:55, Jose Manuel wrote: >>> Would it be easy to integrate Python in Web pages with HTML? I have >>> read many info on Internet saying it is, and I hope so .... >> >> You probably want to be looking at IronPython and Silverlight. >> In fact, the prolific Michael Foord has already produced an >> example of this, which gives you the Python tutorial online! >> >> http://trypython.org >> >> TJG > > Granted that I know next to nothing about webwork, but > is there a reason why you recommended a competing, > nonstandard technology rather than simply pointing him > towards more standards compliant tools that exist to do > exactly what he asked for? Seems a bit dodgy to > advocate a closed solution when the alternative has 100% > market share. I can't say I thought *very* hard before sending that but... The OP asked for "integrate Python in Web Pages with HTML" which I understood -- perhaps wrongly -- to mean: run Python in the browser. The only two ways I'm aware of doing that in Python are the undersupported Python-as-IE-scripting-language and IronPython/Silverlight. Now I look again, I realise that he may have meant simply: Python as a server-side toolset with possible support for Javascript. In which case, of course, my answer was not so applicable. TJG From pruebauno at latinmail.com Tue Mar 23 16:36:20 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 13:36:20 -0700 (PDT) Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: Stefan Behnel wrote: > nn, 23.03.2010 19:46: > > Actually what I want is to write a particular byte to standard output, > > and I want this to work regardless of where that output gets sent to. > > I am aware that I could do > > open('nnout','w',encoding='latin1').write(mychar) but I am porting a > > python2 program and don't want to rewrite everything that uses that > > script. > > Are you writing text or binary data to stdout? > > Stefan latin1 charset text. From torriem at gmail.com Tue Mar 23 16:47:20 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Mar 2010 14:47:20 -0600 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4BA928D8.4050903@gmail.com> Jose Manuel wrote: > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... Django is, among several other similar projects and frameworks, very popular for generating web apps in Python. I have only used Django and it works very well. From chambon.pascal at wanadoo.fr Tue Mar 23 16:49:14 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Tue, 23 Mar 2010 21:49:14 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> Message-ID: <4BA9294A.9090703@wanadoo.fr> Gabriel Genellina a ?crit : > > En Mon, 22 Mar 2010 15:20:39 -0300, Pascal Chambon > escribi?: >> >> Allright, here is more concretely the problem : >> >> ERROR:root:An error >> Traceback (most recent call last): >> File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c >> return d() >> File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d >> def d(): raise ValueError >> ValueError >> >>> >> >> As you see, the traceback only starts from function c, which handles >> the exception. >> It doesn't show main(), a() and b(), which might however be (and are, >> in my case) critical to diagnose the severity of the problem (since >> many different paths would lead to calling c()). >> >> So the question is : is that possible to enforce, by a way or >> another, the retrieval of the FULL traceback at exception raising >> point, instead of that incomplete one ? > > Thanks for bringing this topic! I learned a lot trying to understand > what happens. > > The exception traceback (what sys.exc_info()[2] returns) is *not* a > complete stack trace. The sys module documentation is wrong [1] when > it says "...encapsulates the call stack at the point where the > exception originally occurred." > > The Language Reference is more clear [2]: "Traceback objects represent > a stack trace of an exception. A traceback object is created when an > exception occurs. When the search for an exception handler unwinds the > execution stack, at each unwound level a traceback object is inserted > in front of the current traceback. When an exception handler is > entered, the stack trace is made available to the program." > > That is, a traceback holds only the *forward* part of the stack: the > frames already exited when looking for an exception handler. Frames > going from the program starting point up to the current execution > point are *not* included. > > Conceptually, it's like having two lists: stack and traceback. The > complete stack trace is always stack+traceback. At each step (when > unwinding the stack, looking for a frame able to handle the current > exception) an item is popped from the top of the stack (last item) and > inserted at the head of the traceback. > > The traceback holds the "forward" path (from the current execution > point, to the frame where the exception was actually raised). It's a > linked list, its tb_next attribute holds a reference to the next item; > None marks the last one. > > The "back" path (going from the current execution point to its caller > and all the way to the program entry point) is a linked list of > frames; the f_back attribute points to the previous one, or None. > > In order to show a complete stack trace, one should combine both. The > traceback module contains several useful functions: extract_stack() + > extract_tb() are a starting point. The simplest way I could find to > make the logging module report a complete stack is to monkey patch > logging.Formatter.formatException so it uses format_exception() and > format_stack() combined (in fact it is simpler than the current > implementation using a StringIO object): Good point, there is clearly a distinction between "stack trace" and "exception traceback" that I didn't know (actually, it seems no one makes it in computer literature). > Good catch, Gabriel. > > There should be no need to monkey-patch the logging module - it's > better if I include the change in the module itself. The only > remaining question is that of backward compatibility, but I can do > this for Python 2.7/3.2 only so that won't be an issue. It's probably > a good idea to log an issue on the bug tracker, though, so we have > some history for the change - do you want to do that, or shall I? > > Regards, > > Vinay Sajip > Well having it fixed in logging would be great, but that kind of information is good to have in other circumstances, so shouldn't we rather advocate the availability of this "stack trace part" in exc_info too ? This way, people like me who consider frames as black magic wouldn't need to meet complex stuffs as "traceback.format_stack(ei[2].tb_frame.f_back" :p Should I open an issue for this evolution of exceptiuon handling, or should we content ourselves of this "hacking" of frame stck ? Regards, Pascal From pmaupin at gmail.com Tue Mar 23 17:24:30 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 23 Mar 2010 14:24:30 -0700 (PDT) Subject: Python is cool!! References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> Message-ID: <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> On Mar 23, 3:12?pm, Tim Golden wrote: > I can't say I thought *very* hard before sending that but... > The OP asked for "integrate Python in Web Pages with HTML" > which I understood -- perhaps wrongly -- to mean: run Python > in the browser. The only two ways I'm aware of doing that > in Python are the undersupported Python-as-IE-scripting-language > and IronPython/Silverlight. If I had to run Python in a browser, the first thing I would do is turn to Pyjamas: http://pyjs.org/ Regards, Pat From anand.shashwat at gmail.com Tue Mar 23 17:50:16 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 03:20:16 +0530 Subject: Python is cool!! In-Reply-To: <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> Message-ID: There is a project PyWhip (renamed as PyKata) which aims for the same purpose. Google AppEmgine + Django does the trick for that. May be you can take an inspiration or two from there especially because all code is open to/for you. ~l0nwlf On Wed, Mar 24, 2010 at 2:54 AM, Patrick Maupin wrote: > On Mar 23, 3:12 pm, Tim Golden wrote: > > I can't say I thought *very* hard before sending that but... > > The OP asked for "integrate Python in Web Pages with HTML" > > which I understood -- perhaps wrongly -- to mean: run Python > > in the browser. The only two ways I'm aware of doing that > > in Python are the undersupported Python-as-IE-scripting-language > > and IronPython/Silverlight. > > If I had to run Python in a browser, the first thing I would do is > turn to Pyjamas: http://pyjs.org/ > > Regards, > Pat > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Mar 23 18:09:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 23 Mar 2010 18:09:36 -0400 Subject: Pythonic way to trim and keep leading and trailing whitespace Message-ID: <1269382176.23636.1366365237@webmail.messagingengine.com> I'm looking for a pythonic way to trim and keep leading whitespace in a string. Use case: I have a bunch of text strings with various amounts of leading and trailing whitespace (spaces and tabs). I want to grab the leading and trailing whitespace, save it, surround the remaining text with html tags, and then add back the leading and trailing whitespace. The only solution I can think of is regex, and that makes me think of the 2 proverbial problems that come with that :) Is there a 'better' solution than regex for this scenario? (Seems like this would be a common type of string processing). Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From dpawlows at umich.edu Tue Mar 23 18:13:36 2010 From: dpawlows at umich.edu (dpawlows) Date: Tue, 23 Mar 2010 18:13:36 -0400 Subject: Posting to https Message-ID: <0BAF76CC-8D91-4872-A5F2-EEC9F15C97AF@umich.edu> I am trying to obtain data on a https site, but everytime I try to access the data that is behind the logon screen, I get the logon page instead. I was able to successfully do a test problem: import sys, urllib2, urllib zipcode = "48103" url = 'http://www.wunderground.com/cgi-bin/findweather/getForecast' data = urllib.urlencode([('query', zipcode)]) req = urllib2.Request(url) fd = urllib2.urlopen(req, data) while 1: data = fd.read(1024) if not len(data): break sys.stdout.write(data) which performed as I expected. However, for the url 'https://secure.umcu.org/cgi-bin/mcw000.cgi?MCWSTART' with data = ... {'HBUSERNAME':username,'PASSWORD':password} I was sent just the logon screen. Am I missing something important that has to do with interaction with javascript, https, or cgi, or something completely different? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Tue Mar 23 18:16:45 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 23 Mar 2010 17:16:45 -0500 Subject: Python is cool!! In-Reply-To: References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> Message-ID: On Tue, Mar 23, 2010 at 4:50 PM, Shashwat Anand wrote: > There is a project PyWhip (renamed as PyKata) which aims for the same > purpose. Google AppEmgine + Django does the trick for that. May be you can > take an inspiration or two from there especially because all code is open > to/for you. But, if I understand PyWhip/PyKata after glancing at the project page, it doesn't actually run code in the browser... Regards, Pat From emile at fenx.com Tue Mar 23 18:34:48 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 23 Mar 2010 15:34:48 -0700 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <1269382176.23636.1366365237@webmail.messagingengine.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: On 3/23/2010 3:09 PM python at bdurham.com said... > I'm looking for a pythonic way to trim and keep leading > whitespace in a string. > > Use case: I have a bunch of text strings with various amounts of > leading and trailing whitespace (spaces and tabs). I want to grab > the leading and trailing whitespace, save it, surround the > remaining text with html tags, and then add back the leading and > trailing whitespace. I'd do it this way: target = ' spam and eggs ' stripped = target.strip() replaced = target.replace(stripped,"%s" % stripped) HTH, Emile > > The only solution I can think of is regex, and that makes me > think of the 2 proverbial problems that come with that :) > > Is there a 'better' solution than regex for this scenario? (Seems > like this would be a common type of string processing). > > Thanks, > Malcolm > > From daniel.chiquito at gmail.com Tue Mar 23 18:39:15 2010 From: daniel.chiquito at gmail.com (Daniel Chiquito) Date: Tue, 23 Mar 2010 18:39:15 -0400 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <1269382176.23636.1366365237@webmail.messagingengine.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: <9deff17c1003231539kfdef1cfn5fd45e06e330d613@mail.gmail.com> As far as I know, I don't think there is anything that strips it and returns the material that was stripped. Regex's would be your best bet. Daniel On Tue, Mar 23, 2010 at 6:09 PM, wrote: > I'm looking for a pythonic way to trim and keep leading whitespace in a > string. > > Use case: I have a bunch of text strings with various amounts of leading > and trailing whitespace (spaces and tabs). I want to grab the leading and > trailing whitespace, save it, surround the remaining text with html tags, > and then add back the leading and trailing whitespace. > > The only solution I can think of is regex, and that makes me think of the 2 > proverbial problems that come with that :) > > Is there a 'better' solution than regex for this scenario? (Seems like this > would be a common type of string processing). > > Thanks, > Malcolm > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- ~ -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Tue Mar 23 18:42:47 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 23 Mar 2010 23:42:47 +0100 Subject: Unicode blues in Python3 In-Reply-To: References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: <4BA943E7.5000202@v.loewis.de> nn wrote: > > Stefan Behnel wrote: >> nn, 23.03.2010 19:46: >>> Actually what I want is to write a particular byte to standard output, >>> and I want this to work regardless of where that output gets sent to. >>> I am aware that I could do >>> open('nnout','w',encoding='latin1').write(mychar) but I am porting a >>> python2 program and don't want to rewrite everything that uses that >>> script. >> Are you writing text or binary data to stdout? >> >> Stefan > > latin1 charset text. Are you sure about that? If you carefully reconsider, could you come to the conclusion that you are not writing text at all, but binary data? If it really was text that you write, why do you need to use U+00FD (LATIN SMALL LETTER Y WITH ACUTE). To my knowledge, that character is really infrequently used in practice. So that you try to write it strongly suggests that it is not actually text what you are writing. Also, your formulation suggests the same: "Is there any way to write a value 253 to standard output?" If you would really be writing text, you'd ask "Is there any way to write '?' to standard output?" Regards, Martin From vinay_sajip at yahoo.co.uk Tue Mar 23 18:43:40 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 23 Mar 2010 15:43:40 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> Message-ID: <0301d0b5-5d5d-436f-a342-16fe81b340d7@t41g2000yqt.googlegroups.com> On Mar 23, 8:49?pm, Pascal Chambon wrote: > > Should I open an issue for this evolution of exceptiuon handling, or > should we content ourselves of this "hacking" of frame stck ? > Possibly worth raising an issue (not logging-related), but perhaps it's worth seeing if this has come up before creating the issue. Regards, Vinay Sajip From python at bdurham.com Tue Mar 23 18:45:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 23 Mar 2010 18:45:36 -0400 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: <1269384336.29264.1366374513@webmail.messagingengine.com> Emile, > target = ' spam and eggs ' > stripped = target.strip() > replaced = target.replace(stripped,"%s" % stripped) Brilliant! That's just the type of clever solution I was looking for. Thank you! Malcolm ----- Original message ----- From: "Emile van Sebille" To: python-list at python.org Date: Tue, 23 Mar 2010 15:34:48 -0700 Subject: Re: Pythonic way to trim and keep leading and trailing whitespace On 3/23/2010 3:09 PM python at bdurham.com said... > I'm looking for a pythonic way to trim and keep leading > whitespace in a string. > > Use case: I have a bunch of text strings with various amounts of > leading and trailing whitespace (spaces and tabs). I want to grab > the leading and trailing whitespace, save it, surround the > remaining text with html tags, and then add back the leading and > trailing whitespace. I'd do it this way: target = ' spam and eggs ' stripped = target.strip() replaced = target.replace(stripped,"%s" % stripped) HTH, Emile > > The only solution I can think of is regex, and that makes me > think of the 2 proverbial problems that come with that :) > > Is there a 'better' solution than regex for this scenario? (Seems > like this would be a common type of string processing). > > Thanks, > Malcolm > > -- http://mail.python.org/mailman/listinfo/python-list From anand.shashwat at gmail.com Tue Mar 23 18:50:25 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 04:20:25 +0530 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <9deff17c1003231539kfdef1cfn5fd45e06e330d613@mail.gmail.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> <9deff17c1003231539kfdef1cfn5fd45e06e330d613@mail.gmail.com> Message-ID: regex is not goto that you should always avoid using it. It have its own use-case, here regex solution is intuitive although @emile have done this for you via string manpulation. On Wed, Mar 24, 2010 at 4:09 AM, Daniel Chiquito wrote: > As far as I know, I don't think there is anything that strips it and > returns the material that was stripped. Regex's would be your best bet. > > Daniel > > On Tue, Mar 23, 2010 at 6:09 PM, wrote: > >> I'm looking for a pythonic way to trim and keep leading whitespace in a >> string. >> >> Use case: I have a bunch of text strings with various amounts of leading >> and trailing whitespace (spaces and tabs). I want to grab the leading and >> trailing whitespace, save it, surround the remaining text with html tags, >> and then add back the leading and trailing whitespace. >> >> The only solution I can think of is regex, and that makes me think of the >> 2 proverbial problems that come with that :) >> >> Is there a 'better' solution than regex for this scenario? (Seems like >> this would be a common type of string processing). >> >> Thanks, >> Malcolm >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > ~ > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue Mar 23 19:38:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Mar 2010 18:38:10 -0500 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <1269382176.23636.1366365237@webmail.messagingengine.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: <4BA950E2.4020708@tim.thechases.com> python at bdurham.com wrote: > I'm looking for a pythonic way to trim and keep leading > whitespace in a string. > > Use case: I have a bunch of text strings with various amounts of > leading and trailing whitespace (spaces and tabs). I want to grab > the leading and trailing whitespace, save it, surround the > remaining text with html tags, and then add back the leading and > trailing whitespace. > > The only solution I can think of is regex, and that makes me > think of the 2 proverbial problems that come with that :) Just in case you're okay with a regexp solution, you can use >>> s = "\t\tabc def " >>> import re >>> r = re.compile(r'^(\s*)(.*?)(\s*)$') >>> m = re.match(s) >>> m.groups() ('\t\t', 'abc def', ' ') >>> leading, text, trailing = m.groups() While Emile's solution works nicely for your particular use-case, in the event you need to discern between leading/trailing whitespace, the above makes it pretty easy. -tkc From martin.hellwig at dcuktec.org Tue Mar 23 19:57:23 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 23 Mar 2010 23:57:23 +0000 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: On 03/23/10 23:38, Tim Chase wrote: > Just in case you're okay with a regexp solution, you can use > > >>> s = "\t\tabc def " > >>> import re > >>> r = re.compile(r'^(\s*)(.*?)(\s*)$') > >>> m = re.match(s) > >>> m.groups() > ('\t\t', 'abc def', ' ') > >>> leading, text, trailing = m.groups() Ahhh regex, the hammer, Swiss Army Knife, cable tie, duct tape, superglue and soldering iron, all wrapped in one*. Mastery of it will enable you to drive the nails in your coffin at an incomparable speed. :-) *Yes I was a sysadmin, why do you ask? -- mph From nilly16 at yahoo.com Tue Mar 23 20:05:09 2010 From: nilly16 at yahoo.com (Jimbo) Date: Tue, 23 Mar 2010 17:05:09 -0700 (PDT) Subject: Advice Criticism on Python App Message-ID: I have made a Python App(really script) that will check a stocks current values from a website & save that data to a SQLite 3 database. I am looking for any suggestions & criticisms on what I should do better or anything at all but mainly in these areas: [QUOTE] - Correct Python Layout of code - Correct error checking: Am I catching all my errors or are my exceptions not specific enough? Should I be using more try excepts inside my functions? - Are there any areas where huge errors, bugs etc could occur that I have not compensated for? - I am also looking for suggestions on how to write a function better, so if you think that function is really bad & should be rewritten completely or something I would really like to hear it. - Anything else that you see - Is python meant to be used in the way I have used it? To make a 'semi detailed' app?[/QUOTE] Any advice criticism would be really helpful. App: [CODE]""" *Stock Data Builder* Algorithm: - Search website for stock - Get website HTML source code - Search code for target stock data(price,dividends,etc..) - Add data to text file """ import sys import os import sqlite3 import datetime import time import urllib2 ### Global Variables ### menu = "***Stock Program*** \n\n1. Add a Stock to track \n2. Get Todays Tracking Data \n3. Exit \nEnter decision: " target = '

",sourceCode) getStockData(targetData,Stock) Stock.printStats() #writeStockToDatabase(conn,Stock) else: print "You must first identify a stock to follow. \nPlease select option 1." elif (decision==3): print "Thank you for using Stock Program. Goodbye.\n" programEnd = True; # Exit program conn.close() return 0 # End program main()[/CODE] From clp2 at rebertia.com Tue Mar 23 21:32:11 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Mar 2010 18:32:11 -0700 Subject: Advice Criticism on Python App In-Reply-To: References: Message-ID: <50697b2c1003231832i280655adu9c52ee45f9c1de15@mail.gmail.com> On Tue, Mar 23, 2010 at 5:05 PM, Jimbo wrote: > I have made a Python App(really script) that will check a stocks > current values from a website & save that data to a SQLite 3 database. > > I am looking for any suggestions & criticisms on what I should do > better or anything at all but mainly in these areas: > Any advice criticism would be really helpful. Complying with Python naming conventions would be one place to start: * Class names should be in StudlyCaps (so class "Stock", not class "stock"). * Constants should be in UPPERCASE_WITH_UNDERSCORES. * Most other names should be words_separated_by_underscores, not camelCaseLikeThis; FWIW, I'm not a fan of this part of the guideline personally. Also, conditions don't need parentheses around them. So: if (decision == 1): #WRONG! harder to read, extra syntactic noise if decision == 1: #RIGHT For many more style details, see PEP 8 -- Style Guide for Python Code: http://www.python.org/dev/peps/pep-0008/ Additionally, the "return 0" in main() serves no purpose; the return value isn't used as the exit code for the program. You can either eliminate the line entirely or use plain "return" if you want the extra clarity. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Tue Mar 23 21:36:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Mar 2010 01:36:31 +0000 Subject: Advice Criticism on Python App In-Reply-To: References: Message-ID: <4BA96C9F.9080301@mrabarnett.plus.com> Jimbo wrote: > I have made a Python App(really script) that will check a stocks > current values from a website & save that data to a SQLite 3 database. > > I am looking for any suggestions & criticisms on what I should do > better or anything at all but mainly in these areas: > [QUOTE] > - Correct Python Layout of code > - Correct error checking: Am I catching all my errors or are my > exceptions not specific enough? Should I be using more try excepts > inside my functions? > - Are there any areas where huge errors, bugs etc could occur that I > have not compensated for? > - I am also looking for suggestions on how to write a function better, > so if you think that function is really bad & should be rewritten > completely or something I would really like to hear it. > - Anything else that you see > - Is python meant to be used in the way I have used it? To make a > 'semi detailed' app?[/QUOTE] > > Any advice criticism would be really helpful. > > App: > [CODE]""" > *Stock Data Builder* > Algorithm: > - Search website for stock > - Get website HTML source code > - Search code for target stock data(price,dividends,etc..) > - Add data to text file > """ > > import sys > import os > import sqlite3 > import datetime > import time > import urllib2 > > ### Global Variables ### > menu = "***Stock Program*** \n\n1. Add a Stock to track \n2. Get > Todays Tracking Data \n3. Exit \nEnter decision: " > target = '",sourceCode) > getStockData(targetData,Stock) > Stock.printStats() > #writeStockToDatabase(conn,Stock) > else: > print "You must first identify a stock to follow. > \nPlease select option 1." > elif (decision==3): > print "Thank you for using Stock Program. Goodbye.\n" > programEnd = True; # Exit program > > conn.close() > return 0 # End program > 'main' is called by the main program and its return value is never used, so just omit this return statement. > main()[/CODE] The recommended standard in Python is for names of classes to be CamelCase, names of constants to be UPPERCASE_WITH_UNDERSCORES, and names of everything else to be lowercase_with_underscores. From no.email at nospam.invalid Tue Mar 23 21:39:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Mar 2010 18:39:49 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> <7xpr2v2wd7.fsf@ruckus.brouhaha.com> Message-ID: <7xaaty4hwa.fsf@ruckus.brouhaha.com> Antoine Pitrou writes: >> See: http://www.cs.rice.edu/~scrosby/hash/ ... > Certainly interesting in a purely academic point of view, but in real > life if you want to cause a denial of service by overwhelming a server, > there are far more obvious options than trying to guess the server's use > of hash tables and trying to cause lots of collisions in them. If you look at the very low bandwidth used in some of those hashtable attacks, it's hard to see any other somewhat-generic attack that's comparably effective. Usually we think of "DOS" as involving massive botnets and the like, not a dribble of a few hundred characters per second. From vipshopper.us at hotmail.com Tue Mar 23 21:53:31 2010 From: vipshopper.us at hotmail.com (marrylin) Date: Tue, 23 Mar 2010 18:53:31 -0700 (PDT) Subject: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Message-ID: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Air jordan(1-24)shoes $33 UGG BOOT $50 Nike shox(R4,NZ,OZ,TL1,TL2,TL3) $35 Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 FREE SHIPPING From eire1130 at gmail.com Tue Mar 23 22:51:48 2010 From: eire1130 at gmail.com (JR) Date: Tue, 23 Mar 2010 19:51:48 -0700 (PDT) Subject: 'gcc' failed with exit status 1 Message-ID: <8e68f9ea-7c99-4d52-90f3-0ea90b8f5c57@z3g2000yqz.googlegroups.com> Hello All, I was hoping I could get some help with this issue with getting Cython to work. Earlier I had an issue that said "unable to find vcvarsall.bat" and it turns out there is an active bug report that covers that issue (I have a 64 bit windows system). I still hadn't installed 3.1.2, so I did that tonight and now I have the issue below. Any thoughts on what I am doing wrong? Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\James>cd C:\Python31 C:\Python31>python setup.py build_ext --inplace running build_ext cythoning hello.pyx to hello.c Error converting Pyrex file to C: ------------------------------------------------------------ ... def say_hello_to(name): ^ ------------------------------------------------------------ C:\Python31\hello.pyx:1:23: Unrecognized character building 'hello' extension C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python31\include - IC:\Pytho n31\PC -c hello.c -o build\temp.win-amd64-3.1\Release\hello.o hello.c:1:2: #error Do not use this file, it is the result of a failed Cython co mpilation. error: command 'gcc' failed with exit status 1 C:\Python31> From steven at REMOVE.THIS.cybersource.com.au Wed Mar 24 00:41:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Mar 2010 04:41:01 GMT Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: On Tue, 23 Mar 2010 11:46:33 -0700, nn wrote: > Actually what I want is to write a particular byte to standard output, > and I want this to work regardless of where that output gets sent to. What do you mean "work"? Do you mean "display a particular glyph" or something else? In bash: $ echo -e "\0101" # octal 101 = decimal 65 A $ echo -e "\0375" # decimal 253 ? but if I change the terminal encoding, I get this: $ echo -e "\0375" ? Or this: $ echo -e "\0375" ? depending on which encoding I use. I think your question is malformed. You need to work out what behaviour you actually want, before you can ask for help on how to get it. -- Steven From stefan_ml at behnel.de Wed Mar 24 02:48:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 24 Mar 2010 07:48:58 +0100 Subject: 'gcc' failed with exit status 1 In-Reply-To: <8e68f9ea-7c99-4d52-90f3-0ea90b8f5c57@z3g2000yqz.googlegroups.com> References: <8e68f9ea-7c99-4d52-90f3-0ea90b8f5c57@z3g2000yqz.googlegroups.com> Message-ID: JR, 24.03.2010 03:51: > I was hoping I could get some help with this issue with getting Cython > to work. Earlier I had an issue that said "unable to find > vcvarsall.bat" and it turns out there is an active bug report that > covers that issue (I have a 64 bit windows system). I still hadn't > installed 3.1.2, so I did that tonight and now I have the issue below. > Any thoughts on what I am doing wrong? > > > Microsoft Windows [Version 6.1.7600] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\James>cd C:\Python31 > > C:\Python31>python setup.py build_ext --inplace > running build_ext > cythoning hello.pyx to hello.c > > Error converting Pyrex file to C: > ------------------------------------------------------------ > ... > def say_hello_to(name): > ^ > ------------------------------------------------------------ > > C:\Python31\hello.pyx:1:23: Unrecognized character Given that you're on Windows, this looks like a known bug in Cython: http://trac.cython.org/cython_trac/ticket/520 This is due to the lack of universal newline support in the codecs module, which has been fixed in the new Py2.6+ 'io' module. A patch for Cython that switches to the new 'io' module and works around this issue in older Python versions is available: http://hg.cython.org/cython-devel/raw-rev/751bdd38b55c That being said, the simplest way to work around this issue is to switch to Unix line endings in your source file. Most editors support this without problems. Stefan From xenoszh at gmail.com Wed Mar 24 03:23:39 2010 From: xenoszh at gmail.com (Parker) Date: Wed, 24 Mar 2010 00:23:39 -0700 (PDT) Subject: Python is cool!! References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: On Mar 23, 4:55?pm, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... > > Any opinion this must be the one you want http://web2py.com/ From stef.mientki at gmail.com Wed Mar 24 03:52:02 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 24 Mar 2010 08:52:02 +0100 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4BA9C4A2.40100@gmail.com> On 23-03-2010 17:55, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... > > Any opinion > you might take a look at http://www.sagemath.org/ cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Mar 24 04:03:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 05:03:46 -0300 Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> <0301d0b5-5d5d-436f-a342-16fe81b340d7@t41g2000yqt.googlegroups.com> Message-ID: En Tue, 23 Mar 2010 19:43:40 -0300, Vinay Sajip escribi?: > On Mar 23, 8:49 pm, Pascal Chambon wrote: >> >> Should I open an issue for this evolution of exceptiuon handling, or >> should we content ourselves of this "hacking" of frame stck ? > > Possibly worth raising an issue (not logging-related), but perhaps > it's worth seeing if this has come up before creating the issue. There is, from 2006: http://bugs.python.org/issue1553375 I'll add a patch+tests to this issue. -- Gabriel Genellina From joho.smithury at gmail.com Wed Mar 24 05:07:26 2010 From: joho.smithury at gmail.com (John Smithury) Date: Wed, 24 Mar 2010 17:07:26 +0800 Subject: Where can i reference the "regular expressions" Message-ID: Dear pythoners, I'm a new member to studay the python, i wan't to studay the "regular expressions" handle like below: ==============source============ the is name ==============source end========= after convert, the result like below: -------------------------result------------------------ {'t','t','e'}, {'i','s'}, {'n','a','m','e'} -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Wed Mar 24 05:18:14 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 24 Mar 2010 10:18:14 +0100 Subject: Where can i reference the "regular expressions" In-Reply-To: References: Message-ID: <6faf39c91003240218x770290c3l8c70ea5c3e70f6ac@mail.gmail.com> On Wed, Mar 24, 2010 at 10:07 AM, John Smithury wrote: > Dear pythoners, > > I'm a new member to studay the python, i wan't to studay the "regular > expressions" handle like below: > > ==============source============ > the > is > name > ==============source end========= > > > after convert, the result like below: > > -------------------------result------------------------ > {'t','t','e'}, > {'i','s'}, > {'n','a','m','e'} What did you think of yourself, and where did you get into the "I don't know what to do now" place? Why do you think your problem would have to do with regular expressions? -- Andr? Engels, andreengels at gmail.com From __peter__ at web.de Wed Mar 24 05:34:31 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Mar 2010 10:34:31 +0100 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Vinay Sajip wrote: > Sorry I'm a little late to this discussion. I could add a _findCaller > function to the module (not part of the public API, but replaceable by > someone who really needs to) which does the heavy lifting, and > Logger.findCaller just calls it. Then those who need to can implement > their own strategy, without needing to jump through hoops. Does that > approach sound helpful? You mean you'd have to monkey-patch logging._findCaller() instead of overriding logging.Logger.findCaller()? I don't see a big advantage in that. Here's an alternative proposal: simplify findCaller() by moving part of the code into a generator: def callers(self): """ Walk up the call stack. Helper for findCaller(). """ f = currentframe() #On some versions of IronPython, currentframe() returns None if #IronPython isn't run with -X:Frames. if f is not None: f = f.f_back while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) yield filename, f.f_lineno, co.co_name f = f.f_back def findCaller(self): """ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ for filename, lineno, funcname in self.callers(): if filename != _srcfile: return filename, lineno, funcname return UNKNOWN_CALLER Another simplification might be to have setLoggerClass() implicitly set the root logger and to drop the distinct RootLogger class completely. Note that I have no strong opinion on all this. If you leave things as is I'm fine with that. Peter From mail at timgolden.me.uk Wed Mar 24 05:41:00 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Mar 2010 09:41:00 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: Message-ID: <4BA9DE2C.6060307@timgolden.me.uk> On 23/03/2010 17:01, Alex Hall wrote: > Hi all, but mainly Tim Golden: > Tim, I am using your wonderful message loop for keyboard input, the > one on your site that you pointed me to a few months ago. It has been > working perfectly as long as I had only one dictionary of keys mapping > to one dictionary of functions, but now I want two of each. My program > has different modes, which may have varying keystrokes, and I also > have some global keystrokes which are the same across all modes, like > exiting or switching modes. I cannot figure out how to make the > message loop look in two dictionaries at onc. I tried using an if, > saying that if action_to_take was not set in the mode-specific > dictionary then look at the global dictionary, but it is like it is > never looking in the global dictionary at all. I get no syntax errors > or problems when running the program, so it has to be something in my > logic. There's definitely some confusion, as MRAB picked up, with the globalkeys / globalfuncs thing. I can see no problem with simply defining an additional pair of dictionaries parallel with each of the keys/funcs dictionaries (note that the numbers are different from those of othe other dictionaries as these are the registration ids of the hotkeys): global_keys = { 100: (68, win32com.MOD_ALT | win32con.MOD_CONTROL ...), ... } global_funcs = { 100 : dict.ShowLookupDialog, ... } Then your central action code could be something like: action_to_take = global_funcs.get (msg.wParam) or HOTKEY_ACTIONS.get (msg.wParam) if action_to_take: action_to_take () This assumes that the funcs dictionaries will only ever contain a valid function, so the only possible Falsish value will arise from the get returning None. TJG BTW, you're shadowing a couple of builtins: global & dict which might give you problems later if you needed them. There are other issues with the structure of your code but nothing a little refactoring couldn't sort out if you felt so inclined. From andreengels at gmail.com Wed Mar 24 05:50:37 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 24 Mar 2010 10:50:37 +0100 Subject: Where can i reference the "regular expressions" In-Reply-To: References: <6faf39c91003240218x770290c3l8c70ea5c3e70f6ac@mail.gmail.com> Message-ID: <6faf39c91003240250p3327c795k6544ad089a96c464@mail.gmail.com> On Wed, Mar 24, 2010 at 10:34 AM, John Smithury wrote: > ==============source============ > the > is > name > ==============source end========= > > First, get the word only(discard the "" and ""), it can use > regular expression, right? > > the > is > name > Second, get a charactor in each word and compose like format {'t','h','e'} >>>>for a in line > > > Most import is learning the "regular expressions" var this example. Okay, then I'll go into that part. regex = re.compile("([^<>]*)") [^<>] here means "any character but < or >" * means that we have any number (zero or more) of such characters The brackets mean that this is the part of the expression we are interested in (the group) The expression as a whole thus means: First , then the part we are interested in, which is a random string of things that are not < or >, then To use this expression (assuming 'text' is the string you want to check: result = regex.findall(text) will find all occurences of the regular expression, and provide you with the content of the group. -- Andr? Engels, andreengels at gmail.com From jeanmichel at sequans.com Wed Mar 24 06:37:17 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Mar 2010 11:37:17 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BA9EB5D.5050003@sequans.com> Peter Otten wrote: > Vinay Sajip wrote: > > >> Sorry I'm a little late to this discussion. I could add a _findCaller >> function to the module (not part of the public API, but replaceable by >> someone who really needs to) which does the heavy lifting, and >> Logger.findCaller just calls it. Then those who need to can implement >> their own strategy, without needing to jump through hoops. Does that >> approach sound helpful? >> > > [snip] > > Note that I have no strong opinion on all this. If you leave things as is > I'm fine with that. > > Peter > Agreed, I'm not sure it's worth the effort Vinay. JM From mehgcap at gmail.com Wed Mar 24 06:43:24 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 06:43:24 -0400 Subject: exiting threaded program? Message-ID: Hi all, I have a program with a timer in it, therefore I have multiple threads. My method of exiting by using "user32.PostQuitMessage (0)" no longer seems to be doing the job since I added the timer. What else do I have to do to close my program? I say it is not closing because, before, I would be returned to a prompt in the cmd line, but now I cannot type in the cmd line window even after the program supposedly closes, whereas before I could have. Thanks. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From vinay_sajip at yahoo.co.uk Wed Mar 24 06:45:32 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 24 Mar 2010 03:45:32 -0700 (PDT) Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: On Mar 24, 9:34?am, Peter Otten <__pete... at web.de> wrote: > > You mean you'd have to monkey-patchlogging._findCaller() instead of > overridinglogging.Logger.findCaller()? > > I don't see a big advantage in that. > Only that you just have to replace a function, and not have to subclass Logger + override findCaller. And it's not especially monkey- patching if the function is put there specifically to be replaced when needed :-) > Another simplification might be to have setLoggerClass() implicitly set the > root logger and to drop the distinct RootLogger class completely. I can't remember now why I created a separate class for the root - I thought it might have some specialization which never happened. Of course, I'm not sure if anyone is using it, so I can't just get rid of it. Anyway, the root logger is in some sense special so it might be more useful in the future. > Note that I have no strong opinion on all this. If you leave things as is > I'm fine with that. Yes, it's hardly a common case that the OP is mentioning. AFAIK this is the first time it's come up. I just thought from your and Jean- Michel's solutions that there might be a need felt by more people to have this functionality be more flexible. Regards, Vinay Sajip From mehgcap at gmail.com Wed Mar 24 06:48:21 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 06:48:21 -0400 Subject: using message loop for hotkey capturing In-Reply-To: <4BA9DE2C.6060307@timgolden.me.uk> References: <4BA9DE2C.6060307@timgolden.me.uk> Message-ID: Thanks, it seems to be working for now... Hopefully that trend continues! On 3/24/10, Tim Golden wrote: > On 23/03/2010 17:01, Alex Hall wrote: >> Hi all, but mainly Tim Golden: >> Tim, I am using your wonderful message loop for keyboard input, the >> one on your site that you pointed me to a few months ago. It has been >> working perfectly as long as I had only one dictionary of keys mapping >> to one dictionary of functions, but now I want two of each. My program >> has different modes, which may have varying keystrokes, and I also >> have some global keystrokes which are the same across all modes, like >> exiting or switching modes. I cannot figure out how to make the >> message loop look in two dictionaries at onc. I tried using an if, >> saying that if action_to_take was not set in the mode-specific >> dictionary then look at the global dictionary, but it is like it is >> never looking in the global dictionary at all. I get no syntax errors >> or problems when running the program, so it has to be something in my >> logic. > > There's definitely some confusion, as MRAB picked up, with the > globalkeys / globalfuncs thing. I can see no problem with simply > defining an additional pair of dictionaries parallel with each of > the keys/funcs dictionaries (note that the numbers are different > from those of othe other dictionaries as these are the registration > ids of the hotkeys): > > global_keys = { > 100: (68, win32com.MOD_ALT | win32con.MOD_CONTROL ...), > ... > } > > global_funcs = { > 100 : dict.ShowLookupDialog, > ... > } > > Then your central action code could be something like: > > action_to_take = global_funcs.get (msg.wParam) or HOTKEY_ACTIONS.get > (msg.wParam) > if action_to_take: > action_to_take () > > This assumes that the funcs dictionaries will only ever contain a > valid function, so the only possible Falsish value will arise from > the get returning None. > > TJG > > BTW, you're shadowing a couple of builtins: global & dict which > might give you problems later if you needed them. There are other > issues with the structure of your code but nothing a little > refactoring couldn't sort out if you felt so inclined. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From mail at timgolden.me.uk Wed Mar 24 06:48:55 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Mar 2010 10:48:55 +0000 Subject: exiting threaded program? In-Reply-To: References: Message-ID: <4BA9EE17.4050606@timgolden.me.uk> On 24/03/2010 10:43, Alex Hall wrote: > Hi all, > I have a program with a timer in it, therefore I have multiple > threads. My method of exiting by using "user32.PostQuitMessage (0)" no > longer seems to be doing the job since I added the timer. What else do > I have to do to close my program? I say it is not closing because, > before, I would be returned to a prompt in the cmd line, but now I > cannot type in the cmd line window even after the program supposedly > closes, whereas before I could have. Thanks. > Make the timer thread a daemon? TJG From alfps at start.no Wed Mar 24 06:55:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 24 Mar 2010 11:55:34 +0100 Subject: exiting threaded program? In-Reply-To: References: Message-ID: * Alex Hall: > Hi all, > I have a program with a timer in it, therefore I have multiple > threads. Is the "therefore..." an inference or independendent information? If it is an inference then it may not be correct. For example, timers in a GUI program need not involve additional threads. > My method of exiting by using "user32.PostQuitMessage (0)" This sounds like the Windows API level accessed from Python, not Python level? At the Windows API level, as I recall PostQuitMessage results in a WM_QUIT posted to the current thread's message queue, where it'll be processed by this thread's message loop, if it has one, which will then ideally finish. Possibly, if you indeed have more than one thread, you're posting the WM_QUIT to the wrong thread -- to quit the app it needs to be posted to the main thread. > no > longer seems to be doing the job since I added the timer. What else do > I have to do to close my program? I say it is not closing because, > before, I would be returned to a prompt in the cmd line, but now I > cannot type in the cmd line window even after the program supposedly > closes, whereas before I could have. Thanks. Try to reduce the problem to a minimal complete program, and post that? Unless the above comments help? Cheers, - Alf From mehgcap at gmail.com Wed Mar 24 07:04:40 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 07:04:40 -0400 Subject: exiting threaded program? In-Reply-To: <4BA9EE17.4050606@timgolden.me.uk> References: <4BA9EE17.4050606@timgolden.me.uk> Message-ID: A daemon... Good idea, and that makes more sense for what the thread does anyway; it is just a timer, updating a variable by contacting a server every hour. By the way, just what is the difference between user32.PostQuitMessage (0) and sys.exit()? On 3/24/10, Tim Golden wrote: > On 24/03/2010 10:43, Alex Hall wrote: >> Hi all, >> I have a program with a timer in it, therefore I have multiple >> threads. My method of exiting by using "user32.PostQuitMessage (0)" no >> longer seems to be doing the job since I added the timer. What else do >> I have to do to close my program? I say it is not closing because, >> before, I would be returned to a prompt in the cmd line, but now I >> cannot type in the cmd line window even after the program supposedly >> closes, whereas before I could have. Thanks. >> > > Make the timer thread a daemon? > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From mail at timgolden.me.uk Wed Mar 24 07:08:06 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Mar 2010 11:08:06 +0000 Subject: exiting threaded program? In-Reply-To: References: <4BA9EE17.4050606@timgolden.me.uk> Message-ID: <4BA9F296.4010504@timgolden.me.uk> On 24/03/2010 11:04, Alex Hall wrote: > A daemon... Good idea, and that makes more sense for what the thread > does anyway; it is just a timer, updating a variable by contacting a > server every hour. By the way, just what is the difference between > user32.PostQuitMessage (0) and sys.exit()? The former is a notification to a Windows message loop (something most Python programs don't have) that it should exit; the latter is a system call to exit the running program -- after any message loops have completed if applicable. BTW if you're running a Windows message loop anyway, you could just use Windows timers, catch the WM_TIMER message and avoid the complication of threads. Just an idea. TJG From info at egenix.com Wed Mar 24 08:36:39 2010 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 24 Mar 2010 13:36:39 +0100 Subject: ANN: eGenix mxODBC Zope Database Adapter 2.0.0 Message-ID: <4BAA0757.5050701@egenix.com> ________________________________________________________________________ ANNOUNCEMENT mxODBC Zope Database Adapter Version 2.0.0 for Zope and the Plone CMS Available for Zope 2.12 and later on Windows, Linux, Mac OS X, FreeBSD and other platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.0.0-GA.html ________________________________________________________________________ INTRODUCTION The eGenix mxODBC Zope Database Adapter allows you to easily connect your Zope or Plone installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, FreeBSD and other platforms. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. ________________________________________________________________________ NEWS We are pleased to announce a new version 2.0 of our mxODBC Zope DA product. The new version was changes to conform with the new Zope 2.12 layout and installation system and includes many enhancements over our previous 1.0 version: * Includes mxODBC 3.1 with updated support for many current ODBC drivers, giving you more portability and features for a wider range of database backends. * Mac OS X 10.6 (Snow Leopard) support. * Python 2.5 and 2.6 support. * Zero maintenance support to automatically reconnect the Zope connection after a network or database problem. * More flexible Unicode support with options to work with pure Unicode, plain strings or mixed setups - even for databases that don't support Unicode * Automatic and transparent text encoding and decoding * More flexible date/time support including options to work with Python datetime objects, mxDateTime, strings or tuples * New decimal support to have the Zope DA return decimal column values using Python's decimal objects. * Fully eggified to simplify easy_install and buildout based installation ________________________________________________________________________ UPGRADING If you have already bought mxODBC Zope DA 1.0.x licenses, we offer you a time limited upgrade option: * If you have purchased the licenses between 2009-06-01 and 2009-12-31 you can get a 20% discount on the full price of version 2.0. * If you have purchased the licenses after 2010-01-01 you can get a 40% discount on the full price of version 2.0. This offer is time limited until 2010-09-30. Please write to sales at egenix.com for details on how to get the needed discount coupons. ________________________________________________________________________ MORE INFORMATION For more information on the mxODBC Zope Database Adapter, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/zope/mxODBCZopeDA/ You can buy mxODBC Zope DA licenses online from the eGenix.com shop at: http://shop.egenix.com/ ________________________________________________________________________ Thank you, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 24 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From pruebauno at latinmail.com Wed Mar 24 09:03:31 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 24 Mar 2010 06:03:31 -0700 (PDT) Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> <4BA943E7.5000202@v.loewis.de> Message-ID: <0250ffe0-0bb0-4cb2-8c3e-6446fb51b0b8@r27g2000yqn.googlegroups.com> Martin v. Loewis wrote: > nn wrote: > > > > Stefan Behnel wrote: > >> nn, 23.03.2010 19:46: > >>> Actually what I want is to write a particular byte to standard output, > >>> and I want this to work regardless of where that output gets sent to. > >>> I am aware that I could do > >>> open('nnout','w',encoding='latin1').write(mychar) but I am porting a > >>> python2 program and don't want to rewrite everything that uses that > >>> script. > >> Are you writing text or binary data to stdout? > >> > >> Stefan > > > > latin1 charset text. > > Are you sure about that? If you carefully reconsider, could you come to > the conclusion that you are not writing text at all, but binary data? > > If it really was text that you write, why do you need to use > U+00FD (LATIN SMALL LETTER Y WITH ACUTE). To my knowledge, that > character is really infrequently used in practice. So that you try to > write it strongly suggests that it is not actually text what you are > writing. > > Also, your formulation suggests the same: > > "Is there any way to write a value 253 to standard output?" > > If you would really be writing text, you'd ask > > > "Is there any way to write '?' to standard output?" > > Regards, > Martin To be more informative I am both writing text and binary data together. That is I am embedding text from another source into stream that uses non-ascii characters as "control" characters. In Python2 I was processing it mostly as text containing a few "funny" characters. From pruebauno at latinmail.com Wed Mar 24 09:08:26 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 24 Mar 2010 06:08:26 -0700 (PDT) Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: <5db21794-371b-42eb-8c08-06395149faea@y17g2000yqd.googlegroups.com> Steven D'Aprano wrote: > On Tue, 23 Mar 2010 11:46:33 -0700, nn wrote: > > > Actually what I want is to write a particular byte to standard output, > > and I want this to work regardless of where that output gets sent to. > > What do you mean "work"? > > Do you mean "display a particular glyph" or something else? > > In bash: > > $ echo -e "\0101" # octal 101 = decimal 65 > A > $ echo -e "\0375" # decimal 253 > ? > > but if I change the terminal encoding, I get this: > > $ echo -e "\0375" > ? > > Or this: > > $ echo -e "\0375" > ? > > depending on which encoding I use. > > I think your question is malformed. You need to work out what behaviour > you actually want, before you can ask for help on how to get it. > > > > -- > Steven Yes sorry it is a bit ambiguous. I don't really care what glyph is, the program reading my output reads 8 bit values expects the binary value 0xFD as control character and lets everything else through as is. From melanienicoleo at gmail.com Wed Mar 24 09:32:27 2010 From: melanienicoleo at gmail.com (melanienicoleo) Date: Wed, 24 Mar 2010 06:32:27 -0700 (PDT) Subject: UNDERAGE DAUGHTERS FUCK - FATHER-YOUNG DAUGHTER INCEST - SEXY YOUNG LEGS Message-ID: http://dizzyporn.com/2010-Mar/Preteen_Pantyhose_03.avi http://dizzyporn.com/2010-Mar/Young_Brazil_Teen_Model.avi http://dizzyporn.com/2010-Mar/Naked_Underage_Lolita.avi http://dizzyporn.com/2010-Mar/Underage_Hardcore_Fucking_720x480.avi http://dizzyporn.com/2010-Mar/Preteen_Cameltoe.mpeg http://dizzyporn.com/2010-Mar/Underage_Lesbian_Porn_07.avi http://dizzyporn.com/2010-Mar/Lolita_Pussy_Insertions_XviD.AC3.avi http://dizzyporn.com/2010-Mar/Black_Young_Baby_640x480.wmv http://dizzyporn.com/2010-Mar/3d_Underage_Hentai.avi http://dizzyporn.com/2010-Mar/Horny_Preteen_Pussy.avi http://dizzyporn.com/2010-Mar/Young_Girls_Squirting_Trailer.wmv http://dizzyporn.com/2010-Mar/Underage_Uncensored_XxX.avi http://dizzyporn.com/2010-Mar/Underage_Lolitas_Fucking.mpeg http://dizzyporn.com/2010-Mar/Japan_Underground_Lolita_Bondage_2008.JP.avi underage nudism preteen black girl lesbian sex mature and young russian lolita thumbs sweet young pussy free galleries underage japanese porn free lolita porn young girls poop preteen erected young russian model preteen lolitas tgp young chubby models underage illegal girls young male celebrities nude asian underage girls well hung young boys underage nude photos free young teen pussy nude underage teen art very young russian virgin sex very young gay studs petite underage nonude preteen cam photos bald preteen pussy young girls and boys nude lolita ls news lolita girls in pantyhose free young lolita ass selector bbs lolitas lolita sluts hands on science for young kids preteen nudists galleries preteen lolita ls magazine young black lolita cute young virgins preteen bbs loli bbs preteen young hairless girls impact of underage drinking hey young girl lolita underage bbs rompl lolita modeling pics young puffy nipple teen lolita dog sex fake underage amateur underage sex among young teens preteen underware young hot latin lesbians free young hardcore video porn sexy young models preteen underage models young black gays fucking lolitas preteen young adult nudists lolita cp preteen pre teen xxx lolita russian teens lolitas machine teen cute young art young models really younge anal free nude ls girl preteen pictures young male underwear models young girl thong very young teen redheads preteens lolitas very young voyeur real young porn live fast die young lolita twink porn pics preteen naturalist underaged schoolgirl young incest lollita clip young son & mom incest sites young asian gay dvd ukraine angels lolita birthday parties for preteens young japanese sluts sweet preteen pussy girls lolita bs little lolita bbs, little lolita lolita guestbook preteen girl pussy little lolitas top free underage preteen lolita sites lolitas slaves 10- russian teens young cute boys youngest schoolgirl uniform sex underage studio From solipsis at pitrou.net Wed Mar 24 09:41:11 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 24 Mar 2010 13:41:11 +0000 (UTC) Subject: Unicode blues in Python3 References: Message-ID: Le Tue, 23 Mar 2010 10:33:33 -0700, nn a ?crit?: > I know that unicode is the way to go in Python 3.1, but it is getting in > my way right now in my Unix scripts. How do I write a chr(253) to a > file? > > #nntst2.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar) print() writes to the text (unicode) layer of sys.stdout. If you want to access the binary (bytes) layer, you must use sys.stdout.buffer. So: sys.stdout.buffer.write(chr(253).encode('latin1')) or: sys.stdout.buffer.write(bytes([253])) See http://docs.python.org/py3k/library/io.html#io.TextIOBase.buffer From lawandawil at gmail.com Wed Mar 24 10:14:48 2010 From: lawandawil at gmail.com (anthoony) Date: Wed, 24 Mar 2010 07:14:48 -0700 (PDT) Subject: PRETEEN ASIAN NUDES - UNCENSORED UNDERAGE SEX - YOUNG FUCK ASIAN Message-ID: <95203262-9476-4a0a-b5c8-d2061fb348c1@z4g2000yqa.googlegroups.com> http://dizzyporn.com/2010-Mar/Christine_Young_Masturbation_BDRip.XviD.AC.avi http://dizzyporn.com/2010-Mar/Young_Sisters__Mobile.Spycam.3gp http://dizzyporn.com/2010-Mar/Underage_Asian_Teens_Fucking.mpeg http://dizzyporn.com/2010-Mar/Hot_Lolita_Stripping.mpeg http://dizzyporn.com/2010-Mar/Lolitas_Fingering_Pussy_800x600.wmv http://dizzyporn.com/2010-Mar/Preteen_Forced_Fucking.mp4 http://dizzyporn.com/2010-Mar/Brutal_Lolita_Fucking_EDTV_720x576.avi http://dizzyporn.com/2010-Mar/Christine_Young_Hardcore_HDRip.XviD.DVDRip.avi http://dizzyporn.com/2010-Mar/Yong_Lolita_Sex.avi http://dizzyporn.com/2010-Mar/Young_Pissing_Scene.mpeg http://dizzyporn.com/2010-Mar/Lolita_Pussy_Licking_EDTV_720x576.avi http://dizzyporn.com/2010-Mar/Young_Lolita_Bondage_EDTV_640x480.avi http://dizzyporn.com/2010-Mar/Bizzare_Underage_Sex_HDRip.XviD.DVDRip.avi lolita girls young cute young butts nude preteen angels underage lolita models russian young lolita sex free underage porn webcams hot young chick blowjobs for free schoolgirls preteen sex fucking very young girls preteen nipples preteens with big breast youngest first ladies lesbian lolita girl underage nude boy real young tits underage school girls naked czech underage girl iligal underage young african girl hidden preteen lolitas preteen nude softcore amateur young blonde underage pedolove naked lolita underage underage youth lolitas young naked bbw underage lolita top sites preteen bbs pedo underage lolitas mature women young males russian preteen photos lolita model top nude sites rape lolita russian lolita monthly underage toons young teens giving blowjobs tiny young girls young blowjob facials bikini teen lolita young and pregnant young girl bikini beach young hardcore free thumbnails civil war underage enlistees young girls strip lolita boys naked young anal gapes underage italian models kinder lolitas ukraine lolita young girls cock preteen panty wetting nude young model little girl lolitas maxi young preteen gallery links preteen girls slumber partys ohio welfare office youngstown swimsuit preteen incest granny young dick petite young preteen asian girl boy boy gay teen young hot young blonde cheerleader teen petite young young up skirts young asian cumshots lolita teen girls kelli young forum young incest and rape pedo preteen pussy, pedo pussy amateur young blowjob little russian preteen adults and young boys preteenteen tits tiny preteen model bbs alcoholism and underage drinking youngest penis young blondes fucking young super models nn preteen girls black preteen models free gallery mature young preteen girls bbs youngest twink girls pics young deep throat fucking young virgins nude young indian little tiny girl preteen model junior high girls young From hv at tbz-pariv.de Wed Mar 24 10:29:03 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 24 Mar 2010 15:29:03 +0100 Subject: crypto: verify external pkcs7 signature Message-ID: <80ulu3Fg0jU1@mid.individual.net> Hi, some black box system gives me secKey.pkcs7 signature and a data file. The signature should be correct, but it fails. On newer system I get this: M2Crypto.SMIME.PKCS7_Error: digest failure on older systems (openssl-0.9.8h-28.10.1) I get PKCS7 routines:PKCS7_verify:signature failure:pk7_smime.c:312 On a system with openssl-0.9.8e-45.13 the script creates a core dump. Any hints? {{{ def verify(file): s = SMIME.SMIME() cert_file='CN=NW4.cert' x509=X509.load_cert(cert_file) sk=X509.X509_Stack() sk.push(x509) s.set_x509_stack(sk) # Load the signer's CA cert. In this case, because the signer's # cert is self-signed, it is the signer's cert itself. st = X509.X509_Store() st.load_info(cert_file) # CA Cert s.set_x509_store(st) from M2Crypto.BIO import File # Load the data, verify it. p7=SMIME.load_pkcs7('secKey.pkcs7') try: print s.verify(p7, File(open(file))) except (M2Crypto.SMIME.PKCS7_Error, M2Crypto.SMIME.SMIME_Error), exc: print '%s failed: %s' % (file, str(exc).strip()) return False return True }}} -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From python at bdurham.com Wed Mar 24 10:52:40 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 10:52:40 -0400 Subject: Sniffing encoding type by looking at file BOM header Message-ID: <1269442360.3213.1366489361@webmail.messagingengine.com> I assume there's no standard library function that wraps codecs.open() to sniff a file's BOM header and open the file with the appropriate encoding? My reading of the docs leads me to believe that there are 5 types of possible BOM headers with multiple names (synoymns?) for the same BOM encoding type. BOM = '\xff\xfe' BOM_LE = '\xff\xfe' BOM_UTF16 = '\xff\xfe' BOM_UTF16_LE = '\xff\xfe' BOM_BE = '\xfe\xff' BOM32_BE = '\xfe\xff' BOM_UTF16_BE = '\xfe\xff' BOM64_BE = '\x00\x00\xfe\xff' BOM_UTF32_BE = '\x00\x00\xfe\xff' BOM64_LE = '\xff\xfe\x00\x00' BOM_UTF32 = '\xff\xfe\x00\x00' BOM_UTF32_LE = '\xff\xfe\x00\x00' BOM_UTF8 = '\xef\xbb\xbf' Is the process of writing a BOM sniffer readlly as simple as detecting one of these 5 header types and then calling codecs.open() with the appropriate encoding= parameter? Note: I'm only interested in Unicode encodings. I am not interested in any of the non-Unicode encodings supported by the codecs module. Thank you, Malcolm From googler.1.webmaster at spamgourmet.com Wed Mar 24 11:09:27 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Wed, 24 Mar 2010 08:09:27 -0700 (PDT) Subject: C-API: Extract information from function object Message-ID: Hi, I have a reference to a function and would like to know how to extract information from a function object. Information I am looking for: line and file where this function is from. PyObject_Call can do this to when I call a function object and something failed so these information are written to the traceback. So any suggestions how to do that? Thx!! moerchendiser2k3 From anand.shashwat at gmail.com Wed Mar 24 11:17:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 20:47:12 +0530 Subject: spams Message-ID: Lately this list have been spammed a lot. Any workarounds by moderators? ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoavglazner at gmail.com Wed Mar 24 11:27:38 2010 From: yoavglazner at gmail.com (Glazner) Date: Wed, 24 Mar 2010 08:27:38 -0700 (PDT) Subject: Advice needed on parallel processing in python Message-ID: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Hi! I need to replace an app that does number crunching over a local network. it have about 50 computers as slaves each computer needs to run COM that will do the "job" right now the system uses MFC threads and DCOM to distribute the load. as i said, Now i'm trying to replace this system with python. I already use win32all and read about Pareller Python and Pyro. a requirement is that messages can be sent to the remote worker. If anyone can share experience I'll love to hear Many Thanks, Yoav Glazner From no.email at please.post Wed Mar 24 11:29:07 2010 From: no.email at please.post (kj) Date: Wed, 24 Mar 2010 15:29:07 +0000 (UTC) Subject: sum for sequences? Message-ID: Is there a sequence-oriented equivalent to the sum built-in? E.g.: seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) ? (By "sequence" I'm referring primarily to lists and tuples, and excluding strings, since for these there is ''.join()). TIA! ~K From yoavglazner at gmail.com Wed Mar 24 11:39:10 2010 From: yoavglazner at gmail.com (Glazner) Date: Wed, 24 Mar 2010 08:39:10 -0700 (PDT) Subject: sum for sequences? References: Message-ID: On Mar 24, 5:29?pm, kj wrote: > Is there a sequence-oriented equivalent to the sum built-in? ?E.g.: > > ? seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > > (By "sequence" I'm referring primarily to lists and tuples, and > excluding strings, since for these there is ''.join()). > > TIA! > > ~K try itertools.chain From neilc at norwich.edu Wed Mar 24 11:42:02 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Mar 2010 15:42:02 GMT Subject: sum for sequences? References: Message-ID: <80uq6aF6i4U1@mid.individual.net> On 2010-03-24, kj wrote: > > > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > > (By "sequence" I'm referring primarily to lists and tuples, and > excluding strings, since for these there is ''.join()). reduce, or functools.reduce in Python 3.1. >>> functools.reduce(operator.add, ((1, 2), (5, 6))) (1, 2, 5, 6) -- Neil Cerutti "It's not fun to build walls. But it's even less fun to live without walls in a world full of zombies." --Greedy Goblin From insomnia.iit.roorkee at gmail.com Wed Mar 24 11:42:44 2010 From: insomnia.iit.roorkee at gmail.com (insomnia iit roookee) Date: Wed, 24 Mar 2010 08:42:44 -0700 (PDT) Subject: coding contest Message-ID: IIT ROORKEE COGNIZANCE presents INSOMNIA :THE MIDNIGHT PROGRAMMING CONTEST... www.insomnia.cognizance.org.in Starts on : 27th March, 9:00 PM Cash prizes worth Rs.30,000 on stake for this round. (PS: Problems of previous rounds are available for practice.) From darcy at druid.net Wed Mar 24 11:42:51 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 24 Mar 2010 11:42:51 -0400 Subject: spams In-Reply-To: References: Message-ID: <20100324114251.ac0714c8.darcy@druid.net> On Wed, 24 Mar 2010 20:47:12 +0530 Shashwat Anand wrote: > Lately this list have been spammed a lot. Any workarounds by moderators? Not as long as it is gatewayed to Usenet. You can kill most of the spam by blocking anything from gmail.com with a Newsgroups line. Unfortunately you will also block a lot of legitimate postings. If they would turn off the gateway then legitimate posters can choose to join the list but as long as the gateway is there then there is no reason to switch. With the gateway off there are all sorts of tools to reduce spam. I think the best one is to set the flag to only allow subscribers to post and to start all new users as moderated and remove the moderation on the first posting as long as it is not spam. If the first posting is not spam then chances are none of the rest from that user will be spam. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Wed Mar 24 11:42:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 11:42:52 -0400 Subject: sum for sequences? In-Reply-To: References: Message-ID: kj wrote: > > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > > (By "sequence" I'm referring primarily to lists and tuples, and > excluding strings, since for these there is ''.join()). > Do you mean you want to flatten a list structure? There have been several discussions about this, which Google will find for you quite easily. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at please.post Wed Mar 24 12:05:10 2010 From: no.email at please.post (kj) Date: Wed, 24 Mar 2010 16:05:10 +0000 (UTC) Subject: What's the matter with docs.python.org? Message-ID: In the last couple of weeks, docs.python.org has been down repeatedly (like right now). Has anyone else noticed this? ~K From python at bdurham.com Wed Mar 24 12:17:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 12:17:16 -0400 Subject: Programmatically discovering encoding types supported by codecs module Message-ID: <1269447436.19612.1366507993@webmail.messagingengine.com> Is there a way to programmatically discover the encoding types supported by the codecs module? For example, the following link shows a table with Codec, Aliases, and Language columns. http://docs.python.org/library/codecs.html#standard-encodings I'm looking for a way to programmatically generate this table through some form of module introspection. Ideas? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Mar 24 12:19:09 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 12:19:09 -0400 Subject: What's the matter with docs.python.org? In-Reply-To: References: Message-ID: <1269447549.19932.1366508801@webmail.messagingengine.com> KJ, > In the last couple of weeks, docs.python.org has been down repeatedly > (like right now). Has anyone else noticed this? I've been surfing docs.python.org all morning and haven't had any problems. I'm connecting from Bethlehem, PA (USA). Malcolm From philip at semanchuk.com Wed Mar 24 12:19:19 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 24 Mar 2010 12:19:19 -0400 Subject: What's the matter with docs.python.org? In-Reply-To: References: Message-ID: <2329E820-C060-43F2-AE3C-0FBF53221AA9@semanchuk.com> On Mar 24, 2010, at 12:05 PM, kj wrote: > In the last couple of weeks, docs.python.org has been down repeatedly > (like right now). Has anyone else noticed this? http://downforeveryoneorjustme.com/docs.python.org Works for me... HTH Philip From duncan.booth at invalid.invalid Wed Mar 24 12:20:17 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 Mar 2010 16:20:17 GMT Subject: sum for sequences? References: Message-ID: kj wrote: > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > Apart from the suggestions for Google for general list flattening, for this specific example you could just use the 'sum' built-in: >>> sum(((1, 2), (5, 6)), ()) (1, 2, 5, 6) Just give it an empty tuple as the starting value. From steve at holdenweb.com Wed Mar 24 12:24:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 12:24:55 -0400 Subject: What's the matter with docs.python.org? In-Reply-To: References: Message-ID: kj wrote: > > > In the last couple of weeks, docs.python.org has been down repeatedly > (like right now). Has anyone else noticed this? http://downforeveryoneorjustme.com/docs.python.org regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at please.post Wed Mar 24 12:25:45 2010 From: no.email at please.post (kj) Date: Wed, 24 Mar 2010 16:25:45 +0000 (UTC) Subject: What's the matter with docs.python.org? References: Message-ID: In Philip Semanchuk writes: >On Mar 24, 2010, at 12:05 PM, kj wrote: >> In the last couple of weeks, docs.python.org has been down repeatedly >> (like right now). Has anyone else noticed this? >http://downforeveryoneorjustme.com/docs.python.org Very handy. Thanks! ~K From gagsl-py2 at yahoo.com.ar Wed Mar 24 12:49:30 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 13:49:30 -0300 Subject: C-API: Extract information from function object References: Message-ID: En Wed, 24 Mar 2010 12:09:27 -0300, moerchendiser2k3 escribi?: > I have a reference to a function and would like to know how to extract > information from a function object. > > Information I am looking for: line and file where this function is > from. > > PyObject_Call can do this to when I call a function object and > something failed so these information are written to the traceback. So > any suggestions how to do that? See the Language Reference; the associated code object holds the file and starting line the function comes from. The traceback object contains better information (like the line being executed instead of the first one). Why don't you use it instead? -- Gabriel Genellina From anand.shashwat at gmail.com Wed Mar 24 13:12:09 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 22:42:09 +0530 Subject: spams In-Reply-To: <20100324114251.ac0714c8.darcy@druid.net> References: <20100324114251.ac0714c8.darcy@druid.net> Message-ID: seems good :) On Wed, Mar 24, 2010 at 9:12 PM, D'Arcy J.M. Cain wrote: > On Wed, 24 Mar 2010 20:47:12 +0530 > Shashwat Anand wrote: > > Lately this list have been spammed a lot. Any workarounds by moderators? > > Not as long as it is gatewayed to Usenet. You can kill most of the > spam by blocking anything from gmail.com with a Newsgroups line. > Unfortunately you will also block a lot of legitimate postings. > > If they would turn off the gateway then legitimate posters can choose > to join the list but as long as the gateway is there then there is no > reason to switch. > > With the gateway off there are all sorts of tools to reduce spam. I > think the best one is to set the flag to only allow subscribers to post > and to start all new users as moderated and remove the moderation on > the first posting as long as it is not spam. If the first posting is > not spam then chances are none of the rest from that user will be spam. > > -- > D'Arcy J.M. Cain | Democracy is three wolves > http://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Mar 24 13:18:32 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 24 Mar 2010 13:18:32 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: <1269447436.19612.1366507993@webmail.messagingengine.com> References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: On Wed, Mar 24, 2010 at 12:17 PM, wrote: > Is there a way to programmatically discover the encoding types supported by > the codecs module? > > For example, the following link shows a table with Codec, Aliases, and > Language columns. > http://docs.python.org/library/codecs.html#standard-encodings > > I'm looking for a way to programmatically generate this table through some > form of module introspection. > > Ideas? > > Malcolm > -- According to my brief messing around with the REPL, encodings.aliases.aliases is a good place to start. I don't know of any way to get the Language column, but at the very least that will give you most of the supported encodings and any aliases they have. From torriem at gmail.com Wed Mar 24 13:33:46 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 24 Mar 2010 11:33:46 -0600 Subject: Unicode blues in Python3 In-Reply-To: References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: <4BAA4CFA.7000907@gmail.com> Steven D'Aprano wrote: > I think your question is malformed. You need to work out what behaviour > you actually want, before you can ask for help on how to get it. It may or may not be malformed, but I understand the question. So let eme translate for you. How can he write arbitrary bytes ( 0x0 through 0xff) to stdout without having them mangled by encodings. It's a very simple question, really. Looks like Antoine Pitrou has answered this question quite nicely as well. From pruebauno at latinmail.com Wed Mar 24 13:34:20 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 24 Mar 2010 10:34:20 -0700 (PDT) Subject: Unicode blues in Python3 References: Message-ID: <408cc5cf-28ac-440e-9536-e557347c6c1f@i25g2000yqm.googlegroups.com> Antoine Pitrou wrote: > Le Tue, 23 Mar 2010 10:33:33 -0700, nn a ?crit?: > > > I know that unicode is the way to go in Python 3.1, but it is getting in > > my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > #nntst2.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar) > > print() writes to the text (unicode) layer of sys.stdout. > If you want to access the binary (bytes) layer, you must use > sys.stdout.buffer. So: > > sys.stdout.buffer.write(chr(253).encode('latin1')) > > or: > > sys.stdout.buffer.write(bytes([253])) > > See http://docs.python.org/py3k/library/io.html#io.TextIOBase.buffer Just what I needed! Now I full control of the output. Thanks Antoine. The new io stack is still a bit of a mystery to me. Thanks everybody else, and sorry for confusing the issue. Latin1 just happens to be very convenient to manipulate bytes and is what I thought of initially to handle my mix of textual and non-textual data. From gagsl-py2 at yahoo.com.ar Wed Mar 24 13:39:20 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 14:39:20 -0300 Subject: Programmatically discovering encoding types supported by codecs module References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: En Wed, 24 Mar 2010 13:17:16 -0300, escribi?: > Is there a way to programmatically discover the encoding types > supported by the codecs module? > > For example, the following link shows a table with Codec, > Aliases, and Language columns. > http://docs.python.org/library/codecs.html#standard-encodings > > I'm looking for a way to programmatically generate this table > through some form of module introspection. After looking at how things are done in codecs.c and encodings/__init__.py I think you should enumerate all modules in the encodings package that define a getregentry function. Aliases come from encodings.aliases.aliases. -- Gabriel Genellina From wolfgang.lipp at gmail.com Wed Mar 24 13:44:13 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Wed, 24 Mar 2010 10:44:13 -0700 (PDT) Subject: Is it possible to use re2 from Python? References: Message-ID: yes we can! http://github.com/facebook/pyre2 as pointed out by http://stackoverflow.com/users/219162/daniel-stutzbach now gotta go and try it out. From wolfgang.lipp at gmail.com Wed Mar 24 13:47:22 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Wed, 24 Mar 2010 10:47:22 -0700 (PDT) Subject: how to do asynchronous http requests with epoll and python 3.1 Message-ID: <031f3a5b-28ac-42f0-a6a8-2cb7998cad6d@q16g2000yqq.googlegroups.com> i asked this question before on http://stackoverflow.com/questions/2489780/how-to-do-asynchronous-http-requests-with-epoll-and-python-3-1 but without a definitive answer as yet. can someone help me out? i want to do several simple http GET and POST requests in the same process using Python 3.1 without using threading. the original post: there is an interesting page [http://scotdoyle.com/python-epoll- howto.html][1] about how to do asnchronous / non-blocking / AIO http serving in python 3. there is the [tornado web server][2] which does include a non-blocking http client. i have managed to port parts of the server to python 3.1, but the implementation of the client requires [pyCurl][3] and [seems to have problems][4] (with one participant stating how ?Libcurl is such a pain in the neck?, and looking at the incredibly ugly pyCurl page i doubt pyCurl will arrive in py3+ any time soon). now that epoll is available in the standard library, it should be possible to do asynchronous http requests out of the box with python. i really do not want to use asyncore or whatnot; epoll has a reputation for being the ideal tool for the task, and it is part of the python distribution, so using anything but epoll for non-blocking http is highly counterintuitive (prove me wrong if you feel like it). oh, and i feel threading is horrible. no threading. i use [stackless] [5]. *people further interested in the topic of asynchronous http should not miss out on this [talk by peter portante at PyCon2010][6]; also of interest is [the keynote][7], where speaker antonio rodriguez at one point emphasizes the importance of having up-to-date web technology libraries right in the standard library.* [1]: http://scotdoyle.com/python-epoll-howto.html [2]: http://www.tornadoweb.org/ [3]: http://pycurl.sourceforge.net/ [4]: http://groups.google.com/group/python-tornado/browse_thread/thread/276059a076593266/c49e8f834497271e?lnk=gst&q=httpclient+trouble+with+epoll#c49e8f834497271e [5]: http://stackless.com/ [6]: http://python.mirocommunity.org/video/1501/pycon-2010-demystifying-non-bl [7]: http://python.mirocommunity.org/video/1605/pycon-2010-keynote-relentlessl From python at bdurham.com Wed Mar 24 13:55:32 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 13:55:32 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: <1269453332.6801.1366527617@webmail.messagingengine.com> Benjamin, > According to my brief messing around with the REPL, encodings.aliases.aliases is a good place to start. I don't know of any way to get the Language column, but at the very least that will give you most of the supported encodings and any aliases they have. Thank you - that's exactly the type of information I was looking for. I'm including the following for anyone browsing the mailing list archives in the future. Here's the snippet we're using to dynamically generate the codec documentation posted on the docs.python website. import encodings encodingDict = encodings.aliases.aliases encodingType = dict() for key, value in encodingDict.items(): if value not in encodingType: encodingType[ value ] = list() encodingType[ value ].append( key ) for key in sorted( encodingType.keys() ): aliases = sorted( encodingType[ key ] ) aliases = ', '.join( aliases ) print '%-20s%s' % ( key, aliases ) Regards, Malcolm From python at bdurham.com Wed Mar 24 13:58:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 13:58:47 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: <1269453527.7192.1366528303@webmail.messagingengine.com> Gabriel, > After looking at how things are done in codecs.c and encodings/__init__.py I think you should enumerate all modules in the encodings package that define a getregentry function. Aliases come from encodings.aliases.aliases. Thanks for looking into this for me. Benjamin Kaplan made a similar observation. My reply to him included the snippet of code we're using to generate the actual list of encodings that our software will support (thanks to Python's codecs and encodings modules). Your help is always appreciated :) Regards, Malcolm ----- Original message ----- From: "Gabriel Genellina" To: python-list at python.org Date: Wed, 24 Mar 2010 14:39:20 -0300 Subject: Re: Programmatically discovering encoding types supported by codecs module En Wed, 24 Mar 2010 13:17:16 -0300, escribi?: > Is there a way to programmatically discover the encoding types > supported by the codecs module? > > For example, the following link shows a table with Codec, > Aliases, and Language columns. > http://docs.python.org/library/codecs.html#standard-encodings > > I'm looking for a way to programmatically generate this table > through some form of module introspection. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From joncle at googlemail.com Wed Mar 24 14:13:11 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Mar 2010 11:13:11 -0700 (PDT) Subject: Advice needed on parallel processing in python References: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Message-ID: On 24 Mar, 15:27, Glazner wrote: > Hi! > > I need to replace an app that does number crunching over a local > network. > it have about 50 computers as slaves > each computer needs to run COM that will do the "job" > right now the system uses MFC threads and DCOM to distribute the load. > > as i said, Now i'm trying to replace this system with python. > I already use win32all and read about Pareller Python and Pyro. > > a requirement is that messages can be sent to the remote worker. > > If anyone can share experience I'll love to hear > > Many Thanks, > Yoav Glazner Would Celery suit? http://celeryproject.org/ hth Jon. From anand.shashwat at gmail.com Wed Mar 24 14:17:55 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 23:47:55 +0530 Subject: Advice needed on parallel processing in python In-Reply-To: References: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Message-ID: have you checked hadoop ? On Wed, Mar 24, 2010 at 11:43 PM, Jon Clements wrote: > On 24 Mar, 15:27, Glazner wrote: > > Hi! > > > > I need to replace an app that does number crunching over a local > > network. > > it have about 50 computers as slaves > > each computer needs to run COM that will do the "job" > > right now the system uses MFC threads and DCOM to distribute the load. > > > > as i said, Now i'm trying to replace this system with python. > > I already use win32all and read about Pareller Python and Pyro. > > > > a requirement is that messages can be sent to the remote worker. > > > > If anyone can share experience I'll love to hear > > > > Many Thanks, > > Yoav Glazner > > Would Celery suit? http://celeryproject.org/ > > hth > > Jon. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Wed Mar 24 15:35:27 2010 From: nagle at animats.com (John Nagle) Date: Wed, 24 Mar 2010 12:35:27 -0700 Subject: Unicode blues in Python3 In-Reply-To: <0250ffe0-0bb0-4cb2-8c3e-6446fb51b0b8@r27g2000yqn.googlegroups.com> References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> <4BA943E7.5000202@v.loewis.de> <0250ffe0-0bb0-4cb2-8c3e-6446fb51b0b8@r27g2000yqn.googlegroups.com> Message-ID: <4baa64e1$0$1632$742ec2ed@news.sonic.net> nn wrote: > To be more informative I am both writing text and binary data > together. That is I am embedding text from another source into stream > that uses non-ascii characters as "control" characters. In Python2 I > was processing it mostly as text containing a few "funny" characters. OK. Then you need to be writing arrays of bytes, not strings. Encoding is your problem. This has nothing to do with Unicode. John Nagle From leahy_rich at hotmail.com Wed Mar 24 16:26:51 2010 From: leahy_rich at hotmail.com (Richard Leahy) Date: Wed, 24 Mar 2010 22:26:51 +0200 Subject: help sending text to windows edit control Message-ID: I am trying to write text into a windows edit control using python. it seems to write to every control i try except the edit box not sure if this is a security measure or not. here is my code any help please. import os,sys,subprocess,time from subprocess import * from os import * from ctypes import * from ctypes.wintypes import * PROCESS_ALL_ACCESS = ( 0x000F0000 | 0x00100000 | 0xFFF ) kernel32 = windll.kernel32 pid = sys.argv[1] h_process = kernel32.OpenProcess( PROCESS_ALL_ACCESS, False, int(pid) ) if not h_process: print "[*] Couldn't acquire a handle to PID: %s" % pid sys.exit(0) user32 = windll.user32 # parent window window_handle = windll.user32.FindWindowA(None, "Windows App") if not window_handle: print "[*] cant find window" # 1 is the control id of the edit box child window #below line has no effect on the control for some reason?? windll.user32.SetDlgItemTextA(window_handle, 1, "test") # 2 is the control id of a button # this line works and changes the button text? not sure whats going on windll.user32.SetDlgItemTextA(window_handle, 2, "test") _________________________________________________________________ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Mar 24 16:34:59 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 16:34:59 -0400 Subject: Is there a way to detect an environment's "default" encoding type (Windows)? Message-ID: <1269462899.32722.1366552387@webmail.messagingengine.com> Is there a way to detect an environment's "default" encoding type under Windows? I'm not sure if code page and encoding mean the same thing here. For example: When I use Word on my US based version of Windows and decide to save a file as text, I am prompted with an encoding dialog that defaults to 'Windows (default)' which appears maps to their 'Western European (Windows)' code page which I assume maps to code page 1252. (That's a lot of assumptions!). I would like to be able to make the same assumption about text files produced on a user's system. (Of course our software will offer a way to explictly specify an encoding format as well). Here's what I've been able to dig up so far but I'm not sure how reliable this is or if its the same information Word is looking at when it offers a default encoding value. >>> import locale >>> locale.getdefaultlocale()[1] 'cp1252' Any ideas? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.mtarver at ukonline.co.uk Wed Mar 24 16:50:57 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Wed, 24 Mar 2010 13:50:57 -0700 (PDT) Subject: the Python Foundation Message-ID: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> >From the website The Python Software Foundation (PSF) is a 501(c)(3) non-profit corporation that holds the intellectual property rights behind the Python programming language. We manage the open source licensing for Python version 2.1 and later and own and protect the trademarks associated with Python. Could somebody explain 'what holding the intellectual property rights' means in this context and in what sense PSF manages the licensing and protects the trademarks associated with Python? This is for my education. thanks Mark From steven at REMOVE.THIS.cybersource.com.au Wed Mar 24 17:07:24 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Mar 2010 21:07:24 GMT Subject: sum for sequences? References: Message-ID: On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote: > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? Yes, sum. help(sum) is your friend. >>> a = range(2) >>> b = range(3) >>> c = range(4) >>> sum((a, b, c), []) [0, 1, 0, 1, 2, 0, 1, 2, 3] Beware though that sum on lists and tuples will be fairly inefficient if you have lots of them. You may find that this will be much more efficient: result = [] for seq in sequences: result.extend(seq) -- Steven From robert.kern at gmail.com Wed Mar 24 17:09:09 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Mar 2010 16:09:09 -0500 Subject: the Python Foundation In-Reply-To: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: On 2010-03-24 15:50 PM, Mark Tarver wrote: >> From the website > > The Python Software Foundation (PSF) is a 501(c)(3) non-profit > corporation that > holds the intellectual property rights behind the Python programming > language. We manage the open source licensing for Python version 2.1 > and later and own and protect the trademarks associated with Python. > > Could somebody explain 'what holding the intellectual property rights' > means in this context and in what sense PSF manages the licensing and > protects the trademarks associated with Python? This is for my > education. The PSF owns the Python language trademark: http://tess2.uspto.gov/bin/showfield?f=doc&state=4007:oc64of.5.1 Its trademark policy is given in detail here: http://www.python.org/psf/trademarks/ It also controls the license of the Python interpreter and its surrounding code. Contributors license their code to the PSF. Contributors keep the copyright to their code, but they agree to give the PSF the right to distribute it under a different license if the PSF decides to change licenses. See the Contributor Agreement: http://www.python.org/psf/contrib/contrib-form/ I believe they also outright own the copyright to most of the code that was in the Python 2.1 release and up until this Contributor Agreement was set up. I could be wrong about that, though. -- 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 From mehgcap at gmail.com Wed Mar 24 17:12:45 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 17:12:45 -0400 Subject: timers not canceling! Message-ID: Hi all, I am having trouble with a timer I am trying to use. It is the same timer, but I need to cancel it when a certain event happens, then start it again when a second event happens. The below is from a shell session, not a file, but it shows my problem: I call cancel on a timer, then call start on it, and it thinks it is already running? What am I missing? >>> from threading import Timer >>> def func(): ... print("Time up!") ... >>> t=Timer(10.0, func) >>> t.start() >>> t.cancel() >>> t.start() Traceback (most recent call last): File "", line 1, in File "C:\python26\lib\threading.py", line 465, in start raise RuntimeError("thread already started") RuntimeError: thread already started >>> I typed start, then typed cancel within ten seconds (probably four or five), then called start again a couple seconds later. I figured canceling the timer would kill the thread so I could start it again. I am not looking for a reset, since I do not want it counting always. Thanks. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From chairman at python.org Wed Mar 24 17:18:39 2010 From: chairman at python.org (Steve Holden, Chairman, PSF) Date: Wed, 24 Mar 2010 17:18:39 -0400 Subject: the Python Foundation In-Reply-To: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: <4BAA81AF.1010308@python.org> Mark Tarver wrote: >>From the website > > The Python Software Foundation (PSF) is a 501(c)(3) non-profit > corporation that > holds the intellectual property rights behind the Python programming > language. We manage the open source licensing for Python version 2.1 > and later and own and protect the trademarks associated with Python. > > Could somebody explain 'what holding the intellectual property rights' > means in this context and in what sense PSF manages the licensing and > protects the trademarks associated with Python? This is for my > education. > The PSF requires that contributors sign an agreement licensing their code to us, and allowing us to distribute it under the license of our choosing (this does not in any way preclude the contributor licensing the same code to any other party under different terms). In this way people who use Python can be relatively sure that the code is untrammeled by claims of copyright or patent by anyone other than the PSF, and can therefore use it without fear of losing their rights to do so because of legal action by third parties. We have also registered the trademark "Python" for use in reference to computer programming languages, thereby ensuring that we can take action should some ill-advised individual or organization decide to produce another language with "Python" in its name which we did not feel conformed sufficiently strictly to the language definition, for instance. The PSF has an established policy with regard to the use of its trademarks, which you can read at http://www.python.org/psf/trademarks/ regards Steve -- Steve Holden Chairman, Python Software Foundation See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Mar 24 17:36:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 17:36:20 -0400 Subject: timers not canceling! In-Reply-To: References: Message-ID: <4BAA85D4.8050405@holdenweb.com> Alex Hall wrote: > Hi all, > I am having trouble with a timer I am trying to use. It is the same > timer, but I need to cancel it when a certain event happens, then > start it again when a second event happens. The below is from a shell > session, not a file, but it shows my problem: I call cancel on a > timer, then call start on it, and it thinks it is already running? > What am I missing? > >>>> from threading import Timer >>>> def func(): > ... print("Time up!") > ... >>>> t=Timer(10.0, func) >>>> t.start() >>>> t.cancel() >>>> t.start() > Traceback (most recent call last): > File "", line 1, in > File "C:\python26\lib\threading.py", line 465, in start > raise RuntimeError("thread already started") > RuntimeError: thread already started > > I typed start, then typed cancel within ten seconds (probably four or > five), then called start again a couple seconds later. I figured > canceling the timer would kill the thread so I could start it again. I > am not looking for a reset, since I do not want it counting always. > Thanks. I believe you'll need to create a new Timer each time you need one - a Timer is a threading.thread, and these can only be started once. "thread already started" implies that the thread is running, but you actually get the same message if you try to start any terminated thread (including a canceled one), so "threads cannot be restarted" might be a better message. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Mar 24 17:36:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 17:36:20 -0400 Subject: timers not canceling! In-Reply-To: References: Message-ID: <4BAA85D4.8050405@holdenweb.com> Alex Hall wrote: > Hi all, > I am having trouble with a timer I am trying to use. It is the same > timer, but I need to cancel it when a certain event happens, then > start it again when a second event happens. The below is from a shell > session, not a file, but it shows my problem: I call cancel on a > timer, then call start on it, and it thinks it is already running? > What am I missing? > >>>> from threading import Timer >>>> def func(): > ... print("Time up!") > ... >>>> t=Timer(10.0, func) >>>> t.start() >>>> t.cancel() >>>> t.start() > Traceback (most recent call last): > File "", line 1, in > File "C:\python26\lib\threading.py", line 465, in start > raise RuntimeError("thread already started") > RuntimeError: thread already started > > I typed start, then typed cancel within ten seconds (probably four or > five), then called start again a couple seconds later. I figured > canceling the timer would kill the thread so I could start it again. I > am not looking for a reset, since I do not want it counting always. > Thanks. I believe you'll need to create a new Timer each time you need one - a Timer is a threading.thread, and these can only be started once. "thread already started" implies that the thread is running, but you actually get the same message if you try to start any terminated thread (including a canceled one), so "threads cannot be restarted" might be a better message. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steven at REMOVE.THIS.cybersource.com.au Wed Mar 24 17:38:08 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Mar 2010 21:38:08 GMT Subject: timers not canceling! References: Message-ID: On Wed, 24 Mar 2010 17:12:45 -0400, Alex Hall wrote: > Hi all, > I am having trouble with a timer I am trying to use. It is the same > timer, but I need to cancel it when a certain event happens, then start > it again when a second event happens. The below is from a shell session, > not a file, but it shows my problem: I call cancel on a timer, then call > start on it, and it thinks it is already running? What am I missing? > >>>> from threading import Timer >>>> def func(): > ... print("Time up!") > ... >>>> t=Timer(10.0, func) >>>> t.start() >>>> t.cancel() >>>> t.start() > Traceback (most recent call last): > File "", line 1, in > File "C:\python26\lib\threading.py", line 465, in start > raise RuntimeError("thread already started") > RuntimeError: thread already started The start method is to start generic threads, not just timers, and threads don't support being restarted. Timers are fairly simple objects: after you start the thread, they just wait until the time expires, then run a function. You can cancel them, but not pause and restart them. To do what you are trying to do, you will need to subclass either Timer or thread and implement your own logic for pausing or restarting the count down. > I typed start, then typed cancel within ten seconds (probably four or > five), then called start again a couple seconds later. I figured > canceling the timer would kill the thread so I could start it again. That's not how they work. "start" means "start the thread", not "start the timer", and threads cannot be restarted. The documentation is very clear: "start() Start the thread?s activity. It must be called at most once per thread object. It arranges for the object?s run() method to be invoked in a separate thread of control." http://docs.python.org/library/threading.html#thread-objects -- Steven From martin at v.loewis.de Wed Mar 24 18:22:01 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 24 Mar 2010 23:22:01 +0100 Subject: RELEASED Python 2.6.5 In-Reply-To: References: Message-ID: > Is anyone else having trouble with the 2.6.5 Windows x86 installer? Not me. Run msiexec /i py...msi /l*v py.log and inspect py.log for errors (post it to bugs.python.org if you can't determine the cause of the problems). Are you using SUBST by any chance? Regards, Martin From gagsl-py2 at yahoo.com.ar Wed Mar 24 18:50:11 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 19:50:11 -0300 Subject: Programmatically discovering encoding types supported by codecs module References: <1269447436.19612.1366507993@webmail.messagingengine.com> <1269453527.7192.1366528303@webmail.messagingengine.com> Message-ID: En Wed, 24 Mar 2010 14:58:47 -0300, escribi?: >> After looking at how things are done in codecs.c and >> encodings/__init__.py I think you should enumerate all modules in the >> encodings package that define a getregentry function. Aliases come from >> encodings.aliases.aliases. > > Thanks for looking into this for me. Benjamin Kaplan made a similar > observation. My reply to him included the snippet of code we're using to > generate the actual list of encodings that our software will support > (thanks to Python's codecs and encodings modules). I was curious as whether both methods would give the same results: py> modules=set() py> for name in glob.glob(os.path.join(encodings.__path__[0], "*.py")): ... name = os.path.basename(name)[:-3] ... try: mod = __import__("encodings."+name, fromlist=['ilovepythonbutsometimesihateit']) ... except ImportError: continue ... if hasattr(mod, 'getregentry'): ... modules.add(name) ... py> fromalias = set(encodings.aliases.aliases.values()) py> fromalias - modules set(['tactis']) py> modules - fromalias set(['charmap', 'cp1006', 'cp737', 'cp856', 'cp874', 'cp875', 'idna', 'iso8859_1', 'koi8_u', 'mac_arabic', 'mac_centeuro', 'mac_croatian', 'mac_farsi', 'mac_romanian', 'palmos', 'punycode', 'raw_unicode_escape', 'string_escape', 'undefined', 'unicode_escape', 'unicode_internal', 'utf_8_sig']) There is a missing 'tactis' encoding (?) and about twenty without alias. -- Gabriel Genellina From no.email at nospam.invalid Wed Mar 24 19:19:19 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Mar 2010 16:19:19 -0700 Subject: sum for sequences? References: Message-ID: <7x1vf91f60.fsf@ruckus.brouhaha.com> kj writes: > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) use itertools.chain for this. A few people have mentioned that sum will also work, but I think for that purpose it could have O(n**2) complexity. From no.email at nospam.invalid Wed Mar 24 19:22:17 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Mar 2010 16:22:17 -0700 Subject: the Python Foundation References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: <7xwrx1z4nq.fsf@ruckus.brouhaha.com> "Steve Holden, Chairman, PSF" writes: > We have also registered the trademark "Python" for use in reference to > computer programming languages, thereby ensuring that we can take action > should some ill-advised individual or organization decide to produce > another language with "Python" in its name There has been a Lisp compiler called "Python" for many years: http://portal.acm.org/citation.cfm?id=141471.141558 From steve at holdenweb.com Wed Mar 24 20:26:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 20:26:20 -0400 Subject: timers not canceling! In-Reply-To: <4BAA85D4.8050405@holdenweb.com> References: <4BAA85D4.8050405@holdenweb.com> Message-ID: <4BAAADAC.4030603@holdenweb.com> Steve Holden wrote: > Alex Hall wrote: [...] > "thread already started" implies that the thread is running, but you > actually get the same message if you try to start any terminated thread > (including a canceled one), so "threads cannot be restarted" might be a > better message. > Or, better still, "Threads can only be started once". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Mar 24 20:26:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 20:26:20 -0400 Subject: timers not canceling! In-Reply-To: <4BAA85D4.8050405@holdenweb.com> References: <4BAA85D4.8050405@holdenweb.com> Message-ID: <4BAAADAC.4030603@holdenweb.com> Steve Holden wrote: > Alex Hall wrote: [...] > "thread already started" implies that the thread is running, but you > actually get the same message if you try to start any terminated thread > (including a canceled one), so "threads cannot be restarted" might be a > better message. > Or, better still, "Threads can only be started once". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From patrickwasp at gmail.com Wed Mar 24 20:33:35 2010 From: patrickwasp at gmail.com (Waspinator) Date: Wed, 24 Mar 2010 17:33:35 -0700 (PDT) Subject: cxfreeze on ubuntu 9.10 Message-ID: <84719a38-3d00-4d46-aa11-f0dca7ace71c@q15g2000yqj.googlegroups.com> Hi, I'm trying to compile a python script on Ubuntu 9.10. It uses the gtk toolkit. I tried to run GUI2EXE for a cxfreeze gui, but even after installing wxPython in synaptic it still complains about not having it. I also tried to use cxfreeze by itself but the file it produces does not run. I tried to follow the information at http://cx-freeze.sourceforge.net/cx_Freeze.html I created a setup.py file that looks like this (from the page) from cx_Freeze import setup, Executable setup( name = "gtk_test", version = "0.1", description = "gtk_test", executables = [Executable("gtk_test.py")]) and ran: python setup.py build When I try to run the executable I get the following error: ../build/exe.linux-i686-2.6/library.zip/gtk/_gtk.py:12: RuntimeWarning: tp_compare didn't return -1 or -2 for exception ImportError: could not import gio ImportError: could not import gio Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/cx_Freeze/initscripts/ Console.py", line 29, in exec code in m.__dict__ File "gtk_test.py", line 274, in File "gtk_test.py", line 228, in main AttributeError: 'module' object has no attribute 'Window' I was thinking of using the 'copy-dependent-files' option but I'm not sure how. Any ideas? Thanks From mehgcap at gmail.com Wed Mar 24 22:31:03 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 22:31:03 -0400 Subject: threads (specifically timers) and releasing resources Message-ID: Okay, I have my program and it has three different modes (there will be more than that). Each mode will have a timer attached to it. If the mode remains active and the timer runs out, a function specific to that mode is called. If that mode is switched away from, however, the timer is canceled and a new timer is created for the mode to which the user just switched. My question is: what happens with resources taken up by previous timers, whether they cancel or execute? I would hate for my program to run for a long time and slowly build up a massive list of old threads (timers), taking up resources which should have been released. Will Python perform GC and completely erase a thread once it is done, or will it keep hanging around? If the latter, is there a way to completely destroy a thread? Thanks; Google was not too helpful on this one! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From kurianmthayil at gmail.com Wed Mar 24 22:59:38 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Thu, 25 Mar 2010 08:29:38 +0530 Subject: MySQLdb compiled -- Import issue Message-ID: <1269485978.14968.17.camel@localhost> Hi All, I am just a month old with Python and trying to learn CGI with Python. I was trying to install MySQLdb module in my new CentOS 5.3 box with Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb module (MySQL-python-1.2.3c1). Did build as normal user and install as root. MySQL server version that I'm using is 5.1.41, if that has anything to do with the error. I then copied, libmysqlclient_r.so.16 library to /usr/lib/ folder and then I am able to import the module as root user. But cannot do this as normal user. Now, while doing import MySQLdb as normal user, I get the following error message. The scripts will be run as apache and hence cannot have this error. Please check the following output. Also I have attached the output while doing build and install process. [kurianmt at server MySQL-python-1.2.3c1]$ python Python 2.4.3 (#1, Jan 21 2009, 01:10:13) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path It would be a great help if I understand what's going on!!! Thanks in advance. Regards, Kurian Mathew Thayil. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- [kurianmt at server MySQL-python-1.2.3c1]$ python setup.py build running build running build_py creating build creating build/lib.linux-i686-2.4 copying _mysql_exceptions.py -> build/lib.linux-i686-2.4 creating build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/release.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/times.py -> build/lib.linux-i686-2.4/MySQLdb creating build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.4/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.linux-i686-2.4 gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/local/include/mysql -I/usr/include/python2.4 -c _mysql.c -o build/temp.linux-i686-2.4/_mysql.o -DUNIV_LINUX -DUNIV_LINUX In file included from _mysql.c:36: /usr/local/include/mysql/my_config.h:1050:1: warning: "HAVE_WCSCOLL" redefined In file included from /usr/include/python2.4/pyconfig.h:4, from /usr/include/python2.4/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /usr/include/python2.4/pyconfig-32.h:648:1: warning: this is the location of the previous definition gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -L/usr/local/lib/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -o build/lib.linux-i686-2.4/_mysql.so -------------- next part -------------- [root at server MySQL-python-1.2.3c1]# python setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info/PKG-INFO writing top-level names to MySQL_python.egg-info/top_level.txt writing dependency_links to MySQL_python.egg-info/dependency_links.txt reading manifest file 'MySQL_python.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'MySQL_python.egg-info/SOURCES.txt' installing library code to build/bdist.linux-i686/egg running install_lib running build_py copying MySQLdb/release.py -> build/lib.linux-i686-2.4/MySQLdb running build_ext creating build/bdist.linux-i686 creating build/bdist.linux-i686/egg copying build/lib.linux-i686-2.4/_mysql.so -> build/bdist.linux-i686/egg copying build/lib.linux-i686-2.4/_mysql_exceptions.py -> build/bdist.linux-i686/egg creating build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/connections.py -> build/bdist.linux-i686/egg/MySQLdb creating build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/CR.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/__init__.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/REFRESH.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/FLAG.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/ER.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/CLIENT.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/__init__.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/times.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/release.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/cursors.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/converters.py -> build/bdist.linux-i686/egg/MySQLdb byte-compiling build/bdist.linux-i686/egg/_mysql_exceptions.py to _mysql_exceptions.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/connections.py to connections.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/CR.py to CR.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/__init__.py to __init__.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/FLAG.py to FLAG.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/ER.py to ER.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/__init__.py to __init__.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/times.py to times.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/release.py to release.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/cursors.py to cursors.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/converters.py to converters.pyc creating stub loader for _mysql.so byte-compiling build/bdist.linux-i686/egg/_mysql.py to _mysql.pyc creating build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-i686/egg/EGG-INFO writing build/bdist.linux-i686/egg/EGG-INFO/native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist/MySQL_python-1.2.3c1-py2.4-linux-i686.egg' and adding 'build/bdist.linux-i686/egg' to it removing 'build/bdist.linux-i686/egg' (and everything under it) Processing MySQL_python-1.2.3c1-py2.4-linux-i686.egg Removing /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg Copying MySQL_python-1.2.3c1-py2.4-linux-i686.egg to /usr/lib/python2.4/site-packages MySQL-python 1.2.3c1 is already the active version in easy-install.pth Installed /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg Processing dependencies for MySQL-python==1.2.3c1 Finished processing dependencies for MySQL-python==1.2.3c1 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From half.italian at gmail.com Wed Mar 24 23:15:00 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Wed, 24 Mar 2010 20:15:00 -0700 (PDT) Subject: MySQLdb compiled -- Import issue References: Message-ID: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> On Mar 24, 7:59?pm, Kurian Thayil wrote: > Hi All, > > I am just a month old with Python and trying to learn CGI with Python. I > was trying to install MySQLdb module in my new CentOS 5.3 box with > Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb > module (MySQL-python-1.2.3c1). Did build as normal user and install as > root. MySQL server version that I'm using is 5.1.41, if that has > anything to do with the error. I then copied, libmysqlclient_r.so.16 > library to /usr/lib/ folder and then I am able to import the module as > root user. But cannot do this as normal user. > > Now, while doing import MySQLdb as normal user, I get the following > error message. The scripts will be run as apache and hence cannot have > this error. Please check the following output. Also I have attached the > output while doing build and install process. > > [kurianmt at server MySQL-python-1.2.3c1]$ python > Python 2.4.3 (#1, Jan 21 2009, 01:10:13) > [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb > > /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path > > It would be a great help if I understand what's going on!!! Thanks in > advance. > > Regards, > > Kurian Mathew Thayil. > > ?MySQLdb-build.txt > 3KViewDownload > > ?MySQLdb-Install.txt > 6KViewDownload > > ?signature.asc > < 1KViewDownload The warning looks familiar. Are you running python from the MySQLdb source directory? ie. /opt/downloads/py-modules/MySQL-python-1.2.3c1 I think you just need to change directories and the warning will go away. Check what's happening on line 3 of _mysql.py I don't have the source in front of me. ~Sean From aharrisreid at googlemail.com Wed Mar 24 23:17:52 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Thu, 25 Mar 2010 03:17:52 +0000 Subject: Super() function Message-ID: <4BAAD5E0.9050604@googlemail.com> Hi, Using Python 3.1, I sometimes use the super() function to call the equivalent method from a parent class, for example def mymethod(self): super().mymethod() some more code... Is there any way of writing the code so that the super() call is generic and automatically recognises the name of the current method (ie. something like super().thismethod()) or do I always have to repeat the method name after super()? TIA, Alan From littlesweetmelon at gmail.com Wed Mar 24 23:28:58 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 11:28:58 +0800 Subject: Is there any library for indexing binary data? Message-ID: Howdy, Recently, I am finding a good library for build index on binary data. Xapian & Lucene for python binding focus on text digestion rather than binary data. Could anyone give me some recommendation? Is there any library for indexing binary data no matter whether it is written in python? In my case, there is a very big datatable which stores structured binary data, eg: struct Item { long id; // used as key double value; }; I want to build the index on "id" field to speed on searching. Since this datatable is not constant, the library should support incremental indexing. If there is no suitable library, I have to do the index by myself... Thank you in advance. -- ShenLei From timr at probo.com Wed Mar 24 23:41:25 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Mar 2010 20:41:25 -0700 Subject: device identification References: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> <46ggq59e49qpna7f9ae6q8ftobhot351un@4ax.com> <57c86289-85e7-4c9f-b7ed-787687d9a5b6@x23g2000prd.googlegroups.com> Message-ID: Omer Ihsan wrote: > >VID and PID is fair enough. now what i want is that i have a threaded >code that threads two functions to run at the same time. i want each >function to run seperate devices. the problem is if it doesnt identify >the attached devices it might run the code on a single device which >isnt what is required. Some of the libraries that pyusb uses are not thread-safe, like libusb 0.1. >how will i be able to run a code on a device of my choice???....you >can leave away the threading part for now. You can return all of the devices with a particular VID and PID: collection = usb.core.find( find_all=True, idVendor=0x1234, idProduct=0x5678 ) Then you can dish those out to threads using something like the queue module. Or, usb.core.find accepts a predicate function that allows you to use any criteria you wish. What kind of device are you trying to manipulate? I have a lot of USB experience -- perhaps I can offer advice. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kurianmthayil at gmail.com Wed Mar 24 23:41:26 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Thu, 25 Mar 2010 09:11:26 +0530 Subject: MySQLdb compiled -- Import issue In-Reply-To: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> References: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> Message-ID: <1269488486.14968.22.camel@localhost> On Wed, 2010-03-24 at 20:15 -0700, Sean DiZazzo wrote: > On Mar 24, 7:59 pm, Kurian Thayil wrote: > > Hi All, > > > > I am just a month old with Python and trying to learn CGI with Python. I > > was trying to install MySQLdb module in my new CentOS 5.3 box with > > Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb > > module (MySQL-python-1.2.3c1). Did build as normal user and install as > > root. MySQL server version that I'm using is 5.1.41, if that has > > anything to do with the error. I then copied, libmysqlclient_r.so.16 > > library to /usr/lib/ folder and then I am able to import the module as > > root user. But cannot do this as normal user. > > > > Now, while doing import MySQLdb as normal user, I get the following > > error message. The scripts will be run as apache and hence cannot have > > this error. Please check the following output. Also I have attached the > > output while doing build and install process. > > > > [kurianmt at server MySQL-python-1.2.3c1]$ python > > Python 2.4.3 (#1, Jan 21 2009, 01:10:13) > > [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb > > > > /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path > > > > It would be a great help if I understand what's going on!!! Thanks in > > advance. > > > > Regards, > > > > Kurian Mathew Thayil. > > > > MySQLdb-build.txt > > 3KViewDownload > > > > MySQLdb-Install.txt > > 6KViewDownload > > > > signature.asc > > < 1KViewDownload > > The warning looks familiar. Are you running python from the MySQLdb > source directory? ie. /opt/downloads/py-modules/MySQL-python-1.2.3c1 > > I think you just need to change directories and the warning will go > away. Check what's happening on line 3 of _mysql.py I don't have the > source in front of me. > > ~Sean Hi Sean, You are right. I was trying to import the module sitting on the source folder :"-). Thanks for your quick response and let me try further. Regards, Kurian Mathew Thayil. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: face-embarrassed.png Type: image/png Size: 876 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ysj.ray at gmail.com Wed Mar 24 23:42:41 2010 From: ysj.ray at gmail.com (=?UTF-8?B?5bKz5biF5p2w?=) Date: Thu, 25 Mar 2010 11:42:41 +0800 Subject: Super() function In-Reply-To: <4BAAD5E0.9050604@googlemail.com> References: <4BAAD5E0.9050604@googlemail.com> Message-ID: <797c8cbd1003242042s32ee16bbxe6d937a16ab35a50@mail.gmail.com> Hi: On 25 March 2010 11:17, Alan Harris-Reid wrote: > Hi, > > Using Python 3.1, I sometimes use the super() function to call the > equivalent method from a parent class, for example > > def mymethod(self): > super().mymethod() > some more code... > > Is there any way of writing the code so that the super() call is generic > and automatically recognises the name of the current method (ie. something > like super().thismethod()) or do I always have to repeat the method name > after super()? > > TIA, > Alan > -- > http://mail.python.org/mailman/listinfo/python-list > I think, the super() method is designed to delegate any method call to one of the class in its mro list, and the super() function its self return a 'super' object, so it is better to write what method you want to delegate, maybe it's not the current method. -- Best wishes from Ray ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Mar 24 23:47:19 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 24 Mar 2010 20:47:19 -0700 (PDT) Subject: Super() function References: Message-ID: <4cb1beeb-a663-46e0-bedb-63e076b7f32c@h35g2000pri.googlegroups.com> Alan Harris-Reid wrote: > Is there any way of writing the code so that the super() call is generic > and automatically recognises the name of the current method (ie. > something like super().thismethod()) or do I always have to repeat the > method name after super()? To the best of my knowledge, you always need to repeat the method name. super() returns a proxy object that has no awareness of its context, so it's unaware of the method it's being called within (in fact, there's nothing that restricts super() to only being used in methods...). You could probably write a wrapper function that uses inspect to determine in which context super() is being called, but unless you're regularly finding this to be a problem with refactoring I wouldn't worry about it. From half.italian at gmail.com Wed Mar 24 23:54:49 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Wed, 24 Mar 2010 20:54:49 -0700 (PDT) Subject: MySQLdb compiled -- Import issue References: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> Message-ID: > You are right. I was trying to import the module sitting on the source > folder :"-). Thanks for your quick response and let me try further. Sweet! I remember it because it confused the hell out of me on at least one past occasion. :) From gagsl-py2 at yahoo.com.ar Thu Mar 25 00:00:27 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Mar 2010 01:00:27 -0300 Subject: Super() function References: <4BAAD5E0.9050604@googlemail.com> Message-ID: En Thu, 25 Mar 2010 00:17:52 -0300, Alan Harris-Reid escribi?: > Using Python 3.1, I sometimes use the super() function to call the > equivalent method from a parent class, for example > > def mymethod(self): > super().mymethod() > some more code... > > Is there any way of writing the code so that the super() call is generic > and automatically recognises the name of the current method (ie. > something like super().thismethod()) or do I always have to repeat the > method name after super()? This recipe does what you want: http://code.activestate.com/recipes/286195-selfsuper/ (but requires a bit of black magic...) -- Gabriel Genellina From timr at probo.com Thu Mar 25 00:14:23 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Mar 2010 21:14:23 -0700 Subject: Advice Criticism on Python App References: Message-ID: Jimbo wrote: > >class stock: > code = "" > purchasePrice = 0 > purchaseQuantity = 0 > price = [] # list of recent prices > recentBid = [] # list of recent bids for stock > recentOffer = [] # list of recent offers for stock > stockVol = [] # list of stock quantity available on >market Using lists as class variables is a very good way to create very surprising bugs. Consider the following: C:\Dev>type x.py class test: check = [] def __init__(self): self.check.append(1) x = test() y = test() z = test() print x.check print y.check print z.check C:\Dev>x.py [1, 1, 1] [1, 1, 1] [1, 1, 1] C:\Dev> > def __init__(self): > """ Default Constructor """ > self.code = "" > self.purchasePrice = 0 > self.purchaseQuantity = 0 > > def constructor(self, stockCode, purPrice, purQuant): > """ Constructor """ > self.code = stockCode > self.purchasePrice = purPrice > self.purchaseQuantity = purQuant The "constructor" concept here is not very Pythonic. Why not replace those both with: def __init__(self, stockCode="", purPrice=0, purQuant=0): self.code = stockCode self.purchasePrice = purPrice self.purchaseQuantity = purQuant -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gagsl-py2 at yahoo.com.ar Thu Mar 25 00:29:07 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Mar 2010 01:29:07 -0300 Subject: Is there any library for indexing binary data? References: Message-ID: En Thu, 25 Mar 2010 00:28:58 -0300, ?? escribi?: > Recently, I am finding a good library for build index on binary data. > Xapian & Lucene for python binding focus on text digestion rather than > binary data. Could anyone give me some recommendation? Is there any > library for indexing binary data no matter whether it is written in > python? > > In my case, there is a very big datatable which stores structured > binary data, eg: > struct Item > { > long id; // used as key > double value; > }; > > I want to build the index on "id" field to speed on searching. Since > this datatable is not constant, the library should support incremental > indexing. If there is no suitable library, I have to do the index by > myself... What about a database? -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Thu Mar 25 01:10:06 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Mar 2010 05:10:06 GMT Subject: Advice Criticism on Python App References: Message-ID: On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote: > Jimbo wrote: >> >>class stock: >> code = "" >> purchasePrice = 0 >> purchaseQuantity = 0 >> price = [] # list of recent prices >> recentBid = [] # list of recent bids for stock >> recentOffer = [] # list of recent offers for stock >> stockVol = [] # list of stock quantity available on market > > Using lists as class variables is a very good way to create very > surprising bugs. Consider the following: [snip] Don't you think that the class attributes are *supposed* to be shared by all instances? In that case the behaviour you show is not a bug at all. -- Steven From littlesweetmelon at gmail.com Thu Mar 25 01:53:45 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 13:53:45 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: References: Message-ID: Well, Database is not proper because 1. the table is very big (~10^9 rows) 2. we should support very fast *simple* query that is to get value corresponding to single key (~10^7 queries / second). Currently, I have implemented a specific algorithm to deal with my problem. However, I want to employ some library to simplify codings, otherwise I have to write my own code for each big table. It is possible that, after using indexing library, the program cannot run as fast as homemade code. But if it can greatly simplify my job and can provide satisfied speed (eg 10^5~10^6 queries / second), the indexing library is still a good choice for me. -- ShenLei 2010/3/25 Gabriel Genellina : > En Thu, 25 Mar 2010 00:28:58 -0300, ?? > escribi?: > >> Recently, I am finding a good library for build index on binary data. >> Xapian & Lucene for python binding focus on text digestion rather than >> binary data. Could anyone give me some recommendation? Is there any >> library for indexing binary data no matter whether it is written in >> python? >> >> In my case, there is a very big datatable which stores structured >> binary data, eg: >> struct Item >> { >> long id; // used as key >> double value; >> }; >> >> I want to build the index on "id" field to speed on searching. Since >> this datatable is not constant, the library should support incremental >> indexing. If there is no suitable library, I have to do the index by >> myself... > > What about a database? > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > From tomf.sessile at gmail.com Thu Mar 25 02:50:23 2010 From: tomf.sessile at gmail.com (TomF) Date: Wed, 24 Mar 2010 23:50:23 -0700 Subject: sum for sequences? References: Message-ID: <2010032423502316807-tomfsessile@gmailcom> On 2010-03-24 14:07:24 -0700, Steven D'Aprano said: > On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote: > >> Is there a sequence-oriented equivalent to the sum built-in? E.g.: >> >> seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) >> >> ? > > Yes, sum. > > help(sum) is your friend. You might not want to be so glib. The sum doc sure doesn't sound like it should work on lists. Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). -Tom From stefan_ml at behnel.de Thu Mar 25 03:22:30 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Mar 2010 08:22:30 +0100 Subject: C-API: Extract information from function object In-Reply-To: References: Message-ID: Gabriel Genellina, 24.03.2010 17:49: > En Wed, 24 Mar 2010 12:09:27 -0300, moerchendiser2k3 escribi?: > >> I have a reference to a function and would like to know how to extract >> information from a function object. >> >> Information I am looking for: line and file where this function is >> from. >> >> PyObject_Call can do this to when I call a function object and >> something failed so these information are written to the traceback. So >> any suggestions how to do that? > > See the Language Reference; the associated code object holds the file > and starting line the function comes from. > The traceback object contains better information (like the line being > executed instead of the first one). Why don't you use it instead? Note that this was a follow-up to another recent thread where I managed to extract the details from the OP by stoically asking back, especially the information that this is not about exception handling but rather about reporting incorrect return values. This is a good example when you need a reason why not to split threads on the same subject... Stefan From steven at REMOVE.THIS.cybersource.com.au Thu Mar 25 03:34:51 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Mar 2010 07:34:51 GMT Subject: sum for sequences? References: <2010032423502316807-tomfsessile@gmailcom> Message-ID: On Wed, 24 Mar 2010 23:50:23 -0700, TomF wrote: > On 2010-03-24 14:07:24 -0700, Steven D'Aprano > said: >> On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote: >> >>> Is there a sequence-oriented equivalent to the sum built-in? E.g.: >>> >>> seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) >>> >>> ? >> >> Yes, sum. >> >> help(sum) is your friend. > > You might not want to be so glib. The sum doc sure doesn't sound like > it should work on lists. > > Returns the sum of a sequence of numbers (NOT strings) plus the > value of parameter 'start' (which defaults to 0). What part of that suggested to you that sum might not be polymorphic? Sure, it says numbers (which should be changed, in my opinion), but it doesn't specify what sort of numbers -- ints, floats, or custom types that have an __add__ method. It also singles out strings as excluded. Why would you need to explicitly exclude strings, since they're not numbers, if sum *only* works with numbers? E.g. help(math.sin) could have said this, but doesn't: Return the sine of x (NOT a dictionary) It doesn't need to, because dicts aren't exceptional: sin doesn't work on anything *but* numbers. There's no __sin__ method to call on arbitrary types. The fact that sum does single out strings is a clear sign that strings are treated as exceptional and suggests strongly that summing arbitrary types should work. I'm not saying that help(sum) explicitly states that it works with lists (it clearly doesn't), but it does suggest the possibility and makes the experiment worth trying. I'll also note that the Fine Manual makes it even more clear that sum is polymorphic: http://docs.python.org/library/functions.html#sum -- Steven From moekaveli at gmail.com Thu Mar 25 03:41:06 2010 From: moekaveli at gmail.com (Dr. Benjamin David Clarke) Date: Thu, 25 Mar 2010 00:41:06 -0700 (PDT) Subject: Saving a page loaded using the webbrowser library? Message-ID: <3b268d9b-0e37-4e19-9f28-9f560edff76b@b30g2000yqd.googlegroups.com> Does anyone know of a way to save the a loaded web page to file after opening it with a webbrowser.open() call? Specifically, what I want to do is get the raw HTML from a web page. This web page uses Javascript. I need the resulting HTML after the Javascript has been run. I've seen a lot about trying to get Python to run Javascript but there doesn't seem to be any promising solution. I can get the raw HTML that I want by saving the page after it has been loaded via the webbrowser.open() call. Is there any way to automate this? Does anyone have any ideas for better approaches to this problem? I don't need ti to be pretty or anything. From irmen at -NOSPAM-xs4all.nl Thu Mar 25 03:58:28 2010 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Thu, 25 Mar 2010 08:58:28 +0100 Subject: Is there any library for indexing binary data? In-Reply-To: References: Message-ID: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> On 3/25/10 4:28 AM, ?? wrote: > Howdy, > > Recently, I am finding a good library for build index on binary data. > Xapian& Lucene for python binding focus on text digestion rather than > binary data. Could anyone give me some recommendation? Is there any > library for indexing binary data no matter whether it is written in > python? > > In my case, there is a very big datatable which stores structured > binary data, eg: > struct Item > { > long id; // used as key > double value; > }; > > I want to build the index on "id" field to speed on searching. Since > this datatable is not constant, the library should support incremental > indexing. If there is no suitable library, I have to do the index by > myself... > > Thank you in advance. > > -- > ShenLei Put it into an Sqlite database? Or something else from http://docs.python.org/library/persistence.html. Or maybe http://www.pytables.org/ is more suitable to your needs (never used that one myself though). Or install a bank or 2 of memory in your box and read everything into memory in one big hashtable. Btw if you already have a big datatable in which the data is stored, I'm guessing that already is in some form of database format. Can't you write something that understands that database format. But I think you need to provide some more details about your data set. -irmen From no.email at nospam.invalid Thu Mar 25 04:04:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Mar 2010 01:04:23 -0700 Subject: Is there any library for indexing binary data? References: Message-ID: <7xaatwsu7s.fsf@ruckus.brouhaha.com> ?? writes: > Well, Database is not proper because 1. the table is very big (~10^9 > rows) 2. we should support very fast *simple* query that is to get > value corresponding to single key (~10^7 queries / second). Just one numeric key/value pair in each row? What's wrong with universal hashing? PyJudy might also be of interest: http://www.dalkescientific.com/Python/PyJudy.html From irmen at -NOSPAM-xs4all.nl Thu Mar 25 04:13:27 2010 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Thu, 25 Mar 2010 09:13:27 +0100 Subject: Saving a page loaded using the webbrowser library? In-Reply-To: <3b268d9b-0e37-4e19-9f28-9f560edff76b@b30g2000yqd.googlegroups.com> References: <3b268d9b-0e37-4e19-9f28-9f560edff76b@b30g2000yqd.googlegroups.com> Message-ID: <4bab1bad$0$22941$e4fe514c@news.xs4all.nl> On 3/25/10 8:41 AM, Dr. Benjamin David Clarke wrote: > Does anyone know of a way to save the a loaded web page to file after > opening it with a webbrowser.open() call? > > Specifically, what I want to do is get the raw HTML from a web page. > This web page uses Javascript. I need the resulting HTML after the > Javascript has been run. I've seen a lot about trying to get Python to > run Javascript but there doesn't seem to be any promising solution. I > can get the raw HTML that I want by saving the page after it has been > loaded via the webbrowser.open() call. Is there any way to automate > this? Does anyone have any ideas for better approaches to this > problem? I don't need ti to be pretty or anything. I think I would use an appropriate GUI automation library to simulate user interaction with the web browser that you just started, and e.g. select the File > Save page as > HTML only menu option from the browser... If the javascript heavily modifies the DOM, that might not work however. You might need additional tooling such as Web Developer Toolbar for Firefox where you then can View Source > View Generated Source. irmen From news1234 at free.fr Thu Mar 25 04:25:06 2010 From: news1234 at free.fr (News123) Date: Thu, 25 Mar 2010 09:25:06 +0100 Subject: how to display variables down a stackdump when an exception occurred Message-ID: <4bab1de2$0$19315$426a34cc@news.free.fr> Hi, I captured a piece of code with a try except statement: In the except part I display a stackdump try: domyxmlrpcstuff() except Exception as e: import traceback ex_type,ex_value,e_b = sys.exc_info() tbstring = traceback.format_exc() print '%s%s:%s:%s' % \ (msg,ex_type,ex_value,tbstring) The output, that I receive is: File "C:\mycode\myrpcclient.py", line 63, in upload_chunk rslt = myrpcclient.call() File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ return self.__send(self.__name, args) File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request verbose=self.__verbose File "C:\Python26\lib\xmlrpclib.py", line 1253, in request return self._parse_response(h.getfile(), sock) File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response p.feed(response) File "C:\Python26\lib\xmlrpclib.py", line 601, in feed self._parser.Parse(data, 0) ExpatError: syntax error: line 1, column 0 In order to understand more I would like to display the value of data in C:\Python26\lib\xmlrpclib.py", line 601 Is this possible in a non interactive fashion? This is a generic question about inspecting variables down the stack, whenever an exception occurs. I started another thread specifically about displaying the invalid xmlrpc data. N From news1234 at free.fr Thu Mar 25 04:31:05 2010 From: news1234 at free.fr (News123) Date: Thu, 25 Mar 2010 09:31:05 +0100 Subject: xpat error in xmlrp client. How to inspect data. Message-ID: <4bab1f4a$0$25677$426a74cc@news.free.fr> Hi, I'm havign a small xmlrpc client, which works normally fine. (xmlrpc via https) Sometimes however I receive an Exception about an expat error. The output, that I receive is: File "C:\mycode\myrpcclient.py", line 63, in upload_chunk rslt = myrpcclient.call() File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ return self.__send(self.__name, args) File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request verbose=self.__verbose File "C:\Python26\lib\xmlrpclib.py", line 1253, in request return self._parse_response(h.getfile(), sock) File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response p.feed(response) File "C:\Python26\lib\xmlrpclib.py", line 601, in feed self._parser.Parse(data, 0) ExpatError: syntax error: line 1, column 0 In order to continue debugging I'd like to dump the received http data, which "C:\Python26\lib\xmlrpclib.py", line 601 tried to parse without succes. How can I do this? thanks for any suggestions N From littlesweetmelon at gmail.com Thu Mar 25 05:28:25 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 17:28:25 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: <7xaatwsu7s.fsf@ruckus.brouhaha.com> References: <7xaatwsu7s.fsf@ruckus.brouhaha.com> Message-ID: Thank you Rubin! Let me have a look at Judy. It seems good at first glance. -- ShenLei 2010/3/25 Paul Rubin : > ?? writes: >> Well, Database is not proper because 1. the table is very big (~10^9 >> rows) 2. we should support very fast *simple* query that is to get >> value corresponding to single key (~10^7 queries / second). > > Just one numeric key/value pair in each row? What's wrong with > universal hashing? > > PyJudy might also be of interest: > http://www.dalkescientific.com/Python/PyJudy.html > -- > http://mail.python.org/mailman/listinfo/python-list > From tim.wintle at teamrubber.com Thu Mar 25 05:34:17 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 25 Mar 2010 09:34:17 +0000 Subject: Is it possible to use re2 from Python? In-Reply-To: References: Message-ID: <1269509657.7610.13.camel@localhost> On Wed, 2010-03-24 at 10:44 -0700, _wolf wrote: > yes we can! http://github.com/facebook/pyre2 I had made a thin wrapper experiment with here - looks like the version he's shipped is relatively complete and compatible with the re module though. I'll be interested in seeing how well it performs - The wrapper I had been experimenting with ended up far slower than the re module for simple expressions - and the fastest codepaths in RE2 seem to be ones that are incompatible with the API we're used to using in the re module. Tim From littlesweetmelon at gmail.com Thu Mar 25 05:55:27 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 17:55:27 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> References: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> Message-ID: Thank you irmen. I will take a look at pytable. FYI, let me explain the case clearly. Originally, my big data table is simply array of Item: struct Item { long id; // used as key BYTE payload[LEN]; // corresponding value with fixed length }; All items are stored in one file by using "stdio.h" function: fwrite(itemarray, sizeof(Item), num_of_items, fp); Note that "id" is randomly unique without any order. To speed up searching I regrouped / sorted them into two-level hash tables (in the form of files). I want to employ certain library to help me index this table. Since the table contains about 10^9 items and LEN is about 2KB, it is impossible to hold all data in memory. Furthermore, some new item may be inserted into the array. Therefore incremental indexing feature is needed. Hope this help you to understand my case. -- ShenLei 2010/3/25 Irmen de Jong : > On 3/25/10 4:28 AM, ?? wrote: >> >> Howdy, >> >> Recently, I am finding a good library for build index on binary data. >> Xapian& Lucene for python binding focus on text digestion rather than >> binary data. Could anyone give me some recommendation? Is there any >> library for indexing binary data no matter whether it is written in >> python? >> >> In my case, there is a very big datatable which stores structured >> binary data, eg: >> struct Item >> { >> long id; // used as key >> double value; >> }; >> >> I want to build the index on "id" field to speed on searching. Since >> this datatable is not constant, the library should support incremental >> indexing. If there is no suitable library, I have to do the index by >> myself... >> >> Thank you in advance. >> >> -- >> ShenLei > > Put it into an Sqlite database? Or something else from > http://docs.python.org/library/persistence.html. > Or maybe http://www.pytables.org/ is more suitable to your needs (never used > that one myself though). > Or install a bank or 2 of memory in your box and read everything into memory > in one big hashtable. > > Btw if you already have a big datatable in which the data is stored, I'm > guessing that already is in some form of database format. Can't you write > something that understands that database format. > > But I think you need to provide some more details about your data set. > > -irmen > -- > http://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Thu Mar 25 05:57:23 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 25 Mar 2010 09:57:23 +0000 Subject: threads (specifically timers) and releasing resources In-Reply-To: References: Message-ID: <4BAB3383.7080003@timgolden.me.uk> On 25/03/2010 02:31, Alex Hall wrote: > Okay, I have my program and it has three different modes (there will > be more than that). Each mode will have a timer attached to it. If the > mode remains active and the timer runs out, a function specific to > that mode is called. If that mode is switched away from, however, the > timer is canceled and a new timer is created for the mode to which the > user just switched. I assume you're using Python's threading.Timer objects as you'd discussed those before. If so, that's basically a threading.Thread in disguise. In which case, you're going to have to make sure it cleans up after itself, releasing whatever resources it holds. Python's reference-count semantics and cyclic gc will take care of things in the normal way once the timer-thread has completed. But you'll have to make sure it completes. > If the latter, is there a way to completely destroy a thread? No: in Python, a thread has to self-destruct. This is a relatively FAQ and there are quite a few recipes around. Here's an example of something which seems to be close to your current needs: http://code.activestate.com/recipes/464959-resettable-timer-class/ TJG From egbertum at xs4all.nl Thu Mar 25 06:16:32 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 25 Mar 2010 11:16:32 +0100 Subject: from import and __init__.py Message-ID: <20100325101632.GA4727@xs4all.nl> When I do 'from some_package import some_module' the __init__.py of some_package will be run. However, there will not be anything like a package-module, and the effects of __init__.py seem all to be lost. Is that true ? Or can I still do something useful with __init__.py ? e -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From rami.chowdhury at gmail.com Thu Mar 25 07:10:33 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 25 Mar 2010 04:10:33 -0700 Subject: the Python Foundation In-Reply-To: <7xwrx1z4nq.fsf@ruckus.brouhaha.com> References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> <7xwrx1z4nq.fsf@ruckus.brouhaha.com> Message-ID: <20100325111033.GB18576@tigris> On 2010-03-24 16:22, Paul Rubin wrote: > "Steve Holden, Chairman, PSF" writes: > > We have also registered the trademark "Python" for use in reference to > > computer programming languages, thereby ensuring that we can take action > > should some ill-advised individual or organization decide to produce > > another language with "Python" in its name > > There has been a Lisp compiler called "Python" for many years: > > http://portal.acm.org/citation.cfm?id=141471.141558 The FAQ disclaims any connection and claims that Python the Lisp compiler has been around longer than Python the language... http://www.cons.org/cmucl/FAQ.html I was awfully confused the first time I came across SBCL giving me warnings about Python, though -- proves how well the PSF has safeguarded the name! > -- > http://mail.python.org/mailman/listinfo/python-list From newton10471 at gmail.com Thu Mar 25 07:42:08 2010 From: newton10471 at gmail.com (newton10471) Date: Thu, 25 Mar 2010 04:42:08 -0700 (PDT) Subject: chroot fails with mount point passed to subprocess.Popen? References: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Message-ID: <0bbff19b-1cb1-40bb-950c-7594d0eba6cc@r1g2000yqj.googlegroups.com> Hi Alf, After doing some more research, including the character-by-character comparison you suggested (thank you!), I was able to get things working the way I wanted using the following: def getInstalledKernelVersion(mountPoint): linuxFsRoot = mountPoint + "/root" installedKernelVersionResult = subprocess.Popen(['/usr/sbin/ chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'], stdout=subprocess.PIPE).communicate()[0] return installedKernelVersionResult Thanks very much for you help, -Matt On Mar 22, 9:33?am, "Alf P. Steinbach" wrote: > * newton10471: > > > > > Hi, > > > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount > > point passed in as a parameter to the following function: > > > def getInstalledKernelVersion(mountPoint): > > ? ? linuxFsRoot = mountPoint + "/root" > > ? ? print "type of linuxFsRoot is %s" % type(linuxFsRoot) > > ? ? installedKernelVersionResult = > > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) > > ? ? return installedKernelVersionResult > > > and it dies with the following: > > > type of linuxFsRoot is > > chroot: cannot change root directory to /storage/mounts/ > > mnt_3786314034939740895.mnt/root: No such file or directory > > > When I explicitly set linuxFsRoot = "/storage/mounts/ > > mnt_3786314034939740895.mnt/root", it works fine. > > > I also tried this to concatenate the mountpoint + /root, and it failed > > in the same way: > > > linuxFsRoot = ("%s/root") % mountPoint > > Use the os.path functions. > > > Anyone know what might be happening here? > > Since the computed and literal paths /look/ identical and same type, the only > thing I can imagine is that there is some invisible character. Try comparing the > computed and literal path character by character. Print the difference or if > they're identical, that they are. > > Possibly you have GIGO problem. > > Cheers & hth., > > - Alf From steve at holdenweb.com Thu Mar 25 07:42:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Mar 2010 07:42:20 -0400 Subject: from import and __init__.py In-Reply-To: <20100325101632.GA4727@xs4all.nl> References: <20100325101632.GA4727@xs4all.nl> Message-ID: egbert wrote: > When I do 'from some_package import some_module' > the __init__.py of some_package will be run. > However, there will not be anything like a package-module, > and the effects of __init__.py seem all to be lost. Is that true ? > Or can I still do something useful with __init__.py ? > e If I understand correctly what you mean byt a "package-module" then __init__.py is exactly what you are looking for. Many packages are built with an empty __init__.py because they are intended mostly to build a tree-like set of namespaces, but __init__.py *is* run when the package is imported, and its namespace is bound to the name of the package within the importing program. So if you have code you want to run when the package is imported, put it there. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From newton10471 at gmail.com Thu Mar 25 07:42:22 2010 From: newton10471 at gmail.com (newton10471) Date: Thu, 25 Mar 2010 04:42:22 -0700 (PDT) Subject: chroot fails with mount point passed to subprocess.Popen? References: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Message-ID: <73728874-ff0a-4360-a328-50fc19236bf6@d27g2000yqf.googlegroups.com> Hi Alf, After doing some more research, including the character-by-character comparison you suggested (thank you!), I was able to get things working the way I wanted using the following: def getInstalledKernelVersion(mountPoint): linuxFsRoot = mountPoint + "/root" installedKernelVersionResult = subprocess.Popen(['/usr/sbin/ chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'], stdout=subprocess.PIPE).communicate()[0] return installedKernelVersionResult Thanks very much for you help, -Matt On Mar 22, 9:33?am, "Alf P. Steinbach" wrote: > * newton10471: > > > > > Hi, > > > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount > > point passed in as a parameter to the following function: > > > def getInstalledKernelVersion(mountPoint): > > ? ? linuxFsRoot = mountPoint + "/root" > > ? ? print "type of linuxFsRoot is %s" % type(linuxFsRoot) > > ? ? installedKernelVersionResult = > > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) > > ? ? return installedKernelVersionResult > > > and it dies with the following: > > > type of linuxFsRoot is > > chroot: cannot change root directory to /storage/mounts/ > > mnt_3786314034939740895.mnt/root: No such file or directory > > > When I explicitly set linuxFsRoot = "/storage/mounts/ > > mnt_3786314034939740895.mnt/root", it works fine. > > > I also tried this to concatenate the mountpoint + /root, and it failed > > in the same way: > > > linuxFsRoot = ("%s/root") % mountPoint > > Use the os.path functions. > > > Anyone know what might be happening here? > > Since the computed and literal paths /look/ identical and same type, the only > thing I can imagine is that there is some invisible character. Try comparing the > computed and literal path character by character. Print the difference or if > they're identical, that they are. > > Possibly you have GIGO problem. > > Cheers & hth., > > - Alf From dksreddy at gmail.com Thu Mar 25 08:15:54 2010 From: dksreddy at gmail.com (Sandy) Date: Thu, 25 Mar 2010 05:15:54 -0700 (PDT) Subject: cxfreeze on ubuntu 9.10 References: <84719a38-3d00-4d46-aa11-f0dca7ace71c@q15g2000yqj.googlegroups.com> Message-ID: <0a385e57-7564-47e1-ab4b-0c75de8ce0d2@r27g2000yqn.googlegroups.com> I used cxFreeze without any problem on Ubuntu 9.10 32 bit version. I tried it on a wxPython gui script and it works fine though I did'n use any setup file. Just try cxFreeze executable (should be in /usr/bin/) instead of setup file. $/usr/bin/cxFreeze my_script.py --target-dir=/what_ever_dir/ what_ever_dir will have the executable file and other libraries needed to run the executable. - dksr On Mar 25, 12:33?am, Waspinator wrote: > Hi, > > I'm trying to compile a python script on Ubuntu 9.10. It uses the gtk > toolkit. I tried to run GUI2EXE for a cxfreeze gui, but even after > installing wxPython in synaptic it still complains about not having > it. > > I also tried to use cxfreeze by itself but the file it produces does > not run. > > I tried to follow the information athttp://cx-freeze.sourceforge.net/cx_Freeze.html > > I created a setup.py file that looks like this (from the page) > > from cx_Freeze import setup, Executable > > setup( > ? ? ? ? name = "gtk_test", > ? ? ? ? version = "0.1", > ? ? ? ? description = "gtk_test", > ? ? ? ? executables = [Executable("gtk_test.py")]) > > and ran: > > python setup.py build > > When I try to run the executable I get the following error: > > ../build/exe.linux-i686-2.6/library.zip/gtk/_gtk.py:12: > RuntimeWarning: tp_compare didn't return -1 or -2 for exception > ImportError: could not import gio > ImportError: could not import gio > Traceback (most recent call last): > ? File "/usr/lib/pymodules/python2.6/cx_Freeze/initscripts/ > Console.py", line 29, in > ? ? exec code in m.__dict__ > ? File "gtk_test.py", line 274, in > ? File "gtk_test.py", line 228, in main > AttributeError: 'module' object has no attribute 'Window' > > I was thinking of using the 'copy-dependent-files' option but I'm not > sure how. > > Any ideas? > > Thanks From ethan at stoneleaf.us Thu Mar 25 08:28:22 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 25 Mar 2010 05:28:22 -0700 Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] In-Reply-To: References: Message-ID: <4BAB56E6.2070201@stoneleaf.us> Michele Simionato wrote: > On Jan 16, 9:27 pm, mk wrote: > >>Hello everyone, >> >>I looked for it I swear, but just can't find it. >> >>Most Python books seem to focus on examples of how to call functions >>from standard library. I don't need that, I have online Python >>documentation for that. >> >>I mean really advanced mental gymnastics, like gory details of how >>Python objects operate, how to exploit its dynamic capabilities, dos and >>donts with particular Python objects, advanced tricks, everything from >>chained decorators to metaprogramming. Dive Into Python comes closest to >>this ideal from what I have found, but still not far enough. >> >>Anybody found such holy grail? > > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > a review for it: > > http://www.artima.com/weblogs/viewpost.jsp?thread=240415 > > There is plenty of info about Advanced Python on the net, much more > than in book form. Come to think of it, there are my Oxford lectures > (the title was exactly "Advanced Python Programming") and I could > republish it on my blog, since I cannot find them on the net anymore. > > Michele Simionato Michele, Was wondering if you'd had a chance to re-post your lectures -- just did a search for them and came up empty, and I would love to read them! Many thanks in advance! ~Ethan~ From neilc at norwich.edu Thu Mar 25 08:37:14 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Mar 2010 12:37:14 GMT Subject: sum for sequences? References: <2010032423502316807-tomfsessile@gmailcom> Message-ID: <8113nqFsggU3@mid.individual.net> On 2010-03-25, Steven D'Aprano wrote: >> You might not want to be so glib. The sum doc sure doesn't >> sound like it should work on lists. >> >> Returns the sum of a sequence of numbers (NOT strings) plus the >> value of parameter 'start' (which defaults to 0). > > What part of that suggested to you that sum might not be polymorphic? > Sure, it says numbers (which should be changed, in my opinion), but it > doesn't specify what sort of numbers -- ints, floats, or custom types > that have an __add__ method. WTF. -- Neil Cerutti "It's not fun to build walls. But it's even less fun to live without walls in a world full of zombies." --Greedy Goblin From stefan_ml at behnel.de Thu Mar 25 08:44:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Mar 2010 13:44:35 +0100 Subject: sum for sequences? In-Reply-To: <8113nqFsggU3@mid.individual.net> References: <2010032423502316807-tomfsessile@gmailcom> <8113nqFsggU3@mid.individual.net> Message-ID: Neil Cerutti, 25.03.2010 13:37: > On 2010-03-25, Steven D'Aprano wrote: >>> You might not want to be so glib. The sum doc sure doesn't >>> sound like it should work on lists. >>> >>> Returns the sum of a sequence of numbers (NOT strings) plus the >>> value of parameter 'start' (which defaults to 0). >> >> What part of that suggested to you that sum might not be polymorphic? >> Sure, it says numbers (which should be changed, in my opinion), but it >> doesn't specify what sort of numbers -- ints, floats, or custom types >> that have an __add__ method. > > WTF. Warning: truth found! Stefan From python at hope.cz Thu Mar 25 08:45:21 2010 From: python at hope.cz (Johny) Date: Thu, 25 Mar 2010 05:45:21 -0700 (PDT) Subject: Does a tiny Python distribution exist? Message-ID: <29c82125-10ce-4302-9423-c8b92a7911f9@q23g2000yqd.googlegroups.com> Does anyone know if there is a tiny Python distribution available running in a Linux environment? From alfps at start.no Thu Mar 25 09:02:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 25 Mar 2010 14:02:05 +0100 Subject: sum for sequences? In-Reply-To: <8113nqFsggU3@mid.individual.net> References: <2010032423502316807-tomfsessile@gmailcom> <8113nqFsggU3@mid.individual.net> Message-ID: * Neil Cerutti: > On 2010-03-25, Steven D'Aprano wrote: >>> You might not want to be so glib. The sum doc sure doesn't >>> sound like it should work on lists. >>> >>> Returns the sum of a sequence of numbers (NOT strings) plus the >>> value of parameter 'start' (which defaults to 0). >> What part of that suggested to you that sum might not be polymorphic? >> Sure, it says numbers (which should be changed, in my opinion), but it >> doesn't specify what sort of numbers -- ints, floats, or custom types >> that have an __add__ method. > > WTF. I think Steven's argument is that it would be pointless for 'sum' to distinguish between user-defined numerical types and other types that happen to support '+'. It could make such a distinction since there's a type hierarchy for numbers, but then that should IMHO be more clearly documented. However, given that it isn't restricted to numbers, the restriction wrt. strings is a bit perplexing in the context of modern CPython. But for Python implementations that don't offer the '+=' optimization it might help to avoid gross inefficiencies, namely quadratic time string concatenation. E.g., here's a natural implementation of sum -- with unoptimized '+=' yielding quadratic time for the string concatenation (with modern CPython it's linear time, though): >>> def sum_all( values, start = 0 ): ... s = start ... for v in values: s += v ... return s ... >>> sum_all( (1, 2, 3, 4) ) 10 >>> sum_all( ("a", "b", "c", "d"), "" ) 'abcd' >>> sum_all( ((1, 2), (3, 4), (5, 6)), () ) (1, 2, 3, 4, 5, 6) >>> _ However, if that hypothesis about the rationale is correct, then 'sum' should also be restricted to not handle tuples or lists, so forth, but at least the CPython implementation does. So perhaps the documentation needs to be more clear? Cheers, - Alf From icanbob at gmail.com Thu Mar 25 09:17:34 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 25 Mar 2010 06:17:34 -0700 (PDT) Subject: Advice needed on parallel processing in python References: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Message-ID: On Mar 24, 1:13 pm, Jon Clements wrote: > On 24 Mar, 15:27, Glazner wrote: > > > > > Hi! > > > I need to replace an app that does number crunching over a local > > network. > > it have about 50 computers as slaves > > each computer needs to run COM that will do the "job" > > right now the system uses MFC threads and DCOM to distribute the load. > > > as i said, Now i'm trying to replace this system with python. > > I already use win32all and read about Pareller Python and Pyro. > > > a requirement is that messages can be sent to the remote worker. > > > If anyone can share experience I'll love to hear > > > Many Thanks, > > Yoav Glazner > > Would Celery suit?http://celeryproject.org/ > > hth > > Jon. If you can add just one Linux server onto that network you could use SIMPL-Python to do what you want. http://www.icanprogram.com/06py/lesson1/lesson1.html ie. SIMPL messages going seamlessly from Python (Windows) to Python (Windows) with the SIMPL sandbox being hosted on the Linux node. Of course if you wanted to add Linux nodes as processing nodes. Python (Windows) modules could seamlessly exchange messages with those as well. Same would be true if you wanted to distribute part of your app into the cloud. All your Python code would look virtually identical in each of these cases. As an example of an inexpensive Linux node the SIMPL toolkit has been ported to the ~$100 Sheeva Plug computer (http://www.icanprogram.com/ simpl/plugsimplbin.self.html) (http://www.plugcomputer.org). bob From icanbob at gmail.com Thu Mar 25 09:22:14 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 25 Mar 2010 06:22:14 -0700 (PDT) Subject: Python is cool!! References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <05932144-af1d-4369-8999-50ca5575ae20@z4g2000yqa.googlegroups.com> On Mar 23, 11:55 am, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... > > Any opinion You probably want to take a look at this tutorial as well: http://www.icanprogram.com/06py/lesson1/lesson1.html The SIMPL toolkit will give you added flexibility to choose the language for some of your more computationally intensive simulations and still present a unified Python interface to the whole thing. bob From michele.simionato at gmail.com Thu Mar 25 09:24:04 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 25 Mar 2010 06:24:04 -0700 (PDT) Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] References: mailman.1182.1269520510.23598.python-list@python.org Message-ID: <54e41616-df9f-42dd-9c91-9e530650bd99@j21g2000yqh.googlegroups.com> On Mar 25, 1:28?pm, Ethan Furman wrote: > > Michele, > > Was wondering if you'd had a chance to re-post your lectures -- just did > a search for them and came up empty, and I would love to read them! > > Many thanks in advance! Oops, I forgot! I will try to make them available soon. From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 25 10:02:18 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Mar 2010 15:02:18 +0100 Subject: Advice Criticism on Python App In-Reply-To: References: Message-ID: <4bab6cd6$0$9118$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote: > >> Jimbo wrote: >>> class stock: >>> code = "" >>> purchasePrice = 0 >>> purchaseQuantity = 0 >>> price = [] # list of recent prices >>> recentBid = [] # list of recent bids for stock >>> recentOffer = [] # list of recent offers for stock >>> stockVol = [] # list of stock quantity available on market >> Using lists as class variables is a very good way to create very >> surprising bugs. Consider the following: > [snip] > > > Don't you think that the class attributes are *supposed* to be shared by > all instances? In that case the behaviour you show is not a bug at all. Python's class attributes are indeed supposed to be shared - that's even the whole point of having class attributes. But this feature has proven to be confusing for newcomers that more often than not have previous exposure to OOPLs where you do "declare" your class "schema" at the class level (where Python defines class attributes). Now reread the OP's code, and you'll find out he's indeed yet another victim of this gotcha: """ for row in cur.fetchall(): newStock = stock() newStock.code = row[0] newStock.purchasePrice = row[1] newStock.purchaseQuantity = row[2] cur.execute(stockQuery,[newStock.code]) for rw in cur.fetchall(): newStock.price.append(rw[0]) newStock.recentOffer.append(rw[1]) newStock.recentBid.append(rw[2]) newStock.stockVol.append(rw[3]) stockList.append(newStock) """ From mehgcap at gmail.com Thu Mar 25 10:38:36 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 25 Mar 2010 10:38:36 -0400 Subject: threads (specifically timers) and releasing resources In-Reply-To: <4BAB3383.7080003@timgolden.me.uk> References: <4BAB3383.7080003@timgolden.me.uk> Message-ID: Thanks, this should work. On 3/25/10, Tim Golden wrote: > On 25/03/2010 02:31, Alex Hall wrote: >> Okay, I have my program and it has three different modes (there will >> be more than that). Each mode will have a timer attached to it. If the >> mode remains active and the timer runs out, a function specific to >> that mode is called. If that mode is switched away from, however, the >> timer is canceled and a new timer is created for the mode to which the >> user just switched. > > I assume you're using Python's threading.Timer objects as you'd discussed > those before. If so, that's basically a threading.Thread in disguise. > In which case, you're going to have to make sure it cleans up after itself, > releasing whatever resources it holds. > > Python's reference-count semantics and cyclic gc will take care of > things in the normal way once the timer-thread has completed. But > you'll have to make sure it completes. > >> If the latter, is there a way to completely destroy a thread? > > No: in Python, a thread has to self-destruct. This is a relatively > FAQ and there are quite a few recipes around. Here's an example of > something which seems to be close to your current needs: > > http://code.activestate.com/recipes/464959-resettable-timer-class/ > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 25 11:01:51 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Mar 2010 16:01:51 +0100 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4bab7acb$0$2873$426a74cc@news.free.fr> Jose Manuel a ?crit : > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. Python is indeed quite lightweight when compared to Java. But it has it's share of non-obvious features, dark corners, gotchas, and plain warts too. > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... If you think of some server-page PHP-like solution, you won't find much usable stuff. There are quite a few Python web development toolkits / frameworks, but Django is becoming the de facto standard. Arguably not the "best" framework (depending on your definition of "best"), but certainly one of the most pythonic and well documented around. From fpm at u.washington.edu Thu Mar 25 11:10:59 2010 From: fpm at u.washington.edu (cassiope) Date: Thu, 25 Mar 2010 08:10:59 -0700 (PDT) Subject: Does a tiny Python distribution exist? References: <29c82125-10ce-4302-9423-c8b92a7911f9@q23g2000yqd.googlegroups.com> Message-ID: <25d0272d-1a49-40e0-96ac-6c8d431b0c18@c20g2000prb.googlegroups.com> On Mar 25, 5:45?am, Johny wrote: > Does anyone know if there is a tiny Python distribution available > running in a Linux environment? Debian has a package: "python-minimal". HTH... From omrihsan at gmail.com Thu Mar 25 11:23:46 2010 From: omrihsan at gmail.com (Omer Ihsan) Date: Thu, 25 Mar 2010 08:23:46 -0700 (PDT) Subject: nested threading Message-ID: <4566e767-768f-4399-8a6b-5530ec90b03c@a37g2000prd.googlegroups.com> is there anything as "nested threading"....that is, call a thread from within a thread. in this case how will thread locking take place. for example initially there were two functions that were called using threading.Thread. these wont get unlocked unless both of them are done with whatever they need to do. if say function 2 calls another thread. then what?? inquisitive....:-| From mail at timgolden.me.uk Thu Mar 25 11:25:46 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 25 Mar 2010 15:25:46 +0000 Subject: Does a tiny Python distribution exist? In-Reply-To: <25d0272d-1a49-40e0-96ac-6c8d431b0c18@c20g2000prb.googlegroups.com> References: <29c82125-10ce-4302-9423-c8b92a7911f9@q23g2000yqd.googlegroups.com> <25d0272d-1a49-40e0-96ac-6c8d431b0c18@c20g2000prb.googlegroups.com> Message-ID: <4BAB807A.7040104@timgolden.me.uk> On 25/03/2010 15:10, cassiope wrote: > On Mar 25, 5:45 am, Johny wrote: >> Does anyone know if there is a tiny Python distribution available >> running in a Linux environment? > > Debian has a package: "python-minimal". > > HTH... tinypy? http://www.tinypy.org/ TJG From jason.heeris at gmail.com Thu Mar 25 11:39:01 2010 From: jason.heeris at gmail.com (Jason) Date: Thu, 25 Mar 2010 08:39:01 -0700 (PDT) Subject: Represent object type as Message-ID: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> Hi, I want to send objects (new style) over DBUS. DBUS can only send fairly primitive types[1] so I turn my objects into dicts and send that. I'm reusing the __getstate__ function I wrote for pickling like so: def __getstate__(self): attrs = self.__dict__.copy() return attrs ...which is perfectly adequate to dict-ify and reconstitute this simple class. That works just fine over DBUS. The trouble is, the object could actually be of some slightly different types, so I'd like to include that information as well. I tried something like: def __getstate__(self): attrs = self.__dict__.copy() attrs.update({'type': type(self)}) return attrs ...but then realised that "type" is not primitive enough for DBUS to pickle. So, (a) can I get the type name from the type object, or (b) is there a better way to do this? (This pertains to Python 2.5.4.) Cheers, ? Jason [1] http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#data-types From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 25 12:00:34 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Mar 2010 17:00:34 +0100 Subject: Represent object type as In-Reply-To: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> References: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> Message-ID: <4bab888e$0$26553$426a74cc@news.free.fr> Jason a ?crit : > Hi, > > I want to send objects (new style) over DBUS. DBUS can only send > fairly primitive types[1] so I turn my objects into dicts and send > that. I'm reusing the __getstate__ function I wrote for pickling like > so: > > def __getstate__(self): > attrs = self.__dict__.copy() > return attrs > > ...which is perfectly adequate to dict-ify and reconstitute this > simple class. That works just fine over DBUS. > > The trouble is, the object could actually be of some slightly > different types, so I'd like to include that information as well. I > tried something like: > > def __getstate__(self): > attrs = self.__dict__.copy() > attrs.update({'type': type(self)}) attrs['type'] = type(self) Do the same thing with less work !-) Also and while we're at it, using a __magicname__ convention here (ie : '__type__' instead of 'type') might avoid possible collisions. > return attrs > > ...but then realised that "type" is not primitive enough for DBUS to > pickle. > > So, (a) can I get the type name from the type object, attrs['__typename__'] = type(self).__name__ Warning: won't be very useful if your code still uses old-style classes. > or (b) is there > a better way to do this? Depends on what you do with this dict, DBUS etc. And of your definition of "better", of course. HTH From sccolbert at gmail.com Thu Mar 25 12:23:47 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 25 Mar 2010 12:23:47 -0400 Subject: ANN: Pymazon 0.1.1 Released Message-ID: <7f014ea61003250923k50d1fc60h108f83c01c15478b@mail.gmail.com> I'm happy to announce the release of Pymazon 0.1.1! This release brings a big enhancement in the form of PyGtk support in addition to the PyQt4 and Command line interfaces already available. A special thanks to Ray Meyers for his gtk commits! Pymazon Changelog 0.1.1 ----- - Added support for command line options and configuration file - Added support for save name templates - Added a threaded downloader which runs a user-specified simultaneous threads when in gui mode - Added a PyGtk Gui (Submitted by Raymond Myers) - Rewrote the QT Gui with Qt Designer and pyuic4 - this simplified and cleaned up a bunch of stuff - Added graphical progress bars to the Gui's - Removed a check that asserted the downloaded file size was the same as specified in the amz file as Amazon was misreporting file size and it was causing Pymazon to erroneously fail - Cleaned up code all over the place: logging, settings, etc... Pymazon is available in the cheeseshop and google code. Pymazon is a Python implemented downloader for the amazon mp3 store. You can read more about Pymazon at http://code.google.com/p/pymazon/. I always appreciate comments and bug reports. Cheers! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Mar 25 12:43:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Mar 2010 12:43:13 -0400 Subject: from import and __init__.py In-Reply-To: <20100325101632.GA4727@xs4all.nl> References: <20100325101632.GA4727@xs4all.nl> Message-ID: On 3/25/2010 6:16 AM, egbert wrote: > When I do 'from some_package import some_module' > the __init__.py of some_package will be run. > However, there will not be anything like a package-module, > and the effects of __init__.py seem all to be lost. Is that true ? No. If you do from sys import modules print(modules.keys()) you will see both some_package and some_package.some_module among the entries. The first is the result of executing some_package/__init__.py. As usual, that code will *not* be re-exectured on subsequent imports involving some_package. > Or can I still do something useful with __init__.py ? > e Some packages put something like 'from _default_stuff import *' in __init__.py with the intention that the package by used as import package perhaps [optionally] followed by import package.specialized_stuff Terry Jan Reedy From sridharr at activestate.com Thu Mar 25 12:59:30 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 25 Mar 2010 09:59:30 -0700 Subject: ANN: ActivePython 2.6.5.12 and 3.1.2.3 are now available Message-ID: <5BD6EC71-9F23-4DF8-9DCE-9A03E6FFFAEC@activestate.com> We are pleased to announce the availability of both ActivePython 2.6.5.12 and ActivePython 3.1.2.3. http://www.activestate.com/activepython/ Here is what you should know about these two releases: PyWin32: PyWin32 is now included in the 64-bit & Python3 builds! Since we recently updated our PyWin32 source tree, this release comes with several bug fixes. PyPM: There is now an ?upgrade? feature in PyPM, our beloved Python Package Manager distributed with ActivePython free of charge. What this means is that if you type ?pypm upgrade? it will update all your installed Python Packages to the latest version to save you time and keep you up-to-date. Switch between Python versions: Also new in this 2.6 release is a new tool called "pythonselect" that can be used to switch between multiple ActivePython versions. This is currently only supported on MacOSX although support for other platforms and, perhaps, other Python installations, is in the roadmap (patches are welcome too!). Dive Into Python 3: ActivePython 3.1.2.3 now includes Mark Pilgrim?s Dive Into Python 3, the popular advanced tutorial for learning Python3. You can find it in the documentation section. Miscellaneous: We also updated the base Tcl/Tk version to 8.5.8; added OpenSSL and ctypes support in the 64-bit build; upgraded to openssl-0.9.8l; included Tcl/Tk development headers ? among several other bug fixes with IDLE and Tkinter installation. And of course, they use the latest Python version: 2.6.5 and 3.1.2. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html#changes http://docs.activestate.com/activepython/2.6/relnotes.html#changes And our blog post on this release: http://blogs.activestate.com/2010/03/activestate-releases-activepython-2-6-5-12-and-activepython-3-1-2-3/ What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Builds for Solaris, HP-UX and AIX, and access to older versions are available with ActivePython Business Edition: http://www.activestate.com/business_edition/ ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. Beginning with the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: pypm install pylons See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: ActivePython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC (Business Edition only) - Solaris/x86 (Business Edition only) - HP-UX/PA-RISC (Business Edition only) - AIX/PowerPC (Business Edition only) - AIX/PowerPC 64-bit (Business Edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/activepython/enterprise/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From andreas.loescher at s2005.tu-chemnitz.de Thu Mar 25 13:41:23 2010 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Thu, 25 Mar 2010 18:41:23 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: Message-ID: <1269538883.9315.6.camel@laptop> > As you see, the traceback only starts from function c, which handles the > exception. > It doesn't show main(), a() and b(), which might however be (and are, in > my case) critical to diagnose the severity of the problem (since many > different paths would lead to calling c()). This results in the way the tb is created. If an exception occours, and there is no one who handles it in the current function, a traceback object is created. Because the the calling function could have a try-except clause, the function returns with NULL and an set exception. Now if there is no one to handle the exception, a traceback object is created and linked with the existing one. In your case does the traceback start from the function c, because no exception occoured in main() etc. You catched it. If you want to determine the calling path, you can take a look at the encapsuled frame in the tb. Best From anfedorov at gmail.com Thu Mar 25 13:41:57 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 25 Mar 2010 13:41:57 -0400 Subject: Repetition of work in Jython Message-ID: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> Hi all, So from what I understand, Jython translates Python code into JVM byte code. Does anyone know why this was chosen instead of translating Python bytecode to JVM bytecode directly? It seems that it would be a lot easier to get Jython up-to-speed if there could be some "shared components" between them and CPython, no? - Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Mar 25 14:10:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Mar 2010 14:10:00 -0400 Subject: Repetition of work in Jython In-Reply-To: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> References: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> Message-ID: <4BABA6F8.8070609@holdenweb.com> Andrey Fedorov wrote: > Hi all, > > So from what I understand, Jython translates Python code into JVM byte > code. Does anyone know why this was chosen instead of translating Python > bytecode to JVM bytecode directly? It seems that it would be a lot > easier to get Jython up-to-speed if there could be some "shared > components" between them and CPython, no? > I don't *know* why Jim Hugunin chose not to take that approach, but I can easily imagine it would be because a mapping of the Python byte code to the Java byte code would be much less efficient. There are various approaches that one could take. The least efficient would be to write a Python virtual machine in Java, thereby putting two levels of interpretation into the execution paths. I doubt it would be possible to get maximal JVM efficiency from code cast into Python byte codes just because of the disparity between the two VMs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Mar 25 14:10:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Mar 2010 14:10:00 -0400 Subject: Repetition of work in Jython In-Reply-To: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> References: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> Message-ID: <4BABA6F8.8070609@holdenweb.com> Andrey Fedorov wrote: > Hi all, > > So from what I understand, Jython translates Python code into JVM byte > code. Does anyone know why this was chosen instead of translating Python > bytecode to JVM bytecode directly? It seems that it would be a lot > easier to get Jython up-to-speed if there could be some "shared > components" between them and CPython, no? > I don't *know* why Jim Hugunin chose not to take that approach, but I can easily imagine it would be because a mapping of the Python byte code to the Java byte code would be much less efficient. There are various approaches that one could take. The least efficient would be to write a Python virtual machine in Java, thereby putting two levels of interpretation into the execution paths. I doubt it would be possible to get maximal JVM efficiency from code cast into Python byte codes just because of the disparity between the two VMs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From sridharr at activestate.com Thu Mar 25 14:47:27 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 25 Mar 2010 11:47:27 -0700 Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 In-Reply-To: References: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> Message-ID: On 2010-02-09, at 2:49 PM, Sridhar Ratnakumar wrote: > > On 2010-02-07, at 5:02 PM, escalation746 wrote: > >> Andrej Mitrovic wrote: >> >>> Perhaps you've accidentally downloaded the wrong version of PythonWin? >> >> Erk, yes, my bad. >> >> Thanks for the quick help! Though I still wonder why the ActiveState >> build does not include this. > > I just added support for PyWin32 in ActivePython 2.6 64-bit. > > http://twitter.com/sridhr/status/8874549314 > > I should be part of next release (2.6.4.11). PyWin32, and thus PythonWin, is now available in all of the recent ActivePython releases: 2.5.5.7, 2.6.5.12 and 3.1.2.3. See also http://blogs.activestate.com/2010/03/activestate-releases-activepython-2-6-5-12-and-activepython-3-1-2-3/ -srid -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen-NOSPAM- at xs4all.nl Thu Mar 25 14:55:45 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Thu, 25 Mar 2010 19:55:45 +0100 Subject: Is there any library for indexing binary data? In-Reply-To: References: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> Message-ID: <4babb132$0$22945$e4fe514c@news.xs4all.nl> On 25-3-2010 10:55, ?? wrote: > Thank you irmen. I will take a look at pytable. > FYI, let me explain the case clearly. > > Originally, my big data table is simply array of Item: > struct Item > { > long id; // used as key > BYTE payload[LEN]; // corresponding value with fixed length > }; > > All items are stored in one file by using "stdio.h" function: > fwrite(itemarray, sizeof(Item), num_of_items, fp); > > Note that "id" is randomly unique without any order. To speed up > searching I regrouped / sorted them into two-level hash tables (in > the form of files). I want to employ certain library to help me index > this table. > > Since the table contains about 10^9 items and LEN is about 2KB, it is > impossible to hold all data in memory. Furthermore, some new item may > be inserted into the array. Therefore incremental indexing feature is > needed. I see, I thought the payload data was small as well. What about this idea: Build a hash table where the keys are the id from your Item structs and the value is the file seek offset of the Item 'record' in your original datafile. (although that might generate values of type long, which take more memory than int, so maybe we should use file_offset/sizeof(Item). This way you can just keep your original data file (you only have to scan it to build the hash table) and you will avoid a lengthy conversion process. If this hashtable still doesn't fit in memory use a sparse array implementation of some sort that is more efficient at storing simple integers, or just put it into a database solution mentioned in earlier responses. Another thing: I think that your requirement of 1e7 lookups per second is a bit steep for any solution where the dataset is not in core memory at once though. Irmen. From st.chris at gmail.com Thu Mar 25 15:51:48 2010 From: st.chris at gmail.com (=?UTF-8?Q?Christian_=C5=9Etef=C4=83nescu?=) Date: Thu, 25 Mar 2010 20:51:48 +0100 Subject: Improved timedelta attributes/methods Message-ID: Hello dear Python-wielding developers! I generally like date/time handling in Python very much, especially how date operations result in Timedelta objects. But I find it somewhat impractical, that you can only get days, seconds and microseconds out of a time delta. I think it would be much more comfortable to have fields for minutes, hours, maybe also years, months. Is there a specific reasoning why this is not available? I would gladly do my best to implement such a solution, if it would make sense to the devs. Regards, Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at psantoro.net Thu Mar 25 16:07:42 2010 From: peter at psantoro.net (Peter) Date: 25 Mar 2010 20:07:42 GMT Subject: RELEASED Python 2.6.5 References: Message-ID: On Wed, 24 Mar 2010 23:22:01 +0100, Martin v. Loewis wrote: >> Is anyone else having trouble with the 2.6.5 Windows x86 installer? > > Not me. Run > > msiexec /i py...msi /l*v py.log > > and inspect py.log for errors (post it to bugs.python.org if you can't > determine the cause of the problems). Martin, Thanks for the tip about the msiexec command line usage. If I run the installer without selecting the Advanced compiling option, it works fine. The relevent part of the log when it fails using the Advanced compiling option is as follows: -------------------- MSI (s) (4C:B4) [14:41:27:205]: Doing action: CompilePyc Action 14:41:27: CompilePyc. Action start 14:41:27: CompilePyc. MSI (s) (4C:B4) [14:45:45:528]: Note: 1: 1722 2: CompilePyc 3: C:\bin \Python26\python.exe 4: -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" MSI (s) (4C:B4) [14:45:45:528]: Note: 1: 2262 2: Error 3: -2147287038 Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action CompilePyc, location: C:\bin \Python26\python.exe, command: -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" MSI (s) (4C:B4) [14:47:41:133]: Note: 1: 2262 2: Error 3: -2147287038 MSI (s) (4C:B4) [14:47:41:133]: Product: Python 2.6.5 -- Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action CompilePyc, location: C:\bin\Python26 \python.exe, command: -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" Action ended 14:47:41: CompilePyc. Return value 3. Action ended 14:47:41: INSTALL. Return value 3. -------------------- I believe the cause of the installation failure message is with the syntax of the following command: C:\bin\Python26\python.exe -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" If you run this command in the Windows XP shell, it yields an error. If you wrap the -x option's args in double quotes, it runs ok (except for a syntax error when compiling one of the python source files - I don't remember which one): C:\bin\Python26\python.exe -Wi "C:\bin\Python26\Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py3_" "C:\bin\Python26\Lib" So it appears that the Windows XP shell is interpreting the "|" characters within the -x option's args as pipe characters and trys to pipe the "multiple commands" together. The simple work around is to not use the Advanced compiling option. Peter From steve at REMOVE-THIS-cybersource.com.au Thu Mar 25 17:11:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Mar 2010 21:11:50 GMT Subject: sum for sequences? References: <2010032423502316807-tomfsessile@gmailcom> <8113nqFsggU3@mid.individual.net> Message-ID: <4babd196$0$8766$c3e8da3@news.astraweb.com> On Thu, 25 Mar 2010 14:02:05 +0100, Alf P. Steinbach wrote: > * Neil Cerutti: >> On 2010-03-25, Steven D'Aprano >> wrote: >>>> You might not want to be so glib. The sum doc sure doesn't sound >>>> like it should work on lists. >>>> >>>> Returns the sum of a sequence of numbers (NOT strings) plus the >>>> value of parameter 'start' (which defaults to 0). >>> What part of that suggested to you that sum might not be polymorphic? >>> Sure, it says numbers (which should be changed, in my opinion), but it >>> doesn't specify what sort of numbers -- ints, floats, or custom types >>> that have an __add__ method. >> >> WTF. > > I think Steven's argument is that it would be pointless for 'sum' to > distinguish between user-defined numerical types and other types that > happen to support '+'. Before Python2.6, which introduced a numeric tower, Python *couldn't* reliably distinguish between numeric types and other types that overloaded +. Since Python discourages type-checking in favour of duck- typing and try...except, this is seen as a good thing. My argument is that sum isn't hard-coded to only work on the built-ins ints or floats, but it supports any object that you can use the + operator on. The *sole* exceptions are str and unicode (not even UserString), and even there it is very simple to overcome the restriction: >>> sum(['a', 'b'], '') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] >>> class S: ... def __add__(self, other): ... return other ... >>> sum(['a', 'b'], S()) 'ab' [...] > However, given that it isn't restricted to numbers, the restriction wrt. > strings is a bit perplexing in the context of modern CPython. But for > Python implementations that don't offer the '+=' optimization it might > help to avoid gross inefficiencies, namely quadratic time string > concatenation. I agree -- the Python philosophy is to allow the user to shoot themselves in the foot if they wish to. You're responsible for the Big Oh behaviour of your code, not the compiler. [...] > However, if that hypothesis about the rationale is correct, then 'sum' > should also be restricted to not handle tuples or lists, so forth, but > at least the CPython implementation does. The reasoning is that naive users are far, far more likely to try summing a large list of strings than to try summing a large list of lists, and therefore in practical terms the consequences of allowing sum on lists is slight enough and rare enough to not be worth the check. I suspect that this is just an after the fact rationalisation, and that the real reason is that those responsible for the hand-holding in sum merely forgot, or didn't know, that repeated addition of lists and tuples is also O(N**2). But I've never cared enough to dig through the archives to find out. -- Steven From winstonw at stratolab.com Thu Mar 25 17:16:12 2010 From: winstonw at stratolab.com (Winston) Date: Thu, 25 Mar 2010 14:16:12 -0700 (PDT) Subject: Revisiting Generators and Subgenerators Message-ID: I have been reading PEP 380 because I am writing a video game/ simulation in Jython and I need cooperative multitasking. PEP 380 hits on my problem, but does not quite solve it for me. I have the following proposal as an alternative to PEP380. I don't know if this is the right way for me to introduce my idea, but below is my writeup. Any thoughts? ------------------------ Proposal for a new Generator Syntax in Python 3K-- A Baton object for generators to allow subfunction to yield, and to make them symetric. Abstract -------- Generators can be used to make coroutines. But they require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value. We propose a modification to generators in Python 3 where a "Baton" object is given to both sides of a generator. Both sides use the baton object to pass execution to the other side, and also to pass values to the other side. The advantages of a baton object over the current scheme are: (1) the generator function can pass the baton to a subfunction, solving the needs of PEP 380, (2) after creation both sides of the generator function are symetric--they both can call yield(), send(), next(). They do the same thing. This means programming with generators is the same as programming with normal functions. No special contortions are needed to pass values back up to a yield command at the top. Motivation ---------- Generators make certain programming tasks easier, such as (a) an iterator which is of infinite length, (b) using a "trampoline function" they can emulate coroutines and cooperative multitasking, (c) they can be used to make both sides of a producer-consumer pattern easy to write-- both sides can appear to be the caller. On the down side, generators as they currently are implemented in Python 3.1 require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value--subfunctions called by the generator function may not yield a value. Here are two use-cases in which generators are commonly used, but where the current limitation causes less readable code: 1) a long generator function which the programmer wants to split into several functions. The subfunctions should be able to yield a result. Currently the subfunctions have to pass values up to the main generator and have it yield the results back. Similarly subfunctions cannot receive values that the caller sends with generator.send() 2) generators are great for cooperative multitasking. A common use- case is agent simulators where many small "tasklets" need to run and then pass execution over to other tasklets. Video games are a common scenario, as is SimPy. Without cooperative multitasking, each tasklet must be contorted to run in a small piece and then return. Generators help this, but a more complicated algorithm which is best decomposed into several functions must be contorted because the subfuctions cannot yield or recive data from the generator.send(). Here is also a nice description of how coroutines make programs easier to read and write: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html Proposal -------- If there is a way to make a sub-function of a generator yield and receive data from generator.send(), then the two problems above are solved. For example, this declares a generator. The first parameter of the generator is the "context" which represents the other side of the execution frame. a Baton object represents a passing of the execution from one line of code to another. A program creates a Baton like so: generator f( baton ): # compute something baton.yield( result ) # compute something baton.yield( result ) baton = f() while True: print( baton.yield() ) A generator function, denoted with they keyword "generator" instead of "def" will return a "baton". Generators have the following methods: __call__( args... ) -- This creates a Baton object which is passed back to the caller, i.e. the code that executed the Baton() command. Once the baton starts working, the two sides are symetric. So we will call the first frame, frame A and the code inside 'function' frame B. Frame is is returned a baton object. As soon as frame A calls baton.yield(), frame B begins, i.e. 'function' starts to run. function is passed the baton as its first argument, and any additional arguments are also passed in. When frame B yields, any value that it yields will be returned to frame A as the result of it's yield(). Batons have the following methods: yield( arg=None ) -- This method will save the current execution state, restore the other execution state, and start running the other function from where it last left off, or from the beginning if this is the first time. If the optional 'arg' is given, then the other side will be "returned" this value from it's last yield(). Note that like generators, the first call to yield may not pass an argument. next() -- This method is the same as yield(None). next() allows the baton to be an iterator. __iter__() -- A baton is an iterator so this just returns the baton back. But it is needed to allow use of batons in "for" statements. start() -- This starts the frame B function running. It may only be called on a new baton. It starts the baton running in frame B, and returns the Baton object to the caller in frame A. Any value from the first yield is lost. baton = Baton( f ).start() It is equivalent to: baton = Baton( f ) # Create the baton baton.yield() # Begin executing in frame B Examples -------- Simple Generator: generator doubler( baton, sequence ): for a in sequence: print( a ) baton.yield( a+a ) baton = doubler( [3,8,2] ) for j in baton: # For statement calls baton.__iter__, and then baton.next() print j Complicated Generator broken into parts: generator Complicated( baton, sequence ): '''A generator function, but there are no yield statements in this function--they are in subfunctions.''' a = sequence.next() if is_special(a): parse_special( baton, a, sequence) else: parse_regular( baton, a, sequence ) def parse_special( baton, first, rest ): # process first baton.yield() b = rest.next() parse_special( baton, b, rest ) def parse_regular( baton, first, rest ): # more stuff baton.yield() baton = Complicated( iter('some data here') ) baton.yield() Cooperative Multitasker: class Creature( object ): def __init__(self, world): self.world = world generator start( self, baton ): '''Designated entry point for tasklets''' # Baton saved for later. Used in other methods like escape() self.baton = baton self.run() def run(self): pass # override me in your subclass def escape(self): # set direction and velocity away from baton creatures self.baton.yield() def chase(self): while True: # set direction and velocity TOWARDS nearest creature self.baton.yield() # if near enough, try to pounce self.baton.yield() class Vegetarian( Tasklet ): def run(self): if self.world.is_creature_visible(): self.escape() else: # do nothing self.baton.yield() class Carnivore( Tasklet ): def run(self): if self.world.is_creature_visible(): self.chase() else: # do nothing self.baton.yield() w = SimulationWorld() v = Vegetarian( w ).start() c = Carnivore( w ).start() while True: v.yield() c.yield() Benefits -------- This new syntax for a generator provides all the benefits of the old generator, including use like a coroutine. Additionally, it makes both sides of the generator almost symetric, i.e. they both "yield" or "send" to the other. And since the baton objects are passed around, subfunctions can yield back to the other execution frame. This fixes problems such as PEP 380. My ideas for syntax above are not fixed, the important concept here is that the two sides of the generator functions will have a "baton" to represent the other side. The baton can be passed to sub- functions, and values can be sent, via the baton, to the other side. This new syntax for a generator will break all existing programs. But we happen to be at the start of Python 3K where new paradaigms are being examined. Alternative Syntax ------------------ With old style generators, g.next() and g.send( 1 ) are conceptually the same as "yield" and "yield 1" inside the generator. They both pass execution to the other side, and the second form passes a value. Yet they currently have different syntax. Once we have a baton object, we can get rid of one of these forms. g.next() is needed to support iterators. How about we keep baton.next() and baton.send( 1 ). We get rid of yield completely. Perhaps instead of a "generator" keyword to denote the generator function, a "fork" keyword should be used to begin the second execution frame. For example: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = fork f() while True: print( baton.next() ) or maybe the "yield" keyword can be used here: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = yield f while True: print( baton.next() ) From winstonw at stratolab.com Thu Mar 25 17:39:51 2010 From: winstonw at stratolab.com (Winston) Date: Thu, 25 Mar 2010 14:39:51 -0700 (PDT) Subject: Revisiting Generators and Subgenerators Message-ID: Here's my proposal again, but hopefully with better formatting so you can read it easier. -Winston ----------------- Proposal for a new Generator Syntax in Python 3K-- A Baton object for generators to allow subfunction to yield, and to make them symetric. Abstract -------- Generators can be used to make coroutines. But they require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value. We propose a modification to generators in Python 3 where a "Baton" object is given to both sides of a generator. Both sides use the baton object to pass execution to the other side, and also to pass values to the other side. The advantages of a baton object over the current scheme are: (1) the generator function can pass the baton to a subfunction, solving the needs of PEP 380, (2) after creation both sides of the generator function are symetric--they both can call yield(), send(), next(). They do the same thing. This means programming with generators is the same as programming with normal functions. No special contortions are needed to pass values back up to a yield command at the top. Motivation ---------- Generators make certain programming tasks easier, such as (a) an iterator which is of infinite length, (b) using a "trampoline function" they can emulate coroutines and cooperative multitasking, (c) they can be used to make both sides of a producer-consumer pattern easy to write--both sides can appear to be the caller. On the down side, generators as they currently are implemented in Python 3.1 require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value--subfunctions called by the generator function may not yield a value. Here are two use-cases in which generators are commonly used, but where the current limitation causes less readable code: 1) a long generator function which the programmer wants to split into several functions. The subfunctions should be able to yield a result. Currently the subfunctions have to pass values up to the main generator and have it yield the results back. Similarly subfunctions cannot receive values that the caller sends with generator.send() 2) generators are great for cooperative multitasking. A common use-case is agent simulators where many small "tasklets" need to run and then pass execution over to other tasklets. Video games are a common scenario, as is SimPy. Without cooperative multitasking, each tasklet must be contorted to run in a small piece and then return. Generators help this, but a more complicated algorithm which is best decomposed into several functions must be contorted because the subfuctions cannot yield or recive data from the generator.send(). Here is also a nice description of how coroutines make programs easier to read and write: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html Proposal -------- If there is a way to make a sub-function of a generator yield and receive data from generator.send(), then the two problems above are solved. For example, this declares a generator. The first parameter of the generator is the "context" which represents the other side of the execution frame. a Baton object represents a passing of the execution from one line of code to another. A program creates a Baton like so: generator f( baton ): # compute something baton.yield( result ) # compute something baton.yield( result ) baton = f() while True: print( baton.yield() ) A generator function, denoted with they keyword "generator" instead of "def" will return a "baton". Generators have the following methods: __call__( args... ) -- This creates a Baton object which is passed back to the caller, i.e. the code that executed the Baton() command. Once the baton starts working, the two sides are symetric. So we will call the first frame, frame A and the code inside 'function' frame B. Frame is is returned a baton object. As soon as frame A calls baton.yield(), frame B begins, i.e. 'function' starts to run. function is passed the baton as its first argument, and any additional arguments are also passed in. When frame B yields, any value that it yields will be returned to frame A as the result of it's yield(). Batons have the following methods: yield( arg=None ) -- This method will save the current execution state, restore the other execution state, and start running the other function from where it last left off, or from the beginning if this is the first time. If the optional 'arg' is given, then the other side will be "returned" this value from it's last yield(). Note that like generators, the first call to yield may not pass an argument. next() -- This method is the same as yield(None). next() allows the baton to be an iterator. __iter__() -- A baton is an iterator so this just returns the baton back. But it is needed to allow use of batons in "for" statements. start() -- This starts the frame B function running. It may only be called on a new baton. It starts the baton running in frame B, and returns the Baton object to the caller in frame A. Any value from the first yield is lost. baton = Baton( f ).start() It is equivalent to: baton = Baton( f ) # Create the baton baton.yield() # Begin executing in frame B Examples -------- Simple Generator: generator doubler( baton, sequence ): for a in sequence: print( a ) baton.yield( a+a ) baton = doubler( [3,8,2] ) # For statement calls baton.__iter__, and then baton.next() for j in baton: print j Complicated Generator broken into parts: generator Complicated( baton, sequence ): '''A generator function, but there are no yield statements in this function--they are in subfunctions.''' a = sequence.next() if is_special(a): parse_special( baton, a, sequence) else: parse_regular( baton, a, sequence ) def parse_special( baton, first, rest ): # process first baton.yield() b = rest.next() parse_special( baton, b, rest ) def parse_regular( baton, first, rest ): # more stuff baton.yield() baton = Complicated( iter('some data here') ) baton.yield() Cooperative Multitasker: class Creature( object ): def __init__(self, world): self.world = world generator start( self, baton ): '''Designated entry point for tasklets''' # Baton saved for later. Used in other # methods like escape() self.baton = baton self.run() def run(self): pass # override me in your subclass def escape(self): # set direction and velocity away # from baton creatures self.baton.yield() def chase(self): while True: # set direction and velocity TOWARDS # nearest creature self.baton.yield() # if near enough, try to pounce self.baton.yield() class Vegetarian( Tasklet ): def run(self): if self.world.is_creature_visible(): self.escape() else: # do nothing self.baton.yield() class Carnivore( Tasklet ): def run(self): if self.world.is_creature_visible(): self.chase() else: # do nothing self.baton.yield() w = SimulationWorld() v = Vegetarian( w ).start() c = Carnivore( w ).start() while True: v.yield() c.yield() Benefits -------- This new syntax for a generator provides all the benefits of the old generator, including use like a coroutine. Additionally, it makes both sides of the generator almost symetric, i.e. they both "yield" or "send" to the other. And since the baton objects are passed around, subfunctions can yield back to the other execution frame. This fixes problems such as PEP 380. My ideas for syntax above are not fixed, the important concept here is that the two sides of the generator functions will have a "baton" to represent the other side. The baton can be passed to sub-functions, and values can be sent, via the baton, to the other side. This new syntax for a generator will break all existing programs. But we happen to be at the start of Python 3K where new paradaigms are being examined. Alternative Syntax ------------------ yield, next, and send are redundant ------------------------------------ With old style generators, g.next() and g.send( 1 ) are conceptually the same as "yield" and "yield 1" inside the generator. They both pass execution to the other side, and the second form passes a value. Yet they currently have different syntax. Once we have a baton object, we can get rid of one of these forms. g.next() is needed to support iterators. How about we keep baton.next() and baton.send( 1 ). We get rid of yield completely. Use keyword to invoke a generator rather than declare ------------------------------------------------------------ Perhaps instead of a "generator" keyword to denote the generator function, a "fork" keyword should be used to begin the second execution frame. For example: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = fork f() while True: print( baton.next() ) or maybe the "yield" keyword can be used here: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = yield f while True: print( baton.next() ) From michel.metzger at gmail.com Thu Mar 25 18:00:35 2010 From: michel.metzger at gmail.com (Michel) Date: Thu, 25 Mar 2010 15:00:35 -0700 (PDT) Subject: Create a class at run-time Message-ID: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Hi everyone, I'm trying to dynamically create a class. What I need is to define a class, add methods to it and later instantiate this class. Methods need to be bound to the instance though, and that's my problem. Here is what I have so far: method_template = "def test_foo(self):\ #actual test_foo\ pass" exec method_template TestClass = types.ClassType("MyTestClass", (unittest.TestCase, ), {}) TestClass.__module__ = "test" now what to do next? I looked at types.MethodType but it needs an instance to bind the method and a function object. Should I define __new__ to bind the method during instantiation? Hope this makes sense, Michel. From john at castleamber.com Thu Mar 25 18:13:49 2010 From: john at castleamber.com (John Bokma) Date: Thu, 25 Mar 2010 16:13:49 -0600 Subject: XPCOM/hulahop: waiting for JavaScript finished? Message-ID: <87sk7ohwwy.fsf@castleamber.com> I am playing a bit with hulahop/xpcom using the code found at http://www.advogato.org/article/1014.html but have no idea how to check if some JavaScript has finised running. The _loaded method of Browser is called after the document has finished loading, but as far as I can tell this doesn't mean that the JavaScript has finised setting things up. Is there a way to either wait a few seconds in _loaded (fragile, of course). time.sleep() (as expected) blocks. Or better, is there a way to check if JavaScript has stopped running? (Hmmm... thinking of it, this can also run on events, so maybe there is no good way to do this?) Thanks, -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From motoom at xs4all.nl Thu Mar 25 18:18:17 2010 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 25 Mar 2010 23:18:17 +0100 Subject: Create a class at run-time In-Reply-To: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <4BABE129.8010205@xs4all.nl> On 2010-03-25 23:00, Michel wrote: > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Maybe this snippet is of any help? import functools class Template(object): pass def printmyname(self): print self.name t=Template() t.name="Pete" t.printmyname=functools.partial(printmyname,t) u=Template() u.name="Mary" u.printmyname=functools.partial(printmyname,u) t.printmyname() u.printmyname() Greetings, -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html From egbertum at xs4all.nl Thu Mar 25 18:28:48 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 25 Mar 2010 23:28:48 +0100 Subject: from import and __init__.py In-Reply-To: References: <20100325101632.GA4727@xs4all.nl> Message-ID: <20100325222848.GB13846@xs4all.nl> On Thu, Mar 25, 2010 at 12:43:13PM -0400, Terry Reedy wrote: > On 3/25/2010 6:16 AM, egbert wrote: > >When I do 'from some_package import some_module' > >the __init__.py of some_package will be run. > >However, there will not be anything like a package-module, > >and the effects of __init__.py seem all to be lost. Is that true ? > > No. If you do > > from sys import modules > print(modules.keys()) > > you will see both some_package and some_package.some_module among > the entries. Yes, you are right. And I can reach everything with modules['some_package'] or variants thereof. Thanks, egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From pmaupin at gmail.com Thu Mar 25 18:34:32 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 25 Mar 2010 15:34:32 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <239b30ba-5465-4466-b2a6-6a5cf62e1028@35g2000yqm.googlegroups.com> On Mar 25, 5:00?pm, Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: Well, you should just fill your empty dict with function definitions, BEFORE you build the class. That's easiest. Also, you can just use type: def foo(*whatever): print foo bar = type('MyDynamicClass', (object,), dict(foo=foo)) HTH, Pat From james.harris.1 at googlemail.com Thu Mar 25 18:40:33 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Thu, 25 Mar 2010 15:40:33 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi Message-ID: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> I am looking to store named pieces of text in a form that can be edited by a standard editor such as notepad (under Windows) or vi (under Unix) and then pulled into Python as needed. The usual record locking and transactions of databases are not required. Another way to look at it is to treat the separate files as entries in a dictionary. The file name would be the key and the lines of the file the value. Anyone know of a database (with a Python interface) which will allow text files to be treated as database fields? If not I can just write it but I thought it best to ask if there was an existing solution first. James From jkn_gg at nicorp.f9.co.uk Thu Mar 25 18:55:20 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Thu, 25 Mar 2010 15:55:20 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> Message-ID: Kirbybase is one possibility. http://pypi.python.org/pypi/KirbyBase/1.9 J^n From joncle at googlemail.com Thu Mar 25 18:56:22 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 25 Mar 2010 15:56:22 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> Message-ID: <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> On 25 Mar, 22:40, James Harris wrote: > I am looking to store named pieces of text in a form that can be > edited by a standard editor such as notepad (under Windows) or vi > (under Unix) and then pulled into Python as needed. The usual record > locking and transactions of databases are not required. > > Another way to look at it is to treat the separate files as entries in > a dictionary. The file name would be the key and the lines of the file > the value. > > Anyone know of a database (with a Python interface) which will allow > text files to be treated as database fields? If not I can just write > it but I thought it best to ask if there was an existing solution > first. > > James I could be missing something here, but aren't you basically just talking about an OS's filesystem? glob or listdir somewhere, then create a dict using the file contents would meet your criteria, with very little lines of code -- but I would be interested to know what the use-case was for this... Is it read completely at start up time, or if each file contains a large amount of lines and aren't fixed width (or has no other indexing support without maintenance), then is a complete sequential-scan required each time, or do you just tell the user to not update when running (unless I s'pose something along the lines of a SIGHUP for config files is applicable). Sorry, just don't understand why you'd want this. Jon. From sccolbert at gmail.com Thu Mar 25 19:07:56 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 25 Mar 2010 19:07:56 -0400 Subject: nested threading In-Reply-To: <4566e767-768f-4399-8a6b-5530ec90b03c@a37g2000prd.googlegroups.com> References: <4566e767-768f-4399-8a6b-5530ec90b03c@a37g2000prd.googlegroups.com> Message-ID: <7f014ea61003251607q7a3086adx90eb04a1a2861bce@mail.gmail.com> Spawning a thread from within a thread works just fine. Calling thread.start() is a non-blocking function and returns immediately. On Thu, Mar 25, 2010 at 11:23 AM, Omer Ihsan wrote: > is there anything as "nested threading"....that is, call a thread from > within a thread. > in this case how will thread locking take place. > > for example initially there were two functions that were called using > threading.Thread. these wont get unlocked unless both of them are done > with whatever they need to do. if say function 2 calls another thread. > then what?? > > inquisitive....:-| > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Thu Mar 25 19:16:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 26 Mar 2010 12:16:39 +1300 Subject: Sniffing encoding type by looking at file BOM header References: Message-ID: In message , python at bdurham.com wrote: > BOM_UTF8 = '\xef\xbb\xbf' Since when does UTF-8 need a BOM? From irmen-NOSPAM- at xs4all.nl Thu Mar 25 19:21:34 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Fri, 26 Mar 2010 00:21:34 +0100 Subject: Sniffing encoding type by looking at file BOM header In-Reply-To: References: Message-ID: <4babef80$0$22918$e4fe514c@news.xs4all.nl> On 26-3-2010 0:16, Lawrence D'Oliveiro wrote: > In message, > python at bdurham.com wrote: > >> BOM_UTF8 = '\xef\xbb\xbf' > > Since when does UTF-8 need a BOM? It doesn't, but it is allowed. Not recommended though. Unfortunately several tools, such as notepad.exe, have a tendency of silently adding it when saving files. -irmen From martin.hellwig at dcuktec.org Thu Mar 25 19:29:09 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Mar 2010 23:29:09 +0000 Subject: Don't understand behavior; instance form a class in another class' instance Message-ID: Hi all, When I run the following snippet (drastically simplified, to just show what I mean): >> import platform, sys class One(object): def __init__(self): self.one = True def change(self): self.one = False class Two(object): def __init__(self): self._instance_one = One() self.one = self._instance_one.one self.change = self._instance_one.change if __name__ == '__main__': print(sys.version) print(platform.machine()) print(80*'#') TEST1 = One() print(TEST1.one) TEST1.change() print(TEST1.one) TEST1 = None print(80*'#') TEST2 = Two() print(TEST2.one) TEST2.change() print(TEST2.one >> I get the following result: << [GCC 4.2.1 20070719 [FreeBSD]] amd64 ################################################################################ True False ################################################################################ True True ################################################################################ << What I don't understand why in the second test, the last boolean is True instead of (what I expect) False. Could somebody enlighten me please as this has bitten me before and I am confused by this behavior. Thanks in advance -- mph From lists at cheimes.de Thu Mar 25 19:41:57 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 26 Mar 2010 00:41:57 +0100 Subject: Don't understand behavior; instance form a class in another class' instance In-Reply-To: References: Message-ID: Martin P. Hellwig schrieb: > What I don't understand why in the second test, the last boolean is True > instead of (what I expect) False. > Could somebody enlighten me please as this has bitten me before and I am > confused by this behavior. Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you alter TEST2.__instance_one.one you don't magically change TEST2.one, too. Python doesn't have variables like C pointers. Python's copy by object (or share by object) behavior can be understand as labels. The label TEST2.one references the same object as TEST2.__instance_one.one until you change where the label TEST2.__instance_one.one points to. Christian From martin.hellwig at dcuktec.org Thu Mar 25 20:06:06 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 26 Mar 2010 00:06:06 +0000 Subject: Don't understand behavior; instance form a class in another class' instance In-Reply-To: References: Message-ID: On 03/25/10 23:41, Christian Heimes wrote: > Martin P. Hellwig schrieb: >> What I don't understand why in the second test, the last boolean is True >> instead of (what I expect) False. >> Could somebody enlighten me please as this has bitten me before and I am >> confused by this behavior. > > Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you > alter TEST2.__instance_one.one you don't magically change TEST2.one, > too. Python doesn't have variables like C pointers. Python's copy by > object (or share by object) behavior can be understand as labels. The > label TEST2.one references the same object as TEST2.__instance_one.one > until you change where the label TEST2.__instance_one.one points to. > > Christian > Ah okay thanks for the explanation, Am I correct in thinking (please correct me if I mangle up the terminology and/or totally are in the wrong ballpark) that this is more or less because the label of the first class is to an object (boolean with value False) and the label of the second class does not cascade to the first label for looking something up but instead during assignment sees that it is a label to an object instead of the object itself thus copies the label content instead? I probably expected classes namespaces to behave in about the same way as lists and dictionaries do, don't know where I picked that up. Thanks again, -- mph From ovidiudeac at gmail.com Thu Mar 25 20:11:39 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 02:11:39 +0200 Subject: python logging writes an empty file Message-ID: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> Hi, I have the following situation: My application uses nosetests to discover&run the unittests. I pass the log configuration file as --logging-config=logging.conf Everything works just fine, the logs are printed as required by the configuration file which makes me happy. I take this as a sign that my logging.conf is correct Then in my main script, which starts the production application, I have this line: logging.config.fileConfig("logging.conf") The logging module is configured without errors BUT my output.log is EMPTY. It's like all the messages are filtered. If I configure logging like this: logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)s: %(message)s', datefmt='%m-%d %H:%M:%S', filename=file, filemode='w') Then the logs are printed ok. Then I tried this: file = logging.FileHandler(logFileBasename, 'w') file.setLevel(logging.INFO) # set a format which is simpler for console use formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s',) # tell the handler to use this format file.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(file) logging.getLogger('') ...which also leaves my output file EMPTY. I'm out of ideas. Can anybody help me with this? Thanks in advance! ovidiu Here is my logging.conf: [formatters] keys: detailed,simple [handlers] keys: console,file [loggers] keys: root [formatter_simple] format: %(name)s:%(levelname)s: %(message)s [formatter_detailed] format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s [handler_console] class: StreamHandler args: [] formatter: detailed [handler_file] class=FileHandler level=DEBUG formatter=detailed args=('output.log', 'w') filename=output.log mode=w [logger_root] level: INFO handlers: file propagate: 1 From cs at zip.com.au Thu Mar 25 20:23:39 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 26 Mar 2010 11:23:39 +1100 Subject: Revisiting Generators and Subgenerators In-Reply-To: References: Message-ID: <20100326002339.GA18453@cskk.homeip.net> On 25Mar2010 14:39, Winston wrote: | Here's my proposal again, but hopefully with better formatting so you | can read it easier. Having quickly read the Abstract and Motivation, why is this any better than a pair of threads and a pair of Queue objects? (Aside from co-routines being more lightweight in terms of machine resources?) On the flipside, given that generators were recently augumented to support coroutines I can see your motivation within that framework. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ C makes it easy for you to shoot yourself in the foot. C++ makes that harder, but when you do, it blows away your whole leg. - Bjarne Stroustrup From andrej.mitrovich at gmail.com Thu Mar 25 20:25:58 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Thu, 25 Mar 2010 17:25:58 -0700 (PDT) Subject: Traversing through Dir() Message-ID: I would like to traverse through the entire structure of dir(), and write it to a file. Now, if I try to write the contents of dir() to a file (via pickle), I only get the top layer. So even if there are lists within the returned list from dir(), they get written as a list of strings to the file. Basically, I have an embedded and somewhat stripped version of Python. I would like to find out just how much functionality it has (I have no documentation for it), so I thought the best way to do that is traverse thru the dir() call. Any clues as to how I could write the whole structure to a file? I guess I'll need some kind of recursion here. :) From winstonw at stratolab.com Thu Mar 25 20:31:24 2010 From: winstonw at stratolab.com (Winston Wolff) Date: Thu, 25 Mar 2010 17:31:24 -0700 Subject: Revisiting Generators and Subgenerators In-Reply-To: <20100326002339.GA18453@cskk.homeip.net> References: <20100326002339.GA18453@cskk.homeip.net> Message-ID: <21283BA1-DFA5-4DD9-9478-89D0622F447C@stratolab.com> Coroutines achieve very similar things to threads, but avoid problems resulting from the pre-emptive nature of threads. Specifically, a coroutine indicates where it will yield to the other coroutine. This avoids lots of problems related to synchronization. Also the lightweight aspect is apparently important for some simulations when they have many thousands of agents to simulate--this number of threads becomes a problem. -Winston Winston Wolff Stratolab - Games for Learning tel: (646) 827-2242 web: www.stratolab.com On Mar 25, 2010, at 5:23 PM, Cameron Simpson wrote: > > Having quickly read the Abstract and Motivation, why is this any better > than a pair of threads and a pair of Queue objects? (Aside from > co-routines being more lightweight in terms of machine resources?) > > On the flipside, given that generators were recently augumented to > support coroutines I can see your motivation within that framework. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > C makes it easy for you to shoot yourself in the foot. C++ makes that > harder, but when you do, it blows away your whole leg. > - Bjarne Stroustrup From jason.heeris at gmail.com Thu Mar 25 20:49:30 2010 From: jason.heeris at gmail.com (Jason) Date: Thu, 25 Mar 2010 17:49:30 -0700 (PDT) Subject: Represent object type as References: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> <4bab888e$0$26553$426a74cc@news.free.fr> Message-ID: On Mar 26, 12:00?am, Bruno Desthuilliers wrote: > ? ? ? ? ? ?attrs['type'] = type(self) > > Do the same thing with less work !-) Ah, silly me :P > ? ? ?attrs['__typename__'] = type(self).__name__ That's exactly what I needed ? I was not aware of the "__name__" attribute. > Warning: won't be very useful if your code still uses old-style classes. No, all the objects are new-style classes so that's fine. > Depends on what you do with this dict, DBUS etc. And of your definition > of "better", of course. Simplest possible :P But this looks like it, so thanks very much :) Cheers, Jason From anand.shashwat at gmail.com Thu Mar 25 20:59:33 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 06:29:33 +0530 Subject: Traversing through Dir() In-Reply-To: References: Message-ID: have you tried os.walk() ? On Fri, Mar 26, 2010 at 5:55 AM, Andrej Mitrovic wrote: > I would like to traverse through the entire structure of dir(), and > write it to a file. > > Now, if I try to write the contents of dir() to a file (via pickle), I > only get the top layer. So even if there are lists within the returned > list from dir(), they get written as a list of strings to the file. > > Basically, I have an embedded and somewhat stripped version of Python. > I would like to find out just how much functionality it has (I have no > documentation for it), so I thought the best way to do that is > traverse thru the dir() call. Any clues as to how I could write the > whole structure to a file? I guess I'll need some kind of recursion > here. :) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nocbos at gmail.com Thu Mar 25 21:03:58 2010 From: nocbos at gmail.com (C. B.) Date: Thu, 25 Mar 2010 18:03:58 -0700 (PDT) Subject: Automatic import ? Message-ID: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Hi everyone, I'm currently coding a C library which provides several modules and objects. Let's say that some of these objects are classes called AAA and BBB. The constructor of AAA needs to get BBB as argument. So I can run the following code : from mymodule import AAA from mymodule import BBB a = AAA(BBB())) But, as there is no case where AAA can be used without BBB, I would like to avoid importing BBB in my Python scripts when I already import AAA. For now, I think that reproducing the behavior of the __init__.py file could be a good way to do this, but how can I code that using only the C API ? Are there any other solutions ? Is this kind of importation a good idea ? Greetings, Cyrille Bagard From rhodri at wildebst.demon.co.uk Thu Mar 25 21:10:36 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 26 Mar 2010 01:10:36 -0000 Subject: Don't understand behavior; instance form a class in another class' instance References: Message-ID: On Fri, 26 Mar 2010 00:06:06 -0000, Martin P. Hellwig wrote: > On 03/25/10 23:41, Christian Heimes wrote: >> Martin P. Hellwig schrieb: >>> What I don't understand why in the second test, the last boolean is >>> True >>> instead of (what I expect) False. >>> Could somebody enlighten me please as this has bitten me before and I >>> am >>> confused by this behavior. >> >> Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you >> alter TEST2.__instance_one.one you don't magically change TEST2.one, >> too. Python doesn't have variables like C pointers. Python's copy by >> object (or share by object) behavior can be understand as labels. The >> label TEST2.one references the same object as TEST2.__instance_one.one >> until you change where the label TEST2.__instance_one.one points to. >> >> Christian >> > > Ah okay thanks for the explanation, Am I correct in thinking (please > correct me if I mangle up the terminology and/or totally are in the > wrong ballpark) that this is more or less because the label of the first > class is to an object (boolean with value False) > and the label of the second class does not cascade to the first label > for looking something up but instead during assignment sees that it is a > label to an object instead of the object itself thus copies the label > content instead? Pretty much. In the sense that you're thinking of, every assignment works that way, even the initial "TEST1 = One()". Assignment binds names to objects, though you have to be aware that names can be such exotic things as "t", "a[15]" or "TEST2.__instance_one.one" > I probably expected classes namespaces to behave in about the same way > as lists and dictionaries do, don't know where I picked that up. They do, in fact, which isn't terribly surprising considering that class namespaces are implemented with dictionaries. The distinction you're missing is that lists and dictionaries are mutable, while booleans aren't; you can change the contents of a dictionary, but you can't change the 'contents' of a boolean. -- Rhodri James *-* Wildebeeste Herder to the Masses From littlesweetmelon at gmail.com Thu Mar 25 21:45:44 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Fri, 26 Mar 2010 09:45:44 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: <4babb132$0$22945$e4fe514c@news.xs4all.nl> References: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> <4babb132$0$22945$e4fe514c@news.xs4all.nl> Message-ID: Many thanks for your kind reply. As you mentioned, a sparse array may be the best choice. Storing offset rather than payload itself can greatly save memory space. 1e7 queries per second is my ideal aim. But 1e6 must be achieved. Currently I have implemented 5e6 on one PC (without incremental indexing and all incoming queries coming from local data stream). Since the table is very big and responding is time critical, the finally system will be definitely distributed computing. I hope that Judy algorithm can simplify indexing, so I can focus on implementing data persistence and distributed computing affairs. -- ShenLei ? 2010?3?26? ??2:55?Irmen de Jong ??? > On 25-3-2010 10:55, ?? wrote: >> Thank you irmen. I will take a look at pytable. >> FYI, let me explain the case clearly. >> >> Originally, my big data table is simply array of Item: >> struct Item >> { >> long id; // used as key >> BYTE payload[LEN]; // corresponding value with fixed length >> }; >> >> All items are stored in one file by using "stdio.h" function: >> fwrite(itemarray, sizeof(Item), num_of_items, fp); >> >> Note that "id" is randomly unique without any order. To speed up >> searching I regrouped / sorted them into two-level hash tables (in >> the form of files). I want to employ certain library to help me index >> this table. >> >> Since the table contains about 10^9 items and LEN is about 2KB, it is >> impossible to hold all data in memory. Furthermore, some new item may >> be inserted into the array. Therefore incremental indexing feature is >> needed. > > I see, I thought the payload data was small as well. What about this idea: > Build a hash table where the keys are the id from your Item structs and > the value is the file seek offset of the Item 'record' in your original > datafile. (although that might generate values of type long, which take > more memory than int, so maybe we should use file_offset/sizeof(Item). > This way you can just keep your original data file (you only have to > scan it to build the hash table) and you will avoid a lengthy conversion > process. > > If this hashtable still doesn't fit in memory use a sparse array > implementation of some sort that is more efficient at storing simple > integers, or just put it into a database solution mentioned in earlier > responses. > > Another thing: I think that your requirement of 1e7 lookups per second > is a bit steep for any solution where the dataset is not in core memory > at once though. > > Irmen. > -- > http://mail.python.org/mailman/listinfo/python-list > From ivlenin at gmail.com Thu Mar 25 21:53:04 2010 From: ivlenin at gmail.com (I V) Date: 26 Mar 2010 02:53:04 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <4bac1380$1@news.x-privat.org> On Thu, 25 Mar 2010 15:00:35 -0700, Michel wrote: > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods need > to be bound to the instance though, and that's my problem. Here is what > I have so far: I'm not entirely sure what you mean by binding methods to the instance. Do you mean you need to dynamically add methods to a specific instance? Or that you need to add methods to a class, such that they can be invoked on specific instances? For the latter, just do: TestClass.test_foo = test_foo For the former, try: tc = TestClass() tc.test_foo = types.MethodType(test_foo, tc) From martin.hellwig at dcuktec.org Thu Mar 25 21:56:38 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 26 Mar 2010 01:56:38 +0000 Subject: Don't understand behavior; instance form a class in another class' instance In-Reply-To: References: Message-ID: On 03/26/10 01:10, Rhodri James wrote: > > Pretty much. In the sense that you're thinking of, every assignment > works that way, even the initial "TEST1 = One()". Assignment binds names > to objects, though you have to be aware that names can be such exotic > things as "t", "a[15]" or "TEST2.__instance_one.one" > >> I probably expected classes namespaces to behave in about the same way >> as lists and dictionaries do, don't know where I picked that up. > > They do, in fact, which isn't terribly surprising considering that class > namespaces are implemented with dictionaries. The distinction you're > missing is that lists and dictionaries are mutable, while booleans > aren't; you can change the contents of a dictionary, but you can't > change the 'contents' of a boolean. > All makes sense now, thanks Rhodri & Christian. -- mph From nagle at animats.com Thu Mar 25 23:28:19 2010 From: nagle at animats.com (John Nagle) Date: Thu, 25 Mar 2010 20:28:19 -0700 Subject: Is there any library for indexing binary data? In-Reply-To: References: Message-ID: <4BAC29D3.6020503@animats.com> ?? wrote: > Well, Database is not proper because 1. the table is very big (~10^9 > rows) 2. we should support very fast *simple* query that is to get > value corresponding to single key (~10^7 queries / second). Ah, crypto rainbow tables. John Nagle From pmaupin at gmail.com Thu Mar 25 23:30:32 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 25 Mar 2010 20:30:32 -0700 (PDT) Subject: Revisiting Generators and Subgenerators References: <20100326002339.GA18453@cskk.homeip.net> Message-ID: <04e65930-889e-4eea-b12c-6bd21a11630a@z3g2000yqz.googlegroups.com> On Mar 25, 7:31?pm, Winston Wolff wrote: (a bunch of stuff about coroutines) There have been proposals in the past for more full-featured generators, that would work as general purpose coroutines. Among other things, there were issues with exception propagation, and the design was deliberately simplified to what we have today. Before proposing anything in this area you should carefully read PEPs 288, 325, and 342, and all the discussion about those PEPs in the python- dev archives. After reading all that, and still being convinced that you have the greatest thing since sliced bread (and that you REALLY understand all the concerns about exceptions and other things), you need to update your document to address all the concerns raised in the discussions on those PEPs, put on your asbestos suit (modern asbestos-free replacements never work as advertised), and then re-post your document. Personally, I am very interested in co-routines, but I have very little time right now, and am not at all interested in reading a proposal from somebody who doesn't know the full history of how generators got to be the way they are (the lack of coroutines is not an accidental oversight). I suspect I am not alone in this opinion, so there is probably some interest in a realistic proposal, but perhaps also some skepticism about whether a realistic proposal can actually be engineered... Best regards and good luck! Pat From steve at REMOVE-THIS-cybersource.com.au Fri Mar 26 00:20:45 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Mar 2010 04:20:45 GMT Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4bac361d$0$8840$c3e8da3@news.astraweb.com> On Thu, 25 Mar 2010 18:03:58 -0700, C. B. wrote: > Hi everyone, > > I'm currently coding a C library which provides several modules and > objects. > > Let's say that some of these objects are classes called AAA and BBB. The > constructor of AAA needs to get BBB as argument. > > So I can run the following code : > > from mymodule import AAA > from mymodule import BBB > > a = AAA(BBB())) > > But, as there is no case where AAA can be used without BBB, I would like > to avoid importing BBB in my Python scripts when I already import AAA. Since AAA must take an argument of BBB, then give it a default: # in mymodule def AAA(arg=BBB()): ... # in another module from mymodule import AAA a = AAA() Or do this: from mymodule import AAA, BBB a = AAA(BBB()) > For now, I think that reproducing the behavior of the __init__.py file > could be a good way to do this, but how can I code that using only the C > API ? What is the behaviour of the __init__.py file? -- Steven From stefan_ml at behnel.de Fri Mar 26 00:51:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Mar 2010 05:51:22 +0100 Subject: Revisiting Generators and Subgenerators In-Reply-To: <04e65930-889e-4eea-b12c-6bd21a11630a@z3g2000yqz.googlegroups.com> References: <20100326002339.GA18453@cskk.homeip.net> <04e65930-889e-4eea-b12c-6bd21a11630a@z3g2000yqz.googlegroups.com> Message-ID: Patrick Maupin, 26.03.2010 04:30: > ... and then re-post your document. ... preferably to the python-ideas mailing list. Although it seems to me that this is something that could be explored as a library first - which usually means that people will tell you exactly that on python-ideas and ask you to come back with an implementation that has proven to be useful in practice. Stefan From v.harishankar at gmail.com Fri Mar 26 02:37:24 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 12:07:24 +0530 Subject: Question regarding curses and text-input methods Message-ID: <20100326120724.33e8c2a6@gmail.com> I am trying to use Python curses.textpad to get (preferably UTF-8 but not needed) input from the user in a python curses application, but I realize that it is extremely limited and doesn't allow me to specify an existing text to edit. Also it doesn't seem to provide scrolling abilities on the window. Is this at all possible to get a large chunk of text using curses module like a GUI textbox or should I look at alternatives like newt? I prefer curses because it's simple and very flexible, but I am lost for ideas on this. Any ideas which doesn't involve throwing away the whole curses interface would be appreciated. -- V.Harishankar http://literaryforums.org http://harishankar.org From kushal.kumaran+python at gmail.com Fri Mar 26 03:40:26 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 26 Mar 2010 13:10:26 +0530 Subject: Improved timedelta attributes/methods In-Reply-To: References: Message-ID: <1e364c4e1003260040k1fe336d0lcf33577986f64075@mail.gmail.com> 2010/3/26 Christian ?tef?nescu : > Hello dear Python-wielding developers! > > I generally like date/time handling in Python very much, especially how date > operations result in Timedelta objects. But I find it somewhat impractical, > that you can only get days, seconds and microseconds out of a time delta. I > think it would be much more comfortable to have fields for minutes, hours, > maybe also years, months. Is there a specific reasoning why this is not > available? > > I would gladly do my best to implement such a solution, if it would make > sense to the devs. > You might want to check out mxDateTime[1]. It has a RelativeDateTime that seems to do what you like. [1] http://www.egenix.com/products/python/mxBase/mxDateTime/doc/ -- regards, kushal From nocbos at gmail.com Fri Mar 26 04:15:44 2010 From: nocbos at gmail.com (C. B.) Date: Fri, 26 Mar 2010 01:15:44 -0700 (PDT) Subject: Automatic import ? References: 4bac361d$0$8840$c3e8da3@news.astraweb.com Message-ID: > > What is the behaviour of the __init__.py file? > Not yet used, but I read this file is run by Python when a module of a package is imported. So you can insert default importations in it. From alfps at start.no Fri Mar 26 04:18:17 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Mar 2010 09:18:17 +0100 Subject: Traversing through Dir() In-Reply-To: References: Message-ID: * Andrej Mitrovic: > I would like to traverse through the entire structure of dir(), and > write it to a file. > > Now, if I try to write the contents of dir() to a file (via pickle), I > only get the top layer. So even if there are lists within the returned > list from dir(), they get written as a list of strings to the file. > > Basically, I have an embedded and somewhat stripped version of Python. > I would like to find out just how much functionality it has (I have no > documentation for it), so I thought the best way to do that is > traverse thru the dir() call. Any clues as to how I could write the > whole structure to a file? I guess I'll need some kind of recursion > here. :) The built-in dir() function just produces a sequence of strings. You can inspect the attributes via the getattr() function. The getattr() function produces a reference to an object (as does every expression). Problem: if you start with the number 42 and apply dir(), do getattr() on the first string, apply dir() on that object, and so on, with CPython you then get into an infinite recursion because those objects are produced on demand... obj = 42 obj_name = "42" for n in range( 12 ): where = id( obj ) t = type( obj ).__name__ print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) attribute_names = dir( obj ) obj_name = attribute_names[0] obj = getattr( obj, obj_name ) Similarly, if you do this with the Turtle module as starting point, with CPython you get into a different kind of infinite recursion because the chain of attributes so obtained is circular. import turtle obj = turtle obj_name = 'turtle' for n in range( 12 ): where = id( obj ) t = type( obj ).__name__ print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) attribute_names = dir( obj ) obj_name = attribute_names[0] obj = getattr( obj, obj_name ) It's not a clean, strict hierarchy of objects. However, the basic idea is sound when you only want to obtain some limited, known information, such as e.g. short descriptions of all string methods, or a listing of the standard exception hierarchy. for attribute_name in dir( str ): if attribute_name.startswith( "_" ): pass else: attribute = getattr( str, attribute_name ) doc_string = attribute.__doc__ doc_lines = doc_string.splitlines() if len( doc_lines ) > 2: essential_doc = doc_lines[2] else: essential_doc = doc_lines[0] print( attribute_name.ljust( 15 ) + essential_doc ) "Lists the standard exception class hierarchy with short descriptions." import builtins import inspect indentation = "." + 2*" " def is_type( o ): # Could use inspect.isclass for this, but in the DIY spirit: return isinstance( o, type ) def beginning_of( s, max_chars ): return s[:max_chars] # Not yet discussed, but doesn't matter. def print_hierarchy( h, level ): for o in h: if isinstance( o, tuple ): # o is a tuple describing a class cls = o[0] doc_lines = cls.__doc__.splitlines() short_doc = beginning_of( doc_lines[0], 55 ) print( "{:<34} {}".format( level*indentation + cls.__name__, short_doc ) ) else: # o is a list array of subclasses print_hierarchy( o, level + 1 ) classes = [] for name in dir( builtins ): o = getattr( builtins, name ) if is_type( o ): if issubclass( o, BaseException ): classes.append( o ) hierarchy = inspect.getclasstree( classes ) # 'hierarchy' is a list array of tuples and nested list arrays of the same form. # The top level is an array of two items, the first item a tuple describing the 'object' # class, and the second item a list array representing the BaseException hierarchy. print_hierarchy( hierarchy[1], level = 0 ) Cheers & hth., - Alf From michele.simionato at gmail.com Fri Mar 26 04:22:54 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 26 Mar 2010 01:22:54 -0700 (PDT) Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] References: mailman.1182.1269520510.23598.python-list@python.org <54e41616-df9f-42dd-9c91-9e530650bd99@j21g2000yqh.googlegroups.com> Message-ID: <9dd0d6b0-7249-4a6f-8d03-b0c3a44eace2@l25g2000yqd.googlegroups.com> On Mar 25, 2:24?pm, Michele Simionato wrote: > On Mar 25, 1:28?pm, Ethan Furman wrote: > > > > > Michele, > > > Was wondering if you'd had a chance to re-post your lectures -- just did > > a search for them and came up empty, and I would love to read them! > > > Many thanks in advance! > > Oops, I forgot! I will try to make them available soon. Here they are: http://www.phyast.pitt.edu/~micheles/oxford-lectures.zip From james.harris.1 at googlemail.com Fri Mar 26 05:49:53 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Fri, 26 Mar 2010 02:49:53 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> Message-ID: <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> On 25 Mar, 22:56, Jon Clements wrote: > On 25 Mar, 22:40, James Harris wrote: > > > I am looking to store named pieces of text in a form that can be > > edited by a standard editor such as notepad (under Windows) or vi > > (under Unix) and then pulled into Python as needed. The usual record > > locking and transactions of databases are not required. > > > Another way to look at it is to treat the separate files as entries in > > a dictionary. The file name would be the key and the lines of the file > > the value. > > > Anyone know of a database (with a Python interface) which will allow > > text files to be treated as database fields? If not I can just write > > it but I thought it best to ask if there was an existing solution > > first. ... > I could be missing something here, but aren't you basically just > talking about an OS's filesystem? For storage, yes. The files would be marked-up text stored in the filesystem. The "dbms" (I use the term loosely!) would provide access to them by some full or partial key mechanism yet to be determined. Read-only access would do - at least for now. > glob or listdir somewhere, then create a dict using the file contents > would meet your criteria, with very little lines of code -- but I > would be interested to know what the use-case was for this... Is it > read completely at start up time, or if each file contains a large > amount of lines and aren't fixed width (or has no other indexing > support without maintenance), then is a complete sequential-scan > required each time, or do you just tell the user to not update when > running (unless I s'pose something along the lines of a SIGHUP for > config files is applicable). All good questions. For now, at least, the files can be read-only and I'd want those on disk to be the master copies at all times. If I was writing it myself I'd probably 'cache' some files in memory and stat them before use. If newer I would reread the file. > > Sorry, just don't understand why you'd want this. I tried to avoid boring folks with the details. I'm toying with some ideas for a way to help generate source code (in various languages, not just Python). If it goes ahead the text files would be mainly marked-up code snippets - with or without symbols that need to be replaced. Rather than write one single monolithic app I thought to split it into reusable components. One part being data access could perhaps be an existing database (and I'll take a look at jkn's suggestion). Think of the database as similar to an associative array stored on disk. The only difference is I may want to play fast and loose with the keys in some ways - e.g. check for partial key matches or return a list of part-matched keys. The language name could be part of the key but I'd also need to store variants for specific language versions. I'm not sure yet how it will all pan out. As I say, just throwing around some ideas. James From almar.klein at gmail.com Fri Mar 26 05:52:51 2010 From: almar.klein at gmail.com (Almar Klein) Date: Fri, 26 Mar 2010 10:52:51 +0100 Subject: Python database of plain text editable by notepad or vi In-Reply-To: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> Message-ID: Hi, On 25 March 2010 23:40, James Harris wrote: > I am looking to store named pieces of text in a form that can be > edited by a standard editor such as notepad (under Windows) or vi > (under Unix) and then pulled into Python as needed. The usual record > locking and transactions of databases are not required. > I wrote a file format and parser for Python and Matlab that enables saving structured data in a human readable file. I use it to store all kinds of scientific data, but also for ini-like files for certain applications. Implementations and more information can be obtained here: http://code.google.com/p/ssdf/ It's not a database in the sense that you can query it, but it might be enough for your needs; it can store named pieces of (unicode) text. Cheers, Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Fri Mar 26 05:57:53 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 26 Mar 2010 10:57:53 +0100 Subject: sqlite version on windows Message-ID: <4BAC8521.2@shopzeus.com> Hi All, On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: 3.6.10 On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: 3.5.9 Why is that? I wrote a program that uses SAVEPOINT/ROLLBACK to. It is only available in SQLite 3.6.8 and above. Can I install it on Windows somehow? Thanks, Laszlo From v.harishankar at gmail.com Fri Mar 26 06:04:51 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 15:34:51 +0530 Subject: Python database of plain text editable by notepad or vi In-Reply-To: <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: <20100326153451.1fae9524@gmail.com> On Fri, 26 Mar 2010 02:49:53 -0700 (PDT) James Harris wrote: > On 25 Mar, 22:56, Jon Clements wrote: > > On 25 Mar, 22:40, James Harris > > wrote: > > > > > I am looking to store named pieces of text in a form that can be > > > edited by a standard editor such as notepad (under Windows) or vi > > > (under Unix) and then pulled into Python as needed. The usual > > > record locking and transactions of databases are not required. > > > > > Another way to look at it is to treat the separate files as > > > entries in a dictionary. The file name would be the key and the > > > lines of the file the value. > > > > > Anyone know of a database (with a Python interface) which will > > > allow text files to be treated as database fields? If not I can > > > just write it but I thought it best to ask if there was an > > > existing solution first. > ... > > I could be missing something here, but aren't you basically just > > talking about an OS's filesystem? > > For storage, yes. The files would be marked-up text stored in the > filesystem. The "dbms" (I use the term loosely!) would provide access > to them by some full or partial key mechanism yet to be determined. > Read-only access would do - at least for now. > > > glob or listdir somewhere, then create a dict using the file > > contents would meet your criteria, with very little lines of code > > -- but I would be interested to know what the use-case was for > > this... Is it read completely at start up time, or if each file > > contains a large amount of lines and aren't fixed width (or has no > > other indexing support without maintenance), then is a complete > > sequential-scan required each time, or do you just tell the user to > > not update when running (unless I s'pose something along the lines > > of a SIGHUP for config files is applicable). > > All good questions. For now, at least, the files can be read-only and > I'd want those on disk to be the master copies at all times. If I was > writing it myself I'd probably 'cache' some files in memory and stat > them before use. If newer I would reread the file. > > > > > Sorry, just don't understand why you'd want this. > > I tried to avoid boring folks with the details. I'm toying with some > ideas for a way to help generate source code (in various languages, > not just Python). If it goes ahead the text files would be mainly > marked-up code snippets - with or without symbols that need to be > replaced. > > Rather than write one single monolithic app I thought to split it into > reusable components. One part being data access could perhaps be an > existing database (and I'll take a look at jkn's suggestion). > > Think of the database as similar to an associative array stored on > disk. The only difference is I may want to play fast and loose with > the keys in some ways - e.g. check for partial key matches or return a > list of part-matched keys. The language name could be part of the key > but I'd also need to store variants for specific language versions. > I'm not sure yet how it will all pan out. As I say, just throwing > around some ideas. > > James I am not sure exactly what you need, but would you consider using something like ConfigParser module provided by Python? It appears to be something similar to what you need. -- V.Harishankar http://literaryforums.org http://harishankar.org From james.harris.1 at googlemail.com Fri Mar 26 06:12:57 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Fri, 26 Mar 2010 03:12:57 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: mailman.1210.1269597926.23598.python-list@python.org Message-ID: On 26 Mar, 10:04, Harishankar wrote: ... > > Think of the database as similar to an associative array stored on > > disk. The only difference is I may want to play fast and loose with > > the keys in some ways - e.g. check for partial key matches or return a > > list of part-matched keys. The language name could be part of the key > > but I'd also need to store variants for specific language versions. > > I'm not sure yet how it will all pan out. As I say, just throwing > > around some ideas. ... > I am not sure exactly what you need, but would you consider using > something like ConfigParser module provided by Python? It appears to be > something similar to what you need. Thanks, I'll take a look at it. James From gandalf at shopzeus.com Fri Mar 26 07:11:26 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 26 Mar 2010 12:11:26 +0100 Subject: sqlite version on windows In-Reply-To: <4BAC8521.2@shopzeus.com> References: <4BAC8521.2@shopzeus.com> Message-ID: <4BAC965E.70302@shopzeus.com> 2010.03.26. 10:57 keltez?ssel, Laszlo Nagy ?rta: > > Hi All, > > On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: 3.6.10 > On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: 3.5.9 > > Why is that? I wrote a program that uses SAVEPOINT/ROLLBACK to. It is > only available in SQLite 3.6.8 and above. Can I install it on Windows > somehow? Hmm. Looks like I only needed to download a new sqlite3.dll file and put it into Python26\DLLs Why it is not included in the standard distribution? The default installed version 3.5.9 is quite old. Is there a special reason for that? Or do you think that I can post a patch? Thanks, Laszlo From ovidiudeac at gmail.com Fri Mar 26 07:14:01 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 13:14:01 +0200 Subject: Automatic import ? In-Reply-To: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <804cd4021003260414t5c5b7482vf315a2e596d3916c@mail.gmail.com> > But, as there is no case where AAA can be used without BBB, I would > like to avoid importing BBB in my Python scripts when I already import > AAA. Then why do you need to explicitely pass BBB() to AAA constructor? You could leave AAA constructor with no parameters or with a parameter with a default BBB() value From steve at holdenweb.com Fri Mar 26 07:49:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Mar 2010 07:49:25 -0400 Subject: Revisiting Generators and Subgenerators In-Reply-To: References: Message-ID: Winston wrote: [...] > This new syntax for a generator will break all existing > programs. But we happen to be at the start of Python 3K where > new paradaigms are > being examined. However good your idea may be, I suspect this one sentence will kill it. We are no longer "at the start of Py3k", we are moving towards the third release, and there is already a substantial body of code and literature embodying the current syntax. So you would need to reformulate your proposals to incorporate backward compatibility. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Fri Mar 26 08:35:58 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 13:35:58 +0100 Subject: Automatic import ? In-Reply-To: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4BACAA2E.6010402@sequans.com> C. B. wrote: > Hi everyone, > > I'm currently coding a C library which provides several modules and > objects. > > Let's say that some of these objects are classes called AAA and BBB. > The constructor of AAA needs to get BBB as argument. > > So I can run the following code : > > from mymodule import AAA > from mymodule import BBB > > a = AAA(BBB())) > > But, as there is no case where AAA can be used without BBB, I would > like to avoid importing BBB in my Python scripts when I already import > AAA. > > For now, I think that reproducing the behavior of the __init__.py file > could be a good way to do this, but how can I code that using only the > C API ? > > Are there any other solutions ? Is this kind of importation a good > idea ? > > Greetings, > Cyrille Bagard > Make AAA do the call to BBB: def AAA(*args, **kwargs): param = BBB(*args, **kwargs) # more code from mymodule import AAA AAA(1,2,3) # list of parameters you would have used with BBB. Saying that, is there any strong reason (meaning design issue) why you don't want to import explicitly BBB ? Because if the reason is 'It takes too much time', then it's a bad reason. Cheers, JM From philip at semanchuk.com Fri Mar 26 08:57:47 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 26 Mar 2010 08:57:47 -0400 Subject: sqlite version on windows In-Reply-To: <4BAC8521.2@shopzeus.com> References: <4BAC8521.2@shopzeus.com> Message-ID: On Mar 26, 2010, at 5:57 AM, Laszlo Nagy wrote: > > Hi All, > > On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: > 3.6.10 > On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: > 3.5.9 > > Why is that? I wrote a program that uses SAVEPOINT/ROLLBACK to. It > is only available in SQLite 3.6.8 and above. Can I install it on > Windows somehow? I did a little research on this for Python 2.5. What I found is that The Python distributions for Windows from python.org are conservative with their SQLite version. For instance, Python 2.5.0 and 2.5.4 ship with the exact same SQLite version (3.3.4, from February 2006). Our application dependencies state a minimum Python of 2.5. We have to work with the lowest common denominator (2.5.0), so we can't use any SQLite features that showed up after 3.3.4. The few Linux distros that I checked are much more aggressive about bundling newer versions of SQLite. For instance, Ubuntu 8.04 has Python 2.5.2 with SQLite 3.4.2, while Ubuntu 8.10 has the same version of Python but offers SQLite 3.5.9. You asked "why" and I don't know. I imagine it comes down to philosophical differences or maybe just a lack of time to test when building new WIndows distros for Python.org. bye Philip From luismgz at gmail.com Fri Mar 26 09:14:49 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 26 Mar 2010 06:14:49 -0700 (PDT) Subject: OT: Meaning of "monkey" Message-ID: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... Monkeys everywhere. Sorry for the off topic question, but what does "monkey" mean in a nerdy-geek context?? Luis From v.harishankar at gmail.com Fri Mar 26 09:23:25 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 13:23:25 +0000 (UTC) Subject: Have you embraced Python 3.x yet? Message-ID: Have you people embraced Python 3.x or still with 2.5 or 2.6? I personally want to switch over but not too sure how many people are using 3.x as opposed to 2 so I want to keep my programs compatible for the majority. -- Hari From kushal.kumaran+python at gmail.com Fri Mar 26 09:25:41 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 26 Mar 2010 18:55:41 +0530 Subject: OT: Meaning of "monkey" In-Reply-To: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <1e364c4e1003260625u4e747b23g566b0082cb24b6b6@mail.gmail.com> 2010/3/26 Luis M. Gonz?lez : > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? > These might help you get the gist: http://www.catb.org/~esr/jargon/html/C/code-monkey.html http://www.catb.org/~esr/jargon/html/T/tape-monkey.html -- regards, kushal From mehgcap at gmail.com Fri Mar 26 09:29:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 26 Mar 2010 09:29:05 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: Because of compatibility, and many modules being built for 2.6 only, I am still on 2.6.4 (updating to .5 soon). On 3/26/10, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many people are > using 3.x as opposed to 2 so I want to keep my programs compatible for > the majority. > > -- Hari > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From neilc at norwich.edu Fri Mar 26 09:34:35 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Mar 2010 13:34:35 GMT Subject: Have you embraced Python 3.x yet? References: Message-ID: <813rfbFi0kU1@mid.individual.net> On 2010-03-26, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many > people are using 3.x as opposed to 2 so I want to keep my > programs compatible for the majority. I switched 6 months ago, or so. My library needs are met by what's in CPython, so I couldn't see, at the time, a good reason to sit still. My programs didn't take much effort to convert. They are nearly all data conversion programs. Microsoft rendering the one outside module I did use, an Excel reader, obsolete caused me a lot more trouble than switching from 2.5 to 3.1. Past advice in this forum has been that as long as you don't depend on libraries that don't yet support Python 3, you can probably switch over and not need to look back. -- Neil Cerutti From anand.shashwat at gmail.com Fri Mar 26 09:35:54 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 19:05:54 +0530 Subject: OT: Meaning of "monkey" In-Reply-To: <1e364c4e1003260625u4e747b23g566b0082cb24b6b6@mail.gmail.com> References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <1e364c4e1003260625u4e747b23g566b0082cb24b6b6@mail.gmail.com> Message-ID: evolved monkey = human (can relate codemonkey to it) 2010/3/26 Kushal Kumaran > > 2010/3/26 Luis M. Gonz?lez : > > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > > > Monkeys everywhere. > > Sorry for the off topic question, but what does "monkey" mean in a > > nerdy-geek context?? > > > > These might help you get the gist: > > http://www.catb.org/~esr/jargon/html/C/code-monkey.html > http://www.catb.org/~esr/jargon/html/T/tape-monkey.html > > -- > regards, > kushal > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Fri Mar 26 09:37:13 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 19:07:13 +0530 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: 2.6.x is what most applications rely on. It is still too early for python 3 On Fri, Mar 26, 2010 at 6:59 PM, Alex Hall wrote: > Because of compatibility, and many modules being built for 2.6 only, I > am still on 2.6.4 (updating to .5 soon). > > On 3/26/10, Harishankar wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > > > I personally want to switch over but not too sure how many people are > > using 3.x as opposed to 2 so I want to keep my programs compatible for > > the majority. > > > > -- Hari > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Have a great day, > Alex (msg sent from GMail website) > mehgcap at gmail.com; http://www.facebook.com/mehgcap > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Fri Mar 26 09:37:13 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 19:07:13 +0530 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: 2.6.x is what most applications rely on. It is still too early for python 3 On Fri, Mar 26, 2010 at 6:59 PM, Alex Hall wrote: > Because of compatibility, and many modules being built for 2.6 only, I > am still on 2.6.4 (updating to .5 soon). > > On 3/26/10, Harishankar wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > > > I personally want to switch over but not too sure how many people are > > using 3.x as opposed to 2 so I want to keep my programs compatible for > > the majority. > > > > -- Hari > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Have a great day, > Alex (msg sent from GMail website) > mehgcap at gmail.com; http://www.facebook.com/mehgcap > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Mar 26 09:53:26 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 14:53:26 +0100 Subject: python logging writes an empty file In-Reply-To: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> Message-ID: <4BACBC56.1020105@sequans.com> Ovidiu Deac wrote: > Then I tried this: > file = logging.FileHandler(logFileBasename, 'w') > file.setLevel(logging.INFO) > # set a format which is simpler for console use > formatter = logging.Formatter('%(asctime)s %(name)-12s > %(levelname)-8s %(message)s',) > # tell the handler to use this format > file.setFormatter(formatter) > # add the handler to the root logger > logging.getLogger('').addHandler(file) > logging.getLogger('') > > ...which also leaves my output file EMPTY. > > I'm out of ideas. Can anybody help me with this? > > Thanks in advance! > ovidiu > You set le level of your handler, but did not set the level of the logger itself. Replace file.setLevel(logging.INFO) by logging.getLogger().setLevel(logging.INFO) Log events are matched versus the logger level 1st, then the handler level (if applicable). Most of the time you don't need to tune your handler levels. JM From incensedprey at gmail.com Fri Mar 26 10:05:52 2010 From: incensedprey at gmail.com (Kevin Adams) Date: Fri, 26 Mar 2010 07:05:52 -0700 (PDT) Subject: [python3] References: Message-ID: On Mar 19, 3:02?pm, Terry Reedy wrote: > On 3/19/2010 2:17 PM, Steve Holden wrote: > > > > > Kevin Adams wrote: > >> Greetings! > > >> Please forgive me if im posting this to the wrong group. > > >> I'm new to Python, learning Python3 from the O'rielly "Learning > >> Python" book. ?Reading > >> about operator overloading, specifically __getitem__. ? I put together > >> a small bit of code to > >> do some experimenting and threw in a timer so i can see it do its > >> thing. ?For some reason > >> the time.sleep(x) function doesnt work when my print function includes > >> "end=''". > > >> Thanks in advance for any help. > > > Try the following changes: > > >> ---code--- > > >> class TestClass(): > >> ? ? ?def __init__(self): > >> ? ? ? ? ?self.data = "I was far from home and the spell of the eastern > >> sea was upon me." > > >> ? ? ?def __getitem__(self,i): > >> ? ? ? ? ?return self.data[i] > > >> import time > > > import sys > > >> if __name__ == "__main__": > > >> ? ? ?me = TestClass() > >> ? ? ?for x in me: > >> ? ? ? ? ?print(x,end='') ?#if i remove the 'end=''' ?it performs as i'd > >> expect > > ? ? ? ? ? ?sys.stdout.flush() > > >> ? ? ? ? ?time.sleep(int(2)) > > > It may just be that the output is being held in buffers until the > > program terminates. the fluch() methof pushes it straight out. > > The IDLE Shell window must get print output back from the pythonw > process without buffering. When I cut and pasted from IDLE editor to > standard interpreter window, output was bunched after several seconds. > OP should have started with short string and minimal delay so output > would not take a whole minute. Flushing fixed problem in standard > interpreter. I will have to remember that testing partial line output in > IDLE does not show how it will act elsewhere. > > Kevin: when reporting a problem, be more specific as to what 'does not > work' means. > > Terry Jan Reedy Terry: Will definately try to be more informative next time. Thanks again. K From andrej.mitrovich at gmail.com Fri Mar 26 10:16:47 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Fri, 26 Mar 2010 07:16:47 -0700 (PDT) Subject: Traversing through Dir() References: Message-ID: On Mar 26, 9:18?am, "Alf P. Steinbach" wrote: > * Andrej Mitrovic: > > > I would like to traverse through the entire structure of dir(), and > > write it to a file. > > > Now, if I try to write the contents of dir() to a file (via pickle), I > > only get the top layer. So even if there are lists within the returned > > list from dir(), they get written as a list of strings to the file. > > > Basically, I have an embedded and somewhat stripped version of Python. > > I would like to find out just how much functionality it has (I have no > > documentation for it), so I thought the best way to do that is > > traverse thru the dir() call. Any clues as to how I could write the > > whole structure to a file? I guess I'll need some kind of recursion > > here. :) > > The built-in dir() function just produces a sequence of strings. > > You can inspect the attributes via the getattr() function. The getattr() > function produces a reference to an object (as does every expression). Problem: > if you start with the number 42 and apply dir(), do getattr() on the first > string, apply dir() on that object, and so on, with CPython you then get into an > infinite recursion because those objects are produced on demand... > > > obj = 42 > obj_name = "42" > for n in range( 12 ): > ? ? ?where = id( obj ) > ? ? ?t = type( obj ).__name__ > ? ? ?print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) > ? ? ?attribute_names = dir( obj ) > ? ? ?obj_name = attribute_names[0] > ? ? ?obj = getattr( obj, obj_name ) > > > Similarly, if you do this with the Turtle module as starting point, with CPython > you get into a different kind of infinite recursion because the chain of > attributes so obtained is circular. > > > import turtle > > obj = turtle > obj_name = 'turtle' > for n in range( 12 ): > ? ? ?where = id( obj ) > ? ? ?t = type( obj ).__name__ > ? ? ?print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) > ? ? ?attribute_names = dir( obj ) > ? ? ?obj_name = attribute_names[0] > ? ? ?obj = getattr( obj, obj_name ) > > > It's not a clean, strict hierarchy of objects. > > However, the basic idea is sound when you only want to obtain some limited, > known information, such as e.g. short descriptions of all string methods, or a > listing of the standard exception hierarchy. > > > for attribute_name in dir( str ): > ? ? ?if attribute_name.startswith( "_" ): > ? ? ? ? ?pass > ? ? ?else: > ? ? ? ? ?attribute = getattr( str, attribute_name ) > ? ? ? ? ?doc_string = attribute.__doc__ > ? ? ? ? ?doc_lines = doc_string.splitlines() > ? ? ? ? ?if len( doc_lines ) > 2: > ? ? ? ? ? ? ?essential_doc = doc_lines[2] > ? ? ? ? ?else: > ? ? ? ? ? ? ?essential_doc = doc_lines[0] > ? ? ? ? ?print( attribute_name.ljust( 15 ) + essential_doc ) > > > > "Lists the standard exception class hierarchy with short descriptions." > import builtins > import inspect > > indentation ? ? = "." + 2*" " > > def is_type( o ): > ? ? ?# Could use inspect.isclass for this, but in the DIY spirit: > ? ? ?return isinstance( o, type ) > > def beginning_of( s, max_chars ): > ? ? ?return s[:max_chars] ? ?# Not yet discussed, but doesn't matter. > > def print_hierarchy( h, level ): > ? ? ?for o in h: > ? ? ? ? ?if isinstance( o, tuple ): > ? ? ? ? ? ? ?# o is a tuple describing a class > ? ? ? ? ? ? ?cls = o[0] > ? ? ? ? ? ? ?doc_lines = cls.__doc__.splitlines() > ? ? ? ? ? ? ?short_doc = beginning_of( doc_lines[0], 55 ) > ? ? ? ? ? ? ?print( "{:<34} {}".format( > ? ? ? ? ? ? ? ? ?level*indentation + cls.__name__, short_doc > ? ? ? ? ? ? ? ? ?) ) > ? ? ? ? ?else: > ? ? ? ? ? ? ?# o is a list array of subclasses > ? ? ? ? ? ? ?print_hierarchy( o, level + 1 ) > > classes = [] > for name in dir( builtins ): > ? ? ?o = getattr( builtins, name ) > ? ? ?if is_type( o ): > ? ? ? ? ?if issubclass( o, BaseException ): > ? ? ? ? ? ? ?classes.append( o ) > > hierarchy = inspect.getclasstree( classes ) > # 'hierarchy' is a list array of tuples and nested list arrays of the same form. > # The top level is an array of two items, the first item a tuple describing the > 'object' > # class, and the second item a list array representing the BaseException hierarchy. > print_hierarchy( hierarchy[1], level = 0 ) > > > Cheers & hth., > > - Alf Thanks for all of that. And yes, I've noticed I get into infinite recursions all the time, which is why I was asking if there was a simple way to do this. I'll have a look at these later. Kind regards, Andrej Mitrovic From andrej.mitrovich at gmail.com Fri Mar 26 10:22:40 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Fri, 26 Mar 2010 07:22:40 -0700 (PDT) Subject: Have you embraced Python 3.x yet? References: Message-ID: I use both, really. I started by learning and using Python 3, but I ended up using Python 2 much more often compared to Py3. Not because of the functionality of the language, but because most software that embeds Python or is extendable in some way is usually using Python 2. + There's the whole libraries issue (or the lack of them). But I have to say, Python 3 is a sexy language, I can't wait for more libraries to appear so I could focus more of my attention there. From kw at codebykevin.com Fri Mar 26 10:28:12 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 26 Mar 2010 10:28:12 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: <5dda4$4bacc47c$4275d90a$1703@FUSE.NET> On 3/26/10 9:23 AM, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many people are > using 3.x as opposed to 2 so I want to keep my programs compatible for > the majority. > > -- Hari Not yet. Some key libraries I am using for apps under development haven't been ported to support 3.x yet (feedparser, pycrypto). -- Kevin Walzer Code by Kevin http://www.codebykevin.com From ovidiudeac at gmail.com Fri Mar 26 10:29:43 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 16:29:43 +0200 Subject: python logging writes an empty file In-Reply-To: <4BACBC56.1020105@sequans.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> Message-ID: <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> > You set le level of your handler, but did not set the level of the logger > itself. > Replace file.setLevel(logging.INFO) by > logging.getLogger().setLevel(logging.INFO) > > Log events are matched versus the logger level 1st, then the handler level > (if applicable). Most of the time you don't need to tune your handler > levels. Right. Thanks a lot!!! Now for the second part, any idea why logging.config.fileConfig doesn't work? Now the logging.conf looks like this: [formatters] keys: detailed [handlers] keys: console,file [loggers] keys: root [formatter_detailed] format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s [handler_console] class: StreamHandler args: [] formatter: detailed [handler_file] class=FileHandler formatter=detailed args=('output.log', 'w') filename=output.log mode=w [logger_root] level: INFO handlers: file From seb.binet at gmail.com Fri Mar 26 10:29:57 2010 From: seb.binet at gmail.com (Sebastien Binet) Date: Fri, 26 Mar 2010 07:29:57 -0700 (PDT) Subject: Revisiting Generators and Subgenerators References: Message-ID: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> On Mar 25, 10:39?pm, Winston wrote: > Here's my proposal again, but hopefully with better formatting so you > can read it easier. > > -Winston > ----------------- > > Proposal for a new Generator Syntax in Python 3K-- > A Baton object for generators to allow subfunction to yield, and to > make > them symetric. isn't a Baton what CSP calls a channel ? there is this interesting PyCSP library (which implements channels over greenlets, os-processes (via multiprocessing) or python threads) http://code.google.com/p/pycsp cheers, sebastien. From gnarlodious at gmail.com Fri Mar 26 10:30:47 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Fri, 26 Mar 2010 07:30:47 -0700 (PDT) Subject: Have you embraced Python 3.x yet? References: Message-ID: I have been using Py3 since October, I switched over for the OrderedDict feature. Some parts are a little hard to get used to, but others are easier. I am doing web programming, so the UTF 8 default is a big improvement. -- Gnarlie From showell30 at yahoo.com Fri Mar 26 10:31:17 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 26 Mar 2010 07:31:17 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> Message-ID: <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> On Mar 24, 4:19?pm, Paul Rubin wrote: > kj writes: > > Is there a sequence-oriented equivalent to the sum built-in? ?E.g.: > > ? seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > use itertools.chain for this. ?A few people have mentioned that sum will > also work, but I think for that purpose it could have O(n**2) > complexity. I agree on the practical matter that itertools.chain and other solutions are usually the way to go for most tasks that involve iterating through several lists. >From a purely academic standpoint, I'm not convinced that sum() is inefficient in terms of big-O complexity, though. showell at showell-laptop:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 >>> class StupidList: ... def __init__(self, lst): ... print 'creating', lst ... self.lst = lst ... def __add__(self, other): ... self.lst += '|' ... self.lst.extend(other.lst) ... return self ... >>> result = sum([StupidList([1, 2]), StupidList([3,4]), StupidList([5,6])], StupidList([0])) creating [1, 2] creating [3, 4] creating [5, 6] creating [0] >>> result.lst [0, '|', 1, 2, '|', 3, 4, '|', 5, 6] If I'm interpreting the above program correctly, then sum() is doing the most efficient thing under the hood--it appears to do the equivalent of += without creating unnecessary objects for intermediate sums. I think the special-case error message might be a case where practicality simply beats out purity. It would be nice if sum() were completely duck-typed-let-you-shoot-yourself-in-foot-if-you-know-what- you-are-doing, but maybe this was such a pitfall at one time, that extra safeguards were put into sum(). I wonder how severely sum(), without the restriction, would underperform join() on modern versions of Python, though. >>> sum('1', '2') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] Note that you can easily fake out sum() to get duck typing. >>> class EmptyStringStarter: ... def __add__(self, other): return other ... >>> empty = EmptyStringStarter() >>> sum(['hello ', 'world'], empty) 'hello world' From no.email at please.post Fri Mar 26 10:49:02 2010 From: no.email at please.post (kj) Date: Fri, 26 Mar 2010 14:49:02 +0000 (UTC) Subject: Classes as namespaces? Message-ID: What's the word on using "classes as namespaces"? E.g. class _cfg(object): spam = 1 jambon = 3 huevos = 2 breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Granted, this is not the "intended use" for classes, and therefore could be viewed as a misuse ("that's what dictionaries are for", etc.). But other than this somewhat academic objection[*], I really can see no problem with using classes in this way. And yet, I've come across online murky warnings against using classes as "pseudo-namespaces". Is there some problem that I'm not seeing with this technique? ~K [*] My own subjective dislike for the widespread practice of using triple quotes to comment out code is formally similar to this one ("the 'intended use' for triple-quoting is not to comment out code", etc.). Here I find myself on the opposite side of the purist/pragmatic divide. Hmmm. From showell30 at yahoo.com Fri Mar 26 10:56:48 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 26 Mar 2010 07:56:48 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> Message-ID: On Mar 26, 7:31?am, Steve Howell wrote: > On Mar 24, 4:19?pm, Paul Rubin wrote: > > > kj writes: > > > Is there a sequence-oriented equivalent to the sum built-in? ?E.g.: > > > ? seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > > use itertools.chain for this. ?A few people have mentioned that sum will > > also work, but I think for that purpose it could have O(n**2) > > complexity. > > I agree on the practical matter that itertools.chain and other > solutions are usually the way to go for most tasks that involve > iterating through several lists. > > From a purely academic standpoint, I'm not convinced that sum() is > inefficient in terms of big-O complexity, though. > > ?showell at showell-laptop:~$ python > ?Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > ?[GCC 4.3.3] on linux2 > ?>>> class StupidList: > ?... ? def __init__(self, lst): > ?... ? ? print 'creating', lst > ?... ? ? self.lst = lst > ?... ? def __add__(self, other): > ?... ? ? self.lst += '|' > ?... ? ? self.lst.extend(other.lst) > ?... ? ? return self > ?... > ?>>> result = sum([StupidList([1, 2]), StupidList([3,4]), > StupidList([5,6])], StupidList([0])) > ?creating [1, 2] > ?creating [3, 4] > ?creating [5, 6] > ?creating [0] > ?>>> result.lst > ?[0, '|', 1, 2, '|', 3, 4, '|', 5, 6] > > If I'm interpreting the above program correctly, then sum() is doing > the most efficient thing under the hood--it appears to do the > equivalent of += without creating unnecessary objects for intermediate > sums. > > I think the special-case error message might be a case where > practicality simply beats out purity. ?It would be nice if sum() were > completely duck-typed-let-you-shoot-yourself-in-foot-if-you-know-what- > you-are-doing, but maybe this was such a pitfall at one time, that > extra safeguards were put into sum(). ?I wonder how severely sum(), > without the restriction, would underperform join() on modern versions > of Python, though. > > ?>>> sum('1', '2') > ?Traceback (most recent call last): > ? ?File "", line 1, in > ?TypeError: sum() can't sum strings [use ''.join(seq) instead] > > Note that you can easily fake out sum() to get duck typing. > > ?>>> class EmptyStringStarter: > ?... ? def __add__(self, other): return other > ?... > ?>>> empty = EmptyStringStarter() > ?>>> sum(['hello ', 'world'], empty) > ?'hello world' Looking at the code answers my own questions: http://svn.python.org/view/python/trunk/Python/bltinmodule.c?view=markup Look for builtin_sum(). First you see the guard against strings: /* reject string values for 'start' parameter */ if (PyObject_TypeCheck(result, &PyBaseString_Type)) { PyErr_SetString(PyExc_TypeError, "sum() can't sum strings [use ''.join(seq) instead]"); Py_DECREF(iter); return NULL; } Py_INCREF(result); Also, Paul's suspicion that sum() works in O(N squared) for lists is confirmed by this comment: /* It's tempting to use PyNumber_InPlaceAdd instead of PyNumber_Add here, to avoid quadratic running time when doing 'sum(list_of_lists, [])'. However, this would produce a change in behaviour: a snippet like empty = [] sum([[x] for x in range(10)], empty) would change the value of empty. */ It's interesting, though, that you can construct classes pretty easily, as I did above, that avoid the quadratic behavior, as long as you do not mind mutating the start value, which I think is usually fine, since the original start value usually is not useful afterward anyway. From robert.kern at gmail.com Fri Mar 26 10:56:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Mar 2010 09:56:52 -0500 Subject: OT: Meaning of "monkey" In-Reply-To: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 2010-03-26 08:14 AM, Luis M. Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? Partly because "monkey" is just a funny word. As for monkey-patching, it came from the Zope community: http://en.wikipedia.org/wiki/Monkey_patching -- 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 From joncle at googlemail.com Fri Mar 26 10:58:52 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Mar 2010 07:58:52 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: On 26 Mar, 09:49, James Harris wrote: > On 25 Mar, 22:56, Jon Clements wrote: > > > > > On 25 Mar, 22:40, James Harris wrote: > > > > I am looking to store named pieces of text in a form that can be > > > edited by a standard editor such as notepad (under Windows) or vi > > > (under Unix) and then pulled into Python as needed. The usual record > > > locking and transactions of databases are not required. > > > > Another way to look at it is to treat the separate files as entries in > > > a dictionary. The file name would be the key and the lines of the file > > > the value. > > > > Anyone know of a database (with a Python interface) which will allow > > > text files to be treated as database fields? If not I can just write > > > it but I thought it best to ask if there was an existing solution > > > first. > ... > > I could be missing something here, but aren't you basically just > > talking about an OS's filesystem? > > For storage, yes. The files would be marked-up text stored in the > filesystem. The "dbms" (I use the term loosely!) would provide access > to them by some full or partial key mechanism yet to be determined. > Read-only access would do - at least for now. > > > glob or listdir somewhere, then create a dict using the file contents > > would meet your criteria, with very little lines of code -- but I > > would be interested to know what the use-case was for this... Is it > > read completely at start up time, or if each file contains a large > > amount of lines and aren't fixed width (or has no other indexing > > support without maintenance), then is a complete sequential-scan > > required each time, or do you just tell the user to not update when > > running (unless I s'pose something along the lines of a SIGHUP for > > config files is applicable). > > All good questions. For now, at least, the files can be read-only and > I'd want those on disk to be the master copies at all times. If I was > writing it myself I'd probably 'cache' some files in memory and stat > them before use. If newer I would reread the file. > It's hard to bore this group :) > > > > Sorry, just don't understand why you'd want this. > > I tried to avoid boring folks with the details. I'm toying with some > ideas for a way to help generate source code (in various languages, > not just Python). If it goes ahead the text files would be mainly > marked-up code snippets - with or without symbols that need to be > replaced. > > Rather than write one single monolithic app I thought to split it into > reusable components. One part being data access could perhaps be an > existing database (and I'll take a look at jkn's suggestion). > > Think of the database as similar to an associative array stored on > disk. The only difference is I may want to play fast and loose with > the keys in some ways - e.g. check for partial key matches or return a > list of part-matched keys. The language name could be part of the key > but I'd also need to store variants for specific language versions. > I'm not sure yet how it will all pan out. As I say, just throwing > around some ideas. > > James Thanks for the explanation. Who admins and, who's editing this data? I couldn't 100% guarantee that I could modify a text file and always put the right delimiter in the right place and remember to escape the relevant chars (and I'm probably not the 'average' user). Any opposition to just putting it in a 'proper' DB, then 'blobbing' the values? (or just integrate a procedure/script/function whatever your chosen RDBMS calls to choose it). Or in some systems, 'externally referencing'... loads of DB's have free front-ends, and there are lots of Python libraries. I think perhaps, all I'm saying is, I'd choose a different approach. I'd provide a front-end, rather than choose to re-write the wheel over DB's. Be nice to know how you get on, if you'd be so kind? Cheers, Jon. From michel.metzger at gmail.com Fri Mar 26 11:00:57 2010 From: michel.metzger at gmail.com (Michel) Date: Fri, 26 Mar 2010 08:00:57 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <3479ec6a-fe04-4088-83e9-e3ef60a8152e@k4g2000prh.googlegroups.com> Well, I don't have the reference to the instance. The class is actually instantiated later by a the unittest library. On Mar 25, 6:18?pm, Michiel Overtoom wrote: > On 2010-03-25 23:00, Michel wrote: > > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods to it and later instantiate this class. Methods > > need to be bound to the instance though, and that's my problem. > > Maybe this snippet is of any help? > > import functools > > class Template(object): > ? ? ?pass > > def printmyname(self): > ? ? ?print self.name > > t=Template() > t.name="Pete" > t.printmyname=functools.partial(printmyname,t) > > u=Template() > u.name="Mary" > u.printmyname=functools.partial(printmyname,u) > > t.printmyname() > u.printmyname() > > Greetings, > > -- > "The ability of the OSS process to collect and harness > the collective IQ of thousands of individuals across > the Internet is simply amazing." - Vinod Valloppillilhttp://www.catb.org/~esr/halloween/halloween4.html From v.harishankar at gmail.com Fri Mar 26 11:04:13 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 15:04:13 +0000 (UTC) Subject: Classes as namespaces? References: Message-ID: On Fri, 26 Mar 2010 14:49:02 +0000, kj wrote: > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore could > be viewed as a misuse ("that's what dictionaries are for", etc.). But > other than this somewhat academic objection[*], I really can see no > problem with using classes in this way. > > And yet, I've come across online murky warnings against using classes as > "pseudo-namespaces". Is there some problem that I'm not seeing with > this technique? > > ~K > > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one ("the > 'intended use' for triple-quoting is not to comment out code", etc.). > Here I find myself on the opposite side of the purist/pragmatic divide. > Hmmm. I myself am a humble beginner in many ways, but generally isn't that (namespacing) achieved by using modules? I don't find the need generally to assign namespace to local variables and when there is a need for it, module level objects do the job. From philip at semanchuk.com Fri Mar 26 11:08:35 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 26 Mar 2010 11:08:35 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <8651EEFD-64CC-4488-B981-F247C4F75BA6@semanchuk.com> On Mar 26, 2010, at 10:49 AM, kj wrote: > > > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". Is there some problem that I'm > not seeing with this technique? I hope it's not problematic; I use it all the time. A few differences about the way I do it: - I respect PEP 8 for the class name (CamelCaps) - If the attributes are supposed to be constants, I capitalize the attributes - I often add NONE with a value of zero so that bool(MyClass.NONE) will evaluate to False and everything else will be True Here's an example from my code: class Apodization(object): """ Apodization constants """ # These constants are arbitrary and may change. # However bool(NONE) is guaranteed to be False NONE = 0 GAUSSIAN = 1 LORENTZIAN = 2 Cheers Philip From jeanmichel at sequans.com Fri Mar 26 11:44:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 16:44:39 +0100 Subject: python logging writes an empty file In-Reply-To: <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> Message-ID: <4BACD667.7020803@sequans.com> Ovidiu Deac wrote: >> You set le level of your handler, but did not set the level of the logger >> itself. >> Replace file.setLevel(logging.INFO) by >> logging.getLogger().setLevel(logging.INFO) >> >> Log events are matched versus the logger level 1st, then the handler level >> (if applicable). Most of the time you don't need to tune your handler >> levels. >> > > Right. Thanks a lot!!! > > Now for the second part, any idea why logging.config.fileConfig doesn't work? > > Now the logging.conf looks like this: > > [formatters] > keys: detailed > > [handlers] > keys: console,file > > [loggers] > keys: root > > [formatter_detailed] > format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s > > [handler_console] > class: StreamHandler > args: [] > formatter: detailed > > [handler_file] > class=FileHandler > formatter=detailed > args=('output.log', 'w') > filename=output.log > mode=w > > [logger_root] > level: INFO > handlers: file > I'm not sure, I don't use configuration file my loggers. I don't think the handler_file should have a filename or mode field though. Try removing them. JM From invalid at invalid.invalid Fri Mar 26 11:45:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 26 Mar 2010 15:45:18 +0000 (UTC) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 2010-03-26, Luis M Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? In colloquial English, "-monkey" is a slang term for a person who does a particular job for a living. For example "grease monkey" is a slang term for an auto mechanic. A "code monkey" is somebody who writes code for a living. It can be slightly derogitory in some situations since it implies that the task is mechanical and repetitive and doesn't require a lot of creative thinking. However, it can be used among peers in an affectionate way. One may refer to one's peer as "code monkey" without offense, but a manager could not refer to one of his employees as a "code monkey" without risking it being seen as an insult. Many people are accustomed to speaking anthopomorphically about computers and programs, so when somebody writes a program that does "foo", the name "foo monkey" seems natural for that program. -- Grant Edwards grant.b.edwards Yow! I don't know WHY I at said that ... I think it gmail.com came from the FILLINGS in my rear molars ... From joncle at googlemail.com Fri Mar 26 11:47:29 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Mar 2010 08:47:29 -0700 (PDT) Subject: Classes as namespaces? References: Message-ID: <809a6515-214f-4460-a847-0e935c7f87b9@t23g2000yqt.googlegroups.com> On 26 Mar, 14:49, kj wrote: > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ? spam = 1 > ? ? jambon = 3 > ? ? huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). ?But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". ?Is there some problem that I'm > not seeing with this technique? > > ~K > > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one > ("the 'intended use' for triple-quoting is not to comment out code", > etc.). ?Here I find myself on the opposite side of the purist/pragmatic > divide. ?Hmmm. Given this example, I would go for the module and CONSTANT_NAMING approach. But yes, even in the docs. you can use a class as a C type-of struct. I stick to the convention of a class knows what it's doing, what it's doing it on, and a module just happens to contain those classes. C++ std::algorithm for instance, makes sense it's called std, ditto algorithm and has shed loads in it, but would I create a class called algorithm (unlikely). I would tend to view modules as "namespace". Rightly or wrongly, just lets you make the right design choice. Jon. From jackdied at gmail.com Fri Mar 26 11:49:14 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 26 Mar 2010 11:49:14 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: On Fri, Mar 26, 2010 at 10:49 AM, kj wrote: > > > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ?spam = 1 > ? ?jambon = 3 > ? ?huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Classes as namespaces are a valid use case (I do it all the time). Python 3 has a small cleanup that makes classes even closer to module namespaces; namely the concept of "unbound methods" goes away. In 3.x when you get a function from a class you get the function itself and not an unbound function. -Jack From jeanmichel at sequans.com Fri Mar 26 11:50:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 16:50:31 +0100 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <4BACD7C7.1060006@sequans.com> kj wrote: > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > You cannot see the problem because there's no problem using classes as namespaces. > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". Is there some problem that I'm > not seeing with this technique? > > ~K > import this [snip] Namespaces are one honking great idea -- let's do more of those! Modules and dictionaries are no more namespaces than classes. So any container is potentially a namespace. JM From michel.metzger at gmail.com Fri Mar 26 11:54:11 2010 From: michel.metzger at gmail.com (Michel) Date: Fri, 26 Mar 2010 08:54:11 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4bac1380$1@news.x-privat.org> Message-ID: I want to add a method to a class such that it can be invoked on specifics instances. You solution works (as well as Patrick's one), thanks ! I still have a question though. If I print the type of the self object I get when my method is called, I get "". I guess this is because the method is defined as a class method. This is ok in my case, but just out of curiosity, what should I do to change this method to an instance method? Thanks for your help, Michel. On Mar 25, 9:53?pm, I V wrote: > On Thu, 25 Mar 2010 15:00:35 -0700, Michel wrote: > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods to it and later instantiate this class. Methods need > > to be bound to the instance though, and that's my problem. Here is what > > I have so far: > > I'm not entirely sure what you mean by binding methods to the instance. > Do you mean you need to dynamically add methods to a specific instance? > Or that you need to add methods to a class, such that they can be invoked > on specific instances? For the latter, just do: > > TestClass.test_foo = test_foo > > For the former, try: > > tc = TestClass() > tc.test_foo = types.MethodType(test_foo, tc) From robert.kern at gmail.com Fri Mar 26 12:06:19 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Mar 2010 11:06:19 -0500 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 2010-03-26 10:45 AM, Grant Edwards wrote: > On 2010-03-26, Luis M Gonz?lez wrote: >> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >> >> Monkeys everywhere. > Many people are accustomed to speaking anthopomorphically about "simiomorphically"? -- 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 From mwilson at the-wire.com Fri Mar 26 12:08:41 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Mar 2010 12:08:41 -0400 Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: Grant Edwards wrote: > However, it can be used among peers in an affectionate way. One may > refer to one's peer as "code monkey" without offense, but a manager > could not refer to one of his employees as a "code monkey" without > risking it being seen as an insult. Somewhere on the Internet there's a particularly brilliant pop song called "Code Monkey". Mel. From joncle at googlemail.com Fri Mar 26 12:14:35 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Mar 2010 09:14:35 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 26 Mar, 15:45, Grant Edwards wrote: > On 2010-03-26, Luis M ?Gonz?lez wrote: > > > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > > Monkeys everywhere. > > Sorry for the off topic question, but what does "monkey" mean in a > > nerdy-geek context?? > > In colloquial English, "-monkey" is a slang term for a > person who does a particular job for a living. ?For example "grease > monkey" is a slang term for an auto mechanic. ?A "code monkey" is > somebody who writes code for a living. > > It can be slightly derogitory in some situations since it implies that > the task is mechanical and repetitive and doesn't require a lot of > creative thinking. > > However, it can be used among peers in an affectionate way. ?One may > refer to one's peer as "code monkey" without offense, but a manager > could not refer to one of his employees as a "code monkey" without > risking it being seen as an insult. > > Many people are accustomed to speaking anthopomorphically about > computers and programs, so when somebody writes a program that does > "foo", the name "foo monkey" seems natural for that program. > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! I don't know WHY I > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? said that ... I think it > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?came from the FILLINGS in > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?my rear molars ... Can I take the slight risk that actually it can also be (as you said 'affectionately') in a very positive sense. The same way "geek" or "nerd" can be applied. I used to be called "Big Geek" from the last company I worked for on PAYE, but that was a compliment. But, I've heard my step-dad call someone a "Geek" which is derogatory. No winning when you have language that can mean "bad" (in meaning "wicked/very good/awesome" (and even 'wicked' means good sometimes - as in enthusiasm for an idea)) or actually "bad/not good [add your own synonyms]". All valid, but which is good/bad :) Anyway, this' a group for Python, not English :) Feel better for my rant :) Jon. From ovidiudeac at gmail.com Fri Mar 26 12:26:20 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 18:26:20 +0200 Subject: python logging writes an empty file In-Reply-To: <4BACD667.7020803@sequans.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> <4BACD667.7020803@sequans.com> Message-ID: <804cd4021003260926y6610e90flb433737dc9a99e4a@mail.gmail.com> Anyway, thanks for the first part. Anybody else has any idea why using the same configuration file works when running the tests with nosetests and doesn't work with logging.config.fileConfig() ? From tim.wintle at teamrubber.com Fri Mar 26 12:54:30 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 26 Mar 2010 16:54:30 +0000 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <1269622470.29388.1.camel@localhost> On Fri, 2010-03-26 at 12:08 -0400, Mel wrote: > Somewhere on the Internet there's a particularly brilliant pop song > called "Code Monkey". http://www.jonathancoulton.com/2006/04/14/thing-a-week-29-code-monkey/ (he's linked to the mp3 from there) From __peter__ at web.de Fri Mar 26 13:29:23 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Mar 2010 18:29:23 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: > > method_template = "def test_foo(self):\ > #actual test_foo\ > pass" > exec method_template > > TestClass = types.ClassType("MyTestClass", (unittest.TestCase, ), {}) > TestClass.__module__ = "test" > > now what to do next? Just assign it: >>> import unittest >>> class MyTestClass(unittest.TestCase): pass ... >>> def test_foo(self): ... self.assertEquals(1, 2) ... >>> MyTestClass.test_foo = test_foo # <---- >>> unittest.main() F ====================================================================== FAIL: test_foo (__main__.MyTestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "", line 2, in test_foo AssertionError: 1 != 2 ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) If you don't know the method name beforehand use setattr(MyTestClass, method_name, method), e. g: >>> import unittest >>> class MyTestClass(unittest.TestCase): pass ... >>> def make_method(n): ... def test(self): self.assertEquals(2, n) ... return test ... >>> for i in range(3): ... setattr(MyTestClass, "test_%d" % i, make_method(i)) ... >>> unittest.main() FF. ====================================================================== FAIL: test_0 (__main__.MyTestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "", line 2, in test AssertionError: 2 != 0 ====================================================================== FAIL: test_1 (__main__.MyTestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "", line 2, in test AssertionError: 2 != 1 ---------------------------------------------------------------------- Ran 3 tests in 0.000s FAILED (failures=2) Peter From sccolbert at gmail.com Fri Mar 26 13:36:55 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 26 Mar 2010 13:36:55 -0400 Subject: Classes as namespaces? In-Reply-To: <4BACD7C7.1060006@sequans.com> References: <4BACD7C7.1060006@sequans.com> Message-ID: <7f014ea61003261036t11f50d89k409b66f854d53ab1@mail.gmail.com> i use them in Pymazon to encapsulate program wide settings and enforce valid values for these settings. http://code.google.com/p/pymazon/source/browse/pymazon/settings.py On Fri, Mar 26, 2010 at 11:50 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > kj wrote: > >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): >> spam = 1 >> jambon = 3 huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> >> >> Granted, this is not the "intended use" for classes, and therefore >> could be viewed as a misuse ("that's what dictionaries are for", >> etc.). But other than this somewhat academic objection[*], I really >> can see no problem with using classes in this way. >> >> > You cannot see the problem because there's no problem using classes as > namespaces. > > And yet, I've come across online murky warnings against using >> classes as "pseudo-namespaces". Is there some problem that I'm >> not seeing with this technique? >> >> ~K >> >> > import this > [snip] > Namespaces are one honking great idea -- let's do more of those! > > Modules and dictionaries are no more namespaces than classes. So any > container is potentially a namespace. > > JM > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Mar 26 13:38:58 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 26 Mar 2010 17:38:58 +0000 Subject: Have you embraced Python 3.x yet? References: Message-ID: On Fri, 26 Mar 2010 13:23:25 +0000, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? Still with 2.6, and probably will be indefinitely. I use Python mostly for Unix scripting: the kind of task which would traditionally have used Bourne shell. For that purpose, life is much simpler when everything is byte strings rather than character strings. If I was doing the same thing on Windows, Python 3.x would probably make more sense, as all of the OS APIs use Unicode (although there's still a hell of a lot of software written using the "ANSI" interfaces; my AppLocale folder has over a hundred entries). From no.email at please.post Fri Mar 26 13:51:36 2010 From: no.email at please.post (kj) Date: Fri, 26 Mar 2010 17:51:36 +0000 (UTC) Subject: Classes as namespaces? References: Message-ID: Thanks for all your comments. I see that modules are arguably Python's standard way for implementing namespaces. I guess I tend to avoid modules primarily because of lingering mental trauma over incidents of insane/bizarro import bugs in the past. (It's not rational, I know; it's like when one develops an aversion for some previously liked food after a bout of food poisoning with it.) Now I postpone creating a new Python module until the pain of not doing so forces me beyond my phobia. (Yes, you got that right, I'm a basket case.) From ownbusiness.ws at gmail.com Fri Mar 26 14:04:18 2010 From: ownbusiness.ws at gmail.com (www.ownbusiness.ws) Date: Fri, 26 Mar 2010 11:04:18 -0700 (PDT) Subject: Income for life ! Message-ID: www.ownbusiness.ws Change your life now. Try, it really works. From pavithra445 at gmail.com Fri Mar 26 14:04:44 2010 From: pavithra445 at gmail.com (PAVITHRA) Date: Fri, 26 Mar 2010 11:04:44 -0700 (PDT) Subject: EARN MONEY IN FREE TIME(DO MORE & EARN MORE) Message-ID: http://cancerresearch-vijay.blogspot.com/ http://nutritionhealthnoni.blogspot.com/ http://vijay-forestenjoy.blogspot.com/ http://information-041.blogspot.com/ http://onlineworktamilnadu.blogspot.com/ http://vijay-onlinejob.blogspot.com/ http://online-trading111.blogspot.com/ http://hot-problem.blogspot.com/ http://vijay681.blogspot.com/ http://nutuernoni.blogspot.com/ http://nonisearch2008.blogspot.com From ownbusiness.ws at gmail.com Fri Mar 26 14:05:12 2010 From: ownbusiness.ws at gmail.com (www.ownbusiness.ws) Date: Fri, 26 Mar 2010 11:05:12 -0700 (PDT) Subject: Income for life ! Message-ID: <5bd2ff92-4327-4699-a839-e280e0aa6225@j21g2000yqh.googlegroups.com> www.ownbusiness.ws Change your life now. Try, it really works. From philip at semanchuk.com Fri Mar 26 14:10:59 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 26 Mar 2010 14:10:59 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <4CA7EC42-05F4-46F2-A8B2-6BD8FE1CE17A@semanchuk.com> On Mar 26, 2010, at 1:51 PM, kj wrote: > Thanks for all your comments. > > I see that modules are arguably Python's standard way for implementing > namespaces. I guess I tend to avoid modules primarily because of > lingering mental trauma over incidents of insane/bizarro import > bugs in the past. There can be good reasons (i.e. unrelated to trauma) not to use a one- namespace-per-module rule. For instance, The app I'm working on now has 43 classes defined in a constants.py file. Each class is just a namespace for constants. That's much more practical than 43 modules called foo_constants.py, bar_constants.py, etc. My Currency(type=CurrencyType.USD, value=decimal.Decimal(".02")), Philip From luismgz at gmail.com Fri Mar 26 14:26:04 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 26 Mar 2010 11:26:04 -0700 (PDT) Subject: Classes as namespaces? References: Message-ID: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> On 26 mar, 11:49, kj wrote: > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ? spam = 1 > ? ? jambon = 3 > ? ? huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) I see no problem. I wouldn't mix English, French and Spanish in the same recipe though... From michel.metzger at gmail.com Fri Mar 26 14:41:21 2010 From: michel.metzger at gmail.com (Michel) Date: Fri, 26 Mar 2010 11:41:21 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> Thanks Peter. I searched a little bit more and wrote the following example: ------------------------------------ import types class MyClass: def test_toto(self): print type(self) print self.name def test_toto(self): print type(self) print self.name MyDynClass = types.ClassType("MyDynClass", (object, ), {}) MyDynClass.__module__ = "test.complex.hierarchy" MyDynClass.test_toto = test_toto t1 = MyDynClass() t2 = MyDynClass() t1.name = "Marcel" t2.name = "Oscar" t1.test_toto() t2.test_toto() c1 = MyClass() c1.name = "Raoul" c1.test_toto() -------------------------------- the output is: Marcel Oscar Raoul I'm wondering why the type of the self parameter is not 'instance' in the calls t1.test_toto() and t2.test_toto() The rest of the behavior is correct though, so I guess it's just internal Python stuff. Thanks for your help, Michel. On Mar 26, 1:29?pm, Peter Otten <__pete... at web.de> wrote: > Michel wrote: > > Hi everyone, > > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods to it and later instantiate this class. Methods > > need to be bound to the instance though, and that's my problem. Here > > is what I have so far: > > > method_template = "def test_foo(self):\ > > ? ? #actual test_foo\ > > ? ? pass" > > exec method_template > > > TestClass = types.ClassType("MyTestClass", (unittest.TestCase, ), {}) > > TestClass.__module__ = "test" > > > now what to do next? > > Just assign it: > > >>> import unittest > >>> class MyTestClass(unittest.TestCase): pass > ... > >>> def test_foo(self): > > ... ? ? self.assertEquals(1, 2) > ...>>> MyTestClass.test_foo = test_foo # <---- > >>> unittest.main() > > F > ====================================================================== > FAIL: test_foo (__main__.MyTestClass) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ? File "", line 2, in test_foo > AssertionError: 1 != 2 > > ---------------------------------------------------------------------- > Ran 1 test in 0.000s > > FAILED (failures=1) > > If you don't know the method name beforehand use > > setattr(MyTestClass, method_name, method), e. g: > > >>> import unittest > >>> class MyTestClass(unittest.TestCase): pass > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?>>> def make_method(n): > > ... ? ? def test(self): self.assertEquals(2, n) > ... ? ? return test ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ...>>> for i in range(3): > > ... ? ? setattr(MyTestClass, "test_%d" % i, make_method(i)) > ...>>> unittest.main() > > FF. > ====================================================================== > FAIL: test_0 (__main__.MyTestClass) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ? File "", line 2, in test > AssertionError: 2 != 0 > > ====================================================================== > FAIL: test_1 (__main__.MyTestClass) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ? File "", line 2, in test > AssertionError: 2 != 1 > > ---------------------------------------------------------------------- > Ran 3 tests in 0.000s > > FAILED (failures=2) > > Peter From vinay_sajip at yahoo.co.uk Fri Mar 26 15:09:10 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 26 Mar 2010 12:09:10 -0700 (PDT) Subject: python logging writes an empty file References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> <4BACD667.7020803@sequans.com> Message-ID: <12364311-5d80-4a14-a19b-f1e29aea9735@g19g2000yqe.googlegroups.com> On Mar 26, 4:26?pm, Ovidiu Deac wrote: > Anyway, thanks for the first part. > > Anybody else has any idea why using the same configuration file works > when running the tests with nosetests and doesn't work withlogging.config.fileConfig() ? It's probably because the fileConfig code is intended to *replace* any existing configuration. This means disabling any existing loggers which are not named explicitly, or not descendants of loggers named explicitly, in the configuration. Make sure you call logging.config.fileConfig() before any loggers have been instantiated in your code, or else ensure that all the top-level parents of those loggers (i.e. just below the root logger) are defined in the configuration. If you have version 2.6 or newer of Python, the fileConfig call has an optional keyword parameter disable_existing_loggers which has a default value of True, but which you can set to False to avoid disabling the existing loggers. Regards, Vinay Sajip From jonas at lophus.org Fri Mar 26 15:10:24 2010 From: jonas at lophus.org (Jonas H.) Date: Fri, 26 Mar 2010 20:10:24 +0100 Subject: [C-API] malloc error in PyDict_New Message-ID: <4BAD06A0.3080206@lophus.org> Hi there, I'm currently diving into Python C programming and I have a problem with `PyDict_New`. My application receives a SIGABRT from malloc every time I execute `PyDict_New`. malloc throws the following error: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) [snip]' failed. gdb gives me the following traceback: Program received signal SIGABRT, Aborted. 0x0012d422 in __kernel_vsyscall () (gdb) bt full #0 0x0012d422 in __kernel_vsyscall () #5 0x003fef8c in malloc () from /lib/tls/i686/cmov/libc.so.6 #6 0x001b129c in new_arena (nbytes=3221223842) at ../Objects/obmalloc.c:534 i = numarenas = 16 arenaobj = 0x0 excess = 16 #7 PyObject_Malloc (nbytes=3221223842) at ../Objects/obmalloc.c:794 bp = pool = next = size = 4983326 #8 0x001baef5 in PyString_FromString (str=0x2964bf "") at ../Objects/stringobject.c:138 op = 0x0 #9 0x001a9d55 in PyDict_New () at ../Objects/dictobject.c:227 mp = #10 0x08048fc0 in Transaction_new () at bjoern.c:32 transaction = 0x80503a0 #11 0x08049309 in on_sock_accept (mainloop=0x13a120, accept_watcher=0xbffff770, revents=1) at bjoern.c:109 [snip] #12 0x00130594 in ev_invoke_pending () from /usr/lib/libev.so.3 #13 0x00135774 in ev_loop () from /usr/lib/libev.so.3 #14 0x080496e0 in main (argcount=1, args=0xbffff864) at bjoern.c:207 [snip] I have walked millions of Google pages but I couldn't find any explanation what causes the allocation error. I tried to put the `PyDict_New` somewhere else to let it be invoked earlier/later. The only effect I got is a "memory corruption" reported by glibc. Could anybody tell me what exactly I'm doing wrong? It is quite possible that I fscked up some pointers or memory ranges as this is my first C project. You can find the whole source at github: http://github.com/jonashaag/bjoern The call to `PyDict_New` is here: http://github.com/jonashaag/bjoern/blob/master/bjoern.c#L32 Thanks for your help! Jonas From __peter__ at web.de Fri Mar 26 15:16:28 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Mar 2010 20:16:28 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> Message-ID: Michel wrote: > Thanks Peter. > > I searched a little bit more and wrote the following example: > > ------------------------------------ > import types > > class MyClass: > > def test_toto(self): > print type(self) > print self.name > > def test_toto(self): > print type(self) > print self.name > > MyDynClass = types.ClassType("MyDynClass", (object, ), {}) > MyDynClass.__module__ = "test.complex.hierarchy" > MyDynClass.test_toto = test_toto > > t1 = MyDynClass() > t2 = MyDynClass() > > t1.name = "Marcel" > t2.name = "Oscar" > > t1.test_toto() > t2.test_toto() > > c1 = MyClass() > c1.name = "Raoul" > c1.test_toto() > -------------------------------- > > the output is: > > > Marcel > > Oscar > > Raoul > > I'm wondering why the type of the self parameter is not 'instance' in > the calls > t1.test_toto() and t2.test_toto() > > The rest of the behavior is correct though, so I guess it's just > internal Python stuff. In Python 2.x there are "classic" and "newstyle" classes. In practice the main differences are that classic classes are more likely to call __getattr__() and that only newstyle classes support properties correctly. By inheriting from object you make MyDynClass a newstyle class: >>> classic = types.ClassType("A", (), {}) >>> newstyle = types.ClassType("A", (object,), {}) >>> type(classic()), type(classic) (, ) >>> type(newstyle()), type(newstyle) (, ) Classic classes exist for backwards compatibility and because most programmers are too lazy to have their classes inherit from object when the difference doesn't matter. When you create a class dynamically I recommend that you use the type() builtin instead of types.ClassType(). This will always create a newstyle class -- even when you don't inherit from object explicitly: >>> type(type("A", (), {})) >>> type("A", (), {}).__bases__ (,) Peter From steve at holdenweb.com Fri Mar 26 15:19:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Mar 2010 15:19:44 -0400 Subject: Create a class at run-time In-Reply-To: <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> Message-ID: Michel wrote: > Thanks Peter. > > I searched a little bit more and wrote the following example: > > ------------------------------------ > import types > > class MyClass: > > def test_toto(self): > print type(self) > print self.name > > def test_toto(self): > print type(self) > print self.name > > MyDynClass = types.ClassType("MyDynClass", (object, ), {}) > MyDynClass.__module__ = "test.complex.hierarchy" > MyDynClass.test_toto = test_toto > > t1 = MyDynClass() > t2 = MyDynClass() > > t1.name = "Marcel" > t2.name = "Oscar" > > t1.test_toto() > t2.test_toto() > > c1 = MyClass() > c1.name = "Raoul" > c1.test_toto() > -------------------------------- > > the output is: > > > Marcel > > Oscar > > Raoul > > I'm wondering why the type of the self parameter is not 'instance' in > the calls > t1.test_toto() and t2.test_toto() > > The rest of the behavior is correct though, so I guess it's just > internal Python stuff. > Yes, it's just that MyClass is an old-style class (its type is ) whereas MyDynClass is a new-style class (its type is , because it inherits from object). It's as though you had written class MyClass: ... class MyDynClass(object): ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From stefan_ml at behnel.de Fri Mar 26 15:41:50 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Mar 2010 20:41:50 +0100 Subject: [C-API] malloc error in PyDict_New In-Reply-To: <4BAD06A0.3080206@lophus.org> References: <4BAD06A0.3080206@lophus.org> Message-ID: Jonas H., 26.03.2010 20:10: > I'm currently diving into Python C programming and I have a problem with > `PyDict_New`. > > My application receives a SIGABRT from malloc every time I execute > `PyDict_New`. malloc throws the following error: > > malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) > &((av)->bins[((1) - 1) * 2])) [snip]' failed. In case this code is not called from within Python but from some kind of network layer callback (maybe in a thread created by C code?), you will have to set up a Python interpreter environment for such a thread first. See the PyInterpreterState and PyThreadState functions here: http://docs.python.org/c-api/init.html Stefan From phlip2005 at gmail.com Fri Mar 26 15:44:04 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 26 Mar 2010 12:44:04 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> On Mar 26, 6:14?am, Luis M. Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? > > Luis Better at typing than thinking. From mensanator at aol.com Fri Mar 26 16:07:34 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 26 Mar 2010 13:07:34 -0700 (PDT) Subject: Have you embraced Python 3.x yet? References: Message-ID: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> On Mar 26, 8:23?am, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? 3.1. The only module I use regularly is gmpy and that's one that has been updated. From ovidiudeac at gmail.com Fri Mar 26 16:08:14 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 22:08:14 +0200 Subject: python logging writes an empty file In-Reply-To: <12364311-5d80-4a14-a19b-f1e29aea9735@g19g2000yqe.googlegroups.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> <4BACD667.7020803@sequans.com> <12364311-5d80-4a14-a19b-f1e29aea9735@g19g2000yqe.googlegroups.com> Message-ID: <804cd4021003261308m5c5fc88cp35e0d1c43909aeb2@mail.gmail.com> It worked. Setting disable_existing_loggers=False fixed my problem. Thanks to both of you! Ovidiu On Fri, Mar 26, 2010 at 9:09 PM, Vinay Sajip wrote: > On Mar 26, 4:26?pm, Ovidiu Deac wrote: >> Anyway, thanks for the first part. >> >> Anybody else has any idea why using the same configuration file works >> when running the tests with nosetests and doesn't work withlogging.config.fileConfig() ? > > It's probably because the fileConfig code is intended to *replace* any > existing configuration. This means disabling any existing loggers > which are not named explicitly, or not descendants of loggers named > explicitly, in the configuration. > > Make sure you call logging.config.fileConfig() before any loggers have > been instantiated in your code, or else ensure that all the top-level > parents of those loggers (i.e. just below the root logger) are defined > in the configuration. > > If you have version 2.6 or newer of Python, the fileConfig call has an > optional keyword parameter disable_existing_loggers which has a > default value of True, but which you can set to False to avoid > disabling the existing loggers. > > Regards, > > Vinay Sajip > -- > http://mail.python.org/mailman/listinfo/python-list > From mensanator at aol.com Fri Mar 26 16:18:47 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 26 Mar 2010 13:18:47 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: On Mar 26, 2:44?pm, Phlip wrote: > On Mar 26, 6:14?am, Luis M. Gonz?lez wrote: > > > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > > Monkeys everywhere. > > Sorry for the off topic question, but what does "monkey" mean in a > > nerdy-geek context?? > > > Luis > > Better at typing than thinking. Really? I thought it was more of a reference to Eddington, i.e., given enough time even a monkey can type out a program. From sccolbert at gmail.com Fri Mar 26 16:26:44 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 26 Mar 2010 16:26:44 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> Message-ID: <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> On Fri, Mar 26, 2010 at 4:07 PM, Mensanator wrote: > On Mar 26, 8:23 am, Harishankar wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > 3.1. > > The only module I use regularly is gmpy and that's one that has > been updated. > -- > http://mail.python.org/mailman/listinfo/python-list > I won't switch until NumPy and SciPy make the jump. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivlenin at gmail.com Fri Mar 26 16:46:04 2010 From: ivlenin at gmail.com (I V) Date: 26 Mar 2010 21:46:04 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4bac1380$1@news.x-privat.org> Message-ID: <4bad1d0c$1@news.x-privat.org> On Fri, 26 Mar 2010 08:54:11 -0700, Michel wrote: > I want to add a method to a class such that it can be invoked on > specifics instances. > You solution works (as well as Patrick's one), thanks ! I still have a > question though. If I print the type of the self object I get when my > method is > called, I get "". I guess this is because the > method is defined as a class method. > This is ok in my case, but just out of curiosity, what should I do to > change this method to an instance method? It already is an instance method. When you create a TestClass instance, the type of that instance is TestClass (the type of TestClass itself is "type"). From ricaraoz at gmail.com Fri Mar 26 16:51:23 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 26 Mar 2010 17:51:23 -0300 Subject: Classes as namespaces? In-Reply-To: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> Message-ID: <4BAD1E4B.5000000@gmail.com> Luis M. Gonz?lez wrote: > On 26 mar, 11:49, kj wrote: > >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): >> spam = 1 >> jambon = 3 >> huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> > > I see no problem. > I wouldn't mix English, French and Spanish in the same recipe though... > Why? Do you think it might get over cooked? ;c) -------------- next part -------------- An HTML attachment was scrubbed... URL: From winstonwolff at gmail.com Fri Mar 26 17:34:42 2010 From: winstonwolff at gmail.com (Winston) Date: Fri, 26 Mar 2010 14:34:42 -0700 (PDT) Subject: Revisiting Generators and Subgenerators References: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> Message-ID: On Mar 26, 7:29?am, Sebastien Binet wrote: > > Proposal for a new Generator Syntax in Python 3K-- > > A Baton object for generators to allow subfunction to yield, and to > > make > > them symetric. > > isn't a Baton what CSP calls a channel ? > > there is this interesting PyCSP library (which implements channels > over greenlets, os-processes (via multiprocessing) or python threads)http://code.google.com/p/pycsp > > cheers, > sebastien. Thanks for the link. After reading about Greenlets, it seems my Baton is a Greenlet. It is not passed in to the new greenlet as I wrote above, but both sides use it to pass execution to the other, and to send a value on switching. I'm glad my thinking is matching other people's thinking. Now I have to search for a greenlet written for Jython. And thanks to others for their thoughts on this subject. -Winston From novacompute at gmail.com Fri Mar 26 17:58:08 2010 From: novacompute at gmail.com (wukong) Date: Fri, 26 Mar 2010 14:58:08 -0700 (PDT) Subject: exec .exe Message-ID: newbie question, how do you run a .exe generated by MSVC++ in python in windows? From ldo at geek-central.gen.new_zealand Fri Mar 26 18:05:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Mar 2010 11:05:34 +1300 Subject: sqlite version on windows References: <4BAC8521.2@shopzeus.com> Message-ID: In message , Philip Semanchuk wrote: > On Mar 26, 2010, at 5:57 AM, Laszlo Nagy wrote: >> >> On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: >> 3.6.10 >> On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: >> 3.5.9 >> >> Why is that? > > The few Linux distros that I checked are much more aggressive about > bundling newer versions of SQLite. For instance, Ubuntu 8.04 has > Python 2.5.2 with SQLite 3.4.2, while Ubuntu 8.10 has the same version > of Python but offers SQLite 3.5.9. > > You asked "why" and I don't know. I imagine it comes down to > philosophical differences or maybe just a lack of time to test when > building new WIndows distros for Python.org. Maybe the issues are more practical than philosophical. Linux distros use an integrated package manager and are maintained by a cohesive community. What that means is that the SQLite package isn?t just used by Python, but by a bunch of other stuff as well. So all the maintainers of those packages have an interest in making sure that SQLite doesn?t break them. Whereas on Windows, the Python download has to include _all_ its dependencies, it cannot rely on a system-integrated package manager to automatically provide them. And the same is true for every other open-source package that anyone tries to pre-build for Windows. So they all have to provide their own installation routines, their own updates, their own testing ... in short, a lot of duplication of effort. This is expensive. From emile at fenx.com Fri Mar 26 18:09:24 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 26 Mar 2010 15:09:24 -0700 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: On 3/26/2010 1:18 PM Mensanator said... > On Mar 26, 2:44 pm, Phlip wrote: >> On Mar 26, 6:14 am, Luis M. Gonz?lez wrote: >> >>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >> >>> Monkeys everywhere. >>> Sorry for the off topic question, but what does "monkey" mean in a >>> nerdy-geek context?? >> >>> Luis >> >> Better at typing than thinking. > > Really? I thought it was more of a reference to Eddington, i.e., given > enough time even a monkey can type out a program. I like the quote that went along the lines of 'here we are, and no we haven't' From irmen-NOSPAM- at xs4all.nl Fri Mar 26 18:10:38 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Fri, 26 Mar 2010 23:10:38 +0100 Subject: exec .exe In-Reply-To: References: Message-ID: <4bad3060$0$22937$e4fe514c@news.xs4all.nl> On 26-3-2010 22:58, wukong wrote: > newbie question, how do you run a .exe generated by MSVC++ in python > in windows? Use the subprocess module, for instance: subprocess.call(["notepad.exe", "d:/file.txt"]) irmen From cs at zip.com.au Fri Mar 26 18:28:28 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 27 Mar 2010 09:28:28 +1100 Subject: Revisiting Generators and Subgenerators In-Reply-To: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> References: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> Message-ID: <20100326222828.GA15135@cskk.homeip.net> On 26Mar2010 07:29, Sebastien Binet wrote: | On Mar 25, 10:39?pm, Winston wrote: | > A Baton object for generators to allow subfunction to yield, and to | > make them symetric. | | isn't a Baton what CSP calls a channel ? I was thinking about this (roughly) in the shower this morning before seeing this message. One difference is that a Channel or zero-storage Queue lets the putter continue execution after the put (or at least the other side's get). A co-routine won't proceed until later, no? So a co-routine setup will do lazier computation than a similar threaded setup. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Principles have no real force except when one is well fed. - Mark Twain From novacompute at gmail.com Fri Mar 26 18:48:02 2010 From: novacompute at gmail.com (wukong) Date: Fri, 26 Mar 2010 15:48:02 -0700 (PDT) Subject: exec .exe References: <4bad3060$0$22937$e4fe514c@news.xs4all.nl> Message-ID: <8524a2ad-1f16-45b1-9c56-6f8b5b7e1413@l12g2000pra.googlegroups.com> On Mar 26, 3:10?pm, Irmen de Jong wrote: > On 26-3-2010 22:58, wukong wrote: > > > newbie question, how do you run a .exe generated by MSVC++ in python > > in windows? > > Use the subprocess module, for instance: > subprocess.call(["notepad.exe", "d:/file.txt"]) > > irmen worked like a charm, :-) thanks irmen. From tjreedy at udel.edu Fri Mar 26 19:43:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Mar 2010 19:43:18 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: On 3/26/2010 9:23 AM, Harishankar wrote: > Have you people embraced Python 3.x? Yes. My current work only needs the stdlib and I much prefer the streamlined language. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 26 20:03:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Mar 2010 00:03:30 GMT Subject: Classes as namespaces? References: Message-ID: <4bad4b52$0$27866$c3e8da3@news.astraweb.com> On Fri, 26 Mar 2010 14:49:02 +0000, kj wrote: > What's the word on using "classes as namespaces"? >>> import this [...] Namespaces are one honking great idea -- let's do more of those! > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one ("the > 'intended use' for triple-quoting is not to comment out code", etc.). On the contrary. CPython deliberately strips bare strings (whether triple quoted or not) out during compilation. This isn't an accident, it is deliberate. >>> code = """ ... x = 1 ... y = 2 ... # comment ... "a string" ... z = 4 ... """ >>> o = compile(code, '', 'exec') >>> dis.dis(o) 2 0 LOAD_CONST 0 (1) 3 STORE_NAME 0 (x) 3 6 LOAD_CONST 1 (2) 9 STORE_NAME 1 (y) 6 12 LOAD_CONST 2 (4) 15 STORE_NAME 2 (z) 18 LOAD_CONST 3 (None) 21 RETURN_VALUE Why should you not do this? First, it is implementation-specific: other Pythons may not behave the same. Potentially they may compile in the (potentially large) string, push it on the stack, then immediately pop it off again. Older versions of CPython used to do that for non-strings. Secondly, and FAR more importantly, leaving large amounts of commented out code in your source is a TERRIBLE idea. Yes, sure, it's tempting to do, especially for quick and dirty scripts. Resist the temptation. Learn how to use a proper code repository. Don't leave the detritus of ancient unused code in your source files -- it confuses the reader, makes searching harder, slows down parsing, and (trust me) you will never need to read the old code again. It just gets in the way. Of course, like everything, this needs to be considered in context. You might leave commented-out code like this: # DON'T DO THIS: # s = spam(s, s*2) # It doesn't work. See bug #12345 in the tracker. Instead do this: s = spam(s*2, s) -- Steven From debatem1 at gmail.com Fri Mar 26 20:33:12 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 26 Mar 2010 20:33:12 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: On Fri, Mar 26, 2010 at 9:23 AM, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many people are > using 3.x as opposed to 2 so I want to keep my programs compatible for > the majority. > > -- Hari > -- > http://mail.python.org/mailman/listinfo/python-list > Yes- I write new code in 3.x and backport it PRN. Geremy Condra From ethan at stoneleaf.us Fri Mar 26 20:59:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 26 Mar 2010 17:59:21 -0700 Subject: Python database of plain text editable by notepad or vi In-Reply-To: References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: <4BAD5869.1010107@stoneleaf.us> Jon Clements wrote: > On 26 Mar, 09:49, James Harris wrote: > >>On 25 Mar, 22:56, Jon Clements wrote: >> >> >> >> >>>On 25 Mar, 22:40, James Harris wrote: >> >>>>I am looking to store named pieces of text in a form that can be >>>>edited by a standard editor such as notepad (under Windows) or vi >>>>(under Unix) and then pulled into Python as needed. The usual record >>>>locking and transactions of databases are not required. >> >>>>Another way to look at it is to treat the separate files as entries in >>>>a dictionary. The file name would be the key and the lines of the file >>>>the value. >> >>>>Anyone know of a database (with a Python interface) which will allow >>>>text files to be treated as database fields? If not I can just write >>>>it but I thought it best to ask if there was an existing solution >>>>first. >> >>... >> >>>I could be missing something here, but aren't you basically just >>>talking about an OS's filesystem? >> >>For storage, yes. The files would be marked-up text stored in the >>filesystem. The "dbms" (I use the term loosely!) would provide access >>to them by some full or partial key mechanism yet to be determined. >>Read-only access would do - at least for now. >> >> >>>glob or listdir somewhere, then create a dict using the file contents >>>would meet your criteria, with very little lines of code -- but I >>>would be interested to know what the use-case was for this... Is it >>>read completely at start up time, or if each file contains a large >>>amount of lines and aren't fixed width (or has no other indexing >>>support without maintenance), then is a complete sequential-scan >>>required each time, or do you just tell the user to not update when >>>running (unless I s'pose something along the lines of a SIGHUP for >>>config files is applicable). >> >>All good questions. For now, at least, the files can be read-only and >>I'd want those on disk to be the master copies at all times. If I was >>writing it myself I'd probably 'cache' some files in memory and stat >>them before use. If newer I would reread the file. >> > > > It's hard to bore this group :) > > >> >>>Sorry, just don't understand why you'd want this. >> >>I tried to avoid boring folks with the details. I'm toying with some >>ideas for a way to help generate source code (in various languages, >>not just Python). If it goes ahead the text files would be mainly >>marked-up code snippets - with or without symbols that need to be >>replaced. >> >>Rather than write one single monolithic app I thought to split it into >>reusable components. One part being data access could perhaps be an >>existing database (and I'll take a look at jkn's suggestion). >> >>Think of the database as similar to an associative array stored on >>disk. The only difference is I may want to play fast and loose with >>the keys in some ways - e.g. check for partial key matches or return a >>list of part-matched keys. The language name could be part of the key >>but I'd also need to store variants for specific language versions. >>I'm not sure yet how it will all pan out. As I say, just throwing >>around some ideas. >> >>James > > > Thanks for the explanation. > > Who admins and, who's editing this data? > > I couldn't 100% guarantee that I could modify a text file and always > put the right > delimiter in the right place and remember to escape the relevant chars > (and I'm > probably not the 'average' user). > > Any opposition to just putting it in a 'proper' DB, then 'blobbing' > the values? > (or just integrate a procedure/script/function whatever your chosen > RDBMS calls to choose it). > Or in some systems, 'externally referencing'... loads of DB's have > free front-ends, > and there are lots of Python libraries. > > I think perhaps, all I'm saying is, I'd choose a different approach. > I'd provide a front-end, rather than choose to re-write the wheel over > DB's. Just to provide a counter-viewpoint: The (one) system I have worked with that was like that (program source files kept in blobs in a database) I absolutely hated. I was stuck with using the tools provided by the app (which, amazingly enough, I also hated ;), and unable to use my own tools because because *my* source files were _not_ saved as *files*. Okay, venting over. My point is, if what you are storing is plain ol' source files, providing a way to directly access them is a good thing. If what you are storing is a mangled version, the ability to let the user choose any editor to use is a good thing. :) My $0.02. ~Ethan~ From nocbos at gmail.com Fri Mar 26 21:18:07 2010 From: nocbos at gmail.com (C. B.) Date: Fri, 26 Mar 2010 18:18:07 -0700 (PDT) Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: At first, thank you all for your answers. Some more details about what I'm coding and what I need... The classes AAA and BBB are just given as examples. In fact, BBB's constructor accepts several parameters, meaning it can be different for each creation of AAA. So it can't be simply skipped from the AAA's one, even if there can be a default value. Making AAA do the call to BBB is a solution, but, in that case, the end-user loses the reference to the used BBB instance. Concerning the reason why I wish to avoid importing, once again AAA and BBB were just examples. I plan to add more classes, so AAA will also need CCC, DDD, and so on to work. It takes time to write the relative importations, that's ok, but I think it could be more pleasant for the end-user to not have to write a huge list of "from mymodule import xxx" if it is possible to take advantage of automatic importations. Cheers, From apt.shansen at gmail.invalid Fri Mar 26 21:45:54 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Fri, 26 Mar 2010 18:45:54 -0700 Subject: GIF89A and PIL Message-ID: <2010032618455468300-aptshansen@gmailinvalid> Hi, all. Is it possible to get PIL to save GIF's in GIF89A format, instead of GIF87A? If not, are there any decent other image libraries out there that anyone's familiar with? The only one I could find was PythonMagick, which seems completely undocumented. Or I'm blind. Ahem. But the problem is, I have a nice, small little 72 byte GIF89A file, that I want to do some slight tweaking on and then re-save. I noticed that even if I completely skipped the tweaking step and -just- saved, it exploded into a 919 byte GIF87A file. And in this context, bytes really, really matter. I picked GIF over PNG because the same file in PNG was 120 bytes :) I'm not an expert on graphics, so I don't actually know for certain if its the fact that PIL is saving in GIF87A format that's causing the size to explode, it might just be that PIL is doing.. Something Weird when it saves it as a GIF, too. To demonstrate: >>> f = open('../tiles/BaseTemplate.gif', 'rb') >>> d1 = f.read() >>> len(d1) 73 >>> d1 'GIF89a\x10\x00\x10\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00!\xf9\x04\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x10\x00\x10\x00\x00\x02 \x8c\x8fi\xc0\xed\xbe\x9edq\xbej\x1b\xce`go\x81\x93(\x91W\xc0AhJ\xad\xac\xa9*\xb2Q\x00\x00;' >>> im = Image.open('../tiles/BaseTemplate.gif') >>> import cStringIO >>> cfp = cStringIO.StringIO() >>> im.save(cfp, format="gif") >>> cfp.seek(0) >>> d2 = cfp.read() >>> d2 'GIF87a\x10[...snip...]\x00;' >>> len(d2) 919 -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 26 22:00:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Mar 2010 02:00:24 GMT Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4bad66b8$0$27866$c3e8da3@news.astraweb.com> On Fri, 26 Mar 2010 18:18:07 -0700, C. B. wrote: > It takes time to write the relative importations, that's ok, but I think > it could be more pleasant for the end-user to not have to write a huge > list of "from mymodule import xxx" if it is possible to take advantage > of automatic importations. You mean by black magic? Something like this? >>> GGG = "My really important value" >>> from mymodule import AAA >>> print AAA() "something" >>> print GGG >>> print "WTF happened to my important value???" 'magic ate it' As a general rule, Python does not allow magic. One exception is: from mymodule import * however once you have been bitten by it, you will soon learn to avoid it as almost always a bad idea. -- Steven From timr at probo.com Fri Mar 26 23:15:27 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 26 Mar 2010 20:15:27 -0700 Subject: Advice Criticism on Python App References: Message-ID: Steven D'Aprano wrote: >On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote: > >> Jimbo wrote: >>> >>>class stock: >>> code = "" >>> purchasePrice = 0 >>> purchaseQuantity = 0 >>> price = [] # list of recent prices >>> recentBid = [] # list of recent bids for stock >>> recentOffer = [] # list of recent offers for stock >>> stockVol = [] # list of stock quantity available on market >> >> Using lists as class variables is a very good way to create very >> surprising bugs. Consider the following: > >Don't you think that the class attributes are *supposed* to be shared by >all instances? In that case the behaviour you show is not a bug at all. Yes, it occurred to me just after I sent that pot that I had answered a different question from the one he asked. I SUSPECT that he is using class variables as a way to initialize members, not as true class variables. Thanks for clarifying this. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Fri Mar 26 23:50:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Mar 2010 03:50:00 +0000 Subject: Automatic import ? In-Reply-To: References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4BAD8068.3010309@mrabarnett.plus.com> C. B. wrote: > At first, thank you all for your answers. > > Some more details about what I'm coding and what I need... > > The classes AAA and BBB are just given as examples. In fact, BBB's > constructor accepts several parameters, meaning it can be different > for each creation of AAA. So it can't be simply skipped from the AAA's > one, even if there can be a default value. > > Making AAA do the call to BBB is a solution, but, in that case, the > end-user loses the reference to the used BBB instance. > > Concerning the reason why I wish to avoid importing, once again AAA > and BBB were just examples. I plan to add more classes, so AAA will > also need CCC, DDD, and so on to work. > > It takes time to write the relative importations, that's ok, but I > think it could be more pleasant for the end-user to not have to write > a huge list of "from mymodule import xxx" if it is possible to take > advantage of automatic importations. > Couldn't you just have: import mymodule as m and then use: m.AAA m.BBB and so on? It's not much longer and it avoids 'magic'. From ldo at geek-central.gen.new_zealand Sat Mar 27 00:37:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Mar 2010 17:37:10 +1300 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> Message-ID: In message <2010032618455468300-aptshansen at gmailinvalid>, Stephen Hansen wrote: > Is it possible to get PIL to save GIF's in GIF89A format, instead of > GIF87A? Why? What does GIF do for you that PNG doesn?t? From apt.shansen at gmail.invalid Sat Mar 27 00:53:10 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Fri, 26 Mar 2010 21:53:10 -0700 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> Message-ID: <2010032621531095506-aptshansen@gmailinvalid> On 2010-03-26 21:37:10 -0700, Lawrence D'Oliveiro said: > In message <2010032618455468300-aptshansen at gmailinvalid>, Stephen Hansen > wrote: > >> Is it possible to get PIL to save GIF's in GIF89A format, instead of >> GIF87A? > > Why? What does GIF do for you that PNG doesn?t? If I take this PSD and save it as a GIF as fully optimized as possible, its 72 bytes; do the same with PNG, and its 120. In this situation that difference really is very important. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From greg.ewing at canterbury.ac.nz Sat Mar 27 01:18:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 27 Mar 2010 17:18:40 +1200 Subject: from import and __init__.py In-Reply-To: References: <20100325101632.GA4727@xs4all.nl> Message-ID: <815i6bF3lcU1@mid.individual.net> egbert wrote: > Yes, you are right. And I can reach everything with > modules['some_package'] > or variants thereof. Although note that the usual way to get it would be to simply do import some_package -- Greg From greg.ewing at canterbury.ac.nz Sat Mar 27 01:23:19 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 27 Mar 2010 17:23:19 +1200 Subject: Represent object type as In-Reply-To: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> References: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> Message-ID: <815if2F3lcU2@mid.individual.net> Jason wrote: > I'm reusing the __getstate__ function I wrote for pickling like > so: Instead of reinventing part of pickle, is there some reason you couldn't just use it? -- Greg From anythinginternetseo at gmail.com Sat Mar 27 01:26:02 2010 From: anythinginternetseo at gmail.com (anything internet) Date: Fri, 26 Mar 2010 22:26:02 -0700 (PDT) Subject: Stop the Heat from Sun Rays! Message-ID: Stop the Heat! Stop UV Damage! Save Money! - More Details : http://www.suntechglasstinting.com/welcome.php From matttibbals69 at yahoo.com Sat Mar 27 01:48:45 2010 From: matttibbals69 at yahoo.com (matttibbals) Date: Fri, 26 Mar 2010 22:48:45 -0700 (PDT) Subject: python Message-ID: <65354fef-2e84-4182-bfdb-69dc5468e9b6@f12g2000prn.googlegroups.com> I'm Matt Tibbals, pedophile. http://www.matthewtibbals.com From lacrima.maxim at gmail.com Sat Mar 27 02:10:59 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Fri, 26 Mar 2010 23:10:59 -0700 (PDT) Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] References: mailman.1182.1269520510.23598.python-list@python.org <54e41616-df9f-42dd-9c91-9e530650bd99@j21g2000yqh.googlegroups.com> <9dd0d6b0-7249-4a6f-8d03-b0c3a44eace2@l25g2000yqd.googlegroups.com> Message-ID: On Mar 26, 10:22?am, Michele Simionato wrote: > On Mar 25, 2:24?pm, Michele Simionato > wrote: > > > On Mar 25, 1:28?pm, Ethan Furman wrote: > > > > Michele, > > > > Was wondering if you'd had a chance to re-post your lectures -- just did > > > a search for them and came up empty, and I would love to read them! > > > > Many thanks in advance! > > > Oops, I forgot! I will try to make them available soon. > > Here they are:http://www.phyast.pitt.edu/~micheles/oxford-lectures.zip Hello, Michele! Thanks a lot for posting!!! From vipshopper.us at hotmail.com Sat Mar 27 03:53:05 2010 From: vipshopper.us at hotmail.com (marrylin) Date: Sat, 27 Mar 2010 00:53:05 -0700 (PDT) Subject: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Message-ID: <31437927-ccfd-403f-b79e-e349e662b286@33g2000yqj.googlegroups.com> Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Air jordan(1-24)shoes $33 UGG BOOT $50 Nike shox(R4,NZ,OZ,TL1,TL2,TL3) $35 Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 FREE SHIPPING From steve at REMOVE-THIS-cybersource.com.au Sat Mar 27 06:18:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Mar 2010 10:18:35 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> Message-ID: <4baddb7b$0$27866$c3e8da3@news.astraweb.com> On Fri, 26 Mar 2010 07:31:17 -0700, Steve Howell wrote: > From a purely academic standpoint, I'm not convinced that sum() is > inefficient in terms of big-O complexity, though. > > showell at showell-laptop:~$ python > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on > linux2 > >>> class StupidList: [...] But it's not *sum* that is inefficient, it is sum *with a particular data structure*. Sure, if you create your own data structure, you can make it as efficient as you like. Obviously the sum algorithm itself has to perform one addition per item, or O(N), which scales tolerably well. But each addition has a cost. If the cost is constant, then sum() as a whole remains O(N). But if the cost of addition varies with N, sum() degrades badly. We can compare the performance of sum with different data structures, starting with plain integers versus long integers: >>> from timeit import Timer >>> setup = 'data = [%d]*%d' >>> for i in range(6): ... t1 = Timer('sum(data, 0)', setup % (1, 10**i)) ... t2 = Timer('sum(data, 0)', setup % (10**50, 10**i)) ... print min(t1.repeat(number=1000)), ... print min(t2.repeat(number=1000)) ... 0.00179290771484 0.00263810157776 0.00340414047241 0.00854396820068 0.0190401077271 0.0502791404724 0.155302047729 0.645124912262 0.794432878494 2.55748295784 7.97877693176 25.3812758923 Both scale about as well, but the cost varies significantly: arithmetic on very large longints is expensive. Strings, with a trick to fool sum into accepting them, versus lists. Note that I changed the number of iterations from 6 down to 5. The reason why will become obvious: >>> class EmptyStringStarter: ... def __add__(self, other): ... return other ... >>> empty = EmptyStringStarter() >>> setup = """from __main__ import empty; data = [%r]*%d""" >>> >>> for i in range(5): ... t1 = Timer('sum(data, empty)', setup % ('a', 10**i)) ... t2 = Timer('sum(data, [])', setup % ([1], 10**i)) ... print min(t1.repeat(number=1000)), ... print min(t2.repeat(number=1000)) ... 0.00849103927612 0.00226998329163 0.0121459960938 0.0082700252533 0.0489149093628 0.186735153198 0.428920030594 5.28623914719 14.6552250385 589.102822065 Strings perform tolerably well, up to a point, but lists perform terribly. And in fact, the relatively good performance of strings is an artifact of recent versions of CPython. In Jython and IronPython, and older versions of CPython, it will behave as poorly as lists. > I wonder how severely sum(), without > the restriction, would underperform join() on modern versions of Python, > though. Take note that, in order to get an answer in reasonable time, I've reduced the number of timing iterations drastically: >>> for i in range(6): ... t1 = Timer('sum(data, empty)', setup % ('a', 10**i)) ... t2 = Timer('"".join(data)', setup % ('a', 10**i)) ... print min(t1.repeat(number=10)), ... print min(t2.repeat(number=10)) ... 8.89301300049e-05 1.09672546387e-05 0.000131845474243 2.19345092773e-05 0.000591993331909 9.29832458496e-05 0.0101289749146 0.00082802772522 0.365957021713 0.00884819030762 24.2072279453 0.0421011447906 Note the performance degradation of sum. It gets worse. Much worse: >>> for i in range(4, 7): ... t1 = Timer('sum(data, empty)', setup % ('a', 10**i)) ... t2 = Timer('"".join(data)', setup % ('a', 10**i)) ... print min(t1.repeat(number=1)), # note fewer iterations ... print min(t2.repeat(number=1)) ... 0.031229019165 0.000817060470581 2.45445990562 0.00365781784058 1024.79705095 0.0398509502411 This is absolutely catastrophic performance degradation. -- Steven From davea at ieee.org Sat Mar 27 06:18:40 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 27 Mar 2010 05:18:40 -0500 Subject: Traversing through Dir() In-Reply-To: References: Message-ID: <4BADDB80.90003@ieee.org> Andrej Mitrovic wrote: > On Mar 26, 9:18 am, "Alf P. Steinbach" wrote: > >> >> hierarchy =nspect.getclasstree( classes ) >> # 'hierarchy' is a list array of tuples and nested list arrays of the same form. >> # The top level is an array of two items, the first item a tuple describing the >> 'object' >> # class, and the second item a list array representing the BaseException hierarchy. >> print_hierarchy( hierarchy[1], level = ) >> >> >> Cheers & hth., >> >> - Alf >> > > Thanks for all of that. And yes, I've noticed I get into infinite > recursions all the time, which is why I was asking if there was a > simple way to do this. I'll have a look at these later. > > Kind regards, > Andrej Mitrovic > > I can't help with the original question, but generally the cure for getting into infinite recursion when traversing a tree with multiple connections is to keep a set() of all visited nodes. Whenever you hit a node a second time, don't visit it or its dependents. It's not hard to add to otherwise working code, and frequently the easiest place is right at the beginning of the recursive function. if new_node in myset: return myset.add(new_node) ...process_this_node... for child in new_node: ...recurse... HTH DaveA From v.harishankar at gmail.com Sat Mar 27 07:06:36 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 27 Mar 2010 11:06:36 +0000 (UTC) Subject: Any examples/documentation for python-newt Message-ID: I am writing a fairly featureful TUI in python and I figured newt is the best lightweight TUI which actually offers widgets. curses is low level and its text editing capabilities are poor while UIs like urwid and stfl too complex for simple programs like the ones I am creating. Could anybody point me to at least a decent example program in newt/snack and I don't mean popcorn.py or peanuts.py. Something that at least shows how to create a basic menu-driven program in the command line with a main menu and implementing several sub menus. Also a bit of explanation of the behaviour of OK and Cancel buttons in standard forms would be of help. So anybody uses newt? Or have people stopped using text based UIs completely? -- -- Harishankar (http://harishankar.org http://literaryforums.org) -- -- Harishankar (http://harishankar.org http://literaryforums.org) From tartley at tartley.com Sat Mar 27 07:28:56 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Sat, 27 Mar 2010 04:28:56 -0700 (PDT) Subject: Classes as namespaces? References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> Message-ID: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> On Mar 26, 6:26?pm, Luis M. Gonz?lez wrote: > On 26 mar, 11:49, kj wrote: > > > What's the word on using "classes as namespaces"? ?E.g. > > > class _cfg(object): > > ? ? spam = 1 > > ? ? jambon = 3 > > ? ? huevos = 2 > > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > I see no problem. > I wouldn't mix English, French and Spanish in the same recipe though... Hey everyone. By coincidence, only yesterday I was wondering about using classes as a way of labeling a block of code, ie. an lightweight alternative to defining a function that would only be called from one location. eg. instead of: x = 1 ((some complex logic)) y = 2 one might like to name the complex block of logic, just to make it readable: x = 1 def account_for_non_square_pixels(x): ((some complex logic)) account_for_non_square_pixels() y = 2 But defining and then calling the function like that is a tad cumbersome. So I was wondering about: x = 1 class account_for_non_square_pixels: ((some complex logic)) y = 2 I don't exactly like this, but I think you can see what I'm getting at. Does this fall down in some way I haven't grasped? Is it as awful an abuse of 'class' as my intuition suggests it is? Is there a way to do it better? From jcd at sdf.lonestar.org Sat Mar 27 07:54:06 2010 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sat, 27 Mar 2010 07:54:06 -0400 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <20100327115406.GA22246@sdf.lonestar.org> On Sat, Mar 27, 2010 at 04:28:56AM -0700, Jonathan Hartley wrote regarding Re: Classes as namespaces?: > > Hey everyone. By coincidence, only yesterday I was wondering about > using classes as a way of labeling a block of code, ie. an lightweight > alternative to defining a function that would only be called from one > location. > > eg. instead of: > > > x = 1 > ((some complex logic)) > y = 2 > > > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? Is it as awful > an abuse of 'class' as my intuition suggests it is? Is there a way to > do it better? > -- > http://mail.python.org/mailman/listinfo/python-list Hmm. I don't like that because it leaves a class polluting your namespace that doesn't behave like a class. Using a function for that purpose doesn't seem as bad, because even if you don't call it again, at least you *could*, and it would behave in an expected fashion. If you're dead-set against calling the chunk of code you just created, and you're using python 2.5 or higher, you might consider creating a no-op context manager: x = 1 with code_block("Account for non square pixels"): ((complex_logic)) y = 2 Though in general, I think refactoring your code to reasonably scoped functions or methods is a better idea. If it's too complex to read in one block, it's probably too complex for one function. From jeanmichel at sequans.com Sat Mar 27 07:54:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sat, 27 Mar 2010 12:54:42 +0100 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <4BADF202.3090704@sequans.com> Jonathan Hartley wrote: > On Mar 26, 6:26 pm, Luis M. Gonz?lez wrote: > >> On 26 mar, 11:49, kj wrote: >> >> >>> What's the word on using "classes as namespaces"? E.g. >>> >>> class _cfg(object): >>> spam = 1 >>> jambon = 3 >>> huevos = 2 >>> >>> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >>> >> I see no problem. >> I wouldn't mix English, French and Spanish in the same recipe though... >> > > > Hey everyone. By coincidence, only yesterday I was wondering about > using classes as a way of labeling a block of code, ie. an lightweight > alternative to defining a function that would only be called from one > location. > > eg. instead of: > > > x = 1 > ((some complex logic)) > y = 2 > > > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? Is it as awful > an abuse of 'class' as my intuition suggests it is? Is there a way to > do it better? > on good way to label part of the code is to simply add comments. You can also find tricks to indent this code block, but I've never seen that before. x=1 # account for non square pixels some complex logic # done y=2 I'm perfectly comfortable using classes for namespaces, 'cause classes implement objects or entities, and a namespaces can easily be designed as a coherent entity. For labelling code that you will not reuse, I'm not sure classes are suitable in the way people may issue a 'WTF' when reading your code. JM From jcd at sdf.lonestar.org Sat Mar 27 08:04:59 2010 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sat, 27 Mar 2010 08:04:59 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <20100327120458.GB22246@sdf.lonestar.org> On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes as namespaces?: > > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". Is there some problem that I'm > not seeing with this technique? > > ~K I don't see anything wrong with this, except that I would clean it up in a couple ways. Like other posters, I would give the class a proper class name (Cfg). I also would not assign integers to spam, jambon, or huevos. Instead I would assign each a bare object(). That way you won't get unexpected interactions with other constants outside the class. An object() is equal only to itself. I would also not rule out letting your "pseudo-namespace" grow into a full-fledged class. If you've got a method that makes sense with your class, use it. class Cfg(object): spam = object() jambon = object() huevos = object() def get_animal(self, meat): if meat == self.jambon: return 'pig' elif meat == self.huevos: return 'chicken' elif meat = self.spam: return 'spamalope' Later, perhaps, you might refactor so that each meat type (OK so huevos aren't a meat) gets its own subclass, with a simple, one-line get_animal method. Cheers, Cliff From steve at holdenweb.com Sat Mar 27 08:22:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Mar 2010 08:22:17 -0400 Subject: Classes as namespaces? In-Reply-To: <20100327120458.GB22246@sdf.lonestar.org> References: <20100327120458.GB22246@sdf.lonestar.org> Message-ID: J. Clifford Dyer wrote: > On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes > as namespaces?: >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): spam = 1 jambon = 3 huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> [...] > I also would not assign integers to spam, jambon, or huevos. Instead > I would assign each a bare object(). That way you won't get > unexpected interactions with other constants outside the class. An > object() is equal only to itself. > It also has the advantage (?) that you can use "is" (identity) comparisons rather than testing for equality, though this is only a readability issue, I suspect. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Sat Mar 27 08:42:07 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sat, 27 Mar 2010 13:42:07 +0100 Subject: Automatic import ? In-Reply-To: References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4BADFD1F.5000405@sequans.com> C. B. wrote: > [snip] > It takes time to write the relative importations, that's ok, but I > think it could be more pleasant for the end-user to not have to write > a huge list of "from mymodule import xxx" if it is possible to take > advantage of automatic importations. > > Cheers, > In that particular case, replace automatic by implicit, and you got the reason why it is not a good idea. Maybe in your case the C habits clashes to the python habits. Talking about python, if the user needs to know about BBB, then it has to import it, perdiod. If the user needs to know about many objects, then it has to import them all, explicitly. However it looks like all your objects belong to the same module, quoting MRAB: " Couldn't you just have: import mymodule as m and then use: m.AAA m.BBB " You don't like prefixing your object with the namespace they belong to ? Well, you should :o) JM PS : I would'n have renamed the module, but that falls into personal preferences. From ethan at stoneleaf.us Sat Mar 27 09:13:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 27 Mar 2010 06:13:01 -0700 Subject: Simple Traits Message-ID: <4BAE045D.3080604@stoneleaf.us> Wow. I just stumbled across one of Michele Simionato's offerings, called simple traits (strait for short) which looks *really* cool. You can find it here: http://pypi.python.org/pypi/strait/0.5.1 Extremely quick summary: Instead of multiple inheritance, with it's range of problems, use single inheritance for the basics, and include traits for various extra functionality that you want your class to have. As a side note, one of his blog entries at Artima talks about using composition instead of mixins when constructing a class, e.g. by doing: class foo(object): import baz def __init__(self): self.baz.do_something() which has the benefit (over mixins) of avoiding name-space pollution, as well as being able to tell where your methods are coming from. The cool thing (to me, at least) was the realization of being able to use import statements in class construction. Thanks, Michele!! ~Ethan~ From ethan at stoneleaf.us Sat Mar 27 09:19:02 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 27 Mar 2010 06:19:02 -0700 Subject: Simple Traits Questions Message-ID: <4BAE05C6.4070601@stoneleaf.us> Okay, different post for my actual questions. :) On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) it has the example of choosing which methods to keep in the composed class: class TOSWidget(BaseWidget): __metaclass__ = include(Pack, Place, Grid) info = Pack.info.im_func config = Pack.config.im_func configure = Pack.configure.im_func slaves = Pack.slaves.im_func forget = Pack.forget.im_func propagate = Pack.propagate.im_func My question is: Why use info = Pack.info.im_func instead of info = Pack.info ? Any and all enlightenment appreciated! ~Ethan~ From philip at semanchuk.com Sat Mar 27 09:26:40 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Mar 2010 09:26:40 -0400 Subject: Classes as namespaces? In-Reply-To: <20100327120458.GB22246@sdf.lonestar.org> References: <20100327120458.GB22246@sdf.lonestar.org> Message-ID: On Mar 27, 2010, at 8:04 AM, J. Clifford Dyer wrote: > On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes > as namespaces?: >> >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): >> spam = 1 >> jambon = 3 >> huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> >> >> Granted, this is not the "intended use" for classes, and therefore >> could be viewed as a misuse ("that's what dictionaries are for", >> etc.). But other than this somewhat academic objection[*], I really >> can see no problem with using classes in this way. >> >> And yet, I've come across online murky warnings against using >> classes as "pseudo-namespaces". Is there some problem that I'm >> not seeing with this technique? >> >> ~K > > I don't see anything wrong with this, except that I would clean it > up in a couple ways. Like other posters, I would give the class a > proper class name (Cfg). > > I also would not assign integers to spam, jambon, or huevos. > Instead I would assign each a bare object(). That way you won't get > unexpected interactions with other constants outside the class. An > object() is equal only to itself. What I like about this method is that it will break the bad habit I see in junior programmers of making assumptions about the value of the constant. For instance, if they see that Cfg.JAMBON = 3 and hardcode 3 in their code somewhere, that will work fine until someone re-orders the constants. Using object() instead forces them to use Cfg.JAMBON since the value will (probably) change with every run of the program. It will also discourage bugs-waiting-to-happen like this: if breakfast > Cfg.SPAM: print "Good news, breakfast is jambon or huevos" bye P From ethan at stoneleaf.us Sat Mar 27 09:34:45 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 27 Mar 2010 06:34:45 -0700 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <4BAE0975.1090004@stoneleaf.us> Jonathan Hartley wrote: > Hey everyone. By coincidence, only yesterday I was wondering about > using classes as a way of labeling a block of code, ie. an lightweight > alternative to defining a function that would only be called from one > location. > > eg. instead of: > > > x = 1 > ((some complex logic)) > y = 2 > > > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? Is it as awful > an abuse of 'class' as my intuition suggests it is? Is there a way to > do it better? Both solutions look horrible to me, as both hurt readability. Make your function somewhere else, then call it in the code. Who cares if you only use it once? x = 1 account_for_non_square_pixels() y = 2 Isn't that easier to read? And when you want to (read/change) the complex code, you have an easy place to go to do it. ~Ethan~ From jmheralds at gmail.com Sat Mar 27 09:37:26 2010 From: jmheralds at gmail.com (James Heralds) Date: Sat, 27 Mar 2010 06:37:26 -0700 (PDT) Subject: Call for papers (Deadline Extended): SETP-10, USA, July 2010 Message-ID: It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Call for papers (Deadline Extended): SETP-10, USA, July 2010 The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. ? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) ? International Conference on Automation, Robotics and Control Systems (ARCS-10) ? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) ? International Conference on Computer Communications and Networks (CCN-10) ? International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) ? International Conference on High Performance Computing Systems (HPCS-10) ? International Conference on Information Security and Privacy (ISP-10) ? International Conference on Image and Video Processing and Computer Vision (IVPCV-10) ? International Conference on Software Engineering Theory and Practice (SETP-10) ? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World? Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining ? all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. Sincerely James Heralds From invalid at invalid.invalid Sat Mar 27 10:44:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Mar 2010 14:44:23 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On 2010-03-27, Harishankar wrote: > I am writing a fairly featureful TUI in python and I figured newt is the > best lightweight TUI which actually offers widgets. curses is low level > and its text editing capabilities are poor while UIs like urwid and stfl > too complex for simple programs like the ones I am creating. > > Could anybody point me to at least a decent example program in newt/snack > and I don't mean popcorn.py or peanuts.py. Something that at least shows > how to create a basic menu-driven program in the command line with a main > menu and implementing several sub menus. Also a bit of explanation of the > behaviour of OK and Cancel buttons in standard forms would be of help. > > So anybody uses newt? Or have people stopped using text based UIs > completely? I've used it for some trivial stuff, but not for anything very sophisticated. Redhat's text-mode installer program (anaconda) was written in Python using Newt (I believe it is why Newt was invented). That's probably the most "full featured" example I know of. -- Grant From v.harishankar at gmail.com Sat Mar 27 10:49:37 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 27 Mar 2010 14:49:37 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On Sat, 27 Mar 2010 14:44:23 +0000, Grant Edwards wrote: > On 2010-03-27, Harishankar wrote: >> I am writing a fairly featureful TUI in python and I figured newt is >> the best lightweight TUI which actually offers widgets. curses is low >> level and its text editing capabilities are poor while UIs like urwid >> and stfl too complex for simple programs like the ones I am creating. >> >> Could anybody point me to at least a decent example program in >> newt/snack and I don't mean popcorn.py or peanuts.py. Something that at >> least shows how to create a basic menu-driven program in the command >> line with a main menu and implementing several sub menus. Also a bit of >> explanation of the behaviour of OK and Cancel buttons in standard forms >> would be of help. >> >> So anybody uses newt? Or have people stopped using text based UIs >> completely? > > I've used it for some trivial stuff, but not for anything very > sophisticated. Redhat's text-mode installer program (anaconda) was > written in Python using Newt (I believe it is why Newt was invented). > That's probably the most "full featured" example I know of. Does your code use forms in an application loop? I am having a bit of trouble with getting the form to stack up properly when I displaying another. As far as I know the two examples uses a single instance of a form which is discarded immediately on exit. If you have even a small code sample I wouldn't mind reading it! -- -- Harishankar (http://harishankar.org http://literaryforums.org) From invalid at invalid.invalid Sat Mar 27 10:56:30 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Mar 2010 14:56:30 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On 2010-03-27, Harishankar wrote: >> I've used it for some trivial stuff, but not for anything very >> sophisticated. Redhat's text-mode installer program (anaconda) was >> written in Python using Newt (I believe it is why Newt was invented). >> That's probably the most "full featured" example I know of. > > Does your code use forms in an application loop? Not really. It uses a series of forms. I don't think I ever stack forms. > I am having a bit of trouble with getting the form to stack up > properly when I displaying another. As far as I know the two examples > uses a single instance of a form which is discarded immediately on > exit. That's pretty much all my program did. > If you have even a small code sample I wouldn't mind reading it! I'm afraid I'm not at liberty to post it. -- Grant From aharrisreid at googlemail.com Sat Mar 27 11:08:09 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sat, 27 Mar 2010 15:08:09 +0000 Subject: Super() function In-Reply-To: <797c8cbd1003242042s32ee16bbxe6d937a16ab35a50@mail.gmail.com> References: <4BAAD5E0.9050604@googlemail.com> <797c8cbd1003242042s32ee16bbxe6d937a16ab35a50@mail.gmail.com> Message-ID: <4BAE1F59.4070800@googlemail.com> ?p wrote: > Hi: > > On 25 March 2010 11:17, Alan Harris-Reid > wrote: > > Hi, > > Using Python 3.1, I sometimes use the super() function to call the > equivalent method from a parent class, for example > > def mymethod(self): > super().mymethod() > some more code... > > Is there any way of writing the code so that the super() call is > generic and automatically recognises the name of the current > method (ie. something like super().thismethod()) or do I always > have to repeat the method name after super()? > > TIA, > Alan > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > I think, the super() method is designed to delegate any method call > to one of the class in its mro list, and the super() function its self > return a 'super' object, so it is better to write what method you want > to delegate, maybe it's not the current method. > > -- > Best wishes from Ray ... Thanks Ray - I'll stick to repeating the method name. Regards, Alan -------------- next part -------------- An HTML attachment was scrubbed... URL: From v.harishankar at gmail.com Sat Mar 27 11:12:57 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 27 Mar 2010 15:12:57 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On Sat, 27 Mar 2010 14:56:30 +0000, Grant Edwards wrote: > On 2010-03-27, Harishankar wrote: > >>> I've used it for some trivial stuff, but not for anything very >>> sophisticated. Redhat's text-mode installer program (anaconda) was >>> written in Python using Newt (I believe it is why Newt was invented). >>> That's probably the most "full featured" example I know of. >> >> Does your code use forms in an application loop? > > Not really. It uses a series of forms. I don't think I ever stack > forms. > >> I am having a bit of trouble with getting the form to stack up properly >> when I displaying another. As far as I know the two examples uses a >> single instance of a form which is discarded immediately on exit. > > That's pretty much all my program did. > >> If you have even a small code sample I wouldn't mind reading it! > > I'm afraid I'm not at liberty to post it. Thanks anyway. I'm taking a look at text.py in the anaconda source code tree here: http://git.fedorahosted.org/git/anaconda.git? p=anaconda.git;a=blob_plain;f=text.py;hb=HEAD I'm afraid it looks as though newt was primarily built to display a series of forms in order, like an installer does, so it is inherently limited by that interface. However, it might still be what I can use... -- Harishankar (http://harishankar.org http://literaryforums.org) From alain at dpt-info.u-strasbg.fr Sat Mar 27 11:17:46 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 27 Mar 2010 16:17:46 +0100 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> Message-ID: <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> Stephen Hansen writes: > Is it possible to get PIL to save GIF's in GIF89A format, instead of > GIF87A? GIF89 was patented. I guess that is why it isn't used by PIL. (The patent has expired now, IIRC.) Anyway, PNG was supposed to replace GIF. > If not, are there any decent other image libraries out there > that anyone's familiar with? The only one I could find was > PythonMagick, which seems completely undocumented. Or I'm blind. I don't know PythonMagick, but it is based on ImageMagick, which is kind of a swiss-knife in image manipulation and conversion. You could try the standalone tools first, to see if you get what you want/need. > But the problem is, I have a nice, small little 72 byte GIF89A file, > that I want to do some slight tweaking on and then re-save. I noticed > that even if I completely skipped the tweaking step and -just- saved, > it exploded into a 919 byte GIF87A file. And in this context, bytes > really, really matter. I picked GIF over PNG because the same file in > PNG was 120 bytes :) [...] >>>> f = open('../tiles/BaseTemplate.gif', 'rb') >>>> d1 = f.read() >>>> len(d1) > 73 >>>> d1 > 'GIF89a\x10\x00\x10\x00[...]' Hmm, a 16x16 image. Don't expect much from the most sophisticated formats (e.g, PNG), because their overhead (headers etc.) may well be above the size of the data. Compression isn't usually targeted at small files. (BTW: "slight tweaking" may have an effect on file-size if it introduces new colors, because GIF uses a color-table. I guess you know all this.) GIF uses the LZW algorithm, and so does zip and gzip (the latter with an additional layer of Huffmann coding). If your images are of fixed size, you _may_ be better off compressing the raw data with a general purpose compressor (i.e., gzip). Check the packages gzip and zlib. -- Alain. From vicente.soler at gmail.com Sat Mar 27 11:24:26 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 27 Mar 2010 08:24:26 -0700 (PDT) Subject: function decorator-like function Message-ID: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> Hi, Still learning Python, now decorators. Before diving deeply into decorators, I'd like to apply a function to another function. My "extremely simple function" should print number 3, then the sum of its 2 arguments. Say that I call f(5,7) I'd like to get, somehow, 3 then 12. I've tried the following: def d(f): print 3 return f def f(a, b): print a+b f=d(f) However, it does not work. Calling f(5,7) only returns 12, (3 is missing) How should I proceed? From pmaupin at gmail.com Sat Mar 27 12:06:40 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 27 Mar 2010 09:06:40 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> Message-ID: <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> On Mar 27, 10:24?am, vsoler wrote: > Hi, > > Still learning Python, now decorators. > > Before diving deeply into decorators, I'd like to apply a function to > another function. > > My "extremely simple function" should print number 3, then the sum of > its 2 arguments. > > Say that I call ? f(5,7) > I'd like to get, somehow, 3 then 12. > > I've tried the following: > > def d(f): > ? ? print 3 > ? ? return f > > def f(a, b): > ? ? print a+b > > f=d(f) > > However, it does not work. Calling f(5,7) only returns 12, (3 is > missing) > How should I proceed? >>> def d(f): ... def wrapper(*args): ... print 3 ... return f(*args) ... return wrapper ... >>> def f(a, b): ... print a + b ... >>> f = d(f) >>> f(5, 7) 3 12 HTH, Pat From lkizer at cfl.rr.com Sat Mar 27 12:21:02 2010 From: lkizer at cfl.rr.com (Larry Kizer) Date: Sat, 27 Mar 2010 12:21:02 -0400 Subject: Ipython(x,y) Won't Run Message-ID: <4bae3040$0$5117$9a6e19ea@unlimited.newshosting.com> I uninstalled my previous version of Python and installed Python(x,y) ver 2.6.2.0 in Windows XP - Install seemed to work fine but when I try to run Ipython(x,y) I get the following error: python.exe has encountered a problem and needs to close. We are sorry for the inconvenience. Any ideas? Thanks. LK From vicente.soler at gmail.com Sat Mar 27 12:21:06 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 27 Mar 2010 09:21:06 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> Message-ID: On 27 mar, 17:06, Patrick Maupin wrote: > On Mar 27, 10:24?am, vsoler wrote: > > > > > Hi, > > > Still learning Python, now decorators. > > > Before diving deeply into decorators, I'd like to apply a function to > > another function. > > > My "extremely simple function" should print number 3, then the sum of > > its 2 arguments. > > > Say that I call ? f(5,7) > > I'd like to get, somehow, 3 then 12. > > > I've tried the following: > > > def d(f): > > ? ? print 3 > > ? ? return f > > > def f(a, b): > > ? ? print a+b > > > f=d(f) > > > However, it does not work. Calling f(5,7) only returns 12, (3 is > > missing) > > How should I proceed? > >>> def d(f): > > ... ? ? def wrapper(*args): > ... ? ? ? ? print 3 > ... ? ? ? ? return f(*args) > ... ? ? return wrapper > ...>>> def f(a, b): > > ... ? ? print a + b > ...>>> f = d(f) > >>> f(5, 7) > > 3 > 12 > > HTH, > Pat Pat, I think some lines are missing. I don't see "d" function defined. Any lines above def wrapper? Thank you From vicente.soler at gmail.com Sat Mar 27 12:24:51 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 27 Mar 2010 09:24:51 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> Message-ID: On 27 mar, 17:21, vsoler wrote: > On 27 mar, 17:06, Patrick Maupin wrote: > > > > > On Mar 27, 10:24?am, vsoler wrote: > > > > Hi, > > > > Still learning Python, now decorators. > > > > Before diving deeply into decorators, I'd like to apply a function to > > > another function. > > > > My "extremely simple function" should print number 3, then the sum of > > > its 2 arguments. > > > > Say that I call ? f(5,7) > > > I'd like to get, somehow, 3 then 12. > > > > I've tried the following: > > > > def d(f): > > > ? ? print 3 > > > ? ? return f > > > > def f(a, b): > > > ? ? print a+b > > > > f=d(f) > > > > However, it does not work. Calling f(5,7) only returns 12, (3 is > > > missing) > > > How should I proceed? > > >>> def d(f): > > > ... ? ? def wrapper(*args): > > ... ? ? ? ? print 3 > > ... ? ? ? ? return f(*args) > > ... ? ? return wrapper > > ...>>> def f(a, b): > > > ... ? ? print a + b > > ...>>> f = d(f) > > >>> f(5, 7) > > > 3 > > 12 > > > HTH, > > Pat > > Pat, > > I think some lines are missing. I don't see "d" function defined. Any > lines above def wrapper? > > Thank you Patrick, I see what happened. The first line was somehow hidden. Thank you very much. Vicente Soler From aharrisreid at googlemail.com Sat Mar 27 12:43:11 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sat, 27 Mar 2010 16:43:11 +0000 Subject: Super() function In-Reply-To: References: <4BAAD5E0.9050604@googlemail.com> Message-ID: <4BAE359F.6090200@googlemail.com> Gabriel Genellina wrote: >
En Thu, 25 Mar 2010 00:17:52 -0300, Alan > Harris-Reid escribi?: > >> Using Python 3.1, I sometimes use the super() function to call the >> equivalent method from a parent class, for example >> >> def mymethod(self): >> super().mymethod() >> some more code... >> >> Is there any way of writing the code so that the super() call is >> generic and automatically recognises the name of the current method >> (ie. something like super().thismethod()) or do I always have to >> repeat the method name after super()? > > This recipe does what you want: > http://code.activestate.com/recipes/286195-selfsuper/ > (but requires a bit of black magic...) > Hi Gabriel - thanks for the reply. Goodness me - that's a mighty complicated recipe for what I want to achieve! I think I'll stick with repeating the method name - it's a small price to pay. Regards, Alan From james.harris.1 at googlemail.com Sat Mar 27 13:01:34 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sat, 27 Mar 2010 10:01:34 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: <929d4c9a-ec2d-4b21-ac10-9ae099c040b0@q21g2000yqm.googlegroups.com> On 26 Mar, 14:58, Jon Clements wrote: > On 26 Mar, 09:49, James Harris wrote: ... > > I'm toying with some > > ideas for a way to help generate source code (in various languages, > > not just Python). If it goes ahead the text files would be mainly > > marked-up code snippets - with or without symbols that need to be > > replaced. > > > Rather than write one single monolithic app I thought to split it into > > reusable components. One part being data access could perhaps be an > > existing database (and I'll take a look at jkn's suggestion). > > > Think of the database as similar to an associative array stored on > > disk. The only difference is I may want to play fast and loose with > > the keys in some ways - e.g. check for partial key matches or return a > > list of part-matched keys. The language name could be part of the key > > but I'd also need to store variants for specific language versions. > > I'm not sure yet how it will all pan out. As I say, just throwing > > around some ideas. ... > Thanks for the explanation. No problem. Thanks for taking an interest! > Who admins and, who's editing this data? For the app I have in mind a programmer would admin and edit the files. > I couldn't 100% guarantee that I could modify a text file and always > put the right > delimiter in the right place and remember to escape the relevant chars > (and I'm > probably not the 'average' user). Apart from any markup each file would be just source code or, maybe, individual fragments of source code so there would be few delimiters to get right. And any that were wrong could be detected either by the code writer or the compiler when used. > Any opposition to just putting it in a 'proper' DB, then 'blobbing' > the values? > (or just integrate a procedure/script/function whatever your chosen > RDBMS calls to choose it). > Or in some systems, 'externally referencing'... loads of DB's have > free front-ends, > and there are lots of Python libraries. I've thought of that. Like Ethan, though, I'd prefer simple text for this. Databases, for good reasons, tend to obscure text. For one thing it makes them more secure but it also makes them less transparent and harder to examine and edit. For this app simple text files seem to be the best option at the moment. > > I think perhaps, all I'm saying is, I'd choose a different approach. > I'd provide a front-end, rather than choose to re-write the wheel over > DB's. Agreed. That was my reason for asking the question initially. > Be nice to know how you get on, if you'd be so kind? I don't know yet if it will be feasible but if I do eventually write something I'll report back. James From tjreedy at udel.edu Sat Mar 27 13:10:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Mar 2010 13:10:22 -0400 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: On 3/27/2010 7:28 AM, Jonathan Hartley wrote: > On Mar 26, 6:26 pm, Luis M. Gonz?lez wrote: > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? The assignments within the class are performed within a new local namespace. So moving non-toy code within a class block will typically fail. From pmaupin at gmail.com Sat Mar 27 14:07:47 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 27 Mar 2010 11:07:47 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> Message-ID: <40ba11d3-5a18-4da4-a48a-0dd815f3b459@35g2000yqm.googlegroups.com> On Mar 27, 11:24?am, vsoler wrote: > I see what happened. The first line was somehow hidden. > Thank you very much. You're welcome. Sorry about the formatting. Also, note that if your decorator is complicated, you might want to use a class instead of a nested function. Here's the same thing, using a class (and using the actual decorator syntax): class d(object): def __init__(self, func): self.func = func def __call__(self, *args): print 3 return self.func(*args) @d def f(a, b): print a + b f(5, 7) Pat From pmaupin at gmail.com Sat Mar 27 14:22:09 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 27 Mar 2010 11:22:09 -0700 (PDT) Subject: Classes as namespaces? References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <8db24743-f293-4f87-b2fa-d86291de2f86@j21g2000yqh.googlegroups.com> On Mar 27, 12:10?pm, Terry Reedy wrote: > On 3/27/2010 7:28 AM, Jonathan Hartley wrote: > > > On Mar 26, 6:26 pm, Luis M. Gonz?lez ?wrote: > > But defining and then calling the function like that is a tad > > cumbersome. So I was wondering about: > > > x = 1 > > class account_for_non_square_pixels: > > ? ?((some complex logic)) > > y = 2 > The assignments within the class are performed within > a new local namespace. I could be misunderstanding, but I think that may be the point. When you have what is basically a bunch of linear logic in Python, sometimes it makes sense to break the logic up into separate namespaces, such that you don't pollute the global namespace too badly (which could cause obscure failures due to inadvertently reusing a variable name which is not properly initialized on the second use). As the OP mentioned, functions are typically used for this, but then you have to decide if you are going to put all your functions above all the rest of the code, or in-line, which is where they belong according to the flow. Either decision has drawbacks -- it is jarring to see functions defined in the middle of a code flow, but it requires extra work to page up and down to see code that is logically in the middle of a code flow, but has been moved out to a sub-function somewhere. > So moving non-toy code within a class block > will typically fail. I think, as with moving non-toy code into a function, the point may be to *force* (more obvious) failures when something is screwed up, rather than allowing the silent failures that can easily occur with a large number of only marginally related variables in one big namespace. I have done what (I think) the OP is suggesting in the distant past. I don't know why I don't do it any more -- perhaps it is more of a comfort thing, or maybe I have gotten better at choosing the right abstraction points for the function boundaries so that I don't always need to read the function code when I am reading the code that invokes it. But in any case, I don't personally think that: a = 27 b = 30 class DoMoreComputation: c = a + b d = DoMoreComputation.c is a terrible, ugly thing, although it is not my current preference. Regards, Pat From andrej.mitrovich at gmail.com Sat Mar 27 15:29:39 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sat, 27 Mar 2010 12:29:39 -0700 (PDT) Subject: Vertical line in function arguments Message-ID: <3d96ca83-7741-483d-8449-d88dc0f445b7@y17g2000yqd.googlegroups.com> There is this peace of code in a 3rd party module: MidiIn.SetFilter(pypm.FILT_ACTIVE | pypm.FILT_CLOCK | pypm.FILT_PITCHBEND | pypm.FILT_NOTE) What are the vertical lines in a function call such as this? This actually calls a function from a Pyrex module that was compiled into a .pyd. Those filters are hex constants, but I've no idea what these vertical lines mean. Is this some form of binary "or" operation? From andrej.mitrovich at gmail.com Sat Mar 27 15:30:53 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sat, 27 Mar 2010 12:30:53 -0700 (PDT) Subject: Vertical line in function arguments References: <3d96ca83-7741-483d-8449-d88dc0f445b7@y17g2000yqd.googlegroups.com> Message-ID: <150eb50d-6117-426b-a014-e6b1662a867e@19g2000yqu.googlegroups.com> Well I hate it when this happens. I ask a question, and literally 2 seconds later I bump into the answer. This explains it a bit: http://docs.python.org/library/stdtypes.html#bit-string-operations-on-integer-types From lie.1296 at gmail.com Sat Mar 27 15:48:21 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 28 Mar 2010 06:48:21 +1100 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4bae6130$1@dnews.tpgi.com.au> On 03/22/2010 07:07 PM, Steven D'Aprano wrote: > Perhaps you should have said that it was a wrapper around deque giving > richer functionality, rather than giving the impression that it was a > brand new data structure invented by you. People are naturally going to > be more skeptical about a newly invented data structure than one based on > a reliable, component like deque. Well, technically StringChain is not a data structure in the first place. StringChain is a string; a string that is implemented using deque data structure to make appending algorithmically efficient. It is not a data structure, in the sense that I can't put arbitrary "thing" into the data structure. In the same sense, "string" is also not a data structure as "string" is an implementation of stream using "array" data structure; "StringChain" is an implementation of stream using "deque" data structure. From jenjenmu at gmail.com Sat Mar 27 17:14:31 2010 From: jenjenmu at gmail.com (knobbyknees) Date: Sat, 27 Mar 2010 14:14:31 -0700 (PDT) Subject: Python Psycopg2 - Interface Error : Connection already closed Message-ID: I'm not sure if this is the right group, but I'm hoping it is... Basically, I'm trying to use pgloader, which depends on python and psycopg2. After banging my head against a wall, I found this: Found this: http://www.mail-archive.com/sqlalchemy at googlegroups.com/msg13209.html Although, the suggestion didn't work for me at all... Running this command: /usr/bin/pgloader -c /var/mybin/pgconfs/fr.conf Yields this in the pgloader.log (with the process just hanging) more /tmp/pgloader.log 27-03-2010 12:22:53 pgloader INFO Logger initialized 27-03-2010 12:22:53 pgloader INFO Reformat path is ['/usr/ share/python-support/pgloader/reformat'] 27-03-2010 12:22:53 pgloader INFO Will consider following sections: 27-03-2010 12:22:53 pgloader INFO fixed 27-03-2010 12:22:54 fixed INFO fixed processing 27-03-2010 12:22:54 pgloader INFO All threads are started, wait for them to terminate 27-03-2010 12:22:57 fixed ERROR connection already closed 27-03-2010 12:22:57 fixed INFO closing current database connection [pgsql] host = localhost port = 5432 base = frdb user = username pass = password [fixed] table = fr format = fixed filename = /var/www/fr.txt ... This is what I see for the traceback: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 847, in run self.terminate() File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 874, in terminate self.db.close() File "/usr/lib/pymodules/python2.6/pgloader/db.py", line 103, in close self.dbconn.close() I'm at a total loss here.... Can anyone please help me out? From nocbos at gmail.com Sat Mar 27 18:39:23 2010 From: nocbos at gmail.com (C. B.) Date: Sat, 27 Mar 2010 15:39:23 -0700 (PDT) Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <23f6145e-c44d-4d37-8e5e-a98636d4d452@i25g2000yqm.googlegroups.com> > In that particular case, replace automatic by implicit, and you got the > reason why it is not a good idea. > Maybe in your case the C habits clashes to the python habits. > You're right ! As a C developer, I appreciate to only include to deal with strings, without wondering which other header provides size_t definition. > Talking about python, if the user needs to know about BBB, then it has > to import it, perdiod. If the user needs to know about many objects, > then it has to import them all, explicitly. Ok. If this is the Python way of coding, that's ok for me. I will stop now my quest for an automatic import and work like that. The most interesting solution I have found until now is using PyImport_AppendInittab() and PyEval_GetGlobals() functions. But this also brings lots of problems (mainly namespaces and unloading). Anyway, the time spent to look for a solution was a nice way to learn Python internals :) Cheers, From saimapk81 at gmail.com Sat Mar 27 18:51:43 2010 From: saimapk81 at gmail.com (saima81) Date: Sat, 27 Mar 2010 15:51:43 -0700 (PDT) Subject: "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ Message-ID: <7fce4205-a64f-46dd-8066-cdfd45400183@a16g2000pre.googlegroups.com> "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ From greg.ewing at canterbury.ac.nz Sat Mar 27 18:56:21 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Mar 2010 10:56:21 +1200 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <817g5kFb3mU1@mid.individual.net> Jonathan Hartley wrote: > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > class account_for_non_square_pixels: > ((some complex logic)) I don't see much advantage -- you're still leaving behind an object that won't be used again. If you're concerned about namespace pollution, there are a couple of ways to clean it up: 1) Delete the function after using it: def account_for_non_square_pixels(x): ... account_for_non_square_pixels() del account_for_non_square_pixels 2) Use __all__ to specify which names you intend to export (doesn't prevent anyone from importing something explicitly, but at least it makes your intention clear, stops irrelevant things appearing in dir() or help(), etc). -- Greg From greg.ewing at canterbury.ac.nz Sat Mar 27 19:40:07 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Mar 2010 11:40:07 +1200 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <817inlFoj9U1@mid.individual.net> kj wrote: > What's the word on using "classes as namespaces"? My only concern would be that classes do magical things with certain types when you retrieve them as attributes (e.g. functions, property descriptors), so you can't use one as a completely general purpose transparent container. But for enum constants and the like this isn't a problem. If you're up for a bit of hackery, the following code tricks the class statement into producing a module instead of a class: from types import ModuleType class MetaNamespace(ModuleType): def __init__(self, name, bases, dict): ModuleType.__init__(self, name) self.__file__ = __file__ self.__dict__.update(dict) Namespace = MetaNamespace.__new__(MetaNamespace) class Foo(Namespace): ford = 42 arthur = 88 print Foo print Foo.__dict__ -- Greg From robert.kern at gmail.com Sat Mar 27 20:23:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Mar 2010 19:23:51 -0500 Subject: Simple Traits Questions In-Reply-To: <4BAE05C6.4070601@stoneleaf.us> References: <4BAE05C6.4070601@stoneleaf.us> Message-ID: On 2010-03-27 08:19 , Ethan Furman wrote: > Okay, different post for my actual questions. :) > > On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) > it has the example of choosing which methods to keep in the composed class: > > class TOSWidget(BaseWidget): > __metaclass__ = include(Pack, Place, Grid) > info = Pack.info.im_func > config = Pack.config.im_func > configure = Pack.configure.im_func > slaves = Pack.slaves.im_func > forget = Pack.forget.im_func > propagate = Pack.propagate.im_func > > My question is: > > Why use > > info = Pack.info.im_func > > instead of > > info = Pack.info > > ? Pack.info is an unbound method object attached to the Pack class, not a function object. It has some extra semantics on top of functions and is tied to the Pack class. The .im_func attribute gets the actual function object underneath. When defining the TOSWidget class, the objects defined in the suite under the class: statement need to be actual functions in order to be turned into unbound methods attached to the TOSWidget class. -- 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 From robert.kern at gmail.com Sat Mar 27 20:25:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Mar 2010 19:25:23 -0500 Subject: Ipython(x,y) Won't Run In-Reply-To: <4bae3040$0$5117$9a6e19ea@unlimited.newshosting.com> References: <4bae3040$0$5117$9a6e19ea@unlimited.newshosting.com> Message-ID: On 2010-03-27 11:21 , Larry Kizer wrote: > I uninstalled my previous version of Python and installed Python(x,y) > ver 2.6.2.0 in Windows XP - Install seemed to work fine but when I try to > run > Ipython(x,y) I get the following error: python.exe has encountered a > problem and needs to close. We are sorry for the inconvenience. > Any ideas? Thanks. You will want to report Python(x,y) bugs here: http://www.pythonxy.com/ -- 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 From apt.shansen at gmail.invalid Sat Mar 27 22:44:54 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Sat, 27 Mar 2010 19:44:54 -0700 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> Message-ID: <2010032719445464825-aptshansen@gmailinvalid> On 2010-03-27 08:17:46 -0700, Alain Ketterlin said: > Stephen Hansen writes: >> If not, are there any decent other image libraries out there >> that anyone's familiar with? The only one I could find was >> PythonMagick, which seems completely undocumented. Or I'm blind. > > I don't know PythonMagick, but it is based on ImageMagick, which is kind > of a swiss-knife in image manipulation and conversion. You could try the > standalone tools first, to see if you get what you want/need. Well, I know it -can- do what I need, except the subprocess business isn't something I want to deal with. And the library seems utterly undocumented. :( > Hmm, a 16x16 image. Don't expect much from the most sophisticated > formats (e.g, PNG), because their overhead (headers etc.) may well be > above the size of the data. Compression isn't usually targeted at small > files. Yeah, I don't expect much from PNG. The images are very small but I might be sending a LOT of them over a pipe which is fairly tight, so 50-60 bytes matters. That's why I selected GIF. > (BTW: "slight tweaking" may have an effect on file-size if it introduces > new colors, because GIF uses a color-table. I guess you know all this.) Yeah, I know this is possible, which is why the tweaking was to be very careful: these images all have only a couple indexed colors each, and I should be able to do the tweaks and not increase the size excessively. However, the problem is: I left out all the tweaks and it still exploded in size. Just opening, and then saving the same file with no changes at all, resulted in a 72 byte file growing to 920. I thought it was GIF87a vs GIF89a... but have since come to determine it doesn't appear to be. I decided to give PNG a try again, since those extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better then 900. Unfortunately, I hit the same wall there. If I convert these itty-bitty images into PNG, they're about 120 bytes or so. Opening one in PNG, making no changes, and saving, results in the new file being 900 bytes too :( So I wonder if there's just some hyper-optimization Photoshop does that PIL can't round-trip. > GIF uses the LZW algorithm, and so does zip and gzip (the latter with an > additional layer of Huffmann coding). If your images are of fixed size, > you _may_ be better off compressing the raw data with a general purpose > compressor (i.e., gzip). Check the packages gzip and zlib. Hm. I hadn't thought of compressing the saved version. I could do that, I suppose: it just seems there is so much extra stuff which shouldn't be needed that's being saved out. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From v.harishankar at gmail.com Sat Mar 27 23:32:16 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 28 Mar 2010 03:32:16 +0000 (UTC) Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: On Sat, 27 Mar 2010 19:44:54 -0700, Stephen Hansen wrote: > On 2010-03-27 08:17:46 -0700, Alain Ketterlin said: > >> Stephen Hansen writes: > >>> If not, are there any decent other image libraries out there that >>> anyone's familiar with? The only one I could find was PythonMagick, >>> which seems completely undocumented. Or I'm blind. >> >> I don't know PythonMagick, but it is based on ImageMagick, which is >> kind of a swiss-knife in image manipulation and conversion. You could >> try the standalone tools first, to see if you get what you want/need. > > Well, I know it -can- do what I need, except the subprocess business > isn't something I want to deal with. And the library seems utterly > undocumented. :( > >> Hmm, a 16x16 image. Don't expect much from the most sophisticated >> formats (e.g, PNG), because their overhead (headers etc.) may well be >> above the size of the data. Compression isn't usually targeted at small >> files. > > Yeah, I don't expect much from PNG. The images are very small but I > might be sending a LOT of them over a pipe which is fairly tight, so > 50-60 bytes matters. That's why I selected GIF. > >> (BTW: "slight tweaking" may have an effect on file-size if it >> introduces new colors, because GIF uses a color-table. I guess you know >> all this.) > > Yeah, I know this is possible, which is why the tweaking was to be very > careful: these images all have only a couple indexed colors each, and I > should be able to do the tweaks and not increase the size excessively. > > However, the problem is: I left out all the tweaks and it still exploded > in size. > > Just opening, and then saving the same file with no changes at all, > resulted in a 72 byte file growing to 920. > > I thought it was GIF87a vs GIF89a... but have since come to determine it > doesn't appear to be. I decided to give PNG a try again, since those > extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better > then 900. Unfortunately, I hit the same wall there. > > If I convert these itty-bitty images into PNG, they're about 120 bytes > or so. Opening one in PNG, making no changes, and saving, results in the > new file being 900 bytes too :( > > So I wonder if there's just some hyper-optimization Photoshop does that > PIL can't round-trip. > >> GIF uses the LZW algorithm, and so does zip and gzip (the latter with >> an additional layer of Huffmann coding). If your images are of fixed >> size, you _may_ be better off compressing the raw data with a general >> purpose compressor (i.e., gzip). Check the packages gzip and zlib. > > Hm. I hadn't thought of compressing the saved version. I could do that, > I suppose: it just seems there is so much extra stuff which shouldn't be > needed that's being saved out. This might not be of much use to you, but I've found by experience that PNGs are almost always bigger or equal to GIFs of the same resolution, colour depth and so on. I've never yet seen a PNG file that is smaller than a GIF for the same set of pixels. As mentioned above, compressing raw data stream might be more beneficial in this situation. Also try the pngcrush utility and see what size it gives you. http://pmt.sourceforge.net/pngcrush/ -- Harishankar (http://harishankar.org http://literaryforums.org) From apt.shansen at gmail.invalid Sun Mar 28 00:31:16 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Sat, 27 Mar 2010 21:31:16 -0700 Subject: Classes as namespaces? References: Message-ID: <2010032721311671584-aptshansen@gmailinvalid> On 2010-03-26 07:49:02 -0700, kj said: > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. On the contrary, this is the intended use of classes. Or at least, one of them. A class *is* a namespace, albeit one that you must address explicitly unlike the local and global namespaces which are usually implicit. That said... > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one > ("the 'intended use' for triple-quoting is not to comment out code", > etc.). Here I find myself on the opposite side of the purist/pragmatic > divide. Hmmm. What?! Where do you get this "widespread practice"? You mentioned that before when you last posted about that and I forgot to comment. I've never seen it. In the 110k lines of in-house code I maintain, we don't use it once; we have somewhere around 300k lines of third-party code from a wide range of sources, and although I haven't reviewed it all by any means, I regularly have to peek over it and I never seen triple quoted "comments". Hell, I almost never see commented -code-. Code should only be commented while fiddling or debugging. Once fiddlng is done, dead code should be removed. I'm sure it -happens- every once in awhile, but.. why? Who uses editors that can't block comment/uncomment anymore? :( -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From sccolbert at gmail.com Sun Mar 28 01:21:18 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 28 Mar 2010 01:21:18 -0400 Subject: GIF89A and PIL In-Reply-To: References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: <7f014ea61003272221t15e84931hf56411ecd00a1cb5@mail.gmail.com> since the images only use a couple colors each, just run length encode it. Depending on the image, you may be able to get a super small size that way, and avoid the whole mess. On Sat, Mar 27, 2010 at 11:32 PM, Harishankar wrote: > On Sat, 27 Mar 2010 19:44:54 -0700, Stephen Hansen wrote: > > > On 2010-03-27 08:17:46 -0700, Alain Ketterlin said: > > > >> Stephen Hansen writes: > > > >>> If not, are there any decent other image libraries out there that > >>> anyone's familiar with? The only one I could find was PythonMagick, > >>> which seems completely undocumented. Or I'm blind. > >> > >> I don't know PythonMagick, but it is based on ImageMagick, which is > >> kind of a swiss-knife in image manipulation and conversion. You could > >> try the standalone tools first, to see if you get what you want/need. > > > > Well, I know it -can- do what I need, except the subprocess business > > isn't something I want to deal with. And the library seems utterly > > undocumented. :( > > > >> Hmm, a 16x16 image. Don't expect much from the most sophisticated > >> formats (e.g, PNG), because their overhead (headers etc.) may well be > >> above the size of the data. Compression isn't usually targeted at small > >> files. > > > > Yeah, I don't expect much from PNG. The images are very small but I > > might be sending a LOT of them over a pipe which is fairly tight, so > > 50-60 bytes matters. That's why I selected GIF. > > > >> (BTW: "slight tweaking" may have an effect on file-size if it > >> introduces new colors, because GIF uses a color-table. I guess you know > >> all this.) > > > > Yeah, I know this is possible, which is why the tweaking was to be very > > careful: these images all have only a couple indexed colors each, and I > > should be able to do the tweaks and not increase the size excessively. > > > > However, the problem is: I left out all the tweaks and it still exploded > > in size. > > > > Just opening, and then saving the same file with no changes at all, > > resulted in a 72 byte file growing to 920. > > > > I thought it was GIF87a vs GIF89a... but have since come to determine it > > doesn't appear to be. I decided to give PNG a try again, since those > > extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better > > then 900. Unfortunately, I hit the same wall there. > > > > If I convert these itty-bitty images into PNG, they're about 120 bytes > > or so. Opening one in PNG, making no changes, and saving, results in the > > new file being 900 bytes too :( > > > > So I wonder if there's just some hyper-optimization Photoshop does that > > PIL can't round-trip. > > > >> GIF uses the LZW algorithm, and so does zip and gzip (the latter with > >> an additional layer of Huffmann coding). If your images are of fixed > >> size, you _may_ be better off compressing the raw data with a general > >> purpose compressor (i.e., gzip). Check the packages gzip and zlib. > > > > Hm. I hadn't thought of compressing the saved version. I could do that, > > I suppose: it just seems there is so much extra stuff which shouldn't be > > needed that's being saved out. > > This might not be of much use to you, but I've found by experience that > PNGs are almost always bigger or equal to GIFs of the same resolution, > colour depth and so on. I've never yet seen a PNG file that is smaller > than a GIF for the same set of pixels. > > As mentioned above, compressing raw data stream might be more beneficial > in this situation. > > Also try the pngcrush utility and see what size it gives you. > http://pmt.sourceforge.net/pngcrush/ > > -- > Harishankar (http://harishankar.org http://literaryforums.org) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Sun Mar 28 02:36:40 2010 From: python at rcn.com (Raymond Hettinger) Date: Sat, 27 Mar 2010 23:36:40 -0700 (PDT) Subject: Classes as namespaces? References: Message-ID: <03b4f91e-39aa-4b97-a510-fa784ad906f6@u5g2000prd.googlegroups.com> On Mar 26, 7:49?am, kj wrote: > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ? spam = 1 > ? ? jambon = 3 > ? ? huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Works for me. Raymond From catalinfest at gmail.com Sun Mar 28 02:59:05 2010 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Sat, 27 Mar 2010 23:59:05 -0700 (PDT) Subject: Encryption source code with md5 Message-ID: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Dear friends . I have two simple questions: It is possible to encrypt with md5 python source code? What option do I have to protect my python source code? Thank you . From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Mar 28 03:22:11 2010 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 28 Mar 2010 07:22:11 +0000 (UTC) Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: Harishankar wrote: > >> Just opening, and then saving the same file with no changes at all, >> resulted in a 72 byte file growing to 920. >> >> I thought it was GIF87a vs GIF89a... but have since come to determine it >> doesn't appear to be. I decided to give PNG a try again, since those >> extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better >> then 900. Unfortunately, I hit the same wall there. >> > Also try the pngcrush utility and see what size it gives you. > http://pmt.sourceforge.net/pngcrush/ > optipng gives slightly better results. Anyway, depending on your pictures, you might find out that using *.ppm.gz, *.pgm.gz or *.pbm.gz outperforms both optimised gif ad png... and if sending more pictures down the line, tar-ing them (*.p?m) and compressing the result will give even better sizes. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From agoretoy at gmail.com Sun Mar 28 04:15:22 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 28 Mar 2010 02:15:22 -0600 Subject: Encryption source code with md5 In-Reply-To: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: There's not many options when it comes to obfuscating python source. If you even do find a way to obfuscate it. It won't take much to reverse it. That's just how python works. Really I wouldn't even worry about looking for a way to do this, reason behind that is that it's not difficult to reverse it. This is not c,c++, php or java man/woman. Good luck. Thank you, -Alex Goretoy http://launchpad.net/~a1g On Sun, Mar 28, 2010 at 12:59 AM, catalinfest at gmail.com < catalinfest at gmail.com> wrote: > Dear friends . > > I have two simple questions: > It is possible to encrypt with md5 python source code? > What option do I have to protect my python source code? > > Thank you . > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From starglider.dev at gmail.com Sun Mar 28 06:02:03 2010 From: starglider.dev at gmail.com (starglider develop) Date: Sun, 28 Mar 2010 11:02:03 +0100 Subject: Encryption source code with md5 In-Reply-To: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: py2exe On 28 March 2010 07:59, catalinfest at gmail.com wrote: > Dear friends . > > I have two simple questions: > It is possible to encrypt with md5 python source code? > What option do I have to protect my python source code? > > Thank you . > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Sun Mar 28 06:08:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 28 Mar 2010 23:08:22 +1300 Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: In message <91541c26-6f18-40c7- a0df-252a52bb7cd5 at l25g2000yqd.googlegroups.com>, catalinfest at gmail.com wrote: > It is possible to encrypt with md5 python source code? Don?t use MD5. > What option do I have to protect my python source code? Copyright. From news1234 at free.fr Sun Mar 28 06:25:36 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Mar 2010 12:25:36 +0200 Subject: Classes as namespaces? In-Reply-To: <2010032721311671584-aptshansen@gmailinvalid> References: <2010032721311671584-aptshansen@gmailinvalid> Message-ID: <4baf2ea0$0$4595$426a74cc@news.free.fr> Hi STephen, Stephen Hansen wrote: > That said... > >> [*] My own subjective dislike for the widespread practice of using >> triple quotes to comment out code is formally similar to this one >> ("the 'intended use' for triple-quoting is not to comment out code", >> etc.). Here I find myself on the opposite side of the purist/pragmatic >> divide. Hmmm. > > What?! > > Where do you get this "widespread practice"? You mentioned that before > when you last posted about that and I forgot to comment. I've never seen > it. I wouldn't say it's wide spread, but definitely something one encounters. Especially with python rather new to python > > In the 110k lines of in-house code I maintain, we don't use it once; we > have somewhere around 300k lines of third-party code from a wide range > of sources, and although I haven't reviewed it all by any means, I > regularly have to peek over it and I never seen triple quoted "comments". > > Hell, I almost never see commented -code-. Code should only be commented > while fiddling or debugging. Once fiddlng is done, dead code should be > removed. > > I'm sure it -happens- every once in awhile, but.. why? Who uses editors > that can't block comment/uncomment anymore? :( I had to explain block comment / uncomment to some collegues before the triple quote commenting disappeared from our code. Unfortunaltely everybody uses a different type of editor, so I googled for them to show them what their editors can do. You'd be surprised how many people do neither master their editors nor care for it. bye N From python at bdurham.com Sun Mar 28 06:48:52 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 28 Mar 2010 06:48:52 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: References: <1269447436.19612.1366507993@webmail.messagingengine.com><1269453527.7192.1366528303@webmail.messagingengine.com> Message-ID: <1269773332.19498.1367099243@webmail.messagingengine.com> Gabriel, Thank you for your analysis - very interesting. Enjoyed your fromlist choice of names. I'm still in my honeymoon phase with Python so I only know the first part :) Regards, Malcolm ----- Original message ----- From: "Gabriel Genellina" To: python-list at python.org Date: Wed, 24 Mar 2010 19:50:11 -0300 Subject: Re: Programmatically discovering encoding types supported by codecs module En Wed, 24 Mar 2010 14:58:47 -0300, escribi?: >> After looking at how things are done in codecs.c and >> encodings/__init__.py I think you should enumerate all modules in the >> encodings package that define a getregentry function. Aliases come from >> encodings.aliases.aliases. > > Thanks for looking into this for me. Benjamin Kaplan made a similar > observation. My reply to him included the snippet of code we're using to > generate the actual list of encodings that our software will support > (thanks to Python's codecs and encodings modules). I was curious as whether both methods would give the same results: py> modules=set() py> for name in glob.glob(os.path.join(encodings.__path__[0], "*.py")): ... name = os.path.basename(name)[:-3] ... try: mod = __import__("encodings."+name, fromlist=['ilovepythonbutsometimesihateit']) ... except ImportError: continue ... if hasattr(mod, 'getregentry'): ... modules.add(name) ... py> fromalias = set(encodings.aliases.aliases.values()) py> fromalias - modules set(['tactis']) py> modules - fromalias set(['charmap', 'cp1006', 'cp737', 'cp856', 'cp874', 'cp875', 'idna', 'iso8859_1', 'koi8_u', 'mac_arabic', 'mac_centeuro', 'mac_croatian', 'mac_farsi', 'mac_romanian', 'palmos', 'punycode', 'raw_unicode_escape', 'string_escape', 'undefined', 'unicode_escape', 'unicode_internal', 'utf_8_sig']) There is a missing 'tactis' encoding (?) and about twenty without alias. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From arunbgg at gmail.com Sun Mar 28 07:09:05 2010 From: arunbgg at gmail.com (Arun Balagopal) Date: Sun, 28 Mar 2010 16:39:05 +0530 Subject: Need help with using SOAP based web service Message-ID: <29c2bde91003280409y7460ca50oabacec7f1271d0ca@mail.gmail.com> Hi, I am working on a project in text mining using Python. As part of the project I need to use a technical term extractor, and I found the Terminesystem from NACTEM very useful. I have used the web demo (it's pretty nifty) and now want to integrate it in my project. The service provides a SOAP interface, which I am trying to use in Python with the ZSI 2.0 module (I have never used it before). The sample client scripts and instructions for Python are provided here Here's what I did. I installed ZSI 2.0 and its dependency PyXml. Then as given in the instructions, I generated wrappers for the service (2 python files). However when I try to run the sample script, I get errors (something about no attribute 'typecode'). I have tried tweaking in the source, but still no luck. If anybody knows how exactly to get this thing working, please help. I am new to the mailing list, and I apologize if this is the wrong place to post such questions. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Sun Mar 28 07:17:24 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 28 Mar 2010 13:17:24 +0200 Subject: Encryption source code with md5 In-Reply-To: References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> On 28-3-2010 12:08, Lawrence D'Oliveiro wrote: > In message<91541c26-6f18-40c7- > a0df-252a52bb7cd5 at l25g2000yqd.googlegroups.com>, catalinfest at gmail.com > wrote: > >> It is possible to encrypt with md5 python source code? > > Don?t use MD5. Also, md5 is not an encryption algorithm at all, it is a secure hashing function. (well, not so secure anymore nowadays, which probably is why Lawrence already wrote to avoid using it). irmen From kelithaem at gmail.com Sun Mar 28 07:30:51 2010 From: kelithaem at gmail.com (Rolla) Date: Sun, 28 Mar 2010 04:30:51 -0700 (PDT) Subject: AUTHENTIC DESIGNER HANDBAGS ACCESSORIES GREAT DISCOUNTS! WWW.VOGUELANDE.COM Message-ID: <5820a042-2e7d-4f3a-a672-cd4a4315a72f@g28g2000prb.googlegroups.com> Dear Customer, We now have NEW ARRIVAL accessories coming. Please check the site as follows, http://www.voguelande.com/ChanelAcce.html http://www.voguelande.com/Accessories.html CONTACT INFO: INFO at VOGUELANDE.COM From zaq2442 at gmail.com Sun Mar 28 08:12:49 2010 From: zaq2442 at gmail.com (=?UTF-8?B?2KfYp9in2KfZhNmI2KfZgdmK?=) Date: Sun, 28 Mar 2010 05:12:49 -0700 (PDT) Subject: =?windows-1256?B?0czhIM3H4+Eg3e0gx+Hf5u3KICEhISDV5tE=?= Message-ID: <0a44111d-e4f8-4822-a4cd-828bb3fa54a8@q15g2000yqj.googlegroups.com> http://www.nb11.net/vb/forumdisplay.php?f=25 From catalinfest at gmail.com Sun Mar 28 09:00:58 2010 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Sun, 28 Mar 2010 06:00:58 -0700 (PDT) Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: I had a talk about Python and distribution of commercial products created with python. This made me think of a way to protect my source code to be distributed. I thought a live CD version and then to an encryption method of a portion of source code. These thoughts are the source of two questions. From l.quesada at 4c.ucc.ie Sun Mar 28 09:26:43 2010 From: l.quesada at 4c.ucc.ie (Luis Quesada) Date: Sun, 28 Mar 2010 14:26:43 +0100 Subject: map, index Message-ID: Dear all, I am new to Python, so I apologize in advance if you find my questions naive (or if they have been already answered in this forum). 1. What is the most pythonic way of mapping a list where the value each element is mapped to depends on the index of the element. Is there a way of writing the following without using zip: map(lambda (id,v):id*v,zip(range(len(L)),L)) I wonder whether there is something like mapInd in Oz (http://www.mozart-oz.org/documentation/base/list.html) so that you can pass a binary function to map and refer to the index of the element in the body of the given function. It would be cool to be able to simply write: mapInd(lambda id,v:id*v,L) 2. Is there a higher order index function that lets you specify the condition to be met by the returned element. I mean something like: def my_index(f,L,default): for x in L: if f(x):return x return default Thanks in advance for your answer! Cheers, Luis From ethan at stoneleaf.us Sun Mar 28 09:46:36 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 28 Mar 2010 06:46:36 -0700 Subject: Simple Traits Questions In-Reply-To: References: <4BAE05C6.4070601@stoneleaf.us> Message-ID: <4BAF5DBC.7050909@stoneleaf.us> Robert Kern wrote: > On 2010-03-27 08:19 , Ethan Furman wrote: > >> Okay, different post for my actual questions. :) >> >> On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) >> it has the example of choosing which methods to keep in the composed >> class: >> >> class TOSWidget(BaseWidget): >> __metaclass__ = include(Pack, Place, Grid) >> info = Pack.info.im_func >> config = Pack.config.im_func >> configure = Pack.configure.im_func >> slaves = Pack.slaves.im_func >> forget = Pack.forget.im_func >> propagate = Pack.propagate.im_func >> >> My question is: >> >> Why use >> >> info = Pack.info.im_func >> >> instead of >> >> info = Pack.info >> >> ? > > > Pack.info is an unbound method object attached to the Pack class, not a > function object. It has some extra semantics on top of functions and is > tied to the Pack class. The .im_func attribute gets the actual function > object underneath. When defining the TOSWidget class, the objects > defined in the suite under the class: statement need to be actual > functions in order to be turned into unbound methods attached to the > TOSWidget class. Ah, thank you. In Python 3, though, would the Pack.info form be correct? ~Ethan~ From duncan.booth at invalid.invalid Sun Mar 28 09:53:36 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Mar 2010 13:53:36 GMT Subject: map, index References: Message-ID: Luis Quesada wrote: > Is there a way > of writing the following without using zip: > map(lambda (id,v):id*v,zip(range(len(L)),L)) [ id*v for id,v in enumerate(L) ] From steve at holdenweb.com Sun Mar 28 10:08:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 28 Mar 2010 10:08:20 -0400 Subject: Encryption source code with md5 In-Reply-To: References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: catalinfest at gmail.com wrote: > I had a talk about Python and distribution of commercial products > created with python. This made me think of a way to protect my source > code to be distributed. I thought a live CD version and then to an > encryption method of a portion of source code. These thoughts are the > source of two questions. I'd suggest that you don't think about encrypting your source code until you have a rather better handle on encryption technology. Your mention of MD5, a hashing rather than an encryption algorithm, makes it clear that you aren't familiar with the technologies at present. There's nothing wrong with ignorance (I have a more than adequate supply of my own), but in encryption it's *very* easy to make mistakes that render whole systems vulnerable to trivial attack. So you do really need to know what you are doing. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From showell30 at yahoo.com Sun Mar 28 10:16:10 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 07:16:10 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: On Mar 27, 3:18?am, Steven D'Aprano wrote: > On Fri, 26 Mar 2010 07:31:17 -0700, Steve Howell wrote: > > From a purely academic standpoint, I'm not convinced that sum() is > > inefficient in terms of big-O complexity, though. > > > ?showell at showell-laptop:~$ python > > ?Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on > > ?linux2 > > ?>>> class StupidList: > > [...] > > But it's not *sum* that is inefficient, it is sum *with a particular data > structure*. > Yep, the implied context was with particular data structures. > Sure, if you create your own data structure, you can make it as efficient > as you like. Obviously the sum algorithm itself has to perform one > addition per item, or O(N), which scales tolerably well. But each > addition has a cost. If the cost is constant, then sum() as a whole > remains O(N). But if the cost of addition varies with N, sum() degrades > ba > The surprising part of sum() is not that the outer loop to do the sums is O(N). It is hard to imagine any other implementation (without parallelizing it). The mildly surprising part of sum() is that is does add vs. add-in- place, which leads to O(N) vs. O(1) for the inner loop calls, for certain data structures, notably lists, even though none of the intermediate results get used by the caller. For lists, you could make a more efficient variant of sum() that clones the start value and does add-in-place. I could guess pretty confidently that the reason this optimization was never tried is that sum() has always been intended to be used on numerics, since other alternatives exist for strings (join), lists (chain), and hand-coded data classes that support add-in-place (roll- your-own loop). The documentation is pretty clear on the intention that sum() is intended for numbers: http://docs.python.org/library/functions.html#sum Except for strings, the docs are not explicit about efficiency concerns for other data structures, or the fact that the reference implementation does add vs. add-in-place under the hood. http://docs.python.org/library/functions.html#sum From michele.simionato at gmail.com Sun Mar 28 10:17:24 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 28 Mar 2010 07:17:24 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> <40ba11d3-5a18-4da4-a48a-0dd815f3b459@35g2000yqm.googlegroups.com> Message-ID: <1ea8ca8b-b556-44f1-9af8-75e1f60c5fb1@i25g2000yqm.googlegroups.com> Another option is to use my own decorator module (http:// pypi.python.org/pypi/decorator): from decorator import decorator @decorator def d(func, *args): print 3 return func(*args) @d def f(a, b): print a + b f(5, 7) From l.quesada at 4c.ucc.ie Sun Mar 28 10:34:12 2010 From: l.quesada at 4c.ucc.ie (Luis Quesada) Date: Sun, 28 Mar 2010 15:34:12 +0100 Subject: map, index In-Reply-To: References: Message-ID: Duncan Booth wrote: > Luis Quesada wrote: > >> Is there a way >> of writing the following without using zip: >> map(lambda (id,v):id*v,zip(range(len(L)),L)) > > [ id*v for id,v in enumerate(L) ] Cool! Thanks! Cheers, Luis From v.harishankar at gmail.com Sun Mar 28 10:39:12 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 28 Mar 2010 14:39:12 +0000 (UTC) Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: On Sun, 28 Mar 2010 10:08:20 -0400, Steve Holden wrote: > catalinfest at gmail.com wrote: >> I had a talk about Python and distribution of commercial products >> created with python. This made me think of a way to protect my source >> code to be distributed. I thought a live CD version and then to an >> encryption method of a portion of source code. These thoughts are the >> source of two questions. > > I'd suggest that you don't think about encrypting your source code until > you have a rather better handle on encryption technology. Your mention > of MD5, a hashing rather than an encryption algorithm, makes it clear > that you aren't familiar with the technologies at present. > > There's nothing wrong with ignorance (I have a more than adequate supply > of my own), but in encryption it's *very* easy to make mistakes that > render whole systems vulnerable to trivial attack. So you do really need > to know what you are doing. > > regards > Steve This article offers some good ideas and also sums up some good points *against* code obfuscation. http://stackoverflow.com/questions/261638/how-do-i-protect-python-code Read it and judge whether the benefits of not obfuscating code outweighs the advantages of obfuscating it. -- Harishankar (http://harishankar.org http://literaryforums.org) From steve at REMOVE-THIS-cybersource.com.au Sun Mar 28 10:57:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Mar 2010 14:57:08 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <4baf6e43$0$8756$c3e8da3@news.astraweb.com> On Sun, 28 Mar 2010 07:16:10 -0700, Steve Howell wrote: > The mildly surprising part of sum() is that is does add vs. add-in- > place, which leads to O(N) vs. O(1) for the inner loop calls, for > certain data structures, notably lists, even though none of the > intermediate results get used by the caller. For lists, you could make > a more efficient variant of sum() that clones the start value and does > add-in-place. I have no doubt that you could make a version of sum for lists which is more efficient than the existing one. After all, join more or less does the same sort of thing, and it's very efficient. But don't think that add- in-place is necessarily cheap. List appends are amortized O(1) each; if you are adding M lists of N items each, that gives you O(M*N). It's possible to improve the performance a tad if you can make multiple appends in roughly constant time, which is what list.extend (probably?) does, but only up to a point. Lists are over-allocated, but if you try to add more items than there is room for, you need to make the list bigger, and that means reallocating memory, which could easily be O(N**2) or worse, depending on how good your OS's memory management is. Under Linux, at least by default, malloc will never fail, but there's no guarantee how long it will take to return. If the OOM killer has to start shutting down other applications, and paging more and more memory to disk, eventually malloc will return (or the system will core dump), but it could take a while... -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 28 10:58:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Mar 2010 14:58:18 GMT Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: <4baf6e8a$0$8756$c3e8da3@news.astraweb.com> On Sun, 28 Mar 2010 10:08:20 -0400, Steve Holden wrote: > catalinfest at gmail.com wrote: >> I had a talk about Python and distribution of commercial products >> created with python. This made me think of a way to protect my source >> code to be distributed. I thought a live CD version and then to an >> encryption method of a portion of source code. These thoughts are the >> source of two questions. > > I'd suggest that you don't think about encrypting your source code until > you have a rather better handle on encryption technology. Your mention > of MD5, a hashing rather than an encryption algorithm, makes it clear > that you aren't familiar with the technologies at present. Furthermore, you should forget about encrypting your program until you are sure that it is something that needs encrypting. In my experience, most times newbies start waffling on about encrypting their precious code (usually displaying total confusion about encryption technology), it turns out their critical application is something like Notepad only with fewer features. Not that I'm jaded at all. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 28 10:59:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Mar 2010 14:59:18 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> <4bae6130$1@dnews.tpgi.com.au> Message-ID: <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote: > On 03/22/2010 07:07 PM, Steven D'Aprano wrote: >> Perhaps you should have said that it was a wrapper around deque giving >> richer functionality, rather than giving the impression that it was a >> brand new data structure invented by you. People are naturally going to >> be more skeptical about a newly invented data structure than one based >> on a reliable, component like deque. > > Well, technically StringChain is not a data structure in the first > place. StringChain is a string; And strings are data structures, as are arrays and structs. Just because they're simple data structures made directly from primitives rather than rich, complex structures, doesn't mean they're not data structures. > a string that is implemented using deque > data structure to make appending algorithmically efficient. It is not a > data structure, in the sense that I can't put arbitrary "thing" into the > data structure. Any "thing" that can be pickled or serialised can be put into a string. -- Steven From duncan.booth at invalid.invalid Sun Mar 28 11:17:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Mar 2010 15:17:46 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: Steve Howell wrote: > The mildly surprising part of sum() is that is does add vs. add-in- > place, which leads to O(N) vs. O(1) for the inner loop calls, for > certain data structures, notably lists, even though none of the > intermediate results get used by the caller. For lists, you could > make a more efficient variant of sum() that clones the start value and > does add-in-place. Doing add-in-place isn't the only way to make sum more efficient: if you assume that addition is associative (which of course the builtin sum can't) then you can form partial sums. e.g. instead of calculating: (((((((a + b) + c) + d) + e) + f) + g) + h) you calculate: (((a + b) + (c + d)) + ((e + f) + (g + h))) Obviously this requires more space than the naive sum, but not as much as you might at first expect: you only need to hold log(n) intermediates values at any time. > I could guess pretty confidently that the reason this optimization was > never tried is that sum() has always been intended to be used on > numerics, since other alternatives exist for strings (join), lists > (chain), and hand-coded data classes that support add-in-place (roll- > your-own loop). Doing it this way helps summing lists or strings (though not as much as str.join), but it also helps if you need to sum a long list of similarly sized floats as you'll get a more accurate answer. See http://groups.google.com/group/comp.lang.python/browse_thread/thread/9eda29 faf92f532e/027cef7d4429aa3a for an earlier discussion of this, or just Google comp.lang.python for 'pairwise sum'. Here's the code I posted in that thread: def sumpairs(seq): tmp = [] for i,v in enumerate(seq): if i&1: tmp[-1] = tmp[-1] + v i = i + 1 n = i & -i while n > 2: t = tmp.pop(-1) tmp[-1] = tmp[-1] + t n >>= 1 else: tmp.append(v) while len(tmp) > 1: t = tmp.pop(-1) tmp[-1] = tmp[-1] + t return tmp[0] and I claimed that my Python coded sumpairs function was faster than the builtin sum on a list of lists once you had more than about 210 items. I never did get round to rewriting it in C for a more realistic speed comparison: summing integers my Python version is about 60 times slower than the builtin. From showell30 at yahoo.com Sun Mar 28 11:55:05 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 08:55:05 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> On Mar 28, 8:17?am, Duncan Booth wrote: > Steve Howell wrote: > > The mildly surprising part of sum() is that is does add vs. add-in- > > place, which leads to O(N) vs. O(1) for the inner loop calls, for > > certain data structures, notably lists, even though none of the > > intermediate results get used by the caller. ?For lists, you could > > make a more efficient variant of sum() that clones the start value and > > does add-in-place. > > Doing add-in-place isn't the only way to make sum more efficient: if you > assume that addition is associative (which of course the builtin sum can't) > then you can form partial sums. e.g. instead of calculating: > > ? (((((((a + b) + c) + d) + e) + f) + g) + h) > > you calculate: > > ? (((a + b) + (c + d)) + ((e + f) + (g + h))) > > Obviously this requires more space than the naive sum, but not as much as > you might at first expect: you only need to hold log(n) intermediates > values at any time. > Yep, I did mention in my post that the outer loop does not *have* to be O(N), if you can parallelize it. Apart from reducing intermediates, the divide-and-conquer method does not reduce overall computation time unless you have multiple processors, correct? > > I could guess pretty confidently that the reason this optimization was > > never tried is that sum() has always been intended to be used on > > numerics, since other alternatives exist for strings (join), lists > > (chain), and hand-coded data classes that support add-in-place (roll- > > your-own loop). > > Doing it this way helps summing lists or strings (though not as much as > str.join), but it also helps if you need to sum a long list of similarly > sized floats as you'll get a more accurate answer. > Interesting! That makes sense. The docs for math.fsum() suggest that partial sums are used to maintain precision. http://docs.python.org/library/math.html#math.fsum > Seehttp://groups.google.com/group/comp.lang.python/browse_thread/thread/... > faf92f532e/027cef7d4429aa3a > for an earlier discussion of this, or just Google comp.lang.python for > 'pairwise sum'. > > Here's the code I posted in that thread: > > def sumpairs(seq): > ? ? tmp = [] > ? ? for i,v in enumerate(seq): > ? ? ? ? if i&1: > ? ? ? ? ? ? tmp[-1] = tmp[-1] + v > ? ? ? ? ? ? i = i + 1 > ? ? ? ? ? ? n = i & -i > ? ? ? ? ? ? while n > 2: > ? ? ? ? ? ? ? ? t = tmp.pop(-1) > ? ? ? ? ? ? ? ? tmp[-1] = tmp[-1] + t > ? ? ? ? ? ? ? ? n >>= 1 > ? ? ? ? else: > ? ? ? ? ? ? tmp.append(v) > ? ? while len(tmp) > 1: > ? ? ? ? t = tmp.pop(-1) > ? ? ? ? tmp[-1] = tmp[-1] + t > ? ? return tmp[0] > > and I claimed that my Python coded sumpairs function was faster than the > builtin sum on a list of lists once you had more than about 210 items. > I never did get round to rewriting it in C for a more realistic speed > comparison: summing integers my Python version is about 60 times slower > than the builtin. From wolftracks at invalid.com Sun Mar 28 12:20:21 2010 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 28 Mar 2010 09:20:21 -0700 Subject: Why this Difference in Importing NumPy 1.2 vs 1.4? Message-ID: I wrote a program in Python 2.5 under Win7 and it runs fine using Numpy 1.2 , but not on a colleague's machine who has a slightly newer 2.5 and uses NumPy 1.4. We both use IDLE to execute the program. During import he gets this: >>> Traceback (most recent call last): File "C:\Documents and Settings\HP_Administrator.DavesDesktop\My Documents\Astro\Meteors\NC-FireballReport.py", line 38, in from scipy import stats as stats # scoreatpercentile File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in from stats import * File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in import scipy.special as special File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, in from numpy.testing import NumpyTest ImportError: cannot import name NumpyTest >>> Comments? It looks as though the problem is in NumPy 1.4. If it's either in NumPy or SciPy, how does my colleague back out to an earlier version to agree with mine? Does he just pull down 1.3 or better 1.2 (I use it.), and install it? How does he somehow remove 1.4? Is it as easy as going to IDLE's path browser and removing, under site-packages, numpy? (I'm not sure that's even possible. I don't see a right-click menu.) From showell30 at yahoo.com Sun Mar 28 12:21:59 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 09:21:59 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <4baf6e43$0$8756$c3e8da3@news.astraweb.com> Message-ID: <2af1fb7c-5952-484b-af2a-95ea97b47994@x11g2000prb.googlegroups.com> On Mar 28, 7:57?am, Steven D'Aprano wrote: > On Sun, 28 Mar 2010 07:16:10 -0700, Steve Howell wrote: > > The mildly surprising part of sum() is that is does add vs. add-in- > > place, which leads to O(N) vs. O(1) for the inner loop calls, for > > certain data structures, notably lists, even though none of the > > intermediate results get used by the caller. ?For lists, you could make > > a more efficient variant of sum() that clones the start value and does > > add-in-place. > > I have no doubt that you could make a version of sum for lists which is > more efficient than the existing one. After all, join more or less does > the same sort of thing, and it's very efficient. But don't think that add- > in-place is necessarily cheap. List appends are amortized O(1) each; if > you are adding M lists of N items each, that gives you O(M*N). > O(M*N) is still cheaper than O(M*N*N). > It's possible to improve the performance a tad if you can make multiple > appends in roughly constant time, which is what list.extend (probably?) > does, but only up to a point. Lists are over-allocated, but if you try to > add more items than there is room for, you need to make the list bigger, > and that means reallocating memory, which could easily be O(N**2) or > worse, depending on how good your OS's memory management is. Under Linux, > at least by default, malloc will never fail, but there's no guarantee how > long it will take to return. If the OOM killer has to start shutting down > other applications, and paging more and more memory to disk, eventually > malloc will return (or the system will core dump), but it could take a > while... > Even though extend() obviously has to do memory allocations along the way itself, it is still more efficient than the alternative. No need to speculate, you can measure these methods on your platform: M = 10 N = 1000 def in_place( start = [], sublists = ([[None] * M]) * N ): accum = start[:] for sublist in sublists: accum.extend(sublist) return accum def with_intermediates( start = [], sublists = ([[None] * M]) * N ): accum = start for sublist in sublists: accum = accum + sublist return accum From fhernandezn at gmail.com Sun Mar 28 12:22:23 2010 From: fhernandezn at gmail.com (Fabian Hernandez) Date: Sun, 28 Mar 2010 12:22:23 -0400 Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION In-Reply-To: References: Message-ID: <3be2e7f21003280922t1f248ae6pb68e37caf048dded@mail.gmail.com> 2010/3/27 G.Lowell Krane > Here is the ad i am trying to get Python-list to post ASAP--this weekend. > > Also, in case one of your best applications is not public, and you want to > demonstrate it, do you prefer webex or what do you prefer? > --gary > > ---------- Forwarded message ---------- > From: G.Lowell Krane > Date: Fri, Mar 26, 2010 at 4:26 PM > Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup > To: python-list at python.org > > > TECH ADVISOR (1-3 hrs/wk) WANTED FOR UNUSUAL SOCIAL VENTURE STARTUP > > > This position is for an unusual well advanced (though not yet in beta) > Social Venture Internet Startup that has hopefully figured out a way through > an unusually robust web application to help the 95% of unhappy couples in > the Western Hemisphere who cannot afford or will not trust a marriage > therapist, to save, ensure, deepen their relationships (about 60MM > couples!). The monetization model is initially subscriber (very low fee that > mkt research (harris poll) has shown the majority of these in USA, at least > would like to use this for about $20/mo for at least 3 mo or longer as long > as they felt it was helping at least a little.) Our startup, eCoupleCoach > /ParejasContentas, would in fact be the pioneer of this blue ocean market > using a conceptual advance, and employing a social media as well as "tapping > the wisdom of the best experts" model. > > > Our urgent need now is for someone who is a senior level > developer/programmer to be able to vet three or four of the best web > application teams we have finally found, or at least the one python team we > found (in Bogota, where I, the ceo/founder/head research psychologist, will > be working with them daily to ensure maximum efficiency).** > > *BTW, anyone who has gone through a tough divorce (or whose parents > divorced at a tender age, will probably find this enormously fascinating and > gratifying?an opportunity to turn your lemons into lemonade.* > > Besides the python freelance team ( team, we also have a .net freelance > team, and php company . We might identify a 4th soon. But the priority > now is to vet the python team?one lead developer who has been doing python > on and off (part and fulltime )for several years (but collapsed, 3 years), > and the other developer, about 1 year. The third member of their team is > more of a designer, doing css and html. > > After this vetting, we ideally hope, if you are excited about our potential > and yours with us, that you will want to stay on up to two hours a week (of > course the more you can devote the better if you are interested in any other > challenges) to at least QA the code quality and make sure it is being > dumped at least weekly. > > WHAT WE HAVE GOING FOR US: A lot. Once we hear from you, we will send > detailed backgrounders. > > COMPENSATION: would be negotiable and this could also lead to a highly > responsible high up position once we are funded. > > TO APPLY: PLEASE email me at eCoupleCoach at gmail.com to make initial > contact, and send us your resume. After this we will > Send you detailed backgrounders on who we are and what we have going for > us. > > IN YOUR SIGNATURE (so easy to find): Please also indicate your skype > contact info, for follow up phone conversation, unless you prefer chat, in > which case your chat contact info (preferably google), since I am in > Colombia now and will be till the beta is done, though my partner and VP of > Product Development/Project Manager is in NYC. > > > > > > > Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y > eCoupleCoach) > "Tapping the wisdom of the best experts and the wisest couples (TM)," and > "Making Honesty easier than ever before." > Medellin and Bogota: 300 415 5298 > Skype: garykrane > > "The greatness of a human is to be measured exactly by the degree to which > he has helped his/her fellow human."-Gandhi > "The best things in life are not things" (anon) > > > > > -- > Attentamente, > Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y > eCoupleCoach) > "Tapping the wisdom of the best experts and the wisest couples (TM)," and > "Making Honesty easier than ever before." > Medellin: 300 415 5298 > Skype: garykrane > > "Un ser humano se convierte en una gran exactitud en la medida en la que ?l > trabaja para el bienestar de sus compa?eros " - Mahatma Gandhi > "The greatness of a human is to be measured exactly by the degree to which > he has helped his/her fellow human."-Gandhi > "The best things in life are not things" (anon) > > -- Fabian Hernandez Nieto http://www.sidesoftware.net Linux User # 485518 -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Sun Mar 28 12:26:39 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 09:26:39 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> <40ba11d3-5a18-4da4-a48a-0dd815f3b459@35g2000yqm.googlegroups.com> <1ea8ca8b-b556-44f1-9af8-75e1f60c5fb1@i25g2000yqm.googlegroups.com> Message-ID: On Mar 28, 9:17?am, Michele Simionato wrote: > Another option is to use my own decorator module (http:// > pypi.python.org/pypi/decorator): > > from decorator import decorator > > @decorator > def d(func, *args): > ? ? print 3 > ? ? return func(*args) > > @d > def f(a, b): > ? ? print a + b > > f(5, 7) That looks cool (and I'm glad you mentioned it), but it appeared to me the OP was trying to manually construct the equivalent of a decorator without the "@" syntax, in order to gain an understanding of how decorators work, and for this particular purpose, piling additional magic on top of decorators is probably not helpful :-) Regards, Pat From fhernandezn at gmail.com Sun Mar 28 12:44:56 2010 From: fhernandezn at gmail.com (Fabian Hernandez) Date: Sun, 28 Mar 2010 12:44:56 -0400 Subject: OT: Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION Message-ID: <3be2e7f21003280944i49f4e1a2g6dd199be2e1b3018@mail.gmail.com> ---------- Forwarded message ---------- From: G.Lowell Krane Date: 2010/3/27 Subject: Fwd: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION To: Daniel Arbelaez Cc: arpunk , Fabian Hernandez Here is the ad i am trying to get Python-list to post ASAP--this weekend. Also, in case one of your best applications is not public, and you want to demonstrate it, do you prefer webex or what do you prefer? --gary ---------- Forwarded message ---------- From: G.Lowell Krane Date: Fri, Mar 26, 2010 at 4:26 PM Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup To: python-list at python.org TECH ADVISOR (1-3 hrs/wk) WANTED FOR UNUSUAL SOCIAL VENTURE STARTUP This position is for an unusual well advanced (though not yet in beta) Social Venture Internet Startup that has hopefully figured out a way through an unusually robust web application to help the 95% of unhappy couples in the Western Hemisphere who cannot afford or will not trust a marriage therapist, to save, ensure, deepen their relationships (about 60MM couples!). The monetization model is initially subscriber (very low fee that mkt research (harris poll) has shown the majority of these in USA, at least would like to use this for about $20/mo for at least 3 mo or longer as long as they felt it was helping at least a little.) Our startup, eCoupleCoach /ParejasContentas, would in fact be the pioneer of this blue ocean market using a conceptual advance, and employing a social media as well as "tapping the wisdom of the best experts" model. Our urgent need now is for someone who is a senior level developer/programmer to be able to vet three or four of the best web application teams we have finally found, or at least the one python team we found (in Bogota, where I, the ceo/founder/head research psychologist, will be working with them daily to ensure maximum efficiency).** *BTW, anyone who has gone through a tough divorce (or whose parents divorced at a tender age, will probably find this enormously fascinating and gratifying?an opportunity to turn your lemons into lemonade.* Besides the python freelance team ( team, we also have a .net freelance team, and php company . We might identify a 4th soon. But the priority now is to vet the python team?one lead developer who has been doing python on and off (part and fulltime )for several years (but collapsed, 3 years), and the other developer, about 1 year. The third member of their team is more of a designer, doing css and html. After this vetting, we ideally hope, if you are excited about our potential and yours with us, that you will want to stay on up to two hours a week (of course the more you can devote the better if you are interested in any other challenges) to at least QA the code quality and make sure it is being dumped at least weekly. WHAT WE HAVE GOING FOR US: A lot. Once we hear from you, we will send detailed backgrounders. COMPENSATION: would be negotiable and this could also lead to a highly responsible high up position once we are funded. TO APPLY: PLEASE email me at eCoupleCoach at gmail.com to make initial contact, and send us your resume. After this we will Send you detailed backgrounders on who we are and what we have going for us. IN YOUR SIGNATURE (so easy to find): Please also indicate your skype contact info, for follow up phone conversation, unless you prefer chat, in which case your chat contact info (preferably google), since I am in Colombia now and will be till the beta is done, though my partner and VP of Product Development/Project Manager is in NYC. Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y eCoupleCoach) "Tapping the wisdom of the best experts and the wisest couples (TM)," and "Making Honesty easier than ever before." Medellin and Bogota: 300 415 5298 Skype: garykrane "The greatness of a human is to be measured exactly by the degree to which he has helped his/her fellow human."-Gandhi "The best things in life are not things" (anon) -- Attentamente, Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y eCoupleCoach) "Tapping the wisdom of the best experts and the wisest couples (TM)," and "Making Honesty easier than ever before." Medellin: 300 415 5298 Skype: garykrane "Un ser humano se convierte en una gran exactitud en la medida en la que ?l trabaja para el bienestar de sus compa?eros " - Mahatma Gandhi "The greatness of a human is to be measured exactly by the degree to which he has helped his/her fellow human."-Gandhi "The best things in life are not things" (anon) -- Fabian Hernandez Nieto http://www.sidesoftware.net Linux User # 485518 -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Sun Mar 28 12:46:07 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 09:46:07 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <2eb7e099-6ad5-46f0-abe3-4599231f70f5@z4g2000yqa.googlegroups.com> On Mar 28, 10:17?am, Duncan Booth wrote: > Doing add-in-place isn't the only way to make sum more efficient: if you > assume that addition is associative (which of course the builtin sum can't) > then you can form partial sums. e.g. instead of calculating: ... > > Doing it this way helps summing lists or strings (though not as much as > str.join), but it also helps if you need to sum a long list of similarly > sized floats as you'll get a more accurate answer. Also, partial sums would be a clear winner over add-in-place if someone were dumb^H^H^H^Hnaive enough to use sum() on a long list of tuples :-) From alfps at start.no Sun Mar 28 12:56:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Mar 2010 18:56:26 +0200 Subject: sum for sequences? In-Reply-To: <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: * Steve Howell: > On Mar 28, 8:17 am, Duncan Booth wrote: >> Steve Howell wrote: >>> The mildly surprising part of sum() is that is does add vs. add-in- >>> place, which leads to O(N) vs. O(1) for the inner loop calls, for >>> certain data structures, notably lists, even though none of the >>> intermediate results get used by the caller. For lists, you could >>> make a more efficient variant of sum() that clones the start value and >>> does add-in-place. >> Doing add-in-place isn't the only way to make sum more efficient: if you >> assume that addition is associative (which of course the builtin sum can't) >> then you can form partial sums. e.g. instead of calculating: >> >> (((((((a + b) + c) + d) + e) + f) + g) + h) >> >> you calculate: >> >> (((a + b) + (c + d)) + ((e + f) + (g + h))) >> >> Obviously this requires more space than the naive sum, but not as much as >> you might at first expect: you only need to hold log(n) intermediates >> values at any time. >> > > Yep, I did mention in my post that the outer loop does not *have* to > be O(N), if you can parallelize it. Apart from reducing > intermediates, the divide-and-conquer method does not reduce overall > computation time unless you have multiple processors, correct? > With a single thread of execution it can reduce the time for large integers and custom numerical types, with n the number of final bits, from O(n^2) to O(n log n). I don't think the parallelism here is very relevant for Python. From a more practical point of view, the sum efficiency could be improved by doing the first addition using '+' and the rest using '+=', without changing the behavior. Cheers & hth., - Alf From showell30 at yahoo.com Sun Mar 28 13:21:08 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 10:21:08 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> On Mar 28, 9:56?am, "Alf P. Steinbach" wrote: > * Steve Howell: >> (talking about summing a list of lists) > > ?From a more practical point of view, the sum efficiency could be improved by > doing the first addition using '+' and the rest using '+=', without changing the > behavior. I like that approach, because you don't have to assume that the start object is clonable, although perhaps you need to make that assumption anyway for the case where the list is empty. Here is code that might shed light on Alf's suggested approach: import timeit M = 10 N = 8000 def in_place( start = [], sublists = ([[None] * M]) * N ): # only macro-optimized i = 0 for sublist in sublists: if i == 0: accum = start + sublist i += 1 else: accum.extend(sublist) if i == 0: return 'whatever' # semantics here? return accum def with_intermediates( start = [], sublists = ([[None] * M]) * N ): accum = start for sublist in sublists: accum = accum + sublist return accum t1 = timeit.timeit('in_place()', 'from __main__ import in_place', number=10) t2 = timeit.timeit('with_intermediates()', 'from __main__ import with_intermediates', number=10) print M, N, t1, t2, int(t2 / t1) For N=100, you get a significant speedup (x84): 10 1000 0.00102496147156 0.0867249965668 84 More data: 10 1000 0.00102496147156 0.0867249965668 84 10 2000 0.00211381912231 0.172616004944 81 10 4000 0.00491786003113 0.561800956726 114 10 8000 0.0706541538239 19.9019489288 281 10 16000 0.0161759853363 9.64171791077 596 10 32000 0.0351569652557 43.98346591 1251 From pmaupin at gmail.com Sun Mar 28 13:27:38 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 10:27:38 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: On Mar 28, 11:56?am, "Alf P. Steinbach" wrote: > ?From a more practical point of view, the sum efficiency could be improved by > doing the first addition using '+' and the rest using '+=', without changing the > behavior. Mod parent up!!!! :-) From showell30 at yahoo.com Sun Mar 28 13:34:13 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 10:34:13 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> Message-ID: <0c76b611-c54f-4474-8f45-d745c53f72d0@k5g2000prg.googlegroups.com> On Mar 28, 10:21?am, Steve Howell wrote: > ? ? import timeit > ? ? M = 10 > ? ? N = 8000 > > ? ? def in_place( > ? ? ? ? start = [], > ? ? ? ? sublists = ([[None] * M]) * N > ? ? ? ? ): > ? ? ? ? # only macro-optimized > ? ? ? ? i = 0 > ? ? ? ? for sublist in sublists: > ? ? ? ? ? ? if i == 0: > ? ? ? ? ? ? ? ?accum = start + sublist > ? ? ? ? ? ? ? ?i += 1 > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? accum.extend(sublist) FYI I later obtained similar results with the more general: accum += sublist > ? ? ? ? if i == 0: > ? ? ? ? ? ? return 'whatever' # semantics here? > ? ? ? ? return accum > > ? ? def with_intermediates( > ? ? ? ? start = [], > ? ? ? ? sublists = ([[None] * M]) * N > ? ? ? ? ): > ? ? ? ? accum = start > ? ? ? ? for sublist in sublists: > ? ? ? ? ? ? accum = accum + sublist > ? ? ? ? return accum > From pmaupin at gmail.com Sun Mar 28 14:16:25 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 11:16:25 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> <0c76b611-c54f-4474-8f45-d745c53f72d0@k5g2000prg.googlegroups.com> Message-ID: <56cb099a-7757-481e-a316-f9655c3ac03c@k13g2000yqe.googlegroups.com> On Mar 28, 12:34?pm, Steve Howell wrote: > FYI I later obtained similar results with the more general: > ? ? ? ? ? ? ? ? ? accum += sublist Yeah, but you still have to create an object of the correct type for accum. And for summing small lists, that will actually increase the runtime. (Worst case, a list of a single item: you have to create the accum object based on the type of the start value, then do two += into it, for the start value and the first item in the list, vs just doing a single + which automatically creates an object.) Personally, I think the most general approach, if sum were open to enhancements, would be to automatically apply Alf's suggestion of "+" on summing the first item to the start value, and "+=" on subsequent items. Also, you *could* add a parameter to sum(), for example, default "partialsums=False" that would allow the use of partial sums in those cases where that might give better behavior (such as floats and tuples). From showell30 at yahoo.com Sun Mar 28 14:50:09 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 11:50:09 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> <0c76b611-c54f-4474-8f45-d745c53f72d0@k5g2000prg.googlegroups.com> <56cb099a-7757-481e-a316-f9655c3ac03c@k13g2000yqe.googlegroups.com> Message-ID: <975c7b4e-6c30-40b7-a4da-bcbbeb13e1aa@l5g2000pri.googlegroups.com> On Mar 28, 11:16?am, Patrick Maupin wrote: > On Mar 28, 12:34?pm, Steve Howell wrote: > > > FYI I later obtained similar results with the more general: > > ? ? ? ? ? ? ? ? ? accum += sublist > > Yeah, but you still have to create an object of the correct type for > accum. ? I think you overlooked the surrounding code. Here is the code again: def in_place( start = [], sublists = ([[None] * M]) * N ): # only macro-optimized i = 0 for sublist in sublists: if i == 0: accum = start + sublist i += 1 else: accum += sublist if i == 0: return 'whatever' # semantics here? return accum No need to infer the type. > And for summing small lists, that will actually increase the > runtime. ?(Worst case, a list of a single item: you have to create the > accum object based on the type of the start value, then do two += into > it, for the start value and the first item in the list, vs just doing > a single + which automatically creates an object.) > For small lists, the performance of any sane implementation would probably be so fast as to be negligible, unless you are in a really tight loop. If you are in a tight loop, then your use case probably eventually sums large lists. Even if it doesn't, the slowdown is just a constant. For M=5, I get these results on my machine: M N t1 t2 (t2/t1) 5 1 3.50475311279e-05 3.2901763916e-05 0.938775510204 5 2 2.00271606445e-05 1.59740447998e-05 0.797619047619 5 4 6.79492950439e-05 6.31809234619e-05 0.929824561404 5 8 0.000124931335449 0.000126123428345 1.00954198473 5 64 0.000530958175659 0.00226187705994 4.25999101931 5 1024 0.00262904167175 0.27246594429 103.636981953 t1 = time with add only first element t2 = time with add all elements Very small penalty for small lists, very large gain for large lists. > Personally, I think the most general approach, if sum were open to > enhancements, would be to automatically apply Alf's suggestion of "+" > on summing the first item to the start value, and "+=" on subsequent > items. ? See above. That's the approach I would use as well. From robert.kern at gmail.com Sun Mar 28 15:03:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 28 Mar 2010 14:03:49 -0500 Subject: Simple Traits Questions In-Reply-To: <4BAF5DBC.7050909@stoneleaf.us> References: <4BAE05C6.4070601@stoneleaf.us> <4BAF5DBC.7050909@stoneleaf.us> Message-ID: On 2010-03-28 08:46 , Ethan Furman wrote: > Robert Kern wrote: >> On 2010-03-27 08:19 , Ethan Furman wrote: >> >>> Okay, different post for my actual questions. :) >>> >>> On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) >>> it has the example of choosing which methods to keep in the composed >>> class: >>> >>> class TOSWidget(BaseWidget): >>> __metaclass__ = include(Pack, Place, Grid) >>> info = Pack.info.im_func >>> config = Pack.config.im_func >>> configure = Pack.configure.im_func >>> slaves = Pack.slaves.im_func >>> forget = Pack.forget.im_func >>> propagate = Pack.propagate.im_func >>> >>> My question is: >>> >>> Why use >>> >>> info = Pack.info.im_func >>> >>> instead of >>> >>> info = Pack.info >>> >>> ? >> >> >> Pack.info is an unbound method object attached to the Pack class, not >> a function object. It has some extra semantics on top of functions and >> is tied to the Pack class. The .im_func attribute gets the actual >> function object underneath. When defining the TOSWidget class, the >> objects defined in the suite under the class: statement need to be >> actual functions in order to be turned into unbound methods attached >> to the TOSWidget class. > > Ah, thank you. > > In Python 3, though, would the Pack.info form be correct? Seems so: Python 3.1 (r31:73578, Jun 27 2009, 21:49:46) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class Pack(): ... def info(self, x): ... pass ... >>> Pack.info -- 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 From nytrokiss at gmail.com Sun Mar 28 16:01:38 2010 From: nytrokiss at gmail.com (James Matthews) Date: Sun, 28 Mar 2010 13:01:38 -0700 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: <8a6b8e351003281301s121ed942x9847b4fc7d451f0f@mail.gmail.com> I am still on py 2.6 and since my code is heavy model dependent. I am bound to the most critical ones. Although I would really like if someone could backport some new stuff done with the GIL on 3.2 (they had a nice talk about it at PyCon) On Fri, Mar 26, 2010 at 5:33 PM, geremy condra wrote: > On Fri, Mar 26, 2010 at 9:23 AM, Harishankar > wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > > > I personally want to switch over but not too sure how many people are > > using 3.x as opposed to 2 so I want to keep my programs compatible for > > the majority. > > > > -- Hari > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Yes- I write new code in 3.x and backport it PRN. > > Geremy Condra > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sun Mar 28 16:46:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Mar 2010 13:46:40 -0700 Subject: map, index References: Message-ID: <7xeij418en.fsf@ruckus.brouhaha.com> Luis Quesada writes: >> [ id*v for id,v in enumerate(L) ] > Cool! Thanks! If you really want to write that in pointfree style (untested): import itertools, operator ... itertools.starmap(operator.mul, enumerate(L)) For your other question, you could probably do something ugly with ifilter, but it's not worth it. For the style of programming you're interested in, you should read the docs for the itertools module. Python culture in general tends to not be that fond of heavy use of HOF's, since it's very easy to make mistakes with its iterator protocol and with its dynamic type system. From kgo at grant-olson.net Sun Mar 28 16:46:50 2010 From: kgo at grant-olson.net (Grant Olson) Date: Sun, 28 Mar 2010 16:46:50 -0400 Subject: ANN: Pyasm version 0.3 Message-ID: <4BAFC03A.8010707@grant-olson.net> Pyasm is a full-featured dynamic assembler written entirely in Python. By dynamic, I mean that it can be used to generate and execute machine code in python at runtime without requiring the generation of object files and linkage. It essentially allow 'inline' assembly in python modules on x86 platforms. In addition, pyasm can generate COFF format object files, which may be of interest to anyone writing a compiler in python. More details and downloads are available at: http://www.grant-olson.net/python/pyasm The 0.3 release is long overdue. It includes: + A binary installer for python 2.6. The previous binary installer was python 2.4. + Automatic mapping of python structure values in the assembler. For Example, assuming EAX is a pointer to a string, MOV [EAX+PyString_ob_sval],0x42424242 will change the first four letters of the string to B's + The assembler now supports implicit string creation: PUSH 'foo\n\0' + The ability to build and test with the mingw toolset on windows. This previously required an MSVC toolset. Thanks to Markus L?ll for sorting this out. -Grant From no.email at nospam.invalid Sun Mar 28 16:49:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Mar 2010 13:49:32 -0700 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <7xaats189v.fsf@ruckus.brouhaha.com> Steve Howell writes: > The documentation is pretty clear on the intention that sum() is > intended for numbers: ... I've never been big on the idea of duck-typing addition. Who would have thought that (1,2,3)+(4.5.6) was something other than the vector sum? I think itertools.chain more directly expresses what the OP was trying to do, and is preferable for readability, independently of these performance questions. From philip at semanchuk.com Sun Mar 28 17:43:46 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 28 Mar 2010 17:43:46 -0400 Subject: Python Psycopg2 - Interface Error : Connection already closed In-Reply-To: References: Message-ID: <0A52C506-749F-460D-A660-A72BB793A1E2@semanchuk.com> On Mar 27, 2010, at 5:14 PM, knobbyknees wrote: > I'm not sure if this is the right group, but I'm hoping it is... > > Basically, I'm trying to use pgloader, which depends on python and > psycopg2. After banging my head against a wall, I found this: > > Found this: > http://www.mail-archive.com/sqlalchemy at googlegroups.com/msg13209.html > > Although, the suggestion didn't work for me at all... > > Running this command: > /usr/bin/pgloader -c /var/mybin/pgconfs/fr.conf > > Yields this in the pgloader.log (with the process just hanging) > > more /tmp/pgloader.log > 27-03-2010 12:22:53 pgloader INFO Logger initialized > 27-03-2010 12:22:53 pgloader INFO Reformat path is ['/usr/ > share/python-support/pgloader/reformat'] > 27-03-2010 12:22:53 pgloader INFO Will consider following > sections: > 27-03-2010 12:22:53 pgloader INFO fixed > 27-03-2010 12:22:54 fixed INFO fixed processing > 27-03-2010 12:22:54 pgloader INFO All threads are started, > wait for them to terminate > 27-03-2010 12:22:57 fixed ERROR connection already closed > 27-03-2010 12:22:57 fixed INFO closing current database > connection > > [pgsql] > host = localhost > port = 5432 > base = frdb > user = username > pass = password > > > [fixed] > table = fr > format = fixed > filename = /var/www/fr.txt > ... > > > This is what I see for the traceback: > Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 525, in > __bootstrap_inner > self.run() > File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 847, > in run > self.terminate() > File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 874, > in terminate > self.db.close() > File "/usr/lib/pymodules/python2.6/pgloader/db.py", line 103, in > close > self.dbconn.close() > > > I'm at a total loss here.... Can anyone please help me out? Hi knobbyknees, I can't help you with this problem, but the folks on the psycopg2 mailing list are probably a much better crowd to ask: http://lists.initd.org/mailman/listinfo/psycopg Good luck Philip From tjreedy at udel.edu Sun Mar 28 18:06:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Mar 2010 18:06:21 -0400 Subject: Simple Traits Questions In-Reply-To: <4BAF5DBC.7050909@stoneleaf.us> References: <4BAE05C6.4070601@stoneleaf.us> <4BAF5DBC.7050909@stoneleaf.us> Message-ID: On 3/28/2010 9:46 AM, Ethan Furman wrote: > Robert Kern wrote: >> On 2010-03-27 08:19 , Ethan Furman wrote: >> >>> Okay, different post for my actual questions. :) >>> >>> On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) >>> it has the example of choosing which methods to keep in the composed >>> class: >>> >>> class TOSWidget(BaseWidget): >>> __metaclass__ = include(Pack, Place, Grid) >>> info = Pack.info.im_func >>> config = Pack.config.im_func >>> configure = Pack.configure.im_func >>> slaves = Pack.slaves.im_func >>> forget = Pack.forget.im_func >>> propagate = Pack.propagate.im_func >>> >>> My question is: >>> >>> Why use >>> >>> info = Pack.info.im_func >>> >>> instead of >>> >>> info = Pack.info >>> >>> ? >> >> >> Pack.info is an unbound method object attached to the Pack class, not >> a function object. It has some extra semantics on top of functions and >> is tied to the Pack class. The .im_func attribute gets the actual >> function object underneath. When defining the TOSWidget class, the >> objects defined in the suite under the class: statement need to be >> actual functions in order to be turned into unbound methods attached >> to the TOSWidget class. > > Ah, thank you. > > In Python 3, though, would the Pack.info form be correct? Yes. One of the simplifications of Py3. From l.quesada at 4c.ucc.ie Sun Mar 28 18:14:31 2010 From: l.quesada at 4c.ucc.ie (Luis Quesada) Date: Sun, 28 Mar 2010 23:14:31 +0100 Subject: map, index In-Reply-To: <7xeij418en.fsf@ruckus.brouhaha.com> References: <7xeij418en.fsf@ruckus.brouhaha.com> Message-ID: <9xQrn.826$I8.164@news.indigo.ie> Paul Rubin wrote: > Luis Quesada writes: >>> [ id*v for id,v in enumerate(L) ] >> Cool! Thanks! > > If you really want to write that in pointfree style (untested): > > import itertools, operator > ... > itertools.starmap(operator.mul, enumerate(L)) > > For your other question, you could probably do something ugly > with ifilter, but it's not worth it. > > For the style of programming you're interested in, you should read the > docs for the itertools module. Python culture in general tends to > not be that fond of heavy use of HOF's, since it's very easy to make > mistakes with its iterator protocol and with its dynamic type system. Thanks a lot for the pointer. Python is rather cool indeed. Cheers, Luis From tdelaney at avaya.com Sun Mar 28 20:58:07 2010 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Mon, 29 Mar 2010 08:58:07 +0800 Subject: Super() function In-Reply-To: <4BAE359F.6090200@googlemail.com> References: <4BAAD5E0.9050604@googlemail.com> <4BAE359F.6090200@googlemail.com> Message-ID: > Gabriel Genellina wrote: >> Alan Harris-Reid escribi?: >> >>> Using Python 3.1, I sometimes use the super() function to call the >>> equivalent method from a parent class, for example >>> >>> def mymethod(self): >>> super().mymethod() >>> some more code... >>> >>> Is there any way of writing the code so that the super() call is >>> generic and automatically recognises the name of the current method >>> (ie. something like super().thismethod()) or do I always have to >>> repeat the method name after super()? >> >> This recipe does what you want: >> http://code.activestate.com/recipes/286195-selfsuper/ >> (but requires a bit of black magic...) >> > Hi Gabriel - thanks for the reply. > > Goodness me - that's a mighty complicated recipe for what I want to achieve! > I think I'll stick with repeating the method name - it's a small price to pay. I wrote that recipe back before Python 3.x supported super() without parameters, and near equivalent functionality was part of the new super PEP as an option. However, Guido decided to go with the much simpler super().attr with no shortcutting. If you think the pure-python version of the recipe is complicated, you should have a look at the performance-optimised Pyrex version ;) Tim Delaney From steven at REMOVE.THIS.cybersource.com.au Sun Mar 28 21:34:54 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 01:34:54 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <7xaats189v.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 28 Mar 2010 13:49:32 -0700, Paul Rubin wrote: > Steve Howell writes: >> The documentation is pretty clear on the intention that sum() is >> intended for numbers: ... > > I've never been big on the idea of duck-typing addition. Who would have > thought that (1,2,3)+(4.5.6) was something other than the vector sum? But your arguments are tuples, not vectors. There are languages which do treat arithmetic operations on vectors as vector operations, as do (e.g.) H-P scientific calculators. That's a fine design choice, and it works for languages where the emphasis is on scientific calculations. But Python is a more generalist language, so in my mind it is more appropriate to treat lists as generic lists, and not numeric vectors: [1, 2, 3] + [4, "a"] => [1, 2, 3, 4, "a"] just as "123" + "4a" => "1234a" -- Steven From keith at nekotaku.com Sun Mar 28 22:14:19 2010 From: keith at nekotaku.com (KB) Date: Sun, 28 Mar 2010 19:14:19 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse Message-ID: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Hi there, I have in the past used PythonWin to write python for COM, and switched to Eclipse. I am getting an error from the IDE saying it does not recognise CoInitialize(): **** import pythoncom pythoncom.CoInitialize() pythoncom.CoUninitialize() **** (red X next to the two bottom lines saying: "Undefined variable from import: CoInitialize") If I open a PyDev/Python Console window in Eclipse, I can type the above, no errors, no problem. I tried removing my Python Interpreter and re-adding/re-building but no change. python 2.5.2 eclipse 3.5.1 pydev 1.5.0 Thanks! From ysj.ray at gmail.com Sun Mar 28 22:25:50 2010 From: ysj.ray at gmail.com (Ray Allen) Date: Mon, 29 Mar 2010 10:25:50 +0800 Subject: Have you embraced Python 3.x yet? In-Reply-To: <8a6b8e351003281301s121ed942x9847b4fc7d451f0f@mail.gmail.com> References: <8a6b8e351003281301s121ed942x9847b4fc7d451f0f@mail.gmail.com> Message-ID: <797c8cbd1003281925q31217cb9q8436a8fe20388ac0@mail.gmail.com> In our company, we still use python-2.5.4, and will be updated to python-2.5.5. I hope we can go to 2.6.x or 3.x, but I'm not sure when. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Sun Mar 28 22:45:32 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 02:45:32 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: On Sun, 28 Mar 2010 18:56:26 +0200, Alf P. Steinbach wrote: > From a more practical point of view, the sum efficiency could be > improved by doing the first addition using '+' and the rest using '+=', > without changing the behavior. But that would change the behaviour. The __iadd__ method is not the same as the __add__ method, and you can't guarantee that they will behave the same -- or even similarly. And what about tuples? And subclasses of list/tuples? How many different types need to be optimized? In practical terms, does anyone actually ever use sum on more than a handful of lists? I don't believe this is more than a hypothetical problem. The primary use case for sum is adding numbers when floating point accuracy is not critical. If you need float accuracy, use math.fsum. If you need to add more than a handful of small lists, don't use sum: just calling extend in a loop is probably fast enough, or use itertools.chain. Trying to turn sum into an all-singing all-dancing function optimised for an ever-increasing number of objects is a fool's errand. The implementation of sum in C is already complex enough: 95 lines, excluding comments, blanks and braces, for something which is a lightweight function with very simple semantics. But if anyone wants to submit a patch to the bug tracker, go right ahead. Without a patch though, I'd say that Python-Dev will consider this a non- issue. -- Steven From jason.scheirer at gmail.com Sun Mar 28 23:16:43 2010 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Sun, 28 Mar 2010 20:16:43 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Message-ID: <03f8158f-cc4e-4e98-a45a-d0749030e877@w29g2000prg.googlegroups.com> On Mar 28, 7:14?pm, KB wrote: > Hi there, > > I have in the past used PythonWin to write python for COM, and > switched to Eclipse. > > I am getting an error from the IDE saying it does not recognise > CoInitialize(): > > **** > import pythoncom > > pythoncom.CoInitialize() > pythoncom.CoUninitialize() > **** > > (red X next to the two bottom lines saying: "Undefined variable from > import: CoInitialize") > > If I open a PyDev/Python Console window in Eclipse, I can type the > above, no errors, no problem. > > I tried removing my Python Interpreter and re-adding/re-building but > no change. > > python 2.5.2 > eclipse 3.5.1 > pydev 1.5.0 > > Thanks! PyDev is probably only looking at functions/classes defined in Python source files and not ones defined in C extensions. To confirm, try typing this in the window: import _ctypes _ctypes._Pointer() If it says that _ctypes._Pointer doesn't exist, then that's obviously the problem. From dieterv at optionexplicit.be Mon Mar 29 01:59:24 2010 From: dieterv at optionexplicit.be (Dieter Verfaillie) Date: Mon, 29 Mar 2010 07:59:24 +0200 Subject: pythoncom.CoInitialize() not recognised in Eclipse In-Reply-To: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Message-ID: <20100329075924.64164i05fobzkdrw@webmail.linuxsystems.be> Quoting KB : > I am getting an error from the IDE saying it does not recognise > CoInitialize(): > > **** > import pythoncom > > pythoncom.CoInitialize() > pythoncom.CoUninitialize() > **** It works out of the box with PyDev 1.5.5.2010030420 on Eclipse 3.5.2 on Windows XP. If nothing seems to work for you, you could try adding pythoncom to the "Forced Builtins" tab of your Python interpreter configuration to see if it helps (restart eclipse after you've done that, sometimes changes to the symbols database don't get picked up without restarting eclipse...) mvg, Dieter ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From gaoxtwarrior at gmail.com Mon Mar 29 02:42:41 2010 From: gaoxtwarrior at gmail.com (Gao) Date: Mon, 29 Mar 2010 14:42:41 +0800 Subject: How to verify a signature using SHA1WithRSA with python Message-ID: I have a public key, and I want to write a method that verify a string which is a signature signed by this public key's private key. And is M2Crypto I can't find algorithm named "SHA1WithRSA" or so . Could anyone help me? From alfps at start.no Mon Mar 29 03:34:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 29 Mar 2010 09:34:07 +0200 Subject: sum for sequences? In-Reply-To: References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: * Steven D'Aprano: > On Sun, 28 Mar 2010 18:56:26 +0200, Alf P. Steinbach wrote: > >> From a more practical point of view, the sum efficiency could be >> improved by doing the first addition using '+' and the rest using '+=', >> without changing the behavior. > > But that would change the behaviour. The __iadd__ method is not the same > as the __add__ method, and you can't guarantee that they will behave the > same -- or even similarly. Hm, I don't think it's documented (except if the reference implementation serves as documentation) which one is currently used. > And what about tuples? And subclasses of list/tuples? How many different > types need to be optimized? Point. One would need to check for availability of '+='. > In practical terms, does anyone actually ever use sum on more than a > handful of lists? I don't believe this is more than a hypothetical > problem. Agreed. Cheers, - Alf From vamsi2123.vgn at gmail.com Mon Mar 29 03:37:44 2010 From: vamsi2123.vgn at gmail.com (vamsi.v) Date: Mon, 29 Mar 2010 13:07:44 +0530 Subject: header intact Message-ID: > > confirm bec6a35eaf702fee07b1542f90784d939bbbebff > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Mon Mar 29 03:41:23 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 29 Mar 2010 19:41:23 +1200 Subject: GIF89A and PIL In-Reply-To: <2010032719445464825-aptshansen@gmailinvalid> References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: <81b39uFggeU1@mid.individual.net> Stephen Hansen wrote: > So I wonder if there's just some hyper-optimization Photoshop does that > PIL can't round-trip. You may find that PIL isn't bothering to compress at all, or only doing it in a very simpleminded way. -- Greg From stephane at harobed.org Mon Mar 29 04:12:09 2010 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Mon, 29 Mar 2010 10:12:09 +0200 Subject: =?windows-1252?Q?I=27m_looking_for_html_cleaner=2E_Exa?= =?windows-1252?Q?mple_=3A_convert_=3Ch1=3E=3Cspan=3E=3Cfont=3Emy_?= =?windows-1252?Q?title=3C/font=3E=3C/span=3E=3C/h1=3E_=3D=3E_=3Ch1=3E?= =?windows-1252?Q?my_title=3C/h1=3E=85?= Message-ID: Hi, I work on HTML cleaner. I export OpenOffice.org documents to HTML. Next, I would like clean this HTML export files : * remove comment * remove style * remove dispensable tag * ... some difficulty : * convert

my text foo bar

=>

my text foo par

* convert

my title

=>

my title

to do this process, I use lxml and pyquery. Question : * are there some xml helper tools in Python to do this process ? I've looked for in pypi, I found nothing about it If you confirm than this tools don't exists, I'll maybe publish a helper package to do this "clean" processing. Thanks for your help, Stephane From v.harishankar at gmail.com Mon Mar 29 05:09:42 2010 From: v.harishankar at gmail.com (Harishankar) Date: Mon, 29 Mar 2010 09:09:42 +0000 (UTC) Subject: I'm looking for html cleaner. Example : convert

my title

=>

my =?windows-1251?q?title=3C=2Fh1=3E=85?= References: Message-ID: On Mon, 29 Mar 2010 10:12:09 +0200, St?phane Klein wrote: > Hi, > > I work on HTML cleaner. > > I export OpenOffice.org documents to HTML. Next, I would like clean this > HTML export files : > > * remove comment > * remove style > * remove dispensable tag > * ... > > some difficulty : > > * convert

my text foo bar

=>

my text foo par

> * convert

my title

=>

my > title

> > to do this process, I use lxml and pyquery. > > Question : > > * are there some xml helper tools in Python to do this process ? I've > looked for in pypi, I found nothing about it > > If you confirm than this tools don't exists, I'll maybe publish a helper > package to do this "clean" processing. > > Thanks for your help, > Stephane Take a look at htmllib and HTMLParser (two different modules) in the Python built-in library. In Python 3.x there is one called html.parser You can use this to parse out specific tags from HTML documents. If you want something more advanced, consider using XML. -- Harishankar (http://harishankar.org http://literaryforums.org) From pieter.cogghe at gmail.com Mon Mar 29 05:39:05 2010 From: pieter.cogghe at gmail.com (Yuccaplant) Date: Mon, 29 Mar 2010 02:39:05 -0700 (PDT) Subject: refer to self in a decorator on a class method Message-ID: Hi all, I would like to do something like this: ******************** class HelloWorld (object): def __init__(self,clk): self.clk = clk @always(self.clk.posedge) def sayHello(self): print "%s Hello World!" % now() ******************** Problem is however I can't refer to self in the decorator call. Is there any workarround? thanks a lot, pieter From __peter__ at web.de Mon Mar 29 05:53:51 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Mar 2010 11:53:51 +0200 Subject: refer to self in a decorator on a class method References: Message-ID: Yuccaplant wrote: > Hi all, > > I would like to do something like this: > > ******************** > class HelloWorld (object): > > def __init__(self,clk): > self.clk = clk > > @always(self.clk.posedge) > def sayHello(self): > print "%s Hello World!" % now() > ******************** > > Problem is however I can't refer to self in the decorator call. Is > there any workarround? Pass attribute names: >>> def always(name): ... def always(f): ... def wrapper(self, *args, **kw): ... print attrgetter(name)(self) ... return f(self, *args, **kw) ... return wrapper ... return always ... >>> from operator import attrgetter >>> class A(object): ... def __init__(self, clk): ... self.clk = clk ... @always("clk.posedge") ... def hello(self): ... print "hello world" ... >>> class clk: ... posedge = 42 ... >>> A(clk).hello() 42 hello world There may be better ways depending on your usecase. Peter From cournape at gmail.com Mon Mar 29 06:06:53 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 29 Mar 2010 19:06:53 +0900 Subject: Have you embraced Python 3.x yet? In-Reply-To: <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> Message-ID: <5b8d13221003290306n7580c5dey8111071fbb4c073c@mail.gmail.com> On Sat, Mar 27, 2010 at 5:26 AM, Chris Colbert wrote: > > I won't switch until NumPy and SciPy make the jump. We're almost there, though (mostly thanks to other people's work on Numpy): http://github.com/cournape/scipy3/branches/py3k David From dr.mtarver at ukonline.co.uk Mon Mar 29 06:46:10 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Mon, 29 Mar 2010 03:46:10 -0700 (PDT) Subject: the Python Foundation References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: <63099700-c0a0-4d9c-b1f1-e872fe52f0cf@y17g2000yqd.googlegroups.com> On 24 Mar, 22:18, "Steve Holden, Chairman, PSF" wrote: > MarkTarver wrote: > >>From the website > > > The Python Software Foundation (PSF) is a 501(c)(3) non-profit > > corporation that > > holds the intellectual property rights behind the Python programming > > language. We manage the open source licensing for Python version 2.1 > > and later and own and protect the trademarks associated with Python. > > > Could somebody explain 'what holding the intellectual property rights' > > means in this context and in what sense PSF manages the licensing and > > protects the trademarks associated with Python? ? This is for my > > education. > > The PSF requires that contributors sign an agreement licensing their > code to us, and allowing us to distribute it under the license of our > choosing (this does not in any way preclude the contributor licensing > the same code to any other party under different terms). > > In this way people who use Python can be relatively sure that the code > is untrammeled by claims of copyright or patent by anyone other than the > PSF, and can therefore use it without fear of losing their rights to do > so because of legal action by third parties. > > We have also registered the trademark "Python" for use in reference to > computer programming languages, thereby ensuring that we can take action > should some ill-advised individual or organization decide to produce > another language with "Python" in its name which we did not feel > conformed sufficiently strictly to the language definition, for instance. > > The PSF has an established policy with regard to the use of its > trademarks, which you can read at > > ?http://www.python.org/psf/trademarks/ > > regards > ?Steve > -- > Steve Holden ? ? ? ?Chairman, Python Software Foundation > See PyCon Talks from Atlanta 2010 ?http://pycon.blip.tv/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ Thankyou to all on this thread for this clarification. I may return and ask some questions if I need further clarification. Mark From pon at iki.fi Mon Mar 29 07:13:49 2010 From: pon at iki.fi (Pasi Oja-Nisula) Date: 29 Mar 2010 11:13:49 GMT Subject: Python magazine Message-ID: Python magazine web site says this: "So, sit back and relax - enjoy your holidays, and come see us again on January 26th, when the new PyMag will launch." Anyone heard any rumours or anything? I quite liked the magazine. Pasi From 1234567890 at vanwingerde.net Mon Mar 29 08:11:57 2010 From: 1234567890 at vanwingerde.net (Jaap van Wingerde) Date: Mon, 29 Mar 2010 05:11:57 -0700 (PDT) Subject: Python magazine References: Message-ID: <88f34d4c-b620-4d8e-9e02-4c42384735b6@35g2000yqm.googlegroups.com> On 29 mrt, 13:13, Pasi Oja-Nisula wrote: > Python magazine web site says this: > "So, sit back and relax - enjoy your holidays, and come see us again on > January 26th, when the new ?PyMag will launch." From ben+python at benfinney.id.au Mon Mar 29 08:43:29 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Mar 2010 23:43:29 +1100 Subject: Have you embraced Python 3.x yet? References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> Message-ID: <878w9bnvri.fsf@benfinney.id.au> David Cournapeau writes: > On Sat, Mar 27, 2010 at 5:26 AM, Chris Colbert wrote: > > I won't switch until NumPy and SciPy make the jump. > > We're almost there, though (mostly thanks to other people's work on > Numpy): > > http://github.com/cournape/scipy3/branches/py3k Are you maintaining separate parallel Python 3 versus Python 2 code bases? If not, what are you doing in that regard? -- \ ?The most common way people give up their power is by thinking | `\ they don't have any.? ?Alice Walker | _o__) | Ben Finney From cournape at gmail.com Mon Mar 29 08:58:17 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 29 Mar 2010 21:58:17 +0900 Subject: Have you embraced Python 3.x yet? In-Reply-To: <878w9bnvri.fsf@benfinney.id.au> References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> <878w9bnvri.fsf@benfinney.id.au> Message-ID: <5b8d13221003290558w18fa6c94s4605189382148366@mail.gmail.com> On Mon, Mar 29, 2010 at 9:43 PM, Ben Finney wrote: > David Cournapeau writes: > >> On Sat, Mar 27, 2010 at 5:26 AM, Chris Colbert wrote: >> > I won't switch until NumPy and SciPy make the jump. >> >> We're almost there, though (mostly thanks to other people's work on >> Numpy): >> >> http://github.com/cournape/scipy3/branches/py3k > > Are you maintaining separate parallel Python 3 versus Python 2 code > bases? No, we don't have the manpower to have two code bases - the C code handles both versions, and the python 2 code is converted to python 3 "on the fly". We are lucky not to have too much IO / string handling, which are the hard things to handle with 2to3. The hard part was NumPy, because it used the python C api so much. Porting scipy to something somewhat usable was an half-day job, cheers, David From wolftracks at invalid.com Mon Mar 29 09:04:17 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 29 Mar 2010 06:04:17 -0700 Subject: Why this Difference in Importing NumPy 1.2 vs 1.4? In-Reply-To: References: Message-ID: Add/Remove under Control Panel. It's a numpy problem. On 3/28/2010 9:20 AM, W. eWatson wrote: > I wrote a program in Python 2.5 under Win7 and it runs fine using Numpy > 1.2 , but not on a colleague's machine who has a slightly newer 2.5 and > uses NumPy 1.4. We both use IDLE to execute the program. During import > he gets this: > > >>> > Traceback (most recent call last): > File "C:\Documents and Settings\HP_Administrator.DavesDesktop\My > Documents\Astro\Meteors\NC-FireballReport.py", line 38, in > from scipy import stats as stats # scoreatpercentile > File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in > > from stats import * > File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in > > import scipy.special as special > File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, > in > from numpy.testing import NumpyTest > ImportError: cannot import name NumpyTest > >>> > > Comments? > > It looks as though the problem is in NumPy 1.4. If it's either in NumPy > or SciPy, how does my colleague back out to an earlier version to agree > with mine? Does he just pull down 1.3 or better 1.2 (I use it.), and > install it? How does he somehow remove 1.4? Is it as easy as going to > IDLE's path browser and removing, under site-packages, numpy? (I'm not > sure that's even possible. I don't see a right-click menu.) From slais-www at ucl.ac.uk Mon Mar 29 09:09:48 2010 From: slais-www at ucl.ac.uk (djc) Date: Mon, 29 Mar 2010 14:09:48 +0100 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: Mensanator wrote: > On Mar 26, 2:44 pm, Phlip wrote: >> On Mar 26, 6:14 am, Luis M. Gonz?lez wrote: >> >>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >>> Monkeys everywhere. >>> Sorry for the off topic question, but what does "monkey" mean in a >>> nerdy-geek context?? >>> Luis >> Better at typing than thinking. > > Really? I thought it was more of a reference to Eddington, i.e., given > enough time even a monkey can type out a program. Precisely, given infinite typing and zero thinking... Note also the expression 'talk to the organ grinder not the monkey' and 'a trained monkey could do it' and then there are monkey wrenches, and monkey bikes... and never call the Librarian a monkey -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 29 09:22:06 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 29 Mar 2010 15:22:06 +0200 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: <4bb0a951$0$11311$426a34cc@news.free.fr> djc a ?crit : > > and never call the Librarian a monkey ook ?!? From krister.svanlund at gmail.com Mon Mar 29 09:32:08 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 29 Mar 2010 15:32:08 +0200 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: <2cf430a61003290632k1e40eb81r38e8b0a67d6eb3a8@mail.gmail.com> On Mon, Mar 29, 2010 at 3:09 PM, djc wrote: > Mensanator wrote: >> On Mar 26, 2:44 pm, Phlip wrote: >>> On Mar 26, 6:14 am, Luis M. Gonz?lez wrote: >>> >>>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >>>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >>>> Monkeys everywhere. >>>> Sorry for the off topic question, but what does "monkey" mean in a >>>> nerdy-geek context?? >>>> Luis >>> Better at typing than thinking. >> >> Really? I thought it was more of a reference to Eddington, i.e., given >> enough time even a monkey can type out a program. > > > Precisely, given infinite typing and zero thinking... > > Note also the expression 'talk to the organ ?grinder not the monkey' > > and 'a trained monkey could do it' > > and then there are monkey wrenches, and monkey bikes... > > and never call the Librarian a monkey > The monkeys comes from different places... for example: "The term monkey patch was first used as guerrilla patch, [...], which was referred to as the patches engaging in battle with each other. Since the word guerrilla and gorilla are near-homophones, people started using the incorrect term gorilla patch instead of guerrilla patch. When a developer then created a guerrilla patch they tried very hard to avoid any battles that may ensue due to the patch and the term monkey patch was coined to make the patch sound less forceful." And then there is, as said, monkey wrenches which is utility tools. Codemonkeys, i believe, comes from the infinite monkeys theory. From pierre.gaillard at gmail.com Mon Mar 29 09:44:51 2010 From: pierre.gaillard at gmail.com (Pierre) Date: Mon, 29 Mar 2010 06:44:51 -0700 (PDT) Subject: Matplotlib patches collection + alpha face Message-ID: <7727f7e7-6337-4107-92c3-f5cfb2e90772@q15g2000yqj.googlegroups.com> Hello, I would like to draw on the same axes several patches (rectangle) with different alpha-face (transparency)... Anyone has an idea ? In particular, I would like to use the class PatchCollection but it seems that the alpha property is common to all the patches... Thanks for your help. From debatem1 at gmail.com Mon Mar 29 10:01:28 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 29 Mar 2010 10:01:28 -0400 Subject: How to verify a signature using SHA1WithRSA with python In-Reply-To: References: Message-ID: On Mon, Mar 29, 2010 at 2:42 AM, Gao wrote: > I have a public key, and I want to write a method that verify a string which > is a signature signed by this public key's private key. And is M2Crypto I > can't find algorithm named "SHA1WithRSA" or so . Could anyone help me? > -- > http://mail.python.org/mailman/listinfo/python-list > In OpenSSL you would simply use the EVP_Verify* functions, I don't see that in M2Crypto's documentation though. You may have to use RSA_Verify. If you're not forced to use M2Crypto, you *may* want to check out evpy, which is a set of ctypes bindings for openssl's evp interface and a very easy to use wrapper. It's available at http://gitorious.org/evpy, and will be up for a first release in a few weeks. Geremy Condra From pmaupin at gmail.com Mon Mar 29 10:40:54 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 07:40:54 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> On Mar 28, 9:45?pm, Steven D'Aprano wrote: > And what about tuples? And subclasses of list/tuples? How many different > types need to be optimized? One of the beautiful things about Python is that, for most things, there are few surprises for even new users. "There should be one obvious way to do it" for the user means that, sometimes, under the hood, there are a lot of special cases for the implementers. > In practical terms, does anyone actually ever use sum on more than a > handful of lists? I don't believe this is more than a hypothetical > problem. Right now, it's probably not, because when somebody sums a large list and gets thwacked on the head by the lack of efficiency, they then come here and get thwacked because "everybody knows" they should user itertools or something else; not sum(). > > The primary use case for sum is adding numbers when floating point > accuracy is not critical. If you need float accuracy, use math.fsum. See, I think the very existence of math.fsum() already violates "there should be one obvious way to do it." > But if anyone wants to submit a patch to the bug tracker, go right ahead. > Without a patch though, I'd say that Python-Dev will consider this a non- > issue. Agreed. Wish I had the time to do this sort of cleanup. Regards, Pat From showell30 at yahoo.com Mon Mar 29 11:12:00 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 08:12:00 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> Message-ID: <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> On Mar 29, 7:40?am, Patrick Maupin wrote: > On Mar 28, 9:45?pm, Steven D'Aprano > > wrote: > > And what about tuples? And subclasses of list/tuples? How many different > > types need to be optimized? > > One of the beautiful things about Python is that, for most things, > there are few surprises for even new users. ?"There should be one > obvious way to do it" for the user means that, sometimes, under the > hood, there are a lot of special cases for the implementers. > If nothing else, I think it's reasonably for users to expect symmetry. If you can use "+" to concatentate lists, then it seems reasonable that something spelled "sum" would concatenate lists as well, and in reasonable time. > > In practical terms, does anyone actually ever use sum on more than a > > handful of lists? I don't believe this is more than a hypothetical > > problem. > > Right now, it's probably not, because when somebody sums a large list > and gets thwacked on the head by the lack of efficiency, they then > come here and get thwacked because "everybody knows" they should user > itertools or something else; not sum(). > Indeed. It would be nice if the docs for sum() at least pointed to list(itertools.chain(list_of_lists)), or whatever the most kosher alternative is supposed to be. It only takes a handful of sublists, about ten on my box, to expose the limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's under the hood. It only takes 200 sublists to start getting a 10x degradation in performance. > > The primary use case for sum is adding numbers when floating point > > accuracy is not critical. If you need float accuracy, use math.fsum. > > See, I think the very existence of math.fsum() already violates "there > should be one obvious way to do it." > The nice thing about math.fsum() is that it is at least documented from sum(), although I suspect some users try sum() without even consulting the docs. You could appease all users with an API where the most obvious choice, sum(), never behaves badly, and where users can still call more specialized versions (math.fsum() and friends) directly if they know what they are doing. This goes back to the statement that Patrick makes--under the hood, this means more special cases for implementers, but fewer pitfalls for users. From gareth.sims at googlemail.com Mon Mar 29 11:31:46 2010 From: gareth.sims at googlemail.com (Gryff) Date: Mon, 29 Mar 2010 08:31:46 -0700 (PDT) Subject: Newbie question: Tuples and reading csv files Message-ID: Hi Its been 20 years since I programmed, so I'm stepping back in via Python. However I'm beating my brains on tuples/lists (what I used to know as arrays). I've fooled around with small code snippets and tried a few things, but I can't figure out how to grab elements of tuples ... For example, I'm reading in a small csv file like this: import csv csvfile = open("example.csv") #sniff the dialect dialect = csv.Sniffer().sniff(csvfile.read(1024)) csvfile.seek(0) # get file in using reader method mylist=[] reader = csv.reader(csvfile, dialect) # grab the lines into a reader and pass to mylist for row in reader: mylist.append(row) # now print something out to prove this worked print mylist[:3] and the output I get is: ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'] ['2010-03-05', '224.20', '230.70', '223.80', '228.30', '5051500', '228.30'] ['2010-03-04', '223.00', '228.50', '220.50', '224.50', '4040500', '224.50'] So far so good but not useful. My "mylist" has all the data in there, but I can only figure out how to get each line out!?! -> I want to get access to the individual items in each line. In my bad old days I'd have used an array and grabbed "mylist [row,item]" ...job done. Try as I like and after *lots* of reading around, I can't figure out whether: a) I'm missing something...really...simple b) "You can't do that" (and I should just use numpy and arrays?) c) errrr.... Like I said, basic/newbie question from a programmer who spent 20 years away from it. Cheers Gareth From showell30 at yahoo.com Mon Mar 29 11:34:32 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 08:34:32 -0700 (PDT) Subject: Newbie question: Tuples and reading csv files References: Message-ID: <029f4a90-fbe5-4739-9c1d-f048046e4d9f@k5g2000prg.googlegroups.com> On Mar 29, 8:31?am, Gryff wrote: > Hi > > Its been 20 years since I programmed, so I'm stepping back in via > Python. However I'm beating my brains on tuples/lists (what I used to > know as arrays). I've fooled around with small code snippets and tried > a few things, but I can't figure out how to grab elements of > tuples ... > > For example, I'm reading in a small csv file like this: > > import csv > > csvfile = open("example.csv") > > #sniff the dialect > dialect = csv.Sniffer().sniff(csvfile.read(1024)) > csvfile.seek(0) > > # get file in using reader method > > mylist=[] > reader = csv.reader(csvfile, dialect) > > # grab the lines into a reader and pass to mylist > > for row in reader: > > ? ? mylist.append(row) > > # now print something out to prove this worked > > print mylist[:3] > > and the output I get is: > > ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'] > ['2010-03-05', '224.20', '230.70', '223.80', '228.30', '5051500', > '228.30'] > ['2010-03-04', '223.00', '228.50', '220.50', '224.50', '4040500', > '224.50'] > > So far so good but not useful. My "mylist" has all the data in there, > but I can only figure out how to get each line out!?! > -> I want to get access to the individual items in each line. In my > bad old days I'd have used an array and grabbed "mylist > [row,item]" ...job done. You are not too far: mylist[row][item] If you try that and still get an error (unlikely), be sure to post the exact code you tried and any error messages. From kushal.kumaran+python at gmail.com Mon Mar 29 11:42:37 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 29 Mar 2010 21:12:37 +0530 Subject: Newbie question: Tuples and reading csv files In-Reply-To: References: Message-ID: <1e364c4e1003290842q1b0f65a4kc09faae19a40f097@mail.gmail.com> On Mon, Mar 29, 2010 at 9:01 PM, Gryff wrote: > Hi > > Its been 20 years since I programmed, so I'm stepping back in via > Python. However I'm beating my brains on tuples/lists (what I used to > know as arrays). I've fooled around with small code snippets and tried > a few things, but I can't figure out how to grab elements of > tuples ... > > For example, I'm reading in a small csv file like this: > > import csv > > csvfile = open("example.csv") > > #sniff the dialect > dialect = csv.Sniffer().sniff(csvfile.read(1024)) > csvfile.seek(0) > > # get file in using reader method > > mylist=[] > reader = csv.reader(csvfile, dialect) > > # grab the lines into a reader and pass to mylist > > for row in reader: > > ? ?mylist.append(row) > > # now print something out to prove this worked > > print mylist[:3] > > and the output I get is: > > ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'] > ['2010-03-05', '224.20', '230.70', '223.80', '228.30', '5051500', > '228.30'] > ['2010-03-04', '223.00', '228.50', '220.50', '224.50', '4040500', > '224.50'] > > So far so good but not useful. My "mylist" has all the data in there, > but I can only figure out how to get each line out!?! > -> I want to get access to the individual items in each line. In my > bad old days I'd have used an array and grabbed "mylist > [row,item]" ...job done. Try as I like and after *lots* of reading > around, I can't figure out whether: > mylist is a list of lists. mylist[0] gives you the first list (the row with the column headings, in your case). You can get the first item in that list by mylist[0][0]. > a) I'm missing something...really...simple > b) "You can't do that" ?(and I should just use numpy and arrays?) > c) errrr.... > > Like I said, basic/newbie question from a programmer who spent 20 > years away from it. > -- regards, kushal From patentsvnc at gmail.com Mon Mar 29 11:50:20 2010 From: patentsvnc at gmail.com (Den) Date: Mon, 29 Mar 2010 08:50:20 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <5ad930bd-131a-4b7d-99ea-e3258f75449e@a16g2000pre.googlegroups.com> On Mar 26, 6:14?am, Luis M. Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? > > Luis To go even more off topic, I remember Trunk Monkey commercials. Also, I remember a web site whose intentions was to simulate monkeys typing Shakespeare. They had set up a distributed system where you could contribute your computer to providing random characters, which they compared to a selected set of Shakespeare's plays. Just before the site disappeared (or I lost track of it), they had received strings representing the first maybe 15 or 20 characters of several plays. Den From gareth.sims at googlemail.com Mon Mar 29 11:51:25 2010 From: gareth.sims at googlemail.com (Gryff) Date: Mon, 29 Mar 2010 08:51:25 -0700 (PDT) Subject: Newbie question: Tuples and reading csv files References: <029f4a90-fbe5-4739-9c1d-f048046e4d9f@k5g2000prg.googlegroups.com> Message-ID: *tada!* *enlightenment* Thanks - I figured it was something simple.... :-) From tim at johnsons-web.com Mon Mar 29 12:40:23 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 29 Mar 2010 11:40:23 -0500 Subject: Jython as an alternative to Python Message-ID: FYI: I've used python for years primarily on *nix platforms and primarily for web programming. I'm considering studying a scripting language that uses and accesses java. My first obvious choice would by jython. The following questions could probably be answered by pointers to previous discussions, docs or blogs. 1)What can jython *do* that cannot be done by python. 2)What is the current state of jython as a development community? I.E. is it being upgraded, updated etc. 3)Is the jython community "bound to" the python community? I.E. I don't think python is going to "go away", what happens if jython development "stalls". 4)If someone in this community would consider a java scripting language other than jython, what would it be? And why? 5)Are there issues installing and deploying jython on shared webservers? I.E. Assuming that a dedicated server is one that I have full access to and can install what I please, and a shared server would not afford me such access; is there any trend for "server farms" to install jython? Thanks -- Tim tim at johnsons-web.com http://www.akwebsoft.com From keith at nekotaku.com Mon Mar 29 13:16:40 2010 From: keith at nekotaku.com (KB) Date: Mon, 29 Mar 2010 10:16:40 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> <03f8158f-cc4e-4e98-a45a-d0749030e877@w29g2000prg.googlegroups.com> Message-ID: <9e8fc13f-f8f2-4efa-8900-d19e228f0c99@t9g2000prh.googlegroups.com> On Mar 28, 8:16?pm, Jason Scheirer wrote: > On Mar 28, 7:14?pm, KB wrote: > > > > > Hi there, > > > I have in the past used PythonWin to write python for COM, and > > switched to Eclipse. > > > I am getting an error from the IDE saying it does not recognise > > CoInitialize(): > > > **** > > import pythoncom > > > pythoncom.CoInitialize() > > pythoncom.CoUninitialize() > > **** > > > (red X next to the two bottom lines saying: "Undefined variable from > > import: CoInitialize") > > > If I open a PyDev/Python Console window in Eclipse, I can type the > > above, no errors, no problem. > > > I tried removing my Python Interpreter and re-adding/re-building but > > no change. > > > python 2.5.2 > > eclipse 3.5.1 > > pydev 1.5.0 > > > Thanks! > > PyDev is probably only looking at functions/classes defined in Python > source files and not ones defined in C extensions. > > To confirm, try typing this in the window: > > import _ctypes > _ctypes._Pointer() > > If it says that _ctypes._Pointer doesn't exist, then that's obviously > the problem. No problems at all with the editor recognising the above. Also note that I tried the pythoncom snippet in my OP from the IDE's python console without issue... weird. From keith at nekotaku.com Mon Mar 29 13:50:18 2010 From: keith at nekotaku.com (KB) Date: Mon, 29 Mar 2010 10:50:18 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Message-ID: On Mar 28, 10:59?pm, "Dieter Verfaillie" wrote: > Quoting KB : > > > I am getting an error from the IDE saying it does not recognise > > CoInitialize(): > > > **** > > import pythoncom > > > pythoncom.CoInitialize() > > pythoncom.CoUninitialize() > > **** > > It works out of the box with PyDev 1.5.5.2010030420 on Eclipse 3.5.2 ? > on Windows XP. If nothing seems to work for you, you could try adding ? > pythoncom to the > "Forced Builtins" tab of your Python interpreter configuration to see if it > helps (restart eclipse after you've done that, sometimes changes to ? > the symbols > database don't get picked up without restarting eclipse...) Dieter, Thanks, I tried updating my PyDev and Eclipse to your versions. Still same issue. How exactly would I add pythoncom to the Forced Builtins ? I tried simply adding "pythoncom" to the Forced Builtin's tab but no change. Any suggestions? From steve at holdenweb.com Mon Mar 29 14:02:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Mar 2010 14:02:04 -0400 Subject: Jython as an alternative to Python In-Reply-To: References: Message-ID: Tim Johnson wrote: > FYI: I've used python for years primarily on *nix platforms and > primarily for web programming. I'm considering studying a scripting > language that uses and accesses java. My first obvious choice would by > jython. The following questions could probably be answered by pointers > to previous discussions, docs or blogs. > > 1)What can jython *do* that cannot be done by python. > Import Java classes and instantiate them, calling their methods from Python. > 2)What is the current state of jython as a development community? > I.E. is it being upgraded, updated etc. > It's currently just about at 2.6, and the developers are committed to a port to 3.x (probably 3.2, I suspect) but haven't yet committed to a timescale. Two of the main developers have just started work at Sauce Labs, and this may affect their availability. > 3)Is the jython community "bound to" the python community? > I.E. I don't think python is going to "go away", what happens if > jython development "stalls". > The PSF has already once provided a grant to keep Jython moving forward when it looked like it might stall. I don't know whether this is inevitable in the future, but *I* think Jython should be kept in the mainstream. > 4)If someone in this community would consider a java scripting language > other than jython, what would it be? And why? > Pass. > 5)Are there issues installing and deploying jython on shared webservers? > I.E. Assuming that a dedicated server is one that I have full access to and > can install what I please, and a shared server would not afford me > such access; is there any trend for "server farms" to install jython? I don't know. A survey of Python-friendly hosting companies would be useful. You could use http://wiki.python.org/moin/PythonHosting as a starting point, and publish the data you discover. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From gagsl-py2 at yahoo.com.ar Mon Mar 29 15:19:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Mar 2010 16:19:18 -0300 Subject: Super() function References: <4BAAD5E0.9050604@googlemail.com> <4BAE359F.6090200@googlemail.com> Message-ID: En Sun, 28 Mar 2010 21:58:07 -0300, Delaney, Timothy (Tim) escribi?: >> Gabriel Genellina wrote: >>> Alan Harris-Reid escribi?: >>> >>>> Using Python 3.1, I sometimes use the super() function to call the >>>> equivalent method from a parent class, for example >>>> >>>> def mymethod(self): >>>> super().mymethod() >>>> some more code... >>> >>> This recipe does what you want: >>> http://code.activestate.com/recipes/286195-selfsuper/ > If you think the pure-python version of the recipe is complicated, you > should have > a look at the performance-optimised Pyrex version ;) Where can we look at it? The link in the activestate recipe does not work anymore :( -- Gabriel Genellina From tim at johnsons-web.com Mon Mar 29 15:40:22 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 29 Mar 2010 14:40:22 -0500 Subject: Jython as an alternative to Python References: Message-ID: On 2010-03-29, Steve Holden wrote: > Tim Johnson wrote: <<.>> 1)What can jython *do* that cannot be done by python. >> > Import Java classes and instantiate them, calling their methods from Python. Of course >> 2)What is the current state of jython as a development community? >> I.E. is it being upgraded, updated etc. >> > It's currently just about at 2.6, and the developers are committed to a > port to 3.x (probably 3.2, I suspect) but haven't yet committed to a > timescale. Two of the main developers have just started work at Sauce > Labs, and this may affect their availability. That is the news I was looking for. >> 3)Is the jython community "bound to" the python community? >> I.E. I don't think python is going to "go away", what happens if >> jython development "stalls". >> > The PSF has already once provided a grant to keep Jython moving forward > when it looked like it might stall. I don't know whether this is > inevitable in the future, but *I* think Jython should be kept in the > mainstream. Ditto. >> 4)If someone in this community would consider a java scripting language >> other than jython, what would it be? And why? >> > Pass. . I've looked at clojure and kawa since I have a comfort level with lisp dialects, but clojure seems pretty proprietory (and thus exotic). kawa advertises that it complies with the general scheme specification. And I'm a little leery about the 'exotic' since I already use two 'exotic' server - side languages. >> 5)Are there issues installing and deploying jython on shared webservers? >> I.E. Assuming that a dedicated server is one that I have full access to and >> can install what I please, and a shared server would not afford me >> such access; is there any trend for "server farms" to install jython? > > I don't know. A survey of Python-friendly hosting companies would be > useful. You could use Not really a big deal with me, as I work primarily with dedicated servers, but .... > http://wiki.python.org/moin/PythonHosting Not much there. I will look further, given time, I note the googling "jython friendly hostings" shows this thread at the top :) I appreciate the reply. thanks -- Tim tim at johnsons-web.com http://www.akwebsoft.com From christos.jonathan.hayward at gmail.com Mon Mar 29 15:41:15 2010 From: christos.jonathan.hayward at gmail.com (Jonathan Hayward) Date: Mon, 29 Mar 2010 12:41:15 -0700 (PDT) Subject: "Usability, the Soul of Python" Message-ID: I've posted "Usability, the Soul of Python: An Introduction to the Python Programming Language Through the Eyes of Usability", at: http://JonathansCorner.com/python/ The basic suggestion is that much of what works well in Python has something to do with the usability it offers programmers. Enjoy. -- Jonathan Hayward, christos.jonathan.hayward at gmail.com An Orthodox Christian author: theology, literature, et cetera. My award-winning collection is available for free reading online: I invite you to visit my main site at http://JonathansCorner.com/ From phlip2005 at gmail.com Mon Mar 29 15:45:39 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 29 Mar 2010 12:45:39 -0700 (PDT) Subject: "Usability, the Soul of Python" References: Message-ID: Jonathan Hayward wrote: > I've posted "Usability, the Soul of Python: An Introduction to the > Python Programming Language Through the Eyes of Usability", at: > > ? ?http://JonathansCorner.com/python/ > > The basic suggestion is that much of what works well in Python has > something to do with the usability it offers programmers. You mean like... Order.has_many :line_items ? Oops, sorry, wrong language. My bad! -- Phlip http://zeekland.zeroplayer.com/ From saimapk81 at gmail.com Mon Mar 29 16:07:59 2010 From: saimapk81 at gmail.com (saima81) Date: Mon, 29 Mar 2010 13:07:59 -0700 (PDT) Subject: "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ Message-ID: <26910518-73d6-4fd8-8cdb-9bc862d58beb@a4g2000prb.googlegroups.com> "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ From stefan_ml at behnel.de Mon Mar 29 16:14:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 29 Mar 2010 22:14:22 +0200 Subject: =?windows-1252?Q?Re=3A_I=27m_looking_for_html_cleaner=2E?= =?windows-1252?Q?_Example_=3A_convert_=3Ch1=3E=3Cspan=3E=3Cfont=3E?= =?windows-1252?Q?my_title=3C/font=3E=3C/span=3E=3C/h1=3E_=3D=3E_=3C?= =?windows-1252?Q?h1=3Emy_title=3C/h1=3E=85?= In-Reply-To: References: Message-ID: St?phane Klein, 29.03.2010 10:12: > I work on HTML cleaner. > > I export OpenOffice.org documents to HTML. > Next, I would like clean this HTML export files : > > * remove comment > * remove style > * remove dispensable tag > * ... > > some difficulty : > > * convert

my text foo bar

=>

my text foo par

> * convert

my title

=>

my title

> > to do this process, I use lxml and pyquery. lxml.html has tools for that in the 'clean' module. Just specify the list of tags that you want to discard. > * are there some xml helper tools in Python to do this process ? I've > looked for in pypi, I found nothing about it The HTML tools in the standard library are close to non-existant. You can achieve some things with the builtin tools, but if they fail for a particular input document, there's little you can do. > If you confirm than this tools don't exists, I'll maybe publish a helper > package to do this "clean" processing. Take a look at lxml.html.clean first. Stefan From g.bogle at auckland.no.spam.ac.nz Mon Mar 29 18:31:14 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 30 Mar 2010 11:31:14 +1300 Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: I prefer to think of myself as a code-ape - I look down on code-monkeys. From steve at REMOVE-THIS-cybersource.com.au Mon Mar 29 19:19:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 23:19:28 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> Message-ID: <4bb13580$0$8827$c3e8da3@news.astraweb.com> On Mon, 29 Mar 2010 07:40:54 -0700, Patrick Maupin wrote: > On Mar 28, 9:45?pm, Steven D'Aprano > wrote: >> And what about tuples? And subclasses of list/tuples? How many >> different types need to be optimized? > > One of the beautiful things about Python is that, for most things, there > are few surprises for even new users. "There should be one obvious way > to do it" for the user means that, sometimes, under the hood, there are > a lot of special cases for the implementers. It never ceases to amaze me how often people simply don't understand this. "There should be one obvious way to do it" is the opposite of "NO obvious way", not of "many ways which may or may not be obvious". The complete quote from the Zen makes that clear: There should be one-- and preferably ONLY one --obvious way to do it. [Emphasis added] And don't forget the next line: Although that way may not be obvious at first unless you're Dutch. Python is under no compulsion to make "the obvious way" obvious to anyone except Guido. It's a bonus if it happens to be obvious to newbies, not a requirement. And besides, what is "it" you're talking about? * Adding integers, decimals or fractions, or floats with a low requirement for precision and accuracy? Use sum. * Adding floats with a high requirement for precision and accuracy? Use math.fsum. * Concatenating strings? Use ''.join. * Joining lists? Use [].extend. * Iterating over an arbitrary sequence of arbitrary sequences? Use itertools.chain. That's five different "its", and five obvious ways to do them. >> In practical terms, does anyone actually ever use sum on more than a >> handful of lists? I don't believe this is more than a hypothetical >> problem. > > Right now, it's probably not, because when somebody sums a large list > and gets thwacked on the head by the lack of efficiency, they then come > here and get thwacked because "everybody knows" they should user > itertools or something else; not sum(). Exactly. If you're adding a large number of large lists, you're already doing it wrong. Making sum more efficient is just a band aid. >> The primary use case for sum is adding numbers when floating point >> accuracy is not critical. If you need float accuracy, use math.fsum. > > See, I think the very existence of math.fsum() already violates "there > should be one obvious way to do it." How does the existence of math.fsum contradict the existence of sum? -- Steven From tdelaney at avaya.com Mon Mar 29 19:35:43 2010 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Tue, 30 Mar 2010 07:35:43 +0800 Subject: Super() function In-Reply-To: References: <4BAAD5E0.9050604@googlemail.com><4BAE359F.6090200@googlemail.com> Message-ID: Gabriel Genellina write: > En Sun, 28 Mar 2010 21:58:07 -0300, Delaney, Timothy (Tim) escribi?: >>> Gabriel Genellina wrote: >>>> Alan Harris-Reid escribi?: >>>> >>>>> Using Python 3.1, I sometimes use the super() function to call the >>>>> equivalent method from a parent class, for example >>>>> >>>>> def mymethod(self): >>>>> super().mymethod() >>>>> some more code... >>>> >>>> This recipe does what you want: >>>> http://code.activestate.com/recipes/286195-selfsuper/ >> If you think the pure-python version of the recipe is complicated, you >> should have a look at the performance-optimised Pyrex version ;) > > Where can we look at it? The link in the activestate recipe does not work anymore :( You're right - I've changed ISPs. I'll have to find somewhere else to upload it and change the link. Can't do it today unfortunately. Tim Delaney From no.email at nospam.invalid Mon Mar 29 19:36:17 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 29 Mar 2010 16:36:17 -0700 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: <7xtyryitu6.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > * Iterating over an arbitrary sequence of arbitrary sequences? > Use itertools.chain. chain is only for finite sequences. For arbitrary sequences, use chain.from_iterable. From steve at REMOVE-THIS-cybersource.com.au Mon Mar 29 19:38:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 23:38:53 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> Message-ID: <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> On Mon, 29 Mar 2010 08:12:00 -0700, Steve Howell wrote: > On Mar 29, 7:40?am, Patrick Maupin wrote: >> On Mar 28, 9:45?pm, Steven D'Aprano >> >> wrote: >> > And what about tuples? And subclasses of list/tuples? How many >> > different types need to be optimized? >> >> One of the beautiful things about Python is that, for most things, >> there are few surprises for even new users. ?"There should be one >> obvious way to do it" for the user means that, sometimes, under the >> hood, there are a lot of special cases for the implementers. >> >> > If nothing else, I think it's reasonably for users to expect symmetry. Why? What is symmetry in programming? Since the + operator takes both numbers and lists, and the - operator doesn't, does "symmetry" require that we make up some list operation so that integers and lists are symmetrical? > If you can use "+" to concatentate lists, then it seems reasonable that > something spelled "sum" would concatenate lists as well, and in > reasonable time. Where do you get the "reasonable time" from? A *single* + on lists can be slooooow. Try this: L = [None]*10**9 result = L+L (assuming you've even got enough memory to do so) With a very few exceptions (e.g. dict lookup being "usually" O(1), list append being amortized O(1)), Python makes no promises about performance. It's not part of the language. If you, the programmer, are making any assumptions about performance that aren't clearly and explicitly documented in the official docs, then YOU are at fault, not Python. >> > In practical terms, does anyone actually ever use sum on more than a >> > handful of lists? I don't believe this is more than a hypothetical >> > problem. >> >> Right now, it's probably not, because when somebody sums a large list >> and gets thwacked on the head by the lack of efficiency, they then come >> here and get thwacked because "everybody knows" they should user >> itertools or something else; not sum(). >> >> > Indeed. It would be nice if the docs for sum() at least pointed to > list(itertools.chain(list_of_lists)), or whatever the most kosher > alternative is supposed to be. > > It only takes a handful of sublists, about ten on my box, to expose the > limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's under > the hood. It only takes 200 sublists to start getting a 10x degradation > in performance. And how many times have you needed to add 200 sublists? How many times have you needed to add 10 sublists? Nobody has demonstrated that this is anything more than a hypothetical problem. >> > The primary use case for sum is adding numbers when floating point >> > accuracy is not critical. If you need float accuracy, use math.fsum. >> >> See, I think the very existence of math.fsum() already violates "there >> should be one obvious way to do it." >> >> > The nice thing about math.fsum() is that it is at least documented from > sum(), although I suspect some users try sum() without even consulting > the docs. > > You could appease all users with an API where the most obvious choice, > sum(), never behaves badly, and where users can still call more > specialized versions (math.fsum() and friends) directly if they know > what they are doing. This goes back to the statement that Patrick > makes--under the hood, this means more special cases for implementers, > but fewer pitfalls for users. More special cases for implementers means more bugs in the language, which means I end up writing my own code and ignoring the built-in version anyway. More special cases means I have to pay the cost of high accuracy float summation even when I don't need, or want, it. More special cases means I'm fooled into paying the cost of summing lists when I don't need to, because it's easier than importing itertools: for item in sum(lots_of_lists): pass needlessly creates a large list out of the smaller ones. Even if I don't fall for the temptation, and write bad code, I still pay the cost in the libraries and applications written by others. More special cases isn't free. It's MORE costly than teaching users to use list.extend or itertools.chain. -- Steven From mensanator at aol.com Mon Mar 29 19:59:58 2010 From: mensanator at aol.com (Mensanator) Date: Mon, 29 Mar 2010 16:59:58 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On Mar 29, 5:31?pm, Gib Bogle wrote: > I prefer to think of myself as a code-ape - I look down on code-monkeys. Why? They have prehensile tails. From nagle at animats.com Mon Mar 29 20:30:05 2010 From: nagle at animats.com (John Nagle) Date: Mon, 29 Mar 2010 17:30:05 -0700 Subject: "Usability, the Soul of Python" In-Reply-To: References: Message-ID: <4bb14173$0$1640$742ec2ed@news.sonic.net> Jonathan Hayward wrote: > I've posted "Usability, the Soul of Python: An Introduction to the > Python Programming Language Through the Eyes of Usability", at: > > http://JonathansCorner.com/python/ No, it's just a rather verbose introduction to Python, in dark brown type on a light brown background. One could write a good paper on this topic, but this isn't it. By the same author: "The Case For Uncreative Web Design", which has no examples. John Nagle From nagle at animats.com Mon Mar 29 20:35:09 2010 From: nagle at animats.com (John Nagle) Date: Mon, 29 Mar 2010 17:35:09 -0700 Subject: =?windows-1252?Q?Re=3A_I=27m_looking_for_html_cleaner=2E?= =?windows-1252?Q?_Example_=3A_convert_=3Ch1=3E=3Cspan=3E=3Cfont=3E?= =?windows-1252?Q?my_title=3C/font=3E=3C/span=3E=3C/h1=3E_=3D=3E_=3C?= =?windows-1252?Q?h1=3Emy_title=3C/h1=3E=85?= In-Reply-To: References: Message-ID: <4bb142a4$0$1669$742ec2ed@news.sonic.net> St?phane Klein wrote: > Hi, > > I work on HTML cleaner. > > I export OpenOffice.org documents to HTML. > Next, I would like clean this HTML export files : > > * remove comment > * remove style > * remove dispensable tag > * ... Try parsing with HTML5 Parser ("http://code.google.com/p/html5lib/") which is the closest thing to a good parser available for Python. It's basically a reference implementation of HTML5, including all the handling of bad HTML. Once you have a tree, write something to go through the tree and remove empty tags from a list of tags which do nothing when empty. Then regenerate HTML from the tree. Or just use HTML Tidy: "http://www.w3.org/People/Raggett/tidy/" John Nagle From lxkain at gmail.com Mon Mar 29 20:54:26 2010 From: lxkain at gmail.com (LX) Date: Mon, 29 Mar 2010 17:54:26 -0700 (PDT) Subject: decorators only when __debug__ == True Message-ID: Hi all, I have a question about decorators. I would like to use them for argument checking, and pre/post conditions. However, I don't want the additional overhead when I run in non-debug mode. I could do something like this, using a simple trace example. @decorator def pass_decorator(f, *args, **kw): # what about the slow-down that incurs when using pass_decorator? return f(*args, **kw) @decorator def trace_decorator(f, *args, **kw): print "calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) trace_enable_flag = False #__debug__ trace = trace_decorator if trace_enable_flag else pass_decorator Trouble is, there is still an additional encapsulating function call. Is there any way to eliminate the extra function call altogether? Thanks in advance! From brian at sweetapp.com Mon Mar 29 21:23:12 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 29 Mar 2010 18:23:12 -0700 Subject: xml-rpc In-Reply-To: <4B9C9AF9.80609@gmail.com> References: <4B9C9AF9.80609@gmail.com> Message-ID: <0590084D-BB4A-4D4E-B331-B7F486597A1A@sweetapp.com> On Mar 14, 2010, at 12:14 AM, ahmet erdinc yilmaz wrote: > Hello, > > Recenetly we are developing a senior project and decide to use > xmlrpclib. > However I have some questions. In the documentation I could not find > any clue about > handling requests? Does the server handles each request in a > separate thread? Or is > there some queuing mechanism for client calls? Thanks in advance. By default calls are processed serially. Look for ThreadingMixIn in: http://docs.python.org/library/socketserver.html And maybe read this too: http://code.activestate.com/recipes/81549-a-simple-xml-rpc-server/ Cheers, Brian > > > --erdinc > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Mon Mar 29 21:34:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 02:34:27 +0100 Subject: decorators only when __debug__ == True In-Reply-To: References: Message-ID: <4BB15523.4040901@mrabarnett.plus.com> LX wrote: > Hi all, I have a question about decorators. I would like to use them > for argument checking, and pre/post conditions. However, I don't want > the additional overhead when I run in non-debug mode. I could do > something like this, using a simple trace example. > > > @decorator > def pass_decorator(f, *args, **kw): # what about the slow-down that > incurs when using pass_decorator? > return f(*args, **kw) > > @decorator > def trace_decorator(f, *args, **kw): > print "calling %s with args %s, %s" % (f.func_name, args, kw) > return f(*args, **kw) > > trace_enable_flag = False #__debug__ > trace = trace_decorator if trace_enable_flag else pass_decorator > > > Trouble is, there is still an additional encapsulating function call. > Is there any way to eliminate the extra function call altogether? > Thanks in advance! I think you have misunderstood certain details about decorators. This code with a decorator: @decorator def hello(): print "hello world" basically does this: def hello(): print "hello world" hello = decorator(hello) so your non-decorator just needs to return the function it was passed: def pass_decorator(func): return func and your trace decorator would be something like this: def trace_decorator(func): def show(*args, **kwargs): print "calling %s with args %s, %s" % (func.func_name, args, kwargs) result = func(*args, **kwargs) print "returning %s from %s" % (result, func.func_name) return result return show From showell30 at yahoo.com Mon Mar 29 22:05:30 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 19:05:30 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mar 29, 4:38?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 08:12:00 -0700, Steve Howell wrote: > > On Mar 29, 7:40?am, Patrick Maupin wrote: > >> On Mar 28, 9:45?pm, Steven D'Aprano > > >> wrote: > >> > And what about tuples? And subclasses of list/tuples? How many > >> > different types need to be optimized? > > >> One of the beautiful things about Python is that, for most things, > >> there are few surprises for even new users. ?"There should be one > >> obvious way to do it" for the user means that, sometimes, under the > >> hood, there are a lot of special cases for the implementers. > > > If nothing else, I think it's reasonably for users to expect symmetry. > > Why? What is symmetry in programming? "Symmetry" is best shown by example. >>> 3 - 2 1 >>> set([1,2,3]) - set([2,3]) set([1]) >>> 5 * 3 15 >>> [1, 2, 3, 4, 5] * 3 [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5] >>> 1 + 2 + 3 + 4 10 >>> sum([1,2,3,4]) 10 >>> [1,2] + [3,4] [1, 2, 3, 4] >>> sum([[1,2], [3,4]], []) [1, 2, 3, 4] > Since the + operator takes both numbers and lists, and the - operator > doesn't, does "symmetry" require that we make up some list operation so > that integers and lists are symmetrical? > No. Nobody is advocating for list subtraction. > > If you can use "+" to concatentate lists, then it seems reasonable that > > something spelled "sum" would concatenate lists as well, and in > > reasonable time. > > Where do you get the "reasonable time" from? > >From common sense. Concatenation of lists should be in O(M*N) time, not O(M*N*N), because there is no need to build intermediate lists. > > With a very few exceptions (e.g. dict lookup being "usually" O(1), list > append being amortized O(1)), Python makes no promises about performance. > It's not part of the language. If you, the programmer, are making any > assumptions about performance that aren't clearly and explicitly > documented in the official docs, then YOU are at fault, not Python. I'm not making any assumptions here. I know that sum() is needlessly slow for lists, even though it is not explicitly documented. > > > It only takes a handful of sublists, about ten on my box, to expose the > > limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's under > > the hood. ?It only takes 200 sublists to start getting a 10x degradation > > in performance. > > And how many times have you needed to add 200 sublists? > > How many times have you needed to add 10 sublists? > Aggregating lists is a very common task in programming. An example of a list of lists would be a list of departments, where each department is a list of employees. If you want to sort the employees, you will want to aggregate to a list. > More special cases for implementers means more bugs in the language, > which means I end up writing my own code and ignoring the built-in > version anyway. > Special cases do not have to introduce bugs in the language. > More special cases means I have to pay the cost of high accuracy float > summation even when I don't need, or want, it. > Nothing about making sum() work for the general cases precludes more specific, optimized functions. > More special cases means I'm fooled into paying the cost of summing lists > when I don't need to, because it's easier than importing itertools: You don't have to be fooled. > for item in sum(lots_of_lists): > ? ? pass > > needlessly creates a large list out of the smaller ones. Although this is a mostly harmless example, developers with common sense would not sum lots of lists unless they expected to keep the resulting list around for multiple operations, or for one operation, like sort(), where you need to create a list for the subsequent operation. > Even if I don't > fall for the temptation, and write bad code, I still pay the cost in the > libraries and applications written by others. You already pay the small price for polymorphism when you use Python. > More special cases isn't free. Nobody said they were. > It's MORE costly than teaching users to > use list.extend or itertools.chain. > Which the docs for sum() don't do. From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 22:11:09 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 02:11:09 GMT Subject: decorators only when __debug__ == True References: Message-ID: On Mon, 29 Mar 2010 17:54:26 -0700, LX wrote: > Hi all, I have a question about decorators. I would like to use them for > argument checking, and pre/post conditions. However, I don't want the > additional overhead when I run in non-debug mode. I could do something > like this, using a simple trace example. def decorator(func): if __debug__: @functools.wraps(func) def inner(*args, **kwargs): preprocess() result = func(*args, **kwargs) postprocess() return result return inner else: return func -- Steven From pmaupin at gmail.com Mon Mar 29 22:24:42 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 19:24:42 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> On Mar 29, 6:19?pm, Steven D'Aprano wrote: > How does the existence of math.fsum contradict the existence of sum? You're exceptionally good at (probably deliberately) mis-interpreting what people write. Regards, Pat From pmaupin at gmail.com Mon Mar 29 22:31:44 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 19:31:44 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: <8dac78c8-124a-4b02-9944-6d577bfac84f@15g2000yqi.googlegroups.com> On Mar 29, 6:38?pm, Steven D'Aprano wrote: > With a very few exceptions (e.g. dict lookup being "usually" O(1), list > append being amortized O(1)), Python makes no promises about performance. > It's not part of the language. If you, the programmer, are making any > assumptions about performance that aren't clearly and explicitly > documented in the official docs, then YOU are at fault, not Python. It's not about promises, guarantees, quid-pro-quo, etc. It's about a lack of surprises. Which, 99% of the time, Python excels at. This is why many of us program in Python. This is why some of us who would never use sum() on lists, EVEN IF IT WERE FIXED TO NOT BE SO OBNOXIOUSLY SLOW, advocate that it, in fact, be fixed to not be so obnoxiously slow. BTW, it's also not about "fault". There is no shame in writing a Python program, seeing that it doesn't go fast enough, and then hammering on it until it does. There is also no shame in not reading the docs before you write the program, although arguably (and you obviously work very hard to help see to this) a great deal of shame attaches to posting to the newsgroup before reading the docs. Regards, Pat From showell30 at yahoo.com Mon Mar 29 22:53:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 19:53:04 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mar 29, 4:19?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 07:40:54 -0700, Patrick Maupin wrote: > > On Mar 28, 9:45?pm, Steven D'Aprano > > wrote: > >> And what about tuples? And subclasses of list/tuples? How many > >> different types need to be optimized? > > > One of the beautiful things about Python is that, for most things, there > > are few surprises for even new users. ?"There should be one obvious way > > to do it" for the user means that, sometimes, under the hood, there are > > a lot of special cases for the implementers. > > It never ceases to amaze me how often people simply don't understand this. > > "There should be one obvious way to do it" is the opposite of "NO obvious > way", not of "many ways which may or may not be obvious". The complete > quote from the Zen makes that clear: > > There should be one-- and preferably ONLY one --obvious way to do it. > [Emphasis added] > > And don't forget the next line: > > Although that way may not be obvious at first unless you're Dutch. > > Python is under no compulsion to make "the obvious way" obvious to anyone > except Guido. It's a bonus if it happens to be obvious to newbies, not a > requirement. > > And besides, what is "it" you're talking about? > > * Adding integers, decimals or fractions, or floats with a low > ? requirement for precision and accuracy? Use sum. > > * Adding floats with a high requirement for precision and accuracy? > ? Use math.fsum. > > * Concatenating strings? Use ''.join. > > * Joining lists? Use [].extend. > > * Iterating over an arbitrary sequence of arbitrary sequences? > ? Use itertools.chain. > > That's five different "its", and five obvious ways to do them. > Let's go through them... > * Adding integers, decimals or fractions, or floats with a low > requirement for precision and accuracy? Use sum. > Pretty obvious. >>> sum([1, 2, 3]) 6 > * Adding floats with a high requirement for precision and accuracy? > Use math.fsum. > Mostly obvious. >>> fsum([1.234534665989, 2.987, 3]) Traceback (most recent call last): File "", line 1, in NameError: name 'fsum' is not defined >>> import math >>> math.fsum([1.234534665989, 2.987, 3]) 7.2215346659890001 > * Concatenating strings? Use ''.join. Common pitfall: >>> ['abc', 'def', 'ghi'].join() Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute 'join' >>> ''.join(['abc', 'def', 'ghi']) 'abcdefghi' > * Joining lists? Use [].extend. Obvious, yes. Convenient? Not really. >>> start = [] >>> for list in [[1, 2], [3, 4]]: ... start.extend(list) ... >>> start [1, 2, 3, 4] > * Iterating over an arbitrary sequence of arbitrary sequences? > Use itertools.chain. >>> group1 = ['al', 'bob'] >>> group2 = ['cal'] >>> groups = [group1, group2] Obvious if you are Dutch... >>> itertools.chain(groups) Traceback (most recent call last): File "", line 1, in NameError: name 'itertools' is not defined >>> import itertools >>> itertools.chain(groups) >>> len(itertools.chain(groups)) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'itertools.chain' has no len() >>> len(list(itertools.chain(groups))) 2 >>> len(list(itertools.chain(*groups))) 3 So you have sum, fsum, join, extend, and chain. Sum is builtin, but you have to import fsum from math and chain from itertools. Join is actually a method on strings, not sequences. Chain can take multiple lists, or you can use the splat operator on a list of lists. Extend is actually a method on lists, and it only takes one list, not multiple ones. >>> [].extend(*groups) Traceback (most recent call last): File "", line 1, in TypeError: extend() takes exactly one argument (2 given) Just commit all that to memory, and enjoy the productivity of using a high level language! ;) From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:01:03 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:01:03 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Mar 2010 19:05:30 -0700, Steve Howell wrote: >> > If nothing else, I think it's reasonably for users to expect >> > symmetry. >> >> Why? What is symmetry in programming? > > "Symmetry" is best shown by example. > > >>> 3 - 2 > 1 > >>> set([1,2,3]) - set([2,3]) > set([1]) That's a useless example. >>> 42 - 10 32 >>> set([42]) - set([10]) set([42]) You don't define symmetry. You don't even give a sensible example of symmetry. Consequently I reject your argument that because sum is the obvious way to sum a lot of integers, "symmetry" implies that it should be the obvious way to concatenate a lot of lists. >>> 1+2 3 >>> [1] + [2] [1, 2] >>> set([1]) + set([2]) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'set' and 'set' >> > If you can use "+" to concatentate lists, then it seems reasonable >> > that something spelled "sum" would concatenate lists as well, and in >> > reasonable time. >> >> Where do you get the "reasonable time" from? >> >> > From common sense. Concatenation of lists should be in O(M*N) time, not > O(M*N*N), because there is no need to build intermediate lists. You are correct that building intermediate lists isn't *compulsory*, there are alternatives, but the alternatives themselves have costs. Complexity itself is a cost. sum currently has nice simple semantics, which means you can reason about it: sum(sequence, start) is the same as total = start for item in sequence: total = total + start return total You don't have to care what the items in sequence are, you don't have to make assumptions about what methods sequence and start have (beyond supporting iteration and addition). Adding special cases to sum means it becomes more complex and harder to reason about. If you pass some other sequence type in the middle of a bunch of lists, what will happen? Will sum suddenly break, or perhaps continue to work but inefficiently? You still need to ask these questions with existing sum, but it is comparatively easy to answer them: you only need to consider how the alternative behaves when added to a list. You don't have to think about the technicalities of the sum algorithm itself -- sometimes it calls +, sometimes extend, sometimes +=, sometimes something else... which of the various different optimized branches will I fall into this time? Who knows? sum already has two branches. In my opinion, three branches is one too many. [...] >> > It only takes a handful of sublists, about ten on my box, to expose >> > the limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's >> > under the hood. ?It only takes 200 sublists to start getting a 10x >> > degradation in performance. >> >> And how many times have you needed to add 200 sublists? >> >> How many times have you needed to add 10 sublists? >> >> > Aggregating lists is a very common task in programming. "Aggregating" lists? Not summing them? I think you've just undercut your argument that sum is the "obvious" way of concatenating lists. In natural language, we don't talk about "summing" lists, we talk about joining, concatenating or aggregating them. You have just done it yourself, and made my point for me. And this very thread started because somebody wanted to know what the equivalent to sum for sequences. If sum was the obvious way to concatenate sequences, this thread wouldn't even exist. > An example of a > list of lists would be a list of departments, where each department is a > list of employees. If you want to sort the employees, you will want to > aggregate to a list. I grant you that 10 departments is likely to be a borderline case, but if you have 200 departments, then you will most likely be querying a database and getting back a single list of employees. And if you're not, you probably should be. >> More special cases for implementers means more bugs in the language, >> which means I end up writing my own code and ignoring the built-in >> version anyway. >> >> > Special cases do not have to introduce bugs in the language. They don't *have* to, but since even Donald Knuth has written code with bugs in it, it is a safe bet that the number of bugs in code written by mere mortals will be roughly proportional to the complexity: more complex means more bugs. You can go to the bank with that. >> More special cases means I have to pay the cost of high accuracy float >> summation even when I don't need, or want, it. >> >> > Nothing about making sum() work for the general cases precludes more > specific, optimized functions. You have missed my point. If I call your version of sum which all the special cases, I pay the overhead of the complexity regardless of whether I need it or not. The existence of other functions which duplicate the special cases in sum is irrelevant. [...] >> It's MORE costly than teaching users to use list.extend or >> itertools.chain. >> >> > Which the docs for sum() don't do. Patches are always welcome. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:02:25 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:02:25 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xtyryitu6.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 29 Mar 2010 16:36:17 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> * Iterating over an arbitrary sequence of arbitrary sequences? >> Use itertools.chain. > > chain is only for finite sequences. For arbitrary sequences, use > chain.from_iterable. Correction noted. Obviously I'm not Dutch. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:29:11 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:29:11 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> Message-ID: On Mon, 29 Mar 2010 19:24:42 -0700, Patrick Maupin wrote: > On Mar 29, 6:19?pm, Steven D'Aprano cybersource.com.au> wrote: >> How does the existence of math.fsum contradict the existence of sum? > > You're exceptionally good at (probably deliberately) mis-interpreting > what people write. I cannot read your mind, I can only interpret the words you choose to write. You said [quote] See, I think the very existence of math.fsum() already violates "there should be one obvious way to do it." [end quote] If sum satisfies the existence of one obvious way, how does math.fsum violate it? sum exists, and is obvious, regardless of whatever other solutions exist as well. -- Steven From pmaupin at gmail.com Mon Mar 29 23:33:14 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 20:33:14 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> Message-ID: <559a2ee3-fb2c-477f-a444-7edbb6da8676@r1g2000yqj.googlegroups.com> On Mar 29, 10:29?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 19:24:42 -0700, Patrick Maupin wrote: > > On Mar 29, 6:19?pm, Steven D'Aprano > cybersource.com.au> wrote: > >> How does the existence of math.fsum contradict the existence of sum? > > > You're exceptionally good at (probably deliberately) mis-interpreting > > what people write. > > I cannot read your mind, I can only interpret the words you choose to > write. You said > > [quote] > See, I think the very existence of math.fsum() already violates "there > should be one obvious way to do it." > [end quote] > > If sum satisfies the existence of one obvious way, how does math.fsum > violate it? sum exists, and is obvious, regardless of whatever other > solutions exist as well. Because sum() is the obvious way to sum floats; now the existence of math.fsum() means there are TWO obvious ways to sum floats. Is that really that hard to understand? How can you misconstrue this so badly that you write something that can be (easily) interpreted to mean that you think that I think that once math.fsum() exists, sum() doesn't even exist any more???? From showell30 at yahoo.com Mon Mar 29 23:34:17 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 20:34:17 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: <3c7ed32c-201f-41c8-bd46-4bf3092a3d6f@x12g2000yqx.googlegroups.com> On Mar 29, 8:01?pm, Steven D'Aprano wrote: > You don't define symmetry. You don't even give a sensible example of > symmetry. Consequently I reject your argument that because sum is the > obvious way to sum a lot of integers, "symmetry" implies that it should > be the obvious way to concatenate a lot of lists. > You are not rejecting my argument; you are rejecting an improper paraphrase of my argument. My argument was that repeated use of "+" is spelled "sum" for integers, so it's natural to expect the same name for repeated use of "+" on lists. Python already allows for this symmetry, just SLOWLY. > > You are correct that building intermediate lists isn't *compulsory*, > there are alternatives, but the alternatives themselves have costs. > Complexity itself is a cost. sum currently has nice simple semantics, > which means you can reason about it: sum(sequence, start) is the same as > > total = start > for item in sequence: > ? ? total = total + start > return total > I could just as reasonably expect these semantics: total = start for item in sequence: total += start return total Python does not contradict my expectations here: >>> start = [] >>> x = sum([], start) >>> x.append(1) >>> start [1] > You don't have to care what the items in sequence are, you don't have to > make assumptions about what methods sequence and start have (beyond > supporting iteration and addition). The only additional assumption I'm making is that Python can take advantage of in-place addition, which is easy to introspect. > Adding special cases to sum means it > becomes more complex and harder to reason about. If you pass some other > sequence type in the middle of a bunch of lists, what will happen? Will > sum suddenly break, or perhaps continue to work but inefficiently? This is mostly a red herring, as I would tend to use sum() on sequences of homogenous types. Python already gives me the power to shoot myself in the foot for strings. >>> list = [1, 2] >>> list += "foo" >>> list [1, 2, 'f', 'o', 'o'] >>> lst = [1,2] >>> lst.extend('foo') >>> lst [1, 2, 'f', 'o', 'o'] I'd prefer to get an exception for cases where += would do the same. >>> start = [] >>> bogus_example = [[1, 2], None, [3]] >>> for item in bogus_example: start += item ... Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not iterable > You still need to ask these questions with existing sum, but it is > comparatively easy to answer them: you only need to consider how the > alternative behaves when added to a list. You don't have to think about > the technicalities of the sum algorithm itself -- sometimes it calls +, > sometimes extend, sometimes +=, sometimes something else I would expect sum() to support the same contract as +=, which already works for numerics (so no backward incompatibility), and which already works for lists. For custom-designed classes, I would rely on the promise that augmented assignment falls back to normal methods. > ... which of the > various different optimized branches will I fall into this time? Who > knows? sum already has two branches. In my opinion, three branches is one > too many. As long as it falls into the branch that works, I'm happy. :) > > "Aggregating" lists? Not summing them? I think you've just undercut your > argument that sum is the "obvious" way of concatenating lists. > > In natural language, we don't talk about "summing" lists, we talk about > joining, concatenating or aggregating them. You have just done it > yourself, and made my point for me. Nor do you use "chain" or "extend." > And this very thread started because > somebody wanted to know what the equivalent to sum for sequences. > > If sum was the obvious way to concatenate sequences, this thread wouldn't > even exist. This thread is entitled "sum for sequences." I think you just made my point. From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:49:46 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:49:46 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> <8dac78c8-124a-4b02-9944-6d577bfac84f@15g2000yqi.googlegroups.com> Message-ID: On Mon, 29 Mar 2010 19:31:44 -0700, Patrick Maupin wrote: > It's about a lack of surprises. Which, 99% of the time, Python excels > at. This is why many of us program in Python. This is why some of us > who would never use sum() on lists, EVEN IF IT WERE FIXED TO NOT BE SO > OBNOXIOUSLY SLOW, advocate that it, in fact, be fixed to not be so > obnoxiously slow. As I said, patches are welcome. Personally, I expect that it would be rejected, but that's not my decision to make, and who knows, perhaps I'm wrong and you'll have some of the Python-Dev people support your idea. sum is not designed to work with lists. It happens to work because lists happen to use + for concatenation, and because it is too much trouble for too little benefit to explicitly exclude lists in the same way sum explicitly excludes strings. In the Python philosophy, simplicity of implementation is a virtue: the code that is not there contributes exactly no bugs and has precisely no overhead. sum has existed as a Python built-in for many years -- by memory, since Python 2.2, which was nearly nine years ago. Unlike the serious gotcha of repeated string concatenation: # DO NOT DO THIS result = "" for s in items: result += s which *does* cause real problems in real code, I don't believe that there have been any significant problems caused by summing lists of lists. As problems go, it is such a minor one that it isn't worth this discussion, let alone fixing it. But if anyone disagrees, this is open source, go ahead and fix it. You don't need my permission. -- Steven From gagsl-py2 at yahoo.com.ar Tue Mar 30 00:00:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Mar 2010 01:00:16 -0300 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> <81b39uFggeU1@mid.individual.net> Message-ID: En Mon, 29 Mar 2010 04:41:23 -0300, Gregory Ewing escribi?: > Stephen Hansen wrote: > >> So I wonder if there's just some hyper-optimization Photoshop does that >> PIL can't round-trip. > > You may find that PIL isn't bothering to compress at all, > or only doing it in a very simpleminded way. Indeed. Fredrik Lundh, in http://mail.python.org/pipermail/image-sig/1998-July/000506.html "When writing GIF files, PIL uses a simpleminded encoding that, by some odd reason, LZW decoders have no trouble reading. To write compressed GIF files, there are a number of options: -- install NETPBM, and hack GifImagePlugin so it uses _save_ppm instead of _save (just remove "_ppm" from the latter). -- write an _imaging_gif module that takes a PIL image and writes a GIF version of it. how you implement that is up to you..." After twelve years the above comments are still applicable. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 30 00:36:52 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Mar 2010 01:36:52 -0300 Subject: xpat error in xmlrp client. How to inspect data. References: <4bab1f4a$0$25677$426a74cc@news.free.fr> Message-ID: En Thu, 25 Mar 2010 05:31:05 -0300, News123 escribi?: > I'm havign a small xmlrpc client, which works normally fine. > (xmlrpc via https) > > Sometimes however I receive an Exception about an expat error. > > > The output, that I receive is: > File "C:\mycode\myrpcclient.py", line 63, in upload_chunk > rslt = myrpcclient.call() > File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ > return self.__send(self.__name, args) > File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request > verbose=self.__verbose > File "C:\Python26\lib\xmlrpclib.py", line 1253, in request > return self._parse_response(h.getfile(), sock) > File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response > p.feed(response) > File "C:\Python26\lib\xmlrpclib.py", line 601, in feed > self._parser.Parse(data, 0) > ExpatError: syntax error: line 1, column 0 > > > In order to continue debugging I'd like to dump the received http data, > which "C:\Python26\lib\xmlrpclib.py", line 601 tried to parse without > succes. > > How can I do this? a) Use the standard cgitb module (despite its name, it is useful outside CGI scripts) b) Use the tb module available from http://pypi.python.org/pypi/tb Both provide a more verbose traceback, including local variables at each execution frame. c) Replace ("monkey-patch") the feed() method with a more debug-friendly version: def feed(self, data): try: self._parser.Parse(data, 0) except xmlrpclib.expat.ExpatError, e: e.args += (data,) raise xmlrpclib.ExpatParser.feed = feed (Or perhaps set e.data = data) d) In your exception handler, walk the traceback object until you reach the feed() call, and inspect the corresponding tb_frame.f_locals dictionary. -- Gabriel Genellina From cs at zip.com.au Tue Mar 30 00:41:11 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 30 Mar 2010 15:41:11 +1100 Subject: GIF89A and PIL In-Reply-To: <2010032719445464825-aptshansen@gmailinvalid> References: <2010032719445464825-aptshansen@gmailinvalid> Message-ID: <20100330044111.GA684@cskk.homeip.net> On 27Mar2010 19:44, Stephen Hansen wrote: | Yeah, I don't expect much from PNG. The images are very small but I | might be sending a LOT of them over a pipe which is fairly tight, so | 50-60 bytes matters. That's why I selected GIF. How well does a stream of XPM files compress? Probably not enough, I would guess. Just wondering. Do you need to move a "standard" image format around? If everything's 16x16 8 bit colour (and if, with luck, they share a colour map) maybe you can ship raw bytes expressing what you want. How colourful are these GIFs? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ What I want is Facts. Teach these boys and girls nothing but Facts. Facts alone are wanted in life. Plant nothing else, and root out everything else. - Charles Dickens John Huffam 1812-1870 Hard Times [1854] From kse.listed.co1 at gmail.com Tue Mar 30 00:41:38 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Mon, 29 Mar 2010 21:41:38 -0700 (PDT) Subject: "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ Message-ID: "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ From vinni at altern.org Tue Mar 30 01:47:40 2010 From: vinni at altern.org (Vincent MAILLE) Date: Mon, 29 Mar 2010 22:47:40 -0700 (PDT) Subject: PyScripter Logo Message-ID: <9483843a-e855-4648-ae69-fef9e7006ffd@z3g2000yqz.googlegroups.com> Hi, Where can I find a image of the snake PyScipter in high quality ? Thnaks, Vincent From steven at REMOVE.THIS.cybersource.com.au Tue Mar 30 02:41:51 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 06:41:51 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Mar 2010 19:53:04 -0700, Steve Howell wrote: > On Mar 29, 4:19?pm, Steven D'Aprano cybersource.com.au> wrote: [...] >> Python is under no compulsion to make "the obvious way" obvious to >> anyone except Guido. It's a bonus if it happens to be obvious to >> newbies, not a requirement. >> >> And besides, what is "it" you're talking about? >> >> * Adding integers, decimals or fractions, or floats with a low >> ? requirement for precision and accuracy? Use sum. >> >> * Adding floats with a high requirement for precision and accuracy? >> ? Use math.fsum. >> >> * Concatenating strings? Use ''.join. >> >> * Joining lists? Use [].extend. >> >> * Iterating over an arbitrary sequence of arbitrary sequences? >> ? Use itertools.chain. >> >> That's five different "its", and five obvious ways to do them. >> >> > Let's go through them... "Obvious" doesn't mean you don't have to learn the tools you use. It doesn't mean that there's no need to think about the requirements of your problem. It doesn't even mean that the way to do it has to be a built-in or pre-built solution in the standard library, or that somebody with no Python experience could intuit the correct function to use based on nothing more than a good grasp of English. It certainly doesn't mean that users shouldn't be expected to know how to import a module: > >>> fsum([1.234534665989, 2.987, 3]) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'fsum' is not defined I called it math.fsum every time I referred to it. Did I need to specify that you have to import the math module first? >> * Concatenating strings? Use ''.join. > > > Common pitfall: > > >>> ['abc', 'def', 'ghi'].join() > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'list' object has no attribute 'join' Is it really common? I've been hanging around this newsgroup for many years now, and I don't believe I've ever seen anyone confused by this. I've seen plenty of newbies use repeated string concatenation, but never anyone trying to do a string join and getting it wrong. If you have any links to threads showing such confusion, I'd be grateful to see them. >> * Joining lists? Use [].extend. > > Obvious, yes. Convenient? Not really. > > >>> start = [] > >>> for list in [[1, 2], [3, 4]]: > ... start.extend(list) > ... > >>> start > [1, 2, 3, 4] Why isn't that convenient? It is an obvious algorithm written in three short lines. If you need a one-liner, write a function and call it: concatenate_lists(sequence_of_lists) >> * Iterating over an arbitrary sequence of arbitrary sequences? >> Use itertools.chain. > > >>> group1 = ['al', 'bob'] > >>> group2 = ['cal'] > >>> groups = [group1, group2] > > Obvious if you are Dutch... Or are familiar with the itertools module and the Pythonic practice of iterating over lazy sequences. Iterators and itertools are fundamental to the Pythonic way of doing things. > >>> itertools.chain(groups) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'itertools' is not defined That's the second time you've either mistakenly neglected to import a module, or deliberately not imported it to make the rhetorical point that you have to import a module before using it. Yes, you *do* have to import modules before using them. What's your point? Not everything has to be a built-in. [...] > Sum is builtin, but you have to import fsum from math and chain from > itertools. > > Join is actually a method on strings, not sequences. Is that supposed to be an argument against them? [...] > Just commit all that to memory, and enjoy the productivity of using a > high level language! ;) If you don't know your tools, you will spend your life hammering screws in with the butt of your saw. It will work, for some definition of work. Giving saws heavier, stronger handles to make it faster to hammer screws is not what I consider good design. -- Steven From no.email at nospam.invalid Tue Mar 30 02:55:55 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 29 Mar 2010 23:55:55 -0700 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: <7xr5n2i9hg.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >>>> ... >>> ... >> ... > "Obvious" doesn't mean you don't have to learn the tools you use.... Geez you guys, get a room ;-). You're all good programmers with too much experience for this arguing over stuff this silly. From loveguruworld7 at gmail.com Tue Mar 30 03:05:01 2010 From: loveguruworld7 at gmail.com (love guru 4 world) Date: Tue, 30 Mar 2010 00:05:01 -0700 (PDT) Subject: Watch Angelina Jolie's sex scandal videos at her house Message-ID: <67a85379-1f60-4028-b812-4650fb3fc719@a16g2000pre.googlegroups.com> Watch Angelina Jolie's sex scandal videos at her house for more details register here to start watching video now http://moourl.com/82x99 From keeloh at rocketmail.com Tue Mar 30 03:33:01 2010 From: keeloh at rocketmail.com (POOJA) Date: Tue, 30 Mar 2010 00:33:01 -0700 (PDT) Subject: Help Desk Software by PerlDesk Message-ID: Help Desk Software by PerlDesk ------------------------ http://sites.google.com/site/freehelpdesksoftware From chris at simplistix.co.uk Tue Mar 30 04:03:00 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 30 Mar 2010 09:03:00 +0100 Subject: PyDispatcher on sourceforge doesn't play nice with easy_install Message-ID: <4BB1B034.9020905@simplistix.co.uk> Hi All, Using easy_install to get PyDispatcher results in: Searching for PyDispatcher Reading http://pypi.python.org/simple/PyDispatcher/ Reading http://pydispatcher.sourceforge.net Reading https://sourceforge.net/project/showfiles.php?group_id=79755 Reading http://sourceforge.net/projects/pydispatcher/files/pydispatcher/ Best match: PyDispatcher 2.0.1 Downloading http://sourceforge.net/projects/pydispatcher/files/pydispatcher/2.0.1/PyDispatcher-2.0.1-py2.5.egg/download Processing download error: Couldn't find a setup script in /tmp/easy_install-ioAdEo/download Who's the maintainer of PyDispatcher nowadays? Would be handy if they removed the sourceforge link from pypi. In the meantime, the following works around the problem: easy_install PyDispatcher -H *.python.org cheers, Chris From steven at REMOVE.THIS.cybersource.com.au Tue Mar 30 04:06:09 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 08:06:09 GMT Subject: PyScripter Logo References: <9483843a-e855-4648-ae69-fef9e7006ffd@z3g2000yqz.googlegroups.com> Message-ID: On Mon, 29 Mar 2010 22:47:40 -0700, Vincent MAILLE wrote: > Where can I find a image of the snake PyScipter in high quality ? Did you mean PyScripter (note spelling)? If so, then googling for PyScripter brings me to the PyScripter project, which has contact details. You should ask the project author. -- Steven From jeanmichel at sequans.com Tue Mar 30 05:03:06 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 30 Mar 2010 11:03:06 +0200 Subject: "Usability, the Soul of Python" In-Reply-To: <4bb14173$0$1640$742ec2ed@news.sonic.net> References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <4BB1BE4A.50407@sequans.com> John Nagle wrote: > Jonathan Hayward wrote: >> I've posted "Usability, the Soul of Python: An Introduction to the >> Python Programming Language Through the Eyes of Usability", at: >> >> http://JonathansCorner.com/python/ > > No, it's just a rather verbose introduction to Python, in dark brown > type on a light brown background. One could write a good paper on this > topic, but this isn't it. > > > John Nagle Why is it bad ? JM From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 06:10:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 10:10:55 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xr5n2i9hg.fsf@ruckus.brouhaha.com> Message-ID: <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >>>>> ... >>>> ... >>> ... >> "Obvious" doesn't mean you don't have to learn the tools you use.... > > Geez you guys, get a room ;-). You're all good programmers with too > much experience for this arguing over stuff this silly. Yes Mum ;) You're right of course. I spend too much time being this guy: http://xkcd.com/386/ and not enough this one: http://xkcd.com/167/ -- Steven From am8734200 at gmail.com Tue Mar 30 06:19:33 2010 From: am8734200 at gmail.com (a m) Date: Tue, 30 Mar 2010 03:19:33 -0700 (PDT) Subject: It's a fact not lost on the opportunity to see yourself Message-ID: <49471fea-67f2-476a-93cf-1e9f9eabfcb7@i25g2000yqm.googlegroups.com> http://www.google.com/url?sa=D&q=http://www.google.com/url%3Fsa%3DD%26q%3Dhttp://osamah2000.jeeran.com/daauageralmuslmeen1.htm%26usg%3DAFQjCNGQhhGz-1TGv9Y7gE8zKwHHustJCg&usg=AFQjCNH5ZzXRqkh5EGL1dsjQxcjNQCmAEQ From malte.usenet at web.de Tue Mar 30 07:17:21 2010 From: malte.usenet at web.de (Malte Dik) Date: Tue, 30 Mar 2010 13:17:21 +0200 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <81e4u2F7ubU1@mid.dfncis.de> > Why is it bad ? > Not working code, examples, that are weird to read, and a lot of text :) From lie.1296 at gmail.com Tue Mar 30 07:23:32 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 30 Mar 2010 22:23:32 +1100 Subject: StringChain -- a data structure for managing large sequences ofchunks of bytes In-Reply-To: <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> <4bae6130$1@dnews.tpgi.com.au> <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> Message-ID: <4bb1df60$1@dnews.tpgi.com.au> On 03/29/2010 01:59 AM, Steven D'Aprano wrote: > On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote: > >> On 03/22/2010 07:07 PM, Steven D'Aprano wrote: >>> Perhaps you should have said that it was a wrapper around deque giving >>> richer functionality, rather than giving the impression that it was a >>> brand new data structure invented by you. People are naturally going to >>> be more skeptical about a newly invented data structure than one based >>> on a reliable, component like deque. >> >> Well, technically StringChain is not a data structure in the first >> place. StringChain is a string; > > And strings are data structures, as are arrays and structs. Just because > they're simple data structures made directly from primitives rather than > rich, complex structures, doesn't mean they're not data structures. Array is a way to structure data and thus a data structure; array is the concept of structuring data using contiguous memory with elements addressed by an index. string is just a contiguous memory reserved to store data, or in other words: string is an array. This is what I meant when I said string is not itself a data structure. >> a string that is implemented using deque >> data structure to make appending algorithmically efficient. It is not a >> data structure, in the sense that I can't put arbitrary "thing" into the >> data structure. > > Any "thing" that can be pickled or serialised can be put into a string. Fair enough, you're right to think so but IMHO I disagree. Streams (or perhaps 'blob' to avoid the connotation of FIFO) are the data structure which you can put anything pickleable/serialisable into, but string (the implementation of stream/blob using array) are just a special case of array data structure and not a different, separate data structure than array. Perhaps I should not make such a bold claim as saying string is not data structure; what I have in mind is that string is just a special case of array and not distinctly separate data structure than array. From steve at holdenweb.com Tue Mar 30 07:33:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 07:33:37 -0400 Subject: sum for sequences? In-Reply-To: <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xr5n2i9hg.fsf@ruckus.brouhaha.com> <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> Message-ID: <4BB1E191.9040909@holdenweb.com> Steven D'Aprano wrote: > On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote: > >> Steven D'Aprano writes: >>>>>> ... >>>>> ... >>>> ... >>> "Obvious" doesn't mean you don't have to learn the tools you use.... >> Geez you guys, get a room ;-). You're all good programmers with too >> much experience for this arguing over stuff this silly. > > Yes Mum ;) > > > You're right of course. I spend too much time being this guy: > > http://xkcd.com/386/ > > and not enough this one: > > http://xkcd.com/167/ > > Yeah, it can happen to all of us. I've certainly been "that guy" too. But Steven, surely now it's time to *show us the squirrels* regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 30 07:33:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 07:33:37 -0400 Subject: sum for sequences? In-Reply-To: <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xr5n2i9hg.fsf@ruckus.brouhaha.com> <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> Message-ID: <4BB1E191.9040909@holdenweb.com> Steven D'Aprano wrote: > On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote: > >> Steven D'Aprano writes: >>>>>> ... >>>>> ... >>>> ... >>> "Obvious" doesn't mean you don't have to learn the tools you use.... >> Geez you guys, get a room ;-). You're all good programmers with too >> much experience for this arguing over stuff this silly. > > Yes Mum ;) > > > You're right of course. I spend too much time being this guy: > > http://xkcd.com/386/ > > and not enough this one: > > http://xkcd.com/167/ > > Yeah, it can happen to all of us. I've certainly been "that guy" too. But Steven, surely now it's time to *show us the squirrels* regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From lie.1296 at gmail.com Tue Mar 30 07:39:41 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 30 Mar 2010 22:39:41 +1100 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <4bb1e329$1@dnews.tpgi.com.au> On 03/27/2010 10:28 PM, Jonathan Hartley wrote: > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > I never liked the narrow definition of function as "reusable piece of code". This narrow definition implies that a piece of code used only once do not need to be made a function. I would rather define function as "a logically independent piece of code" and encourage refactorizing code into functions even if they are only used once as long as they are conceptually a "step" and being able to reuse code as a nice side-effect of it. Under this definition, the "some complex logic" conceptually is an independent piece of code that can (and probably should) be factorized. From alfps at start.no Tue Mar 30 07:40:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 30 Mar 2010 13:40:22 +0200 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: * Jean-Michel Pichavant: > John Nagle wrote: >> Jonathan Hayward wrote: >>> I've posted "Usability, the Soul of Python: An Introduction to the >>> Python Programming Language Through the Eyes of Usability", at: >>> >>> http://JonathansCorner.com/python/ >> >> No, it's just a rather verbose introduction to Python, in dark brown >> type on a light brown background. One could write a good paper on this >> topic, but this isn't it. >> >> >> John Nagle > Why is it bad ? Consider From a usability standpoint, the braces go with the lines to print out the stanza rather than the for statement or the code after, so the following is best: for(i = 99; i > 0; ++i) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i + 1); } This is just unsubstantiated opinion, but worse, it makes a tacit assumption that there is "best" way to do indentation. However, most programmers fall into that trap, and I've done it myself. In fact, when I worked as a consultant (then in Andersen Consulting, now Accenture) I used the style above. Petter Hesselberg, author of "Industrial Strength Windows Programming" (heh, I'm mentioned) asked my why on Earth I did that, like, nobody does that? It was a habit I'd picked up in Pascal, from very na?ve considerations of parse nesting levels, a kind of misguided idealism instead of more practical pragmatism, but since I realized that that was an incredibly weak argument I instead answered by pointing towards Charles Petzold's code in his "Programming Windows" books. And amazingly I was allowed to continue using this awkward and impractical style. I may or may not have been responsible for the similarly impractical compromise convention of using three spaces per indentation level. At least, in one big meeting the question about number of spaces was raised by the speaker, and I replied from the benches, just in jest, "three!". And that was it (perhaps). Cheers, - Alf (admitting to earlier mistakes) From contact at xavierho.com Tue Mar 30 08:11:05 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 30 Mar 2010 22:11:05 +1000 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <2d56febf1003300511h617d7487t1bee6f69c6722a17@mail.gmail.com> Did no one notice that for(i = 99; i > 0; ++i) Gives you an infinite loop (sort of) because i starts a 99, and increases every loop? Cheers, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: contact at xavierho.com Website: http://xavierho.com/ On Tue, Mar 30, 2010 at 9:40 PM, Alf P. Steinbach wrote: > * Jean-Michel Pichavant: > >> John Nagle wrote: >> >>> Jonathan Hayward wrote: >>> >>>> I've posted "Usability, the Soul of Python: An Introduction to the >>>> Python Programming Language Through the Eyes of Usability", at: >>>> >>>> http://JonathansCorner.com/python/ >>>> >>> >>> No, it's just a rather verbose introduction to Python, in dark brown >>> type on a light brown background. One could write a good paper on this >>> topic, but this isn't it. >>> >>> >>> John Nagle >>> >> Why is it bad ? >> > > Consider > > > > From a usability standpoint, the braces go with the lines to print out the > stanza rather than the for statement or the code after, so the following is > best: > > for(i = 99; i > 0; ++i) > { > printf("%d slabs of spam in my mail!\n", i); > printf("%d slabs of spam,\n", i); > printf("Send one to abuse and Just Hit Delete,\n"); > printf("%d slabs of spam in my mail!\n\n", i + 1); > } > > > > This is just unsubstantiated opinion, but worse, it makes a tacit > assumption that there is "best" way to do indentation. However, most > programmers fall into that trap, and I've done it myself. In fact, when I > worked as a consultant (then in Andersen Consulting, now Accenture) I used > the style above. Petter Hesselberg, author of "Industrial Strength Windows > Programming" (heh, I'm mentioned) asked my why on Earth I did that, like, > nobody does that? It was a habit I'd picked up in Pascal, from very na?ve > considerations of parse nesting levels, a kind of misguided idealism instead > of more practical pragmatism, but since I realized that that was an > incredibly weak argument I instead answered by pointing towards Charles > Petzold's code in his "Programming Windows" books. And amazingly I was > allowed to continue using this awkward and impractical style. > > I may or may not have been responsible for the similarly impractical > compromise convention of using three spaces per indentation level. At least, > in one big meeting the question about number of spaces was raised by the > speaker, and I replied from the benches, just in jest, "three!". And that > was it (perhaps). > > > Cheers, > > - Alf (admitting to earlier mistakes) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 30 09:46:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 09:46:20 -0400 Subject: StringChain -- a data structure for managing large sequences ofchunks of bytes In-Reply-To: <4bb1df60$1@dnews.tpgi.com.au> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> <4bae6130$1@dnews.tpgi.com.au> <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> <4bb1df60$1@dnews.tpgi.com.au> Message-ID: Lie Ryan wrote: > On 03/29/2010 01:59 AM, Steven D'Aprano wrote: >> On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote: >> >>> On 03/22/2010 07:07 PM, Steven D'Aprano wrote: >>>> Perhaps you should have said that it was a wrapper around deque giving >>>> richer functionality, rather than giving the impression that it was a >>>> brand new data structure invented by you. People are naturally going to >>>> be more skeptical about a newly invented data structure than one based >>>> on a reliable, component like deque. >>> Well, technically StringChain is not a data structure in the first >>> place. StringChain is a string; >> And strings are data structures, as are arrays and structs. Just because >> they're simple data structures made directly from primitives rather than >> rich, complex structures, doesn't mean they're not data structures. > > Array is a way to structure data and thus a data structure; array is the > concept of structuring data using contiguous memory with elements > addressed by an index. string is just a contiguous memory reserved to > store data, or in other words: string is an array. This is what I meant > when I said string is not itself a data structure. > >>> a string that is implemented using deque >>> data structure to make appending algorithmically efficient. It is not a >>> data structure, in the sense that I can't put arbitrary "thing" into the >>> data structure. >> Any "thing" that can be pickled or serialised can be put into a string. > > Fair enough, you're right to think so but IMHO I disagree. Streams (or > perhaps 'blob' to avoid the connotation of FIFO) are the data structure > which you can put anything pickleable/serialisable into, but string (the > implementation of stream/blob using array) are just a special case of > array data structure and not a different, separate data structure than > array. > > Perhaps I should not make such a bold claim as saying string is not data > structure; what I have in mind is that string is just a special case of > array and not distinctly separate data structure than array. While this may be true conceptually it's certainly not true in Python (and in Python you need to be careful to distinguish between lists and arrays, since it does have both types). >From the point of view of the language, strings are primitives. But every Python implementation uses a data structure to store them, and the structure is definitely not the same as is used to store lists, or arrays (which in Python are container types, whereas the string isn't because the individual indexable elements are immutable). As always, it's better to seek common ground than pick the nits: I don't think that there's really that much difference between your approach and Steven's, but he's a well-known nit-picker (and we are *sometimes* grateful for it). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mwilson at the-wire.com Tue Mar 30 09:53:52 2010 From: mwilson at the-wire.com (Mel) Date: Tue, 30 Mar 2010 09:53:52 -0400 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> <559a2ee3-fb2c-477f-a444-7edbb6da8676@r1g2000yqj.googlegroups.com> Message-ID: Patrick Maupin wrote: > Because sum() is the obvious way to sum floats; now the existence of > math.fsum() means there are TWO obvious ways to sum floats. Is that > really that hard to understand? How can you misconstrue this so badly > that you write something that can be (easily) interpreted to mean that > you think that I think that once math.fsum() exists, sum() doesn't > even exist any more???? floats are nasty -- as evidence the recent thread on comparing floats for equality. People use floats when they have to. fsum exists because of this: mwilson at tecumseth:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from math import fsum >>> a=(1.0e200, 156.0, -1.0e200) >>> sum(a) 0.0 >>> fsum(a) 156.0 You could generalize sum, but after that, there's a case that even fsum can't handle: >>> ni=1.0e200+1.0j >>> nj=1.0+1.0e200j >>> ai=(ni, nj, 156.0+651.0j, -ni, -nj) >>> sum(ai) (-1+0j) >>> fsum(ai) Traceback (most recent call last): File "", line 1, in TypeError: can't convert complex to float; use abs(z) >>> Mel. From sccolbert at gmail.com Tue Mar 30 10:25:54 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 10:25:54 -0400 Subject: "Usability, the Soul of Python" In-Reply-To: <2d56febf1003300511h617d7487t1bee6f69c6722a17@mail.gmail.com> References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <2d56febf1003300511h617d7487t1bee6f69c6722a17@mail.gmail.com> Message-ID: <7f014ea61003300725yf3dfcbdw2976160ca37f60f3@mail.gmail.com> not really, the int will eventually overflow and cycle around ;) On Tue, Mar 30, 2010 at 8:11 AM, Xavier Ho wrote: > Did no one notice that > > > for(i = 99; i > 0; ++i) > > Gives you an infinite loop (sort of) because i starts a 99, and increases > every loop? > > Cheers, > > Ching-Yun Xavier Ho, Technical Artist > > Contact Information > Mobile: (+61) 04 3335 4748 > Skype ID: SpaXe85 > Email: contact at xavierho.com > Website: http://xavierho.com/ > > > > On Tue, Mar 30, 2010 at 9:40 PM, Alf P. Steinbach wrote: > >> * Jean-Michel Pichavant: >> >>> John Nagle wrote: >>> >>>> Jonathan Hayward wrote: >>>> >>>>> I've posted "Usability, the Soul of Python: An Introduction to the >>>>> Python Programming Language Through the Eyes of Usability", at: >>>>> >>>>> http://JonathansCorner.com/python/ >>>>> >>>> >>>> No, it's just a rather verbose introduction to Python, in dark brown >>>> type on a light brown background. One could write a good paper on this >>>> topic, but this isn't it. >>>> >>>> >>>> John Nagle >>>> >>> Why is it bad ? >>> >> >> Consider >> >> >> >> >From a usability standpoint, the braces go with the lines to print out >> the stanza rather than the for statement or the code after, so the following >> is best: >> >> for(i = 99; i > 0; ++i) >> { >> printf("%d slabs of spam in my mail!\n", i); >> printf("%d slabs of spam,\n", i); >> printf("Send one to abuse and Just Hit Delete,\n"); >> printf("%d slabs of spam in my mail!\n\n", i + 1); >> } >> >> >> >> This is just unsubstantiated opinion, but worse, it makes a tacit >> assumption that there is "best" way to do indentation. However, most >> programmers fall into that trap, and I've done it myself. In fact, when I >> worked as a consultant (then in Andersen Consulting, now Accenture) I used >> the style above. Petter Hesselberg, author of "Industrial Strength Windows >> Programming" (heh, I'm mentioned) asked my why on Earth I did that, like, >> nobody does that? It was a habit I'd picked up in Pascal, from very na?ve >> considerations of parse nesting levels, a kind of misguided idealism instead >> of more practical pragmatism, but since I realized that that was an >> incredibly weak argument I instead answered by pointing towards Charles >> Petzold's code in his "Programming Windows" books. And amazingly I was >> allowed to continue using this awkward and impractical style. >> >> I may or may not have been responsible for the similarly impractical >> compromise convention of using three spaces per indentation level. At least, >> in one big meeting the question about number of spaces was raised by the >> speaker, and I replied from the benches, just in jest, "three!". And that >> was it (perhaps). >> >> >> Cheers, >> >> - Alf (admitting to earlier mistakes) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bluemangroupie at gmail.com Tue Mar 30 11:13:02 2010 From: bluemangroupie at gmail.com (aditya) Date: Tue, 30 Mar 2010 08:13:02 -0700 (PDT) Subject: Binary Decimals in Python Message-ID: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. - Aditya From anand.shashwat at gmail.com Tue Mar 30 11:19:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 30 Mar 2010 20:49:52 +0530 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: decimal binary number is not included AFAIK On Tue, Mar 30, 2010 at 8:43 PM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > > - Aditya > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Tue Mar 30 11:28:50 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 30 Mar 2010 08:28:50 -0700 (PDT) Subject: Binary Decimals in Python References: Message-ID: <4e7acb50-797f-4e19-a915-90724cf157fc@u22g2000yqf.googlegroups.com> On Mar 30, 10:13?am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > > - Aditya So, why should int('1.1', 2) throw an error when int('1.1') doesn't? Regards, Pat From pmaupin at gmail.com Tue Mar 30 11:31:25 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 30 Mar 2010 08:31:25 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> <559a2ee3-fb2c-477f-a444-7edbb6da8676@r1g2000yqj.googlegroups.com> Message-ID: <9437e04d-b7ba-489e-9737-89cd1af41b40@k19g2000yqn.googlegroups.com> On Mar 30, 8:53?am, Mel wrote: > floats are nasty -- as evidence the recent thread on comparing floats for > equality. ?People use floats when they have to. ?fsum exists because of > this: ... I understand there are technical reasons for why math.fsum() exists. I still think that whatever math.fsum() does should probably be a part of sum(). Regards, Pat From kgo at grant-olson.net Tue Mar 30 11:35:21 2010 From: kgo at grant-olson.net (Grant Olson) Date: Tue, 30 Mar 2010 11:35:21 -0400 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: <4BB21A39.1070102@grant-olson.net> On 3/30/2010 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > Well technically that would be a 'radix point', not a decimal point. But I think the problem is that computers don't store fractional values that way internally. They either use floating or fixed point math. You would never look at raw binary data on a computer and see something like '1010.1010', and no one would write it that way, and no language (that I know of) would accept that as a valid value if you did something like "x = 0b1010.1010" So in that sense, it might not be an intentional oversight, but it's not a very practical or useful feature. From benjamin.kaplan at case.edu Tue Mar 30 11:37:36 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 30 Mar 2010 11:37:36 -0400 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > > - Aditya > -- Because int stands for integer and 1.1 is not an integer. You get the same error if you try doing int('1.1') > http://mail.python.org/mailman/listinfo/python-list > From tibor.beck at hotmail.com Tue Mar 30 11:40:56 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Tue, 30 Mar 2010 08:40:56 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' Message-ID: Hi, how can I write the popular C/JAVA syntax in Python? Java example: return (a==b) ? 'Yes' : 'No' My first idea is: return ('No','Yes')[bool(a==b)] Is there a more elegant/common python expression for this? From anand.shashwat at gmail.com Tue Mar 30 11:43:39 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 30 Mar 2010 21:13:39 +0530 Subject: Binary Decimals in Python In-Reply-To: <4BB21A39.1070102@grant-olson.net> References: <4BB21A39.1070102@grant-olson.net> Message-ID: The conversion is not supported for decimal integers AFAIK, however '0b123.456' is always valid. I guess you can always get a decimal number convertor onto Python-recipes On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson wrote: > On 3/30/2010 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > > int('11',2) # returns 3 > > > > But decimal binary numbers throw a ValueError: > > > > int('1.1',2) # should return 1.5, throws error instead. > > > > Is this by design? It seems to me that this is not the correct > > behavior. > > > > Well technically that would be a 'radix point', not a decimal point. > > But I think the problem is that computers don't store fractional values > that way internally. They either use floating or fixed point math. You > would never look at raw binary data on a computer and see something like > '1010.1010', and no one would write it that way, and no language (that I > know of) would accept that as a valid value if you did something like "x > = 0b1010.1010" > > So in that sense, it might not be an intentional oversight, but it's not > a very practical or useful feature. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at cox.net Tue Mar 30 11:44:23 2010 From: mrmakent at cox.net (Mike Kent) Date: Tue, 30 Mar 2010 08:44:23 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: Message-ID: <034130b2-295b-4564-ac32-44de15d3f1c1@33g2000yqj.googlegroups.com> On Mar 30, 11:40?am, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > ? ? return (a==b) ? 'Yes' : 'No' > > My first idea is: > ? ? return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? return ('Yes' if a == b else 'No') From python at rcn.com Tue Mar 30 11:49:04 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 30 Mar 2010 08:49:04 -0700 (PDT) Subject: Binary Decimals in Python References: Message-ID: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> On Mar 30, 8:13?am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. The int() constructor returns integers. So, look to float() for non-integral values. Binary representation isn't supported yet, but we do have hex: >>> float.fromhex('1.8') 1.5 Raymond From kgo at grant-olson.net Tue Mar 30 11:51:49 2010 From: kgo at grant-olson.net (Grant Olson) Date: Tue, 30 Mar 2010 11:51:49 -0400 Subject: Binary Decimals in Python In-Reply-To: References: <4BB21A39.1070102@grant-olson.net> Message-ID: <4BB21E15.60507@grant-olson.net> Doh! Well the problem is that int's are integers. So yeah, you can't even do that with normal value "int ('2.1')" will also throw an error. And floats don't support radix conversion, because no-one really writes numbers that way. (At least computer programmers...) On 3/30/2010 11:43 AM, Shashwat Anand wrote: > The conversion is not supported for decimal integers AFAIK, however > '0b123.456' is always valid. I guess you can always get a decimal number > convertor onto Python-recipes > > > > On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson > wrote: > > On 3/30/2010 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > > int('11',2) # returns 3 > > > > But decimal binary numbers throw a ValueError: > > > > int('1.1',2) # should return 1.5, throws error instead. > > > > Is this by design? It seems to me that this is not the correct > > behavior. > > > > Well technically that would be a 'radix point', not a decimal point. > > But I think the problem is that computers don't store fractional values > that way internally. They either use floating or fixed point math. You > would never look at raw binary data on a computer and see something like > '1010.1010', and no one would write it that way, and no language (that I > know of) would accept that as a valid value if you did something like "x > = 0b1010.1010" > > So in that sense, it might not be an intentional oversight, but it's not > a very practical or useful feature. > -- > http://mail.python.org/mailman/listinfo/python-list > > From python at mrabarnett.plus.com Tue Mar 30 11:54:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 16:54:08 +0100 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: <4BB21EA0.5060306@mrabarnett.plus.com> aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > int() returns an integer (hence the name!), so it should never return a float anyway. What you want is for float() to accept a base, but that is rarely needed. From bluemangroupie at gmail.com Tue Mar 30 11:54:43 2010 From: bluemangroupie at gmail.com (aditya) Date: Tue, 30 Mar 2010 08:54:43 -0700 (PDT) Subject: Binary Decimals in Python References: Message-ID: On Mar 30, 10:37?am, Benjamin Kaplan wrote: > On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws error instead. > > > Is this by design? It seems to me that this is not the correct > > behavior. > > > - Aditya > > -- > > Because int stands for integer and 1.1 is not an integer. You get the > same error if you try doing int('1.1') > > >http://mail.python.org/mailman/listinfo/python-list > > That makes sense. The closest thing I've found is this question on StackOverflow: http://stackoverflow.com/questions/1592158/python-convert-hex-to-float It seems to me that adding a conversion feature to floats would be a lot more intuitive. From mcfletch at vrplumber.com Tue Mar 30 11:56:08 2010 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 30 Mar 2010 11:56:08 -0400 Subject: PyDispatcher on sourceforge doesn't play nice with easy_install In-Reply-To: <4BB1B034.9020905@simplistix.co.uk> References: <4BB1B034.9020905@simplistix.co.uk> Message-ID: <4BB21F18.2010705@vrplumber.com> Chris Withers wrote: > Hi All, > > Using easy_install to get PyDispatcher results in: > ... > Who's the maintainer of PyDispatcher nowadays? Would be handy if they > removed the sourceforge link from pypi. ... Thanks for the report. I've released a 2.0.2 version on PyPI. That should now work properly with easy_install. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From bluemangroupie at gmail.com Tue Mar 30 11:56:26 2010 From: bluemangroupie at gmail.com (aditya) Date: Tue, 30 Mar 2010 08:56:26 -0700 (PDT) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> Message-ID: <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> On Mar 30, 10:49?am, Raymond Hettinger wrote: > On Mar 30, 8:13?am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws error instead. > > > Is this by design? It seems to me that this is not the correct > > behavior. > > The int() constructor returns integers. > So, look to float() for non-integral values. > Binary representation isn't supported yet, > but we do have hex: > > ? ? >>> float.fromhex('1.8') > ? ? 1.5 > > Raymond That looks very elegant, thanks! From clp2 at rebertia.com Tue Mar 30 12:01:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 09:01:54 -0700 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: References: Message-ID: <50697b2c1003300901k157d10b0u7308b96a1f8be984@mail.gmail.com> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > ? ?return (a==b) ? 'Yes' : 'No' > > My first idea is: > ? ?return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? Yes, Python has ternary operator-like syntax: return ('Yes' if a==b else 'No') Note that this requires a recent version of Python. Cheers, Chris -- http://blog.rebertia.com From fetchinson at googlemail.com Tue Mar 30 12:17:04 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 30 Mar 2010 18:17:04 +0200 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <034130b2-295b-4564-ac32-44de15d3f1c1@33g2000yqj.googlegroups.com> References: <034130b2-295b-4564-ac32-44de15d3f1c1@33g2000yqj.googlegroups.com> Message-ID: >> Hi, how can I write the popular C/JAVA syntax in Python? >> >> Java example: >> return (a==b) ? 'Yes' : 'No' >> >> My first idea is: >> return ('No','Yes')[bool(a==b)] >> >> Is there a more elegant/common python expression for this? > > return ('Yes' if a == b else 'No') And for less clutter you can even leave the parenthesis: return 'Yes' if a == b else 'No' -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fordhaivat at gmail.com Tue Mar 30 12:23:28 2010 From: fordhaivat at gmail.com (Someone Something) Date: Tue, 30 Mar 2010 12:23:28 -0400 Subject: CPAN for python? Message-ID: Hi, I've learned python a few months ago but I still use Perl because of CPAN and the tremendous amount of stuff that's already been done for you. is there something like CPAN for python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Tue Mar 30 12:34:18 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Tue, 30 Mar 2010 09:34:18 -0700 (PDT) Subject: Python Script Creator/Generator (function factory) Message-ID: Hello, I have the following situation: I've got a 3rd party application that has a Python API. The applicaiton has integrated support for MIDI Hardware Controllers, which can be used to manipulate various parameters of the application. The app can also load Python User Scripts, which can define the mapping between the Controllers and Parameters, but they can also be used to define the behavior of those mappings as well. I want to provide my users a GUI App that allows them to map their MIDI Controllers to the application's Parameters, but with a specific behavior. Once they've defined the mappings and behavior, my application would generate a custom Python User Script, which then gets loaded by the 3rd party app. I've already got MIDI covered, and the GUI. Deployment via Pyinstaller has been taken care of as well. My application can currently map Controllers to Parameters in a 1:1 fashion, and can generate a simple python User Script with all the mappings. What I'm left with implementing is the behavior part. Let me give you a simple example of a possible behavior that the user could select: - The user has a button on their MIDI Hardware (a simple type of MIDI controller) - The first time the button is hit, a specific parameter is selected in the 3rd party application. - The second time the button is hit, a different parameter is selected. - And so on, depending on the behavior of the function that's mapped to that MIDI button So, in essence, a simple User Script would look something like this (pseudocode-ish): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ swap_parameters() if button1 was_hit_the_first_time: select parameter1 else: select parameter2 buttons = ( button1 = swap_parameters() button3 = parameter3 button4 = parameter4 ... ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ What I had in mind, was to have a collection of behaviors stored in a file (basically functions such as "swap_parameters") which the user could select via my application, map them to a specific MIDI Controller (such as a Button), and generate the User Script. In essence, I'm trying to build a function factory that's specific to the 3rd party application's provided API. But the user would have the ability to change the way the function works. In the above example, the user might want their MIDI Button to select parameter2 first, and parameter1 the second time. Has anyone had any experience with generating functionality this way, and could you give me some pointers in the right direction? Any tips, advice, book recommendations are more than welcome. Kind regards, Andrej Mitrovic From andrej.mitrovich at gmail.com Tue Mar 30 12:35:42 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Tue, 30 Mar 2010 09:35:42 -0700 (PDT) Subject: Python Script Creator/Generator (function factory) References: Message-ID: I forgot to mention, I'm using Python 2.5.x. I can't use Python 3 unfortunately, the 3rd party application uses Py2.5.x internally, so I have to limit the functionality to that version. From kushal.kumaran+python at gmail.com Tue Mar 30 12:51:40 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 30 Mar 2010 22:21:40 +0530 Subject: CPAN for python? In-Reply-To: References: Message-ID: <1e364c4e1003300951w58515844n222e79df61b60779@mail.gmail.com> On Tue, Mar 30, 2010 at 9:53 PM, Someone Something wrote: > Hi, > I've learned python a few months ago but I still use Perl because of CPAN > and the tremendous amount of stuff that's already been done for you. is > there something like CPAN for python? > Try PyPI. http://pypi.python.org/pypi -- regards, kushal From gatoygata2 at gmail.com Tue Mar 30 12:57:34 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 30 Mar 2010 09:57:34 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: Message-ID: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> On Mar 30, 5:40?pm, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > ? ? return (a==b) ? 'Yes' : 'No' > > My first idea is: > ? ? return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? (a==b) and 'YES' or 'NO' Yes, ugly Joaquin From robert.kern at gmail.com Tue Mar 30 12:58:39 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 11:58:39 -0500 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb22b39$0$1638$742ec2ed@news.sonic.net> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: On 2010-03-30 12:08 PM, John Nagle wrote: > Chris Rebert wrote: >> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >> wrote: >>> Hi, how can I write the popular C/JAVA syntax in Python? >>> >>> Java example: >>> return (a==b) ? 'Yes' : 'No' >>> >>> My first idea is: >>> return ('No','Yes')[bool(a==b)] >>> >>> Is there a more elegant/common python expression for this? >> >> Yes, Python has ternary operator-like syntax: >> return ('Yes' if a==b else 'No') >> >> Note that this requires a recent version of Python. > > Who let the dogs in? That's awful syntax. http://www.python.org/dev/peps/pep-0308/ -- 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 From anand.shashwat at gmail.com Tue Mar 30 13:03:51 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 30 Mar 2010 22:33:51 +0530 Subject: CPAN for python? In-Reply-To: <1e364c4e1003300951w58515844n222e79df61b60779@mail.gmail.com> References: <1e364c4e1003300951w58515844n222e79df61b60779@mail.gmail.com> Message-ID: This has been discussed tons of times. You should have atleast googled it. Python have nothing like CPAN and Cheese Shop (pypi) comes closest to it. On Tue, Mar 30, 2010 at 10:21 PM, Kushal Kumaran < kushal.kumaran+python at gmail.com > wrote: > On Tue, Mar 30, 2010 at 9:53 PM, Someone Something > wrote: > > Hi, > > I've learned python a few months ago but I still use Perl because of CPAN > > and the tremendous amount of stuff that's already been done for you. is > > there something like CPAN for python? > > > > Try PyPI. http://pypi.python.org/pypi > > -- > regards, > kushal > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 13:05:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 17:05:14 GMT Subject: Binary Decimals in Python References: <4e7acb50-797f-4e19-a915-90724cf157fc@u22g2000yqf.googlegroups.com> Message-ID: <4bb22f4a$0$8827$c3e8da3@news.astraweb.com> On Tue, 30 Mar 2010 08:28:50 -0700, Patrick Maupin wrote: > On Mar 30, 10:13?am, aditya wrote: >> To get the decimal representation of a binary number, I can just do >> this: >> >> int('11',2) # returns 3 >> >> But decimal binary numbers throw a ValueError: >> >> int('1.1',2) # should return 1.5, throws error instead. >> >> Is this by design? It seems to me that this is not the correct >> behavior. >> >> - Aditya > > So, why should int('1.1', 2) throw an error when int('1.1') doesn't? >>> int('1.1') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1.1' int('1.1', 2) shouldn't return 1.5 because 1.5 isn't an integer. The obvious question is, why doesn't float('1.1', 2) work? The answer is that Python doesn't support floats in any base except 10. It's not something needed very often, and it's harder to get right than it might seem. -- Steven From philip at semanchuk.com Tue Mar 30 13:07:28 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 30 Mar 2010 13:07:28 -0400 Subject: CPAN for python? In-Reply-To: References: Message-ID: <37A3074F-2980-4241-AC59-19E3252D9C6A@semanchuk.com> On Mar 30, 2010, at 12:23 PM, Someone Something wrote: > Hi, > I've learned python a few months ago but I still use Perl because of > CPAN and the tremendous amount of stuff that's already been done for > you. is there something like CPAN for python? Yes and no, depending on what CPAN means to you. This question come up often; have a look in the archives. Here's one thread on the topic from last month: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ecd51ced8d24593e/f773e080024862cb?lnk=gst&q=cpan#f773e080024862cb From nagle at animats.com Tue Mar 30 13:08:31 2010 From: nagle at animats.com (John Nagle) Date: Tue, 30 Mar 2010 10:08:31 -0700 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: References: Message-ID: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Chris Rebert wrote: > On Tue, Mar 30, 2010 at 8:40 AM, gentlestone wrote: >> Hi, how can I write the popular C/JAVA syntax in Python? >> >> Java example: >> return (a==b) ? 'Yes' : 'No' >> >> My first idea is: >> return ('No','Yes')[bool(a==b)] >> >> Is there a more elegant/common python expression for this? > > Yes, Python has ternary operator-like syntax: > return ('Yes' if a==b else 'No') > > Note that this requires a recent version of Python. Who let the dogs in? That's awful syntax. John Nagle From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 13:09:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 17:09:18 GMT Subject: (a==b) ? 'Yes' : 'No' References: Message-ID: <4bb2303e$0$8827$c3e8da3@news.astraweb.com> On Tue, 30 Mar 2010 08:40:56 -0700, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > return (a==b) ? 'Yes' : 'No' > > My first idea is: > return ('No','Yes')[bool(a==b)] You don't need the call to bool. ('No','Yes')[a==b] > Is there a more elegant/common python expression for this? The above is pretty elegant to my eyes, but you can also do: return 'Yes' if a==b else 'No' -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 13:11:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 17:11:29 GMT Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <4bb230c1$0$8827$c3e8da3@news.astraweb.com> On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote: >> Yes, Python has ternary operator-like syntax: return ('Yes' if a==b >> else 'No') >> >> Note that this requires a recent version of Python. > > Who let the dogs in? That's awful syntax. I used to think so to, but now I like it. It matches common English syntax like: "I'm going to the movies tonight, if I leave the office early, otherwise I'll stay home and nitpick on Usenet." -- Steven From sccolbert at gmail.com Tue Mar 30 13:12:04 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 13:12:04 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb22b39$0$1638$742ec2ed@news.sonic.net> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <7f014ea61003301012u2b52cf7bi75298750989c46a7@mail.gmail.com> On Tue, Mar 30, 2010 at 1:08 PM, John Nagle wrote: > Chris Rebert wrote: > >> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >> wrote: >> >>> Hi, how can I write the popular C/JAVA syntax in Python? >>> >>> Java example: >>> return (a==b) ? 'Yes' : 'No' >>> >>> My first idea is: >>> return ('No','Yes')[bool(a==b)] >>> >>> Is there a more elegant/common python expression for this? >>> >> >> Yes, Python has ternary operator-like syntax: >> return ('Yes' if a==b else 'No') >> >> Note that this requires a recent version of Python. >> > > Who let the dogs in? That's awful syntax. > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > I wouldn't say that. It reads exactly how one would say it. I prefer this over the ? semantics. Whenever I see that, my mind goes "Does a equal b? If so, return this, otherwise return that". "Return this if a equals b, otherwise return that" is much more direct and declaritive IMHO. -------------- next part -------------- An HTML attachment was scrubbed... URL: From howe.steven at gmail.com Tue Mar 30 13:19:26 2010 From: howe.steven at gmail.com (Steven Howe) Date: Tue, 30 Mar 2010 10:19:26 -0700 Subject: CPAN for python? In-Reply-To: References: Message-ID: <4BB2329E.9050304@gmail.com> This question comes up at least once a month, eliciting a thread that goes on for day. Wouldn't it be wise to put a link on the bottom of the mail list? Something like CPAN for Python == PyPi << make that an href or Python( CPAN ) = PyPi Not too many characters. sph On 03/30/2010 09:23 AM, Someone Something wrote: > Hi, > I've learned python a few months ago but I still use Perl because of > CPAN and the tremendous amount of stuff that's already been done for > you. is there something like CPAN for python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From gatoygata2 at gmail.com Tue Mar 30 13:50:15 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 30 Mar 2010 10:50:15 -0700 (PDT) Subject: How many packages there are in PyPI Message-ID: <084b6a4e-27e6-45e0-bebf-256b41598f20@z3g2000yqz.googlegroups.com> Hi, PyPI is reaching the 10000 package figure (In the case of 3.x only about 140 packages and increasing very very slowly). Looking at available packages for 3.x I observed that some packages are listed several times. For example, lxml is listed 5 times. Are these repetitions included in the package count? If yes, just out of curiosity, somebody knows what the actual number of different packages in the PyPI reservoir is? Joaquin. From steve at holdenweb.com Tue Mar 30 13:56:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 13:56:04 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb22b39$0$1638$742ec2ed@news.sonic.net> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Chris Rebert wrote: >> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >> wrote: >>> Hi, how can I write the popular C/JAVA syntax in Python? >>> >>> Java example: >>> return (a==b) ? 'Yes' : 'No' >>> >>> My first idea is: >>> return ('No','Yes')[bool(a==b)] >>> >>> Is there a more elegant/common python expression for this? >> >> Yes, Python has ternary operator-like syntax: >> return ('Yes' if a==b else 'No') >> >> Note that this requires a recent version of Python. > > Who let the dogs in? That's awful syntax. > Yes, that's deliberately awful syntax. Guido designed it that way to ensure that people didn't aver-use it, thereby reducing the readability of Python applications. Speaking purely personally I hardly ever use it, but don't dislike it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mensanator at aol.com Tue Mar 30 14:03:27 2010 From: mensanator at aol.com (Mensanator) Date: Tue, 30 Mar 2010 11:03:27 -0700 (PDT) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> Message-ID: <4eea3f36-10da-498a-890b-d879aac1fb86@y14g2000yqm.googlegroups.com> On Mar 30, 10:49?am, Raymond Hettinger wrote: > On Mar 30, 8:13?am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws error instead. > > > Is this by design? It seems to me that this is not the correct > > behavior. > > The int() constructor returns integers. > So, look to float() for non-integral values. > Binary representation isn't supported yet, It is supported in the gmpy module. >>> import gmpy >>> help(gmpy.mpf) Help on built-in function mpf in module gmpy: mpf(...) mpf(n): builds an mpf object with a numeric value n (n may be any Python number, or an mpz, mpq, or mpf object) and a default precision (in bits) depending on the nature of n mpf(n,bits=0): as above, but with the specified number of bits (0 means to use default precision, as above) mpf(s,bits=0,base=10): builds an mpf object from a string s made up of digits in the given base, possibly with fraction-part (with period as a separator) and/or exponent-part (with exponent marker 'e' for base<=10, else '@'). If base=256, s must be a gmpy.mpf portable binary representation as built by the function gmpy.fbinary (and the .binary method of mpf objects). The resulting mpf object is built with a default precision (in bits) if bits is 0 or absent, else with the specified number of bits. >>> gmpy.mpf('1.1',0,2) mpf('1.5e0') > but we do have hex: > > ? ? >>> float.fromhex('1.8') > ? ? 1.5 > > Raymond From robert.kern at gmail.com Tue Mar 30 14:05:13 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 13:05:13 -0500 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb230c1$0$8827$c3e8da3@news.astraweb.com> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <4bb230c1$0$8827$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-30 12:11 PM, Steven D'Aprano wrote: > On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote: > >>> Yes, Python has ternary operator-like syntax: return ('Yes' if a==b >>> else 'No') >>> >>> Note that this requires a recent version of Python. >> >> Who let the dogs in? That's awful syntax. > > I used to think so to, but now I like it. It matches common English > syntax like: > > "I'm going to the movies tonight, if I leave the office early, otherwise > I'll stay home and nitpick on Usenet." I would suggest that this is much more common and less awkward English usage: "If I leave the office early, I'm going to the movies tonight; otherwise, I'll stay home and nitpick on Usenet." I don't have a problem with the current syntax, and while its English analogue is grammatical, I don't think you can rightly call it idiomatic. -- 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 From invalid at invalid.invalid Tue Mar 30 14:08:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Mar 2010 18:08:14 +0000 (UTC) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: On 2010-03-30, John Nagle wrote: > Hex floats are useful because you can get a string representation of > the exact value of a binary floating point number. It should always > be the case that > > float.fromhex(float.hex(x)) == x Until you try running your program on a machine that represents floats using a radix other than 2,4, or 16. ;) And it works for NaN and Inf too! It would have been nice to have had that 5-6 years ago when I had to write my own pickle/unpickle methods for floating point values so that inf and nan were portable between Windows and Linux. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From nagle at animats.com Tue Mar 30 14:14:07 2010 From: nagle at animats.com (John Nagle) Date: Tue, 30 Mar 2010 11:14:07 -0700 Subject: Binary Decimals in Python In-Reply-To: <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> Message-ID: <4bb23a99$0$1582$742ec2ed@news.sonic.net> aditya wrote: > On Mar 30, 10:49 am, Raymond Hettinger wrote: >> On Mar 30, 8:13 am, aditya wrote: >> >>> To get the decimal representation of a binary number, I can just do >>> this: >>> int('11',2) # returns 3 >>> But decimal binary numbers throw a ValueError: >>> int('1.1',2) # should return 1.5, throws error instead. >>> Is this by design? It seems to me that this is not the correct >>> behavior. >> The int() constructor returns integers. >> So, look to float() for non-integral values. >> Binary representation isn't supported yet, >> but we do have hex: >> >> >>> float.fromhex('1.8') >> 1.5 >> >> Raymond > > That looks very elegant, thanks! Hex floats are useful because you can get a string representation of the exact value of a binary floating point number. It should always be the case that float.fromhex(float.hex(x)) == x That's not always true of decimal representations, due to rounding problems. Long discussion of this here: "http://bugs.python.org/issue1580" John Nagle From no.spam at local.local Tue Mar 30 14:16:09 2010 From: no.spam at local.local (Robert Fendt) Date: Tue, 30 Mar 2010 20:16:09 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <20100330201609.6ef12ee1@vulcan.local> And thus spake Steve Holden Tue, 30 Mar 2010 13:56:04 -0400: > >> Yes, Python has ternary operator-like syntax: > >> return ('Yes' if a==b else 'No') > >> > >> Note that this requires a recent version of Python. > > > > Who let the dogs in? That's awful syntax. > > Yes, that's deliberately awful syntax. Guido designed it that way to > ensure that people didn't aver-use it, thereby reducing the readability > of Python applications. Speaking purely personally I hardly ever use it, > but don't dislike it. In fact, the syntax just shouts 'do [...] unless' to me. And that's so strong a Perl-ism I cannot quite express how ugly I actually find it... Regards, Robert From nagle at animats.com Tue Mar 30 14:24:05 2010 From: nagle at animats.com (John Nagle) Date: Tue, 30 Mar 2010 11:24:05 -0700 Subject: How many packages there are in PyPI In-Reply-To: <084b6a4e-27e6-45e0-bebf-256b41598f20@z3g2000yqz.googlegroups.com> References: <084b6a4e-27e6-45e0-bebf-256b41598f20@z3g2000yqz.googlegroups.com> Message-ID: <4BB241C5.60501@animats.com> Joaquin Abian wrote: > Hi, > PyPI is reaching the 10000 package figure (In the case of 3.x only > about 140 packages and increasing very very slowly). > > Looking at available packages for 3.x I observed that some packages > are listed several times. For example, lxml is listed 5 times. > Are these repetitions included in the package count? If yes, just out > of curiosity, somebody knows what the actual number of different > packages in the PyPI reservoir is? > > Joaquin. There aren't that many packages "in" PyPI. It's more of a directory than a repository. And some of the links are dead. I just tried "Dejavu", which only has a link to "projects.amor.org". That subdomain is dead. "amor.org" is some kind of religious organization. John Nagle From python at mrabarnett.plus.com Tue Mar 30 14:52:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 19:52:36 +0100 Subject: Binary Decimals in Python In-Reply-To: <4bb23a99$0$1582$742ec2ed@news.sonic.net> References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: <4BB24874.6020309@mrabarnett.plus.com> John Nagle wrote: > aditya wrote: >> On Mar 30, 10:49 am, Raymond Hettinger wrote: >>> On Mar 30, 8:13 am, aditya wrote: >>> >>>> To get the decimal representation of a binary number, I can just do >>>> this: >>>> int('11',2) # returns 3 >>>> But decimal binary numbers throw a ValueError: >>>> int('1.1',2) # should return 1.5, throws error instead. >>>> Is this by design? It seems to me that this is not the correct >>>> behavior. >>> The int() constructor returns integers. >>> So, look to float() for non-integral values. >>> Binary representation isn't supported yet, >>> but we do have hex: >>> >>> >>> float.fromhex('1.8') >>> 1.5 >>> >>> Raymond >> >> That looks very elegant, thanks! > > Hex floats are useful because you can get a string representation > of the exact value of a binary floating point number. It should > always be the case that > > float.fromhex(float.hex(x)) == x > > That's not always true of decimal representations, due to rounding > problems. > Floats have a limited length, unlike ints which are virtually unlimited. > Long discussion of this here: "http://bugs.python.org/issue1580" > From john at castleamber.com Tue Mar 30 15:19:19 2010 From: john at castleamber.com (John Bokma) Date: Tue, 30 Mar 2010 13:19:19 -0600 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> Message-ID: <87sk7h8vns.fsf@castleamber.com> Robert Fendt writes: > In fact, the syntax just shouts 'do [...] unless' to me. And > that's so strong a Perl-ism I cannot quite express how ugly I > actually find it... And a == b and 'Yes' or 'No' isn't a Perl-ism? Sheesh, this group would be so much nicer without the constant dragging in of Perl to make a point. On top of that, do { } unless blocks are not idomatic in Perl. Perl Best Practices even clearly states to *never* use unless. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From quentel.pierre at wanadoo.fr Tue Mar 30 15:38:08 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Tue, 30 Mar 2010 12:38:08 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> Message-ID: <5ef544bb-95a0-4329-80ef-f679d62b8ead@z11g2000yqz.googlegroups.com> On 30 mar, 21:19, John Bokma wrote: > Robert Fendt writes: > > In fact, the syntax just shouts 'do [...] unless' to me. And > > that's so strong a Perl-ism I cannot quite express how ugly I > > actually find it... > > And > > ?a == b and 'Yes' or 'No' > > isn't a Perl-ism? > > Sheesh, this group would be so much nicer without the constant dragging > in of Perl to make a point. On top of that, do { ?} unless blocks are > not idomatic in Perl. Perl Best Practices even clearly states to *never* > use unless. > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development I'm surprised nobody proposed a solution with itertools ;-) - Pierre From russ.paielli at gmail.com Tue Mar 30 16:03:37 2010 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 30 Mar 2010 13:03:37 -0700 (PDT) Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: According to Wikipedia, this is called the Whitesmith style: for(i = 99; i > 0; ++i) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i + 1); } I agree with the Mr. Hayward that it is preferable to the more common K&R style, because the braces do not violate and visually clutter the logical indentation structure. It looks more like Python. The deeper the level of nesting, the more this style reduces visual clutter compared to the conventional style. A slightly better style, in my opinion, is the Banner style: for(i = 99; i > 0; ++i) { // a blank line here is optional printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i + 1); } On Mar 30, 4:40?am, "Alf P. Steinbach" wrote: > * Jean-Michel Pichavant: > > > John Nagle wrote: > >> Jonathan Hayward wrote: > >>> I've posted "Usability, the Soul of Python: An Introduction to the > >>> Python Programming Language Through the Eyes of Usability", at: > > >>> ? ?http://JonathansCorner.com/python/ > > >> ? ?No, it's just a rather verbose introduction to Python, in dark brown > >> type on a light brown background. ?One could write a good paper on this > >> topic, but this isn't it. > > >> ? ? ? ? ? ? ? ? John Nagle > > Why is it bad ? > > Consider > > > ?From a usability standpoint, the braces go with the lines to print out the > stanza rather than the for statement or the code after, so the following is best: > > for(i = 99; i > 0; ++i) > ? ? ?{ > ? ? ?printf("%d slabs of spam in my mail!\n", i); > ? ? ?printf("%d slabs of spam,\n", i); > ? ? ?printf("Send one to abuse and Just Hit Delete,\n"); > ? ? ?printf("%d slabs of spam in my mail!\n\n", i + 1); > ? ? ?} > > > This is just unsubstantiated opinion, but worse, it makes a tacit assumption > that there is "best" way to do indentation. However, most programmers fall into > that trap, and I've done it myself. In fact, when I worked as a consultant (then > in Andersen Consulting, now Accenture) I used the style above. Petter > Hesselberg, author of "Industrial Strength Windows Programming" (heh, I'm > mentioned) asked my why on Earth I did that, like, nobody does that? It was a > habit I'd picked up in Pascal, from very na?ve considerations of parse nesting > levels, a kind of misguided idealism instead of more practical pragmatism, but > since I realized that that was an incredibly weak argument I instead answered by > pointing towards Charles Petzold's code in his "Programming Windows" books. And > amazingly I was allowed to continue using this awkward and impractical style. > > I may or may not have been responsible for the similarly impractical compromise > convention of using three spaces per indentation level. At least, in one big > meeting the question about number of spaces was raised by the speaker, and I > replied from the benches, just in jest, "three!". And that was it (perhaps). > > Cheers, > > - Alf ?(admitting to earlier mistakes) From no.spam at local.local Tue Mar 30 16:16:00 2010 From: no.spam at local.local (Robert Fendt) Date: Tue, 30 Mar 2010 22:16:00 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> Message-ID: <20100330221600.42cd3536@vulcan.local> And thus spake John Bokma Tue, 30 Mar 2010 13:19:19 -0600: > And > > a == b and 'Yes' or 'No' > > isn't a Perl-ism? I never said that this would be better. I don't even get the point of what the advantage is supposed to be of inverting the order of the return statement and the conditional check what should actually _be_ returned. What's wrong with just writing if a==b: return 'Yes' else: return 'No' apart from it being a few more line breaks and an additional return statement? The inverted form is not more readable per se (in fact, quite the opposite), and I would even suggest to minimise its use even in languages like C++ and Java. The Python syntax is even worse since it not only inverts the order of return statement and conditional check, but it also puts the conditional between the two results. I find such a convoluted construct especially ugly in a language which I previously regarded as having a rather striking beauty of syntactical simplicity. The construct is superfluous, illogical, unelegant, and thus very un-pythonesque, IMHO. But of course that's just my $0.02. > Sheesh, this group would be so much nicer without the constant dragging > in of Perl to make a point. On top of that, do { } unless blocks are > not idomatic in Perl. Perl Best Practices even clearly states to *never* > use unless. Sorry, but you have just underlined my point, in fact. If it's discouraged by experts, then of course the question must be valid why such a feature even exists (okay, apart from 'it seemed like a good idea at the time'). And more importantly (and more on-topic here), why we have to have an analogon in Python. Regards, Robert From ckaynor at zindagigames.com Tue Mar 30 16:19:33 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 30 Mar 2010 13:19:33 -0700 Subject: Binary Decimals in Python In-Reply-To: <4bb23a99$0$1582$742ec2ed@news.sonic.net> References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: Chris On Tue, Mar 30, 2010 at 11:14 AM, John Nagle wrote: > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: >> >>> On Mar 30, 8:13 am, aditya wrote: >>> >>> To get the decimal representation of a binary number, I can just do >>>> this: >>>> int('11',2) # returns 3 >>>> But decimal binary numbers throw a ValueError: >>>> int('1.1',2) # should return 1.5, throws error instead. >>>> Is this by design? It seems to me that this is not the correct >>>> behavior. >>>> >>> The int() constructor returns integers. >>> So, look to float() for non-integral values. >>> Binary representation isn't supported yet, >>> but we do have hex: >>> >>> >>> float.fromhex('1.8') >>> 1.5 >>> >>> Raymond >>> >> >> That looks very elegant, thanks! >> > > Hex floats are useful because you can get a string representation > of the exact value of a binary floating point number. It should > always be the case that > > float.fromhex(float.hex(x)) == x > > That's not always true of decimal representations, due to rounding > problems. > Actually, any number you can represent exactly in base 2 (or any power there of) you can also represent exactly in decimal - its the other way around thats a problem. > > Long discussion of this here: "http://bugs.python.org/issue1580" > > > John Nagle > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 30 16:32:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 16:32:51 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <20100330221600.42cd3536@vulcan.local> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: Robert Fendt wrote: > And thus spake John Bokma > Tue, 30 Mar 2010 13:19:19 -0600: > >> And >> >> a == b and 'Yes' or 'No' >> >> isn't a Perl-ism? > > I never said that this would be better. I don't even get the > point of what the advantage is supposed to be of inverting the > order of the return statement and the conditional check what > should actually _be_ returned. What's wrong with just writing > > if a==b: > return 'Yes' > else: > return 'No' > > apart from it being a few more line breaks and an additional > return statement? The inverted form is not more readable per > se (in fact, quite the opposite), and I would even suggest to > minimise its use even in languages like C++ and Java. The Python > syntax is even worse since it not only inverts the order of > return statement and conditional check, but it also puts the > conditional between the two results. > > I find such a convoluted construct especially ugly in a language > which I previously regarded as having a rather striking beauty > of syntactical simplicity. The construct is superfluous, > illogical, unelegant, and thus very un-pythonesque, IMHO. But of > course that's just my $0.02. > >> Sheesh, this group would be so much nicer without the constant dragging >> in of Perl to make a point. On top of that, do { } unless blocks are >> not idomatic in Perl. Perl Best Practices even clearly states to *never* >> use unless. > > Sorry, but you have just underlined my point, in fact. If it's > discouraged by experts, then of course the question must be > valid why such a feature even exists (okay, apart from 'it > seemed like a good idea at the time'). And more importantly (and > more on-topic here), why we have to have an analogon in Python. It exists because people nagged Guido mercilessly until, against his better judgment, he capitulated. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From saimapk81 at gmail.com Tue Mar 30 16:33:15 2010 From: saimapk81 at gmail.com (saima81) Date: Tue, 30 Mar 2010 13:33:15 -0700 (PDT) Subject: "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ Message-ID: <57003757-f992-4c10-82d5-1d91fe247d35@z35g2000yqd.googlegroups.com> "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ From lxkain at gmail.com Tue Mar 30 16:43:42 2010 From: lxkain at gmail.com (LX) Date: Tue, 30 Mar 2010 13:43:42 -0700 (PDT) Subject: decorators only when __debug__ == True References: Message-ID: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> On Mar 29, 6:34?pm, MRAB wrote: > LX wrote: > > Hi all, I have a question about decorators. I would like to use them > > for argument checking, and pre/post conditions. However, I don't want > > the additional overhead when I run in non-debug mode. I could do > > something like this, using a simple trace example. > > > @decorator > > def pass_decorator(f, *args, **kw): # what about the slow-down that > > incurs when using pass_decorator? > > ? ? return f(*args, **kw) > > > @decorator > > def trace_decorator(f, *args, **kw): > > ? ? print "calling %s with args %s, %s" % (f.func_name, args, kw) > > ? ? return f(*args, **kw) > > > trace_enable_flag = False #__debug__ > > trace = trace_decorator if trace_enable_flag else pass_decorator > > > Trouble is, there is still an additional encapsulating function call. > > Is there any way to eliminate the extra function call altogether? > > Thanks in advance! > > I think you have misunderstood certain details about decorators. > > This code with a decorator: > > ? ? ?@decorator > ? ? ?def hello(): > ? ? ? ? ?print "hello world" > > basically does this: > > ? ? ?def hello(): > ? ? ? ? ?print "hello world" > ? ? ?hello = decorator(hello) > > so your non-decorator just needs to return the function it was passed: > > ? ? ?def pass_decorator(func): > ? ? ? ? ?return func > > and your trace decorator would be something like this: > > ? ? ?def trace_decorator(func): > ? ? ? ? ?def show(*args, **kwargs): > ? ? ? ? ? ? ?print "calling %s with args %s, %s" % (func.func_name, > args, kwargs) > ? ? ? ? ? ? ?result = func(*args, **kwargs) > ? ? ? ? ? ? ?print "returning %s from %s" % (result, func.func_name) > ? ? ? ? ? ? ?return result > ? ? ? ? ?return show Sure, but during runtime, pass_decorator will still be called, even though it doesn't do anything. I am wondering if I can disable this additional function call at non-debug runtime. In other words, I want the calling stack to contain no decorator at all, not even pass_decorator. I should mention that, in my code, the symbol "decorator" is imported from Michele Simionato's decorator.py file. From lxkain at gmail.com Tue Mar 30 16:44:40 2010 From: lxkain at gmail.com (LX) Date: Tue, 30 Mar 2010 13:44:40 -0700 (PDT) Subject: decorators only when __debug__ == True References: Message-ID: On Mar 29, 7:11?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 17:54:26 -0700, LX wrote: > > Hi all, I have a question about decorators. I would like to use them for > > argument checking, and pre/post conditions. However, I don't want the > > additional overhead when I run in non-debug mode. I could do something > > like this, using a simple trace example. > > def decorator(func): > ? ? if __debug__: > ? ? ? ? @functools.wraps(func) > ? ? ? ? def inner(*args, **kwargs): > ? ? ? ? ? ? preprocess() > ? ? ? ? ? ? result = func(*args, **kwargs) > ? ? ? ? ? ? postprocess() > ? ? ? ? ? ? return result > ? ? ? ? return inner > ? ? else: > ? ? ? ? return func > > -- > Steven Actually, I am using "decorator" from Michele Simionato's decorator.py file, at http://pypi.python.org/pypi/decorator. From anton.shishkov at gmail.com Tue Mar 30 16:47:42 2010 From: anton.shishkov at gmail.com (ASh) Date: Tue, 30 Mar 2010 13:47:42 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: Message-ID: Hi, please help me understand why am I getting error with this query new_start_date = "NOW() - '29 days'::INTERVAL" self.dyndb.orderdb.query('''update xxxx set creation_date = %s where id_order = %s''', (new_start_date, "123")) ... psycopg2.DataError: invalid input syntax for type timestamp with time zone: "NOW() - '29 days'::INTERVAL" From news1234 at free.fr Tue Mar 30 17:01:40 2010 From: news1234 at free.fr (News123) Date: Tue, 30 Mar 2010 23:01:40 +0200 Subject: xpat error in xmlrp client. How to inspect data. In-Reply-To: References: <4bab1f4a$0$25677$426a74cc@news.free.fr> Message-ID: <4bb266b5$0$21786$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Thu, 25 Mar 2010 05:31:05 -0300, News123 escribi?: > >> I'm havign a small xmlrpc client, which works normally fine. >> (xmlrpc via https) >> >> Sometimes however I receive an Exception about an expat error. >> >> >> The output, that I receive is: >> File "C:\mycode\myrpcclient.py", line 63, in upload_chunk >> rslt = myrpcclient.call() >> File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ >> return self.__send(self.__name, args) >> File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request >> verbose=self.__verbose >> File "C:\Python26\lib\xmlrpclib.py", line 1253, in request >> return self._parse_response(h.getfile(), sock) >> File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response >> p.feed(response) >> File "C:\Python26\lib\xmlrpclib.py", line 601, in feed >> self._parser.Parse(data, 0) >> ExpatError: syntax error: line 1, column 0 >> > > a) Use the standard cgitb module (despite its name, it is useful outside > CGI scripts) > > b) Use the tb module available from http://pypi.python.org/pypi/tb > I'm currently using the default module traceback and code, which looks roughly like: try: xmlrpccall() except Exception as e: ex_type,ex_value,e_b = sys.exc_info() tbstring = traceback.format_exc() logging.error('%s:%s:%s' % (ex_type,ex_value,tbstring) do cgitb or tb really provide much more info? > Both provide a more verbose traceback, including local variables at each > execution frame. > > c) Replace ("monkey-patch") the feed() method with a more debug-friendly > version: > > def feed(self, data): > try: > self._parser.Parse(data, 0) > except xmlrpclib.expat.ExpatError, e: > e.args += (data,) > raise > > xmlrpclib.ExpatParser.feed = feed Well, the monkey patch seems to be THE solution for my problem. Thanks a lot. Now I'll just have to wait till the problem shows up again. Probably I'll just display the backtrace in the except section. > > (Or perhaps set e.data = data) > > d) In your exception handler, walk the traceback object until you reach > the feed() call, and inspect the corresponding tb_frame.f_locals > dictionary. How can I walk a traceback? For the current problem the the monkeypatch should be good enough, but for other cases it might be good to know. bye N From mensanator at aol.com Tue Mar 30 17:05:44 2010 From: mensanator at aol.com (Mensanator) Date: Tue, 30 Mar 2010 14:05:44 -0700 (PDT) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: <951faaf2-affd-474c-811b-157579b2897c@g10g2000yqh.googlegroups.com> On Mar 30, 1:52?pm, MRAB wrote: > John Nagle wrote: > > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: > >>> On Mar 30, 8:13 am, aditya wrote: > > >>>> To get the decimal representation of a binary number, I can just do > >>>> this: > >>>> int('11',2) # returns 3 > >>>> But decimal binary numbers throw a ValueError: > >>>> int('1.1',2) # should return 1.5, throws error instead. > >>>> Is this by design? It seems to me that this is not the correct > >>>> behavior. > >>> The int() constructor returns integers. > >>> So, look to float() for non-integral values. > >>> Binary representation isn't supported yet, > >>> but we do have hex: > > >>> ? ? >>> float.fromhex('1.8') > >>> ? ? 1.5 > > >>> Raymond > > >> That looks very elegant, thanks! > > > ? ?Hex floats are useful because you can get a string representation > > of the exact value of a binary floating point number. ?It should > > always be the case that > > > ? ? ?float.fromhex(float.hex(x)) == x > > > That's not always true of decimal representations, due to rounding > > problems. > > Floats have a limited length, unlike ints which are virtually unlimited. gmpy gives you arbitrary precision floats, also. > > > > > Long discussion of this here: "http://bugs.python.org/issue1580"- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - From philip at semanchuk.com Tue Mar 30 17:26:51 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 30 Mar 2010 17:26:51 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: References: Message-ID: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> On Mar 30, 2010, at 4:47 PM, ASh wrote: > Hi, please help me understand why am I getting error with this query > > > new_start_date = "NOW() - '29 days'::INTERVAL" > self.dyndb.orderdb.query('''update xxxx set creation_date > = %s > where id_order = %s''', (new_start_date, "123")) > > > > ... > psycopg2.DataError: invalid input syntax for type timestamp with time > zone: "NOW() - '29 days'::INTERVAL" Hi Anton, It sounds to me like the problem is with your SQL rather than with psycopg2 or Python. Try the query directly in Postgres -- does it work there? If so, then your next step should be to ask on the psycopg2 mailing list that Google can find for you. Good luck Philip From hp6 at rice.edu Tue Mar 30 17:31:58 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 16:31:58 -0500 Subject: A question about making a sort-of-counter. Message-ID: <4BB26DCE.7070307@rice.edu> Suppose I have a list. a = list() And suppose allowed digits as the element are 1,2,3,4,5. What can I do in order to iterate over all possible values for each element? For instance, the sequence of the list I want to have would be [1,1,1,1,1] [1,1,1,1,2] [1,1,1,1,3] .... [5,5,5,5,4] [5,5,5,5,5] How can I make it happen? Thanks, Justin. From python at mrabarnett.plus.com Tue Mar 30 17:41:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 22:41:31 +0100 Subject: decorators only when __debug__ == True In-Reply-To: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <4BB2700B.90200@mrabarnett.plus.com> LX wrote: > On Mar 29, 6:34 pm, MRAB wrote: >> LX wrote: >>> Hi all, I have a question about decorators. I would like to use them >>> for argument checking, and pre/post conditions. However, I don't want >>> the additional overhead when I run in non-debug mode. I could do >>> something like this, using a simple trace example. >>> @decorator >>> def pass_decorator(f, *args, **kw): # what about the slow-down that >>> incurs when using pass_decorator? >>> return f(*args, **kw) >>> @decorator >>> def trace_decorator(f, *args, **kw): >>> print "calling %s with args %s, %s" % (f.func_name, args, kw) >>> return f(*args, **kw) >>> trace_enable_flag = False #__debug__ >>> trace = trace_decorator if trace_enable_flag else pass_decorator >>> Trouble is, there is still an additional encapsulating function call. >>> Is there any way to eliminate the extra function call altogether? >>> Thanks in advance! >> I think you have misunderstood certain details about decorators. >> >> This code with a decorator: >> >> @decorator >> def hello(): >> print "hello world" >> >> basically does this: >> >> def hello(): >> print "hello world" >> hello = decorator(hello) >> >> so your non-decorator just needs to return the function it was passed: >> >> def pass_decorator(func): >> return func >> >> and your trace decorator would be something like this: >> >> def trace_decorator(func): >> def show(*args, **kwargs): >> print "calling %s with args %s, %s" % (func.func_name, >> args, kwargs) >> result = func(*args, **kwargs) >> print "returning %s from %s" % (result, func.func_name) >> return result >> return show > > Sure, but during runtime, pass_decorator will still be called, even > though it doesn't do anything. I am wondering if I can disable this > additional function call at non-debug runtime. In other words, I want > the calling stack to contain no decorator at all, not even > pass_decorator. > > I should mention that, in my code, the symbol "decorator" is imported > from Michele Simionato's decorator.py file. pass_decorator will be called when the decorated function is _defined_, but not when the decorated function is _called_. From python at mrabarnett.plus.com Tue Mar 30 17:43:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 22:43:04 +0100 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <20100330221600.42cd3536@vulcan.local> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <4BB27068.9020009@mrabarnett.plus.com> Robert Fendt wrote: > And thus spake John Bokma > Tue, 30 Mar 2010 13:19:19 -0600: > >> And >> >> a == b and 'Yes' or 'No' >> >> isn't a Perl-ism? > > I never said that this would be better. I don't even get the > point of what the advantage is supposed to be of inverting the > order of the return statement and the conditional check what > should actually _be_ returned. What's wrong with just writing > > if a==b: > return 'Yes' > else: > return 'No' > > apart from it being a few more line breaks and an additional > return statement? The inverted form is not more readable per > se (in fact, quite the opposite), and I would even suggest to > minimise its use even in languages like C++ and Java. The Python > syntax is even worse since it not only inverts the order of > return statement and conditional check, but it also puts the > conditional between the two results. > > I find such a convoluted construct especially ugly in a language > which I previously regarded as having a rather striking beauty > of syntactical simplicity. The construct is superfluous, > illogical, unelegant, and thus very un-pythonesque, IMHO. But of > course that's just my $0.02. > I think you mean that it's very _un-Pythonic_ (perhaps because it's very very Pythonesque)! :-) >> Sheesh, this group would be so much nicer without the constant dragging >> in of Perl to make a point. On top of that, do { } unless blocks are >> not idomatic in Perl. Perl Best Practices even clearly states to *never* >> use unless. > > Sorry, but you have just underlined my point, in fact. If it's > discouraged by experts, then of course the question must be > valid why such a feature even exists (okay, apart from 'it > seemed like a good idea at the time'). And more importantly (and > more on-topic here), why we have to have an analogon in Python. > From no.spam at local.local Tue Mar 30 17:47:27 2010 From: no.spam at local.local (Robert Fendt) Date: Tue, 30 Mar 2010 23:47:27 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <20100330234727.25bcbda8@vulcan.local> And thus spake MRAB Tue, 30 Mar 2010 22:43:04 +0100: > I think you mean that it's very _un-Pythonic_ (perhaps because it's very > very Pythonesque)! :-) Yes. Of course. What was I thinking. ;-) Regards, Robert From mail at hellmutweber.de Tue Mar 30 17:49:24 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Tue, 30 Mar 2010 23:49:24 +0200 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BB271E4.4000505@hellmutweber.de> Hi Peter and Jean-Michel, thanks for all your hints and pieces of code. It took me a while to play around with what I got from you (and some study of Vinay's module documentation. Now I have come up with a more complete solution I'm quite satisfied with. And I would be very glad to receive your comments on my code indicating what I could do better, given that I'm still at the very beginning with python. Cheers + TIA Hellmut Here is my module and a corresponding test program: leo at sylvester hw_logg $ cat loc_logg.py #!/bin/env python # -*- coding: utf-8 -*- """Hw's local logging module To be done: Factorize 'trace' decorator to own module (to permit dependency on debug level) ??? """ import sys # Basic system functions import logging # Logging base import logging.handlers import inspect # monkey patch caller filename # --- color change strings for terminal output --- # pc_yell = '\033[01;93m' pc_purp = '\033[01;33m' pc_gren = '\033[01;92m' pc_blue = '\033[01;94m' # pc_bold = '\033[01;1m' pc_norm = '\033[0m' # pc_reed = '\033[01;91m' pc_cyan = '\033[01;96m' level_color = { 'fatal': pc_yell, 'error': pc_yell, 'warning': pc_purp, 'info': pc_gren, 'debug': pc_blue, 'bold': pc_bold, 'normal': pc_norm } # --- define string building help function --- # def argskw_2_string(*args, **kwargs): """Generate String from *args and **kwargs Return string with *args list (comma separated) in first line **kwargs key=val list (comma separated) in second line """ _str_lines = [] if args: _args_strings = '' for a in args: _args_strings += str(a) + ', ' _str_lines.append(_args_strings) if kwargs: _kwargs_strings = '' for k in kwargs: _kwargs_strings += str(k)+' = '+str(kwargs[k]) + ', ' _str_lines.append(_kwargs_strings) return ''.join(_str_lines) # --- Class for all logging functionality --- # class locLogg(): _logger = None def __init__(self, newlogg=None): if not locLogg._logger: locLogg._logger = newlogg def init_logging(self, loclogg_output='line', # stream or/and file loclogg_fname='loggfile.txt', loclogg_dblevel='DEBUG' ): """Initiate logging with locLogg._logger Defines the logging handler to be used and initiates it. Possible values for loclogg_output: line ==> output to console file ==> log_file must be given both ==> log_file must be given null ==> no logging (NullHandler) """ locLogg._logger.handlers=[] if loclogg_output in ('null'): class NullHandler(logging.Handler): def emit(self, record): pass locLogg._logger.addHandler(NullHandler()) if loclogg_output in ('line', 'both'): locLogg._logger.addHandler(logging.StreamHandler()) if loclogg_output in ('file', 'both'): locLogg._logger.addHandler( logging.handlers.RotatingFileHandler(loclogg_fname, maxBytes=200000, backupCount=5) ) for _loc_logger in locLogg._logger.handlers: _loc_logger.setFormatter(logging.Formatter( '%(asctime)s ' + \ '%(custom_filename)s <%(custom_lineno)d>:' + \ '%(levelname)s %(message)s')) # Can this be done better ? _loc_levels = {'NOTSET': 0, 'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'ERROR': 40, 'CRITICAL': 50} locLogg._logger.setLevel(_loc_levels[loclogg_dblevel]) def info_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.info(str(level_color['info'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno': previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def debug_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.debug(str(level_color['debug'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def warn_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.debug(str(level_color['warning'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def error_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.error(str(level_color['error'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def fatal_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.fatal(str(level_color['fatal'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) # --- Permit definition of a tracing decorator --- from decorator import decorator @decorator def trace(f, *args, **kw): print "@trace: calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) # cf. doc of Michele Simoniato's decorator module if __name__ == '__main__': _logger = logging.getLogger('jmp_logg__main__') foo = locLogg(_logger) foo.init_logging() foo.info_log('a foo info') foo.info_log('another bar info', 1,2,3, a=11, b=22, c=44) foo.debug_log('a debug bar info', 'a', '1aA', qwe=2, asd=99) foo.warn_log('a test info', 'ggg', '2U2', yxcv=2, asdf=99) try: b = 123 c = 0 a = b / c except: foo.fatal_log('Division by zero', b=123, c=0) leo at sylvester hw_logg $ cat test_loclogg.py #!/bin/env python # -*- coding: utf-8 -*- import logging _logger = logging.getLogger() import sys pyDevelDir = '/home/leo/leo/brbeit/py-devel/Modules' sys.path.append(pyDevelDir) from hw_logg.loc_logg import locLogg foo = locLogg(_logger) foo.init_logging( loclogg_output='both', loclogg_dblevel='DEBUG') import loc_module as jm foo.info_log('First info with args in string: %d %d %d' % (1,2,3)) foo.warn_log('First warning') foo.debug_log('First debug message TestTestTest', '----------', 4,5,6, 12*25, d=34, e='qwe') foo.debug_log('Before calling jm.doIt()') jm.doIt(True) foo.info_log('Second info with kwargs separate:', a=11,b=22,c=33) x = jm.MyClass(1, 2, 'abc') x.mymethod() x.mymethod(123, 234, a=1, b=2, c=3) try: jm.doIt(0) except Exception, e: foo.error_log(str(e), 1,5,8) foo.fatal_log('Fatal message') leo at sylvester hw_logg $ cat loc_module.py # -*- coding: utf-8 -*- import logging _logger = logging.getLogger('jmp_logger') import sys pyDevelDir = '/home/leo/leo/brbeit/py-devel/Modules' sys.path.append(pyDevelDir) from hw_logg.loc_logg import locLogg, trace foo = locLogg(_logger) foo.info_log("Start importing "+__name__) def doIt(yn=None): foo.debug_log("doin' stuff, yn =", str(yn)) # logLevel at calling point ! print '=====> Output from doIt:', yn #do stuff...but suppose an error occurs? if yn: foo.info_log('yn: good value') else: raise TypeError, "bogus type error for testing" class MyClass(object): @trace def __init__(self, *args, **kwargs): print 'MyClass.__init__' @trace def mymethod(self, *args, **kwargs): print 'MyClass.mymethod' foo.info_log("End importing "+__name__) -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From darcy at druid.net Tue Mar 30 17:50:56 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 30 Mar 2010 17:50:56 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: References: Message-ID: <20100330175056.ca69563c.darcy@druid.net> On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) ASh wrote: > Hi, please help me understand why am I getting error with this query > > > new_start_date = "NOW() - '29 days'::INTERVAL" > self.dyndb.orderdb.query('''update xxxx set creation_date > = %s > where id_order = %s''', (new_start_date, "123")) Put single quotes around the first %s in the query. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From robert.kern at gmail.com Tue Mar 30 17:58:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 16:58:34 -0500 Subject: A question about making a sort-of-counter. In-Reply-To: <4BB26DCE.7070307@rice.edu> References: <4BB26DCE.7070307@rice.edu> Message-ID: On 2010-03-30 16:31 PM, Justin Park wrote: > Suppose I have a list. > a = list() > And suppose allowed digits as the element are 1,2,3,4,5. > > What can I do in order to iterate over all possible values for each element? > For instance, the sequence of the list I want to have would be > [1,1,1,1,1] > [1,1,1,1,2] > [1,1,1,1,3] > > .... > > [5,5,5,5,4] > [5,5,5,5,5] > > How can I make it happen? def counter(n=5, length=5): for i in xrange(n ** length): x = [] for j in range(length): i, r = divmod(i, n) x.append(r) yield [k+1 for k in x[::-1]] -- 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 From anon at blank.com Tue Mar 30 18:00:13 2010 From: anon at blank.com (anon) Date: Tue, 30 Mar 2010 23:00:13 +0100 Subject: A question about making a sort-of-counter. In-Reply-To: References: Message-ID: Justin Park wrote: > Suppose I have a list. > a = list() > And suppose allowed digits as the element are 1,2,3,4,5. > > What can I do in order to iterate over all possible values for each element? > For instance, the sequence of the list I want to have would be > [1,1,1,1,1] > [1,1,1,1,2] > [1,1,1,1,3] > > .... > > [5,5,5,5,4] > [5,5,5,5,5] > > How can I make it happen? > > Thanks, > Justin. http://docs.python.org/library/itertools.html#itertools.product from itertools import product for item in product([1, 2], repeat=2): print item From invalid at invalid.invalid Tue Mar 30 18:01:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Mar 2010 22:01:14 +0000 (UTC) Subject: Can't get odtwriter to work Message-ID: I just installed odtwriter 1.3d on a Gentoo system running Python 2.6.4. I used the normal "python setup.py build" then "python setup.py install" method. But, odtwriter doesn't seem to work: rst2odt.py --help Traceback (most recent call last): File "/usr/bin/rst2odt.py", line 5, in pkg_resources.run_script('odtwriter==1.3d', 'rst2odt.py') File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 461, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1194, in run_script execfile(script_filename, namespace, namespace) File "/usr/lib/python2.6/site-packages/odtwriter-1.3d-py2.6.egg/EGG-INFO/scripts/rst2odt.py", line 21, in from docutils.writers.odtwriter import Writer, Reader ImportError: No module named odtwriter I verified that I have docutils installed: Python 2.6.4 (r264:75706, Mar 1 2010, 10:33:43) [GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import docutils >>> docutils What am I doing wrong? -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From crebert at ucsd.edu Tue Mar 30 18:08:17 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Tue, 30 Mar 2010 15:08:17 -0700 Subject: A question about making a sort-of-counter. In-Reply-To: <4BB26DCE.7070307@rice.edu> References: <4BB26DCE.7070307@rice.edu> Message-ID: <50697b2c1003301508w7dca3ab0pb9468a7a90afdd45@mail.gmail.com> On Tue, Mar 30, 2010 at 2:31 PM, Justin Park wrote: > Suppose I have a list. > a = list() > And suppose allowed digits as the element are 1,2,3,4,5. > > What can I do in order to iterate over all possible values for each element? > For instance, the sequence of the list I want to have would be > [1,1,1,1,1] > [1,1,1,1,2] > [1,1,1,1,3] > > .... > > [5,5,5,5,4] > [5,5,5,5,5] > > How can I make it happen? allowed = range(1,6) length = 5 for counter_tuple in product(allowed, repeat=length): counter_list = list(counter_tuple) # if you really need a list #do whatever with the counter value See the docs for itertools.product(); an example virtually identical to your situation is given: http://docs.python.org/library/itertools.html#itertools.product Cheers, Chris -- http://blog.rebertia.com From hp6 at rice.edu Tue Mar 30 18:12:28 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 17:12:28 -0500 Subject: A question about making a sort-of-counter. In-Reply-To: <50697b2c1003301508w7dca3ab0pb9468a7a90afdd45@mail.gmail.com> References: <4BB26DCE.7070307@rice.edu> <50697b2c1003301508w7dca3ab0pb9468a7a90afdd45@mail.gmail.com> Message-ID: <4BB2774C.7040906@rice.edu> Thanks! It works! Justin. Chris Rebert wrote: > On Tue, Mar 30, 2010 at 2:31 PM, Justin Park wrote: > >> Suppose I have a list. >> a = list() >> And suppose allowed digits as the element are 1,2,3,4,5. >> >> What can I do in order to iterate over all possible values for each element? >> For instance, the sequence of the list I want to have would be >> [1,1,1,1,1] >> [1,1,1,1,2] >> [1,1,1,1,3] >> >> .... >> >> [5,5,5,5,4] >> [5,5,5,5,5] >> >> How can I make it happen? >> > > allowed = range(1,6) > length = 5 > for counter_tuple in product(allowed, repeat=length): > counter_list = list(counter_tuple) # if you really need a list > #do whatever with the counter value > > See the docs for itertools.product(); an example virtually identical > to your situation is given: > http://docs.python.org/library/itertools.html#itertools.product > > Cheers, > Chris > -- > http://blog.rebertia.com > > From apt.shansen at gmail.invalid Tue Mar 30 18:17:28 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Tue, 30 Mar 2010 15:17:28 -0700 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <2010033015172862741-aptshansen@gmailinvalid> On 2010-03-30 13:16:00 -0700, Robert Fendt said: > > I find such a convoluted construct especially ugly in a language > which I previously regarded as having a rather striking beauty > of syntactical simplicity. The construct is superfluous, > illogical, unelegant, and thus very un-pythonesque, IMHO. But of > course that's just my $0.02. In Python before list-comprehensions, I might have agreed with you. Initially, I was quite resistant to list comprehensions as well. They seemed ugly, and backwards, and why not just write a for loop? Then I got used to them, and I find they are very elegant when used properly. Sometimes you can do something ugly with them, but its actually quite possible to write positively hideous Python even without any of these new fancy shmancy features. But, in the post-comprehension world, where one can do: my_odds = [x for x in range(100) if x % 2 == 1] Things have changed. I've now grown used to reading expressions like that which seem a bit backwards, with the value being returned by an expression is the left-most element. Its not an exact correlation because they're answering different problems. But having gotten used to list comprehensions, and actually quite appreciating their elegance now, I find this reads very well: is_odd = "odd" if x % 2 == 1 else "even" In fact, it reads better then any of the other conditional expression syntaxes people proposed back in the day, and a LOT better then what was done before: is_odd = x % 2 == 1 and "odd" or "even" Even if the above falls a bit more in line with what other languages usually do order-wise, this isn't other languages. Now, none of this addresses your original argument of why not just use a regular if statement. I dunno, I often used "and/or" for simple expressions or defaults and found it very convienent and made code more readable then the line and whitespace inducing true if-statement. And so I'm glad to have something even more readable and without the bug-prone and/or error. Why not just use a for loop anytime you use a list comprehension? :) Same question really applies. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From invalid at invalid.invalid Tue Mar 30 18:20:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Mar 2010 22:20:29 +0000 (UTC) Subject: Can't get odtwriter to work References: Message-ID: On 2010-03-30, Grant Edwards wrote: > I just installed odtwriter 1.3d on a Gentoo system running Python > 2.6.4. I used the normal "python setup.py build" then "python > setup.py install" method. But, odtwriter doesn't seem to work: > > rst2odt.py --help > > Traceback (most recent call last): > File "/usr/bin/rst2odt.py", line 5, in > pkg_resources.run_script('odtwriter==1.3d', 'rst2odt.py') > File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 461, in run_script > self.require(requires)[0].run_script(script_name, ns) > File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1194, in run_script > execfile(script_filename, namespace, namespace) > File "/usr/lib/python2.6/site-packages/odtwriter-1.3d-py2.6.egg/EGG-INFO/scripts/rst2odt.py", line 21, in > from docutils.writers.odtwriter import Writer, Reader > ImportError: No module named odtwriter > > I verified that I have docutils installed: > > Python 2.6.4 (r264:75706, Mar 1 2010, 10:33:43) > [GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import docutils > >>> docutils > > > What am I doing wrong? I'm not sure what/if I did wrong when installing docutils/odtwriter, but I managed to make it work by manually copying everything from /usr/lib/python2.6/site-packages/odtwriter-1.3d-py2.6.egg/docutils/writers to /usr/lib/python2.6/site-packages/docutils/writers I think that means that odtwriter's setup.py is old/broken, but I don't know enough to fix it... -- Grant Edwards grant.b.edwards Yow! I'm having a MID-WEEK at CRISIS! gmail.com From no.spam at local.local Tue Mar 30 18:32:41 2010 From: no.spam at local.local (Robert Fendt) Date: Wed, 31 Mar 2010 00:32:41 +0200 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <20100331003241.47fa91f6@vulcan.local> And thus spake "Alf P. Steinbach" Tue, 30 Mar 2010 13:40:22 +0200: > > From a usability standpoint, the braces go with the lines to print out the > stanza rather than the for statement or the code after, so the following is best: > > for(i = 99; i > 0; ++i) > { > printf("%d slabs of spam in my mail!\n", i); > printf("%d slabs of spam,\n", i); > printf("Send one to abuse and Just Hit Delete,\n"); > printf("%d slabs of spam in my mail!\n\n", i + 1); > } > I liked this one even more: One way of writing the same code in Python would be: count = 99 while count > 0: print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' The braces are gone, and with them the holy wars. Whatever brace styles Python programmers may happen to use in languages with braces, all the Python code looks the same, and while the major brace styles illustrated above are a few of many ways the C code could be laid out, there's only one real way to do it. Has the fact changed that Python does not care about (1) how many characaters you use for indentation, (1a) you can use tabs OR spaces, (2) indentation does not have to be consistent across a module, (3) not even across a file, (4) even in nested blocks and (5) you can even switch from spaces to tabs and back in the same file? So much for 'all the Python code looks the same'. In general I do not really see what qualifies the author for an article on Python's usability. On the same site one can also find a lot of things e.g. on intelligent design and creationism, and the 'The Case For Uncreative Web Design' in which the author advocates 'uncreative' (in the sense of non-distracting) web design while at the same time showcasing quite the opposite: suffice it to say I found most essays rather difficult to read from a technical point of view, to say nothing about the content. Regards, Robert From anton.shishkov at gmail.com Tue Mar 30 18:45:03 2010 From: anton.shishkov at gmail.com (ASh) Date: Tue, 30 Mar 2010 15:45:03 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: Message-ID: On Mar 31, 12:26?am, Philip Semanchuk wrote: > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > Hi, please help me understand why am I getting error with this query > > > ? ? ? ? ? ?new_start_date = "NOW() - '29 days'::INTERVAL" > > ? ? ? ? ? ?self.dyndb.orderdb.query('''update xxxx set creation_date > > = %s > > ? ? ? ? ? ?where id_order = %s''', (new_start_date, "123")) > > > ... > > psycopg2.DataError: invalid input syntax for type timestamp with time > > zone: "NOW() - '29 days'::INTERVAL" > > Hi Anton, > It sounds to me like the problem is with your SQL rather than with ? > psycopg2 or Python. Try the query directly in Postgres -- does it work ? > there? If so, then your next step should be to ask on the psycopg2 ? > mailing list that Google can find for you. > > Good luck > Philip sql itself is correct From anton.shishkov at gmail.com Tue Mar 30 18:46:12 2010 From: anton.shishkov at gmail.com (ASh) Date: Tue, 30 Mar 2010 15:46:12 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: Message-ID: On Mar 31, 12:50?am, "D'Arcy J.M. Cain" wrote: > On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) > > ASh wrote: > > Hi, please help me understand why am I getting error with this query > > > ? ? ? ? ? ? new_start_date = "NOW() - '29 days'::INTERVAL" > > ? ? ? ? ? ? self.dyndb.orderdb.query('''update xxxx set creation_date > > = %s > > ? ? ? ? ? ? where id_order = %s''', (new_start_date, "123")) > > Put single quotes around the first %s in the query. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. Tried like you said, got this error: psycopg2.ProgrammingError: syntax error at or near "NOW" LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 da... ^ From hp6 at rice.edu Tue Mar 30 18:50:18 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 17:50:18 -0500 Subject: Sometimes the python shell cannot recognize the presence of an attribute. Message-ID: <4BB2802A.7050500@rice.edu> Sometimes when I am working on an already generated package, the python shell cannot perceive the presence of an attribute that I implemented on top of what was there. Is there a way to have it perceive newly created attributes? Thanks, Justin. From hp6 at rice.edu Tue Mar 30 18:57:37 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 17:57:37 -0500 Subject: Sometimes the python shell cannot recognize the presence of an attribute. In-Reply-To: <4BB2802A.7050500@rice.edu> References: <4BB2802A.7050500@rice.edu> Message-ID: <4BB281E1.2030101@rice.edu> Sorry, my mistake. The real problem is this. When I started working on the package, somehow all of indentations were made by space-bars instead of using tabs. But when I am implementing my own on top of it, I still use tabs to make indentations. This is causing a problem. I have to either conform to their style and change all my tabs to the space-bars making up those spaces, or change all indentations in the previous implementations by tabs. But both the previous implementations and what I am going to do are also so large that either way is not going to be efficient. What can I do in order to resolve this issue? Thanks, Justin. Justin Park wrote: > Sometimes when I am working on an already generated package, > the python shell cannot perceive the presence of an attribute that I > implemented on top of what was there. > > Is there a way to have it perceive newly created attributes? > > Thanks, > Justin. > > From ldo at geek-central.gen.new_zealand Tue Mar 30 19:18:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 31 Mar 2010 12:18:21 +1300 Subject: (a==b) ? 'Yes' : 'No' References: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> Message-ID: In message <7316f3d2-bcc9-4a1a-8598- cdd5d41fd74b at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > (a==b) and 'YES' or 'NO' > > Yes, ugly Why would you say that?s ugly? By the way, you don?t need the parentheses. From clp2 at rebertia.com Tue Mar 30 19:20:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 16:20:32 -0700 Subject: "Usability, the Soul of Python" In-Reply-To: <20100331003241.47fa91f6@vulcan.local> References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <20100331003241.47fa91f6@vulcan.local> Message-ID: <50697b2c1003301620j376e4787xa8763cb0d21bd2f1@mail.gmail.com> On Tue, Mar 30, 2010 at 3:32 PM, Robert Fendt wrote: > And thus spake "Alf P. Steinbach" > Tue, 30 Mar 2010 13:40:22 +0200: >> >> ?From a usability standpoint, the braces go with the lines to print out the >> stanza rather than the for statement or the code after, so the following is best: >> >> for(i = 99; i > 0; ++i) >> ? ? ?{ >> ? ? ?printf("%d slabs of spam in my mail!\n", i); >> ? ? ?printf("%d slabs of spam,\n", i); >> ? ? ?printf("Send one to abuse and Just Hit Delete,\n"); >> ? ? ?printf("%d slabs of spam in my mail!\n\n", i + 1); >> ? ? ?} >> > > I liked this one even more: > > > One way of writing the same code in Python would be: > > count = 99 > while count > 0: > ? ?print u'%d slabs of spam in my mail!' % count > ? ?print u'%d slabs of spam,' % count > ? ?print u'Send one to abuse and Just Hit Delete,' > ? ?count += 1 > ? ?print u'%d slabs of spam in my mail!' % count > ? ?print u'' > > The braces are gone, and with them the holy wars. Whatever brace > styles Python programmers may happen to use in languages with > braces, all the Python code looks the same, and while the major > brace styles illustrated above are a few of many ways the C code > could be laid out, there's only one real way to do it. > > > Has the fact changed that Python does not care about (1) how > many characaters you use for indentation, (1a) you can use tabs > OR spaces, (2) indentation does not have to be consistent across > a module, (3) not even across a file, (4) even in nested blocks > and (5) you can even switch from spaces to tabs and back in the > same file? So much for 'all the Python code looks the same'. Since we're harping on block delimitation, I'll plug a post I did on the subject a little while ago: http://blog.rebertia.com/2010/01/24/of-braces-and-semicolons/ Hopefully it's more thorough than the OP's. Cheers, Chris From ldo at geek-central.gen.new_zealand Tue Mar 30 19:23:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 31 Mar 2010 12:23:46 +1300 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <20100331003241.47fa91f6@vulcan.local> Message-ID: In message <20100331003241.47fa91f6 at vulcan.local>, Robert Fendt wrote: > The braces are gone, and with them the holy wars. Let me start a new one. I would still put in some kind of explicit indicator of the end of the grouping construct: count = 99 while count > 0: print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' #end while From see at sig.for.address Tue Mar 30 19:25:38 2010 From: see at sig.for.address (Victor Eijkhout) Date: Tue, 30 Mar 2010 18:25:38 -0500 Subject: sort array, apply rearrangement to second Message-ID: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> I have two arrays, made with numpy. The first one has values that I want to use as sorting keys; the second one needs to be sorted by those keys. Obviously I could turn them into a dictionary of pairs and sort by the first member, but I think that's not very efficient, at least in space, and this needs to be done as efficiently as possible. I could use a hand. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From ldo at geek-central.gen.new_zealand Tue Mar 30 19:32:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 31 Mar 2010 12:32:42 +1300 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: In message , Alf P. Steinbach wrote: > This is just unsubstantiated opinion, but worse, it makes a tacit > assumption that there is "best" way to do indentation. However, most > programmers fall into that trap, and I've done it myself. Having used so many different languages over the years, I have settled on a reasonably common set of indentation conventions that work across most of them. The only one that currently annoys me is JavaScript, because its semicolons- are-optional rule means that certain ways I write statements continued across multiple lines are interpreted as prematurely completing the statement. In revenge for that, I refuse to put optional semicolons in my JavaScript code altogether. > I may or may not have been responsible for the similarly impractical > compromise convention of using three spaces per indentation level. At > least, in one big meeting the question about number of spaces was raised > by the speaker, and I replied from the benches, just in jest, "three!". > And that was it (perhaps). I use four. Why four? Because it?s divisible by two. Because I use the half- step (two columns) for lines containing nothing but bracketing symbols: for (i = 99; i > 0; --i) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i - 1); } /*for*/ for i := 99 downto 1 do begin writeln(i, " slabs of spam in my mail!"); writeln(i, " slabs of spam,"); writeln("Send one to abuse and Just Hit Delete,"); writeln(i - 1, " slabs of spam in my mail!\n\n") end {for} Actually this looks like another opportunity for a loop-with-exit-in-the- middle: for (i = 99;;) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); --i; if (i == 0) break; printf("%d slabs of spam in my mail!\n\n", i); } /*for*/ From hidura at gmail.com Tue Mar 30 19:33:25 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Tue, 30 Mar 2010 23:33:25 +0000 Subject: Fetch files from mail in python Message-ID: <0016e6470e5c57735f04830d0e5a@google.com> Hello list, i want to know how could i fetch a file from an email, what kind of library i have to use for that, actually i am working in the support of IMAP and POP3. Thanks. Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Mar 30 19:39:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 16:39:08 -0700 Subject: Fetch files from mail in python In-Reply-To: <0016e6470e5c57735f04830d0e5a@google.com> References: <0016e6470e5c57735f04830d0e5a@google.com> Message-ID: <50697b2c1003301639l4fa75583mc4b290b4c83664cf@mail.gmail.com> On Tue, Mar 30, 2010 at 4:33 PM, wrote: > Hello list, i want to know how could i fetch a file from an email, what kind > of library i have to use for that, actually i am working in the support of > IMAP and POP3. Next time, consult the Global Module Index (http://docs.python.org/modindex.html) before posting. IMAP: http://docs.python.org/library/imaplib.html POP: http://docs.python.org/library/poplib.html Cheers, Chris -- http://blog.rebertia.com From steve at holdenweb.com Tue Mar 30 19:43:41 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:43:41 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: References: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message <7316f3d2-bcc9-4a1a-8598- > cdd5d41fd74b at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > >> (a==b) and 'YES' or 'NO' >> >> Yes, ugly > > Why would you say that?s ugly? > > By the way, you don?t need the parentheses. But at the same time, if you don't *absolutely know* you don't need the parentheses then the parentheses are a very good idea, so I applaud the example as Pythonic while agreeing that it's ugly. A conditional expression seems more natural. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 30 19:44:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:44:53 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: <20100330175056.ca69563c.darcy@druid.net> References: <20100330175056.ca69563c.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) > ASh wrote: >> Hi, please help me understand why am I getting error with this query >> >> >> new_start_date = "NOW() - '29 days'::INTERVAL" >> self.dyndb.orderdb.query('''update xxxx set creation_date >> = %s >> where id_order = %s''', (new_start_date, "123")) > > Put single quotes around the first %s in the query. > And in future please tell us exactly what error you are trying to explain by quoting the traceback exactly. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Tue Mar 30 19:45:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 31 Mar 2010 01:45:35 +0200 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: * Victor Eijkhout: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. Just do the pairing, but in a 'list', not a dictionary (a dictionary is unordered and can't be sorted). You need to keep track of which keys belong to which values anyway. And anything in Python is a reference: you're not copying the data by creating the pairs. That is, the space overhead is proportional to the number of items but is independent of the data size of each item. Cheers & hth., - Alf From steve at holdenweb.com Tue Mar 30 19:52:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:52:25 -0400 Subject: Sometimes the python shell cannot recognize the presence of an attribute. In-Reply-To: <4BB281E1.2030101@rice.edu> References: <4BB2802A.7050500@rice.edu> <4BB281E1.2030101@rice.edu> Message-ID: Justin Park wrote: > Sorry, my mistake. > > The real problem is this. > When I started working on the package, somehow all of indentations were > made by space-bars instead of using tabs. > But when I am implementing my own on top of it, I still use tabs to make > indentations. > > This is causing a problem. > I have to either conform to their style and change all my tabs to the > space-bars making up those spaces, > or change all indentations in the previous implementations by tabs. > But both the previous implementations and what I am going to do are also > so large that either way is not going to be efficient. > > What can I do in order to resolve this issue? > You might try Googling for "expandtabs". This isn't a new problem, though I agree it can be very vexing when it's new to you ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 30 19:56:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:56:25 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. > Well, my first approach would be to do it as inefficiently as I can ( or at least no more efficiently than I can with a simple-minded approach) and then take it from there. If I believe this is not a premature optimization (a question about which I am currently skeptical) I'd suggest conversion to a list of pairs rather than a dict. Can you use zip() on numpy arrays? That would be the easiest way to create the list of pairs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From darcy at druid.net Tue Mar 30 20:10:34 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 30 Mar 2010 20:10:34 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: References: Message-ID: <20100330201034.020c3bf6.darcy@druid.net> On Tue, 30 Mar 2010 15:46:12 -0700 (PDT) ASh wrote: > > > ? ? ? ? ? ? new_start_date = "NOW() - '29 days'::INTERVAL" > > > ? ? ? ? ? ? self.dyndb.orderdb.query('''update xxxx set creation_date > > > = %s > > > ? ? ? ? ? ? where id_order = %s''', (new_start_date, "123")) > > > > Put single quotes around the first %s in the query. > > Tried like you said, got this error: > > psycopg2.ProgrammingError: syntax error at or near "NOW" > LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 > da... Right. I misread it. Please show us the exact error that you get with the original code. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Tue Mar 30 20:12:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 20:12:54 -0400 Subject: "Usability, the Soul of Python" In-Reply-To: References: Message-ID: Jonathan Hayward wrote: > I've posted "Usability, the Soul of Python: An Introduction to the > Python Programming Language Through the Eyes of Usability", at: > > http://JonathansCorner.com/python/ > > The basic suggestion is that much of what works well in Python has > something to do with the usability it offers programmers. > > Enjoy. > Now try another one called "Brevity, the Soul of Technical Writing: An Introduction to Making Yourself Understood Through the Eyes of Readability". What I managed to read seemed to be making worthwhile points, but I felt a bit like I was wading through a steaming pile of irrelevant verbiage that actually made it more difficult to extract the useful nuggets. Bravo for undertaking this task, but I do feel the treatment needs work from a good copy editor. Of course you have to take into account my allergy to folksy metaphors and meandering discourse. Had I chosen your style I might instead have written the criticism above as: """ I would like to begin my critique of this paper with a feature that many competent technical writers completely fail to appreciate: why brevity is desirable in technical writing. Technical writing is not, of course, the only form of writing that there is. People have been writing ever since the first caveman decided he could leave marks on the wall of a cave to indicate that food could be had in the vicinity. The basic concept of brevity is that you should not, as a writer, use superfluous words because if you do then the reader will always be in doubt about which parts of your discourse are meaningful and which are merely decoration. ... """ And so on. As I say, this may be criticism dictated by my personal taste, but I feel you could condense the presentation considerably to good effect. Sorry if this offends. It's meant to help. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at mrabarnett.plus.com Tue Mar 30 20:13:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 31 Mar 2010 01:13:16 +0100 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: <4BB2939C.2040706@mrabarnett.plus.com> Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. > You could sort a list of the indices, using the first array to provide the keys. From hidura at gmail.com Tue Mar 30 20:47:47 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Wed, 31 Mar 2010 00:47:47 +0000 Subject: Fetch files from mail in python In-Reply-To: <50697b2c1003301639l4fa75583mc4b290b4c83664cf@mail.gmail.com> Message-ID: <0016e68ded464e17c304830e18f9@google.com> I did that but i want to know if i have a file inside the mail how could i download that file from my mail. On Mar 30, 2010 7:39pm, Chris Rebert wrote: > On Tue, Mar 30, 2010 at 4:33 PM, hidura at gmail.com> wrote: > > Hello list, i want to know how could i fetch a file from an email, what > kind > > of library i have to use for that, actually i am working in the support > of > > IMAP and POP3. > Next time, consult the Global Module Index > (http://docs.python.org/modindex.html) before posting. > IMAP: http://docs.python.org/library/imaplib.html > POP: http://docs.python.org/library/poplib.html > Cheers, > Chris > -- > http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Mar 30 20:56:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 17:56:27 -0700 Subject: Fetch files from mail in python In-Reply-To: <0016e68ded464e17c304830e18f9@google.com> References: <50697b2c1003301639l4fa75583mc4b290b4c83664cf@mail.gmail.com> <0016e68ded464e17c304830e18f9@google.com> Message-ID: <50697b2c1003301756u3c169616o3dc2a7bebbe70219@mail.gmail.com> > On Mar 30, 2010 7:39pm, Chris Rebert wrote: >> On Tue, Mar 30, 2010 at 4:33 PM, ?hidura at gmail.com> wrote: >> > Hello list, i want to know how could i fetch a file from an email, what >> > kind >> > of library i have to use for that, actually i am working in the support >> > of >> > IMAP and POP3. >> >> IMAP: http://docs.python.org/library/imaplib.html >> POP: http://docs.python.org/library/poplib.html On Tue, Mar 30, 2010 at 5:47 PM, wrote: > I did that but i want to know if i have a file inside the mail how could i > download that file from my mail. I believe you'd use the email.parser module: http://docs.python.org/library/email.parser.html Cheers, Chris From cs at zip.com.au Tue Mar 30 21:04:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 31 Mar 2010 12:04:43 +1100 Subject: "Usability, the Soul of Python" In-Reply-To: <7f014ea61003300725yf3dfcbdw2976160ca37f60f3@mail.gmail.com> References: <7f014ea61003300725yf3dfcbdw2976160ca37f60f3@mail.gmail.com> Message-ID: <20100331010443.GA12592@cskk.homeip.net> On 30Mar2010 10:25, Chris Colbert wrote: | not really, the int will eventually overflow and cycle around ;) | | On Tue, Mar 30, 2010 at 8:11 AM, Xavier Ho wrote: | | > Did no one notice that | > for(i = 99; i > 0; ++i) | > Gives you an infinite loop (sort of) because i starts a 99, and increases | > every loop? And here we see the strength of the Usability example; in Python it won't overflow, rather seguing seamlessly into an increasing expensive arbitrary sized int. Though most machines will eventually run out of memory to hold it... -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Surely it was of this place, now Cambridge but formerly known by the name of Babylon, that the prophet spoke when he said, 'the wild beasts of the desert shall dwell there, and their houses shall be full of doleful creatures, and owls shall build there, and satyrs shall dance there.' - Thomas Gray (1716-1771) From john at castleamber.com Tue Mar 30 21:22:42 2010 From: john at castleamber.com (John Bokma) Date: Tue, 30 Mar 2010 19:22:42 -0600 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <87hbnxz3ml.fsf@castleamber.com> Robert Fendt writes: > And thus spake John Bokma > Tue, 30 Mar 2010 13:19:19 -0600: > >> And >> >> a == b and 'Yes' or 'No' >> >> isn't a Perl-ism? > > I never said that this would be better. It was not my intention to imply you did. But yet I do see books on Python mention the and or usage, and personally I think the ... if ... else is preferable. > point of what the advantage is supposed to be of inverting the > order of the return statement and the conditional check what > should actually _be_ returned. What's wrong with just writing > > if a==b: > return 'Yes' > else: > return 'No' To me the else is adding unneeded noise, I would just write: if a==b: return 'Yes' return 'No' > apart from it being a few more line breaks and an additional > return statement? The inverted form is not more readable per > se (in fact, quite the opposite), and I would even suggest to > minimise its use even in languages like C++ and Java. The Python > syntax is even worse since it not only inverts the order of > return statement and conditional check, but it also puts the > conditional between the two results. I use(d) the if ... else as follows (per Programming in Python 3): list = [] if list is None else list in Perl I would've written: defined $list or $list = []; Which I prefer over: $list = [] unless defined $list; and more over: $list = [] if not defined $list; To me the first Perl form reads as a pre-condition: the list must be defined *or* make it so. And maybe you're right, the Python one could've been written: if list is None: list = [] which looks, now, also more readable to me as well. >> Sheesh, this group would be so much nicer without the constant dragging >> in of Perl to make a point. On top of that, do { } unless blocks are >> not idomatic in Perl. Perl Best Practices even clearly states to *never* >> use unless. > > Sorry, but you have just underlined my point, in fact. If it's > discouraged by experts, then of course the question must be > valid why such a feature even exists (okay, apart from 'it > seemed like a good idea at the time'). I guess the latter. Perl has quite some things that in retrospect could've been done better. On the other hand, Perl developers are very fanatic about backwards compatibility, which makes it hard to remove stuff like unless. On top of that Perl can't be statically analyzed, meaning you can't just write a perl4to5 or perl510to512 converter. > And more importantly (and > more on-topic here), why we have to have an analogon in Python. My point. You can sufficiently argue what's wrong with if..else in Python 3 without dragging Perl into it and staying in Python context. I am both a Perl and (learning) Python programmer, and to be honest I get very tired of the somewhat weekly omg Perl suxxxorsss!!11111 Each language has its own suckage. There are several reasons why while I am learning Python I also keep updating my Perl skills ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From sccolbert at gmail.com Tue Mar 30 21:59:32 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 21:59:32 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: On Tue, Mar 30, 2010 at 7:25 PM, Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. > > Victor. > -- > Victor Eijkhout -- eijkhout at tacc utexas edu > -- > http://mail.python.org/mailman/listinfo/python-list > I'm not quite sure what you are asking, but there is probably an efficient way to do it in pure numpy. You can either post an example of what you want here, or better, take it to the NumPy mailing list and I will help you there. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sccolbert at gmail.com Tue Mar 30 22:11:41 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 22:11:41 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: On Tue, Mar 30, 2010 at 9:59 PM, Chris Colbert wrote: > > > On Tue, Mar 30, 2010 at 7:25 PM, Victor Eijkhout wrote: > >> I have two arrays, made with numpy. The first one has values that I want >> to use as sorting keys; the second one needs to be sorted by those keys. >> Obviously I could turn them into a dictionary of pairs and sort by the >> first member, but I think that's not very efficient, at least in space, >> and this needs to be done as efficiently as possible. >> >> I could use a hand. >> >> Victor. >> -- >> Victor Eijkhout -- eijkhout at tacc utexas edu >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > I'm not quite sure what you are asking, but there is probably an efficient > way to do it in pure numpy. You can either post an example of what you want > here, or better, take it to the NumPy mailing list and I will help you > there. > > This seems to be what you want: http://stackoverflow.com/questions/1903462/how-can-i-zip-sort-parallel-numpy-arrays -------------- next part -------------- An HTML attachment was scrubbed... URL: From russ.paielli at gmail.com Tue Mar 30 22:18:50 2010 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 30 Mar 2010 19:18:50 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <60a3bde8-c503-4d14-89f0-a68f683afd32@x3g2000yqd.googlegroups.com> On Mar 30, 10:08?am, John Nagle wrote: > Chris Rebert wrote: > > On Tue, Mar 30, 2010 at 8:40 AM, gentlestone wrote: > >> Hi, how can I write the popular C/JAVA syntax in Python? > > >> Java example: > >> ? ?return (a==b) ? 'Yes' : 'No' > > >> My first idea is: > >> ? ?return ('No','Yes')[bool(a==b)] > > >> Is there a more elegant/common python expression for this? > > > Yes, Python has ternary operator-like syntax: > > return ('Yes' if a==b else 'No') > > > Note that this requires a recent version of Python. > > ? ? ?Who let the dogs in? ?That's awful syntax. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Baloney. The Python ternary syntax is perfectly fine. The "if" could have been put in front, as in Scala: return if a == b "yes" else "no" but either way is fine and perfectly readable as far as I am concerned. From python.list at tim.thechases.com Tue Mar 30 22:25:13 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Mar 2010 21:25:13 -0500 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <87hbnxz3ml.fsf@castleamber.com> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> <87hbnxz3ml.fsf@castleamber.com> Message-ID: <4BB2B289.9050301@tim.thechases.com> John Bokma wrote: > And maybe you're right, the Python one could've been written: > > if list is None: > list = [] > > which looks, now, also more readable to me as well. Though there's a slight difference[1], I'd usually use lst = lst or [] for your particular initialization use case. -tkc [1] Difference being >>> lst = [] >>> other = lst >>> if lst is None: # your code ... lst = [] ... >>> other.append(42) >>> lst, other ([42], [42]) >>> lst = [] >>> other = lst >>> lst = lst or [] # my proposal >>> other.append(42) >>> lst, other ([], [42]) From robert.kern at gmail.com Tue Mar 30 23:00:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 22:00:38 -0500 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: On 2010-03-30 18:25 , Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. second[first.argsort()] Ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists -- 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 From keeloh at rocketmail.com Tue Mar 30 23:39:53 2010 From: keeloh at rocketmail.com (POOJA) Date: Tue, 30 Mar 2010 20:39:53 -0700 (PDT) Subject: Consolidate Credit Card Debt Message-ID: <5270502a-1fc4-41cf-8427-30c5dee865fd@k5g2000prg.googlegroups.com> Consolidate Credit Card Debt ------------------------------ http://sites.google.com/site/creditcarddebtconsolidation33 From gagsl-py2 at yahoo.com.ar Wed Mar 31 02:22:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 31 Mar 2010 03:22:54 -0300 Subject: xpat error in xmlrp client. How to inspect data. References: <4bab1f4a$0$25677$426a74cc@news.free.fr> <4bb266b5$0$21786$426a74cc@news.free.fr> Message-ID: En Tue, 30 Mar 2010 18:01:40 -0300, News123 escribi?: > Gabriel Genellina wrote: >> En Thu, 25 Mar 2010 05:31:05 -0300, News123 escribi?: >> >>> I'm havign a small xmlrpc client, which works normally fine. >>> (xmlrpc via https) >>> >>> Sometimes however I receive an Exception about an expat error. >>> >>> >>> The output, that I receive is: >>> File "C:\mycode\myrpcclient.py", line 63, in upload_chunk >>> rslt = myrpcclient.call() >>> File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ >>> return self.__send(self.__name, args) >>> File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request >>> verbose=self.__verbose >>> File "C:\Python26\lib\xmlrpclib.py", line 1253, in request >>> return self._parse_response(h.getfile(), sock) >>> File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response >>> p.feed(response) >>> File "C:\Python26\lib\xmlrpclib.py", line 601, in feed >>> self._parser.Parse(data, 0) >>> ExpatError: syntax error: line 1, column 0 >>> >> >> a) Use the standard cgitb module (despite its name, it is useful outside >> CGI scripts) >> >> b) Use the tb module available from http://pypi.python.org/pypi/tb >> > I'm currently using the default module traceback and code, which looks > roughly like: > > try: > xmlrpccall() > except Exception as e: > ex_type,ex_value,e_b = sys.exc_info() > tbstring = traceback.format_exc() > logging.error('%s:%s:%s' % (ex_type,ex_value,tbstring) > > > do cgitb or tb really provide much more info? Well, for each frame along the stack, cgitb shows the value of all function arguments, the value of each name referenced, and a few more lines of code around the current one. It's rather verbose, but doesn't include all local variables. The tb module shows -also for each frame along the stack- the value of all its local names (but doesn't include any global one). Just try both of them and see which one you like most. >> d) In your exception handler, walk the traceback object until you reach >> the feed() call, and inspect the corresponding tb_frame.f_locals >> dictionary. > > How can I walk a traceback? For the current problem the the monkeypatch > should be good enough, but for other cases it might be good to know. Each traceback object is linked to the next one via its tb_next attribute. But inspect.trace() builds a list of traceback records that may be easier to handle; see the inspect module documentation. You can identify the desired frame with its filename and function name, and then access its local variables with f_locals. I did something like that to gather context information for errors happening in a third party library that were hard to diagnose otherwise. -- Gabriel Genellina From frank at chagford.com Wed Mar 31 02:49:04 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 31 Mar 2010 08:49:04 +0200 Subject: Sublassing tuple works, subclassing list does not Message-ID: Hi all I needed something similar to, but not quite the same as, collections.namedtuple. The differences are that namedtuple requires the 'names' to be provided at creation time, and then lends itself to creating multiple instances of itself. I wanted a more generic class where I could supply the 'names' and 'values' at instantiation time. I came up with a simple solution that seems to work - >>> class MyTuple(tuple): ... def __new__(cls, names, values): ... for name, value in zip(names, values): ... setattr(cls, name, value) ... return tuple.__new__(cls, values) ... >>> names = ['A', 'B', 'C'] >>> values = ['a', 'b', 'c'] >>> >>> tup = MyTuple(names, values) >>> >>> print tup ('a', 'b', 'c') >>> >>> print tup[0] a >>> >>> print tup.B b >>> Then I had a need to add elements after the tuple had been created. As tuples are immutable, I thought it would be easy to change it to a list. However, it does not work - >>> class MyList(list): ... def __new__(cls, names, values): ... for name, value in zip(names, values): ... setattr(cls, name, value) ... return list.__new__(cls, values) ... >>> names = ['A', 'B', 'C'] >>> values = ['a', 'b', 'c'] >>> >>> lst = MyList(names, values) Traceback (most recent call last): File "", line 1, in TypeError: list() takes at most 1 argument (2 given) >>> I can find a workaround, but I would be interested to know the reason why it does not work. Version is 2.6.2. Thanks Frank Millman From affdfsdfdsfsd at b.com Wed Mar 31 03:47:32 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 31 Mar 2010 07:47:32 GMT Subject: Python + OpenOffice Calc Message-ID: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Hi all! i'm giving away to a friend of mine that have a garage (he repair car) my old computer. He will use it essentialy to create estimates of the work via an ods file (i've made a simple ods file to be filled with the cost of materials and a description of the work). He's totally new with computer and have difficult to fill the ods file, so i'ld like to create a simple python program that help him to introduce the data in to the ods file via a simple gui. So what i'm looking for is a way in python to insert data in a particular cell of the ods file and possibly to save it and print it when it's full filled with data. the guy is similar to this: 3 fields: quantity - description of the piece bought - price a way to add a new "line" if needed (for a new piece entry) similar to the "add rule" in evolution 1 text field for the description of the work + 1 field for the price of the work and off course a way to insert this data in to the ods file via python Any hints/tutorial/info? thanks Nico From __peter__ at web.de Wed Mar 31 03:52:09 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Mar 2010 09:52:09 +0200 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Hellmut Weber wrote: > Hi Peter and Jean-Michel, > thanks for all your hints and pieces of code. > > It took me a while to play around with what I got from you (and some > study of Vinay's module documentation. > > Now I have come up with a more complete solution I'm quite satisfied > with. And I would be very glad to receive your comments on my code > indicating what I could do better, given that I'm still at the very > beginning with python. > Here is my module and a corresponding test program: > # --- color change strings for terminal output --- > # > pc_yell = '\033[01;93m' > pc_purp = '\033[01;33m' > pc_gren = '\033[01;92m' Hw lng wld psts + prgrms b wr it nt 4 z art of clvr + ez 2 mmrz abbreviations ;) > # --- Class for all logging functionality --- > # > class locLogg(): > _logger = None > > def debug_log(self, msg, *args, **kwargs): > def warn_log(self, msg, *args, **kwargs): > def error_log(self, msg, *args, **kwargs): It should be easy to factor out most the code in your xxx_log() methods into a common helper. > def fatal_log(self, msg, *args, **kwargs): > previousFrame = inspect.currentframe().f_back > locLogg._logger.fatal(str(level_color['fatal'])+msg+pc_norm + \ > ' ' + argskw_2_string(*args, **kwargs), > extra={'custom_lineno':previousFrame.f_lineno, > 'custom_filename': previousFrame.f_code.co_filename }) I think the formatting belongs into another layer. That's the purpose of the logging.Formatter class. You could enhance it along those lines: class Formatter(logging.Formatter): markers = { logging.INFO: ("", ""), logging.WARN: ("", ""), } def format(self, record): message = logging.Formatter.format(self, record) try: prefix, suffix = self.markers[record.levelno] except KeyError: pass else: message = prefix + message + suffix return message My general impression is that you are fighting the logging library's structure rather than trying to use it as effectively as possible. > foo.info_log('another bar info', 1,2,3, a=11, b=22, c=44) You could achieve something similar with a standard logger by passing your extra information through the extra parameter, e. g: def extra(*args, **kw): return dict(argskw=(args, kw)) foo.info("another...", extra=extra(1, 2, 3, a=11, b=22)) Peter From kse.listed.co1 at gmail.com Wed Mar 31 03:56:41 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Wed, 31 Mar 2010 00:56:41 -0700 (PDT) Subject: "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ Message-ID: <1c64f0d6-e34a-4997-b919-ba9b49b5e466@y11g2000prf.googlegroups.com> "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ VV From __peter__ at web.de Wed Mar 31 03:57:51 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Mar 2010 09:57:51 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <5ef544bb-95a0-4329-80ef-f679d62b8ead@z11g2000yqz.googlegroups.com> Message-ID: Pierre Quentel wrote: > I'm surprised nobody proposed a solution with itertools ;-) next(itertools.takewhile(lambda _: a == b, ["yes"]), "no") You spoke to soon :) Peter From clp2 at rebertia.com Wed Mar 31 03:58:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Mar 2010 00:58:46 -0700 Subject: Python + OpenOffice Calc In-Reply-To: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Message-ID: On Wed, Mar 31, 2010 at 12:47 AM, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price > > a way to add a new "line" if needed (for a new piece entry) similar to the > "add rule" in evolution > > 1 text field for the description of the work + 1 field for the price of > the work > > and off course a way to insert this data in to the ods file via python > > Any hints/tutorial/info? PyUNO: http://wiki.services.openoffice.org/wiki/PyUNO_bridge Cheers, Chris -- http://blog.rebertia.com From v.harishankar at gmail.com Wed Mar 31 04:16:58 2010 From: v.harishankar at gmail.com (Harishankar) Date: Wed, 31 Mar 2010 08:16:58 +0000 (UTC) Subject: No editbox () functionality in python-dialog module? Message-ID: Strange issue, I find that the dialog utility has an editbox function but the python-dialog module doesn't provide this and there's no mention of the reason for the omission of this important functionality. Is there no easy and simple way to create a multi-line input dialog in ANY of the text mode console libraries? :-( -- Harishankar (http://harishankar.org http://literaryforums.org) From lbolla at gmail.com Wed Mar 31 04:18:39 2010 From: lbolla at gmail.com (lbolla) Date: Wed, 31 Mar 2010 01:18:39 -0700 (PDT) Subject: Sublassing tuple works, subclassing list does not References: Message-ID: On Mar 31, 7:49?am, "Frank Millman" wrote: > Hi all > > I needed something similar to, but not quite the same as, > collections.namedtuple. > > The differences are that namedtuple requires the 'names' to be provided at > creation time, and then lends itself to creating multiple instances of > itself. I wanted a more generic class where I could supply the 'names' and > 'values' at instantiation time. > > I came up with a simple solution that seems to work - > > >>> class MyTuple(tuple): > > ... ? def __new__(cls, names, values): > ... ? ? for name, value in zip(names, values): > ... ? ? ? setattr(cls, name, value) > ... ? ? return tuple.__new__(cls, values) > ... > > >>> names = ['A', 'B', 'C'] > >>> values = ['a', 'b', 'c'] > > >>> tup = MyTuple(names, values) > > >>> print tup > ('a', 'b', 'c') > > >>> print tup[0] > a > > >>> print tup.B > b > > Then I had a need to add elements after the tuple had been created. As > tuples are immutable, I thought it would be easy to change it to a list. > However, it does not work - > > >>> class MyList(list): > > ... ? def __new__(cls, names, values): > ... ? ? for name, value in zip(names, values): > ... ? ? ? setattr(cls, name, value) > ... ? ? return list.__new__(cls, values) > ...>>> names = ['A', 'B', 'C'] > >>> values = ['a', 'b', 'c'] > > >>> lst = MyList(names, values) > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: list() takes at most 1 argument (2 given) > > > > I can find a workaround, but I would be interested to know the reason why it > does not work. > > Version is 2.6.2. > > Thanks > > Frank Millman When subclassing immutable types, you need to override __new__; otherwise you need to override __init__. Here is an in-depth explanation: http://www.python.org/download/releases/2.2/descrintro/#metaclasses Here is some code: class MyTuple(tuple): def __new__(cls, names, values): for name, value in zip(names, values): setattr(cls, name, value) return tuple.__new__(cls, values) class MyList(list): def __init__(self, names, values): list.__init__(self, values) for name, value in zip(names, values): setattr(self, name, value) names = ['A', 'B', 'C'] values = ['a', 'b', 'c'] tup = MyTuple(names, values) print tup print tup[0] print tup.B lst = MyList(names, values) print lst print lst[0] print lst.B L. From frank at chagford.com Wed Mar 31 04:29:17 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 31 Mar 2010 10:29:17 +0200 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: "lbolla" wrote in message news:f8011c0b-0b1b-4a4f-94ff-304c16ef9a5b at q16g2000yqq.googlegroups.com... On Mar 31, 7:49 am, "Frank Millman" wrote: >> Hi all >> > When subclassing immutable types, you need to override __new__; > otherwise you need to override __init__. Perfect. Thanks very much. Frank From michael.ricordeau at gmail.com Wed Mar 31 04:29:43 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 31 Mar 2010 10:29:43 +0200 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> References: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> Message-ID: <20100331102943.7f542d17@moriz.interne> Hi You cannot add 'NOW() - '29 days'::INTERVAL' as a query because cursor.execute() will try to mogrify it. You can do : import datetime idays = psycopg2.extensions.adapt(datetime.timedelta(days=29)) self.dyndb.orderdb.query('update xxxx set creation_date=(NOW() - %s) where id_order=%s', idays, "123")) Or: import datetime interval = datetime.datetime.now() - datetime.timedelta(days=29) self.dyndb.orderdb.query('update xxxx set creation_date=%s where id_order=%s', (interval, "123")) # But in this case current date/time is not evaluated from postgresql server but only from python env ... this may cause some bugs You may also try to add an interval type with psycopg2.extensions.INTERVAL (I never played with it) Le Tue, 30 Mar 2010 17:26:51 -0400, Philip Semanchuk a ?crit : > > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > Hi, please help me understand why am I getting error with this query > > > > > > new_start_date = "NOW() - '29 days'::INTERVAL" > > self.dyndb.orderdb.query('''update xxxx set creation_date > > = %s > > where id_order = %s''', (new_start_date, "123")) > > > > > > > > ... > > psycopg2.DataError: invalid input syntax for type timestamp with time > > zone: "NOW() - '29 days'::INTERVAL" > > Hi Anton, > It sounds to me like the problem is with your SQL rather than with > psycopg2 or Python. Try the query directly in Postgres -- does it work > there? If so, then your next step should be to ask on the psycopg2 > mailing list that Google can find for you. > > Good luck > Philip > From richard.lamboj at bilcom.at Wed Mar 31 04:36:32 2010 From: richard.lamboj at bilcom.at (Richard Lamboj) Date: Wed, 31 Mar 2010 10:36:32 +0200 Subject: libpst - python bindings Message-ID: <201003311036.32554.richard.lamboj@bilcom.at> Hello, are there any python bindings for libpst? http://www.five-ten-sg.com/libpst/ https://alioth.debian.org/projects/libpst/ Kind Regards Richi From anton.shishkov at gmail.com Wed Mar 31 04:42:41 2010 From: anton.shishkov at gmail.com (Anton Shishkov) Date: Wed, 31 Mar 2010 01:42:41 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: Message-ID: On Mar 31, 3:10?am, "D'Arcy J.M. Cain" wrote: > On Tue, 30 Mar 2010 15:46:12 -0700 (PDT) > > ASh wrote: > > > > ? ? ? ? ? ? new_start_date = "NOW() - '29 days'::INTERVAL" > > > > ? ? ? ? ? ? self.dyndb.orderdb.query('''update xxxx set creation_date > > > > = %s > > > > ? ? ? ? ? ? where id_order = %s''', (new_start_date, "123")) > > > > Put single quotes around the first %s in the query. > > > Tried like you said, got this error: > > > psycopg2.ProgrammingError: syntax error at or near "NOW" > > LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 > > da... > > Right. ?I misread it. ?Please show us the exact error that you get with > the original code. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. Error: cursor.execute(sql, params) File "/opt/local/lib/python2.5/site-packages/psycopg2/extras.py", line 118, in execute return _cursor.execute(self, query, vars, async) psycopg2.ProgrammingError: syntax error at or near "NOW" LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 da... ^ From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 31 04:58:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 31 Mar 2010 10:58:53 +0200 Subject: Sublassing tuple works, subclassing list does not In-Reply-To: References: Message-ID: <4bb30e95$0$17814$426a74cc@news.free.fr> lbolla a ?crit : > > class MyList(list): > def __init__(self, names, values): > list.__init__(self, values) > for name, value in zip(names, values): > setattr(self, name, value) > > names = ['A', 'B', 'C'] > values = ['a', 'b', 'c'] > > lst = MyList(names, values) > print lst > print lst[0] > print lst.B > >>> lst[0] = "foobar" >>> lst.A 'a'>>> lst.B = 42 >>> lst[1] 'b' >>> lst.D="duh" >>> lst[3] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range From rtw at rtw.me.uk Wed Mar 31 05:02:27 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Wed, 31 Mar 2010 04:02:27 -0500 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: Frank Millman wrote in news:mailman.1360.1270018159.23598.python- list at python.org in comp.lang.python: > I came up with a simple solution that seems to work - > >>>> class MyTuple(tuple): > ... def __new__(cls, names, values): > ... for name, value in zip(names, values): > ... setattr(cls, name, value) > ... return tuple.__new__(cls, values) > ... >>>> names = ['A', 'B', 'C'] >>>> values = ['a', 'b', 'c'] >>>> >>>> tup = MyTuple(names, values) >>>> Are you aware you are adding attributes to the class here, IOW: MyTuple.C == 'c' If you want to add attibutes to the instance: class MyTuple(tuple): def __new__(cls, names, values): r = tuple.__new__(cls, values) for name, value in zip(names, values): setattr(r, name, value) return r names = ['A', 'B', 'C'] values = ['a', 'b', 'c'] tup = MyTuple(names, values) assert tup[0] == 'a' assert tup.B == 'b' try: MyTuple.C except AttributeError: pass else: assert False From pavlovevidence at gmail.com Wed Mar 31 05:38:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 31 Mar 2010 02:38:33 -0700 (PDT) Subject: Sublassing tuple works, subclassing list does not References: Message-ID: <2baf58a8-b5f1-4db0-9dff-260c62f1641f@h4g2000pre.googlegroups.com> On Mar 31, 2:02?am, Rob Williscroft wrote: > Frank Millman wrote in news:mailman.1360.1270018159.23598.python- > l... at python.org in comp.lang.python: > > > I came up with a simple solution that seems to work - > > >>>> class MyTuple(tuple): > > ... ? def __new__(cls, names, values): > > ... ? ? for name, value in zip(names, values): > > ... ? ? ? setattr(cls, name, value) > > ... ? ? return tuple.__new__(cls, values) > > ... > >>>> names = ['A', 'B', 'C'] > >>>> values = ['a', 'b', 'c'] > > >>>> tup = MyTuple(names, values) > > Are you aware you are adding attributes to the class here, IOW: > > ? ? ? ? MyTuple.C == 'c' > If you want to add attibutes to the instance: > > class MyTuple(tuple): > ? def __new__(cls, names, values): > ? ? r = ?tuple.__new__(cls, values) > ? ? for name, value in zip(names, values): > ? ? ? setattr(r, name, value) > ? ? return r > > names = ['A', 'B', 'C'] > values = ['a', 'b', 'c'] > > tup = MyTuple(names, values) > > assert tup[0] == 'a' > assert tup.B == 'b' > > try: > ? MyTuple.C > except AttributeError: > ? pass > else: > ? assert False Careful, this adds the new attributes as to the object's __dict__, not to the tuple item slots. Which works ok if you don't care if that someone can mutate the attributes, and if they do the attributes no longer match the items. Personally I do mind. tup = MyTuple(names,values) assert tup.A == 'a' assert tup[0] == 'a' tup.A = 'd' # doesn't fail but should assert tup.A == 'd' assert tup[0] == 'd' # fails but, granted you allow mutabilty, shouldn't The best way to do what the OP wanted (originally) is this, no subclassing necessary: def my_named_tuple(names,values): return namedtuple('ad_hoc_named_tuple',names)(*values) As for the OP's second problem, to append named items, I'd first consider whether I'm thinking about the problem correctly, and if so, go with a subclass of list and overriding __getattr__. Probably one of the rare cases I would override __getattr__ other than a proxy class. Carl Banks From mark.dufour at gmail.com Wed Mar 31 05:50:42 2010 From: mark.dufour at gmail.com (Mark Dufour) Date: Wed, 31 Mar 2010 11:50:42 +0200 Subject: ANN: Shed Skin 0.4 Message-ID: Hi all, I have just released Shed Skin 0.4, an experimental (restricted) Python-to-C++ compiler. Please see my blog for more details about the release: http://shed-skin.blogspot.com/ Thanks, Mark Dufour. -- "Overdesigning is a SIN. It's the archetypal example of what I call 'bad taste'" - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Wed Mar 31 06:39:30 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 31 Mar 2010 11:39:30 +0100 Subject: PyDispatcher on sourceforge doesn't play nice with easy_install In-Reply-To: <4BB21F18.2010705@vrplumber.com> References: <4BB1B034.9020905@simplistix.co.uk> <4BB21F18.2010705@vrplumber.com> Message-ID: <4BB32662.9080702@simplistix.co.uk> Mike C. Fletcher wrote: > Chris Withers wrote: >> Hi All, >> >> Using easy_install to get PyDispatcher results in: >> > ... >> Who's the maintainer of PyDispatcher nowadays? Would be handy if they >> removed the sourceforge link from pypi. > ... > > Thanks for the report. I've released a 2.0.2 version on PyPI. That > should now work properly with easy_install. Great! Thanks Mike! Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From iwanttobeabadger at googlemail.com Wed Mar 31 06:49:14 2010 From: iwanttobeabadger at googlemail.com (Nathan Harmston) Date: Wed, 31 Mar 2010 11:49:14 +0100 Subject: Generating text from a regular expression Message-ID: Hi everyone, I have a slightly complicated/medium sized regular expression and I want to generate all possible words that it can match (to compare performance of regex against an acora based matcher). Using the regular expression as a grammar to generate all words in its language. I was wondering if this possible in Python or possible using anything. Google doesnt seem to give any obvious answers. Many thanks in advance, Nathan From anton.shishkov at gmail.com Wed Mar 31 06:50:39 2010 From: anton.shishkov at gmail.com (Anton Shishkov) Date: Wed, 31 Mar 2010 03:50:39 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> Message-ID: On Mar 31, 11:29?am, Michael Ricordeau wrote: > Hi > > You cannot add 'NOW() - '29 days'::INTERVAL' as a query because cursor.execute() will try to mogrify it. > > You can do : > ? import datetime > ? idays = psycopg2.extensions.adapt(datetime.timedelta(days=29)) > ? self.dyndb.orderdb.query('update xxxx set creation_date=(NOW() - %s) where id_order=%s', idays, "123")) > > Or: > ? import datetime > ? interval = datetime.datetime.now() - datetime.timedelta(days=29) > ? self.dyndb.orderdb.query('update xxxx set creation_date=%s where id_order=%s', (interval, "123")) > ? # But in this case current date/time is not evaluated from postgresql server but only from python env ... this may cause some bugs ? ? > > You may also try to add an interval type with psycopg2.extensions.INTERVAL (I never played with it) > > Le Tue, 30 Mar 2010 17:26:51 -0400, > Philip Semanchuk a ?crit : > > > > > > > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > > Hi, please help me understand why am I getting error with this query > > > > ? ? ? ? ? ?new_start_date = "NOW() - '29 days'::INTERVAL" > > > ? ? ? ? ? ?self.dyndb.orderdb.query('''update xxxx set creation_date > > > = %s > > > ? ? ? ? ? ?where id_order = %s''', (new_start_date, "123")) > > > > ... > > > psycopg2.DataError: invalid input syntax for type timestamp with time > > > zone: "NOW() - '29 days'::INTERVAL" > > > Hi Anton, > > It sounds to me like the problem is with your SQL rather than with ? > > psycopg2 or Python. Try the query directly in Postgres -- does it work ? > > there? If so, then your next step should be to ask on the psycopg2 ? > > mailing list that Google can find for you. > > > Good luck > > Philip thank you for good examples (bow) From hniksic at xemacs.org Wed Mar 31 07:07:55 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 31 Mar 2010 13:07:55 +0200 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: <87iq8czr3o.fsf@busola.homelinux.net> "Frank Millman" writes: >>>> class MyList(list): > ... def __new__(cls, names, values): > ... for name, value in zip(names, values): > ... setattr(cls, name, value) > ... return list.__new__(cls, values) Did you really mean to setattr the class here? If I'm guessing your intentions correctly, it should be: def __new__(cls, names, values): self = list.__new__(cls, values) for name, value in zip(names, values): setattr(self, name, value) return self > Traceback (most recent call last): > File "", line 1, in > TypeError: list() takes at most 1 argument (2 given) >>>> > > I can find a workaround, but I would be interested to know the reason > why it does not work. Because you didn't define __init__, so MyList inherited the one from list, and it has a different signature to what you're calling it with. Simply add an __init__ with the proper signature, and the proper upcall to list.__init__: def __init__(self, names, values): list.__init__(self, values) But if you're doing that, you don't need __new__ at all. Simply override __init__ and place your setattr loop there: >>> class MyList(list): ... def __init__(self, names, values): ... for name, value in zip(names, values): ... setattr(self, name, value) ... list.__init__(self, values) ... >>> MyList(['a'], [1]) [1] >>> _.a 1 From frank at chagford.com Wed Mar 31 07:51:05 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 31 Mar 2010 13:51:05 +0200 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: On Mar 31, 8:49 am, "Frank Millman" wrote: > Hi all Thanks to all for the helpful replies. Rob, you are correct, I had not realised I was adding attributes to the class instead of the instance. Your alternative does work correctly. Thanks. Carl, I understand your concern about modifying attributes. In my particular case, this is not a problem, as the class is under my control, and an instance will not be modified once it is set up, but I agree one must be careful not to mis-use it. My use-case is that I want to create a number of objects, I want to store them in a tuple/list so that I can retrieve them sequentially, and I also want to retrieve them individually by name. Normally I would create a tuple and a dictionary to serve the two purposes, but I thought this might be a convenient way to get both behaviours from the same structure. Regarding adding elements after instantiation, I would subclass 'list', as suggested by others, and then add an 'add' method, like this - def add(self, name, value): setattr(self, name, value) self.append(value) I tested this and it behaves as I want. Having said all of this, I have realised that what I probably want is an ordered dict. I will play with the one in PyPi, hopefully it will render this entire discussion redundant. It was interesting, though, and I have learned a lot. Thanks again Frank From gagsl-py2 at yahoo.com.ar Wed Mar 31 07:58:03 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 31 Mar 2010 08:58:03 -0300 Subject: Generating text from a regular expression References: Message-ID: En Wed, 31 Mar 2010 07:49:14 -0300, Nathan Harmston escribi?: > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match (to compare > performance of regex against an acora based matcher). Using the > regular expression as a grammar to generate all words in its language. > I was wondering if this possible in Python or possible using anything. > Google doesnt seem to give any obvious answers. I've done this some time ago. This recipe http://code.activestate.com/recipes/577041-merge-multiple-potentially-infinite-sorted-inputs-/ provides an infinite merge operation, required for effectively enumerating a regular language (with shorter strings first, else 'a*b' would get stuck repeating "a"s and never yielding any "b"). The example at the end shows the basics of how to use it (by hand) in a very simple case. To enumerate all strings matching '(a|bc)*' one should invoke closure(product(['a'],['b','c'])), which gives: '', 'a', 'aa', 'bc', 'aaa', 'abc', 'bca', 'aaaa', 'aabc', 'abca', 'bcaa', 'bcbc', 'aaaaa', 'aaabc', 'aabca', 'abcaa', 'abcbc', 'bcaaa', 'bcabc', 'bcbca', ... Converting the former expression into the later function calls requires a parser (not shown -- and I won't be able to find it until Friday) -- Gabriel Genellina From python.list at tim.thechases.com Wed Mar 31 08:01:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 31 Mar 2010 07:01:57 -0500 Subject: Generating text from a regular expression In-Reply-To: References: Message-ID: <4BB339B5.3050505@tim.thechases.com> Nathan Harmston wrote: > I have a slightly complicated/medium sized regular expression > and I want to generate all possible words that it can match > (to compare performance of regex against an acora based > matcher). Using the regular expression as a grammar to > generate all words in its language. I was wondering if this > possible in Python or possible using anything. Google doesnt > seem to give any obvious answers. Unless you limit your regexp to bounded regular expressions (you don't use the "*", "+" and unbounded-top-end "{...}" tokens), it has an infinite number of possible words that can match. As a simple example, the regexp "a*" matches "" (the empty string), "a", "aa", "aaa", "aaaa"...and so on up to the limit of a string length. There was a discussion on this a while back: http://mail.python.org/pipermail/python-list/2010-February/1235120.html so you might chat with the person who started that thread. You basically have to write a regexp parser that generates code to generate the expressions, and even simple expressions such as "[a-z]{1,30}" can create an astronomical number of possible inputs. -tkc From piet at vanoostrum.org Wed Mar 31 08:50:51 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 31 Mar 2010 14:50:51 +0200 Subject: os.walk restart References: Message-ID: You have no guarantee that on the next run the directories will be visited in the same order as in the first run (this could depend on the filesystem). So then remembering a last directory won't do it. You could write each completed directory name to a file, and then on the second run check whether a directory is in that list and skip the program run for these. Something like this (symbolically): lastrun = map(string.strip, logfile.readlines()) newlog = ... open logfile in append mode ... for root, dirs, files in os.walk(basedir): if root not in lastrun: run program newlog.write(root) newlog.flush() -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonwaar op http://www.zylja.com From jura.grozni at gmail.com Wed Mar 31 09:01:34 2010 From: jura.grozni at gmail.com (azrael) Date: Wed, 31 Mar 2010 06:01:34 -0700 (PDT) Subject: wrapping data from groups Message-ID: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> Hi Could anyone give me a hint about a problem I have. I want to wrap data from newsgroups like comp.lang.python. Is there anywhere out some module for this or does google has something for this. From jeanmichel at sequans.com Wed Mar 31 09:02:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 31 Mar 2010 15:02:16 +0200 Subject: libpst - python bindings In-Reply-To: <201003311036.32554.richard.lamboj@bilcom.at> References: <201003311036.32554.richard.lamboj@bilcom.at> Message-ID: <4BB347D8.7050202@sequans.com> Richard Lamboj wrote: > Hello, > > are there any python bindings for libpst? > > http://www.five-ten-sg.com/libpst/ > https://alioth.debian.org/projects/libpst/ > > Kind Regards > > Richi > http://www.lmgtfy.com/?q=libpst+python 3rd hit Cheers, JM From steve at holdenweb.com Wed Mar 31 09:28:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 09:28:32 -0400 Subject: wrapping data from groups In-Reply-To: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> References: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> Message-ID: azrael wrote: > Hi > > Could anyone give me a hint about a problem I have. I want to wrap > data from newsgroups like comp.lang.python. Is there anywhere out > some module for this or does google has something for this. nntplib would be the normal starting point. I've used it, and it works reasonably well. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From invalid at invalid.invalid Wed Mar 31 10:13:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 31 Mar 2010 14:13:32 +0000 (UTC) Subject: Generating text from a regular expression References: Message-ID: On 2010-03-31, Nathan Harmston wrote: > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match > > I was wondering if this possible in Python or possible using > anything. Google doesnt seem to give any obvious answers. We did this one a couple weeks ago. It's not possible in the general case (there are an infinite number of matching words for many/most regular expressions). -- Grant Edwards grant.b.edwards Yow! ... the MYSTERIANS are at in here with my CORDUROY gmail.com SOAP DISH!! From ptmcg at austin.rr.com Wed Mar 31 11:23:48 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 31 Mar 2010 08:23:48 -0700 (PDT) Subject: Generating text from a regular expression References: Message-ID: <829a8515-0c35-449e-abb9-2321092f2598@l25g2000yqd.googlegroups.com> On Mar 31, 5:49?am, Nathan Harmston wrote: > Hi everyone, > > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match (to compare > performance of regex against an acora based matcher). The pyparsing wiki Examples page includes this regex inverter: http://pyparsing.wikispaces.com/file/view/invRegex.py >From the module header: # Supports: # - {n} and {m,n} repetition, but not unbounded + or * repetition # - ? optional elements # - [] character ranges # - () grouping # - | alternation -- Paul From jmontoyaz at gmail.com Wed Mar 31 12:40:30 2010 From: jmontoyaz at gmail.com (Javier Montoya) Date: Wed, 31 Mar 2010 09:40:30 -0700 (PDT) Subject: associative array Message-ID: Dear all, I'm a newbie in python and would be acknowledge if somebody could shed some light on associative arrays. More precisely, I would like to create a multi-dimensional associative array. I have for example a list of students which are identified uniquely by their student IDs. Additionally, for each student I have some information: FirstName, LastName, etc. The array would have then the following form: [StudentID] => [FirstName][LastName][Telephone]...[ ... ] I would like to be able to access a field directly by using a StudentID [StudentID][FirstName] [StudentID][LastName] How could I manipulate such an array (create the array, add elements, access data)? Best wishes From kushal.kumaran+python at gmail.com Wed Mar 31 12:52:14 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 31 Mar 2010 22:22:14 +0530 Subject: associative array In-Reply-To: References: Message-ID: On Wed, Mar 31, 2010 at 10:10 PM, Javier Montoya wrote: > Dear all, > > I'm a newbie in python and would be acknowledge if somebody could shed > some light on associative arrays. > More precisely, I would like to create a multi-dimensional associative > array. I have for example a list of students which are identified > uniquely by their student IDs. Additionally, for each student I have > some information: FirstName, LastName, etc. > > The array would have then the following form: > [StudentID] => [FirstName][LastName][Telephone]...[ ... ] > > I would like to be able to access a field directly by using a > StudentID > [StudentID][FirstName] > [StudentID][LastName] > > How could I manipulate such an array (create the array, add elements, > access data)? > Did you try the python tutorial? Dictionaries might be what you are looking for. http://docs.python.org/tutorial/datastructures.html#dictionaries -- regards, kushal From jura.grozni at gmail.com Wed Mar 31 12:58:40 2010 From: jura.grozni at gmail.com (azrael) Date: Wed, 31 Mar 2010 09:58:40 -0700 (PDT) Subject: wrapping data from groups References: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> Message-ID: I tried to use some servers I know but they have a limited amount of stored threads. not like google that has every thread ever opened. so I tried to wrap google's html but I get a 403 error. any sugesstions? On Mar 31, 3:28?pm, Steve Holden wrote: > azrael wrote: > > Hi > > > Could anyone give me a hint about a problem I have. I want to wrap > > data from ?newsgroups like comp.lang.python. Is there anywhere out > > some module for this or does google has something for this. > > nntplib would be the normal starting point. I've used it, and it works > reasonably well. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > See PyCon Talks from Atlanta 2010 ?http://pycon.blip.tv/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ From ccurvey at gmail.com Wed Mar 31 13:08:50 2010 From: ccurvey at gmail.com (Chris Curvey) Date: Wed, 31 Mar 2010 10:08:50 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter Message-ID: I must be having a brain cramp. Given a list of objects, how can I sort the list on one attribute in descending order, then sort within each group in ascending order on another attribute. For example: class Foo: def __init__(self, a, b, c): self.a = a self.b = b self.c = c I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort ascending on both attributes, but how could i sort by "a, descending, then b, ascending)?" From tomf.sessile at gmail.com Wed Mar 31 13:21:36 2010 From: tomf.sessile at gmail.com (TomF) Date: Wed, 31 Mar 2010 10:21:36 -0700 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <5ef544bb-95a0-4329-80ef-f679d62b8ead@z11g2000yqz.googlegroups.com> Message-ID: <2010033110213616807-tomfsessile@gmailcom> On 2010-03-31 00:57:51 -0700, Peter Otten <__peter__ at web.de> said: > Pierre Quentel wrote: > >> I'm surprised nobody proposed a solution with itertools ;-) > > next(itertools.takewhile(lambda _: a == b, ["yes"]), "no") > > You spoke to soon :) I salute you, sir, for upholding the standards of this group. -Tom From safoo.alahmadi at gmail.com Wed Mar 31 13:30:39 2010 From: safoo.alahmadi at gmail.com (safwan alahmadi) Date: Wed, 31 Mar 2010 10:30:39 -0700 (PDT) Subject: Video is very funny..hhhhhhhhhhhh Message-ID: <9ba61e22-bcca-4684-a5d6-1fd587641525@8g2000yqz.googlegroups.com> hhhhhhhhhhhh Video is very funny http://www.youtube.com/watch?v=-cKvPp71QFY From mail at timgolden.me.uk Wed Mar 31 13:35:00 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 31 Mar 2010 18:35:00 +0100 Subject: sorting ascending/descending with operator.attrgetter In-Reply-To: References: Message-ID: <4BB387C4.5010002@timgolden.me.uk> On 31/03/2010 18:08, Chris Curvey wrote: > I must be having a brain cramp. Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > def __init__(self, a, b, c): > self.a = a > self.b = b > self.c = c I think this is the kind of thing you're after... http://ramblings.timgolden.me.uk/2009/10/15/reverse-sorting-on-arbitrary-key-segments/ ... at least the link to the Wiki should help: http://wiki.python.org/moin/HowTo/Sorting TJG From gherron at digipen.edu Wed Mar 31 13:36:22 2010 From: gherron at digipen.edu (Gary Herron) Date: Wed, 31 Mar 2010 10:36:22 -0700 Subject: associative array In-Reply-To: References: Message-ID: <4BB38816.4030305@digipen.edu> Javier Montoya wrote: > Dear all, > > I'm a newbie in python and would be acknowledge if somebody could shed > some light on associative arrays. > More precisely, I would like to create a multi-dimensional associative > array. I have for example a list of students which are identified > uniquely by their student IDs. Additionally, for each student I have > some information: FirstName, LastName, etc. > > The array would have then the following form: > [StudentID] => [FirstName][LastName][Telephone]...[ ... ] > > I would like to be able to access a field directly by using a > StudentID > [StudentID][FirstName] > [StudentID][LastName] > > How could I manipulate such an array (create the array, add elements, > access data)? > > Best wishes > > > Create a class for student with attributes for ID, FirstName, LastName, etc. class Student: def __init__(self, id, FirstName, ...): self.id = id self.FirstName = FirstName ... then whenever you create a student object, use a dictionary to associate the object with its is AA = {} # An empty dictionary s = Student(...) AA[s.id] = s ... and repeat for many students... Then to access a student's object given an id: s = AA[id] print s.id, s.FirstName, s.LastName, ... I'd *not* call this a multi-dimension association, but rather just an association between student objects and their ids. Hope that helps, Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From __peter__ at web.de Wed Mar 31 13:49:08 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Mar 2010 19:49:08 +0200 Subject: sorting ascending/descending with operator.attrgetter References: Message-ID: Chris Curvey wrote: > I must be having a brain cramp. Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > def __init__(self, a, b, c): > self.a = a > self.b = b > self.c = c > > > I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort > ascending on both attributes, but how could i sort by "a, descending, > then b, ascending)?" In the general case you have to sort twice: >>> from collections import namedtuple >>> Foo = namedtuple("Foo", "a b") >>> items = [Foo(x, y) for x in range(3) for y in range(3)] >>> def show(items): ... for item in items: print item ... >>> show(items) Foo(a=0, b=0) Foo(a=0, b=1) Foo(a=0, b=2) Foo(a=1, b=0) Foo(a=1, b=1) Foo(a=1, b=2) Foo(a=2, b=0) Foo(a=2, b=1) Foo(a=2, b=2) >>> from operator import attrgetter >>> items.sort(key=attrgetter("b")) >>> items.sort(key=attrgetter("a"), reverse=True) >>> show(items) Foo(a=2, b=0) Foo(a=2, b=1) Foo(a=2, b=2) Foo(a=1, b=0) Foo(a=1, b=1) Foo(a=1, b=2) Foo(a=0, b=0) Foo(a=0, b=1) Foo(a=0, b=2) This is guaranteed to work because list.sort() is "stable", i. e. it doesn't alter the order of items with equal keys. Peter From nathan.alexander.rice at gmail.com Wed Mar 31 13:58:58 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 31 Mar 2010 13:58:58 -0400 Subject: Question about list comprehension/standard "for" disparities Message-ID: I was just wondering, why the list/generator and standard "for" have disparities? It would be really nice to be able to do: for x in y if foo: ... rather than: for x in (x for x in y if foo): ... Also, from a style standpoint, I prefer to extract the loop logic into a function if it's more than a few lines long. As a result, most of my loops are of the form: for x in y: bar(x) So I frequently end up using map. As I understand it, there is some discussion of removing map() in favor of comprehensions. Is there any reason why the for syntax could not be expanded to accommodate statements of the form: bar(x) for x in y ? This inconsistency really bothered me when I started playing with python, and it seems kind of at-odds with the "one right way to do things" mentality. -Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From wescpy at gmail.com Wed Mar 31 14:01:58 2010 From: wescpy at gmail.com (wesley chun) Date: Wed, 31 Mar 2010 11:01:58 -0700 Subject: ANN: Intro+Intermediate Python course, SF, May 10-12 Message-ID: Need to get up-to-speed with Python as quickly as possible? Come join me, Wesley Chun, author of Prentice-Hall's bestseller "Core Python Programming," for a comprehensive intro course coming up this May in beautiful Northern California! Please pass on this note to whomever you think may be interested. I look forward to meeting you and your colleagues! feel free to pass around the PDF flyer linked down below. (Comprehensive) Introduction to Python Mon-Wed, 2010 May 10-12, 9am-5pm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (COMPREHENSIVE) INTRO+INTERMEDIATE PYTHON Although this course may appear to those new to Python, it is also perfect for those who have tinkered with it and want to "fill in the gaps" and/or want to get more in-depth formal training. It combines the best of both an introduction to the language as well as a "Python Internals" training course. We will immerse you in the world of Python in only a few days, showing you more than just its syntax (which you don't really need a book to learn, right?). Knowing more about how Python works under the covers, including the relationship between data objects and memory management, will make you a much more effective Python programmer coming out of the gate. 3 hands-on labs each day will help hammer the concepts home. Come find out why Google, Yahoo!, Disney, ILM/LucasFilm, VMware, NASA, Ubuntu, YouTube, and Red Hat all use Python. Users supporting or jumping to Plone, Zope, TurboGears, Pylons, Django, Google App Engine, Jython, IronPython, and Mailman will also benefit! PREVIEW 1: you will find (and can download) a video clip of a class session recorded live to get an idea of my lecture style and the interactive classroom environment at: http://cyberwebconsulting.com PREVIEW 2: Partnering with O'Reilly and Pearson, Safari Books Online has asked me to deliver a 1-hour webcast last Spring called "What is Python?". This was an online seminar based on a session that I've delivered at numerous conferences in the past. It will give you an idea of lecture style as well as an overview of the material covered in the course. info:http://www.safaribooksonline.com/events/WhatIsPython.html download (reg req'd): http://www.safaribooksonline.com/Corporate/DownloadAndResources/webcastInfo.php?page=WhatIsPython - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WHERE: near the San Francisco Airport (SFO/San Bruno), CA, USA WEB: http://cyberwebconsulting.com FLYER: http://starship.python.net/crew/wesc/flyerPP1may10.pdf LOCALS: easy freeway (101/280/380) with lots of parking plus public transit (BART and CalTrain) access via the San Bruno stations, easily accessible from all parts of the Bay Area VISITORS: free shuttle to/from the airport, free high-speed internet, free breakfast and regular evening receptions; fully-equipped suites See website for costs, venue info, and registration. There is a significant discounts available for full-time students, secondary teachers, and others. Hope to see you there! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com From nagle at animats.com Wed Mar 31 14:05:58 2010 From: nagle at animats.com (John Nagle) Date: Wed, 31 Mar 2010 11:05:58 -0700 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <4bb38a31$0$1595$742ec2ed@news.sonic.net> Alf P. Steinbach wrote: > * Jean-Michel Pichavant: >> John Nagle wrote: >>> Jonathan Hayward wrote: >>>> I've posted "Usability, the Soul of Python: An Introduction to the >>>> Python Programming Language Through the Eyes of Usability", at: >>>> >>>> http://JonathansCorner.com/python/ >>> >>> No, it's just a rather verbose introduction to Python, in dark brown >>> type on a light brown background. One could write a good paper on this >>> topic, but this isn't it. >>> >>> >>> John Nagle >> Why is it bad ? > > Consider > > > > From a usability standpoint, the braces go with the lines to print out > the stanza rather than the for statement or the code after, so the > following is best: The last time I ran a C++ project, I just had everyone run their code through Artistic Style ("http://astyle.sourceforge.net") with "--style=ansi". No more inconsistencies. John Nagle From see at sig.for.address Wed Mar 31 14:58:03 2010 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 31 Mar 2010 13:58:03 -0500 Subject: sort array, apply rearrangement to second References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: <1jg81f7.5ub3191oci9fkN%see@sig.for.address> Robert Kern wrote: > second[first.argsort()] Really cool. Thanks. > Ask numpy questions on the numpy mailing list. I will. I thought that this question would have an answer in a generic python idiom. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From pmaupin at gmail.com Wed Mar 31 15:05:24 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 31 Mar 2010 12:05:24 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter References: Message-ID: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> On Mar 31, 12:08?pm, Chris Curvey wrote: > I must be having a brain cramp. ?Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > ? ? def __init__(self, a, b, c): > ? ? ? ? self.a = a > ? ? ? ? self.b = b > ? ? ? ? self.c = c > > I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort > ascending on both attributes, but how could i sort by "a, descending, > then b, ascending)?" You can provide a cmp function to the string sort method, e.g. cmp = lambda x,y: -cmp(x.a, y.a) or cmp(x.b, y.b) You can also possibly gain some efficiency by using key instead of cmp. For example, if one of the objects is numeric, you can call sort() with something like key = lambda x:(-x.a, x.b) Or if b is numeric but a is a string, you could use lambda x:(x.a, - x.b) and then use list.reverse() afterward. HTH, Pat From gatoygata2 at gmail.com Wed Mar 31 15:11:18 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Wed, 31 Mar 2010 12:11:18 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> Message-ID: On Mar 31, 1:18?am, Lawrence D'Oliveiro wrote: > In message <7316f3d2-bcc9-4a1a-8598- > > cdd5d41fd... at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > > (a==b) and 'YES' or 'NO' > > > Yes, ugly > > Why would you say that?s ugly? > > By the way, you don?t need the parentheses. Lawrence, maybe it was not the perfect adjective. I meant 'not beautiful' because for me it is not an expression I can easily read. It is not internalized in my brain. I know how to use it because I learnt how to do it time ago(in Learning Python) but always I have to think how it works (like a mental translation). For me the other alternative expresion is more readable: take_it if you_have_it else search_for_it this was already in my brain before I started writing python code. Thus, I prefer this option for my code. On the other hand, in my post, I proposed the and/or style because I found interesting how symmetrical it was with the one the OP was refering: (a==b) ? 'Yes' : 'No' (a==b) and 'Yes' or 'No' I know, I could write it without parenthesis but it seems more naturally organized with it and I read it faster and clearly. I dont know exactly why but it seems also safer to me. Joaquin From robert.kern at gmail.com Wed Mar 31 15:13:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 31 Mar 2010 14:13:52 -0500 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg81f7.5ub3191oci9fkN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> <1jg81f7.5ub3191oci9fkN%see@sig.for.address> Message-ID: On 2010-03-31 13:58 PM, Victor Eijkhout wrote: > Robert Kern wrote: > >> second[first.argsort()] > > Really cool. Thanks. > >> Ask numpy questions on the numpy mailing list. > > I will. I thought that this question would have an answer in a generic > python idiom. When dealing with numpy arrays, the generic Python idiom is often much slower. -- 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 From ricaraoz at gmail.com Wed Mar 31 15:21:48 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Wed, 31 Mar 2010 16:21:48 -0300 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <20100331003241.47fa91f6@vulcan.local> Message-ID: <4BB3A0CC.2090409@gmail.com> Lawrence D'Oliveiro wrote: > In message <20100331003241.47fa91f6 at vulcan.local>, Robert Fendt wrote: > > >> The braces are gone, and with them the holy wars. >> > > Let me start a new one. I would still put in some kind of explicit indicator > of the end of the grouping construct: > > count = 99 > while count > 0: > print u'%d slabs of spam in my mail!' % count > print u'%d slabs of spam,' % count > print u'Send one to abuse and Just Hit Delete,' > count += 1 > print u'%d slabs of spam in my mail!' % count > print u'' > #end while > I'd much prefer the following : ## Beginning of a program block count = 99 # Set the variable count as a name for the integer object 99 while count > 0: # if count is the name of 0 or less then exit the loop (this will NEVER happen) ## Beginning of a while loop print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' ## End of a while loop ## End of a program block Which is reeeaaally easier to understand than : count = 99 while True print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Mar 31 15:22:26 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 15:22:26 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg81f7.5ub3191oci9fkN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> <1jg81f7.5ub3191oci9fkN%see@sig.for.address> Message-ID: Victor Eijkhout wrote: > Robert Kern wrote: > >> second[first.argsort()] > > Really cool. Thanks. > >> Ask numpy questions on the numpy mailing list. > > I will. I thought that this question would have an answer in a generic > python idiom. > > Victor. Not an unreasonable assumption, but it turns out that for most Python users (estimate PFTA: 97%) numpy/scipt is esoteric knowledge. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at rcn.com Wed Mar 31 16:09:54 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 31 Mar 2010 13:09:54 -0700 (PDT) Subject: sort array, apply rearrangement to second References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: <8d8415a5-ba77-4dc3-b870-f159886e76b5@i25g2000yqm.googlegroups.com> On Mar 30, 4:25?pm, s... at sig.for.address (Victor Eijkhout) wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary ?of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. Alf's recommendation is clean and correct. Just make a list of tuples. FWIW, here's a little hack that does the work for you: >>> values = ['A', 'B', 'C', 'D', 'E'] >>> keys = [50, 20, 40, 10, 30] >>> keyiter = iter(keys) >>> sorted(values, key=lambda k: next(keyiter)) ['D', 'B', 'E', 'C', 'A'] Raymond From pulikesimahesh at gmail.com Wed Mar 31 16:18:44 2010 From: pulikesimahesh at gmail.com (SWETHA) Date: Wed, 31 Mar 2010 13:18:44 -0700 (PDT) Subject: Want / Need Genuine Google Adsense Account for Rs.300/- Message-ID: Genuine Google Adsense Account for Rs.300/- We will approve your google adsense approval. We will help you till you get the first adsense check. Please send your mobile number to pramesh0538 at gmail.com , i will call you with in 15 minutes and give you the google adsense account. High Price Reduction for multiple adsense accounts. From icanbob at gmail.com Wed Mar 31 16:21:16 2010 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 31 Mar 2010 13:21:16 -0700 (PDT) Subject: Python + OpenOffice Calc References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Message-ID: <1233c19f-3268-4e57-bec7-e72c17941981@z9g2000vbm.googlegroups.com> On Mar 31, 2:47 am, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price > > a way to add a new "line" if needed (for a new piece entry) similar to the > "add rule" in evolution > > 1 text field for the description of the work + 1 field for the price of > the work > > and off course a way to insert this data in to the ods file via python > > Any hints/tutorial/info? > > thanks > Nico OOcalc supports a little known feature whereby data can be automatically sync'd between the spreadsheet and an HTML table. A few years ago I did up a demo of this in action using Tcl/Tk (http:// www.icanprogram.com/hosug). It should not be too hard to port this idea to Python. bob From steve at holdenweb.com Wed Mar 31 16:21:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 16:21:17 -0400 Subject: Question about list comprehension/standard "for" disparities In-Reply-To: References: Message-ID: Nathan Rice wrote: > I was just wondering, why the list/generator and standard "for" have > disparities? > > It would be really nice to be able to do: > > for x in y if foo: > ... > > rather than: > > for x in (x for x in y if foo): > ... > But it's not much of an issue when you can easily write for x in y: if foo: ... is it? What's the advantage of your preferred format that overrides its reduced readability? > Also, from a style standpoint, I prefer to extract the loop logic into a > function if it's more than a few lines long. As a result, most of my > loops are of the form: > > for x in y: > bar(x) > > So I frequently end up using map. As I understand it, there is some > discussion of removing map() in favor of comprehensions. Is there any > reason why the for syntax could not be expanded to accommodate > statements of the form: > > bar(x) for x in y > > ? > Put parentheses around it and you have a generator expression, which sounds like it's exactly what you want: a lazy way of producing a sequence of values: >>> y = ["this", "that", "and", "the", "other"] >>> def bar(x): ... return 2*x ... >>> ge = (bar(x) for x in y) >>> ge >>> for x in ge: ... print x ... thisthis thatthat andand thethe otherother >>> If you need to use the sequence repeatedly then a list comprehension is clearly better, since you don't exhaust it by iterating over it. I doubt map's going to disappear, but neither are comprehensions or generator expressions. > This inconsistency really bothered me when I started playing with > python, and it seems kind of at-odds with the "one right way to do > things" mentality. > That's the Platonic ideal, but the real world is a dirty place and Python lives firmly in the real world! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From sccolbert at gmail.com Wed Mar 31 16:38:04 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 31 Mar 2010 16:38:04 -0400 Subject: Python + OpenOffice Calc In-Reply-To: <1233c19f-3268-4e57-bec7-e72c17941981@z9g2000vbm.googlegroups.com> References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> <1233c19f-3268-4e57-bec7-e72c17941981@z9g2000vbm.googlegroups.com> Message-ID: On Wed, Mar 31, 2010 at 4:21 PM, bobicanprogram wrote: > On Mar 31, 2:47 am, Tracubik wrote: > > Hi all! > > i'm giving away to a friend of mine that have a garage (he repair car) my > > old computer. He will use it essentialy to create estimates of the work > > via an ods file (i've made a simple ods file to be filled with the cost > of > > materials and a description of the work). > > He's totally new with computer and have difficult to fill the ods file, > so > > i'ld like to create a simple python program that help him to introduce > the > > data in to the ods file via a simple gui. > > So what i'm looking for is a way in python to insert data in a particular > > cell of the ods file and possibly to save it and print it when it's full > > filled with data. > > > > the guy is similar to this: > > > > 3 fields: quantity - description of the piece bought - price > > > > a way to add a new "line" if needed (for a new piece entry) similar to > the > > "add rule" in evolution > > > > 1 text field for the description of the work + 1 field for the price of > > the work > > > > and off course a way to insert this data in to the ods file via python > > > > Any hints/tutorial/info? > > > > thanks > > Nico > > > OOcalc supports a little known feature whereby data can be > automatically sync'd between the spreadsheet and an HTML table. A > few years ago I did up a demo of this in action using Tcl/Tk (http:// > www.icanprogram.com/hosug). It should not be too hard to port this > idea to Python. > > bob > -- > http://mail.python.org/mailman/listinfo/python-list > if he cant click on a cell in oocalc, what makes you think he'll be able to use your program? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lxkain at gmail.com Wed Mar 31 16:59:01 2010 From: lxkain at gmail.com (LX) Date: Wed, 31 Mar 2010 13:59:01 -0700 (PDT) Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: On Mar 30, 2:41?pm, MRAB wrote: > LX wrote: > > On Mar 29, 6:34 pm, MRAB wrote: > >> LX wrote: > >>> Hi all, I have a question about decorators. I would like to use them > >>> for argument checking, and pre/post conditions. However, I don't want > >>> the additional overhead when I run in non-debug mode. I could do > >>> something like this, using a simple trace example. > >>> @decorator > >>> def pass_decorator(f, *args, **kw): # what about the slow-down that > >>> incurs when using pass_decorator? > >>> ? ? return f(*args, **kw) > >>> @decorator > >>> def trace_decorator(f, *args, **kw): > >>> ? ? print "calling %s with args %s, %s" % (f.func_name, args, kw) > >>> ? ? return f(*args, **kw) > >>> trace_enable_flag = False #__debug__ > >>> trace = trace_decorator if trace_enable_flag else pass_decorator > >>> Trouble is, there is still an additional encapsulating function call. > >>> Is there any way to eliminate the extra function call altogether? > >>> Thanks in advance! > >> I think you have misunderstood certain details about decorators. > > >> This code with adecorator: > > >> ? ? ?@decorator > >> ? ? ?def hello(): > >> ? ? ? ? ?print "hello world" > > >> basically does this: > > >> ? ? ?def hello(): > >> ? ? ? ? ?print "hello world" > >> ? ? ?hello =decorator(hello) > > >> so your non-decoratorjust needs to return the function it was passed: > > >> ? ? ?def pass_decorator(func): > >> ? ? ? ? ?return func > > >> and your tracedecoratorwould be something like this: > > >> ? ? ?def trace_decorator(func): > >> ? ? ? ? ?def show(*args, **kwargs): > >> ? ? ? ? ? ? ?print "calling %s with args %s, %s" % (func.func_name, > >> args, kwargs) > >> ? ? ? ? ? ? ?result = func(*args, **kwargs) > >> ? ? ? ? ? ? ?print "returning %s from %s" % (result, func.func_name) > >> ? ? ? ? ? ? ?return result > >> ? ? ? ? ?return show > > > Sure, but during runtime, pass_decorator will still be called, even > > though it doesn't do anything. I am wondering if I can disable this > > additional function call at non-debug runtime. In other words, I want > > the calling stack to contain nodecoratorat all, not even > > pass_decorator. > > > I should mention that, in my code, the symbol "decorator" is imported > > from Michele Simionato'sdecorator.py file. > > pass_decorator will be called when the decorated function is _defined_, > but not when the decorated function is _called_. Why is it then that during runtime, with a breakpoint in some arbitrary main() in main.py, I get something similar to the following call stack: main.py, line xxx, in main() , line 2, in main decorator.py, line 261, in pass_decorator return f(*args, **kw) main.py, line yyy, in main() * breakpoint line here * It looks to me the call stack still includes the additional level of the decorator... what am I missing? Thank you for your time. From novacompute at gmail.com Wed Mar 31 17:26:24 2010 From: novacompute at gmail.com (wukong) Date: Wed, 31 Mar 2010 14:26:24 -0700 (PDT) Subject: subprocess only good for win32? Message-ID: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> subprocess works fine on my win pro 32-bit, but not on vista 64-bit. am i doing some wrong, or it just won't work for win64? If that's true, will it be extended to win64 in teh future? thanks in advance wk From python at mrabarnett.plus.com Wed Mar 31 17:27:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 31 Mar 2010 22:27:05 +0100 Subject: decorators only when __debug__ == True In-Reply-To: References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <4BB3BE29.70504@mrabarnett.plus.com> LX wrote: > On Mar 30, 2:41 pm, MRAB wrote: >> LX wrote: >>> On Mar 29, 6:34 pm, MRAB wrote: >>>> LX wrote: >>>>> Hi all, I have a question about decorators. I would like to use them >>>>> for argument checking, and pre/post conditions. However, I don't want >>>>> the additional overhead when I run in non-debug mode. I could do >>>>> something like this, using a simple trace example. >>>>> @decorator >>>>> def pass_decorator(f, *args, **kw): # what about the slow-down that >>>>> incurs when using pass_decorator? >>>>> return f(*args, **kw) >>>>> @decorator >>>>> def trace_decorator(f, *args, **kw): >>>>> print "calling %s with args %s, %s" % (f.func_name, args, kw) >>>>> return f(*args, **kw) >>>>> trace_enable_flag = False #__debug__ >>>>> trace = trace_decorator if trace_enable_flag else pass_decorator >>>>> Trouble is, there is still an additional encapsulating function call. >>>>> Is there any way to eliminate the extra function call altogether? >>>>> Thanks in advance! >>>> I think you have misunderstood certain details about decorators. >>>> This code with adecorator: >>>> @decorator >>>> def hello(): >>>> print "hello world" >>>> basically does this: >>>> def hello(): >>>> print "hello world" >>>> hello =decorator(hello) >>>> so your non-decoratorjust needs to return the function it was passed: >>>> def pass_decorator(func): >>>> return func >>>> and your tracedecoratorwould be something like this: >>>> def trace_decorator(func): >>>> def show(*args, **kwargs): >>>> print "calling %s with args %s, %s" % (func.func_name, >>>> args, kwargs) >>>> result = func(*args, **kwargs) >>>> print "returning %s from %s" % (result, func.func_name) >>>> return result >>>> return show >>> Sure, but during runtime, pass_decorator will still be called, even >>> though it doesn't do anything. I am wondering if I can disable this >>> additional function call at non-debug runtime. In other words, I want >>> the calling stack to contain nodecoratorat all, not even >>> pass_decorator. >>> I should mention that, in my code, the symbol "decorator" is imported >>> from Michele Simionato'sdecorator.py file. >> pass_decorator will be called when the decorated function is _defined_, >> but not when the decorated function is _called_. > > Why is it then that during runtime, with a breakpoint in some > arbitrary main() in main.py, I get something similar to the following > call stack: > > main.py, line xxx, in > main() > > , line 2, in main > > decorator.py, line 261, in pass_decorator > return f(*args, **kw) > > main.py, line yyy, in main() > * breakpoint line here * > > It looks to me the call stack still includes the additional level of > the decorator... what am I missing? Thank you for your time. Are you still defining your decorators in the same way as in your original post? A decorator shouldn't call the function it's decorating. My version of pass_decorator just returns the function it's decorating, not call it, and my version of trace_decorator returns a locally-defined function which will call the decorated function. From apt.shansen at gmail.invalid Wed Mar 31 17:28:27 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Wed, 31 Mar 2010 14:28:27 -0700 Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <2010033114282721695-aptshansen@gmailinvalid> On 2010-03-31 13:59:01 -0700, LX said: >> pass_decorator will be called when the decorated function is _defined_, >> but not when the decorated function is _called_. > > Why is it then that during runtime, with a breakpoint in some > arbitrary main() in main.py, I get something similar to the following > call stack: > > main.py, line xxx, in > main() > > , line 2, in main > > decorator.py, line 261, in pass_decorator > return f(*args, **kw) > > main.py, line yyy, in main() > * breakpoint line here * > > It looks to me the call stack still includes the additional level of > the decorator... what am I missing? Thank you for your time. You're not defining pass_decorator correctly. Always show us the actual code when you're showing results. Your pass_decorator should just return the original function, undecorated, unmodified if you're not in debug. It should only return a decorated function otherwise. Consider: ----- from decorator import decorator def debug_decorator(fn): if __debug__: def wrapper(fn, *args, **kwargs): # insert pre-condition testing here if len(args) != 1: raise ValueError("Incorrect number of arguments") result = fn(*args, **kwargs) # insert post-condition testing here if result not in (True, False): raise ValueError("Incorrect return value!") return result return decorator(wrapper, fn) else: return fn @debug_decorator def my_test(arg): if not arg: raise RuntimeError return True my_test(0) ----- And the output depending on if you're in debug mode or not: Top:test ixokai$ python deco.py Traceback (most recent call last): File "deco.py", line 27, in my_test(0) File "", line 2, in my_test File "deco.py", line 10, in wrapper result = fn(*args, **kwargs) File "deco.py", line 24, in my_test raise RuntimeError RuntimeError Top:test ixokai$ python -O deco.py Traceback (most recent call last): File "deco.py", line 27, in my_test(0) File "deco.py", line 24, in my_test raise RuntimeError RuntimeError -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From clp2 at rebertia.com Wed Mar 31 17:33:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Mar 2010 14:33:13 -0700 Subject: subprocess only good for win32? In-Reply-To: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: On Wed, Mar 31, 2010 at 2:26 PM, wukong wrote: > subprocess works fine on my win pro 32-bit, but not on vista 64-bit. > am i doing some wrong, or it just won't work for win64? ?If that's > true, will it be extended to win64 in teh future? Please characterize exactly how it is not working for you. Include any error message and/or exception traceback. Cheers, Chris -- http://blog.rebertia.com From dreadpiratejeff at gmail.com Wed Mar 31 17:37:10 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 31 Mar 2010 17:37:10 -0400 Subject: Get Eclipse/PyDev to run scripts that don't end in .py Message-ID: Is there any way to tell PyDev in Eclipse to run a script that doesn't end in .py? Even if I have to go and manually set something for each file... I've inherited (in a manner of speaking) a dev project that is done in python2.6... I pulled the latest dev branch and have it opened as a project in Eclipse, however, none of the python files end in .py, so PyDev only sees them as text files. And because of that, I can't run them in Eclipse to try my changes, debug, etc. So, is there a way to make them show up as python code without the .py extension? Because of this, I also don't get any of the fancy indenting and highlighting that I'd normally get... Cheers, Jeff From novacompute at gmail.com Wed Mar 31 17:43:26 2010 From: novacompute at gmail.com (wukong) Date: Wed, 31 Mar 2010 14:43:26 -0700 (PDT) Subject: subprocess only good for win32? References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: On Mar 31, 2:33?pm, Chris Rebert wrote: > On Wed, Mar 31, 2010 at 2:26 PM, wukong wrote: > > subprocess works fine on my win pro 32-bit, but not on vista 64-bit. > > am i doing some wrong, or it just won't work for win64? ?If that's > > true, will it be extended to win64 in teh future? > > Please characterize exactly how it is not working for you. > Include any error message and/or exception traceback. > > Cheers, > Chris > --http://blog.rebertia.com thanks for checking in, here's the error msg. """ Traceback (most recent call last): File "C:/GUI/mainFunc.py", line 230, in OnSolve subprocess.call([filename]) File "C:\Program Files (x86)\python26\lib\subprocess.py", line 470, in call return Popen(*popenargs, **kwargs).wait() File "C:\Program Files (x86)\python26\lib\subprocess.py", line 621, in __init__ errread, errwrite) File "C:\Program Files (x86)\python26\lib\subprocess.py", line 830, in _execute_child startupinfo) WindowsError: [Error 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail """ also subprocess.py clearly says """ import sys mswindows = (sys.platform == "win32") """ thanks wk From tjreedy at udel.edu Wed Mar 31 17:54:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Mar 2010 17:54:56 -0400 Subject: subprocess only good for win32? In-Reply-To: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: On 3/31/2010 5:26 PM, wukong wrote: > subprocess works fine on my win pro 32-bit, but not on vista 64-bit. You are more likely to get a helpful answer if you give a minimal example and explain exactly what 'not [works fine]' means. What did happen? Include full error traceback if there was one. From python at rcn.com Wed Mar 31 18:42:34 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 31 Mar 2010 15:42:34 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter References: Message-ID: On Mar 31, 10:08?am, Chris Curvey wrote: > I must be having a brain cramp. ?Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > ? ? def __init__(self, a, b, c): > ? ? ? ? self.a = a > ? ? ? ? self.b = b > ? ? ? ? self.c = c > > I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort > ascending on both attributes, but how could i sort by "a, descending, > then b, ascending)?" Rely on sort stability and do two passes: allmyfoos.sort(operator.attrgetter('b')) allmyfoos.sort(operator.attrgetter('a'), reverse=True) Raymond From martin at v.loewis.de Wed Mar 31 18:47:18 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 01 Apr 2010 00:47:18 +0200 Subject: subprocess only good for win32? In-Reply-To: References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: <4BB3D0F6.2010906@v.loewis.de> > WindowsError: [Error 14001] The application has failed to start > because its side-by-side configuration is incorrect. Please see the > application event log for more detail This is a configuration error on your system. The application you are trying to start is incorrectly installed - it's not only that Python can't start it, but nobody can. Regards, Martin From abrahamalrajhi at gmail.com Wed Mar 31 18:48:07 2010 From: abrahamalrajhi at gmail.com (Abethebabe) Date: Wed, 31 Mar 2010 15:48:07 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? Message-ID: I wanted to know if there was a way I could get a Python program to run off of my flash drive as soon as the computer (Windows) detected the device? For example I could have a a simple program that would create a text document on the computers desktop when my flash drive is detected. From steve at REMOVE-THIS-cybersource.com.au Wed Mar 31 18:53:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Mar 2010 22:53:51 GMT Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> On Wed, 31 Mar 2010 22:27:05 +0100, MRAB wrote: > LX wrote: [...] >> It looks to me the call stack still includes the additional level of >> the decorator... what am I missing? Thank you for your time. > > Are you still defining your decorators in the same way as in your > original post? > > A decorator shouldn't call the function it's decorating. *raises eyebrow* Surely, in the general case, a decorator SHOULD call the function it is decorating? I'm sure you know that, but your wording is funny and could confuse the OP. In this specific case, where the OP wants a "do nothing pass-decorator", he should do this: def decorator(func): if __debug__: ... else: return func rather than this: def decorator(func): if __debug__: ... else: def inner(*args): return func(*args) return inner -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Mar 31 18:57:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Mar 2010 22:57:10 GMT Subject: sorting ascending/descending with operator.attrgetter References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> Message-ID: <4bb3d346$0$8827$c3e8da3@news.astraweb.com> On Wed, 31 Mar 2010 12:05:24 -0700, Patrick Maupin wrote: > You can provide a cmp function to the string sort method, e.g. cmp = > lambda x,y: -cmp(x.a, y.a) or cmp(x.b, y.b) String sort method? >>> ''.sort Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'sort' >>> import string >>> string.sort Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'sort' Did you mean list sort method? > You can also possibly gain some efficiency by using key instead of cmp. That is an impressive understatement. key is called once for every item, cmp is called once for every comparison. cmp has been dropped from Python 3.x because its performance is poor. -- Steven From rantingrick at gmail.com Wed Mar 31 19:00:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 31 Mar 2010 16:00:46 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? References: Message-ID: <19123497-50f6-4234-bf99-6550f35324a4@o30g2000yqb.googlegroups.com> On Mar 31, 5:48?pm, Abethebabe wrote: > I wanted to know if there was a way I could get a Python program to > run off of my flash drive as soon as the computer (Windows) detected > the device? > > For example I could have a a simple program that would create a text > document on the computers desktop when my flash drive is detected. Well i sure hope your intentions are for the forces of good and NOT the forces of evil. Anyway the beauty of USB is the fact you can read and write to it just like any other file on your harddisc, unlike with CD media where you need a CS degree and MS's blessing. So now the question really is """ How do i run a python script when i plug in my flash drive"""? And thats a good question. Well it's going to involve "something" watching and waiting for this (big hint) "event" to happen. Maybe something like a "Flash Drive plug in watcher sevice" Do you have any experience with win32 programming? From alfps at start.no Wed Mar 31 19:04:39 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 01 Apr 2010 01:04:39 +0200 Subject: Getting a Python program to run of off a flash drive? In-Reply-To: References: Message-ID: * Abethebabe: > I wanted to know if there was a way I could get a Python program to > run off of my flash drive as soon as the computer (Windows) detected > the device? > > For example I could have a a simple program that would create a text > document on the computers desktop when my flash drive is detected. As long as its your own computer, no problem. However, in the war between the corporate "we own your computer" and the individual's "I think the computer's mine" (so eloquently expressed as the main goal of the 70's Smalltalk project, to bring effective computing to the masses) the arms race is currently stuck at a point where any computer-literate person running Windows turns off the various run-automatically features as soon as they're sneak-introduced by Windows service packs and IE updates and whatever. I don't know, but I think there are six or seven such schemes. Happily, as far as I know they can all be turned off. If not for this then the recording industry could have sued a lot of people in Norway. But our laws require copy protection schemes to be effective, and a scheme based on a feature that most intelligent persons have turned off isn't effective, so wrt. law it's like it's not there. I think it was EMI who once distributed a nasty rootkit (and yes, it was theirs, it was not an accident) as a copy protection scheme on a music CD. Getting a lot of bad publicity for that they and other record companies didn't back off but continued with just less malware-like auto run protection. I was perplexed when I learned that one CD with Madrugada, that I'd copied to my hard disk, was supposedly protected this way. Sure enough, there was this sticker on it. However, since the idiot scheme they used was based on auto-run I never noticed. Cheers, - Alf From python at mrabarnett.plus.com Wed Mar 31 19:27:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 01 Apr 2010 00:27:51 +0100 Subject: decorators only when __debug__ == True In-Reply-To: <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> Message-ID: <4BB3DA77.1040302@mrabarnett.plus.com> Steven D'Aprano wrote: > On Wed, 31 Mar 2010 22:27:05 +0100, MRAB wrote: > >> LX wrote: > [...] >>> It looks to me the call stack still includes the additional level of >>> the decorator... what am I missing? Thank you for your time. >> Are you still defining your decorators in the same way as in your >> original post? >> >> A decorator shouldn't call the function it's decorating. > > *raises eyebrow* > > Surely, in the general case, a decorator SHOULD call the function it is > decorating? I'm sure you know that, but your wording is funny and could > confuse the OP. > What I mean is that the function that's doing the decorating shouldn't call the function; it's the locally-defined wrapper function that calls the decorated function. For example, in my version of trace_decorator() it's show() that calls the decorated function, not trace_decorator() itself. Unless the word 'decorator' refers to the locally-defined function, in which case, what do you call the function that does the wrapping, the one whose name follows the '@'? > In this specific case, where the OP wants a "do nothing pass-decorator", > he should do this: > > def decorator(func): > if __debug__: > ... > else: > return func > > rather than this: > > def decorator(func): > if __debug__: > ... > else: > def inner(*args): > return func(*args) > return inner > > > From lxkain at gmail.com Wed Mar 31 20:01:05 2010 From: lxkain at gmail.com (LX) Date: Wed, 31 Mar 2010 17:01:05 -0700 (PDT) Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> <2010033114282721695-aptshansen@gmailinvalid> Message-ID: <241036ac-23c9-4f2c-8619-69fbba5f300e@30g2000yqi.googlegroups.com> On Mar 31, 2:28?pm, Stephen Hansen wrote: > On 2010-03-31 13:59:01 -0700, LX said: > > > > > > >> pass_decorator will be called when the decorated function is _defined_, > >> but not when the decorated function is _called_. > > > Why is it then that during runtime, with a breakpoint in some > > arbitrary main() in main.py, I get something similar to the following > > call stack: > > > main.py, line xxx, in > > ?main() > > > , line 2, in main > > >decorator.py, line 261, in pass_decorator > > ?return f(*args, **kw) > > > main.py, line yyy, in main() > > ?* breakpoint line here * > > > It looks to me the call stack still includes the additional level of > > thedecorator... what am I missing? Thank you for your time. > > You're not defining pass_decorator correctly. Always show us the actual > code when you're showing results. > > Your pass_decorator should just return the original function, > undecorated, unmodified if you're not in debug. It should only return a > decorated function otherwise. > > Consider: > > ----- > fromdecoratorimportdecorator > > def debug_decorator(fn): > ? ? if __debug__: > ? ? ? ? def wrapper(fn, *args, **kwargs): > ? ? ? ? ? ? # insert pre-condition testing here > ? ? ? ? ? ? if len(args) != 1: > ? ? ? ? ? ? ? ? raise ValueError("Incorrect number of arguments") > > ? ? ? ? ? ? result = fn(*args, **kwargs) > > ? ? ? ? ? ? # insert post-condition testing here > ? ? ? ? ? ? if result not in (True, False): > ? ? ? ? ? ? ? ? raise ValueError("Incorrect return value!") > > ? ? ? ? ? ? return result > ? ? ? ? returndecorator(wrapper, fn) > ? ? else: > ? ? ? ? return fn > > @debug_decorator > def my_test(arg): > ? ? if not arg: > ? ? ? ? raise RuntimeError > ? ? return True > > my_test(0) > ----- > > And the output depending on if you're in debug mode or not: > Top:test ixokai$ python deco.py > Traceback (most recent call last): > ? File "deco.py", line 27, in > ? ? my_test(0) > ? File "", line 2, in my_test > ? File "deco.py", line 10, in wrapper > ? ? result = fn(*args, **kwargs) > ? File "deco.py", line 24, in my_test > ? ? raise RuntimeError > RuntimeError > > Top:test ixokai$ python -O deco.py > Traceback (most recent call last): > ? File "deco.py", line 27, in > ? ? my_test(0) > ? File "deco.py", line 24, in my_test > ? ? raise RuntimeError > RuntimeError > > -- > --S > > ... p.s: change the ".invalid" to ".com" in email address to reply privately. Thank you all a lot! The last 3 posts helped me figure it out. Indeed, my pass_decorator function used "@decorator", using the decoratory.py library. This prevented return of the original function. The code that I have now is: #NOT THIS: #@decorator #def pass_decorator(f, *args, **kw): # what about the slow-down that incurs when using pass_decorator #return f(*args, **kw) def pass_decorator(f): return f @decorator def trace_decorator(f, *args, **kw): print "calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) trace_enable_flag = False #__debug__ trace = trace_decorator if trace_enable_flag else pass_decorator From pmaupin at gmail.com Wed Mar 31 20:21:18 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 31 Mar 2010 17:21:18 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> <4bb3d346$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mar 31, 5:57?pm, Steven D'Aprano wrote: > Did you mean list sort method? Why, yes. Yes, I did. Yes, I'm an old forgetful man who sometimes misspeaks or mistypes, and you're the smartest, sharpest guy in the world. Most helpful, too. It's much more useful to show how I'm wrong than to provide useful info to the OP. Teaches people not to quickly post on CLP to try to help out people with immediate problems. No, it would have been much more useful for me to self-edit my post for a couple of days before posting. Doesn't matter though. The OP was sorting lists, not strings, so he knew what I meant. > > You can also possibly gain some efficiency by using key instead of cmp. > > That is an impressive understatement. key is called once for every item, > cmp is called once for every comparison. cmp has been dropped from Python > 3.x because its performance is poor. Yes, well, I did have the "Use a key" statement before "use cmp" (before I did the tiny bit of editing I did before posting) and then it occurred to me that he might be sorting with strings, so I thought I would give him something that worked, and then something that might work better under some circumstances. And, BTW, if he is only occasionally sorting a few short strings^H^H^H^H^H^H^Hlists, he'll never notice a performance difference. But at least you can take comfort that he now knows how superior your intellect is to mine. Of course, he might accidentally underestimate Peter and Raymond's intellect. They published dual sort solutions that are, for most cases, probably better than the single sort solution I published, but neglected to call attention to just how bad my suggestion was. From abrahamalrajhi at gmail.com Wed Mar 31 20:32:33 2010 From: abrahamalrajhi at gmail.com (Abethebabe) Date: Wed, 31 Mar 2010 17:32:33 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? References: <19123497-50f6-4234-bf99-6550f35324a4@o30g2000yqb.googlegroups.com> Message-ID: <11ac4094-655e-4474-98c8-fa8829d4f56f@z3g2000yqz.googlegroups.com> On Mar 31, 7:00?pm, rantingrick wrote: > On Mar 31, 5:48?pm, Abethebabe wrote: > > > I wanted to know if there was a way I could get a Python program to > > run off of my flash drive as soon as the computer (Windows) detected > > the device? > > > For example I could have a a simple program that would create a text > > document on the computers desktop when my flash drive is detected. > > Well i sure hope your intentions are for the forces of good and NOT > the forces of evil. Anyway the beauty of USB is the fact you can read > and write to it just like any other file on your harddisc, unlike with > CD media where you need a CS degree and MS's blessing. So now the > question really is > > """ How do i run a python script when i plug in my flash drive"""? > > And thats a good question. Well it's going to involve "something" > watching and waiting for this (big hint) "event" to happen. Maybe > something like a "Flash Drive plug in watcher sevice" Do you have any > experience with win32 programming? I'm a web programmer and python is my first delve into desktop programming. I had a rough guesstimation that I'd need to maybe use wxpython with an API for the flash drive (wasn't sure if hardware had this, I guess it would be the drivers?) So do you think wxPython would have the answer I'm looking for? Thanks for your reply btw From abrahamalrajhi at gmail.com Wed Mar 31 20:33:49 2010 From: abrahamalrajhi at gmail.com (Abethebabe) Date: Wed, 31 Mar 2010 17:33:49 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? References: Message-ID: On Mar 31, 7:04?pm, "Alf P. Steinbach" wrote: > * Abethebabe: > > > I wanted to know if there was a way I could get a Python program to > > run off of my flash drive as soon as the computer (Windows) detected > > the device? > > > For example I could have a a simple program that would create a text > > document on the computers desktop when my flash drive is detected. > > As long as its your own computer, no problem. > > However, in the war between the corporate "we own your computer" and the > individual's "I think the computer's mine" (so eloquently expressed as the main > goal of the 70's Smalltalk project, to bring effective computing to the masses) > the arms race is currently stuck at a point where any computer-literate person > running Windows turns off the various run-automatically features as soon as > they're sneak-introduced by Windows service packs and IE updates and whatever. I > don't know, but I think there are six or seven such schemes. Happily, as far as > I know they can all be turned off. If not for this then the recording industry > could have sued a lot of people in Norway. But our laws require copy protection > schemes to be effective, and a scheme based on a feature that most intelligent > persons have turned off isn't effective, so wrt. law it's like it's not there. > > I think it was EMI who once distributed a nasty rootkit (and yes, it was theirs, > it was not an accident) as a copy protection scheme on a music CD. Getting a lot > of bad publicity for that they and other record companies didn't back off but > continued with just less malware-like auto run protection. I was perplexed when > I learned that one CD with Madrugada, that I'd copied to my hard disk, was > supposedly protected this way. Sure enough, there was this sticker on it. > However, since the idiot scheme they used was based on auto-run I never noticed. > > Cheers, > > - Alf Interesting, so every new computer I'd use it on I would need to disable these filters? If I could just disable them on my computer though I'd be happy enough. From keith at nekotaku.com Wed Mar 31 20:38:46 2010 From: keith at nekotaku.com (KB) Date: Wed, 31 Mar 2010 17:38:46 -0700 (PDT) Subject: CGI templating with python Message-ID: Hi there, Years ago I wrote a LAMP app using python. I find I need a simple web data entry tool to store records (stock research) and when I enter a stock ticker, to pull up all the past research I have done. I am imagining fields like ticker, date, pulldown menus for various options, long text for comments etc.. It's a very light weight application, so I was wondering if using something like Cheetah is the best way to do this? Or should I research Zope further or are there any other suggestions? Environment: - Python 2.5 (w/ MySQLdb) - MySQL 5.1 - Windows Vista Many thanks in advance! From martin.hellwig at dcuktec.org Wed Mar 31 21:13:57 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 01 Apr 2010 02:13:57 +0100 Subject: Get Eclipse/PyDev to run scripts that don't end in .py In-Reply-To: References: Message-ID: On 03/31/10 22:37, J wrote: > Is there any way to tell PyDev in Eclipse to run a script that doesn't > end in .py? Even if I have to go and manually set something for each > file... > > I've inherited (in a manner of speaking) a dev project that is done in > python2.6... I pulled the latest dev branch and have it opened as a > project in Eclipse, however, none of the python files end in .py, so > PyDev only sees them as text files. And because of that, I can't run > them in Eclipse to try my changes, debug, etc. > > So, is there a way to make them show up as python code without the .py > extension? Because of this, I also don't get any of the fancy > indenting and highlighting that I'd normally get... > > Cheers, > > Jeff You probably need to do that one level higher, i.e. in Eclipse (hint: Preferences>General>Editors>File Associations ). I do have a couple of remarks though. It sounds to me like you inherited something of more or less a 'shipped' product. Perhaps it would be wise to invest some time to restructure the project so that it works nicely with all the tools you have (unit testing, coverage, refactoring, etc.) and build a script that from your source builds the actually release (resembling that what you have inherited). This question would probably have been more suitable in http://sourceforge.net/projects/pydev/forums/forum/293649 (that is the PyDev forum), and it is likely that they would have sent you through to http://www.eclipse.org/forums/ . -- mph From fabiofz at gmail.com Wed Mar 31 21:17:09 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 31 Mar 2010 22:17:09 -0300 Subject: Get Eclipse/PyDev to run scripts that don't end in .py In-Reply-To: References: Message-ID: On Wed, Mar 31, 2010 at 6:37 PM, J wrote: > Is there any way to tell PyDev in Eclipse to run a script that doesn't > end in .py? ?Even if I have to go and manually set something for each > file... > > I've inherited (in a manner of speaking) a dev project that is done in > python2.6... I pulled the latest dev branch and have it opened as a > project in Eclipse, however, none of the python files end in .py, so > PyDev only sees them as text files. ?And because of that, I can't run > them in Eclipse to try my changes, debug, etc. > > So, is there a way to make them show up as python code without the .py > extension? ?Because of this, I also don't get any of the fancy > indenting and highlighting that I'd normally get... You have to change it in 2 places: 1. window > preferences > general > editors > file associations: add the *.extension and bind it to the Python Editor (see how the *.py association is done). 2. window > preferences > Pydev > editor > code style > file types: add your custom extension there (and you may want to change the default python extension if you'll keep creating modules with that different extension). Cheers, Fabio From steven at REMOVE.THIS.cybersource.com.au Wed Mar 31 21:30:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Apr 2010 01:30:21 GMT Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Thu, 01 Apr 2010 00:27:51 +0100, MRAB wrote: >>> A decorator shouldn't call the function it's decorating. >> >> *raises eyebrow* >> >> Surely, in the general case, a decorator SHOULD call the function it is >> decorating? I'm sure you know that, but your wording is funny and could >> confuse the OP. >> > What I mean is that the function that's doing the decorating shouldn't > call the function; it's the locally-defined wrapper function that calls > the decorated function. Ah, gotcha, that makes sense. Now I understand the distinction you were making. Thank you for the clarification. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Mar 31 21:34:36 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Apr 2010 01:34:36 GMT Subject: sorting ascending/descending with operator.attrgetter References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> <4bb3d346$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Wed, 31 Mar 2010 17:21:18 -0700, Patrick Maupin wrote: > Doesn't matter though. The OP was sorting lists, not strings, so he > knew what I meant. I have found that when people ask basic questions about fundamental Python operations like sorting, it is risky to assume that they will know what I meant if I say something different. Since I've been on both the giving and receiving end of carelessly inaccurate answers, I know how frustrating it is to spend significant time trying to work out what I was doing wrong, only to be told much later "Oh, I meant you should do Y, not X. I thought you would understand what I meant." -- Steven From steve at holdenweb.com Wed Mar 31 22:19:27 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 22:19:27 -0400 Subject: sorting ascending/descending with operator.attrgetter In-Reply-To: References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> <4bb3d346$0$8827$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 31 Mar 2010 17:21:18 -0700, Patrick Maupin wrote: > >> Doesn't matter though. The OP was sorting lists, not strings, so he >> knew what I meant. > > I have found that when people ask basic questions about fundamental > Python operations like sorting, it is risky to assume that they will know > what I meant if I say something different. > > Since I've been on both the giving and receiving end of carelessly > inaccurate answers, I know how frustrating it is to spend significant > time trying to work out what I was doing wrong, only to be told much > later "Oh, I meant you should do Y, not X. I thought you would understand > what I meant." > But you surely will admit that you could be held to, well rather than "be pedantic" perhaps we should say "tend towards the literal"? I'm the same myself, and I know from personal experience that while I am (simply?) seeking accuracy and truth it sometimes bugs the hell out of people ... It's a geek thing. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From robert.kern at gmail.com Wed Mar 31 22:46:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 31 Mar 2010 21:46:54 -0500 Subject: CGI templating with python In-Reply-To: References: Message-ID: On 2010-03-31 19:38 , KB wrote: > Hi there, > > Years ago I wrote a LAMP app using python. I find I need a simple web > data entry tool to store records (stock research) and when I enter a > stock ticker, to pull up all the past research I have done. I am > imagining fields like ticker, date, pulldown menus for various > options, long text for comments etc.. > > It's a very light weight application, so I was wondering if using > something like Cheetah is the best way to do this? > > Or should I research Zope further or are there any other suggestions? Django will probably get you where you want to go the fastest: http://www.djangoproject.com/ In particular, its admin interface will probably automatically generate a usable UI for you without your having to write many templates at all. -- 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 From aahz at pythoncraft.com Wed Mar 31 23:33:35 2010 From: aahz at pythoncraft.com (Aahz) Date: 31 Mar 2010 20:33:35 -0700 Subject: Getting a Python program to run of off a flash drive? References: Message-ID: In article , Alf P. Steinbach wrote: > >I think it was EMI who once distributed a nasty rootkit (and yes, it >was theirs, it was not an accident) as a copy protection scheme on a >music CD. Sony, and I still (mostly) boycott Sony. (I buy no Sony hardware, but because Sony owns a movie studio, it's a little more difficult to boycott Sony DVDs.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? From ded.utility at gmail.com Wed Mar 31 23:36:56 2010 From: ded.utility at gmail.com (d d) Date: Wed, 31 Mar 2010 23:36:56 -0400 Subject: how to build with --enable-shared so that binary knows where libraries are. Message-ID: The following is on Linux. I'd like to build python with ./configure --enable-shared. And install in a non-standard place (an nfs-mounted directory). However, the binary is then not usable, since it can't find the library. I can fix this by defining LD_LIBRARY_PATH, but I don't want to do that. Doing anything system-specific is impractical, since many systems will point to this directory (LD_LIBRARY_PATH is feasible, though undesired, because it can be set in a common script that users call from their .cshrc files.) Is there a way to configure the build such that the binary will know where the shared library is? I found this: http://koansys.com/tech/building-python-with-enable-shared-in-non-standard-location It recommends LDFLAGS="-rpath ", and mentions that you get a "compiler cannot create executables" error unless you first create the empty directory. But I get that error even when I do create the empty directory. Any help would be appreciated. --Dan From rantingrick at gmail.com Wed Mar 31 23:53:08 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 31 Mar 2010 20:53:08 -0700 (PDT) Subject: Python + OpenOffice Calc References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Message-ID: On Mar 31, 2:47?am, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price So what is your plan...? * Pop up a dialog with three entrys, * have him fill out the three entrys, * then have python insert the data into the spreadsheet? ...Why bother messing with OO, too much trouble for me? If the guy is that scared of spreadsheets I would skip the spreadsheet all together and just use a Tk.Listbox to display the data. Create a big button at the bottom (preferably in Times 20 red font) that says "NEW INPUT" and let him edit lines by double clicking on them. You need a good Scrolled Listbox with a nice interface, an entry dialog, and some file IO with backup protection. Thats about it. I would probably create a new file every day, week, or month depending on the amount of data he enters daily, you don't want to load enormous files into a Tk.Listbox. Then just save all the data as csv and you can always load it into a spreadsheet later if the IRS comes knocking, or you need to print a professional looking spreadsheet ;-). Simple, 100% python solution! If you want to do this and need help i would be happy to offer my assistance. This would be a "fairly" simple script and great learning experience for you. From clp2 at rebertia.com Mon Mar 1 01:30:45 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 28 Feb 2010 22:30:45 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> References: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Message-ID: <50697b2c1002282230v2f421944u5866685a985fd904@mail.gmail.com> On Sun, Feb 28, 2010 at 10:39 PM, John Nagle wrote: > Patrick Maupin wrote: >> >> All: >> >> Finding .ini configuration files too limiting, JSON and XML to hard to >> manually edit, and YAML too complex to parse quickly, I have started >> work on a new configuration file parser. > > ? You're not supposed to edit those formats manually. Huh? True for XML /perhaps/, but for the others I quite disagree. Perhaps you could explain your reasoning? Cheers, Chris -- http://blog.rebertia.com From nagle at animats.com Mon Mar 1 01:39:56 2010 From: nagle at animats.com (John Nagle) Date: Sun, 28 Feb 2010 22:39:56 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Patrick Maupin wrote: > All: > > Finding .ini configuration files too limiting, JSON and XML to hard to > manually edit, and YAML too complex to parse quickly, I have started > work on a new configuration file parser. You're not supposed to edit those formats manually. John Nagle From rantingrick at gmail.com Mon Mar 1 01:41:26 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 28 Feb 2010 22:41:26 -0800 (PST) Subject: Sample code usable Tkinter listbox References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> Message-ID: <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> On Feb 28, 9:57?pm, "Alf P. Steinbach" wrote: > * rantingrick: I just hate overriding all the paths to each listbox method. How about just overideing the Listboxe's geomerty methods once an your done? #-- start script --# import Tkinter as tk from Tkconstants import * import tkMessageBox as MB class ScrolledList(tk.Listbox): def __init__(self, master, **kw): self.frame = tk.Frame(master) self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) self.hbar = tk.Scrollbar(self.frame, orient=HORIZONTAL) self.block = tk.Frame(self.frame, width=18, height=18) self.block.grid(row=1, column=1) self.vbar = tk.Scrollbar(self.frame, orient=VERTICAL) kw.setdefault('activestyle', 'none') kw.setdefault('highlightthickness', 0) if 'pack' in kw.keys() and kw.pop('pack') == 1: self.frame.pack(fill=BOTH, expand=1) tk.Listbox.__init__(self, self.frame, **kw) self.grid(row=0, column=0, sticky=N+S+E+W) self.hbar.configure(command=self.xview) self.vbar.configure(command=self.yview) self.config( yscrollcommand=self.vbar.set, xscrollcommand=self.hbar.set ) self.hbar.grid(row=1, column=0, sticky=W+E) self.vbar.grid(row=0, column=1, sticky=N+S) self.pack = lambda **kw: self.frame.pack(**kw) self.grid = lambda **kw: self.frame.grid(**kw) self.place = lambda **kw: self.frame.place(**kw) self.pack_config = lambda **kw: self.frame.pack_config(**kw) self.grid_config = lambda **kw: self.frame.grid_config(**kw) self.place_config = lambda **kw: self.frame.place_config(**kw) self.pack_configure = lambda **kw: self.frame.pack_config(**kw) self.grid_configure = lambda **kw: self.frame.grid_config(**kw) self.place_configure = lambda **kw: self.frame.place_config(**kw) def gets(self): return self.get(0, END) def sets(self, arg): self.delete(0, END) try: arg = arg.strip('\n').splitlines() except AttributeError: pass if hasattr(arg, '__getitem__'): for item in arg: self.insert(END, str(item)) else: raise TypeError("Scrolledlist.sets() requires a string of iterable of strings") if __name__ == '__main__': root = tk.Tk() listbox = ScrolledList(root, width=50, height=5, fg='green', selectmode='Extended', pack=1) #listbox.sets(1.25) #listbox.sets('1\n2\n3\n4\n5\n\n\n') listbox.sets(range(100)) root.mainloop() #-- end script --# From stefan_ml at behnel.de Mon Mar 1 02:46:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Mar 2010 08:46:04 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: References: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> Message-ID: Hal Styli, 01.03.2010 00:15: > Stefan, I was happy to see such concise code. > Your python worked with only very minor modifications. > > Hai's test xml data *without* the first and last line is close enough > to the data I am using: > > > > > > > > ... quirky. > > I get a large file given to me in this format. I believe it is > created by something like: > grep 'customer=' *.xml, where there are a large number of xml files. Try to get this fixed at the source. Exporting non-XML that looks like XML is not a good idea in general, and it means that everyone who wants to read the data has to adapt, instead of fixing the source once and for all. > I had to edit the data to include the first and last lines, > and , > to get the python code to work. It's not an arduous task(!), but can > you recommend a way to get it to work without > manually editing the data? Iff this cannot be fixed at the source, you can write a file-like wrapper around a file that simply returns the boundary tags before and after reading from the file itself. All you need is a .read(n) method, see the documentation of the file type. > One other thing, what's the Roland Mueller post above about (I'm > viewing htis in google groups)? What would the test.xsl file look > like? This is the XSLT script he posted: ============================ , , ============================ Stefan From steven.bethard at gmail.com Mon Mar 1 03:31:09 2010 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 1 Mar 2010 00:31:09 -0800 Subject: [ANN] argparse 1.1 - Command-line parsing library Message-ID: ======================= Announcing argparse 1.1 ======================= The argparse module provides an easy, declarative interface for creating command line tools, which knows how to: * parse the arguments and flags from sys.argv * convert arg strings into objects for your program * format and print informative help messages * and much more... The argparse module improves on the standard library optparse module in a number of ways including: * handling positional arguments * supporting sub-commands * allowing alternative option prefixes like + and / * handling zero-or-more and one-or-more style arguments * producing more informative usage messages * providing a much simpler interface for custom types and actions Download argparse ================= The argparse homepage has links for source, MSI and single file distributions of argparse: http://code.google.com/p/argparse/ About this release ================== This is the final release of argparse before its move to the Python 2.7 and 3.2 standard libraries. Major enhancements in this release: * ArgumentParser(..., version=XXX) is deprecated. Instead, you should use add_argument(..., action='version') which is more flexible and does not force you to accept -v/--version as your version flags. * Usage and help (but not version) messages are now written to stdout instead of stderr, consistent with most existing programs. * User defined types passed as a type= argument can now raise an ArgumentTypeError to provide a custom error message. * Namespace objects now support containment, e.g. "'foo' in args". Various bugs were also squashed, e.g. "from argparse import *" now works. See the news file for detailed information: http://argparse.googlecode.com/svn/tags/r11/NEWS.txt Enjoy! Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus From anthra.norell at bluewin.ch Mon Mar 1 04:17:59 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 01 Mar 2010 10:17:59 +0100 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: <4B8B8647.1040008@bluewin.ch> Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. > What compels you to write Python code without semicolons? Frederic From chris at simplistix.co.uk Mon Mar 1 04:38:13 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 01 Mar 2010 09:38:13 +0000 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <4B8B8B05.3060407@simplistix.co.uk> Aahz wrote: > In article <4b79e28c$0$4610$426a74cc at news.free.fr>, > News123 wrote: > >> Is there a python way to register new windows services. >> >> I am aware of the >> instsrv.exe program, which can be used to install services. >> I could use subprocess.Popen to call >> >> instsrv.exe "service_name" program.exe >> >> but wondered, whether there's already an existing function. > > Use the win32 package. Indeed, there's some intersting code in this area here: http://svn.zope.org/Zope/trunk/src/nt_svcutils/service.py?rev=104819&view=auto http://svn.zope.org/Zope/trunk/src/Zope2/Startup/zopectl.py?rev=105396&view=auto ...particularly in the do_install function in the latter... Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From bartsmeets86 at gmail.com Mon Mar 1 04:48:05 2010 From: bartsmeets86 at gmail.com (Bart Smeets) Date: Mon, 1 Mar 2010 10:48:05 +0100 Subject: Detecting new removable drives in Linux Message-ID: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> Hello, I'm trying to write a script which detects when a new removable drive is connected to the computer. On #python I was advised to use the dbus-bindings. However the documentation on this is limited. Does anyone know of an example of how I can detect new removable drives? Thanks in advance! Regards, Bart -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 1 05:34:45 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Mar 2010 11:34:45 +0100 Subject: Docstrings considered too complicated In-Reply-To: <4B89D8BE.2040905@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> Message-ID: <4B8B9845.70604@sequans.com> MRAB wrote: > Gregory Ewing wrote: >> Mel wrote: >> >>> You could think of it as a not bad use of the design principle >>> "Clear The Simple Stuff Out Of The Way First". Destinations are >>> commonly a lot simpler than sources >> >> That's not usually true in assembly languages, though, >> where the source and destination are both very restricted >> and often about the same complexity. >> >> That's not to say that right-to-left is the wrong way >> to do it in an assembly language, but there are less >> misleading words than "move" that could be used. >> >> Z80 assembly language uses "load", which makes things >> considerably clearer: >> >> LD A, B ; load A with B >> > Some processors distinguish between "load" (memory to register) and > "store" (register to memory), and the destination and LHS operand of > binary operations might be the same register, for example: > > CLC ; clear the carry > LDA first ; accumulator := byte at first > ADCA second ; accumulator := accumulator + byte at second + carry > STA result ; byte at third := accumulator > Guys, you sound like people arguing about old school TV show / series like star treck :-) - "He was wearing a blue suit !" - "Check episode number 29, he appeared with a pink one!" I'm glad I'm too young to had to code in assembler, or to bear the vision of those unlikely space suits from the 70's ;-) JM From lucaberto at libero.it Mon Mar 1 05:48:34 2010 From: lucaberto at libero.it (luca72) Date: Mon, 1 Mar 2010 02:48:34 -0800 (PST) Subject: pythonpath Message-ID: <7b9322bb-0b63-44e4-94c5-324006adff8b@t23g2000yqt.googlegroups.com> Sorry for my stupid question if i have to load module from a folder i have to append it to the sys path the folder? ex: if my folder module is /home/lucak904/Scrivania/Luca/enigma2 i do this : import sys sys.path.append('/home/lucak904/Scrivania/Luca/enigma2') If this is correct why when i write: form enigma2 import * i get no module named enigma2 Thanks Luca I'm under linux From candide at free.invalid Mon Mar 1 05:58:57 2010 From: candide at free.invalid (candide) Date: Mon, 01 Mar 2010 11:58:57 +0100 Subject: Starting Python from the terminal with no welcome message In-Reply-To: References: <4b8afafa$0$28635$426a74cc@news.free.fr> Message-ID: <4b8b9df2$0$10478$426a74cc@news.free.fr> Tim Chase a ?crit : > > bash$ python -ic "" > > to get a python shell without the banner. > Works fine. thanks a lot. From nanyaks at googlemail.com Mon Mar 1 07:01:08 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:01:08 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On Feb 25, 12:21 pm, "Martin P. Hellwig" wrote: > On 02/25/10 10:26, simn_stv wrote: > > what i am concerned about is scalability and > > efficiency, well, as far as the 'core' is concerned. > > > would python be able to manage giving me a solid 'core' and will i be > > able to use python provide any API i would like to implement?... > > > Python isn't the most efficient language, the assembler provided by the > maker of your CPU probably is the best you can get, LOL...;), yeah right, the mere thought of writing assembler instructions is SCARY!! >everything after > that is a trade-off between performance and flexibility (flexible in the > most flexible sense of the word :-)). > > That being said, for me, Python (well actually any turing complete > programming language), is more like a box of lego with infinite amount > of pieces. > Scalability and API issues are the same as the shape and function of the > model your making with lego. > > Sure some type of pieces might be more suited than other types but since > you can simulate any type of piece with the ones that are already > present, you are more limited by your imagination than by the language. > > So in short, I don't see any serious problems using Python, I have used > it in Enterprise environments without any problems but than again I was > aware not to use it for numerical intensive parts without the use of 3rd > party libraries like numpy. Which for me resulted in not doing the > compression of a database delta's in pure python but to offload that to > a more suitable external program, still controlled from Python though. > > -- > mph From marduk at python.net Mon Mar 1 07:09:38 2010 From: marduk at python.net (Albert Hopkins) Date: Mon, 01 Mar 2010 07:09:38 -0500 Subject: Detecting new removable drives in Linux In-Reply-To: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> References: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> Message-ID: <1267445378.72674.3.camel@centar> On Mon, 2010-03-01 at 10:48 +0100, Bart Smeets wrote: > Hello, > > > I'm trying to write a script which detects when a new removable drive > is connected to the computer. On #python I was advised to use the > dbus-bindings. However the documentation on this is limited. Does > anyone know of an example of how I can detect new removable drives? The documentation does suck and, at least for the python bindings, is horribly outdated. Also, the python bindings for dbus are not as "pythonic" as they could be. I was working on a python/dbus program a while back and basically had to resort to looking at the source of a program that did, or almost did, what I wanted and using that as an example. You may even want to look at C sources as I don't think the python bindings are that much different. HTH, -a From lyh19901223 at gmail.com Mon Mar 1 07:10:55 2010 From: lyh19901223 at gmail.com (=?UTF-8?B?5YiY5a6H6L6J?=) Date: Mon, 1 Mar 2010 12:10:55 +0000 Subject: pythonpath Message-ID: >Sorry for my stupid question if i have to load module >from a folder ihave to append it to the sys path the >folder? >ex: >if my folder module is /home/lucak904/Scrivania/Luca/enigma2 >i do this : >import sys >sys.path.append('/home/lucak904/Scrivania/Luca/enigma2') >If this is correct why when i write: >form enigma2 import * >i get no module named enigma2 is the folder module /home/lucak904/Scrivania/Luca/enigma2.py? i think the extension is necessary . -- wolf python london -------------- next part -------------- An HTML attachment was scrubbed... URL: From nanyaks at googlemail.com Mon Mar 1 07:11:07 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:11:07 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On Feb 25, 5:18 pm, "D'Arcy J.M. Cain" wrote: > On Thu, 25 Feb 2010 15:29:34 +0000 > "Martin P. Hellwig" wrote: > > > On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > > > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > > > > > Our biggest problem was in > > > a network heavy element of the app and that was low level TCP/IP stuff > > > that rather than being Python's problem was something we used Python to > > > fix. > > > > Out off interest, could you elaborate on that? > > Somewhat - there is an NDA so I can't give exact details. It was > crucial to our app that we sync up databases in Canada and the US (later > Britain, Europe and Japan) in real time with those transactions. Our > problem was that even though our two server systems were on the > backbone, indeed with the same major carrier, we could not keep them in > sync. We were taking way to long to transact an update across the > network. > > The problem had to do with the way TCP/IP works, especially closer to > the core. Our provider was collecting data and sending it only after > filling a buffer or after a timeout. The timeout was short so it > wouldn't normally be noticed and in most cases (web pages e.g.) the > connection is opened, data is pushed and the connection is closed so > the buffer is flushed immediately. Our patterns were different so we > were hitting the timeout on every single transaction and there was no > way we would have been able to keep up. > > Our first crack at fixing this was to simply add garbage to the packet > we were sending. Making the packets an order of magnitude bigger sped > up the proccessing dramatically. That wasn't a very clean solution > though so we looked for a better way. > > That better way turned out to asynchronous update transactions. All we > did was keep feeding updates to the remote site and forget about ACKS. > We then had a second process which handled ACKS and tracked which > packets had been properly transferred. The system had IDs on each > update and retries happened if ACKS didn't happen soon enough. > Naturally we ignored ACKS that we had already processed. > > All of the above (and much more complexity not even discussed here) was > handled by Python code and database manipulation. There were a few > bumps along the way but overall it worked fine. If we were using C or > even assembler we would not have sped up anything and the solution we > came up with would have been horrendous to code. As it was I and my > chief programmer locked ourselves in the boardroom and had a working > solution before the day was out. sure it wouldnt have sped it up a bit, even a bit?; probably the development and maintenance time would be a nightmare but it should speed the app up a bit... > > Python wins again. > > -- > D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. seriously added to the reputation of python, from my own perspective...kudos python! From marduk at python.net Mon Mar 1 07:14:19 2010 From: marduk at python.net (Albert Hopkins) Date: Mon, 01 Mar 2010 07:14:19 -0500 Subject: pythonpath In-Reply-To: <7b9322bb-0b63-44e4-94c5-324006adff8b@t23g2000yqt.googlegroups.com> References: <7b9322bb-0b63-44e4-94c5-324006adff8b@t23g2000yqt.googlegroups.com> Message-ID: <1267445659.72674.8.camel@centar> On Mon, 2010-03-01 at 02:48 -0800, luca72 wrote: > Sorry for my stupid question if i have to load module from a folder i > have to append it to the sys path the folder? > ex: > if my folder module is /home/lucak904/Scrivania/Luca/enigma2 > i do this : > import sys > sys.path.append('/home/lucak904/Scrivania/Luca/enigma2') > If this is correct why when i write: > form enigma2 import * > i get no module named enigma2 There are two reasons for this: 1. enigma2 is not in your namespace. What's inside enigma is. For example, you can't say "from site-packages import *" because Python doesn't look at "site-packages". It looks at what's inside site-packages. If you wanted" enigma2" to be in your namespace, you should add /home/lucak904/Scrivania/Luca" to your system path. 2. Even if you did above, it may not work because enigma2 is a directory. Remember "from x import *" only works for modules and packages, so if you want "enigma2" to be a package, remember to add an (empty) __init__.py to the directory. Hope this helps. -a From alfps at start.no Mon Mar 1 07:19:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 13:19:32 +0100 Subject: Sample code usable Tkinter listbox In-Reply-To: <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> Message-ID: * rantingrick: > > kw.setdefault('activestyle', 'none') Hm, let me steal this line... Thanks! Cheers, - Alf From nanyaks at googlemail.com Mon Mar 1 07:27:12 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:27:12 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <79ff2083-bde8-4a60-854d-b90e3d944b94@y17g2000yqd.googlegroups.com> On Feb 25, 5:18 pm, "D'Arcy J.M. Cain" wrote: > On Thu, 25 Feb 2010 15:29:34 +0000 > "Martin P. Hellwig" wrote: > > > On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > > > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > > > > > Our biggest problem was in > > > a network heavy element of the app and that was low level TCP/IP stuff > > > that rather than being Python's problem was something we used Python to > > > fix. > > > > Out off interest, could you elaborate on that? > > Somewhat - there is an NDA so I can't give exact details. It was > crucial to our app that we sync up databases in Canada and the US (later > Britain, Europe and Japan) in real time with those transactions. Our > problem was that even though our two server systems were on the > backbone, indeed with the same major carrier, we could not keep them in > sync. We were taking way to long to transact an update across the > network. > > The problem had to do with the way TCP/IP works, especially closer to > the core. Our provider was collecting data and sending it only after > filling a buffer or after a timeout. The timeout was short so it > wouldn't normally be noticed and in most cases (web pages e.g.) the > connection is opened, data is pushed and the connection is closed so > the buffer is flushed immediately. Our patterns were different so we > were hitting the timeout on every single transaction and there was no > way we would have been able to keep up. > > Our first crack at fixing this was to simply add garbage to the packet > we were sending. Making the packets an order of magnitude bigger sped > up the proccessing dramatically. That wasn't a very clean solution > though so we looked for a better way. > > That better way turned out to asynchronous update transactions. All we > did was keep feeding updates to the remote site and forget about ACKS. > We then had a second process which handled ACKS and tracked which > packets had been properly transferred. The system had IDs on each > update and retries happened if ACKS didn't happen soon enough. > Naturally we ignored ACKS that we had already processed. > > All of the above (and much more complexity not even discussed here) was > handled by Python code and database manipulation. There were a few > bumps along the way but overall it worked fine. If we were using C or > even assembler we would not have sped up anything and the solution we > came up with would have been horrendous to code. As it was I and my > chief programmer locked ourselves in the boardroom and had a working > solution before the day was out. sure it wouldnt have sped it up a bit, even a bit?; probably the development and maintenance time would be a nightmare but it should speed the app up a bit... > > Python wins again. > > -- > D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. seriously added to the reputation of python, from my own perspective...kudos python! From nanyaks at googlemail.com Mon Mar 1 07:32:16 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 04:32:16 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> Message-ID: <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> On Feb 26, 10:32 am, mdipierro wrote: > 100,000 hits a day is not a low. I get that some day on my web server > without problem and without one request dropped. > > Most frameworks web2py, Django, Pylons can handle that kind of load > since Python is not the bottle neck. taking a look at django right now, doesnt look too bad from where im standing, maybe when i get into the code i'd run into some issues that would cause some headaches!! > You have to follow some tricks: > > 1) have the web server serve static pages directly and set the pragma > cache expire to one month > 2) cache all pages that do not have forms for at least few minutes > 3) avoid database joins but this would probably be to the detriment of my database design, which is a no-no as far as im concerned. The way the tables would be structured requires 'joins' when querying the db; or could you elaborate a little?? > 4) use a server with at least 512KB Ram. hmmm...!, still thinking about what you mean by this statement also. > 5) if you pages are large, use gzip compression > > If you develop your app with the web2py framework, you always have the > option to deploy on the Google App Engine. If you can live with their > constraints you should have no scalability problems. > > Massimo > > On Feb 25, 4:26 am, simn_stv wrote: > > > hello people, i have been reading posts on this group for quite some > > time now and many, if not all (actually not all!), seem quite > > interesting. > > i plan to build an application, a network based application that i > > estimate (and seriously hope) would get as many as 100, 000 hits a day > > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > > or anything like it, its mainly for a financial transactions which > > gets pretty busy... > > so my question is this would anyone have anything that would make > > python a little less of a serious candidate (cos it already is) and > > the options may be to use some other languages (maybe java, C (oh > > God))...i am into a bit of php and building API's in php would not be > > the hard part, what i am concerned about is scalability and > > efficiency, well, as far as the 'core' is concerned. > > > would python be able to manage giving me a solid 'core' and will i be > > able to use python provide any API i would like to implement?... > > > im sorry if my subject was not as clear as probably should be!. > > i guess this should be the best place to ask this sort of thing, hope > > im so right. > > > Thanks thanks for the feedback... From stefan_ml at behnel.de Mon Mar 1 07:46:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Mar 2010 13:46:22 +0100 Subject: Detecting new removable drives in Linux In-Reply-To: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> References: <2119ee91003010148u4954d495kd53454c27f2b54b2@mail.gmail.com> Message-ID: Bart Smeets, 01.03.2010 10:48: > I'm trying to write a script which detects when a new removable drive is > connected to the computer. On #python I was advised to use the > dbus-bindings. However the documentation on this is limited. Does anyone > know of an example of how I can detect new removable drives? You could execute a script from HAL, e.g. using halevt, and let the script communicate with your program. http://www.nongnu.org/halevt/ Stefan From wuwei23 at gmail.com Mon Mar 1 08:01:49 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 1 Mar 2010 05:01:49 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> Message-ID: <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> Andreas Waldenburger wrote: > But as I said: a) I am (we are) not in a position to impose this (We > don't work with the code, we just run the software). I personally believe that the end users have _every_ right to impose quality requirements on code used within their business...although I may not bring this up in front of them at meetings :) From usenot at geekmail.INVALID Mon Mar 1 08:09:43 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 14:09:43 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> Message-ID: <20100301140943.4edca16b@geekmail.INVALID> On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 wrote: > Andreas Waldenburger wrote: > > But as I said: a) I am (we are) not in a position to impose this (We > > don't work with the code, we just run the software). > > I personally believe that the end users have _every_ right to impose > quality requirements on code used within their business...although I > may not bring this up in front of them at meetings :) Huh? That's like demanding a certain type of truck or vehicle maintenance plan from a trucking company. Sure, you *could* do it, but that effectively only limits your options. I think there should be a clear separation of concerns here. /W -- INVALID? DE! From sayedjewel21 at gmail.com Mon Mar 1 08:26:31 2010 From: sayedjewel21 at gmail.com (sayed jewel21) Date: Mon, 1 Mar 2010 05:26:31 -0800 (PST) Subject: connect with me Message-ID: <3fc01795-acc4-4e9f-a683-a34293166899@d27g2000yqf.googlegroups.com> dear guys you can do subscribe with site easily- http://freelivestreamonlinepctv.blogspot.com/ From vinay_sajip at yahoo.co.uk Mon Mar 1 08:27:30 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 1 Mar 2010 05:27:30 -0800 (PST) Subject: ANN: A new version (0.2.4) of the Python module which wraps GnuPG has been released. Message-ID: <3188c3be-0ba5-48b6-a234-d5e41e034923@t23g2000yqt.googlegroups.com> A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is a minor enhancement release. See the project website ( http://code.google.com/p/python-gnupg/ ) for more information. The current version passes all tests on Windows (Python 2.4, 2.5, 2.6, 3.1, Jython 2.5.1) and Ubuntu (Python 2.4, 2.5, 2.6, 3.0, Jython 2.5.1). What Does It Do? ================ The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf ... -----END PGP MESSAGE-----\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' For more information, visit http://code.google.com/p/python-gnupg/ - as always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. From highcar at gmail.com Mon Mar 1 08:49:06 2010 From: highcar at gmail.com (elca) Date: Mon, 1 Mar 2010 05:49:06 -0800 (PST) Subject: python socket service related question! Message-ID: <27743609.post@talk.nabble.com> Hello,All im totally new to socket programming in python. i was read some tutorial and manual, but i didn't found what i want to make python related socket script in manual or tutorial. i want to make socket script which can send some info to server and also receive some info from server. For example, i want to send my login information to server, and want to receive result reply from server. but i have no idea..how to send my login information(id and password) to server. i was captured with wireshark, some process to send login info to server. and i was found port number is 5300 and server ip is 58.225.56.152 and i was send id is 'aaaaaaa' and password 'bbbbbbb' and i was received 'USER NOT FOUND' result from server. how can i make this kind of process with python socket ? if anyone help me some reference or some example or anything help much appreciate! 0000 00 50 56 f2 c8 cc 00 0c 29 a8 f8 c0 08 00 45 00 .PV.....).....E. 0010 00 e2 2a 19 40 00 80 06 d0 55 c0 a8 cb 85 3a e1 ..*. at ....U....:. 0020 38 98 05 f3 15 9a b9 86 62 7b 0d ab 0f ba 50 18 8.......b{....P. 0030 fa f0 26 14 00 00 50 54 3f 09 a2 91 7f 13 00 00 ..&...PT?....... 0040 00 1f 14 00 02 00 00 00 00 00 00 00 07 00 00 00 ................ 0050 61 61 61 61 61 61 61 50 54 3f 09 a2 91 7f 8b 00 aaaaaaaPT?...... 0060 00 00 1f 15 00 08 00 00 00 07 00 00 00 61 61 61 .............aaa 0070 61 61 61 61 07 00 00 00 62 62 62 62 62 62 62 01 aaaa....bbbbbbb. 0080 00 00 00 31 02 00 00 00 4b 52 0f 00 00 00 31 39 ...1....KR....19 0090 32 2e 31 36 38 2e 32 30 33 2e 31 33 33 30 00 00 2.168.203.1330.. 00a0 00 4d 69 63 72 6f 73 6f 66 74 20 57 69 6e 64 6f .Microsoft Windo 00b0 77 73 20 58 50 20 50 72 6f 66 65 73 73 69 6f 6e ws XP Profession 00c0 61 6c 20 53 65 72 76 69 63 65 20 50 61 63 6b 20 al Service Pack 00d0 32 14 00 00 00 31 30 30 31 33 30 30 35 33 31 35 2....10013005315 00e0 37 38 33 37 32 30 31 32 33 03 00 00 00 34 37 30 783720123....470 0000 00 0c 29 a8 f8 c0 00 50 56 f2 c8 cc 08 00 45 00 ..)....PV.....E. 0010 00 28 ae 37 00 00 80 06 8c f1 3a e1 38 98 c0 a8 .(.7......:.8... 0020 cb 85 15 9a 05 f3 0d ab 0f ba b9 86 63 35 50 10 ............c5P. 0030 fa f0 5f 8e 00 00 00 00 00 00 00 00 .._......... 0000 00 0c 29 a8 f8 c0 00 50 56 f2 c8 cc 08 00 45 00 ..)....PV.....E. 0010 00 4c ae 38 00 00 80 06 8c cc 3a e1 38 98 c0 a8 .L.8......:.8... 0020 cb 85 15 9a 05 f3 0d ab 0f ba b9 86 63 35 50 18 ............c5P. 0030 fa f0 3e 75 00 00 50 54 3f 09 a2 91 7f 16 00 00 ..>u..PT?....... 0040 00 1f 18 00 01 00 00 00 0e 00 00 00 55 73 65 72 ............User 0050 20 4e 6f 74 20 46 6f 75 6e 64 Not Found -- View this message in context: http://old.nabble.com/python-socket-service-related-question%21-tp27743609p27743609.html Sent from the Python - python-list mailing list archive at Nabble.com. From victorsubervi at gmail.com Mon Mar 1 09:02:56 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 1 Mar 2010 10:02:56 -0400 Subject: Permission Problem Message-ID: <4dc0cfea1003010602w755b52feu2e7f9dca710ff71@mail.gmail.com> Hi; I encountered and solved this problem before with the help of the list, but it's back, and I've reviewed and done everything I was shown to do last time, so I'm lost. Here's the script: #!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from login import login import MySQLdb import re, string import fpformat form = cgi.FieldStorage() width = form.getfirst('width') lines = ''' #!/usr/bin/python return %s''' % width f = 'width.py' try: os.remove(f) except OSError: pass f = open(f, 'w') f.writelines(lines) f.close() Simple enough. Here's the permissions: drwxrwxrwx 31 root root 4096 Feb 23 04:57 .. -rwxrwxrwx 1 root root 390 Mar 1 05:52 preload.py All loaded up deliberately to try and get it to work. Here's the error: /var/www/html/globalsolutionsgroup.vi/preload.py 21 except OSError: 22 pass 23 f = open(f, 'w') 24 f.writelines(lines) 25 f.close() f = 'width.py', builtin open = IOError: [Errno 13] Permission denied: 'width.py' args = (13, 'Permission denied') errno = 13 filename = 'width.py' strerror = 'Permission denied' What'd I do wrong? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From urbangabo at gmail.com Mon Mar 1 09:05:03 2010 From: urbangabo at gmail.com (Gabor Urban) Date: Mon, 1 Mar 2010 15:05:03 +0100 Subject: Class attributes / methods lost? Message-ID: Hi guys, I am building a nested data structure with the following compontens: <> class Item: def __init__(self, pId, pChange, pComment): self.ID = pId self.Delta = pChange self.Comment = pComment def PrintItem(self): str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) return str class Package: def __init__(self, pSerial, pDate, pOwner, pSchema): self.serial = pSerial self.date = pDate self.owner = pOwner self.schema = pSchema self.items = [] def insertItem(self, pItem): self.items.append(pItem) def printPackage(self): lines = [] str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) number = self.items.length for idx in xrange(number): line = '' istr = self.items[idx].PrintItem() line = str + ',' + istr lines.append(line) return lines <> The above structure is processed with next code: <> size = len(packages) package = None for index in xrange(size): logger.info('PrettyPrinting package id=%d',index) oplines = [] oplines = packages[index].printPackage() for i in xrange(oplines.length): data.append(oplines[i]) <> I've got the next error message: ' Traceback (most recent call last): File "XmlHistory_orig.py", line 203, in ? oplines = packages[index].printPackage() TypeError: unbound method printPackage() must be called with Package instance as first argument (got nothing instead) ' I did give a try to access the fields directly <> packages = [] data = [] size = len(packages) for index in xrange(size): str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) itemnum = len(packages[index].items) oplines = [] for itemIndx in xrange(itemnum): element = '%s,%s,%s'%(packages[index].items[itemIdx].ID,packages[index].items[itemIdx].Delta,packages[index].items[itemIdx].comment) oplines.append(str + ','+elemt) <> Error: Traceback (most recent call last): File "XmlHistory.py", line 204, in ? str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) AttributeError: class Package has no attribute 'serial' The strange in this issue for me, that I do not see why are the class methods and fields lost. Any idea is wellcome. Gabor -- Linux: Choice of a GNU Generation From __peter__ at web.de Mon Mar 1 09:24:37 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Mar 2010 15:24:37 +0100 Subject: Class attributes / methods lost? References: Message-ID: Gabor Urban wrote: > I am building a nested data structure with the following compontens: > Any idea is wellcome. The error messages suggest that you are using classes where you should be using class instances, but you don't provide the code where this problem originates. The code you do give looks like a very literal and incomplete conversion from Java. Rather than go into the details I suggest that you have a look at the Tutorial (and PEP 8) before you proceed. http://docs.python.org/tutorial/index.html http://www.python.org/dev/peps/pep-0008/ Peter From nanyaks at googlemail.com Mon Mar 1 09:42:28 2010 From: nanyaks at googlemail.com (simn_stv) Date: Mon, 1 Mar 2010 06:42:28 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> <7upi0jFuapU2@mid.uni-berlin.de> Message-ID: <7f8b1651-69fc-4ae1-8f55-840ff9f9d1dc@15g2000yqa.googlegroups.com> On Feb 26, 10:19 am, "Diez B. Roggisch" wrote: > Am 26.02.10 05:01, schrieb D'Arcy J.M. Cain: > > > > > On Fri, 26 Feb 2010 01:12:00 +0100 > > "Diez B. Roggisch" wrote: > >>> That better way turned out to asynchronous update transactions. All we > >>> did was keep feeding updates to the remote site and forget about ACKS. > >>> We then had a second process which handled ACKS and tracked which > >>> packets had been properly transferred. The system had IDs on each > >>> update and retries happened if ACKS didn't happen soon enough. > >>> Naturally we ignored ACKS that we had already processed. > > >> sounds like using UDP to me, of course with a protocol on top (namely > >> the one you implemented). > > >> Any reason you sticked to TCP instead? > > > TCP does a great job of delivering a stream of data in order and > > handling the retries. The app really was connection oriented and we > > saw no reason to emulate that over an unconnected protocol. There were > > other wheels to reinvent that were more important. > > So when you talk about ACKs, you don't mean these on the TCP-level > (darn, whatever iso-level that is...), but on some higher level? > > Diez i think its on the TCP that he's referring to or is it?... if it is, that means he's doing some 'mean' network level scripting, impressive...but i never thought python could go that deep in network programming!... From darcy at druid.net Mon Mar 1 09:43:13 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 1 Mar 2010 09:43:13 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <20100301094313.e04eab06.darcy@druid.net> On Mon, 1 Mar 2010 04:11:07 -0800 (PST) simn_stv wrote: > > All of the above (and much more complexity not even discussed here) was > > handled by Python code and database manipulation. There were a few > > bumps along the way but overall it worked fine. If we were using C or > > even assembler we would not have sped up anything and the solution we > > came up with would have been horrendous to code. As it was I and my > > chief programmer locked ourselves in the boardroom and had a working > > solution before the day was out. > > sure it wouldnt have sped it up a bit, even a bit?; probably the > development and maintenance time would be a nightmare but it should > speed the app up a bit... What do you mean by "even a bit?" The bulk of the time is in sending bits on the wire. Computer time was always negligible in this situation. Yes, I can write all of my applications in assembler to get a 0.00000000000001% increase in speed but who cares? If you have decent algorithms in place then 99% of the time I/O will be your bottleneck and if it isn't then you have a compute heavy problem that assembler isn't going to fix. And even if I get a 100% increase in speed, I still lose. Computer time is cheaper than programmer time by so many orders of magnitude that it isn't even worh factoring in the speedup. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Mon Mar 1 10:02:15 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Mon, 1 Mar 2010 10:02:15 -0500 Subject: taking python enterprise level?... In-Reply-To: <7f8b1651-69fc-4ae1-8f55-840ff9f9d1dc@15g2000yqa.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> <7upi0jFuapU2@mid.uni-berlin.de> <7f8b1651-69fc-4ae1-8f55-840ff9f9d1dc@15g2000yqa.googlegroups.com> Message-ID: <20100301100215.a9387aa4.darcy@druid.net> On Mon, 1 Mar 2010 06:42:28 -0800 (PST) simn_stv wrote: > On Feb 26, 10:19 am, "Diez B. Roggisch" wrote: > > So when you talk about ACKs, you don't mean these on the TCP-level > > (darn, whatever iso-level that is...), but on some higher level? > > i think its on the TCP that he's referring to or is it?... No, I mean in our own application layer. > if it is, that means he's doing some 'mean' network level scripting, > impressive...but i never thought python could go that deep in network > programming!... What I meant was that we just keep sending packets which TCP/IP keeps in order for us by reassembling out-of-order and retransmitted packets. Asynchronously we sent back to our own application an ACK that our app level packet was finally received. It's a sliding window protocol. http://en.wikipedia.org/wiki/Sliding_Window_Protocol -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From victorsubervi at gmail.com Mon Mar 1 10:07:52 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Mon, 1 Mar 2010 11:07:52 -0400 Subject: Permission Problem In-Reply-To: <4dc0cfea1003010602w755b52feu2e7f9dca710ff71@mail.gmail.com> References: <4dc0cfea1003010602w755b52feu2e7f9dca710ff71@mail.gmail.com> Message-ID: <4dc0cfea1003010707j872922ckd30d62173e831c6e@mail.gmail.com> Never mind. I figured out my error. beno On Mon, Mar 1, 2010 at 10:02 AM, Victor Subervi wrote: > Hi; > I encountered and solved this problem before with the help of the list, but > it's back, and I've reviewed and done everything I was shown to do last > time, so I'm lost. Here's the script: > > #!/usr/bin/python > > import cgitb; cgitb.enable() > import cgi > import sys,os > sys.path.append(os.getcwd()) > from login import login > import MySQLdb > import re, string > import fpformat > > form = cgi.FieldStorage() > width = form.getfirst('width') > lines = ''' > #!/usr/bin/python > > return %s''' % width > f = 'width.py' > try: > os.remove(f) > except OSError: > pass > f = open(f, 'w') > f.writelines(lines) > f.close() > > Simple enough. Here's the permissions: > > drwxrwxrwx 31 root root 4096 Feb 23 04:57 .. > -rwxrwxrwx 1 root root 390 Mar 1 05:52 preload.py > > All loaded up deliberately to try and get it to work. Here's the error: > > /var/www/html/globalsolutionsgroup.vi/preload.py > 21 except OSError: > 22 pass > 23 f = open(f, 'w') > 24 f.writelines(lines) > 25 f.close() > f = 'width.py', builtin open = > IOError: [Errno 13] Permission denied: 'width.py' > args = (13, 'Permission denied') > errno = 13 > filename = 'width.py' > strerror = 'Permission denied' > > What'd I do wrong? > TIA, > beno > > -- > The Logos has come to bear > http://logos.13gems.com/ > -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 1 10:09:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Mar 2010 16:09:22 +0100 Subject: Class attributes / methods lost? In-Reply-To: References: Message-ID: <4B8BD8A2.40800@sequans.com> Gabor Urban wrote: > Hi guys, > > I am building a nested data structure with the following compontens: > > <> > > class Item: > def __init__(self, pId, pChange, pComment): > self.ID = pId > self.Delta = pChange > self.Comment = pComment > > def PrintItem(self): > str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) > return str > > class Package: > def __init__(self, pSerial, pDate, pOwner, pSchema): > self.serial = pSerial > self.date = pDate > self.owner = pOwner > self.schema = pSchema > self.items = [] > > def insertItem(self, pItem): > self.items.append(pItem) > > def printPackage(self): > lines = [] > str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) > number = self.items.length > for idx in xrange(number): > line = '' > istr = self.items[idx].PrintItem() > line = str + ',' + istr > lines.append(line) > return lines > > <> > > The above structure is processed with next code: > > <> > > size = len(packages) > package = None > for index in xrange(size): > logger.info('PrettyPrinting package id=%d',index) > oplines = [] > oplines = packages[index].printPackage() > for i in xrange(oplines.length): > data.append(oplines[i]) > <> > > I've got the next error message: > ' Traceback (most recent call last): > File "XmlHistory_orig.py", line 203, in ? > oplines = packages[index].printPackage() > TypeError: unbound method printPackage() must be called with Package > instance as first argument (got nothing instead) ' > > I did give a try to access the fields directly > > <> > packages = [] > data = [] > > size = len(packages) > for index in xrange(size): > str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) > itemnum = len(packages[index].items) > oplines = [] > for itemIndx in xrange(itemnum): > element = > '%s,%s,%s'%(packages[index].items[itemIdx].ID,packages[index].items[itemIdx].Delta,packages[index].items[itemIdx].comment) > oplines.append(str + ','+elemt) > > <> > > Error: > > Traceback (most recent call last): > File "XmlHistory.py", line 204, in ? > str = '%s,%s,%s,%s'%(packages[index].serial,packages[index].date,packages[index].owner,packages[index].schema) > AttributeError: class Package has no attribute 'serial' > > The strange in this issue for me, that I do not see why are the class > methods and fields lost. > > Any idea is wellcome. > > Gabor > Ok here are some suggestions : 1/ do not name a method PrintItem if the method does not print anything (it does not) 2/ use the __str__ method to return a nice representation of your objects 3/ use pythonic iteration controls 4/ be consistant with your naming convention, your Item's attributes start with an Uppercase letter, Package's attributes with a lowercase one. (I suggest the lowercase) class Item(object): def __init__(self, pId, pChange, pComment): self.id = pId self.delta = pChange self.comment = pComment def __str__(self): return self.__class__.__name__ + ':' + str(self.__dict__) class Package(object): def __init__(self, pSerial, pDate, pOwner, pSchema): self.serial = pSerial self.date = pDate self.owner = pOwner self.schema = pSchema self.items = [] def insertItem(self, pItem): self.items.append(pItem) def __str__(self): _dict = self.__dict__.copy() _dict['items'] = [str(item) for item in self.items] return self.__class__.__name__ + ':' + str(_dict) i1 = Item('a', 'b', 'c') i2 = Item('foo', 'bar', 'baz') p = Package(1,2,3,4) p.insertItem(i1) p.insertItem(i2) packages = [p] for package in packages: print package >>> Package:{'date': 2, 'owner': 3, 'serial': 1, 'schema': 4, 'items': ["Item:{'comment': 'c', 'id': 'a', 'delta': 'b'}", "Item:{'comment': 'baz', 'id': 'foo', 'delta': 'bar'}"]} Regarding the error you get, it seems you've stored the class itself, instead instances. The error should be in the way you've built the package list, but you did not provide the code. JM From python at mrabarnett.plus.com Mon Mar 1 10:17:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Mar 2010 15:17:14 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4B8B9845.70604@sequans.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> Message-ID: <4B8BDA7A.3060600@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > MRAB wrote: >> Gregory Ewing wrote: >>> Mel wrote: >>> >>>> You could think of it as a not bad use of the design principle >>>> "Clear The Simple Stuff Out Of The Way First". Destinations are >>>> commonly a lot simpler than sources >>> >>> That's not usually true in assembly languages, though, >>> where the source and destination are both very restricted >>> and often about the same complexity. >>> >>> That's not to say that right-to-left is the wrong way >>> to do it in an assembly language, but there are less >>> misleading words than "move" that could be used. >>> >>> Z80 assembly language uses "load", which makes things >>> considerably clearer: >>> >>> LD A, B ; load A with B >>> >> Some processors distinguish between "load" (memory to register) and >> "store" (register to memory), and the destination and LHS operand of >> binary operations might be the same register, for example: >> >> CLC ; clear the carry >> LDA first ; accumulator := byte at first >> ADCA second ; accumulator := accumulator + byte at second + carry >> STA result ; byte at third := accumulator >> > Guys, you sound like people arguing about old school TV show / series > like star treck :-) > - "He was wearing a blue suit !" > - "Check episode number 29, he appeared with a pink one!" > > I'm glad I'm too young to had to code in assembler, or to bear the > vision of those unlikely space suits from the 70's ;-) > Ah, yes, Star Trek (the original series). If they transported down to a planet and there was a man in a red shirt who you'd never seen before, he'd be the one to die! :-) BTW, the first programming I did was in hexadecimal (C4xx was "LDI xx"). From greg.lindstrom at novasyshealth.com Mon Mar 1 10:19:57 2010 From: greg.lindstrom at novasyshealth.com (Greg Lindstrom) Date: Mon, 01 Mar 2010 09:19:57 -0600 Subject: Looking for an Application Message-ID: <4B8BDB1D.2050309@novasyshealth.com> A few months ago there was a post dealing with an application that would power scripts based on graphical snippets of the screen. Essentially, the script would "look" for a match with what you pasted into it. I don't recall the name of the application, but would like to try it. Does anyone remember what it is? Thanks, --greg From arjun.chennu at gmail.com Mon Mar 1 10:35:38 2010 From: arjun.chennu at gmail.com (Arjun Chennu) Date: Mon, 1 Mar 2010 16:35:38 +0100 Subject: How to end TCP socket data while using readline()? In-Reply-To: <20100227041115.GA24869@cskk.homeip.net> References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> <20100227041115.GA24869@cskk.homeip.net> Message-ID: Thanks for the feedback. Opening a separate file-obj for writing and for reading is just what I've been trying, but I don't seem to get it to work. I'm new to python and I'm not sure if I'm missing the intricacy of some command. Please help: Here is my server snippet: (conn, addr) = sock1.accept() # connected socket print 'Client (localhost) port: ', addr[1] cf = conn.makefile('r',0) # file obj for reading lf = open('ccs.txt','w') for linenum, line in enumerate(cf): # iterate over socket lines lf.write(line) #sys.stdout.write(line) print len(line) cf.close() stat = 'wrote %s lines to file.\n' %(linenum+1) cff = conn.makefile('w',0) # file obj for writing cff.writelines(stat) # cff.write(stat) does not work either!! cff.close() lf.close() conn.close() print stat, "DONE!" And here is the client that I have for it: (sfp is the local file object i read from) for line in sfp.readlines(): cf.write(line) print len(line) print 'done sending' cf.close() #writing ends here cff = s.makefile('r',0) # file obj for writing for line in cff.readlines(): print line cff.close() sfp.close() s.close() The execution sends all the lines (and prints out the len(line) ) and then stays waiting. THen when I manually terminate the client script, the server script happily types the "DONE!" output. Where is this protocol hanging up? Help much appreciated, with a small explanation. Cheers, Arjun On Sat, Feb 27, 2010 at 05:11, Cameron Simpson wrote: > On 26Feb2010 10:39, Arjun wrote: > | Hi, I have a small script that runs a TCP server. A client connects to > | this server and transmits a stored file line-by-line, and then waits > | for a confirmation "done". However, when I run them the first loop > | never really ends -- as the TCP server keeps expecting more data. I am > | using a file-like-object, and so somehow I have to communicate to the > | server that it is the end-of-file. > | > | here is some server code > | > | sock1.bind(('', port)) > | print "Listening at port: ", port > | sock1.listen(1) # listening socket > | (conn, addr) = sock1.accept() # connected socket > | print 'Client (localhost) port: ', addr[1] > | > | cf = conn.makefile('r',0) # file like obj for socket > [...] > | print 'close' > | cf.flush() > | cf.close() > | sfp.close() > [...] > > Too many files. It's not that hard! Or shouldn't be. > > | So what I am wondering is: > | > | 1. Using a file-like object means that the socket becomes uni- > | directional, until the mode of the file object is changed from 'r' to > | 'w' (or vice versa). This seems inefficient, and rather unPythonesque. > | Can somebody tell me if there is a more elegant way of receiving all > | the lines from the client, and then sending a "done" message to the > | client? > > Get the socket. It is a file descriptor (or in may be a python "socket" > object with a file descriptor inside). > > Open _two_ "file" objects on it using > from_file = os.fdopen(fd_of_socket, "r") > to_file = os.fdopen(fd_of_socket, "w"). > > Use the same: > print >>to_file, 'close' > to_file.flush() > method as you're using already. > Read from to_file as needed. > > The same scheme should work in both server and client: > > Don't look for EOF, watch the input line flow. > > You might need to use readline() instead of the file-by-line iteration > stuff, > which I seem to recall has some sort of problem handing out the "latest" > line. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > It's better, when you're riding with someone you don't know so well, to > stick > to the inside line - it's easier to avoid the bits... > - Barry Sheene > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arjun.chennu at gmail.com Mon Mar 1 10:53:10 2010 From: arjun.chennu at gmail.com (Arjun Chennu) Date: Mon, 1 Mar 2010 16:53:10 +0100 Subject: How to end TCP socket data while using readline()? In-Reply-To: References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> <20100227041115.GA24869@cskk.homeip.net> Message-ID: It DOES seem like only when the connection socket is closed via conn.close() that the data is flushed and the 'waiting' ends. So with the earlier suggestion that I open one file-obj for reading and one for writing, I still cannot acheive two-way communication because I need to close the connection for it to actually occur completely! My client waits after the "done sending" line indefinitely. Weird. A On Mon, Mar 1, 2010 at 16:35, Arjun Chennu wrote: > Thanks for the feedback. > > Opening a separate file-obj for writing and for reading is just what I've > been trying, but I don't seem to get it to work. I'm new to python and I'm > not sure if I'm missing the intricacy of some command. Please help: > > Here is my server snippet: > > > (conn, addr) = sock1.accept() # connected socket > print 'Client (localhost) port: ', addr[1] > > cf = conn.makefile('r',0) # file obj for reading > > lf = open('ccs.txt','w') > > for linenum, line in enumerate(cf): # iterate over socket > lines > lf.write(line) > #sys.stdout.write(line) > print len(line) > > cf.close() > > stat = 'wrote %s lines to file.\n' %(linenum+1) > cff = conn.makefile('w',0) # file obj for writing > cff.writelines(stat) # cff.write(stat) does not work > either!! > cff.close() > > lf.close() > conn.close() > print stat, "DONE!" > > And here is the client that I have for it: (sfp is the local file object i > read from) > > > for line in sfp.readlines(): > cf.write(line) > print len(line) > > print 'done sending' > cf.close() #writing ends here > > cff = s.makefile('r',0) # file obj for writing > for line in cff.readlines(): > print line > > cff.close() > > sfp.close() > s.close() > > The execution sends all the lines (and prints out the len(line) ) and then > stays waiting. THen when I manually terminate the client script, the server > script happily types the "DONE!" output. > > Where is this protocol hanging up? Help much appreciated, with a small > explanation. > > Cheers, > Arjun > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Mon Mar 1 11:08:35 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 08:08:35 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: Message-ID: On Feb 28, 9:18?pm, Steven D'Aprano > Wait a minute... if JSON is too hard to edit, and RSON is a *superset* of > JSON, that means by definition every JSON file is also a valid RSON file. > Since JSON is too hard to manually edit, so is RSON. Well, Python is essentially a superset of JSON, with string escape handling being ever so slightly different, and using True instead of true, False instead of false, and None instead of null. YMMV, but I find it possible, even probable, to write Python that is far easier to edit than JSON, and in fact, I have used Python for configuration files that are only to be edited by programmers or other technical types. > Come back when you actually have MANY users other than yourself using > this is real-world projects. Until then, it is too early to even consider > adding it the std library. Python comes with batteries included, but not > experimental batteries that aren't even built yet, let alone proven that > they work. I know that it is too early to be included in the library. But there is a chicken-and-egg problem. PEP 1 says you should circulate a design for discussion before writing code... I fully expect this sort of negative feedback, fully expect that it will be years (if ever) before the code makes it into the standard library, and yet I offer the design for your perusal, just on the slim chance that I might get a few constructive criticisms on the actual design to go along with all the silly strawmen reductio ad absurdum arguments by people who aren't even going to bother to read the thing. Best regards, Pat From qtrimble at gmail.com Mon Mar 1 11:15:19 2010 From: qtrimble at gmail.com (qtrimble) Date: Mon, 1 Mar 2010 08:15:19 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> <121bb934-6d62-482a-a5c2-848668ce237d@q16g2000yqq.googlegroups.com> Message-ID: On Feb 26, 6:19?pm, ru... at yahoo.com wrote: > On Feb 26, 2:21?pm, qtrimble wrote: > > > > > On Feb 26, 4:14?pm, OdarR wrote: > > > > > > below is just a sample. ?There are well over 500,000 lines that need > > > > processed. > > > > > wer1999001 > > > > ? ? ? 31.2234 ? ? ?82.2367 > > > > ? ? ? 37.9535 ? ? ?82.3456 > > > > wer1999002 > > > > ? ? ? 31.2234 ? ? ?82.2367 > > > > ? ? ? 37.9535 ? ? ?82.3456 > > > > did you try something as a working basis ? > > > > Olivier > > > Yes but it's very simple - > > > fileIN = open(r"C:\testing.txt", "r") > > > for line in fileIN: > > ? ? year = line[3:7] > > ? ? day = line[7:10] > > ? ? print year, day > > > This is good since i can get the year and day of year into a variable > > but I haven't gotten any further. > > How about something like (untested): > > ? for line in fileIN: > ? ? ? ?if line.startswith ("wer"): > ? ? ? ? ? ?year = line[3:7] > ? ? ? ? ? ?day = line[7:10] > ? ? ? ? else: > ? ? ? ? ? ?print "%s-%s %s" % (year, day, line.strip()) > > You can adjust the details as needed... Thanks to all of you for your suggestions. This is what I have now. It may not be the most efficient or well written script but it works! Thanks again! fileIN = open(r"C:\z_paul\ims1999.txt", "r") for line in fileIN: if line.startswith("ims"): year = line[3:7] day = line[7:10] newfile = file(r"C:\z_paul\output\ims" + year + day + ".txt", "wt") newfile.write("YEAR,DOY,Y_COORD,X_COORD,TYPE\n") else: temp = line.replace(' ',',') temp2 = temp.replace(', ',',') newfile.write(year + "," + day + temp2) newfile.close() From lie.1296 at gmail.com Mon Mar 1 11:18:30 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 02 Mar 2010 03:18:30 +1100 Subject: Docstrings considered too complicated In-Reply-To: <20100301140943.4edca16b@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> Message-ID: <4b8be8f7$1@dnews.tpgi.com.au> On 03/02/10 00:09, Andreas Waldenburger wrote: > On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 > wrote: > >> Andreas Waldenburger wrote: >>> But as I said: a) I am (we are) not in a position to impose this (We >>> don't work with the code, we just run the software). >> >> I personally believe that the end users have _every_ right to impose >> quality requirements on code used within their business...although I >> may not bring this up in front of them at meetings :) > > Huh? That's like demanding a certain type of truck or vehicle > maintenance plan from a trucking company. Sure, you *could* do it, but > that effectively only limits your options. I think there should be a > clear separation of concerns here. If my truck contains food items that spoils quickly, I would want to make sure that the trucking company takes good care of their refrigeration system and that the truck have as little chance as possible for breakdown due to poor maintenance. From tibor.beck at hotmail.com Mon Mar 1 11:22:27 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Mon, 1 Mar 2010 08:22:27 -0800 (PST) Subject: AOP decorator? Message-ID: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> Hi, suppose my source code looks like: -------------------------------- import aspect_xy class Basic(object, aspect_xy.Basic): pass # basic attributes and methods ... -------------------------------- and the source code of aspect_xy.py is: -------------------------------- class Basic(object): pass # aspect extra attributes and methods ... -------------------------------- how can I write this with decorators? I want something like: ------------------------------- import aspect_xy @aspect_xy # extra attributes and methods ... class Basic(object): pass # basic attributes and methods ... ---------------------------------------------------------- I want to write class decorator function, which: 1. Takes the basic class as parameter 2. Find the same class name in aspect_xy.py 3. Inherit the found aspect class Is it possible? From pmaupin at gmail.com Mon Mar 1 11:27:34 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 08:27:34 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Message-ID: <445e1928-b312-4082-8987-494ad2641e5d@y17g2000yqd.googlegroups.com> On Mar 1, 12:39?am, John Nagle wrote: > Patrick Maupin wrote: > > All: > > > Finding .ini configuration files too limiting, JSON and XML to hard to > > manually edit, and YAML too complex to parse quickly, I have started > > work on a new configuration file parser. > > ? ? You're not supposed to edit those formats manually. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Opinions on that will vary, and as the saying goes, "everybody is entitled to his own opinions, but not his own facts." I submit as fact that there are many initialization files in each of these formats, and I would be willing to place a wager that the majority of the people on this list have used a text editor to modify at least one file in this category at least once. IOW, in my opinion (and it is only an opinion, not a fact), you are actually helping to make the case that a better format is needed. Regards, Pat From anand.shashwat at gmail.com Mon Mar 1 11:59:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 1 Mar 2010 22:29:52 +0530 Subject: Looking for an Application In-Reply-To: <4B8BDB1D.2050309@novasyshealth.com> References: <4B8BDB1D.2050309@novasyshealth.com> Message-ID: project sikuli : http://groups.csail.mit.edu/uid/sikuli/ On Mon, Mar 1, 2010 at 8:49 PM, Greg Lindstrom < greg.lindstrom at novasyshealth.com> wrote: > A few months ago there was a post dealing with an application that would > power scripts based on graphical snippets of the screen. Essentially, the > script would "look" for a match with what you pasted into it. I don't > recall the name of the application, but would like to try it. Does anyone > remember what it is? > > Thanks, > --greg > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From noamraph at gmail.com Mon Mar 1 12:07:15 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Mon, 1 Mar 2010 09:07:15 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> Message-ID: This is most probably a bug discovered in DreamPie 1.0 (See https://bugs.launchpad.net/dreampie/+bug/525652 ) Can you try to download DreamPie 1.0.1, and if it still happens, report a bug? Thanks! Noam From noamraph at gmail.com Mon Mar 1 12:08:28 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Mon, 1 Mar 2010 09:08:28 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: Can you try DreamPie 1.0.1 and say if it still happens? There's a bug report system at launchpad.net/dreampie. Thanks, Noam From robert.kern at gmail.com Mon Mar 1 12:13:37 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Mar 2010 11:13:37 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: On 2010-03-01 10:08 , Patrick Maupin wrote: > On Feb 28, 9:18 pm, Steven D'Aprano >> Come back when you actually have MANY users other than yourself using >> this is real-world projects. Until then, it is too early to even consider >> adding it the std library. Python comes with batteries included, but not >> experimental batteries that aren't even built yet, let alone proven that >> they work. > > I know that it is too early to be included in the library. But there > is a chicken-and-egg problem. PEP 1 says you should circulate a > design for discussion before writing code... Ignore it. That comment really doesn't apply to this case. That's for things that only make sense in the language or standard library, like context managers. For libraries like this, Steven's summary is correct. It needs to have a useful life as a third party package for a few years before you should propose it for inclusion into the standard library. By all means, distribute a design document for comment before you implement things; it's a reasonable practice. But don't bother with a PEP yet. -- 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 From arnodel at googlemail.com Mon Mar 1 12:15:23 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 01 Mar 2010 17:15:23 +0000 Subject: Looking for an Application References: Message-ID: Greg Lindstrom writes: > A few months ago there was a post dealing with an application that > would power scripts based on graphical snippets of the screen. > Essentially, the script would "look" for a match with what you pasted > into it. I don't recall the name of the application, but would like > to try it. Does anyone remember what it is? > > Thanks, > --greg Project SIKULI? http://groups.csail.mit.edu/uid/sikuli/ -- Arnaud From rantingrick at gmail.com Mon Mar 1 12:18:12 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 1 Mar 2010 09:18:12 -0800 (PST) Subject: Sample code usable Tkinter listbox References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> <0f801cb4-20fc-4955-bdf6-ec7a2bc5cecb@g19g2000yqe.googlegroups.com> Message-ID: On Mar 1, 6:19?am, "Alf P. Steinbach" wrote: > > ? ? ? ? kw.setdefault('activestyle', 'none') > > Hm, let me steal this line... Thanks! Yes! the default activestyle is quite annoying! From mmitchell at transparent.com Mon Mar 1 12:20:30 2010 From: mmitchell at transparent.com (Matt Mitchell) Date: Mon, 1 Mar 2010 12:20:30 -0500 Subject: Is there a better way to do this? Message-ID: Hi, I wrote a python script that uses pysvn to export projects from an svn repo I have. The repo has hundreds of projects in it with a directory structure that is pretty uniform however it's not exactly uniform because of the capitalization. I.e.: \root \project English \Stuff \Stuff 2 \Project Spanish \Stuff 3 \Stuff 4 My svn repo is case sensitive so if I try to get \root\project Spanish\Stuff 3 I get an error. Fixing the capitalization is not an option for me. My initial idea was to make a list of all the different ways "project" has been capitalized in my repo and try each one. The code looks like this: import pysvn def getstuff(stuffiwant, languageiwantitin): projects = ("project %s/", "Project %s/", "pRojects %s/") c = pysvn.Client() for p in projects: exportme = p % languageiwantitin exportme = "http://localhost/" + exportme + stuffiwant try: c.export(exportme, "C:\\temp\\") break except pysvn.ClientError: print "Not the right capitalization." # do the rest of the stuff I need to do. This works, but to me it seems like there has to be a better way of doing it. Any feedback or suggestions would be appreciated. Thanks, Matt From usenot at geekmail.INVALID Mon Mar 1 12:22:55 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 18:22:55 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> Message-ID: <20100301182255.3de59bc6@geekmail.INVALID> On Tue, 02 Mar 2010 03:18:30 +1100 Lie Ryan wrote: > On 03/02/10 00:09, Andreas Waldenburger wrote: > > On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 > > wrote: > > > >> Andreas Waldenburger wrote: > >>> But as I said: a) I am (we are) not in a position to impose this > >>> (We don't work with the code, we just run the software). > >> > >> I personally believe that the end users have _every_ right to > >> impose quality requirements on code used within their > >> business...although I may not bring this up in front of them at > >> meetings :) > > > > Huh? That's like demanding a certain type of truck or vehicle > > maintenance plan from a trucking company. Sure, you *could* do it, > > but that effectively only limits your options. I think there should > > be a clear separation of concerns here. > > If my truck contains food items that spoils quickly, I would want to > make sure that the trucking company takes good care of their > refrigeration system and that the truck have as little chance as > possible for breakdown due to poor maintenance. My point was that it should not be any of your concern *how* they do it, only *that* they do it. Back in the software world: Those guys write code that works. It does what it's supposed to do. Why should we care where they put their comments? -- INVALID? DE! From pmaupin at gmail.com Mon Mar 1 12:34:47 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 09:34:47 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: Message-ID: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> On Mar 1, 11:13?am, Robert Kern wrote: > Ignore it. That comment really doesn't apply to this case. That's for things > that only make sense in the language or standard library, like context managers. > For libraries like this, Steven's summary is correct. It needs to have a useful > life as a third party package for a few years before you should propose it for > inclusion into the standard library. By all means, distribute a design document > for comment before you implement things; it's a reasonable practice. But don't > bother with a PEP yet. So, I went and re-read PEP 1, and in the fine print it directs me to PEP 2. Mea culpa -- I though I understood the PEP. Nonetheless, the fact that I created what I call a "PEP draft" seems to have had more read into it than I meant. I will bear this in mind when I start future projects. I have a couple of projects, and contribute to another, which in no way should wind up in the standard library. But I find the lack of a good, up-to-date, configuration reader in the library to be an issue, which is why I had the temerity to try to start a discussion on what a good standard configuration file reader should be. Yes, I would like to create something compelling enough to go into the standard library. No, I don't expect it to wind up there for a very long time, if ever. BUT, at the same time, following the PEP format is very valuable for my project. It forces me to think more deeply about the problem I am solving and it forces me to write down some documentation. Really, it's no more burdensome than any other similar useful template. Or, to put it another way, it is my goal (which I may or may not be smart enough to reach) to write a module that anybody would want to use; that is good enough to put into the standard library. Whether this happens or not, one useful tool to help the module down that path (and produce a better module for me and other users even if it never becomes part of the standard library) is to think about what it takes to get into the standard library. Part of this involves writing the PEP. Writing a PEP is a good exercise; the format itself helps me to focus on important issues. So I was writing the contents of the PEP anyway, just for me. The real question, then, is when to release the PEP (vs. the code). I've already got some coding done, but it is not yet good enough to share, and if there is anybody else out there grappling with the same issues at this time, I would prefer not to go into production with it until they have had a chance to look over the design and offer insights and criticisms. Best regards, Pat From robert.kern at gmail.com Mon Mar 1 12:42:16 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Mar 2010 11:42:16 -0600 Subject: Docstrings considered too complicated In-Reply-To: <20100301182255.3de59bc6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: On 2010-03-01 11:22 , Andreas Waldenburger wrote: > Back in the software world: Those guys write code that works. It does > what it's supposed to do. Why should we care where they put their > comments? Software usually needs to be maintained and extended over the course of its lifetime. The original team that wrote it may not be available in the future. Furthermore, docstrings are not comments. They become part of the function object and can be introspected at runtime. This is a very important tool when working with code at the interactive prompt and for the collection of API documentation. Comments are less useful than docstrings; the OP's complaint was that his programmers were putting the function documentation in other places than docstrings, rendering them less useful than they could have been. -- 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 From jeanmichel at sequans.com Mon Mar 1 12:42:17 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Mar 2010 18:42:17 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100301182255.3de59bc6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: <4B8BFC79.10103@sequans.com> Andreas Waldenburger wrote: > On Tue, 02 Mar 2010 03:18:30 +1100 Lie Ryan wrote: > > >> On 03/02/10 00:09, Andreas Waldenburger wrote: >> >>> On Mon, 1 Mar 2010 05:01:49 -0800 (PST) alex23 >>> wrote: >>> >>> >>>> Andreas Waldenburger wrote: >>>> >>>>> But as I said: a) I am (we are) not in a position to impose this >>>>> (We don't work with the code, we just run the software). >>>>> >>>> I personally believe that the end users have _every_ right to >>>> impose quality requirements on code used within their >>>> business...although I may not bring this up in front of them at >>>> meetings :) >>>> >>> Huh? That's like demanding a certain type of truck or vehicle >>> maintenance plan from a trucking company. Sure, you *could* do it, >>> but that effectively only limits your options. I think there should >>> be a clear separation of concerns here. >>> >> If my truck contains food items that spoils quickly, I would want to >> make sure that the trucking company takes good care of their >> refrigeration system and that the truck have as little chance as >> possible for breakdown due to poor maintenance. >> > > My point was that it should not be any of your concern *how* they do > it, only *that* they do it. > > Back in the software world: Those guys write code that works. It does > what it's supposed to do. Why should we care where they put their > comments? > > If you've bought the code and want to maintain it, you'd better make sure it's possible. By the way, the ISO 9001 standard ask for your out sourced processing to be compliant with your QA objectives, so if you care about your code, then you should care for the code you buy. JM From R.Brodie at rl.ac.uk Mon Mar 1 12:47:59 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 1 Mar 2010 17:47:59 -0000 Subject: Is there a better way to do this? References: Message-ID: "Matt Mitchell" wrote in message news:mailman.65.1267464765.23598.python-list at python.org... > My initial idea was to make a list of all the different > ways "project" has been capitalized in my repo and try each one. The > code looks like this: I would use pysvn.Client.list to get a list of files at whatever directory level you require. Then you can do a case insensitive compare or whatever else. From wolftracks at invalid.com Mon Mar 1 12:49:58 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 01 Mar 2010 09:49:58 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 In-Reply-To: References: Message-ID: On 2/23/2010 6:04 PM, Aahz wrote: > In article, > W. eWatson wrote: >> >> My claim is that if one creates a program in a folder that reads a file >> in the folder it and then copies it to another folder, it will read the >> data file in the first folder, and not a changed file in the new folder. >> I'd appreciate it if some w7 users could try this, and let me know what >> they find. >> >> My experience is that if one checks the properties of the copied file, >> it will point to the original py file and execute it and not the copy. > > I've no time to verify your specific claim and have no readily available > proof for mine, but I've seen similar issues on Win7. AFAIK, this has > nothing to do with Python. I've been away for several days and have no idea if anyone above figured this out. Likely not,since your post is at the end. Interesting about 'similar'. I'm pretty much done exploring every nook and cranny on this problem. It can be worked around. I will say that if I look at the properties of the copied file, it shows a shortcut tab that leads back to the original file. I have no recollection of making a shortcut, and always use Copy and Paste. Further, if I do create shortcut in W7, it adds "-shortcut to the file suffix. I do not ever recall seeing that anywhere. I just tried it in XP, and it puts it in front of the name. From joaopcf at gmail.com Mon Mar 1 12:54:20 2010 From: joaopcf at gmail.com (=?ISO-8859-1?Q?Jo=E3o?=) Date: Mon, 1 Mar 2010 09:54:20 -0800 (PST) Subject: [newbie] - python list into a sql query Message-ID: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> Hi. Can someone guide me into getting this to work? It's just really querying a DB of an Autodiscovery tool to have a bunch of updated dns files. (Thought I'm still building the first script steps) I was able to successfully query the DB against a single groupid, but am failing in passing a list of integers into the sql query. I'm failing miserably in, sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ( select hostid from hosts_groups WHERE groupid IN (' + ','.join(map(str, %s)) + ')''' % grp_range with _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1") I'll gladly accept any other code change suggestion #!/usr/bin/env python import MySQLdb import sys, os import code builder_path = '/opt/scripts/dns_builder' grp_range = range(10,15) try: db = MySQLdb.connect(host="localhost", user="tst",passwd="tst",db="tst_db" ) except MySQLdb.Error, e: print "Error %d: %s" % (e.args[0], e.args[1]) cursor = db.cursor() sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ( select hostid from hosts_groups WHERE groupid IN (' + ','.join(map(str, %s)) + ')''' % grp_range cursor.execute(sql) f = open('%s/dns_unknown_list.txt', 'w+') % builder_path data = cursor.fetchall() for row in data: ip = row[0] host = row[1] dns = row[2] if host == dns: #tmn if ip[0][:10] in ('140.254.30','10.13.74.') group1_file = open('%s/group1.zone', 'w') % builder_path print >>group1_file, '''$ORIGIN group1 ''' print >>group1_file, '%s IN A %s' % (dns, ip) elif ip[0][:3] in ('8.128.46.','6.128.101') group2_file = open('%s/group2.zone', 'w') % builder_path print >>group2_file, '''$ORIGIN group2 ''' print >>group2_file, '%s IN A %s' % (dns, ip) else: print >>f, 'unknown IN A %s' % ip db.close() input_file.close() f.close() From no.email at nospam.invalid Mon Mar 1 13:03:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 10:03:33 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> Message-ID: <7xljebyl56.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > it is my goal (which I may or may not be smart enough to reach) to > write a module that anybody would want to use; But you are working on a solution in search of a problem. The really smart thing to do would be pick something more useful to work on. We don't need another configuration language. I can't even say "yet another" because there's already a "yet another" called yaml. From robert.kern at gmail.com Mon Mar 1 13:05:06 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Mar 2010 12:05:06 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> Message-ID: On 2010-03-01 11:34 , Patrick Maupin wrote: > On Mar 1, 11:13 am, Robert Kern wrote: >> Ignore it. That comment really doesn't apply to this case. That's for things >> that only make sense in the language or standard library, like context managers. >> For libraries like this, Steven's summary is correct. It needs to have a useful >> life as a third party package for a few years before you should propose it for >> inclusion into the standard library. By all means, distribute a design document >> for comment before you implement things; it's a reasonable practice. But don't >> bother with a PEP yet. > > So, I went and re-read PEP 1, and in the fine print it directs me to > PEP 2. Mea culpa -- I though I understood the PEP. > > Nonetheless, the fact that I created what I call a "PEP draft" seems > to have had more read into it than I meant. I will bear this in mind > when I start future projects. I have a couple of projects, and > contribute to another, which in no way should wind up in the standard > library. But I find the lack of a good, up-to-date, configuration > reader in the library to be an issue, which is why I had the temerity > to try to start a discussion on what a good standard configuration > file reader should be. > > Yes, I would like to create something compelling enough to go into the > standard library. No, I don't expect it to wind up there for a very > long time, if ever. BUT, at the same time, following the PEP format > is very valuable for my project. It forces me to think more deeply > about the problem I am solving and it forces me to write down some > documentation. Really, it's no more burdensome than any other similar > useful template. Certainly. The PEP format is a useful one. I've used it myself for some numpy design documents. But can you see why people might get confused about your intentions when you call it a draft PEP and post it to python-dev? If you stop calling it a PEP and stop talking about putting it in the standard library, people will stop being distracted by those issues. -- 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 From maygeo at netplus.ch Mon Mar 1 13:07:17 2010 From: maygeo at netplus.ch (Raphael Mayoraz) Date: Mon, 01 Mar 2010 10:07:17 -0800 Subject: Variable definition In-Reply-To: <4B887224.2080805@optimum.net> References: <4B885A0B.9040705@netplus.ch> <4B887224.2080805@optimum.net> Message-ID: <4B8C0255.3090509@netplus.ch> John Posner wrote: > On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >> Hello, >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >> for key, value in varDic.iteritems(): >> 'myPrefix' + key = value >> > > No trick, just swap a new key-value pair for each existing pair: > > for key, value in varDic.iteritems(): > varDic[myPrefix + key] = value > del varDict[key] > > Just make sure that *myPrefix* isn't an empty string! > > -John Thanks for your answer. However, your solution changes the key name in the dictionary. That's not what I want I need to do. What I want is to define a new variable which name is define as a string: 'myPrefx' + key. In the example I give, I would get 3 variables: myPrefixred = a myPrefixgreen = b myPrefixblue = c Raphael From fetchinson at googlemail.com Mon Mar 1 13:40:00 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Mar 2010 19:40:00 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7xljebyl56.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: >> it is my goal (which I may or may not be smart enough to reach) to >> write a module that anybody would want to use; > > But you are working on a solution in search of a problem. The really > smart thing to do would be pick something more useful to work on. We > don't need another configuration language. I can't even say "yet > another" because there's already a "yet another" called yaml. And in case you are new here let me assure you that Paul is saying this with his full intention of being helpful to you. I also would think that working on such a project might be fun and educational for you but completely useless if you have users other than yourself in mind. Again, I'm trying to be helpful here, so you can focus on a project that is both fun/educational for you and also potentially useful for others. This RSON business is not one of them. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at mrabarnett.plus.com Mon Mar 1 13:44:49 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Mar 2010 18:44:49 +0000 Subject: [newbie] - python list into a sql query In-Reply-To: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> References: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> Message-ID: <4B8C0B21.8010404@mrabarnett.plus.com> Jo?o wrote: > Hi. > > Can someone guide me into getting this to work? It's just really > querying a DB of an Autodiscovery tool to have a bunch of updated dns > files. > (Thought I'm still building the first script steps) I was able to > successfully query the DB against a single groupid, but am failing in > passing a list of integers into the sql query. > > I'm failing miserably in, > > sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN > ( > select hostid from hosts_groups WHERE groupid IN (' + > ','.join(map(str, %s)) + ')''' % grp_range > > > with > _mysql_exceptions.ProgrammingError: (1064, "You have an error in > your SQL syntax; check the manual that corresponds to your MySQL > server version for the right syntax to use near '' at line 1") > [snip] The triple-quoted string starts at: '''SELECT ... and ends at: ...)''' % grp_range which means that the part where you do the .join is _inside_ the string. From pmaupin at gmail.com Mon Mar 1 13:45:07 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 10:45:07 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> On Mar 1, 12:03?pm, Paul Rubin wrote: > But you are working on a solution in search of a problem. ?The really > smart thing to do would be pick something more useful to work on. ?We > don't need another configuration language. ?I can't even say "yet > another" because there's already a "yet another" called yaml. The only "in search of" here is that, instead of working on a point solution for my particular problem, I am "in search of" a solution that is a bit more elegant and general, and that might help solve other people's problems too. If you are not one of those that has this sort of problem at this point in time, then feel free to kill- file this thread. Thanks, Pat From leo.shklovskii at gmail.com Mon Mar 1 13:47:42 2010 From: leo.shklovskii at gmail.com (Leo) Date: Mon, 1 Mar 2010 10:47:42 -0800 (PST) Subject: python shell crashing on paste References: <1ede46e4-8ca1-4fe0-ad3f-7e781bbe1182@b36g2000pri.googlegroups.com> <4b84ca31$0$15832$ba4acef3@reader.news.orange.fr> Message-ID: <227e3061-db36-4188-a174-74019814af63@t31g2000prh.googlegroups.com> Thanks for responding Michel. It looks like its an issue with pyreadline - http://ipython.scipy.org/moin/PyReadline/Intro - causing the crash. I'm working with the author of it on trying to get the issue figured out. It's not related to UAC. -- --Leo On Feb 23, 10:41?pm, "Michel Claveau - MVP" wrote: > Hi! > > Where (directory) are you, when the problem come? > Have you try with UAC disabled? > > @+ > -- ? > MCI From rami.chowdhury at gmail.com Mon Mar 1 14:04:25 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 1 Mar 2010 11:04:25 -0800 Subject: [newbie] - python list into a sql query In-Reply-To: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> References: <3b20cfbf-c31f-44c4-8fbc-f95ab71690ff@x22g2000yqx.googlegroups.com> Message-ID: <201003011104.25211.rami.chowdhury@gmail.com> On Monday 01 March 2010 09:54:20 Jo?o wrote: > Hi. > > Can someone guide me into getting this to work? It's just really > querying a DB of an Autodiscovery tool to have a bunch of updated dns > files. I wouldn't be building SQL queries by hand if I could avoid it -- is this just a few one-off scripts or a project that could usefully benefit from a database abstraction layer (like SQLAlchemy: http://www.sqlalchemy.org)? > > sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN > ( > select hostid from hosts_groups WHERE groupid IN (' + > ','.join(map(str, %s)) + ')''' % grp_range > I'm not sure what you expect this to evaluate to? #>>> grp_range = [1, 2, 3] # dummy data #>>> sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ... ( ... SELECT hostid FROM hosts_groups WHERE groupid IN (' + ... ','.join(map(str, %s)) + ')''' % grp_range #>>> print sql SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN ( SELECT hostid FROM hosts_groups WHERE groupid IN (' + ','.join(map(str, [1, 2, 3])) + ') Since the triple-quoted string only ends at the corresponding triple quote, you're including some Python code into the string instead of executing it. If you really want to splice the elements of grp_range into the query, you should do something like: #>>> sql = 'SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN (SELECT hostid FROM hosts_groups WHERE groupid IN (%s))' % ",".join(str(x) for x in grp_range) #>>> sql 'SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE hostid IN (SELECT hostid FROM hosts_groups WHERE groupid IN (1,2,3))' Although, really, if you can, I'd parameterise the query (http://mysql- python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.BaseCursor- class.html#execute) at the very least... > > with > _mysql_exceptions.ProgrammingError: (1064, "You have an error in > your SQL syntax; check the manual that corresponds to your MySQL > server version for the right syntax to use near '' at line 1") > > > > I'll gladly accept any other code change suggestion > > > #!/usr/bin/env python > > import MySQLdb > import sys, os > import code > > builder_path = '/opt/scripts/dns_builder' > grp_range = range(10,15) > > try: > db = MySQLdb.connect(host="localhost", > user="tst",passwd="tst",db="tst_db" ) > except MySQLdb.Error, e: > print "Error %d: %s" % (e.args[0], e.args[1]) > > cursor = db.cursor() > > sql = '''SELECT ip, host, dns FROM zabbix_tst_db.hosts WHERE > hostid IN ( > select hostid from hosts_groups WHERE groupid IN (' + > ','.join(map(str, %s)) + ')''' % grp_range > > cursor.execute(sql) > > f = open('%s/dns_unknown_list.txt', 'w+') % builder_path > data = cursor.fetchall() > > for row in data: > ip = row[0] > host = row[1] > dns = row[2] > if host == dns: > #tmn > if ip[0][:10] in ('140.254.30','10.13.74.') > group1_file = open('%s/group1.zone', 'w') % builder_path > print >>group1_file, '''$ORIGIN group1 > > ''' > print >>group1_file, '%s IN A %s' % (dns, ip) > elif ip[0][:3] in ('8.128.46.','6.128.101') > group2_file = open('%s/group2.zone', 'w') % builder_path > print >>group2_file, '''$ORIGIN group2 > > ''' > print >>group2_file, '%s IN A %s' % (dns, ip) > else: > print >>f, 'unknown IN A %s' % ip > > db.close() > input_file.close() > f.close() ---- Rami Chowdhury "As an online discussion grows longer, the probability of a comparison involving Nazis or Hitler approaches one." -- Godwin's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From pmaupin at gmail.com Mon Mar 1 14:18:20 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 11:18:20 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> Message-ID: <062d989e-27db-46b3-913f-0573bb70543f@y17g2000yqd.googlegroups.com> > > Certainly. The PEP format is a useful one. I've used it myself for some numpy > design documents. But can you see why people might get confused about your > intentions when you call it a draft PEP and post it to python-dev? If you stop > calling it a PEP and stop talking about putting it in the standard library, > people will stop being distracted by those issues. As I mentioned, I didn't see the fine print in PEP 1 about PEP 2 being the document for library modules. As I mentioned, mea culpa. It is painfully obvious that some don't like the way I have gone about describing the project. They obviously view me announcing this as premature, or presumptuous, or something, and they have some sort of visceral reaction to that. However, I do not believe that any people (other than me) were really confused in the process. I made my intentions clear, and some people reacted badly to that because I didn't follow the process (for which I apologize again). But calling it a draft PEP is a distraction (because of the visceral reaction), but is not really what I would call confusing. My intention actually is to try to build something that is worthy of the standard library, and to eventually try to get it accepted, because I perceive a hole there, with a lot of point solutions being done to solve a common problem, and I believe the pushback is coming from people who fully understood that intention from my posting. I will try to say "hey -- here's a hole in the library and a proposal for how to fix it" more diplomatically and in the correct forum in the future, but it would be disingenuous for me to disown my goal of getting a better configparser into the standard library. Regards, Pat From pmaupin at gmail.com Mon Mar 1 14:30:28 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 11:30:28 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> On Mar 1, 12:40?pm, Daniel Fetchinson wrote: > > But you are working on a solution in search of a problem. ?The really > > smart thing to do would be pick something more useful to work on. ?We > > don't need another configuration language. ?I can't even say "yet > > another" because there's already a "yet another" called yaml. > > And in case you are new here let me assure you that Paul is saying > this with his full intention of being helpful to you. I also would > think that working on such a project might be fun and educational for > you but completely useless if you have users other than yourself in > mind. Again, I'm trying to be helpful here, so you can focus on a > project that is both fun/educational for you and also potentially > useful for others. This RSON business is not one of them. OK, but I am a bit unclear on what you and/or Paul are claiming. It could be one of a number of things. For example: - There is a preexisting file format suitable for my needs, so I should not invent another one. - If I invent a file format suitable for my needs, it couldn't possibly be general enough for anybody else. - Even if it was general enough for somebody else, there would only be two of them. I've been known to waste time (or be accused of wasting time) on various endeavors, but I like to know exactly *why* it is perceived to be a waste. Regards, Pat From jjposner at optimum.net Mon Mar 1 14:34:53 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 01 Mar 2010 14:34:53 -0500 Subject: Variable definition In-Reply-To: <4B8C0255.3090509@netplus.ch> References: <4B885A0B.9040705@netplus.ch> <4B887224.2080805@optimum.net> <4B8C0255.3090509@netplus.ch> Message-ID: <4B8C16DD.40506@optimum.net> On 3/1/2010 1:07 PM, Raphael Mayoraz wrote: > John Posner wrote: >> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >>> Hello, >>> >>> I'd like to define variables with some specific name that has a common >>> prefix. >>> Something like this: >>> >>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >>> for key, value in varDic.iteritems(): >>> 'myPrefix' + key = value >>> >> >> No trick, just swap a new key-value pair for each existing pair: >> >> for key, value in varDic.iteritems(): >> varDic[myPrefix + key] = value >> del varDict[key] >> >> Just make sure that *myPrefix* isn't an empty string! >> >> -John > Thanks for your answer. > However, your solution changes the key name in the dictionary. > That's not what I want I need to do. What I want is to define a new > variable which name is define as a string: 'myPrefx' + key. In the example > I give, I would get 3 variables: > myPrefixred = a > myPrefixgreen = b > myPrefixblue = c Yes, I misinterpreted your request. I believe there's a consensus around here that you shouldn't even try to accomplish your goal. Instead of creating *myPrefixred* as a (module-)global name or a (function-)local name, you should just use the dictionary as-is: *varDict['red']*. Or maybe make the names into attributes of a class, as Alex Goretoy suggested. [1] Can you present a convincing argument as to why you really, really need to use the name *myPrefixred* ? -John [1] http://mail.python.org/pipermail/python-list/2010-February/1237736.html From helps4indian at gmail.com Mon Mar 1 14:37:03 2010 From: helps4indian at gmail.com (coolboy8) Date: Mon, 1 Mar 2010 11:37:03 -0800 (PST) Subject: Best auto insurance company // Best auto insurance company /// Best auto insurance company /// Message-ID: <795a705c-5564-4cf8-8b83-71d2aeae4a53@s36g2000prf.googlegroups.com> VISIT http://alturl.com/8xs8 From no.email at nospam.invalid Mon Mar 1 14:37:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 11:37:39 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> Message-ID: <7xhbozrfy4.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > - There is a preexisting file format suitable for my needs, so I > should not invent another one. There are in fact quite a few--json, yaml, .ini, xml, Python literals (http://code.activestate.com/recipes/364469-safe-eval/), s-expressions, actual Python code that the application can import, and so forth. The problem isn't that you're trying to invent a useless file format per se, but rather that in trying to get other people to learn it and use it, you're also trying to appropriate a chunk of the user community's scarce and precious brain cells without good justification. Newbie designers are often lured into that and they're unfortunately (i.e. to the community's detrimtent) often more successful than they really should be. Your one complaint about yaml is that it's slow to parse. Why do you care about the parsing speed of a config file? If the existing implementation is too slow, why not write a faster one instead of designing yayaml? Even yaml is excessive in my view. "Yet another" was an ok plan when Steve Johnson started the trope by writing Yacc 30 years ago. These days, don't do yet another without very convincing reasons for rejecting what is already there. From tjreedy at udel.edu Mon Mar 1 14:41:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Mar 2010 14:41:27 -0500 Subject: AOP decorator? In-Reply-To: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> References: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> Message-ID: On 3/1/2010 11:22 AM, gentlestone wrote: > Hi, > > suppose my source code looks like: > -------------------------------- > import aspect_xy > class Basic(object, aspect_xy.Basic): > pass # basic attributes and methods ... As a sidenote, this violates my understanding of aspect-oriented programming, which is to add aspects that go across several derived classes. But... > -------------------------------- > and the source code of aspect_xy.py is: > -------------------------------- > class Basic(object): > pass # aspect extra attributes and methods ... > -------------------------------- > how can I write this with decorators? I want something like: > ------------------------------- > import aspect_xy > @aspect_xy # extra attributes and methods ... > class Basic(object): > pass # basic attributes and methods ... > ---------------------------------------------------------- > I want to write class decorator function, which: > 1. Takes the basic class as parameter > 2. Find the same class name in aspect_xy.py > 3. Inherit the found aspect class > Is it possible? You would have to look at the difference between Basic with and without the explicit base class and patch the latter to look like the former. At minimum, you would have to fix .__bases__ and .__mro__, but I do not know if those are writable. To me, it seems easier to be explicit. tjr From joncle at googlemail.com Mon Mar 1 14:49:39 2010 From: joncle at googlemail.com (Jon Clements) Date: Mon, 1 Mar 2010 11:49:39 -0800 (PST) Subject: AOP decorator? References: <9437135d-e2f7-4317-a5bd-46346fa5b5fb@q21g2000yqm.googlegroups.com> Message-ID: <0d3daa47-cb27-4134-a6b5-be3824f5cf0b@f8g2000yqn.googlegroups.com> On Mar 1, 4:22?pm, gentlestone wrote: > Hi, > > suppose my source code looks like: > -------------------------------- > ? import aspect_xy > ? class Basic(object, aspect_xy.Basic): > ? ? pass # basic attributes and methods ... > -------------------------------- > and the source code of aspect_xy.py is: > -------------------------------- > ? class Basic(object): > ? ? pass ?# aspect extra attributes and methods ... > -------------------------------- > how can I write this with decorators? I want something like: > ------------------------------- > ? import aspect_xy > ? @aspect_xy # extra attributes and methods ... > ? class Basic(object): > ? ? pass # basic attributes and methods ... > ---------------------------------------------------------- > I want to write class decorator function, which: > 1. Takes the basic class as parameter > 2. Find the same class name in aspect_xy.py > 3. Inherit the found aspect class > Is it possible? Untested and written quickly, so all possible disclaimers apply ;) class BaseObject(object): pass def aspect_xy_dec(base): def wrapper(cls): return type(cls.__name__, (base, getattr(aspect_xy, cls.__name__)), {}) return wrapper @aspect_xy(BaseObject) class SomeObject: pass Cheers, Jon. From pmaupin at gmail.com Mon Mar 1 14:59:13 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 11:59:13 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> Message-ID: <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> On Mar 1, 1:37?pm, Paul Rubin wrote: > There are in fact quite a few--json, yaml, .ini, xml, Python literals > (http://code.activestate.com/recipes/364469-safe-eval/), s-expressions, > actual Python code that the application can import, and so forth. Yes, I know about those. > The problem isn't that you're trying to invent a useless file format per > se, but rather that in trying to get other people to learn it and use > it, you're also trying to appropriate a chunk of the user community's > scarce and precious brain cells without good justification. ?Newbie > designers are often lured into that and they're unfortunately (i.e. to > the community's detrimtent) often more successful than they really > should be. Can't disagree with the statement about newbie designers. On the flip side, sometimes things wind up being defacto standards, simply because nobody could be bothered to write a better one, and they have lots of little niggling warts that also collectively take up a lot of time and attention. There is obviously a good balance somewhere. > Your one complaint about yaml is that it's slow to parse. ?Why do you > care about the parsing speed of a config file? ?If the existing > implementation is too slow, why not write a faster one instead of > designing yayaml? ?Even yaml is excessive in my view. ?"Yet another" was > an ok plan when Steve Johnson started the trope by writing Yacc 30 years > ago. ?These days, don't do yet another without very convincing reasons > for rejecting what is already there. One of my complaints. If you had read the document you would have seen others. I actually have several complaints about YAML, but I tried to write a cogent summary. Regards, Pat From bdesth.quelquechose at free.quelquepart.fr Mon Mar 1 14:59:55 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Mon, 01 Mar 2010 20:59:55 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: Message-ID: <4b8c2a34$0$10470$426a74cc@news.free.fr> Michael Rudolf a ?crit : > Out of curiosity I tried this and it actually worked as expected: > >>>> class T(object): > x=[] > foo=x.append > def f(self): > return self.x > > >>>> t=T() >>>> t.f() > [] >>>> T.foo(1) >>>> t.f() > [1] >>>> > > At first I thought "hehe, always fun to play around with python. Might > be useful sometimes" - but then It really confused me what I did. I > mean: f is what we call a method, right? Wrong. It's a function. T.f is an unbound method (in python 2.x at least) and t.f is a bound method. > But was is foo? A bound method. Bound to x, of course. > It is not a > method and not a classmethod as it accepts no self and no cls. Yes it does. Else how would t.foo(4) (or T.foo(4)) append 4 to x ? > Perhaps this all does not matter, It does. > but now I am really confused about the > terminology. So: what makes a method a method? The right question is: what makes a function a method !-) > And of what type? Answer here: http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 I really have to put this in the wiki :-/ From no.email at nospam.invalid Mon Mar 1 15:08:58 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 12:08:58 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> Message-ID: <7x635fdcth.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > One of my complaints. If you had read the document you would have > seen others. I actually have several complaints about YAML, but I > tried to write a cogent summary. Yaml sucks, but seems to have gotten some traction regardless. Therefore the Python principle of "there should be one and only one obvious way to do it" says: don't try to replace the existing thing if your new thing is only slightly better. Just deal with the existing thing's imperfections or make improvements to it. If you can make a really powerful case that your new thing is 1000x better than the old thing, that's different, but I don't think we're seeing that here. Also, XML is used for pretty much everything in the Java world. It sucks too, but it is highly standardized, it observably gets the job done, there are tons of structure editors for it, etc. Frankly I'd rather have stayed with it than deal with Yaml. There are too many of these damn formats. We should ban all but one of them (I don't much care which one). And making even more of them is not the answer. From usenot at geekmail.INVALID Mon Mar 1 15:24:13 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 21:24:13 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: <20100301212413.5694580e@geekmail.INVALID> On Mon, 01 Mar 2010 11:42:16 -0600 Robert Kern wrote: > On 2010-03-01 11:22 , Andreas Waldenburger wrote: > > > Back in the software world: Those guys write code that works. It > > does what it's supposed to do. Why should we care where they put > > their comments? > > Software usually needs to be maintained and extended over the course > of its lifetime. The original team that wrote it may not be available > in the future. > > Furthermore, docstrings are not comments. They become part of the > function object and can be introspected at runtime. This is a very > important tool when working with code at the interactive prompt and > for the collection of API documentation. Comments are less useful > than docstrings; the OP's complaint was that his programmers were > putting the function documentation in other places than docstrings, > rendering them less useful than they could have been. > No, the OP complained about those guys being idiots. I should know, because I posted it. /W -- INVALID? DE! From usenot at geekmail.INVALID Mon Mar 1 15:29:54 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Mon, 1 Mar 2010 21:29:54 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> Message-ID: <20100301212954.7aa0b99d@geekmail.INVALID> On Mon, 01 Mar 2010 18:42:17 +0100 Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: > [snip] > > Back in the software world: Those guys write code that works. It > > does what it's supposed to do. Why should we care where they put > > their comments? > > > > > If you've bought the code and want to maintain it, you'd better make > sure it's possible. > Fair enough, but we don't want to maintain it. > By the way, the ISO 9001 standard ask for your out sourced processing > to be compliant with your QA objectives, so if you care about your > code, then you should care for the code you buy. > We did not buy code. If it were written in C or such, we would never get to see it. It's not our concern. /W -- INVALID? DE! From pmaupin at gmail.com Mon Mar 1 15:35:46 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 12:35:46 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <2804c8c0-ffe5-4dde-b076-3e0948c32021@g11g2000yqe.googlegroups.com> On Mar 1, 2:08?pm, Paul Rubin wrote: > Yaml sucks, but seems to have gotten some traction regardless. Yes, that's actually one of the reasons I want to do this. I've heard that some of the YAML people want that in the standard library, and IMHO that would be a huge mistake. > Therefore the Python principle of "there should be one and only one > obvious way to do it" says: don't try to replace the existing thing if > your new thing is only slightly better. But for my use-case, YAML is irretrievably broken. Sure, it looks reasonably nice, but it increases regression runtime unacceptably. Also, despite their current protestations that Yaml AIN'T markup language, the syntax still belies its markup roots. I'm looking for a configuration language, not a markup language. >?Just deal with the existing thing's imperfections or make improvements to it. Well, I've looked at the YAML parser and I can assure you that I will not be contributing to that project. > If you can make a really powerful case that your new thing is 1000x better than the old thing, that's different, but I don't think we're seeing that here. Well, there's no way I'm hitting three orders of magnitude, but I don't think the bar is really that high. We will see. > Also, XML is used for pretty much everything in the Java world. ?It > sucks too, but it is highly standardized, it observably gets the job > done, there are tons of structure editors for it, etc. ?Frankly > I'd rather have stayed with it than deal with Yaml. XML can certainly be made readable by humans. It's hard to make it writeable by (average) humans just using a regular text editor, and even though there are tons of structure editors, requiring non- technical people to find one of those and start using it is a non- starter in many cases. But I can't strongly disagree with the opinion that YAML doesn't offer all that much over it. > There are too many of these damn formats. ?We should ban all but one of > them (I don't much care which one). ?And making even more of them is not > the answer. Well, I think that XML and YAML both overreach by trying to be all things to all applications. So I'm aiming a lot lower than that. I just want to make really good configuration files that are easy to modify in a text editor. None of the existing formats are suitable. I may be the only one who feels that way. OTOH, if we never invented new things, then I wouldn't be enjoying restructured text, and I'd be missing out on a lot there... Regards, Pat From no.email at nospam.invalid Mon Mar 1 15:42:20 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Mar 2010 12:42:20 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <2804c8c0-ffe5-4dde-b076-3e0948c32021@g11g2000yqe.googlegroups.com> Message-ID: <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > But for my use-case, YAML is irretrievably broken. Sure, it looks > reasonably nice, but it increases regression runtime unacceptably. How big are the files that you want to parse with it? Sheesh. > Well, I've looked at the YAML parser and I can assure you that I will > not be contributing to that project. So write a new one that parses the same syntax, but cleaner and faster. > XML can certainly be made readable by humans. It's hard to make it > writeable by (average) humans just using a regular text editor, I do it all the time; it's a bit dreary but not difficult. And there is absolutely no way to get anything done in this field anymore without dealing with XML from time to time. So given that we all have some experience using it, it's sensible to stick with it. > None of the existing formats are suitable. I may be the only one who > feels that way. OTOH, if we never invented new things, then I > wouldn't be enjoying restructured text, and I'd be missing out on a > lot there... ReST is another abomination that should never have gotten off the ground. It is one of the reasons I react so negatively to your config format proposal. It just sounds like more of the same. From urbangabo at gmail.com Mon Mar 1 15:53:57 2010 From: urbangabo at gmail.com (Gabor Urban) Date: Mon, 1 Mar 2010 21:53:57 +0100 Subject: Class attributes / methods..... full Python script Message-ID: Hi guys, thanks for the ideas. Here you are the code. Not transcoded from Java for I do not know Java enough.. I am scanning an XML file, and have a large ammount of logging. Any ideas are wellcome as before.... Thnx Code:> #--------------------------------------------- ## Generate CSV from OEP History XML #--------------------------------------------- import sys import os from xml.dom.minidom import parse, parseString import xml.dom import logging versionStr = '0.01' class Item: def __init__(self, pId, pChange, pComment): self.ID = pId self.Delta = pChange self.Comment = pComment def PrintItem(self): str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) return str class Package: def __init__(self, pSerial, pDate, pOwner, pSchema): self.serial = pSerial self.date = pDate self.owner = pOwner self.schema = pSchema self.items = [] def insertItem(self, pItem): self.items.append(pItem) def printPackage(self): lines = [] str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) number = self.items.length for idx in xrange(number): line = '' istr = self.items[idx].PrintItem() line = str + ',' + istr lines.append(line) return lines def getItem(tracer, pkgItem, itemName): retval = -1 name = "" found = 0 str = "" tracer.info('Function getItem entry, name = %s',itemName) nItem = pkgItem.getElementsByTagName(itemName).item(0) for node in pkgItem.childNodes: if node.nodeType != xml.dom.Node.TEXT_NODE: tracer.debug('Scanning node name = %s',node.nodeName) if node.nodeName == itemName: tracer.debug('Pkg %s found',itemName) else: tracer.warning('Pkg %s is not found',itemName) continue for entity in node.childNodes: if entity.nodeType == xml.dom.Node.TEXT_NODE: retval = entity.nodeValue tracer.debug("Node value found %s",retval) found = 1 break if found == 1: break tracer.debug('Function getItem returns %s',retval) return retval logger = logging.getLogger('XmlHistory') handler = logging.FileHandler("Xmlhistory.trc",'a') ## handler = logging.StreamHandler(sys.stderr) logger.addHandler(handler) formatter = logging.Formatter("%(name)s %(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s") handler.setFormatter(formatter) logger.setLevel(2) fileName = "history.xml" output = 'history.csv' logger.info('Xml history generator version %s',versionStr) logger.info('Starting history generation on file:%s',fileName) packages = [] data = [] ## Start XML processing dataSource = parse(fileName) print dataSource.documentElement.tagName listCsomag = dataSource.getElementsByTagName("csomag") size = listCsomag.length logger.debug('Number of packages = %d',size) for idx in xrange(size): attrib = "" package = None serial = 0 date = "" owner = "" schema = "" flag = False logger.info('Parsing package id=%d',idx) attrib = getItem(logger, listCsomag.item(idx),'sorszam') if attrib <> "NUM" and attrib <> -1: serial = int(attrib) flag = True logger.debug('Package serial set to %d',serial) else: logger.debug("Template package found.") break attrib = "" attrib = getItem(logger,listCsomag.item(idx),"datum") if attrib <> -1: date = attrib flag = flag and True logger.debug('Package date set to %s',date) attrib = "" attrib = getItem(logger,listCsomag.item(idx),"ki") if attrib <> -1: owner = attrib flag = flag and True logger.debug('Package owner set to %s',owner) attrib = "" attrib = getItem(logger,listCsomag.item(idx),"sema") if attrib <> -1: schema = attrib flag = flag and True logger.debug('Package schema set to %s',schema) if flag <> True: logger.error('Package id=%d is inconsistent',idx) break else: logger.info('Package id=%d is ok',idx) package = Package(serial,date,owner,schema) listItem = listCsomag.item(idx).getElementsByTagName("item") itemSize = listItem.length logger.debug('Number of items = %d',itemSize) for num in xrange(itemSize): flag = False value = -1 listId = 0 change = "" comment = "" item = None logger.info('Parsing item id = %d',num) value = getItem(logger,listItem.item(num),"item_id") if value <> -1: listId = int(value) flag = True logger.debug('List id set to %d',listId) value = "" value = getItem(logger,listItem.item(num),"valtozas") if value <> -1: change = value flag = flag and True logger.debug('List change desc. set to "%s"',change) value = "" value = getItem(logger,listItem.item(num),"komment") if value <> -1: comment = value flag = flag and True logger.debug('List comment desc. set to "%s"',comment) if flag <> True: logger.error('Item id = %d inconsistent',num) break else: logger.info('Item id = %d is ok',num) item = Item(listId,change,comment) package.insertItem(item) packages.append(Package) logger.info('Processing Xml file %s is done',fileName) logger.info('Generating file %s is started',output) size = len(packages) package = None for index in xrange(size): logger.info('PrettyPrinting package id=%d',index) oplines = [] oplines = packages[index].printPackage() for i in xrange(oplines.length): data.append(oplines[i]) print data -- Linux: Choice of a GNU Generation From gh at ghaering.de Mon Mar 1 15:59:53 2010 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 01 Mar 2010 21:59:53 +0100 Subject: Building Python with Scons Message-ID: I'm setting up a third-party library project (similar to the one in Google Chromium) where I use SCons as build tool. Now I need to integrate Python, too. Has anybody written a Scons script for Python 2.x or 3.x, yet? -- Gerhard From philip at semanchuk.com Mon Mar 1 16:02:48 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 1 Mar 2010 16:02:48 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7x635fdcth.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <7E76CFE6-DBEA-491C-B636-338D378672C4@semanchuk.com> On Mar 1, 2010, at 3:08 PM, Paul Rubin wrote: > Patrick Maupin writes: >> One of my complaints. If you had read the document you would have >> seen others. I actually have several complaints about YAML, but I >> tried to write a cogent summary. > > Yaml sucks, but seems to have gotten some traction regardless. > Therefore the Python principle of "there should be one and only one > obvious way to do it" says: don't try to replace the existing thing if > your new thing is only slightly better. Just deal with the existing > thing's imperfections or make improvements to it. If you can make a > really powerful case that your new thing is 1000x better than the old > thing, that's different, but I don't think we're seeing that here. > > Also, XML is used for pretty much everything in the Java world. It > sucks too, but it is highly standardized, it observably gets the job > done, there are tons of structure editors for it, etc. Frankly > I'd rather have stayed with it than deal with Yaml. > > There are too many of these damn formats. We should ban all but one > of > them (I don't much care which one). And making even more of them is > not > the answer. I dunno, times change, needs change. We must invent new tools, be those computer languages or data formats. Otherwise we'd still be programming in COBOL and writing fixed-length records to 12 inch floppies.* If Mr. Maupin was a giant corporation trying to shove a proprietary format down our collective throats, I might object to RSON. But he's not. He appears willing for it live or die on its merits, so I say good luck to him. I don't want or need it, but someone else might. Cheers Philip * You had floppies? Bleddy luxury! We wrote our data on wood pulp we'd chewed ourselves and dried into paper, using drops of our own blood to represent 1s and 0s. From breamoreboy at yahoo.co.uk Mon Mar 1 16:09:39 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Mar 2010 21:09:39 +0000 Subject: Docstrings considered too complicated In-Reply-To: <20100301212954.7aa0b99d@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> Message-ID: Andreas Waldenburger wrote: > On Mon, 01 Mar 2010 18:42:17 +0100 Jean-Michel Pichavant > wrote: > >> Andreas Waldenburger wrote: >> [snip] >>> Back in the software world: Those guys write code that works. It >>> does what it's supposed to do. Why should we care where they put >>> their comments? >>> >>> >> If you've bought the code and want to maintain it, you'd better make >> sure it's possible. >> > Fair enough, but we don't want to maintain it. > > >> By the way, the ISO 9001 standard ask for your out sourced processing >> to be compliant with your QA objectives, so if you care about your >> code, then you should care for the code you buy. >> > We did not buy code. If it were written in C or such, we would never > get to see it. > > It's not our concern. > > /W > From your original post. a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: So what is the relationship between your company and this other company? When it gets down to pounds, shillings and pence (gosh, I'm old!:) it sure as hell could make a tremendous difference in the long term, given that usually maintainance costs are astronomical when compared to initial development costs. Regards. Mark Lawrence. From pmaupin at gmail.com Mon Mar 1 16:11:59 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 13:11:59 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <2804c8c0-ffe5-4dde-b076-3e0948c32021@g11g2000yqe.googlegroups.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Message-ID: <0417d443-2013-4f62-9158-b684e3be779c@u9g2000yqb.googlegroups.com> On Mar 1, 2:42?pm, Paul Rubin wrote: > Patrick Maupin writes: > > But for my use-case, YAML is irretrievably broken. ?Sure, it looks > > reasonably nice, but it increases regression runtime unacceptably. > > How big are the files that you want to parse with it? ?Sheesh. Tiny, but over and over. The rst2pdf testsuite can generate approximately 160 PDFs, totalling around 2.5 MB, in around 22 seconds on one of my machines. But if I replace the JSON parser with a YAML parser, that goes up to 55 seconds. Wait, maybe it's because JSON is optimized in C! Nope, using JSON but disabling the C scanner only takes it to 22.3 seconds... > > > Well, I've looked at the YAML parser and I can assure you that I will > > not be contributing to that project. > > So write a new one that parses the same syntax, but cleaner and faster. But there are already several parsers for YAML, and none of them agree! The syntax definition is a mess. The thing's been in development for 10 years now, and there is no one true way to do it. Seriously, YAML overreaches for what I want. > > XML can certainly be made readable by humans. ?It's hard to make it > > writeable by (average) humans just using a regular text editor, > > I do it all the time; it's a bit dreary but not difficult. ?And there is > absolutely no way to get anything done in this field anymore without > dealing with XML from time to time. ?So given that we all have some > experience using it, it's sensible to stick with it. But people "in this field" are not really my target audience. Well, I mean people in this field are the target audience for the library, but not for the writing of the actual text files. > ReST is another abomination that should never have gotten off the > ground. ?It is one of the reasons I react so negatively to your > config format proposal. ?It just sounds like more of the same. Well, that clarifies a lot. I guess we'll just have to agree to disagree :-) Regards, Pat From alfps at start.no Mon Mar 1 16:16:59 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 22:16:59 +0100 Subject: How to crash CPython 3.1.1 in Windows XP Message-ID: How to crash CPython 3.1.1 in Windows XP: python -c "import os; os.spawnl( os.P_WAIT, 'blah' )" I reported this as a bug, Workaround: it seems that spawnl is happy with an absolute path as second arg, followed by a third arg which should be the name of the program (repeated). Cheers, - Alf From __peter__ at web.de Mon Mar 1 17:12:33 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Mar 2010 23:12:33 +0100 Subject: Class attributes / methods..... full Python script References: Message-ID: Gabor Urban wrote: > thanks for the ideas. Here you are the code. Not transcoded from Java > for I do not know Java enough.. > > I am scanning an XML file, and have a large ammount of logging. > > Any ideas are wellcome as before.... > > Thnx > > Code:> > packages.append(Package) Replace Package (the class) with package (an instance). > for i in xrange(oplines.length): > data.append(oplines[i]) Python lists don't have a length attribute. You can determine their length with len(oplines). To iterate over the items of a list you need not know the list's length: for line in oplines: data.append(line) which can be simplified to data.extend(oplines) Peter PS: Rrread the tutorial From emile at fenx.com Mon Mar 1 17:12:56 2010 From: emile at fenx.com (Emile van Sebille) Date: Mon, 01 Mar 2010 14:12:56 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7E76CFE6-DBEA-491C-B636-338D378672C4@semanchuk.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7E76CFE6-DBEA-491C-B636-338D378672C4@semanchuk.com> Message-ID: On 3/1/2010 1:02 PM Philip Semanchuk said... > * You had floppies? Bleddy luxury! We wrote our data on wood pulp we'd > chewed ourselves and dried into paper, using drops of our own blood to > represent 1s and 0s. You had left-over blood?!! Emile :) From python at mrabarnett.plus.com Mon Mar 1 17:31:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Mar 2010 22:31:02 +0000 Subject: Class attributes / methods..... full Python script In-Reply-To: References: Message-ID: <4B8C4026.3010907@mrabarnett.plus.com> Gabor Urban wrote: > Hi guys, > > thanks for the ideas. Here you are the code. Not transcoded from Java > for I do not know Java enough.. > > I am scanning an XML file, and have a large ammount of logging. > > Any ideas are wellcome as before.... > > Thnx > > Code:> > > #--------------------------------------------- > ## Generate CSV from OEP History XML > #--------------------------------------------- > > import sys > import os > from xml.dom.minidom import parse, parseString > import xml.dom > import logging > > versionStr = '0.01' > > class Item: > def __init__(self, pId, pChange, pComment): > self.ID = pId > self.Delta = pChange > self.Comment = pComment > > def PrintItem(self): > str = '%s,%s,%s'%(self.ID,self.Delta,self.comment) > return str > > class Package: > def __init__(self, pSerial, pDate, pOwner, pSchema): > self.serial = pSerial > self.date = pDate > self.owner = pOwner > self.schema = pSchema > self.items = [] > > def insertItem(self, pItem): > self.items.append(pItem) > > def printPackage(self): > lines = [] > str = '%s,%s,%s,%s'%(self.serial,self.date,self.owner,self.schema) > number = self.items.length If this is meant to get the length of self.items, then it won't work. It should be: number = len(self.items) > for idx in xrange(number): > line = '' What's the purpose of this line? You're not using 'line' before you assign to it again. > istr = self.items[idx].PrintItem() > line = str + ',' + istr > lines.append(line) > return lines > > def getItem(tracer, pkgItem, itemName): > retval = -1 > name = "" > found = 0 > str = "" > tracer.info('Function getItem entry, name = %s',itemName) > nItem = pkgItem.getElementsByTagName(itemName).item(0) > for node in pkgItem.childNodes: > if node.nodeType != xml.dom.Node.TEXT_NODE: > tracer.debug('Scanning node name = %s',node.nodeName) > if node.nodeName == itemName: > tracer.debug('Pkg %s found',itemName) > else: > tracer.warning('Pkg %s is not found',itemName) > continue > for entity in node.childNodes: > if entity.nodeType == xml.dom.Node.TEXT_NODE: > retval = entity.nodeValue > tracer.debug("Node value found %s",retval) > found = 1 > break > if found == 1: > break > tracer.debug('Function getItem returns %s',retval) > return retval > > logger = logging.getLogger('XmlHistory') > handler = logging.FileHandler("Xmlhistory.trc",'a') > ## handler = logging.StreamHandler(sys.stderr) > logger.addHandler(handler) > formatter = logging.Formatter("%(name)s %(asctime)s %(filename)s > %(lineno)d %(levelname)s %(message)s") > handler.setFormatter(formatter) > logger.setLevel(2) > > fileName = "history.xml" > output = 'history.csv' > logger.info('Xml history generator version %s',versionStr) > logger.info('Starting history generation on file:%s',fileName) > > packages = [] > data = [] > > ## Start XML processing > > dataSource = parse(fileName) > print dataSource.documentElement.tagName > listCsomag = dataSource.getElementsByTagName("csomag") > size = listCsomag.length > logger.debug('Number of packages = %d',size) > for idx in xrange(size): > attrib = "" > package = None > serial = 0 > date = "" > owner = "" > schema = "" > flag = False > logger.info('Parsing package id=%d',idx) > attrib = getItem(logger, listCsomag.item(idx),'sorszam') > if attrib <> "NUM" and attrib <> -1: > serial = int(attrib) > flag = True > logger.debug('Package serial set to %d',serial) > else: > logger.debug("Template package found.") > break > attrib = "" What's the purpose of this line? You're not using 'attrib' before you assign to it again. You're doing this repeatedly in the code. > attrib = getItem(logger,listCsomag.item(idx),"datum") > if attrib <> -1: > date = attrib > flag = flag and True Whether 'flag' is False or True, this line won't change it. You're also doing this repeatedly in the code. > logger.debug('Package date set to %s',date) > attrib = "" > attrib = getItem(logger,listCsomag.item(idx),"ki") > if attrib <> -1: > owner = attrib > flag = flag and True > logger.debug('Package owner set to %s',owner) > attrib = "" > attrib = getItem(logger,listCsomag.item(idx),"sema") > if attrib <> -1: > schema = attrib > flag = flag and True > logger.debug('Package schema set to %s',schema) > > if flag <> True: Clearer as: if not flag: or even clearer if you picked a better name than 'flag'. > logger.error('Package id=%d is inconsistent',idx) > break > else: > logger.info('Package id=%d is ok',idx) > > package = Package(serial,date,owner,schema) > > listItem = listCsomag.item(idx).getElementsByTagName("item") > itemSize = listItem.length > logger.debug('Number of items = %d',itemSize) > for num in xrange(itemSize): > flag = False > value = -1 > listId = 0 > change = "" > comment = "" > item = None > logger.info('Parsing item id = %d',num) > value = getItem(logger,listItem.item(num),"item_id") > if value <> -1: > listId = int(value) > flag = True > logger.debug('List id set to %d',listId) > value = "" > value = getItem(logger,listItem.item(num),"valtozas") > if value <> -1: > change = value > flag = flag and True > logger.debug('List change desc. set to "%s"',change) > value = "" > value = getItem(logger,listItem.item(num),"komment") > if value <> -1: > comment = value > flag = flag and True > logger.debug('List comment desc. set to "%s"',comment) > > if flag <> True: > logger.error('Item id = %d inconsistent',num) > break > else: > logger.info('Item id = %d is ok',num) > > item = Item(listId,change,comment) > package.insertItem(item) > > packages.append(Package) > The instance is 'package', the class is 'Package'. You're using the wrong one. > logger.info('Processing Xml file %s is done',fileName) > logger.info('Generating file %s is started',output) > > size = len(packages) > package = None > for index in xrange(size): > logger.info('PrettyPrinting package id=%d',index) > oplines = [] > oplines = packages[index].printPackage() > for i in xrange(oplines.length): The length of a list, string, etc, is given by 'len', eg. len(oplines). > data.append(oplines[i]) > > print data > From ben+python at benfinney.id.au Mon Mar 1 17:48:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 02 Mar 2010 09:48:47 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> Message-ID: <87eik3zmi8.fsf@benfinney.id.au> Andreas Waldenburger writes: > On Mon, 01 Mar 2010 18:42:17 +0100 Jean-Michel Pichavant > wrote: > > > Andreas Waldenburger wrote: > > [snip] > > > Back in the software world: Those guys write code that works. It > > > does what it's supposed to do. Why should we care where they put > > > their comments? > > > > > If you've bought the code and want to maintain it, you'd better make > > sure it's possible. > > > Fair enough, but we don't want to maintain it. Do you want it maintained beyond the span of your agreement with the current developers? Do you want to have free choice in who will maintain it over the period that you need it maintained? I understood ?want to maintain it? in Jean-Michel's message to include the possibility to get someone else to maintain it on your terms. > It's not our concern. Then I don't see what that problem is. -- \ ?To save the world requires faith and courage: faith in reason, | `\ and courage to proclaim what reason shows to be true.? | _o__) ?Bertrand Russell | Ben Finney From jon.sneyers at gmail.com Mon Mar 1 17:55:44 2010 From: jon.sneyers at gmail.com (Jon Sneyers) Date: 1 Mar 2010 14:55:44 -0800 Subject: Call for Participation: CHR Summer School Message-ID: <8331b2f8-c9b7-4d23-923a-06e52cd75e19@z35g2000yqd.googlegroups.com> - Call for Participation - First International Summer School on CHR: Programming and Reasoning with Rules and Constraints August 30 - September 3 2010 Leuven, Belgium Website: http://www.cs.kuleuven.be/~dtai/CHR/summerschool **************************************************************************** * EARLY REGISTRATION DISCOUNT: When registering (including payment) before * * March 31, the registration fee will be reduced by 20 euro! * * * * Additional early registration incentive: * * The first 7 registrants get a FREE copy of the book * * "Constraint Handling Rules - Current Research Topics" * **************************************************************************** The aim of the summer school is to familiarize the participants with state-of-the-art high-level declarative programming with rules and constraints as well as providing insights into the analysis of programs based on these concepts. The courses cover a wide range from theory to practice. The summer school will be based on the advanced high-level rule-based formalism and programming language Constraint Handling Rules (CHR) http://constraint-handling-rules.org/ Intended Audience: The summer school provides courses at various levels. It is open to anyone interested. It aims at Phd. students, but also post-docs, interested researchers and master students as well as interested parties from industry. Besides a working knowledge of English, there are no prerequisites. A basic knowledge of logic and Prolog that is usually covered in undergraduate classes could be helpful. Lectures and Courses: The programming language CHR will be introduced by several lecturers on the first day of the summer school. - Slim Abdennadher, GUC, Egypt Analysis of CHR Solvers - Henning Christiansen, U. Roskilde, Denmark Abduction and language processing with CHR - Thom Fruehwirth, University Ulm, Germany CHR - a common platform for rule-based approaches - Jon Sneyers, K.U.Leuven, Belgium Computability and Complexity of CHR - Peter Van Weert, K.U.Leuven, Belgium Implementation of CHR Systems A final evaluation for each course is possible through a final exam or project as determined by the instructor. The daily schedule admits laboratory, recitation or working group activities to be organized in addition to lectures. Registration: The registration fee for the School is 300 euro and includes teaching material with book, as well as accomodation and coffee breaks. Meals are not included. Attendance is limited to 20 students and will be allocated on a first-come- first-served basis. Without accommodation the registration fee is reduced to 200 euro. Location: Leuven is a lively student town in Belgium with a very high density of pubs offering hundreds of types of local beers. Organization: Thom Fruehwirth, University of Ulm, Germany Jon Sneyers, K.U. Leuven, Belgium Peter Van Weert, K.U. Leuven, Belgium -- Looking for an H-912 (container). From g.bogle at auckland.no.spam.ac.nz Mon Mar 1 18:04:02 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 02 Mar 2010 12:04:02 +1300 Subject: PyQt4.7 and PyQwt5.2.0 References: Message-ID: Gib Bogle wrote: > I installed the latest PyQt (4.7-1), then PyQwt 5.2.0, which was built > with PyQt4.5.4. This line > > import PyQt4.Qwt5 as Qwt > > fails to load the DLL. Could this be the result of not using PyQt4 4.5.4? I guess I can answer my own question. As far as I can determine, PyQwt 5.2.0 needs PyQt 4.5.4 to work. From rhodri at wildebst.demon.co.uk Mon Mar 1 18:06:27 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 01 Mar 2010 23:06:27 -0000 Subject: Variable definition References: <4B885A0B.9040705@netplus.ch> <4B887224.2080805@optimum.net> Message-ID: On Mon, 01 Mar 2010 18:07:17 -0000, Raphael Mayoraz wrote: > Thanks for your answer. > However, your solution changes the key name in the dictionary. > That's not what I want I need to do. What I want is to define a new > variable which name is define as a string: 'myPrefx' + key. In the > example > I give, I would get 3 variables: > myPrefixred = a > myPrefixgreen = b > myPrefixblue = c I repeat my previous question: why? What problem do you think this will solve that will not be more easily solved working with the language rather than against it? -- Rhodri James *-* Wildebeeste Herder to the Masses From max at alcyone.com Mon Mar 1 18:30:55 2010 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Mar 2010 15:30:55 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: Daniel Fetchinson wrote: >>> it is my goal (which I may or may not be smart enough to reach) to >>> write a module that anybody would want to use; >> But you are working on a solution in search of a problem. The really >> smart thing to do would be pick something more useful to work on. We >> don't need another configuration language. I can't even say "yet >> another" because there's already a "yet another" called yaml. > > And in case you are new here let me assure you that Paul is saying > this with his full intention of being helpful to you. I also would > think that working on such a project might be fun and educational for > you but completely useless if you have users other than yourself in > mind. Again, I'm trying to be helpful here, so you can focus on a > project that is both fun/educational for you and also potentially > useful for others. This RSON business is not one of them. Agreed. Even YAML's acronym indicates that it is already a bridge too far; we don't need more. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis It's better to be quotable than to be honest. -- Tom Stoppard From max at alcyone.com Mon Mar 1 18:33:08 2010 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Mar 2010 15:33:08 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> Message-ID: Patrick Maupin wrote: > On Mar 1, 12:03 pm, Paul Rubin wrote: > >> But you are working on a solution in search of a problem. The really >> smart thing to do would be pick something more useful to work on. We >> don't need another configuration language. I can't even say "yet >> another" because there's already a "yet another" called yaml. > > The only "in search of" here is that, instead of working on a point > solution for my particular problem, I am "in search of" a solution > that is a bit more elegant and general, and that might help solve > other people's problems too. If you are not one of those that has > this sort of problem at this point in time, then feel free to kill- > file this thread. Psst. That you're allowed to present the idea that you think is good doesn't mean that other people aren't allowed to respond and point out that in their opinion it's not such a good idea. You don't own this or any other thread. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis It's better to be quotable than to be honest. -- Tom Stoppard From max at alcyone.com Mon Mar 1 18:57:42 2010 From: max at alcyone.com (Erik Max Francis) Date: Mon, 01 Mar 2010 15:57:42 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: Patrick Maupin wrote: > On Feb 28, 9:18 pm, Steven D'Aprano > Wait a minute... if JSON is too > hard to edit, and RSON is a *superset* of >> JSON, that means by definition every JSON file is also a valid RSON file. >> Since JSON is too hard to manually edit, so is RSON. > > Well, Python is essentially a superset of JSON, with string escape > handling being ever so slightly different, and using True instead of > true, False instead of false, and None instead of null. YMMV, but I > find it possible, even probable, to write Python that is far easier to > edit than JSON, and in fact, I have used Python for configuration > files that are only to be edited by programmers or other technical > types. This not only seriously stretching the meaning of the term "superset" (as Python is most definitely not even remotely a superset of JSON), but still doesn't address the question. Is RSON and _actual_ superset of JSON, or are you just misusing the term there, as well? If it is, then your rationale for not using JSON makes no sense if you're making a new format that's merely a superset of it. Obviously JSON can't be that unreadable if you're _extending_ it to make your own "more readable" format. If JSON is unreadable, so must be RSON. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis It's better to be quotable than to be honest. -- Tom Stoppard From massimodipierro71 at gmail.com Mon Mar 1 19:20:06 2010 From: massimodipierro71 at gmail.com (mdipierro) Date: Mon, 1 Mar 2010 16:20:06 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> Message-ID: <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> On Mar 1, 6:32?am, simn_stv wrote: ... > > > You have to follow some tricks: > > > 1) have the web server serve static pages directly and set the pragma > > cache expire to one month > > 2) cache all pages that do not have forms for at least few minutes > > 3) avoid database joins > > but this would probably be to the detriment of my database design, > which is a no-no as far as im concerned. The way the tables would be > structured requires 'joins' when querying the db; or could you > elaborate a little?? Joins are the bottle neck of most web app that relay on relational databases. That is why non-relational databases such as Google App Engine, CouchDB, MongoDB do not even support Joins. You have to try to minimize joins as much as possible by using tricks such as de- normalization and caching. > > 4) use a server with at least 512KB Ram. > > hmmm...!, still thinking about what you mean by this statement also. I meant 512MB. The point is you need a lot of ram because you want to run multiple python instances, cache in ram as much as possible and also allow the database to buffer in ram as much as possible. You will see Ram usage tends to spike when you have lots of concurrent requests. From misceverything at gmail.com Mon Mar 1 19:41:57 2010 From: misceverything at gmail.com (T) Date: Mon, 1 Mar 2010 16:41:57 -0800 (PST) Subject: Py2exe - Bad File Descriptor References: <0c04902d-03e8-4b0e-8dd3-3bbdf7ea09b6@z11g2000yqz.googlegroups.com> Message-ID: On Feb 28, 10:00?pm, Dennis Lee Bieber wrote: > On Sun, 28 Feb 2010 13:22:19 -0800 (PST), T > declaimed the following in gmane.comp.python.general: > > > Sorry for the lack of code - yes, it does try to write to the > > console. ?From what I'm finding, this error may be due to the fact > > that there is no "console" to write to when I'm logged off. ?However, > > I would like to be able to print to screen if I run the EXE in debug > > mode (i.e. "myservice.exe debug"). ?Do you know of any way around > > this? ?Also, I need to get the output generated from an external EXE - > > will subprocess.Popen cause problems if I use stdout=PIPE? ?Thanks for > > your help! > > ? ? ? ? True services typically don't have interactive (console) type I/O... > What is more likely to work is to have an open socket waiting for > connections, and the use of a separate user-space client that connects > to the socket... > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ?HTTP://wlfraed.home.netcom.com/ So how would that work..would the program buffer all the "print" output, then send it to the client when it connects? Do you happen to know of any available code that utilizes this method, or something similar? Thanks for your help. From pmaupin at gmail.com Mon Mar 1 19:45:07 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 16:45:07 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <466b86b0-a115-4871-b17c-b16d7d74fce0@y17g2000yqd.googlegroups.com> Message-ID: <2e244da6-7fdc-48a2-acd4-c8861c5d7c2f@q16g2000yqq.googlegroups.com> On Mar 1, 5:33?pm, Erik Max Francis wrote: > Psst. ?That you're allowed to present the idea that you think is good > doesn't mean that other people aren't allowed to respond and point out > that in their opinion it's not such a good idea. ?You don't own this or > any other thread. Absolutely, but I still do (and will always) express a clear preference for opinions that have at least a modicum of reasoning behind them. Regards, Pat From pmaupin at gmail.com Mon Mar 1 19:56:46 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 16:56:46 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: Message-ID: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> On Mar 1, 5:57?pm, Erik Max Francis wrote: > Patrick Maupin wrote: > This not only seriously stretching the meaning of the term "superset" > (as Python is most definitely not even remotely a superset of JSON), but Well, you are entitled to that opinion, but seriously, if I take valid JSON, replace unquoted true with True, unquoted false with False, replace unquoted null with None, and take the quoted strings and replace occurrences of \uXXXX with the appropriate unicode, then I do, in fact, have valid Python. But don't take my word for it -- try it out! But if you really want to be pedantic about it, JavaScript (rather than Python) is, in fact a superset of JSON, and, despite the disparagement JavaScript receives, in my opinion, it is possible to write much better looking JavaScript than JSON for many tasks. YAML, also, is a superset of JSON, and IMO, it is possible to write much better looking YAML than JSON. > still doesn't address the question. ?Is RSON and _actual_ superset of > JSON, or are you just misusing the term there, as well? Yes, the RSON definition, in fact, a superset of JSON, just like the YAML definition. But RSON is a much smaller grammar than YAML. ?If it is, then > your rationale for not using JSON makes no sense if you're making a new > format that's merely a superset of it. ?Obviously JSON can't be that > unreadable if you're _extending_ it to make your own "more readable" > format. ?If JSON is unreadable, so must be RSON. Well, we'll have to agree to disagree here. Bearing in mind that the definition of "unreadable" depends on the target application and user, obviously, it will be *possible* to write unreadable RSON, just as it is *possible* to write unreadable JavaScript or Python or YAML, but it will be *possible* to write better looking RSON than is possible to achieve with JSON, just as it is *possible* to write better looking JavaScript or YAML or Python than it is *possible* to achieve with pure JSON. Best regards, Pat From jjposner at optimum.net Mon Mar 1 20:07:37 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 01 Mar 2010 20:07:37 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8c2a34$0$10470$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> Message-ID: On 3/1/2010 2:59 PM, Bruno Desthuilliers wrote: > Answer here: > > http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 > > I really have to put this in the wiki :-/ Bruno, I performed a light copy-edit of your writeup and put in some reStructuredText (reST) markup. The result is at: http://cl1p.net/bruno_0301.rst/ The only sentence that I think needs work is: Having access to itself (of course), the instance (if there's one) and the class, it's easy for it to wrap all this into a **method** object. Maybe this? With the instance object (if any) and class object available, it's easy to create a method object that wraps the function object. Begging pardon for my presumptuousness, John From xi at gamma.dn.ua Mon Mar 1 20:07:39 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 20:07:39 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> Message-ID: <4B8C64DB.3010105@gamma.dn.ua> Erik Max Francis wrote: > Daniel Fetchinson wrote: >>>> it is my goal (which I may or may not be smart enough to reach) to >>>> write a module that anybody would want to use; >>> But you are working on a solution in search of a problem. The really >>> smart thing to do would be pick something more useful to work on. We >>> don't need another configuration language. I can't even say "yet >>> another" because there's already a "yet another" called yaml. >> >> And in case you are new here let me assure you that Paul is saying >> this with his full intention of being helpful to you. I also would >> think that working on such a project might be fun and educational for >> you but completely useless if you have users other than yourself in >> mind. Again, I'm trying to be helpful here, so you can focus on a >> project that is both fun/educational for you and also potentially >> useful for others. This RSON business is not one of them. > > Agreed. Even YAML's acronym indicates that it is already a bridge too > far; we don't need more. > Note that YA in the acronym doesn't mean Yet Another, YAML = YAML Ain't Markup Language. Thanks, Kirill From roy at panix.com Mon Mar 1 20:20:05 2010 From: roy at panix.com (Roy Smith) Date: Mon, 01 Mar 2010 20:20:05 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> Message-ID: In article , MRAB wrote: > Ah, yes, Star Trek (the original series). > > If they transported down to a planet and there was a man in a red shirt > who you'd never seen before, he'd be the one to die! :-) Of course. Everybody knows there's an endless supply of red shirts. From eman_no1 at yahoo.com Mon Mar 1 20:47:44 2010 From: eman_no1 at yahoo.com (Eman) Date: Mon, 1 Mar 2010 17:47:44 -0800 (PST) Subject: How to use python to register a service (an existing .exe file) References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <881a0df5-872f-4c19-a989-fe3ffe775655@k2g2000pro.googlegroups.com> On Feb 15, 4:10?pm, News123 wrote: > Hi, > > Is there a python way to register new windows services. > > I am aware of the > instsrv.exe program, which can be used to install services. > I could use subprocess.Popen to call > > instsrv.exe "service_name" program.exe > > but wondered, whether there's already an existing function. > > Thans in advance and bye > > N Try my favorite 3rd pary tools maker, Chilkatsoft.com. http://www.chilkatsoft.com/refdoc/pythonCkServiceRef.html Eman_No1 From xi at gamma.dn.ua Mon Mar 1 21:02:34 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 21:02:34 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: Message-ID: <4B8C71BA.9060106@gamma.dn.ua> Patrick Maupin wrote: > All: > > Finding .ini configuration files too limiting, JSON and XML to hard to > manually edit, and YAML too complex to parse quickly, I have started > work on a new configuration file parser. I'd like to note that with the optional libyaml bindings, the PyYAML parser is pretty fast. > I call the new format RSON (for "Readable Serial Object Notation"), > and it is designed to be a superset of JSON. > > I would love for it to be considered valuable enough to be a part of > the standard library, but even if that does not come to pass, I would > be very interested in feedback to help me polish the specification, > and then possibly help for implementation and testing. > > The documentation is in rst PEP form, at: > > http://rson.googlecode.com/svn/trunk/doc/draftpep.txt === cut === Because YAML does allow for highly readable configuration files, it is tempting to overlook its other flaws for the task. But a fully (or almost) compliant parser has to understand the whole YAML specification, and this is apparently expensive. Running the rst2pdf testsuite, without sphinx or most of the other optional packages, in "fast" mode (preloading all the modules, and then forking for every test) generates 161 smallish PDF files, totaling around 2.5 MB. On one test system this process takes 22 seconds. Disabling the _json C scanner and reading the configuration files using the json pure Python implementation adds about 0.3 seconds to the 22 seconds. But using pyyaml v. 3.09 instead of json adds 33 seconds to the 22 second process! It might seem that this is an edge case, but it makes it unacceptable to use YAML for this sort of testing, and taking 200 ms to read in 1000 lines of simple JSON will be unacceptable in many other application domains as well. === cut === I'd question your testing methodology. From your description, it looks like the _json speedup never was enabled. Also PyYAML provides optional bindings to libyaml, which makes parsing and emitting yaml much faster. In my tests, it parses a 10Mb file in 3 sec. === cut === RSON semantics are based on JSON. Like JSON, an RSON document represents either a single scalar object, or a DAG (Directed Acyclic Graph), which may contain only a few simple data types. === cut === JSON doesn't represent a DAG, at least, not an arbitrary DAG since each node in the document has no more than one parent. It would be more accurate to say that that it represents a tree-like structure. === cut === The YAML syntax for supporting back-references was considered and deemed unsatisfactory. A human user who wants to put identical information in a "ship to" and "bill to" address is much more likely to use cut and paste than he is to understand and use backreferences, so the additional overhead of supporting more complex document structures is unwarranted. The concept of a "merge" in YAML, where two sub-trees of data can be merged together (similar to a recursive Python dictionary update) is quite useful, though, and will be copied. This does not alter the outcome that parsing a RSON file will result in a DAG, but does give more flexibility in the syntax that can be used to achieve a particular output DAG. === cut === This paragraph assumes the reader is familiar with intricate details of the YAML grammar and semantics. I bet most of your audience are completely lost here. === cut === Enhanced example:: key1/key2a key3a = Some random string key3b = 42 key1/key2a key3c 1 2 {} key4a = anything key4b = something else [] a b c 3 4 key1/key2b = [1, 2, 3, 4] key5 = "" This is a multi-line string. It is dedented to the farthest left column that is indented from the line containing "". key6 = [""] This is an array of strings, one per line. Each string is dedented appropriately. === cut === Frankly, this is an example that only a mother could love. I'd suggest you to add some real-world examples, make sure they look nice and put them to the introductory part of the document. Examples is how the format will be evaluated by the readers, and yours don't stand a chance. Seriously, the only reason YAML enjoys its moderate popularity despite its overcomplicated grammar, chronic lack of manpower and deficient implementations is because it's so cute. Disclaimer: I'm the author of PyYAML and libyaml. Thanks, Kirill From axpbgj at terra.com Mon Mar 1 21:12:02 2010 From: axpbgj at terra.com (floatron) Date: 01 Mar 2010 23:12:02 -0300 Subject: ze Basta de cloro en su piscina Message-ID: <20100301231202.1A5E8DBF4FBCD983@terra.com> An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Mon Mar 1 21:19:34 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 20:19:34 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4B8C71BA.9060106@gamma.dn.ua> References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: Kirill: Thank you for your constructive criticism. This is the gem that made it worthwhile to post my document. I think all of your points are spot-on, and I will be fixing the documentation. I can well believe that the C implementation of YAML is much faster than the Python one, but I am aiming for something that will be reasonably quick in pure Python. I will double-check the JSON C test results, but something I probably did not make clear is that the 22 seconds is not spent parsing -- that is for the entire test, which involves reading restructured text and generating some 160 separate PDF files. Best regards, Pat On Mon, Mar 1, 2010 at 8:02 PM, Kirill Simonov wrote: > Patrick Maupin wrote: >> >> All: >> >> Finding .ini configuration files too limiting, JSON and XML to hard to >> manually edit, and YAML too complex to parse quickly, I have started >> work on a new configuration file parser. > > I'd like to note that with the optional libyaml bindings, the PyYAML parser > is pretty fast. > >> I call the new format RSON (for "Readable Serial Object Notation"), >> and it is designed to be a superset of JSON. >> >> I would love for it to be considered valuable enough to be a part of >> the standard library, but even if that does not come to pass, I would >> be very interested in feedback to help me polish the specification, >> and then possibly help for implementation and testing. >> >> The documentation is in rst PEP form, at: >> >> http://rson.googlecode.com/svn/trunk/doc/draftpep.txt > > === cut === > Because YAML does allow for highly readable configuration files, it > is tempting to overlook its other flaws for the task. ?But a fully > (or almost) compliant parser has to understand the whole YAML > specification, and this is apparently expensive. ?Running the rst2pdf > testsuite, without sphinx or most of the other optional packages, in > "fast" mode (preloading all the modules, and then forking for every > test) generates 161 smallish PDF files, totaling around 2.5 MB. ?On > one test system this process takes 22 seconds. ?Disabling the _json C > scanner and reading the configuration files using the json pure Python > implementation adds about 0.3 seconds to the 22 seconds. ?But using > pyyaml v. 3.09 instead of json adds 33 seconds to the 22 second process! > It might seem that this is an edge case, but it makes it unacceptable to > use YAML for this sort of testing, and taking 200 ms to read in 1000 > lines of simple JSON will be unacceptable in many other application > domains as well. > === cut === > > I'd question your testing methodology. ?From your description, it looks like > the _json speedup never was enabled. ?Also PyYAML provides optional bindings > to libyaml, which makes parsing and emitting yaml much faster. ?In my tests, > it parses a 10Mb file in 3 sec. > > === cut === > RSON semantics are based on JSON. ?Like JSON, an RSON document represents > either a single scalar object, or a DAG (Directed Acyclic Graph), which > may contain only a few simple data types. > === cut === > > JSON doesn't represent a DAG, at least, not an arbitrary DAG since each node > in the document has no more than one parent. ?It would be more accurate to > say that that it represents a tree-like structure. > > === cut === > The YAML syntax for supporting back-references was considered and deemed > unsatisfactory. A human user who wants to put identical information in a > "ship to" and "bill to" address is much more likely to use cut and paste > than he is to understand and use backreferences, so the additional overhead > of supporting more complex document structures is unwarranted. > > The concept of a "merge" in YAML, where two sub-trees of data can be > merged together (similar to a recursive Python dictionary update) > is quite useful, though, and will be copied. ?This does not alter the > outcome that parsing a RSON file will result in a DAG, but does give > more flexibility in the syntax that can be used to achieve a particular > output DAG. > === cut === > > This paragraph assumes the reader is familiar with intricate details of the > YAML grammar and semantics. ?I bet most of your audience are completely lost > here. > > === cut === > Enhanced example:: > > ? ?key1/key2a > ? ? ? ?key3a = Some random string > ? ? ? ?key3b = 42 > ? ?key1/key2a > ? ? ? ?key3c > ? ? ? ? ? ?1 > ? ? ? ? ? ?2 > ? ? ? ? ? ?{} > ? ? ? ? ? ? ? ?key4a = anything > ? ? ? ? ? ? ? ?key4b = something else > ? ? ? ? ? ?[] > ? ? ? ? ? ? ? ?a > ? ? ? ? ? ? ? ?b > ? ? ? ? ? ? ? ?c > ? ? ? ? ? ?3 > ? ? ? ? ? ?4 > ? ?key1/key2b = [1, 2, 3, 4] > ? ?key5 = "" > ? ? ? This is a multi-line string. ?It is > ? ? ? ? ?dedented to the farthest left > ? ? ? ? ?column that is indented from > ? ? ? ? ?the line containing "". > ? ?key6 = [""] > ? ? ? This is an array of strings, one per line. > ? ? ? Each string is dedented appropriately. > === cut === > > Frankly, this is an example that only a mother could love. ?I'd suggest you > to add some real-world examples, make sure they look nice and put them to > the introductory part of the document. ?Examples is how the format will be > evaluated by the readers, and yours don't stand a chance. > > Seriously, the only reason YAML enjoys its moderate popularity despite its > overcomplicated grammar, chronic lack of manpower and deficient > implementations is because it's so cute. > > > > Disclaimer: I'm the author of PyYAML and libyaml. > > Thanks, > Kirill > From pmaupin at gmail.com Mon Mar 1 21:21:37 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 1 Mar 2010 20:21:37 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4B8C71BA.9060106@gamma.dn.ua> References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: On Mon, Mar 1, 2010 at 8:02 PM, Kirill Simonov wrote: BTW, congratulations on slogging through the YAML grammar to generate such a good working C library! That must have been a tremendous effort. Regards, Pat From nipukumar at gmail.com Mon Mar 1 21:39:54 2010 From: nipukumar at gmail.com (Niranjan Kumar Das) Date: Mon, 1 Mar 2010 18:39:54 -0800 Subject: New User Message-ID: Hello Group, I am starting to programme in python 1st time. Just thought i will ask the group members about some well known useful books. I am looking for books at two level. a) For beginers b) For Advaced user Appreciate your help and suggestion in the matter. Thanks, Niranjan -------------- next part -------------- An HTML attachment was scrubbed... URL: From xi at gamma.dn.ua Mon Mar 1 21:54:51 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 21:54:51 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: <4B8C7DFB.8000800@gamma.dn.ua> Patrick Maupin wrote: > Kirill: > > Thank you for your constructive criticism. This is the gem that made > it worthwhile to post my document. I think all of your points are > spot-on, and I will be fixing the documentation. You are welcome. Despite what others have been saying, I don't think this area is closed to innovations. > I can well believe that the C implementation of YAML is much faster > than the Python one, but I am aiming for something that will be > reasonably quick in pure Python. I will double-check the JSON C test > results, but something I probably did not make clear is that the 22 > seconds is not spent parsing -- that is for the entire test, which > involves reading restructured text and generating some 160 separate > PDF files. Yes, this makes more sense. It's quite possible that the pure-Python PyYAML parser is much slower than the pure-Python JSON parser. At the same time, semantically meaningful whitespaces will likely hinder the pure-Python performance. To make it fast, you'll need to convert the inner loops of the parser to regexps, and it is hard to support variable-length indentation with static regular expressions. Thanks, Kirill From xi at gamma.dn.ua Mon Mar 1 22:03:22 2010 From: xi at gamma.dn.ua (Kirill Simonov) Date: Mon, 01 Mar 2010 22:03:22 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4B8C71BA.9060106@gamma.dn.ua> Message-ID: <4B8C7FFA.4080909@gamma.dn.ua> Patrick Maupin wrote: > On Mon, Mar 1, 2010 at 8:02 PM, Kirill Simonov wrote: > > BTW, congratulations on slogging through the YAML grammar to generate > such a good working C library! > > That must have been a tremendous effort. The trick was to completely ignore the grammar described in the specification. In fact, the syntax of YAML is pretty close the Python syntax and, with some effort, the Python scanner and parser could be adapted to parsing YAML. Once I realized it, I got a working parser in a week or so. Thanks, Kirill From anand.shashwat at gmail.com Mon Mar 1 22:35:16 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 2 Mar 2010 09:05:16 +0530 Subject: New User In-Reply-To: References: Message-ID: for beginners : http://openbookproject.net/thinkcs/python/english2e/index.html python cookbook - 2 by alex martelli is fantastic if you have your basics cleared. On Tue, Mar 2, 2010 at 8:09 AM, Niranjan Kumar Das wrote: > Hello Group, > I am starting to programme in python 1st time. Just thought i will ask the > group members about some well known useful books. I am looking for books at > two level. > > a) For beginers > b) For Advaced user > > Appreciate your help and suggestion in the matter. > > Thanks, > Niranjan > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Mar 1 23:27:41 2010 From: roy at panix.com (Roy Smith) Date: Mon, 1 Mar 2010 20:27:41 -0800 (PST) Subject: Adding to a module's __dict__? Message-ID: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> >From inside a module, I want to add a key-value pair to the module's __dict__. I know I can just do: FOO = 'bar' at the module top-level, but I've got 'FOO' as a string and what I really need to do is __dict__['Foo'] = 'bar' When I do that, I get "NameError: name '__dict__' is not defined". Is it possible to do what I'm trying to do? From tjreedy at udel.edu Mon Mar 1 23:55:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Mar 2010 23:55:25 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 3/1/2010 7:56 PM, Patrick Maupin wrote: > On Mar 1, 5:57 pm, Erik Max Francis wrote: >> Patrick Maupin wrote: >> This not only seriously stretching the meaning of the term "superset" >> (as Python is most definitely not even remotely a superset of JSON), but > > Well, you are entitled to that opinion, but seriously, if I take valid > JSON, replace unquoted true with True, unquoted false with False, > replace unquoted null with None, and take the quoted strings and > replace occurrences of \uXXXX with the appropriate unicode, then I do, > in fact, have valid Python. But don't take my word for it -- try it > out! To me this is so strained that I do not see why why you are arguing the point. So what? The resulting Python 'program' will be equivalent, I believe, to 'pass'. Ie, construct objects and then discard them with no computation or output. I suggest dropping this red-herring distraction. > But if you really want to be pedantic about it, JavaScript (rather > than Python) is, in fact a superset of JSON, and, despite the > disparagement JavaScript receives, in my opinion, it is possible to > write much better looking JavaScript than JSON for many tasks. > > YAML, also, is a superset of JSON, and IMO, it is possible to write > much better looking YAML than JSON. I agree that adding a bit of syntax to something can sometimes make it easier to write readable text. This is hardly a new idea and should not be controversial. That is why people developed 'macro assembley' as a superset of 'assembly' languages and why, for instance, Python added the 'with' statement. I read your proposal. I have not needed config files and have never written json or yaml and so cannot really evaluate your proposal for something 'in between'. It does seem plausible that it could be useful. While using the PEP format is great, calling your currently vaperware module proposal a 'standards track' PEP is somewhat off-putting and confusing. If Guido rejected it, would you simply drop the idea? If not, if you would continue it as a third-party module that would eventually be released and announced on PyPI, I seriously suggest renaming it to what it is. Terry Jan Reedy From clp2 at rebertia.com Tue Mar 2 00:38:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Mar 2010 21:38:34 -0800 Subject: Adding to a module's __dict__? In-Reply-To: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <50697b2c1003012138k1a0083d0r3fc12fdfe5bc5857@mail.gmail.com> On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: > >From inside a module, I want to add a key-value pair to the module's > __dict__. ?I know I can just do: > > FOO = 'bar' > > at the module top-level, but I've got 'FOO' as a string and what I > really need to do is > > __dict__['Foo'] = 'bar' > > When I do that, I get "NameError: name '__dict__' is not defined". ?Is > it possible to do what I'm trying to do? Yes; just modify the dict returned by the globals() built-in function instead. It's usually not wise to do this and is better to use a separate dict instead, but I'll assume you know what you're doing and have good reasons to disregard the standard advice due to your use-case. Cheers, Chris -- One should avoid using the Big Hammer unnecessarily, but sometimes you really do need it and it's nice that it's available for such cases. http://blog.rebertia.com From narkewoody at gmail.com Tue Mar 2 00:48:33 2010 From: narkewoody at gmail.com (Steven Woody) Date: Tue, 2 Mar 2010 13:48:33 +0800 Subject: How to find an COM object in using of pywin32 Message-ID: Hi, I want to interactive with an OLE application with pywin32. The problem is I get totally no idea how to find the object in OLEView and how to figure out it's interface. With pywin32's example, I even don't understand that in the below statement, win32com.client.Dispatch('Excel.Application') that where the name 'Excel.Application' comes from? In OLEView (Microsoft's COM brower), I cannot find this name. Could you give me any help? Thanks -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke public key at http://subkeys.pgp.net:11371 (narkewoody at gmail.com) From vaidehi.pawar at yahoo.co.in Tue Mar 2 01:50:05 2010 From: vaidehi.pawar at yahoo.co.in (Vaidehi Pawar) Date: Tue, 2 Mar 2010 12:20:05 +0530 (IST) Subject: No subject Message-ID: <745414.12322.qm@web95110.mail.in2.yahoo.com> http://adimteknikhirdavat.com/James.html The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/ From darcy at druid.net Tue Mar 2 01:58:13 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 2 Mar 2010 01:58:13 -0500 Subject: taking python enterprise level?... In-Reply-To: <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> Message-ID: <20100302015813.5397655e.darcy@druid.net> On Mon, 1 Mar 2010 16:20:06 -0800 (PST) mdipierro wrote: > Joins are the bottle neck of most web app that relay on relational > databases. That is why non-relational databases such as Google App > Engine, CouchDB, MongoDB do not even support Joins. You have to try to > minimize joins as much as possible by using tricks such as de- > normalization and caching. I keep seeing this statement but nothing to back it up. I have created many apps that run on Python with a PostgreSQL database with a fully normalized schema and I can assure you that database joins were never my problem unless I made a badly constructed query or left off a critical index. > I meant 512MB. The point is you need a lot of ram because you want to > run multiple python instances, cache in ram as much as possible and > also allow the database to buffer in ram as much as possible. You will > see Ram usage tends to spike when you have lots of concurrent > requests. Put as much memory as you can afford/fit into your database server. It's the cheapest performance boost you can get. If you have a serious application put at least 4GB into your dedicated database server. Swapping is your enemy. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From arnodel at googlemail.com Tue Mar 2 02:09:24 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 02 Mar 2010 07:09:24 +0000 Subject: Draft PEP on RSON configuration file format References: Message-ID: Erik Max Francis writes: > Patrick Maupin wrote: >> On Feb 28, 9:18 pm, Steven D'Aprano > Wait a minute... if JSON is too >> hard to edit, and RSON is a *superset* of >>> JSON, that means by definition every JSON file is also a valid RSON file. >>> Since JSON is too hard to manually edit, so is RSON. >> >> Well, Python is essentially a superset of JSON, with string escape >> handling being ever so slightly different, and using True instead of >> true, False instead of false, and None instead of null. YMMV, but I >> find it possible, even probable, to write Python that is far easier to >> edit than JSON, and in fact, I have used Python for configuration >> files that are only to be edited by programmers or other technical >> types. > > This not only seriously stretching the meaning of the term "superset" > (as Python is most definitely not even remotely a superset of JSON), > but still doesn't address the question. Is RSON and _actual_ superset > of JSON, or are you just misusing the term there, as well? If it is, > then your rationale for not using JSON makes no sense if you're making > a new format that's merely a superset of it. Obviously JSON can't be > that unreadable if you're _extending_ it to make your own "more > readable" format. If JSON is unreadable, so must be RSON. Your argument is utterly speculative as you are making clear you haven't read the OP's proposal. -- Arnaud From techupdater.admin at gmail.com Tue Mar 2 02:58:01 2010 From: techupdater.admin at gmail.com (Rishabh Verma) Date: Mon, 1 Mar 2010 23:58:01 -0800 (PST) Subject: OSSCamp Chandigarh April 2010 - Open Source Is The Future Message-ID: <9ca0e032-94d2-47f0-8f88-e8113f9ad795@z10g2000prh.googlegroups.com> Hello All, OSSCamp is again being organized in Chandigarh on April 10, 2010. This is another step ahead to foster the open source community in the city beautiful. This event is a purely community organized event by some of the open source evangelists of Chandigarh and it would be great if you guys join us to make this event a great success. At a Camp, we love to cross-talk, huddle together, raise some noise, celebrate technology, argue over the coolest OS, fight on our fav programming languages, discuss stuff, and what not! OSScamp Chandigarh April 2010 April 10, 2009 Venue: To Be Decided Time: 10AM - 6PM You can register for the event at : http://chd.osscamp.in/ Follow Us on Twitter : http://twitter.com/osscamp Facebook Event Page : http://www.facebook.com/event.php?eid=247304090115&ref=ts From alfps at start.no Tue Mar 2 03:42:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 09:42:46 +0100 Subject: How to find an COM object in using of pywin32 In-Reply-To: References: Message-ID: * Steven Woody: > Hi, > > I want to interactive with an OLE application with pywin32. The > problem is I get totally no idea how to find the object in OLEView and > how to figure out it's interface. > > With pywin32's example, I even don't understand that in the below statement, > > win32com.client.Dispatch('Excel.Application') > > that where the name 'Excel.Application' comes from? In OLEView > (Microsoft's COM brower), I cannot find this name. It's a "programmatic identifier" a.k.a. "progid". It identifies a COM class and it's used as a readable but more name-collision-prone alternative to the 128-bit UUID. You can find the programmatic identifiers in the Windows registry (use e.g. regedit); often they're not documented. Cheers, - Alf From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 2 03:57:52 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 02 Mar 2010 09:57:52 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> Message-ID: <4b8cd310$0$4604$426a34cc@news.free.fr> John Posner a ?crit : > On 3/1/2010 2:59 PM, Bruno Desthuilliers wrote: > >> Answer here: >> >> http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/bd71264b6022765c/3a77541bf9d6617d#doc_89d608d0854dada0 >> >> >> I really have to put this in the wiki :-/ > > > Bruno, I performed a light copy-edit of your writeup and put in some > reStructuredText (reST) markup. The result is at: > > http://cl1p.net/bruno_0301.rst/ Cool. > > The only sentence that I think needs work is: > > Having access to itself (of course), the > instance (if there's one) and the class, it's easy for it > to wrap all this into a **method** object. > > Maybe this? > > With the instance object (if any) and class object available, > it's easy to create a method object that wraps the function object. That's perfect. But there's also a typo to fix in the Python implementation of the Method object: in the call method, it should inject self.im_self as first arg, not self.im_func. This had been spotted by someone named John Posner, IIRC !-) > > Begging pardon for my presumptuousness, Begging pardon for my laziness :-/ From groups_ads12 at yahoo.com Tue Mar 2 04:43:53 2010 From: groups_ads12 at yahoo.com (groups_ads12) Date: Tue, 02 Mar 2010 09:43:53 -0000 Subject: learn ajax Message-ID: ajax.learn.net.in afc ajax ajax ajax and php ajax and php building responsive web applications ajax application ajax applications ajax asp ajax c# ajax code ajax company ajax control ajax control toolkit ajax controls ajax data grid ajax design ajax design patterns ajax developer ajax developers ajax development ajax drag and drop ajax dropdown ajax example ajax examples ajax expert ajax fc ajax for web application developers ajax form tutorial ajax forms ajax forum ajax framework ajax frameworks ajax grid ajax grid control ajax http ajax jsp ajax libraries ajax library ajax net ajax net tutorial ajax photo ajax photo gallery ajax php ajax portal ajax program ajax programmer ajax programmers ajax programming ajax rails ajax request ajax sample ajax samples ajax script ajax scripts ajax soccer ajax soccer club ajax software ajax support ajax technology ajax test ajax tool ajax toolkit ajax toolkits ajax tools ajax training ajax training sessions ajax tutorial ajax tutorials ajax web ajax web 2.0 ajax web application ajax web applications ajax web design ajax web development ajax web hosting ajax web programming ajax webmail ajax website ajax windows ajax with php ajax xml ajax xmlhttp ajax xmlhttprequest asp.net ajax atlas ajax beginning ajax with php from novice to professional build your own ajax web applications coldfusion ajax dhtml ajax dojo ajax google ajax api jsf ajax jsf and ajax learn ajax microsoft ajax prototype ajax prototype ajax request prototype ajax tutorial prototype.js ajax struts ajax using ajax -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Mar 2 05:09:54 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Mar 2010 11:09:54 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> Message-ID: >> > But you are working on a solution in search of a problem. The really >> > smart thing to do would be pick something more useful to work on. We >> > don't need another configuration language. I can't even say "yet >> > another" because there's already a "yet another" called yaml. >> >> And in case you are new here let me assure you that Paul is saying >> this with his full intention of being helpful to you. I also would >> think that working on such a project might be fun and educational for >> you but completely useless if you have users other than yourself in >> mind. Again, I'm trying to be helpful here, so you can focus on a >> project that is both fun/educational for you and also potentially >> useful for others. This RSON business is not one of them. > > OK, but I am a bit unclear on what you and/or Paul are claiming. It > could be one of a number of things. For example: > > - There is a preexisting file format suitable for my needs, so I > should not invent another one. I suspect this to be true, if we mean the same thing by "configuration file format". Especially if RSON will be a superset of JSON. > - If I invent a file format suitable for my needs, it couldn't > possibly be general enough for anybody else. Quite possibly, the reason is that the already existing file formats have an ecosystem around them that make them attractive. Your file format will have to cope with this barrier to attract new users which I think will be very difficult, given the wide range of already existing formats, covering just about any use case. > - Even if it was general enough for somebody else, there would only be > two of them. See above. > I've been known to waste time (or be accused of wasting time) on > various endeavors, but I like to know exactly *why* it is perceived to > be a waste. Don't get me wrong, I also waste lot of time on hobby/fun/educational projects ("waste" in this case is only meant as "useless for others", not "useless for me") because it's, well, hobby and fun and educational :) It's just good to know if a given project is in this category or outside. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From jeanmichel at sequans.com Tue Mar 2 05:29:33 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Mar 2010 11:29:33 +0100 Subject: Adding to a module's __dict__? In-Reply-To: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8CE88D.8030404@sequans.com> Roy Smith wrote: > >From inside a module, I want to add a key-value pair to the module's > __dict__. I know I can just do: > > FOO = 'bar' > > at the module top-level, but I've got 'FOO' as a string and what I > really need to do is > > __dict__['Foo'] = 'bar' > > When I do that, I get "NameError: name '__dict__' is not defined". Is > it possible to do what I'm trying to do? > test.py: import sys varName= 'foo' setattr(sys.modules[__name__], varName, 42) in a shell: import test print test.foo >>> 42 JM From no-spam at non-existing.invalid Tue Mar 2 06:11:10 2010 From: no-spam at non-existing.invalid (Robert) Date: Tue, 02 Mar 2010 12:11:10 +0100 Subject: (and about tests) Re: Pedantic pickling error after reload? In-Reply-To: <7uq299FrmfU1@mid.uni-berlin.de> References: <7uo1aqFitnU1@mid.uni-berlin.de> <7uq299FrmfU1@mid.uni-berlin.de> Message-ID: >> well, reloading is the thing which I do most in coding practice :-) >> For me its a basic thing like cell proliferation in biology. > > I simply never do it. It has subtle issues, one of them you found, > others you say you work around by introducing actual frameworks. But you > might well forget some corner-cases & suddently chase a chimera you deem > a bug, that in fact is just an unwanted side-effect of reloading. well, at dev time there is a different rule: the more bugs, the better (they can raise/indicate certain design and coding weaknesses) > > And all this extra complexity is only good for the process of actually > changing the code. It doesn't help you maintaining code quality. neither does a improved editor, interactive/debugging/reload scheme replace tests, nor do tests replace them the other way around. different dimensions. just the benefactions on all levels radiate recursively of course ... e.g. by a good reload scheme one can even work the tests out better (and debug more efficiently when the tests bump). that little reload support code is a rather constant small stub compared to the app size (unless with trivial 1-day apps maybe). Most 'utility' modules don't need extra care at all. Plus maybe 1 .. 5 extra lines per few frequently changed GUI classes (when well organized) and some 5..10 lines for preserving/re-fixing the few application data anchors. Thats all. No need to get it fully consistent, as serves its purpose when editing during runtime is possible in 'most cases'. And most edit cases during debug sessions are typically just small fixes and touches of function code. One fix revealing the next follow-up bug .. beautifying things .. as it is. critical data structure changes are very rare occasions. A general reload scheme ("edit at runtime") zeroes out most effectively a core time consumer while exploring, iterating, debugging, smoothing .. On the time scale of these tasks, this effect can in my opinion by far not be matched equivalently by setup code of whatever kind in non-trivial apps. (As I did/do this before or with less dynamic programming languages) >> I typically need just 1 full app reboot on 20..50 edit-run-cycles I >> guess. And just few unit test runs per release. Even for >> Cython/pyximport things I added support for this reload edit-run-cycle, >> because I cannot imagine to dev without this. > > Let me assure you - it works :) > > for example yesterday, I create a full CRUD-interface for a web-app > (which is the thing I work on mostly these days) without *once* taking a > look at the browser. I wrote actions, forms, HTML, and tests along, > developed the thing ready, asserted certain constraints and error-cases, > and once finished, fired up the browser - and he saw, it worked! > > Yes, I could have written that code on the fly, hitting F5 every few > seconds/minutes to see if things work out (instead of just running the > specific tests through nose) - and once I'd be finished, I didn't have > anything permanent that ensured the functionality over time. well in this 1-day example you coded a thing which obviously you had already done similarly several times. still I guess, you had some debug session too. some exploration of new things and new aspects. profiting e.g. particularly from the Python interactive / interactive debugger, post mortem etc. .. unless you type so perfect from scratch as that guy in Genesis 1 :-) >> this is a comfortable quasi religious theory raised often and easily >> here and there - impracticable and very slow on that fine grained code >> evolution level however. an interesting issue. > > To me, that's as much as an religious statement often heard by people > that aren't (really) into test-driven development. By which I personally > don't mean the variant where one writes tests first, and then code. I > always develop both in lock-step, sometimes introducing a new feauter > first in my test as e.g. new arguments, or new calls, and then > implementing them, but as often the other way round. > > The argument is always a variation of "my problem is to complicated, the > code-base to interviened to make it possible to test this". well, nothing against preaching about tests ;-) , unless its too much. like with every extreme there is also a threshold where you don't draw anymore at the bottom line by adding more tests. there are costs too. other bottle necks ... its not against test writing for testing/validating/stabilizing and other indirect high-level benefactions. there are simply other dimensions too, which are worth a thought or two. the question about a good reload scheme is more oriented towards the debugging/interactive/exploration/editing level. things, where particularly Python opens new dimensions by its superior dynamic and self-introspective nature. > I call this a bluff. You might work with a code-base that makes it > harder than needed to write tests for new functionality. But then, most > of the time this is a sign of lack of design. Writing with testability > in mind makes you think twice about how to proper componentize your > application, clearly separate logic from presentation, validates > API-design because using the API is immediatly done when writing the > tests you need, and so forth. yes, tests writing can also induce a better code modularization. a good editor, good debugging/reload scheme etc also radiate... the test runner can be connected to the post mortem debugger/interactive and so on. >> "Reload > pychecker/pylint > tests" works most effectively with Python >> in my opinion. >> And for GUI-development the difference is max. >> (min for math algorithms which are well away from data structures/OO) > > As I said, I mainly do web these days. Which can be considered GUIs as > well. Testing the HTTP-interface is obviously easier & possible, and > what I described earlier. > > But we also use selenium to test JS-driven interfaces, as now the > complexity of the interface rises, with all the bells & whistles of > ajaxiness and whatnot. (the CRUD approach on 'form handling IO level' as it is typically more simple regarding tests writing than GUI programming - because of the atomic operations and straight interface. similar like alg and I/O testing. While test writing for a flattery JS/CSS-heavy multi-language multi-state web GUIs (with subtle user interactions) is perhaps similar complex than doing it for a desktop GUI app I think. ) >> A rule that unit tests are used only near a release or a milestone is >> healthy in that sense I think. >> (And a quick edit-(real)run-interact cycle is good for speed) > > Nope, not in my opinion. Making tests an afterthought may well lead to > them being written carelessly, not capturing corner-cases you Anyway one can formulate/write tests on each error/problem/design question which one thinks is worth a test. A interesting question may be however: if the tests (both: unit tests and auto code checks) should be _run_ permanently - in order to lets say have a 'zero test dump status' overall every few minutes, at the time scale of editing/exploring/debugging ? I think that one doesn't loose on the savety net effect, but one wins on overall validation power of the tests, when one _uses_ the (new and old) tests not too often: more rarely/later/before the 'release'. because after many things are rewired in the code (incl. test code) for a milestone/release step or, each bump which arises fresh, lets you think/cure about the network effects and deeper effect of errors in common, similar contexts etc. While when one makes the code fit against the 'few artificial tests' (which are always very/too few!) too fast on the wrong time scale, its like in that example of quick antibiotica application/abuse: the cure for the bumps then tend to be too short sighted. symptom curing. while the clever bugs arise in background ... having fresh written tests unused for some time is no problem, because they will induce there own debug session sooner or later .. > Testing is no silver bullet. But it's a rather mighte sword.. :) > I'd say testing has its place amongst other things and dimensions like (incomplete): Editor: type, browse Language: formulate Interactive: inspect, try Debug: inspect, fix Reload: fix, iterate, explore, clean Design: organize Code checks: stabilize Unit tests: stabilize Feedback: realize Each issue can be improved. effective in overall speed. He saw: If you have no good editor there is some 1.5 .. 2 x less dev speed. If you have no Python (Ruby, Groovy...) there is some 1.5 .. 2 x less dev speed. If you have no good Interactive/Debugging there is some 1.5 .. 2 x less dev speed. If you have no improved reload scheme there is another 1.5 .. 2 x less dev speed. If you have no good design scheme there is another 1.5 .. 2 x less dev speed. If you have no good code checks there is another 1.5 .. 2 x less dev speed. If you have no good test scheme there is another 1.5 .. 2 x less dev speed. If you have no good bug report scheme there is another 1.5 .. 2 x less dev speed. ... A improved reload scheme may even speed up at the center of the development wheel: iteration. I guess I underrated... Robert From emannion at gmail.com Tue Mar 2 06:34:16 2010 From: emannion at gmail.com (enda man) Date: Tue, 2 Mar 2010 03:34:16 -0800 (PST) Subject: Call Signtool using python Message-ID: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Hi, I want to call the Windows signtool to sign a binary from a python script. Here is my script: // os.chdir('./Install/activex/cab') subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) // But I am getting this error: //// SignTool Error: The specified PFX password is not correct. Number of files successfully Signed: 0 Number of warnings: 0 Number of errors: 1 Finished building plugin installer scons: done building targets. //// This python script is called as part of a scons build, which is also python code. Anyone seen this before or can pass on any ideas. Tks, EM From wuwei23 at gmail.com Tue Mar 2 07:50:25 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 2 Mar 2010 04:50:25 -0800 (PST) Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: Message-ID: "W. eWatson" wrote: > My claim is that if one creates a program in a folder that reads a file > in the folder it and then copies it to another folder, it will read ?the > data file in the first folder, and not a changed file in the new folder. > I'd appreciate it if some w7 users could try this, and let me know what > they find. On a fresh install of Win7 Ultimate, I created your program & the text file in one folder, then copied the program both using ctrl-c/ctrl-v and later ctrl-drag-&-drop. In both cases, the copied program *did not* refer to the text file when executed: D:\projects>a Traceback (most recent call last): File "D:\projects\a.py", line 1, in track_file = open("verify.txt") IOError: [Errno 2] No such file or directory: 'verify.txt' Whatever you seem to think you did, you didn't, or you're not providing enough detail on what you did to repeat the behaviour. I do agree with the sentiment that this isn't a Python issue. From vriolk at gmail.com Tue Mar 2 08:12:37 2010 From: vriolk at gmail.com (coldpizza) Date: Tue, 2 Mar 2010 05:12:37 -0800 (PST) Subject: How to use python to register a service (an existing .exe file) References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <7655fe5a-3f37-4835-8fa2-cf95928ef124@q16g2000yqq.googlegroups.com> instsrv.exe does not come with Windows by default, but I guess it should be possible to add a service using the win32 built-in `sc` command line tool. Try `sc create` from a console. The app you want to install as a service will still have to be compliant with the win32 service interface, otherwise it will throw an error, although the app will still be started. On Feb 16, 2:10?am, News123 wrote: > Hi, > > Is there a python way to register new windows services. > > I am aware of the > instsrv.exe program, which can be used to install services. > I could use subprocess.Popen to call > > instsrv.exe "service_name" program.exe > > but wondered, whether there's already an existing function. > > Thans in advance and bye > > N From roy at panix.com Tue Mar 2 08:21:03 2010 From: roy at panix.com (Roy Smith) Date: Tue, 02 Mar 2010 08:21:03 -0500 Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: In article , Chris Rebert wrote: > On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: > > >From inside a module, I want to add a key-value pair to the module's > > __dict__. ??I know I can just do: > > > > FOO = 'bar' > > > > at the module top-level, but I've got 'FOO' as a string and what I > > really need to do is > > > > __dict__['Foo'] = 'bar' > > > > When I do that, I get "NameError: name '__dict__' is not defined". ??Is > > it possible to do what I'm trying to do? > > Yes; just modify the dict returned by the globals() built-in function > instead. Ah, cool. Thanks. > It's usually not wise to do this and is better to use a > separate dict instead, but I'll assume you know what you're doing and > have good reasons to disregard the standard advice due to your > use-case. Why is it unwise? The use case is I'm importing a bunch of #define constants from a C header file. I've got triples that I want to associate; the constant name, the value, and a string describing it. The idea is I want to put in the beginning of the module: declare('XYZ_FOO', 0, "The foo property") declare('XYZ_BAR', 1, "The bar property") declare('XYZ_BAZ', 2, "reserved for future use") and so on. I'm going to have hundreds of these, so ease of use, ease of maintenance, and niceness of presentation are important. My declare() function will not just set XYZ_FOO = 1 at module global scope, but also insert entries in a variety of dicts so I can look up the description string, map from a value back to the constant name, etc. I *could* do this in a separate dict, but the notational convenience of being able to have the original constant names globally available is pretty important. From steve at holdenweb.com Tue Mar 2 08:33:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 08:33:11 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8D1397.5050507@holdenweb.com> Roy Smith wrote: > In article , > Chris Rebert wrote: > >> On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: >>> >From inside a module, I want to add a key-value pair to the module's >>> __dict__. ? I know I can just do: >>> >>> FOO = 'bar' >>> >>> at the module top-level, but I've got 'FOO' as a string and what I >>> really need to do is >>> >>> __dict__['Foo'] = 'bar' >>> >>> When I do that, I get "NameError: name '__dict__' is not defined". ? Is >>> it possible to do what I'm trying to do? >> Yes; just modify the dict returned by the globals() built-in function >> instead. > > Ah, cool. Thanks. > >> It's usually not wise to do this and is better to use a >> separate dict instead, but I'll assume you know what you're doing and >> have good reasons to disregard the standard advice due to your >> use-case. > > Why is it unwise? > > The use case is I'm importing a bunch of #define constants from a C header > file. I've got triples that I want to associate; the constant name, the > value, and a string describing it. The idea is I want to put in the > beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > and so on. I'm going to have hundreds of these, so ease of use, ease of > maintenance, and niceness of presentation are important. > > My declare() function will not just set XYZ_FOO = 1 at module global scope, > but also insert entries in a variety of dicts so I can look up the > description string, map from a value back to the constant name, etc. > > I *could* do this in a separate dict, but the notational convenience of > being able to have the original constant names globally available is pretty > important. > And how important is it to make sure that whatever data your program processes doesn't overwrite the actual variable names you want to use to program the processing? If you use this technique you are effectively making your program a hostage to fortune, as you no longer control the namespace you are using for the programming. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 2 08:33:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 08:33:11 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8D1397.5050507@holdenweb.com> Roy Smith wrote: > In article , > Chris Rebert wrote: > >> On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: >>> >From inside a module, I want to add a key-value pair to the module's >>> __dict__. ? I know I can just do: >>> >>> FOO = 'bar' >>> >>> at the module top-level, but I've got 'FOO' as a string and what I >>> really need to do is >>> >>> __dict__['Foo'] = 'bar' >>> >>> When I do that, I get "NameError: name '__dict__' is not defined". ? Is >>> it possible to do what I'm trying to do? >> Yes; just modify the dict returned by the globals() built-in function >> instead. > > Ah, cool. Thanks. > >> It's usually not wise to do this and is better to use a >> separate dict instead, but I'll assume you know what you're doing and >> have good reasons to disregard the standard advice due to your >> use-case. > > Why is it unwise? > > The use case is I'm importing a bunch of #define constants from a C header > file. I've got triples that I want to associate; the constant name, the > value, and a string describing it. The idea is I want to put in the > beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > and so on. I'm going to have hundreds of these, so ease of use, ease of > maintenance, and niceness of presentation are important. > > My declare() function will not just set XYZ_FOO = 1 at module global scope, > but also insert entries in a variety of dicts so I can look up the > description string, map from a value back to the constant name, etc. > > I *could* do this in a separate dict, but the notational convenience of > being able to have the original constant names globally available is pretty > important. > And how important is it to make sure that whatever data your program processes doesn't overwrite the actual variable names you want to use to program the processing? If you use this technique you are effectively making your program a hostage to fortune, as you no longer control the namespace you are using for the programming. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jjposner at optimum.net Tue Mar 2 09:17:00 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 02 Mar 2010 09:17:00 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8cd310$0$4604$426a34cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> Message-ID: On 3/2/2010 3:57 AM, Bruno Desthuilliers wrote: >> >> With the instance object (if any) and class object available, >> it's easy to create a method object that wraps the function object. > > That's perfect. Fixed. > But there's also a typo to fix in the Python implementation of the > Method object: in the call method, it should inject self.im_self as > first arg, not self.im_func. This had been spotted by someone named John > Posner, IIRC !-) Fixed (oops!). I've updated the text at this location: > http://cl1p.net/bruno_0301.rst/ I think the ball is back in your court, Bruno. I'd be happy to help more -- feel free to contact me off-list, at jjposner at optimum.net. Best, John From marduk at python.net Tue Mar 2 09:24:58 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 09:24:58 -0500 Subject: os.fdopen() issue in Python 3.1? Message-ID: <1267539898.477222.7.camel@necropolis> I have a snippet of code that looks like this: pid, fd = os.forkpty() if pid == 0: subprocess.call(args) else: input = os.fdopen(fd).read() ... This seems to work find for CPython 2.5 and 2.6 on my Linux system. However, with CPython 3.1 I get: input = os.fdopen(fd).read() IOError: [Errno 5] Input/output error Is there something wrong in Python 3.1? Is this the correct way to do this (run a process in a pseudo-tty and read it's output) or is there another way I should/could be doing this? -a From mwilson at the-wire.com Tue Mar 2 09:26:06 2010 From: mwilson at the-wire.com (Mel) Date: Tue, 02 Mar 2010 09:26:06 -0500 Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: Roy Smith wrote: [ ... ] > Why is it unwise? > > The use case is I'm importing a bunch of #define constants from a C header > file. I've got triples that I want to associate; the constant name, the > value, and a string describing it. The idea is I want to put in the > beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > and so on. I'm going to have hundreds of these, so ease of use, ease of > maintenance, and niceness of presentation are important. As long as the header file says what you think it says, you're fine. If you encounter a file that does "#define sys", then the sys module is forever masked, and your module can't invoke it. A header file that contains "#define declare" will be fun. Mel. From mmitchell at transparent.com Tue Mar 2 09:46:21 2010 From: mmitchell at transparent.com (Matt Mitchell) Date: Tue, 2 Mar 2010 09:46:21 -0500 Subject: Call Signtool using python In-Reply-To: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> References: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Message-ID: I think you need to use the /p switch to pass signtool.exe a password when using the /f switch. Check out http://msdn.microsoft.com/en-us/library/8s9b9yaz%28VS.80%29.aspx for more info. ----------------------------------- The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. -----Original Message----- From: python-list-bounces+mmitchell=transparent.com at python.org [mailto:python-list-bounces+mmitchell=transparent.com at python.org] On Behalf Of enda man Sent: Tuesday, March 02, 2010 6:34 AM To: python-list at python.org Subject: Call Signtool using python Hi, I want to call the Windows signtool to sign a binary from a python script. Here is my script: // os.chdir('./Install/activex/cab') subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) // But I am getting this error: //// SignTool Error: The specified PFX password is not correct. Number of files successfully Signed: 0 Number of warnings: 0 Number of errors: 1 Finished building plugin installer scons: done building targets. //// This python script is called as part of a scons build, which is also python code. Anyone seen this before or can pass on any ideas. Tks, EM -- http://mail.python.org/mailman/listinfo/python-list From lutz at learning-python.com Tue Mar 2 10:11:41 2010 From: lutz at learning-python.com (Mark Lutz) Date: Tue, 2 Mar 2010 07:11:41 -0800 (PST) Subject: Python training in Florida, April 27-29 Message-ID: <70339c5d-a874-4610-a528-787f18855a4c@y17g2000yqd.googlegroups.com> Tired of the Winter weather? Make your plans now to attend our upcoming Florida Python training seminar in April. This 3-day public class will be held on April 27-29, in Sarasota, Florida. It is open to both individual and group enrollments. For more details on the class, as well as registration instructions, please visit the class web page: http://learning-python.com/2010-public-classes.html Note that we have moved to a new domain name. If you are unable to attend in April, our next Sarasota class is already scheduled for July 13-15. Thanks, and we hope to see you at a Python class in sunny and warm Florida soon. --Mark Lutz at learning-python.com From roy at panix.com Tue Mar 2 10:19:56 2010 From: roy at panix.com (Roy Smith) Date: Tue, 2 Mar 2010 07:19:56 -0800 (PST) Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: On Mar 2, 8:33?am, Steve Holden wrote: > And how important is it to make sure that whatever data your program > processes doesn't overwrite the actual variable names you want to use to > program the processing? Oh, I see what you're saying. You're thinking I was going to machine- process the C header file and pattern-match the #define statements? Actually, I was just hand-copying the values, and was looking for a way to reduce typing. But, I suppose if I were to machine-process the header files, that would be a concern. I suppose in that case I would make sure I only inserted variables which matched a particular pattern (ie, "[A-Z]+_[A- Z][A-Z0-9]+"). In fact, now that you got me thinking in that direction... Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm manually re- typing the data out of that. Sigh. From victorsubervi at gmail.com Tue Mar 2 10:48:19 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 11:48:19 -0400 Subject: Email Script Message-ID: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> Hi; I have the following code: def my_mail(): user, passwd, db, host = login() database = MySQLdb.connect(host, user, passwd, db) cursor= database.cursor() ourEmail1 = 'marilyn at globalsolutionsgroup.vi' ourEmail1 = 'phil at globalsolutionsgroup.vi' ourEmail2 = 'benoismyname at gmail.com' form = cgi.FieldStorage() name = form.getfirst('name', '') email = form.getfirst('from', '') message = form.getfirst('message', '') message = 'Name: %s\nMessage: %s' % (name, message) subject = 'Message from Web Site' Email( from_address = email, to_address = ourEmail1, subject = subject, message = message ).send() Email( from_address = email, to_address = ourEmail2, subject = subject, message = message ).send() print 'Thank you, %s, we will get back to you shortly!
' % (name) This sends only the first of the two emails. Why doesn't it work to send the second? What do? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Tue Mar 2 10:53:10 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 11:53:10 -0400 Subject: Email Script In-Reply-To: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> Message-ID: <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi wrote: > Hi; > I have the following code: > > def my_mail(): > user, passwd, db, host = login() > database = MySQLdb.connect(host, user, passwd, db) > cursor= database.cursor() > ourEmail1 = 'marilyn at globalsolutionsgroup.vi' > ourEmail1 = 'phil at globalsolutionsgroup.vi' > ourEmail2 = 'benoismyname at gmail.com' > form = cgi.FieldStorage() > name = form.getfirst('name', '') > email = form.getfirst('from', '') > message = form.getfirst('message', '') > message = 'Name: %s\nMessage: %s' % (name, message) > subject = 'Message from Web Site' > Email( > from_address = email, > to_address = ourEmail1, > subject = subject, > message = message > ).send() > Email( > from_address = email, > to_address = ourEmail2, > subject = subject, > message = message > ).send() > print 'Thank you, %s, we will get back to you shortly!
' % (name) > > This sends only the first of the two emails. Why doesn't it work to send > the second? What do? > TIA, > beno > Should I put a timer between instances of Email? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 2 11:14:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 11:14:37 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: Roy Smith wrote: > On Mar 2, 8:33 am, Steve Holden wrote: > >> And how important is it to make sure that whatever data your program >> processes doesn't overwrite the actual variable names you want to use to >> program the processing? > > Oh, I see what you're saying. You're thinking I was going to machine- > process the C header file and pattern-match the #define statements? > Actually, I was just hand-copying the values, and was looking for a > way to reduce typing. > > But, I suppose if I were to machine-process the header files, that > would be a concern. I suppose in that case I would make sure I only > inserted variables which matched a particular pattern (ie, "[A-Z]+_[A- > Z][A-Z0-9]+"). In fact, now that you got me thinking in that > direction... > > Somewhat sadly, in my case, I can't even machine process the header > file. I don't, strictly speaking, have a header file. What I have is > a PDF which documents what's in the header file, and I'm manually re- > typing the data out of that. Sigh. > Don't worry. Now you have revealed the *real* problem you may well find there are c.l.py readers who can help! Python can read PDFs ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jjposner at optimum.net Tue Mar 2 11:18:02 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 02 Mar 2010 11:18:02 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <4B8D3A3A.8030501@optimum.net> On 3/2/2010 10:19 AM, Roy Smith wrote: > > Somewhat sadly, in my case, I can't even machine process the header > file. I don't, strictly speaking, have a header file. What I have is > a PDF which documents what's in the header file, and I'm manually re- > typing the data out of that. Sigh. Here's an idea, perhaps too obvious, to minimize your keystrokes: 1. Create a text file with the essential data: XYZ_FOO 0 The foo property XYZ_BAR 1 The bar property XYZ_BAZ 2 reserved for future use 2. Use a Python script to convert this into the desired code: declare('XYZ_FOO', 0, "The foo property") declare('XYZ_BAR', 1, "The bar property") declare('XYZ_BAZ', 2, "reserved for future use") Note: >>> s 'XYZ_FOO 0 The foo property' >>> s.split(None, 2) ['XYZ_FOO', '0', 'The foo property'] HTH, John From aahz at pythoncraft.com Tue Mar 2 11:22:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 08:22:38 -0800 Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> Message-ID: In article , D'Arcy J.M. Cain wrote: > >Put as much memory as you can afford/fit into your database server. >It's the cheapest performance boost you can get. If you have a serious >application put at least 4GB into your dedicated database server. >Swapping is your enemy. Also, put your log/journal files on a different spindle from the database files. That makes a *huge* difference. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From michaelveloz at gmail.com Tue Mar 2 11:29:04 2010 From: michaelveloz at gmail.com (Veloz) Date: Tue, 2 Mar 2010 08:29:04 -0800 (PST) Subject: Queue peek? Message-ID: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Hi all I'm looking for a queue that I can use with multiprocessing, which has a peek method. I've seen some discussion about queue.peek but don't see anything in the docs about it. Does python have a queue class with peek semantics? Michael From a_jtim at bellsouth.net Tue Mar 2 11:31:16 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 2 Mar 2010 08:31:16 -0800 (PST) Subject: freebsd and multiprocessing Message-ID: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> Hi, I'm intending to use multiprocessing on a freebsd machine (6.3 release, quad core, 8cpus, amd64). I see in the doc that on this platform I can't use synchronize: ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770. As far as I can tell, I have no need to synchronize the processes--I have several processes run separately and I need to know when they're all finished; there's no communication between them and each owns its own log file for output. Is anyone using multiprocessing on FreeBSD and run into any other gotchas? thanks, --Tim Arnold From robert.kern at gmail.com Tue Mar 2 11:34:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Mar 2010 10:34:51 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 2010-03-01 22:55 PM, Terry Reedy wrote: > On 3/1/2010 7:56 PM, Patrick Maupin wrote: >> On Mar 1, 5:57 pm, Erik Max Francis wrote: >>> Patrick Maupin wrote: >>> This not only seriously stretching the meaning of the term "superset" >>> (as Python is most definitely not even remotely a superset of JSON), but >> >> Well, you are entitled to that opinion, but seriously, if I take valid >> JSON, replace unquoted true with True, unquoted false with False, >> replace unquoted null with None, and take the quoted strings and >> replace occurrences of \uXXXX with the appropriate unicode, then I do, >> in fact, have valid Python. But don't take my word for it -- try it >> out! > > To me this is so strained that I do not see why why you are arguing the > point. So what? The resulting Python 'program' will be equivalent, I > believe, to 'pass'. Ie, construct objects and then discard them with no > computation or output. Not if you eval() rather than exec(). It's reasonably well-accepted that JSON is very close to being a subset of Python's expression syntax with just a few modifications. -- 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 From robert.kern at gmail.com Tue Mar 2 11:37:55 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Mar 2010 10:37:55 -0600 Subject: Is this secure? In-Reply-To: References: <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-28 01:28 AM, Aahz wrote: > In article, > Robert Kern wrote: >> >> If you are storing the password instead of making your user remember >> it, most platforms have some kind of keychain secure password >> storage. I recommend reading up on the APIs available on your targeted >> platforms. > > Are you sure? I haven't done a lot of research, but my impression was > that Windows didn't have anything built in. You're right, not built-in, but Windows does provide enough crypto services for a cross-platform Python implementation to be built: http://pypi.python.org/pypi/keyring -- 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 From pavlovevidence at gmail.com Tue Mar 2 11:49:26 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Mar 2010 08:49:26 -0800 (PST) Subject: Adding to a module's __dict__? References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <8fa1b0d6-3f1b-4499-872c-e5854d289e9e@w27g2000pre.googlegroups.com> On Mar 2, 5:21?am, Roy Smith wrote: > In article , > ?Chris Rebert wrote: > > > > > On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith wrote: > > > >From inside a module, I want to add a key-value pair to the module's > > > __dict__. ?I know I can just do: > > > > FOO = 'bar' > > > > at the module top-level, but I've got 'FOO' as a string and what I > > > really need to do is > > > > __dict__['Foo'] = 'bar' > > > > When I do that, I get "NameError: name '__dict__' is not defined". ?Is > > > it possible to do what I'm trying to do? > > > Yes; just modify the dict returned by the globals() built-in function > > instead. > > Ah, cool. ?Thanks. > > > It's usually not wise to do this and is better to use a > > separate dict instead, but I'll assume you know what you're doing and > > have good reasons to disregard the standard advice due to your > > use-case. > > Why is it unwise? He didn't say it was unwise. He said it's usually not wise. Carl Banks From philip at semanchuk.com Tue Mar 2 11:52:13 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 2 Mar 2010 11:52:13 -0500 Subject: freebsd and multiprocessing In-Reply-To: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> Message-ID: <21D34712-C0F0-40E5-9D62-DB867962ED8A@semanchuk.com> On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: > Hi, > I'm intending to use multiprocessing on a freebsd machine (6.3 > release, quad core, 8cpus, amd64). I see in the doc that on this > platform I can't use synchronize: > > ImportError: This platform lacks a functioning sem_open > implementation, therefore, the required synchronization primitives > needed will not function, see issue 3770. > > As far as I can tell, I have no need to synchronize the processes--I > have several processes run separately and I need to know when they're > all finished; there's no communication between them and each owns its > own log file for output. > > Is anyone using multiprocessing on FreeBSD and run into any other > gotchas? Hi Tim, I don't use multiprocessing but I've written two low-level IPC packages, one for SysV IPC and the other for POSIX IPC. I think that multiprocessing prefers POSIX IPC (which is where sem_open() comes from). I don't know what it uses if that's not available, but SysV IPC seems a likely alternative. I must emphasize, however, that that's a guess on my part. FreeBSD didn't have POSIX IPC support until 7.0, and that was sort of broken until 7.2. As it happens, I was testing my POSIX IPC code against 7.2 last night and it works just fine. SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is the oldest I've tested). ISTR that by default each message queue is limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably tell you that and may even let you change it. Other than that I can't think of any SysV limitations that might bite you. HTH Philip From victorsubervi at gmail.com Tue Mar 2 11:56:58 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 12:56:58 -0400 Subject: Email Script In-Reply-To: <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> Message-ID: <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> On Tue, Mar 2, 2010 at 11:53 AM, Victor Subervi wrote: > On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> def my_mail(): >> user, passwd, db, host = login() >> database = MySQLdb.connect(host, user, passwd, db) >> cursor= database.cursor() >> ourEmail1 = 'marilyn at globalsolutionsgroup.vi' >> ourEmail1 = 'phil at globalsolutionsgroup.vi' >> ourEmail2 = 'benoismyname at gmail.com' >> form = cgi.FieldStorage() >> name = form.getfirst('name', '') >> email = form.getfirst('from', '') >> message = form.getfirst('message', '') >> message = 'Name: %s\nMessage: %s' % (name, message) >> subject = 'Message from Web Site' >> Email( >> from_address = email, >> to_address = ourEmail1, >> subject = subject, >> message = message >> ).send() >> Email( >> from_address = email, >> to_address = ourEmail2, >> subject = subject, >> message = message >> ).send() >> print 'Thank you, %s, we will get back to you shortly!
' % (name) >> >> This sends only the first of the two emails. Why doesn't it work to send >> the second? What do? >> TIA, >> beno >> > > Should I put a timer between instances of Email? > >> >> Adding a timer didn't work. Do I need to explicitly close the smtp connection before sending the next email? I don't understand why there's a problem. TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Mar 2 12:26:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 17:26:18 +0000 Subject: Adding to a module's __dict__? In-Reply-To: <4B8D3A3A.8030501@optimum.net> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> <4B8D3A3A.8030501@optimum.net> Message-ID: <4B8D4A3A.90501@mrabarnett.plus.com> John Posner wrote: > On 3/2/2010 10:19 AM, Roy Smith wrote: >> >> Somewhat sadly, in my case, I can't even machine process the header >> file. I don't, strictly speaking, have a header file. What I have is >> a PDF which documents what's in the header file, and I'm manually re- >> typing the data out of that. Sigh. > > Here's an idea, perhaps too obvious, to minimize your keystrokes: > > 1. Create a text file with the essential data: > > XYZ_FOO 0 The foo property > XYZ_BAR 1 The bar property > XYZ_BAZ 2 reserved for future use > > 2. Use a Python script to convert this into the desired code: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > Note: > > >>> s > 'XYZ_FOO 0 The foo property' > >>> s.split(None, 2) > ['XYZ_FOO', '0', 'The foo property'] > You might be able to reduce your typing by copy-and-pasting the relevant text from the PDF into an editor and then editing it. From python at mrabarnett.plus.com Tue Mar 2 12:32:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 17:32:40 +0000 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <1267539898.477222.7.camel@necropolis> References: <1267539898.477222.7.camel@necropolis> Message-ID: <4B8D4BB8.8020909@mrabarnett.plus.com> Albert Hopkins wrote: > I have a snippet of code that looks like this: > > pid, fd = os.forkpty() > if pid == 0: > subprocess.call(args) > else: > input = os.fdopen(fd).read() > ... > > > This seems to work find for CPython 2.5 and 2.6 on my Linux system. > However, with CPython 3.1 I get: > > input = os.fdopen(fd).read() > IOError: [Errno 5] Input/output error > > Is there something wrong in Python 3.1? Is this the correct way to do > this (run a process in a pseudo-tty and read it's output) or is there > another way I should/could be doing this? > The documentation also mentions the 'pty' module. Have you tried that instead? From emannion at gmail.com Tue Mar 2 12:33:39 2010 From: emannion at gmail.com (enda man) Date: Tue, 2 Mar 2010 09:33:39 -0800 (PST) Subject: Call Signtool using python References: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Message-ID: On Mar 2, 2:46?pm, "Matt Mitchell" wrote: > I think you need to use the /p switch to pass signtool.exe a password > when using the /f switch. > Check outhttp://msdn.microsoft.com/en-us/library/8s9b9yaz%28VS.80%29.aspxfor > more info. > > ----------------------------------- > The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately by telephone (603) 262-6300 or by electronic mail immediately. Thank you. > > -----Original Message----- > From: python-list-bounces+mmitchell=transparent.... at python.org > > [mailto:python-list-bounces+mmitchell=transparent.... at python.org] On > Behalf Of enda man > Sent: Tuesday, March 02, 2010 6:34 AM > To: python-l... at python.org > Subject: Call Signtool using python > > Hi, > > I want to call the Windows signtool to sign a binary from a python > script. > > Here is my script: > // > os.chdir('./Install/activex/cab') > subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", > "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) > // > > But I am getting this error: > //// > SignTool Error: The specified PFX password is not correct. > > Number of files successfully Signed: 0 > Number of warnings: 0 > Number of errors: 1 > Finished building plugin installer > scons: done building targets. > //// > > This python script is called as part of a scons build, which is also > python code. > > Anyone seen this before or can pass on any ideas. > Tks, > EM > > --http://mail.python.org/mailman/listinfo/python-list > > The same command works when run from the command line but when I run it from python using subprocess.call(...) it fails as described in my first post. I do not need to use the /p switch as the password is embedded in the pfx file. That is why I think it is something I am or am not doing in python. EM From usenot at geekmail.INVALID Tue Mar 2 12:35:27 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 18:35:27 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> Message-ID: <20100302183527.47c6e8f5@geekmail.INVALID> On Mon, 01 Mar 2010 21:09:39 +0000 Mark Lawrence wrote: > Andreas Waldenburger wrote: > > [snip] > > We did not buy code. If it were written in C or such, we would never > > get to see it. > > > > It's not our concern. > > > > /W > > > > From your original post. > > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > > So what is the relationship between your company and this other > company? They write a piece of software that we run as a component in a software ecosystem that we (and others) have developed. > When it gets down to pounds, shillings and pence (gosh, I'm > old!:) it sure as hell could make a tremendous difference in the long > term, given that usually maintainance costs are astronomical when > compared to initial development costs. > I totally agree, but as long as their software works, why should we care how their code looks? It's totally their responsibility. Why should we nanny every partner we have? Don't get me wrong; our whole system is more fragile than I find comfortable. But I guess getting 10ish different parties around the globe to work in complete unison is quite a feat, and I'm surprised it even works as it is. But it does, and I'm glad we don't have to micromanage other people's code. /W -- INVALID? DE! From tjreedy at udel.edu Tue Mar 2 12:38:55 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Mar 2010 12:38:55 -0500 Subject: Adding to a module's __dict__? In-Reply-To: <4B8D3A3A.8030501@optimum.net> References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> <4B8D3A3A.8030501@optimum.net> Message-ID: On 3/2/2010 11:18 AM, John Posner wrote: > On 3/2/2010 10:19 AM, Roy Smith wrote: >> >> Somewhat sadly, in my case, I can't even machine process the header >> file. I don't, strictly speaking, have a header file. What I have is >> a PDF which documents what's in the header file, and I'm manually re- >> typing the data out of that. Sigh. There are Python modules to read/write pdf. > Here's an idea, perhaps too obvious, to minimize your keystrokes: > > 1. Create a text file with the essential data: > > XYZ_FOO 0 The foo property > XYZ_BAR 1 The bar property > XYZ_BAZ 2 reserved for future use > > 2. Use a Python script to convert this into the desired code: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") > > Note: > > >>> s > 'XYZ_FOO 0 The foo property' > >>> s.split(None, 2) > ['XYZ_FOO', '0', 'The foo property'] Given that set of triples is constant, I would think about having the Python script do the computation just once, instead of with every inport. In other words, the script should *call* the declare function and then write out the resulting set of dicts either to a .py or pickle file. tjr From usenot at geekmail.INVALID Tue Mar 2 12:40:56 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 18:40:56 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> Message-ID: <20100302184056.743a71e7@geekmail.INVALID> On Tue, 02 Mar 2010 09:48:47 +1100 Ben Finney wrote: > > It's not our concern. > > Then I don't see what that problem is. There is none. I was griping about how stupid they are. That is a personal problem I have with their *code* (not software), and I thought I'd just share my superiority complex with everyone. I had hoped that everyone just read it, went like "Oh geez.", smiled it off with a hint of lesson learned and got back to whatever it was they were doing. Alas, I was wrong ... and I'm sorry. /W -- INVALID? DE! From affdfsdfdsfsd at b.com Tue Mar 2 12:46:12 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 02 Mar 2010 17:46:12 GMT Subject: case do problem Message-ID: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> hi, i've to convert from Pascal this code: iterations=0; count=0; REPEAT; iterations = iterations+1; ... IF (genericCondition) THEN count=count+1; ... CASE count OF: 1: m = 1 2: m = 10 3: m = 100 UNTIL count = 4 OR iterations = 20 i do something like this: iterations = 0 count = 0 m_Switch = (1,10,100) while True: iterations +=1 ... if (genericCondition): count +=1 ... try: m = m_Switch[count-1] except: pass if count = 4 or iterations = 20 the problem is that when count = 4 m_Switch[4-1] have no value, so i use the try..except. Is there a better solution to solve this problem? and, generally speaking, the try..except block slow down the execution of the program or not? Thank you in advance Nico From mrkafk at gmail.com Tue Mar 2 12:46:22 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 18:46:22 +0100 Subject: conditional import into global namespace Message-ID: Hello everyone, I have a class that is dependent on subprocess functionality. I would like to make it self-contained in the sense that it would import subprocess if it's not imported yet. What is the best way to proceed with this? I see a few possibilities: 1. do a class level import, like: class TimeSync(object): import subprocess 2. do an import in init, which is worse bc it's ran every time an instance is created: def __init__(self, shiftsec, ntpserver): import subprocess Both of those methods have disadvantage in this context, though: they create 'subprocess' namespace in a class or instance, respectively. Is there anyway to make it a global import? Regards, mk From invalid at invalid.invalid Tue Mar 2 12:46:52 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Mar 2010 17:46:52 +0000 (UTC) Subject: Broken references in postings Message-ID: I've noticed recently that a lot of the "refernces" and "in-reply-to" headers in c.l.p are broken, resulting in the inability to move from a child to a parent in a tree. For example in a recent reply (subejct: os.fdopen() issue in Python 3.1?), the references and in-reply-to headers both contained: 1267539898.477222.7.camel at necropolis However, the article replied to has a message-ID header of mailman.110.1267539885.23598.python-list at python.org I don't see 1267539898.477222.7.camel at necropolis anywhere in the headers of the referrant. Is something broken in the mail<->news gateway? Or is it just individual news/mail clients that are broken? -- Grant Edwards grant.b.edwards Yow! I own seven-eighths of at all the artists in downtown gmail.com Burbank! From affdfsdfdsfsd at b.com Tue Mar 2 12:50:45 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 02 Mar 2010 17:50:45 GMT Subject: case do problem References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <4b8d4ff5$0$1132$4fafbaef@reader1.news.tin.it> additional information: when count=4 i haven't to change the m value, so i have to do nothing or something like m = m Nico From tjreedy at udel.edu Tue Mar 2 12:59:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Mar 2010 12:59:00 -0500 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 3/2/2010 11:34 AM, Robert Kern wrote: > On 2010-03-01 22:55 PM, Terry Reedy wrote: >> On 3/1/2010 7:56 PM, Patrick Maupin wrote: >>> On Mar 1, 5:57 pm, Erik Max Francis wrote: >>>> Patrick Maupin wrote: >>>> This not only seriously stretching the meaning of the term "superset" >>>> (as Python is most definitely not even remotely a superset of JSON), >>>> but >>> >>> Well, you are entitled to that opinion, but seriously, if I take valid >>> JSON, replace unquoted true with True, unquoted false with False, >>> replace unquoted null with None, and take the quoted strings and >>> replace occurrences of \uXXXX with the appropriate unicode, then I do, >>> in fact, have valid Python. But don't take my word for it -- try it >>> out! >> >> To me this is so strained that I do not see why why you are arguing the >> point. So what? The resulting Python 'program' will be equivalent, I >> believe, to 'pass'. Ie, construct objects and then discard them with no >> computation or output. > > Not if you eval() rather than exec(). >>> eval(1) creates and objects and discards it, with a net result of 'pass'. What do you think I am missing. It's reasonably well-accepted that > JSON is very close to being a subset of Python's expression syntax with > just a few modifications. It is specifically JavaScript Object Notation, which is very similar to a subset of Python's object notation (number and string literals and list and dict displays (but not set displays), and three named constants). Without operators, it barely qualifies, to me, even as 'expression syntax'. To me, comparing object notation with programming language is not helpful to the OP's purpose. His main claim is that JSON can be usefully extended but that YAML is too much, so that perhaps he, with help, can find a 'sweet spot' in between. Terry Jan Reedy From a_jtim at bellsouth.net Tue Mar 2 12:59:10 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 2 Mar 2010 09:59:10 -0800 (PST) Subject: freebsd and multiprocessing References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> Message-ID: <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> On Mar 2, 11:52?am, Philip Semanchuk wrote: > On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: > > > > > > > Hi, > > I'm intending to use multiprocessing on a freebsd machine (6.3 > > release, quad core, 8cpus, amd64). I see in the doc that on this > > platform I can't use synchronize: > > > ImportError: This platform lacks a functioning sem_open > > implementation, therefore, the required synchronization primitives > > needed will not function, see issue 3770. > > > As far as I can tell, I have no need to synchronize the processes--I > > have several processes run separately and I need to know when they're > > all finished; there's no communication between them and each owns its > > own log file for output. > > > Is anyone using multiprocessing on FreeBSD and run into any other > > gotchas? > > Hi Tim, > I don't use multiprocessing but I've written two low-level IPC ? > packages, one for SysV IPC and the other for POSIX IPC. > > I think that multiprocessing prefers POSIX IPC (which is where ? > sem_open() comes from). I don't know what it uses if that's not ? > available, but SysV IPC seems a likely alternative. I must emphasize, ? > however, that that's a guess on my part. > > FreeBSD didn't have POSIX IPC support until 7.0, and that was sort of ? > broken until 7.2. As it happens, I was testing my POSIX IPC code ? > against 7.2 last night and it works just fine. > > SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is the ? > oldest I've tested). ISTR that by default each message queue is ? > limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably ? > tell you that and may even let you change it. Other than that I can't ? > think of any SysV limitations that might bite you. > > HTH > Philip Hi Philip, Thanks for that information. I wish I could upgrade the machine to 7.2! alas, out of my power. I get the following results from sysctl: % sysctl kern.ipc | grep msg kern.ipc.msgseg: 2048 kern.ipc.msgssz: 8 kern.ipc.msgtql: 40 kern.ipc.msgmnb: 2048 kern.ipc.msgmni: 40 kern.ipc.msgmax: 16384 I'll write some test programs using multiprocessing and see how they go before committing to rewrite my current code. I've also been looking at 'parallel python' although it may have the same issues. http://www.parallelpython.com/ thanks again, --Tim From clp2 at rebertia.com Tue Mar 2 12:59:22 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Mar 2010 09:59:22 -0800 Subject: Call Signtool using python In-Reply-To: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> References: <24bf5006-db86-4415-89ec-c5eab8f1c740@x22g2000yqx.googlegroups.com> Message-ID: <50697b2c1003020959g33d31d45ge1a7b7986b7e5a45@mail.gmail.com> On Tue, Mar 2, 2010 at 3:34 AM, enda man wrote: > Hi, > > I want to call the Windows signtool to sign a binary from a python > script. > > Here is my script: > // > os.chdir('./Install/activex/cab') > subprocess.call(["signtool", "sign", "/v", "/f", "webph.pfx", "/t", > "http://timestamp.verisign.com/scripts/timstamp.dll", "WebPh.exe" ]) > // > > But I am getting this error: > //// > SignTool Error: The specified PFX password is not correct. > > Number of files successfully Signed: 0 > Number of warnings: 0 > Number of errors: 1 > Finished building plugin installer > scons: done building targets. > //// > > > This python script is called as part of a scons build, which is also > python code. > > Anyone seen this before or can pass on any ideas. Nothing looks obviously wrong (though I'm unfamiliar with signtool). Have you tried specifying an absolute path to webph.pfx? Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Tue Mar 2 13:00:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 19:00:09 +0100 Subject: case do problem In-Reply-To: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: * Tracubik: > hi, i've to convert from Pascal this code: > > iterations=0; > count=0; > REPEAT; > iterations = iterations+1; > ... > IF (genericCondition) THEN count=count+1; > ... > CASE count OF: > 1: m = 1 > 2: m = 10 > 3: m = 100 Uhm, is this syntactically valid Pascal? As I recall, every Pascal construct was delimited in some way. Once I had the complete Pascal syntax in my head, but alas, not anymore... > UNTIL count = 4 OR iterations = 20 > > i do something like this: > > iterations = 0 > count = 0 > > m_Switch = (1,10,100) > > while True: > iterations +=1 > ... > if (genericCondition): > count +=1 > ... > try: > m = m_Switch[count-1] > except: pass > if count = 4 or iterations = 20 > > the problem is that when count = 4 m_Switch[4-1] have no value, so i use > the try..except. iterations = 0 count = 0 while not( count == 4 or iterations == 20 ): iterations += 1 # ... if generic_condition: count += 1 # ... m = (1, 10, 100, 100)[count] > Is there a better solution to solve this problem? Define "better". Do you mean faster, more clear, shorter, using less memory, what? Above I've assumed that you want to get rid of the try block, since that's what you're asking about: > and, generally > speaking, the try..except block slow down the execution of the program or > not? Probably, but don't think about it. Python programming is at a level where that kind of efficiency doesn't count. Or, ideally it shouldn't count. Cheers & hth., - Alf From alfps at start.no Tue Mar 2 13:01:36 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 19:01:36 +0100 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: * Alf P. Steinbach: > * Tracubik: >> hi, i've to convert from Pascal this code: >> >> iterations=0; >> count=0; >> REPEAT; >> iterations = iterations+1; >> ... >> IF (genericCondition) THEN count=count+1; >> ... >> CASE count OF: >> 1: m = 1 >> 2: m = 10 >> 3: m = 100 > > Uhm, is this syntactically valid Pascal? As I recall, every Pascal > construct was delimited in some way. Once I had the complete Pascal > syntax in my head, but alas, not anymore... > > >> UNTIL count = 4 OR iterations = 20 >> >> i do something like this: >> >> iterations = 0 >> count = 0 >> >> m_Switch = (1,10,100) >> >> while True: >> iterations +=1 >> ... >> if (genericCondition): >> count +=1 >> ... >> try: >> m = m_Switch[count-1] >> except: pass >> if count = 4 or iterations = 20 >> >> the problem is that when count = 4 m_Switch[4-1] have no value, so i >> use the try..except. > > iterations = 0 > count = 0 > while not( count == 4 or iterations == 20 ): > iterations += 1 > # ... > if generic_condition: > count += 1 > # ... > m = (1, 10, 100, 100)[count] Add one extra 100 there. >> Is there a better solution to solve this problem? > > Define "better". Do you mean faster, more clear, shorter, using less > memory, what? > > Above I've assumed that you want to get rid of the try block, since > that's what you're asking about: > > >> and, generally speaking, the try..except block slow down the execution >> of the program or not? > > Probably, but don't think about it. Python programming is at a level > where that kind of efficiency doesn't count. Or, ideally it shouldn't > count. > > > Cheers & hth., > > - Alf From alfps at start.no Tue Mar 2 13:04:21 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Mar 2010 19:04:21 +0100 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: * Alf P. Steinbach: > * Alf P. Steinbach: >> * Tracubik: >>> hi, i've to convert from Pascal this code: >>> >>> iterations=0; >>> count=0; >>> REPEAT; >>> iterations = iterations+1; >>> ... >>> IF (genericCondition) THEN count=count+1; >>> ... >>> CASE count OF: >>> 1: m = 1 >>> 2: m = 10 >>> 3: m = 100 >> >> Uhm, is this syntactically valid Pascal? As I recall, every Pascal >> construct was delimited in some way. Once I had the complete Pascal >> syntax in my head, but alas, not anymore... >> >> >>> UNTIL count = 4 OR iterations = 20 >>> >>> i do something like this: >>> >>> iterations = 0 >>> count = 0 >>> >>> m_Switch = (1,10,100) >>> >>> while True: >>> iterations +=1 >>> ... >>> if (genericCondition): >>> count +=1 >>> ... >>> try: >>> m = m_Switch[count-1] >>> except: pass >>> if count = 4 or iterations = 20 >>> >>> the problem is that when count = 4 m_Switch[4-1] have no value, so i >>> use the try..except. >> >> iterations = 0 >> count = 0 >> while not( count == 4 or iterations == 20 ): >> iterations += 1 >> # ... >> if generic_condition: >> count += 1 >> # ... >> m = (1, 10, 100, 100)[count] > > Add one extra 100 there. Oh dear, it's one of those days. if 1 <= count <= 3: m = (1, 10, 100)[count - 1] >>> Is there a better solution to solve this problem? >> >> Define "better". Do you mean faster, more clear, shorter, using less >> memory, what? >> >> Above I've assumed that you want to get rid of the try block, since >> that's what you're asking about: >> >> >>> and, generally speaking, the try..except block slow down the >>> execution of the program or not? >> >> Probably, but don't think about it. Python programming is at a level >> where that kind of efficiency doesn't count. Or, ideally it shouldn't >> count. >> >> >> Cheers & hth., >> >> - Alf From jeanmichel at sequans.com Tue Mar 2 13:05:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Mar 2010 19:05:25 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100302184056.743a71e7@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> Message-ID: <4B8D5365.9060502@sequans.com> Andreas Waldenburger wrote: > On Tue, 02 Mar 2010 09:48:47 +1100 Ben Finney > wrote: > > >>> It's not our concern. >>> >> Then I don't see what that problem is. >> > > There is none. I was griping about how stupid they are. That is a > personal problem I have with their *code* (not software), and I thought > I'd just share my superiority complex with everyone. > > I had hoped that everyone just read it, went like "Oh geez.", smiled it > off with a hint of lesson learned and got back to whatever it was they > were doing. Alas, I was wrong ... and I'm sorry. > > /W > > There's something wrong saying that stupid people write working code that totally satisfies your needs. Don't you agree ? ;-) JM From python at rcn.com Tue Mar 2 13:18:54 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 2 Mar 2010 10:18:54 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Message-ID: On Mar 2, 8:29?am, Veloz wrote: > Hi all > I'm looking for a queue that I can use with multiprocessing, which has > a peek method. > > I've seen some discussion about queue.peek but don't see anything in > the docs about it. > > Does python have a queue class with peek semantics? Am curious about your use case? Why peek at something that could be gone by the time you want to use it. val = q.peek() if something_i_want(val): v2 = q.get() # this could be different than val Wouldn't it be better to just get() the value and return if you don't need it? val = q.peek() if not something_i_want(val): q.put(val) Raymond From python at mrabarnett.plus.com Tue Mar 2 13:21:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 18:21:02 +0000 Subject: conditional import into global namespace In-Reply-To: References: Message-ID: <4B8D570E.5070804@mrabarnett.plus.com> mk wrote: > Hello everyone, > > I have a class that is dependent on subprocess functionality. I would > like to make it self-contained in the sense that it would import > subprocess if it's not imported yet. > > What is the best way to proceed with this? > > I see a few possibilities: > > 1. do a class level import, like: > > class TimeSync(object): > > import subprocess > > > 2. do an import in init, which is worse bc it's ran every time an > instance is created: > > def __init__(self, shiftsec, ntpserver): > import subprocess > > > Both of those methods have disadvantage in this context, though: they > create 'subprocess' namespace in a class or instance, respectively. > > Is there anyway to make it a global import? > The simplest solution is just import it at the top of the module. From tjreedy at udel.edu Tue Mar 2 13:25:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Mar 2010 13:25:16 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <1267539898.477222.7.camel@necropolis> References: <1267539898.477222.7.camel@necropolis> Message-ID: On 3/2/2010 9:24 AM, Albert Hopkins wrote: > I have a snippet of code that looks like this: > > pid, fd = os.forkpty() > if pid == 0: > subprocess.call(args) > else: > input = os.fdopen(fd).read() > ... > > > This seems to work find for CPython 2.5 and 2.6 on my Linux system. To get help, or report a bug, for something like this, be as specific as possible. 'Linux' may be too generic. > However, with CPython 3.1 I get: > > input = os.fdopen(fd).read() > IOError: [Errno 5] Input/output error > > Is there something wrong in Python 3.1? Is this the correct way to do > this (run a process in a pseudo-tty and read it's output) or is there > another way I should/could be doing this? No idea, however, the first thing I would do is call the .fdopen and .read methods separately (on separate lines) to isolate which is raising the error. tjr From python at mrabarnett.plus.com Tue Mar 2 13:26:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 18:26:08 +0000 Subject: case do problem In-Reply-To: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <4B8D5840.4070601@mrabarnett.plus.com> Tracubik wrote: > hi, i've to convert from Pascal this code: > > iterations=0; > count=0; > REPEAT; > iterations = iterations+1; > ... > IF (genericCondition) THEN count=count+1; > ... > CASE count OF: > 1: m = 1 > 2: m = 10 > 3: m = 100 > UNTIL count = 4 OR iterations = 20 > > i do something like this: > > iterations = 0 > count = 0 > > m_Switch = (1,10,100) > > while True: > iterations +=1 > ... > if (genericCondition): > count +=1 > ... > try: > m = m_Switch[count-1] > except: pass > if count = 4 or iterations = 20 > > the problem is that when count = 4 m_Switch[4-1] have no value, so i use > the try..except. > > Is there a better solution to solve this problem? and, generally > speaking, the try..except block slow down the execution of the program or > not? > Use a dict: m_Switch = {1: 1, 2: 10, 3: 100} and then catch the KeyError. Don't use a bare 'except', catch the specific exception you want to catch, and don't worry about the speed unless you discover that it's real problem. From malaclypse2 at gmail.com Tue Mar 2 13:31:13 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 2 Mar 2010 13:31:13 -0500 Subject: conditional import into global namespace In-Reply-To: References: Message-ID: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> On Tue, Mar 2, 2010 at 12:46 PM, mk wrote: > Hello everyone, > > I have a class that is dependent on subprocess functionality. I would like > to make it self-contained in the sense that it would import subprocess if > it's not imported yet. > > What is the best way to proceed with this? Just import subprocess at the top of your module. If subprocess hasn't been imported yet, it will be imported when your module is loaded. If it's already been imported, your module will use the cached version that's already been imported. In other words, it sounds like Python already does what you want. You don't need to do anything special. -- Jerry From a_jtim at bellsouth.net Tue Mar 2 13:31:50 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Tue, 2 Mar 2010 10:31:50 -0800 (PST) Subject: freebsd and multiprocessing References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> Message-ID: <4079148c-3690-4c24-b3db-79f685bf8eab@q15g2000yqj.googlegroups.com> On Mar 2, 12:59?pm, Tim Arnold wrote: > On Mar 2, 11:52?am, Philip Semanchuk wrote: > > On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: > > > > Hi, > > > I'm intending to use multiprocessing on a freebsd machine (6.3 > > > release, quad core, 8cpus, amd64). I see in the doc that on this > > > platform I can't use synchronize: > > > > ImportError: This platform lacks a functioning sem_open > > > implementation, therefore, the required synchronization primitives > > > needed will not function, see issue 3770. > > > > As far as I can tell, I have no need to synchronize the processes--I > > > have several processes run separately and I need to know when they're > > > all finished; there's no communication between them and each owns its > > > own log file for output. > > > > Is anyone using multiprocessing on FreeBSD and run into any other > > > gotchas? > > > Hi Tim, > > I don't use multiprocessing but I've written two low-level IPC ? > > packages, one for SysV IPC and the other for POSIX IPC. > > > I think that multiprocessing prefers POSIX IPC (which is where ? > > sem_open() comes from). I don't know what it uses if that's not ? > > available, but SysV IPC seems a likely alternative. I must emphasize, ? > > however, that that's a guess on my part. > > > FreeBSD didn't have POSIX IPC support until 7.0, and that was sort of ? > > broken until 7.2. As it happens, I was testing my POSIX IPC code ? > > against 7.2 last night and it works just fine. > > > SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is the ? > > oldest I've tested). ISTR that by default each message queue is ? > > limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably ? > > tell you that and may even let you change it. Other than that I can't ? > > think of any SysV limitations that might bite you. > > > HTH > > Philip > > Hi Philip, > Thanks for that information. I wish I could upgrade the machine to > 7.2! alas, out of my power. ?I get the following results from sysctl: > % sysctl kern.ipc | grep msg > kern.ipc.msgseg: 2048 > kern.ipc.msgssz: 8 > kern.ipc.msgtql: 40 > kern.ipc.msgmnb: 2048 > kern.ipc.msgmni: 40 > kern.ipc.msgmax: 16384 > > I'll write some test programs using multiprocessing and see how they > go before committing to rewrite my current code. I've also been > looking at 'parallel python' although it may have the same issues.http://www.parallelpython.com/ > > thanks again, > --Tim Well that didn't work out well. I can't import either Queue or Pool from multiprocessing, so I'm back to the drawing board. I'll see now how parallel python does on freebsd. --Tim From mrkafk at gmail.com Tue Mar 2 13:33:31 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 19:33:31 +0100 Subject: Email Script In-Reply-To: <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> Message-ID: Where do you take class Email from? There's no info in your mail on this. Regards, mk From victorsubervi at gmail.com Tue Mar 2 13:37:43 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 2 Mar 2010 14:37:43 -0400 Subject: Email Script In-Reply-To: <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> <4dc0cfea1003020856x2146652ahaa1537d15c05c347@mail.gmail.com> Message-ID: <4dc0cfea1003021037wb1a60a0y8966e00489954f48@mail.gmail.com> On Tue, Mar 2, 2010 at 12:56 PM, Victor Subervi wrote: > On Tue, Mar 2, 2010 at 11:53 AM, Victor Subervi wrote: > >> On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi wrote: >> >>> Hi; >>> I have the following code: >>> >>> def my_mail(): >>> user, passwd, db, host = login() >>> database = MySQLdb.connect(host, user, passwd, db) >>> cursor= database.cursor() >>> ourEmail1 = 'marilyn at globalsolutionsgroup.vi' >>> ourEmail1 = 'phil at globalsolutionsgroup.vi' >>> ourEmail2 = 'benoismyname at gmail.com' >>> form = cgi.FieldStorage() >>> name = form.getfirst('name', '') >>> email = form.getfirst('from', '') >>> message = form.getfirst('message', '') >>> message = 'Name: %s\nMessage: %s' % (name, message) >>> subject = 'Message from Web Site' >>> Email( >>> from_address = email, >>> to_address = ourEmail1, >>> subject = subject, >>> message = message >>> ).send() >>> Email( >>> from_address = email, >>> to_address = ourEmail2, >>> subject = subject, >>> message = message >>> ).send() >>> print 'Thank you, %s, we will get back to you shortly!
' % (name) >>> >>> This sends only the first of the two emails. Why doesn't it work to send >>> the second? What do? >>> TIA, >>> beno >>> >> >> Should I put a timer between instances of Email? >> >>> >>> Adding a timer didn't work. Do I need to explicitly close the smtp > connection before sending the next email? I don't understand why there's a > problem. > TIA, > beno > Seems like the problem was I had to import simplemail for each of the my_email functions. beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Mar 2 13:39:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 02 Mar 2010 12:39:10 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On 2010-03-02 11:59 AM, Terry Reedy wrote: > On 3/2/2010 11:34 AM, Robert Kern wrote: >> On 2010-03-01 22:55 PM, Terry Reedy wrote: >>> On 3/1/2010 7:56 PM, Patrick Maupin wrote: >>>> On Mar 1, 5:57 pm, Erik Max Francis wrote: >>>>> Patrick Maupin wrote: >>>>> This not only seriously stretching the meaning of the term "superset" >>>>> (as Python is most definitely not even remotely a superset of JSON), >>>>> but >>>> >>>> Well, you are entitled to that opinion, but seriously, if I take valid >>>> JSON, replace unquoted true with True, unquoted false with False, >>>> replace unquoted null with None, and take the quoted strings and >>>> replace occurrences of \uXXXX with the appropriate unicode, then I do, >>>> in fact, have valid Python. But don't take my word for it -- try it >>>> out! >>> >>> To me this is so strained that I do not see why why you are arguing the >>> point. So what? The resulting Python 'program' will be equivalent, I >>> believe, to 'pass'. Ie, construct objects and then discard them with no >>> computation or output. >> >> Not if you eval() rather than exec(). > > >>> eval(1) > > creates and objects and discards it, with a net result of 'pass'. > What do you think I am missing. x = eval('1') > It's reasonably well-accepted that >> JSON is very close to being a subset of Python's expression syntax with >> just a few modifications. > > It is specifically JavaScript Object Notation, which is very similar to > a subset of Python's object notation (number and string literals and > list and dict displays (but not set displays), and three named > constants). Without operators, it barely qualifies, to me, even as > 'expression syntax'. Literal expression syntax, then. -- 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 From albert at spenarnc.xs4all.nl Tue Mar 2 13:48:59 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 02 Mar 2010 18:48:59 GMT Subject: Writing an assembler in Python References: Message-ID: In article , Giorgos Tzampanakis wrote: >I'm implementing a CPU that will run on an FPGA. I want to have a >(dead) simple assembler that will generate the machine code for >me. I want to use Python for that. Are there any libraries that >can help me with the parsing of the assembly code? I have a pentium assembler in perl on my website below. (postit-fixup principle). You could borrow some idea's, if you can read perl. The main purpose is to have a very simple and straightforward assembler at the expense of ease of use. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From michaelveloz at gmail.com Tue Mar 2 14:02:08 2010 From: michaelveloz at gmail.com (Veloz) Date: Tue, 2 Mar 2010 11:02:08 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Message-ID: <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> On Mar 2, 1:18?pm, Raymond Hettinger wrote: > On Mar 2, 8:29?am, Veloz wrote: > > > Hi all > > I'm looking for a queue that I can use with multiprocessing, which has > > a peek method. > > > I've seen some discussion about queue.peek but don't see anything in > > the docs about it. > > > Does python have a queue class with peek semantics? > > Am curious about your use case? ?Why peek at something > that could be gone by the time you want to use it. > > ? val = q.peek() > ? if something_i_want(val): > ? ? ? ?v2 = q.get() ? ? ? ? # this could be different than val > > Wouldn't it be better to just get() the value and return if you don't > need it? > > ? val = q.peek() > ? if not something_i_want(val): > ? ? ? q.put(val) > > Raymond Yeah, I hear you. Perhaps queue is not the best solution. My highest level use case is this: The user visits a web page (my app is a Pylons app) and requests a "report" be created. The report takes too long to create and display on the spot, so the user expects to visit some url "later" and see if the specific report has completed, and if so, have it returned to them. At a lower level, I'm thinking of using some process workers to create these reports in the background; there'd be a request queue (into which requests for reports would go, each with an ID) and a completion queue, into which the workers would write an entry when a report was created, along with an ID matching the original request. The "peek" parts comes in when the user comes back later to see if their report has done. That is, in my page controller logic, I'd like to look through the complete queue and see if the specific report has been finished (I could tell by matching up the ID of the original request to the ID in the completed queue). If there was an item in the queue matching the ID, it would be removed. It's since occurred to me that perhaps a queue is not the best way to handle the completions. (We're ignoring the file system as a solution for the time being, and focusing on in-memory structures). I'm wondering now if a simple array of completed items wouldn't be better. Of course, all the access to the array would have to be thread/process- proof. As you pointed out, for example, multi-part operations such as "is such-and-such an ID in the list? If so, remove it and return in" would have to be treated atomically to avoid concurrency issues. Any thoughts on this design approach are welcomed :-) Michael From philip at semanchuk.com Tue Mar 2 14:28:57 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 2 Mar 2010 14:28:57 -0500 Subject: freebsd and multiprocessing In-Reply-To: <4079148c-3690-4c24-b3db-79f685bf8eab@q15g2000yqj.googlegroups.com> References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> <4079148c-3690-4c24-b3db-79f685bf8eab@q15g2000yqj.googlegroups.com> Message-ID: <83E70F2A-6024-4790-AA29-60908CB0CFC4@semanchuk.com> On Mar 2, 2010, at 1:31 PM, Tim Arnold wrote: > On Mar 2, 12:59 pm, Tim Arnold wrote: >> On Mar 2, 11:52 am, Philip Semanchuk wrote: >>> On Mar 2, 2010, at 11:31 AM, Tim Arnold wrote: >> >>>> Hi, >>>> I'm intending to use multiprocessing on a freebsd machine (6.3 >>>> release, quad core, 8cpus, amd64). I see in the doc that on this >>>> platform I can't use synchronize: >> >>>> ImportError: This platform lacks a functioning sem_open >>>> implementation, therefore, the required synchronization primitives >>>> needed will not function, see issue 3770. >> >>>> As far as I can tell, I have no need to synchronize the >>>> processes--I >>>> have several processes run separately and I need to know when >>>> they're >>>> all finished; there's no communication between them and each owns >>>> its >>>> own log file for output. >> >>>> Is anyone using multiprocessing on FreeBSD and run into any other >>>> gotchas? >> >>> Hi Tim, >>> I don't use multiprocessing but I've written two low-level IPC >>> packages, one for SysV IPC and the other for POSIX IPC. >> >>> I think that multiprocessing prefers POSIX IPC (which is where >>> sem_open() comes from). I don't know what it uses if that's not >>> available, but SysV IPC seems a likely alternative. I must >>> emphasize, >>> however, that that's a guess on my part. >> >>> FreeBSD didn't have POSIX IPC support until 7.0, and that was sort >>> of >>> broken until 7.2. As it happens, I was testing my POSIX IPC code >>> against 7.2 last night and it works just fine. >> >>> SysV IPC works under FreeBSD 6 (and perhaps earlier versions; 6 is >>> the >>> oldest I've tested). ISTR that by default each message queue is >>> limited to 2048 bytes in total size. 'sysctl kern.ipc' can probably >>> tell you that and may even let you change it. Other than that I >>> can't >>> think of any SysV limitations that might bite you. >> >>> HTH >>> Philip >> >> Hi Philip, >> Thanks for that information. I wish I could upgrade the machine to >> 7.2! alas, out of my power. I get the following results from sysctl: >> % sysctl kern.ipc | grep msg >> kern.ipc.msgseg: 2048 >> kern.ipc.msgssz: 8 >> kern.ipc.msgtql: 40 >> kern.ipc.msgmnb: 2048 >> kern.ipc.msgmni: 40 >> kern.ipc.msgmax: 16384 >> >> I'll write some test programs using multiprocessing and see how they >> go before committing to rewrite my current code. I've also been >> looking at 'parallel python' although it may have the same issues.http://www.parallelpython.com/ >> >> thanks again, >> --Tim > > Well that didn't work out well. I can't import either Queue or Pool > from multiprocessing, so I'm back to the drawing board. I'll see now > how parallel python does on freebsd. Sorry to hear that didn't work for you. Should you need to get down to the nuts & bolts level, my module for SysV IPC is here: http://semanchuk.com/philip/sysv_ipc/ Good luck with Parallel Python, Philip From pmaupin at gmail.com Tue Mar 2 14:30:32 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 2 Mar 2010 11:30:32 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: On Mar 2, 11:59?am, Terry Reedy wrote: > To me, comparing object notation with programming language is not > helpful to the OP's purpose. Yes, I agree, it was a distraction. I fell into the trap of responding to the ludicrous claim that "if X is a superset of Y, then X cannot possibly look better than Y" (a claim made by multiple people all thinking it was clever) by showing that Y has other supersets that do in fact look better than Y. In doing this, I made the mistake of choosing a superset of an analogue to Y, rather than to Y itself. When called out on it, I showed that, in fact, the actual X that IS a superset of Y can be used in a way that looks better. However, you are right that JSON is such a small subset of JS that it's really pretty ridiculous to even compare them, but that still makes the point that the original argument I was trying to refute is completely specious. In retrospect, though, I should have chosen a better way to make that point, because I let myself get caught up in making and then defending a flippant statement that I don't really care about one way or the other. > His main claim is that JSON can be usefully > extended but that YAML is too much, so that perhaps he, with help, can > find a 'sweet spot' in between. An excellent summary of my position. Thanks, Pat From python at mrabarnett.plus.com Tue Mar 2 14:44:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Mar 2010 19:44:53 +0000 Subject: Queue peek? In-Reply-To: <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: <4B8D6AB5.8010408@mrabarnett.plus.com> Veloz wrote: > On Mar 2, 1:18 pm, Raymond Hettinger wrote: >> On Mar 2, 8:29 am, Veloz wrote: >> >>> Hi all >>> I'm looking for a queue that I can use with multiprocessing, which has >>> a peek method. >>> I've seen some discussion about queue.peek but don't see anything in >>> the docs about it. >>> Does python have a queue class with peek semantics? >> Am curious about your use case? Why peek at something >> that could be gone by the time you want to use it. >> >> val = q.peek() >> if something_i_want(val): >> v2 = q.get() # this could be different than val >> >> Wouldn't it be better to just get() the value and return if you don't >> need it? >> >> val = q.peek() >> if not something_i_want(val): >> q.put(val) >> >> Raymond > > Yeah, I hear you. Perhaps queue is not the best solution. My highest > level use case is this: The user visits a web page (my app is a > Pylons app) and requests a "report" be created. The report takes too > long to create and display on the spot, so the user expects to visit > some url "later" and see if the specific report has completed, and if > so, have it returned to them. > > At a lower level, I'm thinking of using some process workers to create > these reports in the background; there'd be a request queue (into > which requests for reports would go, each with an ID) and a completion > queue, into which the workers would write an entry when a report was > created, along with an ID matching the original request. > > The "peek" parts comes in when the user comes back later to see if > their report has done. That is, in my page controller logic, I'd like > to look through the complete queue and see if the specific report has > been finished (I could tell by matching up the ID of the original > request to the ID in the completed queue). If there was an item in the > queue matching the ID, it would be removed. > > It's since occurred to me that perhaps a queue is not the best way to > handle the completions. (We're ignoring the file system as a solution > for the time being, and focusing on in-memory structures). I'm > wondering now if a simple array of completed items wouldn't be better. > Of course, all the access to the array would have to be thread/process- > proof. As you pointed out, for example, multi-part operations such as > "is such-and-such an ID in the list? If so, remove it and return in" > would have to be treated atomically to avoid concurrency issues. > > Any thoughts on this design approach are welcomed :-) > A set of completed reports, or a dict with the ID as the key? The advantage of a dict is that the value could contain several bits of information, such as when it was completed, the status (OK or failed), etc. You might want to wrap it in a class with locks (mutexes) to ensure it's threadsafe. From martin.hellwig at dcuktec.org Tue Mar 2 14:58:22 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 02 Mar 2010 19:58:22 +0000 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: On 03/02/10 19:44, MRAB wrote: > information, such as when it was completed, the status (OK or failed), > etc. You might want to wrap it in a class with locks (mutexes) to ensure > it's threadsafe. What actually happens if multiple threads at the same time, write to a shared dictionary (Not using the same key)? I would think that if the hashing part of the dictionary has some sort of serialization (please forgive me if I misuse a term) it should 'just work'(tm)? -- mph From marduk at python.net Tue Mar 2 15:22:27 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 15:22:27 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: References: <1267539898.477222.7.camel@necropolis> Message-ID: <1267561347.4507.5.camel@necropolis> On Tue, 2010-03-02 at 13:25 -0500, Terry Reedy wrote: > To get help, or report a bug, for something like this, be as specific as > possible. 'Linux' may be too generic. This is on Python on Gentoo Linux x64 with kernel 2.6.33. > > > However, with CPython 3.1 I get: > > > > input = os.fdopen(fd).read() > > IOError: [Errno 5] Input/output error > > > > Is there something wrong in Python 3.1? Is this the correct way to do > > this (run a process in a pseudo-tty and read it's output) or is there > > another way I should/could be doing this? > > No idea, however, the first thing I would do is call the .fdopen and > .read methods separately (on separate lines) to isolate which is raising > the error. The exception occurs on the read() method. From marduk at python.net Tue Mar 2 15:22:58 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 15:22:58 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <4B8D4BB8.8020909@mrabarnett.plus.com> References: <1267539898.477222.7.camel@necropolis> <4B8D4BB8.8020909@mrabarnett.plus.com> Message-ID: <1267561378.4507.6.camel@necropolis> On Tue, 2010-03-02 at 17:32 +0000, MRAB wrote: > The documentation also mentions the 'pty' module. Have you tried that > instead? I haven't but I'll give it a try. Thanks. -a From daniel at stutzbachenterprises.com Tue Mar 2 15:33:33 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Tue, 2 Mar 2010 14:33:33 -0600 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: On Tue, Mar 2, 2010 at 1:58 PM, Martin P. Hellwig < martin.hellwig at dcuktec.org> wrote: > What actually happens if multiple threads at the same time, write to a > shared dictionary (Not using the same key)? > All of Python's built-in types are thread safe. Both updates will happen. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Tue Mar 2 15:41:44 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 21:41:44 +0100 Subject: conditional import into global namespace In-Reply-To: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> References: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> Message-ID: Jerry Hill wrote: > Just import subprocess at the top of your module. If subprocess > hasn't been imported yet, it will be imported when your module is > loaded. If it's already been imported, your module will use the > cached version that's already been imported. > > In other words, it sounds like Python already does what you want. You > don't need to do anything special. Oh, thanks! Hmm it's different than dealing with packages I guess -- IIRC, in packages only code in package's __init__.py was executed? Regards, mk From popuser at christest2.dc.k12us.com Tue Mar 2 15:57:36 2010 From: popuser at christest2.dc.k12us.com (Pop User) Date: Tue, 02 Mar 2010 15:57:36 -0500 Subject: freebsd and multiprocessing In-Reply-To: <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> References: <7cabdddf-d936-48c7-9b76-97c37def5f8f@z35g2000yqd.googlegroups.com> <5c8d7d72-710a-41c1-897e-8d5605c61373@e7g2000yqf.googlegroups.com> Message-ID: <4B8D7BC0.6010109@christest2.dc.k12us.com> On 3/2/2010 12:59 PM, Tim Arnold wrote: > > I'll write some test programs using multiprocessing and see how they > go before committing to rewrite my current code. I've also been > looking at 'parallel python' although it may have the same issues. > http://www.parallelpython.com/ > parallelpython works for me on FreeBSD 6.2. From matt at sidefx.com Tue Mar 2 15:59:15 2010 From: matt at sidefx.com (Matt Chaput) Date: Tue, 02 Mar 2010 15:59:15 -0500 Subject: Multiprocessing problem Message-ID: <4B8D7C23.7050905@sidefx.com> Hi, I'm having a problem with the multiprocessing package. I'm trying to use a simple pattern where a supervisor object starts a bunch of worker processes, instantiating them with two queues (a job queue for tasks to complete and an results queue for the results). The supervisor puts all the jobs in the "job" queue, then join()s the workers, and then pulls all the completed results off the "results" queue. (I don't think I can just use something like Pool.imap_unordered for this because the workers need to be objects with state.) Here's a simplified example: http://pastie.org/850512 The problem is that seemingly randomly, but almost always, the worker processes will deadlock at some point and stop working before they complete. This will leave the whole program stalled forever. This seems more likely the more work each worker does (to the point where adding the time.sleep(0.01) as seen in the example code above guarantees it). The problem seems to occur on both Windows and Mac OS X. I've tried many random variations of the code (e.g. using JoinableQueue, calling cancel_join_thread() on one or both queues even though I have no idea what it does, etc.) but keep having the problem. Am I just using multiprocessing wrong? Is this a bug? Any advice? Thanks, Matt From rfritz at u.washington.edu Tue Mar 2 16:14:50 2010 From: rfritz at u.washington.edu (R Fritz) Date: Tue, 2 Mar 2010 13:14:50 -0800 Subject: cpan for python? References: Message-ID: On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: > > On Feb 28, 2010, at 9:28 AM, Someone Something wrote: > >> Is there something like cpan for python? I like python's syntax, but >> Iuse perl because of cpan and the tremendous modules that it has. -- > > Please search the mailing list archives. > > This subject has been discussed to absolute death. But somehow the question is not in the FAQ, though the answer is. See: -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From ben+python at benfinney.id.au Tue Mar 2 16:22:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 08:22:40 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <20100302183527.47c6e8f5@geekmail.INVALID> Message-ID: <878waazae7.fsf@benfinney.id.au> Andreas Waldenburger writes: > Don't get me wrong; our whole system is more fragile than I find > comfortable. But I guess getting 10ish different parties around the > globe to work in complete unison is quite a feat, and I'm surprised it > even works as it is. But it does, and I'm glad we don't have to > micromanage other people's code. It's rather odd that you think of ?require general quality standards, independently measurable and testable? to be ?micromanaging?. I guess that when even the *customers* will resist implementing such quality expectations, it's little surprise that the vendors continue to push out such shoddy work on their customers. -- \ ?Why am I an atheist? I ask you: Why is anybody not an atheist? | `\ Everyone starts out being an atheist.? ?Andy Rooney, _Boston | _o__) Globe_ 1982-05-30 | Ben Finney From davea at ieee.org Tue Mar 2 16:23:34 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 02 Mar 2010 16:23:34 -0500 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> <4B8D3A3A.8030501@optimum.net> Message-ID: <4B8D81D6.4070001@ieee.org> Terry Reedy wrote: > On 3/2/2010 11:18 AM, John Posner wrote: >> On 3/2/2010 10:19 AM, Roy Smith wrote: >>> >>> Somewhat sadly, in my case, I can't even machine process the header >>> file. I don't, strictly speaking, have a header file. What I have is >>> a PDF which documents what's in the header file, and I'm manually re- >>> typing the data out of that. Sigh. > > There are Python modules to read/write pdf. > >> Here's an idea, perhaps too obvious, to minimize your keystrokes: >> >> 1. Create a text file with the essential data: >> >> XYZ_FOO 0 The foo property >> XYZ_BAR 1 The bar property >> XYZ_BAZ 2 reserved for future use >> >> 2. Use a Python script to convert this into the desired code: >> >> declare('XYZ_FOO', 0, "The foo property") >> declare('XYZ_BAR', 1, "The bar property") >> declare('XYZ_BAZ', 2, "reserved for future use") >> >> Note: >> >> >>> s >> 'XYZ_FOO 0 The foo property' >> >>> s.split(None, 2) >> ['XYZ_FOO', '0', 'The foo property'] > > Given that set of triples is constant, I would think about having the > Python script do the computation just once, instead of with every > inport. In other words, the script should *call* the declare function > and then write out the resulting set of dicts either to a .py or > pickle file. > > tjr > > There have been lots of good suggestions in this thread. Let me give you my take: 1) you shouldn't want to clutter up the global dictionary of your main processing module. There's too much risk of getting a collision, either with the functions you write, or with some builtin. That's especially true if you might later want to use a later version of that pdf file. Easiest solution for your purposes, make it a separate module. Give it a name like defines, and in your main module, you use import defines print defines.XYZ_FOO And if that's too much typing, you can do: import defines as I print I.XYZ_FOO Next problem is to parse that pdf file. One solution is to use a pdf library. But another is to copy/paste it into a text file, and parse that. Assuming it'll paste, and that the lines you want are recognizable (eg. they all begin as #define), the parsing should be pretty easy. The results of the parsing is a file defines.py Now, if the pdf ever changes, rerun your parsing program. But don't run it every time your application runs. If the pdf file were changing often, then I'd have a different answer: 2) define an empty class, just as a placeholder, and make one instance I Populate a class instance I with setattrib() calls, but access it with direct syntax, same as our first example. DaveA From ben+python at benfinney.id.au Tue Mar 2 16:25:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 08:25:13 +1100 Subject: Broken references in postings References: Message-ID: <874okyza9y.fsf@benfinney.id.au> Grant Edwards writes: > Or is it just individual news/mail clients that are broken? This, I believe. Many clients mess up the References and In-Reply-To fields, in the face of many years of complaint to the vendors. Most free-software clients get it right, AFAICT. -- \ ?Contentment is a pearl of great price, and whosoever procures | `\ it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.? ?J. Balguy | Ben Finney From dont.spam.holgerm1969 at gmx.de Tue Mar 2 16:26:59 2010 From: dont.spam.holgerm1969 at gmx.de (Holger Mueller) Date: Tue, 2 Mar 2010 22:26:59 +0100 Subject: Writing an assembler in Python References: Message-ID: Giorgos Tzampanakis wrote: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. I want to use Python for that. Are there any libraries that > can help me with the parsing of the assembly code? Why coding assembler if you can type in hexdumps... scnr Holger -- http://www.kati-und-holger.de/holgersblog.php From MLMDev at Comcast.net Tue Mar 2 16:48:08 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Tue, 2 Mar 2010 16:48:08 -0500 Subject: CGI, POST, and file uploads Message-ID: <5F601006-5DCE-4353-BD04-DFABDFA8C5D2@Comcast.net> Can someone tell me how to upload the contents of a (relatively small) file using an HTML form and CGI in Python 3.1? As far as I can tell from a half-day of experimenting, browsing, and searching the Python issue tracker, this is broken. Very simple example:



cgi-test.py: #!/usr/local/bin/python3 import cgi import sys form = cgi.FieldStorage() print(form.getfirst('contents'), file=sys.stderr) print('done') I run a CGI server with: #!/usr/bin/env python3 from http.server import HTTPServer, CGIHTTPRequestHandler HTTPServer(('', 9000), CGIHTTPRequestHandler).serve_forever() What happens is that the upload never stops. It works in 2.6. If I cancel the upload from the browser, I get the following output, so I know that basically things are working; the cgi script just never finishes reading the POST input: localhost - - [02/Mar/2010 16:37:36] "POST /cgi/cgi-test.py HTTP/1.1" 200 - <<>> ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 55779) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 307, in process_request self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socketserver.py", line 614, in __init__ self.handle() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 352, in handle self.handle_one_request() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 346, in handle_one_request method() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 868, in do_POST self.run_cgi() File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/http/server.py", line 1045, in run_cgi if not self.rfile.read(1): File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ python3.1/socket.py", line 214, in readinto return self._sock.recv_into(b) socket.error: [Errno 54] Connection reset by peer ---------------------------------------- From usenot at geekmail.INVALID Tue Mar 2 16:51:56 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 22:51:56 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> Message-ID: <20100302225156.67171851@geekmail.INVALID> On Tue, 02 Mar 2010 19:05:25 +0100 Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: > > > > I had hoped that everyone just read it, went like "Oh geez.", > > smiled it off with a hint of lesson learned and got back to > > whatever it was they were doing. Alas, I was wrong ... and I'm > > sorry. > > > There's something wrong saying that stupid people write working code > that totally satisfies your needs. Don't you agree ? ;-) > No, in fact I don't. It works. They are supposed to make it work. And that's what they do. Whether or not they put their docstrings in the place they should does not change that their code works. Sorry, you guys drained all the funny out of me. /W -- INVALID? DE! From mrkafk at gmail.com Tue Mar 2 16:54:39 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Mar 2010 22:54:39 +0100 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: Daniel Stutzbach wrote: > On Tue, Mar 2, 2010 at 1:58 PM, Martin P. Hellwig > > wrote: > > What actually happens if multiple threads at the same time, write to > a shared dictionary (Not using the same key)? > All of Python's built-in types are thread safe. Both updates will happen. No need to use synchro primitives like locks? I know that it may work, but that strikes me as somehow wrong... I'm used to using things like Lock().acquire() and Lock().release() when accessing shared data structures, whatever they are. Although trying to do the "right thing" may indeed get one in trouble in case of deadlock caused by a bug in one's own program. Regards, mk From eike.welk at gmx.net Tue Mar 2 17:00:29 2010 From: eike.welk at gmx.net (Eike Welk) Date: Tue, 02 Mar 2010 23:00:29 +0100 Subject: Method / Functions - What are the differences? References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> Message-ID: John Posner wrote: > I've updated the text at this location: > > > http://cl1p.net/bruno_0301.rst/ I think this is a very useful writeup! It would be perfect with a little bit of introduction that says: 1. - What it is: "The rough details of method look-up"; 2. - which contains some of the questions that that made that authors write the text. This way people with similar questions can find it with Google. Additionally the link to the relevant section in the Python documentation would be great. I can't find it! A link to an article about the details of class creation and metaclasses would be good too. Thanks for writing this great little text, Eike. From jkrukoff at ltgc.com Tue Mar 2 17:08:43 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Tue, 02 Mar 2010 15:08:43 -0700 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: <1267567723.4101.28.camel@localhost.localdomain> On Tue, 2010-03-02 at 22:54 +0100, mk wrote: > No need to use synchro primitives like locks? > > I know that it may work, but that strikes me as somehow wrong... I'm > used to using things like Lock().acquire() and Lock().release() when > accessing shared data structures, whatever they are. This is one of those places where the GIL is a good thing, and makes your life simpler. You could consider it that the interpreter does the locking for you for such primitive operations, if you like. -- John Krukoff Land Title Guarantee Company From usenot at geekmail.INVALID Tue Mar 2 17:19:09 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Tue, 2 Mar 2010 23:19:09 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <20100302183527.47c6e8f5@geekmail.INVALID> <878waazae7.fsf@benfinney.id.au> Message-ID: <20100302231909.6a5bad2d@geekmail.INVALID> On Wed, 03 Mar 2010 08:22:40 +1100 Ben Finney wrote: > Andreas Waldenburger writes: > > > Don't get me wrong; our whole system is more fragile than I find > > comfortable. But I guess getting 10ish different parties around the > > globe to work in complete unison is quite a feat, and I'm surprised > > it even works as it is. But it does, and I'm glad we don't have to > > micromanage other people's code. > > It's rather odd that you think of ?require general quality standards, > independently measurable and testable? to be ?micromanaging?. > I should know better than to argue these things, but I don't. Hmph. We demand testable quality standards, but not of their code. We demand it of their software. We say *what* we want, they decide *how* they'll do it. Noncompliance will be fined, by a contractually agreed amount. Everything beyond that is micromanaging and detracts workforce from the stuff *we* have to do. We are in exactly the same kind of bond with a company that buys our system (and support). I have yet to see any one of them demand to see how we write our code. Why should they care? (Rhetorical question, I refuse to discuss this any further.) > I guess that when even the *customers* will resist implementing such > quality expectations, it's little surprise that the vendors continue > to push out such shoddy work on their customers. > When I'm building bicycles I can go to the trouble of going by what method of galvanization my tires are produced. Or I save myself the trouble and just take the best offer and hold them responsible when they don't deliver on their promise. Both possible, both work, and both appropriate in certain situations. You can keep discussing if you want, I've said more than I was hoping to. /W -- INVALID? DE! From albert at spenarnc.xs4all.nl Tue Mar 2 17:38:11 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 02 Mar 2010 22:38:11 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: In article , Mel wrote: >Jean-Michel Pichavant wrote: >> Andreas Waldenburger wrote: >>> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >>> wrote: >>>> Reminiscent of: >>>> mov AX,BX ; Move the contents of BX into AX > >>> Well, there might be some confusion there as to what gets moved where, >>> wouldn't you say? I guess this goes away after a couple of months, >>> though. > >> I agree to that statement, I was surprised that mov AX,BX assumes that >> BX is the source, and AX the destination. I never programmed in >> assembler though. > >You could think of it as a not bad use of the design principle "Clear The >Simple Stuff Out Of The Way First". Destinations are commonly a lot simpler >than sources -- just as in Python assignment statements. So you can tell >more or less at a glance what's going to be changed, then get into the deep >analysis to find what it's going to be changed to. The real background is that a very long time ago at Intel the first guy that wrote an assembler, got it "wrong", i.e. violated the conventions established already at the time. No nothing clever, nothing conscious, just reinventing the wheel badly. Next time you tell me that the MSDOS "file" system was well thought out :-) > Mel. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From verace at bohlsenrestaurants.com Tue Mar 2 17:39:46 2010 From: verace at bohlsenrestaurants.com (Sugar Dining Den and Social Club) Date: Tue, 02 Mar 2010 14:39:46 -0800 Subject: Verace Hospitality Late Night Dinner Message-ID: An HTML attachment was scrubbed... URL: From tomf.sessile at gmail.com Tue Mar 2 17:47:36 2010 From: tomf.sessile at gmail.com (TomF) Date: Tue, 2 Mar 2010 14:47:36 -0800 Subject: cpan for python? References: Message-ID: <2010030214473616807-tomfsessile@gmailcom> On 2010-03-02 13:14:50 -0800, R Fritz said: > On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: >> >> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: >> >>> Is there something like cpan for python? I like python's syntax, but >>> Iuse perl because of cpan and the tremendous modules that it has. -- >> >> Please search the mailing list archives. >> >> This subject has been discussed to absolute death. > > But somehow the question is not in the FAQ, though the answer is. See: > > There > is also a program called cpan, distributed with Perl. It is used for searching, downloading, installing and testing modules from the CPAN repository. It's far more extensive than setuptools. AFAIK the python community has developed nothing like it. -Tom From aahz at pythoncraft.com Tue Mar 2 17:53:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 14:53:32 -0800 Subject: Broken references in postings References: Message-ID: In article , Grant Edwards wrote: > >I've noticed recently that a lot of the "refernces" and >"in-reply-to" headers in c.l.p are broken, resulting in the >inability to move from a child to a parent in a tree. One issue with the mail/news gateway is that (unless it's been fixed) In-Reply-To: does not get copied to References: (which is what most newsreaders need to thread properly). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Tue Mar 2 17:59:14 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 14:59:14 -0800 Subject: Is this secure? References: Message-ID: In article , Robert Kern wrote: >On 2010-02-28 01:28 AM, Aahz wrote: >> In article, >> Robert Kern wrote: >>> >>> If you are storing the password instead of making your user remember >>> it, most platforms have some kind of keychain secure password >>> storage. I recommend reading up on the APIs available on your targeted >>> platforms. >> >> Are you sure? I haven't done a lot of research, but my impression was >> that Windows didn't have anything built in. > >You're right, not built-in, but Windows does provide enough crypto >services for a cross-platform Python implementation to be built: > > http://pypi.python.org/pypi/keyring Thanks you! That's a big help! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Tue Mar 2 18:01:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Mar 2010 15:01:31 -0800 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> Message-ID: In article <20100302225156.67171851 at geekmail.INVALID>, Andreas Waldenburger wrote: > >Sorry, you guys drained all the funny out of me. Don't let a few nitpickers do that! I thought it was funny; after that, just remember that every Usenet thread drifts away from *your* point. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From matt at whoosh.ca Tue Mar 2 18:04:09 2010 From: matt at whoosh.ca (Matt Chaput) Date: Tue, 02 Mar 2010 18:04:09 -0500 Subject: Multiprocessing problem In-Reply-To: <4B8D7C23.7050905@sidefx.com> References: <4B8D7C23.7050905@sidefx.com> Message-ID: <4B8D9969.60801@whoosh.ca> On 3/2/2010 3:59 PM, Matt Chaput wrote: > I'm trying to use a simple pattern where a supervisor object starts a > bunch of worker processes, instantiating them with two queues (a job > queue for tasks to complete and an results queue for the results). The > supervisor puts all the jobs in the "job" queue, then join()s the > workers, and then pulls all the completed results off the "results" queue. > Here's a simplified example: > > http://pastie.org/850512 I should mention that if I change my code so the workers just pull things off the job queue but don't put any results on the result queue until after they see the None sentinel in the job queue and break out of the loop, I don't get the deadlock. So it's something about getting from one queue and putting to another queue in close proximity. Hopefully I'm making a simple mistake with how I'm using the library and it'll be easy to fix... Thanks, Matt From invalid at invalid.invalid Tue Mar 2 18:12:17 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Mar 2010 23:12:17 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: On 2010-03-02, Albert van der Horst wrote: > No nothing clever, nothing conscious, just reinventing the wheel > badly. > > Next time you tell me that the MSDOS "file" system was well thought > out :-) Just a mediocre copy of the CP/M filesystem, which was in turn copied from DEC's RSTS or RSX. -- Grant Edwards grant.b.edwards Yow! Kids, don't gross me at off ... "Adventures with gmail.com MENTAL HYGIENE" can be carried too FAR! From steve at holdenweb.com Tue Mar 2 18:24:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Mar 2010 18:24:51 -0500 Subject: Email Script In-Reply-To: <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> References: <4dc0cfea1003020748g786aded2i9c5287972aa8984c@mail.gmail.com> <4dc0cfea1003020753g404e6fbcr29ed52e21e2bb18c@mail.gmail.com> Message-ID: Victor Subervi wrote: > On Tue, Mar 2, 2010 at 11:48 AM, Victor Subervi This sends only the first of the two emails. Why doesn't it work to > send the second? What do? > TIA, > beno > > > Should I put a timer between instances of Email? > > Np. http://en.wikipedia.org/wiki/Cargo_cult_programming regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Tue Mar 2 18:32:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Mar 2010 23:32:52 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> Message-ID: <4b8da024$0$8783$c3e8da3@news.astraweb.com> On Tue, 02 Mar 2010 22:51:56 +0100, Andreas Waldenburger wrote: > On Tue, 02 Mar 2010 19:05:25 +0100 Jean-Michel Pichavant > wrote: > >> Andreas Waldenburger wrote: >> > >> > I had hoped that everyone just read it, went like "Oh geez.", smiled >> > it off with a hint of lesson learned and got back to whatever it was >> > they were doing. Alas, I was wrong ... and I'm sorry. >> > >> There's something wrong saying that stupid people write working code >> that totally satisfies your needs. Don't you agree ? ;-) >> > No, in fact I don't. > > It works. They are supposed to make it work. And that's what they do. > Whether or not they put their docstrings in the place they should does > not change that their code works. > > Sorry, you guys drained all the funny out of me. Most of the customers I've worked for have insisted we follow best practices. Sometimes they even invent their own best practices that nobody has even heard of, and that's fun (not). You're the first one I've ever met that bitches publicly that your contractors don't follow best practice, but objects strenuously to the idea that you are right to care about that they don't. Wow. Just... wow. P.S. next time you want some not-quite-best-practice Python code written, send me an email off-list. I'll be more than happy to do not-quite-best- practice work for you. *wink* -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Mar 2 18:34:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Mar 2010 23:34:02 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <20100302183527.47c6e8f5@geekmail.INVALID> <878waazae7.fsf@benfinney.id.au> <20100302231909.6a5bad2d@geekmail.INVALID> Message-ID: <4b8da06a$0$8783$c3e8da3@news.astraweb.com> On Tue, 02 Mar 2010 23:19:09 +0100, Andreas Waldenburger wrote: > We demand testable quality standards, but not of their code. We demand > it of their software. We say *what* we want, they decide *how* they'll > do it. Noncompliance will be fined, by a contractually agreed amount. > Everything beyond that is micromanaging and detracts workforce from the > stuff *we* have to do. You specify the Functional Requirements but not the Design Requirements. Fair enough. > We are in exactly the same kind of bond with a company that buys our > system (and support). I have yet to see any one of them demand to see > how we write our code. Why should they care? (Rhetorical question, I > refuse to discuss this any further.) It is true that most people don't care how code is written. But they *should* care, because how it is written directly impacts the quality of the code. Saying "I don't care how it is written" is precisely the same as saying "I don't care how reliable, secure or efficient the code is". Of course people do this. People also inhale carcinogenic chemicals, vote bad laws into place, drive too fast, ingest noxious chemicals, and spend hours on Usenet debating the number of angels that can dance on the head of a pin. >> I guess that when even the *customers* will resist implementing such >> quality expectations, it's little surprise that the vendors continue to >> push out such shoddy work on their customers. >> > When I'm building bicycles I can go to the trouble of going by what > method of galvanization my tires are produced. Or I save myself the > trouble and just take the best offer and hold them responsible when they > don't deliver on their promise. Both possible, both work, and both > appropriate in certain situations. Many years ago, I assisted a professional building architect design a software system for specifying the requirements of major architectural works such as bridges and high-rise buildings. They specify *everything*, right down to the type of sand used in the concrete and the grade of steel used for the frame. When using the wrong type of sand could mean that the bridge collapses in 35 years, you soon learn that, yes, you damn well better care. -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Mar 2 18:36:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 02 Mar 2010 23:36:21 GMT Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> Message-ID: <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> On Tue, 02 Mar 2010 11:30:32 -0800, Patrick Maupin wrote: > On Mar 2, 11:59?am, Terry Reedy wrote: > >> To me, comparing object notation with programming language is not >> helpful to the OP's purpose. > > Yes, I agree, it was a distraction. I fell into the trap of responding > to the ludicrous claim that "if X is a superset of Y, then X cannot > possibly look better than Y" (a claim made by multiple people all > thinking it was clever) by showing that Y has other supersets that do in > fact look better than Y. It's not ludicrous. You claim that: (1) JSON is too hard to edit; (2) RSON is a superset of JSON (the PEP even explicitly says "All valid UTF-8 encoded JSON files are also valid RSON files"); (3) which implies that all JSON files are valid RSON files. If you reject the logical conclusion that RSON must therefore also be too hard to edit, then perhaps JSON isn't too hard to edit either. You seem to be taking the position that if you start with a config file config.json, it is "too hard to edit", but then by renaming it to config.rson it magically becomes easier to edit. That *is* ludicrous. Perhaps what you mean to say is that JSON *can be* (not is) too hard to edit, and RSON *can be* too hard to edit too, but RSON has additional benefits, including being easier to edit *sometimes*. So far you have done (in my opinion) a really poor job of explaining what those benefits are. You've bad-mouthed existing config formats, then tried to convince us that RSON is almost exactly the same as one of those formats apart from a couple of trivial changes of spelling (True for true, etc.). In my opinion, if you're going to get any traction with RSON, you need to demonstrate some examples of where JSON actually is hard to write, and show how RSON makes it easier. It's not good enough showing badly written JSON, it has to be examples that can't be written less badly given the constraints of JSON. -- Steven From ben+python at benfinney.id.au Tue Mar 2 18:42:04 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 10:42:04 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> Message-ID: <877hpuxpdf.fsf@benfinney.id.au> Andreas Waldenburger writes: > It works. They are supposed to make it work. And that's what they do. > Whether or not they put their docstrings in the place they should does > not change that their code works. No-one has been denying that. What the quality of their source code *does* affect, though, is its maintainability over time ? especially in the inevitable event that the relationship with you as their customer comes to an end. The arguments I've seen here in this sub-thread have been in favour of customers demanding that the code meets functional requirements *and* soruce code quality requirements. Just as customers should demand both that a building be built to do its job well, *and* that its architectural plans meet measurable, testable industry standards of quality for independent re-use at some indeterminate later date. If we don't demand such things as customers of program developers, we deserve what programs we get. -- \ ?Special today: no ice cream.? ?mountain inn, Switzerland | `\ | _o__) | Ben Finney From marduk at python.net Tue Mar 2 18:45:49 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 18:45:49 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <4B8D4BB8.8020909@mrabarnett.plus.com> References: <1267539898.477222.7.camel@necropolis> <4B8D4BB8.8020909@mrabarnett.plus.com> Message-ID: <1267573549.495250.0.camel@centar> On Tue, 2010-03-02 at 17:32 +0000, MRAB wrote: > The documentation also mentions the 'pty' module. Have you tried that > instead? I tried to use pty.fork() but it also produces the same error. I also tried passing 'r', and 'rb' to fdopen() but it didn't make any difference. -a From marduk at python.net Tue Mar 2 18:59:00 2010 From: marduk at python.net (Albert Hopkins) Date: Tue, 02 Mar 2010 18:59:00 -0500 Subject: os.fdopen() issue in Python 3.1? In-Reply-To: <1267561347.4507.5.camel@necropolis> References: <1267539898.477222.7.camel@necropolis> <1267561347.4507.5.camel@necropolis> Message-ID: <1267574340.495250.4.camel@centar> This appears to be Issue 5380[1] which is still open. I've cc'ed myself to that issue. [1] http://bugs.python.org/issue5380 From marketing at rbcom.it Tue Mar 2 19:08:19 2010 From: marketing at rbcom.it (RBCOM MEDIA GROUP) Date: Wed, 3 Mar 2010 01:08:19 +0100 Subject: UNA VETRINA SUL MONDO Message-ID: <00e99839$40240$efd90474441088@raffaele-6a745d> ITALIA WEEKEND

... > > Is there any way to do this in ElementTree? I think the easiest is to iterate not over the elements themselves, but over their parents, and then to remove all children of the specified tag in each step. Stefan From robert.kern at gmail.com Tue Mar 9 11:01:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Mar 2010 10:01:07 -0600 Subject: scipy sparse matrix question In-Reply-To: <1jf28jr.7abra61nwu04pN%see@sig.for.address> References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> Message-ID: On 2010-03-09 00:14 AM, Victor Eijkhout wrote: > I can't find any detailed information about scipy.sparse. The place to ask would be on scipy-user: http://www.scipy.org/Mailing_Lists > My specific question: what does "for x in A" give me when A is a sparse > matrix? It seems to yield all nonzero locations, No, it gives you rows, just like a dense 2D array. -- 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 From __peter__ at web.de Tue Mar 9 11:10:26 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Mar 2010 17:10:26 +0100 Subject: related lists mean value (golfed) References: Message-ID: Michael Rudolf wrote: > Am 09.03.2010 13:02, schrieb Peter Otten: >>>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] >> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] >> Peter > > ... pwned. > Should be the fastest and shortest way to do it. It may be short, but it is not particularly efficient. A dict-based approach is probably the fastest. If y is guaranteed to be sorted itertools.groupby() may also be worth a try. $ cat tmp_average_compare.py from __future__ import division from collections import defaultdict try: from itertools import izip as zip except ImportError: pass x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(x=x, y=y): p = defaultdict(int) q = defaultdict(int) for a, b in zip(x, y): p[b] += a q[b] += 1 return [p[b]/q[b] for b in y] def g(x=x, y=y): return [sum(a for a,b in zip(x,y)if b==c)/y.count(c)for c in y] if __name__ == "__main__": print(f()) print(g()) assert f() == g() $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'f()' 100000 loops, best of 3: 11.4 usec per loop $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'g()' 10000 loops, best of 3: 22.8 usec per loop Peter From mehgcap at gmail.com Tue Mar 9 11:18:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 9 Mar 2010 11:18:05 -0500 Subject: odd error In-Reply-To: References: Message-ID: I know ctrl-c kills a process in the shell, but these are global hotkeys and all others work fine. You made me discover something, though: the error only happens if ctrl-shift-c is pressed when in the shell from where the program was run; when pressed anywhere else, the keystroke does nothing at all. Is there something I am missing about these keystroke dictionaries? It seems like they do not work unless the keycodes are in numerical order and are not separated by more than one number. Currently, my dictionary consists of the numbers 1-0 on the top of the keyboard, but adding any other keycode, like the 99 in my original message, will cause that keystroke to do absolutely nothing. Thanks to your response, I suspect the problem is something to do with the keypress being captured by the shell. Still, not being able to use anything except numbers is very annoying!! Why would this be happening? On 3/9/10, Ulrich Eckhardt wrote: > Alex Hall wrote: >> Now, though, when I press ctrl-shift-c (keystroke 11), nothing >> happens. > > Control-C sends a special signal to the console, like Control-Break. > >> Pressing any other keystroke after that will crash the program >> with some sort of Python internal com server exception that I >> have never seen before. > > Neither do I, in particular since you don't share that rare gem with us. ;) > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From showell30 at yahoo.com Tue Mar 9 11:29:44 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 08:29:44 -0800 (PST) Subject: related lists mean value References: Message-ID: <253e4e31-21f7-42cc-8276-72afe8702946@q2g2000pre.googlegroups.com> On Mar 8, 2:34?pm, dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > What results are you expecting if you have multiple runs of 'a' in a longer list? From rrpsteps at gmail.com Tue Mar 9 11:33:40 2010 From: rrpsteps at gmail.com (Rikal) Date: Tue, 9 Mar 2010 08:33:40 -0800 (PST) Subject: 1794 - Best, Cheapest Web-Hosting, Domain at $1.99! Message-ID: <6cb49bce-7913-4e60-a458-5650f95ddc03@15g2000yqi.googlegroups.com> World's Cheapest Rate Hosting, 99.9% Uptime US Based Dedicated Server, Fast Customer Service Register Domain only at $1.99 per Year 3 Month Hosting Free with 1 year Package From mail at timgolden.me.uk Tue Mar 9 11:34:03 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Mar 2010 16:34:03 +0000 Subject: odd error In-Reply-To: References: Message-ID: <4B96787B.3030907@timgolden.me.uk> On 09/03/2010 13:55, Alex Hall wrote: > Hi all, > In the same program I wrote about yesterday, I have a dictionary of > keystrokes which are captured. I just tried adding a new one, bringing > the total to 11. Here are entries 10 and 11; 10 has been working fine > for months. > > 10 : (57, win32con.MOD_CONTROL), > 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) > > Now, though, when I press ctrl-shift-c (keystroke 11) Ctrl-C (with or without any other modifier) has a special meaning which overrides any hotkeys. You may be able to do something by adding a break handler through SetConsoleCtrlHandler (exposed in win32api). But it would obviously be a special case outside your normal control flow. TJG From gherron at islandtraining.com Tue Mar 9 11:34:38 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 09 Mar 2010 08:34:38 -0800 Subject: imported var not being updated In-Reply-To: <4B9658C2.1040707@optimum.net> References: <4B9658C2.1040707@optimum.net> Message-ID: <4B96789E.8040402@islandtraining.com> John Posner wrote: > On 3/8/2010 11:55 PM, Gary Herron wrote: > >> >> The form of import you are using >> from helpers import mostRecent >> makes a *new* binding to the value in the module that's doing the >> import. > > > >> What you can do, is not make a separate binding, but reach into the >> helpers module to get the value there. Like this: >> >> import helpers >> print helpers.mostRecent >> > > Gary, are you asserting that in these separate situations: > > one.py: > > from helpers import mostRecent > x = mostRecent > > two.py: > > import helpers > x = helpers.mostRecent > > > ... the name "x" will be bound to different objects? > > Tx, > John Hi John, No they are bound to the same object ... to start with. But if, as the OP indicated, something in the helpers module changes that module's binding of 'mostRecent', then the only helpers.mostRecent in your two.py will notice that change. The variable 'x' in both samples and the 'mostRecent' value in one.py will remain unchanged. That's true for mutable *and* immutable values -- however, mutable values admit a further consideration: Since all 'x's and 'mostRecent's refer to the same value, any mutation is noticed in all cases. But, *any* assignment ( with = or of the form *from helpers import mostRecent* ) breaks the reference to the shared value. Gary Herron -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Mar 9 11:36:32 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Mar 2010 16:36:32 +0000 Subject: odd error In-Reply-To: <4B96787B.3030907@timgolden.me.uk> References: <4B96787B.3030907@timgolden.me.uk> Message-ID: <4B967910.1090108@timgolden.me.uk> On 09/03/2010 16:34, Tim Golden wrote: > On 09/03/2010 13:55, Alex Hall wrote: >> Hi all, >> In the same program I wrote about yesterday, I have a dictionary of >> keystrokes which are captured. I just tried adding a new one, bringing >> the total to 11. Here are entries 10 and 11; 10 has been working fine >> for months. >> >> 10 : (57, win32con.MOD_CONTROL), >> 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) >> >> Now, though, when I press ctrl-shift-c (keystroke 11) > > Ctrl-C (with or without any other modifier) has a special meaning > which overrides any hotkeys. You may be able to do something by > adding a break handler through SetConsoleCtrlHandler (exposed in > win32api). But it would obviously be a special case outside your > normal control flow. ... or you could use SetConsoleMode to disable input processing. But that would only work (I think) in one console, not at a global level. TJG From showell30 at yahoo.com Tue Mar 9 11:38:35 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 08:38:35 -0800 (PST) Subject: related lists mean value References: <4B95B4FF.1070407@optimum.net> <5574554b-1d62-4faf-bb89-34cb431741cd@q2g2000pre.googlegroups.com> Message-ID: <08f0cc42-1d5b-4e45-be51-b68c617bd554@m27g2000prl.googlegroups.com> On Mar 9, 7:21?am, Steve Howell wrote: > > def num_dups_at_head(lst): > ? ? assert len(lst) > 0 > ? ? val = lst[0] > ? ? i = 1 > ? ? while i < len(lst) and lst[i] == val: > ? ? ? ? i += 1 > ? ? return i > > def smooth(x, y): > ? ? result = [] > ? ? while x: > ? ? ? ? cnt = num_dups_at_head(y) > ? ? ? ? avg = sum(x[:cnt]) * 1.0 / cnt > ? ? ? ? result += [avg] * cnt > ? ? ? ? x = x[cnt:] # expensive? > ? ? ? ? y = y[cnt:] # expensive? > ? ? return result > BTW I recognize that my solution would be inefficient for long lists, unless the underlying list implementation had copy-on-write. I'm wondering what the easiest fix would be. I tried a quick shot at islice(), but the lack of len() thwarted me. From theller at ctypes.org Tue Mar 9 11:43:23 2010 From: theller at ctypes.org (Thomas Heller) Date: Tue, 09 Mar 2010 17:43:23 +0100 Subject: libc Sleep api performs a busy waiting In-Reply-To: <27e52ad11003082013h658cf7deu761e7d14198af9f1@mail.gmail.com> References: <27e52ad11003082013h658cf7deu761e7d14198af9f1@mail.gmail.com> Message-ID: Joe Fox schrieb: > Hi, > > actually i have simplified my scenario a lot here , > > In my actual case , i have to call a C-api which blocks on c select , in a > separate thread. > > my thread is getting struck in that api , and thus blocking all the other > threads. > Can you point to something which will help me call this blocking C-api call > without my thread getting struck. > ctypes. Releases the GIL before calling C api functions. From mehgcap at gmail.com Tue Mar 9 11:48:10 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 9 Mar 2010 11:48:10 -0500 Subject: odd error In-Reply-To: <4B96787B.3030907@timgolden.me.uk> References: <4B96787B.3030907@timgolden.me.uk> Message-ID: Okay, I changed the keycode from 99 (c) to 107 (k), and the errors have disappeared. However, now the function that should be called is not. As I said in a previous message, I have always had trouble with this sort of keystroke dictionary. It seems like, if a keycode is out of order or not one more than the number before it, the function to which it is tied will not get called. I am using the message looping mode from Tim Golden's website, and it works beautifully until I try to put an out-of-sequence keycode into the keystrokes dictionary. The dictionary contains numbers 0-9 (48-57) and all is well, but when I put in this 107 code then the function tied to 107 is not called, yet the ones tied to 48-57 still work normally. Why would the sequence matter, or does it not and I am doing something else wrong? Here is a sample of my dictionary: keys.append({ 1 : (48, win32con.MOD_CONTROL), 2 : (49, win32con.MOD_CONTROL), 3 : (50, win32con.MOD_CONTROL), 4 : (51, win32con.MOD_CONTROL), 5 : (52, win32con.MOD_CONTROL), 6 : (53, win32con.MOD_CONTROL), 7 : (54, win32con.MOD_CONTROL), 8 : (55, win32con.MOD_CONTROL), 9 : (56, win32con.MOD_CONTROL), 10 : (57, win32con.MOD_CONTROL), 11 : (107, win32con.MOD_CONTROL | win32con.MOD_SHIFT) #never calls its #function, and note that it is not in the sequence of the other ten }) and here is a list of functions tied to it: funcs.append({ 1 : exitProgram, 2 : arm.sayLoad1, 3 : arm.sayLoad2, 4 : arm.sayLoad3, 5 : arm.sayLoad4, 6 : arm.sayProcAvg, 7 : arm.sayUsedRam, 8 : arm.sayDisk1Info, 9 : arm.sayDisk2Info, 10 : nextMode, 11: clipboard.toClipboard }) If I were to tie clipboard.toClipboard to any of keys 1-10 (0-9, or 48-57) then it would work fine; it is when the 107 shows up that the function is not called, and this is a huge limitation for the rest of the program since I am stuck with just the ten numbers available on the keyboard. Any suggestions would be great! On 3/9/10, Tim Golden wrote: > On 09/03/2010 13:55, Alex Hall wrote: >> Hi all, >> In the same program I wrote about yesterday, I have a dictionary of >> keystrokes which are captured. I just tried adding a new one, bringing >> the total to 11. Here are entries 10 and 11; 10 has been working fine >> for months. >> >> 10 : (57, win32con.MOD_CONTROL), >> 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) >> >> Now, though, when I press ctrl-shift-c (keystroke 11) > > Ctrl-C (with or without any other modifier) has a special meaning > which overrides any hotkeys. You may be able to do something by > adding a break handler through SetConsoleCtrlHandler (exposed in > win32api). But it would obviously be a special case outside your > normal control flow. > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From jjposner at optimum.net Tue Mar 9 11:49:37 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Mar 2010 11:49:37 -0500 Subject: imported var not being updated In-Reply-To: <4b965fde$0$14410$426a74cc@news.free.fr> References: <4B9658C2.1040707@optimum.net> <4b965fde$0$14410$426a74cc@news.free.fr> Message-ID: <4b967bfa$0$31260$607ed4bc@cv.net> On 3/9/2010 9:48 AM, Bruno Desthuilliers wrote: > John Posner a ?crit : >> On 3/8/2010 11:55 PM, Gary Herron wrote: >> >>> >>> The form of import you are using >>> from helpers import mostRecent >>> makes a *new* binding to the value in the module that's doing the >>> import. >> >> >> >>> What you can do, is not make a separate binding, but reach into the >>> helpers module to get the value there. Like this: >>> >>> import helpers >>> print helpers.mostRecent >>> >> >> Gary, are you asserting that in these separate situations: >> >> one.py: >> >> from helpers import mostRecent >> x = mostRecent >> >> two.py: >> >> import helpers >> x = helpers.mostRecent >> >> >> ... the name "x" will be bound to different objects? > > Nope. What he's saying is that one.x and two.x are two different names - > each living in it's own namespace - that happen to be bound to the same > object. Now rebiding one.x to a different object will _of course_ have > no impact on the object two.x is bound to. Sure -- my bad, Python 101. In this case, the module *helpers* is the equivalent of a container object, one of whose attributes *mostRecent* gets bound to a series of immutable string objects. > > That's exactly the same as: > > one = dict() > two = dict() > > # one['x'] and two['x'] refer to the same object > one['x'] = two['x'] = ["foo", "bar"] > print one['x'], two['x'], one['x'] is two['x'] > > # mutating one['x'], visible in two['x'] > # (of course since it's the same object) > one['x'].append("baaz") > print one['x'], two['x'], one['x'] is two['x'] > > # now rebind one['x'] > one['x'] = 42 > > # obvious result: one['x'] and two['x'] now refer to 2 different objects > print one['x'], two['x'], one['x'] is two['x'] > > > If in doubt about namespaces, think dicts. Namespaces are like dicts - > and are often nothing else that a plain old dict FWIW. No doubts here, I hope. I even tend to see namespaces where, strictly speaking, they don't exist. As I said at the end of a recent (and flame-ridden) thread [1]: ----------- * A dict is a collection of user-devised names, each of which is assigned to an object. * A list/tuple is an interpreter-maintained collection of integer names (0, 1, 2, ...), each of which is assigned to an object. ----------- So in my world, in mylist[cnt+1], the expression *cnt+1* is equivalent to the integer "name" 4 (if cnt==3, that is), so that mylist[cnt+1] = obj.subobj.attr ... is just a NAME2 = NAME1 kind of assignment statement, binding an additional name to an object that already has a name. Tx, John [1] http://mail.python.org/pipermail/python-list/2010-February/1236318.html From cbmanica at gmail.com Tue Mar 9 11:54:55 2010 From: cbmanica at gmail.com (C. Benson Manica) Date: Tue, 9 Mar 2010 08:54:55 -0800 (PST) Subject: String is ASCII or UTF-8? Message-ID: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. From alfps at start.no Tue Mar 9 12:02:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Mar 2010 18:02:29 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: * C. Benson Manica: > Hours of Googling has not helped me resolve a seemingly simple > question - Given a string s, how can I tell whether it's ascii (and > thus 1 byte per character) or UTF-8 (and two bytes per character)? > This is python 2.4.3, so I don't have getsizeof available to me. Generally, if you need 100% certainty then you can't tell the encoding from a sequence of byte values. However, if you know that it's EITHER ascii or utf-8 then the presence of any value above 127 (or, for signed byte values, any negative values), tells you that it can't be ascii, hence, must be utf-8. And since utf-8 is an extension of ascii nothing is lost by assuming ascii in the other case. So, problem solved. If the string represents the contents of a file then you may also look for an UTF-8 represention of the Unicode BOM (Byte Order Mark) at the beginning. If found then it indicates utf-8 for almost-sure and more expensive searching can be avoided. It's just three bytes to check. Cheers & hth., - Alf From mail at timgolden.me.uk Tue Mar 9 12:07:44 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Mar 2010 17:07:44 +0000 Subject: String is ASCII or UTF-8? In-Reply-To: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <4B968060.7080606@timgolden.me.uk> On 09/03/2010 16:54, C. Benson Manica wrote: > Hours of Googling has not helped me resolve a seemingly simple > question - Given a string s, how can I tell whether it's ascii (and > thus 1 byte per character) or UTF-8 (and two bytes per character)? > This is python 2.4.3, so I don't have getsizeof available to me. You can't. You can apply one or more heuristics, depending on exactly what your requirement is. But any valid ASCII text is also valid UTF8-encoded text since UTF-8 isn't "two bytes per char" but a variable number of bytes per char. Obviously, you can test whether all the bytes are less than 128 which suggests that the text is legal ASCII. But then it's also legal UTF8. Or you can just attempt to decode and catch the exception: try: unicode (text, "ascii") except UnicodeDecodeError: print "Not ASCII" TJG From stef.mientki at gmail.com Tue Mar 9 12:12:48 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 09 Mar 2010 18:12:48 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <4B968190.6010208@gmail.com> On 09-03-2010 18:02, Alf P. Steinbach wrote: > * C. Benson Manica: >> Hours of Googling has not helped me resolve a seemingly simple >> question - Given a string s, how can I tell whether it's ascii (and >> thus 1 byte per character) or UTF-8 (and two bytes per character)? >> This is python 2.4.3, so I don't have getsizeof available to me. > > Generally, if you need 100% certainty then you can't tell the encoding > from a sequence of byte values. > > However, if you know that it's EITHER ascii or utf-8 then the presence > of any value above 127 (or, for signed byte values, any negative > values), tells you that it can't be ascii, AFAIK it's completely impossible. UTF-8 characters have 1 to 4 bytes / byte. I can create ASCII strings containing byte values between 127 and 255. cheers, Stef > hence, must be utf-8. And since utf-8 is an extension of ascii nothing > is lost by assuming ascii in the other case. So, problem solved. > > If the string represents the contents of a file then you may also look > for an UTF-8 represention of the Unicode BOM (Byte Order Mark) at the > beginning. If found then it indicates utf-8 for almost-sure and more > expensive searching can be avoided. It's just three bytes to check. > > > Cheers & hth., > > - Alf From tjreedy at udel.edu Tue Mar 9 12:13:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Mar 2010 12:13:33 -0500 Subject: scipy sparse matrix question In-Reply-To: <1jf28jr.7abra61nwu04pN%see@sig.for.address> References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> Message-ID: On 3/9/2010 1:14 AM, Victor Eijkhout wrote: > I can't find any detailed information about scipy.sparse. Scipy questions are best asked on the scipy list, which I suspect you can also access via news.gmane.org. > > My specific question: what does "for x in A" give me when A is a sparse > matrix? Try it and see what you get. From MLMDev at Comcast.net Tue Mar 9 12:15:59 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Tue, 9 Mar 2010 12:15:59 -0500 Subject: sys.stdout vs. sys.stderr In-Reply-To: References: Message-ID: On Jan 11, 2010, at 1:47 PM Nobody wrote: > >> On Mon, 11 Jan 2010 10:09:36 +0100, Martin v. Loewis wrote: >> >>> In Python 3.1 is there any difference in the buffering behavior of >>> the >>> initial sys.stdout and sys.stderr streams? >> >> No. >> >>> Were they different at some earlier point in Python's evolution? >> >> That depends on the operating system. These used to be whatever the >> C library set up as stdout and stderr. Typically, they were buffered >> in the same way. > > On Unix, stdout will be line buffered if it is associated with a tty > and fully buffered otherwise, while stderr is always unbuffered. > > On Windows, stdout and stderr are unbuffered if they refer to a > character > device, fully buffered otherwise (Windows doesn't have line buffering; > setvbuf(_IOLBF) is equivalent to setvbuf(_IOFBF)). > > ANSI C says: > > As initially opened, the standard error stream is not fully > buffered; the > standard input and standard output streams are fully buffered if and > only > if the stream can be determined not to refer to an interactive > device. > I don't want to get into a quibble fight here, but I need to reraise this issue. [I teach and write and want to make sure I get this right. I already have an incorrect paragraph about this in my Bioinformatics Programming Using Python book.] The key question here is line buffering vs full buffering. In Unix (at least in an OS X Terminal), the following code prints a number every two seconds in Python 2: >>> for n in range(5): . . . print >> sys.stderr, n, # final , to not send newline . . . time.sleep(2) However, in Python 3, similar code does not print the numbers until the whole thing finishes (again, running from the terminal). >>> for n in range(5): . . . print(n, file=sys.stderr, end='') . . . time.sleep(2) So it appears that in a Unix terminal window, Python 2 does not line- buffer stderr whereas Python 3 does. That's what tripped me up. While developing and debugging code, I often print periods on a line as some loop progresses (sometimes every Nth time around, for some reasonable N) just to know the pace of execution and that the program is still doing something. In doing that recently in Python 3 I discovered that I either had to leave out the end='' or do sys.stderr.flush() after every print, which amounts to the same thing. This was a big surprise, after many, many years of C, C++, Java, and Python programming -- I have always thought of stderr as completely unbuffered in languages that have it. Doesn't mean some languages line- buffer stderr on some platforms, just pointing out an assumption I've lived with for a very long time that tripped me up writing a note about using stderr in Python 3 without actually demonstrating the code and therefore not catching my error. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cbmanica at gmail.com Tue Mar 9 12:17:58 2010 From: cbmanica at gmail.com (C. Benson Manica) Date: Tue, 9 Mar 2010 09:17:58 -0800 (PST) Subject: String is ASCII or UTF-8? References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> On Mar 9, 12:07?pm, Tim Golden wrote: > You can't. You can apply one or more heuristics, depending on exactly > what your requirement is. But any valid ASCII text is also valid > UTF8-encoded text since UTF-8 isn't "two bytes per char" but a variable > number of bytes per char. Hm, well that's very unfortunate. I'm using a database library which seems to assume that all strings passed to it are ASCII, and I'm attempting to use it on two different systems - one where all strings are ASCII, and one where they seem to be UTF-8. The strings come from the same place, i.e. they're exclusively normal ASCII characters. What I would want is to check once for whether the strings passed to function foo() are ASCII or UTF-8, and if they are to assume that all strings need to be decoded. So that's not possible? From R.Brodie at rl.ac.uk Tue Mar 9 12:24:49 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 9 Mar 2010 17:24:49 -0000 Subject: String is ASCII or UTF-8? References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> Message-ID: "C. Benson Manica" wrote in message news:98375575-1071-46af-8ebc-f3c817b47e1d at q23g2000yqd.googlegroups.com... >The strings come from the same place, i.e. they're exclusively > normal ASCII characters. In this case then converting them to/from UTF-8 is a no-op, so it makes no difference at all. From cbmanica at gmail.com Tue Mar 9 12:31:59 2010 From: cbmanica at gmail.com (C. Benson Manica) Date: Tue, 9 Mar 2010 09:31:59 -0800 (PST) Subject: String is ASCII or UTF-8? References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> Message-ID: <1c9b34ab-d949-4d2d-afbd-9a1c41462f0a@g4g2000yqa.googlegroups.com> On Mar 9, 12:24?pm, "Richard Brodie" wrote: > "C. Benson Manica" wrote in messagenews:98375575-1071-46af-8ebc-f3c817b47e1d at q23g2000yqd.googlegroups.com... > > >The strings come from the same place, i.e. they're exclusively > > normal ASCII characters. > > In this case then converting them to/from UTF-8 is a no-op, so > it makes no difference at all. Except to the database library, which seems perfectly happy to send an 8-character UTF-8 string to the database as 16 raw characters... From robert.kern at gmail.com Tue Mar 9 12:36:48 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Mar 2010 11:36:48 -0600 Subject: String is ASCII or UTF-8? In-Reply-To: <4B968190.6010208@gmail.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <4B968190.6010208@gmail.com> Message-ID: On 2010-03-09 11:12 AM, Stef Mientki wrote: > On 09-03-2010 18:02, Alf P. Steinbach wrote: >> * C. Benson Manica: >>> Hours of Googling has not helped me resolve a seemingly simple >>> question - Given a string s, how can I tell whether it's ascii (and >>> thus 1 byte per character) or UTF-8 (and two bytes per character)? >>> This is python 2.4.3, so I don't have getsizeof available to me. >> >> Generally, if you need 100% certainty then you can't tell the encoding >> from a sequence of byte values. >> >> However, if you know that it's EITHER ascii or utf-8 then the presence >> of any value above 127 (or, for signed byte values, any negative >> values), tells you that it can't be ascii, > AFAIK it's completely impossible. > UTF-8 characters have 1 to 4 bytes / byte. > I can create ASCII strings containing byte values between 127 and 255. No, you can't. ASCII strings only have characters in the range 0..127. You could create Latin-1 (or any number of the 8-bit encodings out there) strings with characters 0..255, yes, but not ASCII. -- 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 From askedrelic at gmail.com Tue Mar 9 12:37:12 2010 From: askedrelic at gmail.com (Matthew Behrens) Date: Tue, 9 Mar 2010 12:37:12 -0500 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: References: Message-ID: <75d625cc1003090937t24c2dbe7u9a61e5a9a2107d19@mail.gmail.com> > I like this tools, I'm wonder if there are similar tools in Python ? Blogofile is a static file blog engine/compiler, inspired by Jekyll. http://blogofile.com/ http://github.com/EnigmaCurry/blogofile From tjreedy at udel.edu Tue Mar 9 12:59:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Mar 2010 12:59:16 -0500 Subject: String is ASCII or UTF-8? In-Reply-To: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: On 3/9/2010 11:54 AM, C. Benson Manica wrote: > Hours of Googling has not helped me resolve a seemingly simple > question - Given a string s, how can I tell whether it's ascii (and > thus 1 byte per character) or UTF-8 (and two bytes per character)? Utf-8 is an encoding that uses 1 to 4 bytes per character. So it is not clear what you are asking. Alf answered one of the possible questions. > This is python 2.4.3, so I don't have getsizeof available to me. From rschroev_nospam_ml at fastmail.fm Tue Mar 9 13:13:07 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 09 Mar 2010 19:13:07 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: <1c9b34ab-d949-4d2d-afbd-9a1c41462f0a@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> <1c9b34ab-d949-4d2d-afbd-9a1c41462f0a@g4g2000yqa.googlegroups.com> Message-ID: Op 2010-03-09 18:31, C. Benson Manica schreef: > On Mar 9, 12:24 pm, "Richard Brodie" wrote: >> "C. Benson Manica" wrote in messagenews:98375575-1071-46af-8ebc-f3c817b47e1d at q23g2000yqd.googlegroups.com... >> >>> The strings come from the same place, i.e. they're exclusively >>> normal ASCII characters. >> >> In this case then converting them to/from UTF-8 is a no-op, so >> it makes no difference at all. > > Except to the database library, which seems perfectly happy to send an > 8-character UTF-8 string to the database as 16 raw characters... In that case I think you mean UTF-16 or UCS-2 instead of UTF-8. UTF-16 uses 2 or more bytes per character, UCS-2 always uses 2 bytes per character. UTF-8 uses 1 or more bytes per character. If your texts are in a Western language, the second byte will be zero in most characters; you could check for that (but note that the second byte might be the first one in the byte stream, depending on the byte ordering). HTH, Roel -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From pruebauno at latinmail.com Tue Mar 9 13:24:27 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 9 Mar 2010 10:24:27 -0800 (PST) Subject: related lists mean value (golfed) References: Message-ID: <62af4b09-77f6-47ab-bce0-2cfcbafecfed@c16g2000yqd.googlegroups.com> Peter Otten wrote: > Michael Rudolf wrote: > > > Am 09.03.2010 13:02, schrieb Peter Otten: > >>>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] > >> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > >> Peter > > > > ... pwned. > > Should be the fastest and shortest way to do it. > > It may be short, but it is not particularly efficient. A dict-based approach > is probably the fastest. If y is guaranteed to be sorted itertools.groupby() > may also be worth a try. > > $ cat tmp_average_compare.py > from __future__ import division > from collections import defaultdict > try: > from itertools import izip as zip > except ImportError: > pass > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > def f(x=x, y=y): > p = defaultdict(int) > q = defaultdict(int) > for a, b in zip(x, y): > p[b] += a > q[b] += 1 > return [p[b]/q[b] for b in y] > > def g(x=x, y=y): > return [sum(a for a,b in zip(x,y)if b==c)/y.count(c)for c in y] > > if __name__ == "__main__": > print(f()) > print(g()) > assert f() == g() > $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'f()' > 100000 loops, best of 3: 11.4 usec per loop > $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'g()' > 10000 loops, best of 3: 22.8 usec per loop > > Peter I converged to the same solution but had an extra reduction step in case there were a lot of repeats in the input. I think it is a good compromise between efficiency, readability and succinctness. x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] from collections import defaultdict totdct = defaultdict(int) cntdct = defaultdict(int) for name, num in zip(y,x): totdct[name] += num cntdct[name] += 1 avgdct = {name : totdct[name]/cnts for name, cnts in cntdct.items()} w = [avgdct[name] for name in y] From stefan_ml at behnel.de Tue Mar 9 14:19:44 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Mar 2010 20:19:44 +0100 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: References: Message-ID: KLEIN St?phane, 09.03.2010 09:30: > Today, I've show this static web site generating tools writed in ruby : > > * http://webgen.rubyforge.org/index.html > * http://nanoc.stoneship.org/about/ > * http://webby.rubyforge.org/tutorial/ > > I like this tools, I'm wonder if there are similar tools in Python ? Here's a still incomplete but not so short list of web frameworks in Python: http://wiki.python.org/moin/WebFrameworks You might be interested in the templating frameworks if all you want is generate static pages. Stefan From tavares at fe.up.pt Tue Mar 9 14:25:57 2010 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Tue, 9 Mar 2010 11:25:57 -0800 (PST) Subject: ICNAAM 2010 Mini-Symposium on Computational Bioimaging and Visualization Message-ID: Dear Colleague, Within the ICNAAM 2010 - 8th International Conference of Numerical Analysis and Applied Mathematics (http://www.icnaam.org), to be held in Rhodes, Greece, on 19-25 September 2010, we are organizing the Mini- Symposium on ?Computational Bioimaging and Visualization?. Due to your research activities in the related fields, we would like to invite you to submit an invited extended abstract to our mini- symposium. Your contribution is mostly welcomed, and we would be honoured if you could accept this invitation. TOPICS OF INTEREST (not restricted to): - Image Processing and Analysis for Computational Bioimaging and Visualization; - Biomedical Signal and Image Acquisition and Processing; - Data Processing, Modeling and Analysis; - Scientific Visualization; - Enhanced Visualization; - Human Computer Interaction; - Simulation and Animation; - Virtual Reality; - Computer Aided Diagnosis, Surgery, Therapy, Treatment and Telemedicine Systems; - Software Development for Computational Bioimaging and Visualization; - Grid Computing in Computational Bioimaging and Visualization; - Applications of Computational Bioimaging and Visualization. IMPORTANT DATES: Deadline for Submission of Extended Abstract: July 22, 2010; Notification of acceptance: July 29, 2010; Deadline for Submission of the source files of the camera ready extended abstracts to American Institute of Physics (AIP Conference Proceedings): August 1, 2010. SUBMISSION INSTRUCTIONS: Extended abstracts will be published in a Special Volume of the AIP Conference Proceedings. Please, see the Instructions for Authors at: http://www.icnaam.org/abstract.htm, and select the Mini-Symposium on ?Computational Bioimaging and Visualization? when submitting your contribution. With kind regards, Jo?o Manuel R. S. Tavares, University of Porto, Portugal, tavares at fe.up.pt Renato Natal Jorge, University of Porto, Portugal, rnatal at fe.up.pt (Organizers of the Mini-Symposium on ?Computational Bioimaging and Visualization?) From tarekamr at gmail.com Tue Mar 9 15:31:15 2010 From: tarekamr at gmail.com (tarekamr at gmail.com) Date: Tue, 9 Mar 2010 12:31:15 -0800 (PST) Subject: Pyrhon2.5 to 2.4 conversion References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <8676dc2a-2246-4fcb-8736-e6effeddbcad@b7g2000yqd.googlegroups.com> Thanks a lot everybody for your help, it worked now :) On Feb 28, 4:12?am, MRAB wrote: > tarek... at gmail.com wrote: > > Hi, > > > I am currently using oauth2.py library, and it works fine on one of my > > PC's (python2.5), but later on when I tried to use it with python2.4 > > the following line (line 332 inhttp://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > > showed a syntax error > > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > > sorted(self.items()) if k != 'oauth_signature'] > > > So it there a way to convert this line to a python2.4 compliant > > syntax. > > I think the clearest is: > > items = [] > for k, v in sorted(self.items()): > ? ? ?if k != 'oauth_signature': > ? ? ? ? ?if type(v) == ListType: > ? ? ? ? ? ? ?v = sorted(v) > ? ? ? ? ?items.append((k, v)) From martin at v.loewis.de Tue Mar 9 15:44:54 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 09 Mar 2010 21:44:54 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <4B96B346.2050700@v.loewis.de> > I can create ASCII strings containing byte values between 127 and 255. No, you can't - or what you create wouldn't be an ASCII string, by definition of ASCII. Regards, Martin From see at sig.for.address Tue Mar 9 15:52:03 2010 From: see at sig.for.address (Victor Eijkhout) Date: Tue, 9 Mar 2010 14:52:03 -0600 Subject: scipy sparse matrix question References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> Message-ID: <1jf3d8v.crydq1be5um2N%see@sig.for.address> Terry Reedy wrote: > > My specific question: what does "for x in A" give me when A is a sparse > > matrix? > > Try it and see what you get. Ah, how do I see what I get? If I print it it looks plausible, but I don't know how to pull it apart. It doesn't seem to be an array. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From gagsl-py2 at yahoo.com.ar Tue Mar 9 15:56:24 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Mar 2010 17:56:24 -0300 Subject: How to detect C Function block using python References: <769249.71022.qm@web62401.mail.re1.yahoo.com> Message-ID: En Tue, 09 Mar 2010 04:51:57 -0300, Faheem escribi?: > I'm new in this community. I am writing a static analyzer for validating > C Code using python and for that I'm looking for a python module/API > that will detect Function block of a given C-File. I know simple > function can be detected using push "{" and poping it if character "}" > is found. This solution is actually done already, I want a robust API > that can do more then that like detecting Function name parameters its > return types etc. Take a look at ctypeslib [1]; it uses gccxml [2] to parse .h header files and generate equivalent Python declarations. [1] http://svn.python.org/view/ctypes/trunk/ctypeslib/ [2] http://www.gccxml.org/ -- Gabriel Genellina From robert.kern at gmail.com Tue Mar 9 16:13:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Mar 2010 15:13:23 -0600 Subject: scipy sparse matrix question In-Reply-To: <1jf3d8v.crydq1be5um2N%see@sig.for.address> References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> <1jf3d8v.crydq1be5um2N%see@sig.for.address> Message-ID: On 2010-03-09 14:52 PM, Victor Eijkhout wrote: > Terry Reedy wrote: > >>> My specific question: what does "for x in A" give me when A is a sparse >>> matrix? >> >> Try it and see what you get. > > Ah, how do I see what I get? If I print it it looks plausible, but I > don't know how to pull it apart. It doesn't seem to be an array. In [5]: I = sparse.csr_matrix(np.eye(4)) In [6]: list(I) Out[6]: [<1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>, <1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>, <1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>, <1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>] What is unclear about that? They are obviously 1x4 sparse matrices, i.e. the rows of the matrix. Use the .indices and .data attributes to get the indices of the nonzero values and the corresponding values. Details may differ depending on the format of sparse matrix. Some aren't even iterable. -- 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 From anfedorov at gmail.com Tue Mar 9 16:26:52 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Tue, 9 Mar 2010 16:26:52 -0500 Subject: Down casting Python objects Message-ID: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to "down cast" x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect things to work OK in all major versions of CPython? -------------- next part -------------- An HTML attachment was scrubbed... URL: From art at hens-teeth.net Tue Mar 9 16:28:54 2010 From: art at hens-teeth.net (Art Zemon) Date: Tue, 09 Mar 2010 15:28:54 -0600 Subject: CSV DictReader loops when used with MySQLdb Message-ID: <4B96BD96.5010605@hens-teeth.net> I'm going crazy. Using python 2.5.2 on 64 bit Linux. I have a class which reads CSV files using the CSV DictReader. If I print the rows, everything works perfectly. If I insert the rows into a MySQL table using MySQLdb, the DictReader loops back and begins re-reading from the beginning of the file when it reaches EOF. Here's the code: class CsvLoader: """load data from a CSV file into a corresponding MySQL table""" def __init__(self, fname, schema, db, useCleanReader = False): self.schema = schema self.db = db if useCleanReader: self.reader = csv.DictReader(CleanReader(fname), delimiter=',', quotechar='"') else: self.reader = csv.DictReader(open(fname), delimiter=',', quotechar='"') def loadMysql(self): for row in self.reader: self.db.insertGeneric(self.schema.tableName(), row) def printRows(self): for row in self.reader: print "\n", row and here is the insertGeneric method: def insertGeneric(self, table, record): """execute a generic INSERT, given a dict as input""" fieldList = [] valueList = [] for k in record.keys(): fieldList.append(k) valueList.append(record[k]) fields = ", ".join(fieldList) m = ['%s'] valueMarkers = ", ".join(m * len(valueList)) # create a string like: %s, %s, %s... sql = 'insert into %s (%s) values (%s)' % (table, fields, valueMarkers) cursor = self.conn.cursor() print "+++ insert: %s <= %s" % (sql, valueList) cursor.execute(sql, valueList) cursor.close() useCleanReader is False CsvLoader.printRows() works fine. CsvLoader.loadMySql() keeps looping through the CSV file. Ideas? -- Art Z. -- Art Zemon, President Hen's Teeth Network Phone: (866)HENS-NET or (636)447-3030 ext. 200 Twitter: AZemon -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Tue Mar 9 16:36:08 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 09 Mar 2010 22:36:08 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <4B968190.6010208@gmail.com> Message-ID: <4B96BF48.7080201@gmail.com> On 09-03-2010 18:36, Robert Kern wrote: > On 2010-03-09 11:12 AM, Stef Mientki wrote: >> On 09-03-2010 18:02, Alf P. Steinbach wrote: >>> * C. Benson Manica: >>>> Hours of Googling has not helped me resolve a seemingly simple >>>> question - Given a string s, how can I tell whether it's ascii (and >>>> thus 1 byte per character) or UTF-8 (and two bytes per character)? >>>> This is python 2.4.3, so I don't have getsizeof available to me. >>> >>> Generally, if you need 100% certainty then you can't tell the encoding >>> from a sequence of byte values. >>> >>> However, if you know that it's EITHER ascii or utf-8 then the presence >>> of any value above 127 (or, for signed byte values, any negative >>> values), tells you that it can't be ascii, >> AFAIK it's completely impossible. >> UTF-8 characters have 1 to 4 bytes / byte. >> I can create ASCII strings containing byte values between 127 and 255. > > No, you can't. ASCII strings only have characters in the range 0..127. > You could create Latin-1 (or any number of the 8-bit encodings out > there) strings with characters 0..255, yes, but not ASCII. > Probably, and according to wikipedia you're right. I think I've to get rid of my old books, Borland turbo Pascal 4 (1987) has an ASCII table of 256 characters, while the small letters say 7-bit ;-) cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From bringa at gmail.com Tue Mar 9 16:41:10 2010 From: bringa at gmail.com (Daniel Klein) Date: Tue, 9 Mar 2010 13:41:10 -0800 (PST) Subject: Named loops for breaking Message-ID: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Hey, I did a little searching and couldn't really find much recent on this. The only thing I found was this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a696624c92b91181/5b7479fdc3362b83?lnk=gst&q=break+named+loop#5b7479fdc3362b83 Basically I'm wondering if there are any plans to implemented named loops in Python, so I can tell a break command to break out of a specific loop in the case of nested loops. Currently I'm using boolean flag variables, but I find that very clumsy. I know this idea of breaking out of specific loops from javascript; I guess java does it too. It just seems a very Pythonian idea to me: clear, promotes code legibility, seems obvious. From shengcer at gmail.com Tue Mar 9 16:48:42 2010 From: shengcer at gmail.com (Shane) Date: Tue, 9 Mar 2010 13:48:42 -0800 (PST) Subject: How to dynamic insert more conditional statements into a function Message-ID: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> Hi I am a newbie for Python Here is a question, say I have a list L, function foo is: def foo(L): if L[0] > 0: return True if later I want another function goo which returns "True" when L[0] and L[1] are both > 0, i.e., def goo(L): if L[0] > 0 and L[1] > 0: return True Can anybody tell me how can I write the function "goo" based upon the function "foo"? Thanks! I know if it is implementable, I should use "decorator". But I just cannot figure out how. From no.email at nospam.invalid Tue Mar 9 16:58:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 09 Mar 2010 13:58:01 -0800 Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <7xocixximu.fsf@ruckus.brouhaha.com> Daniel Klein writes: > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. Currently I'm using boolean > flag variables, but I find that very clumsy. The usual way to do this in Python is with an exception, perhaps a specially named one if that makes your code clearer: class Whatever(Exception): pass ... try: for x in thingie: for y in x.whatsis(): if lose(y): raise Whatever ... except Whatever: pass This situation doesn't come up all that often and you should probably ask yourself if you really need those nested loops. You might also be able to put the nested loop structure into a function that you can then exit with a return statement. From ccurvey at gmail.com Tue Mar 9 17:05:15 2010 From: ccurvey at gmail.com (Chris Curvey) Date: Tue, 9 Mar 2010 14:05:15 -0800 (PST) Subject: find text location (in pixels) using python (pyPdf) Message-ID: Has anyone ever tried to find the pixel (or point) location of text in a PDF using Python? I've been using the pyPdf libraries for other things, and it seems to me that if I can find the bounding box for text, I should be able to calculate the location. What I want to do is take a PDF of one of our vendor invoices and blur everything in it except the block that's related to a single customer. So if I have an invoice that looks like: Alfred Annoying 123 Elm St Somewhere, NJ $100 Barbie Bonehead 456 Pine St Elsewhere, NJ $125 Charlie Clueless 789 Beech St. Everywhere, NJ $150 I want to show Barbie just her section of the invoice (with the header intact, so that she can tell it's a real invoice) but with Alfred and Charlie's information blurred out. I was going to convert the PDF to a JPG or PNG and do the blurring with ImageMagick/PythonMagick. But that requires me to know the pixel location of the regions that I want blurred and left alone. I'm also open to other ideas if I'm going about this the hard way.... From donal.k.fellows at man.ac.uk Tue Mar 9 17:06:39 2010 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Tue, 9 Mar 2010 14:06:39 -0800 (PST) Subject: Updates about Tk References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> <6adc$4b895233$4275d90a$6509@FUSE.NET> Message-ID: <6aa37d52-13a0-4c1b-9304-d301ed8f8c63@q23g2000yqd.googlegroups.com> On Feb 27, 5:29?pm, rantingrick wrote: > Great post Kevin! The only thing i would like to add are my two > favorite references for learning Tkinter. They are not geared around > the new ttk stuff, but still 95% relevant to any Tkinter-ing > > http://effbot.org/tkinterbook/ > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ You might also want to check out: http://www.tkdocs.com/ Which covers the ttk widgets too (and, for multi-language people, it also handles how to do it from four languages). Donal. From emile at fenx.com Tue Mar 9 17:15:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Mar 2010 14:15:18 -0800 Subject: String is ASCII or UTF-8? In-Reply-To: <4B96BF48.7080201@gmail.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <4B968190.6010208@gmail.com> <4B96BF48.7080201@gmail.com> Message-ID: On 3/9/2010 1:36 PM Stef Mientki said... > On 09-03-2010 18:36, Robert Kern wrote: >> No, you can't. ASCII strings only have characters in the range 0..127. >> You could create Latin-1 (or any number of the 8-bit encodings out >> there) strings with characters 0..255, yes, but not ASCII. >> > Probably, and according to wikipedia you're right. I too looked at wikipedia, and it seems historically incomplete to me. In particular, I looked for 'high order ascii', which, when I was working with Basic Four in the '70's, is what they used. Essentially, the high order bit was set for all characters to make 8A a line feed, etc. Still the same 0..127 characters, but not really an extended ascii which is where wikipedia forwards you to. I remember having to strap the eighth bit high when I reused the older line printers to get them to work. Emile From emile at fenx.com Tue Mar 9 17:21:37 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Mar 2010 14:21:37 -0800 Subject: How to dynamic insert more conditional statements into a function In-Reply-To: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> References: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> Message-ID: On 3/9/2010 1:48 PM Shane said... > Hi I am a newbie for Python > > Here is a question, say I have a list L, > > function foo is: > > def foo(L): > if L[0]> 0: return True > > if later I want another function goo which returns "True" when L[0] > and L[1] are both> 0, i.e., > > def goo(L): > if L[0]> 0 and L[1]> 0: return True Here's one way... def foo(L,deep=0): return L[0] and not deep or foo(L[1:],deep-1) Subject to clean up. Emile From gramos at yahoo.com Tue Mar 9 17:53:50 2010 From: gramos at yahoo.com (brown wrap) Date: Tue, 9 Mar 2010 14:53:50 -0800 (PST) Subject: Can't build hashlib In-Reply-To: Message-ID: <865538.86264.qm@web111703.mail.gq1.yahoo.com> The md5 module is used in build xulrunner and Firefox from source. When I do run the install its says md5 no such module. I compiled Python 2.6.4 after installing openssl and BerkleyDB, yet I get this error when compilying Python: Failed to find the necessary bits to build these modules: _tkinter bsddb185 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _hashlib _ssl From sluggoster at gmail.com Tue Mar 9 18:18:11 2010 From: sluggoster at gmail.com (Mike Orr) Date: Tue, 9 Mar 2010 15:18:11 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <8fc356e0-f3ed-4a67-9b37-f21561cef4a5@p13g2000pre.googlegroups.com> Message-ID: <73dcf2e2-a391-4c7a-9ded-b1ab156ad59f@u19g2000prh.googlegroups.com> I just saw this thread on the Python-URL. On Feb 14, 12:39?pm, a... at pythoncraft.com (Aahz) wrote: > >> Sean DiZazzo =A0 wrote: > > >>>Why did Path() get rejected? Is it the idea itself, or just the > >>>approach that was used? What are the complaints? > > >> You should search for the discussiona around it. > > >I read the discussion, and there was definitely some going back and > >forth on whether it should be sub-classed from string, but the > >conversation just seemed to stop abruptly with no decision one way of > >the other. ?Maybe I missed a thread. It has a habit of being discussed and dropped repeatedly. The main issue is that Guido doesn't see an OO approach as necessarily better than the existing functions, so it has a high bar for acceptance. One issue is that some people see a need to separate filesystem- independent functionality (joining paths and extracting components) from filesystem-dependent functionality (listing directories, removing files, etc). ``path.py`` and PEP 355 were rejected mainly because of this. There was support for a small filesystem-independent class that could be put into the stdlib, and some modest moving/renaming of the filesystem functions (which are scattered across os, os.path, shutil, glob, etc). We were hoping to get this done for Python 3 but didn't make it. I wrote a ``Unipath`` package that tried to be a compromise between what everybody wanted, with a FS-independent class and a FS- dependent subclass, but could not get any feedback on it. Somebody else was going to write a PEP for the renamings, but I never saw it. Since then, path.py has been included in a couple packages and seems to have the most widespread use. I gave up on the stdlib and reconfigured Unipath as a pure 3rd-party library. (The FS-independent AbstractPath class is still there if anybody wants to use it for a PEP.) The other people who made their own implementations seemed to be happy with theirs, and that was that. The string vs non-string argument has pretty much been decided in favor of strings (i.e., a string subclass). Not ``"a.txt".open()`` but ``open(Path("a.txt"))``. Too many standard and 3rd-party modules expect string paths: you'd have to convert your path to a string every time you pass it as an argument. The main problem with string paths is that .join() means something else, but that's usually solved by using a different method name: "joinpath", "child", "/", etc. Other proposals have been a tuple subclass, so that ``Path("a/b/c.txt") [-1] == Path("c.txt")``, and a library that can do non-native paths (Windows style on Unix systems and vice-versa). These don't seem to be in vogue anymore. What has become more common is virtual paths; i.e., the same interface for filesystems, FTP, zip files, etc. That was discussed during the last go-around but there were no implementations. Now there are a few projects active on this, such as http://groups.google.com/group/stdpyfs . This is probably the future of any path object, so it would make sense to define a path now that can work with all these backends. --Mike From jcb at iteris.com Tue Mar 9 18:56:47 2010 From: jcb at iteris.com (Metalone) Date: Tue, 9 Mar 2010 15:56:47 -0800 (PST) Subject: file seek is slow Message-ID: I ran a comparison that timed 1e6 file seeks. The tests were run with Python 2.6.4 and Microsoft Visual C 6.0 on Windows XP with an Intel 3GHz single processor with hyperthreading. Results: C : 0.812 seconds Python: 1.458 seconds. difference = 0.646 seconds. If the file.seek is removed the Python loop takes 2ms so the loop overhead is minimal. Without pysco the loop overhead is 4.6ms and Python takes 1.866. Any ideas what is causing the slow down over the 'C' version. In general I have been trying to take a video application written in C+ + and make it work in Python. There seem to be delays in the handoff to Windows System code that make the Python version just a touch slower in some areas, but these slowdowns are critically effecting the work. File seek is not a deal breaker here, it is just the latest thing I have noticed and the simplest to demonstrate. Python version: import time def main(): # write temp file SIZE = 1000 f1 = file('video.txt', 'wb') f1.write('+' * SIZE) f1.close() f1 = file('video.txt', 'rb') t0 = time.clock() for i in xrange(1000000): f1.seek(0) delta = time.clock() - t0 print "%.3f" % delta f1.close() if __name__ == '__main__': import psyco psyco.full() main() // 'C' version #include #include #define SIZE 1000 static void main(int argc, char *argv[]) { FILE *f1; int i; int t0; float delta; char buffer[SIZE]; // write temp file memset(buffer, (int)'+', SIZE); f1 = fopen("video.txt", "wb"); fwrite(buffer, SIZE, 1, f1); fclose(f1); f1 = fopen("video.txt", "rb"); t0 = clock(); for (i=0; i < 1000000; i++) { fseek(f1, 0, SEEK_SET); } delta = (float)(clock() - t0) / CLOCKS_PER_SEC; printf("%.3f\n", delta); fclose(f1); } From martin.hellwig at dcuktec.org Tue Mar 9 18:58:01 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 09 Mar 2010 23:58:01 +0000 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: On 02/09/10 14:00, Phlip wrote: > Ah, now we get down to the root of the problem. Because Python is so > stuck on the "one best way to do it" mentality, language bigotry > prevented the Committee from picking from among several equally valid > but non-best options. And after 20 years of growth, Python still has > no Pathname class. What a mature community! C-: > Well even if this statement would be true, I personally think that not proclaiming something a 'standard' if you are sure that you are not sure about it, is a virtue. -- mph From ptmcg at austin.rr.com Tue Mar 9 19:11:35 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 9 Mar 2010 16:11:35 -0800 (PST) Subject: file seek is slow References: Message-ID: This is a pretty tight loop: for i in xrange(1000000): f1.seek(0) But there is still a lot going on, some of which you can lift out of the loop. The easiest I can think of is the lookup of the 'seek' attribute on the f1 object. Try this: f1_seek = f1.seek for i in xrange(1000000): f1_seek(0) How does that help your timing? -- Paul From greg.ewing at canterbury.ac.nz Tue Mar 9 19:17:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 10 Mar 2010 13:17:48 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: <7vo661F7s7U1@mid.individual.net> Dave Angel wrote: > If you assume it's done in a single pass, and you know which byte is the > end of the buffer, I'd think you could learn a lot by just tweaking that > last byte. I'm sure I would, but unfortunately I can't control the last byte. The bytes that I can influence are some distance back from the end of the data. -- Greg From robin.rytich at gmail.com Tue Mar 9 20:57:47 2010 From: robin.rytich at gmail.com (Robin Rytich) Date: Wed, 10 Mar 2010 04:57:47 +0300 Subject: Knight's tour Warndorff's algorithm problem Message-ID: <1268186267.11433.47.camel@rytich-laptop> Hi all I'm having some troubles with writing Knight's tour (http://en.wikipedia.org/wiki/Knight%27s_tour) solution in Python 3. I'm using Warnsdorff's algorithm (http://en.wikipedia.org/wiki/Knight% 27s_tour#Algorithm) and I'm wondering why it doesn't work with boards of certain sizes. I've written a solution and I like it but it does not work correctly for 15x15, 26x26, 27x27 and 32x32 boards (don't know why; checked from 5x5 to 40x40). So I'd be really glad if you tell me whether I am too stupid for Python or for Discrete Math? In other words, did I implemented Warnsdorff's algorithm in Python 3 correctly or maybe all my troubles are because I haven't read tutorial with enough patience? P.S. Warnsdorff's algorithm says that it's not really important which square to choose between those which have equal amount of ways out. In spite of that I tried to changed my program and added '=' to condition at line 78. Results were quite surprising: now it works for 5x5, 6x6, ... 34x34 but not for 35x35! -------------- next part -------------- A non-text attachment was scrubbed... Name: knights_tour.py Type: text/x-python Size: 3210 bytes Desc: not available URL: From wuwei23 at gmail.com Tue Mar 9 21:10:20 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Mar 2010 18:10:20 -0800 (PST) Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <41d99d1f-7499-4c3e-8c25-8d58a6c16bd3@c37g2000prb.googlegroups.com> Daniel Klein wrote: > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. You should be able to do this with the goto module: http://entrian.com/goto/ But please note that I'm not seriously advocating its use :) From dr.cg at 126.com Tue Mar 9 22:36:10 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 10 Mar 2010 11:36:10 +0800 (CST) Subject: Six Minutes and fourty two seconds Message-ID: <5fa8d25e.47df.1274624d257.Coremail.dr.cg@126.com> >Tobiah wrote: >> Now that I use python, this is the amount of time >> per day that I spend adding forgotten semicolons while >> debugging other languages. >> >What compels you to write Python code without semicolons? >Frederic Try the C language without semicolons and braces http://pythoidc.googlecode.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Mar 9 23:01:01 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Mar 2010 20:01:01 -0800 (PST) Subject: odd error References: <4B96787B.3030907@timgolden.me.uk> Message-ID: <5bfe3bef-3e27-4e46-a3ae-3f029630d80a@c37g2000prb.googlegroups.com> Alex Hall wrote: > Why would the sequence > matter, or does it not and I am doing something else wrong? Here is a > sample of my dictionary: Showing us the code that handles the dictionary lookup + function calling would probably help us a lot more here. From fukazawa at gmail.com Wed Mar 10 00:01:48 2010 From: fukazawa at gmail.com (Andy) Date: Tue, 9 Mar 2010 21:01:48 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> <6596caf4-8d36-40b4-8e8d-a5ed2a18f245@z1g2000prc.googlegroups.com> Message-ID: <9a15f63e-c486-40fd-bd6f-9c328328f0a1@a16g2000pre.googlegroups.com> Hi Kishore, Have you tried "ser=serial.Serial(port='COM2', baudrate=9600)" instead of "port='\\.\COM2'"? Also, I'd suggest you temporarily define some other parameters that now you're leaving to default values. From the documentation of pyserial: readline(size=None, eol='\n') You're sure that your Arduino device is sending a '\n' right after the '1', aren't you? Or is it two consecutive '1'? And another idea: If this is your first experience with PySerial, I suggest you first use some free software as counterpart to your Arduino device in order to confirm the microcontroller is sending exactly what you think it is sending. In other words, is it sending to your Python program '11' or '1\n1\n'? Also to confirm other details such as parity bits, baud, etc. Cheers, Andy From showell30 at yahoo.com Wed Mar 10 00:23:08 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 21:23:08 -0800 (PST) Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <3b1dce65-99ed-471a-8494-9eaf0e6d44ad@e19g2000prn.googlegroups.com> On Mar 7, 7:09?pm, Gregory Ewing wrote: > Given some known data/crc pairs, how feasible is it to > figure out the polynomial being used to generate the crc? > > In the case I'm looking at, it appears that the crc > size may be at least 24 bits, so just trying all possible > polynomials probably isn't doable. > > An article I found hints at the possibility of using > GCDs to make the search more efficient, but doesn't go > into any details. Anyone know of any literature about > this? > > If it helps, I have the ability to generate test cases > with known message contents to some extent, although > I don't have complete control over the contents. Also > it's a manual process, so generating large numbers of > them automatically isn't an option. > Hi Greg. I would at least flip one bit at a time on the first byte of your data to see if the transformation is bitwise. From rami.chowdhury at gmail.com Wed Mar 10 00:24:00 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 9 Mar 2010 21:24:00 -0800 Subject: Down casting Python objects In-Reply-To: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> Message-ID: <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> On Mar 9, 2010, at 13:26 , Andrey Fedorov wrote: > So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to "down cast" x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect things to work OK in all major versions of CPython? Could you tell us *why* you need to down-cast x? Explicit type-casting is usually unnecessary in Python... ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -------------- next part -------------- An HTML attachment was scrubbed... URL: From stava at telcotec.se Wed Mar 10 00:31:19 2010 From: stava at telcotec.se (Lars Stavholm) Date: Wed, 10 Mar 2010 11:01:19 +0530 Subject: pexpect and logging integration Message-ID: <4B972EA7.50807@telcotec.se> Hi all, has anyone managed to integrate pexpect and logging? I.e., I'd like to be able to pick up the dialog, commands sent and responses received, in my logging. I know about the pexpect logfile, and I can log things to stdout or stderr, but I really need to log using the python logging library. Any thoughts appreciated /Lars From gagsl-py2 at yahoo.com.ar Wed Mar 10 00:37:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 02:37:14 -0300 Subject: Knight's tour Warndorff's algorithm problem Message-ID: El 9 mar, 22:57, Robin Rytich escribi?: > I'm having some troubles with writing Knight's tour > (http://en.wikipedia.org/wiki/Knight%27s_tour) solution in Python 3. I'm > using Warnsdorff's algorithm (http://en.wikipedia.org/wiki/Knight% > 27s_tour#Algorithm) and I'm wondering why it doesn't work with boards of > certain sizes. I've written a solution and I like it but it does not > work correctly for 15x15, 26x26, 27x27 and 32x32 boards (don't know why; > checked from 5x5 to 40x40). Warnsdorff's algorithm is heuristic; it works most of the time, but in some cases leads to a dead end and you have to backtrack and try another alternative. The starting square is important; if you start at 1,1 (instead of 0,0) your program finds a solution for all those problematic board sizes. > So I'd be really glad if you tell me whether > I am too stupid for Python or for Discrete Math? In other words, did I > implemented Warnsdorff's algorithm in Python 3 correctly or maybe all my > troubles are because I haven't read tutorial with enough patience? Your implementation looks fine to me. Some comments on the code itself: > class ChessBoard: > > size = 8 # Board square width and height. > cell = [] # Embedded list of board cells. This sets a class attribute (as opposed to normal, instance attributes) which is shared by all ChessBoard instances (this really should be covered in the FAQ!). You really want an instance attribute here: do `self.cell = []` in __init__ > def __init__(self): > > import sys > > # Reading board size. > > if len(sys.argv) >= 2: > self.size = int(sys.argv[1]) I would process command line arguments when the script starts, and supply size/x/y as parameters to the ChessBoard constructor. In other words, the caller must provide those parameters, it's not ChessBoard responsability to hunt for them. > if (next != 0): > (self.y, self.x) = (next.y, next.x) All those six () are unnecessary. Also, `next` might refer to integer 0 or a ChessBoardSquare instance. That's perfectly legal in Python, but *I* prefer to assign objects of the same type when using the same variable name. In this case, 0 is used only as a marker, any other non-ChessBoardSquare instance would do, and I'd substitute None instead. (This is more than a stylistic whim: some JIT compiler may benefit from knowing the object type won't change) > def printField(self): > """ This function prints field to standart output. for i in > range(self.size): > for j in range(self.size): > print(self.cell[i][j].status, end = '') > print() Instead of artificially iterate over the *indices* to finally reach the objects, you may directly iterate over the board squares: for row in self.cell: for square in row: print(square.status, end = '') print() Later: > applicants = [[y - 1, x - 2], [y - 1, x + 2], > [y + 1, x - 2], [y + 1, x + 2], > [y - 2, x - 1], [y - 2, x + 1], > [y + 2, x - 1], [y + 2, x + 1]] > result = [] > for applicant in applicants: > if applicant[0] < 0 or applicant[0] >= self.size: > continue > if applicant[1] < 0 or applicant[1] >= self.size: > continue > if self.cell[applicant[0]][applicant[1]].status == 0: > result.append(self.cell[applicant[0]][applicant[1]]) It would be better to use meaningful names instead of applicant[0], applicant[1] -- let me re-use y,x. We can write a more concise condition: result = [] for y,x in applicants: if not 0 <= y < self.size: continue if not 0 <= x < self.size: continue if self.cell[y][x].status == 0: result.append(self.cell[y][x]) Now, lets combine all those conditions into a single one: result = [] for y,x in applicants: if 0 <= y < self.size and 0 <= x < self.size and self.cell[y][x].status == 0: result.append(self.cell[y][x]) Finally, a code pattern like the above can always be rewritten as a list comprehension: result = [self.cell[y][x] for y,x in applicants if 0 <= y < self.size and 0 <= x < self.size and self.cell[y][x].status == 0 ] Apart from these points, your program looks fine to me. You even added function docstrings! (ok, they might be more informative, but at least they exist!) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 01:29:02 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 03:29:02 -0300 Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein escribi?: > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. See PEP3136 [1] and its rejection note [2] I think you may find some more discussion in the python-ideas list. > Currently I'm using boolean > flag variables, but I find that very clumsy. I know this idea of > breaking out of specific loops from javascript; I guess java does it > too. It just seems a very Pythonian idea to me: clear, promotes code > legibility, seems obvious. Although I've occasionally missed the feature myself, I agree with Guido's arguments against it. You have several alternatives: refactor the loop into an auxiliary function, use a specific exception, add boolean flags, or repeat the test at the outer levels. (I usually choose the first). [1] http://www.python.org/dev/peps/pep-3136/ [2] http://mail.python.org/pipermail/python-3000/2007-July/008663.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 01:35:12 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 03:35:12 -0300 Subject: How to dynamic insert more conditional statements into a function References: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> Message-ID: En Tue, 09 Mar 2010 18:48:42 -0300, Shane escribi?: > Hi I am a newbie for Python > > Here is a question, say I have a list L, > > function foo is: > > def foo(L): > if L[0] > 0: return True > > if later I want another function goo which returns "True" when L[0] > and L[1] are both > 0, i.e., > > def goo(L): > if L[0] > 0 and L[1] > 0: return True > > Can anybody tell me how can I write the function "goo" based upon the > function "foo"? Thanks! > I know if it is implementable, I should use "decorator". But I just > cannot figure out how. To implement goo based on foo: def goo(L): if foo(L) and L[1]>0: return True I don't see how to use a decorator here - maybe your example became too simple to be useful. A more realistic use case? -- Gabriel Genellina From agoretoy at gmail.com Wed Mar 10 01:58:13 2010 From: agoretoy at gmail.com (alex goretoy) Date: Wed, 10 Mar 2010 00:58:13 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: > > DATE_TYPE = type(date.today()) def dates_diff(self, *targs): nargs = len(targs) if nargs == 0: return self.enddate - self.startdate if nargs == 1: arg = targs[0] if not isinstance(arg, (list, tuple)) or len(arg) != 2: raise Exception( "single arg must be list or tuple of length 2") start, end = arg elif nargs == 2: start, end = targs else: raise Exception("expected 0,1, or 2 args; found %d" % nargs) if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE): return end - start raise Exception("both values must be of type DATE_TYPE") > HTH, > John This is awesome. Thank you for your contribution. I wasn't sure anyone was gonna reply; just saw your reply, pardon my delay. I will make the changes you suggested to other functions that apply in the lib as well(mimic that style of coding). Make it so it raises exceptions instead of failing over quietly(fallback to the __init__ passed args in other words). Is There any other functions or methods that you would recommend be added to the lib? Any and all other suggestions are welcome. I love python and you guys are practically helping me expand on my knowledge in this realm :) I haven't touched it in a little bit so after I mess with it again I'll be able to add more this thread/lib or whatever. Thanks Again, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Mar 10 02:04:04 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 04:04:04 -0300 Subject: Down casting Python objects References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> Message-ID: En Tue, 09 Mar 2010 18:26:52 -0300, Andrey Fedorov escribi?: > So I have `x', a instance of class `Foo'. I also have class `Bar', a > class > extending `Foo' with a couple of methods. I'd like to "down cast" x as > efficiently as possible. Is it OK to just set `x.__class__ = Bar' and > expect > things to work OK in all major versions of CPython? If the assignment x.__class__ = Bar succeeds, yes, that's enough. But you may not be able to reassign __class__ in some cases (e.g. Foo defines __slots__ but Bar doesn't, so you have a layout conflict). Of course, you always have to make sure Bar invariants hold on this particular instance... I must ask, why you didn't create a Bar instance in the first place? -- Gabriel Genellina From timr at probo.com Wed Mar 10 02:08:48 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 09 Mar 2010 23:08:48 -0800 Subject: file seek is slow References: Message-ID: Metalone wrote: > >static void main(int argc, char *argv[]) As a side note, do you realize that this definition is invalid, in two ways? "main" cannot be declared "static". The whole reason we use the special name "main" is so that the startup code in the C run-time can link to it. If "main" is static, it won't be exposed in the object file, and the linker couldn't find it. It happens to work here because your C compiler knows about "main" and discards the "static", but that's not a good practice. Further, it's not valid to have "main" return "void". The standards require that it be declared as returning "int". Again, "void" happens to work in VC++, but there are architectures where it does not. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From agoretoy at gmail.com Wed Mar 10 02:14:45 2010 From: agoretoy at gmail.com (alex goretoy) Date: Wed, 10 Mar 2010 01:14:45 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: I have another quick question. What would be the best way to implement dates length function? or should i just leave that up to the user using the lib? -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From agoretoy at gmail.com Wed Mar 10 02:23:31 2010 From: agoretoy at gmail.com (alex goretoy) Date: Wed, 10 Mar 2010 01:23:31 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: >>> import datelib >>> datelib.datelib().dates_list() [datetime.date(2009, 3, 10), datetime.date(2009, 4, 10), datetime.date(2009, 5, 10), datetime.date(2009, 6, 10), datetime.date(2009, 7, 10), datetime.date(2009, 8, 10), datetime.date(2009, 9, 10), datetime.date(2009, 10, 10), datetime.date(2009, 11, 10), datetime.date(2009, 12, 10), datetime.date(2010, 1, 10), datetime.date(2010, 2, 10), datetime.date(2010, 3, 10)] >>> len(datelib.datelib().dates_list()) 13 >>> I know i can do this and untested below: function dates_len(*targs, **dargs) return len(self.dates_list(*targs, **dargs)) Is this bloating the lib with unnecessary functions/methods? -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Mar 10 03:07:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 05:07:18 -0300 Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: En Tue, 09 Mar 2010 12:01:22 -0300, kishore escribi?: >> >> > Iam using python 2.5.4 >> > pyserial 2.4 >> > pywin32-214 >> > on windows 7 >> >> > i hav a small test script written to query a serial device (arduino) >> > and get back reply appropriately >> > > Thanks for your response > i tried closing idle and the following code prints > port opened > Write failed > > code: > > import serial > import time > ser=serial.Serial(port='\\.\COM2', baudrate=9600) If you want a string containing these 8 characters \\.\COM2 you have to write it either as r'\\.\COM2' or '\\\\.\\COM2' > if ser: > print 'port opened' Either the Serial object is constructed and returned, or an exception is raised. 'if ser:' has no sense; Python is not C... > ser.open() > if ser.write('1'): > print 'Write success' > else: > print 'write failed' The write method, when successful, implicitly returns None. None has a false boolean value, so your code will always print 'write failed'. Usually, in Python, error conditions are marked by raising an exception. Using return values to indicate success/failure is uncommon. Also, are you sure the device doesn't expect a newline character? '1\n'? You may need to call ser.flushOutput() to ensure the output buffer is actually emptied. > time.sleep(1) > a=ser.readline() print repr(a) > time.sleep(1) > b=ser.readline() print repr(b) > ser.close() > I believe this might be a serial port access error. > how to solve this? > Any suggestions? I don't think so. If you could not access the serial port, you'd have seen an IOError exception or similar. -- Gabriel Genellina From kishoreinme at gmail.com Wed Mar 10 03:39:36 2010 From: kishoreinme at gmail.com (kishore) Date: Wed, 10 Mar 2010 00:39:36 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: <85262eff-ac2d-4fe1-bca3-2840c13ef06d@b36g2000pri.googlegroups.com> On Mar 10, 1:07?pm, "Gabriel Genellina" wrote: > En Tue, 09 Mar 2010 12:01:22 -0300, kishore > escribi?: > > > > > > >> > Iam using python 2.5.4 > >> > pyserial ?2.4 > >> > pywin32-214 > >> > on windows 7 > > >> > i hav a small test script written to query a serial device (arduino) > >> > and get back reply appropriately > > > Thanks for your response > > i tried closing idle and the following code prints > > port opened > > Write failed > > > code: > > > import serial > > import time > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > If you want a string containing these 8 characters \\.\COM2 you have to > write it either as r'\\.\COM2' or '\\\\.\\COM2' > > > if ser: > > ? ?print 'port opened' > > Either the Serial object is constructed and returned, or an exception is > raised. 'if ser:' has no sense; Python is not C... > > > ser.open() > > if ser.write('1'): > > ? ?print 'Write success' > > else: > > ? ?print 'write failed' > > The write method, when successful, implicitly returns None. None has a > false boolean value, so your code will always print 'write failed'. > > Usually, in Python, error conditions are marked by raising an exception. > Using return values to indicate success/failure is uncommon. > > Also, are you sure the device doesn't expect a newline character? '1\n'? > > You may need to call ser.flushOutput() to ensure the output buffer is > actually emptied. > > > time.sleep(1) > > a=ser.readline() > > print repr(a) > > > time.sleep(1) > > b=ser.readline() > > print repr(b) > > > ser.close() > > I believe this might be a serial port access error. > > how to solve this? > > Any suggestions? > > I don't think so. If you could not access the serial port, you'd have seen > an IOError exception or similar. > > -- > Gabriel Genellina thanks Gabriel & Andy..ll get back soon here after trying ur suggestions From jeherul at gmail.com Wed Mar 10 04:06:28 2010 From: jeherul at gmail.com (JEHERUL) Date: Wed, 10 Mar 2010 14:36:28 +0530 Subject: about Telnetlib problem Message-ID: <46c1bcc21003100106s1db37a95ke928306c5e79d088@mail.gmail.com> Dear All I am trying to telnet to a Cisco router . Following is my code . #code router.py import getpass import sys import telnetlib HOST = "router address" # router address is ommitted for security reason user = raw_input("Username : ") password = getpass.getpass() tn = telnetlib.Telnet(HOST) tn.read_until("Username: ") tn.write(user + "\n") tn.read_until("Password: ") tn.write(password + "\n") tn.read_until("I>") tn.write("sh int f0/0") print "Just to check" print tn.read_all() print "after read" tn.write("exit\n") But when I execute the program I got the following error . Traceback (most recent call last): File "router.py", line 23, in ? print tn.read_all() File "/usr/lib/python2.4/telnetlib.py", line 330, in read_all self.fill_rawq() File "/usr/lib/python2.4/telnetlib.py", line 521, in fill_rawq buf = self.sock.recv(50) Please help me . Regards -- Jeherul Islam Indian Institute of Information Technology and Management . Gwalior (MP) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Mar 10 04:16:27 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Mar 2010 09:16:27 GMT Subject: odd error References: <4B96787B.3030907@timgolden.me.uk> Message-ID: On Tue, 09 Mar 2010 11:48:10 -0500, Alex Hall wrote: > Okay, I changed the keycode from 99 (c) to 107 (k), and the errors have > disappeared. However, now the function that should be called is not. As > I said in a previous message, I have always had trouble with this sort > of keystroke dictionary. It seems like, if a keycode is out of order or > not one more than the number before it, the function to which it is tied > will not get called. Dictionaries aren't ordered, that can't be the problem. > keys.append({ > 1 : (48, win32con.MOD_CONTROL), > 2 : (49, win32con.MOD_CONTROL), [...] Dicts don't have an append message. Why are you building a list and adding a dictionary to it? The question is, how many such dicts are in the list, and which one are you searching for the function? Is it possible that the problem is that you have multiple dicts in the keys list, and then perform your look-ups on the wrong one? Likewise for your list of functions: > funcs.append({ > 1 : exitProgram, > 2 : arm.sayLoad1, [...] Perhaps all you need is a single dict, mapping characters to functions: funcs = { # Just a dict # keycode: function 'q': exitProgram, 'a': arm.sayLoad1 # etc. } Then whenever you get a keyboard event, convert it to the character: keycode = 113 c = chr(keycode) funcs(c)() -- Steven From mail at timgolden.me.uk Wed Mar 10 04:25:53 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Mar 2010 09:25:53 +0000 Subject: odd error In-Reply-To: References: <4B96787B.3030907@timgolden.me.uk> Message-ID: <4B9765A1.1030509@timgolden.me.uk> On 10/03/2010 09:16, Steven D'Aprano wrote: > Perhaps all you need is a single dict, mapping characters to functions: > > funcs = { # Just a dict > # keycode: function > 'q': exitProgram, > 'a': arm.sayLoad1 > # etc. > } > > > Then whenever you get a keyboard event, convert it to the character: > > keycode = 113 > c = chr(keycode) > funcs(c)() FWIW (altho' it's not clear from the OP's code) he's basically doing this: http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html which uses the dictionary keys as an id in the call to RegisterHotKey. Obviously, that doesn't explain why he's building lists of dictionaries. TJG From robin.rytich at gmail.com Wed Mar 10 04:32:05 2010 From: robin.rytich at gmail.com (Robin Rytich) Date: Wed, 10 Mar 2010 12:32:05 +0300 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: <1268213525.12869.188.camel@rytich-laptop> On Wed, 2010-03-10 at 02:37 -0300, Gabriel Genellina wrote: > Warnsdorff's algorithm is heuristic; it works most of the time, but in > some cases leads to a dead end and you have to backtrack and try another > alternative. > The starting square is important; if you start at 1,1 (instead of 0,0) > your program finds a solution for all those problematic board sizes. Wow, didn't know about that. It seems to be a good idea for me to make a little research around this question. > Some comments on the code itself: > This sets a class attribute (as opposed to normal, instance attributes) > which is shared by all ChessBoard instances (this really should be covered > in the FAQ!). Damn, I'm ashamed. About other points, I actually totally agree with you (and corrected almost everything before received your letter). Thank you for your remarks, I'll review public code more careful next time. Robin Rytich From mehgcap at gmail.com Wed Mar 10 07:09:13 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 10 Mar 2010 07:09:13 -0500 Subject: odd error In-Reply-To: <4B9765A1.1030509@timgolden.me.uk> References: <4B96787B.3030907@timgolden.me.uk> <4B9765A1.1030509@timgolden.me.uk> Message-ID: I am honestly a bit lost as to why keys.append() is not a good choice here, but I have it working. I apparently have to use the ascii for capital letters if I am capturing the shift modifier, not the lowercase ascii. Using 67 instead of 99 works as expected. I use append because the program has three different modes. Eventually, each mode may have its own keystrokes. When the user switches modes, the previous mode's keystrokes are unregistered and the new keystrokes, keys[currentModeNumber], are registered. The same with the functions; when a function is called from the dictionary, it is called using funcs[currentModeNumber]. Again, this lets me put all my functions into one big list, where each member of the list is a dictionary. I probably have the terminology wrong, but hopefully that makes sense. Sorry for not explaining that earlier, but I was just looking for problems in the key codes. Thanks for your help! On 3/10/10, Tim Golden wrote: > On 10/03/2010 09:16, Steven D'Aprano wrote: >> Perhaps all you need is a single dict, mapping characters to functions: >> >> funcs = { # Just a dict >> # keycode: function >> 'q': exitProgram, >> 'a': arm.sayLoad1 >> # etc. >> } >> >> >> Then whenever you get a keyboard event, convert it to the character: >> >> keycode = 113 >> c = chr(keycode) >> funcs(c)() > > FWIW (altho' it's not clear from the OP's code) he's basically > doing this: > > http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html > > which uses the dictionary keys as an id in the call to RegisterHotKey. > > Obviously, that doesn't explain why he's building lists of dictionaries. > > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From mail at timgolden.me.uk Wed Mar 10 07:15:06 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Mar 2010 12:15:06 +0000 Subject: odd error In-Reply-To: References: <4B96787B.3030907@timgolden.me.uk> <4B9765A1.1030509@timgolden.me.uk> Message-ID: <4B978D4A.5060204@timgolden.me.uk> On 10/03/2010 12:09, Alex Hall wrote: > I am honestly a bit lost as to why keys.append() is not a good choice > here, but I have it working. That's ok; it's just not clear from the context why you have a list of dicts but your comment about different modes explains that. > I apparently have to use the ascii for > capital letters if I am capturing the shift modifier, not the > lowercase ascii. Using 67 instead of 99 works as expected. That's probably because the os is "preprocessing" the keystroke so that shift-a returns "A" and not "a". You might find that you don't even *need* the shift modifier in those circs. If I get the time this pm, I'll try to put together some example code which runs to more than 10 items in a dict just in case there is some bizarre cornercase which is causing a problem but I honestly doubt it. TJG From paskari007 at yahoo.ca Wed Mar 10 07:19:29 2010 From: paskari007 at yahoo.ca (PEYMAN ASKARI) Date: Wed, 10 Mar 2010 04:19:29 -0800 (PST) Subject: Importing Modules Message-ID: <676034.43316.qm@web30001.mail.mud.yahoo.com> Hello I frequent the PyGtk mailing list all the time, but this is the first time I am posting here =) I wanted to know if imported classes are treated differently than internal classes. I have attached a minimal example which points out what I mean. Essentially, if I create a class: class A(): ?__init__(self): ? pass and call A, or A() I get something to the effect of? <__main__.A instance at 0xb7f088ac> but if I call from module_name import A and then call A or A() I get something to the effect of? I was wondering if this would be a problem. I have included the test_import.py file as well as 4 module files which it loads. Save the tes_import.py file to a folder, create another folder there, and save ONLY the 4 modules files to that new folder. In the code, update line 26 to reflect to path of the newly created directory Thanks in advanced Peyman -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test_import.py Type: text/x-python Size: 2218 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_1.py Type: text/x-python Size: 67 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_2.py Type: text/x-python Size: 67 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_3.py Type: text/x-python Size: 67 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_4.py Type: text/x-python Size: 67 bytes Desc: not available URL: From jeanmichel at sequans.com Wed Mar 10 07:27:33 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 13:27:33 +0100 Subject: Import problem In-Reply-To: <4b957866$0$17135$426a34cc@news.free.fr> References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b957866$0$17135$426a34cc@news.free.fr> Message-ID: <4B979035.60505@sequans.com> News123 wrote: > Jean-Michel Pichavant wrote: > >> Johny wrote: >> >>> I have this directory structure >>> >>> C: >>> \A >>> __init__.py >>> amodule.py >>> >>> \B >>> __init__.py >>> bmodule.py >>> >>> \D >>> __init__.py >>> dmodule.py >>> >>> and I want to import bmodule.py >>> C:\>cd \ >>> >>> C:\>python >>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>> (Intel)] on win >>> 32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>>>>> from A.B import bmodule >>>>>> >>>>>> >>> I am bmodule >>> C:\> >>> >>> so far so good. Now I would like to import bmodule but if the current >>> directory is \D subdirectory. >>> >>> C:> cd \A\B\D >>> C:\A\B\D> >>> C:\A\B\D>python >>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>> (Intel)] on win >>> 32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>>>>> import sys >>>>>> sys.path.append('C:\\A') >>>>>> from A.B import bmodule >>>>>> >>>>>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named A.B >>> >>> C:\> >>> >>> so I can not import a module from the parent directory? Or where did I >>> make an error? >>> Thanks for help >>> >>> L. >>> >>> >> try >> >> import sys >> sys.path.append('C:\\') >> from A.B import bmodule >> >> > is there any 'automatic' way of finding the top level > directory?basically the 'top level directory is the first directory > going upwards, that doesn't contain a __init__.py file. > what if some user has an __init__.py file the top level directory of your package ? > of course you could do this 'manually' by > doing: > > # assume, that this module is A.amodule > import sys > import os > > # I'd love to have a similiar automatic construct > if __name__ == "__main__": > level = 1 # or function locating how far to go up before > # finding a dir, whcih does not contain a __init__.py > mydir = os.path.split(__file__)[0] > topdir = os.path.join( mydir,*(("..",)*level)) > abstop = os.path.abspath(topdir) > sys.path.append(abstop) > > ## now you can import with the normal module paths > > import A.blo > print "and I found blo",dir(A.blo) > > > bye N > > > > You don't want to do that and you don't need it neither. That's what the env variable PYTHONPATH is for. set it correctly, install your package inside and everything works just fine (+standard). With a linux OS it easy to create smb links to point to any working directory. It should be possible on windows as well. If your package is meant to be destributed, you may use setup.py JM From victorsubervi at gmail.com Wed Mar 10 07:32:15 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 10 Mar 2010 08:32:15 -0400 Subject: Interacting With Another Script Message-ID: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Hi; There's a program (vpopmail) that has commands which, when called, request input ("email address", "password", etc.) from the command line. I would like to build a TTW interface for my clients to use that interacts with these commands. It's easy enough for me to get the information from a script, but how do I input it when these functions keep requesting information? I hope I've made myself clear :-} TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Wed Mar 10 08:12:14 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 08:12:14 -0500 Subject: Can't define __call__ within __init__? Message-ID: Want to switch __call__ behavior. Why doesn't this work? What is the correct way to write this? class X (object): def __init__(self, i): if i == 0: def __call__ (self): return 0 else: def __call_ (self): return 1 x = X(0) x() TypeError: 'X' object is not callable From jeanmichel at sequans.com Wed Mar 10 08:22:36 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 14:22:36 +0100 Subject: Named loops for breaking In-Reply-To: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <4B979D1C.6090706@sequans.com> Daniel Klein wrote: > Hey, > > I did a little searching and couldn't really find much recent on this. > The only thing I found was this: > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/a696624c92b91181/5b7479fdc3362b83?lnk=gst&q=break+named+loop#5b7479fdc3362b83 > > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. Currently I'm using boolean > flag variables, but I find that very clumsy. I know this idea of > breaking out of specific loops from javascript; I guess java does it > too. It just seems a very Pythonian idea to me: clear, promotes code > legibility, seems obvious. > Strange that I've rarely been in need of such feature. Continues & breaks are mess-prone, adding an 'outter block' break feature would just increase the messing potential of such controls. Just my opinion though. Still there's a control that is able to break outter scopes : return. So embed your loop in a function and you'll be able to break whenever you want. JM From simon at brunningonline.net Wed Mar 10 08:27:31 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Mar 2010 13:27:31 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> On 10 March 2010 13:12, Neal Becker wrote: > Want to switch __call__ behavior. ?Why doesn't this work? ?What is the > correct way to write this? > > class X (object): > ? ?def __init__(self, i): > ? ? ? ?if i == 0: > ? ? ? ? ? ?def __call__ (self): > ? ? ? ? ? ? ? ?return 0 > ? ? ? ?else: > ? ? ? ? ? ?def __call_ (self): > ? ? ? ? ? ? ? ?return 1 > > > x = X(0) > > x() > TypeError: 'X' object is not callable __call__ is in the __init__ method's local namespace - you need to bind it to the class's namespace instead: X.__call__ = __call__ But this probably isn't what you want either, since all instances of X will share the same method. What are you trying to do? In your simple example, you'd be much better off with a single __call__ method. But you knew that. -- Cheers, Simon B. From anfedorov at gmail.com Wed Mar 10 08:31:14 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Wed, 10 Mar 2010 08:31:14 -0500 Subject: Down casting Python objects In-Reply-To: <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> Message-ID: <7659cab31003100531i51749f7er6f23ca0ef59cdddf@mail.gmail.com> On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury wrote: > Could you tell us *why* you need to down-cast x? Explicit type-casting is > usually unnecessary in Python... Sure! It's related to the longer question I unwisely asked during PyCon [1] (when no one had time to read it, I suppose). I have a couple of different flavors of request objects which I'd like to make conform to a single interface. So Request `x' come in, I determine which kind of request I'm dealing with, and would like to "down-cast" it to ARequest or BRequest, classes which will provide appropriate accessor properties for the rest of the code to use. An option clearly in line with Python's docs might be for `x' to be an attribute of an ARequest instance, but that would complicate the code of ARequest. What I'm looking for is a way of adding mix-in's at runtime, if that makes sense. Cheers, Andrey 1. http://mail.python.org/pipermail/python-list/2010-February/1236681.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Mar 10 08:40:19 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 10 Mar 2010 13:40:19 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: Neal Becker wrote: > Want to switch __call__ behavior. Why doesn't this work? What is the > correct way to write this? > > class X (object): > def __init__(self, i): > if i == 0: > def __call__ (self): > return 0 > else: > def __call_ (self): > return 1 > > > x = X(0) > > x() > TypeError: 'X' object is not callable > > I think it's because X has already been constructed when __init__ is called, so __new__ is the place for your conditional code. From ndbecker2 at gmail.com Wed Mar 10 08:41:28 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 08:41:28 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Simon Brunning wrote: > On 10 March 2010 13:12, Neal Becker wrote: >> Want to switch __call__ behavior. Why doesn't this work? What is the >> correct way to write this? >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> def __call__ (self): >> return 0 >> else: >> def __call_ (self): >> return 1 >> >> >> x = X(0) >> >> x() >> TypeError: 'X' object is not callable > > __call__ is in the __init__ method's local namespace - you need to > bind it to the class's namespace instead: > > X.__call__ = __call__ > > But this probably isn't what you want either, since all instances of X > will share the same method. > > What are you trying to do? In your simple example, you'd be much > better off with a single __call__ method. But you knew that. > Sorry, a bit early in the morning. This works: class X (object): def __init__(self, i): if i == 0: def F (self): return 0 else: def F (self): return 1 self.F = F def __call__ (self): return self.F (self) Not sure if there is a more elegant (or compact) way to write this. Could __call__ be defined directly within __init__? What I'm trying to do is make a callable whose behavior is switched based on some criteria that will be fixed for all calls. In my example, this will ultimately be determined by the setting of a command line switch. From martin.hellwig at dcuktec.org Wed Mar 10 08:54:27 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Mar 2010 13:54:27 +0000 Subject: Does this already exists?: A module that checks if the used platform is supported Message-ID: Hi all, Before I start reinventing a squared wheel, I have the following question: Is there already a (standard) module that wraps around the various os/sys information which checks if the platform + version is supported for what I want to do with it. For example I am currently looking at making a wrapper around sysctl, for Freebsd only (2.2 onwards perhaps later I add Linux if I feel up to it. So yes of course I can do a os.uname() but it struck me that there must be a better way. * If you think I made a thought error along the line and there is a better solution, please do tell me too :-) Thanks, -- mph * Something like: test = RequirePlatform(do_not_raise=True) test.require(platform='freebsd', version_min='2.2') # If the platform is anything else but FreeBSD 2.2+ # raise an EnvironmentError. Otherwise, store the # result of the test (True/False). # Result of the require (and any additional tests # can be accessed using the index operators if test[0]: print('supported') From mnordhoff at mattnordhoff.com Wed Mar 10 08:58:07 2010 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Wed, 10 Mar 2010 13:58:07 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: <4B97A56F.5060903@mattnordhoff.com> Neal Becker wrote: > Simon Brunning wrote: > >> On 10 March 2010 13:12, Neal Becker wrote: >>> Want to switch __call__ behavior. Why doesn't this work? What is the >>> correct way to write this? >>> >>> class X (object): >>> def __init__(self, i): >>> if i == 0: >>> def __call__ (self): >>> return 0 >>> else: >>> def __call_ (self): >>> return 1 >>> >>> >>> x = X(0) >>> >>> x() >>> TypeError: 'X' object is not callable >> __call__ is in the __init__ method's local namespace - you need to >> bind it to the class's namespace instead: >> >> X.__call__ = __call__ >> >> But this probably isn't what you want either, since all instances of X >> will share the same method. >> >> What are you trying to do? In your simple example, you'd be much >> better off with a single __call__ method. But you knew that. >> > > Sorry, a bit early in the morning. This works: > class X (object): > def __init__(self, i): > if i == 0: > def F (self): > return 0 > else: > def F (self): > return 1 > self.F = F > > def __call__ (self): > return self.F (self) > > > Not sure if there is a more elegant (or compact) way to write this. > Could __call__ be defined directly within __init__? > > What I'm trying to do is make a callable whose behavior is switched based on > some criteria that will be fixed for all calls. In my example, this will > ultimately be determined by the setting of a command line switch. ISTM it would be prettiest to do: class X(object): def __init__(self, i): self.flag = i == 0 def __call__(self): if self.flag: return 0 else: return 1 Or, if the comparison isn't particularly expensive, it would look nicer to just use self.i and do "self.i == 0" in __call__. Not that it matters, but this is probably faster than your version, too, since it saves a method call. By the way, IIRC Python only looks up double-underscore methods on the class, not the instance. That's why you had to indirect through self.F. -- Matt Nordhoff From jeanmichel at sequans.com Wed Mar 10 09:07:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 15:07:57 +0100 Subject: pexpect and logging integration In-Reply-To: <4B972EA7.50807@telcotec.se> References: <4B972EA7.50807@telcotec.se> Message-ID: <4B97A7BD.6050003@sequans.com> Lars Stavholm wrote: > Hi all, > > has anyone managed to integrate pexpect and logging? > > I.e., I'd like to be able to pick up the dialog, > commands sent and responses received, in my logging. > I know about the pexpect logfile, and I can log things > to stdout or stderr, but I really need to log using the > python logging library. > > Any thoughts appreciated > /Lars > > I had to implement this. It's a bit of a hack, but it does the job. The following code is tested with python 2.5, I remember pexpect behaves slightly differently in python 2.3. import logging import pexpect import re # this will be the method called by the pexpect object to log def _write(*args, **kwargs): content = args[0] # let's ignore other params, pexpect only use one arg AFAIK if content in [' ', '', '\n', '\r', '\r\n']: return # don't log empty lines for eol in ['\r\n', '\r', '\n']: # remove ending EOL, the logger will add it anyway content = re.sub('\%s$' % eol, '', content) return logger.info(content) # call the logger info method with the reworked content # our flush method def _doNothing(): pass # get the logger logger = logging.getLogger('foo') # configure the logger logger.handlers=[] logger.addHandler(logging.StreamHandler()) logger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) logger.setLevel(logging.INFO) # give the logger the methods required by pexpect logger.write = _write logger.flush = _doNothing p = pexpect.spawn('echo "hello world !!"', logfile=logger) p.expect('!!') ... 2010-03-10 15:01:31,234 - foo - INFO - hello world !! Hope it helps. JM From jeanmichel at sequans.com Wed Mar 10 09:10:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 15:10:10 +0100 Subject: about Telnetlib problem In-Reply-To: <46c1bcc21003100106s1db37a95ke928306c5e79d088@mail.gmail.com> References: <46c1bcc21003100106s1db37a95ke928306c5e79d088@mail.gmail.com> Message-ID: <4B97A842.4030709@sequans.com> JEHERUL wrote: > Dear All > > I am trying to telnet to a Cisco router . Following is my code . > > #code router.py > > import getpass > import sys > import telnetlib > > HOST = "router address" # router address is ommitted for > security reason > user = raw_input("Username : ") > password = getpass.getpass() > > tn = telnetlib.Telnet(HOST) > > tn.read_until("Username: ") > tn.write(user + "\n") > tn.read_until("Password: ") > tn.write(password + "\n") > > > tn.read_until("I>") > tn.write("sh int f0/0") > > print "Just to check" > > > print tn.read_all() > > print "after read" > tn.write("exit\n") > > > > But when I execute the program I got the following error . > > > Traceback (most recent call last): > File "router.py", line 23, in ? > print tn.read_all() > File "/usr/lib/python2.4/telnetlib.py", line 330, in read_all > self.fill_rawq() > File "/usr/lib/python2.4/telnetlib.py", line 521, in fill_rawq > buf = self.sock.recv(50) > > Please help me . > > Regards > -- > Jeherul Islam > Indian Institute of Information Technology and Management . > Gwalior (MP) > > Hi, Your error trace is incomplete it's missing the exception. It would be better if you provide it. JM From tjreedy at udel.edu Wed Mar 10 09:21:12 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 09:21:12 -0500 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: On 3/10/2010 12:37 AM, Gabriel Genellina wrote: >> if (next != 0): >> (self.y, self.x) = (next.y, next.x) In Python3, next is a builtin function. Choose a different name, at least in public code ;=). From richardbp at gmail.com Wed Mar 10 09:29:03 2010 From: richardbp at gmail.com (Richard) Date: Wed, 10 Mar 2010 06:29:03 -0800 (PST) Subject: os.rename [Errno 31] Too many links Message-ID: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> I want to atomically write to a file so have been using temporary files and renaming: temp = tempfile.NamedTemporaryFile(delete=False) temp.file.write(data) temp.file.close() os.rename(temp.name, output_file) This worked but after 39567 files os.rename raises an OSError: [Errno 31] Too many links I can still create files in this directory so I doubt it is a platform limitation. Can you tell what is wrong? Am I not freeing the temporary file resources properly? thanks, Richard From tjreedy at udel.edu Wed Mar 10 09:32:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 09:32:03 -0500 Subject: Importing Modules In-Reply-To: <676034.43316.qm@web30001.mail.mud.yahoo.com> References: <676034.43316.qm@web30001.mail.mud.yahoo.com> Message-ID: On 3/10/2010 7:19 AM, PEYMAN ASKARI wrote: > Hello > > I frequent the PyGtk mailing list all the time, but this is the first > time I am posting here =) > > I wanted to know if imported classes are treated differently than > internal classes. > > I have attached a minimal example which points out what I mean. > Essentially, if I create a class: > > class A(): > __init__(self): > pass > > and call A, or A() I get something to the effect of <__main__.A instance > at 0xb7f088ac> > > but if I call from module_name import A and then call A or A() I get > something to the effect of > > I was wondering if this would be a problem. Only if you code cares about A.__module__ (3.x, not sure of 2.x) and the string returned by str or repr, which nearly always, it should not. tjr From jjposner at optimum.net Wed Mar 10 09:45:38 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Mar 2010 09:45:38 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b911ee0$0$4988$607ed4bc@cv.net> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> Message-ID: <4B97B092.4060901@optimum.net> [ cross-posting to edu-sig ] Bruno (and anyone else interested) -- As I promised/threatened, here's the *start* of a write-up on properties, aimed at non-advanced Python programmers: http://www.jjposner.net/media/python-properties-0310.pdf I'm interested in corrections, of course. But I'm also interested in opinions as to whether this somewhat lengthy treatment is worth the effort -- does it improve on existing write-ups? Tx, John From bringa at gmail.com Wed Mar 10 10:15:47 2010 From: bringa at gmail.com (Daniel Klein) Date: Wed, 10 Mar 2010 07:15:47 -0800 (PST) Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <43248058-f388-4127-904a-e0c2e80a36e4@33g2000yqj.googlegroups.com> Thanks for the link to the PEP. I should search through PEPs first next time :) Okay, I understand Guido's reasoning and yield the point. I typed up the specific example in which I came across this problem and, while doing so, realized there's a much better way of approaching the problem, so thank you for that as well :) From jpeck at fedex.com Wed Mar 10 10:17:12 2010 From: jpeck at fedex.com (Jeff Peck) Date: Wed, 10 Mar 2010 09:17:12 -0600 Subject: Bluetooth In-Reply-To: References: Message-ID: <4B97B7F8.2030303@fedex.com> On 3/7/2010 1:26 PM, PythonAB wrote: > Hello, > > > I'm writing a script that has to connect a bluetooth device > with a 3D application. > On my search for a bluetooth module i ran into this: > http://www.python.org/download/releases/2.4/notes/ > where it says: > "The socket module now supports Bluetooth sockets, > if the system has " > > Yet I can't find anything at all in the socket manuals > nor anywhere else on the site... > > Does the socket module really support Bluetooth out of the box? > I've used socket before but never read anything about bluetooth... > > Maybe I need to get the bluetooth.h file, but i have no idea what I > am supposed to do with it... > > Can anyone shed some light on this for me please? > > thanks in advance, > > gr > Arno Have you come across the PyBluez library yet? I recently used it in a project and it worked very well. Hth, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Wed Mar 10 10:19:04 2010 From: no.email at please.post (kj) Date: Wed, 10 Mar 2010 15:19:04 +0000 (UTC) Subject: Anything like "Effective Java" for Python? Message-ID: Subject line pretty much says it all: is there a book like "Effective Java" for Python. I.e. a book that assumes that readers are experienced programmers that already know the basics of the language, and want to focus on more advanced programming issues? ~K From simon at brunningonline.net Wed Mar 10 10:29:44 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Mar 2010 15:29:44 +0000 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <8c7f10c61003100729j2afba0c9rf00760e48f535249@mail.gmail.com> On 10 March 2010 15:19, kj wrote: > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. ?I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? is good. -- Cheers, Simon B. From echerlin at gmail.com Wed Mar 10 10:31:35 2010 From: echerlin at gmail.com (Edward Cherlin) Date: Wed, 10 Mar 2010 10:31:35 -0500 Subject: [Edu-sig] Method / Functions - What are the differences? In-Reply-To: <4B97B092.4060901@optimum.net> References: <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> <4B97B092.4060901@optimum.net> Message-ID: On Wed, Mar 10, 2010 at 09:45, John Posner wrote: > [ cross-posting to edu-sig ] > > Bruno (and anyone else interested) -- > > As I promised/threatened, here's the *start* of a write-up on properties, > aimed at non-advanced Python programmers: > > ?http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested in corrections, of course. But I'm also interested in > opinions as to whether this somewhat lengthy treatment is worth the effort > -- does it improve on existing write-ups? I find that it will explain things to those who already understand most of the concepts. However, I felt as though I were being led through a maze without knowing where we were headed. This suggests that the concepts can be re-ordered in a manner that will help your readers more, and then we can refactor further. (Yes, you can apply Extreme Programming concepts to create Extreme Documentation, including consultations with users, pair or group writing, frequent refactoring, and more, as at FLOSSManuals.net.) Who is your expected audience? > Tx, > John > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- Edward Mokurai (??/???????????????/????????????? ?) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://www.earthtreasury.org/ From bsagert at gmail.com Wed Mar 10 10:55:27 2010 From: bsagert at gmail.com (Bill) Date: Wed, 10 Mar 2010 07:55:27 -0800 (PST) Subject: I passed a fizzbuzz test but failed at recursion. Message-ID: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Look at this recursive fizzbuzz function from http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html def fizzbuzz(num): if num: if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' else : return fizzbuzz(num-1) + ('%d \n' % num) return '' print fizzbuzz(100) This returns "1 2 fizz 4 ...etc... 97 98 fizz buzz" which is correct. However, when I try to decipher the logic of the function I imagine the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". After all, the first num is 100 which decrements by one until a zero stops the recursive loop. My (faulty) reasoning is that fizzbuzz(100) would firstly print a "fizz" and the last fizzbuzz(1) would finally print a "1". My logic is wrong, but I don't know why. From hv at tbz-pariv.de Wed Mar 10 11:08:44 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 10 Mar 2010 17:08:44 +0100 Subject: os.rename [Errno 31] Too many links In-Reply-To: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> References: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> Message-ID: <7vpugdF5bqU1@mid.individual.net> Richard wrote: > I want to atomically write to a file so have been using temporary > files and renaming: > > temp = tempfile.NamedTemporaryFile(delete=False) > temp.file.write(data) > temp.file.close() > os.rename(temp.name, output_file) > > This worked but after 39567 files os.rename raises an OSError: [Errno > 31] Too many links > > I can still create files in this directory so I doubt it is a platform > limitation. > Can you tell what is wrong? Am I not freeing the temporary file > resources properly? If you are on linux you can have a look at the open file descriptors of a running process like this: ls -l /proc/PID/fd/ But I guess it is a limitation of your filesystem. What do you use? I once had this problem with ext2. It has a low limit for subdirectories. With xfs the limits are much greater. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From chris.hulan at gmail.com Wed Mar 10 11:24:00 2010 From: chris.hulan at gmail.com (Chris Hulan) Date: Wed, 10 Mar 2010 08:24:00 -0800 (PST) Subject: I passed a fizzbuzz test but failed at recursion. References: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Message-ID: <749d9c6e-f41f-4859-9c57-459caeddf6e4@j27g2000yqn.googlegroups.com> On Mar 10, 10:55?am, Bill wrote: > Look at this recursive fizzbuzz function fromhttp://www.codinghorror.com/blog/2007/02/why-cant-programmers-program... > > def fizzbuzz(num): > ? ? if num: > ? ? ? ? if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' > ? ? ? ? elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' > ? ? ? ? elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' > ? ? ? ? else : return fizzbuzz(num-1) + ('%d \n' % num) > ? ? return '' > print fizzbuzz(100) > > This returns "1 2 fizz 4 ...etc... 97 98 fizz buzz" which is correct. > > However, when I try to decipher the logic of the function I imagine > the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". > > After all, the first num is 100 which decrements by one until a zero > stops the recursive loop. > > My (faulty) reasoning is that fizzbuzz(100) would firstly print a > "fizz" and ?the last fizzbuzz(1) would finally print a "1". > > My logic is wrong, but I don't know why. There's only one print, it prints the string returned by fizzbuzz(100) The string is constructed via recursion ie: fizzbuzz(6) fizzbuzz(5) fizzbuzz(4) fizzbuzz(3) fizzbuzz(2) fizzbuzz(1) fizzbuzz(0) ''+'1 \n' '1 \n'+'2 \n' '1 \n2 \n'+'fizz \n' '1 \n2 \n fizz \n'+'4 \n' '1 \n2 \n fizz \n4 \n'+'buzz \n' '1 \n2 \n fizz \n4 \nbuzz \n'+'fizz \n' print '1 \n2 \n fizz \n4 \nbuzz \nfizz \n' clear as mud ;) From clp2 at rebertia.com Wed Mar 10 11:31:06 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Mar 2010 08:31:06 -0800 Subject: Interacting With Another Script In-Reply-To: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Message-ID: <50697b2c1003100831l302a84e2j1aeaf351dd4e1fe6@mail.gmail.com> On Wed, Mar 10, 2010 at 4:32 AM, Victor Subervi wrote: > Hi; > There's a program (vpopmail) that has commands which, when called, request > input ("email address", "password", etc.) from the command line. I would > like to build a TTW interface for my clients to use that interacts with > these commands. It's easy enough for me to get the information from a > script, but how do I input it when these functions keep requesting > information? I hope I've made myself clear :-} (assuming TTW = Thru The Web; been a while since I've come across an unknown, non-new acronym) [Disclaimer: I know zilch about vpopmail's specifics] Option A. Check for when the latest output looks prompt-like (e.g. colon followed by a space; this will be program-specific and possibly different for vpopmail) and then ask for input. For example: 1. Get new session request from client 2. Run new vpopmail process 3. Wait until prompt detected in process' output 4. Send back webpage with the output and a
to answer the prompt 5. Write user's response from form as input to process. 6. If read EOF, send final output back as webpage to client and close session. Else, GOTO 3 (See also: expect) Option B. Web pseudo-shell using AJAX. Client polls server for new output. Client pushes new input to server at any time. 1. Get new session request from client 2. Run new vpopmail process 3. Send back webpage w/ JavaScript code 4.1. Client periodically polls server for new output via AJAX and displays it when there is some. 4.2. Client has omnipresent that on submission sends an AJAX request to the server with the given input. 5. If get input message from client, write input to process' stdin. If get polling message from client, do non-blocking read on the process' output and respond with the result. If get EOF, inform client on next poll and then close session. Option C. The most user-friendly, and in some sense simplest, one. Figure out the "conversation tree" vpopmail follows. Create a matching form tree workflow, presenting multiple input fields at once. Run vpopmail and write the appropriate input to its stdin based on the form data. Send the output back as a webpage. [Session management & timeouts in the preceding are left as exercises for the implementor] Option D. The Zen option: It seems quite probable that someone's already written a web frontend for vpopmail administration/configuration. Just use that. The best software is that which you don't have to write. Cheers, Chris -- Ironically, I have yet to code a webapp. http://blog.rebertia.com From clp2 at rebertia.com Wed Mar 10 11:39:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Mar 2010 08:39:57 -0800 Subject: Interacting With Another Script In-Reply-To: <4dc0cfea1003100834g5d611cdcg63842d385f350fe7@mail.gmail.com> References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> <50697b2c1003100831l302a84e2j1aeaf351dd4e1fe6@mail.gmail.com> <4dc0cfea1003100834g5d611cdcg63842d385f350fe7@mail.gmail.com> Message-ID: <50697b2c1003100839w5dc9a63fo5702ef1e842f40da@mail.gmail.com> On Wed, Mar 10, 2010 at 8:34 AM, Victor Subervi wrote: > On Wed, Mar 10, 2010 at 12:31 PM, Chris Rebert wrote: >> Option C. The most user-friendly, and in some sense simplest, one. >> Figure out the "conversation tree" vpopmail follows. Create a matching >> form tree workflow, presenting multiple input fields at once. Run >> vpopmail and write the appropriate input to its stdin based on the >> form data. Send the output back as a webpage. > > Yeah, that was my idea. But how does the program know when it's being > prompted to enter data? That's my question ;) There's no magical "prompt time". The process's stdin's openness to writing is not conditional. Just send it all the input at once with the proper newlines in place and it should work just fine assuming the user input was valid (barring vpopmail using some fancy terminal input malarkey like curses). Cheers, Chris -- http://blog.rebertia.com From invalid at invalid.invalid Wed Mar 10 11:44:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Mar 2010 16:44:29 +0000 (UTC) Subject: Interacting With Another Script References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> <50697b2c1003100831l302a84e2j1aeaf351dd4e1fe6@mail.gmail.com> <4dc0cfea1003100834g5d611cdcg63842d385f350fe7@mail.gmail.com> Message-ID: On 2010-03-10, Chris Rebert wrote: > On Wed, Mar 10, 2010 at 8:34 AM, Victor Subervi wrote: > >> Yeah, that was my idea. But how does the program know when it's being >> prompted to enter data? That's my question ;) > > There's no magical "prompt time". That depends on the program. Some programs that prompt for input (particulary username/password) flush stdin before displaying each prompt. I'm not saying the program in question does that... > The process's stdin's openness to writing is not conditional. That doesn't mean that data written prior to the prompt won't be ignore. > Just send it all the input at once with the proper newlines in place > and it should work just fine assuming the user input was valid > (barring vpopmail using some fancy terminal input malarkey like > curses). It's worth trying, but there's a slight chance it won't work. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From chris at simplistix.co.uk Wed Mar 10 11:46:23 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 10 Mar 2010 16:46:23 +0000 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <4B97CCDF.7070802@simplistix.co.uk> kj wrote: > > > Subject line pretty much says it all: is there a book like "Effective > Java" oxymoronic, no? Sorry, couldn't resist ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From krishna.k.0001 at gmail.com Wed Mar 10 11:47:44 2010 From: krishna.k.0001 at gmail.com (Krishna K) Date: Wed, 10 Mar 2010 08:47:44 -0800 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} In-Reply-To: <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> Message-ID: On Fri, Feb 19, 2010 at 11:27 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Fri, Feb 19, 2010 at 10:36 PM, krishna > wrote: > > I have to manage a couple of dicts with huge dataset (larger than > > feasible with the memory on my system), it basically has a key which > > is a string (actually a tuple converted to a string) and a two item > > list as value, with one element in the list being a count related to > > the key. I have to at the end sort this dictionary by the count. > > > > The platform is linux. I am planning to implement it by setting a > > threshold beyond which I write the data into files (3 columns: 'key > > count some_val' ) and later merge those files (I plan to sort the > > individual files by the key column and walk through the files with one > > pointer per file and merge them; I would add up the counts when > > entries from two files match by key) and sorting using the 'sort' > > command. Thus the bottleneck is the 'sort' command. > > > > Any suggestions, comments? > > > > You should be using BDBs or even something like PostgreSQL. The > indexes there will give you the scalability you need. I doubt you will > be able to write anything that will select, update, insert or delete > data better than what BDBs and PostgreSQL can give you. > > -- > Jonathan Gardner > jgardner at jonathangardner.net Thank you. I tried BDB, it seems to get very very slow as you scale. Thank you, Krishna -------------- next part -------------- An HTML attachment was scrubbed... URL: From phlip2005 at gmail.com Wed Mar 10 11:54:51 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 10 Mar 2010 08:54:51 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: Martin P. Hellwig wrote: > Well even if this statement would be true, I personally think that not > proclaiming something a 'standard' if you are sure that you are not sure > about it, is a virtue. In terms of trying too hard to achieve perfection, am I missing a Python repository similar to the C++ Boost project? All the nice-to- have classes that extend the core of C++ get to live in Boost before the C++ Committee pulls the best ideas off the top and add them to the Standard Library... -- Phlip http://penbird.tumblr.com/ From clp2 at rebertia.com Wed Mar 10 12:15:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Mar 2010 09:15:07 -0800 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <50697b2c1003100915u206aaef9n314503b3cb9d6187@mail.gmail.com> On Wed, Mar 10, 2010 at 8:54 AM, Phlip wrote: > Martin P. Hellwig wrote: >> Well even if this statement would be true, I personally think that not >> proclaiming something a 'standard' if you are sure that you are not sure >> about it, is a virtue. > > In terms of trying too hard to achieve perfection, am I missing a > Python repository similar to the C++ Boost project? All the nice-to- > have classes that extend the core of C++ get to live in Boost before > the C++ Committee pulls the best ideas off the top and add them to the > Standard Library... The next closest thing would probably be the Python Cookbook: http://code.activestate.com/recipes/langs/python/ However, such stuff can also be found as third-party modules. Cheers, Chris -- http://blog.rebertia.com From duncan.booth at invalid.invalid Wed Mar 10 12:26:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Mar 2010 17:26:46 GMT Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> <13c167f4-5e37-48a0-a480-3494c212035c@k5g2000pra.googlegroups.com> Message-ID: Xah Lee wrote: > On Mar 8, 11:14??am, Duncan Booth > wrote: >> Xah Lee wrote: >> > For example, consider, if you are within world's top 100th user of >> > database in terms of database size, such as Google, then it may be >> > that the off-the-shelf tools may be limiting. But how many users >> > really have such massive size of data? >> >> You've totally missed the point. It isn't the size of the data you >> have today that matters, it's the size of data you could have in >> several years > ' >> time. > > so, you saying, in several years, we'd all become the world's top 100 > database users in terms of size, like Google? > No, I'm saying that if you plan to build a business that could grow you should be clear up front how you plan to handle the growth. It's too late if you suddenly discover your platform isn't scalable just when you need to scale it. From duncan.booth at invalid.invalid Wed Mar 10 12:39:27 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Mar 2010 17:39:27 GMT Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Neal Becker wrote: > What I'm trying to do is make a callable whose behavior is switched > based on some criteria that will be fixed for all calls. In my > example, this will ultimately be determined by the setting of a > command line switch. > If you want different behaviour its usually best to use different classes. You can keep all the common behaviour in a base class and just override the __call__ method for the different behaviour. Then use a factory function to decide which class to instantiate or else override __new__ and make the decision there. e.g. >>> class X(object): def __call__(self): return 0 def __new__(cls, i): if i!=0: cls = Y return object.__new__(cls) >>> class Y(X): def __call__(self): return 1 >>> x = X(0) >>> x() 0 >>> y = X(1) >>> y() 1 >>> isinstance(x, X) True >>> isinstance(y, X) True P.S. I don't know what you did in your post but your Followup-To header is pointing to a group on gmane which makes extra work for me replying. Please don't do that. From dickinsm at gmail.com Wed Mar 10 12:47:19 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Mar 2010 09:47:19 -0800 (PST) Subject: Calculating very large exponents in python References: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> Message-ID: On Mar 9, 6:39?am, casevh wrote: > [also replying to Geremy since the OP's message doesn't appear...] > > On Mar 8, 11:05?am, geremy condra wrote: > > > > > > > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > > > Thanks Geremy, > > > > That has been an absolute bump........... GOD i cant sit on my chair, it has > > > worked even on 512 bit number and with no time.......... > > > superb i would say. > > > > lastly, i am using the code below to calculate Largest Prime factor of a > > > number: > > > > print > > > ('''======================================================================= ?========''' > > > ?????? '''????????????? CALCULATE? HIGHEST PRIME > > > FACTOR????????????????????????????????? ''' > > > > '''======================================================================== ?=======''') > > > > #!/usr/bin/env python > > > def highest_prime_factor(n): > > > ?? if isprime(n): > > > ????? return n > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return highest_prime_factor(n/x) > > > def isprime(n): > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return False > > > ?? return True > > > if? __name__ == "__main__": > > > ?? import time > > > ?? start = time.time() > > > ?? print highest_prime_factor(1238162376372637826) > > > ?? print time.time() - start > > > > the code works with a bit of delay on the number : "1238162376372637826" but > > > extending it to > > > (10902610991329142436630551158108608965062811746392577675456004845499113044 ?30471090261099132914243663055115810860896506281174639257767545600484549911 3?0443047) > > > ?makes python go crazy. Is there any way just like above, i can have it > > > calculated it in no time. > > > > thanks for the support. > > > If you're just looking for the largest prime factor I would suggest using > > a fermat factorization attack. In the example you gave, it returns > > nearly immediately. > > > Geremy Condra- Hide quoted text - > > > - Show quoted text - > > For a Python-based solution, you might want to look at pyecm (http:// > sourceforge.net/projects/pyecm/) > > On a system with gmpy installed also, pyecm found the following > factors: > > 101, 521, 3121, 9901, 36479, 300623, 53397071018461, > 1900381976777332243781 > > There still is a 98 digit unfactored composite: > > 602525071745682437589111511878284384468144476539868422797968232621651594065 00174226172705680274911 > > Factoring this remaining composite using ECM may not be practical. > > casevh The complete factorization is: 101 x 521 x 3121 x 9901 x 36479 x 300623 x 53397071018461 x 1900381976777332243781 x 6060517860310398033985611921721 x 9941808367425935774306988776021629111399536914790551022447994642391 It helps if you notice that the digits of the original 156-digit number come from concatenating a 78-digit string to itself, giving an immediate factor of 10**78 + 1. (Oops. Perhaps this was supposed to be a secret back door to the OP's crypto scheme. I've given it away now. :)) -- Mark From barry at python.org Wed Mar 10 12:50:10 2010 From: barry at python.org (Barry Warsaw) Date: Wed, 10 Mar 2010 12:50:10 -0500 Subject: Python 2.6.5 release candidate 2 now available Message-ID: <20100310125010.415f838e@heresy.wooz.org> Hi everyone, The source tarballs and Windows installer for Python 2.6.5 release candidate 2 are now available: http://www.python.org/download/releases/2.6.5/ As usual, please download, install, and test them with your favorite projects and environments. A number of regressions and build problems on OS X have been fixed since rc1, and I'm really hoping we will not have to do an rc3. I'm currently planning on releasing 2.6.5 final on March 19, 2010. Enjoy, -Barry P.S. The Mac installer will hopefully be available soon. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From dickinsm at gmail.com Wed Mar 10 12:51:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Mar 2010 09:51:23 -0800 (PST) Subject: Calculating very large exponents in python References: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> Message-ID: <9a244983-53ab-4ee5-a176-c67332337c96@15g2000yqi.googlegroups.com> On Mar 9, 1:54?pm, casevh wrote: > After a few hours, the remaining factors are > > 6060517860310398033985611921721 > > and > > 9941808367425935774306988776021629111399536914790551022447994642391 > > casevh Whoops---I missed this. I'm too slow! But at least my answers agree with yours. (Factoring 10**78+1 took around 7 seconds using GP/Pari on a 2.5 GHz MacBook; factoring the remaining quotient n / (10**78+1) was much quicker.) -- Mark From tjreedy at udel.edu Wed Mar 10 12:52:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 12:52:47 -0500 Subject: I passed a fizzbuzz test but failed at recursion. In-Reply-To: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> References: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Message-ID: On 3/10/2010 10:55 AM, Bill wrote: > Look at this recursive fizzbuzz function from > http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html > > def fizzbuzz(num): > if num: > if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' > elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' > elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' In all 3 branches, 'is' should be '=='. As written, this code depends on the implementation treating 0 as a singleton, which CPython does as an optimization, but which the language def does not require. > else : return fizzbuzz(num-1) + ('%d \n' % num) > return '' > print fizzbuzz(100) > > This returns "1 2 fizz 4 ...etc... 97 98 fizz buzz" which is correct. > > However, when I try to decipher the logic of the function I imagine > the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". > > After all, the first num is 100 which decrements by one until a zero > stops the recursive loop. > > My (faulty) reasoning is that fizzbuzz(100) would firstly print a > "fizz" and the last fizzbuzz(1) would finally print a "1". If one reversed the string addition in each branch, it would. As written, the 'word' for n is tacked on at the end. > My logic is wrong, but I don't know why. Is this slightly revised version any clearer? def fizzbuzz_rb(n): if n: previous = fizzbuzz_rb(n-1) word = (not n % 15 and 'fizzbuzz \n' or not n % 5 and 'buzz \n' or not n % 3 and 'fizz \n' or '%d \n' % n) return previous + word else: return '' or this equivalent tail-recursive version? def fizzbuzz_rt(i,n,s): if i <= n: word = (not i % 15 and 'fizzbuzz \n' or not i % 5 and 'buzz \n' or not i % 3 and 'fizz \n' or '%d \n' % i) return fizzbuzz_rt(i+1, n, s+word) else: return s or this equivalent iterative version? def fizzbuzz_it(n): s = '' for i in range(1,n+1): s += (not i % 15 and 'fizzbuzz \n' or not i % 5 and 'buzz \n' or not i % 3 and 'fizz \n' or '%d \n' % i) return s print (fizzbuzz_rb(100) == fizzbuzz_rt(1,100,'') == fizzbuzz_it(100)) # prints True Terry Jan Reedy From ndbecker2 at gmail.com Wed Mar 10 13:23:02 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 13:23:02 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Duncan Booth wrote: ... > > P.S. I don't know what you did in your post but your Followup-To header is > pointing to a group on gmane which makes extra work for me replying. > Please don't do that. I'm sorry about that, there is some bad interaction between gmane's nntp- smtp gateway and python's mail list. I don't know what to do about it. I think the problem only happens on python's mail list (I've never seen it reported on any of the MANY other lists I use via gmane). From duncan.booth at invalid.invalid Wed Mar 10 13:37:59 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Mar 2010 18:37:59 GMT Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Neal Becker wrote: > Duncan Booth wrote: > ... >> >> P.S. I don't know what you did in your post but your Followup-To >> header is pointing to a group on gmane which makes extra work for me >> replying. Please don't do that. > > I'm sorry about that, there is some bad interaction between gmane's > nntp- smtp gateway and python's mail list. I don't know what to do > about it. I think the problem only happens on python's mail list > (I've never seen it reported on any of the MANY other lists I use via > gmane). > Are the other mailing lists gatewayed from Usenet? It may not matter if there's a followup-to header on a mailing list, it probably just gets ignored, but it does matter on Usenet (which after all is what Gmane is emulating). From debatem1 at gmail.com Wed Mar 10 13:49:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 10 Mar 2010 13:49:59 -0500 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} In-Reply-To: References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> Message-ID: On Wed, Mar 10, 2010 at 11:47 AM, Krishna K wrote: > > > On Fri, Feb 19, 2010 at 11:27 PM, Jonathan Gardner > wrote: >> >> On Fri, Feb 19, 2010 at 10:36 PM, krishna >> wrote: >> > I have to manage a couple of dicts with huge dataset (larger than >> > feasible with the memory on my system), it basically has a key which >> > is a string (actually a tuple converted to a string) and a two item >> > list as value, with one element in the list being a count related to >> > the key. I have to at the end sort this dictionary by the count. >> > >> > The platform is linux. I am planning to implement it by setting a >> > threshold beyond which I write the data into files (3 columns: 'key >> > count some_val' ) and later merge those files (I plan to sort the >> > individual files by the key column and walk through the files with one >> > pointer per file and merge them; I would add up the counts when >> > entries from two files match by key) and sorting using the 'sort' >> > command. Thus the bottleneck is the 'sort' command. >> > >> > Any suggestions, comments? >> > >> >> You should be using BDBs or even something like PostgreSQL. The >> indexes there will give you the scalability you need. I doubt you will >> be able to write anything that will select, update, insert or delete >> data better than what BDBs and PostgreSQL can give you. >> >> -- >> Jonathan Gardner >> jgardner at jonathangardner.net > > Thank you. I tried BDB, it seems to get very very slow as you scale. > > Thank you, > Krishna Have you tried any of the big key-value store systems, like couchdb etc? Geremy Condra From mrkafk at gmail.com Wed Mar 10 13:58:07 2010 From: mrkafk at gmail.com (mk) Date: Wed, 10 Mar 2010 19:58:07 +0100 Subject: Text mining in Python Message-ID: Hello everyone, I need to do the following: (0. transform words in a document into word roots) 1. analyze a set of documents to see which words are highly frequent 2. detect clusters of those highly frequent words 3. map the clusters to some "special" keywords 4. rank the documents on clusters and "top n" most frequent words 5. provide search that would rank documents according to whether search words were "special" cluster keywords or frequent words Is there some good open source engine out there that would be suitable to the task at hand? Anybody has experience with them? Now, I do now about NLTK and Python bindings to UIMA. The thing is, I do not know if those are good for the above task. If somebody has experience with those or other and would be able to say if they're good for this, please post. Regards, mk From robert.kern at gmail.com Wed Mar 10 14:05:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 13:05:38 -0600 Subject: Text mining in Python In-Reply-To: References: Message-ID: On 2010-03-10 12:58 PM, mk wrote: > Hello everyone, > > I need to do the following: > > (0. transform words in a document into word roots) > > 1. analyze a set of documents to see which words are highly frequent > > 2. detect clusters of those highly frequent words > > 3. map the clusters to some "special" keywords > > 4. rank the documents on clusters and "top n" most frequent words > > 5. provide search that would rank documents according to whether search > words were "special" cluster keywords or frequent words > > Is there some good open source engine out there that would be suitable > to the task at hand? Anybody has experience with them? You can probably do most of this with Whoosh: http://whoosh.ca/ -- 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 From steve at holdenweb.com Wed Mar 10 14:06:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Mar 2010 14:06:05 -0500 Subject: Down casting Python objects In-Reply-To: <7659cab31003100531i51749f7er6f23ca0ef59cdddf@mail.gmail.com> References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> <7659cab31003100531i51749f7er6f23ca0ef59cdddf@mail.gmail.com> Message-ID: Andrey Fedorov wrote: > On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury > > wrote: > > Could you tell us *why* you need to down-cast x? Explicit > type-casting is usually unnecessary in Python... > > > Sure! It's related to the longer question I unwisely asked during PyCon > [1] (when no one had time to read it, I suppose). > > I have a couple of different flavors of request objects which I'd like > to make conform to a single interface. So Request `x' come in, I > determine which kind of request I'm dealing with, and would like to > "down-cast" it to ARequest or BRequest, classes which will provide > appropriate accessor properties for the rest of the code to use. > > An option clearly in line with Python's docs might be for `x' to be an > attribute of an ARequest instance, but that would complicate the code of > ARequest. What I'm looking for is a way of adding mix-in's at runtime, > if that makes sense. > The technique you need is not inheritance (which you are really trying to abuse here, IMHO) but delegation. Since all requests start out as of the same type, why not just give each request a handler attribute and set it to a BarHandler or FooHandler instance as appropriate. Then your generic code can call the handler's methods, obtaining Foo- or Bar-style behavior as appropriate. If the handler needs to manipulate the request object then the request object can pass itself in as a method argument. Technically your requests are delegating the handling to a subsidiary object which implements the correct behavior for the request type. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tack at urandom.ca Wed Mar 10 14:31:56 2010 From: tack at urandom.ca (Jason Tackaberry) Date: Wed, 10 Mar 2010 14:31:56 -0500 Subject: Text mining in Python In-Reply-To: References: Message-ID: <1268249516.5238.779.camel@arrakis> On Wed, 2010-03-10 at 19:58 +0100, mk wrote: > I need to do the following: [...] > Is there some good open source engine out there that would be suitable > to the task at hand? Anybody has experience with them? It sounds like a full text search engine might do a bit more than you need, but based on what you described, should also be sufficient. I highly recommend Xapian (xapian.org). It has feature-complete Python bindings, it's very well designed, and its performance is fantastic. Xapian supports stemmers for most major languages (except for Asian languages, unfortunately). Cheers, Jason. From ndbecker2 at gmail.com Wed Mar 10 14:42:39 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 14:42:39 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Duncan Booth wrote: > Neal Becker wrote: > >> Duncan Booth wrote: >> ... >>> >>> P.S. I don't know what you did in your post but your Followup-To >>> header is pointing to a group on gmane which makes extra work for me >>> replying. Please don't do that. >> >> I'm sorry about that, there is some bad interaction between gmane's >> nntp- smtp gateway and python's mail list. I don't know what to do >> about it. I think the problem only happens on python's mail list >> (I've never seen it reported on any of the MANY other lists I use via >> gmane). >> > Are the other mailing lists gatewayed from Usenet? It may not matter if > there's a followup-to header on a mailing list, it probably just gets > ignored, but it does matter on Usenet (which after all is what Gmane is > emulating). For the record, it isn't really gatewayed to usenet - it's just allowing you to read your favorite ML via nntp - which is MUCH more sensible than actually having all that mail delivered personally to you, if you read a lot of lists. From jcb at iteris.com Wed Mar 10 15:03:35 2010 From: jcb at iteris.com (Metalone) Date: Wed, 10 Mar 2010 12:03:35 -0800 (PST) Subject: file seek is slow References: Message-ID: f1_seek = f1.seek did not change the performance at all. As it turns out each call is only 646 nanoseconds slower than 'C'. However, that is still 80% of the time to perform a file seek, which I would think is a relatively slow operation compared to just making a system call. From jcb at iteris.com Wed Mar 10 15:04:28 2010 From: jcb at iteris.com (Metalone) Date: Wed, 10 Mar 2010 12:04:28 -0800 (PST) Subject: file seek is slow References: Message-ID: Thanks, Tim. Good to know. From robert.kern at gmail.com Wed Mar 10 15:06:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 14:06:34 -0600 Subject: Can't define __call__ within __init__? In-Reply-To: References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: On 2010-03-10 13:42 PM, Neal Becker wrote: > Duncan Booth wrote: > >> Neal Becker wrote: >> >>> Duncan Booth wrote: >>> ... >>>> >>>> P.S. I don't know what you did in your post but your Followup-To >>>> header is pointing to a group on gmane which makes extra work for me >>>> replying. Please don't do that. >>> >>> I'm sorry about that, there is some bad interaction between gmane's >>> nntp- smtp gateway and python's mail list. I don't know what to do >>> about it. I think the problem only happens on python's mail list >>> (I've never seen it reported on any of the MANY other lists I use via >>> gmane). >>> >> Are the other mailing lists gatewayed from Usenet? It may not matter if >> there's a followup-to header on a mailing list, it probably just gets >> ignored, but it does matter on Usenet (which after all is what Gmane is >> emulating). > > For the record, it isn't really gatewayed to usenet - it's just allowing you > to read your favorite ML via nntp - which is MUCH more sensible than > actually having all that mail delivered personally to you, if you read a lot > of lists. python-list is also gatewayed to the real USENET group comp.lang.python in addition to its GMane gateway. Duncan is reading comp.lang.python from a real USENET server, not via python-list through his email client. Most of the other lists you read via GMane aren't gatewayed to the real USENET, so your Followup-To header never caused a problem for anyone else. -- 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 From robert.kern at gmail.com Wed Mar 10 15:08:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 14:08:38 -0600 Subject: Can't define __call__ within __init__? In-Reply-To: References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: On 2010-03-10 12:23 PM, Neal Becker wrote: > Duncan Booth wrote: > ... >> >> P.S. I don't know what you did in your post but your Followup-To header is >> pointing to a group on gmane which makes extra work for me replying. >> Please don't do that. > > I'm sorry about that, there is some bad interaction between gmane's nntp- > smtp gateway and python's mail list. I don't know what to do about it. I > think the problem only happens on python's mail list (I've never seen it > reported on any of the MANY other lists I use via gmane). I think it may be your news reader adding the Original-Followup-To header. I use Thunderbird 3 to read this list via GMane, too, but my posts do not contain the header. What newsreader are you using? -- 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 From lacrima.maxim at gmail.com Wed Mar 10 15:16:25 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 10 Mar 2010 12:16:25 -0800 (PST) Subject: Can't install ssl for Python2.5 Message-ID: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> Hello! I use Ubuntu 9.10 Karmic Koala. It has Python 2.6 as default installation. And I installed Python 2.5 alongside (for the need of Google AppEngine). But it seems like my Python 2.5 installation lacks ssl support. I can't import ssl and starting appengine server fails with "'module' object has no attribute 'HTTPSHandler'". So I tried to install this: http://pypi.python.org/pypi/ssl/1.15 But it failed with a very strange error: sudo easy_install-2.5 ssl ------------- Searching for ssl Reading http://pypi.python.org/simple/ssl/ Reading http://docs.python.org/dev/library/ssl.html Best match: ssl 1.15 Downloading http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz#md5=81ea8a1175e437b4c769ae65b3290e0c Processing ssl-1.15.tar.gz Running ssl-1.15/setup.py -q bdist_egg --dist-dir /tmp/easy_install- Kd839q/ssl-1.15/egg-dist-tmp-QCIl6J looking for /usr/include/openssl/ssl.h looking for /usr/local/ssl/include/openssl/ssl.h looking for /usr/include/krb5.h looking for /usr/kerberos/include/krb5.h error: Setup script exited with error: SandboxViolation: open('/usr/ local/lib/python2.5/test/test_ssl.py', 'wb') {} The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted. This package cannot be safely installed by EasyInstall, and may not support alternate installation locations even if you run its setup script by hand. Please inform the package's author and the EasyInstall maintainers to find out if a fix or workaround is available. ------------- I don't know how to solve this problem and I am looking forward for help. Thanks in advance. with regards, Maxim. From mail at hellmutweber.de Wed Mar 10 16:23:18 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Wed, 10 Mar 2010 22:23:18 +0100 Subject: logging: local functions ==> loss of lineno Message-ID: <4B980DC6.4050807@hellmutweber.de> Hi Vinay Sajip, I'm very glad discoverd your logging module ;-) (That's what I would have liked 25 years ago when I was working as a technical software developper!) Now I'm writing just some personal tools, I like python and want to use logging on a regular basis. Logging works very well giving the filename and line number of the point where it is called. As long as I use the loggers directly. BUT when I have to wrap the logger call in some other function, I always get file name and line number of the call of the logger inside the wrapping function. Is there a possibility to get this information in this situation too? TIA Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From martin at v.loewis.de Wed Mar 10 16:23:38 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 10 Mar 2010 22:23:38 +0100 Subject: Can't install ssl for Python2.5 In-Reply-To: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> References: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> Message-ID: > I don't know how to solve this problem and I am looking forward for > help. Try running "python setup.py install" directly, after downloading and unpacking the package. Regards, Martin From ldo at geek-central.gen.new_zealand Wed Mar 10 16:49:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:49:51 +1300 Subject: Knight's tour Warndorff's algorithm problem References: Message-ID: In message , Gabriel Genellina wrote: > Warnsdorff's algorithm is heuristic ... Then it shouldn?t be called an ?algorithm?. From dreadpiratejeff at gmail.com Wed Mar 10 16:52:28 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 10 Mar 2010 16:52:28 -0500 Subject: Ideas for creating processes Message-ID: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> I'm working on a project and thought I'd ask for a suggestion on how to proceed (I've got my own ideas, but I wanted to see if I was on the right track) For now, I've got this: def main(): ## get our list of directories to refresh releases=sys.argv[1:] if len(releases) < 1: print "You need to provide at least one dir to update" sys.exit() ## Lets figure out what there is to update updateDirs = [] for rel in releases: currentDir = os.path.join(homedir, rel) for item in os.listdir(currentDir): updateDirs += [os.path.join(homedir, rel, item)] which returns a list of full pathnames to directories that need to be updated (updates will be carried out by calling rsync or zsync eventually) The directory hierarchy looks like this: /home/user/files /home/user/files/version1 /home/user/files/version1/type1 /home/user/files/version1/type2 /home/user/files/version2 /home/user/files/version2/type1 and the list ends up looking like this: ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] the next thing I need to do is figure out how to update those. the quick and dirty would be (as I'm imagining it at the moment): for path in pathlist: chdir into path execute rsync or zsync but that gets me moving into one dir, updating, then moving into another. What I was wondering about though, is spawning off separate rsync processes to run concurrently (each rsync will hit a different remote dir for each local dir) so I'm trying to figure out a good way to do this: for path in pathlist: kick off an individual rsync|zsync process to update path wait for all child processes to end exit program. I've been looking at subprocess because at the moment, that's all I really know... But is there a better way of kicking off multiple simultaneous processes so I can update all dirs at once instead of one at a time? No, this isn't homework, it's something I'm working on to sync a couple directories of ISO images to grab nightly builds Yes, there are plenty of pre-made scripts out there, but I don't want to even look at those because I figured this would be a good learning experience, and I want to try to solve this as much on my own as I can without just cut and pasting from someone elses program. So, with that said, any ideas on the best way to proceed? I'm going to start looking at ways to use subprocess to do this, or would there be a better way (multi-threading maybe?) Or am I even in the right ballpark? Cheers Jeff From james.harris.1 at googlemail.com Wed Mar 10 16:53:34 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Wed, 10 Mar 2010 13:53:34 -0800 (PST) Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: On 10 Mar, 06:29, "Gabriel Genellina" wrote: > En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein ? > escribi : > > > Basically I'm wondering if there are any plans to implemented named > > loops in Python, so I can tell a break command to break out of a > > specific loop in the case of nested loops. > > See PEP3136 [1] and its rejection note [2] > I think you may find some more discussion in the python-ideas list. > > > Currently I'm using boolean > > flag variables, but I find that very clumsy. I know this idea of > > breaking out of specific loops from javascript; I guess java does it > > too. It just seems a very Pythonian idea to me: clear, promotes code > > legibility, seems obvious. > > Although I've occasionally missed the feature myself, I agree with Guido's ? > arguments against it. I don't agree with Guido's second reason in particular. He writes in the link Gabriel provided > [2]http://mail.python.org/pipermail/python-3000/2007-July/ 008663.html G> However, I'm rejecting it on the basis that code so complicated to G> require this feature is very rare. In most cases there are existing G> work-arounds that produce clean code, for example using 'return'. G> While I'm sure there are some (rare) real cases where clarity of the G> code would suffer from a refactoring that makes it possible to use G> return, this is offset by two issues: G> 1. The complexity added to the language, permanently. This affects not G> only all Python implementations, but also every source analysis tool, G> plus of course all documentation for the language. Guido may have a point here about source tools but I don't think the language becomes more complex. If anything it would become more orthogonal - i.e. fewer arbitrary restrictions. And documentation is needed for any change so saying that documentation would need to be updated is an odd reason to reject a change. G> 2. My expectation that the feature will be abused more than it will be G> used right, leading to a net decrease in code clarity (measured across G> all Python code written henceforth). Lazy programmers are everywhere, G> and before you know it you have an incredible mess on your hands of G> unintelligible code. Breaking out of an inner loop is just as natural as breaking out of the immediately enclosing loop. ISTM that if one is allowed the other should be also. > You have several alternatives: refactor the loop ? > into an auxiliary function, use a specific exception, add boolean flags, ? > or repeat the test at the outer levels. (I usually choose the first). The auxiliary function idea (Guido's preference as well as Gabriel's) works but it may require accessing of variables which don't appear in the function interface, and the "return" in that function is no different from the break dropping through multiple levels. Return does exactly that (as well as setting a result value). There are often times when it *is* better to factor out the code to a different function but adding a function just to enable a break from an inner loop doesn't seem to me a good reason. James From ldo at geek-central.gen.new_zealand Wed Mar 10 16:56:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:56:19 +1300 Subject: Draft PEP on RSON configuration file format References: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Message-ID: In message <4b8b5cef$0$1625$742ec2ed at news.sonic.net>, John Nagle wrote: > Patrick Maupin wrote: >> >> Finding .ini configuration files too limiting, JSON and XML to hard to >> manually edit, and YAML too complex to parse quickly, I have started >> work on a new configuration file parser. > > You're not supposed to edit those formats manually. Strange. A previous client of mine was a totally non-IT-technical guy, yet I was able to set him up with editing XML files (needed to drive some software I wrote for him) just fine. Of course he was using a purpose-built editor, namely KXMLEditor. From ldo at geek-central.gen.new_zealand Wed Mar 10 16:57:15 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:57:15 +1300 Subject: Passing FILE * types using ctypes References: <7vbrveFegeU1@mid.individual.net> Message-ID: In message <7vbrveFegeU1 at mid.individual.net>, Gregory Ewing wrote: > If you need the same FILE * that Python is using, you > may need to use ctypes to extract it out of the file > object. Why would Python be using a FILE *? From ldo at geek-central.gen.new_zealand Wed Mar 10 16:58:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:58:30 +1300 Subject: Passing FILE * types using ctypes References: Message-ID: In message , Zeeshan Quireshi wrote: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer ... Another option is to fix your library not to use stdio directly. From isso.moh at gmail.com Wed Mar 10 17:03:50 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Wed, 10 Mar 2010 23:03:50 +0100 Subject: show image in python Message-ID: Hey, This is my program 1 #!/usr/bin/python 2 import PIL 3 import numpy 4 import Image 5 import ImageOps 6 import sys 7 8 def Matimg(path): 9 """transforme image en matrice""" 10 Img = Image.open(str(path)) 11 Img1 = ImageOps.grayscale(Img) 12 largeur,hauteur = Img1.size 13 imdata = Img1.getdata() 14 tab = numpy.array(imdata) 15 matrix = numpy.reshape(tab,(hauteur,largeur)) 16 return matrix 17 18 def Creeimg(): 19 """transforme matrice en image""" 20 img = Image.new ("L",(8,8)) 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 22 img.putdata(matrix) 23 img.show() 24 img.save(fp="./ana.bmp") 25 26 if __name__== '__main__': 27 if len(sys.argv) < 2 : 28 print "Usage: img.py " 29 sys.exit(0) 30 path = sys.argv[1] 31 matrix = Matimg(path) 32 print matrix 33 Creeimg() My probeleme : In line 23 "img.show()" Don't work, normally I show the image but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" it's work WHERE IS THE PROBLEME. I have this error in shell : "(eog:3176): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory. This indicates a bug in someone's code. You must ensure an error is NULL before it's set. The overwriting error message was: Error in getting image file info " os: ubuntu 9.10 sorry for my english. ;-) -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Wed Mar 10 17:04:47 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 10 Mar 2010 17:04:47 -0500 Subject: Ideas for creating processes In-Reply-To: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> Message-ID: <36dec4ff1003101404v402f0b59lf0ac67e4a9c8cc3c@mail.gmail.com> On Wed, Mar 10, 2010 at 16:52, J wrote: > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > ? ?chdir into path > ? ?execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > ? ?kick off an individual rsync|zsync process to update path And now I'm looking at subprocess and I can set shell=True and it will intrepret special characters like & So could I do something like this: for item in pathlist: subprocess.Popen('rsync command &', shell=True) and simply wait unti they are all done? From robert.kern at gmail.com Wed Mar 10 17:05:45 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 16:05:45 -0600 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: On 2010-03-10 15:49 PM, Lawrence D'Oliveiro wrote: > In message, Gabriel > Genellina wrote: > >> Warnsdorff's algorithm is heuristic ... > > Then it shouldn?t be called an ?algorithm?. There are lots of algorithms that use heuristics or are heuristics. The two are orthogonal concepts. -- 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 From robert.kern at gmail.com Wed Mar 10 17:09:26 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 16:09:26 -0600 Subject: Passing FILE * types using ctypes In-Reply-To: References: <7vbrveFegeU1@mid.individual.net> Message-ID: On 2010-03-10 15:57 PM, Lawrence D'Oliveiro wrote: > In message<7vbrveFegeU1 at mid.individual.net>, Gregory Ewing wrote: > >> If you need the same FILE * that Python is using, you >> may need to use ctypes to extract it out of the file >> object. > > Why would Python be using a FILE *? In Python 2.x, Python's file objects use a stdio FILE* pointer underneath. The I/O subsystem was rewritten in Python 3.x to use only file descriptors. -- 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 From invalid at invalid.invalid Wed Mar 10 17:09:58 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Mar 2010 22:09:58 +0000 (UTC) Subject: Knight's tour Warndorff's algorithm problem References: Message-ID: On 2010-03-10, Lawrence D'Oliveiro wrote: > In message , Gabriel > Genellina wrote: > >> Warnsdorff's algorithm is heuristic ... > > Then it shouldn???t be called an ???algorithm???. Why? An algorithm is just a well-defined series of steps. Just because it uses heuristics doesn't mean it's not an algorithm. In my book it's still an algorithm even if it never produces a correct result. It's just not a very _good_ algorithm. :) -- Grant Edwards grant.b.edwards Yow! YOU PICKED KARL at MALDEN'S NOSE!! gmail.com From xahlee at gmail.com Wed Mar 10 17:36:58 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 10 Mar 2010 14:36:58 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> <13c167f4-5e37-48a0-a480-3494c212035c@k5g2000pra.googlegroups.com> Message-ID: <06323935-e1a0-4447-b4d8-f62bf94dfb40@e19g2000prn.googlegroups.com> On Mar 10, 9:26?am, Duncan Booth wrote: > No, I'm saying that if you plan to build a business that could grow you > should be clear up front how you plan to handle the growth. It's too late > if you suddenly discover your platform isn't scalable just when you need to > scale it. Right, but that doesn't seems to have any relevance about my point. Many says that scalability is key to NoSQL, i pointed out that unless you are like google, or ranked top 1000 in the world in terms data size, the scalability reason isn't that strong. Xah Lee wrote: > many people mentioned scalibility... though i think it is fruitful to > talk about at what size is the NoSQL databases offer better > scalability than SQL databases. > > For example, consider, if you are within world's top 100th user of > database in terms of database size, such as Google, then it may be > that the off-the-shelf tools may be limiting. But how many users > really have such massive size of data? note that google's need for > database today isn't just a seach engine. > > It's db size for google search is probably larger than all the rest of > search engine company's sizes combined. Plus, there's youtube (vid > hosting), gmail, google code (source code hosting), google blog, orkut > (social networking), picasa (photo hosting), etc, each are all ranked > within top 5 or so with respective competitors in terms of number of > accounts... so, google's datasize is probably number one among the > world's user of databases, probably double or triple than the second > user with the most large datasize. At that point, it seems logical > that they need their own db, relational or not. Xah ? http://xahlee.org/ ? From alfps at start.no Wed Mar 10 17:53:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Mar 2010 23:53:09 +0100 Subject: Named loops for breaking In-Reply-To: References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: * James Harris: > On 10 Mar, 06:29, "Gabriel Genellina" wrote: >> En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein >> escribi : >> >>> Basically I'm wondering if there are any plans to implemented named >>> loops in Python, so I can tell a break command to break out of a >>> specific loop in the case of nested loops. >> See PEP3136 [1] and its rejection note [2] >> I think you may find some more discussion in the python-ideas list. >> >>> Currently I'm using boolean >>> flag variables, but I find that very clumsy. I know this idea of >>> breaking out of specific loops from javascript; I guess java does it >>> too. It just seems a very Pythonian idea to me: clear, promotes code >>> legibility, seems obvious. >> Although I've occasionally missed the feature myself, I agree with Guido's >> arguments against it. > > I don't agree with Guido's second reason in particular. He writes in > the link Gabriel provided > > > [2]http://mail.python.org/pipermail/python-3000/2007-July/ > 008663.html > > G> However, I'm rejecting it on the basis that code so complicated to > G> require this feature is very rare. In most cases there are existing > G> work-arounds that produce clean code, for example using 'return'. > G> While I'm sure there are some (rare) real cases where clarity of > the > G> code would suffer from a refactoring that makes it possible to use > G> return, this is offset by two issues: > > G> 1. The complexity added to the language, permanently. This affects > not > G> only all Python implementations, but also every source analysis > tool, > G> plus of course all documentation for the language. > > Guido may have a point here about source tools but I don't think the > language becomes more complex. If anything it would become more > orthogonal - i.e. fewer arbitrary restrictions. And documentation is > needed for any change so saying that documentation would need to be > updated is an odd reason to reject a change. > > G> 2. My expectation that the feature will be abused more than it will > be > G> used right, leading to a net decrease in code clarity (measured > across > G> all Python code written henceforth). Lazy programmers are > everywhere, > G> and before you know it you have an incredible mess on your hands of > G> unintelligible code. > > Breaking out of an inner loop is just as natural as breaking out of > the immediately enclosing loop. ISTM that if one is allowed the other > should be also. > >> You have several alternatives: refactor the loop >> into an auxiliary function, use a specific exception, add boolean flags, >> or repeat the test at the outer levels. (I usually choose the first). > > The auxiliary function idea (Guido's preference as well as Gabriel's) > works but it may require accessing of variables which don't appear in > the function interface, and the "return" in that function is no > different from the break dropping through multiple levels. Return does > exactly that (as well as setting a result value). > > There are often times when it *is* better to factor out the code to a > different function but adding a function just to enable a break from > an inner loop doesn't seem to me a good reason. Gabriel Genellina mentioned these alternatives: "refactor the loop into an auxiliary function, use a specific exception, add boolean flags, or repeat the test at the outer levels. (I usually choose the first)" And I agree, but in Python there is at least one more very practical alternative, namely /flatting/ the nested loops, representing them as a single loop. It can go like this -- very artifical construed example: from __future__ import print_function try: range = xrange except: pass def inclusive_range( first, last ): return range( first, last + 1 ) def xy_range( x_range, y_range ): for x in x_range: for y in y_range: yield (x, y) def main(): needle = 42 x_range = inclusive_range( 1, 10 ) y_range = inclusive_range( 1, 10 ) pos = None for (x, y) in xy_range( x_range, y_range ): if x*y == needle: pos = (x, y) break if pos is None: print( "Sorry, {0} not found.".format( needle ) ) else: print( "{0} found at {1}.".format( needle, pos ) ) main() Cheers & hth., - Alf PS: Gabriel, if you read this and don't understand it (as you mentioned in another thread that you never understand my postings), please just ask! From martin.hellwig at dcuktec.org Wed Mar 10 17:55:25 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Mar 2010 22:55:25 +0000 Subject: Ideas for creating processes In-Reply-To: References: Message-ID: On 03/10/10 21:52, J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) Well I can't speak with authority but I would go into similar lines, especially since you want to call an external program in the end anyway. Otherwise threading might have been an option. Just make sure that all subprocesses are exited nicely before you are on the end of your script ;-) -- mph From nyamatongwe+thunder at gmail.com Wed Mar 10 18:01:05 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 10 Mar 2010 23:01:05 GMT Subject: file seek is slow In-Reply-To: References: Message-ID: Metalone: > As it turns out each call is only > 646 nanoseconds slower than 'C'. > However, that is still 80% of the time to perform a file seek, > which I would think is a relatively slow operation compared to just > making a system call. A seek may not be doing much beyond setting a current offset value. It is likely that fseek(f1, 0, SEEK_SET) isn't even doing a system call. An implementation of fseek will often return relatively quickly when the position is within the current buffer -- from line 192 in http://www.google.com/codesearch/p?hl=en#XAzRy8oK4zA/libc/stdio/fseek.c&q=fseek&sa=N&cd=1&ct=rc Neil From python at mrabarnett.plus.com Wed Mar 10 18:03:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Mar 2010 23:03:17 +0000 Subject: Ideas for creating processes In-Reply-To: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> Message-ID: <4B982535.4080000@mrabarnett.plus.com> J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) > > For now, I've got this: > > def main(): > ## get our list of directories to refresh > releases=sys.argv[1:] > if len(releases) < 1: > print "You need to provide at least one dir to update" > sys.exit() > > ## Lets figure out what there is to update > updateDirs = [] > for rel in releases: > currentDir = os.path.join(homedir, rel) > for item in os.listdir(currentDir): > updateDirs += [os.path.join(homedir, rel, item)] > > which returns a list of full pathnames to directories that need to be > updated (updates will be carried out by calling rsync or zsync > eventually) > > The directory hierarchy looks like this: > > /home/user/files > /home/user/files/version1 > /home/user/files/version1/type1 > /home/user/files/version1/type2 > /home/user/files/version2 > /home/user/files/version2/type1 > > and the list ends up looking like this: > > ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] > > the next thing I need to do is figure out how to update those. > > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > chdir into path > execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > kick off an individual rsync|zsync process to update path > > wait for all child processes to end > exit program. > > I've been looking at subprocess because at the moment, that's all I > really know... > But is there a better way of kicking off multiple simultaneous > processes so I can update all dirs at once instead of one at a time? > > No, this isn't homework, it's something I'm working on to sync a > couple directories of ISO images to grab nightly builds > Yes, there are plenty of pre-made scripts out there, but I don't want > to even look at those because I figured this would be a good learning > experience, and I want to try to solve this as much on my own as I can > without just cut and pasting from someone elses program. > > So, with that said, any ideas on the best way to proceed? I'm going > to start looking at ways to use subprocess to do this, or would there > be a better way (multi-threading maybe?) > > Or am I even in the right ballpark? > Are you sure that you would gain from doing more than one at a time? The bottleneck will probably be the speed of your network connection, and if that's working at its maximum speed with one sync then doing several concurrently won't save any time. (The syncs will also be completing for disk I/O.) It might, however, save time if the remote server takes time to respond to a sync and/or doesn't use your network connection at its maximum speed (the server's connection will have its own limits, of course, and might be talking to other computers at the same time). You could increase the number of concurrent syncs until you find the number that gives the best results. From nilly16 at yahoo.com Wed Mar 10 18:06:41 2010 From: nilly16 at yahoo.com (Jimbo) Date: Wed, 10 Mar 2010 15:06:41 -0800 (PST) Subject: Python Script to get Info from Site not working Message-ID: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> Hello I am asking what is probably a very easy thing to do but I cannot find a tutorial on how to do it anywhere. [b]I want to use a Python script to get information from a webpage. [/b] I found a semi Python & internet tutorial here if anyone else would like it http://www.upriss.org.uk/python/session6.html I would like to create a python script that gets a value from a set of radio buttons on a HTML page & tell me which one is selected. I have 3 radio buttons: Tea, Coffee, Hot Chocolate & a Submit button My script is meant to find which radio button is selected & tell me that. But it just keeps saying "No Drink Selected!" Can you help me figure out how to fix this. FYI: My Python script & my HTML page are both saved in the same directory. And I made the webpage using Notepad++, I open the webpage in Interent Explorer & I made the Python Script in Idle. Python Script: [code]# Practice 9 CGI ######### don't change the following three lines: ########### import cgi print("Content-Type: text/html\n") form = cgi.FieldStorage() ## add a form.getvalue for each of the names in your form: ## drink = form.getvalue("drink") ########## start of HTML code ########### print(""" What would you like to drink

Your drink:

""") ############ end of HTML code ############# if drink == "tea": print("You requested tea.") elif drink == "coffee": print("You requested coffee.") elif drink == "hot chocolate": print ("You requested hot chocolate.") else: print ("You need to select a drink!") ########### start of HTML code ########### print ("""

Thank you for your visit. Please come again.

""") ############# end of HTML code ############## [/code] HTML Code: [code] Tea
Coffee
Hot Chocolate

[/code] From news1234 at free.fr Wed Mar 10 18:17:19 2010 From: news1234 at free.fr (News123) Date: Thu, 11 Mar 2010 00:17:19 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b957866$0$17135$426a34cc@news.free.fr> Message-ID: <4B98287F.2010101@free.fr> Hi JM, Jean-Michel Pichavant wrote: > News123 wrote: >> Jean-Michel Pichavant wrote: >> >>> Johny wrote: >>> >>>> I have this directory structure >>>> >>>> C: >>>> \A >>>> __init__.py >>>> amodule.py >>>> >>>> \B >>>> __init__.py >>>> bmodule.py >>>> >>>> \D >>>> __init__.py >>>> dmodule.py >>>> >>>> and I want to import bmodule.py >>>> C:\>cd \ >>>> >>>> C:\>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> from A.B import bmodule >>>>>>> >>>> I am bmodule >>>> C:\> >>>> >>>> so far so good. Now I would like to import bmodule but if the current >>>> directory is \D subdirectory. >>>> >>>> C:> cd \A\B\D >>>> C:\A\B\D> >>>> C:\A\B\D>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> import sys >>>>>>> sys.path.append('C:\\A') >>>>>>> from A.B import bmodule >>>>>>> >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> ImportError: No module named A.B >>>> >>>> C:\> >>>> >>>> so I can not import a module from the parent directory? Or where did I >>>> make an error? >>>> Thanks for help >>>> >>>> L. >>>> >>> try >>> >>> import sys >>> sys.path.append('C:\\') >>> from A.B import bmodule >>> >>> >> is there any 'automatic' way of finding the top level >> directory?basically the 'top level directory is the first directory >> going upwards, that doesn't contain a __init__.py file. >> > what if some user has an __init__.py file the top level directory of > your package ? Is there any other usage of __init.py__ than indicating a module directory? I wasn't aware of it, but you're right I did not investigte in depth and users can of course do whatever they like. >> of course you could do this 'manually' by >> doing: >> >> # assume, that this module is A.amodule >> import sys >> import os >> >> # I'd love to have a similiar automatic construct >> if __name__ == "__main__": >> level = 1 # or function locating how far to go up before >> # finding a dir, whcih does not contain a __init__.py >> mydir = os.path.split(__file__)[0] >> topdir = os.path.join( mydir,*(("..",)*level)) >> abstop = os.path.abspath(topdir) >> sys.path.append(abstop) >> >> ## now you can import with the normal module paths >> >> import A.blo >> print "and I found blo",dir(A.blo) >> >> > You don't want to do that and you don't need it neither. That's what the > env variable PYTHONPATH is for. set it correctly, install your package > inside and everything works just fine (+standard). With a linux OS it > easy to create smb links to point to any working directory. It should be > possible on windows as well. I like your idea with the symlinks. However not sure how to do it with windows. I assume default shortcuts won't do. > > If your package is meant to be destributed, you may use setup.py > > Well, It's nice if a user just unpacks a zip file and can click on any script with the .py suffix in the tree. (Its nice for example for tutorials / demos ) It's also nice if he can later on just delete the unpacked directory and there will be no trace left in the registry or in the python base dir. This is why I'm interested in solutions without setup.py or changing environment variables. bye N From news1234 at free.fr Wed Mar 10 18:18:05 2010 From: news1234 at free.fr (News123) Date: Thu, 11 Mar 2010 00:18:05 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b957866$0$17135$426a34cc@news.free.fr> Message-ID: <4b9828ad$0$698$426a74cc@news.free.fr> Hi JM, Jean-Michel Pichavant wrote: > News123 wrote: >> Jean-Michel Pichavant wrote: >> >>> Johny wrote: >>> >>>> I have this directory structure >>>> >>>> C: >>>> \A >>>> __init__.py >>>> amodule.py >>>> >>>> \B >>>> __init__.py >>>> bmodule.py >>>> >>>> \D >>>> __init__.py >>>> dmodule.py >>>> >>>> and I want to import bmodule.py >>>> C:\>cd \ >>>> >>>> C:\>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> from A.B import bmodule >>>>>>> >>>> I am bmodule >>>> C:\> >>>> >>>> so far so good. Now I would like to import bmodule but if the current >>>> directory is \D subdirectory. >>>> >>>> C:> cd \A\B\D >>>> C:\A\B\D> >>>> C:\A\B\D>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> import sys >>>>>>> sys.path.append('C:\\A') >>>>>>> from A.B import bmodule >>>>>>> >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> ImportError: No module named A.B >>>> >>>> C:\> >>>> >>>> so I can not import a module from the parent directory? Or where did I >>>> make an error? >>>> Thanks for help >>>> >>>> L. >>>> >>> try >>> >>> import sys >>> sys.path.append('C:\\') >>> from A.B import bmodule >>> >>> >> is there any 'automatic' way of finding the top level >> directory?basically the 'top level directory is the first directory >> going upwards, that doesn't contain a __init__.py file. >> > what if some user has an __init__.py file the top level directory of > your package ? Is there any other usage of __init.py__ than indicating a module directory? I wasn't aware of it, but you're right I did not investigte in depth and users can of course do whatever they like. >> of course you could do this 'manually' by >> doing: >> >> # assume, that this module is A.amodule >> import sys >> import os >> >> # I'd love to have a similiar automatic construct >> if __name__ == "__main__": >> level = 1 # or function locating how far to go up before >> # finding a dir, whcih does not contain a __init__.py >> mydir = os.path.split(__file__)[0] >> topdir = os.path.join( mydir,*(("..",)*level)) >> abstop = os.path.abspath(topdir) >> sys.path.append(abstop) >> >> ## now you can import with the normal module paths >> >> import A.blo >> print "and I found blo",dir(A.blo) >> >> > You don't want to do that and you don't need it neither. That's what the > env variable PYTHONPATH is for. set it correctly, install your package > inside and everything works just fine (+standard). With a linux OS it > easy to create smb links to point to any working directory. It should be > possible on windows as well. I like your idea with the symlinks. However not sure how to do it with windows. I assume default shortcuts won't do. > > If your package is meant to be destributed, you may use setup.py > > Well, It's nice if a user just unpacks a zip file and can click on any script with the .py suffix in the tree. (Its nice for example for tutorials / demos ) It's also nice if he can later on just delete the unpacked directory and there will be no trace left in the registry or in the python base dir. This is why I'm interested in solutions without setup.py or changing environment variables. bye N From ndbecker2 at gmail.com Wed Mar 10 18:38:10 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 18:38:10 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Robert Kern wrote: > On 2010-03-10 12:23 PM, Neal Becker wrote: >> Duncan Booth wrote: >> ... >>> >>> P.S. I don't know what you did in your post but your Followup-To header >>> is pointing to a group on gmane which makes extra work for me replying. >>> Please don't do that. >> >> I'm sorry about that, there is some bad interaction between gmane's nntp- >> smtp gateway and python's mail list. I don't know what to do about it. >> I think the problem only happens on python's mail list (I've never seen >> it reported on any of the MANY other lists I use via gmane). > > I think it may be your news reader adding the Original-Followup-To header. > I use Thunderbird 3 to read this list via GMane, too, but my posts do not > contain the header. What newsreader are you using? > knode. From sjdevnull at yahoo.com Wed Mar 10 18:38:28 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Wed, 10 Mar 2010 15:38:28 -0800 (PST) Subject: file seek is slow References: Message-ID: On Mar 10, 6:01?pm, Neil Hodgson wrote: > Metalone: > > > As it turns out each call is only > > 646 nanoseconds slower than 'C'. > > However, that is still 80% of the time to perform a file seek, > > which I would think is a relatively slow operation compared to just > > making a system call. > > ? ?A seek may not be doing much beyond setting a current offset value. > It is likely that fseek(f1, 0, SEEK_SET) isn't even doing a system call. Exactly. If I replace both calls to fseek with gettimeofday (aka time.time() on my platform in python) I get fairly close results: $ ./testseek 4.120 $ python2.5 testseek.py 4.170 $ ./testseek 4.080 $ python2.5 testseek.py 4.130 FWIW, my results with fseek aren't as bad as those of the OP. This is python2.5 on a 2.6.9 Linux OS, with psyco: $ ./testseek 0.560 $ python2.5 testseek.py 0.750 $ ./testseek 0.570 $ python2.5 testseek.py 0.760 From rbrt.somerville at gmail.com Wed Mar 10 18:48:14 2010 From: rbrt.somerville at gmail.com (robert somerville) Date: Wed, 10 Mar 2010 15:48:14 -0800 Subject: Elementtree install problem in Ubuntu (a newbie ..) Message-ID: <2fb4a5011003101548x862eef2w4f46473bae4bf9f4@mail.gmail.com> Hi ; I installed the elementtree and celementree packages throught the synaptic package manager, all seems to go fine through the install ... when i startup python and try to import them (as per the EFFBOTT.org suggestions) .. PROBLEMS ... (see below ..) What am i doing wrong ??? this is a new window after installation of packages ... Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import elementtree.ElementTree as ET Traceback (most recent call last): File "", line 1, in ImportError: No module named elementtree.ElementTree >>> import elementtree Traceback (most recent call last): File "", line 1, in ImportError: No module named elementtree thanks; Robert somerville -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Wed Mar 10 18:56:08 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 10 Mar 2010 18:56:08 -0500 Subject: Elementtree install problem in Ubuntu (a newbie ..) In-Reply-To: <2fb4a5011003101548x862eef2w4f46473bae4bf9f4@mail.gmail.com> References: <2fb4a5011003101548x862eef2w4f46473bae4bf9f4@mail.gmail.com> Message-ID: On Mar 10, 2010, at 6:48 PM, robert somerville wrote: > Hi ; > I installed the elementtree and celementree packages throught the > synaptic > package manager, all seems to go fine through the install ... > > when i startup python and try to import them (as per the EFFBOTT.org > suggestions) .. PROBLEMS ... (see below ..) What am i doing > wrong ??? this > is a new window after installation of packages ... > > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import elementtree.ElementTree as ET > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named elementtree.ElementTree >>>> import elementtree > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named elementtree Hi Robert, In Python >= 2.5, ElementTree is part the standard library so it doesn't need to be installed separately. Here's the documentation for it: http://www.python.org/doc/2.6.4/library/xml.etree.elementtree.html HTH Philip From genetiq at gmail.com Wed Mar 10 19:05:13 2010 From: genetiq at gmail.com (phantasm) Date: Wed, 10 Mar 2010 16:05:13 -0800 (PST) Subject: Can't install PIL on MacOS X Leopard Message-ID: <94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com> Hello! I'm trying to install PIL module on MacOS X Leopard with python 2.6. Everything seemed to be fine - now I have PIL egg package in "site- packages" directory, but when I'm trying "import PIL", I get an error "ImportError: No module named PIL". All other modules such as SQL Alchemy work fine. Their EGGs reside in a same directory as a resulting PIL package. I've tried to install either via easy_install and manually, results are the same. PYTHONPATH environment variable is set to a correct directory. python command "import _imaging" returns no error. What I'm doing wrong? From rbrt.somerville at gmail.com Wed Mar 10 19:17:29 2010 From: rbrt.somerville at gmail.com (robert somerville) Date: Wed, 10 Mar 2010 16:17:29 -0800 Subject: Python 2.6 and modules dbi AND odbc Message-ID: <2fb4a5011003101617r5518b322y6ccc091046b0ccc4@mail.gmail.com> hi; i am trying to get some legacy python code (which i no nothing about) working with tries to import dbi and odbc (the import fails ...) it looks like these modules are deprecated ?? if so is there a work around , if not deprecated, what am i doing wrong ?? i see no Ubuntu packages that look promising .. Robert Somerville -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Wed Mar 10 19:34:51 2010 From: nad at acm.org (Ned Deily) Date: Wed, 10 Mar 2010 16:34:51 -0800 Subject: Can't install PIL on MacOS X Leopard References: <94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com> Message-ID: In article <94070db2-91f0-47a8-a259-36378aab95ea at o3g2000yqb.googlegroups.com>, phantasm wrote: > I'm trying to install PIL module on MacOS X Leopard with python 2.6. > Everything seemed to be fine - now I have PIL egg package in "site- > packages" directory, but when I'm trying "import PIL", I get an error > "ImportError: No module named PIL". > > All other modules such as SQL Alchemy work fine. Their EGGs reside in > a same directory as a resulting PIL package. > > I've tried to install either via easy_install and manually, results > are the same. PYTHONPATH environment variable is set to a correct > directory. python command "import _imaging" returns no error. > > What I'm doing wrong? Hard to say without more information but it does seem odd that _imaging can be imported. One thing to try: $ python2.6 Python 2.6.4 (r264:75706, Oct 28 2009, 20:34:51) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import _imaging >>> _imaging.__file__ '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-pac kages/PIL/_imaging.so' # or something like that Make sure the file is located within the expected PIL directory. Also make sure there aren't any file permission problems on any of the PIL directories and files. I'm assuming PIL was installed as an unzipped egg. And double-check the contents of any .pth files. -- Ned Deily, nad at acm.org From genetiq at gmail.com Wed Mar 10 19:43:26 2010 From: genetiq at gmail.com (phantasm) Date: Wed, 10 Mar 2010 16:43:26 -0800 (PST) Subject: Can't install PIL on MacOS X Leopard References: <94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com> Message-ID: Thank you for your reply, Ned, but I just tried to install it again and found out that I didn't finally run "python setup.py install" after building PIL manually. It solved the problem. From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:01 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:01 -0300 Subject: Does this already exists?: A module that checks if the used platform is supported References: Message-ID: En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig escribi?: > Before I start reinventing a squared wheel, I have the following > question: > Is there already a (standard) module that wraps around the various > os/sys information which checks if the platform + version is supported > for what I want to do with it. In case you were not aware of it: see the platform module. But you'll have to do the checks yourself (based on the info it returns). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:08 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:08 -0300 Subject: Importing Modules References: <676034.43316.qm@web30001.mail.mud.yahoo.com> Message-ID: En Wed, 10 Mar 2010 09:19:29 -0300, PEYMAN ASKARI escribi?: > I wanted to know if imported classes are treated differently than > internal classes. If by 'internal classes' you mean 'classes defined in the main module', no, they're absolutely the same. > class A(): > __init__(self): > pass > > and call A, or A() I get something to the effect of <__main__.A > instance at 0xb7f088ac> > > but if I call from module_name import A and then call A or A() I get > something to the effect of Note that both reprs have the same structure. Both say When you execute `python test_import.py`, the code is executed into a newly created module called __main__ (not test_import). So __main__ is the name of the main module, and __main__.A is the full name of the A class defined in the __main__ module. In the other case, module_4.module_4 is the full name of the module_4 class defined in the module_4 module. > I was wondering if this would be a problem. In general, no, you shouldn't care. There is a problem, though, if some other module imports the main one (using `import test_import`). Python knows the main one as "__main__", not as "test_import", so it will load it *again*, and you'll end with two separate copies of the same module. Solution: don't do that :) -- redesign your application so subordinate modules don't have to import the main one (move the required parts into a third module). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:14 -0300 Subject: Interacting With Another Script References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Message-ID: En Wed, 10 Mar 2010 09:32:15 -0300, Victor Subervi escribi?: > There's a program (vpopmail) that has commands which, when called, > request > input ("email address", "password", etc.) from the command line. I would > like to build a TTW interface for my clients to use that interacts with > these commands. I know nothing about vpopmail, but can't you provide all the required information by some other means? Command line arguments, a configuration file, perhaps there is an API to call some internal functions? Faking an interactive session would be my last option. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:18 -0300 Subject: Method / Functions - What are the differences? References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> <4B97B092.4060901@optimum.net> Message-ID: En Wed, 10 Mar 2010 11:45:38 -0300, John Posner escribi?: > As I promised/threatened, here's the *start* of a write-up on > properties, aimed at non-advanced Python programmers: > > http://www.jjposner.net/media/python-properties-0310.pdf I'd use 'function' instead of 'procedure', as this last word is very uncommon in Python literature (also, "the procedure's return value..." may look very strange to some people). I'm unsure if one should make a distinction 'storage attribute' vs. 'method attribute', or even if it makes things actually more clear. I think you could present the motivating idea first ("I want to execute some code when accessing an attribute") and only later talk about properties and descriptors (as written, the reader still doesn't know how to define a simple property and you've already talked about deleting attributes...) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:38:09 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:38:09 -0300 Subject: Python Script to get Info from Site not working References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> Message-ID: En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: > I found a semi Python & internet tutorial here if anyone else would > like it http://www.upriss.org.uk/python/session6.html > > My script is meant to find which radio button is selected & tell me > that. But it just keeps saying "No Drink Selected!" Are you sure? From the code you posted, the message should read "You need to select a drink!", not that one. > if drink == "tea": > print("You requested tea.") > elif drink == "coffee": > print("You requested coffee.") > elif drink == "hot chocolate": > print ("You requested hot chocolate.") > else: > print ("You need to select a drink!") Replace the last line with something like this, to see what you are getting exactly: print("Sorry, no %r (%r) available." % ( drink, cgi.escape(repr(type(drink))))) BTW, which Python version are you using? The tutorial you linked to is aimed at Python 2.x, but your print syntax suggests you're using Python 3.x -- Gabriel Genellina From wuwei23 at gmail.com Wed Mar 10 21:16:04 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Mar 2010 18:16:04 -0800 (PST) Subject: Interacting With Another Script References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Message-ID: <2db4409d-d8d7-4af9-a9a7-e8071bc30b0f@o16g2000prh.googlegroups.com> Victor Subervi wrote: > > There's a program (vpopmail) that has commands which, when called, request > > input ("email address", "password", etc.) from the command line. I would > > like to build a TTW interface for my clients to use that interacts with > > these commands. The Pexpect[1] module is pretty much aimed at doing exactly this. 1: http://www.noah.org/wiki/Pexpect From nilly16 at yahoo.com Wed Mar 10 21:26:05 2010 From: nilly16 at yahoo.com (Jimbo) Date: Wed, 10 Mar 2010 18:26:05 -0800 (PST) Subject: Python Script to get Info from Site not working References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> Message-ID: <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> On Mar 11, 12:38?pm, "Gabriel Genellina" wrote: > En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: > > > I found a semi Python & internet tutorial here if anyone else would > > like ithttp://www.upriss.org.uk/python/session6.html > > > My script is meant to find which radio button is selected & tell me > > that. But it just keeps saying "No Drink Selected!" > > Are you sure? From the code you posted, the message should read "You need ? > to select a drink!", not that one. > Replace the last line with something like this, to see what you are ? > getting exactly: > > ? ? ? ? print("Sorry, no %r (%r) available." % ( > ? ? ? ? ? ?drink, > ? ? ? ? ? ?cgi.escape(repr(type(drink))))) > > BTW, which Python version are you using? The tutorial you linked to is ? > aimed at Python 2.x, but your print syntax suggests you're using Python 3.x > > -- > Gabriel Genellina Yeah that("You need to select a drink!") was the string I was getting but I should be getting hot chocolate or something else(which ever one I have selected) I am using 3.x, do you think I should be using something else? Also the your code I put in does the some thing, just now it says "Sorry no none drink available" all the time. From dreadpiratejeff at gmail.com Wed Mar 10 21:52:19 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 10 Mar 2010 21:52:19 -0500 Subject: Ideas for creating processes In-Reply-To: <4B982535.4080000@mrabarnett.plus.com> References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> <4B982535.4080000@mrabarnett.plus.com> Message-ID: <36dec4ff1003101852x1b997d5bg68be4168ce01ce34@mail.gmail.com> On Wed, Mar 10, 2010 at 18:03, MRAB wrote: > Are you sure that you would gain from doing more than one at a time? > > The bottleneck will probably be the speed of your network connection, > and if that's working at its maximum speed with one sync then doing > several concurrently won't save any time. (The syncs will also be > completing for disk I/O.) Good point MRAB... thanks for making it. I started to wonder the same thing, but it took me a couple hours away from working on it and a good dinner before I saw that... Yeah, looking at it freshly now, I agree, I think I probably would be better off running them one at a time. The goal is to update several directories of ISO images with nightly builds. I can use rsync and only download images that are changed, or I can use zsync and only download diffs (I believe that's how it works) which is faster anyway. The only reason I was considering doing them all simultaneously, or in batches at least, is that I have to update 10 - 12 ISOs daily... BUT, now that I look at it from your perspective, yeah, it would probably be faster overall to do them one at a time instead because of the bottleneck. Thanks! That helped a lot (and probably saved me a lot of headache later on) :-) Cheers Jeff From steven at REMOVE.THIS.cybersource.com.au Wed Mar 10 22:18:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Mar 2010 03:18:47 GMT Subject: Can't define __call__ within __init__? References: Message-ID: On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > Want to switch __call__ behavior. Why doesn't this work? What is the > correct way to write this? > > class X (object): > def __init__(self, i): > if i == 0: > def __call__ (self): > return 0 > else: > def __call_ (self): > return 1 Others have already pointed out that there are two reasons that won't work: (1) you define __call__ as a local variable of the __init__ method which then disappears as soon as the __init__ method completes; and (2) special methods like __call__ are only called on the class, not the instance, so you can't give each instance its own method. Perhaps the best way to solve this is to use delegation: def zero_returner(): return 0 def one_returner(): return 1 class X (object): def __init__(self, i): if i == 0: self.func = zero_returner else: self.func = one_returner def __call__(self, *args, **kwargs): return self.func(*args, **kwargs) zero_returner and one_returner can be any callable object, not necessarily a function. Of course, all this assumes that your solution isn't even simpler: class X (object): def __init__(self, i): self.i = i def __call__(self): return self.i but I assume if it was that simple, you would have done that already. -- Steven From tjreedy at udel.edu Wed Mar 10 23:44:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 23:44:49 -0500 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: On 3/10/2010 4:49 PM, Lawrence D'Oliveiro wrote: > In message, Gabriel > Genellina wrote: > >> Warnsdorff's algorithm is heuristic ... > > Then it shouldn?t be called an ?algorithm?. Heuristic algorithms correctly compute some function, just not the one you want ;-). From radhakrishna12 at gmail.com Wed Mar 10 23:47:30 2010 From: radhakrishna12 at gmail.com (Radhakrishna Bhat) Date: Thu, 11 Mar 2010 10:17:30 +0530 Subject: Get a method instance through 'getattr' but not superclass's method Message-ID: I am using getattr to get a method instance from a class. But it also returns methods from the superclass. How to detect if an attribute is from superclass? -Radhakrishna -------------- next part -------------- An HTML attachment was scrubbed... URL: From efiish at gmail.com Wed Mar 10 23:56:48 2010 From: efiish at gmail.com (Lan Qing) Date: Thu, 11 Mar 2010 12:56:48 +0800 Subject: a newbie's question In-Reply-To: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> References: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> Message-ID: hi Cheers, Think you, that helps me a lot. On Tue, Mar 9, 2010 at 10:00 PM, Simon Brunning wrote: > On 9 March 2010 13:51, Lan Qing wrote: > > Hi all, > > I'm a newbie of python programming language. > > Welcome! > > > I have used c/c++ for 5 > > years, and one year experience in Lua programming language. Can any one > give > > me some advice on learning python. Think you for any help!! > > You'll find some useful starting points here - > . > > -- > Cheers, > Simon B. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Thu Mar 11 00:28:01 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 11 Mar 2010 10:58:01 +0530 Subject: a newbie's question In-Reply-To: References: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> Message-ID: Python is one language which is quite easy to get grasp of. one week and you'll start doing productive stuff. Best of luck on your quest. On Thu, Mar 11, 2010 at 10:26 AM, Lan Qing wrote: > hi Cheers, > Think you, that helps me a lot. > > > On Tue, Mar 9, 2010 at 10:00 PM, Simon Brunning wrote: > >> On 9 March 2010 13:51, Lan Qing wrote: >> > Hi all, >> > I'm a newbie of python programming language. >> >> Welcome! >> >> > I have used c/c++ for 5 >> > years, and one year experience in Lua programming language. Can any one >> give >> > me some advice on learning python. Think you for any help!! >> >> You'll find some useful starting points here - >> . >> >> -- >> Cheers, >> Simon B. >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sivaits4u at gmail.com Thu Mar 11 00:40:14 2010 From: sivaits4u at gmail.com (Bujji) Date: Thu, 11 Mar 2010 11:10:14 +0530 Subject: use of multiple versions of python Message-ID: <581ce2791003102140t7fd470e5obcad20ec714f60f3@mail.gmail.com> hi all, I have installed python 2.6 in addition to python 2.5 in my system Now for some modules(while installing ) it needs to use python 2.6 how can i do that in case of easy_install what should i do to it to use python 2.6 from my understanding /usr/bin/python is the one which will be taking care of version. but with this only one version of python can run even though we have tow versions. please post some solution for my problem. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lacrima.maxim at gmail.com Thu Mar 11 00:48:45 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 10 Mar 2010 21:48:45 -0800 (PST) Subject: Can't install ssl for Python2.5 References: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> Message-ID: On Mar 10, 11:23?pm, "Martin v. Loewis" wrote: > > I don't know how to solve this problem and I am looking forward for > > help. > > Try running "python setup.py install" directly, after downloading and > unpacking the package. > > Regards, > Martin Thanks a lot! It helped! From richardbp at gmail.com Thu Mar 11 01:22:56 2010 From: richardbp at gmail.com (Richard) Date: Wed, 10 Mar 2010 22:22:56 -0800 (PST) Subject: os.rename [Errno 31] Too many links References: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> <7vpugdF5bqU1@mid.individual.net> Message-ID: <1082952b-5dc0-4efa-b47f-9ada9aa7980f@x23g2000prd.googlegroups.com> On Mar 11, 3:08?am, Thomas Guettler wrote: > Richard wrote: > > I want to atomically write to a file so have been using temporary > > files and renaming: > > > temp = tempfile.NamedTemporaryFile(delete=False) > > temp.file.write(data) > > temp.file.close() > > os.rename(temp.name, output_file) > > > This worked but after 39567 files os.rename raises an OSError: [Errno > > 31] Too many links > > > I can still create files in this directory so I doubt it is a platform > > limitation. > > Can you tell what is wrong? Am I not freeing the temporary file > > resources properly? > > If you are on linux you can have a look at the open file descriptors of > a running process like this: > > ls -l /proc/PID/fd/ > > But I guess it is a limitation of your filesystem. What do you use? > > I once had this problem with ext2. It has a low limit for > subdirectories. > > With xfs the limits are much greater. > > ? Thomas > > -- > Thomas Guettler,http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de I am using Ubuntu 9.10 with ext3, which I believe has a limit for the number of subdirectories but not files. Thanks for the open file descriptor tip - I will check that out. Richard From stefan_ml at behnel.de Thu Mar 11 02:53:51 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Mar 2010 08:53:51 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: <4B97CCDF.7070802@simplistix.co.uk> References: <4B97CCDF.7070802@simplistix.co.uk> Message-ID: Chris Withers, 10.03.2010 17:46: > kj wrote: >> Subject line pretty much says it all: is there a book like "Effective >> Java" > > oxymoronic, no? > > Sorry, couldn't resist ;-) Nothing to excuse for. I thought exactly the same thing. Stefan From james.harris.1 at googlemail.com Thu Mar 11 03:30:02 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Thu, 11 Mar 2010 00:30:02 -0800 (PST) Subject: Anything like "Effective Java" for Python? References: Message-ID: <62192fd8-2350-49c5-aeea-c8fe14878a61@d2g2000yqa.googlegroups.com> On 10 Mar, 15:19, kj wrote: > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. ?I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? I don't know about the Java book you mention but I find Python in a Nutshell published by O'Reilly to be a good reference. James From stava at telcotec.se Thu Mar 11 03:43:50 2010 From: stava at telcotec.se (Lars Stavholm) Date: Thu, 11 Mar 2010 14:13:50 +0530 Subject: pexpect and logging integration In-Reply-To: <4B97A7BD.6050003@sequans.com> References: <4B972EA7.50807@telcotec.se> <4B97A7BD.6050003@sequans.com> Message-ID: <4B98AD46.6090702@telcotec.se> It works like a charm, thank you! /Lars Jean-Michel Pichavant wrote: > Lars Stavholm wrote: >> Hi all, >> >> has anyone managed to integrate pexpect and logging? >> >> I.e., I'd like to be able to pick up the dialog, >> commands sent and responses received, in my logging. >> I know about the pexpect logfile, and I can log things >> to stdout or stderr, but I really need to log using the >> python logging library. >> >> Any thoughts appreciated >> /Lars >> >> > I had to implement this. > It's a bit of a hack, but it does the job. > > The following code is tested with python 2.5, I remember pexpect behaves > slightly differently in python 2.3. > > import logging > import pexpect > import re > > # this will be the method called by the pexpect object to log > def _write(*args, **kwargs): > content = args[0] > # let's ignore other params, pexpect only use one arg AFAIK > if content in [' ', '', '\n', '\r', '\r\n']: > return # don't log empty lines > for eol in ['\r\n', '\r', '\n']: > # remove ending EOL, the logger will add it anyway > content = re.sub('\%s$' % eol, '', content) > return logger.info(content) # call the logger info method with the > reworked content > > > # our flush method > def _doNothing(): > pass > > # get the logger > logger = logging.getLogger('foo') > > # configure the logger > logger.handlers=[] > logger.addHandler(logging.StreamHandler()) > logger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - > %(name)s - %(levelname)s - %(message)s")) > logger.setLevel(logging.INFO) > > # give the logger the methods required by pexpect > logger.write = _write > logger.flush = _doNothing > > p = pexpect.spawn('echo "hello world !!"', logfile=logger) > p.expect('!!') > > ... 2010-03-10 15:01:31,234 - foo - INFO - hello world !! > > Hope it helps. > > JM > > From mihir3445 at gmail.com Thu Mar 11 04:12:02 2010 From: mihir3445 at gmail.com (Mihir Patel) Date: Thu, 11 Mar 2010 01:12:02 -0800 (PST) Subject: EOFError: EOF when reading a line Message-ID: I am trying to use the subprocess to send the data to child process. I am not sure why i keep getting "EOFError: EOF when reading a line" i am using Python 2.4.3, GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on 64bit linux ,centos Thanks output : ===== Traceback (most recent call last): File "test_input.py", line 3, in ? x = raw_input() EOFError: EOF when reading a line output: hello Main Program: =========== command_line = 'python test_input.py' p =subprocess.Popen(command_line, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) print 'output:', p.communicate()[0] o,e = p.communicate('test') print "out:",o print "error:",e p.stdout.close() print "Exit Success" test_input.py ========== print 'hello\n' x = raw_input() print x From jitu.icfai at gmail.com Thu Mar 11 04:32:18 2010 From: jitu.icfai at gmail.com (jitendra gupta) Date: Thu, 11 Mar 2010 15:02:18 +0530 Subject: Behavior of default parameter in a function Message-ID: def foo(x = [0]): x[0] = x[0] + 1 return x[0] def soo(x = None): if x is None: x = [0] x[0] = x[0] + 1 return x[0] >>> foo() 1 >>>foo() #See the behavior incremented by one 2 >>>foo([1]) # but here based on given number 2 >>>foo() 3 >>>foo([1]) 2 >>>foo() 4 >>>soo() 1 >>>soo() 1 >>>soo([1]) 2 >>>soo() 1 Why foo() is incremented by 1 always when we are not passing any argument, but this is not happening in soo() case, In which scenario we will use these type of function.' Thanks Jitendra Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From shashank.sunny.singh at gmail.com Thu Mar 11 04:40:43 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Thu, 11 Mar 2010 15:10:43 +0530 Subject: Behavior of default parameter in a function In-Reply-To: References: Message-ID: <332972a21003110140h4f83acbp55a0c75ced584ace@mail.gmail.com> quoting from docs:http://docs.python.org/reference/compound_stmts.html *Default parameter values are evaluated when the function definition is executed.* This means that the expression is evaluated once, when the function is defined, and that that same ?pre-computed? value is used for each call. This is especially important to understand when a default parameter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified so default object for x in foo is precomputed once and is modified with each call. hth --shashank On Thu, Mar 11, 2010 at 3:02 PM, jitendra gupta wrote: > > def foo(x = [0]): > x[0] = x[0] + 1 > return x[0] > > def soo(x = None): > if x is None: > x = [0] > x[0] = x[0] + 1 > return x[0] > > >>> foo() > 1 > >>>foo() #See the behavior incremented by one > 2 > >>>foo([1]) # but here based on given number > 2 > >>>foo() > 3 > >>>foo([1]) > 2 > >>>foo() > 4 > > >>>soo() > 1 > >>>soo() > 1 > >>>soo([1]) > 2 > >>>soo() > 1 > > Why foo() is incremented by 1 always when we are not passing any argument, > but this is not happening in soo() case, In which scenario we will use > these type of function.' > > Thanks > Jitendra Kumar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From george.sakkis at gmail.com Thu Mar 11 05:21:51 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Thu, 11 Mar 2010 11:21:51 +0100 Subject: Multiple import of the same module under different names Message-ID: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> The import mechanism is not very smart in identifying whether two modules imported under different name are actually the same module, at least when dealing with implicit relative imports and sys.path manipulation. However, at least in cases of plain file modules, the module's __file__ would be adequate (or at least better than __name__) in determining this. Below is an illustration of the different situations (absolute imports, explicit relative imports, implicit relative import, sys.path tweaking). So why does not import consult __file__ before deciding to create a new module instance ? George === File structure ============= ~/pkg/ __init__.py # empty mod1.py mod2.py mod3.py mod4.py main.py subpkg/ __init__.py # empty foo.py # empty === Run ============= ~$ PYTHONPATH=. python pkg/main.py === Output ============= Imported foo from pkg.subpkg: Imported foo from subpkg: Imported foo from pkg.mod1: Imported foo from mod1: Imported foo from pkg.mod2: Failed to import foo from mod2: Attempted relative import in non-package Imported foo from pkg.mod3: Imported foo from mod3: Imported foo from pkg.mod4: Imported foo from mod4: * 9 total module(s) * 3 distinct module(s) * 1 distinct file(s) /home/george/pkg/subpkg/foo.py === Code ============= ### mod1.py ### # implicit relative import from subpkg import foo ### mod2.py ### # explicit relative import from .subpkg import foo ### mod3.py ### # absolute import from pkg.subpkg import foo ### mod4.py ### # absolute import after tweaking sys.path import sys from os.path import dirname,join sys.path.append(join(dirname(__file__), 'subpkg')) import foo ### main.py ### #!/usr/bin/env python from os.path import abspath, normpath def test(*modules): module_set = set(modules) file_set = set(module_file(m) for m in modules) print '* %d total module(s)' % len(modules) print '* %d distinct module(s)' % len(module_set) for m in module_set: print '\t', m print '* %d distinct file(s)' % len(file_set) for f in file_set: print '\t', f def module_file(mod): f = abspath(normpath(mod.__file__)) if f.endswith('.pyc'): f = f[:-1] return f if __name__ == '__main__': from pkg.subpkg import foo print 'Imported foo from pkg.subpkg:\t', foo from subpkg import foo as rel_foo print 'Imported foo from subpkg:\t\t', rel_foo from pkg.mod1 import foo as foo1 print 'Imported foo from pkg.mod1:\t', foo1 from mod1 import foo as rel_foo1 print 'Imported foo from mod1:\t\t', rel_foo1 from pkg.mod2 import foo as foo2 print 'Imported foo from pkg.mod2:\t', foo2 try: from mod2 import foo as rel_foo2 except ValueError, ex: print 'Failed to import foo from mod2:', ex from pkg.mod3 import foo as foo3 print 'Imported foo from pkg.mod3:\t', foo3 from mod3 import foo as rel_foo3 print 'Imported foo from mod3:\t\t', rel_foo3 from pkg.mod4 import foo as foo4 print 'Imported foo from pkg.mod4:\t', foo4 from mod4 import foo as rel_foo4 print 'Imported foo from mod4:\t\t', rel_foo4 print test(foo, rel_foo, foo1, rel_foo1, foo2, # rel_foo2, foo3, rel_foo3, foo4, rel_foo4) From Neil.Blue at biowisdom.com Thu Mar 11 05:30:24 2010 From: Neil.Blue at biowisdom.com (Neil Blue) Date: Thu, 11 Mar 2010 10:30:24 -0000 Subject: How to handle file uploads with http.server In-Reply-To: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> References: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> Message-ID: <4728DC0EADB2654E8BA2A487F0CF2785AD6D2E@ws-ukexchange.internal.biowisdom.com> Hello, I have a basic http.server instance running (class HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I would like to upload files with multipart forms. def do_POST(self): ctype, pdict = cgi.parse_header(self.headers['Content-Type']) if ctype=='multipart/form-data': print('parsing...') query=cgi.parse_multipart(self.rfile, pdict) print(query) However the file never seems to finish being parsed. There are no errors, but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict) Please can anyone offer some insight into this or somewhere else I may find some more information. Thanks Neil ********************************************* The information contained in this message is likely to be confidential. It is intended only for the person named above. Any dissemination, distribution, copying, disclosure or use of this message or its contents unless authorised by BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of BioWisdom Ltd. If you have received this message in error, please immediately notify us and delete it. Thank you. Registered Office: BioWisdom Ltd, Harston Mill, Harston, Cambridge, CB22 7GG. Registered in England: (GB) 3861669. VAT registered: (GB) 750899881. Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, Internet:www.biowisdom.com ********************************************* From jeanmichel at sequans.com Thu Mar 11 05:44:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Mar 2010 11:44:22 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: <4B980DC6.4050807@hellmutweber.de> References: <4B980DC6.4050807@hellmutweber.de> Message-ID: <4B98C986.10707@sequans.com> Hellmut Weber wrote: > Hi Vinay Sajip, > I'm very glad discoverd your logging module ;-) > (That's what I would have liked 25 years ago when I was working as a > technical software developper!) > > Now I'm writing just some personal tools, I like python and want to > use logging on a regular basis. > > Logging works very well giving the filename and line number of the > point where it is called. As long as I use the loggers directly. > BUT when I have to wrap the logger call in some other function, I > always get file name and line number of the call of the logger inside > the wrapping function. > > Is there a possibility to get this information in this situation too? > > TIA > > Hellmut > You have to specify the file and line number by yourself, the logging feature can only assume that you want the line number of the logger call. i.e. in test.py: import logging import inspect _logger = logging.getLogger(__name__) class Foo: def __init__(self): self._logger = _logger def info(self, msg): previousFrame = inspect.currentframe().f_back self._logger.info(msg, extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename}) if __name__ == '__main__': _logger.handlers=[] _logger.addHandler(logging.StreamHandler()) _logger.handlers[-1].setFormatter(logging.Formatter('file %(custom_filename)s line %(custom_lineno)d : %(message)s')) _logger.setLevel(logging.DEBUG) foo = Foo() foo.info('a foo info') In [3]: run test.py file test.py line 20 : a foo info note that you cannot override the logging builtin 'lineno' key with the extra dictionary, that is why I'm using the 'custom_lineno' key. I don't know why the logger forbids it though, would have been nice to override lineno without the need of adding a new key. JM From __peter__ at web.de Thu Mar 11 06:14:08 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Mar 2010 12:14:08 +0100 Subject: logging: local functions ==> loss of lineno References: Message-ID: Hellmut Weber wrote: > Logging works very well giving the filename and line number of the point > where it is called. As long as I use the loggers directly. > BUT when I have to wrap the logger call in some other function, I always > get file name and line number of the call of the logger inside the > wrapping function. > > Is there a possibility to get this information in this situation too? The official way is probably to write a custom Logger class that overrides the findCaller() method. Below is a hack that monkey-patches the logging._srcfile attribute to ignore user-specified modules in the call stack: $ cat wrapper.py import logging import os import sys logger = logging.getLogger() class SrcFile(object): def __init__(self, exclude_files): self.files = set(exclude_files) def __eq__(self, other): return other in self.files def fixname(filename): if filename.lower().endswith((".pyc", ".pyo")): filename = filename[:-4] + ".py" return os.path.normcase(filename) if "--monkey" in sys.argv: print "patching" logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) def warn(*args, **kw): logger.warn(*args, **kw) $ cat main.py import logging logging.basicConfig(format="%(filename)s <%(lineno)s>: %(message)s") import wrapper wrapper.warn("foo") wrapper.warn("bar") wrapper.warn("baz") $ python main.py wrapper.py <23>: foo wrapper.py <23>: bar wrapper.py <23>: baz $ python main.py --monkey patching main.py <4>: foo main.py <5>: bar main.py <6>: baz $ python -V Python 2.6.4 Peter From steve at holdenweb.com Thu Mar 11 07:37:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 07:37:20 -0500 Subject: Python Script to get Info from Site not working In-Reply-To: <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> Message-ID: Jimbo wrote: > On Mar 11, 12:38 pm, "Gabriel Genellina" > wrote: >> En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: >> >>> I found a semi Python & internet tutorial here if anyone else would >>> like ithttp://www.upriss.org.uk/python/session6.html >>> My script is meant to find which radio button is selected & tell me >>> that. But it just keeps saying "No Drink Selected!" >> Are you sure? From the code you posted, the message should read "You need >> to select a drink!", not that one. > >> Replace the last line with something like this, to see what you are >> getting exactly: >> >> print("Sorry, no %r (%r) available." % ( >> drink, >> cgi.escape(repr(type(drink))))) >> >> BTW, which Python version are you using? The tutorial you linked to is >> aimed at Python 2.x, but your print syntax suggests you're using Python 3.x >> >> -- >> Gabriel Genellina > > Yeah that("You need to select a drink!") was the string I was getting > but I should be getting hot chocolate or something else(which ever one > I have selected) > > I am using 3.x, do you think I should be using something else? Also > the your code I put in does the some thing, just now it says "Sorry no > none drink available" all the time. It may not seem like it, but you *are* making progress here (of a sort). >From the information you have given us so far it appears that your call to form.getvalue() is returning None (which is of type - your browser is probably not displaying this because it sees it as a bogus HTML tag. Perhaps you haven't yet realised the importance of exact copy-and-paste here. What I'd like you to do is change the line drink = form.getvalue("drink") to drink = form.getfirst("drink", "No drink selected") then have you browser display the HTML source of the response page your program is returning and paste that into a reply to this mail. You might also want to take a look at http://docs.python.org/3.1/library/cgi.html for further information about the Python library your are trying to use. In particular I'd recommend heeding its advice about use of the cgitb module. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Mar 11 07:42:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 07:42:29 -0500 Subject: Get a method instance through 'getattr' but not superclass's method In-Reply-To: References: Message-ID: Radhakrishna Bhat wrote: > I am using getattr to get a method instance from a class. But it also > returns methods from the superclass. How to detect if an attribute is > from superclass? > You could try, if x is in instance, looking to see whether the name is defined in x.__class__.__dict__. >>> class A: ... def method1(self): ... print "A1" ... def method2(self): ... print "A2" ... >>> class B(A): ... def method2(self): ... print"B2" ... def method3(self): ... print "B3" ... >>> a = A() >>> b = B() >>> b.method2() B2 >>> b.method1() A1 >>> b.method3() B3 >>> b.__class__.__dict__ {'__module__': '__main__', 'method2': , 'method3': , '__doc__': None} >>> a.__class__.__dict__ {'__module__': '__main__', 'method2': , '__doc__': None, 'method1': } >>> I'd be interested to know why this is so important. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ndbecker2 at gmail.com Thu Mar 11 07:56:59 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 11 Mar 2010 07:56:59 -0500 Subject: Can't define __call__ within __init__? References: Message-ID: Steven D'Aprano wrote: > On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > >> Want to switch __call__ behavior. Why doesn't this work? What is the >> correct way to write this? >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> def __call__ (self): >> return 0 >> else: >> def __call_ (self): >> return 1 > > > Others have already pointed out that there are two reasons that won't > work: > > (1) you define __call__ as a local variable of the __init__ method which > then disappears as soon as the __init__ method completes; and > > (2) special methods like __call__ are only called on the class, not the > instance, so you can't give each instance its own method. > > > Perhaps the best way to solve this is to use delegation: > > > def zero_returner(): > return 0 > > def one_returner(): > return 1 > > > class X (object): > def __init__(self, i): > if i == 0: > self.func = zero_returner > else: > self.func = one_returner > def __call__(self, *args, **kwargs): > return self.func(*args, **kwargs) > > > zero_returner and one_returner can be any callable object, not > necessarily a function. > > Of course, all this assumes that your solution isn't even simpler: > > class X (object): > def __init__(self, i): > self.i = i > def __call__(self): > return self.i > > but I assume if it was that simple, you would have done that already. > > > The example I showed was just a toy problem. The real problem is I expect to call a function many times, and I want to avoid the overhead of the 'if blah' everytime. From paskari007 at yahoo.ca Thu Mar 11 07:58:35 2010 From: paskari007 at yahoo.ca (PEYMAN ASKARI) Date: Thu, 11 Mar 2010 04:58:35 -0800 (PST) Subject: a newbie's question In-Reply-To: Message-ID: <493846.1798.qm@web30003.mail.mud.yahoo.com> Hello I need some help dynamically reloading modules. As it turns out, it is not as simple as calling reload, as outlined here http://pyunit.sourceforge.net/notes/reloading.html Is there builtin support for this? The example they gave does not seem to work for me, and I am unclear as to what PyUnit is. Thanks Peyman --- On Thu, 3/11/10, Lan Qing wrote: From: Lan Qing Subject: Re: a newbie's question To: "Python List" Received: Thursday, March 11, 2010, 4:56 AM hi Cheers,?? ? Think you, that helps me a lot. On Tue, Mar 9, 2010 at 10:00 PM, Simon Brunning wrote: On 9 March 2010 13:51, Lan Qing wrote: > Hi all, > ?? ? ?I'm a newbie of python programming language. Welcome! > I have used c/c++ for 5 > years, and one year experience in Lua programming language. Can any one give > me some advice on learning python. Think you for any help!! You'll find some useful starting points here - . -- Cheers, Simon B. -----Inline Attachment Follows----- -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Mar 11 08:10:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Mar 2010 14:10:40 +0100 Subject: a newbie's question In-Reply-To: <493846.1798.qm@web30003.mail.mud.yahoo.com> References: <493846.1798.qm@web30003.mail.mud.yahoo.com> Message-ID: <4B98EBD0.8020902@sequans.com> PEYMAN ASKARI wrote: > Hello > > I need some help dynamically reloading modules. As it turns out, it is > not as simple as calling reload, as outlined here > http://pyunit.sourceforge.net/notes/reloading.html > > Is there builtin support for this? The example they gave does not seem > to work for me, and I am unclear as to what PyUnit is. > > Thanks > > > Peyman > Please don't top post. As for your question, there's no built-in method to reload a module because it is not possible (in a generic manner). However if you *really* want to do it you can do it for your particular module (and only for this one). It is tough to explain though. You have to know perfectly the python object model and I'm not familiar enough with it to do the explanation. So: 1/ try to live without dynamic reload 2/ if you *really* require dynamic reload, you can try to execute the module in a subprocess. That way, every time you start a new subprocess, the last up to date version of the module is used 3/ reload the module and all it's related objects currently in memory, this is painfull and there are many traps to fall into. I'll let someone else answer this point. JM From radhakrishna12 at gmail.com Thu Mar 11 08:15:19 2010 From: radhakrishna12 at gmail.com (Radhakrishna Bhat) Date: Thu, 11 Mar 2010 18:45:19 +0530 Subject: Get a method instance through 'getattr' but not superclass's method In-Reply-To: References: Message-ID: Thanks. I just have to check in that string if method1 is from present in subclass's __dict__ or not. This is important for me because in my code, I am dynamically calling methods of 2 classes where one is superclass of the other. And I was getting duplicate results because of this problem. -Radhakrishna On Thu, Mar 11, 2010 at 6:12 PM, Steve Holden wrote: > Radhakrishna Bhat wrote: > > I am using getattr to get a method instance from a class. But it also > > returns methods from the superclass. How to detect if an attribute is > > from superclass? > > > You could try, if x is in instance, looking to see whether the name is > defined in x.__class__.__dict__. > > >>> class A: > ... def method1(self): > ... print "A1" > ... def method2(self): > ... print "A2" > ... > >>> class B(A): > ... def method2(self): > ... print"B2" > ... def method3(self): > ... print "B3" > ... > >>> a = A() > >>> b = B() > >>> b.method2() > B2 > >>> b.method1() > A1 > >>> b.method3() > B3 > >>> b.__class__.__dict__ > {'__module__': '__main__', 'method2': , > 'method3': , '__doc__': None} > >>> a.__class__.__dict__ > {'__module__': '__main__', 'method2': , > '__doc__': None, 'method1': } > >>> > > I'd be interested to know why this is so important. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Mar 11 08:30:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 08:30:12 -0500 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: Neal Becker wrote: > Steven D'Aprano wrote: > >> On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: >> >>> Want to switch __call__ behavior. Why doesn't this work? What is the >>> correct way to write this? >>> >>> class X (object): >>> def __init__(self, i): >>> if i == 0: >>> def __call__ (self): >>> return 0 >>> else: >>> def __call_ (self): >>> return 1 >> >> Others have already pointed out that there are two reasons that won't >> work: >> >> (1) you define __call__ as a local variable of the __init__ method which >> then disappears as soon as the __init__ method completes; and >> >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. >> >> >> Perhaps the best way to solve this is to use delegation: >> >> >> def zero_returner(): >> return 0 >> >> def one_returner(): >> return 1 >> >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> self.func = zero_returner >> else: >> self.func = one_returner >> def __call__(self, *args, **kwargs): >> return self.func(*args, **kwargs) >> >> >> zero_returner and one_returner can be any callable object, not >> necessarily a function. >> >> Of course, all this assumes that your solution isn't even simpler: >> >> class X (object): >> def __init__(self, i): >> self.i = i >> def __call__(self): >> return self.i >> >> but I assume if it was that simple, you would have done that already. >> >> >> > The example I showed was just a toy problem. The real problem is > I expect to call a function many times, and I want to avoid the overhead of > the 'if blah' everytime. > This is a premature optimization. First, make it work. Then (if it doesn't work fast enough) make it work faster. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From astley.lejasper at gmail.com Thu Mar 11 08:55:56 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 11 Mar 2010 05:55:56 -0800 (PST) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) Message-ID: I have a Windows 7 (64bit AMD) machine and am having quite a lot of problems installing Reportlabs and Pil. I wondered if anyone else has had the same issues and what the best way of dealing with it. So far I've tried: 1. Reportlabs / Pil 32 installers - I've tried using these but they can't find python. I also tried registering Python (http://effbot.org/ zone/python-register.htm) but this also fails. 2. Reportlabs / Pil Source - I downloaded each of these and tried to do a "python setup.py install". However, both complain that they can't find "vcvarsall.bat". I've done some checking and it's because the compiler isn't present. Everyone is suggesting downloading Visual Studio Express C++, but this only comes with the 32bit compiler. There seems to be quite a lot of work to get 64bit VSE working on a 64bit machine (http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008- express-edition-and-64-bit-targets/). But before I start down that path, I wondered if anyone had any advice (.... and no I don't mean suggesting I swap to Linux). ALJ From victorsubervi at gmail.com Thu Mar 11 08:57:03 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 11 Mar 2010 09:57:03 -0400 Subject: Interacting With Another Script In-Reply-To: <2db4409d-d8d7-4af9-a9a7-e8071bc30b0f@o16g2000prh.googlegroups.com> References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> <2db4409d-d8d7-4af9-a9a7-e8071bc30b0f@o16g2000prh.googlegroups.com> Message-ID: <4dc0cfea1003110557y16ad8e65i81a136d841b7c07e@mail.gmail.com> On Wed, Mar 10, 2010 at 10:16 PM, alex23 wrote: > Victor Subervi wrote: > > > There's a program (vpopmail) that has commands which, when called, > request > > > input ("email address", "password", etc.) from the command line. I > would > > > like to build a TTW interface for my clients to use that interacts with > > > these commands. > > The Pexpect[1] module is pretty much aimed at doing exactly this. > > 1: http://www.noah.org/wiki/Pexpect THIS looks PERFECT! Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Thu Mar 11 09:14:45 2010 From: andreengels at gmail.com (Andre Engels) Date: Thu, 11 Mar 2010 15:14:45 +0100 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: <6faf39c91003110614v2b2aec8dg5c0c62f01fb56503@mail.gmail.com> On Thu, Mar 11, 2010 at 2:30 PM, Steve Holden wrote: >> The example I showed was just a toy problem. ?The real problem is >> I expect to call a function many times, and I want to avoid the overhead of >> the 'if blah' everytime. >> > This is a premature optimization. First, make it work. Then (if it > doesn't work fast enough) make it work faster. Corrolary: When you do make it faster, make it faster where it is slow. Second corrolary: If making it fast is so important that these two rules do not apply, Python is not your language of choice. -- Andr? Engels, andreengels at gmail.com From stefan_ml at behnel.de Thu Mar 11 09:24:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Mar 2010 15:24:13 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: <62192fd8-2350-49c5-aeea-c8fe14878a61@d2g2000yqa.googlegroups.com> References: <62192fd8-2350-49c5-aeea-c8fe14878a61@d2g2000yqa.googlegroups.com> Message-ID: James Harris, 11.03.2010 09:30: > On 10 Mar, 15:19, kj wrote: >> Subject line pretty much says it all: is there a book like "Effective >> Java" for Python. I.e. a book that assumes that readers are >> experienced programmers that already know the basics of the language, >> and want to focus on more advanced programming issues? > > I don't know about the Java book you mention but I find Python in a > Nutshell published by O'Reilly to be a good reference. There's also the Python Cookbook that has a couple of useful recipes that can become handy at times. http://code.activestate.com/recipes/langs/python/ Stefan From gb345 at invalid.com Thu Mar 11 09:57:37 2010 From: gb345 at invalid.com (gb345) Date: Thu, 11 Mar 2010 14:57:37 +0000 (UTC) Subject: Need advice on starting a Python group Message-ID: I'm hoping to get advice from anyone with prior experience setting up a Python group. A friend of mine and I have been trying to start a scientific-programming-oriented Python group in our school (of medecine and bio research), with not much success. The main problem is attendance. Even though a *ton* of people have told us that it's a great idea, that they're *very* interested, and have asked to be added to our mailing list, the attendance to our first few meeting has never been more than 5, including my friend and I. Last time just he and I showed up. The second problem is getting content. The format we'd envisioned for this group was centered around code review (though not limited to it). The idea was that at every meeting a different member would show some code. This could be for any of a number of reasons, such as, for example, 1) illustrate a cool module or technique; 2) present a scientific research problem and how they used Python to solve it, or get help solving it; 3) get general feedback (e.g. on code clarity, software usability, module architecture, etc.). But in principle just about anything is OK: e.g. a talk on favorite Python resources, or a comparison of Python with some other language, or an overview of Python gotchas would all be fair game. Also, we stressed that the talks were not expected to be polished: no need for PowerPoint slides, etc. Just project any old code onto the screen, and talk about it, or scribble stuff on the chalkboard. Still, we have a hard time finding volunteers. And even when we've had volunteers, hardly anyone shows up! Any suggestions would be appreciated. GB P.S. There's a Python Meetup we could go to, but it does not fit the bill for us: it doesn't meet often enough, it's sort of out of the way, and has practically no one doing scientific programming. From no.email at please.post Thu Mar 11 10:05:30 2010 From: no.email at please.post (kj) Date: Thu, 11 Mar 2010 15:05:30 +0000 (UTC) Subject: Anything like "Effective Java" for Python? References: Message-ID: In Chris Withers writes: >kj wrote: >> >> >> Subject line pretty much says it all: is there a book like "Effective >> Java" >oxymoronic, no? >Sorry, couldn't resist ;-) I hear you, but still: read "Effective Java" some day; it will make you a better programmer, whatever your language preference. I'm certainly no fan of Java, but I still rank Effective Java as one of my best reads on programming ever. I felt that my maturity as a programmer went up a notch or two after digesting this book. Cheers, ~K From philip at semanchuk.com Thu Mar 11 10:09:08 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 11 Mar 2010 10:09:08 -0500 Subject: show image in python In-Reply-To: References: Message-ID: On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote: > Hey, This is my program > > 1 #!/usr/bin/python > 2 import PIL > 3 import numpy > 4 import Image > 5 import ImageOps > 6 import sys > 7 > 8 def Matimg(path): > 9 """transforme image en matrice""" > 10 Img = Image.open(str(path)) > 11 Img1 = ImageOps.grayscale(Img) > 12 largeur,hauteur = Img1.size > 13 imdata = Img1.getdata() > 14 tab = numpy.array(imdata) > 15 matrix = numpy.reshape(tab,(hauteur,largeur)) > 16 return matrix > 17 > 18 def Creeimg(): > 19 """transforme matrice en image""" > 20 img = Image.new ("L",(8,8)) > 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] > 22 img.putdata(matrix) > 23 img.show() > 24 img.save(fp="./ana.bmp") > 25 > 26 if __name__== '__main__': > 27 if len(sys.argv) < 2 : > 28 print "Usage: img.py " > 29 sys.exit(0) > 30 path = sys.argv[1] > 31 matrix = Matimg(path) > 32 print matrix > 33 Creeimg() > > My probeleme : In line 23 "img.show()" Don't work, normally I show > the image > but it's not work, but strangely in line 24 "img.save(fp="./ > ana.bmp")" it's > work > WHERE IS THE PROBLEME. > > I have this error in shell : "(eog:3176): GLib-WARNING **: GError > set over > the top of a previous GError or uninitialized memory. > This indicates a bug in someone's code. You must ensure an error is > NULL > before it's set. > The overwriting error message was: Error in getting image file info " > > > os: ubuntu 9.10 Hi issolah, I don't know what your problem is but I have a few suggestions -- 1) You say that img.show() doesn't work. How does it fail? Is that where you get the GLib warning? 2) I'm glad you posted your code, but because it has line numbers, it's awkward to copy & paste into a local example. Please show your code without line numbers. I'm unfamiliar with PIL, so this is just a wild guess, but based on the GLib error it seems like you haven't initialized something properly. Sorry I couldn't be more helpful. Maybe someone who knows more will answer. Good luck Philip From showell30 at yahoo.com Thu Mar 11 10:16:25 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 11 Mar 2010 07:16:25 -0800 (PST) Subject: Anything like "Effective Java" for Python? References: Message-ID: <498a6d4c-3f8b-44fd-b2e0-23793031fee2@a16g2000pre.googlegroups.com> On Mar 11, 7:05?am, kj wrote: > In Chris Withers writes: > > >kj wrote: > > >> Subject line pretty much says it all: is there a book like "Effective > >> Java" > >oxymoronic, no? > >Sorry, couldn't resist ;-) > > I hear you, but still: read "Effective Java" some day; it will make > you a better programmer, whatever your language preference. ?I'm > certainly no fan of Java, but I still rank Effective Java as one > of my best reads on programming ever. ?I felt that my maturity as > a programmer went up a notch or two after digesting this book. > I'll second that. I much prefer Python to Java, but Effective Java is an excellent book. Many of its topics would be applicable to Python, although the solutions in Python would obviously be different. Eliminate obsolete object references (use None to break reference counts) Avoid finalizers (use the "with" statement) Favor immutability Design method signatures carefully (including the x=[] gotcha) Optimize judiciously Don't ignore exceptions Avoid excessive synchronization There are also some topics in Effective Java where the advice is almost the opposite of Python tradition. From CalWhoNOSPAM at roadrunner.com Thu Mar 11 10:43:35 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 10:43:35 -0500 Subject: I get the error: ImportError: No module named ffnet Message-ID: I have the .py file in Eclipse #@PydevCodeAnalysisIgnore from ffnet import ffnet, mlgraph topology = mlgraph( (2, 3, 1) ) nn = ffnet(topology) I select RunAs / Python Run I get the error from ffnet import ffnet, mlgraph ImportError: No module named ffnet In the folder Python26\lib\site-packages I see ffnet-0.6.2-py2.6.egg-info also a folder ffnet in that folder there is a folder Examples If I click one of the examples pyrhon.exe opens and runs it OK. Is there enough in the above for you to tell me how to procede? Thanks in advance for any help at all From kw at codebykevin.com Thu Mar 11 10:44:12 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 11 Mar 2010 10:44:12 -0500 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <94360$4b990fcc$4275d90a$23785@FUSE.NET> On 3/10/10 10:19 AM, kj wrote: > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K I haven't read "Effective Java," but I have found Lutz's "Programming Python" to be a very useful guide to solving various programming issues with the language. It's a big, big book, so there's lots to look at. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From icanbob at gmail.com Thu Mar 11 10:54:44 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 11 Mar 2010 07:54:44 -0800 (PST) Subject: Ideas for creating processes References: Message-ID: <0878d070-2c7a-4bdc-82eb-278432aa6695@b7g2000yqd.googlegroups.com> On Mar 10, 4:52 pm, J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) > > For now, I've got this: > > def main(): > ## get our list of directories to refresh > releases=sys.argv[1:] > if len(releases) < 1: > print "You need to provide at least one dir to update" > sys.exit() > > ## Lets figure out what there is to update > updateDirs = [] > for rel in releases: > currentDir = os.path.join(homedir, rel) > for item in os.listdir(currentDir): > updateDirs += [os.path.join(homedir, rel, item)] > > which returns a list of full pathnames to directories that need to be > updated (updates will be carried out by calling rsync or zsync > eventually) > > The directory hierarchy looks like this: > > /home/user/files > /home/user/files/version1 > /home/user/files/version1/type1 > /home/user/files/version1/type2 > /home/user/files/version2 > /home/user/files/version2/type1 > > and the list ends up looking like this: > > ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] > > the next thing I need to do is figure out how to update those. > > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > chdir into path > execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > kick off an individual rsync|zsync process to update path > > wait for all child processes to end > exit program. > > I've been looking at subprocess because at the moment, that's all I > really know... > But is there a better way of kicking off multiple simultaneous > processes so I can update all dirs at once instead of one at a time? > > No, this isn't homework, it's something I'm working on to sync a > couple directories of ISO images to grab nightly builds > Yes, there are plenty of pre-made scripts out there, but I don't want > to even look at those because I figured this would be a good learning > experience, and I want to try to solve this as much on my own as I can > without just cut and pasting from someone elses program. > > So, with that said, any ideas on the best way to proceed? I'm going > to start looking at ways to use subprocess to do this, or would there > be a better way (multi-threading maybe?) > > Or am I even in the right ballpark? > > Cheers > Jeff You might be able to use the SIMPL toolkit for this one. (http://www.icanprogram.com/06py/lesson1/lesson1.html) You could wrap the rsync executable as a SIMPL receiver module and then message to that from inside your Python script to kick it off and synchronize actions. bob From dvkeeney at gmail.com Thu Mar 11 11:00:29 2010 From: dvkeeney at gmail.com (dkeeney) Date: Thu, 11 Mar 2010 08:00:29 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: <3707bdd1-7371-445e-b303-96c2b636102d@e19g2000prn.googlegroups.com> On Mar 8, 12:14?pm, Duncan Booth wrote: > You've totally missed the point. It isn't the size of the data you have > today that matters, it's the size of data you could have in several years' > time. > > Maybe today you've got 10 users each with 10 megabytes of data, but you're > aspiring to become the next twitter/facebook or whatever. It's a bit late > as you approach 100 million users (and a petabyte of data) to discover that > your system isn't scalable: scalability needs to be built in from day one. Do you have examples of sites that got big by planning their site architecture from day 0 to be big? Judging from published accounts, even Facebook and Twitter did not plan to be 'the next twitter/facebook'; each started with routine LAMP stack architecture and successfully re-engineered the architecture multiple times on the way up. Is there compelling reason to think the 'next twitter/facebook' can't and won't climb a very similar path? I see good reasons to think that they *will* follow the same path, in that there are motivations at both ends of the path for re-engineering as you go. When the site is small, resources commited to the backend are not spent on making the frontend useful, so business-wise the best backend is the cheapest one. When the site becomes super-large, the backend gets re-engineered based on what that organization learned while the site was just large; Facebook, Twitter, and Craigslist all have architectures custom designed to support their specific needs. Had they tried to design for large size while they were small, they would have failed; they couldn't have known enough then about what they would eventually need. The only example I can find of a large site that architected large very early is Google, and they were aiming for a market (search) that was already known to be huge. Its reasonable to assume that the 'next twitter/facebook' will *not* be in web search, social-networking, broadcast instant messaging, or classified ads, just because those niches are taken already. So whichever 'high-scalability' model the aspiring site uses will be the wrong one. They might as well start with a quick and cheap LAMP stack, and re-engineer as they go. Just one internet watcher's biased opinion... David www.rdbhost.com -> SQL databases via a web-service From python at mrabarnett.plus.com Thu Mar 11 11:01:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 16:01:41 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: <6faf39c91003110614v2b2aec8dg5c0c62f01fb56503@mail.gmail.com> References: <6faf39c91003110614v2b2aec8dg5c0c62f01fb56503@mail.gmail.com> Message-ID: <4B9913E5.7060404@mrabarnett.plus.com> Andre Engels wrote: > On Thu, Mar 11, 2010 at 2:30 PM, Steve Holden wrote: > >>> The example I showed was just a toy problem. The real problem is >>> I expect to call a function many times, and I want to avoid the overhead of >>> the 'if blah' everytime. >>> >> This is a premature optimization. First, make it work. Then (if it >> doesn't work fast enough) make it work faster. > > Corrolary: When you do make it faster, make it faster where it is slow. > Second corrolary: If making it fast is so important that these two > rules do not apply, Python is not your language of choice. > Addendum: a bad algorithm is bad, whatever language it's written in. From gnarlodious at gmail.com Thu Mar 11 11:02:59 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Thu, 11 Mar 2010 08:02:59 -0800 (PST) Subject: Insert missing keys using defaultdict Message-ID: <55e00342-a83e-4e45-8448-d04e71251631@c16g2000yqd.googlegroups.com> I am trying to grok this documentation but need help: http://docs.python.org/library/collections.html#defaultdict-examples In a perfect world the dict looks like this: plistDict={'Style':'ExternalURL', 'Ref':'http://Gnarlodious.com/', 'Tip':'Opens in a new window', 'Text':'Gnarlodious.com'} Let's say I want to prep a dict from a plist to insert the values into an HTML link string: "%(Text)s" % plistDict However, in this imperfect world the dict might look like this: plistDict={'Ref':'http://Gnarlodious.com/', 'Text':'Gnarlodious.com'} which would error: KeyError: 'Style' So using defaultdict: from collections import defaultdict How do create a dict assigning every missing key with a default string? -- Gnarlie From isso.moh at gmail.com Thu Mar 11 11:07:39 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Thu, 11 Mar 2010 17:07:39 +0100 Subject: show image in python In-Reply-To: References: Message-ID: hey #!/usr/bin/python 2 import PIL 3 import numpy 4 import Image import ImageOps import sys def Matimg(path): """transforme image en matrice""" Img = Image.open(str(path)) Img1 = ImageOps.grayscale(Img) largeur,hauteur = Img1.size imdata = Img1.getdata() tab = numpy.array(imdata) matrix = numpy.reshape(tab,(hauteur,largeur)) return matrix def Creeimg(): """transforme matrice en image""" img = Image.new ("L",(8,8)) matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] img.putdata(matrix) img.show() img.save(fp="./ana.bmp") if __name__== '__main__': if len(sys.argv) < 2 : print "Usage: img.py " sys.exit(0) path = sys.argv[1] matrix = Matimg(path) print matrix Creeimg() 2010/3/11 Philip Semanchuk > > On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote: > > Hey, This is my program >> >> 1 #!/usr/bin/python >> 2 import PIL >> 3 import numpy >> 4 import Image >> 5 import ImageOps >> 6 import sys >> 7 >> 8 def Matimg(path): >> 9 """transforme image en matrice""" >> 10 Img = Image.open(str(path)) >> 11 Img1 = ImageOps.grayscale(Img) >> 12 largeur,hauteur = Img1.size >> 13 imdata = Img1.getdata() >> 14 tab = numpy.array(imdata) >> 15 matrix = numpy.reshape(tab,(hauteur,largeur)) >> 16 return matrix >> 17 >> 18 def Creeimg(): >> 19 """transforme matrice en image""" >> 20 img = Image.new ("L",(8,8)) >> 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] >> 22 img.putdata(matrix) >> 23 img.show() >> 24 img.save(fp="./ana.bmp") >> 25 >> 26 if __name__== '__main__': >> 27 if len(sys.argv) < 2 : >> 28 print "Usage: img.py " >> 29 sys.exit(0) >> 30 path = sys.argv[1] >> 31 matrix = Matimg(path) >> 32 print matrix >> 33 Creeimg() >> >> My probeleme : In line 23 "img.show()" Don't work, normally I show the >> image >> but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" >> it's >> work >> WHERE IS THE PROBLEME. >> >> I have this error in shell : "(eog:3176): GLib-WARNING **: GError set over >> the top of a previous GError or uninitialized memory. >> This indicates a bug in someone's code. You must ensure an error is NULL >> before it's set. >> The overwriting error message was: Error in getting image file info " >> >> >> os: ubuntu 9.10 >> > > Hi issolah, > I don't know what your problem is but I have a few suggestions -- > 1) You say that img.show() doesn't work. How does it fail? Is that where > you get the GLib warning? > 2) I'm glad you posted your code, but because it has line numbers, it's > awkward to copy & paste into a local example. Please show your code without > line numbers. > > I'm unfamiliar with PIL, so this is just a wild guess, but based on the > GLib error it seems like you haven't initialized something properly. Sorry I > couldn't be more helpful. Maybe someone who knows more will answer. > > Good luck > Philip > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Mar 11 11:20:14 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 11 Mar 2010 08:20:14 -0800 (PST) Subject: Can't define __call__ within __init__? References: Message-ID: On Mar 10, 7:18?pm, Steven D'Aprano wrote: > On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > > Want to switch __call__ behavior. ?Why doesn't this work? ?What is the > > correct way to write this? > > > class X (object): > > ? ? def __init__(self, i): > > ? ? ? ? if i == 0: > > ? ? ? ? ? ? def __call__ (self): > > ? ? ? ? ? ? ? ? return 0 > > ? ? ? ? else: > > ? ? ? ? ? ? def __call_ (self): > > ? ? ? ? ? ? ? ? return 1 > > Others have already pointed out that there are two reasons that won't > work: > > (1) you define __call__ as a local variable of the __init__ method which > then disappears as soon as the __init__ method completes; and > > (2) special methods like __call__ are only called on the class, not the > instance, so you can't give each instance its own method. > Are you sure about that? This program prints 1, 2, 1, 2. class Foo: def __init__(self, a): if a == 1: self.__call__ = lambda: 1 else: self.__call__ = lambda: 2 foo1 = Foo(1) print foo1() foo2 = Foo(2) print foo2() print foo1() print foo2() See here: http://docs.python.org/reference/datamodel.html Class instances Class instances are described below. Class instances are callable only when the class has a __call__() method; x(arguments) is a shorthand for x.__call__(arguments). From george.sakkis at gmail.com Thu Mar 11 11:20:47 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Thu, 11 Mar 2010 08:20:47 -0800 (PST) Subject: Insert missing keys using defaultdict References: <55e00342-a83e-4e45-8448-d04e71251631@c16g2000yqd.googlegroups.com> Message-ID: <350e66eb-5c5b-4abe-826b-44a73a90053c@33g2000yqj.googlegroups.com> On Mar 11, 5:02?pm, Gnarlodious wrote: > I am trying to grok this documentation but need help:http://docs.python.org/library/collections.html#defaultdict-examples > > In a perfect world the dict looks like this: > plistDict={'Style':'ExternalURL', 'Ref':'http://Gnarlodious.com/', > 'Tip':'Opens in a new window', 'Text':'Gnarlodious.com'} > > Let's say I want to prep a dict from a plist to insert the values into > an HTML link string: > "%(Text)s" % > plistDict > > However, in this imperfect world the dict might look like this: > plistDict={'Ref':'http://Gnarlodious.com/', 'Text':'Gnarlodious.com'} > > which would error: > KeyError: 'Style' > > So using defaultdict: > from collections import defaultdict > > How do create a dict assigning every missing key with a default > string? "%(Text)s" % defaultdict(lambda:'_MISSING_', plistDict) HTH, George From gnarlodious at gmail.com Thu Mar 11 11:27:24 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Thu, 11 Mar 2010 08:27:24 -0800 (PST) Subject: Insert missing keys using defaultdict References: <55e00342-a83e-4e45-8448-d04e71251631@c16g2000yqd.googlegroups.com> <350e66eb-5c5b-4abe-826b-44a73a90053c@33g2000yqj.googlegroups.com> Message-ID: <2b32f4ae-a61d-4a5b-a085-1df16a6cea58@c16g2000yqd.googlegroups.com> On Mar 11, 9:20?am, George Sakkis wrote: > > How do create a dict assigning every missing key with a default > > string? > > "%(Text)s" % > defaultdict(lambda:'_MISSING_', plistDict) Brilliant, I love Python. -- Gnarlie From rizwanahmed24 at gmail.com Thu Mar 11 11:28:38 2010 From: rizwanahmed24 at gmail.com (rizwanahmed24 at gmail.com) Date: Thu, 11 Mar 2010 08:28:38 -0800 (PST) Subject: bypass UAC control through python script (to be run from batchfile) Message-ID: <26028cd0-8ead-47d0-95d8-09e2214dddd3@e7g2000yqf.googlegroups.com> Hi here is my problem. i want to install a program through python script. The python scripts is called from a batch file. The UAC control is not allowing the python script to install a msi (installer). I need to somehow by pass the UAC control. i dont want to turn it off permanently. Once i have run the batch file, i do not interact with the system manually, therefore Clicking allow on UAC dialog is not the solution for me. i just want to achieve the goal, whether i run batch file in Admin mode, or do it form python, doesnt matter. any ideas? //Rizwan From robin at reportlab.com Thu Mar 11 11:29:26 2010 From: robin at reportlab.com (Robin Becker) Date: Thu, 11 Mar 2010 16:29:26 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: References: Message-ID: <4B991A66.4020203@chamonix.reportlab.co.uk> On 11/03/2010 13:55, Astley Le Jasper wrote: > I have a Windows 7 (64bit AMD) machine and am having quite a lot of > problems installing Reportlabs and Pil. I wondered if anyone else has > had the same issues and what the best way of dealing with it. > > So far I've tried: > > 1. Reportlabs / Pil 32 installers - I've tried using these but they > can't find python. I also tried registering Python (http://effbot.org/ > zone/python-register.htm) but this also fails. > 2. Reportlabs / Pil Source - I downloaded each of these and tried to > do a "python setup.py install". However, both complain that they can't > find "vcvarsall.bat". I've done some checking and it's because the > compiler isn't present. Everyone is suggesting downloading Visual > Studio Express C++, but this only comes with the 32bit compiler. There > seems to be quite a lot of work to get 64bit VSE working on a 64bit > machine (http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008- > express-edition-and-64-bit-targets/). > > But before I start down that path, I wondered if anyone had any advice > (.... and no I don't mean suggesting I swap to Linux). > > ALJ Hi, you might get more assistance on the reportlab users mailing list at http://two.pairlist.net/mailman/listinfo/reportlab-users We do have users that run both reportlab & pil on 64 bit linux architectures, but I don't think I have ever compiled any of the extensions for 64bit windows. The vcvarsall.bat reference is the distutils package desperately looking for a suitable compiler (and not finding it). Perhaps some expert on the python list knows which versions of VS support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set up a 64bit machine to see if they will install on a 64bit architecture. -- Robin Becker From __peter__ at web.de Thu Mar 11 11:36:03 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Mar 2010 17:36:03 +0100 Subject: Can't define __call__ within __init__? References: Message-ID: Steve Howell wrote: > On Mar 10, 7:18 pm, Steven D'Aprano > wrote: >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. > Are you sure about that? This program prints 1, 2, 1, 2. You are using a classic class while the behaviour described above applies to newstyle classes: >>> class Foo: ... def __init__(self): ... self.__call__ = lambda: 42 ... >>> Foo()() 42 >>> class Bar(object): ... def __init__(self): ... self.__call__ = lambda: 42 ... >>> Bar()() Traceback (most recent call last): File "", line 1, in TypeError: 'Bar' object is not callable I don't think it's a good idea to write new code that requires a classic class. Peter From gherron at islandtraining.com Thu Mar 11 11:48:20 2010 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 11 Mar 2010 08:48:20 -0800 Subject: Behavior of default parameter in a function In-Reply-To: References: Message-ID: <4B991ED4.1030203@islandtraining.com> This is addressed in the FAQ. http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects jitendra gupta wrote: > > def foo(x = [0]): > x[0] = x[0] + 1 > return x[0] > > def soo(x = None): > if x is None: > x = [0] > x[0] = x[0] + 1 > return x[0] > > >>> foo() > 1 > >>>foo() #See the behavior incremented by one > 2 > >>>foo([1]) # but here based on given number > 2 > >>>foo() > 3 > >>>foo([1]) > 2 > >>>foo() > 4 > > >>>soo() > 1 > >>>soo() > 1 > >>>soo([1]) > 2 > >>>soo() > 1 > > Why foo() is incremented by 1 always when we are not passing any argument, > but this is not happening in soo() case, In which scenario > we will use these type of function.' > > Thanks > Jitendra Kumar > From CalWhoNOSPAM at roadrunner.com Thu Mar 11 12:04:20 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 12:04:20 -0500 Subject: I get the error: ImportError: No module named ffnet References: Message-ID: I ran this: import sys from pprint import pprint as pp pp(sys.path) The output included: 'E:\\Program Files\\Python26', 'E:\\Program Files\\Python26\\DLLs', 'E:\\Program Files\\Python26\\lib', 'E:\\Program Files\\Python26\\lib\\lib-tk', 'E:\\Program Files\\Python26\\lib\\plat-win', 'E:\\Program Files\\Python26\\lib\\site-packages', Python is at E:\Python26 but other things like java are at E:\Program Files Showhow it is looking in the wrong place and I don't know how to fix it. I checked the registry. The entries all look good there. Thanks " Cal Who" wrote in message news:hnb339$g2g$1 at news.eternal-september.org... > > > I have the .py file in Eclipse > #@PydevCodeAnalysisIgnore > from ffnet import ffnet, mlgraph > topology = mlgraph( (2, 3, 1) ) > nn = ffnet(topology) > > I select RunAs / Python Run > > I get the error > from ffnet import ffnet, mlgraph > ImportError: No module named ffnet > > In the folder Python26\lib\site-packages I see > ffnet-0.6.2-py2.6.egg-info > > also a folder ffnet > in that folder there is a folder Examples > If I click one of the examples pyrhon.exe opens and runs it OK. > > Is there enough in the above for you to tell me how to procede? > > Thanks in advance for any help at all > > > From bartc at freeuk.com Thu Mar 11 12:22:49 2010 From: bartc at freeuk.com (bartc) Date: Thu, 11 Mar 2010 17:22:49 GMT Subject: Named loops for breaking In-Reply-To: References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: James Harris wrote: > On 10 Mar, 06:29, "Gabriel Genellina" wrote: >> En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein >> escribi : >> >>> Basically I'm wondering if there are any plans to implemented named >>> loops in Python, so I can tell a break command to break out of a >>> specific loop in the case of nested loops. >> >> See PEP3136 [1] and its rejection note [2] >> I think you may find some more discussion in the python-ideas list. > Breaking out of an inner loop is just as natural as breaking out of > the immediately enclosing loop. ISTM that if one is allowed the other > should be also. Exactly. Python already has single-level break (probably some baggage carried over from C), and some of the same arguments can be applied to that too. Given that break does exist, it's annoying that in the followed contrived example: def f(n): return n==2 for i in range(10): print i if f(0): break if f(1): break if f(2): break if f(3): break I can't turn the list of ifs into a loop. I can use break embedded inside a statement inside a loop, provided it's not another loop! That's discrimination... > There are often times when it *is* better to factor out the code to a > different function but adding a function just to enable a break from > an inner loop doesn't seem to me a good reason. Multi-level breaks should just have been part of the language, so they are available to those who want them, and ignored by everyone else. (And in languages where I've implemented them -- all generally faster than Python -- they have no impact on performance. I also had 4 loop controls rather than just 2, all multi-level, and the world hasn't ended yet.) My experience of these break statements is that they are used infrequently in final code. But they are handy when developing code too: you don't want to waste time refactoring, and generally turning code upside-down, when the code has to be rewritten a dozen times anyway. -- Bartc From mrkafk at gmail.com Thu Mar 11 12:28:04 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Mar 2010 18:28:04 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: kj wrote: > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? I'm surprised nobody mentioned Dive Into Python: http://diveintopython.org/ Available for free online. Most Python books contain a lot of 'hello world' material which for someone who knows at least one programming language is boring, this one doesn't, it cuts straight to the point. I found it very readable. Regards, mk From mehgcap at gmail.com Thu Mar 11 12:51:57 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 11 Mar 2010 12:51:57 -0500 Subject: importing modules from subdirs Message-ID: Hi all, The manual says, for modules in a project stored in subdirectories, you can do: import folderName.module I have a couple questions, though: 1. Do I then have to call functions from module like folder.module.function, or can I still use the normal module.function? 2. When I try to do this, it fails. I have an sw folder. Inside that I have a modes folder, holding weather.pyw. Main.pyw, back in the sw folder, is trying to import modes.weather, but nothing happens. I have tried putting weather.pyw in its own weather folder under the modes folder, but that also fails. I have placed an empty __init__.py file in both the modes folder and the weather subfolder, but I cannot get main.pyw to import weather! 3. How does weather import from a folder above or beside it? For example, if a config directory is at the same level as the modes directory, how can weather import something from config? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gherron at islandtraining.com Thu Mar 11 13:00:10 2010 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 11 Mar 2010 10:00:10 -0800 Subject: importing modules from subdirs In-Reply-To: References: Message-ID: <4B992FAA.2020102@islandtraining.com> Alex Hall wrote: > Hi all, > The manual says, for modules in a project stored in subdirectories, you can do: > import folderName.module > > I have a couple questions, though: > 1. Do I then have to call functions from module like > folder.module.function, or can I still use the normal module.function? > Either, depending on how you do the import: import folder.module folder.module.function() or from folder.module import function function() or from folder import module module.function() > 2. When I try to do this, it fails. I have an sw folder. Inside that I > have a modes folder, holding weather.pyw. Main.pyw, back in the sw > folder, is trying to import modes.weather, but nothing happens. I have > tried putting weather.pyw in its own weather folder under the modes > folder, but that also fails. I have placed an empty __init__.py file > in both the modes folder and the weather subfolder, but I cannot get > main.pyw to import weather! > Show us some code and a diagram of your forcer hierarchy, and we'll look at it. > 3. How does weather import from a folder above or beside it? For > example, if a config directory is at the same level as the modes > directory, how can weather import something from config? > You don't import from up the hierarchy. You can put a higher folder on sys.path, and get to it that way. Gary Herron > Thanks! > > From martin at v.loewis.de Thu Mar 11 13:00:21 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 11 Mar 2010 19:00:21 +0100 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: References: Message-ID: <4B992FB5.8090207@v.loewis.de> >> I have a Windows 7 (64bit AMD) machine This is somewhat imprecise: is it a) that your CPU is AMD64, and thus supports 64-bit mode, or b) that *in addition*, your Windows 7 installation is a 64-bit installation, or c) that *in addition*, your Python installation is also a 64-bit installation. Unless you have a specific need for 64-bit mode, I recommend that you use the 32-bit version of Windows (unless you have more than 4GB of main memory), and (even if you have a 64-bit Windows) you install the 32-bit version of Python on it (unless you have the need to access more than 2GB of objects in your Python applications. >> 1. Reportlabs / Pil 32 installers - I've tried using these but they >> can't find python. I also tried registering Python (http://effbot.org/ >> zone/python-register.htm) but this also fails. Install the 32-bit version of Python, and these installers should work fine. > Perhaps some expert on the python list knows which versions of VS > support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set > up a 64bit machine to see if they will install on a 64bit architecture. For Python 2.6 and later, use VS 2008. This comes with an AMD64 compiler. You technically don't need a 64-bit Windows, as it supports cross-compilation (but you would need a 64-bit Windows to test it). I personally build Python on a 32-bit machine, and move the MSI to a 64-bit machine for testing. Regards, Martin From steve at holdenweb.com Thu Mar 11 13:10:48 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 13:10:48 -0500 Subject: importing modules from subdirs In-Reply-To: References: Message-ID: Alex Hall wrote: > Hi all, > The manual says, for modules in a project stored in subdirectories, you can do: > import folderName.module > > I have a couple questions, though: > 1. Do I then have to call functions from module like > folder.module.function, or can I still use the normal module.function? > > 2. When I try to do this, it fails. I have an sw folder. Inside that I > have a modes folder, holding weather.pyw. Main.pyw, back in the sw > folder, is trying to import modes.weather, but nothing happens. I have > tried putting weather.pyw in its own weather folder under the modes > folder, but that also fails. I have placed an empty __init__.py file > in both the modes folder and the weather subfolder, but I cannot get > main.pyw to import weather! > > 3. How does weather import from a folder above or beside it? For > example, if a config directory is at the same level as the modes > directory, how can weather import something from config? > > Thanks! > I haven't checked this, but I believe .pyw names are only for main programs. Try renaming weather.pyw as weather.py and see if it makes any difference. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From drobinow at gmail.com Thu Mar 11 13:14:01 2010 From: drobinow at gmail.com (David Robinow) Date: Thu, 11 Mar 2010 13:14:01 -0500 Subject: use of multiple versions of python In-Reply-To: <581ce2791003102140t7fd470e5obcad20ec714f60f3@mail.gmail.com> References: <581ce2791003102140t7fd470e5obcad20ec714f60f3@mail.gmail.com> Message-ID: <4eb0089f1003111014w4f7bffack1ea409aa7a17ac2c@mail.gmail.com> On Thu, Mar 11, 2010 at 12:40 AM, Bujji wrote: > hi all, > I have installed python 2.6 in addition to python 2.5 in my system > Now for some modules(while installing ) it needs to use python 2.6 > how can i do that > in case of easy_install what should i do to it to use python 2.6 You should have an easy_install-2.5 and easy_install-2.6. One of them will be linked to easy_install, depending on how you did the install. Just use the one you need. From mehgcap at gmail.com Thu Mar 11 13:15:38 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 11 Mar 2010 13:15:38 -0500 Subject: unable to run wxPython script: dll errors Message-ID: Hi all, I am trying to run a file that should pop up a dialog. The dialog is fine (I used XRCed to create it and running it from within that editor brings up the dialog I want). When I run my file, though, I get this traceback: C:\Users\Alex>c:\python26\python.exe i:\arm\dictionary.py Traceback (most recent call last): File "i:\arm\dictionary.py", line 2, in import wx File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 5, in from wx._core import * File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i n import _core_ ImportError: DLL load failed: The specified procedure could not be found. I am running win7x64, wxPython2.8, python2.6. Any ideas why this would be happening? I found a forum post that talked about a manifest file and some dll files being needed, but it did not make a lot of sense. Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gagsl-py2 at yahoo.com.ar Thu Mar 11 13:28:15 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Mar 2010 15:28:15 -0300 Subject: Python Script to get Info from Site not working References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> Message-ID: En Wed, 10 Mar 2010 23:26:05 -0300, Jimbo escribi?: > On Mar 11, 12:38 pm, "Gabriel Genellina" > wrote: >> En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: >> >> > I found a semi Python & internet tutorial here if anyone else would >> > like ithttp://www.upriss.org.uk/python/session6.html >> >> Replace the last line with something like this, to see what you are >> getting exactly: >> >> print("Sorry, no %r (%r) available." % ( >> drink, >> cgi.escape(repr(type(drink))))) >> >> BTW, which Python version are you using? The tutorial you linked to is >> aimed at Python 2.x, but your print syntax suggests you're using Python >> 3.x > I am using 3.x, do you think I should be using something else? Yes, you should use the same version as the tutorial you're following. Learning how to program, CGI, HTML and Python at the same time is hard enough to complicate it with incompatible version differences. I suggest Python 2.6.4 > Also > the your code I put in does the some thing, just now it says "Sorry no > none drink available" all the time. As a general rule, always directly copy and paste the error messages you get and the source code you execute. Do not retype or paraphrase them. That's important for the rest of us to be able to help you - now and in the future. In this case, the message should read "Sorry, no None () available." (None, not none, is a built-in special object in Python). So we know that drink is None instead of one of the expected values, and we could start investigating why. But there is no point in digging further - instead, downgrade to Python 2.6.4 and try again. This might be a server issue, unrelated to your script. BTW, you didn't mention the server software. -- Gabriel Genellina From ludolph at openhazel.co.za Thu Mar 11 13:38:56 2010 From: ludolph at openhazel.co.za (Ludolph) Date: Thu, 11 Mar 2010 20:38:56 +0200 Subject: Visual Python programming and decompilers? Message-ID: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Hi Guys At work I have been exposed to a Agile Platform called OutSystems. It allows you to visually program your web applications http://i.imgur.com/r2F0i.png and I find the idea very intriguing. So I have started to play around with the idea on how will I be able to visually represent Python code as in the above image and then allow the programmer to change some of the flow/code/logic visually and then get it back as python source code. I don't know if this have been tried before and after some googling I can't find anything like this, so maybe I'm just lacking basic googling skills or a python solution like the above does not exist yet. If anybody knows of such solution please let me know, so that I don't spend a lot of time recreating the wheel. Otherwise help me out on the following problem: I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to disassemble the code to workable objects, It even allows me to rebuild the objects to bytecode. So if I define patterns on how python interrupts the source code to bytecode I can visually represent this and also so convert my visual representations back to bytecode. The only problem I have at the moment is how will I get this bytecode back to python source code. I have googled for python decompiler but only found old projects like unpyc, decompyle and some online services. I would like to know if anybody know of a well maintained or at least recent module that can help me accomplish the above mentioned, because I'm hoping I can implement this in Python 3.1. So any input or suggestion would be greatly appreciated. Kind Regards, -- Ludolph Neethling From gagsl-py2 at yahoo.com.ar Thu Mar 11 13:45:03 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Mar 2010 15:45:03 -0300 Subject: Get a method instance through 'getattr' but not superclass's method References: Message-ID: En Thu, 11 Mar 2010 01:47:30 -0300, Radhakrishna Bhat escribi?: > I am using getattr to get a method instance from a class. But it also > returns methods from the superclass. How to detect if an attribute is > from > superclass? You may look it up directly in the class dictionary (__dict__) -- Gabriel Genellina From kevin.p.dwyer at gmail.com Thu Mar 11 13:54:41 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Thu, 11 Mar 2010 18:54:41 +0000 (UTC) Subject: Python 2.6 and modules dbi AND odbc References: <2fb4a5011003101617r5518b322y6ccc091046b0ccc4@mail.gmail.com> Message-ID: On Wed, 10 Mar 2010 16:17:29 -0800, robert somerville wrote: > hi; > i am trying to get some legacy python code (which i no nothing about) > working with tries to import dbi and odbc (the import fails ...) it > looks like these modules are deprecated ?? if so is there a work around > , if not deprecated, what am i doing wrong ?? i see no Ubuntu packages > that look promising .. Hello Robert, These modules are distributed as part of the PyWin32 Python for Windows extensions, so they need to run on a Windows box. They'll run fine there regardless of the deprecation of dbi (though "import dbi" will provide a useful warning message). Pyodbc is a possible alternative. Cheers, Kev From CalWhoNOSPAM at roadrunner.com Thu Mar 11 13:56:08 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 13:56:08 -0500 Subject: I get the error: ImportError: No module named ffnet References: Message-ID: I found out I had something installed wrong. " Cal Who" wrote in message news:hnb339$g2g$1 at news.eternal-september.org... > > > I have the .py file in Eclipse > #@PydevCodeAnalysisIgnore > from ffnet import ffnet, mlgraph > topology = mlgraph( (2, 3, 1) ) > nn = ffnet(topology) > > I select RunAs / Python Run > > I get the error > from ffnet import ffnet, mlgraph > ImportError: No module named ffnet > > In the folder Python26\lib\site-packages I see > ffnet-0.6.2-py2.6.egg-info > > also a folder ffnet > in that folder there is a folder Examples > If I click one of the examples pyrhon.exe opens and runs it OK. > > Is there enough in the above for you to tell me how to procede? > > Thanks in advance for any help at all > > > From jcb at iteris.com Thu Mar 11 14:01:39 2010 From: jcb at iteris.com (Metalone) Date: Thu, 11 Mar 2010 11:01:39 -0800 (PST) Subject: file seek is slow References: Message-ID: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> I am assuming that Python delegates the f.seek call to the seek call in the MS C runtime library msvcrt.dll. Does anybody know a nice link to the Python source like was posted above for the BSD 'C' library? Ok, I ran some more tests. C, seek : 0.812 seconds // test from original post Python, f.seek : 1.458 seconds. // test from original post C, time(&tm) : 0.671 seconds Python, time.time(): 0.513 seconds. Python, ctypes.msvcrt.time(ctypes.byref(tm)): 0.971 seconds. # factored the overhead to be outside the loop, so really this was func_ptr(ptr). Perhaps I am just comparing apples to oranges. I never tested the overhead of ctypes like this before. Most of my problem timings involve calls through ctypes. From CalWhoNOSPAM at roadrunner.com Thu Mar 11 14:01:39 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 14:01:39 -0500 Subject: Where can I find documentation for data[:,9] Message-ID: data = readdata( 'data/input.dat', delimiter = ',' ) input = data[:, :9]#nine data columns Where can I find documentation for the data[:,9] in the code above. Been looking and found many examples but would like to know the definition. I need to skip the first column and then read 9 I would also like to print the data in ihe variable "input" Thanks From robert.kern at gmail.com Thu Mar 11 14:22:21 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Mar 2010 13:22:21 -0600 Subject: Where can I find documentation for data[:,9] In-Reply-To: References: Message-ID: On 2010-03-11 13:01 PM, Cal Who wrote: > data = readdata( 'data/input.dat', delimiter = ',' ) > > input = data[:, :9]#nine data columns > > > > Where can I find documentation for the > > data[:,9] > > in the code above. > > Been looking and found many examples but would like to know the definition. When asking questions like this, it helps *a lot* to provide a complete example, not just a snippet. If I weren't already intimately familiar with the library you are using, I would have no idea how to help you. However, I do know that input object is a numpy array, and the syntax you are asking about is multidimensional slicing. http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html > I need to skip the first column and then read 9 data[:, 1:10] > I would also like to print the data in ihe variable "input" print input -- 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 From misceverything at gmail.com Thu Mar 11 14:29:53 2010 From: misceverything at gmail.com (T) Date: Thu, 11 Mar 2010 11:29:53 -0800 (PST) Subject: Parsing Email Headers Message-ID: All I'm looking to do is to download messages from a POP account and retrieve the sender and subject from their headers. Right now I'm 95% of the way there, except I can't seem to figure out how to *just* get the headers. Problem is, certain email clients also include headers in the message body (i.e. if you're replying to a message), and these are all picked up as additional senders/subjects. So, I want to avoid processing anything from the message body. Here's a sample of what I have: # For each line in message for j in M.retr(i+1)[1]: # Create email message object from returned string emailMessage = email.message_from_string(j) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From") I also tried using the following, but got the same results: emailMessage = email.Parser.HeaderParser().parsestr(j, headersonly=True) Any help would be appreciated! From mehgcap at gmail.com Thu Mar 11 14:56:12 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 11 Mar 2010 14:56:12 -0500 Subject: importing modules from subdirs In-Reply-To: References: Message-ID: Halfway there. It imports now, but it says that the module does not have functions which I know it does have. I will just leave it all in one folder for now and play with organization after I get the project working better. On 3/11/10, Steve Holden wrote: > Alex Hall wrote: >> Hi all, >> The manual says, for modules in a project stored in subdirectories, you >> can do: >> import folderName.module >> >> I have a couple questions, though: >> 1. Do I then have to call functions from module like >> folder.module.function, or can I still use the normal module.function? >> >> 2. When I try to do this, it fails. I have an sw folder. Inside that I >> have a modes folder, holding weather.pyw. Main.pyw, back in the sw >> folder, is trying to import modes.weather, but nothing happens. I have >> tried putting weather.pyw in its own weather folder under the modes >> folder, but that also fails. I have placed an empty __init__.py file >> in both the modes folder and the weather subfolder, but I cannot get >> main.pyw to import weather! >> >> 3. How does weather import from a folder above or beside it? For >> example, if a config directory is at the same level as the modes >> directory, how can weather import something from config? >> >> Thanks! >> > I haven't checked this, but I believe .pyw names are only for main > programs. Try renaming weather.pyw as weather.py and see if it makes any > difference. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From python at mrabarnett.plus.com Thu Mar 11 15:13:48 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 20:13:48 +0000 Subject: Parsing Email Headers In-Reply-To: References: Message-ID: <4B994EFC.4060400@mrabarnett.plus.com> T wrote: > All I'm looking to do is to download messages from a POP account and > retrieve the sender and subject from their headers. Right now I'm 95% > of the way there, except I can't seem to figure out how to *just* get > the headers. Problem is, certain email clients also include headers > in the message body (i.e. if you're replying to a message), and these > are all picked up as additional senders/subjects. So, I want to avoid > processing anything from the message body. > > Here's a sample of what I have: > > # For each line in message > for j in M.retr(i+1)[1]: > # Create email message object from returned string > emailMessage = email.message_from_string(j) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") > > I also tried using the following, but got the same results: > emailMessage = > email.Parser.HeaderParser().parsestr(j, headersonly=True) > > Any help would be appreciated! If you're using poplib then use ".top" instead of ".retr". From debatem1 at gmail.com Thu Mar 11 15:16:26 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 11 Mar 2010 15:16:26 -0500 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: On Thu, Mar 11, 2010 at 1:38 PM, Ludolph wrote: > Hi Guys > > At work I have been exposed to a Agile Platform called OutSystems. It > allows you to visually program your web applications > http://i.imgur.com/r2F0i.png and I find the idea very intriguing. > > So I have started to play around with the idea on how will I be able > to visually represent Python code as in the above image and then allow > the programmer to change some of the flow/code/logic visually and then > get it back as python source code. I don't know if this have been > tried before and after some googling I can't find anything like this, > so maybe I'm just lacking basic googling skills or a python solution > like the above does not exist yet. > > If anybody knows of such solution please let me know, so that I don't > spend a lot of time recreating the wheel. Otherwise help me out on the > following problem: > > I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to > disassemble the code to workable objects, It even allows me to rebuild > the objects to bytecode. So if I define patterns on how python > interrupts the source code to bytecode I can visually represent this > and also so convert my visual representations back to bytecode. > > The only problem I have at the moment is how will I get this bytecode > back to python source code. I have googled for python decompiler but > only found old projects like unpyc, decompyle and some online > services. I would like to know if anybody know of a well maintained or > at least recent module that can help me accomplish the above > mentioned, because I'm hoping I can implement this in Python 3.1. > > So any input or suggestion would be greatly appreciated. > > Kind Regards, > > -- > Ludolph Neethling > -- > http://mail.python.org/mailman/listinfo/python-list > Maybe something like http://www.pypes.org/? They were at pycon and sounded pretty into what they were talking about- I'd send them an email. Geremy Condra From stef.mientki at gmail.com Thu Mar 11 15:17:09 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Mar 2010 21:17:09 +0100 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: <4B994FC5.1030106@gmail.com> On 11-03-2010 19:38, Ludolph wrote: > Hi Guys > > At work I have been exposed to a Agile Platform called OutSystems. It > allows you to visually program your web applications > http://i.imgur.com/r2F0i.png and I find the idea very intriguing. > > Although not as low level as you want, http://mientki.ruhosting.nl/data_www/pylab_works/pw_animations_screenshots.html http://code.google.com/p/pylab-works/ and here an overview of similar packages cheers, Stef From invalid at invalid.invalid Thu Mar 11 15:20:56 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 11 Mar 2010 20:20:56 +0000 (UTC) Subject: Parsing Email Headers References: Message-ID: On 2010-03-11, T wrote: > All I'm looking to do is to download messages from a POP account and > retrieve the sender and subject from their headers. Right now I'm 95% > of the way there, except I can't seem to figure out how to *just* get > the headers. The headers are saparated from the body by a blank line. > Problem is, certain email clients also include headers in the message > body (i.e. if you're replying to a message), and these are all picked > up as additional senders/subjects. So, I want to avoid processing > anything from the message body. Then stop when you see a blank line. Or retreive just the headers. -- Grant Edwards grant.b.edwards Yow! My life is a patio at of fun! gmail.com From astley.lejasper at gmail.com Thu Mar 11 15:57:07 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 11 Mar 2010 12:57:07 -0800 (PST) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) References: <4B992FB5.8090207@v.loewis.de> Message-ID: <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> @Robin Thanks. I thought that this seemed to be a general python thing because it was effecting both installs. However, after also reading Martin's comments ... @Martin > This is somewhat imprecise: is it > a) that your CPU is AMD64, and thus supports 64-bit mode, or > b) that *in addition*, your Windows 7 installation is a 64-bit > installation, or > c) that *in addition*, your Python installation is also a 64-bit > installation. > > Unless you have a specific need for 64-bit mode, I recommend that you > use the 32-bit version of Windows (unless you have more than 4GB of > main memory), and (even if you have a 64-bit Windows) you install the > 32-bit version of Python on it (unless you have the need to access more > than 2GB of objects in your Python applications. Sorry. I have Windows 7 (64-bit) installed on a machine with an AMD cpu (which supports 64-bit mode), with a 64-bit version of (Activestate) python 2.6 .... although I didn't realise the later until I looked just now. > Install the 32-bit version of Python, and these installers should work fine. Well, I uninstalled the 64-bit version and the installers did indeed work. I?m sorry everyone. I didn?t realise I had installed the 64-bit version of Python. Well, at least someone else might find have the same problem. But I think that there is going to be a bit of a rough patch as everyone moves over to 64-bit. ALJ From greg.ewing at canterbury.ac.nz Thu Mar 11 16:40:33 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 12 Mar 2010 10:40:33 +1300 Subject: Reverse engineering CRC? In-Reply-To: <3b1dce65-99ed-471a-8494-9eaf0e6d44ad@e19g2000prn.googlegroups.com> References: <7vj7fdFnnjU1@mid.individual.net> <3b1dce65-99ed-471a-8494-9eaf0e6d44ad@e19g2000prn.googlegroups.com> Message-ID: <7vt5n8FetlU1@mid.individual.net> Steve Howell wrote: > Hi Greg. I would at least flip one bit at a time on the first byte of > your data to see if the transformation is bitwise. I'm actually making good progress on this -- it turns out there *is* a way of deducing the polynomial by looking at the effect of single-bit flips. It's actually quite simple, with no brute-force searching needed at all. Things get a bit tricky when you don't quite know all of the data that goes into the CRC, though, which seems to be the case here... I'm writing up an essay on my experiences. I'll post a link when it's finished. -- Greg From CalWhoNOSPAM at roadrunner.com Thu Mar 11 17:08:36 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 17:08:36 -0500 Subject: Where can I find documentation for data[:,9] References: Message-ID: "Robert Kern" wrote in message news:mailman.631.1268335358.23598.python-list at python.org... > On 2010-03-11 13:01 PM, Cal Who wrote: >> data = readdata( 'data/input.dat', delimiter = ',' ) >> >> input = data[:, :9]#nine data columns >> >> >> >> Where can I find documentation for the >> >> data[:,9] >> >> in the code above. >> >> Been looking and found many examples but would like to know the >> definition. > > When asking questions like this, it helps *a lot* to provide a complete > example, not just a snippet. If I weren't already intimately familiar with > the library you are using, I would have no idea how to help you. > > However, I do know that input object is a numpy array, and the syntax you > are asking about is multidimensional slicing. > > http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html > >> I need to skip the first column and then read 9 > > data[:, 1:10] > >> I would also like to print the data in ihe variable "input" > > print input > > -- > 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 > Thanks, that helped a lot. I'm having trouble knowing what to search for to find documenatation. For example, is print a Python command, a numpy command or a java command? I like to read the documentation even if the command is working for me. Thanks again From martin.hellwig at dcuktec.org Thu Mar 11 17:19:09 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Mar 2010 22:19:09 +0000 Subject: Where can I find documentation for data[:,9] In-Reply-To: References: Message-ID: On 03/11/10 22:08, Cal Who wrote: > Thanks, that helped a lot. > > I'm having trouble knowing what to search for to find documenatation. For > example, is print a Python command, a numpy command or a java command? > > I like to read the documentation even if the command is working for me. > > > Thanks again > > Probably for you the right way would be to familiarize yourself with the namespace concept of Python, this makes it easier to identify whether something is built-in, a standard module or an external module. Which makes it much easier to feed google the right clues. -- mph From misceverything at gmail.com Thu Mar 11 17:44:09 2010 From: misceverything at gmail.com (T) Date: Thu, 11 Mar 2010 14:44:09 -0800 (PST) Subject: Parsing Email Headers References: Message-ID: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> On Mar 11, 3:13?pm, MRAB wrote: > T wrote: > > All I'm looking to do is to download messages from a POP account and > > retrieve the sender and subject from their headers. ?Right now I'm 95% > > of the way there, except I can't seem to figure out how to *just* get > > the headers. ?Problem is, certain email clients also include headers > > in the message body (i.e. if you're replying to a message), and these > > are all picked up as additional senders/subjects. ?So, I want to avoid > > processing anything from the message body. > > > Here's a sample of what I have: > > > ? ? ? ? ? ? ? ? # For each line in message > > ? ? ? ? ? ? ? ? for j in M.retr(i+1)[1]: > > ? ? ? ? ? ? ? ? ? ? # Create email message object from returned string > > ? ? ? ? ? ? ? ? ? ? emailMessage = email.message_from_string(j) > > ? ? ? ? ? ? ? ? ? ? # Get fields > > ? ? ? ? ? ? ? ? ? ? fields = emailMessage.keys() > > ? ? ? ? ? ? ? ? ? ? # If email contains "From" field > > ? ? ? ? ? ? ? ? ? ? if emailMessage.has_key("From"): > > ? ? ? ? ? ? ? ? ? ? ? ? # Get contents of From field > > ? ? ? ? ? ? ? ? ? ? ? ? from_field = emailMessage.__getitem__("From") > > > I also tried using the following, but got the same results: > > ? ? ? ? ? ? ? ? ?emailMessage = > > email.Parser.HeaderParser().parsestr(j, headersonly=True) > > > Any help would be appreciated! > > If you're using poplib then use ".top" instead of ".retr". I'm still having the same issue, even with .top. Am I missing something? for j in M.top(i+1, 0)[1]: emailMessage = email.message_from_string(j) #emailMessage = email.Parser.HeaderParser().parsestr(j, headersonly=True) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From") Is there another way I should be using to retrieve only the headers (not those in the body)? From martin.hellwig at dcuktec.org Thu Mar 11 17:46:57 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Mar 2010 22:46:57 +0000 Subject: Platform Requirement Checker (was Does this already exists?: A module that checks if the used platform is supported) In-Reply-To: References: Message-ID: On 03/11/10 01:37, Gabriel Genellina wrote: > En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig > escribi?: > >> Before I start reinventing a squared wheel, I have the following >> question: >> Is there already a (standard) module that wraps around the various >> os/sys information which checks if the platform + version is supported >> for what I want to do with it. > > In case you were not aware of it: see the platform module. But you'll have > to do the checks yourself (based on the info it returns). > Thanks for the reminder, it indeed slipped my mind. As Python features are luckily mostly platform independent, I am not sure if a convenient 'platform requirement check' module would be worth the energy creating it, any thoughts on that? For clarity purpose I re'added (and adapted) in what lines I was thinking: - test = RequirePlatform(do_not_raise=True) # If do_not_raise is not set or False, an error will be raised # after a failed require line, otherwise just continue. test.require(key='test1', platform='freebsd', version_min='2.2') # If the platform is anything else but FreeBSD 2.2 onwards return False # and store the result of the test. # Result of the require (and any additional tests # can be accessed using the index operators; if test['test1']: print('supported') - Other requirements like architecture, python vm type/version, cpu features, etc. Might also be nice to have. -- mph From CalWhoNOSPAM at roadrunner.com Thu Mar 11 17:52:21 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 17:52:21 -0500 Subject: Where can I find documentation for data[:,9] References: Message-ID: "Martin P. Hellwig" wrote in message news:hnbq8q$vgm$1 at news.eternal-september.org... > On 03/11/10 22:08, Cal Who wrote: > >> Thanks, that helped a lot. >> >> I'm having trouble knowing what to search for to find documenatation. For >> example, is print a Python command, a numpy command or a java command? >> >> I like to read the documentation even if the command is working for me. >> >> >> Thanks again >> >> > Probably for you the right way would be to familiarize yourself with the > namespace concept of Python, this makes it easier to identify whether > something is built-in, a standard module or an external module. > Which makes it much easier to feed google the right clues. > > -- > mph Thanks a lot, I'll look that up now. From jcb at iteris.com Thu Mar 11 17:57:28 2010 From: jcb at iteris.com (Metalone) Date: Thu, 11 Mar 2010 14:57:28 -0800 (PST) Subject: file seek is slow References: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> Message-ID: <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> I just tried the seek test with Cython. Cython fseek() : 1.059 seconds. 30% slower than 'C' Python f.seek : 1.458 secondds. 80% slower than 'C'. It is amazing to me that Cython generates a 'C' file that is 1478 lines. #Cython code import time cdef int SEEK_SET = 0 cdef extern from "stdio.h": void* fopen(char* filename, char* mode) int fseek(void*, long, int) def main(): cdef void* f1 = fopen('video.txt', 'rb') cdef int i=1000000 t0 = time.clock() while i > 0: fseek(f1, 0, SEEK_SET) i -= 1 delta = time.clock() - t0 print "%.3f" % delta if __name__ == '__main__': main() From felix.antoine.fortin at gmail.com Thu Mar 11 18:05:00 2010 From: felix.antoine.fortin at gmail.com (=?ISO-8859-1?Q?F=E9lix=2DAntoine_Fortin?=) Date: Thu, 11 Mar 2010 15:05:00 -0800 (PST) Subject: inspect.stack() and frame Message-ID: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> Given this code : # Experience with frame import sys import inspect def foo(): stack = inspect.stack() print "foo frame : " + str(hex(id(sys._getframe()))) def foo2(): inspect.stack() print "foo2 frame : " + str(hex(id(sys._getframe()))) def bar(): print "bar frame : " + str(hex(id(sys._getframe()))) foo() foo() foo2() foo2() bar() bar() Output example : foo frame : 0x84d2c0 foo frame : 0x844bf0 foo2 frame : 0x898c90 foo2 frame : 0x898c90 bar frame : 0x898f70 bar frame : 0x898f70 Why are the ids (address) of the frame for each foo call not the same? Or why the call to "stack = inspect.stack()" change the address of the frame? From python at mrabarnett.plus.com Thu Mar 11 18:06:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 23:06:40 +0000 Subject: Parsing Email Headers In-Reply-To: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> References: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> Message-ID: <4B997780.4000009@mrabarnett.plus.com> T wrote: > On Mar 11, 3:13 pm, MRAB wrote: >> T wrote: >>> All I'm looking to do is to download messages from a POP account and >>> retrieve the sender and subject from their headers. Right now I'm 95% >>> of the way there, except I can't seem to figure out how to *just* get >>> the headers. Problem is, certain email clients also include headers >>> in the message body (i.e. if you're replying to a message), and these >>> are all picked up as additional senders/subjects. So, I want to avoid >>> processing anything from the message body. >>> Here's a sample of what I have: >>> # For each line in message >>> for j in M.retr(i+1)[1]: >>> # Create email message object from returned string >>> emailMessage = email.message_from_string(j) >>> # Get fields >>> fields = emailMessage.keys() >>> # If email contains "From" field >>> if emailMessage.has_key("From"): >>> # Get contents of From field >>> from_field = emailMessage.__getitem__("From") >>> I also tried using the following, but got the same results: >>> emailMessage = >>> email.Parser.HeaderParser().parsestr(j, headersonly=True) >>> Any help would be appreciated! >> If you're using poplib then use ".top" instead of ".retr". > > I'm still having the same issue, even with .top. Am I missing > something? > > for j in M.top(i+1, 0)[1]: > emailMessage = email.message_from_string(j) > #emailMessage = > email.Parser.HeaderParser().parsestr(j, headersonly=True) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") > > Is there another way I should be using to retrieve only the headers > (not those in the body)? The documentation does say: """unfortunately, TOP is poorly specified in the RFCs and is frequently broken in off-brand servers.""" All I can say is that it works for me with my ISP! :-) From python at mrabarnett.plus.com Thu Mar 11 18:09:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 23:09:05 +0000 Subject: Platform Requirement Checker (was Does this already exists?: A module that checks if the used platform is supported) In-Reply-To: References: Message-ID: <4B997811.3000607@mrabarnett.plus.com> Martin P. Hellwig wrote: > On 03/11/10 01:37, Gabriel Genellina wrote: >> En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig >> escribi?: >> >>> Before I start reinventing a squared wheel, I have the following >>> question: >>> Is there already a (standard) module that wraps around the various >>> os/sys information which checks if the platform + version is supported >>> for what I want to do with it. >> >> In case you were not aware of it: see the platform module. But you'll >> have >> to do the checks yourself (based on the info it returns). >> > Thanks for the reminder, it indeed slipped my mind. > > As Python features are luckily mostly platform independent, I am not > sure if a convenient 'platform requirement check' module would be worth > the energy creating it, any thoughts on that? > > For clarity purpose I re'added (and adapted) in what lines I was thinking: > - > test = RequirePlatform(do_not_raise=True) > # If do_not_raise is not set or False, an error will be raised > # after a failed require line, otherwise just continue. > > test.require(key='test1', platform='freebsd', version_min='2.2') > # If the platform is anything else but FreeBSD 2.2 onwards return False > # and store the result of the test. > # Result of the require (and any additional tests > # can be accessed using the index operators; > > if test['test1']: > print('supported') > - > Other requirements like architecture, python vm type/version, cpu > features, etc. Might also be nice to have. > It might be useful for up-front checking in those platform-specific scripts, although the platform module might already be fulfilling that need. From gundlach at gmail.com Thu Mar 11 18:16:36 2010 From: gundlach at gmail.com (gundlach) Date: Thu, 11 Mar 2010 15:16:36 -0800 (PST) Subject: pivot() equivalent Message-ID: I *know* this already exists, but I can't remember where: def pivot(func, seq): # I know, a good implementation shouldn't call func() twice per item return ( (x for x in seq if func(x)), (x for x in seq if not func(x)) ) I feel like I read a thread in which this was argued to death, and I can't find that either. The scenario: I have a sequence of lines from a file. I want to split it into those lines that contain a substring, and those that don't. I want it to be more efficient and prettier than with = [x for x in lines if substring in x] without = [x for x in lines if substring not in x] Does this exist? TIA, Michael From misceverything at gmail.com Thu Mar 11 18:19:36 2010 From: misceverything at gmail.com (T) Date: Thu, 11 Mar 2010 15:19:36 -0800 (PST) Subject: Parsing Email Headers References: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> Message-ID: <6e0f6857-bedd-4b23-81af-69dd06a53764@q15g2000yqj.googlegroups.com> Thanks for your suggestions! Here's what seems to be working - it's basically the same thing I originally had, but first checks to see if the line is blank response, lines, bytes = M.retr(i+1) # For each line in message for line in lines: if not line.strip(): M.dele(i+1) break emailMessage = email.message_from_string(line) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From") From alfps at start.no Thu Mar 11 18:22:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Mar 2010 00:22:02 +0100 Subject: inspect.stack() and frame In-Reply-To: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> Message-ID: * F?lix-Antoine Fortin: > Given this code : > # Experience with frame > import sys > import inspect > > def foo(): > stack = inspect.stack() > print "foo frame : " + str(hex(id(sys._getframe()))) hex returns a string. applying str is therefore redundant. > def foo2(): > inspect.stack() > print "foo2 frame : " + str(hex(id(sys._getframe()))) > > def bar(): > print "bar frame : " + str(hex(id(sys._getframe()))) > > foo() > foo() > > foo2() > foo2() > > bar() > bar() > > Output example : > foo frame : 0x84d2c0 > foo frame : 0x844bf0 > foo2 frame : 0x898c90 > foo2 frame : 0x898c90 > bar frame : 0x898f70 > bar frame : 0x898f70 > > Why are the ids (address) of the frame for each foo call not the same? You're dealing with Python objects. You're not dealing with the computer's machine stack. Whether you get the same id for two objects whose lifetimes don't overlap depends on the implementation's memory and id allocation strategy. > Or why the call to "stack = inspect.stack()" change the address of the > frame? Does it? Cheers, - Alf From python at rgbaz.eu Thu Mar 11 18:29:12 2010 From: python at rgbaz.eu (PythonAB) Date: Fri, 12 Mar 2010 00:29:12 +0100 Subject: Bluetooth In-Reply-To: <4B97B7F8.2030303@fedex.com> References: <4B97B7F8.2030303@fedex.com> Message-ID: <1ED82F61-E3E8-4A3A-8028-0F8D4B82E580@rgbaz.eu> On 10 mrt 2010, at 16:17, Jeff Peck wrote: > On 3/7/2010 1:26 PM, PythonAB wrote: >> >> Hello, >> >> >> I'm writing a script that has to connect a bluetooth device >> with a 3D application. >> On my search for a bluetooth module i ran into this: >> http://www.python.org/download/releases/2.4/notes/ >> where it says: >> "The socket module now supports Bluetooth sockets, >> if the system has " >> >> Yet I can't find anything at all in the socket manuals >> nor anywhere else on the site... >> >> Does the socket module really support Bluetooth out of the box? >> I've used socket before but never read anything about bluetooth... >> >> Maybe I need to get the bluetooth.h file, but i have no idea what I >> am supposed to do with it... >> >> Can anyone shed some light on this for me please? >> >> thanks in advance, >> >> gr >> Arno > > Have you come across the PyBluez library yet? I recently used it in a project and it worked very well. > > Hth, > Jeff Hi Jeff, Yes I ran into it, but couldn't find an OSX version... I'm using the lightblue module now but would have preferred to use the socket module without compiling python myself. Sorry for not mentioning the platform. gr Arno -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Thu Mar 11 18:39:12 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 11 Mar 2010 18:39:12 -0500 Subject: pivot() equivalent In-Reply-To: References: Message-ID: <4b997f06$0$5013$607ed4bc@cv.net> On 3/11/2010 6:16 PM, gundlach wrote: > I *know* this already exists, but I can't remember where: > > def pivot(func, seq): > # I know, a good implementation shouldn't call func() twice per item > return ( (x for x in seq if func(x)), (x for x in seq if not > func(x)) ) > > I feel like I read a thread in which this was argued to death, and I > can't find that either. > > The scenario: I have a sequence of lines from a file. I want to split > it into those lines that contain a substring, and those that don't. I > want it to be more efficient and prettier than > > with = [x for x in lines if substring in x] > without = [x for x in lines if substring not in x] > > Does this exist? > > TIA, > Michael Try this: > type lines.txt the quick brown fox jumps over the lazy dog > type pivot.py def pivot(pivot_function, filename): a_list = [] b_list = [] for line in open(filename): target_list = a_list if pivot_function(line) else b_list target_list.append(line[:-1]) return (a_list, b_list) print pivot(lambda line: 'e' in line, "lines.txt") > python pivot.py (['the', 'over', 'the'], ['quick', 'brown', 'fox', 'jumps', 'lazy', 'dog']) -John From python at mrabarnett.plus.com Thu Mar 11 18:50:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 23:50:13 +0000 Subject: pivot() equivalent In-Reply-To: References: Message-ID: <4B9981B5.4020005@mrabarnett.plus.com> gundlach wrote: > I *know* this already exists, but I can't remember where: > > def pivot(func, seq): > # I know, a good implementation shouldn't call func() twice per item > return ( (x for x in seq if func(x)), (x for x in seq if not > func(x)) ) > > I feel like I read a thread in which this was argued to death, and I > can't find that either. > > The scenario: I have a sequence of lines from a file. I want to split > it into those lines that contain a substring, and those that don't. I > want it to be more efficient and prettier than > > with = [x for x in lines if substring in x] > without = [x for x in lines if substring not in x] > > Does this exist? > The clearest way is just: def pivot(func, seq): with, without = [], [] for x in seq: if func(x): with.append(x) else: without.append(x) return with, without From felix.antoine.fortin at gmail.com Thu Mar 11 19:03:07 2010 From: felix.antoine.fortin at gmail.com (=?ISO-8859-1?Q?F=E9lix=2DAntoine_Fortin?=) Date: Thu, 11 Mar 2010 16:03:07 -0800 (PST) Subject: inspect.stack() and frame References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> Message-ID: <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> On Mar 11, 6:22?pm, "Alf P. Steinbach" wrote: > * F lix-Antoine Fortin: > > > Given this code : > > # Experience with frame > > import sys > > import inspect > > > def foo(): > > ? ? stack = inspect.stack() > > ? ? print "foo frame : " + str(hex(id(sys._getframe()))) > > hex returns a string. applying str is therefore redundant. > My bad. > > > > > > def foo2(): > > ? ? inspect.stack() > > ? ? print "foo2 frame : " + str(hex(id(sys._getframe()))) > > > def bar(): > > ? ? print "bar frame : " + str(hex(id(sys._getframe()))) > > > foo() > > foo() > > > foo2() > > foo2() > > > bar() > > bar() > > > Output example : > > foo frame : 0x84d2c0 > > foo frame : 0x844bf0 > > foo2 frame : 0x898c90 > > foo2 frame : 0x898c90 > > bar frame : 0x898f70 > > bar frame : 0x898f70 > > > Why are the ids (address) of the frame for each foo call not the same? > > You're dealing with Python objects. You're not dealing with the computer's > machine stack. Whether you get the same id for two objects whose lifetimes don't > overlap depends on the implementation's memory and id allocation strategy. > Okay, I thought I got that when I read the id documentation, but now I get it. So the only to compare two ids, is by making sure their lifetimes overlap. In this case, instead of keeping the ids, I have to keep a reference on the frame to make sure it is still alive when I will compare it with a second one. Thanks! > > Or why the call to "stack = inspect.stack()" change the address of the > > frame? > > Does it? > Yeah it does... I always get N different id when I run foo() N times in a row. Actually, what you said about lifetime applies here too. Here is another quick snippet : import sys import inspect def foo(): stack = inspect.stack() return sys._getframe() def foo2(): stack = inspect.stack() del stack return sys._getframe() def bar(): inspect.stack() return sys._getframe() frame_foo = foo() frame_foo2 = foo2() frame_bar = bar() print sys.getrefcount(frame_foo) print sys.getrefcount(frame_foo2) print sys.getrefcount(frame_bar) Output : 3 2 2 So it seems that there is one more reference to the foo frame because only because of "stack = inspect.stack()", so its lifetime isn't done contrary to foo2 and bar frame, and the frame id of a foo frame is different for each call. Now, what is keeping a reference on foo frame? Thanks Alf, Felix From gagsl-py2 at yahoo.com.ar Thu Mar 11 20:22:51 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Mar 2010 22:22:51 -0300 Subject: EOFError: EOF when reading a line References: Message-ID: En Thu, 11 Mar 2010 06:12:02 -0300, Mihir Patel escribi?: > I am trying to use the subprocess to send the data to child process. I > am not sure why i keep getting "EOFError: EOF when reading a line" > > command_line = 'python test_input.py' > p =subprocess.Popen(command_line, shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE) > print 'output:', p.communicate()[0] > > o,e = p.communicate('test') You may call communicate at most once. -- Gabriel Genellina From albert at spenarnc.xs4all.nl Thu Mar 11 20:33:12 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2010 01:33:12 GMT Subject: My four-yorkshireprogrammers contribution References: <20100224212303.242222c6@geekmail.INVALID> <7v9e3rFl7mU1@mid.individual.net> Message-ID: In article <7vdo8sFrelU1 at mid.individual.net>, Gregory Ewing wrote: >MRAB wrote: > >> By the standards of just a few years later, that's not so much a >> microcomputer as a nanocomputer! > >Although not quite as nano as another design published >in EA a couple of years earlier, the EDUC-8: > > http://www.sworld.com.au/steven/educ-8/ > >It had a *maximum* of 256 bytes -- due to the architecture, >there was no way of addressing any more. Also it was >divided into 16-byte pages, with indirect addressing >required to access anything in a different page from >the instruction. Programming for it must have been >rather challenging. > >As far as I know, the EDUC-8 is unique in being the >only computer design ever published in a hobby magazine >that *wasn't* based on a microprocessor -- it was all >built out of 9000 and 7400 series TTL logic chips! There was the 74 computer in Elektuur (now Elektor). That was a quite respectable computer, built (you guessed) from 74-series chips. How many were built, I don't know. > >-- >Greg Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From steve at holdenweb.com Thu Mar 11 20:43:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 20:43:44 -0500 Subject: file seek is slow In-Reply-To: <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> References: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> Message-ID: Metalone wrote: > I just tried the seek test with Cython. > Cython fseek() : 1.059 seconds. 30% slower than 'C' > Python f.seek : 1.458 secondds. 80% slower than 'C'. > > It is amazing to me that Cython generates a 'C' file that is 1478 > lines. > And what response are you seeking to your amazement? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From albert at spenarnc.xs4all.nl Thu Mar 11 20:49:47 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2010 01:49:47 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: In article , Grant Edwards wrote: >On 2010-03-03, Grant Edwards wrote: >> On 2010-03-03, Gregory Ewing wrote: >>> Grant Edwards wrote: >>> >>>> Just a mediocre copy of the CP/M filesystem, which was in turn >>>> copied from DEC's RSTS or RSX. >>> >>> It was actually an improvement over CP/M's file system. CP/M >>> didn't have hierarchical directories >> >> Neither did the original MS-DOS filesystem. >> >>> or timestamps and recorded file sizes in 128-byte blocks >>> rather than bytes. >> >> I thought that was true of the original MS-DOS filesystem as >> well, but I wouldn't bet money on it. > >I definitely remember that old MS-DOS programs would treat >Ctrl-Z as an EOF marker when it was read from a text file and >would terminate a text file with a Ctrl-Z when writing one. > >I don't know if that was because the underlying filesystem was >still did everything in blocks or if it was because those >MS-DOS programs were direct ports of CP/M programs. I would >have sworn that the orignal MS-DOS file API was FCB based and >worked almost exactly like CP/M. IIRC, the "byte stream" API >showed up (in the OS) sever versions later. The byte stream >API was implemented by many compiler vendor's C libraries on >top of the block-oriented FCB API. My programming reference manual for MSDOS 6.0 (1993) states the FCB stuff as "superseded" (not obsolete or obsolescent). It states: "A programmer should not use a superseded function except to maintain compatibility with versions of MS-DOS earlier than version 2.0." FCB did *not* support paths, but you could access the current directory. >-- >Grant Edwards grant.b.edwards Yow! I had a lease on an Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ldo at geek-central.gen.new_zealand Thu Mar 11 22:15:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Mar 2010 16:15:23 +1300 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4b947298$0$8836$c3e8da3@news.astraweb.com> Message-ID: In message , Dave Angel wrote: > However, if there's anything in there about how to derive the polynomial > algorithm from (a few) samples I missed it entirely. Given that CRC is all just a sequence of xor operations, what happens if you xor various pairs of CRCs together, wouldn?t that cancel out at least parts of the operations? From ldo at geek-central.gen.new_zealand Thu Mar 11 22:16:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Mar 2010 16:16:56 +1300 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: In message <7vlameF7goU1 at mid.individual.net>, Gregory Ewing wrote: > I'm going by the fact that the application reports a > "CRC mismatch" when it's wrong. I can't be sure that what > it calls a "CRC" is really a true CRC, but it's more than > a simple sum, because changing one bit in the file results > in a completely different value. They could be using a strong cryptographic hash and truncating it to 16 bits or something. In which case you?ve got your work cut out for you... From steve at REMOVE-THIS-cybersource.com.au Thu Mar 11 22:24:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 03:24:39 GMT Subject: Can't define __call__ within __init__? References: Message-ID: <4b99b3f7$0$27822$c3e8da3@news.astraweb.com> On Thu, 11 Mar 2010 08:20:14 -0800, Steve Howell wrote: >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. >> >> > Are you sure about that? This program prints 1, 2, 1, 2. The rules for classic classes are different. Since classic classes have gone away in 3.0, and are becoming rarer in 2.x, I didn't bother to mention the complication. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Mar 11 22:30:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 03:30:02 GMT Subject: Can't define __call__ within __init__? References: Message-ID: <4b99b53a$0$27822$c3e8da3@news.astraweb.com> On Thu, 11 Mar 2010 07:56:59 -0500, Neal Becker wrote: > The example I showed was just a toy problem. The real problem is I > expect to call a function many times, and I want to avoid the overhead > of the 'if blah' everytime. Unless the __call__ methods are very small, the overhead of one extra if and one extra attribute lookup will be insignificant. -- Steven From lin.jianying at hotmail.com Thu Mar 11 22:55:13 2010 From: lin.jianying at hotmail.com (marrylin) Date: Thu, 11 Mar 2010 19:55:13 -0800 (PST) Subject: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! Message-ID: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://steezeclothing.com ==== Air jordan(1-24)shoes $33 UGG BOOT $50 Nike shox(R4,NZ,OZ,TL1,TL2,TL3) $35 Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 FREE SHIPPING From python at bdurham.com Fri Mar 12 00:41:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 12 Mar 2010 00:41:16 -0500 Subject: Any downsides to UPX-ing my 32-bit Python 2.6.4 EXE/PYD/DLL files? Message-ID: <1268372476.27561.1364429171@webmail.messagingengine.com> Are there any downsides to UPX-ing my 32-bit Python 2.6.4 development environment EXE/PYD/DLL files? The reason I'm asking is that I frequently use a custom PY2EXE script that UPX's copies of these files on every build. Yes, I could get fancy and try to cache UPXed files, but I think a simpler, safer, and higher performance solution would be for me to just UPX my Python 2.6.4 directory once and be done with it. What are your thoughts? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Fri Mar 12 00:48:52 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 06:48:52 +0100 Subject: sqlite3 is sqlite 2? Message-ID: <4B99D5C4.8070100@shopzeus.com> gandalf at ubuntu:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3.version '2.4.1' Is it possible to install a real sqlite version 3 somehow? I really need it because I have to use savepoint/rollback to. That is only supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know that is not a question about Python itself. But still, it is interesting that a module named "sqlite3" can actually be used for something called "sqlite 2". Thanks Laszlo From pmaupin at gmail.com Fri Mar 12 01:02:54 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Fri, 12 Mar 2010 00:02:54 -0600 Subject: ANNOUNCE: RSON v 0.02 available Message-ID: RSON (Readable Serial Object Notation) is a superset of JSON that is suitable for files that humans have to edit and diff. The current release is decoder-only, but the decoder will read files encoded by JSON encoders such as json or simplejson. The current release consists of a single Python module and a short manual. The manual admittedly needs some work, but has a few syntax examples. http://code.google.com/p/rson/ From gagsl-py2 at yahoo.com.ar Fri Mar 12 01:11:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Mar 2010 03:11:44 -0300 Subject: inspect.stack() and frame References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> Message-ID: En Thu, 11 Mar 2010 21:03:07 -0300, F?lix-Antoine Fortin escribi?: > On Mar 11, 6:22 pm, "Alf P. Steinbach" wrote: >> * F lix-Antoine Fortin: >> >> > Given this code : >> > # Experience with frame >> > import sys >> > import inspect >> >> > def foo(): >> > stack = inspect.stack() >> > print "foo frame : " + str(hex(id(sys._getframe()))) >> >> > def foo2(): >> > inspect.stack() >> > print "foo2 frame : " + str(hex(id(sys._getframe()))) >> >> > def bar(): >> > print "bar frame : " + str(hex(id(sys._getframe()))) >> >> > foo() >> > foo() >> >> > foo2() >> > foo2() >> >> > bar() >> > bar() >> >> > Output example : >> > foo frame : 0x84d2c0 >> > foo frame : 0x844bf0 >> > foo2 frame : 0x898c90 >> > foo2 frame : 0x898c90 >> > bar frame : 0x898f70 >> > bar frame : 0x898f70 >> >> > Why are the ids (address) of the frame for each foo call not the same? >> >> You're dealing with Python objects. You're not dealing with the >> computer's >> machine stack. Whether you get the same id for two objects whose >> lifetimes don't >> overlap depends on the implementation's memory and id allocation >> strategy. >> > > Okay, I thought I got that when I read the id documentation, but now I > get it. > So the only to compare two ids, is by making sure their lifetimes > overlap. In > this case, instead of keeping the ids, I have to keep a reference on > the frame > to make sure it is still alive when I will compare it with a second > one. The best way to compare object identities is using the 'is' operator: `a is b` returns true if and only if after evaluating both operands they are the very same object. id() may be misleading if you are not careful: py> id([]) == id([]) True py> [] is [] False >> > Or why the call to "stack = inspect.stack()" change the address of the >> > frame? >> >> Does it? > > Yeah it does... I always get N different id when I run foo() N times > in a row. Think again after reading the response below. > Actually, what you said about lifetime applies here too. Here is > another quick > snippet : > > import sys > import inspect > > def foo(): > stack = inspect.stack() > return sys._getframe() > > def foo2(): > stack = inspect.stack() > del stack > return sys._getframe() > > def bar(): > inspect.stack() > return sys._getframe() > > frame_foo = foo() > frame_foo2 = foo2() > frame_bar = bar() > > print sys.getrefcount(frame_foo) > print sys.getrefcount(frame_foo2) > print sys.getrefcount(frame_bar) > > Output : > 3 > 2 > 2 > > So it seems that there is one more reference to the foo frame because > only because of "stack = inspect.stack()", so its lifetime isn't done > contrary to foo2 and bar frame, and the frame id of a foo frame is > different for each call. > > Now, what is keeping a reference on foo frame? The foo frame keeps a reference to the 'stack' local variable (in its f_locals attribute), and 'stack' keeps a reference to the current frame too. This doesn't happen neither in foo2() nor bar(), where the local array is empty. inspect.stack() isn't special: any other reference to the current frame would have the same effect. Let's examine the simple example above: py> id([]) == id([]) True Python creates an empty list, takes its id, and discards the list. The list object is then ready to be re-used again (the interpreter keeps a list of free objects for many common types), so the right-hand side gets the very same list. The same thing happens with the frame object in your first examples foo2() and bar(): the frame object is discarded after leaving the function, and is ready to be used again in the next call. But foo() creates a circular reference - the frame object is still alive after leaving the first call, so the second call must use a new frame. (The garbage collector will, eventually, break the cycle and free those objects, but not very soon). -- Gabriel Genellina From enleverLesX_XXmcX at XmclavXeauX.com.invalid Fri Mar 12 01:32:13 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 12 Mar 2010 07:32:13 +0100 Subject: bypass UAC control through python script (to be run from batchfile) References: <26028cd0-8ead-47d0-95d8-09e2214dddd3@e7g2000yqf.googlegroups.com> Message-ID: <4b99dff5$0$17899$ba4acef3@reader.news.orange.fr> Hi ! Install a resident soff (script) by task-planified, in Administrator rights. Then, call this script from current work, for bypass UAC. @-salutations -- Michel Claveau From gandalf at shopzeus.com Fri Mar 12 01:46:48 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 07:46:48 +0100 Subject: sqlite savepoint problem (was: Re: sqlite3 is sqlite 2?) In-Reply-To: <87bpeqzmmv.fsf@castleamber.com> References: <87bpeqzmmv.fsf@castleamber.com> Message-ID: <4B99E358.4020507@shopzeus.com> > > That's the sqlite *bindings* version: > > >>> sqlite3.version > '2.4.1' > >>> sqlite3.sqlite_version > '3.6.16' > >>> Thanks. I tried it and RELEASE command didn't work: >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> with conn: ... conn.execute("BEGIN") ... conn.execute("create table a ( i integer)") ... conn.execute("insert into a values (1)") ... conn.execute("savepoint sp1") ... conn.execute("insert into a values(2)") ... conn.execute("release sp1") ... conn.execute("COMMIT") ... Traceback (most recent call last): File "", line 7, in sqlite3.OperationalError: no such savepoint: sp1 >>> The syntax is correct: http://www.sqlite.org/lang_savepoint.html The savepoint was really created. But I get this error, telling "no such savepoint". What is wrong here? Maybe it has to do something with transaction isolation? :-s Thank you Laszlo From agoretoy at gmail.com Fri Mar 12 01:52:15 2010 From: agoretoy at gmail.com (alex goretoy) Date: Fri, 12 Mar 2010 00:52:15 -0600 Subject: execute bash builtins in python Message-ID: hi, i'm trying to write a section of my program that needs to run bash builtin alias and declare, i've googled and tried every type of example i could find no to avail. this is what I've tried below and it doesn't work, is there a way for me to execute a bah builin from python? what i need is to take alias output and pipe it to another command with python and return the results to a string or list. >>> p1=Popen(["alias"],stdout=PIPE) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/subprocess.py", line 621, in __init__ errread, errwrite) File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory if i add shell=True i get empty string and no thins error message >>> p1=Popen(["alias"],stdout=PIPE,shell=True) >>> p1 >>> p1.stdout.read() '' thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at riddergarn.dk Fri Mar 12 02:11:20 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 07:11:20 +0000 Subject: Threading, Queue for a function so it only runs once at a time. Message-ID: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> Hi, Im programming a simple webcrawler with threading for the fun of it, which is inserting the data fetch into a mysql database, but after continuously cause my mysql server to produce error during database queries (i assume its cause because of the many execution at the same time.) the scipt produces errors. I figured out i need some kind of queue for the function i use to insert into the database, to make sure its only called once at a time. I have looked at the Queue module but its for more complicated than my current python skills can cope with. :) Would somebody please help me out here? Thanks. -- John P. From zookog at gmail.com Fri Mar 12 02:11:37 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Fri, 12 Mar 2010 00:11:37 -0700 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes Message-ID: Folks: Every couple of years I run into a problem where some Python code that worked well at small scales starts burning up my CPU at larger scales, and the underlying issue turns out to be the idiom of accumulating data by string concatenation. It just happened again (http://foolscap.lothar.com/trac/ticket/149 ), and as usual it is hard to make the data accumulator efficient without introducing a bunch of bugs into the surrounding code. So this time around I decided to try encapsulating my preferred more efficient idiom into a reusable class. So I present to you StringChain, which is an efficient way to accumulate and process data in many chunks: http://tahoe-lafs.org/trac/stringchain Here are some benchmarks generated by running python -OOu -c 'from stringchain.bench import bench; bench.quick_bench()' as instructed by the README.txt file. The N: in the left-hand column is how many bytes were in the test dataset. The ave rate: number in the right-hand column is how many bytes per second were processed. "naive" means the string-based idiom sketched above and "strch" means using the StringChain class. _buildup init_naive N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 890, ave rate: 58350579 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 265, ave rate: 34800398 N: 262144, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 79, ave rate: 20745346 N: 524288, time: best: 0.05, 2th-best: 0.05, ave: 0.05, 2th-worst: 0.05, worst: 0.05 (of 5), reps/s: 20, ave rate: 10823850 _buildup init_strch N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 25543, ave rate: 1674043282 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 14179, ave rate: 1858538925 N: 262144, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 8016, ave rate: 2101513050 N: 524288, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 4108, ave rate: 2154215572 _consume init_naive_loaded N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 931, ave rate: 61037862 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 270, ave rate: 35454393 N: 262144, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 74, ave rate: 19471963 N: 524288, time: best: 0.05, 2th-best: 0.05, ave: 0.05, 2th-worst: 0.05, worst: 0.06 (of 5), reps/s: 19, ave rate: 10146747 _consume init_strch_loaded N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 4309, ave rate: 282447500 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 2313, ave rate: 303263357 N: 262144, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 1186, ave rate: 311159052 N: 524288, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 606, ave rate: 317814669 _randomy init_naive N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 479, ave rate: 31450561 N: 131072, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 140, ave rate: 18461191 N: 262144, time: best: 0.02, 2th-best: 0.02, ave: 0.02, 2th-worst: 0.03, worst: 0.03 (of 5), reps/s: 42, ave rate: 11127714 N: 524288, time: best: 0.06, 2th-best: 0.07, ave: 0.08, 2th-worst: 0.08, worst: 0.09 (of 5), reps/s: 13, ave rate: 6906341 _randomy init_strch N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 973, ave rate: 63827127 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 495, ave rate: 64970669 N: 262144, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 239, ave rate: 62913360 N: 524288, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 121, ave rate: 63811569 The naive approach is slower than the StringChain class, and the bigger the dataset the slower it goes. The StringChain class is fast and also it is scalable (with regard to these benchmarks at least...). Thanks! Regards, Zooko From no.email at nospam.invalid Fri Mar 12 02:20:08 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Mar 2010 23:20:08 -0800 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: Message-ID: <7xd3za6m6v.fsf@ruckus.brouhaha.com> "Zooko O'Whielacronx" writes: > Every couple of years I run into a problem where some Python code that > worked well at small scales starts burning up my CPU at larger scales, > and the underlying issue turns out to be the idiom of accumulating > data by string concatenation. I usually use StringIO or cStringIO for that (python 2.x syntax): buf = cStringIO() buf.write("first thing") buf.write("second thing") result = buf.getvalue() Sometimes I like to use a generator instead: def stuff(): yield "first thing" yield "second thing" result = ''.join(stuff()) From martin at v.loewis.de Fri Mar 12 02:31:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 12 Mar 2010 08:31:42 +0100 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> References: <4B992FB5.8090207@v.loewis.de> <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> Message-ID: <4B99EDDE.5070604@v.loewis.de> > I?m sorry everyone. I didn?t realise I had installed the 64-bit > version of Python. Well, at least someone else might find have the > same problem. But I think that there is going to be a bit of a rough > patch as everyone moves over to 64-bit. Expect that move to take a few more years. 64-bit CPUs were introduced more than ten years ago (e.g. Alpha, in 1992), and only slowly reach "the masses". People typically still don't have more than 4GiB of memory in their desktop PCs or laptops, so users who do install 64-bit operating systems on such hardware are still early adaptors. Regards, Martin From gandalf at shopzeus.com Fri Mar 12 02:32:21 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 08:32:21 +0100 Subject: sqlite savepoint problem In-Reply-To: <1268600658.2846.17.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> Message-ID: <4B99EE05.8060505@shopzeus.com> > From memory you can't issue a "CREATE TABLE" statement inside a > transaction, at least not at the default isolation level. Such a > statement will automatically commit the current transaction. Doesn't > help with your current problem but worth pointing out :-) > Thank you. I'll keep in mind. > When debugging strange transaction behaviour, I find it easiest to > create the connection with isolation_level=None so that are no implicit > transactions being created behind your back. Not sure why, but setting > this makes your example work for me. > Yes, same for me. But setting it to None means auto commit mode! See here: http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions But it does not work that way. Look at this example import sqlite3 conn = sqlite3.connect(':memory:') conn.isolation_level = None with conn: conn.execute("create table a ( i integer ) ") with conn: conn.execute("insert into a values (1)") conn.execute("SAVEPOINT sp1") conn.execute("insert into a values (2)") conn.execute("SAVEPOINT sp2") conn.execute("insert into a values (3)") conn.execute("ROLLBACK TO sp2") conn.execute("insert into a values (4)") conn.execute("RELEASE sp1") with conn: for row in conn.execute("select * from a"): print row It prints: (1,) (2,) (4,) So everything is working. Nothing is auto commited. But if I change it to "DEFERRED" or "IMMEDIATE" or "EXCLUSIVE" then it won't work. Why? I'm now confused. Also, I could not find anything about these isolation levels on the sqlite website. The only think I could find is "PRAGMA read_uncommited". If that is the same as setting isolation_level to None, then I don't want it. L From gandalf at shopzeus.com Fri Mar 12 02:48:33 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 08:48:33 +0100 Subject: sqlite savepoint problem In-Reply-To: <4B99EE05.8060505@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> Message-ID: <4B99F1D1.2070202@shopzeus.com> > > I'm now confused. Also, I could not find anything about these > isolation levels on the sqlite website. The only think I could find is > "PRAGMA read_uncommited". If that is the same as setting > isolation_level to None, then I don't want it. Yes, it is. Here is a test: import os import sqlite3 import threading import time FPATH = '/tmp/test.sqlite' if os.path.isfile(FPATH): os.unlink(FPATH) def getconn(): global FPATH conn = sqlite3.connect(FPATH) conn.isolation_level = None return conn class Thr1(threading.Thread): def run(self): conn = getconn() print "Thr1: Inserting 0,1,2,3,4,5" with conn: for i in range(6): conn.execute("insert into a values (?)",[i]) print "Thr1: Commited" with conn: print "Thr1: Selecting all rows:" for row in conn.execute("select * from a"): print row print "Thr1: Wait some..." time.sleep(3) print "Thr1: Selecting again, in the same transaction" for row in conn.execute("select * from a"): print row class Thr2(threading.Thread): def run(self): conn = getconn() with conn: print "Thr2: deleting all rows from a" conn.execute("delete from a") print "Thr2: Now we wait some BEFORE commiting changes." time.sleep(3) print "Thr2: Will roll back!" raise Exception def main(): with getconn() as conn: conn.execute("create table a ( i integer ) ") thr1 = Thr1() thr1.start() time.sleep(1) thr1 = Thr2() thr1.start() main() And the test result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction Thr2: Will roll back! Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "test.py", line 44, in run raise Exception Exception It means that setting isolation_level to None will really allow uncommited changes to be read by other transactions! This is sad, and of course this is something that I do not want. If I change it to DEFERRED then I get a correct result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction (0,) (1,) (2,) (3,) (4,) (5,) Thr2: Will roll back! However, then savepoints won't work. Is there any way to use read commited (or higher) isolation level, and have savepoints working at the same time? I don't see how would savepoints be useful without at least read commited isolation level. :-( L From dr.cg at 126.com Fri Mar 12 02:51:11 2010 From: dr.cg at 126.com (CHEN Guang) Date: Fri, 12 Mar 2010 15:51:11 +0800 (CST) Subject: file seek is slow Message-ID: <61ca1c62.17647.127515b0539.Coremail.dr.cg@126.com> Metalone wrote: > I just tried the seek test with Cython. > Cython fseek() : 1.059 seconds. 30% slower than 'C' > Python f.seek : 1.458 secondds. 80% slower than 'C'. > > It is amazing to me that Cython generates a 'C' file that is 1478 > lines. > PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. PythoidC is the C language like the Python, by the Python and for the Python. CHEN Guang -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Mar 12 03:15:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Mar 2010 09:15:09 +0100 Subject: file seek is slow In-Reply-To: <61ca1c62.17647.127515b0539.Coremail.dr.cg@126.com> References: <61ca1c62.17647.127515b0539.Coremail.dr.cg@126.com> Message-ID: CHEN Guang, 12.03.2010 08:51: > Metalone wrote: >> I just tried the seek test with Cython. >> Cython fseek() : 1.059 seconds. 30% slower than 'C' >> Python f.seek : 1.458 secondds. 80% slower than 'C'. >> >> It is amazing to me that Cython generates a 'C' file that is 1478 >> lines. > > PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. > PythoidC is the C language like the Python, by the Python and for the Python. Except that it's not a language but rather a syntax converter, i.e. it doesn't really add any features to the C language but rather restricts Python syntax to C language features (plus a bit of header file introspection, it seems, but C's preprocessor has a bit of that, too). Stefan From gandalf at shopzeus.com Fri Mar 12 03:35:27 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 09:35:27 +0100 Subject: sqlite savepoint problem [solved] In-Reply-To: <1268604831.2846.23.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> <1268604831.2846.23.camel@durian> Message-ID: <4B99FCCF.5080506@shopzeus.com> > No it doesn't. The problem is that using a connection as a context > manager doesn't do what you think. > > It does *not* start a new transaction on __enter__ and commit it on > __exit__. As far as I can tell it does nothing on __enter__ and calls > con.commit() or con.rollback() on exit. With isolation_level=None, > these are no-ops. > Thank you Ryan! You are abolutely right, and thank you for reading the source. Now everything works as I imagined. The way the context manager and isolation_level works looks very very strange to me. Here is a demonstration: import sqlite3 def getconn(): conn = sqlite3.connect(':memory:') conn.isolation_level = None return conn def main(): with getconn() as conn: conn.execute("create table a ( i integer ) ") try: conn.execute("insert into a values (1)") with conn: conn.execute("insert into a values (2)") raise Exception except: print "There was an error" for row in conn.execute("select * from a"): print row main() Output: There was an error (1,) (2,) Looks like the context manager did not roll back anything. If I remove isolation_level=None then I get this: There was an error E.g. the context manager rolled back something that was executed outside the context. I cannot argue with the implementation - it is that way. But this is not what I would expect. I believe I'm not alone with this. Using your connection manager, everything is perfect: There was an error (1,) The only thing I have left is to implement a connection manager that emulates nested transactions, using a stack of savepoints. :-) Suggestions: Just for clarity, we should put a comment at the end of the documentation here: http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions I would add at least these things: #1. By using isolation_level = None, connection objects (used as a context manager) WON'T automatically commit or rollback transactions. #2. Using any isolation level, connection objects WON'T automatically begin a transaction. #3. Possibly, include your connection manager class code, to show how to do it "the expected" way. Also one should clarify in the documentation, what isolation_level does. Looks like setting isolation_level to None is not really an "auto commit mode". It is not even part of sqlite itself. It is part of the python extension. Thank you again. Laszlo From steve at REMOVE-THIS-cybersource.com.au Fri Mar 12 03:52:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 08:52:30 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: Message-ID: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> On Fri, 12 Mar 2010 00:11:37 -0700, Zooko O'Whielacronx wrote: > Folks: > > Every couple of years I run into a problem where some Python code that > worked well at small scales starts burning up my CPU at larger scales, > and the underlying issue turns out to be the idiom of accumulating data > by string concatenation. I don't mean to discourage you, but the simple way to avoid that is not to accumulate data by string concatenation. The usual Python idiom is to append substrings to a list, then once, at the very end, combine into a single string: accumulator = [] for item in sequence: accumulator.append(process(item)) string = ''.join(accumulator) > It just happened again > (http://foolscap.lothar.com/trac/ticket/149 ), and as usual it is hard > to make the data accumulator efficient without introducing a bunch of > bugs into the surrounding code. I'm sorry, I don't agree about that at all. I've never come across a situation where I wanted to use string concatenation and couldn't easily modify it to use the list idiom above. [...] > Here are some benchmarks generated by running python -OOu -c 'from > stringchain.bench import bench; bench.quick_bench()' as instructed by > the README.txt file. To be taken seriously, I think you need to compare stringchain to the list idiom. If your benchmarks favourably compare to that, then it might be worthwhile. -- Steven From stefan_ml at behnel.de Fri Mar 12 03:56:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Mar 2010 09:56:00 +0100 Subject: file seek is slow In-Reply-To: <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> References: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> Message-ID: Metalone, 11.03.2010 23:57: > I just tried the seek test with Cython. > Cython fseek() : 1.059 seconds. 30% slower than 'C' > Python f.seek : 1.458 secondds. 80% slower than 'C'. > > It is amazing to me that Cython generates a 'C' file that is 1478 > lines. Well, it generated an optimised Python interface for your module and made it compilable in CPython 2.3 through 3.2. It doesn't look like your C module features that. ;) > #Cython code > > import time > > cdef int SEEK_SET = 0 > > cdef extern from "stdio.h": > void* fopen(char* filename, char* mode) > int fseek(void*, long, int) Cython ships with a stdio.pxd that you can cimport. It looks like it doesn't currently define fseek(), but it defines at least fopen() and FILE. Patches are always welcome. > def main(): > cdef void* f1 = fopen('video.txt', 'rb') > cdef int i=1000000 > t0 = time.clock() > while i> 0: > fseek(f1, 0, SEEK_SET) > i -= 1 > delta = time.clock() - t0 Note that the call to time.clock() takes some time, too, so it's not surprising that this is slower than hand-written C code. Did you test how it scales? Also, did you look at the generated C code or the annotated Cython code (cython -a)? Did you make sure both were compiled with the same CFLAGS? Also, any reason you're not using a for-in-xrange loop? It shouldn't make a difference in speed, it's just more common. You even used a for loop in your C code. Finally, I'm not sure why you think that these 30% matter at all. In your original post, you even state that seek-time isn't the "deal breaker", so maybe you should concentrate on the real issues? Stefan From neo100110 at gmail.com Fri Mar 12 03:59:19 2010 From: neo100110 at gmail.com (Neo) Date: Fri, 12 Mar 2010 00:59:19 -0800 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: I have learned java for half a year and now I want to learn Python, should I learn python 3k or the traditional version? On Wed, Mar 10, 2010 at 7:19 AM, kj wrote: > > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rizwanahmed24 at gmail.com Fri Mar 12 04:00:48 2010 From: rizwanahmed24 at gmail.com (rizwanahmed24 at gmail.com) Date: Fri, 12 Mar 2010 01:00:48 -0800 (PST) Subject: bypass UAC control through python script (to be run from batchfile) References: <26028cd0-8ead-47d0-95d8-09e2214dddd3@e7g2000yqf.googlegroups.com> <4b99dff5$0$17899$ba4acef3@reader.news.orange.fr> Message-ID: <2351c608-2ad5-4835-a4cb-068f6646ede0@k17g2000yqb.googlegroups.com> Hi Michel. what is this 'resident soff' script, i cannot find it on google. Secondly if i was to install something in admin mode, then i would have installed the application i want to install. The actual problem is that i dont want to manually run something with admin rights and install. still havent got the solution From jgardner at jonathangardner.net Fri Mar 12 04:05:27 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 12 Mar 2010 01:05:27 -0800 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> On Wed, Mar 3, 2010 at 2:41 PM, Avid Fan wrote: > Jonathan Gardner wrote: >> >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is understood well enough that the >> general nature of the SQL database is unnecessary. >> > > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the query > language? > > Could you give some sort of example of where SQL would not be the way to go. > ? The only things I can think of a simple flat file databases. Sorry for the late reply. Let's say you have an application that does some inserts and updates and such. Eventually, you are going to run into a limitation with the number of inserts and updates you can do at once. The typical solution to this is to shard your database. However, there are other solutions, such as storing the files in a different kind of database, one which is less general but more efficient for your particular data. Let me give you an example. I worked on a system that would load recipients for email campaigns into a database table. The SQL database was nice during the initial design and prototype stage because we could quickly adjust the tables to add or remove columns and try out different designs.. However, once our system got popular, the limitation was how fast we could load recipients into the database. Rather than make our DB bigger or shard the data, we discovered that storing the recipients outside of the database in flat files was the precise solution we needed. Each file represented a different email campaign. The nature of the data was that we didn't need random access, just serial access. Storing the data this way also meant sharding the data was almost trivial. Now, we can load a massive number of recipients in parallel. You are going to discover certain patterns in how your data is used and those patterns may not be best served by a generic relational database. The relational database will definitely help you discover and even experiment with these patterns, but eventually, you will find its limits. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Fri Mar 12 04:14:26 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 12 Mar 2010 01:14:26 -0800 Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: <6cc20cea1003120114s44ed833fmf82c06edc7d47ca0@mail.gmail.com> On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: > > And even when we've had volunteers, hardly anyone shows up! > > Any suggestions would be appreciated. > Two things: One, only you and your friend really care. Let that sink in. No one is going to carry the group but you two, at least initially. Two, there's a lot of people at movie theaters and the county fair. Why? Because it is interesting and fun. Scientists work the same way. Yes, a lot of people are interested in Python. Why don't you do a bit of snooping around and see what people want to know about? Let me give some examples: * Interactive numeric programming with Python * Rapid website development with Pylons (Trust me, everyone wants to make a website.) Show how you are showing off data from one of your experiments of projects and how easy it is to organize and manage data. * How you used Python on your latest and greatest project Don't expect the audience to participate, except to show up and ask questions. If you want to build a Python support group, then form an informal group with your friends. Start a public mailing list and offer Python advice and support for free. Integrate whatever code your org has with Python, and manage and maintain that code so others can use it. Finally, advertise. The more people see "Python", the more they will be interested. Coca-cola and Pepsi are really good at this! -- Jonathan Gardner jgardner at jonathangardner.net From gandalf at shopzeus.com Fri Mar 12 05:12:39 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 11:12:39 +0100 Subject: sqlite savepoint problem [solved] In-Reply-To: <1268639629.2846.48.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> <1268604831.2846.23.camel@durian> <4B99FCCF.5080506@shopzeus.com> <1268639629.2846.48.camel@durian> Message-ID: <4B9A1397.4010409@shopzeus.com> >> #1. By using isolation_level = None, connection objects (used as a >> context manager) WON'T automatically commit or rollback transactions. >> #2. Using any isolation level, connection objects WON'T automatically >> begin a transaction. >> #3. Possibly, include your connection manager class code, to show how to >> do it "the expected" way. >> >> Also one should clarify in the documentation, what isolation_level does. >> Looks like setting isolation_level to None is not really an "auto commit >> mode". It is not even part of sqlite itself. It is part of the python >> extension. >> > > I think of it as almost the opposite - you have to set > isolation_level=None to get the unadulterated behaviour of the > underlying sqlite library. > > I'm sure the devs would appreciate a documentation patch (submission > details at http://python.org/dev/patches/). I'm also pretty confident > that I won't have time to do one up anytime soon :-) > Patch submitted. http://bugs.python.org/issue8145 From robin at reportlab.com Fri Mar 12 05:16:44 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 10:16:44 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> References: <4B992FB5.8090207@v.loewis.de> <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> Message-ID: <4B9A148C.7050707@chamonix.reportlab.co.uk> Following the information from MvL I will try and get the 2.6 pyds built for amd64, I see that there's a cross platform compile technique for distutils, but am not sure if it applies to bdist_winexe etc etc. I'll have a go at this next week. -- Robin Becker From greg.ewing at canterbury.ac.nz Fri Mar 12 06:24:31 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Mar 2010 00:24:31 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: <7vum06Fj82U1@mid.individual.net> Lawrence D'Oliveiro wrote: > They could be using a strong cryptographic hash and truncating it to 16 bits > or something. > > In which case you?ve got your work cut out for you... Nope, I've determined that it's actually a pretty standard CRC, and it's even using one of the standard polynomials, 0x8005. I'll explain the details of how I figured that out in my essay. What confused me initially is that it seems to be adding a few extra bytes to the checked data that aren't present in the file. Figuring out what they're supposed to contain is proving to be quite a headache... -- Greg From news1234 at free.fr Fri Mar 12 06:39:50 2010 From: news1234 at free.fr (News123) Date: Fri, 12 Mar 2010 12:39:50 +0100 Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: <4b9a2806$0$22047$426a74cc@news.free.fr> Jonathan Gardner wrote: > On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: >> And even when we've had volunteers, hardly anyone shows up! >> >> Any suggestions would be appreciated. >> > > Two things: One, only you and your friend really care. Let that sink > in. No one is going to carry the group but you two, at least > initially. > > Two, there's a lot of people at movie theaters and the county fair. > Why? Because it is interesting and fun. Scientists work the same way. > Yes, a lot of people are interested in Python. Why don't you do a bit > of snooping around and see what people want to know about? > > Let me give some examples: > > * Interactive numeric programming with Python > * Rapid website development with Pylons (Trust me, everyone wants to > make a website.) Show how you are showing off data from one of your > experiments of projects and how easy it is to organize and manage > data. > * How you used Python on your latest and greatest project > > Don't expect the audience to participate, except to show up and ask questions. > > If you want to build a Python support group, then form an informal > group with your friends. Start a public mailing list and offer Python > advice and support for free. Integrate whatever code your org has with > Python, and manage and maintain that code so others can use it. > > Finally, advertise. The more people see "Python", the more they will > be interested. Coca-cola and Pepsi are really good at this! > attendance will be very low and be sure nobody cares to check whether anything happened on this group. My suggestion is: I'd suggest to setup a group, to which one can subscribe with mail notification and for all the old ones perhaps even via nntp ;-) and of course via a web front end (though I personally hate web groups) Afterwards you can 'friendly-fore-subscribe' some collegues. ;-) Just talk about your new cool group during lunch, etc. Be sure, that most will be to lazy to unsuscribe. Start discussing interesting topics on this group and then . . . maybe others start joining. maybo nobody cares and you have just to accept it. bye N From robin at reportlab.com Fri Mar 12 06:40:00 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 11:40:00 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B992FB5.8090207@v.loewis.de> References: <4B992FB5.8090207@v.loewis.de> Message-ID: <4B9A2810.9030602@chamonix.reportlab.co.uk> On 11/03/2010 18:00, Martin v. Loewis wrote: > >>> I have a Windows 7 (64bit AMD) machine ...... > >> Perhaps some expert on the python list knows which versions of VS >> support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set >> up a 64bit machine to see if they will install on a 64bit architecture. > > For Python 2.6 and later, use VS 2008. This comes with an AMD64 > compiler. You technically don't need a 64-bit Windows, as it supports > cross-compilation (but you would need a 64-bit Windows to test it). > > I personally build Python on a 32-bit machine, and move the MSI to a > 64-bit machine for testing. > OK I've got the VC2008 64bit tools installed on my 32bit build platform, but I'm getting build errors because of missing libraries. I assume that's because I don't have the python amd64 runtime libraries/dlls etc etc since the errors are looking like this _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FindMethod referenced in function Box_getattr _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Init referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Malloc referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyList_Type referenced in function BoxList_init _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FatalError referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Ready referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Type referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyModule_AddObject referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyErr_NewException referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_InitModule4_64 referenced in function init_rl_accel build\lib.win-amd64-2.6\_rl_accel.pyd : fatal error LNK1120: 69 unresolved externals I assume I can get those from a working Python amd64 install and stuff on one of the compiler paths somehow. -- Robin Becker From robin at reportlab.com Fri Mar 12 06:40:00 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 11:40:00 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B992FB5.8090207@v.loewis.de> References: <4B992FB5.8090207@v.loewis.de> Message-ID: <4B9A2810.9030602@chamonix.reportlab.co.uk> On 11/03/2010 18:00, Martin v. Loewis wrote: > >>> I have a Windows 7 (64bit AMD) machine ...... > >> Perhaps some expert on the python list knows which versions of VS >> support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set >> up a 64bit machine to see if they will install on a 64bit architecture. > > For Python 2.6 and later, use VS 2008. This comes with an AMD64 > compiler. You technically don't need a 64-bit Windows, as it supports > cross-compilation (but you would need a 64-bit Windows to test it). > > I personally build Python on a 32-bit machine, and move the MSI to a > 64-bit machine for testing. > OK I've got the VC2008 64bit tools installed on my 32bit build platform, but I'm getting build errors because of missing libraries. I assume that's because I don't have the python amd64 runtime libraries/dlls etc etc since the errors are looking like this _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FindMethod referenced in function Box_getattr _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Init referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Malloc referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyList_Type referenced in function BoxList_init _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FatalError referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Ready referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Type referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyModule_AddObject referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyErr_NewException referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_InitModule4_64 referenced in function init_rl_accel build\lib.win-amd64-2.6\_rl_accel.pyd : fatal error LNK1120: 69 unresolved externals I assume I can get those from a working Python amd64 install and stuff on one of the compiler paths somehow. -- Robin Becker From news1234 at free.fr Fri Mar 12 06:44:27 2010 From: news1234 at free.fr (News123) Date: Fri, 12 Mar 2010 12:44:27 +0100 Subject: show image in python In-Reply-To: References: Message-ID: <4b9a291b$0$21425$426a74cc@news.free.fr> Philip Semanchuk wrote: > > On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote: > >> Hey, This is my program >> >> 18 def Creeimg(): >> 19 """transforme matrice en image""" >> 20 img = Image.new ("L",(8,8)) >> 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] >> 22 img.putdata(matrix) >> 23 img.show() >> 24 img.save(fp="./ana.bmp") >> 25 >> >> My probeleme : In line 23 "img.show()" Don't work, normally I show the >> image Image show is implemented rather half heartedly (at least on linux) a potential reasons is: - you didn not install the correct image viewer tool (You should see an error message though". Then you could try to install the tool, that python did not find. depending on the platform, you might have bugs, that don't allow to view more than one image at a time / etc. potentially you might be better of by just using a hand rolled os.system() or subprocess.Popen call bye N >> but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" >> it's >> work >> WHERE IS THE PROBLEME. >> >> I have this error in shell : "(eog:3176): GLib-WARNING **: GError set >> over >> the top of a previous GError or uninitialized memory. >> This indicates a bug in someone's code. You must ensure an error is NULL >> before it's set. >> The overwriting error message was: Error in getting image file info " >> >> >> os: ubuntu 9.10 > > Hi issolah, > I don't know what your problem is but I have a few suggestions -- > 1) You say that img.show() doesn't work. How does it fail? Is that where > you get the GLib warning? > 2) I'm glad you posted your code, but because it has line numbers, it's > awkward to copy & paste into a local example. Please show your code > without line numbers. > > I'm unfamiliar with PIL, so this is just a wild guess, but based on the > GLib error it seems like you haven't initialized something properly. > Sorry I couldn't be more helpful. Maybe someone who knows more will answer. > > Good luck > Philip > > > > > From steve at REMOVE-THIS-cybersource.com.au Fri Mar 12 07:35:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 12:35:57 GMT Subject: Unicode characters in btye-strings Message-ID: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> I know this is wrong, but I'm not sure just how wrong it is, or why. Using Python 2.x: >>> s = "???" >>> print s ??? >>> len(s) 6 >>> list(s) ['\xc3', '\xa9', '\xc3', '\xa2', '\xc3', '\x84'] Can somebody explain what happens when I put non-ASCII characters into a non-unicode string? My guess is that the result will depend on the current encoding of my terminal. In this case, my terminal is set to UTF-8. If I change it to ISO 8859-1, and repeat the above, I get this: >>> list("???") ['\xe9', '\xe2', '\xc4'] If I do this: >>> s = u"???" >>> s.encode('utf-8') '\xc3\xa9\xc3\xa2\xc3\x84' >>> s.encode('iso8859-1') '\xe9\xe2\xc4' which at least explains why the bytes have the values which they do. Thank you, -- Steven From jeanmichel at sequans.com Fri Mar 12 07:51:43 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Mar 2010 13:51:43 +0100 Subject: Need advice on starting a Python group In-Reply-To: <4b9a2806$0$22047$426a74cc@news.free.fr> References: <4b9a2806$0$22047$426a74cc@news.free.fr> Message-ID: <4B9A38DF.1020208@sequans.com> News123 wrote: > Jonathan Gardner wrote: > >> On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: >> >>> And even when we've had volunteers, hardly anyone shows up! >>> >>> Any suggestions would be appreciated. >>> >>> >> Two things: One, only you and your friend really care. Let that sink >> in. No one is going to carry the group but you two, at least >> initially. >> >> Two, there's a lot of people at movie theaters and the county fair. >> Why? Because it is interesting and fun. Scientists work the same way. >> Yes, a lot of people are interested in Python. Why don't you do a bit >> of snooping around and see what people want to know about? >> >> Let me give some examples: >> >> * Interactive numeric programming with Python >> * Rapid website development with Pylons (Trust me, everyone wants to >> make a website.) Show how you are showing off data from one of your >> experiments of projects and how easy it is to organize and manage >> data. >> * How you used Python on your latest and greatest project >> >> Don't expect the audience to participate, except to show up and ask questions. >> >> If you want to build a Python support group, then form an informal >> group with your friends. Start a public mailing list and offer Python >> advice and support for free. Integrate whatever code your org has with >> Python, and manage and maintain that code so others can use it. >> >> Finally, advertise. The more people see "Python", the more they will >> be interested. Coca-cola and Pepsi are really good at this! >> >> > > > attendance will be very low and be sure nobody cares to check whether > anything happened on this group. > > My suggestion is: > > > I'd suggest to setup a group, to which one can subscribe with mail > notification and for all the old ones perhaps even via nntp ;-) and of > course via a web front end (though I personally hate web groups) > > Afterwards you can 'friendly-fore-subscribe' some collegues. ;-) > Just talk about your new cool group during lunch, etc. > > Be sure, that most will be to lazy to unsuscribe. > > Start discussing interesting topics on this group and then . . . > maybe others start joining. maybo nobody cares and you have just to > accept it. > > bye > > > N > Python is not interesting enough by itself to grab students attention. It's just a tool to solve some technical problems. So, either python has a direct benefit on the study itself (meaning it can help getting better results), or you'll have to make it intereseting as a hobbit. But python is not music, video, dance nor it is related to sport, sex or whatever things that usually interest people. So I really don't know how to make it interesting, I'm not sure it's even possible nor desirable. Good luck anyway. JM From hv at tbz-pariv.de Fri Mar 12 07:59:54 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 12 Mar 2010 13:59:54 +0100 Subject: Parsing Email Headers In-Reply-To: <6e0f6857-bedd-4b23-81af-69dd06a53764@q15g2000yqj.googlegroups.com> References: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> <6e0f6857-bedd-4b23-81af-69dd06a53764@q15g2000yqj.googlegroups.com> Message-ID: <7vus6aFm6qU1@mid.individual.net> T wrote: > Thanks for your suggestions! Here's what seems to be working - it's > basically the same thing I originally had, but first checks to see if > the line is blank > > response, lines, bytes = M.retr(i+1) > # For each line in message > for line in lines: > if not line.strip(): > M.dele(i+1) > break > > emailMessage = email.message_from_string(line) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") Hi T, wait, this code looks strange. You delete the email if it contains an empty line? I use something like this: message='\n'.join(connection.retr(msg_num)[1]) Your code: emailMessage = email.message_from_string(line) create an email object from only *one* line! You retrieve the whole message (you don't save bandwith), but maybe that's what you want. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From steve at holdenweb.com Fri Mar 12 08:04:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Mar 2010 08:04:19 -0500 Subject: Need advice on starting a Python group In-Reply-To: <4B9A38DF.1020208@sequans.com> References: <4b9a2806$0$22047$426a74cc@news.free.fr> <4B9A38DF.1020208@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > News123 wrote: >> Jonathan Gardner wrote: >> >>> On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: >>> >>>> And even when we've had volunteers, hardly anyone shows up! >>>> >>>> Any suggestions would be appreciated. >>>> >>>> >>> Two things: One, only you and your friend really care. Let that sink >>> in. No one is going to carry the group but you two, at least >>> initially. >>> >>> Two, there's a lot of people at movie theaters and the county fair. >>> Why? Because it is interesting and fun. Scientists work the same way. >>> Yes, a lot of people are interested in Python. Why don't you do a bit >>> of snooping around and see what people want to know about? >>> >>> Let me give some examples: >>> >>> * Interactive numeric programming with Python >>> * Rapid website development with Pylons (Trust me, everyone wants to >>> make a website.) Show how you are showing off data from one of your >>> experiments of projects and how easy it is to organize and manage >>> data. >>> * How you used Python on your latest and greatest project >>> >>> Don't expect the audience to participate, except to show up and ask >>> questions. >>> >>> If you want to build a Python support group, then form an informal >>> group with your friends. Start a public mailing list and offer Python >>> advice and support for free. Integrate whatever code your org has with >>> Python, and manage and maintain that code so others can use it. >>> >>> Finally, advertise. The more people see "Python", the more they will >>> be interested. Coca-cola and Pepsi are really good at this! >>> >>> >> >> >> attendance will be very low and be sure nobody cares to check whether >> anything happened on this group. >> >> My suggestion is: >> >> >> I'd suggest to setup a group, to which one can subscribe with mail >> notification and for all the old ones perhaps even via nntp ;-) and of >> course via a web front end (though I personally hate web groups) >> >> Afterwards you can 'friendly-fore-subscribe' some collegues. ;-) >> Just talk about your new cool group during lunch, etc. >> >> Be sure, that most will be to lazy to unsuscribe. >> >> Start discussing interesting topics on this group and then . . . >> maybe others start joining. maybo nobody cares and you have just to >> accept it. >> >> bye >> >> >> N >> > Python is not interesting enough by itself to grab students attention. > It's just a tool to solve some technical problems. > > So, either python has a direct benefit on the study itself (meaning it > can help getting better results), or you'll have to make it intereseting > as a hobbit. But python is not music, video, dance nor it is related to > sport, sex or whatever things that usually interest people. So I really > don't know how to make it interesting, I'm not sure it's even possible > nor desirable. > > Good luck anyway. > > JM > > All the advice you have had is good. You need to turn around your enthusiasm and look at it from the potential visitor's point of view - what's in it for them? You don't say where you are (and your invalid domain doesn't really help identify that), but if you have any of the superstars from the scientific Python world around you, invite one of them as a guest speaker. Take a look on the web - e.g. in pycon.blip.tv, where all the PyCon talks for the last two years are available. Maybe you could start each meeting by showing one of those videos? Also take a look to see what SciPy conferences have made available (though I don't think they do videos yet). The PSF has invested hugely in making that information available, and the more they get used the happier we will be. But mostly it's a matter of focusing on what your community needs from the group, and providing that. Good luck! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Mar 12 08:07:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Mar 2010 08:07:00 -0500 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: Neo wrote: > I have learned java for half a year and now I want to learn Python, > should I learn python 3k or the traditional version? > That depends on whether you need to use specific libraries that haven't yet been ported to Python 3. If so then start with Python 2. If not, start with 3 - the differences are small enough that you can relatively easily fall back to 2 if you need to get access to non-ported libraries. regards Steve > On Wed, Mar 10, 2010 at 7:19 AM, kj wrote: > > > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Mar 12 08:15:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Mar 2010 08:15:49 -0500 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: alex goretoy wrote: > hi, > i'm trying to write a section of my program that needs to run bash > builtin alias and declare, i've googled and tried every type of example > i could find no to avail. this is what I've tried below and it doesn't > work, is there a way for me to execute a bah builin from python? what i > need is to take alias output and pipe it to another command with python > and return the results to a string or list. > >>>> p1=Popen(["alias"],stdout=PIPE) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/subprocess.py", line 621, in __init__ > errread, errwrite) > File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > if i add shell=True i get empty string and no thins error message > >>>> p1=Popen(["alias"],stdout=PIPE,shell=True) >>>> p1 > >>>> p1.stdout.read() > '' > > thank you, > -Alex Goretoy > For shell=True I believe you should provide the command as a single string, not a list of arguments. >>> p1 = Popen("alias", stdout=PIPE, shell=True) >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bartc at freeuk.com Fri Mar 12 08:38:07 2010 From: bartc at freeuk.com (bartc) Date: Fri, 12 Mar 2010 13:38:07 GMT Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: <3trmn.49663$Ym4.35065@text.news.virginmedia.com> "gb345" wrote in message news:hnb0d1$2el$1 at reader1.panix.com... > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. Last time just he and I showed up. ... > Still, we have a hard time finding volunteers. > > And even when we've had volunteers, hardly anyone shows up! > > Any suggestions would be appreciated. Try and get a girl or two interested in coming to the meetings... -- Bartc From python at mrabarnett.plus.com Fri Mar 12 08:40:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Mar 2010 13:40:23 +0000 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4B9A4447.8010500@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 12 Mar 2010 00:11:37 -0700, Zooko O'Whielacronx wrote: > >> Folks: >> >> Every couple of years I run into a problem where some Python code that >> worked well at small scales starts burning up my CPU at larger scales, >> and the underlying issue turns out to be the idiom of accumulating data >> by string concatenation. > > I don't mean to discourage you, but the simple way to avoid that is not > to accumulate data by string concatenation. > > The usual Python idiom is to append substrings to a list, then once, at > the very end, combine into a single string: > > > accumulator = [] > for item in sequence: > accumulator.append(process(item)) > string = ''.join(accumulator) > > >> It just happened again >> (http://foolscap.lothar.com/trac/ticket/149 ), and as usual it is hard >> to make the data accumulator efficient without introducing a bunch of >> bugs into the surrounding code. > > I'm sorry, I don't agree about that at all. I've never come across a > situation where I wanted to use string concatenation and couldn't easily > modify it to use the list idiom above. > > [...] >> Here are some benchmarks generated by running python -OOu -c 'from >> stringchain.bench import bench; bench.quick_bench()' as instructed by >> the README.txt file. > > To be taken seriously, I think you need to compare stringchain to the > list idiom. If your benchmarks favourably compare to that, then it might > be worthwhile. > IIRC, someone did some work on making concatenation faster by delaying it until a certain threshold had been reached (in the string class implementation). From hiralsmaillist at gmail.com Fri Mar 12 08:49:04 2010 From: hiralsmaillist at gmail.com (hiral) Date: Fri, 12 Mar 2010 05:49:04 -0800 (PST) Subject: result of os.times() is different with 'time' command Options Message-ID: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> Hi, Python version: 2.6 Script: def pt(start_time, end_time): def ptime(time, time_str): min, sec = divmod(time, 60) hr, min = divmod(min, 60) stmt = time_str + '\t' if hr: stmt += str(hr) + 'h' stmt += str(min) + 'm' + str(sec) + 's' print stmt if start_time and end_time: real_time = end_time[4] - start_time[4] ptime(real_time, "real") user_time = end_time[0] - start_time[0] ptime(user_time, "user") sys_time = end_time[1] - start_time[1] ptime(sys_time, "sys") import os, subprocess cmd = ['ls'] print cmd t1 = os.times() subprocess.call(cmd) t2 = os.times() pt(t1, t2) print ".end" Output: real 0.0m0.0100000002421s user 0.0m0.0s sys 0.0m0.0s Command: $ time ls Output: real 0m0.007s user 0m0.000s sys 0m0.000s Is this the intended behaviour? As per the link it was fixed in python 2.5. Can anybody help. Thank you. From hiralsmaillist at gmail.com Fri Mar 12 08:56:34 2010 From: hiralsmaillist at gmail.com (hiral) Date: Fri, 12 Mar 2010 05:56:34 -0800 (PST) Subject: python module/utility equivalent to 'time' (linux) and/or 'ntimer'(Windows) Message-ID: <01b0d61b-eb5f-44dc-862e-e31d64b3b0e9@k24g2000pro.googlegroups.com> Hi, Is there any python module/utility available which would report the time same as 'time' command in linux and/or report time same as 'ntimer' utility in Windows. Thank you. From hiralsmaillist at gmail.com Fri Mar 12 08:59:18 2010 From: hiralsmaillist at gmail.com (hiral) Date: Fri, 12 Mar 2010 05:59:18 -0800 (PST) Subject: to create variable from dict Message-ID: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Hi, Is there any way to create variables which name matches with dict key? For example: dict1 = {"abc":'1", "def":"2"} Now I am looking to have variable name abc and it's value be '1' etc. Pl. suggest. Thank you. From felix.antoine.fortin at gmail.com Fri Mar 12 09:08:09 2010 From: felix.antoine.fortin at gmail.com (=?ISO-8859-1?Q?F=E9lix=2DAntoine_Fortin?=) Date: Fri, 12 Mar 2010 06:08:09 -0800 (PST) Subject: inspect.stack() and frame References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> Message-ID: Thanks Gabriel, you resumed quite well what I did discovered after my second post by playing with the garbage collector module. > (The garbage collector will, ? > eventually, break the cycle and free those objects, but not very soon). I'm not very familiar with the Python garbage collector, so you may excuse my simple question, but how can it break the cycle? I guess the object will be freed at least when the program ends, but could it be before that? Is there a mechanisme in the garbage collector to detect circular references? Felix From albert at spenarnc.xs4all.nl Fri Mar 12 09:13:55 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2010 14:13:55 GMT Subject: Python dos2unix one liner References: <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: In article , Martin P. Hellwig wrote: >On 02/28/10 11:05, Stefan Behnel wrote: >> Steven D'Aprano, 28.02.2010 09:48: >>> There ought to be some kind of competition for the least efficient >>> solution to programming problems >> >> That wouldn't be very interesting. You could just write a code generator >> that spits out tons of garbage code including a line that solves the >> problem, and then let it execute the code afterwards. That beast would >> always win. >> >> Stefan >> >Well that would be an obvious rule that garbage code that does not >contribute to the end result (ie can be taken out without affecting the >end result) would not be allowed. Enforcing the rule is another beast >though, but I would leave that to the competition. Thinking of the international obfuscated c contest (iocc). It is easy to make a mess of a program using the preprocessor. It is also easy to preprocess then prettyprint the program. If the result is not obfuscated, it impresses nobody. Likewise the judges would think nothing of a program with garbage, and would rate it low, so such rule is unnecessary. > >Though the idea of a code generator is solid, but instead of generating >garbage, produces a virtual machine that implements a generator that >produces a virtual machine, etc. etc. That was actually done by Lennart Benschop. He made a Forth program run by an interpreter written in C. Although Forthers thought it was straightforward comprehensible code, it was a winner in the iocc. > >-- >mph Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From emile at fenx.com Fri Mar 12 09:22:23 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Mar 2010 06:22:23 -0800 Subject: Reverse engineering CRC? In-Reply-To: <7vum06Fj82U1@mid.individual.net> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> <7vum06Fj82U1@mid.individual.net> Message-ID: On 3/12/2010 3:24 AM Gregory Ewing said... > What confused me initially is that it seems to be adding > a few extra bytes to the checked data that aren't present > in the file. Figuring out what they're supposed to contain > is proving to be quite a headache... Length? Emile From darcy at druid.net Fri Mar 12 09:30:51 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 12 Mar 2010 09:30:51 -0500 Subject: NoSQL Movement? In-Reply-To: <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> Message-ID: <20100312093051.75022620.darcy@druid.net> On Fri, 12 Mar 2010 01:05:27 -0800 Jonathan Gardner wrote: > Let me give you an example. I worked on a system that would load > recipients for email campaigns into a database table. The SQL database > was nice during the initial design and prototype stage because we > could quickly adjust the tables to add or remove columns and try out > different designs.. However, once our system got popular, the > limitation was how fast we could load recipients into the database. Just curious, what database were you using that wouldn't keep up with you? I use PostgreSQL and would never consider going back to flat files. The only thing I can think of that might make flat files faster is that flat files are buffered whereas PG guarantees that your information is written to disk before returning but if speed is more important than 100% reliability you can turn that off and let PG use the file system buffering just like flat files. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From python.list at tim.thechases.com Fri Mar 12 09:40:52 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Mar 2010 08:40:52 -0600 Subject: to create variable from dict In-Reply-To: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: <4B9A5274.7080301@tim.thechases.com> hiral wrote: > Is there any way to create variables which name matches with dict key? > > For example: > dict1 = {"abc":'1", "def":"2"} > > Now I am looking to have variable name abc and it's value be '1' etc. 1) you can't because "def" is a reserved word in Python. 2) why do you want to? This seems to come up about every week or so and people STILL want to do it. Search the archives...you won't have to go back too far. 3) once you have it, how do you plan to use the variables? If you don't know what they'll be named ahead of time, how can you use them in your code The usual answer is "don't do that -- just use them as a dict", or if you're trying to set up some constants, you can use abc, def_, ghi = 1, 2, 3 -tkc From luismgz at gmail.com Fri Mar 12 09:50:18 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 12 Mar 2010 06:50:18 -0800 (PST) Subject: to create variable from dict References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: On Mar 12, 10:59?am, hiral wrote: > Hi, > > Is there any way to create variables which name matches with dict key? > > For example: > dict1 = {"abc":'1", "def":"2"} > > Now I am looking to have variable name abc and it's value be '1' etc. > > Pl. suggest. > > Thank you. Check out this thread (very recent): http://groups.google.com/group/comp.lang.python/browse_thread/thread/bb1797ffb6fc3bd7/25fe94103c7a231f?lnk=gst&q=luis+variables#25fe94103c7a231f Short answer: you can update globals() with a dictionary, as follows: globals().update( dict1 ) Then you'll have each key-value pair as variables in the global namespace. The question is: should you do it? Luis From jeanmichel at sequans.com Fri Mar 12 10:02:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Mar 2010 16:02:24 +0100 Subject: to create variable from dict In-Reply-To: References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: <4B9A5780.90005@sequans.com> Luis M. Gonz?lez wrote: > On Mar 12, 10:59 am, hiral wrote: > >> Hi, >> >> Is there any way to create variables which name matches with dict key? >> >> For example: >> dict1 = {"abc":'1", "def":"2"} >> >> Now I am looking to have variable name abc and it's value be '1' etc. >> >> Pl. suggest. >> >> Thank you. >> > > Check out this thread (very recent): > http://groups.google.com/group/comp.lang.python/browse_thread/thread/bb1797ffb6fc3bd7/25fe94103c7a231f?lnk=gst&q=luis+variables#25fe94103c7a231f > > Short answer: you can update globals() with a dictionary, as follows: > > globals().update( dict1 ) > > Then you'll have each key-value pair as variables in the global > namespace. > The question is: should you do it? > > Luis > The answer is known: no, he should not do it :o) JM From pemerson at gmail.com Fri Mar 12 10:15:16 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 12 Mar 2010 07:15:16 -0800 (PST) Subject: Exiting gracefully from ThreadingTCPServer Message-ID: <1f31cddf-1104-4579-bd61-5fad3b2c4677@t17g2000prg.googlegroups.com> I'm trying to get threading going for the first time in python, and I'm trying to modify code I found so that I can have the server close the TCP connections and exit gracefully. Two problems: 1) While the KeyboardInterrupt works, if I make more than 0 curls to the server and then quit, I can't run it again right away and get this: socket.error: [Errno 48] Address already in use Not all of my connections are closing properly. How do I fix this? 2) curling localhost:8080/quit does show the "Quitting" output that I expect, but doesn't quit the server until I manually control-c it. I think that I need *all* threads to close and not just the current one, so I'm not quite sure how to proceed. Pointers in the right direction are appreciated. And if there's a "better" way to do this threading httpd server (subjective, I realize), please let me know! Thanks. Pete ############################################# #!/usr/bin/env python import SocketServer import SimpleHTTPServer PORT = 8080 done = False class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): global done if self.path=='/quit': self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.wfile.write('Quitting') done = True return self else: self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.wfile.write('Unknown') return self if __name__ == "__main__": httpd = SocketServer.ThreadingTCPServer(('localhost', PORT),CustomHandler) try: while not done: print "done: ", done httpd.handle_request() except KeyboardInterrupt: print "Server is done." httpd.server_close() From robert.kern at gmail.com Fri Mar 12 10:37:36 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Mar 2010 09:37:36 -0600 Subject: Unicode characters in btye-strings In-Reply-To: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-12 06:35 AM, Steven D'Aprano wrote: > I know this is wrong, but I'm not sure just how wrong it is, or why. > Using Python 2.x: > >>>> s = "???" >>>> print s > ??? >>>> len(s) > 6 >>>> list(s) > ['\xc3', '\xa9', '\xc3', '\xa2', '\xc3', '\x84'] > > Can somebody explain what happens when I put non-ASCII characters into a > non-unicode string? My guess is that the result will depend on the > current encoding of my terminal. Exactly right. -- 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 From robin at reportlab.com Fri Mar 12 10:44:12 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 15:44:12 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A2810.9030602@chamonix.reportlab.co.uk> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> Message-ID: <4B9A614C.1080105@chamonix.reportlab.co.uk> On 12/03/2010 11:40, Robin Becker wrote: ........ > > I assume I can get those from a working Python amd64 install and stuff > on one of the compiler paths somehow. Not sure if this is a bug; I dug around a bit and find that because of the cross compilation distutils is supposed to add an extra library path with the name PCbuild\AMD64 when doing x86-->amd64 cross builds. I tried copying the 2.6.4 amd64 libs/dlls etc etc into c:\python26\PCbuild\AMD64 and reran my cross build c:\python26\python setup.py build --plat-name=win-amd64 however, that still gives linker import errors. Looked in the output I see this > C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\python26 > \libs /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.obj /OUT:build > \lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\temp.win-amd > 64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyNumber_Int referenced in function _parseSequenceInt > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PySequence_GetItem referenced in function _parseSequence that looks wrong because I'm using 32 bit python to do the build and /LIBPATH:C:\python26\libs /LIBPATH:C:\python26\PCbuild\amd64 means that the 32 bit libraries are first. Running the linker command by itself (without the 32bit libs in the command) works fine ie > C:\ux\PydBuilder\rl_addons\rl_accel>"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe" /DLL /nolog > o /INCREMENTAL:NO /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.ob > j /OUT:build\lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\ > temp.win-amd64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp seems to work fine and produce a pyd in build\lib.win-amd64-2.6 -- Robin Becker From robin at reportlab.com Fri Mar 12 10:44:12 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 15:44:12 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A2810.9030602@chamonix.reportlab.co.uk> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> Message-ID: <4B9A614C.1080105@chamonix.reportlab.co.uk> On 12/03/2010 11:40, Robin Becker wrote: ........ > > I assume I can get those from a working Python amd64 install and stuff > on one of the compiler paths somehow. Not sure if this is a bug; I dug around a bit and find that because of the cross compilation distutils is supposed to add an extra library path with the name PCbuild\AMD64 when doing x86-->amd64 cross builds. I tried copying the 2.6.4 amd64 libs/dlls etc etc into c:\python26\PCbuild\AMD64 and reran my cross build c:\python26\python setup.py build --plat-name=win-amd64 however, that still gives linker import errors. Looked in the output I see this > C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\python26 > \libs /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.obj /OUT:build > \lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\temp.win-amd > 64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyNumber_Int referenced in function _parseSequenceInt > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PySequence_GetItem referenced in function _parseSequence that looks wrong because I'm using 32 bit python to do the build and /LIBPATH:C:\python26\libs /LIBPATH:C:\python26\PCbuild\amd64 means that the 32 bit libraries are first. Running the linker command by itself (without the 32bit libs in the command) works fine ie > C:\ux\PydBuilder\rl_addons\rl_accel>"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe" /DLL /nolog > o /INCREMENTAL:NO /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.ob > j /OUT:build\lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\ > temp.win-amd64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp seems to work fine and produce a pyd in build\lib.win-amd64-2.6 -- Robin Becker From python at mrabarnett.plus.com Fri Mar 12 10:47:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Mar 2010 15:47:10 +0000 Subject: inspect.stack() and frame In-Reply-To: References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> Message-ID: <4B9A61FE.1080407@mrabarnett.plus.com> F?lix-Antoine Fortin wrote: > Thanks Gabriel, you resumed quite well what I did discovered after my > second post > by playing with the garbage collector module. > >> (The garbage collector will, >> eventually, break the cycle and free those objects, but not very soon). > > I'm not very familiar with the Python garbage collector, so you may > excuse my > simple question, but how can it break the cycle? I guess the object > will be > freed at least when the program ends, but could it be before that? Is > there a > mechanisme in the garbage collector to detect circular references? > In CPython objects are reference-counted, which allows an object to be collected as soon as there are no references to it. However, this won't take care of circular references, so a secondary garbage collector was introduced which occasionally looks for inaccessible objects (garbage) using (probably) mark-and-sweep. From gabriel.rossetti at arimaz.com Fri Mar 12 10:50:21 2010 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Fri, 12 Mar 2010 16:50:21 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <4B9A62BD.7080805@arimaz.com> kj wrote: > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > Effective Java is a good book, it is not like most people responding to this topic a "how to program in Java" book but a "I know how to program in Python, but I want it to run fast and use a minimal amount of memory". I would have liked to have such a book for Python when I was past the language learning stage. Gabriel From mailinglists at riddergarn.dk Fri Mar 12 10:56:12 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 15:56:12 +0000 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> Message-ID: Sorry but its not really an option for me with PostgreSQL. Thanks anyway. I wonder if there is a simple way of just queueing the run of a function make it only run once at a time but by multiply threads? :) On Fri, 12 Mar 2010 00:54:57 -0800, Jonathan Gardner wrote: > For lots of transactions running at once, MySQL is a terrible choice. > Give PostgreSQL a try. It does a much better job with that kind of > load. > > On Thu, Mar 11, 2010 at 11:11 PM, John P. > wrote: >> Hi, >> >> Im programming a simple webcrawler with threading for the fun of it, >> which >> is inserting the data fetch into a mysql database, but after continuously >> cause my mysql server to produce error during database queries (i assume >> its cause because of the many execution at the same time.) the scipt >> produces errors. >> >> I figured out i need some kind of queue for the function i use to insert >> into the database, to make sure its only called once at a time. >> >> I have looked at the Queue module but its for more complicated than my >> current python skills can cope with. :) >> >> Would somebody please help me out here? >> From godson.g at gmail.com Fri Mar 12 11:13:06 2010 From: godson.g at gmail.com (Godson Gera) Date: Fri, 12 Mar 2010 21:43:06 +0530 Subject: python module/utility equivalent to 'time' (linux) and/or 'ntimer'(Windows) In-Reply-To: <01b0d61b-eb5f-44dc-862e-e31d64b3b0e9@k24g2000pro.googlegroups.com> References: <01b0d61b-eb5f-44dc-862e-e31d64b3b0e9@k24g2000pro.googlegroups.com> Message-ID: Take a look at hotshot module of python http://docs.python.org/library/hotshot.html On Fri, Mar 12, 2010 at 7:26 PM, hiral wrote: > Hi, > > Is there any python module/utility available which would report the > time same as 'time' command in linux and/or report time same as > 'ntimer' utility in Windows. > > Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanks & Regards, Godson Gera http://godson.in http://www.clickindia.com/detail.php?id=493636 -------------- next part -------------- An HTML attachment was scrubbed... URL: From billy.earney at gmail.com Fri Mar 12 11:18:59 2010 From: billy.earney at gmail.com (Billy Earney) Date: Fri, 12 Mar 2010 10:18:59 -0600 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: <4b9a6976.9713f30a.5a73.69a4@mx.google.com> Ludolph, This reminds me of the orange project which is developed in python. http://www.ailab.si/orange/ It is actually for data mining, but many of the concepts could be used for a more general programming structure. Billy -----Original Message----- From: python-list-bounces+billy.earney=gmail.com at python.org [mailto:python-list-bounces+billy.earney=gmail.com at python.org] On Behalf Of Ludolph Sent: Thursday, March 11, 2010 12:39 PM To: python-list at python.org Subject: Visual Python programming and decompilers? Hi Guys At work I have been exposed to a Agile Platform called OutSystems. It allows you to visually program your web applications http://i.imgur.com/r2F0i.png and I find the idea very intriguing. So I have started to play around with the idea on how will I be able to visually represent Python code as in the above image and then allow the programmer to change some of the flow/code/logic visually and then get it back as python source code. I don't know if this have been tried before and after some googling I can't find anything like this, so maybe I'm just lacking basic googling skills or a python solution like the above does not exist yet. If anybody knows of such solution please let me know, so that I don't spend a lot of time recreating the wheel. Otherwise help me out on the following problem: I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to disassemble the code to workable objects, It even allows me to rebuild the objects to bytecode. So if I define patterns on how python interrupts the source code to bytecode I can visually represent this and also so convert my visual representations back to bytecode. The only problem I have at the moment is how will I get this bytecode back to python source code. I have googled for python decompiler but only found old projects like unpyc, decompyle and some online services. I would like to know if anybody know of a well maintained or at least recent module that can help me accomplish the above mentioned, because I'm hoping I can implement this in Python 3.1. So any input or suggestion would be greatly appreciated. Kind Regards, -- Ludolph Neethling -- http://mail.python.org/mailman/listinfo/python-list From darcy at druid.net Fri Mar 12 11:22:04 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 12 Mar 2010 11:22:04 -0500 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> Message-ID: <20100312112204.5513eebb.darcy@druid.net> On Fri, 12 Mar 2010 15:56:12 +0000 "John P." wrote: > Sorry but its not really an option for me with PostgreSQL. Thanks anyway. Why? It's your best option. Any other solutions that you can't use before people give you more suggestions? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From victorsubervi at gmail.com Fri Mar 12 11:22:19 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 12 Mar 2010 12:22:19 -0400 Subject: Help Troubleshooting Message-ID: <4dc0cfea1003120822sb08f494nb56c6f9a438204ff@mail.gmail.com> Hi; I'm running Pexpect (no discussion list) with the following code: #! /usr/bin/python import pexpect def runVpopmail(whatdo, acct, domain, newpw, oldpw=''): if whatdo == 'vadduser': child = pexpect.spawn('/home/vpopmail/bin/%s %s@%s %s' % (whatdo, acct, domain, newpw)) elif whatdo == 'vchangepw': child = pexpect.spawn('/home/vpopmail/bin/%s' % (whatdo)) child.expect('Please enter the email address: ') child.sendline('%s@%s' % (acct, domain)) child.expect('Enter old password: ') child.sendline(oldpw) child.expect('Please enter password for %s@%s: ' % (acct, domain)) child.sendline(newpw) child.expect('enter password again: ') child.sendline(newpw) return child No matter whether I try to add a user or edit a password, the fn seems to return that everything is good, but nothing ever happens. When I place a return of the child value and run it with whatdo==vadduser I get the following output: version: 2.3 ($Revision: 399 $) command: /home/vpopmail/bin/vadduser args: ['/home/vpopmail/bin/vadduser', 'test2 at globalsolutionsgroup.vi', 'qqq'] searcher: None buffer (last 100 chars): before (last 100 chars): None after: None match: None match_index: None exitstatus: None flag_eof: False pid: 1518 child_fd: 3 closed: False timeout: 30 delimiter: pexpect.EOF logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0. I don't know what this means. Any ideas on how to troubleshoot this? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.wintle at teamrubber.com Fri Mar 12 11:36:32 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 12 Mar 2010 16:36:32 +0000 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: <1268411792.6354.2.camel@localhost> On Thu, 2010-03-11 at 20:38 +0200, Ludolph wrote: > > I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to > disassemble the code to workable objects, It even allows me to rebuild > the objects to bytecode. So if I define patterns on how python > interrupts the source code to bytecode I can visually represent this > and also so convert my visual representations back to bytecode. Assuming you're on 2.6 or later, I'd suggest working with the ast module instead: http://docs.python.org/library/ast.html From solipsis at pitrou.net Fri Mar 12 11:48:33 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Mar 2010 16:48:33 +0000 (UTC) Subject: Asynchronous HTTP client References: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> Message-ID: Le Sun, 07 Mar 2010 22:40:36 +0800, pingooo a ?crit?: > I'm writing an open source python client for a web service. The client > may be used in all kinds of environments - Linux, Mac OS X, Windows, web > hosting, etc by others. It is not impossible to have twisted as a > dependency, but that makes deployment a larger job than simply uploading > a Python file. If it can be used by non-Python users, you will have to package it using py2exe or py2app anyway, in which case Twisted will be bundled automatically and the size overhead won't be very large. From mailinglists at riddergarn.dk Fri Mar 12 11:49:04 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 16:49:04 +0000 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: <20100312112204.5513eebb.darcy@druid.net> References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> <20100312112204.5513eebb.darcy@druid.net> Message-ID: <1a57cdb3bd2bdf55176e96369d25d1b7@incoming.servage.net> On Fri, 12 Mar 2010 11:22:04 -0500, "D'Arcy J.M. Cain" wrote: > On Fri, 12 Mar 2010 15:56:12 +0000 > "John P." wrote: >> Sorry but its not really an option for me with PostgreSQL. Thanks anyway. > > Why? It's your best option. Any other solutions that you can't use > before people give you more suggestions? Chill. I didn't ask for an alternative to my database, it could be writing in a file as well. What I need is some kind of queue to my function so it doesnt crack up running 20 times at the same time. I'm working on a remote server which I share with some friends, meaning I can't install whatever I want to. The problem seems to be that my threads are making MySQL queries at the same time before it can fetch the data just requested. Also I said thanks for his effort trying to help and kept a nice tone, shouldn't that be enough? /John From solipsis at pitrou.net Fri Mar 12 11:57:37 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Mar 2010 16:57:37 +0000 (UTC) Subject: file seek is slow References: Message-ID: Le Tue, 09 Mar 2010 15:56:47 -0800, Metalone a ?crit?: > for i in xrange(1000000): > f1.seek(0) This is quite a stupid benchmark to write, since repeatedly seeking to 0 is a no-op. I haven't re-read the file object code recently, but chances are that the Python file object has its own bookkeeping which adds a bit of execution time. But I would suggest measuring the performance of *actual* seeks to different file offsets, before handwaving about the supposed "slowness" of file seeks in Python. Regards Antoine. From mailinglists at riddergarn.dk Fri Mar 12 12:25:13 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 17:25:13 +0000 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: <1a57cdb3bd2bdf55176e96369d25d1b7@incoming.servage.net> References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> <20100312112204.5513eebb.darcy@druid.net> <1a57cdb3bd2bdf55176e96369d25d1b7@incoming.servage.net> Message-ID: <7242f69346c1ddb6803a50449fe36973@incoming.servage.net> On Fri, 12 Mar 2010 16:49:04 +0000, "John P." wrote: > On Fri, 12 Mar 2010 11:22:04 -0500, "D'Arcy J.M. Cain" > wrote: >> On Fri, 12 Mar 2010 15:56:12 +0000 >> "John P." wrote: >>> Sorry but its not really an option for me with PostgreSQL. Thanks > anyway. >> >> Why? It's your best option. Any other solutions that you can't use >> before people give you more suggestions? > > Chill. I didn't ask for an alternative to my database, it could be writing > in a file as well. What I need is some kind of queue to my function so it > doesnt crack up running 20 times at the same time. I'm working on a remote > server which I share with some friends, meaning I can't install whatever I > want to. > The problem seems to be that my threads are making MySQL queries at the > same time before it can fetch the data just requested. Also I said thanks > for his effort trying to help and kept a nice tone, shouldn't that be > enough? > > /John Don't worry guys, I found a solution. My problem was caused because I used the same mysql connection for all the treads, now its working perfectly, with mysql. /John. From cmpython at gmail.com Fri Mar 12 13:31:50 2010 From: cmpython at gmail.com (CM) Date: Fri, 12 Mar 2010 10:31:50 -0800 (PST) Subject: Need advice on starting a Python group References: Message-ID: On Mar 11, 9:57?am, gb345 wrote: > I'm hoping to get advice from anyone with prior experience setting > up a Python group. > > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. ?Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. ?Last time just he and I showed up. > > The second problem is getting content. ?The format we'd envisioned > for this group was centered around code review (though not limited > to it). ?The idea was that at every meeting a different member > would show some code. ?This could be for any of a number of reasons, > such as, for example, 1) illustrate a cool module or technique; 2) > present a scientific research problem and how they used Python to > solve it, or get help solving it; 3) get general feedback (e.g. on > code clarity, software usability, module architecture, etc.). ?But > in principle just about anything is OK: e.g. a talk on favorite > Python resources, or a comparison of Python with some other language, > or an overview of Python gotchas would all be fair game. > > Also, we stressed that the talks were not expected to be polished: > no need for PowerPoint slides, etc. ?Just project any old code onto > the screen, and talk about it, or scribble stuff on the chalkboard. > > Still, we have a hard time finding volunteers. > > And even when we've had volunteers, hardly anyone shows up! Do you advertise each time and describe what the topic will be for that meeting and why the attendees should care? That might make a difference. I.e., there's a big difference between: a) The Thursday afternoon Python for scientific applications is meeting, and I should remember that this week amidst all the other stuff I have going on. and b) Wow, this Thursday there will be an hour workshop on how to create publication quality graphs (somewhat) easily in Python using ready- made tools...and there will be pizza! Also, giving it a cool acronymic name doesn't hurt. :D Che From ugocupcic at gmail.com Fri Mar 12 13:56:00 2010 From: ugocupcic at gmail.com (Ugo Cupcic) Date: Fri, 12 Mar 2010 18:56:00 +0000 Subject: question regarding wxSlider Message-ID: Hi all, I have a question regarding wxSlider. I'm developing a wxwidget python interface for a robotic hand. The sliders send the target values to the joints. I'd like to display the current position of the joint on the slider. I wanted to use wxSlider.SetTick(myposition) but I couldn't get SetTick to display anything. Anyone has an idea ? I attached a dummy code to the message to illustrate. Cheers, Ugo -- Ugo Cupcic http://www.genugo.com/ugocupcic _ ' v ' / \ m m -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: joint_sliders.py Type: text/x-python Size: 3559 bytes Desc: not available URL: From agoretoy at gmail.com Fri Mar 12 13:57:47 2010 From: agoretoy at gmail.com (alex goretoy) Date: Fri, 12 Mar 2010 12:57:47 -0600 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: Steve thank you. The problem is that you can only run commands from Popen or os.system and stuff. You cant run bash shell builtin commands for some reason. I was able to get this to work. What I did is call this: Popen(["bash -c 'source $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read() and make sure you don't have a line like this in your .bashrc: [ -z "$PS1" ] && return Another approach I came up with was to set aliases and functions as a environment variable and access them with os.environ. this is how I'm doing it. export ALIASES=`alias|awk '{print $2}'|cut -d = -f 1|xargs` export FUNCTIONS=`declare -F|awk '{print $3}'|xargs` use this at the end or the .bashrc and then you can access defined aliases and functions inside python with environ -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Fri Mar 12 14:08:19 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 12 Mar 2010 14:08:19 -0500 Subject: question regarding wxSlider In-Reply-To: References: Message-ID: <8EA74011-1EA0-42CB-BAF5-F9A9F1FF2D16@semanchuk.com> On Mar 12, 2010, at 1:56 PM, Ugo Cupcic wrote: > Hi all, > > I have a question regarding wxSlider. I'm developing a wxwidget python > interface for a robotic hand. The sliders send the target values to > the > joints. > > I'd like to display the current position of the joint on the slider. I > wanted to use wxSlider.SetTick(myposition) but I couldn't get > SetTick to > display anything. > > Anyone has an idea ? I attached a dummy code to the message to > illustrate. Hi Ugo, I don't mean to chase you away, but there is a dedicated wxPython mailing list where you obviously have a much better chance of getting an answer. http://www.wxpython.org/maillist.php Developing a robotic hand sounds like fun! Cheers Philip From kwmsmith at gmail.com Fri Mar 12 14:16:14 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Fri, 12 Mar 2010 13:16:14 -0600 Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: On Thu, Mar 11, 2010 at 8:57 AM, gb345 wrote: > > > > I'm hoping to get advice from anyone with prior experience setting > up a Python group. > > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. ?Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. ?Last time just he and I showed up. > > The second problem is getting content. ?The format we'd envisioned > for this group was centered around code review (though not limited > to it). ?The idea was that at every meeting a different member > would show some code. ?This could be for any of a number of reasons, > such as, for example, 1) illustrate a cool module or technique; 2) > present a scientific research problem and how they used Python to > solve it, or get help solving it; 3) get general feedback (e.g. on > code clarity, software usability, module architecture, etc.). ?But > in principle just about anything is OK: e.g. a talk on favorite > Python resources, or a comparison of Python with some other language, > or an overview of Python gotchas would all be fair game. > > Also, we stressed that the talks were not expected to be polished: > no need for PowerPoint slides, etc. ?Just project any old code onto > the screen, and talk about it, or scribble stuff on the chalkboard. > > Still, we have a hard time finding volunteers. > > And even when we've had volunteers, hardly anyone shows up! > > Any suggestions would be appreciated. > > GB > > P.S. ?There's a Python Meetup we could go to, but it does not fit > the bill for us: it doesn't meet often enough, it's sort of out of > the way, and has practically no one doing scientific programming. > -- > http://mail.python.org/mailman/listinfo/python-list > There's a general Scientific Computing interest group that gets together here at the University of Wisconsin-Madison, and it has a significant Python component & focus. They put on a Python bootcamp this January that was a huge success. http://hackerwithin.org/cgi-bin/hackerwithin.fcgi/wiki They have bi-weekly meetings, sometimes it's of the 'come and share on X topic,' although many times its 'local guest speaker is coming to speak about Y'. My impression is that the latter meetings grabbed a number of people around campus -- 'hey, I need to do Y, I'll see what the speaker has to say,' and then they started coming for the show-and-tell meetings. My recommendation would be to provide something of value every meeting, the more specific the better. 'Python' in this regard is a bit open ended. You'd likely get more involvement if you had meetings that focused on, e.g., parallel computing (and have examples in python (mpi4py), and have someone come and talk about MPI or something), or scientific data formats (with examples of pyhdf5 or pytables...), or you could advertise a tutorial on some scipy & numpy features and their advantages over using matlab/octave/idl. It's more work than show-and-tell meetings, but look at it as priming the pump. There is much interest around here re: Python in science, but many have only heard about it, some have dabbled but put it on the shelf, others couldn't get it to work (they're scientists and used to prepackaged software that works out of the box -- if it doesn't, it's somebody else's problem), many others can't justify the time it would take to learn it when they already have something else working. Until something with value comes along (like your meeting with specific topics) to change their minds, an open-ended meeting won't appeal much to them. Just some thoughts, and an example of what's worked here. Personally I tend to make it to the meetings with a specific topic, and end up skipping the ones that are more open-ended. Kurt From gdamjan at gmail.com Fri Mar 12 14:20:48 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Fri, 12 Mar 2010 20:20:48 +0100 Subject: Python for newbies (Pythno users group in Macedonia) Message-ID: Hi all, we are starting with bi-monthly Python User Group meetings in Skopje, Macedonia. The meetings are targeted for both beginners and more experienced users. The basic idea is to have an 1 hour presentation at the start for the beginners and an 1 hour ad-hoc discussion about projects, applications, interesting stuff etc. I'd like to gather some guidance/experince/thoughts about some beginner oriented python lectures we could use? My first idea was to do something like the "Python module of the Week", but maybe there's a better approach? thanks -- damjan From no.email at nospam.invalid Fri Mar 12 14:23:10 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 12 Mar 2010 11:23:10 -0800 Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> Message-ID: <7xljdx73a9.fsf@ruckus.brouhaha.com> "D'Arcy J.M. Cain" writes: > Just curious, what database were you using that wouldn't keep up with > you? I use PostgreSQL and would never consider going back to flat > files. Try making a file with a billion or so names and addresses, then compare the speed of inserting that many rows into a postgres table against the speed of copying the file. > The only thing I can think of that might make flat files faster is > that flat files are buffered whereas PG guarantees that your > information is written to disk before returning Don't forget all the shadow page operations and the index operations, and that a lot of these operations require reading as well as writing remote parts of the disk, so buffering doesn't help avoid every disk seek. Generally when faced with this sort of problem I find it worthwhile to ask myself whether the mainframe programmers of the 1960's-70's had to deal with the same thing, e.g. when sending out millions of phone bills, or processing credit card transactions (TPF), then ask myself how they did it. Their computers had very little memory or disk space by today's standards, so their main bulk storage medium was mag tape. A heck of a lot of these data processing problems can be recast in terms of sorting large files on tape, rather than updating database one record at a time on disk or in memory. And that is still what (e.g.) large search clusters spend a lot of their time doing (look up the term "pennysort" for more info). From martin at v.loewis.de Fri Mar 12 14:29:40 2010 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 12 Mar 2010 20:29:40 +0100 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A614C.1080105@chamonix.reportlab.co.uk> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> Message-ID: <4B9A9624.7040200@v.loewis.de> > Not sure if this is a bug I think it is. It seems that the cross-build support in msvc9compiler has been tested only in a build tree of Python (where there is no Libs directory). For released copies of Python, I could change that to distribute the AMD64 pythonXY.lib in libs/amd64. [FWIW, I'm still puzzled why I ship the import libraries of all the pyd files as well - I can't see a reason other than tradition]. Then, distutils should change to look it up there. Regards, Martin From jcb at iteris.com Fri Mar 12 14:53:28 2010 From: jcb at iteris.com (Metalone) Date: Fri, 12 Mar 2010 11:53:28 -0800 (PST) Subject: file seek is slow References: Message-ID: I almost wrote a long reply to all this. In the end it boils down to being concerned about how much overhead there is to calling a 'C' function. I assumed that file.seek() simply delegated to fseek() and thus was one way to test this overhead. However, I now think that it must be doing more and may not be a reasonable comparison. I have used the profiler about as much as I can to find where my program is slow, and it appears to me that the overhead to calling 'C' functions is now my biggest problem. I have been using Ctypes, which has been a great tool so far. I just discovered Cython and this looks like it may help me. I had not heard of pythoid, so I will check it out. I did not mean to offend anybody in Cython community. It just seemed funny to me that 21 lines of Python became 1478 lines of 'C'. I wasn't really expecting any response to this. I don't know enough about this to really assume anything. Stephan, I just tested 1e7 loops. 'C': 8.133 seconds Cython: 10.812 seconds I can't figure out what Cython is using for CFLAGS, so this could be important. I used While instead of xrange, because I thought it would be faster in Cython. They had roughly the same execution speed. Thanks all for the suggestions. I think I will just consider this thread closed. From john at castleamber.com Fri Mar 12 15:36:35 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 14:36:35 -0600 Subject: Anything like "Effective Java" for Python? References: Message-ID: <87k4thp99o.fsf@castleamber.com> Gabriel Rossetti writes: > kj wrote: >> >> Subject line pretty much says it all: is there a book like "Effective >> Java" for Python. I.e. a book that assumes that readers are >> experienced programmers that already know the basics of the language, >> and want to focus on more advanced programming issues? > > Effective Java is a good book, it is not like most people responding > to this topic a "how to program in Java" I had more the feeling that these responses were more of the "Look, you actually need a book to learn how to program effectively in Java *snigger*" fanboism. > book but a "I know how to program in Python, but I want it to run fast > and use a minimal amount of memory". > I would have liked to have such a book for Python when I was past the > language learning stage. High Performance Python by Anthony Lewis (Author), et al. (*snigger*!) might be such a book but we have to wait a few more months: Publisher: O'Reilly Media; 1 edition (September 15, 2010) (It has been on my wish list for several months) To the OP: right now, Dive into Python is clearly written with people who have experience with programming in mind. I've both the Python 2 and Python 3 version (books). You can download a version of each for free: http://www.google.com/search?q=dive%20into%20python -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From martin at v.loewis.de Fri Mar 12 15:56:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 12 Mar 2010 21:56:42 +0100 Subject: Unicode characters in btye-strings In-Reply-To: References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: >> Can somebody explain what happens when I put non-ASCII characters into a >> non-unicode string? My guess is that the result will depend on the >> current encoding of my terminal. > > Exactly right. To elaborate on the "what happens" part: the string that gets entered is typically passed as a byte sequence, from the terminal (application) to the OS kernel, from the OS kernel to Python's stdin, and from there to the parser. Python recognizes the string delimiters, but (practically) leaves the bytes between the delimiters as-is (*), creating a byte string object with the very same bytes. The more interesting question is what happens when you do py> s = u"???" Here, Python needs to decode the bytes, according to some encoding. Usually, it would want to use the source encoding (as given through -*- Emacs -*- markers), but there are none. Various Python versions then try different things; what they should do is to determine the terminal encoding, and decode the bytes according to that one. Regards, Martin (*) If a source encoding was given, the source is actually recoded to UTF-8, parsed, and then re-encoded back into the original encoding. From spamfresser at ch3ka.de Fri Mar 12 17:55:49 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Fri, 12 Mar 2010 23:55:49 +0100 Subject: Unicode characters in btye-strings In-Reply-To: References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: Am 12.03.2010 21:56, schrieb Martin v. Loewis: > (*) If a source encoding was given, the source is actually recoded to > UTF-8, parsed, and then re-encoded back into the original encoding. Why is that? So "unicode"-strings (as in u"string") are not really unicode-, but utf8-strings? Need citation plz. Thx, Michael From torriem at gmail.com Fri Mar 12 18:15:55 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 12 Mar 2010 16:15:55 -0700 Subject: converting datetime with tzinfo to unix timestamp Message-ID: <4B9ACB2B.3090203@gmail.com> On Python 2.5 here. I've searched and searched but I can't find any way to convert a datetime object that includes a timezone (tzinfo) to a unix timestamp. Folks on the net say to simply use the timetuple() method of the object and feed that to time.mktime(). But that just doesn't seem to work for me. At least if my understanding that the unix timestamp is always UTC. I'm using the pytz module to create a datetime object of a certain timezone. For example: import pytz import datetime import time mountain = pytz.timezone("US/Mountain") # MST or MDT depending on date eastern = pytz.timezone("US/Eastern") # EST or EDT depending on date date1 = mountain.localize(datetime.datetime(2010, 3, 12, 9, 0)) date2 = eastern.localize(datetime.datetime(2010, 3, 12, 9, 0)) Now if I examine the two objects, I get: >>> print date1 2010-03-12 09:00:00-07:00 >>> print date2 2010-03-12 09:00:00-05:00 However the standard time.mktime(date2.timetuple()) thing gives me a timestamp, but it's in my local timezone and gives me the same answer for both dates! Can anyone point me in the right direction? thanks. From mmanns at gmx.net Fri Mar 12 18:24:49 2010 From: mmanns at gmx.net (Martin Manns) Date: Sat, 13 Mar 2010 00:24:49 +0100 Subject: [ANN] Pyspread 0.0.14b released Message-ID: Pyspread 0.0.14b released ========================= I am pleased to announce the new release 0.0.14b of pyspread. About: ------ Pyspread is a cross-platform Python spreadsheet application. It is based on and written in the programming language Python. Instead of spreadsheet formulas, Python expressions are entered into the spreadsheet cells. Each expression returns a Python object that can be accessed from other cells. These objects can represent anything including lists or matrices. Pyspread runs on Linux and *nix platforms with GTK support as well as on Windows (XP and Vista tested). On Mac OS X, some icons are too small but the application basically works. Homepage -------- http://pyspread.sourceforge.net New features ------------ * Cell border can be changed independently. * Cell access allows negative indices when not slicing. Enjoy Martin From john at castleamber.com Fri Mar 12 18:37:54 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 17:37:54 -0600 Subject: Unicode characters in btye-strings References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: <87r5npnmb1.fsf@castleamber.com> Michael Rudolf writes: > Am 12.03.2010 21:56, schrieb Martin v. Loewis: >> (*) If a source encoding was given, the source is actually recoded to >> UTF-8, parsed, and then re-encoded back into the original encoding. > > Why is that? So "unicode"-strings (as in u"string") are not really > unicode-, but utf8-strings? utf8 is a Unicode *encoding*. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From martin at v.loewis.de Fri Mar 12 18:51:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 13 Mar 2010 00:51:42 +0100 Subject: Unicode characters in btye-strings In-Reply-To: References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4B9AD38E.5030402@v.loewis.de> Michael Rudolf wrote: > Am 12.03.2010 21:56, schrieb Martin v. Loewis: >> (*) If a source encoding was given, the source is actually recoded to >> UTF-8, parsed, and then re-encoded back into the original encoding. > > Why is that? Why is what? That string literals get reencoded into the source encoding? > So "unicode"-strings (as in u"string") are not really > unicode-, but utf8-strings? No. String literals, in 2.x, are not written with u"", and are stored in the source encoding. Above procedure applies to regular strings (see where the "*" goes in my original article). > Need citation plz. You really want a link to the source code implementing that? Regards, Martin From morecrown at gmail.com Fri Mar 12 19:29:33 2010 From: morecrown at gmail.com (Hephzibah) Date: Fri, 12 Mar 2010 16:29:33 -0800 (PST) Subject: POS Tagging Message-ID: <1610f59e-b49f-4c5b-ade7-915c92c32b79@q21g2000yqm.googlegroups.com> I just started working on POS tagging with these codes: import nltk text = nltk.word_tokenize("And now for something completely different") #print text print nltk.pos_tag(text) Python prompted me to download a resource with these codes: Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not found. Please use the NLTK Downloader to obtain the resource: I download the resources available using nltk.download(). But I couldn't run POS tagger. Python gave my the following message: Traceback (most recent call last): File "C:/Python25/tag practices.py", line 5, in print nltk.pos_tag(text) File "C:\Python25\lib\site-packages\nltk\tag\__init__.py", line 62, in pos_tag tagger = nltk.data.load(_POS_TAGGER) File "C:\Python25\lib\site-packages\nltk\data.py", line 492, in load resource_val = pickle.load(_open(resource_url)) File "C:\Python25\lib\site-packages\nltk\classify\maxent.py", line 57, in import numpy ImportError: No module named numpy Can someone pls. tell me what I'm supposed to do next? Thanks, Hephzibah From john at castleamber.com Fri Mar 12 19:33:55 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 18:33:55 -0600 Subject: POS Tagging References: <1610f59e-b49f-4c5b-ade7-915c92c32b79@q21g2000yqm.googlegroups.com> Message-ID: <87aaudnjpo.fsf@castleamber.com> Hephzibah writes: > ImportError: No module named numpy > > Can someone pls. tell me what I'm supposed to do next? Install numpy would be my first guess. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alex.kapps at web.de Fri Mar 12 19:44:49 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 13 Mar 2010 01:44:49 +0100 Subject: Python eCommerce, small webshop Message-ID: <4B9AE001.3050406@web.de> Hello everybody! I have to set up a small webshop for used books, CDs, DVD, and stuff and did't find anything realy usefull on google. I'm pretty skilled with Python and would strongly prefer a Python based Shop but all I've found are in early stage, unmaintained or too limited. I've looked around and found many PHP based shops (currently I'm playing with OpenCart but their code is so messy, I don't think this is going to work) and some Ruby based ones (I don't know Ruby at all) I there really no decent, up-to-date, activily maintained and post beta stage Python webshop? What I need is: - full german support (ie. translation, shipping models, payment models, etc) - secure (code, SQL, full SSL, etc) - themable without getting into all gory details of modern HTML/CSS (a bit is OK) - customizable by people with good Python and basic SQL knowledge - finally (after being setup) usable by people without any programming skills at all. Thanks for any tips. Regards Alex From alex.kapps at web.de Fri Mar 12 20:02:36 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 13 Mar 2010 02:02:36 +0100 Subject: Python eCommerce, small webshop Message-ID: <4B9AE42C.1060905@web.de> Hello everybody! I have to set up a small webshop for used books, CDs, DVD, and stuff and did't find anything realy usefull on google. I'm pretty skilled with Python and would strongly prefer a Python based Shop but all I've found are in early stage, unmaintained or too limited. I've looked around and found many PHP based shops (currently I'm playing with OpenCart but their code is so messy, I don't think this is going to work) and some Ruby based ones (I don't know Ruby at all) I there really no decent, up-to-date, activily maintained and post beta stage Python webshop? What I need is: - full german support (ie. translation, shipping models, payment models, etc) - secure (code, SQL, full SSL, etc) - themable without getting into all gory details of modern HTML/CSS (a bit is OK) - customizable by people with good Python and basic SQL knowledge - finally (after being setup) usable by people without any programming skills at all. Thanks for any tips. Regards Alex From emile at fenx.com Fri Mar 12 20:11:04 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Mar 2010 17:11:04 -0800 Subject: Python eCommerce, small webshop In-Reply-To: <4B9AE42C.1060905@web.de> References: <4B9AE42C.1060905@web.de> Message-ID: On 3/12/2010 5:02 PM Alexander Kapps said... > Hello everybody! > > I have to set up a small webshop for used books, CDs, DVD, and stuff and > did't find anything realy usefull on google. Have you checked the current status of Satchmo? Emile > > I'm pretty skilled with Python and would strongly prefer a Python based > Shop but all I've found are in early stage, unmaintained or too limited. > > I've looked around and found many PHP based shops (currently I'm playing > with OpenCart but their code is so messy, I don't think this is going to > work) and some Ruby based ones (I don't know Ruby at all) > > I there really no decent, up-to-date, activily maintained and post beta > stage Python webshop? > > What I need is: > > - full german support (ie. translation, shipping models, payment models, > etc) > - secure (code, SQL, full SSL, etc) > - themable without getting into all gory details of modern HTML/CSS (a > bit is OK) > - customizable by people with good Python and basic SQL knowledge > - finally (after being setup) usable by people without any programming > skills at all. > > > > Thanks for any tips. > > Regards > Alex From alex.kapps at web.de Fri Mar 12 20:38:55 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 13 Mar 2010 02:38:55 +0100 Subject: Python eCommerce, small webshop In-Reply-To: <4B9AEB04.3010403@web.de> References: <4B9AE42C.1060905@web.de> <4B9AEB04.3010403@web.de> Message-ID: <4B9AECAF.10709@web.de> Sorry, Emile for the private post, one beer too much and the wrong button... ;-) Emile van Sebille wrote: > On 3/12/2010 5:02 PM Alexander Kapps said... >> Hello everybody! >> >> I have to set up a small webshop for used books, CDs, DVD, and stuff and >> did't find anything realy usefull on google. > > Have you checked the current status of Satchmo? Sort of. I checked their site and feature list which looks promising. Then I searched for a forum. I have quite some objections against projects who only have a google group with a reaction time measured in days. But since you mentioned it, I'll have a closer look. Thank you. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 12 22:06:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 03:06:52 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4b9b014c$0$27822$c3e8da3@news.astraweb.com> On Fri, 12 Mar 2010 13:40:23 +0000, MRAB wrote: >> To be taken seriously, I think you need to compare stringchain to the >> list idiom. If your benchmarks favourably compare to that, then it >> might be worthwhile. >> > IIRC, someone did some work on making concatenation faster by delaying > it until a certain threshold had been reached (in the string class > implementation). I believe you're talking about this patch: http://bugs.python.org/issue1569040 It's never been formally rejected, but the chances of it being accepted are pretty low. However, in Python 2.4 another optimization was added that makes string concatenation of the form: a = a + b a += b much faster. This is implementation specific (Jython and IronPython don't have it, and almost certainly won't) and it doesn't work for (e.g.): a = b + a See here: http://mail.python.org/pipermail/python-dev/2004-August/046686.html http://bugs.python.org/issue980695 -- Steven From robin1 at cnsp.com Fri Mar 12 22:26:20 2010 From: robin1 at cnsp.com (Robin) Date: Fri, 12 Mar 2010 19:26:20 -0800 (PST) Subject: python to exe Message-ID: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Does anyone know of a good python to stand alone exe compiler? Thanks, -Robin From gagsl-py2 at yahoo.com.ar Fri Mar 12 23:11:47 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Mar 2010 20:11:47 -0800 (PST) Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Message-ID: On 13 mar, 00:26, Robin wrote: > Does anyone know of a good python to stand alone exe compiler? http://tinyurl.com/yfcfzz4 From clp2 at rebertia.com Fri Mar 12 23:12:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Mar 2010 20:12:19 -0800 Subject: python to exe In-Reply-To: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Message-ID: <50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com> On Fri, Mar 12, 2010 at 7:26 PM, Robin wrote: > Does anyone know of a good python to stand alone exe compiler? py2exe: http://www.py2exe.org/ Cheers, Chris -- http://blog.rebertia.com From dr.cg at 126.com Fri Mar 12 23:13:42 2010 From: dr.cg at 126.com (CHEN Guang) Date: Sat, 13 Mar 2010 12:13:42 +0800 (CST) Subject: file seek is slow Message-ID: <3c99dc54.26bd.12755ba44ca.Coremail.dr.cg@126.com> >> Metalone wrote: >>> I just tried the seek test with Cython. >>> Cython fseek() : 1.059 seconds. 30% slower than 'C' >>> Python f.seek : 1.458 secondds. 80% slower than 'C'. >>> >>> It is amazing to me that Cython generates a 'C' file that is 1478 >>> lines. >> >> PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. >> PythoidC is the C language like the Python, by the Python and for the Python. >Except that it's not a language but rather a syntax converter, i.e. it >doesn't really add any features to the C language but rather restricts >Python syntax to C language features (plus a bit of header file >introspection, it seems, but C's preprocessor has a bit of that, too). >Stefan PythoidC is a familar language to Python and C programmers, I do not like waste my time to create unfamilar things to waste users' time studying. In fact PythoidC removed some boring features from C language: 1. no semicolon ; at line ends 2. no braces {} , take Pythonic indent region to express code block PythoidC restricts C syntax to Python language feature, so that C language bacomes friendly to Python programmers and Python IDE. PythoidC realized introspection not only on header files but also any C files. The PythoidC introspection will be as good as Python introspection, if only the C header file wirters adds more detailed annotation. PythoidC is a familar and convenient C language tool for Python programmers and mixed programming. plus, PythoidC is realizable only with Python, it's too far beyond C's preprocessor, believe it, or show us. CHEN Guang Convenient C Python mixed programming --- PythoidC ( http://pythoidc.googlecode.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Fri Mar 12 23:26:34 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 22:26:34 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Message-ID: <87bpes6e4l.fsf@castleamber.com> Gabriel Genellina writes: > On 13 mar, 00:26, Robin wrote: > >> Does anyone know of a good python to stand alone exe compiler? > > http://tinyurl.com/yfcfzz4 Wow, pathetic fuck. You don't have to post you know. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From morecrown at gmail.com Fri Mar 12 23:36:46 2010 From: morecrown at gmail.com (Hephzibah) Date: Fri, 12 Mar 2010 20:36:46 -0800 (PST) Subject: POS Tagging References: <1610f59e-b49f-4c5b-ade7-915c92c32b79@q21g2000yqm.googlegroups.com> <87aaudnjpo.fsf@castleamber.com> Message-ID: <14b223b6-10c2-4ee3-9d18-18677a6769c9@d27g2000yqf.googlegroups.com> On Mar 12, 4:33?pm, John Bokma wrote: > Hephzibah writes: > > ImportError: No module named numpy > > > Can someone pls. tell me what I'm supposed to do next? > > Install numpy would be my first guess. > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development Thanks so much I've been able to resolve the issue. What I did was to run the program after downloading and installing i. a newer version of Python -version 26 ii. pyPAML iii.numpy iv.matplotlib; all from www.nltk.org. regards, Hephzibah From clp2 at rebertia.com Fri Mar 12 23:47:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Mar 2010 20:47:31 -0800 Subject: python to exe In-Reply-To: <4B9B17B3.8000307@cnsp.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com> <4B9B17B3.8000307@cnsp.com> Message-ID: <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> On Fri, Mar 12, 2010 at 8:42 PM, robin wrote: > On 3/12/2010 9:12 PM, Chris Rebert wrote: >> On Fri, Mar 12, 2010 at 7:26 PM, Robin ?wrote: >>> Does anyone know of a good python to stand alone exe compiler? >>> >> py2exe: >> http://www.py2exe.org/ > > do you ?of an alternate compilter it doesn't work (py2exe) on my windows 7 > box, I hate windows7 THanks Robin Nope; py2exe is pretty much the go-to tool for this. Try asking on their mailinglist: https://lists.sourceforge.net/lists/listinfo/py2exe-users Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 01:47:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 06:47:47 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> Message-ID: <4b9b3513$0$27822$c3e8da3@news.astraweb.com> On Fri, 12 Mar 2010 22:26:34 -0600, John Bokma wrote: > Gabriel Genellina writes: > >> On 13 mar, 00:26, Robin wrote: >> >>> Does anyone know of a good python to stand alone exe compiler? >> >> http://tinyurl.com/yfcfzz4 > > Wow, pathetic fuck. You don't have to post you know. Gabriel is one of the more helpful and newbie-friendly of the frequent posters on this newsgroup. Even if his actions were worthy of your abuse (and they aren't), he gets at least one Get Out Of Jail Free card for his long-term helpfulness. Speaking as somebody who finds Let Me Google That For You to be tiresome and not at all amusing, nevertheless I support Gabriel's actions. By merely giving Robin the answer, Robin doesn't learn how to find out the answer to simple questions himself, and by rewarding his laziness, we make a rod for our own back. As the old proverb goes: give a man a fish, and you feed him for a day. Teach him how to fish, and he has food forever. I'm an old-fashioned kind of guy, and don't like LMGTFY because it is tiresome and requires Javascript. I prefer: Google is your friend: http://www.google.com/search?q=python+standalone+exe Oh, and Robin, since you have apparently already tried py2exe and found it doesn't work on Windows 7, you should have said so from the start, instead of wasting everyone's time. -- Steven From ugocupcic at gmail.com Sat Mar 13 03:04:31 2010 From: ugocupcic at gmail.com (Ugo Cupcic) Date: Sat, 13 Mar 2010 08:04:31 +0000 Subject: question regarding wxSlider In-Reply-To: <8EA74011-1EA0-42CB-BAF5-F9A9F1FF2D16@semanchuk.com> References: <8EA74011-1EA0-42CB-BAF5-F9A9F1FF2D16@semanchuk.com> Message-ID: Hi Philip, Thanks for your redirection. I'll try with them :) Cheers, Ugo PS : yes developing a robotic hand is really fun :D On Fri, Mar 12, 2010 at 7:08 PM, Philip Semanchuk wrote: > On Mar 12, 2010, at 1:56 PM, Ugo Cupcic wrote: > > Hi all, >> >> I have a question regarding wxSlider. I'm developing a wxwidget python >> interface for a robotic hand. The sliders send the target values to the >> joints. >> >> I'd like to display the current position of the joint on the slider. I >> wanted to use wxSlider.SetTick(myposition) but I couldn't get SetTick to >> display anything. >> >> Anyone has an idea ? I attached a dummy code to the message to illustrate. >> > > > Hi Ugo, > I don't mean to chase you away, but there is a dedicated wxPython mailing > list where you obviously have a much better chance of getting an answer. > > http://www.wxpython.org/maillist.php > > Developing a robotic hand sounds like fun! > > Cheers > Philip > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ugo Cupcic http://www.genugo.com/ugocupcic _ ' v ' / \ m m -------------- next part -------------- An HTML attachment was scrubbed... URL: From agoretoy at gmail.com Sat Mar 13 03:42:36 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 13 Mar 2010 02:42:36 -0600 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: I found this to be even better; maybe someone will find this useful, who knows. just export PS1, duh Popen(["bash -c 'export PS1='python'; source $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read() -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From g.bogle at auckland.no.spam.ac.nz Sat Mar 13 04:38:29 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 13 Mar 2010 22:38:29 +1300 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > As the old proverb goes: give a man a fish, and you feed him for a day. > Teach him how to fish, and he has food forever. I like this version: Light a man a fire, and you keep him warm for hours. Set a man on fire, and you keep him warm for the rest of his life. ;-) From dr.cg at 126.com Sat Mar 13 05:02:31 2010 From: dr.cg at 126.com (CHEN Guang) Date: Sat, 13 Mar 2010 18:02:31 +0800 (CST) Subject: python to exe Message-ID: <1e3b567.3797.12756f99dda.Coremail.dr.cg@126.com> >Does anyone know of a good python to stand alone exe compiler? >Thanks, >-Robin I tried several such tools and found the easiest one: Pyinstaller ( http://www.pyinstaller.org/ ) but it does not make your script faster, if you want it as fast as C language, please try PythoidC ( http://pythoidc.googlecode.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Sat Mar 13 05:35:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Mar 2010 11:35:41 +0100 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: * Gib Bogle: > Steven D'Aprano wrote: > >> As the old proverb goes: give a man a fish, and you feed him for a >> day. Teach him how to fish, and he has food forever. > > I like this version: > > Light a man a fire, and you keep him warm for hours. Set a man on fire, > and you keep him warm for the rest of his life. > > ;-) Hey! I was going to post that! And there it was, in the next article... :-) Cheers, - Alf From breamoreboy at yahoo.co.uk Sat Mar 13 05:58:15 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Mar 2010 10:58:15 +0000 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Steven D'Aprano wrote: > >> As the old proverb goes: give a man a fish, and you feed him for a >> day. Teach him how to fish, and he has food forever. > > I like this version: > > Light a man a fire, and you keep him warm for hours. Set a man on fire, > and you keep him warm for the rest of his life. > > ;-) I'm certain that members of the Guinea Pig Club might have something to say on that one, see :- http://en.wikipedia.org/wiki/Guinea_Pig_Club From usenot at geekmail.INVALID Sat Mar 13 06:41:38 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 13 Mar 2010 12:41:38 +0100 Subject: to create variable from dict References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: <20100313124138.6d981759@geekmail.INVALID> On Fri, 12 Mar 2010 06:50:18 -0800 (PST) Luis M. Gonz?lez wrote: > The question is: should you do it? And the answer is: No. And the usual disclaimer is: (Unless you *know* it's the best possible solution to your problem.) /W -- INVALID? DE! From steve at holdenweb.com Sat Mar 13 08:08:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:08:24 -0500 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: alex goretoy wrote: > I found this to be even better; maybe someone will find this useful, who > knows. > just export PS1, duh > Popen(["bash -c 'export PS1='python'; source > $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read() > Try using an interactive shell: >>> from subprocess import * >>> p1 = Popen("bash -i -c alias", stdout=PIPE, shell=True) >>> p1.stdout.read() "alias ls='ls --color=auto'\n" >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sat Mar 13 08:09:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:09:34 -0500 Subject: python to exe In-Reply-To: <87bpes6e4l.fsf@castleamber.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> Message-ID: John Bokma wrote: > Gabriel Genellina writes: > >> On 13 mar, 00:26, Robin wrote: >> >>> Does anyone know of a good python to stand alone exe compiler? >> http://tinyurl.com/... > > Wow, pathetic fuck. You don't have to post you know. > And you don't have to give Google a second chance at indexing the URL, but we all make mistakes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sat Mar 13 08:11:07 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:11:07 -0500 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Steven D'Aprano wrote: > >> As the old proverb goes: give a man a fish, and you feed him for a >> day. Teach him how to fish, and he has food forever. > > I like this version: > > Light a man a fire, and you keep him warm for hours. Set a man on fire, > and you keep him warm for the rest of his life. > > ;-) I like "Give a man a fish, and he eats for a day. Teach a man to fish and he will bore you with stories of the one that got away for the rest of his life". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sat Mar 13 08:15:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:15:49 -0500 Subject: Python for newbies (Pythno users group in Macedonia) In-Reply-To: References: Message-ID: ?????? ??????????? wrote: > Hi all, > we are starting with bi-monthly Python User Group meetings in Skopje, > Macedonia. The meetings are targeted for both beginners and more > experienced users. > > The basic idea is to have an 1 hour presentation at the start for the > beginners and an 1 hour ad-hoc discussion about projects, applications, > interesting stuff etc. > > I'd like to gather some guidance/experince/thoughts about some beginner > oriented python lectures we could use? > > My first idea was to do something like the "Python module of the Week", > but maybe there's a better approach? > > thanks > If you are all English-speakers then perhaps you could consider showing a PyCon video - see http://pycon.blip.tv Good luck with the group. I hope to see PyCon Macedonia emerging before too long! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From vicente.soler at gmail.com Sat Mar 13 08:16:52 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Mar 2010 05:16:52 -0800 (PST) Subject: print formatting Message-ID: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> Hello, My script contains a print statement: print '%40s %15d' % (k, m) However, 1- the string is right adjusted, and I would like it left adjusted 2- the number is a decimal number, and I would like it with the thousands separator and 2 decimals If possible, the thousands separator and the decimal separator should use my local settings. Is there any way to achieve this? From steve at holdenweb.com Sat Mar 13 08:31:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:31:32 -0500 Subject: print formatting In-Reply-To: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> References: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> Message-ID: vsoler wrote: > Hello, > > My script contains a print statement: > > print '%40s %15d' % (k, m) > > However, > > 1- the string is right adjusted, and I would like it left > adjusted > 2- the number is a decimal number, and I would like it with > the thousands separator and 2 decimals > > If possible, the thousands separator and the decimal separator should > use my local settings. > > Is there any way to achieve this? Left-alignment is achieved by using a negative width. You can use the locale module to generate thousands-separated numeric string representations: >>> from locale import * >>> setlocale(LC_ALL, '') # locale is otherwise 'C' 'en_US.UTF-8' >>> locale.format("%12.3f", 123456.789, grouping=False) ' 123456.789' >>> locale.format("%12.3f", 123456.789, grouping=True) ' 123,456.789' regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From __peter__ at web.de Sat Mar 13 08:37:50 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Mar 2010 14:37:50 +0100 Subject: print formatting References: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> Message-ID: vsoler wrote: > My script contains a print statement: > > print '%40s %15d' % (k, m) > > However, > > 1- the string is right adjusted, and I would like it left > adjusted > 2- the number is a decimal number, and I would like it with > the thousands separator and 2 decimals > > If possible, the thousands separator and the decimal separator should > use my local settings. > > Is there any way to achieve this? >>> import locale >>> locale.setlocale(locale.LC_ALL, "") 'de_DE.UTF-8' Traditional: >>> print '%-40s|%15s' % (k, locale.format("%d", m, grouping=True)) hello | 1.234.567 New: >>> "{0:<40} {1:15n}".format(k, m) 'hello 1.234.567' See also: http://docs.python.org/dev/py3k/library/string.html#formatstrings Peter From python at bdurham.com Sat Mar 13 08:45:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 13 Mar 2010 08:45:06 -0500 Subject: python to exe In-Reply-To: <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com><50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com><4B9B17B3.8000307@cnsp.com> <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> Message-ID: <1268487906.15871.1364627963@webmail.messagingengine.com> Robin, > do you of an alternate compilter it doesn't work (py2exe) on my windows 7 box I can assure you that Py2exe does work on Windows 7 (my firm develops commercial Python applications packaged using Py2exe running on Windows 7), but it does take a bit of fiddling and some patience. Join the py2exe newsgroup and post your problems there. https://lists.sourceforge.net/lists/listinfo/py2exe-users You may also want to google 'Gui2exe'. This is a free front-end to Py2exe that you can use to generate your Py2exe setup.py scripts. Note that Gui2exe requires wxPython (free) to run. Finally, make sure you are trying to compile 32-bit Python 2.x code. I don't think py2exe supports Python 3.x or 64-bit versions of Python yet. > Nope; py2exe is pretty much the go-to tool for this. I hear great things about PyInstaller. The project is not dead - make sure you use the latest version in the SVN. Search stackoverflow.com for positive feedback and tips on PyInstaller. Its on our plate to take a good look this product 'one of these days'. Good luck! Malcolm From albert at spenarnc.xs4all.nl Sat Mar 13 09:53:35 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Mar 2010 14:53:35 GMT Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: In article , MRAB wrote: >Zeeshan Quireshi wrote: >> On Mar 3, 6:45 pm, Wells wrote: >>> This seems sort of odd to me: >>> >>>>>> a = 1 >>>>>> a += 1.202 >>>>>> a >>> 2.202 >>> >>> Indicates that 'a' was an int that was implicitly casted to a float. >>> But: >>> >>>>>> a = 1 >>>>>> b = 3 >>>>>> a / b >>> 0 >>> >>> This does not implicitly do the casting, it treats 'a' and 'b' as >>> integers, and the result as well. Changing 'b' to 3.0 will yield a >>> float as a result (0.33333333333333331) >>> >>> Is there some way to explain the consistency here? Does python >>> implicitly change the casting when you add variables of a different >>> numeric type? >>> >>> Anyway, just curiosity more than anything else. Thanks! >> >> Python, like most other languages performs only integer division when >> both the operands are ints. So only if one of the types is a flot or >> you explicitly cast your expression to be a double, then the value >> will be a fraction. otherwise you will the quotient. > >int + int gives int >float + float gives float >int + float gives float You skip a step here that the OP may have missed. a = 1 a += 1.222 This invokes the calculation 1 + 1.222 which is int + float. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From karper12345 at yahoo.com Sat Mar 13 09:55:07 2010 From: karper12345 at yahoo.com (Karjer Jdfjdf) Date: Sat, 13 Mar 2010 06:55:07 -0800 (PST) Subject: Use python and Jython together? (newbie) Message-ID: <254688.8813.qm@web44705.mail.sp1.yahoo.com> I'm pretty new at programming and want some advice on mixing Jython and Python. I want to use Jython to access some Java libraries, but I want to keep developing in normal Python. Some modules I use a lot are not available in Jython. The bulk of my programming is in Python but I want to use Java 2D libraries for graphical presentation of data generated in normal Python. Is it possible that I generate data in Python and then pass it through to a Jython program to visualise the data. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sat Mar 13 10:05:06 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Mar 2010 07:05:06 -0800 (PST) Subject: building a dict Message-ID: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Say that "m" is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a "d" dict where each key has an associated list whose first element is the count, and the second is the sum. If a 2- tuple contains a None value, it should be discarded. The expected result is: d={'as':[2, 9], 'ab': [1,5]} How should I proceed? So far I have been unsuccessful. I have tried with a "for" loop. Thank you for your help From lists at cheimes.de Sat Mar 13 10:10:22 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 13 Mar 2010 16:10:22 +0100 Subject: Use python and Jython together? (newbie) In-Reply-To: <254688.8813.qm@web44705.mail.sp1.yahoo.com> References: <254688.8813.qm@web44705.mail.sp1.yahoo.com> Message-ID: <4B9BAADE.7090208@cheimes.de> Karjer Jdfjdf wrote: > I'm pretty new at programming and want some advice on mixing Jython and Python. > > I want to use Jython to access some Java libraries, but I want to keep developing in normal Python. Some modules I use a lot are not available in Jython. > > The bulk of my programming is in Python but I want to use Java 2D libraries for graphical presentation of data generated in normal Python. Is it possible that I generate data in Python and then pass it through to a Jython program to visualise the data. You can't mix Jython and Python in one program. But you can use other means to create bindings for Java code. JCC (http://pypi.python.org/pypi/JCC/2.5.1) is a very powerful code generator for CPython. Christian From joncle at googlemail.com Sat Mar 13 10:25:45 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 07:25:45 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Message-ID: <7f3ae1a0-5de8-4c98-9eec-086b7d927c5c@t41g2000yqt.googlegroups.com> On 13 Mar, 15:05, vsoler wrote: > Say that "m" is a tuple of 2-tuples > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > and I need to build a "d" dict where each key has an associated list > whose first element is the count, and the second is the sum. If a 2- > tuple contains a None value, it should be discarded. > > The expected result is: > d={'as':[2, 9], 'ab': [1,5]} > > How should I proceed? So far I have been unsuccessful. I have tried > with a "for" loop. > > Thank you for your help Something like: d = defaultdict( lambda: [0,0] ) for key, val in filter(lambda L: not any(i is None for i in L), m): d[key][0] += 1 d[key][1] += val hth Jon From pmaupin at gmail.com Sat Mar 13 10:28:19 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 07:28:19 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Message-ID: <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> On Mar 13, 9:05?am, vsoler wrote: > Say that "m" is a tuple of 2-tuples > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > and I need to build a "d" dict where each key has an associated list > whose first element is the count, and the second is the sum. If a 2- > tuple contains a None value, it should be discarded. > > The expected result is: > d={'as':[2, 9], 'ab': [1,5]} > > How should I proceed? So far I have been unsuccessful. I have tried > with a "for" loop. Post your first try at a for loop, and people might be willing to point out problems, but this is such a basic for loop that it is unlikely that anybody is going to write your ENTIRE homework for you. Regards, Pat From albert at spenarnc.xs4all.nl Sat Mar 13 10:29:54 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Mar 2010 15:29:54 GMT Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: In article <7vj7fdFnnjU1 at mid.individual.net>, Gregory Ewing wrote: >Given some known data/crc pairs, how feasible is it to >figure out the polynomial being used to generate the crc? > >In the case I'm looking at, it appears that the crc >size may be at least 24 bits, so just trying all possible >polynomials probably isn't doable. > >An article I found hints at the possibility of using >GCDs to make the search more efficient, but doesn't go >into any details. Anyone know of any literature about >this? > >If it helps, I have the ability to generate test cases >with known message contents to some extent, although >I don't have complete control over the contents. Also >it's a manual process, so generating large numbers of >them automatically isn't an option. If it is really a CRC, it is doable. You can have an indication, if the intention is to detect machine errors (transmission or disk errors) or they want you to prevent tampering with the file. In the latter case it may be a one-way hash. Then it is near impossible, as this is the design criterion for a one-way hash. >-- >Greg Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From steve at holdenweb.com Sat Mar 13 10:36:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 10:36:46 -0500 Subject: building a dict In-Reply-To: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Message-ID: vsoler wrote: > Say that "m" is a tuple of 2-tuples > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > and I need to build a "d" dict where each key has an associated list > whose first element is the count, and the second is the sum. If a 2- > tuple contains a None value, it should be discarded. > > The expected result is: > d={'as':[2, 9], 'ab': [1,5]} > > How should I proceed? So far I have been unsuccessful. I have tried > with a "for" loop. > > Thank you for your help Here's a fairly simple-minded approach using a defaultdict, which calls the dflt() function to create a value when the key is absent. >>> from collections import defaultdict >>> def dflt(): ... return [0, 0] ... >>> m = (('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) >>> d = defaultdict(dflt) >>> for key, n in m: ... if key is not None and n is not None: ... c, t = d[key] ... d[key] = [c+1, t+n] ... >>> d defaultdict(, {'as': [2, 9], 'ab': [1, 5]}) >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From piet at vanoostrum.org Sat Mar 13 10:41:12 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 13 Mar 2010 16:41:12 +0100 Subject: Ideas for creating processes References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> Message-ID: >>>>> J (J) wrote: >J> And now I'm looking at subprocess and I can set shell=True and it will >J> intrepret special characters like & >J> So could I do something like this: >J> for item in pathlist: >J> subprocess.Popen('rsync command &', shell=True) >J> and simply wait unti they are all done? Using shell=True is often the wrong thing to do. And certainly just to get a process to run in the background. subprocess will run them in the background by default. Besides if you do it in the way you propose you can't wait for them. You can only wait for the shell that starts the rsync, but that will be finished almost immediately. >>> import subprocess >>> p = subprocess.Popen('sleep 1000 &', shell=True) >>> p.wait() 0 >>> The wait() returns immediately. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonaccessoires op http://www.zylja.com From joncle at googlemail.com Sat Mar 13 10:58:02 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 07:58:02 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> Message-ID: <251a5a61-aa10-4050-bc0e-da36aed10697@i25g2000yqm.googlegroups.com> On 13 Mar, 15:28, Patrick Maupin wrote: > On Mar 13, 9:05?am, vsoler wrote: > > > Say that "m" is a tuple of 2-tuples > > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > > and I need to build a "d" dict where each key has an associated list > > whose first element is the count, and the second is the sum. If a 2- > > tuple contains a None value, it should be discarded. > > > The expected result is: > > d={'as':[2, 9], 'ab': [1,5]} > > > How should I proceed? So far I have been unsuccessful. I have tried > > with a "for" loop. > > Post your first try at a for loop, and people might be willing to > point out problems, but this is such a basic for loop that it is > unlikely that anybody is going to write your ENTIRE homework for you. > > Regards, > Pat I was thinking it's possibly homework, but looking at previous posts it's fairly unlikely. (If it is, then mea culpa, but as Steve has replied, I think I'll manage to sleep tonight not worrying about the influx of uneducated, incompetent and otherwise useless developers to the market). However, they're receiving some 'elegant' solutions which no professor (unless they're a star pupil - in which case they wouldn't be asking) would take as having been done by their selves. (Or at least I hope not) But yes, I would certainly be interested in the 'unsuccessful attempt'. (To the OP, do post your attempts, it does give more validity). Cheers, Jon. From dreamscmtr63 at gmail.com Sat Mar 13 11:02:07 2010 From: dreamscmtr63 at gmail.com (earner) Date: Sat, 13 Mar 2010 08:02:07 -0800 (PST) Subject: Work at Home - Earn 50, 000 Weekly Without Investment Its Not A Fake, 100% Earning Guarantee Message-ID: Work at Home - Earn 50,000 Weekly Without Investment Its Not A Fake, 100% Earning Guarantee For Register Click Here To Register Now - Start Earning Instantly! http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com From rurpy at yahoo.com Sat Mar 13 11:13:51 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 08:13:51 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> Message-ID: <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> On Mar 13, 8:28 am, Patrick Maupin wrote: > On Mar 13, 9:05 am, vsoler wrote: > > > Say that "m" is a tuple of 2-tuples > > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > > and I need to build a "d" dict where each key has an associated list > > whose first element is the count, and the second is the sum. If a 2- > > tuple contains a None value, it should be discarded. > > > The expected result is: > > d={'as':[2, 9], 'ab': [1,5]} > > > How should I proceed? So far I have been unsuccessful. I have tried > > with a "for" loop. > > Post your first try at a for loop, and people might be willing to > point out problems, but this is such a basic for loop that it is > unlikely that anybody is going to write your ENTIRE homework for you. This is probably what you (OP) were trying to come up with? [untested] d = {} for item in m: key = m[0]; value = m[1] if key is None or value is None: continue if key not in dict: d[key] = [value] else: d[key].append (value) You can replace the for item in m: key = m[0]; value = m[1] above with for key, value in m: which is a little nicer. However, as other responses point out, when you want to "accumulate" results in a dict, collections.defaultdict should pop into your mind first. From mehgcap at gmail.com Sat Mar 13 11:14:37 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sat, 13 Mar 2010 11:14:37 -0500 Subject: wx error, I suspect my class Message-ID: Hello all, I am trying to make a gui out of xrc and wxpython, but I think my understanding of Python's class/method structure is causing problems. The below code returns an error on the line panel=xrc.XRCCTRL(mf, "dl") The error goes back to wxPython itself and says "attribute error: 'none' type object has no attribute 'FindWindowById'" Here is my complete code: import wx from wx import xrc class myapp(wx.App): def OnInit(self): #load the xrc file res=xrc.XmlResource('dictionary.xrc') #load the frame containing everything else mf=res.LoadFrame(None, "mainframe") #assign all necessary controls to variables (text boxes and buttons) for easier binding #format: varName=xrc.XRCCTRL(parent, IDFromXRCFile) panel=xrc.XRCCTRL(mf, "dl") btn_go=xrc.XRCCTRL(panel, "btn_go") btn_close=xrc.XRCCTRL(panel, "btn_close") #now bind the gui controls to functions mf.Bind(wx.EVT_BUTTON, close, id=xrc.XRCID("btn_close")) mf.Show() #end def OnInit def close(self): mf.Close(True) #end def close #end class myapp win=myapp(False) win.MainLoop() That is all there is to it. I made the xrc file with XRCed, so I know it is properly formatted. I always see Python methods and classes using the "self" keyword, but I never understood why or when to/not to use it. I probably need it in the above code, but I am not sure how to insert it correctly. I have been fighting with this code for the last two days with no progress, so I would greatly appreciate any help you can provide. Thanks. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From joncle at googlemail.com Sat Mar 13 11:19:09 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 08:19:09 -0800 (PST) Subject: Decorator to inject function into __call__ of a class Message-ID: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> This is semi-experimental and I'd appreciate opinions of whether it's the correct design approach or not. It seems like a good idea, but it doesn't mean it is. I have a class 'A', this provides standard support functions and exception handling. I have 'B' and 'C' which specialise upon 'A' What I'd like to achieve is something similar to: @inject(B): def some_function(a, b): pass # something useful The name 'some_function' is completely redundant -- don't need it, don't actually care about the function afterwards, as long as it becomes a __call__ of a 'B' *instance*. I've basically got a huge list of functions, which need to be the callable method of an object, and possibly at run-time, so I don't want to do: class Something(B): def __call__(self, etc.. etc...): pass # do something I've got as far as type(somename, (B,), {}) -- do I then __init__ or __new__ the object or... In short, the function should be the __call__ method of an object that is already __init__'d with the function arguments -- so that when the object is called, I get the result of the the function (based on the objects values). Hope that makes sense, Cheers, Jon. From missive at hotmail.com Sat Mar 13 11:23:07 2010 From: missive at hotmail.com (Lee Harr) Date: Sat, 13 Mar 2010 20:53:07 +0430 Subject: Some PyCon videos won't play Message-ID: I am having a great time watching videos from PyCon. Thanks to everyone who presented, and to those who did such a great job putting the videos up at: http://pycon.blip.tv/ My trouble is that, although most of the videos play perfectly, there are a few that refuse to play at all. Like: Python 101 http://pycon.blip.tv/file/3322312/ Using Python to Create Robotic Simulations for Planetary Exploration http://pycon.blip.tv/file/3332780/ Saturday Morning Lightning talks http://pycon.blip.tv/file/3264041/ Is anyone else having trouble with these? _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. https://signup.live.com/signup.aspx?id=60969 From pmaupin at gmail.com Sat Mar 13 11:26:15 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 08:26:15 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: <83cfee5e-6b6a-41e1-b259-9fdf104423b8@u9g2000yqb.googlegroups.com> On Mar 13, 10:19?am, Jon Clements wrote: > What I'd like to achieve is something similar to: > > @inject(B): > ?def some_function(a, b): > ? ? ?pass # something useful So, just typing at the keyboard here, you mean something like: class InjectClass(object): def __init__(self, func, *args, **kw): self.func = func self.args = args self.kw = kw def __call__(self): self.func(*self.args, **self.kw) Or exactly what are you looking for? Pat From rurpy at yahoo.com Sat Mar 13 11:26:59 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 08:26:59 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> Message-ID: <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> On Mar 13, 9:13?am, ru... at yahoo.com wrote: > On Mar 13, 8:28 am, Patrick Maupin wrote: > > > > > On Mar 13, 9:05 am, vsoler wrote: > > > > Say that "m" is a tuple of 2-tuples > > > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > > > and I need to build a "d" dict where each key has an associated list > > > whose first element is the count, and the second is the sum. If a 2- > > > tuple contains a None value, it should be discarded. > > > > The expected result is: > > > d={'as':[2, 9], 'ab': [1,5]} > > > > How should I proceed? So far I have been unsuccessful. I have tried > > > with a "for" loop. > > > Post your first try at a for loop, and people might be willing to > > point out problems, but this is such a basic for loop that it is > > unlikely that anybody is going to write your ENTIRE homework for you. > > This is probably what you (OP) were trying to come up with? > [untested] > > d = {} > for item in m: > ? ? key = m[0]; ?value = m[1] > ? ? if key is None or value is None: continue > ? ? if key not in dict: > ? ? ? ? d[key] = [value] > ? ? else: > ? ? ? ? d[key].append (value) > > You can replace the > ? for item in m: > ? ? ? key = m[0]; ?value = m[1] > above with > ? for key, value in m: > which is a little nicer. > > However, as other responses point out, when you want > to "accumulate" results in a dict, collections.defaultdict > should pop into your mind first. Oops, didn't read very carefully, did I? That should be: d = {} for item in m: key = m[0]; value = m[1] if key is None or value is None: continue if key not in dict: d[key] = [1, value] else: d[key][0] += 1 d[key][1] += value From joncle at googlemail.com Sat Mar 13 11:38:16 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 08:38:16 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <83cfee5e-6b6a-41e1-b259-9fdf104423b8@u9g2000yqb.googlegroups.com> Message-ID: On 13 Mar, 16:26, Patrick Maupin wrote: > On Mar 13, 10:19?am, Jon Clements wrote: > > > What I'd like to achieve is something similar to: > > > @inject(B): > > ?def some_function(a, b): > > ? ? ?pass # something useful > > So, just typing at the keyboard here, you mean something like: > > class InjectClass(object): > ? ? def __init__(self, func, *args, **kw): > ? ? ? ? self.func = func > ? ? ? ? self.args = args > ? ? ? ? self.kw = kw > ? ? def __call__(self): > ? ? ? ? self.func(*self.args, **self.kw) > > Or exactly what are you looking for? > > Pat Not quite. Let's say I have function 'F': def add(a, b): return a + b And a base class of 'C' which does all the __init__ stuff or whatever's needed, the function 'add' should return a new class __init__'d with a and b, but 'add' should be the __call__ of that instance. Hope that makes sense, and TY for your post, Jon. From jackdied at gmail.com Sat Mar 13 11:42:51 2010 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Mar 2010 11:42:51 -0500 Subject: Decorator to inject function into __call__ of a class In-Reply-To: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > This is semi-experimental and I'd appreciate opinions of whether it's > the correct design approach or not. It seems like a good idea, but it > doesn't mean it is. > > I have a class 'A', this provides standard support functions and > exception handling. > I have 'B' and 'C' which specialise upon 'A' > > What I'd like to achieve is something similar to: > > @inject(B): > ?def some_function(a, b): > ? ? pass # something useful > > The name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > > I've basically got a huge list of functions, which need to be the > callable method of an object, and possibly at run-time, so I don't > want to do: > > class Something(B): > ? ?def __call__(self, etc.. etc...): > ? ? ? ? pass # do something > > I've got as far as type(somename, (B,), {}) -- do I then __init__ or > __new__ the object or... > > In short, the function should be the __call__ method of an object that > is already __init__'d with the function arguments -- so that when the > object is called, I get the result of the the function (based on the > objects values). I'm not sure exactly what you are asking for, but if what you want is a bunch of different objects that vary only by their class's __call__ you could do it with a function that returns a new class based on A but with a new __call__: def make_new_call_class(base_class, call_func): class NewClass(base_class): def __call__(self, *args, **kw): return call_func(self, *args, *kw) return NewClass or the return could even be NewClass() [return an instance] if this is a one off. That said, I'm not really sure what this behavior is good for. -Jack From pmaupin at gmail.com Sat Mar 13 12:03:00 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 09:03:00 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <83cfee5e-6b6a-41e1-b259-9fdf104423b8@u9g2000yqb.googlegroups.com> Message-ID: <7c9e6c13-f388-44b9-8fc3-1faaacd8680a@t23g2000yqt.googlegroups.com> On Mar 13, 10:38?am, Jon Clements wrote: > On 13 Mar, 16:26, Patrick Maupin wrote: > > > > > On Mar 13, 10:19?am, Jon Clements wrote: > > > > What I'd like to achieve is something similar to: > > > > @inject(B): > > > ?def some_function(a, b): > > > ? ? ?pass # something useful > > > So, just typing at the keyboard here, you mean something like: > > > class InjectClass(object): > > ? ? def __init__(self, func, *args, **kw): > > ? ? ? ? self.func = func > > ? ? ? ? self.args = args > > ? ? ? ? self.kw = kw > > ? ? def __call__(self): > > ? ? ? ? self.func(*self.args, **self.kw) > > > Or exactly what are you looking for? > > > Pat > > Not quite. > > Let's say I have function 'F': > > def add(a, b): return a + b > > And a base class of 'C' which does all the __init__ stuff or > whatever's needed, > the function 'add' should return a new class __init__'d with a and b, > but 'add' > should be the __call__ of that instance. > > Hope that makes sense, and TY for your post, > > Jon. Well, you could do it with a class. But if I'm understanding correctly, maybe it's simpler than that: >>> def inject(*args, **kw): ... def wrapper(func): ... def go(): ... return func(*args, **kw) ... return go ... return wrapper ... >>> @inject(20, 22) ... def add(a, b): ... return a + b ... >>> add() 42 From jlundell at pobox.com Sat Mar 13 12:03:36 2010 From: jlundell at pobox.com (JLundell) Date: Sat, 13 Mar 2010 09:03:36 -0800 (PST) Subject: class inheritance Message-ID: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> I've got a subclass of fractions.Fraction called Value; it's a mostly trivial class, except that it overrides __eq__ to mean 'nearly equal'. However, since Fraction's operations result in a Fraction, not a Value, I end up with stuff like this: x = Value(1) + Value(2) where x is now a Fraction, not a Value, and x == y uses Fraction.__eq__ rather than Value.__eq__. This appears to be standard Python behavior (int does the same thing). I've worked around it by overriding __add__, etc, with functions that invoke Fraction but coerce the result. But that's tedious; there are a lot of methods to override. So I'm wondering: is there a more efficient way to accomplish what I'm after? From pmaupin at gmail.com Sat Mar 13 12:09:20 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 09:09:20 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <59af7283-f362-4d1e-92c7-14eab59555dd@g19g2000yqe.googlegroups.com> On Mar 13, 11:03?am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? 7 years ago, I had a similar problem for a different and now obsolete reason. I'm sure my solution could be easily updated though. I wrote code to write a wrapper class. Sort of a meta-module. Original reference here: http://groups.google.com/group/comp.lang.python/browse_frm/thread/1253bbab7dfd4b/59289c16603fb374?hl=en&lnk=gst&q=pmaupin+userint#59289c16603fb374 HTH, Pat From joncle at googlemail.com Sat Mar 13 12:10:02 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 09:10:02 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> On 13 Mar, 16:42, Jack Diederich wrote: > On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > > This is semi-experimental and I'd appreciate opinions of whether it's > > the correct design approach or not. It seems like a good idea, but it > > doesn't mean it is. > > > I have a class 'A', this provides standard support functions and > > exception handling. > > I have 'B' and 'C' which specialise upon 'A' > > > What I'd like to achieve is something similar to: > > > @inject(B): > > ?def some_function(a, b): > > ? ? pass # something useful > > > The name 'some_function' is completely redundant -- don't need it, > > don't actually care about the function afterwards, as long as it > > becomes a __call__ of a 'B' *instance*. > > > I've basically got a huge list of functions, which need to be the > > callable method of an object, and possibly at run-time, so I don't > > want to do: > > > class Something(B): > > ? ?def __call__(self, etc.. etc...): > > ? ? ? ? pass # do something > > > I've got as far as type(somename, (B,), {}) -- do I then __init__ or > > __new__ the object or... > > > In short, the function should be the __call__ method of an object that > > is already __init__'d with the function arguments -- so that when the > > object is called, I get the result of the the function (based on the > > objects values). > > I'm not sure exactly what you are asking for, but if what you want is > a bunch of different objects that vary only by their class's __call__ > you could do it with a function that returns a new class based on A > but with a new __call__: > > def make_new_call_class(base_class, call_func): > ? class NewClass(base_class): > ? ? def __call__(self, *args, **kw): > ? ? ? return call_func(self, *args, *kw) > ? return NewClass > > or the return could even be NewClass() [return an instance] if this is > a one off. > > That said, I'm not really sure what this behavior is good for. > > -Jack Cheers Jack for the response. The behaviour is to not derive from a class, but rather allow the decorators to do so... so I would like to iterate over a list of functions (don't care what they're called) and then inject the function as a method. If needs be at run-time. Say I have 1000 functions (okay, admittedly over quoted), but I don't want every programmer to inherit from 'B' or 'C', but to 'inject'. So the idea is that classes are pre-defined, have predictable behaviour, *except* the __call__ is different. You are correct in this. Why do I want that behaviour? -> - It's easier, no inheriting from a class, when needs not. - Some integrity (anyone can define a function and 'inject' to the Management class) - Easier maintainability - maybe :) for i in function_list: i = inject(function_list) At the end of the day: def blah(x, y, z): pass That should be the callable of the object. Cheers again, Jon. From rurpy at yahoo.com Sat Mar 13 12:16:16 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 09:16:16 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> Message-ID: On Mar 13, 9:26?am, ru... at yahoo.com wrote: > That should be: > d = {} > for item in m: ? ? key = item[0]; ?value = item[1] > ? ? if key is None or value is None: continue > ? ? if key not in dict: > ? ? ? ? d[key] = [1, value] > ? ? else: > ? ? ? ? d[key][0] += 1 > ? ? ? ? d[key][1] += value That's it. Any other mistakes, you find 'em. From jackdied at gmail.com Sat Mar 13 12:37:45 2010 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Mar 2010 12:37:45 -0500 Subject: class inheritance In-Reply-To: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: On Sat, Mar 13, 2010 at 12:03 PM, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? If Fraction.__add__ returns a new object but the subclass Value is compatible (as I would except since it is a sublcass) then just change all references in Franction.__add__ to be more generic, ex/ class Franction(): def __add__(self, other): return self.__classs__(self.denominator + other.denominator) That way if __add__ is called by an instance of a subclass it will return an instance of that subclass. -Jack From jackdied at gmail.com Sat Mar 13 12:42:01 2010 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Mar 2010 12:42:01 -0500 Subject: Decorator to inject function into __call__ of a class In-Reply-To: <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> Message-ID: On Sat, Mar 13, 2010 at 12:10 PM, Jon Clements wrote: > On 13 Mar, 16:42, Jack Diederich wrote: >> On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: >> > This is semi-experimental and I'd appreciate opinions of whether it's >> > the correct design approach or not. It seems like a good idea, but it >> > doesn't mean it is. >> >> > I have a class 'A', this provides standard support functions and >> > exception handling. >> > I have 'B' and 'C' which specialise upon 'A' >> >> > What I'd like to achieve is something similar to: >> >> > @inject(B): >> > ?def some_function(a, b): >> > ? ? pass # something useful >> >> > The name 'some_function' is completely redundant -- don't need it, >> > don't actually care about the function afterwards, as long as it >> > becomes a __call__ of a 'B' *instance*. >> >> > I've basically got a huge list of functions, which need to be the >> > callable method of an object, and possibly at run-time, so I don't >> > want to do: >> >> > class Something(B): >> > ? ?def __call__(self, etc.. etc...): >> > ? ? ? ? pass # do something >> >> > I've got as far as type(somename, (B,), {}) -- do I then __init__ or >> > __new__ the object or... >> >> > In short, the function should be the __call__ method of an object that >> > is already __init__'d with the function arguments -- so that when the >> > object is called, I get the result of the the function (based on the >> > objects values). >> >> I'm not sure exactly what you are asking for, but if what you want is >> a bunch of different objects that vary only by their class's __call__ >> you could do it with a function that returns a new class based on A >> but with a new __call__: >> >> def make_new_call_class(base_class, call_func): >> ? class NewClass(base_class): >> ? ? def __call__(self, *args, **kw): >> ? ? ? return call_func(self, *args, *kw) >> ? return NewClass >> >> or the return could even be NewClass() [return an instance] if this is >> a one off. >> >> That said, I'm not really sure what this behavior is good for. >> >> -Jack > > Cheers Jack for the response. > > The behaviour is to not derive from a class, but rather allow > the decorators to do so... so I would like to iterate over > a list of functions (don't care what they're called) and then > inject the function as a method. If needs be at run-time. > > Say I have 1000 functions (okay, admittedly over quoted), but > I don't want every programmer to inherit from 'B' or 'C', but > to 'inject'. So the idea is that classes are pre-defined, have > predictable behaviour, *except* the __call__ is different. > > You are correct in this. Why do I want that behaviour? -> > > - It's easier, no inheriting from a class, when needs not. > - Some integrity (anyone can define a function and 'inject' to the > Management class) > - Easier maintainability - maybe :) > > for i in function_list: > ? ?i = inject(function_list) > > At the end of the day: > def blah(x, y, z): > ? pass > > That should be the callable of the object. I'm still not sure why you are trying to do this, but you can do it with delegation. Have the parent class's __call__ look for an instance attribute named call_this and then call it, ex/ class A(): def __call__(self, *args, **kw): self.call_this(*args, **kw) # we grab this off the instance ob = A() def my_func(*stuff): pass ob.call_this = my_func -Jack From pmaupin at gmail.com Sat Mar 13 12:44:38 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 09:44:38 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <5e8a6388-7532-4183-a69e-bc4330e34b83@t20g2000yqe.googlegroups.com> On Mar 13, 11:37?am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): > ? def __add__(self, other): > ? ? return self.__classs__(self.denominator + other.denominator) > > That way if __add__ is called by an instance of a subclass it will > return an instance of that subclass. > Yes, I think the OP understands that, and also understands that he would have to do the same thing for __sub__, __div__, __rsub__, __radd__, etc. That's why I suggested that, instead of writing all that tedious code, he could write code that writes the tedious code :-) As Terence Parr of ANTLER fame asks: "Why program by hand in five days what you can spend five years of your life automating?" Pat From martin.schoon at gmail.com Sat Mar 13 13:04:19 2010 From: martin.schoon at gmail.com (Martin =?utf-8?B?U2Now7bDtm4=?=) Date: Sat, 13 Mar 2010 19:04:19 +0100 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: <87aaucxfmk.fsf@crunchbang.Belkin> Mark Lawrence writes: > > I'm certain that members of the Guinea Pig Club might have something > to say on that one, see :- > http://en.wikipedia.org/wiki/Guinea_Pig_Club Interesting. My mum is a retired surgeon and in the mid 1980s she attended a course in plastic surgery and among other things she learnt that plastic surgery got going for real during WWII 'thanks' to all pilots with burns. I have forwarded the link above to her. /Martin From jlundell at pobox.com Sat Mar 13 13:11:15 2010 From: jlundell at pobox.com (JLundell) Date: Sat, 13 Mar 2010 10:11:15 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: On Mar 13, 9:37?am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): > ? def __add__(self, other): > ? ? return self.__classs__(self.denominator + other.denominator) > > That way if __add__ is called by an instance of a subclass it will > return an instance of that subclass. That was my first thought, because I had originally assumed that's the way Fraction worked. However, a) it's easier to do the overriding in my own class than patching Fraction (or at least no harder), and 2) Fraction is only doing the same thing that int does, so it's hard to justify a patch. I think Patrick's solution might be the tidiest one. I'll give it a shot (thanks, Patrick). From python at mrabarnett.plus.com Sat Mar 13 13:13:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Mar 2010 18:13:46 +0000 Subject: Use python and Jython together? (newbie) In-Reply-To: <254688.8813.qm@web44705.mail.sp1.yahoo.com> References: <254688.8813.qm@web44705.mail.sp1.yahoo.com> Message-ID: <4B9BD5DA.1060907@mrabarnett.plus.com> Karjer Jdfjdf wrote: > I'm pretty new at programming and want some advice on mixing Jython and > Python. > > I want to use Jython to access some Java libraries, but I want to keep > developing in normal Python. Some modules I use a lot are not available > in Jython. > > The bulk of my programming is in Python but I want to use Java 2D > libraries for graphical presentation of data generated in normal Python. > Is it possible that I generate data in Python and then pass it through > to a Jython program to visualise the data. > You could have 2 scripts running, one in CPython and the other in Jython, communicating via sockets. You would need to decide on a protocol, perhaps passing the data as strings encoded in UTF-8. From news1234 at free.fr Sat Mar 13 13:45:53 2010 From: news1234 at free.fr (News123) Date: Sat, 13 Mar 2010 19:45:53 +0100 Subject: how to start a python script only once Message-ID: <4b9bdd61$0$22515$426a74cc@news.free.fr> Hi, I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -------------------------- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. sqlite and locking -------------------- quite some time ago I used a mysql table and locking as an inter-host mutex. Perhaps sqlite would be good enough for an inter process mutex for processes on the same host, but I don't know it well enough. interprocess mutex -------------------- well I even don't know whether something like this exists on linux / windows Thanks in advanced for any tips N From john at castleamber.com Sat Mar 13 13:52:39 2010 From: john at castleamber.com (John Bokma) Date: Sat, 13 Mar 2010 12:52:39 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: <87fx443vgo.fsf@castleamber.com> Steven D'Aprano writes: > As the old proverb goes: give a man a fish, and you feed him for a day. > Teach him how to fish, and he has food forever. True, but you don't teach someone fishing by poking an eye out with a fishing rod. > I'm an old-fashioned kind of guy, and don't like LMGTFY because it is > tiresome and requires Javascript. I prefer: My reply had little to do with lmgtfy and all to do with hiding it behind tinyurl. But even then, why not do what you just did: give a URL to google directly. For quite some time I thought that comp.lang.perl.misc was quite unfriendly because of a certain attitude. comp.lang.python was quite a refreshment for a while: very newbie friendly, less pissing contests, etc. (but way more fanboism). Yesterday was a sady day: I finally had to conclude that it was only wishful thinking on my part; there is no difference. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Sat Mar 13 14:01:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Mar 2010 14:01:34 -0500 Subject: Some PyCon videos won't play In-Reply-To: References: Message-ID: On 3/13/2010 11:23 AM, Lee Harr wrote: > > I am having a great time watching videos from PyCon. Thanks to > everyone who presented, and to those who did such a great job > putting the videos up at: http://pycon.blip.tv/ > > My trouble is that, although most of the videos play perfectly, > there are a few that refuse to play at all. Like: > > Python 101 > http://pycon.blip.tv/file/3322312/ > > Using Python to Create Robotic Simulations for Planetary Exploration > http://pycon.blip.tv/file/3332780/ > > Saturday Morning Lightning talks > http://pycon.blip.tv/file/3264041/ > > > Is anyone else having trouble with these? Yes, 'spinner' spins indefinitely, while others load and play. From apt.shansen at gmail.com Sat Mar 13 14:02:34 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 13 Mar 2010 11:02:34 -0800 Subject: Decorator to inject function into __call__ of a class In-Reply-To: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: <7a9c25c21003131102x15f7e98agfc1c6ea73962ead1@mail.gmail.com> On Sat, Mar 13, 2010 at 8:19 AM, Jon Clements wrote: > The name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > Special methods are looked up on the class, not the instance, so you can't dot his. However, from reading this thread, I think you're just a bit hung up on naming: you don't need these random / arbitrary functions to be the __call__ on an instance. You need these functions to be called when said instance is called. The easiest way to do that is simply define on the class: def __call__(self, *args, **kwargs): self.func(*args, **kwargs) Then while you are iterating over your list of a thousand functions and making instances, just assign each instance's func attribute. So, for fn in [function_one, function_two, function_three, function_four]: inst = B() inst.func = fn Now, if you really like the decorator syntax, sure: >> def inject(klass): ... def decorator(fn): ... inst = klass() ... inst.func = fn ... return inst ... return decorator ... >>> class A: ... def __init__(self): ... pass ... def __call__(self, *args, **kwargs): ... self.func(*args, **kwargs) ... >>> @inject(A) ... def test(mmm): ... print mmm ... >>> test <__main__.A instance at 0x1004a4fc8> >>> test("Hello") Hello Now, I don't -fully- understand what you're trying to do so this may not be precisely the right thing, but you should be able to adapt the theory. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Sat Mar 13 14:02:44 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 11:02:44 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> Message-ID: <714d79b0-af65-4ce1-806a-73aa1e9b561d@t20g2000yqe.googlegroups.com> On 13 Mar, 17:42, Jack Diederich wrote: > On Sat, Mar 13, 2010 at 12:10 PM, Jon Clements wrote: > > On 13 Mar, 16:42, Jack Diederich wrote: > >> On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > >> > This is semi-experimental and I'd appreciate opinions of whether it's > >> > the correct design approach or not. It seems like a good idea, but it > >> > doesn't mean it is. > > >> > I have a class 'A', this provides standard support functions and > >> > exception handling. > >> > I have 'B' and 'C' which specialise upon 'A' > > >> > What I'd like to achieve is something similar to: > > >> > @inject(B): > >> > ?def some_function(a, b): > >> > ? ? pass # something useful > > >> > The name 'some_function' is completely redundant -- don't need it, > >> > don't actually care about the function afterwards, as long as it > >> > becomes a __call__ of a 'B' *instance*. > > >> > I've basically got a huge list of functions, which need to be the > >> > callable method of an object, and possibly at run-time, so I don't > >> > want to do: > > >> > class Something(B): > >> > ? ?def __call__(self, etc.. etc...): > >> > ? ? ? ? pass # do something > > >> > I've got as far as type(somename, (B,), {}) -- do I then __init__ or > >> > __new__ the object or... > > >> > In short, the function should be the __call__ method of an object that > >> > is already __init__'d with the function arguments -- so that when the > >> > object is called, I get the result of the the function (based on the > >> > objects values). > > >> I'm not sure exactly what you are asking for, but if what you want is > >> a bunch of different objects that vary only by their class's __call__ > >> you could do it with a function that returns a new class based on A > >> but with a new __call__: > > >> def make_new_call_class(base_class, call_func): > >> ? class NewClass(base_class): > >> ? ? def __call__(self, *args, **kw): > >> ? ? ? return call_func(self, *args, *kw) > >> ? return NewClass > > >> or the return could even be NewClass() [return an instance] if this is > >> a one off. > > >> That said, I'm not really sure what this behavior is good for. > > >> -Jack > > > Cheers Jack for the response. > > > The behaviour is to not derive from a class, but rather allow > > the decorators to do so... so I would like to iterate over > > a list of functions (don't care what they're called) and then > > inject the function as a method. If needs be at run-time. > > > Say I have 1000 functions (okay, admittedly over quoted), but > > I don't want every programmer to inherit from 'B' or 'C', but > > to 'inject'. So the idea is that classes are pre-defined, have > > predictable behaviour, *except* the __call__ is different. > > > You are correct in this. Why do I want that behaviour? -> > > > - It's easier, no inheriting from a class, when needs not. > > - Some integrity (anyone can define a function and 'inject' to the > > Management class) > > - Easier maintainability - maybe :) > > > for i in function_list: > > ? ?i = inject(function_list) > > > At the end of the day: > > def blah(x, y, z): > > ? pass > > > That should be the callable of the object. > > I'm still not sure why you are trying to do this, but you can do it > with delegation. ?Have the parent class's __call__ look for an > instance attribute named call_this and then call it, ex/ > > class A(): > ? def __call__(self, *args, **kw): > ? ? self.call_this(*args, **kw) ?# we grab this off the instance > > ob = A() > def my_func(*stuff): pass > ob.call_this = my_func > > -Jack Jack, thanks very much for your replies -- hugely appreciated. I was delayed by the missus calling me for dinner - I'd forgotten we had a stew going in the slow cooker, and she can't make dumplings to save her life :) If I can re-explain slightly, say I have a class 'compute': class Compute(object): def __init__(self, something): self.something = something # misc other methods here..... then... class ComputeAdd(Compute): pass If I do, @inject def ComputeAdd(fst, snd): return fst + snd The end result should be a new class called ComputeAdd __init__'d with fst and snd, which when called, returns fst + snd. Hope that makes sense. Cheers, Jon. From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 14:23:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 19:23:08 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> Message-ID: <4b9be61c$0$27822$c3e8da3@news.astraweb.com> On Sat, 13 Mar 2010 12:52:39 -0600, John Bokma wrote: > For quite some time I thought that comp.lang.perl.misc was quite > unfriendly because of a certain attitude. comp.lang.python was quite a > refreshment for a while: very newbie friendly, less pissing contests, > etc. (but way more fanboism). > > Yesterday was a sady day: I finally had to conclude that it was only > wishful thinking on my part; there is no difference. You were the first one to inject abuse into this thread. There's a big difference between a mildly sarcastic link and dropping the F-word at one of the more helpful and respected members of the community. Perhaps you are projecting your own hostility and aggro onto others? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 14:48:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 19:48:28 GMT Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> <714d79b0-af65-4ce1-806a-73aa1e9b561d@t20g2000yqe.googlegroups.com> Message-ID: <4b9bec0b$0$27822$c3e8da3@news.astraweb.com> On Sat, 13 Mar 2010 11:02:44 -0800, Jon Clements wrote: > If I can re-explain slightly, say I have a class 'compute': > > class Compute(object): > def __init__(self, something): > self.something = something > # misc other methods here..... > > then... > > class ComputeAdd(Compute): > pass What's the purpose of the do-nothing subclass? > If I do, > > @inject > def ComputeAdd(fst, snd): > return fst + snd > > The end result should be a new class called ComputeAdd __init__'d with > fst and snd, That will cause a TypeError, because ComputeAdd inherits __init__ from Compute, which only takes a single argument. So you can't initialise it with two. > which when called, returns fst + snd. > > Hope that makes sense. None what so ever, even after reading the entire thread :-) Forget about the *mechanism*, and focus on the *result* you want. Let me see if I can guess what result you want. You want to start with a single base class, say Compute as defined above. Then you want to write a function which interacts with Compute somehow, say: def func(self, x, y): return self.something + x + y and wave some sort of magic wand (a decorator? something else?) to get an object x so that: x("a", "b") returns self.something + "a" + "b". Is that right? If not, I have no idea what you want! But if this is what you want, then this is probably the simplest approach: Start by adding delegation to the Compute class: class Compute(object): def __init__(self, something): self.something = something def __call__(self, *args, **kwargs): return self.function(*args, **kwargs) Then you can initialise an instance of Compute, and add a function to it: def func(self, x, y): return self.something + x + y added = Computer("spam") added.function = func And then say: added("ham", "eggs") -> "spamhameggs" You could possibly even turn this into a decorator: # untested def magic(baseclass, *args): instance = baseclass(*args) def decorator(func): instance.function = func return instance return decorator @magic(Compute, "spam") def func(self, x, y): return self.something + x + y func("ham", "eggs") -> "spamhameggs" Hope this helps. -- Steven From martin.hellwig at dcuktec.org Sat Mar 13 15:16:48 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 13 Mar 2010 20:16:48 +0000 Subject: python to exe In-Reply-To: <4b9be61c$0$27822$c3e8da3@news.astraweb.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <4b9be61c$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 03/13/10 19:23, Steven D'Aprano wrote: > On Sat, 13 Mar 2010 12:52:39 -0600, John Bokma wrote: > >> For quite some time I thought that comp.lang.perl.misc was quite >> unfriendly because of a certain attitude. comp.lang.python was quite a >> refreshment for a while: very newbie friendly, less pissing contests, >> etc. (but way more fanboism). >> >> Yesterday was a sady day: I finally had to conclude that it was only >> wishful thinking on my part; there is no difference. > > > You were the first one to inject abuse into this thread. There's a big > difference between a mildly sarcastic link and dropping the F-word at one > of the more helpful and respected members of the community. Perhaps you > are projecting your own hostility and aggro onto others? > > > John's thought process is a slippery slope and I make the same 'mistake' (notice the quotes please :-)) so often it would seem I won't learn it ever. However on the rare occasion I notice that I am making the mistake I say to myself: The view of a number of individuals do NOT necessarily represent the view of the majority unless proven otherwise by that actual majority. -- mph From almar.klein at gmail.com Sat Mar 13 15:17:43 2010 From: almar.klein at gmail.com (Almar Klein) Date: Sat, 13 Mar 2010 21:17:43 +0100 Subject: python to exe In-Reply-To: <1e3b567.3797.12756f99dda.Coremail.dr.cg@126.com> References: <1e3b567.3797.12756f99dda.Coremail.dr.cg@126.com> Message-ID: >Does anyone know of a good python to stand alone exe compiler? > > >Thanks, > >-Robin > I tried several such tools and found the easiest one: Pyinstaller ( > http://www.pyinstaller.org/ ) > Don't forget cx_freeze! I found it to work pretty easy, and it also works for py3k. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sat Mar 13 15:26:45 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 13 Mar 2010 12:26:45 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> On Mar 13, 9:03?am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? It's a tad unfortunately Python doesn't make this easier. If I had to do it more than once I'd probably write a mixin to do it: class ArithmeticSelfCastMixin(object): def __add__(self,other): return self.__class__(super(ArithmeticSelfCastMixin,self).__add__(other) # etc. class Value(ArithmeticSelfCastMixin,fraction.Fraction): pass However, I want to warn you about overriding __eq__ to mean "almost equal": it can have unexpected results so I don't recommend it. Two of the main issues with it are: 1. It violates the transitive property ("If A == B and B == C, then A == C") which most programmers expect to be true. 2. It will give unpredictable results when the objects are used in sets or as dictionary keys. Those thow types expect the transitive property to be true. If you are going to redefine __eq__ to mean "almost equal", then at least define __hash__ to raise NotImplementedError so that Python will refuse to use them in sets or as dictionary keys: def __hash__(self): raise NotImplementedError Carl Banks From mcfletch at vrplumber.com Sat Mar 13 16:12:02 2010 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Sat, 13 Mar 2010 16:12:02 -0500 Subject: Python for newbies (Pythno users group in Macedonia) In-Reply-To: References: Message-ID: <4B9BFFA2.7080305@vrplumber.com> ?????? ??????????? wrote: > Hi all, > we are starting with bi-monthly Python User Group meetings in Skopje, > Macedonia. The meetings are targeted for both beginners and more > experienced users. > ... http://us.pycon.org/2010/conference/schedule/event/108/ HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From vicente.soler at gmail.com Sat Mar 13 16:42:12 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Mar 2010 13:42:12 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> Message-ID: <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> On 13 mar, 18:16, ru... at yahoo.com wrote: > On Mar 13, 9:26?am, ru... at yahoo.com wrote:> That should be: > > d = {} > > for item in m: > > ? ? ? key = item[0]; ?value = item[1] > > > ? ? if key is None or value is None: continue > > ? ? if key not in dict: > > ? ? ? ? d[key] = [1, value] > > ? ? else: > > ? ? ? ? d[key][0] += 1 > > ? ? ? ? d[key][1] += value > > That's it. ?Any other mistakes, you find 'em. Thank you all. Your answers are more than valuable to me. I'll study them carefully, but no doubt, my post has been answered. By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. >From what I see from your posts, you would have preferred that I included in my original post my "for loop", so that the post is not so abstract. I have taken note and I'll make it better next time. Thank you for your help. Vicente Soler From rurpy at yahoo.com Sat Mar 13 17:04:54 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 14:04:54 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> Message-ID: <45fd2042-280c-4b7c-ab1f-54a41f6b0cec@o3g2000yqb.googlegroups.com> On Mar 13, 2:42?pm, vsoler wrote: > By the way, I suppose I am the OP. Since I am not an native English > speaking person, I do not know what it stands for. Perhaps you can > tell me. OP means Original Poster (the person who started the discussion) or sometimes Original Post, depending on context. From g.bogle at auckland.no.spam.ac.nz Sat Mar 13 17:20:15 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sun, 14 Mar 2010 11:20:15 +1300 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Mark Lawrence wrote: > > I'm certain that members of the Guinea Pig Club might have something to > say on that one, see :- > http://en.wikipedia.org/wiki/Guinea_Pig_Club > You mean, something like: "That's not funny"? From waldemar.osuch at gmail.com Sat Mar 13 18:12:11 2010 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Sat, 13 Mar 2010 15:12:11 -0800 (PST) Subject: Use python and Jython together? (newbie) References: <254688.8813.qm@web44705.mail.sp1.yahoo.com> Message-ID: <60f0beb3-5ad9-4b60-8aa3-b225f3c6cf6b@f8g2000yqn.googlegroups.com> On Mar 13, 8:10?am, Christian Heimes wrote: > Karjer Jdfjdf wrote: > > I'm pretty new at programming and want some advice on mixing Jython and Python. > > > I want to use Jython to access some Java libraries, but I want to keep developing in normal Python. Some modules I use a lot are not available in Jython. > > > The bulk of my programming is in Python but I want to use Java 2D libraries for graphical presentation of data generated in normal Python. Is it possible that I generate data in Python and then pass it through to a Jython program to visualise the data. > > You can't mix Jython and Python in one program. But you can use other > means to create bindings for Java code. JCC > (http://pypi.python.org/pypi/JCC/2.5.1) is a very powerful code > generator for CPython. > I have not tried it myself but it seems to be possible. http://jpype.sourceforge.net/ From np.mapn at gmail.com Sat Mar 13 18:21:38 2010 From: np.mapn at gmail.com (np map) Date: Sat, 13 Mar 2010 15:21:38 -0800 (PST) Subject: Clustering and automated configuration & deployment toolkit with Python Message-ID: <003064f8-e559-41e9-8110-11fad8373d09@y17g2000yqd.googlegroups.com> I'd like to write an open source clustering (for computation and general use) and automation of configuration/deployment in Python. It's main purpose is to be used in academic environments. It would be something like running numpy/simpy code (and other custom python code) on a set of machines in a distributed fashion (e.g. splitting tasks, doing certain bits on some machines, other sub-tasks on other machines, etc). The cluster could be used in at least two ways: - submit code/files via a web interface, monitor the task via the web interface and download the results from the master node (user<>web interface<>master) - run code directly from another machine on the cluster (as if it were a subprocess or something like this) Requirements (so far): - support the Ubuntu Linux distribution in the initial iteration - be easy to extend to other OS-es and package managers - try to be 3.x compatible where dual compatibility is possible (2.x and 3.x) - it will support Python 2.5-2.6 - document required changes to the 2.x only code to make it work on 3.x - make it easy to submit code directly from python scripts to the cluster (with the right credentials) - support key based authentication for job submission - should talk to at least one type of RDBMS to store various types of data - the cluster should be able to kill a task on nodes automatically if it executes for too long or requires too much memory (configurable) - should be modular (use automation & configuration or just clustering) Therefore, I'd like to know a few things: Is there a clustering toolkit already available for python? What would the recommended architecture be ? How should the "user" code interface with the clustering system's code? How should the results be stored (at the node and master level)? Should threading be supported in the tasks? How should they be returned to the Master node(s)? (polling, submitted by the nodes, etc) What libraries should be used for this? (e.g. fabric as a library, pyro, etc) Any other suggestions and pieces of advice? Should Fabric be used in this clustering system for automation? If not, what else? Would simply using a wrapper written in python for the 'ssh' app be ok? Would the following architecture be ok? Master: splits tasks into sub-tasks, sends them to nodes - provided the node's load isn't greater than a certain percentage, gets results, stores and provides configuration to nodes, stores results, etc Node: runs code, applies configuration, submits the results to the master, etc If this system actually gets python-level code submission inside, how should it work? The reason I posted this set of questions and ideas is that I'd like this to be as flexible and usable as possible. Thanks. From maymunbeyin at gmail.com Sat Mar 13 19:34:55 2010 From: maymunbeyin at gmail.com (kuru) Date: Sat, 13 Mar 2010 16:34:55 -0800 (PST) Subject: Feeding differeent data types to a class instance? Message-ID: Hi I have couple classes in the form of class Vector: def __init__(self,x,y,z): self.x=x self.y=y self.z=z This works fine for me. However I want to be able to provide a list, tuple as well as individual arguments like below myvec=Vector(1,2,3) This works well However I also want to be able to do vect=[1,2,3] myvec=Vec(vect) I want this class to accept multiple data types but process them as they are same when the classs deals with the instances. thanks From rhodri at wildebst.demon.co.uk Sat Mar 13 19:54:40 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Mar 2010 00:54:40 -0000 Subject: Feeding differeent data types to a class instance? References: Message-ID: On Sun, 14 Mar 2010 00:34:55 -0000, kuru wrote: > Hi > > I have couple classes in the form of > > class Vector: > def __init__(self,x,y,z): > self.x=x > self.y=y > self.z=z > > This works fine for me. However I want to be able to provide a list, > tuple as well as individual arguments like below > > myvec=Vector(1,2,3) > > This works well > > > However I also want to be able to do > > vect=[1,2,3] > > myvec=Vec(vect) You can do something like: class Vector(object): def __init__(self, x, y=None, z=None): if isinstance(x, list): self.x = x[0] self.y = x[1] self.z = x[2] else: self.x = x self.y = y self.z = z but this gets messy quite quickly. The usual wisdom these days is to write yourself a separate class method to create your object from a different type: class Vector(object): ... def __init__ as you did before ... @classmethod def from_list(cls, lst): return cls(lst[0], lst[1], lst[2]) vect = [1,2,3] myvec = Vector.from_list(vect) -- Rhodri James *-* Wildebeeste Herder to the Masses From monaghand.david at gmail.com Sat Mar 13 20:00:16 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Sun, 14 Mar 2010 01:00:16 +0000 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> Message-ID: On Sat, 13 Mar 2010 12:52:39 -0600, John Bokma wrote: >Steven D'Aprano writes: > >> As the old proverb goes: give a man a fish, and you feed him for a day. >> Teach him how to fish, and he has food forever. > >True, but you don't teach someone fishing by poking an eye out with a >fishing rod. > >> I'm an old-fashioned kind of guy, and don't like LMGTFY because it is >> tiresome and requires Javascript. I prefer: > >My reply had little to do with lmgtfy and all to do with hiding it behind >tinyurl. But even then, why not do what you just did: give a URL to >google directly. > >For quite some time I thought that comp.lang.perl.misc was quite >unfriendly because of a certain attitude. comp.lang.python was quite a >refreshment for a while: very newbie friendly, less pissing contests, >etc. (but way more fanboism). > >Yesterday was a sady day: I finally had to conclude that it was only >wishful thinking on my part; there is no difference. There was a time, when the internet was young and most newbies couldn't find their own backsides with both hands, that your conclusions would be well placed.That time has long passed: Newsgroups are a long way down the hierarchy since those times and anyone turning up here nowadays _has_ heard of Google. If they haven't used it, I don't really consider the gentle reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle soul to be on the internet at all; someone might say "Boo" to you at any moment. Beware. DaveM From usenot at geekmail.INVALID Sat Mar 13 20:01:37 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 14 Mar 2010 02:01:37 +0100 Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> Message-ID: <20100314020137.2bb95011@geekmail.INVALID> On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler wrote: > By the way, I suppose I am the OP. Since I am not an native English > speaking person, I do not know what it stands for. Perhaps you can > tell me. > Perhaps you can find out yourself: http://www.urbandictionary.com/define.php?term=op /W -- INVALID? DE! From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 20:23:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Mar 2010 01:23:46 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4b9c3aa2$0$27822$c3e8da3@news.astraweb.com> On Sun, 14 Mar 2010 11:20:15 +1300, Gib Bogle wrote: > Mark Lawrence wrote: >> >> I'm certain that members of the Guinea Pig Club might have something to >> say on that one, see :- >> http://en.wikipedia.org/wiki/Guinea_Pig_Club >> >> > You mean, something like: "That's not funny"? Or possibly "That's hilarious!!!". Gallows humour is sometimes hard to predict. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 20:27:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Mar 2010 01:27:56 GMT Subject: Feeding differeent data types to a class instance? References: Message-ID: <4b9c3b9c$0$27822$c3e8da3@news.astraweb.com> On Sat, 13 Mar 2010 16:34:55 -0800, kuru wrote: > I want this class to accept multiple data types but process them as they > are same when the classs deals with the instances. The usual term for this is "polymorphism". > myvec=Vector(1,2,3) > > vect=[1,2,3] > myvec=Vec(vect) I assume you mean Vector in the last line. I find this the easiest way to handle this situation: class Vector(object, *args): if len(args) == 1: # Assume the caller passed a list argument. args = args[0] x, y, z = args # Unpack the arguments. # then process as normal. -- Steven From jgardner at jonathangardner.net Sun Mar 14 03:42:31 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 13 Mar 2010 23:42:31 -0800 Subject: NoSQL Movement? In-Reply-To: <7xljdx73a9.fsf@ruckus.brouhaha.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> Message-ID: <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: > "D'Arcy J.M. Cain" writes: >> Just curious, what database were you using that wouldn't keep up with >> you? ?I use PostgreSQL and would never consider going back to flat >> files. > > Try making a file with a billion or so names and addresses, then > compare the speed of inserting that many rows into a postgres table > against the speed of copying the file. > Also consider how much work it is to partition data from flat files versus PostgreSQL tables. >> The only thing I can think of that might make flat files faster is >> that flat files are buffered whereas PG guarantees that your >> information is written to disk before returning > > Don't forget all the shadow page operations and the index operations, > and that a lot of these operations require reading as well as writing > remote parts of the disk, so buffering doesn't help avoid every disk > seek. > Plus the fact that your other DB operations slow down under the load. -- Jonathan Gardner jgardner at jonathangardner.net From ahmeterdinc09 at gmail.com Sun Mar 14 04:14:49 2010 From: ahmeterdinc09 at gmail.com (ahmet erdinc yilmaz) Date: Sun, 14 Mar 2010 10:14:49 +0200 Subject: xml-rpc Message-ID: <4B9C9AF9.80609@gmail.com> Hello, Recenetly we are developing a senior project and decide to use xmlrpclib. However I have some questions. In the documentation I could not find any clue about handling requests? Does the server handles each request in a separate thread? Or is there some queuing mechanism for client calls? Thanks in advance. --erdinc From niels.ellegaard at gmail.com Sun Mar 14 04:36:24 2010 From: niels.ellegaard at gmail.com (Niels L. Ellegaard) Date: Sun, 14 Mar 2010 09:36:24 +0100 Subject: Some PyCon videos won't play References: Message-ID: <877hpfwb93.fsf@langager.dbnet.dk> Lee Harr writes: > I am having a great time watching videos from PyCon. Thanks to > everyone who presented, and to those who did such a great job > putting the videos up at: http://pycon.blip.tv/ > > My trouble is that, although most of the videos play perfectly, > there are a few that refuse to play at all. Like: I also had problems playing some of the videos (using gnash), but if you press "files and links", then you can download the talk as an ogv file. Furthermore blip.tv provides an rss-feed with ogv-files for each channel on their site. http://pycon.blip.tv/rss Thanks to the pycon people for putting all their nice videos on the web. Niels From bieffe62 at gmail.com Sun Mar 14 04:51:58 2010 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Sun, 14 Mar 2010 00:51:58 -0800 (PST) Subject: how to start a python script only once References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: On 13 Mar, 19:45, News123 wrote: > Hi, > > I'd like to make sure, that a certain python program will only be run > once per host. (linux/windows) > > so if the program is started a second time it should just terminate and > let the other one run. > > This does not have to be the fastest solution, but it should be reliable. > > I have a few ideas, but wonder, which one is the most common > > My ideas so far: > > pid file and file locking > -------------------------- > create a file like program.pid ?with the pid of the running program an > use file locking to avoid race connditions. > > However I currently don't know how to do file locking under windows > and I don't know how to do file lockng with python and linux. > I'll start googling. > > sqlite and locking > -------------------- > quite some time ago I used a mysql table and locking as an inter-host mutex. > > Perhaps sqlite would be good enough for an inter process mutex for > processes on the same host, but I don't know it well enough. > > interprocess mutex > -------------------- > well I even don't know whether something like this exists on linux / windows > > Thanks in advanced for any tips > > N Apart from file, a portable solution would be to bind to an unused porta and assume that finding the port busy means that your program is already running on the port. On recent python installations there is the multiprocessing module which provides process-level semaphores, but I don't know how portable they are. Ciao ---- FB From breamoreboy at yahoo.co.uk Sun Mar 14 05:14:15 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Mar 2010 09:14:15 +0000 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Mark Lawrence wrote: >> >> I'm certain that members of the Guinea Pig Club might have something >> to say on that one, see :- >> http://en.wikipedia.org/wiki/Guinea_Pig_Club >> > > You mean, something like: "That's not funny"? No, simply a statement. From breamoreboy at yahoo.co.uk Sun Mar 14 05:33:17 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Mar 2010 09:33:17 +0000 Subject: python to exe In-Reply-To: <4b9c3aa2$0$27822$c3e8da3@news.astraweb.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <4b9c3aa2$0$27822$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 14 Mar 2010 11:20:15 +1300, Gib Bogle wrote: > >> Mark Lawrence wrote: >>> I'm certain that members of the Guinea Pig Club might have something to >>> say on that one, see :- >>> http://en.wikipedia.org/wiki/Guinea_Pig_Club >>> >>> >> You mean, something like: "That's not funny"? > > Or possibly "That's hilarious!!!". Gallows humour is sometimes hard to > predict. > > > Thinking about it can be that's not funny or hilarious depending on context, which is rather difficult to give on this internet/webby thingy. From martin.hellwig at dcuktec.org Sun Mar 14 06:17:54 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 14 Mar 2010 10:17:54 +0000 Subject: xml-rpc In-Reply-To: References: Message-ID: On 03/14/10 08:14, ahmet erdinc yilmaz wrote: > Hello, > > Recenetly we are developing a senior project and decide to use xmlrpclib. > However I have some questions. In the documentation I could not find any > clue about > handling requests? Does the server handles each request in a separate > thread? Or is > there some queuing mechanism for client calls? Thanks in advance. > > > --erdinc How I usually tackle stuff like this: [martin at aspire8930 /usr/home/martin]$ python Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import SimpleXMLRPCServer >>> help(SimpleXMLRPCServer) CLASSES BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) SimpleXMLRPCRequestHandler SimpleXMLRPCDispatcher CGIXMLRPCRequestHandler SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) SocketServer.TCPServer(SocketServer.BaseServer) SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) Aah so it is based on SocketServer, lets have a look at that: >>> import SocketServer >>> help(SocketServer) Help on module SocketServer: There are five classes in an inheritance diagram, four of which represent synchronous servers of four types: +------------+ | BaseServer | +------------+ | v +-----------+ +------------------+ | TCPServer |------->| UnixStreamServer | +-----------+ +------------------+ | v +-----------+ +--------------------+ | UDPServer |------->| UnixDatagramServer | +-----------+ +--------------------+ So the base of all these servers is BaseServer, hmm somebody must have a laugh right now :-) Okay lets have a look at that then: >>> import BaseServer Traceback (most recent call last): File "", line 1, in ImportError: No module named BaseServer Hmmm okay, lets have a look at the SocketServer source itself then, but where is it? >>> SocketServer.__file__ '/usr/local/lib/python2.6/SocketServer.pyc' I bet that the non compiled file is in the same directory, let's have a look at it with less. >>> quit() [martin at aspire8930 /usr/home/martin]$ less /usr/local/lib/python2.6/SocketServer.py And there it says among other interesting stuff: # The distinction between handling, getting, processing and # finishing a request is fairly arbitrary. Remember: # # - handle_request() is the top-level call. It calls # select, get_request(), verify_request() and process_request() # - get_request() is different for stream or datagram sockets # - process_request() is the place that may fork a new process # or create a new thread to finish the request # - finish_request() instantiates the request handler class; # this constructor will handle the request all by itself def handle_request(self): """Handle one request, possibly blocking. Respects self.timeout. """ # Support people who used socket.settimeout() to escape # handle_request before self.timeout was available. timeout = self.socket.gettimeout() if timeout is None: timeout = self.timeout elif self.timeout is not None: timeout = min(timeout, self.timeout) fd_sets = select.select([self], [], [], timeout) if not fd_sets[0]: self.handle_timeout() return self._handle_request_noblock() def _handle_request_noblock(self): """Handle one request, without blocking. I assume that select.select has returned that the socket is readable before this function was called, so there should be no risk of blocking in get_request(). """ try: request, client_address = self.get_request() except socket.error: return if self.verify_request(request, client_address): try: self.process_request(request, client_address) except: self.handle_error(request, client_address) self.close_request(request) I leave the remaining parts of your question as an exercise :-) -- mph From hackingkk at gmail.com Sun Mar 14 06:32:30 2010 From: hackingkk at gmail.com (hackingKK) Date: Sun, 14 Mar 2010 16:02:30 +0530 Subject: xml-rpc In-Reply-To: References: Message-ID: <4B9CBB3E.3090902@gmail.com> Instead of using the library directly, isn't python-twisted a better choice? happy hacking. Krishnakant. On Sunday 14 March 2010 03:47 PM, Martin P. Hellwig wrote: > On 03/14/10 08:14, ahmet erdinc yilmaz wrote: >> Hello, >> >> Recenetly we are developing a senior project and decide to use >> xmlrpclib. >> However I have some questions. In the documentation I could not find any >> clue about >> handling requests? Does the server handles each request in a separate >> thread? Or is >> there some queuing mechanism for client calls? Thanks in advance. >> >> >> --erdinc > > How I usually tackle stuff like this: > [martin at aspire8930 /usr/home/martin]$ python > Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) > [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. > >>> import SimpleXMLRPCServer > >>> help(SimpleXMLRPCServer) > > CLASSES > > BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) > SimpleXMLRPCRequestHandler > SimpleXMLRPCDispatcher > CGIXMLRPCRequestHandler > SimpleXMLRPCServer(SocketServer.TCPServer, > SimpleXMLRPCDispatcher) > SocketServer.TCPServer(SocketServer.BaseServer) > SimpleXMLRPCServer(SocketServer.TCPServer, > SimpleXMLRPCDispatcher) > > Aah so it is based on SocketServer, lets have a look at that: > > >>> import SocketServer > >>> help(SocketServer) > Help on module SocketServer: > > > There are five classes in an inheritance diagram, four of which > represent > synchronous servers of four types: > > +------------+ > | BaseServer | > +------------+ > | > v > +-----------+ +------------------+ > | TCPServer |------->| UnixStreamServer | > +-----------+ +------------------+ > | > v > +-----------+ +--------------------+ > | UDPServer |------->| UnixDatagramServer | > +-----------+ +--------------------+ > > So the base of all these servers is BaseServer, hmm somebody must have > a laugh right now :-) > > Okay lets have a look at that then: > > >>> import BaseServer > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named BaseServer > > Hmmm okay, lets have a look at the SocketServer source itself then, > but where is it? > >>> SocketServer.__file__ > '/usr/local/lib/python2.6/SocketServer.pyc' > > I bet that the non compiled file is in the same directory, let's have > a look at it with less. > > >>> quit() > [martin at aspire8930 /usr/home/martin]$ less > /usr/local/lib/python2.6/SocketServer.py > > And there it says among other interesting stuff: > > # The distinction between handling, getting, processing and > # finishing a request is fairly arbitrary. Remember: > # > # - handle_request() is the top-level call. It calls > # select, get_request(), verify_request() and process_request() > # - get_request() is different for stream or datagram sockets > # - process_request() is the place that may fork a new process > # or create a new thread to finish the request > # - finish_request() instantiates the request handler class; > # this constructor will handle the request all by itself > > def handle_request(self): > """Handle one request, possibly blocking. > > Respects self.timeout. > """ > # Support people who used socket.settimeout() to escape > # handle_request before self.timeout was available. > timeout = self.socket.gettimeout() > if timeout is None: > timeout = self.timeout > elif self.timeout is not None: > timeout = min(timeout, self.timeout) > fd_sets = select.select([self], [], [], timeout) > if not fd_sets[0]: > self.handle_timeout() > return > self._handle_request_noblock() > > def _handle_request_noblock(self): > """Handle one request, without blocking. > > I assume that select.select has returned that the socket is > readable before this function was called, so there should be > no risk of blocking in get_request(). > """ > try: > request, client_address = self.get_request() > except socket.error: > return > if self.verify_request(request, client_address): > try: > self.process_request(request, client_address) > except: > self.handle_error(request, client_address) > self.close_request(request) > > > I leave the remaining parts of your question as an exercise :-) > From fetchinson at googlemail.com Sun Mar 14 06:49:08 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 14 Mar 2010 11:49:08 +0100 Subject: how to start a python script only once In-Reply-To: <4b9bdd61$0$22515$426a74cc@news.free.fr> References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: > I'd like to make sure, that a certain python program will only be run > once per host. (linux/windows) > > > so if the program is started a second time it should just terminate and > let the other one run. > > This does not have to be the fastest solution, but it should be reliable. > > > I have a few ideas, but wonder, which one is the most common > > > My ideas so far: > > pid file and file locking > -------------------------- > create a file like program.pid with the pid of the running program an > use file locking to avoid race connditions. > > However I currently don't know how to do file locking under windows > and I don't know how to do file lockng with python and linux. > I'll start googling. This is the variant I'm using frequently too and I'd recommend to you as well. Simple to implement and largely problem-free. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From martin.hellwig at dcuktec.org Sun Mar 14 06:50:21 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 14 Mar 2010 10:50:21 +0000 Subject: xml-rpc In-Reply-To: References: Message-ID: On 03/14/10 10:32, hackingKK wrote: > Instead of using the library directly, > isn't python-twisted a better choice? Why? -- mph From spamfresser at ch3ka.de Sun Mar 14 07:25:35 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 12:25:35 +0100 Subject: I passed a fizzbuzz test but failed at recursion. In-Reply-To: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> References: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Message-ID: Am 10.03.2010 16:55, schrieb Bill: > def fizzbuzz(num): > if num: > if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' > elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' > elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' > else : return fizzbuzz(num-1) + ('%d \n' % num) > return '' > print fizzbuzz(100) While I do understand that this is not a Perl group, and this probably won't help the OP, I just could not resist: for i in range(1,101):print('','fizz')[not i%3]+('','buzz')[not i%5]or i > However, when I try to decipher the logic of the function I imagine > the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". No, the function creates the string from right to left. See: fizzbuzz(100) = fizzbuzz(99) + "buzz \n" = fizzbuzz(98) + "fizz \n" + "buzz \n" ... = fizzbuzz(1) + "2 \n" + "fizz \n" + "4 \n" + "buzz\n " + "fizz \n" + .... + "97 \n" + "98 \n" + "fizz \n" + "buzz \n" = fizzbuzz(0) + "1 \n" + "2 \n" + "fizz \n" + "4 \n" + "buzz\n " + "fizz \n" + .... + "97 \n" + "98 \n" + "fizz \n" + "buzz \n" = " " + "1 \n" + "2 \n" + "fizz \n" + "4 \n" + "buzz\n " + "fizz \n" + .... + "97 \n" + "98 \n" + "fizz \n" + "buzz \n" Regards, Michael From vicente.soler at gmail.com Sun Mar 14 07:34:53 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 14 Mar 2010 04:34:53 -0700 (PDT) Subject: "Breaking" the __main__ script Message-ID: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Hello, I am still learning python, thus developnig small scripts. Some of them consist only of the main module. While testing them (debugging) I sometimes want to stop the script at a certain point, with something like stop, break, end or something similar. What statement can I use? Vicente Soler From breamoreboy at yahoo.co.uk Sun Mar 14 07:53:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Mar 2010 11:53:22 +0000 Subject: "Breaking" the __main__ script In-Reply-To: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like stop, break, end or something similar. > > What statement can I use? > > Vicente Soler Something like import sys sys.exit()? HTH. Mark Lawrence From h.stenstrom at gmail.com Sun Mar 14 07:58:07 2010 From: h.stenstrom at gmail.com (=?ISO-8859-1?Q?Helge_Stenstr=F6m?=) Date: Sun, 14 Mar 2010 04:58:07 -0700 (PDT) Subject: Function that knows its argument's variable name Message-ID: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> I want to write function that prints a value of a variable, for debugging. Like: with myVariable = "parrot" otherVariable = "dead" probe(myVariable) probe(otherVariable) instead of the longer print "myVariable = ", myVariable print "otherVariable = ", otherVariable Is that even possible? The function would look like def probe(var): nameOfVar = someMagic(var) print nameOfVar, " = ", var but can someMagic(var) find the variable name? Is that possible? From spamfresser at ch3ka.de Sun Mar 14 08:20:03 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 13:20:03 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Am 14.03.2010 12:53, schrieb Mark Lawrence: > vsoler wrote: >> I sometimes want to stop the script at a certain point, >> with something like stop, break, end or something similar. >> What statement can I use? > Something like > import sys > sys.exit()? Or just "raise SystemExit", "raise SyntaxError" or any other Exception. But you won't have to: If you use IDLE, you can just set breakpoints in your code: enable the debugger in debug-debugger and set breakpoints via right click in your source file. Or you could use a real debugger, like pdb http://docs.python.org/library/pdb.html HTH, Michael From steve at holdenweb.com Sun Mar 14 08:36:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 08:36:55 -0400 Subject: building a dict In-Reply-To: <20100314020137.2bb95011@geekmail.INVALID> References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> <20100314020137.2bb95011@geekmail.INVALID> Message-ID: Andreas Waldenburger wrote: > On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler > wrote: > >> By the way, I suppose I am the OP. Since I am not an native English >> speaking person, I do not know what it stands for. Perhaps you can >> tell me. >> > Perhaps you can find out yourself: > > http://www.urbandictionary.com/define.php?term=op > Possibly so, and that's a useful site, but I hope you aren't suggesting that Vicente shouldn't have asked. It seemed like a perfectly acceptable question to me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Mar 14 09:03:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 09:03:53 -0400 Subject: Feeding differeent data types to a class instance? In-Reply-To: References: Message-ID: kuru wrote: > Hi > > I have couple classes in the form of > > class Vector: > def __init__(self,x,y,z): > self.x=x > self.y=y > self.z=z > > This works fine for me. However I want to be able to provide a list, > tuple as well as individual arguments like below > > myvec=Vector(1,2,3) > > This works well > > > However I also want to be able to do > > vect=[1,2,3] > > myvec=Vec(vect) > > I want this class to accept multiple data types but process them as > they are same when the classs deals with the instances. > > thanks > > With your existing class you can use Python's ability to transform a list or tuple into individual arguments using the * notation: >>> class Vector: ... def __init__(self,x,y,z): ... self.x=x ... self.y=y ... self.z=z ... >>> vl = [1, 2, 3] >>> v = Vector(*vl) >>> v.x 1 >>> v.y 2 >>> v.z 3 >>> Will this do? It seems much simpler than rewriting an already satisfactory class. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Mar 14 09:07:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 09:07:21 -0400 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Mark Lawrence wrote: > vsoler wrote: >> Hello, >> >> I am still learning python, thus developnig small scripts. >> >> Some of them consist only of the main module. While testing them >> (debugging) I sometimes want to stop the script at a certain point, >> with something like stop, break, end or something similar. >> >> What statement can I use? >> >> Vicente Soler > > Something like > import sys > sys.exit()? > > HTH. I think it's less than likely that it will help, since once sys.exit() is called the program is no longer available for inspection. The OP is probably looking for the "pdb" module in the standard library. The documentation is good enough to get you started. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From usenot at geekmail.INVALID Sun Mar 14 09:28:09 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 14 Mar 2010 14:28:09 +0100 Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> <20100314020137.2bb95011@geekmail.INVALID> Message-ID: <20100314142809.5c456262@geekmail.INVALID> On Sun, 14 Mar 2010 08:36:55 -0400 Steve Holden wrote: > Andreas Waldenburger wrote: > > On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler > > wrote: > > > >> By the way, I suppose I am the OP. Since I am not an native English > >> speaking person, I do not know what it stands for. Perhaps you can > >> tell me. > >> > > Perhaps you can find out yourself: > > > > http://www.urbandictionary.com/define.php?term=op > > > Possibly so, and that's a useful site, but I hope you aren't > suggesting that Vicente shouldn't have asked. It seemed like a > perfectly acceptable question to me. > I was a bit trigger happy there, I admit. But with vocabulary questions like these, my first reflex is to ask the web rather than people, because it's usually quicker than Usenet (albeit often only by a minute or so). I somehow felt the need to bestow that bit of "wisdom" on the world. But yeah, the question is fine, of course. /W -- INVALID? DE! From darcy at druid.net Sun Mar 14 09:55:13 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 14 Mar 2010 09:55:13 -0400 Subject: NoSQL Movement? In-Reply-To: <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> Message-ID: <20100314095513.61b0fbaa.darcy@druid.net> On Sat, 13 Mar 2010 23:42:31 -0800 Jonathan Gardner wrote: > On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: > > "D'Arcy J.M. Cain" writes: > >> Just curious, what database were you using that wouldn't keep up with > >> you? ?I use PostgreSQL and would never consider going back to flat > >> files. > > > > Try making a file with a billion or so names and addresses, then > > compare the speed of inserting that many rows into a postgres table > > against the speed of copying the file. That's a straw man argument. Copying an already built database to another copy of the database won't be significantly longer than copying an already built file. In fact, it's the same operation. > Also consider how much work it is to partition data from flat files > versus PostgreSQL tables. Another straw man. I'm sure you can come up with many contrived examples to show one particular operation faster than another. Benchmark writers (bad ones) do it all the time. I'm saying that in normal, real world situations where you are collecting billions of data points and need to actually use the data that a properly designed database running on a good database engine will generally be better than using flat files. > >> The only thing I can think of that might make flat files faster is > >> that flat files are buffered whereas PG guarantees that your > >> information is written to disk before returning > > > > Don't forget all the shadow page operations and the index operations, > > and that a lot of these operations require reading as well as writing > > remote parts of the disk, so buffering doesn't help avoid every disk > > seek. Not sure what a "shadow page operation" is but index operations are only needed if you have to have fast access to read back the data. If it doesn't matter how long it takes to read the data back then don't index it. I have a hard time believing that anyone would want to save billions of data points and not care how fast they can read selected parts back or organize the data though. > Plus the fact that your other DB operations slow down under the load. Not with the database engines that I use. Sure, speed and load are connected whether you use databases or flat files but a proper database will scale up quite well. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From gatoygata2 at gmail.com Sun Mar 14 10:03:29 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 07:03:29 -0700 (PDT) Subject: "Breaking" the __main__ script References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: On 14 mar, 12:34, vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like ? ?stop, break, end ? or something similar. > > What statement can I use? > > Vicente Soler Hola Vicente, You need a debugger. A practical solution to start with is to use an IDE with an integrated debugger. Stani's Python Editor (SPE) is a lightweight IDE with pdb integrated (with style checker also). It is a very good ide for learning (simple and not cluttered) but also for medium size applications (it is very well designed). atb Joaquin From steve at holdenweb.com Sun Mar 14 10:16:43 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 10:16:43 -0400 Subject: NoSQL Movement? In-Reply-To: <20100314095513.61b0fbaa.darcy@druid.net> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> <20100314095513.61b0fbaa.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > On Sat, 13 Mar 2010 23:42:31 -0800 > Jonathan Gardner wrote: >> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: >>> "D'Arcy J.M. Cain" writes: >>>> Just curious, what database were you using that wouldn't keep up with >>>> you? I use PostgreSQL and would never consider going back to flat >>>> files. >>> Try making a file with a billion or so names and addresses, then >>> compare the speed of inserting that many rows into a postgres table >>> against the speed of copying the file. > > That's a straw man argument. Copying an already built database to > another copy of the database won't be significantly longer than copying > an already built file. In fact, it's the same operation. > >> Also consider how much work it is to partition data from flat files >> versus PostgreSQL tables. > > Another straw man. I'm sure you can come up with many contrived > examples to show one particular operation faster than another. > Benchmark writers (bad ones) do it all the time. I'm saying that in > normal, real world situations where you are collecting billions of data > points and need to actually use the data that a properly designed > database running on a good database engine will generally be better than > using flat files. > >>>> The only thing I can think of that might make flat files faster is >>>> that flat files are buffered whereas PG guarantees that your >>>> information is written to disk before returning >>> Don't forget all the shadow page operations and the index operations, >>> and that a lot of these operations require reading as well as writing >>> remote parts of the disk, so buffering doesn't help avoid every disk >>> seek. > > Not sure what a "shadow page operation" is but index operations are > only needed if you have to have fast access to read back the data. If > it doesn't matter how long it takes to read the data back then don't > index it. I have a hard time believing that anyone would want to save > billions of data points and not care how fast they can read selected > parts back or organize the data though. > >> Plus the fact that your other DB operations slow down under the load. > > Not with the database engines that I use. Sure, speed and load are > connected whether you use databases or flat files but a proper database > will scale up quite well. > A common complaint about large database loads taking a long time comes about because of trying to commit the whole change as a single transaction. Such an approach can indeed causes stresses on the database system, but aren't usually necessary. I don't know about PostgreSQL's capabilities in this area but I do know that Oracle (which claims to be all about performance, though in fact I believe PostgreSQL is its equal in many applications) allows you to switch off the various time-consuming features such as transaction logging in order to make bulk updates faster. I also question how many databases would actually find a need to store addresses for a sixth of the world's population, but this objection is made mostly for comic relief: I understand that tables of such a size are necessary sometimes. There was a talk at OSCON two years ago by someone who was using PostgreSQL to process 15 terabytes of medical data. I'm sure he'd have been interested in suggestions that flat files were the answer to his problem ... Another talk a couple of years before that discussed how PostgreSQL was superior to Oracle in handling a three-terabyte data warehouse (though it conceded Oracle's superiority in handling the production OLTP system on which the warehouse was based - but that's four years ago). http://images.omniti.net/omniti.com/~jesus/misc/BBPostgres.pdf Of course if you only need sequential access to the data then the relational approach may be overkill. I would never argue that relational is the best approach for all data and all applications, but it's often better than its less-informed critics realize. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From news1234 at free.fr Sun Mar 14 10:30:13 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 15:30:13 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4b9cf2f5$0$27865$426a34cc@news.free.fr> Hi Francesco, Francesco Bochicchio wrote: > On 13 Mar, 19:45, News123 wrote: >> Hi, >> >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> I have a few ideas, but wonder, which one is the most common >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. >> >> sqlite and locking >> -------------------- >> quite some time ago I used a mysql table and locking as an inter-host mutex. >> >> Perhaps sqlite would be good enough for an inter process mutex for >> processes on the same host, but I don't know it well enough. >> >> interprocess mutex >> -------------------- >> well I even don't know whether something like this exists on linux / windows >> >> Thanks in advanced for any tips >> >> N > > Apart from file, a portable solution would be to bind to an unused > porta and assume that finding the port busy means that your program is > already running on the port. Yes, this should work. I assume in this case the bind() function would handle the race condition. > > On recent python installations there is the multiprocessing module > which provides process-level semaphores, but I don't know how portable > they are. Yes, there are process level semaphores in multiprocesing, but if I understood well, they would either require a common parent process or one process, which were acting as a manager, but then the question would be how to make sure, that the manager process were started only once. ( bind port? ) From news1234 at free.fr Sun Mar 14 10:32:09 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 15:32:09 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4b9cf369$0$27865$426a34cc@news.free.fr> Hi Daniel, Daniel Fetchinson wrote: >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> >> I have a few ideas, but wonder, which one is the most common >> >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. > > This is the variant I'm using frequently too and I'd recommend to you as well. > Simple to implement and largely problem-free. OK, So I'll just have to look in a piece of code, that performs file locking for windows AND for linux and I should be fine. bye N From darcy at druid.net Sun Mar 14 10:48:10 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 14 Mar 2010 10:48:10 -0400 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> <20100314095513.61b0fbaa.darcy@druid.net> Message-ID: <20100314104810.adc0c61a.darcy@druid.net> On Sun, 14 Mar 2010 10:16:43 -0400 Steve Holden wrote: > A common complaint about large database loads taking a long time comes > about because of trying to commit the whole change as a single > transaction. Such an approach can indeed causes stresses on the database > system, but aren't usually necessary. True. > I don't know about PostgreSQL's capabilities in this area but I do know > that Oracle (which claims to be all about performance, though in fact I > believe PostgreSQL is its equal in many applications) allows you to > switch off the various time-consuming features such as transaction > logging in order to make bulk updates faster. Yes, PostgreSQL has a bulk loading option as well. It's usually useful when you are copying data from one database into another and need to do it quickly. > I also question how many databases would actually find a need to store > addresses for a sixth of the world's population, but this objection is > made mostly for comic relief: I understand that tables of such a size > are necessary sometimes. How about Microsoft storing it's user base? Oh wait, they only store registered users with legitimate copies. Never mind. > Of course if you only need sequential access to the data then the > relational approach may be overkill. I would never argue that relational > is the best approach for all data and all applications, but it's often > better than its less-informed critics realize. As a rule I find that in the real world the larger the dataset the more likely you need a proper database. For smaller datasets it doesn't matter so why not use a DB anyway and be prepared when that "throwaway" system suddenly becomes your company's core application. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From news1234 at free.fr Sun Mar 14 10:52:06 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 15:52:06 +0100 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: <4b9cf816$0$20651$426a74cc@news.free.fr> Hi DUncan, Duncan Booth wrote: > Xah Lee wrote: > >> For example, consider, if you are within world's top 100th user of >> database in terms of database size, such as Google, then it may be >> that the off-the-shelf tools may be limiting. But how many users >> really have such massive size of data? > > You've totally missed the point. It isn't the size of the data you have > today that matters, it's the size of data you could have in several years' > time. > > Maybe today you've got 10 users each with 10 megabytes of data, but you're > aspiring to become the next twitter/facebook or whatever. It's a bit late > as you approach 100 million users (and a petabyte of data) to discover that > your system isn't scalable: scalability needs to be built in from day one. any project/product has to adapt over time. Not using SQL just because your 20 user application with 100 data sets might grow into the worlds biggest database doesn't seem right to me. I strongly believe in not overengineering a product. For anything I do I use the most covnenient python library first. This allows me to have results quicky and to get feedback about the product ASAP. Lateron I switch to the more performant versions. bye N From python at bdurham.com Sun Mar 14 11:03:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 14 Mar 2010 11:03:47 -0400 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <1268579027.18252.1364740493@webmail.messagingengine.com> Michael, > Or you could use a real debugger, like pdb > http://docs.python.org/library/pdb.html Any reason you prefer PDB over WinPDB? http://winpdb.org/ Thanks, Malcolm From news1234 at free.fr Sun Mar 14 11:04:25 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 16:04:25 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4B9CFAF9.1070802@free.fr> Hi Daniel, One more question: Daniel Fetchinson wrote: >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> >> I have a few ideas, but wonder, which one is the most common >> >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. > > This is the variant I'm using frequently too and I'd recommend to you as well. > Simple to implement and largely problem-free. > How do you make sure, that pid which is stored in the pid file does really belong to the correct process and not just to any process, that has by coincidence the same pid? bye N From news1234 at free.fr Sun Mar 14 11:04:25 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 16:04:25 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4B9CFAF9.1070802@free.fr> Hi Daniel, One more question: Daniel Fetchinson wrote: >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> >> I have a few ideas, but wonder, which one is the most common >> >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. > > This is the variant I'm using frequently too and I'd recommend to you as well. > Simple to implement and largely problem-free. > How do you make sure, that pid which is stored in the pid file does really belong to the correct process and not just to any process, that has by coincidence the same pid? bye N From david at boddie.org.uk Sun Mar 14 11:14:27 2010 From: david at boddie.org.uk (David Boddie) Date: Sun, 14 Mar 2010 16:14:27 +0100 Subject: Some PyCon videos won't play References: Message-ID: On Saturday 13 March 2010 20:01, Terry Reedy wrote: > On 3/13/2010 11:23 AM, Lee Harr wrote: >> >> I am having a great time watching videos from PyCon. Thanks to >> everyone who presented, and to those who did such a great job >> putting the videos up at: http://pycon.blip.tv/ >> >> My trouble is that, although most of the videos play perfectly, >> there are a few that refuse to play at all. Like: [...] >> Is anyone else having trouble with these? > > Yes, 'spinner' spins indefinitely, while others load and play. You should still be able to get at the videos themselves by inspecting the page contents, looking for download links like this one: http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv In this case, it's an Ogg Theora video file, so you may want to use a player like VLC to view it: http://www.videolan.org/ David From wolfgang.lipp at gmail.com Sun Mar 14 11:57:36 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sun, 14 Mar 2010 08:57:36 -0700 (PDT) Subject: Is it possible to use re2 from Python? Message-ID: i just discovered http://code.google.com/p/re2, a promising library that uses a long-neglected way (Thompson NFA) to implement a regular expression engine that can be orders of magnitudes faster than the available engines of awk, Perl, or Python. so i downloaded the code and did the usual sudo make install thing. however, that action had seemingly done little more than adding /usr/ local/include/re2/re2.h to my system. there seemed to be some `*.a file in addition, but then what is it with this *.a extension? i would like to use re2 from Python (preferrably Python 3.1) and was excited to see files like make_unicode_groups.py in the distro (maybe just used during the build process?). those however were not deployed on my machine. how can i use re2 from Python? (this message appeared before under http://stackoverflow.com/questions/2439345/is-it-possible-to-use-re2-from-python and, even earlier, http://groups.google.com/group/re2-dev/t/59b78327ec3cca0a) From gherron at islandtraining.com Sun Mar 14 12:45:51 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 14 Mar 2010 09:45:51 -0700 Subject: Function that knows its argument's variable name In-Reply-To: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <4B9D12BF.70307@islandtraining.com> Helge Stenstr?m wrote: > I want to write function that prints a value of a variable, for > debugging. Like: > > with > > myVariable = "parrot" > otherVariable = "dead" > > probe(myVariable) > probe(otherVariable) > > instead of the longer > > print "myVariable = ", myVariable > print "otherVariable = ", otherVariable > > Is that even possible? > > The function would look like > > def probe(var): > nameOfVar = someMagic(var) > print nameOfVar, " = ", var > > but can someMagic(var) find the variable name? Is that possible? > That question really doesn't quite make sense. Consider all the ways such a function can be called: someMagic(42) someMagic(40+2) someMagic(f(123)) someMagic(*argTuple) someMagic(**kwDict) someMagic(array[42]) None of which have a variable name associated with the argument. Yet, the answer to your question is not quite absolutely "no". Python has lots of introspection capabilities, including, perhaps, getting at and parsing the original code to find the call. But there's nothing direct for what you want. Gary Herron From vicente.soler at gmail.com Sun Mar 14 13:17:48 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 14 Mar 2010 10:17:48 -0700 (PDT) Subject: iterator/generator Message-ID: I am working on a script that reads data from an excel workbook. The data is located in a named range whose first row contains the headers. It works!!! I find it superb that python is able to do such things!!! Now my questions. a. My ranges can in practice be quite big, and although I am happy with the speed I get, because I am learning python, I think I could do it still a bit better. I think that the line for i in matriz[1:]: could be improved with an iterator/generator, but I am not quite certain how I should proceed. b. the following lines could be improved by means of a defaultdict, that I know because of a previous post. However you may come up with some other ideas (this b. question is not my main concern, you may discard it if you find the post too long) if i[a] and not(i[a] in g) and i[b]: g[i[a]] = i[b] elif i[a] and (i[a] in g) and i[b]: g[i[a]] += i[b] Can anybody provide some hints? Thank you for your cooperation. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + import win32com.client as win32 def agrupar(matriz, c1, c2): a, b = matriz[0].index(c1), matriz[0].index(c2) g = {} for i in matriz[1:]: if i[a] and not(i[a] in g) and i[b]: g[i[a]] = i[b] elif i[a] and (i[a] in g) and i[b]: g[i[a]] += i[b] for k in g: print '%-50s %15d' % (k, g[k]) # Abrir fichero excel xl = win32.gencache.EnsureDispatch('Excel.Application') ##xl.Visible = True wb=xl.Workbooks.Open(r'C:\Users\Vicente\Documents\VS\Python \Presupuesto fijos 10YP 2011-2020 V0.xls') # Obtenci?n de datos datos=wb.Names('Datos').RefersToRange() print agrupar(datos, u'NomCC', u'BGT-09') # Cerrar libro de trabajo wb.Close() print From steve at holdenweb.com Sun Mar 14 13:49:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 13:49:47 -0400 Subject: iterator/generator In-Reply-To: References: Message-ID: vsoler wrote: > I am working on a script that reads data from an excel workbook. The > data is located in a named range whose first row contains the headers. > It works!!! I find it superb that python is able to do such things!!! > > Now my questions. > > a. My ranges can in practice be quite big, and although I am happy > with the speed I get, because I am learning python, I think I could do > it still a bit better. I think that the line for i in matriz[1:]: > could be improved with an iterator/generator, but I am not quite > certain how I should proceed. > > b. the following lines could be improved by means of a defaultdict, > that I know because of a previous post. However you may come up with > some other ideas (this b. question is not my main concern, you may > discard it if you find the post too long) > > if i[a] and not(i[a] in g) and i[b]: > g[i[a]] = i[b] > elif i[a] and (i[a] in g) and i[b]: > g[i[a]] += i[b] > > Can anybody provide some hints? Thank you for your cooperation. > > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > + > import win32com.client as win32 > > def agrupar(matriz, c1, c2): > a, b = matriz[0].index(c1), matriz[0].index(c2) > g = {} > for i in matriz[1:]: > if i[a] and not(i[a] in g) and i[b]: > g[i[a]] = i[b] > elif i[a] and (i[a] in g) and i[b]: > g[i[a]] += i[b] > for k in g: > print '%-50s %15d' % (k, g[k]) > > # Abrir fichero excel > xl = win32.gencache.EnsureDispatch('Excel.Application') > ##xl.Visible = True > wb=xl.Workbooks.Open(r'C:\Users\Vicente\Documents\VS\Python > \Presupuesto fijos 10YP 2011-2020 V0.xls') > > # Obtenci?n de datos > datos=wb.Names('Datos').RefersToRange() > print > agrupar(datos, u'NomCC', u'BGT-09') > > # Cerrar libro de trabajo > wb.Close() > print Before you go too far down this road (and congratulations, by the way, on having achieved what you already have!) you might like to consider the xlrd, xlwt and xlutils modules. Not only are they easy to use, they are also (I believe) cross-platform and do not require Excel to be loaded on the machine running the programs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From maymunbeyin at gmail.com Sun Mar 14 14:16:50 2010 From: maymunbeyin at gmail.com (kuru) Date: Sun, 14 Mar 2010 11:16:50 -0700 (PDT) Subject: Feeding differeent data types to a class instance? References: Message-ID: <3189fde6-bd5e-4ee2-8a8e-41c55cf9f926@q23g2000yqd.googlegroups.com> Hi Thank you so much for all these great suggestions. I will have time today to try all these and see which one works best for me cheers From kevin.p.dwyer at gmail.com Sun Mar 14 14:18:45 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 14 Mar 2010 18:18:45 +0000 (UTC) Subject: Is it possible to use re2 from Python? References: Message-ID: On Sun, 14 Mar 2010 08:57:36 -0700, _wolf wrote: > > how can i use re2 from Python? > Hello Wolf, There's a recent thread about this on the python-dev list, Unfortunately it seems to suggest that there are no Python bindings at present. Cheers, Kev From CalWhoNOSPAM at roadrunner.com Sun Mar 14 14:20:55 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 14:20:55 -0400 Subject: What does Error: 'module' object is not callable Mean? Message-ID: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what "not callable" means. Could it be referencing to "nn" rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable pylab.show() except ImportError, e: print "Cannot make drawffnet plot." From tartley at tartley.com Sun Mar 14 14:24:07 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Sun, 14 Mar 2010 11:24:07 -0700 (PDT) Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com><50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com><4B9B17B3.8000307@cnsp.com> <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> Message-ID: <78b76065-5fcc-4d00-801c-bed3c8a3a1d7@x12g2000yqx.googlegroups.com> On Mar 13, 1:45?pm, pyt... at bdurham.com wrote: > Robin, > > > do you of an alternate compilter it doesn't work (py2exe) on my windows 7 box > > I can assure you that Py2exe does work on Windows 7 (my firm develops > commercial Python applications packaged using Py2exe running on Windows > 7), but it does take a bit of fiddling and some patience. Join the > py2exe newsgroup and post your problems there.https://lists.sourceforge.net/lists/listinfo/py2exe-users > > You may also want to google 'Gui2exe'. This is a free front-end to > Py2exe that you can use to generate your Py2exe setup.py scripts. Note > that Gui2exe requires wxPython (free) to run. > > Finally, make sure you are trying to compile 32-bit Python 2.x code. I > don't think py2exe supports Python 3.x or 64-bit versions of Python yet. > > > Nope; py2exe is pretty much the go-to tool for this. > > I hear great things about PyInstaller. The project is not dead - make > sure you use the latest version in the SVN. > > Search stackoverflow.com for positive feedback and tips on PyInstaller. > Its on our plate to take a good look this product 'one of these days'. > > Good luck! > > Malcolm I summarised a all the alternatives to py2exe I could find, here: http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Looking for those with a green 'y' in the 'Windows' row, you want to check out cx_freeze, PyInstaller, bbfreeze. Best of luck. From mehgcap at gmail.com Sun Mar 14 14:26:18 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 14:26:18 -0400 Subject: problem with variable and function Message-ID: Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? Thanks! Example: myVar={ 1:myFunc } def myFunc(): myOtherVar=myVar would result in myVar saying myFunc does not exist. Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. I basically cannot win either way, and I need a way to resolve this. If you are curious, the dictionary holds function names and maps to a second dictionary of keystrokes, allowing me to map a keystroke to call a function. Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From python.list at tim.thechases.com Sun Mar 14 14:30:59 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Mar 2010 13:30:59 -0500 Subject: "Breaking" the __main__ script In-Reply-To: <1268579027.18252.1364740493@webmail.messagingengine.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <1268579027.18252.1364740493@webmail.messagingengine.com> Message-ID: <4B9D2B63.8030202@tim.thechases.com> python at bdurham.com wrote: >> Or you could use a real debugger, like pdb >> http://docs.python.org/library/pdb.html > > Any reason you prefer PDB over WinPDB? > http://winpdb.org/ I always count "in the standard library" as a big plus over any add-ons It's nice to know about alternatives such as WinPDB, but everybody that has python also has pdb already installed. -tkc From apt.shansen at gmail.com Sun Mar 14 14:33:34 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 14 Mar 2010 10:33:34 -0800 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: <7a9c25c21003141133x567949b2pf002904e8e22fdf5@mail.gmail.com> On Sun, Mar 14, 2010 at 10:20 AM, Cal Who wrote: > from ffnet.tools import drawffnet > import pylab > drawffnet(nn) #Error: 'module' object is not callable First and foremost, please please please: don't describe or paraphrase tracebacks when asking for help, show them. The whole thing. It doesn't -really- matter here, but it still applies. > That said, "drawffnet" is a module. You can't call -- put () on the end of -- a module. Its not a function. Its a file containing code. Perhaps you mean drawffnet.drawffnet()? --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Sun Mar 14 14:36:34 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 14 Mar 2010 14:36:34 -0400 Subject: python to exe In-Reply-To: <78b76065-5fcc-4d00-801c-bed3c8a3a1d7@x12g2000yqx.googlegroups.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com><50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com><4B9B17B3.8000307@cnsp.com><50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> <78b76065-5fcc-4d00-801c-bed3c8a3a1d7@x12g2000yqx.googlegroups.com> Message-ID: <1268591794.10570.1364759429@webmail.messagingengine.com> Jonathan, > I summarised a all the alternatives to py2exe I could find, here: > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Really great work - thanks for sharing this with all of us!!! Regards, Malcolm From tack at urandom.ca Sun Mar 14 14:40:55 2010 From: tack at urandom.ca (Jason Tackaberry) Date: Sun, 14 Mar 2010 14:40:55 -0400 Subject: problem with variable and function In-Reply-To: References: Message-ID: <1268592055.14177.499.camel@willow> Hi Alex, On Sun, 2010-03-14 at 14:26 -0400, Alex Hall wrote: > Reverse it, though: > > def myFunc(): > myOtherVar=myVar > > myVar={ > 1:myFunc > } > > and the function myFunc does not see the dictionary. The code you provided works just fine (as one would expect). If you can provide an example doesn't work, we should be able to explain why and provide advice. Cheers, Jason. From tjreedy at udel.edu Sun Mar 14 14:41:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 14:41:22 -0400 Subject: Some PyCon videos won't play In-Reply-To: References: Message-ID: On 3/14/2010 11:14 AM, David Boddie wrote: > On Saturday 13 March 2010 20:01, Terry Reedy wrote: > >> On 3/13/2010 11:23 AM, Lee Harr wrote: >>> >>> I am having a great time watching videos from PyCon. Thanks to >>> everyone who presented, and to those who did such a great job >>> putting the videos up at: http://pycon.blip.tv/ >>> >>> My trouble is that, although most of the videos play perfectly, >>> there are a few that refuse to play at all. Like: > > [...] > >>> Is anyone else having trouble with these? >> >> Yes, 'spinner' spins indefinitely, while others load and play. > > You should still be able to get at the videos themselves by inspecting > the page contents, looking for download links like this one: > > http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv > > In this case, it's an Ogg Theora video file, so you may want to use > a player like VLC to view it: For people using html5 competant browsers, which, I believe, play .ogv 'in tha page', blip.tv just needs to update site to make html5 pages an alternative to using the flash player. From benjamin.kaplan at case.edu Sun Mar 14 14:41:25 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 14 Mar 2010 14:41:25 -0400 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: On Sun, Mar 14, 2010 at 2:20 PM, Cal Who wrote: > > The below code produces the error as indicated. But, in > E:\Python26\Lib\site-packages\ffnet\tools I see: > drawffnet.py > drawffnet.pyc > drawffnet.pyo > Is that what it is looking for? > > I'm not sure what "not callable" means. > Could it be referencing to "nn" rather than drawffnet? > What should I do to investigate this? > > Thanks > from ffnet import ffnet, mlgraph, readdata > > ...snipped working code here ... > > output, regression = nn.test(inputs2, targets2, iprint = 2) > > from ffnet.tools import drawffnet > import pylab > drawffnet(nn) #Error: 'module' object is not callable > pylab.show() > except ImportError, e: > print "Cannot make drawffnet plot." > > In Python, everything is an object. Certain objects, like functions, are callable. Other objects, like modules are not. You have a module mapped to the name "drawffnet". Python tries to call that object, but it isn't callable. If there is a function drawffnet inside the drawffnet module (I'm not familiar with the package, so I don't know), you need to call that specifically. drawffnet.drawffnet(nn) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Mar 14 14:46:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Mar 2010 18:46:29 +0000 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: <4B9D2F05.1060101@mrabarnett.plus.com> Cal Who wrote: > The below code produces the error as indicated. But, in > E:\Python26\Lib\site-packages\ffnet\tools I see: > drawffnet.py > drawffnet.pyc > drawffnet.pyo > Is that what it is looking for? > > I'm not sure what "not callable" means. > Could it be referencing to "nn" rather than drawffnet? > What should I do to investigate this? > > Thanks > from ffnet import ffnet, mlgraph, readdata > > ...snipped working code here ... > > output, regression = nn.test(inputs2, targets2, iprint = 2) > > from ffnet.tools import drawffnet > import pylab > drawffnet(nn) #Error: 'module' object is not callable > pylab.show() > except ImportError, e: > print "Cannot make drawffnet plot." > You're importing the module 'drawffnet' and then trying to call it in: drawffnet(nn) but, as the traceback says, modules can't be called. I had a quick look at the documentation and it looks like you should be calling a function called 'drawffnet' that's defined in the module called 'drawffnet'. Try doing: from ffnet.tools.drawffnet import drawffnet instead. From tjreedy at udel.edu Sun Mar 14 14:47:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 14:47:45 -0400 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: On 3/14/2010 2:20 PM, Cal Who wrote: > > The below code produces the error as indicated. But, in > E:\Python26\Lib\site-packages\ffnet\tools I see: > drawffnet.py drawffnet is a module initialized from drawffnet.py (or either of the below) > drawffnet.pyc > drawffnet.pyo > Is that what it is looking for? > > I'm not sure what "not callable" means. > Could it be referencing to "nn" rather than drawffnet? > What should I do to investigate this? > > Thanks > from ffnet import ffnet, mlgraph, readdata > > ...snipped working code here ... > > output, regression = nn.test(inputs2, targets2, iprint = 2) > > from ffnet.tools import drawffnet here you create drawffnet from one of the files. > import pylab > drawffnet(nn) #Error: 'module' object is not callable This is an attempt to call the module as if it were a functions, which it is not. You probably want to call a function within the module. > pylab.show() > except ImportError, e: > print "Cannot make drawffnet plot." > > From clp2 at rebertia.com Sun Mar 14 14:48:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Mar 2010 10:48:18 -0800 Subject: problem with variable and function In-Reply-To: References: Message-ID: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: > Hi all, > I have a file with a dictionary and a function. The dictionary holds > the name of the function, and the function references the dictionary. > If I put the dictionary first, the function is happy but the > dictionary says the function is not defined. If I switch the two and > put the function first, the function says the dictionary does not > exist. Does anyone have an idea as to how I can make both of them > happy? > Reverse it, though: > > def myFunc(): > ?myOtherVar=myVar > > myVar={ > ?1:myFunc > } > > and the function myFunc does not see the dictionary. Please be more specific in what you mean by it not "seeing" the dictionary, because the "reversed" approach *should* work: $ python Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def foo(): ... bar = baz ... print bar ... >>> baz = {1:foo} >>> foo() {1: } Cheers, Chris -- http://blog.rebertia.com From CalWho at roadrunner.com Sun Mar 14 14:57:02 2010 From: CalWho at roadrunner.com (Cal Who) Date: Sun, 14 Mar 2010 14:57:02 -0400 Subject: What does Error: 'module' object is not callable Mean? References: <7a9c25c21003141133x567949b2pf002904e8e22fdf5@mail.gmail.com> Message-ID: <379818115B06492999BA94573F720BCB@dad> ----- Original Message ----- From: Stephen Hansen To: Cal Who Cc: python-list at python.org Sent: Sunday, March 14, 2010 2:33 PM Subject: Re: What does Error: 'module' object is not callable Mean? On Sun, Mar 14, 2010 at 10:20 AM, Cal Who wrote: from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable First and foremost, please please please: don't describe or paraphrase tracebacks when asking for help, show them. The whole thing. It doesn't -really- matter here, but it still applies. I'll keep that in mind but in this instance I simply cut and pasted the message. That said, "drawffnet" is a module. You can't call -- put () on the end of -- a module. Its not a function. Its a file containing code. Perhaps you mean drawffnet.drawffnet()? I copied that code from an example and what you suggested fixed it. Thanks. --S ------------------------------------------------------------------------------ No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2746 - Release Date: 03/14/10 03:33:00 -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sun Mar 14 15:10:32 2010 From: john at castleamber.com (John Bokma) Date: Sun, 14 Mar 2010 13:10:32 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> Message-ID: <87sk82zplj.fsf@castleamber.com> David Monaghan writes: > of Google. If they haven't used it, I don't really consider the gentle > reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle > soul to be on the internet at all; someone might say "Boo" to you at any > moment. Beware. I've no problem with lmgtfy. I *do* have a problem with hiding it behing a tinyurl. Why use 2 levels of obfuscating in a group that's about programming in a language that promotes clear coding? The message would have been the same if the OP had just copy pasted the Google link. But hey, that's way less "funny". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mehgcap at gmail.com Sun Mar 14 15:12:35 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 15:12:35 -0400 Subject: problem with variable and function In-Reply-To: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> References: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> Message-ID: Below is pasted the function which is looking for the "funcs" dictionary, as well as the dictionary. They appear in my py file in this order, yet I get an error in nextMode() that "global name 'funcs' is not defined". Oddly, the keys dictionary works fine; it is defined above the nextMode function. def nextMode(): global HOTKEYS global HOTKEY_ACTIONS global mode global modes global modeNum global modeNames global funcs #mode=mode+1 #check to make sure the newly selected mode is enabled tmp=0 while(tmp wrote: > On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: >> Hi all, >> I have a file with a dictionary and a function. The dictionary holds >> the name of the function, and the function references the dictionary. >> If I put the dictionary first, the function is happy but the >> dictionary says the function is not defined. If I switch the two and >> put the function first, the function says the dictionary does not >> exist. Does anyone have an idea as to how I can make both of them >> happy? > >> Reverse it, though: >> >> def myFunc(): >> ?myOtherVar=myVar >> >> myVar={ >> ?1:myFunc >> } >> >> and the function myFunc does not see the dictionary. > > Please be more specific in what you mean by it not "seeing" the > dictionary, because the "reversed" approach *should* work: > > $ python > Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) > [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> def foo(): > ... bar = baz > ... print bar > ... >>>> baz = {1:foo} >>>> foo() > {1: } > > Cheers, > Chris > -- > http://blog.rebertia.com > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From clp2 at rebertia.com Sun Mar 14 15:24:11 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Mar 2010 11:24:11 -0800 Subject: problem with variable and function In-Reply-To: References: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> Message-ID: <50697b2c1003141224o2b645404u30fbc80140eec6bc@mail.gmail.com> > On 3/14/10, Chris Rebert wrote: >> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: >>> Hi all, >>> I have a file with a dictionary and a function. The dictionary holds >>> the name of the function, and the function references the dictionary. >>> If I put the dictionary first, the function is happy but the >>> dictionary says the function is not defined. If I switch the two and >>> put the function first, the function says the dictionary does not >>> exist. Does anyone have an idea as to how I can make both of them >>> happy? >> >>> Reverse it, though: >>> >>> def myFunc(): >>> myOtherVar=myVar >>> >>> myVar={ >>> 1:myFunc >>> } >>> >>> and the function myFunc does not see the dictionary. >> >> Please be more specific in what you mean by it not "seeing" the >> dictionary, because the "reversed" approach *should* work: >> >> $ python >> Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) >> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> def foo(): >> ... bar = baz >> ... print bar >> ... >>>>> baz = {1:foo} >>>>> foo() >> {1: } On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall wrote: > Below is pasted the function which is looking for the "funcs" > dictionary, as well as the dictionary. They appear in my py file in > this order, yet I get an error in nextMode() that "global name 'funcs' > is not defined". Oddly, the keys dictionary works fine; it is defined > above the nextMode function. Please include the full exception Traceback. Also, please don't top-post in the future. > def nextMode(): > ?global HOTKEYS > ?global HOTKEY_ACTIONS > ?global mode You don't need a `global` declaration unless your function needs to rebind the global variable in question. So you can remove the next 4 global declarations; they're unnecessary. > ?global modes > ?global modeNum > ?global modeNames > ?global funcs > ?#mode=mode+1 > ?#check to make sure the newly selected mode is enabled > ?tmp=0 > ?while(tmp ?mode=(mode+1)%modeNum > ?if(sys.modules[modeNames[mode]].enabled=='True'): > ? break #break on the first enabled mode we find > ?#end if > ?tmp+=1 > ?#end while > ?HOTKEYS=keys[mode] > ?HOTKEY_ACTIONS=funcs[mode] > ?registerHotkeys() > ?speak("Now in "+str(modes[mode])+" mode.") > #end def > > #we now have the default mode to be used, but what if it is disabled? > if(sys.modules[modeNames[mode]].enabled=='False'): > ?nextMode() How is this call supposed to work when `funcs` (which nextMode() uses) hasn't been defined yet?! Cheers, Chris -- http://blog.rebertia.com From yoavglazner at gmail.com Sun Mar 14 15:30:43 2010 From: yoavglazner at gmail.com (Glazner) Date: Sun, 14 Mar 2010 12:30:43 -0700 (PDT) Subject: how to start a python script only once References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: On Mar 13, 8:45?pm, News123 wrote: > Hi, > > I'd like to make sure, that a certain python program will only be run > once per host. (linux/windows) > > so if the program is started a second time it should just terminate and > let the other one run. > > This does not have to be the fastest solution, but it should be reliable. > > I have a few ideas, but wonder, which one is the most common > > My ideas so far: > > pid file and file locking > -------------------------- > create a file like program.pid ?with the pid of the running program an > use file locking to avoid race connditions. > > However I currently don't know how to do file locking under windows > and I don't know how to do file lockng with python and linux. > I'll start googling. > > sqlite and locking > -------------------- > quite some time ago I used a mysql table and locking as an inter-host mutex. > > Perhaps sqlite would be good enough for an inter process mutex for > processes on the same host, but I don't know it well enough. > > interprocess mutex > -------------------- > well I even don't know whether something like this exists on linux / windows > > Thanks in advanced for any tips > > N I'll just open a port with a TCP socket, it is cross-platform and free from race conditions. From mehgcap at gmail.com Sun Mar 14 15:34:20 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 15:34:20 -0400 Subject: problem with variable and function In-Reply-To: <50697b2c1003141224o2b645404u30fbc80140eec6bc@mail.gmail.com> References: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> <50697b2c1003141224o2b645404u30fbc80140eec6bc@mail.gmail.com> Message-ID: >> #we now have the default mode to be used, but what if it is disabled? >> if(sys.modules[modeNames[mode]].enabled=='False'): >> nextMode() > >How is this call supposed to work when `funcs` (which nextMode() uses) >hasn't been defined yet?! That seems to have done it, thanks. Sorry about top-posting; inline posting is much harder to read when using a screen reader, as I do, so I am used to top-posting. On 3/14/10, Chris Rebert wrote: >> On 3/14/10, Chris Rebert wrote: >>> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: >>>> Hi all, >>>> I have a file with a dictionary and a function. The dictionary holds >>>> the name of the function, and the function references the dictionary. >>>> If I put the dictionary first, the function is happy but the >>>> dictionary says the function is not defined. If I switch the two and >>>> put the function first, the function says the dictionary does not >>>> exist. Does anyone have an idea as to how I can make both of them >>>> happy? >>> >>>> Reverse it, though: >>>> >>>> def myFunc(): >>>> myOtherVar=myVar >>>> >>>> myVar={ >>>> 1:myFunc >>>> } >>>> >>>> and the function myFunc does not see the dictionary. >>> >>> Please be more specific in what you mean by it not "seeing" the >>> dictionary, because the "reversed" approach *should* work: >>> >>> $ python >>> Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) >>> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> def foo(): >>> ... bar = baz >>> ... print bar >>> ... >>>>>> baz = {1:foo} >>>>>> foo() >>> {1: } > > On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall wrote: >> Below is pasted the function which is looking for the "funcs" >> dictionary, as well as the dictionary. They appear in my py file in >> this order, yet I get an error in nextMode() that "global name 'funcs' >> is not defined". Oddly, the keys dictionary works fine; it is defined >> above the nextMode function. > > Please include the full exception Traceback. > Also, please don't top-post in the future. > >> def nextMode(): >> ?global HOTKEYS >> ?global HOTKEY_ACTIONS >> ?global mode > > You don't need a `global` declaration unless your function needs to > rebind the global variable in question. > So you can remove the next 4 global declarations; they're unnecessary. > >> ?global modes >> ?global modeNum >> ?global modeNames >> ?global funcs >> ?#mode=mode+1 >> ?#check to make sure the newly selected mode is enabled >> ?tmp=0 >> ?while(tmp> ?mode=(mode+1)%modeNum >> ?if(sys.modules[modeNames[mode]].enabled=='True'): >> ? break #break on the first enabled mode we find >> ?#end if >> ?tmp+=1 >> ?#end while >> ?HOTKEYS=keys[mode] >> ?HOTKEY_ACTIONS=funcs[mode] >> ?registerHotkeys() >> ?speak("Now in "+str(modes[mode])+" mode.") >> #end def >> >> #we now have the default mode to be used, but what if it is disabled? >> if(sys.modules[modeNames[mode]].enabled=='False'): >> ?nextMode() > > How is this call supposed to work when `funcs` (which nextMode() uses) > hasn't been defined yet?! > > Cheers, > Chris > -- > http://blog.rebertia.com > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From spamfresser at ch3ka.de Sun Mar 14 15:35:14 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 20:35:14 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Am 14.03.2010 16:03, schrieb python at bdurham.com: > Any reason you prefer PDB over WinPDB? > http://winpdb.org/ Yes. I don't have Windows except one one PC :P From sivamadana at gmail.com Sun Mar 14 16:01:26 2010 From: sivamadana at gmail.com (siva kumar) Date: Sun, 14 Mar 2010 13:01:26 -0700 (PDT) Subject: messages Message-ID: <0273e5a4-2fed-48bb-a7c9-fbd298cd87dd@b36g2000pri.googlegroups.com> For Good messages please visit http://messagezonehere.blogspot.com/2010/03/friendly-messages.html From monaghand.david at gmail.com Sun Mar 14 16:04:01 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Sun, 14 Mar 2010 20:04:01 +0000 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> Message-ID: On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma wrote: >David Monaghan writes: > >> of Google. If they haven't used it, I don't really consider the gentle >> reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle >> soul to be on the internet at all; someone might say "Boo" to you at any >> moment. Beware. Sorry. That last comment of mine was uncalled for. >I've no problem with lmgtfy. I *do* have a problem with hiding it behing >a tinyurl. Why use 2 levels of obfuscating in a group that's about >programming in a language that promotes clear coding? > >The message would have been the same if the OP had just copy pasted the >Google link. But hey, that's way less "funny". Good point, although one could argue the unhidden response is just rude, but the masking does make it genuinely funny. DaveM From python at bdurham.com Sun Mar 14 16:08:21 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 14 Mar 2010 16:08:21 -0400 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <1268597301.21932.1364768439@webmail.messagingengine.com> >> Any reason you prefer PDB over WinPDB? >> http://winpdb.org/ > Yes. I don't have Windows except one one PC :P WinPDB runs on non-Windows platforms :) Malcolm From ryan at rfk.id.au Sun Mar 14 16:10:10 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 07:10:10 +1100 Subject: sqlite3 is sqlite 2? In-Reply-To: <4B99D5C4.8070100@shopzeus.com> References: <4B99D5C4.8070100@shopzeus.com> Message-ID: <1268597410.2846.5.camel@durian> On Fri, 2010-03-12 at 06:48 +0100, Laszlo Nagy wrote: > gandalf at ubuntu:~$ python > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > >>> sqlite3.version > '2.4.1' > > Is it possible to install a real sqlite version 3 somehow? I really need > it because I have to use savepoint/rollback to. That is only supported > from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know > that is not a question about Python itself. That's the sqlite *bindings* version: >>> sqlite3.version '2.4.1' >>> sqlite3.sqlite_version '3.6.16' >>> So this is "pysqlite" version 2.4.1, which wraps sqlite version 3.6.16. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From john at castleamber.com Sun Mar 14 16:11:18 2010 From: john at castleamber.com (John Bokma) Date: Sun, 14 Mar 2010 14:11:18 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> Message-ID: <87fx42zms9.fsf@castleamber.com> David Monaghan writes: > On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma wrote: > >>David Monaghan writes: >> >>> of Google. If they haven't used it, I don't really consider the gentle >>> reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle >>> soul to be on the internet at all; someone might say "Boo" to you at any >>> moment. Beware. > > Sorry. That last comment of mine was uncalled for. Thanks. >>I've no problem with lmgtfy. I *do* have a problem with hiding it behing >>a tinyurl. Why use 2 levels of obfuscating in a group that's about >>programming in a language that promotes clear coding? >> >>The message would have been the same if the OP had just copy pasted the >>Google link. But hey, that's way less "funny". > > Good point, although one could argue the unhidden response is just rude, but > the masking does make it genuinely funny. One could argue, sure. But to me it's just the same as posting GFY (don't want to upset the tender soulds again with "the F-word". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From gatoygata2 at gmail.com Sun Mar 14 16:11:29 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 13:11:29 -0700 (PDT) Subject: "Breaking" the __main__ script References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <7608c2b5-c7e2-4002-aacd-b4a53c487e54@q23g2000yqd.googlegroups.com> On 14 mar, 20:35, Michael Rudolf wrote: > Am 14.03.2010 16:03, schrieb pyt... at bdurham.com: > > > Any reason you prefer PDB over WinPDB? > >http://winpdb.org/ > > Yes. I don't have Windows except one one PC :P WinPdb is crossplatform. Is build with From john at castleamber.com Sun Mar 14 16:14:32 2010 From: john at castleamber.com (John Bokma) Date: Sun, 14 Mar 2010 14:14:32 -0600 Subject: sqlite3 is sqlite 2? References: Message-ID: <87bpeqzmmv.fsf@castleamber.com> Laszlo Nagy writes: > gandalf at ubuntu:~$ python > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sqlite3 >>>> sqlite3.version > '2.4.1' > > Is it possible to install a real sqlite version 3 somehow? I really > need it because I have to use savepoint/rollback to. That is only > supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu > Karmic? I know that is not a question about Python itself. > > But still, it is interesting that a module named "sqlite3" can > actually be used for something called "sqlite 2". You're mistaking the *module* version with the version of the database, unless I am mistaken. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From gatoygata2 at gmail.com Sun Mar 14 16:18:19 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 13:18:19 -0700 (PDT) Subject: "Breaking" the __main__ script References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <6e5a7393-1ec5-4b60-894b-8574be2fe010@30g2000yqi.googlegroups.com> On 14 mar, 20:35, Michael Rudolf wrote: > Am 14.03.2010 16:03, schrieb pyt... at bdurham.com: > > > Any reason you prefer PDB over WinPDB? > >http://winpdb.org/ > > Yes. I don't have Windows except one one PC :P Sorry, i hit the wrong key. Again: winpdb is crossplatform. It uses a wxwindows gui. Names are not really fortunate... I have installed the last winpdb 1.4.6 in SPE today. atb joaquin From spamfresser at ch3ka.de Sun Mar 14 16:32:30 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 21:32:30 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Am 14.03.2010 21:08, schrieb python at bdurham.com: >>> Any reason you prefer PDB over WinPDB? >>> http://winpdb.org/ >> Yes. I don't have Windows except one one PC :P > WinPDB runs on non-Windows platforms :) Uh, OK. Then the name mislead me ;) But yeah, I prefer a console based debugger. From guillermo.listas at googlemail.com Sun Mar 14 16:40:09 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 13:40:09 -0700 (PDT) Subject: Python unicode and Windows cmd.exe Message-ID: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Hi, I would appreciate if someone could point out what am I doing wrong here. Basically, I need to save a string containing non-ascii characters to a file encoded in utf-8. If I stay in python, everything seems to work fine, but the moment I try to read the file with another Windows program, everything goes to hell. So here's the script unicode2file.py: =================================================================== # encoding=utf-8 import codecs f = codecs.open("m.txt",mode="w", encoding="utf8") a = u"ma?ana" print repr(a) f.write(a) f.close() f = codecs.open("m.txt", mode="r", encoding="utf8") a = f.read() print repr(a) f.close() =================================================================== That gives the expected output, both calls to repr() yield the same result. But now, if I do type me.txt in cmd.exe, I get garbled characters instead of "?". I then open the file with my editor (Sublime Text), and I see "ma?ana" normally. I save (nothing to be saved, really), go back to the dos prompt, do type m.txt and I get again the same garbled characters. I then open the file m.txt with notepad, and I see "ma?ana" normally. I save (again, no actual modifications), go back to the dos prompt, do type m.txt and this time it works! I get "ma?ana". When notepad opens the file, the encoding is already UTF-8, so short of a UTF-8 bom being added to the file, I don't know what happens when I save the unmodified file. Also, I would think that the python script should save a valid utf-8 file in the first place... What's going on here? Regards, Guillermo From vlastimil.brom at gmail.com Sun Mar 14 16:49:56 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 14 Mar 2010 21:49:56 +0100 Subject: Is it possible to use re2 from Python? In-Reply-To: References: Message-ID: <9fdb569a1003141349u6f5eee8fk536cb48f139898c7@mail.gmail.com> 2010/3/14 _wolf : >... > i would like to use re2 from Python (preferrably Python 3.1) and was > excited to see files like make_unicode_groups.py in the distro (maybe > just used during the build process?). those however were not deployed > on my machine. >... > If you would need a re engine with features like unicode rangees, script, and character properties classes and many others, you may try the proposed implementation of the re library currently available in python issue tracker: http://bugs.python.org/issue2636 I am personally more than satisfied with this development version sofar, however, as some new feature like unlimited lookarounds etc. suggest, it is a classic backtracking engine (as opposed to re2, if you need this very implementation). hth vbr From steve at holdenweb.com Sun Mar 14 16:55:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 16:55:20 -0400 Subject: "Breaking" the __main__ script In-Reply-To: <1268597301.21932.1364768439@webmail.messagingengine.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <1268597301.21932.1364768439@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: >>> Any reason you prefer PDB over WinPDB? >>> http://winpdb.org/ > >> Yes. I don't have Windows except one one PC :P > > WinPDB runs on non-Windows platforms :) > One might reasonably argue that it has a pretty couter-intuitive name, then. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From CalWhoNOSPAM at roadrunner.com Sun Mar 14 16:58:54 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 16:58:54 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: Thanks for the replies. That fixed it but produced another problem. There are two plotting routines below. Either one will work without error. But the combo produces: The exception unknown software exception (0x40000015) occurred in the application at location 0x1e05b62a. in a dialog box and the following in the console Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what isa wrong? Second question: Is it common to group all the "from" statements at the top of the program or to put them by the relavent code as I have here? Thanks a lot try: #Or we can use the two commented statements #from ffnet.tools import drawffnet from ffnet.tools.drawffnet import drawffnet import pylab #drawffnet.drawffnet(nn) drawffnet(nn) pylab.show() except ImportError, e: print "Cannot make drawffnet plot.\n%s" % e ? ? # Plot adapted from # http://ffnet.sourceforge.net/examples/stock.html # Make plot if matplotlib is avialble try: from pylab import * plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() except ImportError, e: print "Cannot make plots. For plotting install matplotlib.\n%s" % e ? ? From CalWhoNOSPAM at roadrunner.com Sun Mar 14 17:00:37 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 17:00:37 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: "MRAB" wrote in message news:mailman.745.1268592389.23598.python-list at python.org... > Cal Who wrote: >> The below code produces the error as indicated. But, in >> E:\Python26\Lib\site-packages\ffnet\tools I see: >> drawffnet.py >> drawffnet.pyc >> drawffnet.pyo >> Is that what it is looking for? >> >> I'm not sure what "not callable" means. >> Could it be referencing to "nn" rather than drawffnet? >> What should I do to investigate this? >> >> Thanks >> from ffnet import ffnet, mlgraph, readdata >> >> ...snipped working code here ... >> >> output, regression = nn.test(inputs2, targets2, iprint = 2) >> >> from ffnet.tools import drawffnet >> import pylab >> drawffnet(nn) #Error: 'module' object is not callable >> pylab.show() >> except ImportError, e: >> print "Cannot make drawffnet plot." > You're importing the module 'drawffnet' and then trying to call it in: > > drawffnet(nn) > > but, as the traceback says, modules can't be called. > > I had a quick look at the documentation and it looks like you should be > calling a function called 'drawffnet' that's defined in the module > called 'drawffnet'. Try doing: > > from ffnet.tools.drawffnet import drawffnet > > instead. Thanks, Works great - please see my other post From CalWhoNOSPAM at roadrunner.com Sun Mar 14 17:01:46 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 17:01:46 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: "Terry Reedy" wrote in message news:mailman.746.1268592481.23598.python-list at python.org... > On 3/14/2010 2:20 PM, Cal Who wrote: >> >> The below code produces the error as indicated. But, in >> E:\Python26\Lib\site-packages\ffnet\tools I see: >> drawffnet.py > > drawffnet is a module initialized from drawffnet.py (or either of the > below) > >> drawffnet.pyc >> drawffnet.pyo >> Is that what it is looking for? >> >> I'm not sure what "not callable" means. >> Could it be referencing to "nn" rather than drawffnet? >> What should I do to investigate this? >> >> Thanks >> from ffnet import ffnet, mlgraph, readdata >> >> ...snipped working code here ... >> >> output, regression = nn.test(inputs2, targets2, iprint = 2) >> >> from ffnet.tools import drawffnet > > here you create drawffnet from one of the files. > >> import pylab >> drawffnet(nn) #Error: 'module' object is not callable > > This is an attempt to call the module as if it were a functions, which it > is not. You probably want to call a function within the module. Exactly. Thanks it works now. Please see my other post. > > >> pylab.show() >> except ImportError, e: >> print "Cannot make drawffnet plot." >> >> > > From ryan at rfk.id.au Sun Mar 14 17:04:18 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 08:04:18 +1100 Subject: sqlite savepoint problem (was: Re: sqlite3 is sqlite 2?) In-Reply-To: <4B99E358.4020507@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> Message-ID: <1268600658.2846.17.camel@durian> On Fri, 2010-03-12 at 07:46 +0100, Laszlo Nagy wrote: > > > >>> import sqlite3 > >>> conn = sqlite3.connect(':memory:') > >>> with conn: > ... conn.execute("BEGIN") > ... conn.execute("create table a ( i integer)") > ... conn.execute("insert into a values (1)") > ... conn.execute("savepoint sp1") > ... conn.execute("insert into a values(2)") > ... conn.execute("release sp1") > ... conn.execute("COMMIT") > ... > > > > > > Traceback (most recent call last): > File "", line 7, in > sqlite3.OperationalError: no such savepoint: sp1 > >>> > > The syntax is correct: http://www.sqlite.org/lang_savepoint.html > The savepoint was really created. > But I get this error, telling "no such savepoint". What is wrong here? > Maybe it has to do something with transaction isolation? :-s From memory you can't issue a "CREATE TABLE" statement inside a transaction, at least not at the default isolation level. Such a statement will automatically commit the current transaction. Doesn't help with your current problem but worth pointing out :-) When debugging strange transaction behaviour, I find it easiest to create the connection with isolation_level=None so that are no implicit transactions being created behind your back. Not sure why, but setting this makes your example work for me. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nyamatongwe+thunder at gmail.com Sun Mar 14 17:05:59 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 14 Mar 2010 21:05:59 GMT Subject: Python unicode and Windows cmd.exe In-Reply-To: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: Guillermo: > I then open the file m.txt with notepad, and I see "ma?ana" normally. > I save (again, no actual modifications), go back to the dos prompt, do > type m.txt and this time it works! I get "ma?ana". When notepad opens > the file, the encoding is already UTF-8, so short of a UTF-8 bom being > added to the file, That is what happens: the file now starts with a BOM \xEB\xBB\xBF as you can see with a hex editor. > I don't know what happens when I save the > unmodified file. Also, I would think that the python script should > save a valid utf-8 file in the first place... Its just as valid UTF-8 without a BOM. People have different opinions on this but for compatibility, I think it is best to always start UTF-8 files with a BOM. Neil From clp2 at rebertia.com Sun Mar 14 17:17:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Mar 2010 13:17:55 -0800 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: <50697b2c1003141417q37a0c0dfga6ff3955eb0e42f1@mail.gmail.com> On Sun, Mar 14, 2010 at 12:58 PM, Cal Who wrote: > Second question: Is it common to group all the "from" statements at the top > of the program > or to put them by the relavent code as I have here? The former. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Sun Mar 14 17:19:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 17:19:33 -0400 Subject: Some PyCon videos won't play In-Reply-To: References: Message-ID: On 3/14/2010 2:41 PM, Terry Reedy wrote: > On 3/14/2010 11:14 AM, David Boddie wrote: >> You should still be able to get at the videos themselves by inspecting >> the page contents, looking for download links like this one: >> >> http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv >> >> >> In this case, it's an Ogg Theora video file, so you may want to use >> a player like VLC to view it: > > For people using html5 competant browsers, which, I believe, play .ogv > 'in tha page', blip.tv just needs to update site to make html5 pages an > alternative to using the flash player. Actually, for FF3.6, at least, the problem is already solved. I just click on the download button and FF recognizes .ogv as something it can play and it does, replacing the flash player. The FF player lacks a full-screen button, but that is rarely needed for the talks. tjr From cmpython at gmail.com Sun Mar 14 17:22:22 2010 From: cmpython at gmail.com (CM) Date: Sun, 14 Mar 2010 14:22:22 -0700 (PDT) Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> Message-ID: <806f8246-3b3e-4468-b0e4-3c3f032a6f49@z4g2000yqa.googlegroups.com> On Mar 14, 4:04?pm, David Monaghan wrote: > On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma wrote: > >David Monaghan writes: > > >> of Google. If they haven't used it, I don't really consider the gentle > >> reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle > >> soul to be on the internet at all; someone might say "Boo" to you at any > >> moment. Beware. > > Sorry. That last comment of mine was uncalled for. > > >I've no problem with lmgtfy. I *do* have a problem with hiding it behing > >a tinyurl. Why use 2 levels of obfuscating in a group that's about > >programming in a language that promotes clear coding? > > >The message would have been the same if the OP had just copy pasted the > >Google link. But hey, that's way less "funny". > > Good point, although one could argue the unhidden response is just rude, but > the masking does make it genuinely funny. > > DaveM I thought the point of LMGTFY was to humorously and innocuously get across the point that a lot of basic questions can be answered instantly, or just a few key terms and a mouse click away (i.e. "Was that so hard?") instead of having to write and post a message to a group and then wait for responses. In this sense, using LMGTFY *is* a memorable transmission of information beyond just the answer to the question. It is the meta-information of how to "teach a man to fish". If someone "LMGTFY'ed" me due to my asking a really Googleable question, I'd feel I deserved this gentle ribbing and would make a note to be more diligent in my searches before asking a forum. From guillermo.listas at googlemail.com Sun Mar 14 17:22:46 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 14:22:46 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> > ? ?That is what happens: the file now starts with a BOM \xEB\xBB\xBF as > you can see with a hex editor. Is this an enforced convention under Windows, then? My head's aching after so much pulling at my hair, but I have the feeling that the problem only arises when text travels through the dos console... Cheers, Guillermo From gatoygata2 at gmail.com Sun Mar 14 17:25:12 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 14:25:12 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> Message-ID: <3193c95f-29c3-44e5-9ac9-23e00b3a33ff@m37g2000yqf.googlegroups.com> On 14 mar, 22:22, Guillermo wrote: > > ? ?That is what happens: the file now starts with a BOM \xEB\xBB\xBF as > > you can see with a hex editor. > > Is this an enforced convention under Windows, then? My head's aching > after so much pulling at my hair, but I have the feeling that the > problem only arises when text travels through the dos console... > > Cheers, > Guillermo search for BOM in wikipedia. There it talks about notepad behavior. ja From nyamatongwe+thunder at gmail.com Sun Mar 14 17:35:51 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 14 Mar 2010 21:35:51 GMT Subject: Python unicode and Windows cmd.exe In-Reply-To: <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> Message-ID: Guillermo: > Is this an enforced convention under Windows, then? My head's aching > after so much pulling at my hair, but I have the feeling that the > problem only arises when text travels through the dos console... The console is commonly using Code Page 437 which is most compatible with old DOS programs since it can display line drawing characters. You can change the code page to UTF-8 with chcp 65001 Now, "type m.txt" with the original BOM-less file and it should be OK. You may also need to change the console font to one that is Unicode compatible like Lucida Console. Neil From tjreedy at udel.edu Sun Mar 14 17:37:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 17:37:29 -0400 Subject: Python unicode and Windows cmd.exe In-Reply-To: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: On 3/14/2010 4:40 PM, Guillermo wrote: > Hi, > > I would appreciate if someone could point out what am I doing wrong > here. > > Basically, I need to save a string containing non-ascii characters to > a file encoded in utf-8. > > If I stay in python, everything seems to work fine, but the moment I > try to read the file with another Windows program, everything goes to > hell. > > So here's the script unicode2file.py: > =================================================================== > # encoding=utf-8 > import codecs > > f = codecs.open("m.txt",mode="w", encoding="utf8") > a = u"ma?ana" > print repr(a) > f.write(a) > f.close() > > f = codecs.open("m.txt", mode="r", encoding="utf8") > a = f.read() > print repr(a) > f.close() > =================================================================== > > That gives the expected output, both calls to repr() yield the same > result. > > But now, if I do type me.txt in cmd.exe, I get garbled characters > instead of "?". > > I then open the file with my editor (Sublime Text), and I see "ma?ana" > normally. I save (nothing to be saved, really), go back to the dos > prompt, do type m.txt and I get again the same garbled characters. > > I then open the file m.txt with notepad, and I see "ma?ana" normally. > I save (again, no actual modifications), go back to the dos prompt, do > type m.txt and this time it works! I get "ma?ana". When notepad opens > the file, the encoding is already UTF-8, so short of a UTF-8 bom being There is no such thing as a utf-8 'byte order mark'. The concept is an oxymoron. > added to the file, I don't know what happens when I save the > unmodified file. Also, I would think that the python script should > save a valid utf-8 file in the first place... Adding the byte that some call a 'utf-8 bom' makes the file an invalid utf-8 file. However, I suspect that notepad wrote the file in the system encoding, which can encode n with tilde and which cmd.exe does understand. If you started with a file with encoded cyrillic, arabic, hindi, and chinese characters (for instance), I suspect you would get a different result. tjr From wolfgang.lipp at gmail.com Sun Mar 14 17:40:07 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sun, 14 Mar 2010 14:40:07 -0700 (PDT) Subject: Is it possible to use re2 from Python? References: Message-ID: <827b3e77-6f2a-412f-bfc2-4b7c8747ddcb@g11g2000yqe.googlegroups.com> i am afraid that thread goes straight perpendicular to what re2 is supposed to be, or do. my suggestion for these folks would be to create a new, clean interface to stop the violence that comes with the Python ``re`` interface, and open the thing up so one can plug in ``re`` implementations as are needed. when i absolutely need a feature, i can always go to the slower machine; simpler regular expressions could be dealt with more efficiently. From wolfgang.lipp at gmail.com Sun Mar 14 17:40:34 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sun, 14 Mar 2010 14:40:34 -0700 (PDT) Subject: Is it possible to use re2 from Python? References: Message-ID: <0540f7d0-95f6-4b38-900d-dc25958ff232@g26g2000yqn.googlegroups.com> > There's a recent thread about this on the python-dev list, pointers? i searched but didn?t find anything. From guillermo.listas at googlemail.com Sun Mar 14 17:53:11 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 14:53:11 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> Message-ID: <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> > ? ?The console is commonly using Code Page 437 which is most compatible > with old DOS programs since it can display line drawing characters. You > can change the code page to UTF-8 with > chcp 65001 That's another issue in my actual script. A twofold problem, actually: 1) For me chcp gives 850 and I'm relying on that to decode the bytes I get back from the console. I suppose this is bound to fail because another Windows installation might have a different default codepage. 2) My script gets output from a Popen call (to execute a Powershell script [new Windows shell language] from Python; it does make sense!). I suppose changing the Windows codepage for a single Popen call isn't straightforward/possible? Right now, I only get the desired result if I decode the output from Popen as "cp850". From ryan at rfk.id.au Sun Mar 14 18:13:51 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 09:13:51 +1100 Subject: sqlite savepoint problem In-Reply-To: <4B99F1D1.2070202@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> Message-ID: <1268604831.2846.23.camel@durian> On Fri, 2010-03-12 at 08:48 +0100, Laszlo Nagy wrote: > > > > I'm now confused. Also, I could not find anything about these > > isolation levels on the sqlite website. The only think I could find is > > "PRAGMA read_uncommited". If that is the same as setting > > isolation_level to None, then I don't want it. > Yes, it is. Here is a test: No it isn't. The "magic" behind isolation_level is a creation of the python sqlite bindings. You can probably tell that I'm not a fan of it. > import os > import sqlite3 > import threading > import time > > FPATH = '/tmp/test.sqlite' > if os.path.isfile(FPATH): > os.unlink(FPATH) > > def getconn(): > global FPATH > conn = sqlite3.connect(FPATH) > conn.isolation_level = None > return conn > > class Thr1(threading.Thread): > def run(self): > conn = getconn() > print "Thr1: Inserting 0,1,2,3,4,5" > with conn: > for i in range(6): > conn.execute("insert into a values (?)",[i]) > print "Thr1: Commited" > with conn: > print "Thr1: Selecting all rows:" > for row in conn.execute("select * from a"): > print row > print "Thr1: Wait some..." > time.sleep(3) > print "Thr1: Selecting again, in the same transaction" > for row in conn.execute("select * from a"): > print row > > > class Thr2(threading.Thread): > def run(self): > conn = getconn() > with conn: > print "Thr2: deleting all rows from a" > conn.execute("delete from a") > print "Thr2: Now we wait some BEFORE commiting changes." > time.sleep(3) > print "Thr2: Will roll back!" > raise Exception > > > def main(): > with getconn() as conn: > conn.execute("create table a ( i integer ) ") > thr1 = Thr1() > thr1.start() > time.sleep(1) > thr1 = Thr2() > thr1.start() > > main() > > > And the test result: > > Thr1: Inserting 0,1,2,3,4,5 > Thr1: Commited > Thr1: Selecting all rows: > (0,) > (1,) > (2,) > (3,) > (4,) > (5,) > Thr1: Wait some... > Thr2: deleting all rows from a > Thr2: Now we wait some BEFORE commiting changes. > Thr1: Selecting again, in the same transaction > Thr2: Will roll back! > Exception in thread Thread-2: > Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner > self.run() > File "test.py", line 44, in run > raise Exception > Exception > > > It means that setting isolation_level to None will really allow > uncommited changes to be read by other transactions! This is sad, and of > course this is something that I do not want. No it doesn't. The problem is that using a connection as a context manager doesn't do what you think. It does *not* start a new transaction on __enter__ and commit it on __exit__. As far as I can tell it does nothing on __enter__ and calls con.commit() or con.rollback() on exit. With isolation_level=None, these are no-ops. If you create your own connection wrapper that explicitly creates and commits transactions, you example will work fine with isolation_level=None. Here's the relevant changes: class MyConn(sqlite3.Connection): def __enter__(self): self.execute("BEGIN") return self def __exit__(self,exc_type,exc_info,traceback): if exc_type is None: self.execute("COMMIT") else: self.execute("ROLLBACK") def getconn(): global FPATH conn = sqlite3.connect(FPATH,factory=MyConn) conn.isolation_level = None return conn Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nyamatongwe+thunder at gmail.com Sun Mar 14 18:15:41 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 14 Mar 2010 22:15:41 GMT Subject: Python unicode and Windows cmd.exe In-Reply-To: <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> Message-ID: Guillermo: > 2) My script gets output from a Popen call (to execute a Powershell > script [new Windows shell language] from Python; it does make sense!). > I suppose changing the Windows codepage for a single Popen call isn't > straightforward/possible? You could try SetConsoleOutputCP and SetConsoleCP. Neil From guillermo.listas at googlemail.com Sun Mar 14 18:21:11 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 15:21:11 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> Message-ID: <7f81925a-01f3-4d69-b67e-725bd176e440@z4g2000yqa.googlegroups.com> > 2) My script gets output from a Popen call (to execute a Powershell > script [new Windows shell language] from Python; it does make sense!). > I suppose changing the Windows codepage for a single Popen call isn't > straightforward/possible? Nevermind. I'm able to change Windows' codepage to 65001 from within the Powershell script and I get back a string encoded in UTF-8 with BOM, so problem solved! Thanks for the help, Guillermo From CalWhoNOSPAM at roadrunner.com Sun Mar 14 18:49:48 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 18:49:48 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: I cleaned up the code by moving all the imports to the top. There are two plotting routines shown below. Either one will work without error. But when I include both, running produces: The exception unknown software exception (0x40000015) occurred in the application at location 0x1e05b62a. In a dialog box and the following in the console: Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what is wrong? Thanks a lot from pylab import plot, legend, title, grid, show, xlabel, ylabel ...snip.... #FIRST PLOT plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() #SECOND PLOT drawffnet(nn) show() From missive at hotmail.com Sun Mar 14 19:06:19 2010 From: missive at hotmail.com (Lee Harr) Date: Mon, 15 Mar 2010 03:36:19 +0430 Subject: [ANNC] pynguin-0.4 (python turtle graphics application) Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues adding basic functionality and ??? refining the interface. If you are interested, please ??? take a look and let me know what you think. Pynguin is tested with Python 2.6.4 and uses PyQt (4.6) ??? for its GUI elements. Pynguin is released under GPLv3. Changes in pynguin-0.4: ??? - improved document switcher ??? - added easy 'random' color access ??? - added new commands ??????? - onscreen ??????? - onclick ??????? - stamp ??????? - viewcoords ??? - winding fill now default ??????? - added method to switch between winding/oddeven fill ??? - show file name in window header ??? - more examples ??? - added default values for examples that take parameters ??? - fixed star example for even number of sides ??? - fixed crash when changing to alternate view image ??? - fixed problem running code with blank lines ??? - fixed problem with ctrl key getting stuck on ??? - added bug report option in Help menu ??? - allow keypad Enter same as Return ??? - factored in to multiple files Changes in pynguin-0.3: ??? - added new commands ??????? - goto ??????? - turnto ??????? - lineto ??????? - distance ??????? - toward ??????? - write ??? - added more examples ??? - fixed problem when changing speed while code is running ??? - editor auto-indent improvement _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969 From ryan at rfk.id.au Sun Mar 14 19:16:19 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 10:16:19 +1100 Subject: sqlite savepoint problem In-Reply-To: <4B99EE05.8060505@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> Message-ID: <1268608579.2846.34.camel@durian> On Fri, 2010-03-12 at 08:32 +0100, Laszlo Nagy wrote: > > From memory you can't issue a "CREATE TABLE" statement inside a > > transaction, at least not at the default isolation level. Such a > > statement will automatically commit the current transaction. Doesn't > > help with your current problem but worth pointing out :-) > > > Thank you. I'll keep in mind. > > When debugging strange transaction behaviour, I find it easiest to > > create the connection with isolation_level=None so that are no implicit > > transactions being created behind your back. Not sure why, but setting > > this makes your example work for me. > > > Yes, same for me. But setting it to None means auto commit mode! See here: > > http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions > > > But it does not work that way. Look at this example > > import sqlite3 > > conn = sqlite3.connect(':memory:') > conn.isolation_level = None > with conn: > conn.execute("create table a ( i integer ) ") > > with conn: > conn.execute("insert into a values (1)") > conn.execute("SAVEPOINT sp1") > conn.execute("insert into a values (2)") > conn.execute("SAVEPOINT sp2") > conn.execute("insert into a values (3)") > conn.execute("ROLLBACK TO sp2") > conn.execute("insert into a values (4)") > conn.execute("RELEASE sp1") > > with conn: > for row in conn.execute("select * from a"): > print row > > > It prints: > > (1,) > (2,) > (4,) > > So everything is working. Nothing is auto commited. But if I change it > to "DEFERRED" or "IMMEDIATE" or "EXCLUSIVE" then it won't work. Why? I have a theory, based on a quick perusal of the sqlite3 bindings source. The bindings think that "SAVEPOINT sp1" is a "non-DML, non-query" statement. So when isolation_level is something other than None, this statement implicitly commits the current transaction and throws away your savepoints! Annotating your example: # entering this context actually does nothing with conn: # a transaction is magically created before this statement conn.execute("insert into a values (1)") # and is implicitly committed before this statement conn.execute("SAVEPOINT sp1") # a new transaction is magically created conn.execute("insert into a values (2)") # and committed, discarding the first savepoint. conn.execute("SAVEPOINT sp2") # a new transaction is magically created conn.execute("insert into a values (3)") # and committed, discarding the very savepoint we are trying to use. conn.execute("ROLLBACK TO sp2") conn.execute("insert into a values (4)") conn.execute("RELEASE sp1") In your previous multi-threaded example, try adding a "SAVEPOINT sp1" statement after deleting the rows in Thread2. You'll see that the delete is immediately committed and the rows cannot be read back by Thread1. (modified version attached for convenience). Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: test_savepoint_commit.py Type: text/x-python Size: 1818 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From steve at REMOVE-THIS-cybersource.com.au Sun Mar 14 19:18:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Mar 2010 23:18:28 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> <87fx42zms9.fsf@castleamber.com> Message-ID: <4b9d6ec4$0$27822$c3e8da3@news.astraweb.com> On Sun, 14 Mar 2010 14:11:18 -0600, John Bokma wrote: > One could argue, sure. But to me it's just the same as posting GFY > (don't want to upset the tender soulds again with "the F-word". Are you *still* going on about this thing? Sheesh. You've made your point. You don't think posting links to Let Me Google That For You is friendly; you think that "hiding" those links behind tinyurl is downright hostile; and you think that heaping abuse and obscenities on the person who posted the link is acceptable behaviour. You've made it abundantly clear that your concern about keeping this group friendly only applies to others, not to you. Can we move on now? -- Steven From CalWhoNOSPAM at roadrunner.com Sun Mar 14 19:37:00 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 19:37:00 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: I found it. Had to use "figure" to create a new figure! " Cal Who" wrote in message news:hnjp6f$l4$1 at news.eternal-september.org... >I cleaned up the code by moving all the imports to the top. > There are two plotting routines shown below. > Either one will work without error. > But when I include both, running produces: > The exception unknown software exception (0x40000015) occurred in the > application at location 0x1e05b62a. > In a dialog box and the following in the console: > Fatal Python error: PyEval_RestoreThread: NULL tstate > This application has requested the Runtime to terminate it in an unusual > way. > Please contact the application's support team for more information. > > Do you see what is wrong? > > Thanks a lot > > from pylab import plot, legend, title, grid, show, xlabel, ylabel > ...snip.... > > #FIRST PLOT > plot( targets2, 'b--' ) > plot( output, 'k-' ) > legend(('target', 'output')) > xlabel('pattern'); ylabel('benign or malignant') > title('Outputs vs. target of trained network.') > grid(True) > show() > > #SECOND PLOT > drawffnet(nn) > show() > From tjreedy at udel.edu Sun Mar 14 19:39:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 19:39:46 -0400 Subject: Understanding the CPython dict implementation Message-ID: I found this PyCon2010 presentation to be excellent: The Mighty Dictionary, Branden Craig Rhodes, 30 min. http://pycon.blip.tv/file/3264041/ Even knowing Python for over a decade, I learned a few things. Terry Jan Reedy From metolone+gmane at gmail.com Sun Mar 14 20:02:15 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 14 Mar 2010 17:02:15 -0700 Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: "Terry Reedy" wrote in message news:hnjkuo$n16$1 at dough.gmane.org... On 3/14/2010 4:40 PM, Guillermo wrote: > Adding the byte that some call a 'utf-8 bom' makes the file an invalid > utf-8 file. Not true. From http://unicode.org/faq/utf_bom.html: Q: When a BOM is used, is it only in 16-bit Unicode text? A: No, a BOM can be used as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising the BOM will be whatever the Unicode character FEFF is converted into by that transformation format. In that form, the BOM serves to indicate both that it is a Unicode file, and which of the formats it is in. Examples: BytesEncoding Form 00 00 FE FF UTF-32, big-endian FF FE 00 00 UTF-32, little-endian FE FF UTF-16, big-endian FF FE UTF-16, little-endian EF BB BF UTF-8 -Mark From alfps at start.no Sun Mar 14 20:37:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 01:37:04 +0100 Subject: Python unicode and Windows cmd.exe In-Reply-To: References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: * Mark Tolonen: > > "Terry Reedy" wrote in message > news:hnjkuo$n16$1 at dough.gmane.org... > On 3/14/2010 4:40 PM, Guillermo wrote: >> Adding the byte that some call a 'utf-8 bom' makes the file an invalid >> utf-8 file. > > Not true. From http://unicode.org/faq/utf_bom.html: > > Q: When a BOM is used, is it only in 16-bit Unicode text? > A: No, a BOM can be used as a signature no matter how the Unicode text > is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising > the BOM will be whatever the Unicode character FEFF is converted into by > that transformation format. In that form, the BOM serves to indicate > both that it is a Unicode file, and which of the formats it is in. > Examples: > BytesEncoding Form > 00 00 FE FF UTF-32, big-endian > FF FE 00 00 UTF-32, little-endian > FE FF UTF-16, big-endian > FF FE UTF-16, little-endian > EF BB BF UTF-8 Well, technically true, and Terry was wrong about "There is no such thing as a utf-8 'byte order mark'. The concept is an oxymoron.". It's true that as a descriptive term "byte order mark" is an oxymoron for UTF-8. But in this particular context it's not a descriptive term, and it's not only technically allowed, as you point out, but sometimes required. However, some tools are unable to process UTF-8 files with BOM. The most annoying example is the GCC compiler suite, in particular g++, which in its Windows MinGW manifestation insists on UTF-8 source code without BOM, while Microsoft's compiler needs the BOM to recognize the file as UTF-8 -- the only way I found to satisfy both compilers, apart from a restriction to ASCII or perhaps Windows ANSI with wide character literals restricted to ASCII (exploiting a bug in g++ that lets it handle narrow character literals with non-ASCII chars) is to preprocess the source code. But that's not a general solution since the g++ preprocessor, via another bug, accepts some constructs (which then compile nicely) which the compiler doesn't accept when explicit preprocessing isn't used. So it's a mess. Cheers, - Alf From pmaupin at gmail.com Sun Mar 14 22:07:41 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 14 Mar 2010 19:07:41 -0700 (PDT) Subject: iterator/generator References: Message-ID: First of all, as Steve Holden mentioned, do look at xlrd. It's awesome. Second, for your (a) question, if you want an iterator, that's quite easy: matriz = iter(matriz) matriz.next() # Discard the first one for i in matriz: This technique works really well, especially if you have sub-loops. Then, if you use a defaultdict which uses a list for a constructor for i in matriz: if i[a] and i[b]: g[i[a]].append(i[b]) HTH, Pat From timr at probo.com Sun Mar 14 22:14:56 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 14 Mar 2010 19:14:56 -0700 Subject: result of os.times() is different with 'time' command Options References: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> Message-ID: hiral wrote: >... >Output: >real 0.0m0.0100000002421s >user 0.0m0.0s >sys 0.0m0.0s > > >Command: >$ time ls > >Output: >real 0m0.007s >user 0m0.000s >sys 0m0.000s > > >Is this the intended behaviour? What is it that you are wondering about? The formatting difference is due to your code. The difference between 10 milliseconds and 7 milliseconds could be due to any number of things. First, you have the overhead of Python involved in your measurements. Second, you have the variability of memory caching and disk caching. Your Python code causes /bin/ls to be loaded into memory, and it's probably still in a file cache when you run the second command. You can't really do an analysis like this with a task that only takes a few milliseconds. There are too many variables. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mehgcap at gmail.com Sun Mar 14 23:43:35 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 23:43:35 -0400 Subject: dll in project? Message-ID: Hi all, I have a dll I am trying to use, but I get a Windows error 126, "the specified module could not be found". Here is the code segment: nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") I have the specified dll file in the same directory as the file trying to use said dll, and this is the only reference I make to the dll. Do I need to register it somehow? If so, does this need to be done once, or each time the application runs? If I need to register it, how would I do so? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From nagle at animats.com Mon Mar 15 00:05:36 2010 From: nagle at animats.com (John Nagle) Date: Sun, 14 Mar 2010 21:05:36 -0700 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: References: Message-ID: <4b9dad7c$0$1639$742ec2ed@news.sonic.net> The HTMLTemplate module is useful for static web page generation. It doesn't do much. It's not a "content management system". If you just need to generate a page with some data items filled in, it's fine. If you need more than that, there are bigger packages, but they have more baggage. John Nagle From nagle at animats.com Mon Mar 15 00:06:48 2010 From: nagle at animats.com (John Nagle) Date: Sun, 14 Mar 2010 21:06:48 -0700 Subject: Understanding the CPython dict implementation In-Reply-To: References: Message-ID: <4b9dadc4$0$1639$742ec2ed@news.sonic.net> Terry Reedy wrote: > I found this PyCon2010 presentation to be excellent: > The Mighty Dictionary, Branden Craig Rhodes, 30 min. > http://pycon.blip.tv/file/3264041/ > > Even knowing Python for over a decade, I learned a few things. > > Terry Jan Reedy Is this available as a paper? John Nagle From alfps at start.no Mon Mar 15 00:19:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 05:19:41 +0100 Subject: dll in project? In-Reply-To: References: Message-ID: * Alex Hall: > Hi all, > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") > > I have the specified dll file in the same directory as the file trying > to use said dll, and this is the only reference I make to the dll. Do > I need to register it somehow? If so, does this need to be done once, > or each time the application runs? If I need to register it, how would > I do so? Thanks! If 'ctypes.windll.LoadLibrary' just calls the Windows API LoadLibrary function without adding any path, then the directories considered will only be those known to the Windows API, like e.g. the process' current directory (I'm not sure if the current directory is considered, but the details aren't important). And most likely your calling script file is not in any of those directories. Probably it will work to specify the full path to the DLL. You can obtain the path to the calling file's directory by using the __file__ variable and the 'os.path' functions. Cheers & hth., - Alf From alfps at start.no Mon Mar 15 00:24:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 05:24:46 +0100 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: * Sang-Ho Yun: > I learned that I can check the existence of a file using > os.path.isfile("filename"). > > What if I need to check if there is a file that contains "HV" in the > filename? What should I do? from __future__ import print_function import os for filename in os.listdir( "." ): if "HV" in filename.upper(): print( filename ) Cheers & hth., - Alf From gherron at islandtraining.com Mon Mar 15 00:29:26 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 14 Mar 2010 21:29:26 -0700 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: <4B9DB7A6.2010802@islandtraining.com> Alf P. Steinbach wrote: > * Sang-Ho Yun: >> I learned that I can check the existence of a file using >> os.path.isfile("filename"). >> >> What if I need to check if there is a file that contains "HV" in the >> filename? What should I do? > > > from __future__ import print_function > import os > > for filename in os.listdir( "." ): > if "HV" in filename.upper(): > print( filename ) > > > > Cheers & hth., > > - Alf Or learn the glob module. It allows you to ask for a list of files matching a pattern that can include wildcard characters -- probably "*HV*" for your case. Gary Herron From Sang-Ho.Yun at jpl.nasa.gov Mon Mar 15 00:57:39 2010 From: Sang-Ho.Yun at jpl.nasa.gov (Sang-Ho Yun) Date: Sun, 14 Mar 2010 20:57:39 -0800 Subject: File existence check with partial filename Message-ID: I learned that I can check the existence of a file using os.path.isfile("filename"). What if I need to check if there is a file that contains "HV" in the filename? What should I do? Thank you, Sang-Ho From jgardner at jonathangardner.net Mon Mar 15 00:57:58 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sun, 14 Mar 2010 21:57:58 -0700 Subject: NoSQL Movement? In-Reply-To: <20100314095513.61b0fbaa.darcy@druid.net> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> <20100314095513.61b0fbaa.darcy@druid.net> Message-ID: <6cc20cea1003142157h21a1cf22o58899265cd28964f@mail.gmail.com> On Sun, Mar 14, 2010 at 6:55 AM, D'Arcy J.M. Cain wrote: > On Sat, 13 Mar 2010 23:42:31 -0800 > Jonathan Gardner wrote: >> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: >> > "D'Arcy J.M. Cain" writes: >> >> Just curious, what database were you using that wouldn't keep up with >> >> you? ?I use PostgreSQL and would never consider going back to flat >> >> files. >> > >> > Try making a file with a billion or so names and addresses, then >> > compare the speed of inserting that many rows into a postgres table >> > against the speed of copying the file. > > That's a straw man argument. ?Copying an already built database to > another copy of the database won't be significantly longer than copying > an already built file. ?In fact, it's the same operation. > I don't understand what you're trying to get at. Each bit of data follows a particular path through the system. Each bit of data has its own requirements for availability and consistency. No, relational DBs don't have the same performance characteristic as other data systems because they do different things. If you have data that fits a particular style well, then I suggest using that style to manage that data. Let's say I had data that needs to hang around for a little while then disappear into the archives. Let's say you hardly ever do random access on this data because you always work with it serially or in large batches. This is exactly like the recipient d >> Also consider how much work it is to partition data from flat files >> versus PostgreSQL tables. > > Another straw man. ?I'm sure you can come up with many contrived > examples to show one particular operation faster than another. > Benchmark writers (bad ones) do it all the time. ?I'm saying that in > normal, real world situations where you are collecting billions of data > points and need to actually use the data that a properly designed > database running on a good database engine will generally be better than > using flat files. > You're thinking in the general. Yes, RDBMs do wonderful things in the general cases. However, in very specific circumstances, RDBMS do a whole lot worse. Think of the work involved in sharding an RDBMS instance. You need to properly implement two-phase commit above and beyond the normal work involved. I haven't run into a multi-master replication system that is trivial. When you find one, let me know, because I'm sure there are caveats and corner cases that make things really hard to get right. Compare this to simply distributing flat files to one of many machines. It's a whole lot easier to manage and easier to understand, explain, and implement. You should use the right tool for the job. Sometimes the data doesn't fit the profile of an RDBMs, or the RDBMs overhead makes managing the data more difficult than it needs to be. In those cases, it makes a whole lot of sense to try something else out. >> >> The only thing I can think of that might make flat files faster is >> >> that flat files are buffered whereas PG guarantees that your >> >> information is written to disk before returning >> > >> > Don't forget all the shadow page operations and the index operations, >> > and that a lot of these operations require reading as well as writing >> > remote parts of the disk, so buffering doesn't help avoid every disk >> > seek. > > Not sure what a "shadow page operation" is but index operations are > only needed if you have to have fast access to read back the data. ?If > it doesn't matter how long it takes to read the data back then don't > index it. ?I have a hard time believing that anyone would want to save > billions of data points and not care how fast they can read selected > parts back or organize the data though. > I don't care how the recipients for the email campaign were indexed. I don't need an index because I don't do random accesses. I simply need the list of people I am going to send the email campaign to, properly filtered and de-duped, of course. This doesn't have to happen within the database. There are wonderful tools like "sort" and "uniq" to do this work for me, far faster than an RDBMS can do it. In fact, I don't think you can come up with a faster solution than "sort" and "uniq". >> Plus the fact that your other DB operations slow down under the load. > > Not with the database engines that I use. ?Sure, speed and load are > connected whether you use databases or flat files but a proper database > will scale up quite well. > I know for a fact that "sort" and "uniq" are far faster than any RDBMs. The reason why is obvious. -- Jonathan Gardner jgardner at jonathangardner.net From efiish at gmail.com Mon Mar 15 02:44:38 2010 From: efiish at gmail.com (Lan Qing) Date: Mon, 15 Mar 2010 14:44:38 +0800 Subject: Fwd: Some PyCon videos won't play In-Reply-To: References: Message-ID: In China these video can not watch at all. I must spent 3 days to download it... On Mon, Mar 15, 2010 at 5:19 AM, Terry Reedy wrote: > On 3/14/2010 2:41 PM, Terry Reedy wrote: > >> On 3/14/2010 11:14 AM, David Boddie wrote: >> > > You should still be able to get at the videos themselves by inspecting >>> the page contents, looking for download links like this one: >>> >>> >>> http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv >>> >>> >>> In this case, it's an Ogg Theora video file, so you may want to use >>> a player like VLC to view it: >>> >> >> For people using html5 competant browsers, which, I believe, play .ogv >> 'in tha page', blip.tv just needs to update site to make html5 pages an >> alternative to using the flash player. >> > > Actually, for FF3.6, at least, the problem is already solved. I just click > on the download button and FF recognizes .ogv as something it can play and > it does, replacing the flash player. The FF player lacks a full-screen > button, but that is rarely needed for the talks. > > tjr > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hiralsmaillist at gmail.com Mon Mar 15 02:51:28 2010 From: hiralsmaillist at gmail.com (hiral) Date: Sun, 14 Mar 2010 23:51:28 -0700 (PDT) Subject: result of os.times() is different with 'time' command Options References: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> Message-ID: <61c563ad-f0c3-47ae-b689-36c397f88295@l11g2000pro.googlegroups.com> On Mar 15, 7:14?am, Tim Roberts wrote: > hiral wrote: > >... > >Output: > >real ? ?0.0m0.0100000002421s > >user ? ?0.0m0.0s > >sys ? ? 0.0m0.0s > > >Command: > >$ time ls > > >Output: > >real ? ?0m0.007s > >user ? ?0m0.000s > >sys ? ? 0m0.000s > > >Is this the intended behaviour? > > What is it that you are wondering about? ?The formatting difference is due > to your code. ?The difference between 10 milliseconds and 7 milliseconds > could be due to any number of things. ?First, you have the overhead of > Python involved in your measurements. ?Second, you have the variability of > memory caching and disk caching. ?Your Python code causes /bin/ls to be > loaded into memory, and it's probably still in a file cache when you run > the second command. > > You can't really do an analysis like this with a task that only takes a few > milliseconds. ?There are too many variables. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc.- Hide quoted text - > > - Show quoted text - Thanks for your explanation. From hiralsmaillist at gmail.com Mon Mar 15 02:51:42 2010 From: hiralsmaillist at gmail.com (hiral) Date: Sun, 14 Mar 2010 23:51:42 -0700 (PDT) Subject: to create variable from dict References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: On Mar 12, 8:02?pm, Jean-Michel Pichavant wrote: > Luis M. Gonz?lez wrote: > > On Mar 12, 10:59 am,hiral wrote: > > >> Hi, > > >> Is there any way to create variables which name matches with dict key? > > >> For example: > >> dict1 = {"abc":'1", "def":"2"} > > >> Now I am looking to have variable name abc and it's value be '1' etc. > > >> Pl. suggest. > > >> Thank you. > > > Check out this thread (very recent): > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > > Short answer: you can update globals() with a dictionary, as follows: > > > globals().update( dict1 ) > > > Then you'll have each key-value pair as variables in the global > > namespace. > > The question is: should you do it? > > > Luis > > The answer is known: no, he should not do it :o) > > JM- Hide quoted text - > > - Show quoted text - Thanks for your explanations. From xahlee at gmail.com Mon Mar 15 03:16:33 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 15 Mar 2010 00:16:33 -0700 (PDT) Subject: Hacker News, Xahlee.Org, and What is Politics? Message-ID: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> A essay related to the recent discussion of banning, and lisp associated group at ycombinator.com . --------------------------------------------- Hacker News, Xahlee.Org, and What is Politics? Xah Lee, 2010-03-14 Today, i noticed that someone posted one of my article ?Why Emacs is still so useful today? on my blogger site (xahlee.blogspot.com) to Hacker News site here: Source. Note that my site XahLee.org was unceremoniously banned around 2009-02 by the admin geekers there. (see bottom of: Ban Xah Lee). But, apparantly, someone found my article useful. Now, in order to submit my articles, you'll have to use my article mirror at blogger.blogspot.com instead of xahlee.org. -------------------- Tech Geeker's Ignorance Of Politics The human nature of power struggle never ends. Many of these tech geekers think they are apolitical, that they are peace loving, they ride bikes not driving machines that pollute, they don't have interest in business, they embrace the Free of ?freedom? Software or Open Source of ?openness? software. The problem of human animals is that, we all think that, yet, power struggle or the formation of politics isn't something you consciously decide to do. Rather, it is something that you unconsciously do whenever you have interaction with peers when resources are not infinite. At the basic level, you have quarrels with ya brothers about toys, in high school about seats, girls. Going up a bit, you have all these teens, gamers, tech geekers, shouting, kicking, banning, in all sort of internet forums, irc chat rooms, mailing lists, in-world gaming channels. Going up, you have managers fighting in corporations, politicians pissing at each other, leaders warring among nation states. Note the word PEER here, because, you are out of the game with those who are much more powerful than you, and similarly, you can't be bothered by those far beneath you. Of course, the tech geekers all think they are fair, just, maintaining peace. But you can almost see the smug on their faces whenever any of these ?admins?, ?group owners?, ?sysops?, ?operators?, exercise their power. It is a basic human pleasure to force onto uncooperative others. (See: What Desires Are Politically Important?) Serious fairness and open policies never actually come up unless the community becomes large, larger then the original special interest clique. Before the group becomes large, typically their political structure is academically called oligarchy. i.e. basically whoever started the group, his cronies, rule. We all understand conscious power struggle. However, it is when we think that we are not doing politics when exercising our power, is when it is likely most damaging, with respect to human progress. (the subject of human progress, its ideal direction, goal, is itself is quite not agreed upon among historical figures (big philosophers, politicians, leaders, etc.).) Part of the problem is ignorance. Most tech geekers, those coders, engineers, type of folks, typically don't have much education or interest in social sciences. Few years ago on irc channel, i was ranting on the subject of politics, due to some difference of opinion on tech stuff, and learned, rather not surprisingly, that one of the guy don't understand that politics essentially means power struggle. Most tech geekers think that Politics is what politicians do, that it is something about rulers, about bad ass evil lords, ambitious guys, Napolean, or about controversial subjects, back stabbing, cloak and dagger, and isn't about, say, admins or policies in some online forum. -------------------- What Is Politics? Here's some Wikipedia quotes from Politics: Politics is a process by which groups of people make collective decisions. The term is generally applied to behavior within civil governments, but politics has been observed in other group interactions, including corporate, academic, and religious institutions. It consists of "social relations involving authority or power"[1] and refers to the regulation of a political unit,[2] and to the methods and tactics used to formulate and apply policy.[3] ... Political science, the study of politics, examines the acquisition and application of power and "power corrupts". It quotes this juicy quote: ?Politics: A strife of interests masquerading as a contest of principles. The conduct of public affairs for private advantage.? ? Ambrose Bierce[15] I much prefer older edits of Wikipedia's opening paragraph. Here's few excerpts Politics consists of "social relations involving authority or power"[1] and refers to the regulation of a political unit,[2] and to the methods and tactics used to formulate and apply policy.[3] ... In a broader sense, any situation involving power, or any maneouvring in order to enhance one's power or status within a group, may be described as politics (e.g. office politics).[3] This form of politics "is most associated with a struggle for ascendancy among groups having different priorities and power relations."[4] And here's a point-blank shot: Politics is who gets what, when, and how. ? Harold Lasswell ------------------- the url for this essay can be found on my website or blog. Xah ? http://xahlee.org/ ? From gandalf at shopzeus.com Mon Mar 15 03:38:34 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 15 Mar 2010 08:38:34 +0100 Subject: sqlite savepoint problem [solved] In-Reply-To: <1268608579.2846.34.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <1268608579.2846.34.camel@durian> Message-ID: <4B9DE3FA.2090904@shopzeus.com> > Annotating your example: > > # entering this context actually does nothing > with conn: > # a transaction is magically created before this statement > conn.execute("insert into a values (1)") > # and is implicitly committed before this statement > conn.execute("SAVEPOINT sp1") > # a new transaction is magically created > conn.execute("insert into a values (2)") > # and committed, discarding the first savepoint. > conn.execute("SAVEPOINT sp2") > # a new transaction is magically created > conn.execute("insert into a values (3)") > # and committed, discarding the very savepoint we are trying to use. > conn.execute("ROLLBACK TO sp2") > conn.execute("insert into a values (4)") > conn.execute("RELEASE sp1") > We all know the Zen of Python. Explicit is better than implicit. There is no point in using a savepoint outside a transaction. There is no point in using a savepoint if it commits all previous changes automatically. Conclusion: Sqlite's isolation_level is dark magic. It mixes real isolation levels with behaviour of context managers, and automagical commits in the wrong places. Setting isolation_level=None is a must for anyone who want to do any serious work with sqlite. L From Brian.Mingus at Colorado.EDU Mon Mar 15 03:39:29 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 15 Mar 2010 01:39:29 -0600 Subject: Hacker News, Xahlee.Org, and What is Politics? In-Reply-To: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> References: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> Message-ID: <9839a05c1003150039j40cbe2bao16cf51ca431a1a0f@mail.gmail.com> On Mon, Mar 15, 2010 at 1:16 AM, Xah Lee wrote: > A essay related to the recent discussion of banning, and lisp > associated group at ycombinator.com . Is there some Python related issue I might help you out with? Or perhaps you wish to provide Python assistance to someone on this list. Or perhaps you would like to write some Python code, or read the friendly Python manual, or draft a new PEP. Any one of these things would be a much better usage of your time than drafting middle to high school quality essays. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davty216 at student.liu.se Mon Mar 15 03:49:34 2010 From: davty216 at student.liu.se (David Tynnhammar) Date: Mon, 15 Mar 2010 08:49:34 +0100 Subject: "Distributed" database in Python Message-ID: <6da346621003150049h7c8901a2kf7dfb09db3ddf861@mail.gmail.com> Greetings. I'm looking for a "distributed" database. (I'm not sure if distributed is the correct terminology though). My problem is this; I have a client application which once in a while needs to sync with a central database. (And of course the client -databases might be updated locally etc). Are there any other resources you can recommend me? (I have basic RDMS knowledge (MySQL)). From kevin.p.dwyer at gmail.com Mon Mar 15 03:50:09 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 15 Mar 2010 07:50:09 +0000 (UTC) Subject: Is it possible to use re2 from Python? References: <0540f7d0-95f6-4b38-900d-dc25958ff232@g26g2000yqn.googlegroups.com> Message-ID: On Sun, 14 Mar 2010 14:40:34 -0700, _wolf wrote: >> There's a recent thread about this on the python-dev list, > > pointers? i searched but didn?t find anything. http://mail.python.org/pipermail/python-dev/2010-March/098354.html From ryan at rfk.id.au Mon Mar 15 03:53:49 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 18:53:49 +1100 Subject: sqlite savepoint problem [solved] In-Reply-To: <4B99FCCF.5080506@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> <1268604831.2846.23.camel@durian> <4B99FCCF.5080506@shopzeus.com> Message-ID: <1268639629.2846.48.camel@durian> On Fri, 2010-03-12 at 09:35 +0100, Laszlo Nagy wrote: > > No it doesn't. The problem is that using a connection as a context > > manager doesn't do what you think. > > > > It does *not* start a new transaction on __enter__ and commit it on > > __exit__. As far as I can tell it does nothing on __enter__ and calls > > con.commit() or con.rollback() on exit. With isolation_level=None, > > these are no-ops. > > > Thank you Ryan! You are abolutely right, and thank you for reading the > source. Now everything works as I imagined. No problemo - isolation_level has given me my fair share of headaches in the past, so I couldn't resist the opportunity to understand it a little better. > The way the context manager and isolation_level works looks very very > strange to me. Here is a demonstration: > > import sqlite3 > def getconn(): > conn = sqlite3.connect(':memory:') > conn.isolation_level = None > return conn > def main(): > with getconn() as conn: > conn.execute("create table a ( i integer ) ") > try: > conn.execute("insert into a values (1)") > with conn: > conn.execute("insert into a values (2)") > raise Exception > except: > print "There was an error" > for row in conn.execute("select * from a"): > print row > main() > > > Output: > > There was an error > (1,) > (2,) > > > Looks like the context manager did not roll back anything. Yes, because there were no transactions created so there was nothing to roll back. > If I remove > isolation_level=None then I get this: > > There was an error > > E.g. the context manager rolled back something that was executed outside > the context. Yes, because the transactions created by the default isolation level do not nest, so the rollback happens at outermost scope. > I cannot argue with the implementation - it is that way. > But this is not what I would expect. I believe I'm not alone with this. That's at least two of us :-) > Just for clarity, we should put a comment at the end of the > documentation here: > > http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions > > I would add at least these things: > > #1. By using isolation_level = None, connection objects (used as a > context manager) WON'T automatically commit or rollback transactions. > #2. Using any isolation level, connection objects WON'T automatically > begin a transaction. > #3. Possibly, include your connection manager class code, to show how to > do it "the expected" way. > > Also one should clarify in the documentation, what isolation_level does. > Looks like setting isolation_level to None is not really an "auto commit > mode". It is not even part of sqlite itself. It is part of the python > extension. I think of it as almost the opposite - you have to set isolation_level=None to get the unadulterated behaviour of the underlying sqlite library. I'm sure the devs would appreciate a documentation patch (submission details at http://python.org/dev/patches/). I'm also pretty confident that I won't have time to do one up anytime soon :-) Good luck with your project! Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From steven at REMOVE.THIS.cybersource.com.au Mon Mar 15 04:01:02 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Mar 2010 08:01:02 GMT Subject: "Distributed" database in Python References: Message-ID: On Mon, 15 Mar 2010 08:49:34 +0100, David Tynnhammar wrote: > Greetings. I'm looking for a "distributed" database. (I'm not sure if > distributed is the correct terminology though). > > My problem is this; I have a client application which once in a while > needs to sync with a central database. (And of course the client > -databases might be updated locally etc). > > Are there any other resources you can recommend me? (I have basic RDMS > knowledge (MySQL)). Google and Wikipedia are your friends. http://en.wikipedia.org/wiki/Distributed_database http://www.google.com/search?q=distributed+database http://www.google.com/search?q=python+distributed+database If you have already tried this, then you should say so, so that we don't waste our time, and yours, going over ground you have already covered. -- Steven From mail at timgolden.me.uk Mon Mar 15 04:41:10 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 15 Mar 2010 08:41:10 +0000 Subject: dll in project? In-Reply-To: References: Message-ID: <4B9DF2A6.70608@timgolden.me.uk> On 15/03/2010 03:43, Alex Hall wrote: > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") > > I have the specified dll file in the same directory as the file trying > to use said dll The DLL search path: http://msdn.microsoft.com/en-us/library/7d83bc18%28VS.80%29.aspx includes the directory which holds the executable for the current prcoess; it include the current directory; and it includes other things which I doubt apply here. But it doesn't include (if I may be permitted a little well-intentioned ridicule) the directory where the current Python module is stored. In other words: what does os.getcwd () return? TJG From mick.lausch at gmail.com Mon Mar 15 04:43:02 2010 From: mick.lausch at gmail.com (Michael.Lausch) Date: Mon, 15 Mar 2010 01:43:02 -0700 (PDT) Subject: staticmethod and setattr Message-ID: Hi, I managed to get confused by Python, which is not such an easy task. The problem i have is rooted in marshalling, JSON and Dojo. I need some static class in function with the name "$ref" i tried: class Foo(object): @staticmethod def _ref(o): pass setattr(Foo, "$ref", Foo._ref) but when i do something like this in code: class B(object): pass b = Bar f = Foo.getattr("$ref") f(b) if get the following error ypeError unbound method _ref() must be called with Foo instance as first argument (got Bar instance instead) I managed to impelemnt it with a unbound, "normal" _ref() function, but i want one _ref function per class, because they are a little bit different for each class. One aproach which i have not tried is: setattr(Foo, "$ref", Foo._ref.im_func). maybe this works, but i think this is not a clean aproach. Any ideas? From breamoreboy at yahoo.co.uk Mon Mar 15 04:46:31 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 15 Mar 2010 08:46:31 +0000 Subject: iterator/generator In-Reply-To: References: Message-ID: vsoler wrote: > I am working on a script that reads data from an excel workbook. The > data is located in a named range whose first row contains the headers. > It works!!! I find it superb that python is able to do such things!!! > > Now my questions. > > a. My ranges can in practice be quite big, and although I am happy > with the speed I get, because I am learning python, I think I could do > it still a bit better. I think that the line for i in matriz[1:]: > could be improved with an iterator/generator, but I am not quite > certain how I should proceed. I write this :- for j, i in enumerate(matriz): if j: etc... If there's a better method for some definition of better I'm certain we'll quickly get told. Please see the python docs for the enumerate built-in. HTH. Mark Lawrence. [snip the rest] From rantingrick at gmail.com Mon Mar 15 04:55:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Mar 2010 01:55:33 -0700 (PDT) Subject: Hacker News, Xahlee.Org, and What is Politics? References: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> Message-ID: Bravo!, Bravo! A wonderful post xah, thanks for sharing and i hope it sinks in with the people around here who need a lesson in humility. I was just a few days ago feeling quite passionate about this subject and creating my own draft but than i lost interest because i knew nobody would even care and probably just accuse me of trolling. Anyhow thanks for this! From robin at reportlab.com Mon Mar 15 05:58:59 2010 From: robin at reportlab.com (Robin Becker) Date: Mon, 15 Mar 2010 09:58:59 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A9624.7040200@v.loewis.de> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> <4B9A9624.7040200@v.loewis.de> Message-ID: <4B9E04E3.90408@chamonix.reportlab.co.uk> On 12/03/2010 19:29, "Martin v. L?wis" wrote: >> Not sure if this is a bug > > I think it is. It seems that the cross-build support in msvc9compiler > has been tested only in a build tree of Python (where there is no Libs > directory). This minor patch seems to fix the problem for me (using a PCBuild folder parallel to libs) C:\Python\Lib\distutils\command>diff build_ext.py.orig build_ext.py 207c207,209 < self.library_dirs.append(new_lib) --- > self.library_dirs.insert(0,new_lib) > else: > self.library_dirs.append(new_lib) > > For released copies of Python, I could change that to distribute the > AMD64 pythonXY.lib in libs/amd64. [FWIW, I'm still puzzled why I ship > the import libraries of all the pyd files as well - I can't see a reason > other than tradition]. Then, distutils should change to look it up there. ....... Just checked and all the pyd's seem only to export the xxx_init functions (sometimes there are two in the pyd) so the .libs do seem a bit redundant. -- Robin Becker From eckhardt at satorlaser.com Mon Mar 15 06:14:31 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Mar 2010 11:14:31 +0100 Subject: dll in project? References: Message-ID: <7td177-uar.ln1@satorlaser.homedns.org> Alex Hall wrote: > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") In addition to Alf's answer, this can also happen when the OS can't find another DLL that this one depends on. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From greg.ewing at canterbury.ac.nz Mon Mar 15 06:29:51 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 15 Mar 2010 23:29:51 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <4B9E0C1F.9020003@canterbury.ac.nz> I've solved the problem now. It turned out to be a very standard CRC algorithm, complicated by the presence of a few extra bytes of data being checked that didn't appear explicitly in the file anywhere. In the process I developed some very general techniques for solving this kind of problem, which I've written about here if anyone's interested: http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html Thanks for everyone's help, Greg From steve at REMOVE-THIS-cybersource.com.au Mon Mar 15 06:40:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Mar 2010 10:40:31 GMT Subject: staticmethod and setattr References: Message-ID: <4b9e0e9f$0$27822$c3e8da3@news.astraweb.com> On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: > Hi, > > I managed to get confused by Python, which is not such an easy task. > > The problem i have is rooted in marshalling, JSON and Dojo. I need some > static class in function with the name "$ref" i tried: > class Foo(object): > @staticmethod > def _ref(o): > pass > > setattr(Foo, "$ref", Foo._ref) That doesn't work as expected: >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] False Try this instead: >>> setattr(Foo, "$ref", Foo.__dict__['_ref']) >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] True -- Steven From efiish at gmail.com Mon Mar 15 06:57:38 2010 From: efiish at gmail.com (Lan Qing) Date: Mon, 15 Mar 2010 18:57:38 +0800 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: Or use the regular module: import re import os for filename in os.listdir('.'): if re.match("*HV*", filename): # do something with the file On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach wrote: > * Sang-Ho Yun: > > I learned that I can check the existence of a file using >> os.path.isfile("filename"). >> >> What if I need to check if there is a file that contains "HV" in the >> filename? What should I do? >> > > > from __future__ import print_function > import os for filename in os.listdir( "." ): > if "HV" in filename.upper(): > print( filename ) > > > > Cheers & hth., > > - Alf > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mehgcap at gmail.com Mon Mar 15 07:28:11 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 15 Mar 2010 07:28:11 -0400 Subject: dll in project? In-Reply-To: <7td177-uar.ln1@satorlaser.homedns.org> References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: On 3/15/10, Ulrich Eckhardt wrote: > Alex Hall wrote: >> I have a dll I am trying to use, but I get a Windows error 126, "the >> specified module could not be found". Here is the code segment: >> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") > > In addition to Alf's answer, this can also happen when the OS can't find > another DLL that this one depends on. Well, os.getcwd() returns "c:\python26", not my program's directory. However, I changed the reference to the dll to be helpers.progdir+'\\nvdaControllerClient32.dll' and still no luck! helpers.progdir is a var holding the top-level directory of my project, using os.path. Again, using this more precise reference still fails, triggering my except statement in my try/catch loop. From alfps at start.no Mon Mar 15 07:37:55 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 12:37:55 +0100 Subject: dll in project? In-Reply-To: References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: * Alex Hall: > On 3/15/10, Ulrich Eckhardt wrote: >> Alex Hall wrote: >>> I have a dll I am trying to use, but I get a Windows error 126, "the >>> specified module could not be found". Here is the code segment: >>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") >> In addition to Alf's answer, this can also happen when the OS can't find >> another DLL that this one depends on. > > Well, os.getcwd() returns "c:\python26", not my program's directory. > However, I changed the reference to the dll to be > helpers.progdir+'\\nvdaControllerClient32.dll' > and still no luck! Are you sure you get a single directory separator backslash there? I suggest using the os.path 'join' function, whatever it was called. > helpers.progdir is a var holding the top-level > directory of my project, using os.path. But is that where the DLL resides, or is it in some subdirectory? > Again, using this more precise > reference still fails, triggering my except statement in my try/catch > loop. Try also checking the arguments & documentation of ctypes.windll.LoadLibrary. I know, you probably already done that. But I mention it just in case (I'm not familiar with that function at the Python level, so don't know about the args). Cheers & hth., - Alf From eckhardt at satorlaser.com Mon Mar 15 07:44:18 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Mar 2010 12:44:18 +0100 Subject: dll in project? References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: Alex Hall wrote: > On 3/15/10, Ulrich Eckhardt wrote: >> Alex Hall wrote: >>> I have a dll I am trying to use, but I get a Windows error 126, "the >>> specified module could not be found". Here is the code segment: >>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") >> >> In addition to Alf's answer, this can also happen when the OS can't find >> another DLL that this one depends on. Did you check if this could be the case? > Well, os.getcwd() returns "c:\python26", not my program's directory. > However, I changed the reference to the dll to be > helpers.progdir+'\\nvdaControllerClient32.dll' > and still no luck! Generally, there is os.path.join() IIRC which does this portably. This probably doesn't matter though. What I would check is firstly if this file could be opened at all, e.g. using os.stat(). > helpers.progdir is a var holding the top-level directory of my > project, using os.path. Huh? In what way using os.path? > Again, using this more precise reference still fails, triggering my > except statement in my try/catch loop. Same error? See my initial guess! As a tool for finding out if there are missing dependencies, take a look at http://dependencywalker.com BTW: No need to CC me, I read your initial request here, I can ready any follow-ups here, too. ;) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From iwanttobeabadger at googlemail.com Mon Mar 15 08:21:42 2010 From: iwanttobeabadger at googlemail.com (Nathan Harmston) Date: Mon, 15 Mar 2010 12:21:42 +0000 Subject: Large regular expressions Message-ID: Hi, So I m trying to use a very large regular expression, basically I have a list of items I want to find in text, its kind of a conjunction of two regular expressions and a big list......not pretty. However everytime I try to run my code I get this exception: OverflowError: regular expression code size limit exceeded I understand that there is a Python imposed limit on the size of the regular expression. And although its not nice I have a machine with 12Gb of RAM just waiting to be used, is there anyway I can alter Python to allow big regular expressions? Could anyone suggest other methods of these kind of string matching in Python? I m trying to see if my swigged alphabet trie is faster than whats possible in Python! Many thanks, Nathan From mick.lausch at gmail.com Mon Mar 15 08:42:01 2010 From: mick.lausch at gmail.com (Michael.Lausch) Date: Mon, 15 Mar 2010 05:42:01 -0700 (PDT) Subject: staticmethod and setattr References: <4b9e0e9f$0$27822$c3e8da3@news.astraweb.com> Message-ID: <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> On Mar 15, 11:40?am, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: > > Hi, > > > I managed to get confused by Python, which is not such an easy task. > > > The problem i have is rooted in marshalling, JSON and Dojo. I need some > > static class in function with the name "$ref" i tried: > > class Foo(object): > > ? ? @staticmethod > > ? ? def _ref(o): > > ? ? ? ? ?pass > > > setattr(Foo, "$ref", Foo._ref) > > That doesn't work as expected: > > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > False > > Try this instead: > > >>> setattr(Foo, "$ref", Foo.__dict__['_ref']) > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > True Now I'm trying to understand why this is the case. How is Foo.__dict__['_ref'] different from Foo._ref? Shouldn't it return the same attribute? And after further experiments i found out that a making Foo._ref a classmethod does work with my first approach. From stefan_ml at behnel.de Mon Mar 15 08:45:31 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Mar 2010 13:45:31 +0100 Subject: Large regular expressions In-Reply-To: References: Message-ID: Nathan Harmston, 15.03.2010 13:21: > So I m trying to use a very large regular expression, basically I have > a list of items I want to find in text, its kind of a conjunction of > two regular expressions and a big list......not pretty. However > everytime I try to run my code I get this exception: > > OverflowError: regular expression code size limit exceeded > > I understand that there is a Python imposed limit on the size of the > regular expression. And although its not nice I have a machine with > 12Gb of RAM just waiting to be used, is there anyway I can alter > Python to allow big regular expressions? > > Could anyone suggest other methods of these kind of string matching in > Python? If what you are trying to match is in fact a set of strings instead of a set of regular expressions, you might find this useful: http://pypi.python.org/pypi/acora Stefan From alain at dpt-info.u-strasbg.fr Mon Mar 15 08:50:27 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 15 Mar 2010 13:50:27 +0100 Subject: Large regular expressions References: Message-ID: <877hpdycj0.fsf@dpt-info.u-strasbg.fr> Nathan Harmston writes: [...] > Could anyone suggest other methods of these kind of string matching in > Python? I m trying to see if my swigged alphabet trie is faster than > whats possible in Python! Since you mention using a trie, I guess it's just a big alternative of fixed strings. You may want to try using the Aho-Corasick variant. It looks like there are several implementations (google finds at least two). I would be surprised if any pure python solution were faster than tries implemented in C. Don't forget to tell us your findings. -- Alain. From mehgcap at gmail.com Mon Mar 15 09:24:01 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 15 Mar 2010 09:24:01 -0400 Subject: dll in project? In-Reply-To: References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: Okay, I got a new copy and all seems well now. The dll is found and loaded. The functions inside the dll are not working, but that is not Python's fault. Thanks to everyone for your help and suggestions! On 3/15/10, Ulrich Eckhardt wrote: > Alex Hall wrote: >> On 3/15/10, Ulrich Eckhardt wrote: >>> Alex Hall wrote: >>>> I have a dll I am trying to use, but I get a Windows error 126, "the >>>> specified module could not be found". Here is the code segment: >>>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") >>> >>> In addition to Alf's answer, this can also happen when the OS can't find >>> another DLL that this one depends on. > > Did you check if this could be the case? > >> Well, os.getcwd() returns "c:\python26", not my program's directory. >> However, I changed the reference to the dll to be >> helpers.progdir+'\\nvdaControllerClient32.dll' >> and still no luck! > > Generally, there is os.path.join() IIRC which does this portably. This > probably doesn't matter though. What I would check is firstly if this file > could be opened at all, e.g. using os.stat(). > >> helpers.progdir is a var holding the top-level directory of my >> project, using os.path. > > Huh? In what way using os.path? > >> Again, using this more precise reference still fails, triggering my >> except statement in my try/catch loop. > > Same error? See my initial guess! As a tool for finding out if there are > missing dependencies, take a look at http://dependencywalker.com > > BTW: No need to CC me, I read your initial request here, I can ready any > follow-ups here, too. ;) > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From catonano at gmail.com Mon Mar 15 09:41:14 2010 From: catonano at gmail.com (catonano) Date: Mon, 15 Mar 2010 06:41:14 -0700 (PDT) Subject: Dreaming of new generation IDE References: <5b51740d-11f1-4f01-b51c-d1b6ea161eb7@l19g2000yqb.googlegroups.com> Message-ID: Hello again, people On Feb 11, 6:30?pm, Francis Carr wrote: > > I can't believe the code editing situation today is in a such sorry > > state. > > I can't believe an old coder is feeling so sorry for himself. Ok, I'm feeling sorry; still, I think I made a point. > > Today, I tried to understand the twisted.web.client code and I found 3 > Maybe the relevant lesson to be taken from Smalltalk is *not* > ? "put it all in one image" > but instead > ? "write code to solve problems, e.g., reading code" > I suggest defining a few shell functions to *automate* the search, for > example in zsh > > function allf () { > Smalltalk's images are cool. ?But they are such a huge hammer, and > they impose so many additional requirements! ?The costs outweigh the > cool. Francis, I disagree on the final balance statement about the Smalltalk images and I thank you for your suggestions on how to use grep and shell scripting. I also have no problem to admit I was feeling sorry for myself. But today I found something I think is relevant to this thread. It's here: http://www.cs.brown.edu/people/acb/codebubbles_site.htm it's about a IDE for Java called Bubbles. It sports a zooming interface and the MAIN idea it proposes, in my opinion, is that the code is NOT thought as files content, rather as fragments, called bubbles. And then you arrange your bubbles in a 2d space a little bit like in a videogame. I think it's very similar to the Smalltalk image thing (as a concept, if not as an implementation), with its live things and direct manipulation. If you open the footage directly in youtube, you can go to some "related" footages about a similar thing made by Microsoft that of course ditches the main idea retaining the concept of files and directories, overlapping the concept of files and classes (sigh). I didn't imagine such a research existed and the discovery confirms to me that the bother I indicated in this thread is somewhat shared by someone, around the world. As for my feelings, I swear I'm taking care of them in a way that doesn't involve bothering anyone on any newsgroup ;-) Steve, does Bubble gets any closer to your vision than the "ugly" Smalltalk thing ? Bye Catonano From alex at moreati.org.uk Mon Mar 15 09:50:32 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 15 Mar 2010 06:50:32 -0700 (PDT) Subject: Understanding the CPython dict implementation References: <4b9dadc4$0$1639$742ec2ed@news.sonic.net> Message-ID: On Mar 15, 4:06?am, John Nagle wrote: > ? ? Is this available as a paper? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle It doesn't wppear to be, slides are here: http://us.pycon.org/2010/conference/schedule/event/12/ Alex From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 15 09:51:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 15 Mar 2010 14:51:30 +0100 Subject: staticmethod and setattr In-Reply-To: <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> References: <4b9e0e9f$0$27822$c3e8da3@news.astraweb.com> <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> Message-ID: <4b9e3b61$0$12084$426a34cc@news.free.fr> Michael.Lausch a ?crit : (snip) > Now I'm trying to understand why this is the case. > How is Foo.__dict__['_ref'] different from Foo._ref? > Shouldn't it return the same attribute? > It's an application of the descriptor protocol: http://wiki.python.org/moin/FromFunctionToMethod From andreas.loescher at s2005.tu-chemnitz.de Mon Mar 15 10:24:55 2010 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 15 Mar 2010 15:24:55 +0100 Subject: staticmethod and setattr In-Reply-To: <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> Message-ID: <1268663020.10067.35.camel@laptop> Am Montag, den 15.03.2010, 05:42 -0700 schrieb Michael.Lausch: > On Mar 15, 11:40 am, Steven D'Aprano cybersource.com.au> wrote: > > On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: > > > Hi, > > > > > I managed to get confused by Python, which is not such an easy task. > > > > > The problem i have is rooted in marshalling, JSON and Dojo. I need some > > > static class in function with the name "$ref" i tried: > > > class Foo(object): > > > @staticmethod > > > def _ref(o): > > > pass > > > > > setattr(Foo, "$ref", Foo._ref) > > > > That doesn't work as expected: > > > > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > > > False > > > > Try this instead: > > > > >>> setattr(Foo, "$ref", Foo.__dict__['_ref']) > > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > > > True > > Now I'm trying to understand why this is the case. > How is Foo.__dict__['_ref'] different from Foo._ref? > Shouldn't it return the same attribute? > > And after further experiments i found out that a making > Foo._ref a classmethod does work with my first approach. > In the class dictionary are the "raw" objects stored. For example: class Spam: @staticmethod def egg1(): pass def egg2(self): pass >>> Spam.__dict__ {'egg1': , '__module__': '__main__', 'egg2': , '__doc__': None} If you try to call egg1 as staticmethod you will get an error: >>> Spam.__dict__['egg1']() Traceback (most recent call last): File "", line 1, in TypeError: 'staticmethod' object is not callable getattr() is not only a shortcut for the line above. It searches all base classes for the specified name in the class dictionaries. If the name is found, and the object has an additional descriptor, it is applied on the object itself. In case of an static method, the descriptor sm_descr_get is located in Objects/funcobjects.c of the sources and it retriefes the encapsuled callable, which in this case is the function egg1. If you now set the function as new attribute, it is no longer a static method, but a normal function. If a function is retrieved via getattr(), it is encapsuled in an method object. (func_descr_get in the same file) If you now try to call the method in you example, you call a method from a class. This results in an unbound method, which requests an instance of the class as first agument. I hope this clears some things up. Best Andreas From gdamjan at gmail.com Mon Mar 15 10:53:21 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 15 Mar 2010 15:53:21 +0100 Subject: Python for newbies (Pythno users group in Macedonia) References: Message-ID: <28u177-m9j.ln1@archaeopteryx.softver.org.mk> > If you are all English-speakers then perhaps you could consider > showing a PyCon video - see > > http://pycon.blip.tv That's certainly something I'm considering for the more advanced users > Good luck with the group. I hope to see PyCon Macedonia emerging > before too long! Thanks :) I guess we'd have to wait a decade or so for a PyCon here -- damjan From gdamjan at gmail.com Mon Mar 15 11:05:31 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 15 Mar 2010 16:05:31 +0100 Subject: Python for newbies (Pythno users group in Macedonia) References: Message-ID: >> we are starting with bi-monthly Python User Group meetings in Skopje, >> Macedonia. The meetings are targeted for both beginners and more >> experienced users. >> > ... > http://us.pycon.org/2010/conference/schedule/event/108/ Great resource, exactly what I needed. So, they use this book http://www.greenteapress.com/thinkpython/ as a guide, seems like a good choice. I also learned about the tutor mail list: http://mail.python.org/mailman/listinfo/tutor -- damjan From alex at moreati.org.uk Mon Mar 15 11:42:40 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 15 Mar 2010 08:42:40 -0700 (PDT) Subject: EuroPython 2010 - Open for registration and reminder of participation Message-ID: EuroPython 2010 - 17th to 24th July 2010 ---------------------------------------- EuroPython is a conference for the Python programming language community, including the Django, Zope and Plone communities. It is aimed at everyone in the Python community, of all skill levels, both users and programmers. Last year's conference was the largest open source conference in the UK and one of the largest community organised software conferences in Europe. This year EuroPython will be held from the 17th to 24th July in Birmingham, UK. It will include over 100 talks, tutorials, sprints and social events. Registration ------------ Registration is open now at: http://www.europython.eu/registration/ For the best registration rates, book as soon as you can! Extra Early Bird closes soon, after which normal Early Bird rate will apply until 10th May Talks, Activities and Events ---------------------------- Do you have something you wish to present at EuroPython? You want to give a talk, run a tutorial or sprint? Go to http://www.europython.eu/talks/cfp/ for information and advice! Go to http://wiki.europython.eu/Sprints to plan a sprint! Help Us Out ----------- EuroPython is run by volunteers, like you! We could use a hand, and any contribution is welcome. Go to http://wiki.europython.eu/Helping to join us! Go to http://www.europython.eu/contact/ to contact us directly! Sponsors -------- Sponsoring EuroPython is a unique opportunity to affiliate with this prestigious conference and to reach a large number of Python users from computing professionals to academics, from entrepreneurs to motivated and well-educated job seekers. http://www.europython.eu/sponsors/ Spread the Word --------------- We are a community-run not-for-profit conference. Please help to spread the word by distributing this announcement to colleagues, project mailing lists, friends, your blog, Web site, and through your social networking connections. Take a look at our publicity resources: http://wiki.europython.eu/Publicity General Information ------------------- For more information about the conference, please visit the official site: http://www.europython.eu/ Looking forward to see you! The EuroPython Team From python at mrabarnett.plus.com Mon Mar 15 11:44:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Mar 2010 15:44:43 +0000 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: <4B9E55EB.7080802@mrabarnett.plus.com> Lan Qing wrote: > Or use the regular module: > > import re > import os > > for filename in os.listdir('.'): > if re.match("*HV*", filename): > # do something with the file > The regular expression should be ".*HV.*", although: re.search("HV", filename) would be better and: "HV" in filename.upper() would be even better, as Alf posted. > On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach > wrote: > > * Sang-Ho Yun: > > I learned that I can check the existence of a file using > os.path.isfile("filename"). > > What if I need to check if there is a file that contains "HV" in the > filename? What should I do? > > > > from __future__ import print_function > import os > > for filename in os.listdir( "." ): > if "HV" in filename.upper(): > print( filename ) > > > > Cheers & hth., > > - Alf > > -- > http://mail.python.org/mailman/listinfo/python-list > > From python at mrabarnett.plus.com Mon Mar 15 11:51:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Mar 2010 15:51:25 +0000 Subject: Large regular expressions In-Reply-To: References: Message-ID: <4B9E577D.8040905@mrabarnett.plus.com> Nathan Harmston wrote: > Hi, > > So I m trying to use a very large regular expression, basically I have > a list of items I want to find in text, its kind of a conjunction of > two regular expressions and a big list......not pretty. However > everytime I try to run my code I get this exception: > > OverflowError: regular expression code size limit exceeded > > I understand that there is a Python imposed limit on the size of the > regular expression. And although its not nice I have a machine with > 12Gb of RAM just waiting to be used, is there anyway I can alter > Python to allow big regular expressions? > > Could anyone suggest other methods of these kind of string matching in > Python? I m trying to see if my swigged alphabet trie is faster than > whats possible in Python! > There's the regex module at http://pypi.python.org/pypi/regex. It'll even release the GIL while matching on strings! :-) From elias.bachaalany at gmail.com Mon Mar 15 12:39:50 2010 From: elias.bachaalany at gmail.com (lallous) Date: Mon, 15 Mar 2010 09:39:50 -0700 (PDT) Subject: to pass self or not to pass self Message-ID: Hello, Learning Python from the help file and online resources can leave one with many gaps. Can someone comment on the following: # --------- class X: T = 1 def f1(self, arg): print "f1, arg=%d" % arg def f2(self, arg): print "f2, arg=%d" % arg def f3(self, arg): print "f3, arg=%d" % arg # this: F = f2 # versus this: func_tbl = { 1: f1, 2: f2, 3: f3 } def test1(self, n, arg): # why passing 'self' is needed? return self.func_tbl[n](self, arg) def test2(self): f = self.f1 f(6) f = self.F # why passing self is not needed? f(87) # --------- x = X() x.test1(1, 5) print '----------' x.test2() Why in test1() when it uses the class variable func_tbl we still need to pass self, but in test2() we don't ? What is the difference between the reference in 'F' and 'func_tbl' ? Thanks, Elias From constant.beta at gmail.com Mon Mar 15 12:56:39 2010 From: constant.beta at gmail.com (Michal Kwiatkowski) Date: Mon, 15 Mar 2010 09:56:39 -0700 (PDT) Subject: Arguments and a return value of a C function call when using setprofile Message-ID: Hi, I'm trying to write code that will trace arguments and return values of all function calls. Using sys.settrace with 'call' and 'return' events works great for Python functions, but now I want to extend that to C functions as well. Using sys.setprofile instead in theory gives me what I need ('c_call' and 'c_return'), but I'm stuck on getting actual arguments and return values. A snippet of code is worth a thousand words, so here it is: import inspect import sys def trace(frame, event, arg): if event == 'call': print "CALL", frame.f_code.co_name, "arguments:", inspect.getargvalues(frame) elif event == 'return': print "RETURN", frame.f_code.co_name, "return value:", arg elif event == 'c_call': print "C_CALL", arg.__name__, "???" elif event == 'c_return': print "C_RETURN", arg.__name__, "???" def func(x): return x+1 sys.setprofile(trace) func(1) # Python function repr(2) # C function sys.setprofile(None) For a 'c_call' event the trace function is called *before* the call, so frame is still in the context of the caller. 'c_return' event is invoked *after* the function has returned, so I don't get the return value here either. That's why I can't use inspect.getargvalues in those cases. Is there any other way I could get arguments and a return value of a C function call? Cheers, mk From steve at holdenweb.com Mon Mar 15 13:06:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Mar 2010 13:06:45 -0400 Subject: Python for newbies (Pythno users group in Macedonia) In-Reply-To: <28u177-m9j.ln1@archaeopteryx.softver.org.mk> References: <28u177-m9j.ln1@archaeopteryx.softver.org.mk> Message-ID: ?????? ??????????? wrote: >> If you are all English-speakers then perhaps you could consider >> showing a PyCon video - see >> >> http://pycon.blip.tv > > That's certainly something I'm considering for the more advanced users > >> Good luck with the group. I hope to see PyCon Macedonia emerging >> before too long! > > Thanks :) > I guess we'd have to wait a decade or so for a PyCon here > You might be surprised. Python is really taking off right now. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Mar 15 13:09:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Mar 2010 13:09:46 -0400 Subject: Fwd: Some PyCon videos won't play In-Reply-To: References: Message-ID: <4B9E69DA.7080608@holdenweb.com> Lan Qing wrote: > In China these video can not watch at all. I must spent 3 days to > download it... > That's a great pity. If they would be useful to a large population perhaps we could consider having copies hosted where they would be available with higher bandwidth? Who could we (the Python Software Foundation) discuss such a project with? regards Steve > On Mon, Mar 15, 2010 at 5:19 AM, Terry Reedy > wrote: > > On 3/14/2010 2:41 PM, Terry Reedy wrote: > > On 3/14/2010 11:14 AM, David Boddie wrote: > > > You should still be able to get at the videos themselves by > inspecting > the page contents, looking for download links like this one: > > http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv > > > In this case, it's an Ogg Theora video file, so you may want > to use > a player like VLC to view it: > > > For people using html5 competant browsers, which, I believe, > play .ogv > 'in tha page', blip.tv just needs to update > site to make html5 pages an > alternative to using the flash player. > > > Actually, for FF3.6, at least, the problem is already solved. I just > click on the download button and FF recognizes .ogv as something it > can play and it does, replacing the flash player. The FF player > lacks a full-screen button, but that is rarely needed for the talks. > > tjr > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From martin.schmidt1 at gmail.com Mon Mar 15 13:16:01 2010 From: martin.schmidt1 at gmail.com (Martin Schmidt) Date: Mon, 15 Mar 2010 13:16:01 -0400 Subject: extract occurrence of regular expression from elements of XML documents Message-ID: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> Hi, I have just started to use Python a few weeks ago and until last week I had no knowledge of XML. Obviously my programming knowledge is pretty basic. Now I would like to use Python in combination with ca. 2000 XML documents (about 30 kb each) to search for certain regular expression within specific elements of these documents. I would then like to record the number of occurrences of the regular expression within these elements. Moreover I would like to count the total number of words contained within these, and record the attribute of a higher level element that contains them. I was trying to figure out the best way how to do this, but got overwhelmed by the available information (e.g. posts using different approaches based on dom, sax, xpath, elementtree, expat). The outcome should be a file that lists the extracted attribute, the number of occurrences of the regular expression, and the total number of words. I did not find a post that addresses my problem. If someone could help me with this I would really appreciate it. Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From howe.steven at gmail.com Mon Mar 15 13:20:10 2010 From: howe.steven at gmail.com (Steven Howe) Date: Mon, 15 Mar 2010 10:20:10 -0700 Subject: File existence check with partial filename In-Reply-To: <4B9E55EB.7080802@mrabarnett.plus.com> References: <4B9E55EB.7080802@mrabarnett.plus.com> Message-ID: <4B9E6C4A.20509@gmail.com> What wrong with glob? ----------------------- Help on module glob: NAME glob - Filename globbing utility. FILE /usr/lib64/python2.6/glob.py FUNCTIONS glob(pathname) Return a list of paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la fnmatch. iglob(pathname) Return an iterator which yields the paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la fnmatch. DATA __all__ = ['glob', 'iglob'] ------------------- solution: import glob for afile in glob.iglob( "/home/buddy/*.HV" ): print afile sph On 03/15/2010 08:44 AM, MRAB wrote: > Lan Qing wrote: >> Or use the regular module: >> >> import re >> import os >> >> for filename in os.listdir('.'): >> if re.match("*HV*", filename): >> # do something with the file >> > The regular expression should be ".*HV.*", although: > > re.search("HV", filename) > > would be better and: > > "HV" in filename.upper() > > would be even better, as Alf posted. > >> On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach > > wrote: >> >> * Sang-Ho Yun: >> >> I learned that I can check the existence of a file using >> os.path.isfile("filename"). >> >> What if I need to check if there is a file that contains "HV" >> in the >> filename? What should I do? >> >> >> >> from __future__ import print_function >> import os >> >> for filename in os.listdir( "." ): >> if "HV" in filename.upper(): >> print( filename ) >> >> >> >> Cheers & hth., >> >> - Alf >> >> -- http://mail.python.org/mailman/listinfo/python-list >> >> > From steve at holdenweb.com Mon Mar 15 13:29:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Mar 2010 13:29:51 -0400 Subject: extract occurrence of regular expression from elements of XML documents In-Reply-To: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> References: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> Message-ID: Martin Schmidt wrote: > Hi, > > I have just started to use Python a few weeks ago and until last week I > had no knowledge of XML. > Obviously my programming knowledge is pretty basic. > Now I would like to use Python in combination with ca. 2000 XML > documents (about 30 kb each) to search for certain regular expression > within specific elements of these documents. > I would then like to record the number of occurrences of the regular > expression within these elements. > Moreover I would like to count the total number of words contained > within these, and record the attribute of a higher level element that > contains them. > I was trying to figure out the best way how to do this, but got > overwhelmed by the available information (e.g. posts using different > approaches based on dom, sax, xpath, elementtree, expat). > The outcome should be a file that lists the extracted attribute, the > number of occurrences of the regular expression, and the total number of > words. > I did not find a post that addresses my problem. > If someone could help me with this I would really appreciate it. > You would get more specific help if you could post an example of the XML and describe the regex searching you want to do in a little more detail, I suspect. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From joel.pendery at gmail.com Mon Mar 15 13:37:34 2010 From: joel.pendery at gmail.com (Joel Pendery) Date: Mon, 15 Mar 2010 10:37:34 -0700 (PDT) Subject: subtraction is giving me a syntax error Message-ID: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> So I am trying to write a bit of code and a simple numerical subtraction y_diff = y_diff-H is giving me the error Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no encoding declared. Even though I have deleted some lines before it and this line is no longer line 70, I am still getting the error every time. I have tried to change the encoding of the file to utf-8 but to no avail, I still am having this issue. Any ideas? Thanks in advance From tomf.sessile at gmail.com Mon Mar 15 13:42:41 2010 From: tomf.sessile at gmail.com (TomF) Date: Mon, 15 Mar 2010 10:42:41 -0700 Subject: to pass self or not to pass self References: Message-ID: <2010031510424116807-tomfsessile@gmailcom> On 2010-03-15 09:39:50 -0700, lallous said: > Hello, > > Learning Python from the help file and online resources can leave one > with many gaps. Can someone comment on the following: > > # --------- > class X: > T = 1 > > def f1(self, arg): > print "f1, arg=%d" % arg > def f2(self, arg): > print "f2, arg=%d" % arg > def f3(self, arg): > print "f3, arg=%d" % arg > > # this: > F = f2 > # versus this: > func_tbl = { 1: f1, 2: f2, 3: f3 } > > def test1(self, n, arg): > # why passing 'self' is needed? > return self.func_tbl[n](self, arg) > > def test2(self): > f = self.f1 > f(6) > > f = self.F > # why passing self is not needed? > f(87) > > # --------- > x = X() > > x.test1(1, 5) > print '----------' > x.test2() > > Why in test1() when it uses the class variable func_tbl we still need > to pass self, but in test2() we don't ? > > What is the difference between the reference in 'F' and 'func_tbl' ? I recommend putting print statements into your code like this: def test1(self, n, arg): print "In test1, I'm calling a %s" % self.func_tbl[n] return self.func_tbl[n](self, arg) def test2(self): f = self.f1 print "Now in test2, I'm calling a %s" % f f(6) Bottom line: You're calling different things. Your func_tbl is a dict of functions, not methods. -Tom From R.Brodie at rl.ac.uk Mon Mar 15 13:42:50 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 15 Mar 2010 17:42:50 -0000 Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: "Joel Pendery" wrote in message news:56597268-3472-4fd9-a829-6d9cf51cf093 at e7g2000yqf.googlegroups.com... >> y_diff = y_diff-H > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. That's likely an en-dash, not a minus sign. From benjamin.kaplan at case.edu Mon Mar 15 13:48:08 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Mar 2010 13:48:08 -0400 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: On Mon, Mar 15, 2010 at 1:37 PM, Joel Pendery wrote: > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? > > Thanks in advance > It's not UTF-8. My guess would be that you're on Windows and it's a dash character in cp1252. The actual minus sign is 0x2D. Your editor must be putting in the wrong character. -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Mar 15 13:48:54 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Mar 2010 13:48:54 -0400 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <3620300A-6BDB-40DA-98D0-9FB1D4E4B071@semanchuk.com> On Mar 15, 2010, at 1:37 PM, Joel Pendery wrote: > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? 0x96 is the Win1252 minus sign character. Did you copy & paste this code from a Web browser or a word processor? Delete the character between "y_diff" and "H" and replace it with a plain ASCII subtraction sign. From python at mrabarnett.plus.com Mon Mar 15 14:00:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Mar 2010 18:00:42 +0000 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <4B9E75CA.4010203@mrabarnett.plus.com> Joel Pendery wrote: > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? > > Thanks in advance Character '\x96' is an en-dash, which looks like a hyphen/minus sign '-', but isn't. From rami.chowdhury at gmail.com Mon Mar 15 14:01:00 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 15 Mar 2010 11:01:00 -0700 Subject: to pass self or not to pass self In-Reply-To: <2010031510424116807-tomfsessile@gmailcom> References: <2010031510424116807-tomfsessile@gmailcom> Message-ID: <201003151101.01118.rami.chowdhury@gmail.com> On Monday 15 March 2010 10:42:41 TomF wrote: > On 2010-03-15 09:39:50 -0700, lallous said: > > > > Why in test1() when it uses the class variable func_tbl we still need > > to pass self, but in test2() we don't ? > > > > What is the difference between the reference in 'F' and 'func_tbl' ? > > I recommend putting print statements into your code like this: > > def test1(self, n, arg): > print "In test1, I'm calling a %s" % self.func_tbl[n] > return self.func_tbl[n](self, arg) > > def test2(self): > f = self.f1 > print "Now in test2, I'm calling a %s" % f > f(6) > > > Bottom line: You're calling different things. Your func_tbl is a dict > of functions, not methods. > > -Tom To build on that a bit, note that in test2() you are doing: > > f = self.f1 > > f(6) > > > > f = self.F > > # why passing self is not needed? > > f(87) As I understand it, since you obtained the reference to 'f1' from 'self', you got it as a bound rather than an unbound method. So 'self' is automatically passed in as the first argument. ---- Rami Chowdhury "Given enough eyeballs, all bugs are shallow." -- Linus' Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From invalid at invalid.invalid Mon Mar 15 14:09:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 15 Mar 2010 18:09:29 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: On 2010-03-15, Philip Semanchuk wrote: > On Mar 15, 2010, at 1:37 PM, Joel Pendery wrote: > >> So I am trying to write a bit of code and a simple numerical >> subtraction >> >> y_diff = y_diff-H >> >> is giving me the error >> >> Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no >> encoding declared. [...] > > 0x96 is the Win1252 minus sign character. Did you copy & paste this > code from a Web browser or a word processor? > > Delete the character between "y_diff" and "H" and replace it with a > plain ASCII subtraction sign. I think somebody needs to stop editing his code with MS Word and start using a programming editor. ;) -- Grant Edwards grant.b.edwards Yow! Make me look like at LINDA RONSTADT again!! gmail.com From jeanmichel at sequans.com Mon Mar 15 14:24:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:24:38 +0100 Subject: class inheritance In-Reply-To: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <4B9E7B66.10702@sequans.com> JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? > I would change the approach. To the question, "*is* a Value a Fraction", some may tempted to answer "No" (for instance, a fraction has a denominator, a value has not). However "Does a Fraction *have* a Value", you could possibly say "Yes". The value may be then an attribute of the class Fraction, not a subclass. To test fraction equality, use F1 == F2. In order to test 'nearly equality', use F1.val() == F2.val(). JM From jeanmichel at sequans.com Mon Mar 15 14:25:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:25:00 +0100 Subject: staticmethod and setattr In-Reply-To: <1268663020.10067.35.camel@laptop> References: <1268663020.10067.35.camel@laptop> Message-ID: <4B9E7B7C.8050701@sequans.com> Am Montag, den 15.03.2010, 05:42 -0700 schrieb Michael.Lausch: >> On Mar 15, 11:40 am, Steven D'Aprano > cybersource.com.au> wrote: >> >>> On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: >>> >>>> Hi, >>>> >>>> I managed to get confused by Python, which is not such an easy task. >>>> >>>> The problem i have is rooted in marshalling, JSON and Dojo. I need some >>>> static class in function with the name "$ref" i tried: >>>> class Foo(object): >>>> @staticmethod >>>> def _ref(o): >>>> pass >>>> >>>> setattr(Foo, "$ref", Foo._ref) >>>> >>> That doesn't work as expected: >>> >>> >>>>>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] >>>>>> >>> False >>> >>> Try this instead: >>> >>> >>>>>> setattr(Foo, "$ref", Foo.__dict__['_ref']) >>>>>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] >>>>>> >>> True >>> >> Now I'm trying to understand why this is the case. >> How is Foo.__dict__['_ref'] different from Foo._ref? >> Shouldn't it return the same attribute? >> >> And after further experiments i found out that a making >> Foo._ref a classmethod does work with my first approach. >> >> When you declared _ref as static, a static object has been stored in Foo. Using Foo.__dict__ you can access this static object, which is *not* the _ref function Using Foo._ref, you trigger the lookup mechanism which do much more than accessing the dict. Especially, if it finds a __get__ method in the object, it will return the __get__ result instead of the object itself. Foo._ref is equivalent in your case to Foo.__dict__['_ref'].__get__(None, Foo) JM From jeanmichel at sequans.com Mon Mar 15 14:39:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:39:31 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <1268597301.21932.1364768439@webmail.messagingengine.com> Message-ID: <4B9E7EE3.6000807@sequans.com> Steve Holden wrote: > python at bdurham.com wrote: > >>>> Any reason you prefer PDB over WinPDB? >>>> http://winpdb.org/ >>>> >>> Yes. I don't have Windows except one one PC :P >>> >> WinPDB runs on non-Windows platforms :) >> >> > One might reasonably argue that it has a pretty couter-intuitive name, then. > > regards > Steve > 'Win' may stand for Winner, not Windows :D JM From jeanmichel at sequans.com Mon Mar 15 14:41:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:41:18 +0100 Subject: "Breaking" the __main__ script In-Reply-To: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <4B9E7F4E.4040900@sequans.com> vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like stop, break, end or something similar. > > What statement can I use? > > Vicente Soler > import bdb pdb.set_trace() # put this line anywhere you want a breakpoint in your code. type n for next, c for continue, s for step into and google for 'python pdb' for the details. JM From baptiste13z at free.fr Mon Mar 15 14:43:53 2010 From: baptiste13z at free.fr (Baptiste Carvello) Date: Mon, 15 Mar 2010 19:43:53 +0100 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: Joel Pendery a ?crit : > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? > > Thanks in advance Hello, I would say that when you press the minus key, your operating system doesn't encode the standard (ASCII) minus character, but some fancy character, which Python cannot interpret. More precisely, I suspect you are unsing Windows with codepage 1252 (latin 1). With this encoding, you have 2 kinds of minus signs: the standard (45th character, in hex '\x2d') and the non-standard (150th character, in hex '\x96'). cf: http://msdn.microsoft.com/en-us/library/cc195054.aspx Cheers, Baptiste From jeanmichel at sequans.com Mon Mar 15 14:50:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:50:18 +0100 Subject: "Breaking" the __main__ script In-Reply-To: <4B9E7F4E.4040900@sequans.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <4B9E7F4E.4040900@sequans.com> Message-ID: <4B9E816A.7090608@sequans.com> Jean-Michel Pichavant wrote: > vsoler wrote: >> Hello, >> >> I am still learning python, thus developnig small scripts. >> >> Some of them consist only of the main module. While testing them >> (debugging) I sometimes want to stop the script at a certain point, >> with something like stop, break, end or something similar. >> >> What statement can I use? >> >> Vicente Soler >> > import bdb > > pdb.set_trace() # put this line anywhere you want a breakpoint in your > code. > > type n for next, c for continue, s for step into and google for > 'python pdb' for the details. > > JM erratum import pdb From astley.lejasper at gmail.com Mon Mar 15 15:10:21 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Mon, 15 Mar 2010 12:10:21 -0700 (PDT) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> <4B9A9624.7040200@v.loewis.de> Message-ID: <8aa22e57-f152-4dc7-88da-cf6879de41f7@q16g2000yqq.googlegroups.com> Hi Robin, It looks like you've been busy. I'm sorry but you are well over my head at the moment! :-) If you need me to test an install then I'd be happy to help. However, I just received an email from Christoph Gohlke saying: " ... There are 64 bit versions of Reportlab and PIL for Python 2.6 for Windows available at http://www.lfd.uci.edu/~gohlke/pythonlibs/ ..." Regards Neil From dmitrey.kroshko at scipy.org Mon Mar 15 15:13:29 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Mon, 15 Mar 2010 12:13:29 -0700 (PDT) Subject: [ANN] OpenOpt 0.28, FuncDesigner 0.18, DerApproximator 0.18 Message-ID: <4e6fa172-6edb-4c1a-bc9d-8ba334008101@d27g2000yqf.googlegroups.com> Hi all, I'm glad to inform you about new release of our free (BSD-licensed) soft OpenOpt 0.28 (numerical optimization), FuncDesigner 0.18 (CAS with automatic differentiation), DerApproximator 0.18 (finite- differeces derivatives approximation). More details here: http://forum.openopt.org/viewtopic.php?id=222 Regards, D. From philip at semanchuk.com Mon Mar 15 15:38:54 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Mar 2010 15:38:54 -0400 Subject: Clustering and automated configuration & deployment toolkit with Python In-Reply-To: <003064f8-e559-41e9-8110-11fad8373d09@y17g2000yqd.googlegroups.com> References: <003064f8-e559-41e9-8110-11fad8373d09@y17g2000yqd.googlegroups.com> Message-ID: <577D1DA0-EAB5-4AC0-8C65-5E22CD56475C@semanchuk.com> On Mar 13, 2010, at 6:21 PM, np map wrote: > I'd like to write an open source clustering (for computation and > general use) and automation of configuration/deployment in Python. > It's main purpose is to be used in academic environments. > It would be something like running numpy/simpy code (and other custom > python code) on a set of machines in a distributed fashion (e.g. > splitting tasks, doing certain bits on some machines, other sub-tasks > on other machines, etc). Hi np map, Are you aware of ipython? My colleagues tell me that it contains some code for executing processes on remote machines. It sounds like code which you could build on or borrow from. HTH Philip > > The cluster could be used in at least two ways: > - submit code/files via a web interface, monitor the task via the web > interface and download the results from the master node (user<>web > interface<>master) > - run code directly from another machine on the cluster (as if it were > a subprocess or something like this) > > > Requirements (so far): > - support the Ubuntu Linux distribution in the initial iteration > - be easy to extend to other OS-es and package managers > - try to be 3.x compatible where dual compatibility is possible (2.x > and 3.x) > - it will support Python 2.5-2.6 > - document required changes to the 2.x only code to make it work on > 3.x > - make it easy to submit code directly from python scripts to the > cluster (with the right credentials) > - support key based authentication for job submission > - should talk to at least one type of RDBMS to store various types of > data > - the cluster should be able to kill a task on nodes automatically if > it executes for too long or requires too much memory (configurable) > - should be modular (use automation & configuration or just > clustering) > > > Therefore, I'd like to know a few things: > > Is there a clustering toolkit already available for python? > > What would the recommended architecture be ? > > How should the "user" code interface with the clustering system's > code? > > How should the results be stored (at the node and master level)? > > Should threading be supported in the tasks? > > How should they be returned to the Master node(s)? (polling, submitted > by the nodes, etc) > > What libraries should be used for this? (e.g. fabric as a library, > pyro, etc) > > Any other suggestions and pieces of advice? > > Should Fabric be used in this clustering system for automation? If > not, what else? Would simply using a wrapper written in python for the > 'ssh' app be ok? > > Would the following architecture be ok? > Master: splits tasks into sub-tasks, sends them to nodes - provided > the node's load isn't greater than a certain percentage, gets results, > stores and provides configuration to nodes, stores results, etc > Node: runs code, applies configuration, submits the results to the > master, etc > > If this system actually gets python-level code submission inside, how > should it work? > > The reason I posted this set of questions and ideas is that I'd like > this to be as flexible and usable as possible. From aahz at pythoncraft.com Mon Mar 15 15:57:23 2010 From: aahz at pythoncraft.com (Aahz) Date: 15 Mar 2010 12:57:23 -0700 Subject: When to lock data items returned by multiprocessing.Manager? References: <4428d674-7fa7-4095-a93d-75ea31a81d9a@15g2000yqi.googlegroups.com> Message-ID: In article <4428d674-7fa7-4095-a93d-75ea31a81d9a at 15g2000yqi.googlegroups.com>, Veloz wrote: > >So I'm using a multiprocessing.Manager instance in my main app and >asking it to create a dictionary, which I am providing to instances of >the application that I'm forking off with Process. > >The Processes and main app will be reading/writing to the dictionary. > >It's not clear to me what I have to "lock" and what I don't have to >lock. Any ideas? The way I deal with it is by making sure each key is only updated by a single process. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From jkn_gg at nicorp.f9.co.uk Mon Mar 15 16:52:16 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 15 Mar 2010 13:52:16 -0700 (PDT) Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: Hi Greg Just to say thanks for taking the time to write up your work on this interesting topic. Cheers J^n From debatem1 at gmail.com Mon Mar 15 16:57:23 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 15 Mar 2010 16:57:23 -0400 Subject: Reverse engineering CRC? In-Reply-To: <4B9E0C1F.9020003@canterbury.ac.nz> References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: On Mon, Mar 15, 2010 at 6:29 AM, Gregory Ewing wrote: > I've solved the problem now. > > It turned out to be a very standard CRC algorithm, complicated > by the presence of a few extra bytes of data being checked that > didn't appear explicitly in the file anywhere. > > In the process I developed some very general techniques for > solving this kind of problem, which I've written about here > if anyone's interested: > > http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html > > Thanks for everyone's help, > Greg Nice writeup, thanks. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Mon Mar 15 18:33:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Mar 2010 22:33:33 GMT Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote: >> Delete the character between "y_diff" and "H" and replace it with a >> plain ASCII subtraction sign. > > I think somebody needs to stop editing his code with MS Word and start > using a programming editor. ;) I've had this error myself, and I've never used Word to edit code. It can happen if you copy code from a website that "helpfully" converts hyphens to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z characters into strings, etc. They're a devil to debug. -- Steven From sjmachin at lexicon.net Mon Mar 15 18:48:45 2010 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Mar 2010 15:48:45 -0700 (PDT) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <6e982a4f-ebef-4b91-957d-7b50895c7f5d@k18g2000prf.googlegroups.com> On Mar 16, 5:43?am, Baptiste Carvello wrote: > Joel Pendery a ?crit : > > So I am trying to write a bit of code and a simple numerical > > subtraction > > > y_diff = y_diff-H > > > is giving me the error > > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > > encoding declared. > > > I would say that when you press the minus key, your operating system doesn't > encode the standard (ASCII) minus character, but some fancy character, which > Python cannot interpret. The likelihood that any operating system however brain-damaged and in whatever locale would provide by default a "keyboard" or "input method" that generated EN DASH when the '-' key is struck is somewhere between zero and epsilon. Already advanced theories like "used a word processor instead of a programmer's editor" and "scraped it off the web" are much more plausible. > More precisely, I suspect you are unsing Windows with codepage 1252 (latin 1). Codepage 1252 is not "latin1" in the generally accepted meaning of "latin1" i.e. ISO-8859-1. It is a superset. MS in their wisdom or otherwise chose to use most of the otherwise absolutely wasted slots assigned to "C1 control characters" in latin1. > With this encoding, you have 2 kinds of minus signs: the standard (45th > character, in hex '\x2d') and the non-standard (150th character, in hex '\x96'). > > cf:http://msdn.microsoft.com/en-us/library/cc195054.aspx The above link quite correctly says that '\x96` maps to U+2013 EN DASH. EN DASH is not any kind of minus sign. Aside: the syndrome causing the problem is apparent with cp125x for x in range(9) From invalid at invalid.invalid Mon Mar 15 18:56:19 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 15 Mar 2010 22:56:19 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-15, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote: > >>> Delete the character between "y_diff" and "H" and replace it with a >>> plain ASCII subtraction sign. >> >> I think somebody needs to stop editing his code with MS Word and start >> using a programming editor. ;) > > I've had this error myself, and I've never used Word to edit code. It can > happen if you copy code from a website that "helpfully" converts hyphens > to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z characters > into strings, etc. They're a devil to debug. Though it may not be Microsoft Word, I think I'd still maintain that an editor where you can't see a ctrl-Z or tell the difference between an ASCII minus and a windows-codepage-whatever isn't a very good programmer's editor. -- Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are at inserted into VATS of gmail.com NUTRITIONAL YEAST ... From jlundell at pobox.com Mon Mar 15 19:34:35 2010 From: jlundell at pobox.com (JLundell) Date: Mon, 15 Mar 2010 16:34:35 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> Message-ID: <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> On Mar 13, 1:26?pm, Carl Banks wrote: > It's a tad unfortunately Python doesn't make this easier. ?If I had to > do it more than once I'd probably write a mixin to do it: > > class ArithmeticSelfCastMixin(object): > ? ? def __add__(self,other): > ? ? ? ? return > self.__class__(super(ArithmeticSelfCastMixin,self).__add__(other) > ? ? # etc. > > class Value(ArithmeticSelfCastMixin,fraction.Fraction): > ? ? pass > > However, I want to warn you about overriding __eq__ to mean "almost > equal": it can have unexpected results so I don't recommend it. ?Two > of the main issues with it are: > > 1. It violates the transitive property ("If A == B and B == C, then A > == C") which most programmers expect to be true. > > 2. It will give unpredictable results when the objects are used in > sets or as dictionary keys. ?Those thow types expect the transitive > property to be true. ?If you are going to redefine __eq__ to mean > "almost equal", then at least define __hash__ to raise > NotImplementedError so that Python will refuse to use them in sets or > as dictionary keys: > > ? ? def __hash__(self): raise NotImplementedError > > Carl Banks It's also unfortunate that Python doesn't have an approximately-equal operator; it'd come in handy for floating-point applications while preserving hash. If only there were a ~= or ? operator I could overload. And ~ is unary, so no joy. My application is in that sense a little like a floating-point app, in that it needs approximately-equal. And it doesn't need Value to be hashable; thanks for the NotImplementedError suggestion; I've done that as a safeguard. From mail at hellmutweber.de Mon Mar 15 19:36:01 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Tue, 16 Mar 2010 00:36:01 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: Message-ID: <4B9EC461.9090009@hellmutweber.de> Am 11.03.2010 12:14, schrieb Peter Otten: > Hellmut Weber wrote: > >> Logging works very well giving the filename and line number of the point >> where it is called. As long as I use the loggers directly. >> BUT when I have to wrap the logger call in some other function, I always >> get file name and line number of the call of the logger inside the >> wrapping function. >> >> Is there a possibility to get this information in this situation too? > > The official way is probably to write a custom Logger class that overrides > the findCaller() method. > > Below is a hack that monkey-patches the logging._srcfile attribute to ignore > user-specified modules in the call stack: > > $ cat wrapper.py > import logging > import os > import sys > > logger = logging.getLogger() > > class SrcFile(object): > def __init__(self, exclude_files): > self.files = set(exclude_files) > def __eq__(self, other): > return other in self.files > > def fixname(filename): > if filename.lower().endswith((".pyc", ".pyo")): > filename = filename[:-4] + ".py" > return os.path.normcase(filename) > > if "--monkey" in sys.argv: > print "patching" > logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) > > def warn(*args, **kw): > logger.warn(*args, **kw) > > $ cat main.py > import logging > logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") > import wrapper > wrapper.warn("foo") > wrapper.warn("bar") > wrapper.warn("baz") > > $ python main.py > wrapper.py<23>: foo > wrapper.py<23>: bar > wrapper.py<23>: baz > > $ python main.py --monkey > patching > main.py<4>: foo > main.py<5>: bar > main.py<6>: baz > > $ python -V > Python 2.6.4 > > Peter Hi Peter, thanks for your help ;-) I've been offline for a few days so I found your message only today. I'll try your proposal tomorrow. Thanks again Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From pavlovevidence at gmail.com Mon Mar 15 21:03:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Mar 2010 18:03:15 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> Message-ID: <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> On Mar 15, 4:34?pm, JLundell wrote: > It's also unfortunate that Python doesn't have an approximately-equal > operator; it'd come in handy for floating-point applications while > preserving hash. If only there were a ~= or ? operator I could > overload. And ~ is unary, so no joy. One problem with it is that there's no way to make it universal; different appiplications have different ideas of close. Conceivably it could be usefully defined for a user type though.. Bacause of this problem almost no languages have an almost equal operator. I'm curious what languages do, of if there are any with a trinary operator that also takes a threshold. Carl Banks From twistedphrame at gmail.com Mon Mar 15 22:07:00 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Mon, 15 Mar 2010 19:07:00 -0700 (PDT) Subject: Binary data transfer issue Message-ID: <40c9fafc-a172-4c9c-ba21-35ac8a4029aa@z35g2000yqd.googlegroups.com> Hi all, I'm trying to transfer a binary file over xmlrpclib. My test file is a .jpeg file. I can transfer all the data over but when I go to open the .jpeg I get "Error interpreting JPEG image file (Invalid JPEG file structure: SOS before SOF)" here's the code: ===========Various Shared Functions======== #EncodeAES takes a Cipher c and encrypts a String s EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) #DecodeAES takes a Cipher C and decrypts the cyphertext e #then removes the padding from the decrypted string DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING) CIPHER = AES.new("KEY") # method to change strings back into tuples def stringToTuple(string): if string[0] + string[-1] == "()": items = string[1:-1] items = items.split(',') return items else: raise ValueError("Badly formatted string (missing brackets).") ======client================= def Download(self, FileName, Data_Size=1024): ErrorCount = 0 Pkt_Num = -1 OldPkt_Num = Pkt_Num localFile = open("files/"+FileName, "wb") print print "Requesting First Packet" packet = self.client.download(EncodeAES(CIPHER, str(Pkt_Num))) if packet[0] == "False": print packet[1] return False packet = stringToTuple(DecodeAES(CIPHER, packet)) if int(packet[0]) == -3: print "Received Error Packet" else: print "Received Packet: ", int(packet[0]) print "packet[1], ", packet[2:-1] Pkt_Num = int(packet[0]) while Pkt_Num >= 0 and ErrorCount <= 10: if (OldPkt_Num +1) == Pkt_Num: OldPkt_Num = OldPkt_Num +1 localFile.write(binascii. a2b_base64(packet[1][2:-1])) #<<<= os.path.getsize("files/"+self.usr_dict[client][FILENAME]): return EncodeAES(CIPHER, str((-2, "File Transfer Complete"))) try: f = open("files/"+self.usr_dict[client][FILENAME], "rb") except IOError: return EncodeAES(CIPHER, str((-3, "File Could Not be opened"))) data = f.read((Pkt_Num+1 * DataRate)) data = None data = binascii.b2a_base64(f.read(DataRate)) #<<<<<<< References: <40c9fafc-a172-4c9c-ba21-35ac8a4029aa@z35g2000yqd.googlegroups.com> Message-ID: <4B9EF5F9.5010005@mrabarnett.plus.com> Jordan Apgar wrote: > Hi all, > > I'm trying to transfer a binary file over xmlrpclib. My test file is > a .jpeg file. I can transfer all the data over but when I go to open > the .jpeg I get "Error interpreting JPEG image file (Invalid JPEG file > structure: SOS before SOF)" > > here's the code: > > ===========Various Shared Functions======== > #EncodeAES takes a Cipher c and encrypts a String s > EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) > > #DecodeAES takes a Cipher C and decrypts the cyphertext e > #then removes the padding from the decrypted string > DecodeAES = lambda c, e: > c.decrypt(base64.b64decode(e)).rstrip(PADDING) > > > CIPHER = AES.new("KEY") > > > # method to change strings back into tuples > def stringToTuple(string): > if string[0] + string[-1] == "()": > items = string[1:-1] > items = items.split(',') > return items > else: > raise ValueError("Badly formatted string (missing brackets).") > > ======client================= > def Download(self, FileName, Data_Size=1024): > ErrorCount = 0 > Pkt_Num = -1 > OldPkt_Num = Pkt_Num > localFile = open("files/"+FileName, "wb") > print > print "Requesting First Packet" > packet = self.client.download(EncodeAES(CIPHER, str(Pkt_Num))) > if packet[0] == "False": > print packet[1] > return False > packet = stringToTuple(DecodeAES(CIPHER, packet)) > if int(packet[0]) == -3: > print "Received Error Packet" > else: > print "Received Packet: ", int(packet[0]) > > print "packet[1], ", packet[2:-1] > > Pkt_Num = int(packet[0]) > > while Pkt_Num >= 0 and ErrorCount <= 10: > if (OldPkt_Num +1) == Pkt_Num: > OldPkt_Num = OldPkt_Num +1 > localFile.write(binascii. > a2b_base64(packet[1][2:-1])) > #<<< ErrorCount == 0 > else: > ErrorCount = ErrorCount +1 > Pkt_Num = OldPkt_Num > > print "Requesting Packet: ", Pkt_Num +1 > packet = self.client.download(EncodeAES(CIPHER, > str(Pkt_Num))) > packet = stringToTuple(DecodeAES(CIPHER, packet)) > Pkt_Num = int(packet[0]) > if int(packet[0]) == -3: > print "Received Error Packet" > elif int(packet[0]) == -2: > print "Received EOF" > else: > print "Received Packet: ", int(packet[0]) > > localFile.close() > > if Pkt_Num == -2: > print packet[1][2:-1] > return True > elif Pkt_Num == -3: > os.remove("files/"+FileName) > print packet[1][2:-1] > return False > else: > os.remove("files/"+FileName) > print "Unexpected Packet: File Transfer Stopped" > return False > > > ==========Server Method============= > def download(self, Pkt_Num): > > Old_Pkt_Num = self.PKT > DataRate = self.DATA > Pkt_Num = int(DecodeAES(CIPHER,Pkt_Num)) > if Pkt_Num == -1 and Old_Pkt_Num == -1: > Pkt_Num = 0 > try: > f = open("files/"+self.usr_dict[client][FILENAME], > "rb") > except IOError: > return EncodeAES(CIPHER, > str((-3, "File Could Not be > opened"))) > data = binascii.b2a_base64(f.read((Pkt_Num+1 * > DataRate))) #<<<<< f.close() > self.usr_dict[client][PKT] = Pkt_Num > return EncodeAES(CIPHER, > str((Pkt_Num, data))) > > elif Pkt_Num == Old_Pkt_Num: > if Pkt_Num * DataRate >= > os.path.getsize("files/"+self.usr_dict[client][FILENAME]): > return EncodeAES(CIPHER, > str((-2, "File Transfer Complete"))) > try: > f = open("files/"+self.usr_dict[client][FILENAME], > "rb") > except IOError: > return EncodeAES(CIPHER, > str((-3, "File Could Not be opened"))) > data = f.read((Pkt_Num+1 * DataRate)) Here you're reading: Pkt_Num + DataRate bytes again, > data = None discarding what you've just read, > data = binascii.b2a_base64(f.read(DataRate)) > #<<<<<<< f.close() > self.usr_dict[client][PKT] = Pkt_Num +1 > > return EncodeAES(CIPHER, > str((Pkt_Num+1, data))) > > else: > > return EncodeAES(CIPHER, > str((-3, "Incorrect Packet Requested"))) > > > > Thank you all for the help, I know there are better ways and transfer > protocol modules to but I'd like to do this without them. > I'm not surprised that the transfer is failing! :-) From googler.1.webmaster at spamgourmet.com Mon Mar 15 23:15:37 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Mon, 15 Mar 2010 20:15:37 -0700 (PDT) Subject: Build Python with XCode Message-ID: Hi, I would like to build Python with Xcode (but without the makefile). Does anyone know a link where I can get a real xcodeproj with the current Py2.x sources? Thanks in advance!! Bye, donnerCobra From gagsl-py2 at yahoo.com.ar Mon Mar 15 23:52:43 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 00:52:43 -0300 Subject: converting datetime with tzinfo to unix timestamp References: <4B9ACB2B.3090203@gmail.com> Message-ID: En Fri, 12 Mar 2010 20:15:55 -0300, Michael Torrie escribi?: > On Python 2.5 here. > > I've searched and searched but I can't find any way to convert a > datetime object that includes a timezone (tzinfo) to a unix timestamp. > Folks on the net say to simply use the timetuple() method of the object > and feed that to time.mktime(). But that just doesn't seem to work for > me. At least if my understanding that the unix timestamp is always UTC. Try time.mktime(datetimeobject.utctimetuple()) instead. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 01:50:29 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 02:50:29 -0300 Subject: result of os.times() is different with 'time' command Options References: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> <61c563ad-f0c3-47ae-b689-36c397f88295@l11g2000pro.googlegroups.com> Message-ID: En Mon, 15 Mar 2010 03:51:28 -0300, hiral escribi?: > On Mar 15, 7:14 am, Tim Roberts wrote: >> hiral wrote: >> >Output: >> >real 0.0m0.0100000002421s >> >user 0.0m0.0s >> >sys 0.0m0.0s >> >> >Command: >> >$ time ls >> >> >Output: >> >real 0m0.007s >> >user 0m0.000s >> >sys 0m0.000s >> >> You can't really do an analysis like this with a task that only takes a >> few >> milliseconds. There are too many variables. > > Thanks for your explanation. Have you tested with the highly recursive function in that 2007 thread you linked to? This should take time enough to make a problem like this clearly visible. -- Gabriel Genellina From joshua.r.english at gmail.com Tue Mar 16 02:01:07 2010 From: joshua.r.english at gmail.com (Josh English) Date: Mon, 15 Mar 2010 23:01:07 -0700 (PDT) Subject: Dynamic Class Creation Message-ID: I have a large program with lots of data stored in XML. I'm upgrading my GUI to use ObjectListView, but with my data in XML, I don't have regular objects to interact with the OLV. I do have an XML validator that defines the structure of the XML elements, and I'm trying to dynamically create a class to wrap the XML element. So, an element like: Writers of the Future I want to create a class like: class Market(object): def __init__(self, elem): self._elem = elem def get_code(self): return self._elem.get('code') def set_code(self, value): self._elem.set('code', value) def get_title(self): return self._elem.find('title').text def set_title(self, value): node = self._elem.find('title') node.text = value Naturally, I don't want to hand code this for every interface but would like to create them dynamically. (The laziness of programming, I guess.) I have tried several solutions that I found on various forums, but they are all several years old. Questions: What's the best way to create these helper methods? How can I attach them to the class and have it run? I have had a few solutions work where I had a class with three methods (get_code, get_tier, get_mail) but they all return the same value, not the individual values. ---- Josh English From gagsl-py2 at yahoo.com.ar Tue Mar 16 02:16:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 03:16:54 -0300 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: En Mon, 15 Mar 2010 07:29:51 -0300, Gregory Ewing escribi?: > I've solved the problem now. > > It turned out to be a very standard CRC algorithm, complicated > by the presence of a few extra bytes of data being checked that > didn't appear explicitly in the file anywhere. > > In the process I developed some very general techniques for > solving this kind of problem, which I've written about here > if anyone's interested: > > http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html A good solution to an interesting problem - and very nicely explained too! -- Gabriel Genellina From clp2 at rebertia.com Tue Mar 16 02:18:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Mar 2010 23:18:54 -0700 Subject: Dynamic Class Creation In-Reply-To: References: Message-ID: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> On Mon, Mar 15, 2010 at 11:01 PM, Josh English wrote: > I have a large program with lots of data stored in XML. I'm upgrading > my GUI to use ObjectListView, but with my data in XML, I don't have > regular objects to interact with the OLV. I do have an XML validator > that defines the structure of the XML elements, and I'm trying to > dynamically create a class to wrap the XML element. > > So, an element like: > > > Writers of the Future > > > I want to create a class like: > > class Market(object): > ? ?def __init__(self, elem): > ? ? ? ?self._elem = elem > > ? ?def get_code(self): > ? ? ? ?return self._elem.get('code') > > ? ?def set_code(self, value): > ? ? ? ?self._elem.set('code', value) > > ? ?def get_title(self): > ? ? ? ?return self._elem.find('title').text > > ? ?def set_title(self, value): > ? ? ? ?node = self._elem.find('title') > ? ? ? ?node.text = value > > Naturally, I don't want to hand code this for every interface but > would like to create them dynamically. (The laziness of programming, I > guess.) > > I have tried several solutions that I found on various forums, but > they are all several years old. > > Questions: > > What's the best way to create these helper methods? Nested functions: def make_attr_getset(name): def get(self): return self._elem.get(name) def set(self, value): self._elem.set(name, value) return get, set get_code, set_code = make_attr_getset('code') def make_subelement_getset(name): def get(self): return self._elem.find(name).text def set(self, value): node = self._elem.find(name) node.text = value return get, set get_title, set_title = make_subelement_getset('title') > How can I attach them to the class and have it run? Use properties and setattr(): class Market(object): def __init__(... #same as before setattr(Market, 'code', property(get_code, set_code)) setattr(Market, 'title', property(get_title, set_title)) m = Market(the_XML) print m.title #=> Writers of the Future m.title = "Writers of the Past" print m.code #=> WotF m.code = "WofP" Cheers, Chris -- http://blog.rebertia.com From satyamrajuhyd at gmail.com Tue Mar 16 02:44:17 2010 From: satyamrajuhyd at gmail.com (Earn money) Date: Mon, 15 Mar 2010 23:44:17 -0700 (PDT) Subject: Data entry Work available Message-ID: Data entry works Available At No need to pay DEposite http://trading7000.blogspot.com/ Adposting Jobs Availble http://trading7000.blogspot.com/ No need to work Hard Earn Money From Home 7000 in Minutes http://trading7000.blogspot.com/ From gagsl-py2 at yahoo.com.ar Tue Mar 16 02:46:05 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 03:46:05 -0300 Subject: time_struct References: <23dbe409-60ed-4f6f-bd38-4336e4f1b3d0@f8g2000yqn.googlegroups.com> Message-ID: En Sun, 07 Mar 2010 10:50:59 -0300, moerchendiser2k3 escribi?: > can anyone tell me how to return a time_struct from the timemodule in > my own C-Module? > Is that possible? I can just find one function in timefuncs.h, but it > doesnt return any PyObject. The type is available as the struct_time attribute in the time module; you create an instance by calling it with a 9-items sequence. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 03:04:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 04:04:44 -0300 Subject: xml-rpc References: <4B9C9AF9.80609@gmail.com> Message-ID: En Sun, 14 Mar 2010 05:14:49 -0300, ahmet erdinc yilmaz escribi?: > Recenetly we are developing a senior project and decide to use xmlrpclib. > However I have some questions. In the documentation I could not find any > clue about > handling requests? Does the server handles each request in a separate > thread? Or is > there some queuing mechanism for client calls? Thanks in advance. xmlrpclib is a *client* library. Python also provides an XMLRPC *server* in the SimpleXMLRPCServer module. It inherits from SocketServer.TCPServer. The default behavior is to process one request at a time, in a single process. You may alter such behavior by additionally inheriting from ForkingMixIn or ThreadingMixIn. -- Gabriel Genellina From no.email at nospam.invalid Tue Mar 16 03:39:55 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 16 Mar 2010 00:39:55 -0700 Subject: affectation in if statement References: Message-ID: <7x8w9s4svo.fsf@ruckus.brouhaha.com> samb writes: > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > else: > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > else > thing = "" > > Which isn't nice neither because I'm going to have maybe 20 match > tests and I wouldn't like to have 20 indentations. for pat in [r'define\s+(\S+)\s*{$', r'include\s+(\S+)$', ...]: m = re.match(pat, line) ... From ldo at geek-central.gen.new_zealand Tue Mar 16 03:40:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Mar 2010 20:40:36 +1300 Subject: import antigravity Message-ID: Subtle... From sam.bancal at gmail.com Tue Mar 16 03:45:34 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 00:45:34 -0700 (PDT) Subject: affectation in if statement Message-ID: Hi, I'm trying to do something like : if m = re.match(r'define\s+(\S+)\s*{$', line): thing = m.group(1) elif m = re.match(r'include\s+(\S+)$', line): thing = m.group(1) else thing = "" But in fact I'm not allowed to affect a variable in "if" statement. My code should then look like : if re.match(r'define\s+(\S+)\s*{$', line): m = re.match(r'define\s+(\S+)\s*{$', line) thing = m.group(1) elif re.match(r'include\s+(\S+)$', line): m = re.match(r'include\s+(\S+)$', line) thing = m.group(1) else thing = "" Which is not nice because I'm doing twice the same instruction or like : m = re.match(r'define\s+(\S+)\s*{$', line) if m: thing = m.group(1) else: m = re.match(r'include\s+(\S+)$', line) if m: thing = m.group(1) else thing = "" Which isn't nice neither because I'm going to have maybe 20 match tests and I wouldn't like to have 20 indentations. Anyone a recommendation? Thanks! From steven at REMOVE.THIS.cybersource.com.au Tue Mar 16 03:47:45 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 16 Mar 2010 07:47:45 GMT Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Mon, 15 Mar 2010 22:56:19 +0000, Grant Edwards wrote: > On 2010-03-15, Steven D'Aprano > wrote: >> On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote: >> >>>> Delete the character between "y_diff" and "H" and replace it with a >>>> plain ASCII subtraction sign. >>> >>> I think somebody needs to stop editing his code with MS Word and start >>> using a programming editor. ;) >> >> I've had this error myself, and I've never used Word to edit code. It >> can happen if you copy code from a website that "helpfully" converts >> hyphens to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z >> characters into strings, etc. They're a devil to debug. > > Though it may not be Microsoft Word, I think I'd still maintain that an > editor where you can't see a ctrl-Z or tell the difference between an > ASCII minus and a windows-codepage-whatever isn't a very good > programmer's editor. Regarding ctrl-Z (or for that matter other control characters), I agree it's a lack. As for not being able to see the difference between a hyphen and an EN- dash, or minus sign, or whatever it is, yes but they are very similar looking glyphs in virtually ever modern font. It would take a good eye to see the difference between (say) ? ? and -. -- Steven From stefan_ml at behnel.de Tue Mar 16 03:50:30 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 08:50:30 +0100 Subject: extract occurrence of regular expression from elements of XML documents In-Reply-To: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> References: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> Message-ID: Martin Schmidt, 15.03.2010 18:16: > I have just started to use Python a few weeks ago and until last week I had > no knowledge of XML. > Obviously my programming knowledge is pretty basic. > Now I would like to use Python in combination with ca. 2000 XML documents > (about 30 kb each) to search for certain regular expression within specific > elements of these documents. 2000 * 30K isn't a huge problem, that's just 60M in total. If you just have to do it once, drop your performance concerns and just get a solution going. If you have to do it once a day, take care to use a tool that is not too resource consuming. If you have strict requirements to do it once a minute, use a fast machine with a couple of cores and do it in parallel. If you have a huge request workload and want to reverse index the XML to do all sorts of sophisticated queries on it, use a database instead. > I would then like to record the number of occurrences of the regular > expression within these elements. > Moreover I would like to count the total number of words contained within > these, len(text.split()) will give you those. BTW, is it document-style XML (with mixed content as in HTML) or is the text always withing a leaf element? > and record the attribute of a higher level element that contains > them. An example would certainly help here. > I was trying to figure out the best way how to do this, but got overwhelmed > by the available information (e.g. posts using different approaches based on > dom, sax, xpath, elementtree, expat). > The outcome should be a file that lists the extracted attribute, the number > of occurrences of the regular expression, and the total number of words. > I did not find a post that addresses my problem. Funny that you say that after stating that you were overwhelmed by the available information. > If someone could help me with this I would really appreciate it. Most likely, the solution with the best simplicity/performance trade-off would be xml.etree.cElementTree's iterparse(), intercept on each interesting tag name, and search its text/tail using the regexp. That's doable in a couple of lines. But unless you provide more information, it's hard to give better advice. Stefan From stefan_ml at behnel.de Tue Mar 16 03:51:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 08:51:58 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: Lawrence D'Oliveiro, 16.03.2010 08:40: > Subtle... Absolutely. Python 2.4.6 (#2, Jan 21 2010, 23:45:25) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import antigravity Traceback (most recent call last): File "", line 1, in ? ImportError: No module named antigravity Stefan From clp2 at rebertia.com Tue Mar 16 03:52:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 00:52:07 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003160052m6358b020g6a65910c8d7af981@mail.gmail.com> On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro wrote: > Subtle... You're a bit behind the times. If my calculations are right, that comic is over 2 years old. Cheers, Chris From clp2 at rebertia.com Tue Mar 16 03:58:23 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 00:58:23 -0700 Subject: affectation in if statement In-Reply-To: References: Message-ID: <50697b2c1003160058t6ec2627ap42cfc7976f1bd2e4@mail.gmail.com> On Tue, Mar 16, 2010 at 12:45 AM, samb wrote: > Hi, > > I'm trying to do something like : > > if m = re.match(r'define\s+(\S+)\s*{$', line): > ? ?thing = m.group(1) > elif m = re.match(r'include\s+(\S+)$', line): > ? ?thing = m.group(1) > else > ? ?thing = "" > > But in fact I'm not allowed to affect a variable in "if" statement. > My code should then look like : > > if re.match(r'define\s+(\S+)\s*{$', line): > ? ?m = re.match(r'define\s+(\S+)\s*{$', line) > ? ?thing = m.group(1) > elif re.match(r'include\s+(\S+)$', line): > ? ?m = re.match(r'include\s+(\S+)$', line) > ? ?thing = m.group(1) > else > ? ?thing = "" > > Which is not nice because I'm doing twice the same instruction > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > ? ?thing = m.group(1) > else: > ? ?m = re.match(r'include\s+(\S+)$', line) > ? ?if m: > ? ? ? ?thing = m.group(1) > ? ?else > ? ? ? ?thing = "" > > Which isn't nice neither because I'm going to have maybe 20 match > tests and I wouldn't like to have 20 indentations. > > Anyone a recommendation? def extract_thing(line): for regex in (r'define\s+(\S+)\s*{$', r'include\s+(\S+)$'): m = re.match(regex, line) if m: return m.group(1) return "" Or if the real code is more complicated than your example: def extract_thing(line): m = re.match(r'define\s+(\S+)\s*{$', line) if m: return m.group(1) m = re.match(r'include\s+(\S+)$', line) if m: return m.group(1) #etc... return "" Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Tue Mar 16 04:10:39 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Mar 2010 01:10:39 -0700 Subject: affectation in if statement In-Reply-To: References: Message-ID: <4B9F3CFF.8040209@islandtraining.com> samb wrote: > Hi, > > I'm trying to do something like : > > if m = re.match(r'define\s+(\S+)\s*{$', line): > thing = m.group(1) > elif m = re.match(r'include\s+(\S+)$', line): > thing = m.group(1) > else > thing = "" > > But in fact I'm not allowed to affect a variable in "if" statement. > My code should then look like : > > if re.match(r'define\s+(\S+)\s*{$', line): > m = re.match(r'define\s+(\S+)\s*{$', line) > thing = m.group(1) > elif re.match(r'include\s+(\S+)$', line): > m = re.match(r'include\s+(\S+)$', line) > thing = m.group(1) > else > thing = "" > > Which is not nice because I'm doing twice the same instruction > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > else: > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > else > thing = "" > > Which isn't nice neither because I'm going to have maybe 20 match > tests and I wouldn't like to have 20 indentations. > > Anyone a recommendation? > Yes: Use an array of regular expressions and a loop (untested): exprs = ["...", "...", ] thing = "" for expr in exps: m = re.match(expr, line) if m: thing = m.group(1) break > Thanks! > Gary Herron From clp2 at rebertia.com Tue Mar 16 04:16:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 01:16:02 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003160116p20e2e59v42996dd60241b47f@mail.gmail.com> On Tue, Mar 16, 2010 at 12:51 AM, Stefan Behnel wrote: > Lawrence D'Oliveiro, 16.03.2010 08:40: >> >> Subtle... > > Absolutely. > > ?Python 2.4.6 (#2, Jan 21 2010, 23:45:25) > ?[GCC 4.4.1] on linux2 > ?Type "help", "copyright", "credits" or "license" for more information. > ?>>> import antigravity > ?Traceback (most recent call last): > ? ?File "", line 1, in ? > ?ImportError: No module named antigravity http://svn.python.org/view/python/trunk/Lib/antigravity.py?view=markup&pathrev=66902 Cheers, Chris -- http://blog.rebertia.com From sam.bancal at gmail.com Tue Mar 16 04:37:13 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 01:37:13 -0700 (PDT) Subject: affectation in if statement References: Message-ID: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Thanks for all those suggestions. They are good! 1) Let's suppose now that instead of just affecting "thing = m.group(1)", I need to do a piece of logic depending on which match I entered... 2) Concerning the suggestion : m = re.match(r'define\s+(\S+)\s*{$', line) if m: thing = m.group(1) m = re.match(r'include\s+(\S+)$', line) if m: thing = m.group(1) #etc... It means that I'll do all the checks, even if the first one did match and I know that the next will not... Thanks again. From rtw at rtw.me.uk Tue Mar 16 04:52:45 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 16 Mar 2010 03:52:45 -0500 Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Message-ID: samb wrote in news:5c361012-1f7b-487f-915b-0f564b238be3 @e1g2000yqh.googlegroups.com in comp.lang.python: > Thanks for all those suggestions. > They are good! > > 1) Let's suppose now that instead of just affecting "thing = > m.group(1)", I need to do a piece of logic depending on which match I > entered... > > 2) Concerning the suggestion : > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > > #etc... > > It means that I'll do all the checks, even if the first one did match > and I know that the next will not... > Ths is how I did it when I had the need: class ReMatch( object ): def __call__( self, pat, string ): import re self.match = re.match( pat, string ) return self.match is not None clip = ... re = ReMatch() if re( r'\s*TM(\d+)', clip ): ... elif re( r'\s*(https?://.*)', clip ): ... elif re( r'\d{12}$', clip ): ... Rob. -- From clp2 at rebertia.com Tue Mar 16 04:53:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 01:53:33 -0700 Subject: affectation in if statement In-Reply-To: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Message-ID: <50697b2c1003160153o5ca357eci986d40cadd05a06c@mail.gmail.com> On Tue, Mar 16, 2010 at 1:37 AM, samb wrote: > Thanks for all those suggestions. > They are good! > 2) Concerning the suggestion : > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > ? ?thing = m.group(1) > > m = re.match(r'include\s+(\S+)$', line) > if m: > ? ?thing = m.group(1) > > #etc... > > It means that I'll do all the checks, even if the first one did match > and I know that the next will not... Note how I split it out into a separate function and used `return m.group(1)` to avoid that exact situation. Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 16 05:04:10 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 16 Mar 2010 10:04:10 +0100 Subject: to pass self or not to pass self In-Reply-To: References: Message-ID: <4b9f4984$0$10229$426a74cc@news.free.fr> lallous a ?crit : > Hello, > > Learning Python from the help file and online resources can leave one > with many gaps. Can someone comment on the following: (snip code) > Why in test1() when it uses the class variable func_tbl we still need > to pass self, but in test2() we don't ? > > What is the difference between the reference in 'F' and 'func_tbl' ? Answer here: http://wiki.python.org/moin/FromFunctionToMethod From sam.bancal at gmail.com Tue Mar 16 05:53:51 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 02:53:51 -0700 (PDT) Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Message-ID: <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> On Mar 16, 9:53?am, Chris Rebert wrote: > On Tue, Mar 16, 2010 at 1:37 AM, samb wrote: > > Thanks for all those suggestions. > > They are good! > > > 2) Concerning the suggestion : > > m = re.match(r'define\s+(\S+)\s*{$', line) > > if m: > > ? ?thing = m.group(1) > > > m = re.match(r'include\s+(\S+)$', line) > > if m: > > ? ?thing = m.group(1) > > > #etc... > > Note how I split it out into a separate function and used `return > m.group(1)` to avoid that exact situation. Yes, you're right. It's an interresting approach. I'll give it a try. Cheers From sam.bancal at gmail.com Tue Mar 16 06:21:45 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 03:21:45 -0700 (PDT) Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: Hi, I've found a work around, inspired from Rob Williscroft : class ReMatch(object): """ Object to be called : 1st time : do a regexp.match and return the answer (args: regexp, line) 2nd time : return the previous result (args: prev) """ def __call__(self, regexp='', line='', prev=False): if prev: return self.prev_match self.prev_match = re.match(regexp, line) return self.prev_match re_match = ReMatch() if re_match(r'define\s+(\S+)\s*{$', line): m = re_match(prev=True) # do some logic with m elif re_match(r'include\s+(\S+)$', line): m = re_match(prev=True) # do some logic with m else # do some logic Hope this is efficient ... I guess yes. Cheers, Sam From __peter__ at web.de Tue Mar 16 06:45:40 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Mar 2010 11:45:40 +0100 Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: samb wrote: > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ > def __call__(self, regexp='', line='', prev=False): > if prev: > return self.prev_match > self.prev_match = re.match(regexp, line) > return self.prev_match > > re_match = ReMatch() > > if re_match(r'define\s+(\S+)\s*{$', line): > m = re_match(prev=True) > # do some logic with m > elif re_match(r'include\s+(\S+)$', line): > m = re_match(prev=True) > # do some logic with m > else > # do some logic > > Hope this is efficient ... I guess yes. No; just accessing the prev_match attribute instead of passing a flag to the __call__() method is more efficient and easier to read. I think the latter is the relevant point... Peter From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 16 06:53:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 16 Mar 2010 11:53:22 +0100 Subject: affectation in if statement In-Reply-To: References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: <4b9f631c$0$3618$426a74cc@news.free.fr> samb a ?crit : > Hi, > > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ > def __call__(self, regexp='', line='', prev=False): > if prev: > return self.prev_match > self.prev_match = re.match(regexp, line) > return self.prev_match > > re_match = ReMatch() > > if re_match(r'define\s+(\S+)\s*{$', line): > m = re_match(prev=True) > # do some logic with m > elif re_match(r'include\s+(\S+)$', line): > m = re_match(prev=True) > # do some logic with m > else > # do some logic > > Hope this is efficient ... I guess yes. A direct attribute access is cheaper than a method call, and makes for a simpler API too: class ReMatch(object): match = None def __call__(self, regexp, source): self.match = re.match(regexp, source) return self.match re_match = ReMatch() if re_match(r'define\s+(\S+)\s*{$', line): m = re_match.match # do some logic with m elif re_match(r'include\s+(\S+)$', line): m = re_match.match # do some logic with m My 2 cents... From mail at hellmutweber.de Tue Mar 16 06:54:49 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Tue, 16 Mar 2010 11:54:49 +0100 Subject: A tool for find dependencies relationships behind Python projects In-Reply-To: References: Message-ID: <4B9F6379.5040805@hellmutweber.de> Am 24.02.2010 18:49, schrieb Victor Lin: > On 2?23?, ??12?32?, Hellmut Weber wrote: >> Hi Victor, >> I would be intereseted to use your tool ;-) >> >> My system is Sabayon-5.1 on Lenovo T61. >> Trying for the first time easy_install I get the following error: >> >> ==================== >> >> root at sylvester ~ # easy_install gluttony >> Searching for gluttony >> Readinghttp://pypi.python.org/simple/gluttony/ >> Readinghttp://code.google.com/p/python-gluttony/ >> Best match: Gluttony 0.3 >> >> Downloadinghttp://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md... >> >> Processing Gluttony-0.3.zip >> Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir >> /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD >> Traceback (most recent call last): >> File "/usr/bin/easy_install", line 9, in >> load_entry_point('distribute==0.6.8', 'console_scripts', >> 'easy_install')() >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 1708, in main >> with_ei_usage(lambda: >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 1696, in with_ei_usage >> return f() >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 1712, in >> distclass=DistributionWithoutHelpCommands, **kw >> File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup >> dist.run_commands() >> File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands >> self.run_command(cmd) >> File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command >> cmd_obj.run() >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 236, in run >> self.easy_install(spec, not self.no_deps) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 471, in easy_install >> return self.install_item(spec, dist.location, tmpdir, deps) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 501, in install_item >> dists = self.install_eggs(spec, download, tmpdir) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 680, in install_eggs >> return self.build_and_install(setup_script, setup_base) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 957, in build_and_install >> self.run_setup(setup_script, setup_base, args) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 946, in run_setup >> run_setup(setup_script, args) >> File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line >> 29, in run_setup >> lambda: execfile( >> File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line >> 70, in run >> return func() >> File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line >> 31, in >> {'__file__':setup_script, '__name__':'__main__'} >> File "setup.py", line 9, in >> File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", >> line 1, in >> # >> File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", >> line 13, in >> ImportError: No module named pip.log >> root at sylvester ~ # >> >> ==================== >> >> I emerged app-misc/pip, but that didn't help, the error remains the same >> >> What is missing? >> >> Any help appreciated >> >> Best regards >> >> Hellmut >> >> Am 19.02.2010 17:16, schrieb Victor Lin: >> >> >> >> >> >>> Hi, >> >>> I just wrote a tool for drawing dependencies relationships diagram of >>> Python project on Pypi. Here is the home page of the tool: >> >>> http://code.google.com/p/python-gluttony/ >> >>> Some examples: >>> Sprox: >>> http://static.ez2learn.com/gluttony/sprox_dot.png >> >>> TurboGears2: >>> http://static.ez2learn.com/gluttony/tg2_dot.png >> >>> Hope this could be helpful :P >> >>> Regards. >>> Victor Lin. >> >> -- >> Dr. Hellmut Weber m... at hellmutweber.de >> Degenfeldstra?e 2 tel +49-89-3081172 >> D-80803 M?nchen-Schwabing mobil +49-172-8450321 >> please: No DOCs, no PPTs. why: tinyurl.com/cbgq > > Hi, > > That is a mistake I made in when I am making the distribute. Thanks > your reporting. I have already fixed the problem and released > Gluttony 0.4, and I tried to install that, it works fine. > > Victor Lin. Hi Victor, thanks for your message. Sorry I'm so late to answer, I've been offline for a while and didn't remember not to have answered. ,-( I downloaded Gluttony-0.4 and the installation was done in a few seconds. It works just fine ;-) Thanks for providing this tool Cheers Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From jeanmichel at sequans.com Tue Mar 16 06:56:11 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 16 Mar 2010 11:56:11 +0100 Subject: affectation in if statement In-Reply-To: References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: <4B9F63CB.1040708@sequans.com> samb wrote: > Hi, > > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ > def __call__(self, regexp='', line='', prev=False): > if prev: > return self.prev_match > self.prev_match = re.match(regexp, line) > return self.prev_match > > re_match = ReMatch() > > if re_match(r'define\s+(\S+)\s*{$', line): > m = re_match(prev=True) > # do some logic with m > elif re_match(r'include\s+(\S+)$', line): > m = re_match(prev=True) > # do some logic with m > else > # do some logic > > Hope this is efficient ... I guess yes. > > Cheers, > Sam What do you mean by efficient ? If you're talking about speed, make sure you care about it before doing some optimization. If you talk about readability then it is absolutely *not* efficient (to my humble opinion). define, include = re.match(r'define\s+(\S+)\s*{$', line), re.match(r'include\s+(\S+)$', line) if define: # do some stuff elif include: # do some other stuff else: # hello world If you then have some speed problem with that script, you'll start caring about how to execute if faster by making sure that only necessary calls to re.match are done. match = re.match(r'(define)\s+(\S+)\s*{$', line) or re.match(r'(include)\s+(\S+)$', line) # note that the second operand is executed only if the first is None if match.group(1) == 'define': # do some stuff with match.group(2) elif match.group(1) == 'include': # do some other stuff with match.group(2) else: # hello world JM From hackingkk at gmail.com Tue Mar 16 07:02:09 2010 From: hackingkk at gmail.com (hackingKK) Date: Tue, 16 Mar 2010 16:32:09 +0530 Subject: any python libraries for rendering open office spreadsheet to html Message-ID: <4B9F6531.5010604@gmail.com> Hello, Is there a python library which can render ods to html. (I would even prefer javascript library to do this). The reason I am more interested in a python library is because, I am developing a web application in pylons. It is a financial software and initially on the desktop based client, I used odfpy to create spreadsheets. But now I would want to render those sheets to the web front end. Happy hacking. Krishnakant. From steve at REMOVE-THIS-cybersource.com.au Tue Mar 16 07:46:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Mar 2010 11:46:51 GMT Subject: Understanding the CPython dict implementation References: Message-ID: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: > I found this PyCon2010 presentation to be excellent: The Mighty > Dictionary, Branden Craig Rhodes, 30 min. > http://pycon.blip.tv/file/3264041/ Unfortunately, that clip seems to be unwatchable, at least for me. It crashed the Netscape plugin in Konqueror, and crashed Firefox. When I downloaded the ogv file, it crashed MPlayer and Kaffeine. Before crashing, in all four players, it displayed random blocks of colours and lines while the sound played. Not a good advertisement for either BlipTV or Ogg :( -- Steven From googler.1.webmaster at spamgourmet.com Tue Mar 16 07:52:37 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 04:52:37 -0700 (PDT) Subject: C-API PyObject_Call Message-ID: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Hi, i have a serious problem and I am looking for a solution. I pass an instance of a class from a file to PyObject_Call. When something fails, I get a full traceback. If it succeeds, I get the return value. Is it possible to get information from which line/file the return value of PyObject_Call is? Thanks!! moerchendiser2k3 From Ron.Barak at lsi.com Tue Mar 16 07:54:01 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 11:54:01 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Hi, I'm trying to add a library path to my pythonpath, but seems it is not accepted - On Windows DOS window: C:\>echo %PYTHONPATH% c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ C:\>python -c "import sys ; print sys.path" ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] C:\> On Windows cygwin: $ echo $PYTHONPATH .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ $ python -c "import sys ; print sys.path" ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] $ What am I doing wrong ? Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eckhardt at satorlaser.com Tue Mar 16 07:56:36 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 16 Mar 2010 12:56:36 +0100 Subject: import antigravity References: Message-ID: Chris Rebert wrote: > You're a bit behind the times. > If my calculations are right, that comic is over 2 years old. import timetravel Uli From Ron.Barak at lsi.com Tue Mar 16 07:56:47 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 11:56:47 +0000 Subject: Recall: How to add a library path to pythonpath ? Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C839@enbmail01.lsi.com> Barak, Ron would like to recall the message, "How to add a library path to pythonpath ?". From jan at jandecaluwe.com Tue Mar 16 08:10:09 2010 From: jan at jandecaluwe.com (Jan Decaluwe) Date: Tue, 16 Mar 2010 13:10:09 +0100 Subject: The first ASIC designed with MyHDL Message-ID: <4b9f7414$0$2887$ba620e4c@news.skynet.be> I am proud to report on the first ASIC product designed with MyHDL (afaik). http://www.jandecaluwe.com/hdldesign/digmac.html -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a HDL: http://www.myhdl.org VHDL development, the modern way: http://www.sigasi.com Analog design automation: http://www.mephisto-da.com World-class digital design: http://www.easics.com From clp2 at rebertia.com Tue Mar 16 08:13:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 05:13:20 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003160513y7bf2dd8ew9020ddf76f048121@mail.gmail.com> On Tue, Mar 16, 2010 at 4:56 AM, Ulrich Eckhardt wrote: > Chris Rebert wrote: >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. > > import timetravel > > Uli So that's where Guido's been hiding his infamous time machine! Right in plain sight! It's so obvious in retrospect. Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Tue Mar 16 08:13:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Mar 2010 13:13:26 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Ulrich Eckhardt: > Chris Rebert wrote: >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. > > import timetravel C:\test> python Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.altzone -7200 >>> # hm. ... >>> _ Cheers, - Alf From rikutheronin at gmail.com Tue Mar 16 08:27:22 2010 From: rikutheronin at gmail.com (Pablo Recio Quijano) Date: Tue, 16 Mar 2010 13:27:22 +0100 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Message-ID: <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> You have to add yout path to the list: import sys sys.path.append(your_path) Jus simple to add the element on the list :) 2010/3/16 Barak, Ron > Hi, > > I'm trying to add a library path to my pythonpath, but seems it is not > accepted - > > On Windows DOS window: > > C:\>echo %PYTHONPATH% > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > > C:\>python -c "import sys ; print sys.path" > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\syst > em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', > 'C:\\Python26\\l > ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', > 'C:\\Python26\\lib\\ > site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > C:\> > > On Windows cygwin: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > $ python -c "import sys ; print sys.path" > ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > 'c:\\Python26\\lib\\site-packages', > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > $ > > What am I doing wrong ? > > Thanks, > Ron. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Tue Mar 16 08:35:54 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Mar 2010 07:35:54 -0500 Subject: class inheritance In-Reply-To: <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> Message-ID: <4B9F7B2A.1080906@ieee.org> Carl Banks wrote: > On Mar 15, 4:34 pm, JLundell wrote: > >> It's also unfortunate that Python doesn't have an approximately-equal >> operator; it'd come in handy for floating-point applications while >> preserving hash. If only there were a ~=r ? operator I could >> overload. And ~ is unary, so no joy. >> > > One problem with it is that there's no way to make it universal; > different appiplications have different ideas of close. Conceivably > it could be usefully defined for a user type though.. > > Bacause of this problem almost no languages have an almost equal > operator. I'm curious what languages do, of if there are any with a > trinary operator that also takes a threshold. > > Carl Banks > > If I recall correctly, APL has a *fuzz* value, which is used in all(?) comparisons. But I do not recall anything about how it was defined. I do recall that you could change the threshold, and suspect it was relative to the operands. For symmetry, it would probably have to be relative to the average of the two values, or some such. From basaka.chen at gmail.com Tue Mar 16 08:53:35 2010 From: basaka.chen at gmail.com (freakrobot) Date: Tue, 16 Mar 2010 05:53:35 -0700 (PDT) Subject: what's the diffence between "RECENT" and "UNSEEN" in imaplib? Message-ID: <2583d700-db3c-4291-ae18-46f96b02a92d@s25g2000prd.googlegroups.com> When I work with the imaplib, there is a imap4.status(mailboxname, '(MESSAGES RECENT UNSEEN)') function. So I really wonder what's the difference between RECENT and UNSEEN conditions. And what kind of messages belong to RECENT condition? Thank you~ From dmj.ccc at gmail.com Tue Mar 16 08:57:05 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 05:57:05 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple Message-ID: Hi all, This may be a complete brainfart, but it's been puzzling me for a day or two (!). Sorry for not describing "something" in the subject, but it's hard to describe succinctly: I have a short list of non-zero positive integers (say myList=[2,5,8,3,5]). I need to return five lists of non-negative numbers, such that for five different "share sizes", myList[0] and myList[1] will share twice the smaller amount... def getOutcomes(): outcomes=[] if myList[0]<=myList[1]: amountToShare=2*myList[0] remainder=myList[1]-myList[0] outcome.append((amountToShare, remainder)+myList[2:]) # shares are (100%, 0) outcome.append((amountToShare*0.75, remainder +amountToShare*0.25)+myList[2:]) #shares are (75%, 25%), and exactly the same for (50%,50%), (25%, 75%), and (0,100%) ... ... return outcomes i.e. for the above myList, outcomes=[[4,1,8,3,5], [3,2,8,3,5], [2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] if myList[0]>myList[1], i want exactly the opposite to happen (i.e., just switching what happens to positions 0 and 1) Obviously, i can just write the code again, in an else, switching indices 0 and 1. Or, I could just have a test at the beginning, switch them if they are in the order "big, small", and then switch them again at the end in a list comprehension. Both ideas seem terribly silly, and there must be an obvious way to do it that I'm not seeing. any help? many thanks dmj From motoom at xs4all.nl Tue Mar 16 09:00:41 2010 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 16 Mar 2010 14:00:41 +0100 Subject: Understanding the CPython dict implementation In-Reply-To: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> References: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 16 Mar 2010, at 12:46 , Steven D'Aprano wrote: > On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: > >> I found this PyCon2010 presentation to be excellent: The Mighty >> Dictionary, Branden Craig Rhodes, 30 min. >> http://pycon.blip.tv/file/3264041/ > > > Unfortunately, that clip seems to be unwatchable, at least for me. It > crashed the Netscape plugin in Konqueror, and crashed Firefox. When I > downloaded the ogv file, it crashed MPlayer and Kaffeine. It played in VLC without problems. Greetings, From dmj.ccc at gmail.com Tue Mar 16 09:05:30 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 06:05:30 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: ... and of course i screwed up my outcomes... that should read outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] From kw at codebykevin.com Tue Mar 16 09:22:29 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 16 Mar 2010 09:22:29 -0400 Subject: Build Python with XCode In-Reply-To: References: Message-ID: <2c74f$4b9f8616$4275d90a$4845@FUSE.NET> On 3/15/10 11:15 PM, moerchendiser2k3 wrote: > Hi, > > I would like to build Python with Xcode (but without the makefile). > Does anyone know a link where I can get a real xcodeproj with the > current Py2.x sources? > > > Thanks in advance!! Bye, donnerCobra I don't think one exists--I build my Python on OS Xwith configure, make etc.-- but you could try asking on the MacPython list. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From chris at simplistix.co.uk Tue Mar 16 09:47:12 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 16 Mar 2010 13:47:12 +0000 Subject: converting a timezone-less datetime to seconds since the epoch Message-ID: <4B9F8BE0.2050808@simplistix.co.uk> Hi All, We have a bunch of datetime objects that have tzinfo=None. We want to turn them into float timestamps in seconds since the epoch. Here's the first attempt: import time from datetime import datetime from unittest import TestCase def timestamp(dttm): return time.mktime(dttm.timetuple()) class Test(TestCase): def check(self,*args): epoch = datetime.utcfromtimestamp(0) dt = datetime(*args) actual = timestamp(dt) d = dt - epoch expected = d.seconds + 60*60*24*d.days self.assertEquals(expected,actual, '%s != %s (diff %s)'%(expected,actual,expected-actual)) def test_xmas(self): self.check(2009, 12, 25, 1, 2, 3, 456789) def test_midsummer(self): self.check(2009, 6, 21, 2, 3, 4, 5678) For me, test_midsummer fails. I'd be interested in knowing wheher both tests pass for other people. I'd be *more* interested in knowing either why the timestamp function or the tests are wrong and how to correct them... cheers, Chris From pruebauno at latinmail.com Tue Mar 16 09:48:11 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 16 Mar 2010 06:48:11 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: <53f1fd53-7f83-418d-b3f8-ced6f2e929af@g10g2000yqh.googlegroups.com> david jensen wrote: > ... and of course i screwed up my outcomes... that should read > outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] For starters: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder = myList[not low_id]-myList[low_id] tail=myList[2:] outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)] + tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] return outcomes From clp2 at rebertia.com Tue Mar 16 09:57:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 06:57:14 -0700 Subject: what's the diffence between "RECENT" and "UNSEEN" in imaplib? In-Reply-To: <2583d700-db3c-4291-ae18-46f96b02a92d@s25g2000prd.googlegroups.com> References: <2583d700-db3c-4291-ae18-46f96b02a92d@s25g2000prd.googlegroups.com> Message-ID: <50697b2c1003160657g22596349j5f4fb83382e90266@mail.gmail.com> On Tue, Mar 16, 2010 at 5:53 AM, freakrobot wrote: > When I work with the imaplib, > there is a imap4.status(mailboxname, '(MESSAGES RECENT UNSEEN)') > function. > > So I really wonder what's the difference between RECENT and UNSEEN > conditions. > And what kind of messages belong to RECENT condition? A. Your question is not Python-specific and would better have been asked somewhere more relevant. B. RTFRFC: http://www.faqs.org/rfcs/rfc3501.html """ UNSEEN The number of messages which do not have the \Seen flag set. [...] \Seen Message has been read \Recent Message is "recently" arrived in this mailbox. This session is the first session to have been notified about this message; if the session is read-write, subsequent sessions will not see \Recent set for this message. This flag can not be altered by the client. If it is not possible to determine whether or not this session is the first session to be notified about a message, then that message SHOULD be considered recent. If multiple connections have the same mailbox selected simultaneously, it is undefined which of these connections will see newly-arrived messages with \Recent set and which will see it without \Recent set. """ Regards, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Tue Mar 16 10:13:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 07:13:04 -0700 Subject: converting a timezone-less datetime to seconds since the epoch In-Reply-To: <4B9F8BE0.2050808@simplistix.co.uk> References: <4B9F8BE0.2050808@simplistix.co.uk> Message-ID: <50697b2c1003160713x7641d2cfn52a5e5ca199e26de@mail.gmail.com> On Tue, Mar 16, 2010 at 6:47 AM, Chris Withers wrote: > Hi All, > > We have a bunch of datetime objects that have tzinfo=None. > We want to turn them into float timestamps in seconds since the epoch. > > Here's the first attempt: > > import time > from datetime import datetime > from unittest import TestCase > > def timestamp(dttm): > ? ?return time.mktime(dttm.timetuple()) from calendar import timegm def timestamp(dttm): return timegm(dttm.utctimetuple()) #the *utc*timetuple change is just for extra consistency #it shouldn't actually make a difference here And problem solved. As for what the problem was: Paraphrasing the table I got added to the time module docs: (http://docs.python.org/library/time.html) To convert from struct_time in ***UTC*** to seconds since the epoch use calendar.timegm() To convert struct_time in ***local*** time to seconds since the epoch use time.mktime() > I'd be *more* interested in knowing either why the timestamp function or the > tests are wrong and how to correct them... You used a function intended for local times on UTC time data, and therefore got incorrect results. Cheers, Chris -- Entering the workforce in 2012 http://blog.rebertia.com From invalid at invalid.invalid Tue Mar 16 10:20:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 16 Mar 2010 14:20:26 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-16, Steven D'Aprano wrote: >> Though it may not be Microsoft Word, I think I'd still maintain that >> an editor where you can't see a ctrl-Z or tell the difference between >> an ASCII minus and a windows-codepage-whatever isn't a very good >> programmer's editor. > > Regarding ctrl-Z (or for that matter other control characters), I > agree it's a lack. > > As for not being able to see the difference between a hyphen and an > EN- dash, or minus sign, or whatever it is, yes but they are very > similar looking glyphs in virtually ever modern font. It would take a > good eye to see the difference between (say) ??? ??? and -. My point is that if it's an ASCII file, then rendering \x96 as an em-dash isn't correct. I'd expect it to show up highlighted somehow in hex or octal so that I know it's a non-ASCII character. -- Grant Edwards grant.b.edwards Yow! We are now enjoying at total mutual interaction in gmail.com an imaginary hot tub ... From steve at holdenweb.com Tue Mar 16 10:24:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 10:24:36 -0400 Subject: C-API PyObject_Call In-Reply-To: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: moerchendiser2k3 wrote: > Hi, > > i have a serious problem and I am looking for a solution. I pass an > instance of a class from a file to PyObject_Call. When something > fails, I get a full traceback. If it succeeds, I get the return value. > > Is it possible to get information from which line/file the return > value of PyObject_Call is? > > Thanks!! > > moerchendiser2k3 You'll need to use a debugger like gdb that gives you access to the C stack, I believe. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From Ron.Barak at lsi.com Tue Mar 16 10:26:50 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 14:26:50 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> Thanks for the suggestion Pable. However, I really need the $PYTHONPATH to include this additional library, so all Python scripts could use it. In Windows I have defined PYTHONPATH as c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the Windows registry I have HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk; However, even with all the above, the SVMInspecor modules are not found. Bye, Ron. ________________________________ From: Pablo Recio Quijano [mailto:rikutheronin at gmail.com] Sent: Tuesday, March 16, 2010 2:27 PM To: python-list at python.org Subject: Re: How to add a library path to pythonpath ? You have to add yout path to the list: import sys sys.path.append(your_path) Jus simple to add the element on the list :) 2010/3/16 Barak, Ron > Hi, I'm trying to add a library path to my pythonpath, but seems it is not accepted - On Windows DOS window: C:\>echo %PYTHONPATH% c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ C:\>python -c "import sys ; print sys.path" ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] C:\> On Windows cygwin: $ echo $PYTHONPATH .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ $ python -c "import sys ; print sys.path" ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] $ What am I doing wrong ? Thanks, Ron. -- http://mail.python.org/mailman/listinfo/python-list -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From grflanagan at gmail.com Tue Mar 16 10:28:17 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Tue, 16 Mar 2010 14:28:17 +0000 Subject: Searching for most pythonic/least stupid way to do something simple In-Reply-To: References: Message-ID: david jensen wrote: > ... and of course i screwed up my outcomes... that should read > outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] > > > abstracting the given algorithm: def iterweights(N): d = 1.0/(N-1) for i in xrange(N): yield i*d, (N-1-i)*d def iterparts(x0, x1, N): a = min(x0, x1) b = max(x0, x1) s = 2 * a t = b - a for m, n in iterweights(N): if a == x0: yield s*m, s*n+t else: yield s*n+t, s*m for p in iterparts(2, 5, 5): print p print for p in iterparts(5, 2, 5): print p (0.0, 7.0) (1.0, 6.0) (2.0, 5.0) (3.0, 4.0) (4.0, 3.0) (7.0, 0.0) (6.0, 1.0) (5.0, 2.0) (4.0, 3.0) (3.0, 4.0) From Dieter.Faulbaum at bessy.de Tue Mar 16 10:30:51 2010 From: Dieter.Faulbaum at bessy.de (Dieter Faulbaum) Date: Tue, 16 Mar 2010 15:30:51 +0100 Subject: cycling through options Message-ID: Hello, is there a better way for cycling through all options than this: (options, args) = parser.parse_args() for opt in options.__dict__.keys(): print opt, ":", options.__dict__[opt] Thanks for any nicer solution -- Dieter Faulbaum From steve at holdenweb.com Tue Mar 16 10:31:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 10:31:02 -0400 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Hi, > > I'm trying to add a library path to my pythonpath, but seems it is not > accepted - > > On Windows DOS window: > > C:\>echo %PYTHONPATH% > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > That looks like it should work. The only thing I notice is that I don't have a trailing backslash on my Windows PYTHONPATH. Could that be the problem? regards Steve > C:\>python -c "import sys ; print sys.path" > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\syst > em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', > 'C:\\Python26\\l > ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', > 'C:\\Python26\\lib\\ > site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > C:\> > > On Windows cygwin: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > $ python -c "import sys ; print sys.path" > ['', > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > 'c:\\Python26\\lib\\site-packages', > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > $ > > What am I doing wrong ? > > Thanks, > Ron. > > > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From davea at ieee.org Tue Mar 16 11:03:44 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Mar 2010 10:03:44 -0500 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> Message-ID: <4B9F9DD0.2080306@ieee.org> Barak, Ron wrote: > Thanks for the suggestion Pable. > > However, I really need the $PYTHONPATH to include this additional library, so all Python scripts could use it. > > In Windows I have defined PYTHONPATH as c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the Windows registry I have > > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk; > > However, even with all the above, the SVMInspecor modules are not found. > > See my response at the end. Top-posting makes for a very confusing thread. > > > 2010/3/16 Barak, Ron > > > Hi, > > I'm trying to add a library path to my pythonpath, but seems it is not accepted - > > On Windows DOS window: > > C:\>echo %PYTHONPATH% > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > > C:\>python -c "import sys ; print sys.path" > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst > em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l > ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ > site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > C:\> > > On Windows cygwin: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > $ python -c "import sys ; print sys.path" > ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > $ > > What am I doing wrong ? > > Thanks, > Ron. > > > In your original message, what you displayed worked exactly as expected. As you didn't say what made you think something was wrong, I ignored the message. Now, you say that some modules are not found. So how about giving some more specifics so someone can actually debug the problem. Pick a particular module, tell us the complete path to that module, and show us both the sys.path strings (which look correct for the Windows case, and of course bogus for the cygwin case), as well as the offending import statement and its traceback. DaveA From robert.kern at gmail.com Tue Mar 16 11:06:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Mar 2010 10:06:10 -0500 Subject: class inheritance In-Reply-To: <4B9F7B2A.1080906@ieee.org> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> <4B9F7B2A.1080906@ieee.org> Message-ID: On 2010-03-16 07:35 AM, Dave Angel wrote: > > > Carl Banks wrote: >> On Mar 15, 4:34 pm, JLundell wrote: >>> It's also unfortunate that Python doesn't have an approximately-equal >>> operator; it'd come in handy for floating-point applications while >>> preserving hash. If only there were a ~=r ? operator I could >>> overload. And ~ is unary, so no joy. >> >> One problem with it is that there's no way to make it universal; >> different appiplications have different ideas of close. Conceivably >> it could be usefully defined for a user type though.. >> >> Bacause of this problem almost no languages have an almost equal >> operator. I'm curious what languages do, of if there are any with a >> trinary operator that also takes a threshold. >> >> Carl Banks >> > If I recall correctly, APL has a *fuzz* value, which is used in all(?) > comparisons. But I do not recall anything about how it was defined. I do > recall that you could change the threshold, and suspect it was relative > to the operands. For symmetry, it would probably have to be relative to > the average of the two values, or some such. The problem is that frequently there is no system-wide fuzz value which is appropriate for all comparisons in a given program. You need to choose the right value for each comparison. Consequently, you might as well use a function instead of an operator and a global variable. -- 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 From no.email at nospam.invalid Tue Mar 16 11:09:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 16 Mar 2010 08:09:37 -0700 Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: <7xmxy87172.fsf@ruckus.brouhaha.com> david jensen writes: > Obviously, i can just write the code again, in an else, switching > indices 0 and 1. Or, I could just have a test at the beginning, switch > them if they are in the order "big, small", and then switch them again > at the end in a list comprehension. Both ideas seem terribly silly, > and there must be an obvious way to do it that I'm not seeing. Generally when faced with this kind of question, see if you can use the built-in min and max functions: def getOutcomes(): outcomes=[] smaller = min(myList[0], myList[1]) bigger = max(myList[0], myList[1]) amountToShare=2*smaller remainder = bigger - smaller ... From dmj.ccc at gmail.com Tue Mar 16 11:21:41 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 08:21:41 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: <05fe1942-231f-4674-a55a-77ebca451da6@g4g2000yqa.googlegroups.com> Thank you both very much! Yeah: it was a total brainfart on my part: nn's solution should have been obvious. As the general solution, i like your approach, Gerard, but I think I'll stick to nn's, the one i should have written. Again, thank you both! dmj From Ron.Barak at lsi.com Tue Mar 16 11:25:16 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 15:25:16 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <4B9F9DD0.2080306@ieee.org> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> > -----Original Message----- > From: Dave Angel [mailto:davea at ieee.org] > Sent: Tuesday, March 16, 2010 5:04 PM > To: Barak, Ron > Cc: Pablo Recio Quijano; python-list at python.org > Subject: RE: How to add a library path to pythonpath ? > > > > Barak, Ron wrote: > > Thanks for the suggestion Pable. > > > > However, I really need the $PYTHONPATH to include this > additional library, so all Python scripts could use it. > > > > In Windows I have defined PYTHONPATH as > > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the > > Windows registry I have > > > > > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as > > > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn > > spector\lib\;C:\Python26\Lib\lib-tk; > > > > However, even with all the above, the SVMInspecor modules > are not found. > > > > > See my response at the end. Top-posting makes for a very > confusing thread. > > > > > > 2010/3/16 Barak, Ron > > > > > Hi, > > > > I'm trying to add a library path to my pythonpath, but > seems it is not > > accepted - > > > > On Windows DOS window: > > > > C:\>echo %PYTHONPATH% > > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > > > > C:\>python -c "import sys ; print sys.path" > > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > > 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', > > 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', > > 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ > > site-packages', > > 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > > > C:\> > > > > On Windows cygwin: > > > > $ echo $PYTHONPATH > > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > > > $ python -c "import sys ; print sys.path" > > ['', > > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > > 'c:\\Python26\\lib\\site-packages', > > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > > > $ > > > > What am I doing wrong ? > > > > Thanks, > > Ron. > > > > > > > In your original message, what you displayed worked exactly > as expected. As you didn't say what made you think something > was wrong, I ignored the message. > > Now, you say that some modules are not found. So how about > giving some more specifics so someone can actually debug the > problem. Pick a particular module, tell us the complete path > to that module, and show us both the sys.path strings (which > look correct for the Windows case, and of course bogus for > the cygwin case), as well as the offending import statement > and its traceback. > > DaveA Hi Dave, My Python is the Windows Python (I need this for wxPython): $ ls -ls `which python` 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 /usr/bin/python -> /cygdrive/c/Python26/python.exe Here's a demo script: #!/usr/bin/env python import sys print "\n",sys.path,"\n" from ErrorManager.ErrorManager import ErrorManager And it's run produces: $ python -u tmp.py ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] Traceback (most recent call last): File "tmp.py", line 6, in from ErrorManager.ErrorManager import ErrorManager ImportError: No module named ErrorManager.ErrorManager $ ls -ls /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py $ grep ErrorManager /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ ErrorManager/ErrorManager.py class ErrorManager: $ echo $PYTHONPATH .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ Please let me know if the above is enough, or you'd like to see the results from a Windows' DOS window. Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sam.bancal at gmail.com Tue Mar 16 11:40:29 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 08:40:29 -0700 (PDT) Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: <0e235861-54bc-4e0f-bfa1-7472dae8cbc4@30g2000yqi.googlegroups.com> On Mar 16, 11:56?am, Jean-Michel Pichavant wrote: > samb wrote: > > Hi, > > > I've found a work around, inspired from Rob Williscroft : > > > class ReMatch(object): > > ? ? """ > > ? ? ? ? Object to be called : > > ? ? ? ? 1st time : do a regexp.match and return the answer (args: > > regexp, line) > > ? ? ? ? 2nd time : return the previous result (args: prev) > > ? ? """ > > ? ? def __call__(self, regexp='', line='', prev=False): > > ? ? ? ? if prev: > > ? ? ? ? ? ? return self.prev_match > > ? ? ? ? self.prev_match = re.match(regexp, line) > > ? ? ? ? return self.prev_match > > > re_match = ReMatch() > > > if re_match(r'define\s+(\S+)\s*{$', line): > > ? ? m = re_match(prev=True) > > ? ? # do some logic with m > > elif re_match(r'include\s+(\S+)$', line): > > ? ? m = re_match(prev=True) > > ? ? # do some logic with m > > else > > ? ? # do some logic > > > Hope this is efficient ... I guess yes. > > > Cheers, > > Sam > > What do you mean by efficient ? If you're talking about speed, make sure > you care about it before doing some optimization. > If you talk about readability then it is absolutely *not* efficient (to > my humble opinion). > > define, include = re.match(r'define\s+(\S+)\s*{$', line), > re.match(r'include\s+(\S+)$', line) > if define: > ? ? # do some stuff > elif include: > ? ? # do some other stuff > else: > ? ? # hello world > > If you then have some speed problem with that script, you'll start > caring about how to execute if faster by making sure that only necessary > calls to re.match are done. > > match = re.match(r'(define)\s+(\S+)\s*{$', line) or > re.match(r'(include)\s+(\S+)$', line) # note that the second operand is > executed only if the first is None > > if match.group(1) == 'define': > ? ? # do some stuff with match.group(2) > > elif match.group(1) == 'include': > ? ? # do some other stuff with match.group(2) > > else: > ? ? # hello world > > JM Hi, Thanks Bruno for the simpler API! And thanks Jean-Michel, your second suggestion is clearly the best I see. I meant efficient mainly in the readable aspect (important for future maintenance) and secondary for speed of execution. For sure I didn't want to run a regexp twice. Regards, Sam From lists at cheimes.de Tue Mar 16 11:56:28 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Mar 2010 16:56:28 +0100 Subject: How to add a library path to pythonpath ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Message-ID: <4B9FAA2C.3060806@cheimes.de> Steve Holden schrieb: > Barak, Ron wrote: >> Hi, >> >> I'm trying to add a library path to my pythonpath, but seems it is not >> accepted - >> >> On Windows DOS window: >> >> C:\>echo %PYTHONPATH% >> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ >> > That looks like it should work. The only thing I notice is that I don't > have a trailing backslash on my Windows PYTHONPATH. Could that be the > problem? Yes, that's definitely a major issue on Windows. Windows' stat() method returns an error for paths with a trailing (back)slash. For example _stat("C:\\Windows") works but _stat("C:\\Windows\\") sets errno to ENOENT or ENOTDIR. I got bitten by the issue a couple of years ago as I worked on pars of Python's import system. Quoting Tim Peters: [1] The Microsoft stat() function is extremely picky about trailing (back)slashes. For example, if you have a directory c:/python, and pass "c:/python/" to the MS stat (), it claims no such thing exists. This isn't documented by MS, but that's how it works: a trailing (back)slash is required if and only if the path passed in "is a root". So MS stat() doesn't understand "/python/", and doesn't understand "d:" either. The former doesn't tolerate a (back)slash, while the latter requires one. Christian [1] http://mail.python.org/pipermail/python-bugs-list/2002-April/011099.html From googler.1.webmaster at spamgourmet.com Tue Mar 16 12:08:22 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 09:08:22 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: <92d7720e-b8cc-4f41-8191-17c078911909@m37g2000yqf.googlegroups.com> But the stack is empty after PyObject_Call, isnt it? From phlip2005 at gmail.com Tue Mar 16 12:12:08 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Mar 2010 09:12:08 -0700 (PDT) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <7284f1df-100e-4fed-aed2-20b114040d64@v34g2000prm.googlegroups.com> Chris Rebert wrote: > The next closest thing would probably be the Python Cookbook:http://code.activestate.com/recipes/langs/python/ One thing I really like about ... my hacked version of path.py ... is path.cd( lambda: ... ). It works great inside fabfile.py to temporarily switch to a different folder: sample_project = path('sample_project').abspath() def run(): sample_project.cd( lambda: _sh('python manage.py runserver 0.0.0.0:8000 -- settings=test_settings') ) After the lambda runs, we exception-safely return to the home folder. (BTW I'm aware that a fabfile.py command with only one statement will return to its shell and remain in the correct folder. It's just ... the thought!) This be .cd(): class path: def cd(self, block=None): previous = path(os.path.curdir).abspath() self.chdir() if block: try: block() finally: previous.chdir() That's based on Jason Orendoff's work at http://www.jorendorff.com/articles/python/path -- Phlip http://c2.com/cgi/wiki?ZeekLand From stefan_ml at behnel.de Tue Mar 16 12:17:02 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 17:17:02 +0100 Subject: C-API PyObject_Call In-Reply-To: <92d7720e-b8cc-4f41-8191-17c078911909@m37g2000yqf.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <92d7720e-b8cc-4f41-8191-17c078911909@m37g2000yqf.googlegroups.com> Message-ID: moerchendiser2k3, 16.03.2010 17:08: > But the stack is empty after PyObject_Call, isnt it? I think Steve was expecting that you wanted to debug into your program, step into the call, and find the line yourself. Stefan From stefan_ml at behnel.de Tue Mar 16 12:18:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 17:18:01 +0100 Subject: C-API PyObject_Call In-Reply-To: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: moerchendiser2k3, 16.03.2010 12:52: > i have a serious problem and I am looking for a solution. I pass an > instance of a class from a file to PyObject_Call. When something > fails, I get a full traceback. If it succeeds, I get the return value. > > Is it possible to get information from which line/file the return > value of PyObject_Call is? Could you explain what you want to do with this information and in what cases you need it? Do you want to extract the information programmatically at runtime? Stefan From python at hope.cz Tue Mar 16 12:20:40 2010 From: python at hope.cz (Johny) Date: Tue, 16 Mar 2010 09:20:40 -0700 (PDT) Subject: Python bindings tutorial Message-ID: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Is there any tutorial how to write a bindings for a exe ( dos) program? I would like to run it from a Python directly ( using import command and a particular function from the binding) not using os.system command. Thanks L. From davea at ieee.org Tue Mar 16 12:23:54 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Mar 2010 11:23:54 -0500 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> Message-ID: <4B9FB09A.7030609@ieee.org> Barak, Ron wrote: > >> -----Original Message----- >> From: Dave Angel [mailto:davea at ieee.org] >> Sent: Tuesday, March 16, 2010 5:04 PM >> To: Barak, Ron >> Cc: Pablo Recio Quijano; python-list at python.org >> Subject: RE: How to add a library path to pythonpath ? >> >> >> >> Barak, Ron wrote: >> >>> Thanks for the suggestion Pable. >>> >>> However, I really need the $PYTHONPATH to include this >>> >> additional library, so all Python scripts could use it. >> >>> In Windows I have defined PYTHONPATH as >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the >>> Windows registry I have >>> >>> >>> >> HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as >> >> C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn >> >>> spector\lib\;C:\Python26\Lib\lib-tk; >>> >>> However, even with all the above, the SVMInspecor modules >>> >> are not found. >> >>> >> See my response at the end. Top-posting makes for a very >> confusing thread. >> >>> >>> >>> 2010/3/16 Barak, Ron > >>> >>> Hi, >>> >>> I'm trying to add a library path to my pythonpath, but >>> >> seems it is not >> >>> accepted - >>> >>> On Windows DOS window: >>> >>> C:\>echo %PYTHONPATH% >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ >>> >>> C:\>python -c "import sys ; print sys.path" >>> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >>> 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', >>> 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', >>> 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ >>> site-packages', >>> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>> >>> C:\> >>> >>> On Windows cygwin: >>> >>> $ echo $PYTHONPATH >>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >>> >>> $ python -c "import sys ; print sys.path" >>> ['', >>> >>> >> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >> >>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', >>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', >>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', >>> 'c:\\Python26\\lib\\site-packages', >>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>> >>> $ >>> >>> What am I doing wrong ? >>> >>> Thanks, >>> Ron. >>> >>> >>> >>> >> In your original message, what you displayed worked exactly >> as expected. As you didn't say what made you think something >> was wrong, I ignored the message. >> >> Now, you say that some modules are not found. So how about >> giving some more specifics so someone can actually debug the >> problem. Pick a particular module, tell us the complete path >> to that module, and show us both the sys.path strings (which >> look correct for the Windows case, and of course bogus for >> the cygwin case), as well as the offending import statement >> and its traceback. >> >> DaveA >> > > Hi Dave, > > My Python is the Windows Python (I need this for wxPython): > > $ ls -ls `which python` > 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 /usr/bin/python -> /cygdrive/c/Python26/python.exe > > Here's a demo script: > > #!/usr/bin/env python > > import sys > print "\n",sys.path,"\n" > > from ErrorManager.ErrorManager import ErrorManager > > And it's run produces: > > $ python -u tmp.py > > ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > Traceback (most recent call last): > File "tmp.py", line 6, in > from ErrorManager.ErrorManager import ErrorManager > ImportError: No module named ErrorManager.ErrorManager > > $ ls -ls /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py > 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py > > $ grep ErrorManager /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > ErrorManager/ErrorManager.py > class ErrorManager: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > Please let me know if the above is enough, or you'd like to see the results from a Windows' DOS window. > > Thanks, > Ron. > > Well, I pointed out that your cygwin path is bogus, so of course it won't work. One of those entries is '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib' I use Linux, and I use Windows. But cygwin's glomming together has never made sense; some things are Unix-like, and others are Windows-like. So anything you do in that environment is beyond me. If I had to guess, though I'd say you wanted to drop those first two characters from your PYTHONPATH. If you really wanted two directories there, you should be separating them with semicolon (Windows rules), rather than colon (Linux rules). First thing I'd do to test my theories is to print something like: print sys.path[1] print os.listdir(sys.path[1]) Does Python even see the cygwin view of the world ? You also don't show the location of the module you're trying to import. I'm guessing that it's at ...SVMInspector/lib/ErrorManager/ErrorManager.py Do you have a file ...SVMInspector/lib/ErrorManager/__init__.py ? I would seriously recommend against naming your package, your module, and your class all the same thing. Makes debugging very hard. At least make them have different case combinations. DaveA From s.selvamsiva at gmail.com Tue Mar 16 12:31:25 2010 From: s.selvamsiva at gmail.com (S.Selvam) Date: Tue, 16 Mar 2010 22:01:25 +0530 Subject: web sound recording with python In-Reply-To: <4acee8d1$0$919$ba4acef3@news.orange.fr> References: <7676a0f3-5126-4930-af07-0b3cb737dffc@m33g2000pri.googlegroups.com> <4acee8d1$0$919$ba4acef3@news.orange.fr> Message-ID: On Fri, Oct 9, 2009 at 1:10 PM, Michel Claveau - MVP wrote: > Hi! > > On windows, you can record sound who play on the local sound-card. > It is not really Python scripting, but Python can launch it. > Does python do not have support for voice recording ? -- Regards, S.Selvam " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From dmj.ccc at gmail.com Tue Mar 16 12:31:36 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 09:31:36 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> Message-ID: <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> Thanks Paul, but i don't immediately see how that helps (maybe I'm just being dense)... nn's solution, though i initially thought it worked, actually has a similar problem: intended: >>> print getOutcomes([3,4,5,5]) [[6, 1, 5, 5], [4.5, 2.5, 5, 5], [3, 4, 5, 5], [1.5, 5.5, 5, 5], [0, 7, 5, 5]] >>> print getOutcomes([4,3,5,5]) [[7, 0, 5, 5], [5.5, 1.5, 5, 5], [4, 3, 5, 5], [2.5, 4.5, 5, 5], [1, 6, 5, 5]] nn's solution: >>> print getOutcomesNN([4,3,5,5]) [[6.0, 1.0, 5, 5], [4.5, 2.5, 5, 5], [3.0, 4.0, 5, 5], [1.5, 5.5, 5, 5], [0.0, 7.0, 5, 5]] it's obvious why this is happening (the list comprehension assumes that index 0 is, after all, index 0), but not immediately obvious how to fix it, except by going with gerard's solution or doing what i did in the beginning: flip them if they're in the wrong order, remember, and flip them again at the end. dmj From googler.1.webmaster at spamgourmet.com Tue Mar 16 12:41:16 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 09:41:16 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> In one case I have to check the return value of PyObject_Call, and if its not of the correct return value, I throw an exception, but I just get a simple output: TypeError: Expected an instance of XYZ, no int. instead of Traceback (most called...) TypeError: in line 3, file test.py: expected an instance of XYZ, no int... From jackdied at gmail.com Tue Mar 16 12:49:59 2010 From: jackdied at gmail.com (Jack Diederich) Date: Tue, 16 Mar 2010 12:49:59 -0400 Subject: Dynamic Class Creation In-Reply-To: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> References: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> Message-ID: On Tue, Mar 16, 2010 at 2:18 AM, Chris Rebert wrote: > On Mon, Mar 15, 2010 at 11:01 PM, Josh English > wrote: >> I have a large program with lots of data stored in XML. I'm upgrading >> my GUI to use ObjectListView, but with my data in XML, I don't have >> regular objects to interact with the OLV. I do have an XML validator >> that defines the structure of the XML elements, and I'm trying to >> dynamically create a class to wrap the XML element. >> >> So, an element like: >> >> >> Writers of the Future >> >> >> I want to create a class like: >> >> class Market(object): >> ? ?def __init__(self, elem): >> ? ? ? ?self._elem = elem >> >> ? ?def get_code(self): >> ? ? ? ?return self._elem.get('code') >> >> ? ?def set_code(self, value): >> ? ? ? ?self._elem.set('code', value) >> >> ? ?def get_title(self): >> ? ? ? ?return self._elem.find('title').text >> >> ? ?def set_title(self, value): >> ? ? ? ?node = self._elem.find('title') >> ? ? ? ?node.text = value >> >> Naturally, I don't want to hand code this for every interface but >> would like to create them dynamically. (The laziness of programming, I >> guess.) >> >> What's the best way to create these helper methods? You can either define a catch-all __getattr__ method to look them up dynamically, or as Chris kinda-suggested write descriptors for the individual elements. class Market(): def __init__(self, elem): self._elem = elem def __getattr__(self, name): try: # I'm assuming this raises a KeyError when not found return self._elem.get(name) except KeyError: return self._elem.find(name) def __setitem__(self, name, value): # like __getitem__ but for setting Chris' property maker function is almost like a descriptor class (how properties are implemented under the hood), here's a refactoring [untested] class ElemGetProperty(): def __init__(self, name): self.name = name def __get__(self, ob, cls): return ob._elem.get(self.name) def __set__(self, ob, val): ob._elem.set(self.name, val) You could write one property class for each kind of element (get/find) and then put them in your class like this class Market(): code = ElemGetProperty('code') title = ElemFindProeprty('title') The getattr/setattr method is easier to understand and will handle arbitrary elements; for the descriptors version you'll have to define one for each tag that might be used on the class. -Jack From clp2 at rebertia.com Tue Mar 16 12:53:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 09:53:37 -0700 Subject: Dynamic Class Creation In-Reply-To: References: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> Message-ID: <50697b2c1003160953l209c21ddm5b9c0d960a6f2@mail.gmail.com> On Tue, Mar 16, 2010 at 9:49 AM, Jack Diederich wrote: > On Tue, Mar 16, 2010 at 2:18 AM, Chris Rebert wrote: >> On Mon, Mar 15, 2010 at 11:01 PM, Josh English >> wrote: >>> What's the best way to create these helper methods? > > You can either define a catch-all __getattr__ method to look them up > dynamically, or as Chris kinda-suggested write descriptors for the > individual elements. > > class Market(): > ?def __init__(self, elem): > ? ?self._elem = elem > ?def __getattr__(self, name): > ? ?try: > ? ? ?# I'm assuming this raises a KeyError when not found > ? ? ?return self._elem.get(name) > ? ?except KeyError: > ? ? ?return self._elem.find(name) > ?def __setitem__(self, name, value): did you mean __setattr__ here? > The getattr/setattr method is easier to understand and will handle > arbitrary elements; ?for the descriptors version you'll have to define > one for each tag that might be used on the class. Cheers, Chris -- http://blog.rebertia.com From dmj.ccc at gmail.com Tue Mar 16 12:54:57 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 09:54:57 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> Message-ID: <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> of course, changing nn's to: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder = myList[not low_id]-myList[low_id] tail=list(myList[2:]) outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] return outcomes works, just hides the ugliness in a more compact form From martin.schmidt1 at gmail.com Tue Mar 16 12:56:15 2010 From: martin.schmidt1 at gmail.com (Martin Schmidt) Date: Tue, 16 Mar 2010 11:56:15 -0500 Subject: Python-list Digest, Vol 78, Issue 161 In-Reply-To: References: Message-ID: <5444f9711003160956l316a07dfs89f4f418e7528f20@mail.gmail.com> Thanks, Stefan. Actually I will have to run the searches I am interested in only a few times and therefore will drop performance concerns. Thanks for len(text.split()) . I will try it later. The text I am interested in is always in leaf elements. I have posted a concrete example incl. a representative XML file a few minutes ago. I hope this clarifies my problem. Rereading what I wrote sounds admittedly funnny. What I meant that I did not find a post that closely matches my problem (I know that the closeness needed in my case will seem excessive to more experienced Python/XML users). Best regards. Martin P.S. Sorry for my late reply, but my Internet connection was down for a day. > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Tue, 16 Mar 2010 08:50:30 +0100 > Subject: Re: extract occurrence of regular expression from elements of XML > documents > Martin Schmidt, 15.03.2010 18:16: > >> I have just started to use Python a few weeks ago and until last week I >> had >> no knowledge of XML. >> Obviously my programming knowledge is pretty basic. >> Now I would like to use Python in combination with ca. 2000 XML documents >> (about 30 kb each) to search for certain regular expression within >> specific >> elements of these documents. >> > > 2000 * 30K isn't a huge problem, that's just 60M in total. If you just have > to do it once, drop your performance concerns and just get a solution going. > If you have to do it once a day, take care to use a tool that is not too > resource consuming. If you have strict requirements to do it once a minute, > use a fast machine with a couple of cores and do it in parallel. If you have > a huge request workload and want to reverse index the XML to do all sorts of > sophisticated queries on it, use a database instead. > > > I would then like to record the number of occurrences of the regular >> expression within these elements. >> Moreover I would like to count the total number of words contained within >> these, >> > > len(text.split()) will give you those. > > BTW, is it document-style XML (with mixed content as in HTML) or is the > text always withing a leaf element? > > > and record the attribute of a higher level element that contains >> them. >> > > An example would certainly help here. > > > I was trying to figure out the best way how to do this, but got >> overwhelmed >> by the available information (e.g. posts using different approaches based >> on >> dom, sax, xpath, elementtree, expat). >> The outcome should be a file that lists the extracted attribute, the >> number >> of occurrences of the regular expression, and the total number of words. >> I did not find a post that addresses my problem. >> > > Funny that you say that after stating that you were overwhelmed by the > available information. > > > If someone could help me with this I would really appreciate it. >> > > Most likely, the solution with the best simplicity/performance trade-off > would be xml.etree.cElementTree's iterparse(), intercept on each interesting > tag name, and search its text/tail using the regexp. That's doable in a > couple of lines. > > But unless you provide more information, it's hard to give better advice. > > Stefan > > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: "Lawrence D'Oliveiro" > Date: Tue, 16 Mar 2010 00:52:07 -0700 > Subject: Re: import antigravity > On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro > wrote: > > Subtle... > > You're a bit behind the times. > If my calculations are right, that comic is over 2 years old. > > Cheers, > Chris > > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Tue, 16 Mar 2010 08:51:58 +0100 > Subject: Re: import antigravity > Lawrence D'Oliveiro, 16.03.2010 08:40: > >> Subtle... >> > > Absolutely. > > Python 2.4.6 (#2, Jan 21 2010, 23:45:25) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import antigravity > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named antigravity > > > Stefan > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 16 12:56:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 12:56:21 -0400 Subject: How to add a library path to pythonpath ? In-Reply-To: <4B9FB09A.7030609@ieee.org> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> <4B9FB09A.7030609@ieee.org> Message-ID: Dave Angel wrote: > Barak, Ron wrote: >> >>> -----Original Message----- >>> From: Dave Angel [mailto:davea at ieee.org] >>> Sent: Tuesday, March 16, 2010 5:04 PM >>> To: Barak, Ron >>> Cc: Pablo Recio Quijano; python-list at python.org >>> Subject: RE: How to add a library path to pythonpath ? >>> >>> >>> >>> Barak, Ron wrote: >>> >>>> Thanks for the suggestion Pable. >>>> >>>> However, I really need the $PYTHONPATH to include this >>>> >>> additional library, so all Python scripts could use it. >>> >>>> In Windows I have defined PYTHONPATH as >>>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the >>>> Windows registry I have >>>> >>>> >>>> >>> HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as >>> >>> C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn >>> >>>> spector\lib\;C:\Python26\Lib\lib-tk; >>>> >>>> However, even with all the above, the SVMInspecor modules >>>> >>> are not found. >>> >>>> >>> See my response at the end. Top-posting makes for a very >>> confusing thread. >>> >>>> >>>> >>>> 2010/3/16 Barak, Ron > >>>> >>>> Hi, >>>> >>>> I'm trying to add a library path to my pythonpath, but >>>> >>> seems it is not >>> >>>> accepted - >>>> >>>> On Windows DOS window: >>>> >>>> C:\>echo %PYTHONPATH% >>>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ >>>> >>>> C:\>python -c "import sys ; print sys.path" >>>> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >>>> 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', >>>> 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', >>>> 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ >>>> site-packages', >>>> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>>> >>>> C:\> >>>> >>>> On Windows cygwin: >>>> >>>> $ echo $PYTHONPATH >>>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >>>> >>>> $ python -c "import sys ; print sys.path" >>>> ['', >>>> >>>> >>> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >>> >>>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', >>>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', >>>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', >>>> 'c:\\Python26\\lib\\site-packages', >>>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>>> >>>> $ >>>> >>>> What am I doing wrong ? >>>> >>>> Thanks, >>>> Ron. >>>> >>>> >>>> >>>> >>> In your original message, what you displayed worked exactly >>> as expected. As you didn't say what made you think something >>> was wrong, I ignored the message. >>> >>> Now, you say that some modules are not found. So how about >>> giving some more specifics so someone can actually debug the >>> problem. Pick a particular module, tell us the complete path >>> to that module, and show us both the sys.path strings (which >>> look correct for the Windows case, and of course bogus for >>> the cygwin case), as well as the offending import statement >>> and its traceback. >>> >>> DaveA >>> >> >> Hi Dave, >> >> My Python is the Windows Python (I need this for wxPython): >> >> $ ls -ls `which python` >> 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 /usr/bin/python -> >> /cygdrive/c/Python26/python.exe >> >> Here's a demo script: >> >> #!/usr/bin/env python >> >> import sys >> print "\n",sys.path,"\n" >> >> from ErrorManager.ErrorManager import ErrorManager >> >> And it's run produces: >> >> $ python -u tmp.py >> >> ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', >> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', >> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', >> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', >> 'c:\\Python26\\lib\\site-packages', >> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >> >> Traceback (most recent call last): >> File "tmp.py", line 6, in >> from ErrorManager.ErrorManager import ErrorManager >> ImportError: No module named ErrorManager.ErrorManager >> >> $ ls -ls >> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py >> >> 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 >> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py >> >> >> $ grep ErrorManager >> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >> ErrorManager/ErrorManager.py >> class ErrorManager: >> >> $ echo $PYTHONPATH >> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >> >> Please let me know if the above is enough, or you'd like to see the >> results from a Windows' DOS window. >> >> Thanks, >> Ron. >> >> > Well, I pointed out that your cygwin path is bogus, so of course it > won't work. One of those entries is > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib' > > I use Linux, and I use Windows. But cygwin's glomming together has > never made sense; some things are Unix-like, and others are > Windows-like. So anything you do in that environment is beyond me. > > If I had to guess, though I'd say you wanted to drop those first two > characters from your PYTHONPATH. If you really wanted two directories > there, you should be separating them with semicolon (Windows rules), > rather than colon (Linux rules). First thing I'd do to test my theories > is to print something like: > print sys.path[1] > print os.listdir(sys.path[1]) > Does Python even see the cygwin view of the world ? > > You also don't show the location of the module you're trying to import. > I'm guessing that it's at ...SVMInspector/lib/ErrorManager/ErrorManager.py > Do you have a file ...SVMInspector/lib/ErrorManager/__init__.py ? > > I would seriously recommend against naming your package, your module, > and your class all the same thing. Makes debugging very hard. At least > make them have different case combinations. > In point of fact the mistake that's happening here is running the Windows Python under Cygwin and expecting it to make sense. Just because you run the Windows Python interpreter under Windows doesn't make it magically capable of understanding a Cygwin path specification. We have yet to hear why the Cygwin Python isn't acceptable (though one reason might be the unavailability of 2.6). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From martin.schmidt1 at gmail.com Tue Mar 16 12:58:00 2010 From: martin.schmidt1 at gmail.com (Martin Schmidt) Date: Tue, 16 Mar 2010 11:58:00 -0500 Subject: extract occurrence of regular expression from elements of XML documents Message-ID: <5444f9711003160958h6514141amcfa12fa4233c4c67@mail.gmail.com> On Tue, Mar 16, 2010 at 11:56 AM, Martin Schmidt wrote: > Thanks, Stefan. > Actually I will have to run the searches I am interested in only a few > times and therefore will drop performance concerns. > > Thanks for len(text.split()) . > I will try it later. > > The text I am interested in is always in leaf elements. > > I have posted a concrete example incl. a representative XML file a few > minutes ago. > I hope this clarifies my problem. > > Rereading what I wrote sounds admittedly funnny. > What I meant that I did not find a post that closely matches my problem (I > know that the closeness needed in my case will seem excessive to more > experienced Python/XML users). > > Best regards. > > Martin > > > P.S. Sorry for my late reply, but my Internet connection was down for a > day. > > > > >> ---------- Forwarded message ---------- >> From: Stefan Behnel >> To: python-list at python.org >> Date: Tue, 16 Mar 2010 08:50:30 +0100 >> Subject: Re: extract occurrence of regular expression from elements of XML >> documents >> Martin Schmidt, 15.03.2010 18:16: >> >>> I have just started to use Python a few weeks ago and until last week I >>> had >>> no knowledge of XML. >>> Obviously my programming knowledge is pretty basic. >>> Now I would like to use Python in combination with ca. 2000 XML documents >>> (about 30 kb each) to search for certain regular expression within >>> specific >>> elements of these documents. >>> >> >> 2000 * 30K isn't a huge problem, that's just 60M in total. If you just >> have to do it once, drop your performance concerns and just get a solution >> going. If you have to do it once a day, take care to use a tool that is not >> too resource consuming. If you have strict requirements to do it once a >> minute, use a fast machine with a couple of cores and do it in parallel. If >> you have a huge request workload and want to reverse index the XML to do all >> sorts of sophisticated queries on it, use a database instead. >> >> >> I would then like to record the number of occurrences of the regular >>> expression within these elements. >>> Moreover I would like to count the total number of words contained within >>> these, >>> >> >> len(text.split()) will give you those. >> >> BTW, is it document-style XML (with mixed content as in HTML) or is the >> text always withing a leaf element? >> >> >> and record the attribute of a higher level element that contains >>> them. >>> >> >> An example would certainly help here. >> >> >> I was trying to figure out the best way how to do this, but got >>> overwhelmed >>> by the available information (e.g. posts using different approaches based >>> on >>> dom, sax, xpath, elementtree, expat). >>> The outcome should be a file that lists the extracted attribute, the >>> number >>> of occurrences of the regular expression, and the total number of words. >>> I did not find a post that addresses my problem. >>> >> >> Funny that you say that after stating that you were overwhelmed by the >> available information. >> >> >> If someone could help me with this I would really appreciate it. >>> >> >> Most likely, the solution with the best simplicity/performance trade-off >> would be xml.etree.cElementTree's iterparse(), intercept on each interesting >> tag name, and search its text/tail using the regexp. That's doable in a >> couple of lines. >> >> But unless you provide more information, it's hard to give better advice. >> >> Stefan >> >> >> >> >> ---------- Forwarded message ---------- >> From: Chris Rebert >> To: "Lawrence D'Oliveiro" >> Date: Tue, 16 Mar 2010 00:52:07 -0700 >> Subject: Re: import antigravity >> On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro >> wrote: >> > Subtle... >> >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. >> >> Cheers, >> Chris >> >> >> >> ---------- Forwarded message ---------- >> From: Stefan Behnel >> To: python-list at python.org >> Date: Tue, 16 Mar 2010 08:51:58 +0100 >> Subject: Re: import antigravity >> Lawrence D'Oliveiro, 16.03.2010 08:40: >> >>> Subtle... >>> >> >> Absolutely. >> >> Python 2.4.6 (#2, Jan 21 2010, 23:45:25) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import antigravity >> Traceback (most recent call last): >> File "", line 1, in ? >> ImportError: No module named antigravity >> >> >> Stefan >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 16 13:00:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 13:00:36 -0400 Subject: equivalent of Ruby's Pathname? In-Reply-To: <7284f1df-100e-4fed-aed2-20b114040d64@v34g2000prm.googlegroups.com> References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> <7284f1df-100e-4fed-aed2-20b114040d64@v34g2000prm.googlegroups.com> Message-ID: Phlip wrote: > Chris Rebert wrote: > >> The next closest thing would probably be the Python Cookbook:http://code.activestate.com/recipes/langs/python/ > > One thing I really like about ... my hacked version of path.py ... is > path.cd( lambda: ... ). It works great inside fabfile.py to > temporarily switch to a different folder: > > sample_project = path('sample_project').abspath() > > def run(): > sample_project.cd( lambda: > _sh('python manage.py runserver 0.0.0.0:8000 -- > settings=test_settings') ) > > After the lambda runs, we exception-safely return to the home folder. > > (BTW I'm aware that a fabfile.py command with only one statement will > return to its shell and remain in the correct folder. It's just ... > the thought!) > > This be .cd(): > > class path: > > def cd(self, block=None): > previous = path(os.path.curdir).abspath() > self.chdir() > > if block: > try: block() > finally: previous.chdir() > > That's based on Jason Orendoff's work at http://www.jorendorff.com/articles/python/path > Wouldn't this be better written as a context manager? Be aware also that this won't work well in a multi-threaded environment (assuming os.path.chdir is ultimately used to change directories) because it effects the process's (globaL current directory. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mail.to.daniel.platz at googlemail.com Tue Mar 16 13:10:16 2010 From: mail.to.daniel.platz at googlemail.com (Daniel Platz) Date: Tue, 16 Mar 2010 10:10:16 -0700 (PDT) Subject: passing a socket to a subprocess in windows Message-ID: Hello! I have a problem with passing a socket to a subprocess in windows. It works in Linux and for windows there is a workaround in the Python doc. However, this workaround does not work. It was already noted by other people and they Python issue tracker http://bugs.python.org/issue5879 *************************************************************************************************************** the example from http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing named " # Example where a pool of http servers share a single listening socket # " does not work on windows. Reason: s = socket.fromfd(fd, family, type_, proto) in line 156 of reduction.py fails, because fromfd is not available on windows. Sad thing: reduction.py was put into processing.py exactly to solve that problem (i.e. reduction.py is provided as workaround for socket.fromfd not available on windows, from the documentation: if sys.platform == 'win32': import multiprocessing.reduction # make sockets pickable/inheritable the solution within processing was: try: fromfd = socket.fromfd except AttributeError: def fromfd(fd, family, type, proto=0): s = socket._socket.socket() _processing.changeFd(s, fd, family, type, proto) return s but: _multiprocessing has no longer a method changeFd. Harald *********************************************************************************************************************** Has someone information about this or can help me to solve the problem. Thanks in advance Daniel From steve at holdenweb.com Tue Mar 16 13:14:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 13:14:04 -0400 Subject: C-API PyObject_Call In-Reply-To: <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: moerchendiser2k3 wrote: > In one case I have to check the return value of PyObject_Call, and if > its not of the correct return value, > I throw an exception, but I just get a simple output: > > TypeError: Expected an instance of XYZ, no int. > > instead of > > Traceback (most called...) > TypeError: in line 3, file test.py: expected an instance of XYZ, no > int... Could we perhaps see a little bit more of the code? Are you throwing the exception from within your C code or from the Python calling environment with a raise statement? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at bdurham.com Tue Mar 16 13:18:15 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 16 Mar 2010 13:18:15 -0400 Subject: Converting Python CGI to WSGI scripts Message-ID: <1268759895.28810.1365130739@webmail.messagingengine.com> I have a few dozen simple Python CGI scripts. Are there any advantages or disadvantages to rewriting these CGI scripts as WSGI scripts? Apologies if my terminology is not correct ... when I say WSGI scripts I mean standalone scripts like the following simplified (as an example) template: import sys def application(environ, start_response): output = 'Welcome to your mod_wsgi website! It uses:\n\nPython %s' % sys.version response_headers = [ ('Content-Length', str(len(output))), ('Content-Type', 'text/plain'), ] start_response('200 OK', response_headers) return [output] When I say script I don't mean classic WSGI application in the sense of a .serve_forever() loop coordinating a bunch of related scripts - I mean individual, standalone scripts. Hope this makes sense :) Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From gatoygata2 at gmail.com Tue Mar 16 14:13:40 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 16 Mar 2010 11:13:40 -0700 (PDT) Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: <168167cf-c153-4e2b-8bca-5b9ae7afd67d@t23g2000yqt.googlegroups.com> On Mar 16, 5:20?pm, Johny wrote: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > ?not using os.system command. > Thanks > L. subprocess ? From gatoygata2 at gmail.com Tue Mar 16 14:14:50 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 16 Mar 2010 11:14:50 -0700 (PDT) Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: <92fa9d1d-d5a3-46b5-947b-12a0f338ee7e@t41g2000yqt.googlegroups.com> On Mar 16, 5:20?pm, Johny wrote: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > ?not using os.system command. > Thanks > L. subprocess ? From googler.1.webmaster at spamgourmet.com Tue Mar 16 14:25:25 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 11:25:25 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: Hi, currently I am not at home, I will post some stuff when I am back. Just the note: I throw an exception with the C API. Looks like that PyObject *result = PyObject_Call(my_isntance, "", NULL); if(result==NULL) { PyErr_Print(); //when this happens, the traceback is correct with information about the file/line return; } if(!PyXYZ_Check(result)) { PyErr_SetString(PyExc_TypeError, "Wrong type, ...."); PyErr_Print(); //missing information of the file/line. return; } Well, I expect, that there are no information about the line/file, so I know something is missing, but what is missing? Bye, moerchendiser2k3 From twistedphrame at gmail.com Tue Mar 16 14:56:30 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 16 Mar 2010 11:56:30 -0700 (PDT) Subject: datetime string conversion error Message-ID: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Hey all, I'm trying to convert a string to a date time object and all my fields convert except for month which seems to default to january. here's what I'm doing: date = "2010-03-16 14:46:38.409137" olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") print date print olddate I get: 2010-03-16 14:46:38.409137 2010-01-16 14:46:38.409137 notice the 01 in the second date from what I could tell everything is formatted correctly. thanks for the help. ~Jordan From tack at urandom.ca Tue Mar 16 14:59:00 2010 From: tack at urandom.ca (Jason Tackaberry) Date: Tue, 16 Mar 2010 14:59:00 -0400 Subject: to pass self or not to pass self In-Reply-To: <4b9f4984$0$10229$426a74cc@news.free.fr> References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <1268765940.6473.13.camel@arrakis> On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: > Answer here: > > http://wiki.python.org/moin/FromFunctionToMethod I have a sense I used to know this once upon a time, but the question came to my mind (possibly again) and I couldn't think of an answer: Why not create the bound methods at instantiation time, rather than using the descriptor protocol which has the overhead of creating a new bound method each time the method attribute is accessed? Cheers, Jason. From lists at cheimes.de Tue Mar 16 15:07:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Mar 2010 20:07:32 +0100 Subject: datetime string conversion error In-Reply-To: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: <4B9FD6F4.3060503@cheimes.de> Jordan Apgar wrote: > Hey all, > I'm trying to convert a string to a date time object and all my fields > convert except for month which seems to default to january. > > here's what I'm doing: > date = "2010-03-16 14:46:38.409137" > olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > > print date > print olddate > > I get: > 2010-03-16 14:46:38.409137 > 2010-01-16 14:46:38.409137 > > notice the 01 in the second date from what I could tell everything is > formatted correctly. %j is documtend as "Day of the year as a decimal number [001,366].". Did you mean %d instead? Christian From torriem at gmail.com Tue Mar 16 15:07:38 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 16 Mar 2010 13:07:38 -0600 Subject: Searching for most pythonic/least stupid way to do something simple In-Reply-To: <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> Message-ID: <4B9FD6FA.2010607@gmail.com> david jensen wrote: > of course, changing nn's to: > def getOutcomes(myList=[2,5,8,3,5]): > low_id = int(myList[0]>myList[1]) > amountToShare = 2*myList[low_id] > remainder = myList[not low_id]-myList[low_id] > tail=list(myList[2:]) > outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ > tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else > [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc > in (1.0, 0.75, 0.5, 0.25, 0.0)] > return outcomes > > > works, just hides the ugliness in a more compact form If Gerard's code works, I would consider it far superior to your code here. Pythonic does not necessarily mean short and ugly, nor does it mean that you have to always use list comprehensions. Having a readable algorithm that's easy to follow in the future is a far better way than trying to use python's cool features to compact the code to as small and unreadable section as possible. I used to use list comprehension all the time, but I've found that often an explicit for loop is a much better solution in terms of maintainability. Especially when you start seeing nested comprehensions such as you have here. From twistedphrame at gmail.com Tue Mar 16 15:11:54 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 16 Mar 2010 12:11:54 -0700 (PDT) Subject: datetime string conversion error References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: On Mar 16, 3:07?pm, Christian Heimes wrote: > Jordan Apgar wrote: > > Hey all, > > I'm trying to convert a string to a date time object and all my fields > > convert except for month which seems to default to january. > > > here's what I'm doing: > > date = "2010-03-16 14:46:38.409137" > > ?olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > > > print date > > print olddate > > > I get: > > 2010-03-16 14:46:38.409137 > > 2010-01-16 14:46:38.409137 > > > notice the 01 in the second date from what I could tell everything is > > formatted correctly. > > %j is documtend as "Day of the year as a decimal number [001,366].". Did > you mean %d instead? > > Christian That fixed it, thank you From gagsl-py2 at yahoo.com.ar Tue Mar 16 15:12:21 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 16:12:21 -0300 Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: En Tue, 16 Mar 2010 13:20:40 -0300, Johny escribi?: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > not using os.system command. Do you mean that you want to execute a particular function in the .exe program? That's not possible (ok, you *could* do that if you work hard enough, but that's not how things are usually done) -- Gabriel Genellina From zak.mc.kraken at libero.it Tue Mar 16 15:17:43 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Tue, 16 Mar 2010 20:17:43 +0100 Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: Grant Edwards wrote: >> As for not being able to see the difference between a hyphen and an >> EN- dash, or minus sign, or whatever it is, yes but they are very >> similar looking glyphs in virtually ever modern font. It would take a >> good eye to see the difference between (say) ??? ??? and -. > > My point is that if it's an ASCII file, source files aren't (necessary) ASCII files -- By ZeD From hansmu at xs4all.nl Tue Mar 16 15:30:22 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 16 Mar 2010 20:30:22 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Ulrich Eckhardt wrote: > Chris Rebert wrote: >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. > > import timetravel I think you mean: from __future__ import timetravel -- HansM From martin.hellwig at dcuktec.org Tue Mar 16 15:44:58 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 16 Mar 2010 19:44:58 +0000 Subject: import antigravity In-Reply-To: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: On 03/16/10 19:30, Hans Mulder wrote: > Ulrich Eckhardt wrote: >> Chris Rebert wrote: >>> You're a bit behind the times. >>> If my calculations are right, that comic is over 2 years old. >> >> import timetravel > > I think you mean: > > from __future__ import timetravel > > > -- HansM Well according to Marty it is: from __back_to_the_future import DeLorean -- mph From python at mrabarnett.plus.com Tue Mar 16 15:53:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Mar 2010 19:53:20 +0000 Subject: datetime string conversion error In-Reply-To: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: <4B9FE1B0.3040700@mrabarnett.plus.com> Jordan Apgar wrote: > Hey all, > I'm trying to convert a string to a date time object and all my fields > convert except for month which seems to default to january. > > here's what I'm doing: > date = "2010-03-16 14:46:38.409137" > olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > > print date > print olddate > > I get: > 2010-03-16 14:46:38.409137 > 2010-01-16 14:46:38.409137 > > notice the 01 in the second date from what I could tell everything is > formatted correctly. > The problem seems to be related to your use of "%j", which parses the day of the year. If I use "%d" instead, which parses the day of the month (I think that's what you intended!), then the month comes out as 3 as expected. From tjreedy at udel.edu Tue Mar 16 16:04:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Mar 2010 16:04:22 -0400 Subject: Understanding the CPython dict implementation In-Reply-To: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> References: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 3/16/2010 7:46 AM, Steven D'Aprano wrote: > On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: > >> I found this PyCon2010 presentation to be excellent: The Mighty >> Dictionary, Branden Craig Rhodes, 30 min. Sorry, http://pycon.blip.tv/file/3332763/ which plays fine in FF3.6 on windows >> http://pycon.blip.tv/file/3264041/ wrong file number > Unfortunately, that clip seems to be unwatchable, at least for me. It > crashed the Netscape plugin in Konqueror, and crashed Firefox. The flash version does not work for me. This is true of about 1/3 of the Pycon 2010 videos that I have tried. The .ogv version of this and all others that I have tried (hit Download under Comments) plays fine within FF3.6 on my windows xp machine. Perhaps there is a linux-specific bug, if that is what you are running under. Terry Jan Reedy From tjreedy at udel.edu Tue Mar 16 16:10:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Mar 2010 16:10:22 -0400 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: On 3/16/2010 3:12 PM, Gabriel Genellina wrote: > En Tue, 16 Mar 2010 13:20:40 -0300, Johny escribi?: > >> Is there any tutorial how to write a bindings for a exe ( dos) >> program? >> I would like to run it from a Python directly >> ( using import command and a particular function from the binding) >> not using os.system command. > > Do you mean that you want to execute a particular function in the .exe > program? > That's not possible (ok, you *could* do that if you work hard enough, > but that's not how things are usually done) If running a function within the .exe *is* what you want, then you should compile to .dll instead of .exe and use swig or ctypes to do the binding. From invalid at invalid.invalid Tue Mar 16 16:12:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 16 Mar 2010 20:12:29 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-16, Vito 'ZeD' De Tullio wrote: > Grant Edwards wrote: > >>> As for not being able to see the difference between a hyphen and an >>> EN- dash, or minus sign, or whatever it is, yes but they are very >>> similar looking glyphs in virtually ever modern font. It would take a >>> good eye to see the difference between (say) ??? ??? and -. >> >> My point is that if it's an ASCII file, > > source files aren't (necessary) ASCII files OK, if it's a file with encoding , then characters that aren't part of shouldn't be rendered according so some other arbitrary character set. Illegal characters should be flagged and displayed in a manner that makes it obvious you have illegal characters in in the file. If the OP was using a source file with an encoding that isn't accepted by Python, then he needs to pick a source file encoding that is recognized by Python. Using a source file encoding where there are semantically _different_ characters that render identically is just asking for pain... -- Grant Edwards grant.b.edwards Yow! I guess you guys got at BIG MUSCLES from doing too gmail.com much STUDYING! From jgardner at jonathangardner.net Tue Mar 16 16:15:13 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 16 Mar 2010 13:15:13 -0700 Subject: to pass self or not to pass self In-Reply-To: <4b9f4984$0$10229$426a74cc@news.free.fr> References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <6cc20cea1003161315i377bc9c2l525964b1cb6550e7@mail.gmail.com> On Tue, Mar 16, 2010 at 2:04 AM, Bruno Desthuilliers wrote: > lallous a ?crit : >> >> What is the difference between the reference in 'F' and 'func_tbl' ? > > Answer here: > > http://wiki.python.org/moin/FromFunctionToMethod > Among all the things in the Python language proper, this is probably the most confusing thing for new programmers. Heck, even experienced programmers get tangled up because they project how they think things should work on to the Python model. The second most confusing thing is probably how objects get instantiated. -- Jonathan Gardner jgardner at jonathangardner.net From pavlovevidence at gmail.com Tue Mar 16 16:16:50 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 16 Mar 2010 13:16:50 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: On Mar 16, 11:25?am, moerchendiser2k3 wrote: > Hi, currently I am not at home, I will post some stuff when I am back. > Just the note: I throw an exception with the C API. > > Looks like that > > PyObject *result = PyObject_Call(my_isntance, "", NULL); > if(result==NULL) > { > ? ? PyErr_Print(); //when this happens, the traceback is correct with > information about the file/line > ? ? return; > > } > > if(!PyXYZ_Check(result)) > { > ? ? PyErr_SetString(PyExc_TypeError, "Wrong type, ...."); > ? ? PyErr_Print(); //missing information of the file/line. > ? ? return; > } > > Well, I expect, that there are no information about the line/file, so > I know something is missing, but what is missing? Python tracebacks only contain line/file information about Python files, not C files. Here you raise an exception with a C statement, and catch and print it in the very next line. The exception doesn't exit from Python code so there are no lines to print. What line/file data you do expect to see? If you want to see C line/file informnation you have to use a debugger like gdb, as Steve Holden said. Carl Banks From dmj.ccc at gmail.com Tue Mar 16 16:27:19 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 13:27:19 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> Message-ID: <03631aaf-0cf2-4c15-9e0d-7ac0f33ae01d@c16g2000yqd.googlegroups.com> >If Gerard's code works, I would consider it far superior to your code >here. Pythonic does not necessarily mean short and ugly yes, I agree... and in my script i'm using something very like Gerard's (thanks again, Gerard). I just posted the corrected version of nn's because the original solved only half the problem. thanks, all dmj From aahz at pythoncraft.com Tue Mar 16 16:37:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 13:37:57 -0700 Subject: The first ASIC designed with MyHDL References: <4b9f7414$0$2887$ba620e4c@news.skynet.be> Message-ID: In article <4b9f7414$0$2887$ba620e4c at news.skynet.be>, Jan Decaluwe wrote: > >I am proud to report on the first ASIC product designed with MyHDL >(afaik). > >http://www.jandecaluwe.com/hdldesign/digmac.html Congrats! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From benjamin.kaplan at case.edu Tue Mar 16 16:42:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 16 Mar 2010 16:42:05 -0400 Subject: subtraction is giving me a syntax error In-Reply-To: References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Tue, Mar 16, 2010 at 4:12 PM, Grant Edwards wrote: > On 2010-03-16, Vito 'ZeD' De Tullio wrote: > > Grant Edwards wrote: > > > >>> As for not being able to see the difference between a hyphen and an > >>> EN- dash, or minus sign, or whatever it is, yes but they are very > >>> similar looking glyphs in virtually ever modern font. It would take a > >>> good eye to see the difference between (say) ??? ??? and -. > >> > >> My point is that if it's an ASCII file, > > > > source files aren't (necessary) ASCII files > > OK, if it's a file with encoding , then characters that > aren't part of shouldn't be rendered according so some > other arbitrary character set. Illegal characters should be flagged > and displayed in a manner that makes it obvious you have illegal > characters in in the file. > > If the OP was using a source file with an encoding that isn't accepted > by Python, then he needs to pick a source file encoding that is > recognized by Python. > > Using a source file encoding where there are semantically _different_ > characters that render identically is just asking for pain... > > >>> print u'\N{HYPHEN-MINUS}' - >>> print u'\N{MINUS SIGN}' ? >>> print u'\N{SMALL HYPHEN-MINUS}' ? >>> print u'\N{FIGURE DASH}' ? >>> print u'\N{EN DASH}' ? >>> print u'\N{SMALL EM DASH}' ? >>> print u'\N{EM DASH}' ? >>> print u'\N{HORIZONTAL BAR}' ? Good luck finding a character encoding where you can see the difference between each of those in context. Do you program in a hex editor? > -- > Grant Edwards grant.b.edwards Yow! I guess you guys > got > at BIG MUSCLES from doing > too > gmail.com much STUDYING! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Mar 16 16:44:09 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 16 Mar 2010 20:44:09 +0000 Subject: import antigravity In-Reply-To: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: Hans Mulder wrote: > Ulrich Eckhardt wrote: >> Chris Rebert wrote: >>> You're a bit behind the times. >>> If my calculations are right, that comic is over 2 years old. >> >> import timetravel > > I think you mean: > > from __future__ import timetravel > > > -- HansM Taking 1984 into account surely it should be from __past__ import __future__ as future But the question is, have we yet got to 1984, are we currently there or have we already gone past it? Who actually *IS* running the time machine? Are there any bugs?? Regards. Mark Lawrence. From gagsl-py2 at yahoo.com.ar Tue Mar 16 18:39:04 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 19:39:04 -0300 Subject: passing a socket to a subprocess in windows References: Message-ID: En Tue, 16 Mar 2010 14:10:16 -0300, Daniel Platz escribi?: > I have a problem with passing a socket to a subprocess in windows. It > works in Linux and for windows there is a workaround in the Python > doc. However, this workaround does not work. It was already noted by > other people and they Python issue tracker > > http://bugs.python.org/issue5879 Unfortunately I cannot test it at this moment, but around line 360 in socketmodule.c: #if defined(MS_WINDOWS) || defined(__BEOS__) ... #define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */ #endif you could try removing that #define NO_DUP and recompiling. socket.fromfd should appear, and hopefully socket objects can now be sent thru the multiprocessing connection. (I cannot see how the example could have actually worked on Windows, maybe I'm missing something. Perhaps http://bugs.python.org/issue3125 broke this.) -- Gabriel Genellina From jlundell at pobox.com Tue Mar 16 18:55:17 2010 From: jlundell at pobox.com (JLundell) Date: Tue, 16 Mar 2010 15:55:17 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> <4B9F7B2A.1080906@ieee.org> Message-ID: On Mar 16, 8:06?am, Robert Kern wrote: > On 2010-03-16 07:35 AM, Dave Angel wrote: > > > > > > > > > Carl Banks wrote: > >> On Mar 15, 4:34 pm, JLundell wrote: > >>> It's also unfortunate that Python doesn't have an approximately-equal > >>> operator; it'd come in handy for floating-point applications while > >>> preserving hash. If only there were a ~=r ? operator I could > >>> overload. And ~ is unary, so no joy. > > >> One problem with it is that there's no way to make it universal; > >> different appiplications have different ideas of close. Conceivably > >> it could be usefully defined for a user type though.. > > >> Bacause of this problem almost no languages have an almost equal > >> operator. I'm curious what languages do, of if there are any with a > >> trinary operator that also takes a threshold. > > >> Carl Banks > > > If I recall correctly, APL has a *fuzz* value, which is used in all(?) > > comparisons. But I do not recall anything about how it was defined. I do > > recall that you could change the threshold, and suspect it was relative > > to the operands. For symmetry, it would probably have to be relative to > > the average of the two values, or some such. > > The problem is that frequently there is no system-wide fuzz value which is > appropriate for all comparisons in a given program. You need to choose the right > value for each comparison. Consequently, you might as well use a function > instead of an operator and a global variable. > > -- > Robert Kern > APL scaled their fuzz to the larger of the values being compared. In my case, my domain permits me to use a constant fuzz; all my units are the same (votes, as it happens). I've seen abs(a/b-1) used instead of abs(a-b); obviously you'd need to treat comparison with zero specially. But yeah, it's really a domain-specific problem. From joshua.r.english at gmail.com Tue Mar 16 19:31:11 2010 From: joshua.r.english at gmail.com (Josh English) Date: Tue, 16 Mar 2010 16:31:11 -0700 (PDT) Subject: datetime string conversion error References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: On Mar 16, 11:56?am, Jordan Apgar wrote: > here's what I'm doing: > date = "2010-03-16 14:46:38.409137" > ?olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on the other). When I have a script as simple as this: import datetime datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") Running this script brings up a calendar, believe it or not. The calendar displays March 2010, and shows the 22nd as a holiday. When I dismiss the dialog box I get: Traceback (most recent call last): File "strptimetest.py", line 3, in datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") File "C:\Python25\lib\_strptime.py", line 272, in _TimeRE_cache = TimeRE() File "C:\Python25\lib\_strptime.py", line 191, in __init__ self.locale_time = LocaleTime() File "C:\Python25\lib\_strptime.py", line 74, in __init__ self.__calc_weekday() File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] AttributeError: 'module' object has no attribute 'day_abbr' err... what? Is this an old weirdness I don't remember from the 2.5 series? I can select dates in the calendar, but nothing dismisses it but the close box. Josh English Incredibly Confused From robert.kern at gmail.com Tue Mar 16 19:32:04 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Mar 2010 18:32:04 -0500 Subject: class inheritance In-Reply-To: References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> <4B9F7B2A.1080906@ieee.org> Message-ID: On 2010-03-16 17:55 PM, JLundell wrote: > On Mar 16, 8:06 am, Robert Kern wrote: >> On 2010-03-16 07:35 AM, Dave Angel wrote: >> >>> Carl Banks wrote: >>>> On Mar 15, 4:34 pm, JLundell wrote: >>>>> It's also unfortunate that Python doesn't have an approximately-equal >>>>> operator; it'd come in handy for floating-point applications while >>>>> preserving hash. If only there were a ~=r ? operator I could >>>>> overload. And ~ is unary, so no joy. >> >>>> One problem with it is that there's no way to make it universal; >>>> different appiplications have different ideas of close. Conceivably >>>> it could be usefully defined for a user type though.. >> >>>> Bacause of this problem almost no languages have an almost equal >>>> operator. I'm curious what languages do, of if there are any with a >>>> trinary operator that also takes a threshold. >> >>>> Carl Banks >> >>> If I recall correctly, APL has a *fuzz* value, which is used in all(?) >>> comparisons. But I do not recall anything about how it was defined. I do >>> recall that you could change the threshold, and suspect it was relative >>> to the operands. For symmetry, it would probably have to be relative to >>> the average of the two values, or some such. >> >> The problem is that frequently there is no system-wide fuzz value which is >> appropriate for all comparisons in a given program. You need to choose the right >> value for each comparison. Consequently, you might as well use a function >> instead of an operator and a global variable. >> >> -- >> Robert Kern >> > > APL scaled their fuzz to the larger of the values being compared. I know. My statement stands for relative fuzz values as well as it does for absolute fuzz values. :-) > In > my case, my domain permits me to use a constant fuzz; all my units are > the same (votes, as it happens). I've seen abs(a/b-1) used instead of > abs(a-b); obviously you'd need to treat comparison with zero > specially. One usually uses a combination of relative and absolute tolerances to account for the case when the values are close to zero. > But yeah, it's really a domain-specific problem. Right. And a single program might need to deal with multiple domains, so a single global setting to control a language feature is pretty fragile. -- 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 From greg.ewing at canterbury.ac.nz Tue Mar 16 19:32:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 17 Mar 2010 12:32:40 +1300 Subject: Function that knows its argument's variable name In-Reply-To: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <80ai5hFh3uU1@mid.individual.net> Helge Stenstr?m wrote: > I want to write function that prints a value of a variable, for > debugging. Like: > > myVariable = "parrot" > otherVariable = "dead" > > probe(myVariable) > probe(otherVariable) Not exactly, but you can come close with a little hackery. import sys def print_var(name): print name, "=", sys._getframe(1).f_locals[name] def f(): fred = 42 mary = "christmas" print_var("fred") print_var("mary") f() -- Greg From phlip2005 at gmail.com Tue Mar 16 19:40:46 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Mar 2010 16:40:46 -0700 (PDT) Subject: Function that knows its argument's variable name References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <460a8b90-ee92-458c-b09e-abf230d7cdbc@q23g2000yqd.googlegroups.com> > Yet, the answer to your question is not quite absolutely "no". ?Python > has lots of introspection capabilities, including, perhaps, getting at > and parsing the original code to find the call. ? ?But there's nothing > direct for what you want. > > Gary Herron Below my sig is one shot at it; which requires a lambda: for other reasons. It's an assertion used with Django models. You can search for the name of your trace method, instead of lambda, using this brute-force technique. And here's a nice thread on Greg's technique, from a very short time ago: http://groups.google.com/group/comp.lang.python/msg/03dd85ce009044e9 -- Phlip http://penbird.tumblr.com/ def assert_model_changes(self, mod, item, frum, too, lamb): source = open(lamb.func_code.co_filename, 'r').readlines() [lamb.func_code.co_firstlineno - 1] source = source.replace('lambda:', '').strip() model = str(mod.__class__).replace("'>", '').split('.')[-1] should = '%s.%s should equal `%s` before your activation line, `%s`' % \ (model, item, frum, source) self.assertEqual(frum, mod.__dict__[item], should) lamb() mod = mod.__class__.objects.get(pk=mod.pk) should = '%s.%s should equal `%s` after your activation line, ` %s`' % \ (model, item, too, source) self.assertEqual(too, mod.__dict__[item], should) return mod From aahz at pythoncraft.com Tue Mar 16 19:47:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 16:47:41 -0700 Subject: highlight words by regex in pdf files using python References: Message-ID: In article , Peng Yu wrote: > >I don't find a general pdf library in python that can do any >operations on pdfs. > >I want to automatically highlight certain words (using regex) in a >pdf. Could somebody let me know if there is a tool to do so in python? Did you Google at all? "python pdf" finds this as the first link, though I have no clue whether it does what you want: http://pybrary.net/pyPdf/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From spamfresser at ch3ka.de Tue Mar 16 19:48:02 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 17 Mar 2010 00:48:02 +0100 Subject: import antigravity In-Reply-To: References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: Am 16.03.2010 21:44, schrieb Mark Lawrence: > Who actually *IS* running the time machine? Are there any bugs?? My is. And as I'm a lazy hacker: sure. there are bugs. lets just call them features and move on. nothing to see here ;) From aahz at pythoncraft.com Tue Mar 16 19:51:23 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 16:51:23 -0700 Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: In article , Pete Emerson wrote: > >Excellent, this is what I finally discovered, although I was looking >for 'foo' in sys.modules.keys(), which apparently isn't necessary. Actually, `foo in sys.modules.keys()` is double-slow, because first the dict must be scanned to create a list, and then the list must be scanned linearly to test for foo. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Tue Mar 16 19:55:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 16:55:51 -0700 Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> <42062deb-785a-4955-9ce0-d9fb7a26455d@j27g2000yqn.googlegroups.com> Message-ID: In article <42062deb-785a-4955-9ce0-d9fb7a26455d at j27g2000yqn.googlegroups.com>, Vinay Sajip wrote: > >I'm reviewing the documentation at the moment, as it happens, and it >still seems hard to be able to put together a structure which is good >for everyone. A full treatment, it seems to me, would talk a little >about the detail of why things work as they do; but a lot of the time, >people are just interested in getting going with the package, and less >interested in the whys and wherefores. But for people trying to do more >than the basics, that deeper understanding is sometimes necessary. The >hard part is satisfying all audiences in one document! Simple answer: don't The main logging docs should be reference material, but the top of the docs should link to a tutorial (or the other way around, but I think the Python docs have generally preferred to make the primary doc reference). Trying to make one page serve all documentation purposes rarely works. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From gagsl-py2 at yahoo.com.ar Tue Mar 16 20:02:38 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 21:02:38 -0300 Subject: cycling through options References: Message-ID: En Tue, 16 Mar 2010 11:30:51 -0300, Dieter Faulbaum escribi?: > is there a better way for cycling through all options than this: > > > (options, args) = parser.parse_args() > for opt in options.__dict__.keys(): > print opt, ":", options.__dict__[opt] (I assume parser is an optparse.OptionParser instance) You may rewrite it as: for oname, ovalue in vars(options).iteritems(): print oname, ":", ovalue This assumes that the only instance attributes existing in 'options' are, uh, parsed options from the command line. I could not find such guarantee in the documentation. Another way would be to ask the parser about the options it knows of: for oname in (o.dest for o in parser.option_list if o.dest): print oname, ":", getattr(options, oname, None) -- Gabriel Genellina From skippy.hammond at gmail.com Tue Mar 16 20:08:10 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 17 Mar 2010 11:08:10 +1100 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> Message-ID: <4BA01D6A.60208@gmail.com> On 17/03/2010 1:26 AM, Barak, Ron wrote: > Thanks for the suggestion Pable. > However, I really need the $PYTHONPATH to include this additional > library, so all Python scripts could use it. > In Windows I have defined PYTHONPATH as > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the > Windows registry I have > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\/version/\PythonPath\ as > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk; > However, even with all the above, the SVMInspecor modules are not found. You need to create your own sub-key, with any name, under the PythonPath key and add your path there. The reason is that Python only looks for that root key when it can't sniff the location of the library itself based on the location of the executable - and in most cases it can. Python does however enumerate and use the sub-keys in all cases. HTH, Mark From dg.gmane at thesamovar.net Tue Mar 16 21:00:11 2010 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Wed, 17 Mar 2010 02:00:11 +0100 Subject: C++ code generation Message-ID: Hi all, I'm doing some C++ code generation using Python, and would be interested in any comments on the approach I'm taking. Basically, the problem involves doing some nested loops and executing relatively simple arithmetic code snippets, like: for i in xrange(len(X)): X[i] += 5 Actually they're considerably more complicated than this, but this gives the basic idea. One way to get C++ code from this would be to use Cython, but there are two problems with doing that. The first problem is that the arithmetic code snippets are user-specified. What I want to do is generate code, and then compile and run it using Scipy's weave package. The second problem is that I have various different data structures and the C++ code generated needs to be different for the different structures (e.g. sparse or dense matrices). So far what I've been doing is writing Python code that writes the C++ code, but in a very non-transparent way. I like the idea of specifying the C++ code using Python syntax, like in Cython. So the idea I came up with was basically to abuse generators and iterators so that when you write something like: for x in X: ... it actually outputs some C++ code that looks like: for(int i=0; i > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > not using os.system command. An example: PythoidC ( http://pythoidc.googlecode.com ), look at importTemplate.py -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.cg at 126.com Tue Mar 16 21:54:25 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 17 Mar 2010 09:54:25 +0800 (CST) Subject: C++ code generation Message-ID: <11c0630.1732.12769d42e98.Coremail.dr.cg@126.com> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) ----- Original Message ----- From: "Dan Goodman" To: Sent: Wednesday, March 17, 2010 9:00 AM Subject: C++ code generation > Hi all, > > I'm doing some C++ code generation using Python, and would be interested > in any comments on the approach I'm taking. > > Basically, the problem involves doing some nested loops and executing > relatively simple arithmetic code snippets, like: > > for i in xrange(len(X)): > X[i] += 5 > > Actually they're considerably more complicated than this, but this gives > the basic idea. One way to get C++ code from this would be to use > Cython, but there are two problems with doing that. The first problem is > that the arithmetic code snippets are user-specified. What I want to do > is generate code, and then compile and run it using Scipy's weave > package. The second problem is that I have various different data > structures and the C++ code generated needs to be different for the > different structures (e.g. sparse or dense matrices). > > So far what I've been doing is writing Python code that writes the C++ > code, but in a very non-transparent way. I like the idea of specifying > the C++ code using Python syntax, like in Cython. So the idea I came up > with was basically to abuse generators and iterators so that when you > write something like: > > for x in X: > ... > > it actually outputs some C++ code that looks like: > > for(int i=0; i double &x = X[i]; > ... > } > > The ... in the Python code is only executed once because when X is > iterated over it only returns one value. > > Here's the example I've written so far (complete code given below): > > # initialisation code > code = OutputCode() > evaluate = Evaluator(code) > X = Array(code, 'values') > # specification of the C++ loop > for x in X: > evaluate('x += 5; x *= 2') > # and show the output > print code.code > > It generates the following C++ code: > > for(int values_index=0; values_index double &values = values_array[values_index]; > values += 5; > values *= 2; > } > > OK, so that's an overview of the idea that I have of how to do it. Any > comments or suggestions on either the approach or the implementation? > > Below is the complete code I've written for the example above (linewraps > aren't perfect but there's only a couple of lines to correct). > > Thanks for any feedback, > > Dan > > import re, inspect > > # We just use this class to identify certain variables > class Symbol(str): pass > > # This class is basically just a mutable string > class OutputCode(object): > def __init__(self): > self.code = '' > def __iadd__(self, code): > self.code = self.code+code > return self > > # Iterating over instances of this class generates code > # for iterating over a C++ array, it yields a single > # Symbol object, the variable name of the value in the > # array > class Array(object): > def __init__(self, code, name, dtype='double'): > self.name = name > self.dtype = dtype > self.code = code > def __iter__(self): > def f(): > self.code += 'for(int {name}_index=0; > {name}_index<{name}_len; {name}_index++){{\n'.format(name=self.name) > self.code += '{dtype} &{name} = > {name}_array[{name}_index];\n'.format(dtype=self.dtype, name=self.name) > yield Symbol(self.name) > self.code += '}\n' > return f() > > # Instances of this class generate C++ code from Python syntax > # code snippets, replacing variable names that are a Symbol in the > # namespace with the value of that Symbol. > class Evaluator(object): > def __init__(self, code): > self.code = code > def __call__(self, code): > # The set of variables in the code snippet > vars = re.findall(r'\b(\w+)\b', code) > # Extract any names from the namespace of the calling frame > frame = inspect.stack()[1][0] > globals, locals = frame.f_globals, frame.f_locals > values = {} > for var in vars: > if var in locals: > values[var] = locals[var] > elif var in globals: > values[var] = globals[var] > # Replace any variables whose values are Symbols with their values > for var, value in values.iteritems(): > if isinstance(value, Symbol): > code = re.sub(r'\b{var}\b'.format(var=var), str(value), > code) > # Turn Python snippets into C++ (just a simplified version for now) > code = code.replace(';', '\n') > lines = [line.strip() for line in code.split('\n')] > code = ''.join(line+';\n' for line in lines) > self.code += code > > if __name__=='__main__': > code = OutputCode() > evaluate = Evaluator(code) > X = Array(code, 'values') > for x in X: > evaluate('x += 5; x *= 2') > print code.code > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Mar 16 22:07:42 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 23:07:42 -0300 Subject: How to handle file uploads with http.server References: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> <4728DC0EADB2654E8BA2A487F0CF2785AD6D2E@ws-ukexchange.internal.biowisdom.com> Message-ID: En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue escribi?: > I have a basic http.server instance running (class > HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I > would like to upload files with multipart forms. > > def do_POST(self): > ctype, pdict = cgi.parse_header(self.headers['Content-Type']) > if ctype=='multipart/form-data': > print('parsing...') > query=cgi.parse_multipart(self.rfile, pdict) > print(query) > > However the file never seems to finish being parsed. There are no errors, > but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict) This may be related to this bug: http://bugs.python.org/issue8077 reported last week by Mitchell L. Model in this thread: http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/ -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 22:21:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 23:21:14 -0300 Subject: Exiting gracefully from ThreadingTCPServer References: <1f31cddf-1104-4579-bd61-5fad3b2c4677@t17g2000prg.googlegroups.com> Message-ID: En Fri, 12 Mar 2010 12:15:16 -0300, Pete Emerson escribi?: > I'm trying to get threading going for the first time in python, and > I'm trying to modify code I found so that I can have the server close > the TCP connections and exit gracefully. Two problems: Which Python version? > 1) While the KeyboardInterrupt works, if I make more than 0 curls to > the server and then quit, I can't run it again right away and get > this: > socket.error: [Errno 48] Address already in use > > Not all of my connections are closing properly. How do I fix this? > > 2) curling localhost:8080/quit does show the "Quitting" output that I > expect, but doesn't quit the server until I manually control-c it. On Python 2.6, you should call the shutdown() method (from another thread!) instead of simply server_close() See this recipe [1] -- just look at the main() function (disregard all the previous details); it runs the server(s) in their own thread, the main thread just sits and waits for KeyboardInterrupt or SystemExit. [1] http://code.activestate.com/recipes/577025 -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 22:25:50 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 23:25:50 -0300 Subject: datetime string conversion error References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: En Tue, 16 Mar 2010 20:31:11 -0300, Josh English escribi?: > On Mar 16, 11:56 am, Jordan Apgar wrote: > >> here's what I'm doing: >> date = "2010-03-16 14:46:38.409137" >> olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") >> > > Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on > the other). > > When I have a script as simple as this: > > import datetime > > datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") > > > Running this script brings up a calendar, believe it or not. The > calendar displays March 2010, and shows the 22nd as a holiday. When I > dismiss the dialog box I get: > Traceback (most recent call last): > File "strptimetest.py", line 3, in > datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") > File "C:\Python25\lib\_strptime.py", line 272, in > _TimeRE_cache = TimeRE() > File "C:\Python25\lib\_strptime.py", line 191, in __init__ > self.locale_time = LocaleTime() > File "C:\Python25\lib\_strptime.py", line 74, in __init__ > self.__calc_weekday() > File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday > a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] > AttributeError: 'module' object has no attribute 'day_abbr' I'd say you have a calendar.py script somewhere along your sys.path, that shadows the calendar module in the standard library. -- Gabriel Genellina From googler.1.webmaster at spamgourmet.com Tue Mar 16 22:45:50 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 19:45:50 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: <6d496959-1397-427d-82d3-9c11ca956e54@33g2000yqj.googlegroups.com> At first thanks for your answers!!! On 16 Mrz., 21:16, Carl Banks wrote: > Here you raise an exception with a C statement, > and catch and print it in the very next line. ?The exception doesn't > exit from Python code so there are no lines to print. Exactly, I dont expect any line/file information. I am just looking forward for a solution how to solve that. I would like to avoid the use of the debugger in this case. My ideas: 1. I thought the return value might contain any information where it is from. 2. Otherwise it would be cool if there are any information available in which line, file the last called function/method exited. Bye, moerchendiser2k3 From hidura at gmail.com Tue Mar 16 23:08:17 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Wed, 17 Mar 2010 03:08:17 +0000 Subject: Web Hosting Python 3 Message-ID: <0016e64642280288940481f66d5e@google.com> Hello list, i am in a project what need hosting, who give hosting to python3? -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Wed Mar 17 00:12:16 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 16 Mar 2010 21:12:16 -0700 (PDT) Subject: highlight words by regex in pdf files using python References: Message-ID: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> On Mar 4, 6:57?pm, Peng Yu wrote: > I don't find a general pdf library in python that can do any > operations on pdfs. > > I want to automatically highlight certain words (using regex) in a > pdf. Could somebody let me know if there is a tool to do so in python? The problem with PDFs is that they can be quite complicated. There is the outer container structure, which isn't too bad (unless the document author applied encryption or fancy multi-object compression), but then inside the graphics elements, things could be stored as regular ASCII, or as fancy indexes into font-specific tables. Not rocket science, but the only industrial-strength solution for this is probably reportlab's pagecatcher. I have a library which works (primarily with the outer container) for reading and writing, called pdfrw. I also maintain a list of other PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries It may be that pdfminer (link on that page) will do what you want -- it is certainly trying to be complete as a PDF reader. But I've never personally used pdfminer. One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools will read in preexisting PDFs and write them out to a reportlab canvas. This works quite well on a few very simple ASCII PDFs, but the font handling needs a lot of work and probably won't work at all right now on unicode. (But if you wanted to improve it, I certainly would accept patches or give you commit rights!) That pdfrw example does graphics reasonably well. I was actually going down that path for getting better vector graphics into rst2pdf (both uniconvertor and svglib were broken for my purposes), but then I realized that the PDF spec allows you to include a page from another PDF quite easily (the spec calls it a form xObject), so you don't actually need to parse down into the graphics stream for that. So, right now, the best way to do vector graphics with rst2pdf is either to give it a preexisting PDF (which it passes off to pdfrw for conversion into a form xObject), or to give it a .svg file and invoke it with -e inkscape, and then it will use inkscape to convert the svg to a pdf and then go through the same path. HTH, Pat From levi.india at gmail.com Wed Mar 17 00:15:46 2010 From: levi.india at gmail.com (pothuri ramesh) Date: Tue, 16 Mar 2010 21:15:46 -0700 (PDT) Subject: Data entry Work available Message-ID: <09d51eec-68e7-4dac-a5bd-6bc3b0b656d6@l40g2000pro.googlegroups.com> Data entry works Available At No need to pay DEposite http://trading7000.blogspot.com/ Adposting Jobs Availble http://trading7000.blogspot.com/ No need to work Hard Earn Money From Home 7000 in Minutes http://trading7000.blogspot.com/ From lie.1296 at gmail.com Wed Mar 17 00:57:17 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Mar 2010 15:57:17 +1100 Subject: to pass self or not to pass self In-Reply-To: References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <4ba06148$1@dnews.tpgi.com.au> On 03/17/2010 05:59 AM, Jason Tackaberry wrote: > On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: >> Answer here: >> >> http://wiki.python.org/moin/FromFunctionToMethod > > I have a sense I used to know this once upon a time, but the question > came to my mind (possibly again) and I couldn't think of an answer: > > Why not create the bound methods at instantiation time, rather than > using the descriptor protocol which has the overhead of creating a new > bound method each time the method attribute is accessed? Because people wanted it like so. There was once, a time when python doesn't have the descriptor protocol (old-style classes) and many people feels that a high-level language like python should provide some additional hooks for customizing attribute access which the existing solutions like __getattr__ and __setattr__ couldn't easily provide. The result is new-style class. Most people probably would never need to use descriptor protocol directly, since the immediate benefit of descriptor protocol are property(), classmethod(), and instancemethod() decorators which, without descriptor protocol, would never become a possibility. From sbassi at clubdelarazon.org Wed Mar 17 01:22:49 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Wed, 17 Mar 2010 02:22:49 -0300 Subject: Converting Python CGI to WSGI scripts In-Reply-To: <1268759895.28810.1365130739@webmail.messagingengine.com> References: <1268759895.28810.1365130739@webmail.messagingengine.com> Message-ID: <9e2f512b1003162222v98772d0u8d3aea8ced1ee7bb@mail.gmail.com> On Tue, Mar 16, 2010 at 2:18 PM, wrote: > I have a few dozen simple Python CGI scripts. > Are there any advantages or disadvantages to rewriting these CGI scripts as > WSGI scripts? It depends of the script. WSGI should be faster since you don't start a Python instance for each call (as in CGI). -- Sebasti?n Bassi. Diplomado en Ciencia y Tecnolog?a. Curso de Python en un d?a: http://bit.ly/cursopython Python for Bioinformatics: http://tinyurl.com/biopython 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. From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 01:32:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 05:32:05 GMT Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4ba06148$1@dnews.tpgi.com.au> Message-ID: On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote: > Most people probably would never need to use > descriptor protocol directly, since the immediate benefit of descriptor > protocol are property(), classmethod(), and instancemethod() decorators > which, without descriptor protocol, would never become a possibility. There's an instancemethod decorator? Where? Are you thinking of staticmethod? "instancemethod", if you mean what I think you mean, doesn't need a decorator because it is the default behaviour for new-style classes. -- Steven From pmaupin at gmail.com Wed Mar 17 01:35:03 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 16 Mar 2010 22:35:03 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> On Mar 16, 1:59?pm, Jason Tackaberry wrote: > Why not create the bound methods at instantiation time, rather than > using the descriptor protocol which has the overhead of creating a new > bound method each time the method attribute is accessed? Well, for one thing, Python classes are open. They can be added to at any time. For another thing, you might not ever use most of the methods of an instance, so it would be a huge waste to create those. Also, this area has been optimized for normal usage patterns quite heavily, to the point where attempted "optimizations" can lead to results that are, on the surface, quite counterintuitive. For example, if you want to take the length of a lot of different strings, you might think you could save time by binding a local variable to str.__len__ and using that on the strings. Here is an example: >>> def a(s, count, lenfunc): ... for i in xrange(count): ... z = lenfunc(s) ... >>> a('abcdef', 100000000, len) >>> a('abcdef', 100000000, str.__len__) Running cPython 2.6 on my machine, len() runs about 3 times faster than str.__len__(). The overhead of checking that an object is usable with a particular class method far outweighs the cost of creating the bound method! So, one thought for the OP. Whenever I have a dictionary that contains class methods in it, if I'm going to use it heavily, I often recode it to create the dictionary at object creation time with bound methods in it. Regards, Pat From joshua.r.english at gmail.com Wed Mar 17 02:13:47 2010 From: joshua.r.english at gmail.com (Josh English) Date: Tue, 16 Mar 2010 23:13:47 -0700 (PDT) Subject: Dynamic Class Creation References: Message-ID: <8d79f0cb-9c5b-4243-8891-a15fb311f652@z18g2000prh.googlegroups.com> Chris, Thanks. This worked for the attributes, but I think the tactic is still misleading. There are child elements I can't quite determine how to deal with: Analog Science Fiction and Fact Analog Science Fiction First Contact Hard Science Fiction
Stanley Schmidt, Editor 267 Broadway, 4th Floor New York, NY 10007-2352
http://www.analogsf.com
A child element with text and an attribute or two, for example, pose a problem. I can call Market.title but should I try Market.title.field or Market.title_field. Multiple elements, such as keywords, are allowed in xml but harder to map to the object. I don't know if I want to go create a list and methods for accessing those keywords as a list, or redefine the rules of my XML to not allow multiple child elements with the same tag. I can't decide. Then the address is a bit of a bear. In short, I have to figure out the whole object interface to the XML and how I want that to work. Thanks for the suggestion. It is undeniably clever. Josh From tino at wildenhain.de Wed Mar 17 02:30:36 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 17 Mar 2010 07:30:36 +0100 Subject: Function that knows its argument's variable name In-Reply-To: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <4BA0770C.2070306@wildenhain.de> Hi, Am 14.03.2010 12:58, schrieb Helge Stenstr?m: > I want to write function that prints a value of a variable, for > debugging. Like: > > with > > myVariable = "parrot" > otherVariable = "dead" > > probe(myVariable) > probe(otherVariable) > > instead of the longer > > print "myVariable = ", myVariable > print "otherVariable = ", otherVariable > > Is that even possible? > > The function would look like > > def probe(var): > nameOfVar = someMagic(var) > print nameOfVar, " = ", var > > but can someMagic(var) find the variable name? Is that possible? apart from very hackery, why don't you just use: def probe(**vars): for varname,value in vars.items(): print "%s = %r" % (varname,value) and call it like that: probe(myvar="foo") probe(othervar="bar") or even probe(myvar=myvar) (if myvar was assigned before) please note introspective approaches have a very narrow field where they can work - as already shown in other posts: you can have values w/o names and also more then one name to a value (or object). Regards Tino Wildenhain -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3254 bytes Desc: S/MIME Cryptographic Signature URL: From nagle at animats.com Wed Mar 17 02:34:21 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Mar 2010 23:34:21 -0700 Subject: Converting Python CGI to WSGI scripts In-Reply-To: References: <1268759895.28810.1365130739@webmail.messagingengine.com> Message-ID: <4ba0735b$0$1594$742ec2ed@news.sonic.net> Sebastian Bassi wrote: > On Tue, Mar 16, 2010 at 2:18 PM, wrote: >> I have a few dozen simple Python CGI scripts. >> Are there any advantages or disadvantages to rewriting these CGI scripts as >> WSGI scripts? > > It depends of the script. WSGI should be faster since you don't start > a Python instance for each call (as in CGI). It's almost always faster. But be careful about global state. Remember that WSGI/FCGI programs are really functions, called over and over with a new transaction on each call. So your function has to be reusable. Things like initializing global variables at program load time, rather than when the main function is called, may give trouble. Also, be careful about leaving files, database connections, and sockets open after the main function returns. John Nagle From kalakal46 at rediffmail.com Wed Mar 17 02:35:18 2010 From: kalakal46 at rediffmail.com (Hot Girls) Date: Tue, 16 Mar 2010 23:35:18 -0700 (PDT) Subject: %%% Funny College Girls Nude Video HERE %%% Message-ID: <77825db8-8873-4092-8db0-84a36f3fd818@w39g2000prd.googlegroups.com> %%% Funny College Girls Nude Video HERE %%% http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ $$$$ Enjoy actress SEX HERE $$$$ http://sites.google.com/site/hifiprofile/ From stefan_ml at behnel.de Wed Mar 17 02:46:20 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 07:46:20 +0100 Subject: C-API PyObject_Call In-Reply-To: References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: moerchendiser2k3, 16.03.2010 19:25: > Hi, currently I am not at home, I will post some stuff when I am back. > Just the note: I throw an exception with the C API. > > Looks like that > > > PyObject *result = PyObject_Call(my_isntance, "", NULL); > if(result==NULL) > { > PyErr_Print(); //when this happens, the traceback is correct with > information about the file/line > return; > } > > if(!PyXYZ_Check(result)) > { > PyErr_SetString(PyExc_TypeError, "Wrong type, ...."); > PyErr_Print(); //missing information of the file/line. > return; > } > > Well, I expect, that there are no information about the line/file, so > I know something is missing, but what is missing? Two solutions here: 1) put the line number information into the message string when you raise the exception 2) use Cython instead of plain C, as Cython will automatically generate readable stack traces for you, also for non-Python functions. Stefan From stefan_ml at behnel.de Wed Mar 17 02:48:31 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 07:48:31 +0100 Subject: import antigravity In-Reply-To: References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: Michael Rudolf, 17.03.2010 00:48: > Am 16.03.2010 21:44, schrieb Mark Lawrence: >> Who actually *IS* running the time machine? Are there any bugs?? > > My is. And as I'm a lazy hacker: sure. there are bugs. lets just call > them features and move on. nothing to see here ;) I'll know it, I'll just know it! Stefan From stefan_ml at behnel.de Wed Mar 17 02:54:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 07:54:04 +0100 Subject: C++ code generation In-Reply-To: <11c0630.1732.12769d42e98.Coremail.dr.cg@126.com> References: <11c0630.1732.12769d42e98.Coremail.dr.cg@126.com> Message-ID: CHEN Guang, 17.03.2010 02:54: > ----- Original Message ----- > From: "Dan Goodman" > >> I'm doing some C++ code generation using Python, and would be interested >> in any comments on the approach I'm taking. > > PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) It would be nice if you could start reading the posts before you answer, and then try to give an answer that fits the question. Stefan From sam at sambull.co.uk Wed Mar 17 04:43:38 2010 From: sam at sambull.co.uk (Sam Bull) Date: Wed, 17 Mar 2010 08:43:38 +0000 Subject: Timer Message-ID: <1268815418.2682.31.camel@s-desktop> I'm writing a pyGTK program, and I need to display the contents of a window for a few seconds before automatically moving on. I have tried using the time.sleep method, but this has problems, such as the program becoming unresponsive. I have now attempted to use a timer, but this does not seem to run the function at the end of the time. The code of my latest attempt: def next(self=None, testnum=10, testspeed=5): self.count += 1 #Sets label, telling the user the next word to memorise self.nobtns.set_markup("Word %s is: %s" % (self.count, self.words[self.count-1])) self.nobtns.show() if self.count == testnum: #When all words are shown self.nobtns.hide() else: self.timer = threading.Timer(testspeed, self.next, [testnum, testspeed]) self.timer.start() Putting a print statement at the beginning of the function, I can see that the function is not being run by the timer. Any help on getting this working would be appreciated. Thanks, Sam Bull -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From anand.shashwat at gmail.com Wed Mar 17 04:46:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 17 Mar 2010 14:16:00 +0530 Subject: using DictionaryServices module to get work with python2.6 #OSXspecific Message-ID: I wanted to use dictionary in my OSX terminal. So I wrote a function dict() in my ~/.bash_profile dict () { python2.5 -c 'import sys, DictionaryServices; word = " ".join(sys.argv[1:]); print DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word)))' $@ } here is the output: Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ dict lone wolf noun a person who prefers to act or be alone. The question is why not : DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) works with python2.6 ? Is DictionaryService module not available for python2.6 ? Here is the stack-trace: Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import DictionaryServices >>> word = "lone wolf" >>> DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) Traceback (most recent call last): File "", line 1, in IndexError: NSRangeException - *** -[OC_PythonString _createSubstringWithRange:]: Range or index out of bounds >>> Ofcourse it doesnt work with python2.7 too. Is this OSX specific issue ? Can I make it work with my compiled version of python ? Is there any workaround ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From grflanagan at gmail.com Wed Mar 17 04:54:14 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Wed, 17 Mar 2010 08:54:14 +0000 Subject: Dynamic Class Creation In-Reply-To: <8d79f0cb-9c5b-4243-8891-a15fb311f652@z18g2000prh.googlegroups.com> References: <8d79f0cb-9c5b-4243-8891-a15fb311f652@z18g2000prh.googlegroups.com> Message-ID: Josh English wrote: > Chris, > > Thanks. This worked for the attributes, but I think the tactic is > still misleading. There are child elements I can't quite determine how > to deal with: > > > Analog Science Fiction and Fact > Analog > Science Fiction > First Contact > Hard Science Fiction >
> Stanley Schmidt, Editor > 267 Broadway, 4th Floor > New York, NY 10007-2352 >
> http://www.analogsf.com >
> > A child element with text and an attribute or two, for example, pose a > problem. I can call Market.title but should I try Market.title.field > or Market.title_field. > > Multiple elements, such as keywords, are allowed in xml but harder to > map to the object. I don't know if I want to go create a list and > methods for accessing those keywords as a list, or redefine the rules > of my XML to not allow multiple child elements with the same tag. I > can't decide. > > Then the address is a bit of a bear. > > In short, I have to figure out the whole object interface to the XML > and how I want that to work. > Have you heard of or considered PyXB (http://pyxb.sourceforge.net/)? Not that I've much experience with it, but you can use it to generate python code from XML Schema files, and, I think, WSDL definitions. It's a bit of a rabbit hole, but then isn't that half the fun! The following might give you the idea. You start with a Schema schema.xsd, generate a python module from it, then read in some XML with the generated classes to get your custom objects. ---------------- schema.xsd ---------------------- ---------------- genbindings.sh --------------------------- #!/bin/sh pyxbgen -u schema.xsd -m market_binding -r ---------------- demo.py ----------------------------------- s = """ Analog Science Fiction and Fact Analog Science Fiction First Contact Hard Science Fiction
Stanley Schmidt, Editor 267 Broadway, 4th Floor New York
http://www.analogsf.com
""" import xml.dom.minidom import market_binding market = market_binding.CreateFromDOM(xml.dom.minidom.parseString(s).documentElement) print market.tier print market.code print market.keyword assert len(market.keyword) == 3 print market.address.name print market.toxml() From breamoreboy at yahoo.co.uk Wed Mar 17 04:56:48 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 17 Mar 2010 08:56:48 +0000 Subject: using DictionaryServices module to get work with python2.6 #OSXspecific In-Reply-To: References: Message-ID: Shashwat Anand wrote: > I wanted to use dictionary in my OSX terminal. > So I wrote a function dict() in my ~/.bash_profile > > dict () { > python2.5 -c 'import sys, DictionaryServices; word = " > ".join(sys.argv[1:]); print DictionaryServices.DCSCopyTextDefinition(None, > word, (0, len(word)))' $@ > } > > here is the output: > > Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ dict lone wolf > noun > a person who prefers to act or be alone. > > The question is why not : > DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) works > with python2.6 ? > Is DictionaryService module not available for python2.6 ? > > Here is the stack-trace: > > Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python > Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import DictionaryServices >>>> word = "lone wolf" >>>> DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) > Traceback (most recent call last): > File "", line 1, in > IndexError: NSRangeException - *** -[OC_PythonString > _createSubstringWithRange:]: Range or index out of bounds > > Ofcourse it doesnt work with python2.7 too. Is this OSX specific issue ? Can > I make it work with my compiled version of python ? Is there any workaround > ? > > Are you thinking of this? http://pypi.python.org/pypi/pyobjc-framework-DictionaryServices/2.2 HTH. Mark Lawrence From Ron.Barak at lsi.com Wed Mar 17 04:58:47 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 17 Mar 2010 08:58:47 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <4B9FB09A.7030609@ieee.org> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> <4B9FB09A.7030609@ieee.org> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C8DF@enbmail01.lsi.com> > -----Original Message----- > From: Dave Angel [mailto:davea at ieee.org] > Sent: Tuesday, March 16, 2010 6:24 PM > To: Barak, Ron > Cc: Pablo Recio Quijano; python-list at python.org > Subject: Re: How to add a library path to pythonpath ? > > Barak, Ron wrote: > > > >> -----Original Message----- > >> From: Dave Angel [mailto:davea at ieee.org] > >> Sent: Tuesday, March 16, 2010 5:04 PM > >> To: Barak, Ron > >> Cc: Pablo Recio Quijano; python-list at python.org > >> Subject: RE: How to add a library path to pythonpath ? > >> > >> > >> > >> Barak, Ron wrote: > >> > >>> Thanks for the suggestion Pable. > >>> > >>> However, I really need the $PYTHONPATH to include this > >>> > >> additional library, so all Python scripts could use it. > >> > >>> In Windows I have defined PYTHONPATH as > >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and > also in the > >>> Windows registry I have > >>> > >>> > >>> > >> > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as > >> > >> > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMI > >> n > >> > >>> spector\lib\;C:\Python26\Lib\lib-tk; > >>> > >>> However, even with all the above, the SVMInspecor modules > >>> > >> are not found. > >> > >>> > >> See my response at the end. Top-posting makes for a very > confusing > >> thread. > >> > >>> > >>> > >>> 2010/3/16 Barak, Ron > > >>> > >>> Hi, > >>> > >>> I'm trying to add a library path to my pythonpath, but > >>> > >> seems it is not > >> > >>> accepted - > >>> > >>> On Windows DOS window: > >>> > >>> C:\>echo %PYTHONPATH% > >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > >>> > >>> C:\>python -c "import sys ; print sys.path" > >>> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > >>> 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', > >>> 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', > >>> 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ > >>> site-packages', > >>> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > >>> > >>> C:\> > >>> > >>> On Windows cygwin: > >>> > >>> $ echo $PYTHONPATH > >>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > >>> > >>> $ python -c "import sys ; print sys.path" > >>> ['', > >>> > >>> > >> > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > >> > >>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > >>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > >>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > >>> 'c:\\Python26\\lib\\site-packages', > >>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > >>> > >>> $ > >>> > >>> What am I doing wrong ? > >>> > >>> Thanks, > >>> Ron. > >>> > >>> > >>> > >>> > >> In your original message, what you displayed worked exactly as > >> expected. As you didn't say what made you think something > was wrong, > >> I ignored the message. > >> > >> Now, you say that some modules are not found. So how about giving > >> some more specifics so someone can actually debug the > problem. Pick > >> a particular module, tell us the complete path to that module, and > >> show us both the sys.path strings (which look correct for > the Windows > >> case, and of course bogus for the cygwin case), as well as the > >> offending import statement and its traceback. > >> > >> DaveA > >> > > > > Hi Dave, > > > > My Python is the Windows Python (I need this for wxPython): > > > > $ ls -ls `which python` > > 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 > /usr/bin/python -> > > /cygdrive/c/Python26/python.exe > > > > Here's a demo script: > > > > #!/usr/bin/env python > > > > import sys > > print "\n",sys.path,"\n" > > > > from ErrorManager.ErrorManager import ErrorManager > > > > And it's run produces: > > > > $ python -u tmp.py > > > > ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', > > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > > 'c:\\Python26\\lib\\site-packages', > > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > > > Traceback (most recent call last): > > File "tmp.py", line 6, in > > from ErrorManager.ErrorManager import ErrorManager > > ImportError: No module named ErrorManager.ErrorManager > > > > $ ls -ls > > > /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager > > /ErrorManager.py > > 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 > > > /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager > > /ErrorManager.py > > > > $ grep ErrorManager > > /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > ErrorManager/ErrorManager.py > > class ErrorManager: > > > > $ echo $PYTHONPATH > > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > > > Please let me know if the above is enough, or you'd like to > see the results from a Windows' DOS window. > > > > Thanks, > > Ron. > > > > > Well, I pointed out that your cygwin path is bogus, so of > course it won't work. One of those entries is > > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib' > > I use Linux, and I use Windows. But cygwin's glomming > together has never made sense; some things are Unix-like, > and others are Windows-like. So anything you do in that > environment is beyond me. > > If I had to guess, though I'd say you wanted to drop those > first two characters from your PYTHONPATH. If you really > wanted two directories there, you should be separating them > with semicolon (Windows rules), rather than colon (Linux > rules). First thing I'd do to test my theories is to print > something like: > print sys.path[1] > print os.listdir(sys.path[1]) > Does Python even see the cygwin view of the world ? > > You also don't show the location of the module you're trying > to import. > I'm guessing that it's at > ...SVMInspector/lib/ErrorManager/ErrorManager.py > Do you have a file > ...SVMInspector/lib/ErrorManager/__init__.py ? > > I would seriously recommend against naming your package, your > module, and your class all the same thing. Makes debugging > very hard. At least make them have different case combinations. > > DaveA > > Hi Dave, With the suggestions you made above, I managed to solve the problems I reported, and now my paths work as expected. Thanks a lot, Ron. $ cat tmp.py #!/usr/bin/env python import sys import os print "sys.path:",sys.path print "sys.path[1]:",sys.path[1] print "os.listdir(sys.path[1]):",os.listdir(sys.path[1]) from ErrorManager.ErrorManager import ErrorManager $ python -u tmp.py sys.path: ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] sys.path[1]: c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib os.listdir(sys.path[1]): ['ConnectivityManager', 'ErrorManager', 'Utility'] $ echo $PYTHONPATH c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ $ echo $PYTHON_PATH c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikelisanke at gmail.com Wed Mar 17 05:08:18 2010 From: mikelisanke at gmail.com (MikeLisanke@gmail.com) Date: Wed, 17 Mar 2010 02:08:18 -0700 (PDT) Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> On Mar 16, 3:12?pm, "Gabriel Genellina" wrote: > En Tue, 16 Mar 2010 13:20:40 -0300, Johny escribi?: > > > Is there any tutorial how to write a bindings for a exe ( dos) > > program? > > I would like to run it from a Python directly > > ( using import command and a particular function from the binding) > > ?not using os.system command. > > Do you mean that you want to execute a particular function in the .exe ? > program? > That's not possible (ok, you *could* do that if you work hard enough, but ? > that's not how things are usually done) > > -- > Gabriel Genellina Gabriel, Its interesting you've mentioned the hard work involved in this interface (binding to an EXE instead of a DLL). A year or more ago I was looking at interfacing IPMITOOL to python. Do to the problems incurred with swig/python I switched to a running the process through its command-line interface. I always felt the problems in interfacing python to an EXE should be worked on (to minimize them), making the direct use of an EXE API's a routine task. I understand some of the problems using an EXE (not running all of its startup code but enough for its proper operation). Have you found this a recurring question? Thanks. Regards, Mike From Neil.Blue at biowisdom.com Wed Mar 17 05:12:33 2010 From: Neil.Blue at biowisdom.com (Neil Blue) Date: Wed, 17 Mar 2010 09:12:33 -0000 Subject: How to handle file uploads with http.server In-Reply-To: References: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com><4728DC0EADB2654E8BA2A487F0CF2785AD6D2E@ws-ukexchange.internal.biowisdom.com> Message-ID: <4728DC0EADB2654E8BA2A487F0CF2785AD6D3E@ws-ukexchange.internal.biowisdom.com> Thanks Gabriel Yep, that looks like the same one. Cheers Neil -----Original Message----- From: Gabriel Genellina [mailto:gagsl-py2 at yahoo.com.ar] Sent: 17 March 2010 02:08 To: python-list at python.org Subject: Re: How to handle file uploads with http.server En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue escribi?: > I have a basic http.server instance running (class > HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and > I would like to upload files with multipart forms. > > def do_POST(self): > ctype, pdict = cgi.parse_header(self.headers['Content-Type']) > if ctype=='multipart/form-data': > print('parsing...') > query=cgi.parse_multipart(self.rfile, pdict) > print(query) > > However the file never seems to finish being parsed. There are no > errors, but the call hangs at: query=cgi.parse_multipart(self.rfile, > pdict) This may be related to this bug: http://bugs.python.org/issue8077 reported last week by Mitchell L. Model in this thread: http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/ -- Gabriel Genellina ********************************************* The information contained in this message is likely to be confidential. It is intended only for the person named above. Any dissemination, distribution, copying, disclosure or use of this message or its contents unless authorised by BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of BioWisdom Ltd. If you have received this message in error, please immediately notify us and delete it. Thank you. Registered Office: BioWisdom Ltd, Harston Mill, Harston, Cambridge, CB22 7GG. Registered in England: (GB) 3861669. VAT registered: (GB) 750899881. Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, Internet:www.biowisdom.com ********************************************* From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 05:12:54 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 10:12:54 +0100 Subject: to pass self or not to pass self In-Reply-To: <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: <4ba09d09$0$21466$426a74cc@news.free.fr> Patrick Maupin a ?crit : > On Mar 16, 1:59 pm, Jason Tackaberry wrote: >> Why not create the bound methods at instantiation time, rather than >> using the descriptor protocol which has the overhead of creating a new >> bound method each time the method attribute is accessed? > > Well, for one thing, Python classes are open. They can be added to at > any time. For another thing, you might not ever use most of the > methods of an instance, so it would be a huge waste to create those. A possible optimization would be a simple memoization on first access. From __peter__ at web.de Wed Mar 17 05:16:17 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 10:16:17 +0100 Subject: Timer References: Message-ID: Sam Bull wrote: > I'm writing a pyGTK program, and I need to display the contents of a > window for a few seconds before automatically moving on. I have tried > using the time.sleep method, but this has problems, such as the program > becoming unresponsive. > > I have now attempted to use a timer, but this does not seem to run the > function at the end of the time. The code of my latest attempt: > > def next(self=None, testnum=10, testspeed=5): > self.count += 1 > #Sets label, telling the user the next word to memorise > self.nobtns.set_markup("Word %s is: %s" % (self.count, > self.words[self.count-1])) > self.nobtns.show() > if self.count == testnum: #When all words are shown > self.nobtns.hide() > else: > self.timer = threading.Timer(testspeed, self.next, [testnum, > testspeed]) > self.timer.start() > > Putting a print statement at the beginning of the function, I can see > that the function is not being run by the timer. Any help on getting > this working would be appreciated. GUI toolkits usually have their own way of handling timeouts. I don't know pygtk, but the following looks promising: http://www.pygtk.org/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html Peter From anand.shashwat at gmail.com Wed Mar 17 05:18:06 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 17 Mar 2010 14:48:06 +0530 Subject: using DictionaryServices module to get work with python2.6 #OSXspecific In-Reply-To: References: Message-ID: > Are you thinking of this? > http://pypi.python.org/pypi/pyobjc-framework-DictionaryServices/2.2 > I get the same IndexError while working with this wrapper. My guess is python2.6 does not support DictionaryServices on Snow Leopard . -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Mar 17 05:36:29 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 10:36:29 +0100 Subject: Python bindings tutorial In-Reply-To: <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: MikeLisanke at gmail.com, 17.03.2010 10:08: > Its interesting you've mentioned the hard work involved in this > interface (binding to an EXE instead of a DLL). A year or more ago I > was looking at interfacing IPMITOOL to python. Do to the problems > incurred with swig/python I switched to a running the process through > its command-line interface. I always felt the problems in interfacing > python to an EXE should be worked on (to minimize them), making the > direct use of an EXE API's a routine task. I understand some of the > problems using an EXE (not running all of its startup code but > enough for its proper operation). Have you found this a recurring > question? Thanks. I think the point here is that executable binaries are not supposed to be used as libraries. Libraries are. That's the difference between a DLL and an executable in the first place. To run an executable, execute it. The subprocess module is the tool of choice here. To use a DLL, link against it. Stefan From dr.cg at 126.com Wed Mar 17 05:41:55 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 17 Mar 2010 17:41:55 +0800 (CST) Subject: C++ code generation Message-ID: <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> >> ----- Original Message ----- >> From: "Dan Goodman" >> >>> I'm doing some C++ code generation using Python, and would be interested >>> in any comments on the approach I'm taking. >> >> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) > > It would be nice if you could start reading the posts before you answer, > and then try to give an answer that fits the question. > > Stefan I have read the post, may be I lost some words and made you misunderstand. I meant: PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not C++), if you find it useful, welcome to take a look. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Wed Mar 17 06:25:58 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 17 Mar 2010 10:25:58 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <4BA01D6A.60208@gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4BA01D6A.60208@gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C8FE@enbmail01.lsi.com> > -----Original Message----- > From: Mark Hammond [mailto:skippy.hammond at gmail.com] > Sent: Wednesday, March 17, 2010 2:08 AM > To: Barak, Ron > Cc: Pablo Recio Quijano; python-list at python.org > Subject: Re: How to add a library path to pythonpath ? > > On 17/03/2010 1:26 AM, Barak, Ron wrote: > > Thanks for the suggestion Pable. > > However, I really need the $PYTHONPATH to include this additional > > library, so all Python scripts could use it. > > In Windows I have defined PYTHONPATH as > > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the > > Windows registry I have > > > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\/version/\Python > Path\ as > > > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn > > spector\lib\;C:\Python26\Lib\lib-tk; > > However, even with all the above, the SVMInspecor modules > are not found. > > You need to create your own sub-key, with any name, under the > PythonPath key and add your path there. The reason is that > Python only looks for that root key when it can't sniff the > location of the library itself based on the location of the > executable - and in most cases it can. > Python does however enumerate and use the sub-keys in all cases. > > HTH, > > Mark > Hi Mark, Could you give an example ilustrating your suggestion ? Thanks, Ron. From lie.1296 at gmail.com Wed Mar 17 06:41:50 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Mar 2010 21:41:50 +1100 Subject: to pass self or not to pass self In-Reply-To: References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4ba06148$1@dnews.tpgi.com.au> Message-ID: <4ba0b20e$1@dnews.tpgi.com.au> On 03/17/2010 04:32 PM, Steven D'Aprano wrote: > On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote: > >> Most people probably would never need to use >> descriptor protocol directly, since the immediate benefit of descriptor >> protocol are property(), classmethod(), and instancemethod() decorators >> which, without descriptor protocol, would never become a possibility. > > > There's an instancemethod decorator? Where? > > Are you thinking of staticmethod? "instancemethod", if you mean what I > think you mean, doesn't need a decorator because it is the default > behaviour for new-style classes. Whoops... yep, sorry about that. Got all it up the mixed head in... From chambon.pascal at gmail.com Wed Mar 17 06:42:44 2010 From: chambon.pascal at gmail.com (Pakal) Date: Wed, 17 Mar 2010 03:42:44 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() Message-ID: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> Hello I've just realized recently that sys.exc_info() didn't return a full traceback for exception concerned : it actually only contains the frame below the point of exception catching. That's very annoying to me, because I planned to log such tracebacks with logging.critical(*****, exc_info=True), and these partial tracebacks, like the one below, are clearly unsufficient to determine where the problem comes from. A whole traceback, from program entry point to exception raising point, would be much better. 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to ensure critical emails are properly sent Traceback (most recent call last): << HERE, lots of frames missing >> File "test_common.py", line 34, in test_email_sending os.open("qsdsdqsdsdqsd", "r") TypeError: an integer is required Is there any workaround for this ? I've thought about a custom logging formatter, which would take both the exc_info traceback AND its own full backtrace, and to connect them together on their relevant part, but it's awkward and error prone... why can't we just have all the precious traceback info under the hand there (an additional attribute might have pointed the precise frame in which the exception was caught). Tanks for the attention, Regards, Pascal From davea at ieee.org Wed Mar 17 06:55:38 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Mar 2010 05:55:38 -0500 Subject: datetime string conversion error In-Reply-To: References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: <4BA0B52A.10708@ieee.org> Gabriel Genellina wrote: > En Tue, 16 Mar 2010 20:31:11 -0300, Josh English > escribi?: > >> On Mar 16, 11:56 am, Jordan Apgar wrote: >> >>> here's what I'm doing: >>> date = "2010-03-16 14:46:38.409137" >>> olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") >>> >> >> Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on >> the other). >> >> When I have a script as simple as this: >> >> import datetime >> >> datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") >> >> >> Running this script brings up a calendar, believe it or not. The >> calendar displays March 2010, and shows the 22nd as a holiday. When I >> dismiss the dialog box I get: >> Traceback (most recent call last): >> File "strptimetest.py", line 3, in >> datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") >> File "C:\Python25\lib\_strptime.py", line 272, in >> _TimeRE_cache = TimeRE() >> File "C:\Python25\lib\_strptime.py", line 191, in __init__ >> self.locale_time = LocaleTime() >> File "C:\Python25\lib\_strptime.py", line 74, in __init__ >> self.__calc_weekday() >> File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday >> a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] >> AttributeError: 'module' object has no attribute 'day_abbr' > > I'd say you have a calendar.py script somewhere along your sys.path, > that shadows the calendar module in the standard library. > And to find it, you could try the following: import datetime print calendar.__file__ I suspect you have more problems than just that file, but perhaps finding that one can tell you what extra package you've got installed that shadows parts of the standard library. Try temporarily renaming it to see if the problem goes away. DaveA From davea at ieee.org Wed Mar 17 07:14:13 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Mar 2010 06:14:13 -0500 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: <4BA0B985.3060501@ieee.org> Stefan Behnel wrote: >
MikeLisanke at gmail.com, 17.03.2010 10:08: >> Its interesting you've mentioned the hard work involved in this >> interface (binding to an EXE instead of a DLL). A year or more ago I >> was looking at interfacing IPMITOOL to python. Do to the problems >> incurred with swig/python I switched to a running the process through >> its command-line interface. I always felt the problems in interfacing >> python to an EXE should be worked on (to minimize them), making the >> direct use of an EXE API's a routine task. I understand some of the >> problems using an EXE (not running all of its startup code but >> enough for its proper operation). Have you found this a recurring >> question? Thanks. > > I think the point here is that executable binaries are not supposed to > be used as libraries. Libraries are. That's the difference between a > DLL and an executable in the first place. To run an executable, > execute it. The subprocess module is the tool of choice here. To use a > DLL, link against it. > > Stefan > There's no real reason parts of an exe cannot be exported, same as a dll. They are in fact the same structure. And in fact many other files in the Windows environment are also the same structure, from fonts to ocx's Saying they're "not supposed to be used" is like saying that a python module should not have an if __name__ == "__main__": section. After all, who could want to both run a file, and import the same file?? DaveA From hatem.oraby at gmail.com Wed Mar 17 07:26:33 2010 From: hatem.oraby at gmail.com (Hatem Oraby) Date: Wed, 17 Mar 2010 13:26:33 +0200 Subject: Swapping Content of Two Dictionaries. In-Reply-To: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> Message-ID: <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Hello, I want to swap the content of two dictionaries, the obvious way to do it is: a = {1:"I'am A"} b = {2:"I'm B"} temp = a a = b b = temp However, consider the case in which the dictionary we are referencing lives in another module: #external.py # #a = {1:"I'am A} import external temp = external.a external.a = b b = temp Well, still this would work great and anyone later that would refereence external.a would find the content of b, but consider the case where someone else imported "external.py" before my module run, for example: #external.py # #a = {1:"I'm A} #annoyer.py #from external import a # # #Do other stuff with a import external temp = external.a external.a = b b = temp Now in such case when I overwrite the content of external.a in my module, the change in dictionary is not reflected in annoyer module, that's because annoyer hold a reference to the original a but not the new one. annoyer module still see the old content of a. The workaround that i did to solve this problem is the following (I'm simplifying it right here): tempKeys = a.keys() diffKeys = a.keys() - b.keys() #I do it using set()s #item = a temp = {} for key in a.keys(): item[key] = a[key] for key in diffKeys: del a[key] #delete stuff that exist in a but not b. for key in b.keys(): a[key] = b[key] b = temp This works great as the content referenced by the dictionary is changed rather than changing the reference of dictionary itself so it's reflected by any "scope" that references the dictionary. My problem is that i need to do this operation a LOT, simply I got a problem that my program go through a very long loop and inside this loop this operation is needed to be done twice and the dictionary size ain't very small. If anyone has a suggestion one how to do it faster then please feel free and welcome to contribute. Anyway, I decided to go and implement it in C to gain performance, And since I got no expereince in writing C extension I'm not really sure if what I'm doing right or wrong, long story short here is what i decided to do: In real python (I mean not the C code) an object is mainly a reference to a C PyObject (or an inheritance of the PyObject). Python dictionaries are represented as PyDictObject (PyDictObject inherits PyObject), so every Python Dictionary is a reference to PyDictObject, So what i came up with to swap two Python dictionaries is to swap the content of PyDictObjects of the dictionaries, I know that "illegal" way of doing things in Python but I need the hack to gain performance. I opened up python source files: object.h (extracted the definition of PyObject) dictObject.g (extctracted the definition of PyDictObject) And I've written the following C extension: 1. #include 2. #include //I know that it was already imported 3. 4. static char swap_doc[] = 5. "My try to swap dicts, isa hopefully it will work good."; 6. 7. 8. static PyObject* 9. swap_swapDict(PyObject *self, PyObject *args) 10. { 11. PyObject *a, *b; 12. PyDictObject *x, *y; 13. //Temp PyDictObject attriubutes 14. Py_ssize_t ob_refcnt; 15. PyTypeObject *ob_type; 16. Py_ssize_t ma_fill; 17. Py_ssize_t ma_used; 18. Py_ssize_t ma_mask; 19. PyDictEntry *ma_table; 20. PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash); 21. PyDictEntry *ma_smalltable;//[PyDict_MINSIZE]; 22. 23. 24. if (!PyArg_UnpackTuple(args, "swapDict", 2, 2, &a, &b)) { 25. return NULL; 26. } 27. 28. //Make sure that they are dictionaries 29. if (!PyDict_Check(a) && !PyDict_Check(b)) { 30. PyErr_SetString(PyExc_TypeError, 31. "dictionary required, something else was passed"); 32. return NULL; 33. } 34. 35. x = (PyDictObject*)a; 36. y = (PyDictObject*)b; 37. 38. ob_refcnt = x->ob_refcnt; 39. x->ob_refcnt = y->ob_refcnt; 40. y->ob_refcnt = ob_refcnt; 41. 42. ob_type = x->ob_type; 43. x->ob_type = y->ob_type; 44. y->ob_type = ob_type; 45. 46. ma_fill = x->ma_fill; 47. x->ma_fill = y->ma_fill; 48. y->ma_fill = ma_fill; 49. 50. ma_used = x->ma_used; 51. x->ma_used = y->ma_used; 52. y->ma_used = ma_used; 53. 54. ma_mask = x->ma_mask; 55. x->ma_mask = y->ma_mask; 56. y->ma_mask = ma_mask; 57. 58. ma_table = x->ma_table; 59. x->ma_table = y->ma_table; 60. y->ma_table = ma_table; 61. 62. ma_lookup = x-> ma_lookup; 63. x->ma_lookup = y-> ma_lookup; 64. y->ma_lookup = ma_lookup; 65. 66. ma_smalltable = x->ma_smalltable; 67. *(x->ma_smalltable) = *(y->ma_smalltable); 68. *(y->ma_smalltable) = *(ma_smalltable); 69. 70. return Py_None; 71. } 72. 73. //This is extracted form dictObject.h and object.h 74. //typedef struct _dictobject PyDictObject; 75. //struct _dictobject { 76. // PyObject_HEAD 77. // Py_ssize_t ma_fill; /* # Active + # Dummy */ 78. // Py_ssize_t ma_used; /* # Active */ 79. // 80. // /* The table contains ma_mask + 1 slots, and that's a power of 2. 81. // * We store the mask instead of the size because the mask is more 82. // * frequently needed. 83. // */ 84. // Py_ssize_t ma_mask; 85. // 86. // /* ma_table points to ma_smalltable for small tables, else to 87. // * additional malloc'ed memory. ma_table is never NULL! This rule 88. // * saves repeated runtime null-tests in the workhorse getitem and 89. // * setitem calls. 90. // */ 91. // PyDictEntry *ma_table; 92. // PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash); 93. // PyDictEntry ma_smalltable[PyDict_MINSIZE]; 94. //}; 95. //PyObject_Head is a simple two statements equal to: 96. //Py_ssize_t ob_refcnt; 97. //struct _typeobject *ob_type; 98. 99. static char swap_swapDict_doc[] = 100. "Replaces two dicts with each other."; 101. 102. static PyMethodDef swap_methods[] = { 103. {"swapDict", swap_swapDict, METH_VARARGS, swap_swapDict_doc} , 104. {NULL, NULL} 105. }; 106. 107. PyMODINIT_FUNC 108. initswap(void) 109. { 110. Py_InitModule3("swap", swap_methods, swap_doc); 111. } What the code mainly do is that it swap the content of the PyDict objects. However I got a bug where one of them swaps correctly while the other points to a displaced memory location. -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.ricordeau at gmail.com Wed Mar 17 07:40:19 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 17 Mar 2010 12:40:19 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> Message-ID: <20100317124019.7013dfa3@moriz.interne> Hi, to log tracebacks, you can probably try traceback module. I use it like this : import traceback .... #?your code for line in traceback.format_exc().splitlines(): log.trace(line) Le Wed, 17 Mar 2010 03:42:44 -0700 (PDT), Pakal a ?crit : > Hello > > I've just realized recently that sys.exc_info() didn't return a full > traceback for exception concerned : it actually only contains the > frame below the point of exception catching. > > That's very annoying to me, because I planned to log such tracebacks > with logging.critical(*****, exc_info=True), and these partial > tracebacks, like the one below, are clearly unsufficient to determine > where the problem comes from. A whole traceback, from program entry > point to exception raising point, would be much better. > > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to > ensure critical emails are properly sent > Traceback (most recent call last): > << HERE, lots of frames missing >> > File "test_common.py", line 34, in test_email_sending > os.open("qsdsdqsdsdqsd", "r") > TypeError: an integer is required > > Is there any workaround for this ? I've thought about a custom logging > formatter, which would take both the exc_info traceback AND its own > full backtrace, and to connect them together on their relevant part, > but it's awkward and error prone... why can't we just have all the > precious traceback info under the hand there (an additional attribute > might have pointed the precise frame in which the exception was > caught). > > Tanks for the attention, > Regards, > Pascal From alfps at start.no Wed Mar 17 08:03:06 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 17 Mar 2010 13:03:06 +0100 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: * Dave Angel: > Stefan Behnel wrote: >>
MikeLisanke at gmail.com, 17.03.2010 10:08: >>> Its interesting you've mentioned the hard work involved in this >>> interface (binding to an EXE instead of a DLL). A year or more ago I >>> was looking at interfacing IPMITOOL to python. Do to the problems >>> incurred with swig/python I switched to a running the process through >>> its command-line interface. I always felt the problems in interfacing >>> python to an EXE should be worked on (to minimize them), making the >>> direct use of an EXE API's a routine task. I understand some of the >>> problems using an EXE (not running all of its startup code but >>> enough for its proper operation). Have you found this a recurring >>> question? Thanks. >> >> I think the point here is that executable binaries are not supposed to >> be used as libraries. Libraries are. That's the difference between a >> DLL and an executable in the first place. To run an executable, >> execute it. The subprocess module is the tool of choice here. To use a >> DLL, link against it. >> >> Stefan >> > There's no real reason parts of an exe cannot be exported, same as a > dll. They are in fact the same structure. And in fact many other files > in the Windows environment are also the same structure, from fonts to ocx's > > Saying they're "not supposed to be used" is like saying that a python > module should not have an > > if __name__ == "__main__": > > section. After all, who could want to both run a file, and import the > same file?? A Windows DLL has defined initialization and cleanup per process and per thread. This means that e.g. static variables can be properly initialized when you load the DLL in order to use its functions (I'm skipping discussion of subtle problems, but that's the essence). A Windows EXE has (only) a single entry point which is for process startup. It invokes the EXE's behavior-as-a-program. There is no way to use it to e.g. initialize static variables in order to use exported functions. Hence Mike Lisanke's idea of "not running all of its startup code but enough for its proper operation" is generally not possible. An EXE can be used as a kind of server, /if/ it is designed for that. In particular it can be a COM server, allowing access of its functionality from any COM-enabled binding, which for Python would mean OLE Automation (COM, OLE, Automation: this is Microsoft technology, we're talking Windows EXEs here). But a Python binding to EXEs in general can't, as far as I can see, make assumptions about any particular kind of server being implemented by the EXE. Cheers & hth., - Alf From stefan_ml at behnel.de Wed Mar 17 08:18:33 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 13:18:33 +0100 Subject: Python bindings tutorial In-Reply-To: <4BA0B985.3060501@ieee.org> References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> <4BA0B985.3060501@ieee.org> Message-ID: Dave Angel, 17.03.2010 12:14: > Stefan Behnel wrote: >> I think the point here is that executable binaries are not supposed to >> be used as libraries. Libraries are. That's the difference between a >> DLL and an executable in the first place. To run an executable, >> execute it. The subprocess module is the tool of choice here. To use a >> DLL, link against it. >> > There's no real reason parts of an exe cannot be exported, same as a > dll. They are in fact the same structure. And in fact many other files > in the Windows environment are also the same structure, from fonts to ocx's So, because you can, you'd also try to link against fonts then, I guess? I hope you notice that what you and me said isn't contradictory. But there's a reason why there are libraries and executables, and there's no reason you *should* export anything from an executable - that's what libraries are there for. That's my point. Besides, nothing guarantees that it's safe to call stuff that an executable exports. The executable may well require some setup code that it only executes when it is properly started. Stefan From rps at haystack.mit.edu Wed Mar 17 08:24:03 2010 From: rps at haystack.mit.edu (robert schaefer) Date: Wed, 17 Mar 2010 08:24:03 -0400 Subject: question about tkinter Message-ID: <54C3DEE7-50FE-46D8-B1EA-E2C54E11817F@haystack.mit.edu> Hello, This is my first posting to this list so please be gentle - I am new to python and am using it on red-hat linux (I am new to that too). I am responsible for installing open source packages (including python) onto a distributed system of linux boxes. My question is, on python version 2.6.2 tkinter refuses to install. Without tkinter, I cannot use Idle. I looked at the install/configure script and hacked it a bit, but every fix only caused new problems. There are serious issues with that script for finding necessary libraries. We have a Sun-OS box with python version 2.5.x (I don't know the means of installation) that tkinter installed correctly, and Idle works fine. My question is - has anyone else noticed the problem of tkinter and red-hat linux? Has this been corrected in python 2.6.4 (or 2.6.5)? thanks, bob s. ----------------------------------- robert schaefer Atmospheric Sciences Group MIT Haystack Observatory Westford, MA 01886 email: rps at haystack.mit.edu voice: 781-981-5767 www: http://www.haystack.mit.edu From __peter__ at web.de Wed Mar 17 08:34:51 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 13:34:51 +0100 Subject: Swapping Content of Two Dictionaries. References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Message-ID: Hatem Oraby wrote: > Hello, I want to swap the content of two dictionaries, the obvious way to > do it is: > a = {1:"I'am A"} > b = {2:"I'm B"} > temp = a > a = b > b = temp That can be simplified to a, b = b, a and is almost certainly the right approach. > tempKeys = a.keys() > diffKeys = a.keys() - b.keys() #I do it using set()s > > #item = a > temp = {} > for key in a.keys(): > item[key] = a[key] > > for key in diffKeys: > del a[key] #delete stuff that exist in a but not b. > > for key in b.keys(): > a[key] = b[key] > > b = temp > > This works great as the content referenced by the dictionary is changed > rather than changing the reference of dictionary itself so it's reflected > by any "scope" that references the dictionary. > > My problem is that i need to do this operation a LOT, simply I got a > problem that my program go through a very long loop and inside this loop > this operation is needed to be done twice and the dictionary size ain't > very small. You could try >>> a = {"a": 1, "b": 2} >>> b = {"b": 3, "c": 4} >>> t = a.copy() >>> a.clear() >>> a.update(b) >>> b.clear() >>> b.update(t) >>> a {'c': 4, 'b': 3} >>> b {'a': 1, 'b': 2} > If anyone has a suggestion one how to do it faster then please feel free > and welcome to contribute. > Anyway, I decided to go and implement it in C to gain performance, And Premature optimization? If you explain what you are trying to achieve someone might come up with a way to do it without swapping dict contents. Peter From chambon.pascal at gmail.com Wed Mar 17 08:42:06 2010 From: chambon.pascal at gmail.com (Pascal Chambon) Date: Wed, 17 Mar 2010 13:42:06 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: <20100317124019.7013dfa3@moriz.interne> References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> Message-ID: <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> Hello, traceback functions indeed allow the manipulation of exception tracebacks, but the root problem is that anyway, since that traceback is incomplete, your "traceback.format_exc().splitlines()" will only provide frames for callee (downward) functions, not caller (upward) ones, starting from the exception catching frame. Regards, Pascal 2010/3/17 Michael Ricordeau > Hi, > > to log tracebacks, you can probably try traceback module. > > I use it like this : > > import traceback > .... # your code > > for line in traceback.format_exc().splitlines(): > log.trace(line) > > > > Le Wed, 17 Mar 2010 03:42:44 -0700 (PDT), > Pakal a ?crit : > > > Hello > > > > I've just realized recently that sys.exc_info() didn't return a full > > traceback for exception concerned : it actually only contains the > > frame below the point of exception catching. > > > > That's very annoying to me, because I planned to log such tracebacks > > with logging.critical(*****, exc_info=True), and these partial > > tracebacks, like the one below, are clearly unsufficient to determine > > where the problem comes from. A whole traceback, from program entry > > point to exception raising point, would be much better. > > > > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to > > ensure critical emails are properly sent > > Traceback (most recent call last): > > << HERE, lots of frames missing >> > > File "test_common.py", line 34, in test_email_sending > > os.open("qsdsdqsdsdqsd", "r") > > TypeError: an integer is required > > > > Is there any workaround for this ? I've thought about a custom logging > > formatter, which would take both the exc_info traceback AND its own > > full backtrace, and to connect them together on their relevant part, > > but it's awkward and error prone... why can't we just have all the > > precious traceback info under the hand there (an additional attribute > > might have pointed the precise frame in which the exception was > > caught). > > > > Tanks for the attention, > > Regards, > > Pascal > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Mar 17 09:00:32 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 14:00:32 +0100 Subject: question about tkinter References: Message-ID: robert schaefer wrote: > This is my first posting to this list so please be gentle - > > I am new to python and am using it on red-hat linux (I am new to that > too). I am responsible for installing open source packages (including > python) onto a distributed system of linux boxes. > > My question is, on python version 2.6.2 tkinter refuses to install. Does it say "I'm sorry Bob, I'm afraid I can't do this"? > Without tkinter, I cannot use Idle. > > I looked at the install/configure script and hacked it a bit, but every > fix only caused new problems. > There are serious issues with that script for finding necessary > libraries. If there are serious problems you have to give some details. However, if in the past a newbie had problems with Tkinter support on linux the most frequent problem was that the Tcl/Tk development libraries weren't installed. I don't know how those are called on Red Hat, maybe something like tcl*-dev.rpm Did you install these before running the configure script? Peter From lie.1296 at gmail.com Wed Mar 17 09:16:53 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Mar 2010 00:16:53 +1100 Subject: to pass self or not to pass self In-Reply-To: <4ba09d09$0$21466$426a74cc@news.free.fr> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> Message-ID: <4ba0d65f$1@dnews.tpgi.com.au> On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote: > Patrick Maupin a ?crit : >> On Mar 16, 1:59 pm, Jason Tackaberry wrote: >>> Why not create the bound methods at instantiation time, rather than >>> using the descriptor protocol which has the overhead of creating a new >>> bound method each time the method attribute is accessed? >> >> Well, for one thing, Python classes are open. They can be added to at >> any time. For another thing, you might not ever use most of the >> methods of an instance, so it would be a huge waste to create those. > > A possible optimization would be a simple memoization on first access. But what if, for example, one uses some descriptor/metaclass magic to make it so that each subsequent access to the attribute returns a method bound to different objects? From h.stenstrom at gmail.com Wed Mar 17 09:20:42 2010 From: h.stenstrom at gmail.com (=?ISO-8859-1?Q?Helge_Stenstr=F6m?=) Date: Wed, 17 Mar 2010 06:20:42 -0700 (PDT) Subject: Function that knows its argument's variable name References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> <80ai5hFh3uU1@mid.individual.net> Message-ID: <02eb7ec7-1e22-43a4-8019-9a154c734669@y17g2000yqd.googlegroups.com> Thank you to all who answered. Inspection is apparently possible, but too complex for me. Greg's solution does what I want, inserting "" is no problem. /Helge > Not exactly, but you can come close with a little hackery. > > import sys > > def print_var(name): > ? ?print name, "=", sys._getframe(1).f_locals[name] > > def f(): > ? ?fred = 42 > ? ?mary = "christmas" > ? ?print_var("fred") > ? ?print_var("mary") > > f() > > -- > Greg From python at bdurham.com Wed Mar 17 09:22:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Mar 2010 09:22:37 -0400 Subject: Web Hosting Python 3 In-Reply-To: <0016e64642280288940481f66d5e@google.com> References: <0016e64642280288940481f66d5e@google.com> Message-ID: <1268832157.6206.1365286517@webmail.messagingengine.com> Hidura, > Hello list, i am in a project what need hosting, who give hosting to python3? Check out www.webfaction.com. I'm extremely pleased with this vendor. Highly recommended! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Wed Mar 17 09:24:43 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 17 Mar 2010 06:24:43 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> Message-ID: <95063943-4a45-42f5-81a2-761cf48daaa8@d27g2000yqf.googlegroups.com> On Mar 17, 10:42?am, Pakal wrote: > Hello > > I've just realized recently that sys.exc_info() didn't return a full > traceback for exception concerned : it actually only contains the > frame below the point of exception catching. > > That's very annoying to me, because I planned to log such tracebacks > withlogging.critical(*****, exc_info=True), and these partial > tracebacks, like the one below, are clearly unsufficient to determine > where the problem comes from. A whole traceback, from program entry > point to exception raising point, would be much better. > > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to > ensure critical emails are properly sent > Traceback (most recent call last): > << HERE, lots of frames missing >> > ? File "test_common.py", line 34, in test_email_sending > ? ? os.open("qsdsdqsdsdqsd", "r") > TypeError: an integer is required > > Is there any workaround for this ? I've thought about a customlogging > formatter, which would take both the exc_info traceback AND its own > full backtrace, and to connect them together on their relevant part, > but it's awkward and error prone... why can't we just have all the > precious traceback info under the hand there (an additional attribute > might have pointed the precise frame in which the exception was > caught). > > Tanks for the attention, > Regards, > Pascal Do you have a short script which demonstrates the problem? Some more context is needed. For example, if you have multiple threads of execution, the traceback will only go up to the top-level function in the thread. Regards, Vinay Sajip From a_jtim at bellsouth.net Wed Mar 17 09:30:24 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Wed, 17 Mar 2010 06:30:24 -0700 (PDT) Subject: multiprocessing on freebsd Message-ID: Hi, I'm checking to see if multiprocessing works on freebsd for any version of python. My server is about to get upgraded from 6.3 to 8.0 and I'd sure like to be able to use multiprocessing. I think the minimal test would be: --------------------- import multiprocessing q = multiprocessing.Queue() --------------------- with 6.3, I get File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line 212, in Queue from multiprocessing.queues import Queue File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, in from multiprocessing.synchronize import Lock, BoundedSemaphore, Semaphore, Condition File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 33, in " function, see issue 3770.") ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770. thanks for any info, --Tim Arnold From rps at haystack.mit.edu Wed Mar 17 09:32:46 2010 From: rps at haystack.mit.edu (robert schaefer) Date: Wed, 17 Mar 2010 09:32:46 -0400 Subject: question about tkinter In-Reply-To: References: Message-ID: <8C160E0A-D35A-4EA8-822B-8CB5BCD9C529@haystack.mit.edu> Peter, Most of my life has been dealing with recalcitrant HAL's in one guise or another. These days, I think HAL has permanently taken up residence in Toyota's engine and brakes. "Stop the car Dave? Have you changed my oil or even washed me lately?" Some serious "sneak paths" are going on. Anyway - tkinter is in two parts: 1. a python wrapper 2. c code Both are present in the 2.6.2 python download. It appears to be a "I can't find the library" path problem not a file existence problem. 1. gcc can't find the libraries that tkinter c code links to ( I could fix that) 2. the python installer can't find all the library paths to all the pieces - I started fixing this, then determined it would be easier to rewrite from scratch than patch. That is, the given method of building paths in the script are way off from reality, not just an add this one path and everything will now work kind of magic. I felt that the "official" python people would have an easier time of this - so gave up. bob On Mar 17, 2010, at 9:00 AM, Peter Otten wrote: > robert schaefer wrote: > >> This is my first posting to this list so please be gentle - >> >> I am new to python and am using it on red-hat linux (I am new to that >> too). I am responsible for installing open source packages (including >> python) onto a distributed system of linux boxes. >> >> My question is, on python version 2.6.2 tkinter refuses to install. > > Does it say "I'm sorry Bob, I'm afraid I can't do this"? > >> Without tkinter, I cannot use Idle. >> >> I looked at the install/configure script and hacked it a bit, but every >> fix only caused new problems. >> There are serious issues with that script for finding necessary >> libraries. > > If there are serious problems you have to give some details. > > However, if in the past a newbie had problems with Tkinter support on linux > the most frequent problem was that the Tcl/Tk development libraries weren't > installed. I don't know how those are called on Red Hat, maybe something > like > > tcl*-dev.rpm > > Did you install these before running the configure script? > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > > !DSPAM:4ba0d3cd3229021468! > ----------------------------------- robert schaefer Atmospheric Sciences Group MIT Haystack Observatory Westford, MA 01886 email: rps at haystack.mit.edu voice: 781-981-5767 www: http://www.haystack.mit.edu From hidura at gmail.com Wed Mar 17 09:39:21 2010 From: hidura at gmail.com (Hidura) Date: Wed, 17 Mar 2010 09:39:21 -0400 Subject: Web Hosting Python 3 In-Reply-To: <1268832157.6206.1365286517@webmail.messagingengine.com> References: <0016e64642280288940481f66d5e@google.com> <1268832157.6206.1365286517@webmail.messagingengine.com> Message-ID: <4bbf7fb21003170639j1fe53d3fr17524681085b36a0@mail.gmail.com> I've saw last night in the help area they support Python3.1, thanks anyway On Wed, Mar 17, 2010 at 9:22 AM, wrote: > Hidura, > > > Hello list, i am in a project what need hosting, who give hosting to > python3? > > Check out www.webfaction.com. I'm extremely pleased with this vendor. > > Highly recommended! > > Malcolm > -- Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashwiniyal at gmail.com Wed Mar 17 09:54:18 2010 From: ashwiniyal at gmail.com (ashwini yal) Date: Wed, 17 Mar 2010 19:24:18 +0530 Subject: Special characters (^M & ^[[D) when I read pxssh::before and write it to a file Message-ID: <771960b21003170654u1f6bac7bm1c0d7b30e2187f1f@mail.gmail.com> Hi, I am writing a python script which logs into the machine using pxssh, sends a command, reads the response and writes the response to the file. But, when I open the file in the editor like vi, its showing special characters like ^M and ^[[D instead of spaces or newlines. This is how my code looks like ... s = pxssh.pxssh() s.login(ip, username, password) cmd = 'xyz' s.sendline (cmd) s.prompt() output = s.before fileWrite = open(filePath , 'wb') fileWrite.write(output) s.prompt() This is how my filePath looks like when I open it using vi editor. Starting command execution on host xxx.xxx.xxx.xxx D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^M Command executed successfully ^M Executing next command ...^M -- Regards , Ashwini . K -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Mar 17 09:59:40 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 14:59:40 +0100 Subject: question about tkinter References: Message-ID: robert schaefer wrote: > tkinter is in two parts: > 1. a python wrapper > 2. c code > > Both are present in the 2.6.2 python download. > It appears to be a "I can't find the library" path problem not a file > existence problem. > > 1. gcc can't find the libraries that tkinter c code links to ( I could fix > that) 2. the python installer can't find all the library paths to all the > pieces - I started fixing this, then determined it would be easier to > rewrite from scratch than patch. That is, the given method of building > paths in the script are way off from reality, not just an add this one > path and everything will now work kind of magic. I felt that the > "official" python people would have an easier time of this - so gave up. Just to exclude the simple problems (unfortunately I can't help you with the hard ones): Are the tcl development packages installed on your system? Peter From stefan_ml at behnel.de Wed Mar 17 10:10:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 15:10:27 +0100 Subject: Swapping Content of Two Dictionaries. In-Reply-To: <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Message-ID: Hatem Oraby, 17.03.2010 12:26: > However, consider the case in which the dictionary we are referencing lives > in another module: > #external.py > # > #a = {1:"I'am A} > import external > > temp = external.a > external.a = b > b = temp Looks like the interface of your module is broken. It shouldn't export the two dicts. > My problem is that i need to do this operation a LOT, simply I got a problem > that my program go through a very long loop and inside this loop this > operation is needed to be done twice and the dictionary size ain't very > small. Please explain what you use the dicts for and how they are supposed to be used by your own code and by external code. That will allow us to give an advice on how to design your module better. Stefan From pruebauno at latinmail.com Wed Mar 17 10:29:31 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 17 Mar 2010 07:29:31 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> Message-ID: <40341e67-0609-4da7-b32e-afdf3ea5b6cc@d27g2000yqf.googlegroups.com> Michael Torrie wrote: > david jensen wrote: > > of course, changing nn's to: > > def getOutcomes(myList=[2,5,8,3,5]): > > low_id = int(myList[0]>myList[1]) > > amountToShare = 2*myList[low_id] > > remainder = myList[not low_id]-myList[low_id] > > tail=list(myList[2:]) > > outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ > > tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else > > [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc > > in (1.0, 0.75, 0.5, 0.25, 0.0)] > > return outcomes > > > > > > works, just hides the ugliness in a more compact form > > If Gerard's code works, I would consider it far superior to your code > here. Pythonic does not necessarily mean short and ugly, nor does it > mean that you have to always use list comprehensions. Having a > readable algorithm that's easy to follow in the future is a far better > way than trying to use python's cool features to compact the code to as > small and unreadable section as possible. > > I used to use list comprehension all the time, but I've found that often > an explicit for loop is a much better solution in terms of > maintainability. Especially when you start seeing nested comprehensions > such as you have here. To be fair, that list comprehension was unnecessary complicated. The following version does the same thing and still looks pretty reasonable IMHO: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) high_id = not low_id smaller = myList[low_id] bigger = myList[high_id] amountToShare = 2*smaller remainder = bigger-smaller remain0 = low_id*remainder remain1 = high_id*remainder tail = list(myList[2:]) percents = (1.0, 0.75, 0.5, 0.25, 0.0) outcomes = [[remain0+amountToShare*perc, remain1+amountToShare*(1- perc)] +tail for perc in percents] return outcomes From rps at haystack.mit.edu Wed Mar 17 10:33:41 2010 From: rps at haystack.mit.edu (robert schaefer) Date: Wed, 17 Mar 2010 10:33:41 -0400 Subject: question about tkinter In-Reply-To: References: Message-ID: No, And there's a reason (perhaps not a great one - but I'm got some constraints). I am not the system administrator and the tcl installer wants to be installed as root. I tried it. The rationale for not doing this is that the installation packages that I am administrator for, are all installed in non-root directories. by non-root people. If I have to install any package as root, then that becomes "different". The machines are all linux and intended to be swappable/exchangeable and installed by anyone without root access. This simplifies maintenance when a large number of boxes are involved. Are there any tcl/tk packages that permit re-direction of installation to non-root directories? This problem is just an ongoing irritation, python works fine without tkinter, I just can't get idle to work without it. Related to that I tailored Ipython to work with gtk (ipython's default was tkinter) - tailoring was by a command - is there any way to command idle to use gtk? On Mar 17, 2010, at 9:59 AM, Peter Otten wrote: > robert schaefer wrote: > >> tkinter is in two parts: >> 1. a python wrapper >> 2. c code >> >> Both are present in the 2.6.2 python download. >> It appears to be a "I can't find the library" path problem not a file >> existence problem. >> >> 1. gcc can't find the libraries that tkinter c code links to ( I could fix >> that) 2. the python installer can't find all the library paths to all the >> pieces - I started fixing this, then determined it would be easier to >> rewrite from scratch than patch. That is, the given method of building >> paths in the script are way off from reality, not just an add this one >> path and everything will now work kind of magic. I felt that the >> "official" python people would have an easier time of this - so gave up. > > Just to exclude the simple problems (unfortunately I can't help you with the > hard ones): Are the tcl development packages installed on your system? > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > > !DSPAM:4ba0e1dc51621869525538! > ----------------------------------- robert schaefer Atmospheric Sciences Group MIT Haystack Observatory Westford, MA 01886 email: rps at haystack.mit.edu voice: 781-981-5767 www: http://www.haystack.mit.edu From robin at reportlab.com Wed Mar 17 10:38:16 2010 From: robin at reportlab.com (Robin Becker) Date: Wed, 17 Mar 2010 14:38:16 +0000 Subject: bug in bdist_wininst cross compile? Message-ID: <4BA0E958.8050205@chamonix.reportlab.co.uk> has anyone had any success with cross compilation and bdist_wininst; I have modified build_ext very slightly to fix a small bug in cross compilation related to library order. That seems to fix setup.py build --plat-name=win-amd64 however, when I try to do a clean build of an exe ie rm -rf build setup.py bdist_wininst --plat-name=win-amd64 it appears as though build is invoked with the wrong plat-name ie I see this in the output > running bdist_wininst > running build > running build_py > creating build > creating build\lib.win32-2.6 > creating build\lib.win32-2.6\reportlab > copying src\reportlab\rl_config.py -> build\lib.win32-2.6\reportlab ...... > C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nolog followed by errors related to a missing library (the amd64 version won't work with a win32 build). If I build first with setup.py build --plat-name=win-amd64 and then use setup.py bdist_wininst --plat-name=win-amd64 --skip-build then I seem to get a proper amd64 exe. I think the problem can be fixed by modifying distutils/command/bdist_wininst.py using this patch > *** bdist_wininst.py.orig Wed Mar 17 14:00:15 2010 > --- bdist_wininst.py Wed Mar 17 14:29:55 2010 > *************** > *** 79,90 **** > > def finalize_options (self): > if self.bdist_dir is None: > ! if self.skip_build and self.plat_name: > ! # If build is skipped and plat_name is overridden, bdist will > ! # not see the correct 'plat_name' - so set that up manually. > bdist = self.distribution.get_command_obj('bdist') > bdist.plat_name = self.plat_name > ! # next the command will be initialized using that name > bdist_base = self.get_finalized_command('bdist').bdist_base > self.bdist_dir = os.path.join(bdist_base, 'wininst') > if not self.target_version: > --- 79,91 ---- > > def finalize_options (self): > if self.bdist_dir is None: > ! if self.plat_name: > ! #bdist doesn't propagate plat_name so we do it here > ! build = self.distribution.get_command_obj('build') > ! build.plat_name = self.plat_name > bdist = self.distribution.get_command_obj('bdist') > bdist.plat_name = self.plat_name > ! # next the command(s) will be initialized using that name > bdist_base = self.get_finalized_command('bdist').bdist_base > self.bdist_dir = os.path.join(bdist_base, 'wininst') > if not self.target_version: which forces bdist_wininst's version of the plat_name forward onto both build and bdist. -- Robin Becker From pmaupin at gmail.com Wed Mar 17 10:43:50 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 07:43:50 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> Message-ID: <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> On Mar 17, 4:12?am, Bruno Desthuilliers wrote: > Patrick Maupin a ?crit : > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > >> Why not create the bound methods at instantiation time, rather than > >> using the descriptor protocol which has the overhead of creating a new > >> bound method each time the method attribute is accessed? > > > Well, for one thing, Python classes are open. ?They can be added to at > > any time. ?For another thing, you might not ever use most of the > > methods of an instance, so it would be a huge waste to create those. > > A possible optimization would be a simple memoization on first access. I do agree that memoization on access is a good pattern, and I use it frequently. I don't know if I would want the interpreter automagically doing that for everything, though -- it would require some thought to figure out what the overhead cost is for the things that are only used once. Usually, I will have a slight naming difference for the things I want memoized, to get the memoization code to run. For example, if you add an underbar in front of everything you want memoized: class foo(object): def _bar(self): pass def __getattr__(self, aname): if aname.startswith('_'): raise AttributeError value = getattr(self, '_' + aname) self.aname = value return value obj = foo() So then the first time you look up obj.bar, it builds the bound method, and on subsequent accesses it just returns the previously bound method. Regards, Pat From benjamin.kaplan at case.edu Wed Mar 17 10:51:50 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 17 Mar 2010 10:51:50 -0400 Subject: Special characters (^M & ^[[D) when I read pxssh::before and write it to a file In-Reply-To: <771960b21003170654u1f6bac7bm1c0d7b30e2187f1f@mail.gmail.com> References: <771960b21003170654u1f6bac7bm1c0d7b30e2187f1f@mail.gmail.com> Message-ID: On Wed, Mar 17, 2010 at 9:54 AM, ashwini yal wrote: > Hi, > > I am writing a python script which logs into the machine using pxssh, sends > a command, reads the response and writes the response to the file. > > But, when I open the file in the editor like vi, its showing special > characters like ^M and ^[[D instead of spaces or newlines. > > This is how my code looks like ... > > s = pxssh.pxssh() > s.login(ip, username, password) > > cmd = 'xyz' > s.sendline (cmd) > s.prompt() > output = s.before > fileWrite = open(filePath , 'wb') > fileWrite.write(output) > s.prompt() > > > This is how my filePath looks like when I open it using vi editor. > > Starting command execution on host xxx.xxx.xxx.xxx > > > D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^M > > Command executed successfully ^M > > Executing next command ...^M > > I don't know what's going with the ^[[D, but ^M is a carriage return. Your connection is returning CRLF ("\r\n") for the line endings (which is what Windows uses for line endings) instead of the Unix line ending, which is just a line feed "\n". -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 10:51:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 15:51:53 +0100 Subject: to pass self or not to pass self In-Reply-To: <4ba0d65f$1@dnews.tpgi.com.au> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <4ba0d65f$1@dnews.tpgi.com.au> Message-ID: <4ba0ec7a$0$14371$426a74cc@news.free.fr> Lie Ryan a ?crit : > On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote: >> Patrick Maupin a ?crit : >>> On Mar 16, 1:59 pm, Jason Tackaberry wrote: >>>> Why not create the bound methods at instantiation time, rather than >>>> using the descriptor protocol which has the overhead of creating a new >>>> bound method each time the method attribute is accessed? >>> Well, for one thing, Python classes are open. They can be added to at >>> any time. For another thing, you might not ever use most of the >>> methods of an instance, so it would be a huge waste to create those. >> A possible optimization would be a simple memoization on first access. > > But what if, for example, one uses some descriptor/metaclass magic to > make it so that each subsequent access to the attribute returns a method > bound to different objects? Well, that's the whole problem with dynamism vs optimization... From pengyu.ut at gmail.com Wed Mar 17 10:53:42 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 17 Mar 2010 09:53:42 -0500 Subject: highlight words by regex in pdf files using python In-Reply-To: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> References: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> Message-ID: <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> On Tue, Mar 16, 2010 at 11:12 PM, Patrick Maupin wrote: > On Mar 4, 6:57?pm, Peng Yu wrote: >> I don't find a general pdf library in python that can do any >> operations on pdfs. >> >> I want to automatically highlight certain words (using regex) in a >> pdf. Could somebody let me know if there is a tool to do so in python? > > The problem with PDFs is that they can be quite complicated. ?There is > the outer container structure, which isn't too bad (unless the > document author applied encryption or fancy multi-object compression), > but then inside the graphics elements, things could be stored as > regular ASCII, or as fancy indexes into font-specific tables. ?Not > rocket science, but the only industrial-strength solution for this is > probably reportlab's pagecatcher. > > I have a library which works (primarily with the outer container) for > reading and writing, called pdfrw. ?I also maintain a list of other > PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries ?It > may be that pdfminer (link on that page) will do what you want -- it > is certainly trying to be complete as a PDF reader. ?But I've never > personally used pdfminer. > > One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools > will read in preexisting PDFs and write them out to a reportlab > canvas. ?This works quite well on a few very simple ASCII PDFs, but > the font handling needs a lot of work and probably won't work at all > right now on unicode. ?(But if you wanted to improve it, I certainly > would accept patches or give you commit rights!) > > That pdfrw example does graphics reasonably well. ?I was actually > going down that path for getting better vector graphics into rst2pdf > (both uniconvertor and svglib were broken for my purposes), but then I > realized that the PDF spec allows you to include a page from another > PDF quite easily (the spec calls it a form xObject), so you don't > actually need to parse down into the graphics stream for that. ?So, > right now, the best way to do vector graphics with rst2pdf is either > to give it a preexisting PDF (which it passes off to pdfrw for > conversion into a form xObject), or to give it a .svg file and invoke > it with -e inkscape, and then it will use inkscape to convert the svg > to a pdf and then go through the same path. Thank you for your long reply! But I'm not sure if you get my question or not. Acrobat can highlight certain words in pdfs. I could add notes to the highlighted words as well. However, I find that I frequently end up with highlighting some words that can be expressed by a regular expression. To improve my productivity, I don't want do this manually in Acrobat but rather do it in an automatic way, if there is such a tool available. People in reportlab mailing list said this is not possible with reportlab. And I don't see PyPDF can do this. If you know there is an API to for this purpose, please let me know. Thank you! Regards, Peng From wsantee at gmail.com Wed Mar 17 10:57:43 2010 From: wsantee at gmail.com (Wes Santee) Date: Wed, 17 Mar 2010 07:57:43 -0700 (PDT) Subject: Structure accessible by attribute name or index Message-ID: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_result or pwd.getpwnam() returns a struct_passwd. In trying to figure it out, I've only come across C implementations of the above types. Nothing specifically in Python. What is the Python native way to create this kind of object? I apologize if this has been widely covered already. In searching for an answer, I must be missing some fundamental concept that is excluding me from finding an answer. Cheers, -Wes From pmaupin at gmail.com Wed Mar 17 11:11:40 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 10:11:40 -0500 Subject: highlight words by regex in pdf files using python In-Reply-To: <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> References: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> Message-ID: On Wed, Mar 17, 2010 at 9:53 AM, Peng Yu wrote: > Thank you for your long reply! But I'm not sure if you get my question or not. > > Acrobat can highlight certain words in pdfs. I could add notes to the > highlighted words as well. However, I find that I frequently end up > with highlighting some words that can be expressed by a regular > expression. > > To improve my productivity, I don't want do this manually in Acrobat > but rather do it in an automatic way, if there is such a tool > available. People in reportlab mailing list said this is not possible > with reportlab. And I don't see PyPDF can do this. If you know there > is an API to for this purpose, please let me know. Thank you! I do not know of any API specific to this purpose, no. But I mentioned three libraries (pagecatcher, pdfminer, and pdfrw) that are capable, to a greater or lesser extent, of reading in PDFs and giving you the data from them, which you can then do your replacement on and then write back out. I would imagine this would be a piece of cake with pagecatcher. (I noticed you just posted on the reportlab mailing list, but you did not specifically mention pagecatcher.) It will probably take more work with either of the other two. It is probable that none of them do exactly what you want, but also that any of them is a better starting point than coding what you want from scratch. Regards, Pat From lists at cheimes.de Wed Mar 17 11:14:38 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 17 Mar 2010 16:14:38 +0100 Subject: Structure accessible by attribute name or index In-Reply-To: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: Wes Santee wrote: > I am very new to Python, and trying to figure out how to create an > object that has values that are accessible either by attribute name, > or by index. For example, the way os.stat() returns a stat_result or > pwd.getpwnam() returns a struct_passwd. > > In trying to figure it out, I've only come across C implementations of > the above types. Nothing specifically in Python. What is the Python > native way to create this kind of object? > > I apologize if this has been widely covered already. In searching for > an answer, I must be missing some fundamental concept that is > excluding me from finding an answer. You can't use the same implementation as the result object of os.stat() and others. However Python 2.6 has a new factory that creates a similar datatype called named tuple: http://docs.python.org/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields From sparks.m at gmail.com Wed Mar 17 11:16:49 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Wed, 17 Mar 2010 08:16:49 -0700 (PDT) Subject: Nested Scopes unintended behaviour ? Message-ID: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Hi, Is the following behaviour expected ? Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def Toggler(F, B): ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... >>> def Switcher(A,B): ... on=True ... def swtchfun(msg): ... on_ = on ... if on: ... on = False ... print "Switched to A" ... return A ... else: ... print "Switched to B" ... return B ... # ... return Toggler(swtchfun,True) ... >>> Switcher(1,2) Traceback (most recent call last): File "", line 1, in File "", line 13, in Switcher File "", line 2, in Toggler File "", line 4, in swtchfun UnboundLocalError: local variable 'on' referenced before assignment The reason I ask is because logically it makes sense. The on_ = on statement should resolve "on" to be the value on in the enclosing scope, however it appears that the "on = False" statement is taking priority. The reason I say this is because if you remove the "on = False" line you get the expected name resolution: >>> def Toggler(F, B): ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... >>> def Switcher(A,B): ... on=True ... def swtchfun(msg): ... on_ = on ... if on: ... print "Switched to A" ... return A ... else: ... print "Switched to B" ... return B ... # ... return Toggler(swtchfun,True) ... >>> Switcher(1,2) Switched to A 1 ie it looks like python is not looking at the expected scope in the first instance. To me it looks like a bug, but I can also see a rationale where it's considered a feature (because the "on" is on the left hand side resolving the value to a local, rather than a value in an enclosed scope) I know that you can work around this as follows: Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def Toggler(F, B): ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... >>> def Switcher(A,B): ... def switchgen(): ... while True: ... yield A ... yield B ... G = switchgen() ... def swtchfun(msg): ... return G.next() ... # ... return Toggler(swtchfun,True) ... >>> >>> Switcher(1,2) 1 2 1 2 But I'm curious as to whether the nested scope issue above is considered a bug or a feature, so I can deal with it appropriately. Any comments welcome :-) Regards, Michael. -- http://yeoldeclue.com/blog http://www.kamaelia.org/Home.html http://twitter.com/kamaelian From philip at semanchuk.com Wed Mar 17 11:26:51 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Mar 2010 11:26:51 -0400 Subject: multiprocessing on freebsd In-Reply-To: References: Message-ID: <54550297-2B41-4A5B-8A0B-9ABF7B22D4B6@semanchuk.com> On Mar 17, 2010, at 9:30 AM, Tim Arnold wrote: > Hi, > I'm checking to see if multiprocessing works on freebsd for any > version of python. My server is about to get upgraded from 6.3 to 8.0 > and I'd sure like to be able to use multiprocessing. > > I think the minimal test would be: > --------------------- > import multiprocessing > q = multiprocessing.Queue() > --------------------- > > with 6.3, I get > > File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line > 212, in Queue > from multiprocessing.queues import Queue > File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, > in > from multiprocessing.synchronize import Lock, BoundedSemaphore, > Semaphore, Condition > File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line > 33, in > " function, see issue 3770.") > ImportError: This platform lacks a functioning sem_open > implementation, therefore, the required synchronization primitives > needed will not function, see issue 3770. Hi Tim, Under FreeBSD 8/Python 2.6.2 I get the same result, unfortunately. That's a pity because sem_open works under FreeBSD >= 7.2 as we discussed before. Issue 3770 is closed with the note, "we've removed hard-coded platform variables for a better autoconf approach." I'm using the Python built from FreeBSD's ports, and the note makes me think that it's possible that if I built my own Python from the Python.org tarball rather than ports the problem would go away due to autoconf magic. I don't have the time to offer to do this for you, unfortunately. But why not install FreeBSD 8 under VirtualBox or somesuch and give it a go yourself? A couple of quirks I noted related to FreeBSD & POSIX IPC that you might find useful -- - The sem and mqueuefs kernel modules must be loaded, otherwise you'll get a message like this when you try to create a semaphore or message queue: Bad system call: 12 (core dumped) Under 8.0 they're loaded by default, I think. - C apps that want to use message queues must link to the realtime libs (pass -lrt to the linker). This tripped me up for a while. Linking to the realtime libs is required for all POSIX IPC calls under Linux; FreeBSD does not require it for semaphores or shared mem, only message queues. Hope this helps Philip From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 11:34:33 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 16:34:33 +0100 Subject: Structure accessible by attribute name or index In-Reply-To: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: <4ba0f67a$0$17757$426a74cc@news.free.fr> Wes Santee a ?crit : > I am very new to Python, and trying to figure out how to create an > object that has values that are accessible either by attribute name, > or by index. For example, the way os.stat() returns a stat_result or > pwd.getpwnam() returns a struct_passwd. > > In trying to figure it out, I've only come across C implementations of > the above types. Nothing specifically in Python. What is the Python > native way to create this kind of object? Using the appropriate __magicmethods__ for indexed access and computed attributes for the attribute access might be a good solution: # warning : Q&D implementation, would require some sanity checks. class IndexedValueDescriptor(object): def __init__(self, index): self._index = index def __get__(self, instance, cls): if instance is None: return self return instance[self._index] def __set__(self, instance, value): instance[self._index] = value class Structure(object): def __init__(self, value1, value2, value3): self._values = [value1, value2, value3] def __setitem__(self, index, value): self._values[index] = value def __getitem__(self, index): return self._values[index] value1 = IndexedValueDescriptor(0) value2 = IndexedValueDescriptor(1) value3 = IndexedValueDescriptor(2) Note that there are probably other solutions... Don't know how os.stat_result is implemented, might be worth looking at the source code. But anyway : the above should get you started. > I apologize if this has been widely covered already. In searching for > an answer, I must be missing some fundamental concept that is > excluding me from finding an answer. Well, that's not really a FAQ AFAICT !-) From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 11:35:41 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 16:35:41 +0100 Subject: Structure accessible by attribute name or index In-Reply-To: References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: <4ba0f6be$0$17757$426a74cc@news.free.fr> Christian Heimes a ?crit : > However Python 2.6 has a new factory that creates a similar > datatype called named tuple: > http://docs.python.org/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields > Duh... Should spend some more time reading 2.6's What's New :( From emile at fenx.com Wed Mar 17 11:44:03 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Mar 2010 08:44:03 -0700 Subject: Nested Scopes unintended behaviour ? In-Reply-To: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Message-ID: On 3/17/2010 8:16 AM Michael Sparks said... > Hi, > > > Is the following behaviour expected ? In short, yes. Assignment within a function forces the variable to locals. You can get around it like: > > Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def Toggler(F, B): > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... >>>> def Switcher(A,B): > ... on=True > ... def swtchfun(msg): ---> def swtchfun(msg, on=on): > ... on_ = on > ... if on: > ... on = False > ... print "Switched to A" > ... return A > ... else: > ... print "Switched to B" > ... return B > ... # > ... return Toggler(swtchfun,True) > ... >>>> Switcher(1,2) > Traceback (most recent call last): > File "", line 1, in > File "", line 13, in Switcher > File "", line 2, in Toggler > File "", line 4, in swtchfun > UnboundLocalError: local variable 'on' referenced before assignment > > The reason I ask is because logically it makes sense. The on_ = on > statement should resolve "on" to be the value on in the enclosing > scope, however it appears that the "on = False" statement is taking > priority. The reason I say this is because if you remove the "on = > False" line you get the expected name resolution: > >>>> def Toggler(F, B): > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... >>>> def Switcher(A,B): > ... on=True > ... def swtchfun(msg): > ... on_ = on > ... if on: > ... print "Switched to A" > ... return A > ... else: > ... print "Switched to B" > ... return B > ... # > ... return Toggler(swtchfun,True) > ... >>>> Switcher(1,2) > Switched to A > 1 > > ie it looks like python is not looking at the expected scope in the > first instance. > > To me it looks like a bug, but I can also see a rationale where it's > considered a feature (because the "on" is on the left hand side > resolving the value to a local, rather than a value in an enclosed > scope) > > I know that you can work around this as follows: > Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def Toggler(F, B): > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... >>>> def Switcher(A,B): > ... def switchgen(): > ... while True: > ... yield A > ... yield B > ... G = switchgen() > ... def swtchfun(msg): > ... return G.next() > ... # > ... return Toggler(swtchfun,True) > ... >>>> >>>> Switcher(1,2) > 1 > 2 > 1 > 2 > > But I'm curious as to whether the nested scope issue above is > considered a bug or a feature, so I can deal with it appropriately. > > Any comments welcome :-) > > Regards, > > > Michael. > -- > http://yeoldeclue.com/blog > http://www.kamaelia.org/Home.html > http://twitter.com/kamaelian > > > From nobody at nowhere.com Wed Mar 17 11:44:34 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 17 Mar 2010 15:44:34 +0000 Subject: execute bash builtins in python References: Message-ID: On Fri, 12 Mar 2010 08:15:49 -0500, Steve Holden wrote: > For shell=True I believe you should provide the command as a single > string, not a list of arguments. Using shell=True with an argument list is valid. On Unix, it's seldom what you want: it will invoke /bin/sh to execute the first argument with $1, $2, ... set from the remaining arguments. On Windows, a list is converted to a string in the same manner regardless of the value of the "shell" argument. Specifying shell=True causes the command string to be executed via "cmd /c ...". This allows the "program" to be a script, whereas shell=False requires the program to be a binary executable. From python at hope.cz Wed Mar 17 11:47:07 2010 From: python at hope.cz (Johny) Date: Wed, 17 Mar 2010 08:47:07 -0700 (PDT) Subject: pkg-config and Windows Message-ID: I have a program that needs to be installed with setup.py. But there is a problem when I am trying to install the program with setup.py in Windows. When I try to install with python setup.py install it goes like this C:\>python setup.py install running install running build running build_py running build_ext ERROR: Could not find pkg-config! As you can see the installation finishes with the error: Could not find pkg-config! Is there any way how to find out pkg-config in Windows? or how to solve the problem? Thanks L. From tundra at tundraware.com Wed Mar 17 12:32:45 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 11:32:45 -0500 Subject: Win32All On 64-Bit Operating Systems Message-ID: I have a pure-Python program developed on a POSIX platform (FreeBSD) that I'd like to make fully compatible with Windows systems as well. The only conflict arises insofar as this program makes considerable use of the stat UID and GID values, as well as their corresponding user- and group names. Since Windows has not grp and pwd modules, I need to synthesize this. In the past, I've solved this problem by detecting the presence of Win32All. If present, I do the necessary magic to return the true UID/name, GID/name info from Windows itself. If not, I return UID/GID as provided by an os.stat call and use the phoby names "winuser" and "wingroup" respectively. Now for the question: Is there even an instance of Win32All for 64-bit OSs like Vista and Win7? If not, I'm inclined not bother with it at all and just return the phony values as placeholders because I do not want different features on 32- and 64-bit platforms. Thanks, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From wsantee at gmail.com Wed Mar 17 12:40:44 2010 From: wsantee at gmail.com (Wes Santee) Date: Wed, 17 Mar 2010 09:40:44 -0700 (PDT) Subject: Structure accessible by attribute name or index References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: <23c6223c-cc65-44e2-a400-aba5d0a010a6@m37g2000yqf.googlegroups.com> On Mar 17, 11:14?am, Christian Heimes wrote: > Wes Santee wrote: > > I am very new to Python, and trying to figure out how to create an > > object that has values that are accessible either by attribute name, > > or by index. ?For example, the way os.stat() returns a stat_result or > > pwd.getpwnam() returns a struct_passwd. > > > In trying to figure it out, I've only come across C implementations of > > the above types. ?Nothing specifically in Python. ?What is the Python > > native way to create this kind of object? > > > I apologize if this has been widely covered already. ?In searching for > > an answer, I must be missing some fundamental concept that is > > excluding me from finding an answer. > > You can't use the same implementation as the result object of os.stat() > and others. However Python 2.6 has a new factory that creates a similar > datatype called named tuple:http://docs.python.org/library/collections.html#namedtuple-factory-fu... Thanks for the pointer. At least I know there is a reason why I wasn't finding a solution. :) From wsantee at gmail.com Wed Mar 17 12:55:07 2010 From: wsantee at gmail.com (Wes Santee) Date: Wed, 17 Mar 2010 09:55:07 -0700 (PDT) Subject: Structure accessible by attribute name or index References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> <4ba0f67a$0$17757$426a74cc@news.free.fr> Message-ID: <2e0ba087-eb30-460e-a6e2-b29498669107@33g2000yqj.googlegroups.com> On Mar 17, 11:34?am, Bruno Desthuilliers wrote: > Wes Santee a ?crit : > > > I am very new to Python, and trying to figure out how to create an > > object that has values that are accessible either by attribute name, > > or by index. ?For example, the way os.stat() returns a stat_result or > > pwd.getpwnam() returns a struct_passwd. > > > In trying to figure it out, I've only come across C implementations of > > the above types. ?Nothing specifically in Python. ?What is the Python > > native way to create this kind of object? > > Using the appropriate __magicmethods__ for indexed access and computed > attributes for the attribute access might be a good solution: This is as good an excuse as any to get familiar with the rest of the __magicmethods__. :) > > # warning : Q&D implementation, would require some sanity checks. > > class IndexedValueDescriptor(object): > ? ? ?def __init__(self, index): > ? ? ? ? ?self._index = index > ? ? ?def __get__(self, instance, cls): > ? ? ? ? ?if instance is None: > ? ? ? ? ? ? ?return self > ? ? ? ? ?return instance[self._index] > ? ? ?def __set__(self, instance, value): > ? ? ? ? ?instance[self._index] = value > > class Structure(object): > ? ? ?def __init__(self, value1, value2, value3): > ? ? ? ? ?self._values = [value1, value2, value3] > ? ? ?def __setitem__(self, index, value): > ? ? ? ? ?self._values[index] = value > ? ? ?def __getitem__(self, index): > ? ? ? ? ?return self._values[index] > ? ? ?value1 = IndexedValueDescriptor(0) > ? ? ?value2 = IndexedValueDescriptor(1) > ? ? ?value3 = IndexedValueDescriptor(2) > > Note that there are probably other solutions... Don't know how > os.stat_result is implemented, might be worth looking at the source > code. But anyway : the above should get you started. > > > I apologize if this has been widely covered already. ? In searching for > > an answer, I must be missing some fundamental concept that is > > excluding me from finding an answer. > > Well, that's not really a FAQ AFAICT !-) From mail at timgolden.me.uk Wed Mar 17 13:05:48 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Mar 2010 17:05:48 +0000 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: Message-ID: <4BA10BEC.2080802@timgolden.me.uk> On 17/03/2010 16:32, Tim Daneliuk wrote: > I have a pure-Python program developed on a POSIX platform (FreeBSD) that > I'd like to make fully compatible with Windows systems as well. The only > conflict arises insofar as this program makes considerable use of the > stat UID and GID values, as well as their corresponding user- and group > names. Since Windows has not grp and pwd modules, I need to synthesize > this. > > In the past, I've solved this problem by detecting the presence of Win32All. > If present, I do the necessary magic to return the true UID/name, GID/name > info from Windows itself. If not, I return UID/GID as provided by an > os.stat call and use the phoby names "winuser" and "wingroup" respectively. > > Now for the question: Is there even an instance of Win32All for 64-bit > OSs like Vista and Win7? If not, I'm inclined not bother with it at all > and just return the phony values as placeholders because I do not want > different features on 32- and 64-bit platforms. Looks like it: http://sourceforge.net/projects/pywin32/files/ but, frankly, I wouldn't bother with the uid/gid thing on Windows. It's nearly meaningless most of the time. Just return placeholders. TJG From andrej.mitrovich at gmail.com Wed Mar 17 13:41:14 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Mar 2010 10:41:14 -0700 (PDT) Subject: Python Documentation website layout changed? Message-ID: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> Hi, What happened to the sidebar on the left of the documentation website? It seems to be gone: http://docs.python.org/py3k/index.html I found it quite useful since I can quickly swap between Python2/3 documentation, and between other parts of the documentation as well. From a_jtim at bellsouth.net Wed Mar 17 13:57:42 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Wed, 17 Mar 2010 10:57:42 -0700 (PDT) Subject: multiprocessing on freebsd References: Message-ID: <4b29e714-df56-49be-a836-51d5833765f8@x12g2000yqx.googlegroups.com> On Mar 17, 11:26?am, Philip Semanchuk wrote: > On Mar 17, 2010, at 9:30 AM, Tim Arnold wrote: > > > > > > > Hi, > > I'm checking to see if multiprocessing works on freebsd for any > > version of python. My server is about to get upgraded from 6.3 to 8.0 > > and I'd sure like to be able to use multiprocessing. > > > I think the minimal test would be: > > --------------------- > > import multiprocessing > > q = multiprocessing.Queue() > > --------------------- > > > with 6.3, I get > > > File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line > > 212, in Queue > > ? ?from multiprocessing.queues import Queue > > ?File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, > > in > > ? ?from multiprocessing.synchronize import Lock, BoundedSemaphore, > > Semaphore, Condition > > ?File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line > > 33, in > > ? ?" function, see issue 3770.") > > ImportError: This platform lacks a functioning sem_open > > implementation, therefore, the required synchronization primitives > > needed will not function, see issue 3770. > > Hi Tim, > Under FreeBSD 8/Python 2.6.2 I get the same result, unfortunately. ? > That's a pity because sem_open works under FreeBSD >= 7.2 as we ? > discussed before. > > Issue 3770 is closed with the note, "we've removed hard-coded platform ? > variables for a better autoconf approach." I'm using the Python built ? > from FreeBSD's ports, and the note makes me think that it's possible ? > that if I built my own Python from the Python.org tarball rather than ? > ports the problem would go away due to autoconf magic. I don't have ? > the time to offer to do this for you, unfortunately. But why not ? > install FreeBSD 8 under VirtualBox or somesuch and give it a go ? > yourself? > > A couple of quirks I noted related to FreeBSD & POSIX IPC that you ? > might find useful -- > - The sem and mqueuefs kernel modules must be loaded, otherwise you'll ? > get a message like this when you try to create a semaphore or message ? > queue: > Bad system call: 12 (core dumped) > > Under 8.0 they're loaded by default, I think. > > - C apps that want to use message queues must link to the realtime ? > libs (pass -lrt to the linker). This tripped me up for a while. ? > Linking to the realtime libs is required for all POSIX IPC calls under ? > Linux; FreeBSD does not require it for semaphores or shared mem, only ? > message queues. > > Hope this helps > Philip Hi Philip, Thanks for that information (esp the linker info). Once the machine is upgraded, I'll try building python from the tarball. I'll post back here with the results. here's hoping! thanks, --Tim From sccolbert at gmail.com Wed Mar 17 14:14:14 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 17 Mar 2010 14:14:14 -0400 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> On Wed, Mar 17, 2010 at 11:44 AM, Nobody wrote: > On Fri, 12 Mar 2010 08:15:49 -0500, Steve Holden wrote: > > > For shell=True I believe you should provide the command as a single > > string, not a list of arguments. > > Using shell=True with an argument list is valid. > > On Unix, it's seldom what you want: it will invoke /bin/sh to execute the > first argument with $1, $2, ... set from the remaining arguments. > > On Windows, a list is converted to a string in the same manner regardless > of the value of the "shell" argument. Specifying shell=True causes the > command string to be executed via "cmd /c ...". This allows the "program" > to be a script, whereas shell=False requires the program to be a binary > executable. > > -- > http://mail.python.org/mailman/listinfo/python-list > if you can work interactively, save yourself the headache and just use Ipython: brucewayne at broo:~$ ipython Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: alias Total number of aliases: 15 Out[1]: [('cat', 'cat'), ('clear', 'clear'), ('less', 'less'), ('mkdir', 'mkdir'), ('rmdir', 'rmdir'), ('cp', 'cp -i'), ('lc', 'ls -F -o --color'), ('ldir', 'ls -F -o --color %l | grep /$'), ('lf', 'ls -F -o --color %l | grep ^-'), ('lk', 'ls -F -o --color %l | grep ^l'), ('ll', 'ls -lF'), ('ls', 'ls -F'), ('lx', 'ls -F -o --color %l | grep ^-..x'), ('mv', 'mv -i'), ('rm', 'rm -i')] In [2]: -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Wed Mar 17 14:16:42 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Mar 2010 11:16:42 -0700 (PDT) Subject: Python Documentation website layout changed? References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> Message-ID: <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> On Mar 17, 6:41?pm, Andrej Mitrovic wrote: > Hi, > > What happened to the sidebar on the left of the documentation website? > It seems to be gone: > > http://docs.python.org/py3k/index.html > > I found it quite useful since I can quickly swap between Python2/3 > documentation, and between other parts of the documentation as well. Edit: It looks like only the Python 3 pages are affected, the Python 2 pages are the same as before: http://docs.python.org/index.html Might be a bug? From steve at holdenweb.com Wed Mar 17 14:34:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Mar 2010 14:34:17 -0400 Subject: Python Documentation website layout changed? In-Reply-To: <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> Message-ID: <4BA120A9.3060001@holdenweb.com> Andrej Mitrovic wrote: > On Mar 17, 6:41 pm, Andrej Mitrovic > wrote: >> Hi, >> >> What happened to the sidebar on the left of the documentation website? >> It seems to be gone: >> >> http://docs.python.org/py3k/index.html >> >> I found it quite useful since I can quickly swap between Python2/3 >> documentation, and between other parts of the documentation as well. > > Edit: It looks like only the Python 3 pages are affected, the Python 2 > pages are the same as before: > > http://docs.python.org/index.html > > Might be a bug? I'll ask. Georg - is this known behavior or a temporary problem? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From anthra.norell at bluewin.ch Wed Mar 17 14:43:00 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Wed, 17 Mar 2010 19:43:00 +0100 Subject: How to access a web site with an authentication template. Message-ID: <4BA122B4.5030003@bluewin.ch> Hi all, I have spent the better part of this day reading docs and googling archives to no avail. About this: I understand that I can access password protected sites with urllib2. However, the protocol seems to be: I try without password and catch the error coming back. The header will then tell me what the server expects in the line of formats. That doesn't work with a site I am dealing with, because the opening page does not require a password. It presents an id/password entry template and I have no clue how to respond in python. The page source is chock full of java script. The header--if that means anything--is: ... more CSS I don't expect solutions, but rather pointers to relevant reading. Thanks Frederic From tundra at tundraware.com Wed Mar 17 15:07:14 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 14:07:14 -0500 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: Message-ID: <3rl777-q1m2.ln1@ozzie.tundraware.com> On 3/17/2010 12:05 PM, Tim Golden wrote: > On 17/03/2010 16:32, Tim Daneliuk wrote: >> I have a pure-Python program developed on a POSIX platform (FreeBSD) that >> I'd like to make fully compatible with Windows systems as well. The only >> conflict arises insofar as this program makes considerable use of the >> stat UID and GID values, as well as their corresponding user- and group >> names. Since Windows has not grp and pwd modules, I need to synthesize >> this. >> >> In the past, I've solved this problem by detecting the presence of >> Win32All. >> If present, I do the necessary magic to return the true UID/name, >> GID/name >> info from Windows itself. If not, I return UID/GID as provided by an >> os.stat call and use the phoby names "winuser" and "wingroup" >> respectively. >> >> Now for the question: Is there even an instance of Win32All for 64-bit >> OSs like Vista and Win7? If not, I'm inclined not bother with it at all >> and just return the phony values as placeholders because I do not want >> different features on 32- and 64-bit platforms. > > Looks like it: > > http://sourceforge.net/projects/pywin32/files/ Thanks! > > but, frankly, I wouldn't bother with the uid/gid thing on > Windows. It's nearly meaningless most of the time. Just > return placeholders. > > TJG That's not really so. Windows definitely has the notions of users and groups, they just don't quite align with the POSIX model exactly. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From xahlee at gmail.com Wed Mar 17 15:17:28 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 17 Mar 2010 12:17:28 -0700 (PDT) Subject: to RG - Lisp lunacy and Perl psychosis References: <19c5b00d-c1e0-4016-9f72-37229cbf42b9@g19g2000yqe.googlegroups.com> <79tk67-rp51.ln1@osiris.mauzo.dyndns.org> Message-ID: <6ede3156-9e9c-45ed-a532-89f5825646ea@p3g2000pra.googlegroups.com> 2010-03-17 On Mar 10, 9:17?am, Ben Morrow wrote: > Also, flamebait language-comparison xposts involving Lisp are one > of Xah Lee's trademarks. You might want to look into not imitating > him/her/it. being a professional programer today, typically you know more than just one language. Practical questions, discussions, involving more than one language is natural, and in fact happens more and more often in online forums over the past 15 years i've seen. Partly due to, of course, the tremendous birth of languages in the past decade. In the 1980s or 1990s, you don't typically use more than one lang in a project. Today, probably majority of projects requires you to use more than one well known general purpose language. In those times, discussion of more than one language is usually academic comparison. Today, honest post as ?i know this in X but how you do in Y? is a common need. The reason they become flame wars is mostly not about the message content. More about tech geeker's sensitivity, with the carried over old school netiquette that any person mentioning lang x in group y must be of no good intentions. If you look at online forums today, in fact most comp lang forums have no problem in mentioning or discussion different languages in context. The problem occur more frequently in free-for-all type of forums where the know-it-all tech geekers reside (the in-group argot is ?hacker?), each thinking they are justice kings and queens, take opportunities to ridicule, flame, any post that mention other lang or any thing that doesn't seem to be protective of their lang. This is comp.lang.* newsgroups, with good as well as mostly bad aspects. Of course, the free-for-all nature is precisely the reason most tech geekers stay in newsgroups. A good percentage of them, if not majority, are old timers. Most newsgroup tech geekers consider cross-posting wrong. I consider such taboo in this convention being a major contribution to the redundant creation of new languages, flaws, and foster the hostile faction nature of programing language groups we see. It is sad to say, comp.lang.lisp today is 90% machine generated spam. You see that each time this is brought up in the past 3 years, the regulars are too busy boasting about how they've set up some tech geek system so that spam don't reach their eyes, and sternly sputter about web browser using idiots, with, profuse suggestions from their infinite knowledge about what newsgroup reading software people should be using. To the comp.lang.python people, i think perhaps it is fruitful now to think about de-coupling the newsgroup from the mailing list... am not very involved in the comp.lang.python or python community in recent years, but my thought is that, i got the feeling that most practical posts happen in the mailing list and the newsgroup ones tend to be more free flow of thoughts... so perhaps de-couple them is good, because python is main stream now and mailing list is sustainable large, is good for more practical, concrete questions and answers, and philosophical free thoughts still have a place to go, in newsgroups. further readings: ? Proliferation of Computing Languages xahlee.org/UnixResource_dir/writ/new_langs.html ? Tech Geekers vs Spammers xahlee.org/UnixResource_dir/writ/tech_geekers_vs_spammers.html ? Cross-posting & Language Factions xahlee.org/Netiquette_dir/cross-post.html Xah ? http://xahlee.org/ ? From martin.hellwig at dcuktec.org Wed Mar 17 15:25:44 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Mar 2010 19:25:44 +0000 Subject: multiprocessing on freebsd In-Reply-To: References: Message-ID: On 03/17/10 13:30, Tim Arnold wrote: > Hi, > I'm checking to see if multiprocessing works on freebsd for any > version of python. My server is about to get upgraded from 6.3 to 8.0 > and I'd sure like to be able to use multiprocessing. > > I think the minimal test would be: > --------------------- > import multiprocessing > q = multiprocessing.Queue() > --------------------- > > with 6.3, I get > > File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line > 212, in Queue > from multiprocessing.queues import Queue > File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, > in > from multiprocessing.synchronize import Lock, BoundedSemaphore, > Semaphore, Condition > File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line > 33, in > " function, see issue 3770.") > ImportError: This platform lacks a functioning sem_open > implementation, therefore, the required synchronization primitives > needed will not function, see issue 3770. > Build mine from ports, with the following options (notice SEM & PTH): [martin at aspire8930 /usr/home/martin]$ cat /var/db/ports/python26/options # This file is auto-generated by 'make config'. # No user-servicable parts inside! # Options for python26-2.6.4 _OPTIONS_READ=python26-2.6.4 WITH_THREADS=true WITHOUT_HUGE_STACK_SIZE=true WITH_SEM=true WITH_PTH=true WITH_UCS4=true WITH_PYMALLOC=true WITH_IPV6=true WITHOUT_FPECTL=true [martin at aspire8930 /usr/home/martin]$ uname -a FreeBSD aspire8930 8.0-STABLE FreeBSD 8.0-STABLE #3: Wed Feb 3 17:01:18 GMT 2010 martin at aspire8930:/usr/obj/usr/src/sys/ASPIRE8930 amd64 [martin at aspire8930 /usr/home/martin]$ python Python 2.6.4 (r264:75706, Mar 17 2010, 18:44:24) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import multiprocessing as mp >>> queue = mp.Queue() >>> hth -- mph From tjreedy at udel.edu Wed Mar 17 15:55:35 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 15:55:35 -0400 Subject: to pass self or not to pass self In-Reply-To: <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: On 3/17/2010 1:35 AM, Patrick Maupin wrote: >>>> def a(s, count, lenfunc): > ... for i in xrange(count): > ... z = lenfunc(s) > ... >>>> >>> a('abcdef', 100000000, len) >>>> >>> a('abcdef', 100000000, str.__len__) > Running cPython 2.6 on my machine, len() runs about 3 times faster > than str.__len__(). The overhead of checking that an object is usable > with a particular class method far outweighs the cost of creating the > bound method! Wow, this so surprised me, that I had to try it with 3.1 (on winxp), and got a similar result (about 2.6x longer with str.__len__). This is a real lesson in measure, don't guess, and how premature 'optimization' may be a pessimization. Thanks. Terry Jan Reedy From mail at timgolden.me.uk Wed Mar 17 15:59:57 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Mar 2010 19:59:57 +0000 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: <3rl777-q1m2.ln1@ozzie.tundraware.com> References: <3rl777-q1m2.ln1@ozzie.tundraware.com> Message-ID: <4BA134BD.8060704@timgolden.me.uk> On 17/03/2010 19:07, Tim Daneliuk wrote: > That's not really so. Windows definitely has the notions of users and groups, > they just don't quite align with the POSIX model exactly. Yes, my comment was a little blase. I know that Windows has users & groups: http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html :) I was thinking that you wanted a naive transfer of the Posix concept. The "owner" of a file does mean something to Windows (while the "group" really doesn't; it's just an artefact of Windows' posix-compatibility) but not as much as it does on Posix systems, because the security system is much more sophisticated. But maybe I'm teaching my grandmother to suck eggs ? TJG From tjreedy at udel.edu Wed Mar 17 16:12:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 16:12:11 -0400 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> <4BA0B985.3060501@ieee.org> Message-ID: On 3/17/2010 8:18 AM, Stefan Behnel wrote: > Dave Angel, 17.03.2010 12:14: >> Stefan Behnel wrote: >>> I think the point here is that executable binaries are not supposed to >>> be used as libraries. Libraries are. That's the difference between a >>> DLL and an executable in the first place. To run an executable, >>> execute it. The subprocess module is the tool of choice here. To use a >>> DLL, link against it. >>> >> There's no real reason parts of an exe cannot be exported, same as a >> dll. They are in fact the same structure. And in fact many other files >> in the Windows environment are also the same structure, from fonts to >> ocx's > > So, because you can, you'd also try to link against fonts then, I guess? > > I hope you notice that what you and me said isn't contradictory. But > there's a reason why there are libraries and executables, and there's no > reason you *should* export anything from an executable - that's what > libraries are there for. That's my point. To put it another way, if an executable has functions that could/should be available as 'library' functions, then they can/should be put in a separate library file for use as such and called from a smaller .exe. This is what python itself does. For 3.1 on winxp, python.exe is only 26 Kb, while python31.dll, with all the builtin functions and classes, (in windows/system32) is 2072 KB. > > Besides, nothing guarantees that it's safe to call stuff that an > executable exports. The executable may well require some setup code that > it only executes when it is properly started. Terry Jan Reedy From tjreedy at udel.edu Wed Mar 17 16:21:08 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 16:21:08 -0400 Subject: question about tkinter In-Reply-To: References: Message-ID: On 3/17/2010 10:33 AM, robert schaefer wrote: > No, And there's a reason (perhaps not a great one - but I'm got some constraints). > Related to that I tailored Ipython to work with gtk (ipython's default was tkinter) - tailoring was by a command > - is there any way to command idle to use gtk? I am pretty sure not, the gui is hard-coded with tkinter. From tjreedy at udel.edu Wed Mar 17 16:29:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 16:29:02 -0400 Subject: Nested Scopes unintended behaviour ? In-Reply-To: References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Message-ID: On 3/17/2010 11:44 AM, Emile van Sebille wrote: > On 3/17/2010 8:16 AM Michael Sparks said... >> Hi, >> >> >> Is the following behaviour expected ? > > In short, yes. Assignment within a function forces the variable to > locals. In 3.x, one can declare names to be nonlocal (ie, local to some outer function, as opposed to local to the current function or module global). In your case, nonlocal on in your inner swtchfun function would give the behavior you wanted. Terry Jan Reedy From python at bdurham.com Wed Mar 17 16:31:39 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Mar 2010 16:31:39 -0400 Subject: Converting Python CGI to WSGI scripts In-Reply-To: <4ba0735b$0$1594$742ec2ed@news.sonic.net> References: <1268759895.28810.1365130739@webmail.messagingengine.com> <4ba0735b$0$1594$742ec2ed@news.sonic.net> Message-ID: <1268857899.13963.1365364051@webmail.messagingengine.com> Sebastian/John, Thank you very much for your feedback. John: I initially missed the nuance of WSGI scripts being function calls. I suspect your tip has saved me a lot of pain :) Regards, Malcolm From tundra at tundraware.com Wed Mar 17 16:43:15 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 15:43:15 -0500 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: <3rl777-q1m2.ln1@ozzie.tundraware.com> Message-ID: <4fr777-43o2.ln1@ozzie.tundraware.com> On 3/17/2010 2:59 PM, Tim Golden wrote: > On 17/03/2010 19:07, Tim Daneliuk wrote: >> That's not really so. Windows definitely has the notions of users and >> groups, >> they just don't quite align with the POSIX model exactly. > > Yes, my comment was a little blase. I know that Windows has users & groups: > > http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html > > :) > > I was thinking that you wanted a naive transfer of the Posix concept. > The "owner" of a file does mean something to Windows (while the "group" > really doesn't; it's just an artefact of Windows' posix-compatibility) > but not as much as it does on Posix systems, because the security system > is much more sophisticated. > > But maybe I'm teaching my grandmother to suck eggs ? > > TJG Naw. The intent is just to provide as similar as possible a user experience. >From a coding POV, it is surely simpler to just use 'winuser' and 'wingroup', but I am sort of philosophically wired to not throw information away if it's a available from the OS. BTW, wanna beta test a really cool CLI mass file renaming tool????? ;) -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From pmaupin at gmail.com Wed Mar 17 17:21:44 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 14:21:44 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: On Mar 17, 2:55?pm, Terry Reedy wrote: > On 3/17/2010 1:35 AM, Patrick Maupin wrote: > > >>>> def a(s, count, lenfunc): > > ... ? ? for i in xrange(count): > > ... ? ? ? ?z = lenfunc(s) > > ... > >>>> >>> ?a('abcdef', 100000000, len) > >>>> >>> ?a('abcdef', 100000000, str.__len__) > > Running cPython 2.6 on my machine, len() runs about 3 times faster > > than str.__len__(). ?The overhead of checking that an object is usable > > with a particular class method far outweighs the cost of creating the > > bound method! > > Wow, this so surprised me, that I had to try it with 3.1 (on winxp), and > got a similar result (about 2.6x longer with str.__len__). This is a > real lesson in measure, don't guess, and how premature 'optimization' > may be a pessimization. Thanks. > > Terry Jan Reedy Actually, I think I overstated my case -- there is some special logic for len and built-in objects, I think. I can see the same thing with normal attributes on subclasses of object(), but not nearly as dramatic. In any case, your conclusion about this being a lesson in "measure, don't guess" holds, with the additional caveat that, if it matters, you need to somehow do some additional measurements to make sure you are measuring what you think you are measuring! Pat From tundra at tundraware.com Wed Mar 17 17:30:19 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 16:30:19 -0500 Subject: What Does sys.platform Return On 64 Bit Windows Systems? Message-ID: On older 32 bit Windows systems, sys.platform returns: 'win32' What does it return on 64-bit Windows systems? I'd check myself, but I don't have access to 64-bit Windows. TIA, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From gagsl-py2 at yahoo.com.ar Wed Mar 17 17:37:24 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 17 Mar 2010 18:37:24 -0300 Subject: bug in bdist_wininst cross compile? References: <4BA0E958.8050205@chamonix.reportlab.co.uk> Message-ID: En Wed, 17 Mar 2010 11:38:16 -0300, Robin Becker escribi?: > has anyone had any success with cross compilation and bdist_wininst; I > have modified build_ext very slightly to fix a small bug in cross > compilation related to library order. Please post your bug report + patch at http://bugs.python.org or it will be lost. -- Gabriel Genellina From keirvt at gmail.com Wed Mar 17 18:04:14 2010 From: keirvt at gmail.com (Keir Vaughan-taylor) Date: Wed, 17 Mar 2010 15:04:14 -0700 (PDT) Subject: os.walk restart Message-ID: I am traversing a large set of directories using for root, dirs, files in os.walk(basedir): run program Being a huge directory set the traversal is taking days to do a traversal. Sometimes it is the case there is a crash because of a programming error. As each directory is processed the name of the directory is written to a file I want to be able to restart the walk from the directory where it crashed. Is this possible? From gatoygata2 at gmail.com Wed Mar 17 18:34:53 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Wed, 17 Mar 2010 15:34:53 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> Message-ID: On Mar 17, 3:43?pm, Patrick Maupin wrote: > On Mar 17, 4:12?am, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > Patrick Maupin a ?crit : > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > >> Why not create the bound methods at instantiation time, rather than > > >> using the descriptor protocol which has the overhead of creating a new > > >> bound method each time the method attribute is accessed? > > > > Well, for one thing, Python classes are open. ?They can be added to at > > > any time. ?For another thing, you might not ever use most of the > > > methods of an instance, so it would be a huge waste to create those. > > > A possible optimization would be a simple memoization on first access. > > I do agree that memoization on access is a good pattern, and I use it > frequently. ?I don't know if I would want the interpreter > automagically doing that for everything, though -- it would require > some thought to figure out what the overhead cost is for the things > that are only used once. > > Usually, I will have a slight naming difference for the things I want > memoized, to get the memoization code to run. ?For example, if you add > an underbar in front of everything you want memoized: > > class foo(object): > > ? ? def _bar(self): > ? ? ? ? pass > > ? ? def __getattr__(self, aname): > ? ? ? ? if aname.startswith('_'): > ? ? ? ? ? ? raise AttributeError > ? ? ? ? value = getattr(self, '_' + aname) > ? ? ? ? self.aname = value > ? ? ? ? return value > > obj = foo() > > So then the first time you look up obj.bar, it builds the bound > method, and on subsequent accesses it just returns the previously > bound method. > > Regards, > Pat Patrick, I was trying to understand the way your code was working but I thing I'm not getting it. I tested: from time import time class foo1(object): def _bar(self): pass def __getattr__(self, name): value = getattr(self, '_' + name) self.name = value return value class foo2(object): def bar(self): pass def a(klass, count): ins = klass() for i in xrange(count): z = ins.bar() t0 = time() a(foo1, 10000000) t1 = time() a(foo2, 10000000) t2 = time() print t1-t0 #75 sec print t2-t1 #11 sec foo1 is a lot slower than foo2. I understood that memoization should optimize atribute calls. Maybe I am putting my foot in my mouth... Thanks JA From googler.1.webmaster at spamgourmet.com Wed Mar 17 18:35:06 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Wed, 17 Mar 2010 15:35:06 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> > 1) put the line number information into the message string when you raise > the exception you mean the line and file information of the C code, right? From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 18:38:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 22:38:21 GMT Subject: Swapping Content of Two Dictionaries. References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Message-ID: On Wed, 17 Mar 2010 13:34:51 +0100, Peter Otten wrote: > Hatem Oraby wrote: > >> Hello, I want to swap the content of two dictionaries, the obvious way >> to do it is: >> a = {1:"I'am A"} >> b = {2:"I'm B"} >> temp = a >> a = b >> b = temp > > That can be simplified to > > a, b = b, a > > and is almost certainly the right approach. Unfortunately, it may not, because it doesn't swap the content of two dictionaries (as asked for), but instead swaps the dictionaries bound to two names, which is a very different kettle of fish indeed. It may be that the OP's description of his problem is inaccurate, in which case a simple re-binding is the easiest way, but if the subject line is accurate, then he needs your suggested solution using a temporary dict, clear and update. Wrap it in a function, and you have a one-liner swap operation :) -- Steven From gagsl-py2 at yahoo.com.ar Wed Mar 17 18:39:45 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 17 Mar 2010 19:39:45 -0300 Subject: How to access a web site with an authentication template. References: <4BA122B4.5030003@bluewin.ch> Message-ID: En Wed, 17 Mar 2010 15:43:00 -0300, Anthra Norell escribi?: > I understand that I can access password protected sites with urllib2. > [...] a site I am dealing with, because the opening page does not > require a password. It presents an id/password entry template and I have > no clue how to respond in python. The page source is chock full of java > script. Use an HTTP sniffer (there are plenty) to see the actual request that is sent to the server. Then emulate it using urllib2. -- Gabriel Genellina From david at boddie.org.uk Wed Mar 17 18:40:43 2010 From: david at boddie.org.uk (David Boddie) Date: Wed, 17 Mar 2010 23:40:43 +0100 Subject: highlight words by regex in pdf files using python References: Message-ID: On Wednesday 17 March 2010 00:47, Aahz wrote: > In article > , > Peng Yu wrote: >> >>I don't find a general pdf library in python that can do any >>operations on pdfs. >> >>I want to automatically highlight certain words (using regex) in a >>pdf. Could somebody let me know if there is a tool to do so in python? > > Did you Google at all? "python pdf" finds this as the first link, though > I have no clue whether it does what you want: > > http://pybrary.net/pyPdf/ The original poster might also be interested in displaying the highlighted words without modifying the original file. In which case, the Poppler library is worth investigating: http://poppler.freedesktop.org/ David From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 18:42:35 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 22:42:35 GMT Subject: os.walk restart References: Message-ID: On Wed, 17 Mar 2010 15:04:14 -0700, Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to a > file What, a proper, honest-to-goodness core dump? Or do you mean an exception? > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? Quick and dirty with no error-checking: # Untested last_visited = open("last_visited.txt", 'r').read() for root, dirs, files in os.walk(last_visited or basedir): open("last_visited.txt", 'w').write(root) run program -- Steven From news1234 at free.fr Wed Mar 17 18:47:41 2010 From: news1234 at free.fr (News123) Date: Wed, 17 Mar 2010 23:47:41 +0100 Subject: url2lib (windows 7) does not notice when network reconnects (getaddrinfo problem) Message-ID: <4ba15c0d$0$15456$426a74cc@news.free.fr> Hi, I'd like to write a function, that knows when the 'internet' is reachable. My setup is a windows7 host with a wireless USB modem. The modem might connect / disconnect any time. I thought I write a small function just checking whether I can fetch a url. ######### script starts import time,urllib2 myurl = "http://www.mysite.com" # or "www.google.com" or whatever you like while True: connected = False try: urllib2.urlopen(myurl) connected = True except urllib2.URLError as e: print "urlerr %s" % e print "connected",connected time.sleep(1) ########## end of script if the network is connected when I start the script the first time after reboot, then I receive > connected True As expected If the network is disconnected when I start the script the first time after reboot, then I receive > urlerr > connected False as expected Things are getting weired, when my USB wireless modem connects after I started my script: It happens, that I just continue to receive: > urlerr > connected False however when I use a windows cmd window and I start "ping www.mysite.com", then my python script recovers and reports > connected True My perhaps false conclusion is, that getaddrinfo() is not retrying to resolve an IP address, when it failed once. Is this behaviour known? Can this really be possible? I can reproduce this issue. not every time, but rather often. If yes, is there any way to force a new host name lookup under windows? What else could I be doing wrong? Thanks a lot in advance for any ideas N From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 18:49:20 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 22:49:20 GMT Subject: What Does sys.platform Return On 64 Bit Windows Systems? References: Message-ID: On Wed, 17 Mar 2010 16:30:19 -0500, Tim Daneliuk wrote: > On older 32 bit Windows systems, sys.platform returns: 'win32' > > What does it return on 64-bit Windows systems? I'd check myself, but I > don't have access to 64-bit Windows. According to the docs, it returns win32: http://docs.python.org/library/sys.html If anyone knows different, this should be reported as a documentation bug. But 30 seconds of googling suggests that sys.platform is 'win32' even on 64-bit builds of Windows, by design: http://stackoverflow.com/questions/2144748/is-it-safe-to-use-sys-platformwin32-check-on-64-bit-python -- Steven From gagsl-py2 at yahoo.com.ar Wed Mar 17 19:09:28 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 17 Mar 2010 20:09:28 -0300 Subject: os.walk restart References: Message-ID: En Wed, 17 Mar 2010 19:04:14 -0300, Keir Vaughan-taylor escribi?: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to > a file > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? If the 'dirs' list were guaranteed to be sorted, you could remove at each level all previous directories already traversed. But it's not :( Perhaps a better approach would be, once, collect all directories to be processed and write them on a text file -- these are the pending directories. Then, read from the pending file and process every directory in it. If the process aborts for any reason, manually delete the lines already processed and restart. If you use a database instead of a text file, and mark entries as "done" after processing, you can avoid that last manual step and the whole process may be kept running automatically. In some cases you may want to choose the starting point at random. -- Gabriel Genellina From pmaupin at gmail.com Wed Mar 17 19:11:42 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 16:11:42 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> Message-ID: <0314849c-f748-4989-ae91-4dd42c95c251@q21g2000yqm.googlegroups.com> On Mar 17, 5:34?pm, Joaquin Abian wrote: > On Mar 17, 3:43?pm, Patrick Maupin wrote: > > > > > On Mar 17, 4:12?am, Bruno Desthuilliers > > 42.desthuilli... at websiteburo.invalid> wrote: > > > Patrick Maupin a ?crit : > > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > > >> Why not create the bound methods at instantiation time, rather than > > > >> using the descriptor protocol which has the overhead of creating a new > > > >> bound method each time the method attribute is accessed? > > > > > Well, for one thing, Python classes are open. ?They can be added to at > > > > any time. ?For another thing, you might not ever use most of the > > > > methods of an instance, so it would be a huge waste to create those. > > > > A possible optimization would be a simple memoization on first access. > > > I do agree that memoization on access is a good pattern, and I use it > > frequently. ?I don't know if I would want the interpreter > > automagically doing that for everything, though -- it would require > > some thought to figure out what the overhead cost is for the things > > that are only used once. > > > Usually, I will have a slight naming difference for the things I want > > memoized, to get the memoization code to run. ?For example, if you add > > an underbar in front of everything you want memoized: > > > class foo(object): > > > ? ? def _bar(self): > > ? ? ? ? pass > > > ? ? def __getattr__(self, aname): > > ? ? ? ? if aname.startswith('_'): > > ? ? ? ? ? ? raise AttributeError > > ? ? ? ? value = getattr(self, '_' + aname) > > ? ? ? ? self.aname = value > > ? ? ? ? return value > > > obj = foo() > > > So then the first time you look up obj.bar, it builds the bound > > method, and on subsequent accesses it just returns the previously > > bound method. > > > Regards, > > Pat > > Patrick, I was trying to understand the way your code was working but > I thing I'm not getting it. > > I tested: > > from time import time > > class foo1(object): > ? ? def _bar(self): > ? ? ? ? pass > ? ? def __getattr__(self, name): > ? ? ? ? value = getattr(self, '_' + name) > ? ? ? ? self.name = value > ? ? ? ? return value > > class foo2(object): > ? ? def bar(self): > ? ? ? ? pass > > def a(klass, count): > ? ? ins = klass() > ? ? for i in xrange(count): > ? ? ? ? z = ins.bar() > > t0 = time() > a(foo1, ?10000000) > t1 = time() > a(foo2, 10000000) > t2 = time() > > print t1-t0 ? #75 sec > print t2-t1 ? #11 sec > > foo1 is a lot slower than foo2. I understood that memoization should > optimize atribute calls. Maybe I am putting my foot in my mouth... > > Thanks > JA I don't think you are putting your foot in your mouth. I always have to test to remember what works faster and what doesn't. Usually when I memoize as I showed, it is not a simple attribute lookup, but something that takes more work to create. As I stated in my response to Terry, I overstated my case earlier, because of some optimizations in len(), I think. Nonetheless, (at least on Python 2.6) I think the advice I gave to the OP holds. One difference is that you are doing an attribute lookup in your inner loop. I do find that performance hit surprising, but to compare with what the OP is describing, you either need to look up an unbound function in a dict and call it with a parameter, or look up a bound method in a dict and call it without the parameter. Since the dict lookup doesn't usually do anything fancy and unexpected like attribute lookup, we pull the dict lookup out of the equation and out of the inner loop, and just do the comparison like this: >>> class foo(object): ... def bar(self): ... pass ... >>> x = foo() >>> >>> def a(func, count): ... for i in xrange(count): ... z=func() ... >>> def b(func, param, count): ... for i in xrange(count): ... z=func(param) ... >>> >>> a(x.bar, 100000000) # 13 seconds >>> b(foo.bar, x, 100000000) # 18 seconds Regards, Pat From lists at cheimes.de Wed Mar 17 19:16:55 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 18 Mar 2010 00:16:55 +0100 Subject: What Does sys.platform Return On 64 Bit Windows Systems? In-Reply-To: References: Message-ID: <4BA162E7.7000503@cheimes.de> Tim Daneliuk schrieb: > On older 32 bit Windows systems, sys.platform returns: 'win32' > > What does it return on 64-bit Windows systems? I'd check myself, but > I don't have access to 64-bit Windows. Do you want to know if the current build of Python is a 32 or 64bit build? >>> import struct >>> struct.calcsize("P") * 8 64 Christian From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 20:12:14 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 00:12:14 GMT Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> Message-ID: On Mon, 15 Mar 2010 16:34:35 -0700, JLundell wrote: > It's also unfortunate that Python doesn't have an approximately-equal > operator; it'd come in handy for floating-point applications while > preserving hash. If only there were a ~= or ? operator I could overload. > And ~ is unary, so no joy. Not everything needs to be a built-in, or an operator. This might be useful for you: http://code.activestate.com/recipes/577124-approximately-equal/ Feedback welcome. -- Steven From gatoygata2 at gmail.com Wed Mar 17 20:55:41 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Wed, 17 Mar 2010 17:55:41 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> <0314849c-f748-4989-ae91-4dd42c95c251@q21g2000yqm.googlegroups.com> Message-ID: On Mar 18, 12:11?am, Patrick Maupin wrote: > On Mar 17, 5:34?pm, Joaquin Abian wrote: > > > > > On Mar 17, 3:43?pm, Patrick Maupin wrote: > > > > On Mar 17, 4:12?am, Bruno Desthuilliers > > > 42.desthuilli... at websiteburo.invalid> wrote: > > > > Patrick Maupin a ?crit : > > > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > > > >> Why not create the bound methods at instantiation time, rather than > > > > >> using the descriptor protocol which has the overhead of creating a new > > > > >> bound method each time the method attribute is accessed? > > > > > > Well, for one thing, Python classes are open. ?They can be added to at > > > > > any time. ?For another thing, you might not ever use most of the > > > > > methods of an instance, so it would be a huge waste to create those. > > > > > A possible optimization would be a simple memoization on first access. > > > > I do agree that memoization on access is a good pattern, and I use it > > > frequently. ?I don't know if I would want the interpreter > > > automagically doing that for everything, though -- it would require > > > some thought to figure out what the overhead cost is for the things > > > that are only used once. > > > > Usually, I will have a slight naming difference for the things I want > > > memoized, to get the memoization code to run. ?For example, if you add > > > an underbar in front of everything you want memoized: > > > > class foo(object): > > > > ? ? def _bar(self): > > > ? ? ? ? pass > > > > ? ? def __getattr__(self, aname): > > > ? ? ? ? if aname.startswith('_'): > > > ? ? ? ? ? ? raise AttributeError > > > ? ? ? ? value = getattr(self, '_' + aname) > > > ? ? ? ? self.aname = value > > > ? ? ? ? return value > > > > obj = foo() > > > > So then the first time you look up obj.bar, it builds the bound > > > method, and on subsequent accesses it just returns the previously > > > bound method. > > > > Regards, > > > Pat > > > Patrick, I was trying to understand the way your code was working but > > I thing I'm not getting it. > > > I tested: > > > from time import time > > > class foo1(object): > > ? ? def _bar(self): > > ? ? ? ? pass > > ? ? def __getattr__(self, name): > > ? ? ? ? value = getattr(self, '_' + name) > > ? ? ? ? self.name = value > > ? ? ? ? return value > > > class foo2(object): > > ? ? def bar(self): > > ? ? ? ? pass > > > def a(klass, count): > > ? ? ins = klass() > > ? ? for i in xrange(count): > > ? ? ? ? z = ins.bar() > > > t0 = time() > > a(foo1, ?10000000) > > t1 = time() > > a(foo2, 10000000) > > t2 = time() > > > print t1-t0 ? #75 sec > > print t2-t1 ? #11 sec > > > foo1 is a lot slower than foo2. I understood that memoization should > > optimize atribute calls. Maybe I am putting my foot in my mouth... > > > Thanks > > JA > > I don't think you are putting your foot in your mouth. ?I always have > to test to remember what works faster and what doesn't. ?Usually when > I memoize as I showed, it is not a simple attribute lookup, but > something that takes more work to create. ?As I stated in my response > to Terry, I overstated my case earlier, because of some optimizations > in len(), I think. ?Nonetheless, (at least on Python 2.6) I think the > advice I gave to the OP holds. ?One difference is that you are doing > an attribute lookup in your inner loop. ?I do find that performance > hit surprising, but to compare with what the OP is describing, you > either need to look up an unbound function in a dict and call it with > a parameter, or look up a bound method in a dict and call it without > the parameter. ?Since the dict lookup doesn't usually do anything > fancy and unexpected like attribute lookup, we pull the dict lookup > out of the equation and out of the inner loop, and just do the > comparison like this: > > >>> class foo(object): > > ... ? ? def bar(self): > ... ? ? ? ? pass > ...>>> x = foo() > > >>> def a(func, count): > > ... ? ? for i in xrange(count): > ... ? ? ? ? z=func() > ...>>> def b(func, param, count): > > ... ? ? for i in xrange(count): > ... ? ? ? ? z=func(param) > ... > > > > >>> a(x.bar, ? ? ?100000000) ?# 13 seconds > >>> b(foo.bar, x, 100000000) ?# 18 seconds > > Regards, > Pat OK, Thanks. Need to play a little bit with it. Cheers JA From python at bdurham.com Wed Mar 17 22:42:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Mar 2010 22:42:46 -0400 Subject: Possible to open a file for shared write mode under Windows? Message-ID: <1268880166.3322.1365412149@webmail.messagingengine.com> Is there a way to open a file for shared write mode under Windows? I have 2 processes that will write to different regions of this shared file. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Mar 17 23:08:48 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Mar 2010 20:08:48 -0700 (PDT) Subject: os.walk restart References: Message-ID: <92b42203-876f-4383-9af6-b0ed775c3d92@w9g2000prb.googlegroups.com> Steven D'Aprano wrote: > # Untested > last_visited = open("last_visited.txt", 'r').read() > for root, dirs, files in os.walk(last_visited or basedir): > ? ? ?open("last_visited.txt", 'w').write(root) > ? ? ?run program Wouldn't this only walk the directory the exception occured in and not the remaining unwalked dirs from basedir? Something like this should work: import os basedir = '.' walked = open('walked.txt','r').read().split() unwalked = ((r,d,f) for r,d,f in os.walk(basedir) if r not in walked) for root, dirs, files in unwalked: # do something print root walked.append(root) open('walked.txt','w').write('\n'.join(walked)) From python at mrabarnett.plus.com Wed Mar 17 23:34:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Mar 2010 03:34:46 +0000 Subject: os.walk restart In-Reply-To: References: Message-ID: <4BA19F56.4020302@mrabarnett.plus.com> Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to > a file > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? I would write my own walker which sorts the directory entries it finds before walking them and can skip the entries until it gets to the desired starting path, eg if I want to start at "/foo/bar" then skip over the entries in the root directory which start with a name before "foo" and the entries in the subdirectory "/foo" which start with a name before "bar". From showell30 at yahoo.com Wed Mar 17 23:49:58 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 17 Mar 2010 20:49:58 -0700 (PDT) Subject: os.walk restart References: Message-ID: <68cbed3c-87f6-45c9-ac8e-a536cae20f26@k6g2000prg.googlegroups.com> On Mar 17, 3:04?pm, Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > ? ? run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to > a file > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? I assume it's the operation that you are doing on each file that is expensive, not the walk itself. If that's the case, then you might be able to get away with just leaving some kind of breadcrumbs whenever you've successfully processed a directory or a file, so you can quickly short-circuit entire directories or files on the next run, without having to implement any kind of complicated start-where-I-left-off before algorithm. The breadcrumbs could be hidden files in the file system, or an easy- indexable list of files that you persist, etc. What are you doing that takes so long? Also, I can understand why the operations on the files themselves might crash, but can't you catch an exception and keep on chugging? Another option, if you do not do some kind of pruning on the fly, is to persist the list of files that you need to process up front to a file, or a database, and persist the index of the last successfully processed file, so that you can restart as needed from where you left off. From steven at REMOVE.THIS.cybersource.com.au Thu Mar 18 00:04:46 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 04:04:46 GMT Subject: os.walk restart References: <92b42203-876f-4383-9af6-b0ed775c3d92@w9g2000prb.googlegroups.com> Message-ID: On Wed, 17 Mar 2010 20:08:48 -0700, alex23 wrote: > Steven D'Aprano wrote: >> # Untested >> last_visited = open("last_visited.txt", 'r').read() >> for root, dirs, files in os.walk(last_visited or basedir): >> ? ? ?open("last_visited.txt", 'w').write(root) run program > > Wouldn't this only walk the directory the exception occured in and not > the remaining unwalked dirs from basedir? Only if you have some sort of branching file hierarchy with multiple sub- directories in the one directory, instead of a nice simple linear chain of directories a/b/c/d/.../z as nature intended. *wink* Yes, good catch. I said it was untested. You might be able to save the parent of the current directory, and restart from there instead. -- Steven From gagsl-py2 at yahoo.com.ar Thu Mar 18 00:20:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 18 Mar 2010 01:20:31 -0300 Subject: Possible to open a file for shared write mode under Windows? References: <1268880166.3322.1365412149@webmail.messagingengine.com> Message-ID: En Wed, 17 Mar 2010 23:42:46 -0300, escribi?: > Is there a way to open a file for shared write mode under > Windows? > > I have 2 processes that will write to different regions of this > shared file. Using the pywin32 package at sourceforge, you have access to the CreateFile function: http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx You want dwShareMode=FILE_SHARE_WRITE -- Gabriel Genellina From sccolbert at gmail.com Thu Mar 18 00:38:56 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Mar 2010 00:38:56 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: References: <1268880166.3322.1365412149@webmail.messagingengine.com> Message-ID: <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> you could also just have one process do the writing for both processes via pipes. On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina wrote: > En Wed, 17 Mar 2010 23:42:46 -0300, escribi?: > > > Is there a way to open a file for shared write mode under >> Windows? >> >> I have 2 processes that will write to different regions of this >> shared file. >> > > Using the pywin32 package at sourceforge, you have access to the CreateFile > function: http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > You want dwShareMode=FILE_SHARE_WRITE > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Mar 18 00:52:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Mar 2010 00:52:28 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> References: <1268880166.3322.1365412149@webmail.messagingengine.com> <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> Message-ID: Chris Colbert wrote: [top-posting switched to bottom-posting] > > On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina > > wrote: > > En Wed, 17 Mar 2010 23:42:46 -0300, > escribi?: > > > Is there a way to open a file for shared write mode under > Windows? > > I have 2 processes that will write to different regions of this > shared file. > > > Using the pywin32 package at sourceforge, you have access to the > CreateFile function: > http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > You want dwShareMode=FILE_SHARE_WRITE > > you could also just have one process do the writing for both processes > via pipes. You could, but then you'd have to work out how to avoid blocking on one pipe when data was available form the other. Or is this trivially easy, and I just don't know enough about pipes? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at bdurham.com Thu Mar 18 01:15:50 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Mar 2010 01:15:50 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: References: <1268880166.3322.1365412149@webmail.messagingengine.com> Message-ID: <1268889350.21982.1365426663@webmail.messagingengine.com> Hi Gabriel, > Using the pywin32 package at sourceforge, you have access to the CreateFile function: > http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > You want dwShareMode=FILE_SHARE_WRITE Thanks - that was exactly what I was looking for. Regards, Malcolm From sccolbert at gmail.com Thu Mar 18 01:31:33 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Mar 2010 01:31:33 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: References: <1268880166.3322.1365412149@webmail.messagingengine.com> <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> Message-ID: <7f014ea61003172231m60ec154rda99c31c06d82eb6@mail.gmail.com> It's not too difficult: # subp.py import sys import time for i in range(10): sys.stdout.write('I am subprocess\n') sys.stdout.flush() # this may not be necessary time.sleep(1) # writer.py import subprocess import time subp = subprocess.Popen(['/usr/bin/python', '-u', './subp.py'], stdout=subprocess.PIPE) while True: time.sleep(1) print('I am main process.') # write this to one section of the file if subp.poll() != None: # the subprocess has terminated break stdout = subp.stdout.readline() print(stdout) # write this to the other section brucewayne at broo:~/Documents$ python ./writer.py I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. On Thu, Mar 18, 2010 at 12:52 AM, Steve Holden wrote: > Chris Colbert wrote: > [top-posting switched to bottom-posting] > > > > On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina > > > wrote: > > > > En Wed, 17 Mar 2010 23:42:46 -0300, > > escribi?: > > > > > > Is there a way to open a file for shared write mode under > > Windows? > > > > I have 2 processes that will write to different regions of this > > shared file. > > > > > > Using the pywin32 package at sourceforge, you have access to the > > CreateFile function: > > http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > > You want dwShareMode=FILE_SHARE_WRITE > > > > you could also just have one process do the writing for both processes > > via pipes. > > You could, but then you'd have to work out how to avoid blocking on one > pipe when data was available form the other. Or is this trivially easy, > and I just don't know enough about pipes? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Thu Mar 18 01:52:14 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 05:52:14 GMT Subject: Understanding the CPython dict implementation References: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Tue, 16 Mar 2010 16:04:22 -0400, Terry Reedy wrote: > On 3/16/2010 7:46 AM, Steven D'Aprano wrote: >> On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: >> >>> I found this PyCon2010 presentation to be excellent: The Mighty >>> Dictionary, Branden Craig Rhodes, 30 min. > > Sorry, > http://pycon.blip.tv/file/3332763/ > > which plays fine in FF3.6 on windows > > >>> http://pycon.blip.tv/file/3264041/ > > wrong file number > >> Unfortunately, that clip seems to be unwatchable, at least for me. It >> crashed the Netscape plugin in Konqueror, and crashed Firefox. > > The flash version does not work for me. This is true of about 1/3 of the > Pycon 2010 videos that I have tried. The .ogv version of this and all > others that I have tried (hit Download under Comments) plays fine within > FF3.6 on my windows xp machine. Perhaps there is a linux-specific bug, > if that is what you are running under. Amusingly, the FLV files play perfectly for me under Linux, while the OGV files don't :) Thanks for the links, the videos are very interesting. -- Steven From zubin.mithra at gmail.com Thu Mar 18 02:28:53 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Thu, 18 Mar 2010 11:58:53 +0530 Subject: D-Bus Message-ID: <8e7c74321003172328s2f22ae87v4c732ff3d33c094e@mail.gmail.com> Hello, I have experience writing scripts to connect to the D-Bus interface provided by different applications but have no experience writing a D-Bus interface for an application. Could someone point me in the right direction? A tutorial or a good example would be nice. Cheers!!! Zubin Mithra http://zubin71.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Thu Mar 18 03:49:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Mar 2010 20:49:55 +1300 Subject: import antigravity References: Message-ID: In message , Chris Rebert wrote: I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judgement, for which I expect an apology. Otherwise, it becomes grounds for an abuse complaint to your ISP. From stefan_ml at behnel.de Thu Mar 18 04:13:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 09:13:05 +0100 Subject: C-API PyObject_Call In-Reply-To: <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> Message-ID: moerchendiser2k3, 17.03.2010 23:35: >> 1) put the line number information into the message string when you raise >> the exception > > you mean the line and file information of the C code, right? Funny that you (being the OP) ask *me* what kind of line information *you* want. Stefan From stefan_ml at behnel.de Thu Mar 18 04:17:43 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 09:17:43 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: Lawrence D'Oliveiro, 18.03.2010 08:49: > In message, Chris > Rebert wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. I hope you just had a bad day. Threatening others for figuring out your e-mail address is even worse than posting with an illegal e-mail address. Stefan From alfps at start.no Thu Mar 18 04:53:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 18 Mar 2010 09:53:05 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Lawrence D'Oliveiro: > In message , Chris > Rebert wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Hi. Chris Rebert didn't reveal anything not already present in the posting he replied to, and indeed in the posting I'm replying to here. The headers in the article I'm replying to (yours) look like this: Path: feeder.eternal-september.org!eternal-september.org!feeder.erje.net!newsfeed.straub-nv.de!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail From: Lawrence D'Oliveiro Newsgroups: comp.lang.python Subject: Re: import antigravity Followup-To: comp.lang.python Date: Thu, 18 Mar 2010 20:49:55 +1300 Organization: Geek Central Lines: 7 Message-ID: References: NNTP-Posting-Host: 118-92-14-26.dsl.dyn.ihug.co.nz Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: lust.ihug.co.nz 1268898595 20084 118.92.14.26 (18 Mar 2010 07:49:55 GMT) X-Complaints-To: abuse at ihug.co.nz NNTP-Posting-Date: Thu, 18 Mar 2010 07:49:55 +0000 (UTC) User-Agent: KNode/4.3.4 Xref: eternal-september.org comp.lang.python:51777 One must assume that you were not aware that you're posting your mail address in plaintext in every article? Cheers & hth., - Alf From mail at timgolden.me.uk Thu Mar 18 04:54:58 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 18 Mar 2010 08:54:58 +0000 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: <4fr777-43o2.ln1@ozzie.tundraware.com> References: <3rl777-q1m2.ln1@ozzie.tundraware.com> <4fr777-43o2.ln1@ozzie.tundraware.com> Message-ID: <4BA1EA62.1010401@timgolden.me.uk> On 17/03/2010 20:43, Tim Daneliuk wrote: > The intent is just to provide as similar as possible a user experience. >> From a coding POV, it is surely simpler to just use 'winuser' and 'wingroup', > but I am sort of philosophically wired to not throw information away if > it's a available from the OS. It's hardly worth disputing I suppose, but I would argue that simply presenting the owner & group of a file in Windows is actually doing a disservice to the user of the app. It's cluttering up the display with information which is essentially useless. Pretty much the only time I ever look at a file owner is when I have some knotty security issue and I need to assess who might have WRITE_DAC permission. The group - never; it really is a relic. The file owner & group simply don't play the same role in Windows security that they do in *nix. The trouble is that there isn't a simple alternative: most files, even with default security, will have two or three groups involved in their security at different levels. > BTW, wanna beta test a really cool CLI mass file renaming tool????? ;) Sure -- I'll have a look. But I can't promise any great amount of time at present :) TJG From clp2 at rebertia.com Thu Mar 18 04:56:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Mar 2010 01:56:49 -0700 Subject: Recall: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C839@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C839@enbmail01.lsi.com> Message-ID: <50697b2c1003180156q61786c48i122e63caa94514bd@mail.gmail.com> On Tue, Mar 16, 2010 at 4:56 AM, Barak, Ron wrote: > Barak, Ron would like to recall the message, "How to add a library path to pythonpath ?". Good luck with that. :) - Chris From stefan_ml at behnel.de Thu Mar 18 05:19:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 10:19:59 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: Alf P. Steinbach, 18.03.2010 09:53: > > Path: > feeder.eternal-september.org!eternal-september.org!feeder.erje.net!newsfeed.straub-nv.de!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail > > From: Lawrence D'Oliveiro > Newsgroups: comp.lang.python > Subject: Re: import antigravity > Followup-To: comp.lang.python > Date: Thu, 18 Mar 2010 20:49:55 +1300 > Organization: Geek Central > Lines: 7 > Message-ID: > References: > > NNTP-Posting-Host: 118-92-14-26.dsl.dyn.ihug.co.nz > Mime-Version: 1.0 > Content-Type: text/plain; charset="ISO-8859-1" > Content-Transfer-Encoding: 7Bit > X-Trace: lust.ihug.co.nz 1268898595 20084 118.92.14.26 (18 Mar 2010 > 07:49:55 GMT) > X-Complaints-To: abuse at ihug.co.nz > NNTP-Posting-Date: Thu, 18 Mar 2010 07:49:55 +0000 (UTC) > User-Agent: KNode/4.3.4 > Xref: eternal-september.org comp.lang.python:51777 > > > > One must assume that you were not aware that you're posting your mail > address in plaintext in every article? Uhm - where? Stefan From news1234 at free.fr Thu Mar 18 05:20:38 2010 From: news1234 at free.fr (News123) Date: Thu, 18 Mar 2010 10:20:38 +0100 Subject: did anybody play with python and window mobile broadband? Message-ID: <4ba1f067$0$4589$426a74cc@news.free.fr> Hi, I'd like to use a mobile broadband device with a windows python app. Did anybody play already with python and the window mobile broadband interface? I'm looking for examples: - how to connect/disconnect a mobile broadband device (currently I use rasdial. not sure it's the best solution) - to obtain the device's current mode (GPRS / EDGE / . . . ) - to obtain the current signal level Thanks a lot for any pointers N From sanjiva at croatia.oracle.in Thu Mar 18 05:26:24 2010 From: sanjiva at croatia.oracle.in (Sanjiva P.) Date: Thu, 18 Mar 2010 10:26:24 +0100 Subject: did anybody play with python and window mobile broadband? References: <4ba1f067$0$4589$426a74cc@news.free.fr> Message-ID: On 03/18/2010 10:20 AM, News123 wrote: > I'm looking for examples: > - how to connect/disconnect a mobile broadband device (currently I use > rasdial. not sure it's the best solution) > - to obtain the device's current mode (GPRS / EDGE / . . . ) > - to obtain the current signal level > > Thanks a lot for any pointers Well no examples,but most or all of it should work through AT commands. Did you try plugging the mobile broadband interface in? From alfps at start.no Thu Mar 18 05:29:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 18 Mar 2010 10:29:04 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Stefan Behnel: > Alf P. Steinbach, 18.03.2010 09:53: >> >> Path: >> feeder.eternal-september.org!eternal-september.org!feeder.erje.net!newsfeed.straub-nv.de!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail >> >> >> From: Lawrence D'Oliveiro >> Newsgroups: comp.lang.python >> Subject: Re: import antigravity >> Followup-To: comp.lang.python >> Date: Thu, 18 Mar 2010 20:49:55 +1300 >> Organization: Geek Central >> Lines: 7 >> Message-ID: >> References: >> >> NNTP-Posting-Host: 118-92-14-26.dsl.dyn.ihug.co.nz >> Mime-Version: 1.0 >> Content-Type: text/plain; charset="ISO-8859-1" >> Content-Transfer-Encoding: 7Bit >> X-Trace: lust.ihug.co.nz 1268898595 20084 118.92.14.26 (18 Mar 2010 >> 07:49:55 GMT) >> X-Complaints-To: abuse at ihug.co.nz >> NNTP-Posting-Date: Thu, 18 Mar 2010 07:49:55 +0000 (UTC) >> User-Agent: KNode/4.3.4 >> Xref: eternal-september.org comp.lang.python:51777 >> >> >> >> One must assume that you were not aware that you're posting your mail >> address in plaintext in every article? > > Uhm - where? Well, at least the one that Chris Rebert quoted, (in the 'From:' header). The point is, if he's upset about Chris quoting that, then he's probably unaware that he's posting it in plaintext himself. Cheers, - Alf From jpiitula at ling.helsinki.fi Thu Mar 18 05:42:30 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Mar 2010 11:42:30 +0200 Subject: import antigravity References: Message-ID: Alf P. Steinbach writes: > The point is, if he's upset about Chris quoting that, then he's > probably unaware that he's posting it in plaintext himself. The complaint was not about quoting but about using in public. Chris sent his piece to three addresses. From his headers, redacted: Newsgroups: comp.lang.python To: "Lawrence D'Oliveiro" Cc: python-list at python.org Can we stop importing red herrings now? From 2ennel.0569 at gmail.com Thu Mar 18 05:54:16 2010 From: 2ennel.0569 at gmail.com (LALITHA N) Date: Thu, 18 Mar 2010 02:54:16 -0700 (PDT) Subject: ARE YOU ARE FAMILIAR WITH ANY COMPUTER LANGUAGE-GET GOOD LUCK Message-ID: <08d44b50-e96a-464f-9645-ce35b17eb1ab@t9g2000prh.googlegroups.com> http://123maza.com/75/expressions From alfps at start.no Thu Mar 18 06:04:21 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 18 Mar 2010 11:04:21 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Jussi Piitulainen: > Alf P. Steinbach writes: > >> The point is, if he's upset about Chris quoting that, then he's >> probably unaware that he's posting it in plaintext himself. > > The complaint was not about quoting but about using in public. Chris > sent his piece to three addresses. From his headers, redacted: > > Newsgroups: comp.lang.python > To: "Lawrence D'Oliveiro" > Cc: python-list at python.org > > Can we stop importing red herrings now? Oh, I didn't see that -- it's Bad Practice so I didn't look for it. Cheers, - Alf From eglyph at gmail.com Thu Mar 18 06:07:22 2010 From: eglyph at gmail.com (eglyph at gmail.com) Date: Thu, 18 Mar 2010 03:07:22 -0700 (PDT) Subject: did anybody play with python and window mobile broadband? References: <4ba1f067$0$4589$426a74cc@news.free.fr> Message-ID: <9fa65dc9-e9fc-4a35-a796-2e56980b63ac@t23g2000yqt.googlegroups.com> On 18 ???, 11:20, News123 wrote: > I'd like to use a mobile broadband device with a windows python app. > Did anybody play already with python and the window mobile broadband > interface? > There was a discussion on this subject in some local forum recently. I assume you're using PythonCE, right? The best solution proposed there was to use ctypes and WinAPI. You can find a relatively high level APIs to set up a connection (without need to go too low level with AT commands) and make your own wrapper. A good starting point can be found here: http://msdn.microsoft.com/en-us/library/bb416346.aspx (it's not the only way to to things, btw). -- regards, eGlyph From eglyph at gmail.com Thu Mar 18 06:19:55 2010 From: eglyph at gmail.com (eglyph at gmail.com) Date: Thu, 18 Mar 2010 03:19:55 -0700 (PDT) Subject: url2lib (windows 7) does not notice when network reconnects (getaddrinfo problem) References: <4ba15c0d$0$15456$426a74cc@news.free.fr> Message-ID: <46a27485-cbe9-48e1-9055-f7d4d0d20785@u9g2000yqb.googlegroups.com> On 18 ???, 00:47, News123 wrote: > Hi, > > I'd like to write a function, that knows when the 'internet' is reachable. > > My setup is a windows7 host with a wireless USB modem. The modem might > connect / disconnect any time. > > I thought I write a small function just checking whether I can fetch a url. > ######### script starts > import time,urllib2 > > myurl = "http://www.mysite.com" # or "www.google.com" or whatever you like > > while True: > ? ? connected = False > ? ? try: > ? ? ? ? urllib2.urlopen(myurl) > ? ? ? ? connected = True > ? ? except urllib2.URLError as e: > ? ? ? ? print "urlerr %s" % e > ? ? print "connected",connected > ? ? time.sleep(1) > ########## end of script > > if the network is connected when I start the script the first time after > reboot, then ?I receive> connected True > > As expected > > If the network is disconnected when I start the script the first time > after reboot, then ?I receive> urlerr > > connected False > > as expected > > Things are getting weired, when my USB wireless modem connects after > I started my script: > > It happens, that I just continue to receive: > > > urlerr > > connected False > > however when I use a windows cmd window and I start > "pingwww.mysite.com", then my python script recovers and reports > > > connected True > > My perhaps false conclusion is, that getaddrinfo() is not retrying to > resolve an IP address, when it failed once. > > Is this behaviour known? Can this really be possible? > I can reproduce this issue. not every time, but rather often. > > If yes, is there any way to force a new host name lookup under windows? > > What else could I be doing wrong? > > Thanks a lot in advance for any ideas > > N Actually this should be expected behavior. Windows establishes connection automatically when you start pinging something, your script doesn't. Just check the connection state with winapi (ctypes? pywin32?) and establish it if it isn't already. -- regards, eGlyph From sparks.m at gmail.com Thu Mar 18 06:21:08 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Thu, 18 Mar 2010 03:21:08 -0700 (PDT) Subject: Nested Scopes unintended behaviour ? References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Message-ID: <921f09da-bf41-4306-aca5-19baa70dd2b2@e7g2000yqf.googlegroups.com> On Mar 17, 8:29?pm, Terry Reedy wrote: > On 3/17/2010 11:44 AM, Emile van Sebille wrote: > > > On 3/17/2010 8:16 AM Michael Sparks said... > >> Hi, > > >> Is the following behaviour expected ? > > > In short, yes. Assignment within a function forces the variable to > > locals. > > In 3.x, one can declare names to be nonlocal (ie, local to some outer > function, as opposed to local to the current function or module global). > In your case, > ? ?nonlocal on > in your inner swtchfun function would give the behavior you wanted. Ah, excellent. That makes python closures work more like I'd expect them to. (A colleague had written the swtchfun I posted, whereas the generator form was the version I wrote, and he was puzzled as to why it didn't work as he expected. When I saw it I also couldn't see why. After hearing it's expected behaviour in 2.6 it's clear that assigning a name to a value declares the variable to be local, and that unlike much of python (but like yield) this appears based on static analysis of the function declaration, rather than dynamic. This does also make sense since it prevents a name "switching scope" in a function, and a "nonlocal" keyword also makes sense as a result. Thanks to Emile for pointing out you can also do this in 2.6: def Toggler(F, B): print F("Hello") print F("Hello") print F("Hello") print F("Hello") print F("Hello") def Switcher(A,B): enclose={"on" : True} def swtchfun(msg, enclose=enclose): if enclose["on"]: enclose["on"] = False print "Switched to A" return A else: enclose["on"] = True print "Switched to B" return B # return Toggler(swtchfun,True) Switcher(1,2) I think personally I'd use the generator form myself, since I think it's clearer (more clearly loops between the two), but this may be a useful thing to know occasionally. Cheers :-) Michael. From python.list at tim.thechases.com Thu Mar 18 06:25:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Mar 2010 05:25:19 -0500 Subject: os.walk restart In-Reply-To: <68cbed3c-87f6-45c9-ac8e-a536cae20f26@k6g2000prg.googlegroups.com> References: <68cbed3c-87f6-45c9-ac8e-a536cae20f26@k6g2000prg.googlegroups.com> Message-ID: <4BA1FF8F.8080402@tim.thechases.com> Steve Howell wrote: > If that's the case, then you might be able to get away with just > leaving some kind of breadcrumbs whenever you've successfully > processed a directory or a file, Unless you're indexing a read-only device (whether hardware read-only like a CD, or permission-wise read-only like a network share or a non-priv user walking system directories)... > Also, I can understand why the operations on the files themselves > might crash, but can't you catch an exception and keep on chugging? I also wondered this one, perhaps logging the directory in which the exception happened to later revisit. :) -tkc From steve at holdenweb.com Thu Mar 18 07:31:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Mar 2010 07:31:46 -0400 Subject: import antigravity In-Reply-To: References: Message-ID: Jussi Piitulainen wrote: > Alf P. Steinbach writes: > >> The point is, if he's upset about Chris quoting that, then he's >> probably unaware that he's posting it in plaintext himself. > > The complaint was not about quoting but about using in public. Chris > sent his piece to three addresses. From his headers, redacted: > > Newsgroups: comp.lang.python > To: "Lawrence D'Oliveiro" > Cc: python-list at python.org > > Can we stop importing red herrings now? Surely the point of such an obvious obfuscation is that humans can de-obfuscate is easily. The fact that it was then used in an open newsgroup communication is just part of the shit that happens every day. Complaining to Chris's ISP is unlikely to be anything other than a waste of time. Drawing attention to it the way Lawrence did is much more likely to draw attention to it that simply gracefully letting it pass. Lawrence, if you are so worried perhaps you should consider not using e-mail any more. It's clearly too dangerous to suit you. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Thu Mar 18 07:52:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 11:52:08 GMT Subject: import antigravity References: Message-ID: <4ba213e8$0$27806$c3e8da3@news.astraweb.com> On Thu, 18 Mar 2010 09:17:43 +0100, Stefan Behnel wrote: > Lawrence D'Oliveiro, 18.03.2010 08:49: >> In message, Chris >> Rebert wrote: >> >> I see that you published my unobfuscated e-mail address on USENET for >> all to see. I obfuscated it for a reason, to keep the spammers away. >> I'm assuming this was a momentary lapse of judgement, for which I >> expect an apology. Otherwise, it becomes grounds for an abuse complaint >> to your ISP. > > I hope you just had a bad day. Threatening others for figuring out your > e-mail address is even worse than posting with an illegal e-mail > address. No, this is hardly the first time that Lawrence has made such a wankerific threat: http://www.mail-archive.com/python-list%40python.org/msg245012.html I sympathise, because many years ago I lost an email address, made unusable by spam, after using it unobfuscated in Usenet. But I think that the spammers have mostly moved on these days. The pickings are much richer for hijacking people's address books in Hotmail, Facebook or Outlook, and the state of the art of anti-spam is better too. So I think that Lawrence needs to HTFU and stop making empty threats over something so trivial. -- Steven From robin at reportlab.com Thu Mar 18 08:06:16 2010 From: robin at reportlab.com (Robin Becker) Date: Thu, 18 Mar 2010 12:06:16 +0000 Subject: bug in bdist_wininst cross compile? In-Reply-To: References: <4BA0E958.8050205@chamonix.reportlab.co.uk> Message-ID: <4BA21738.9070307@chamonix.reportlab.co.uk> On 17/03/2010 21:37, Gabriel Genellina wrote: > En Wed, 17 Mar 2010 11:38:16 -0300, Robin Becker > escribi?: > >> has anyone had any success with cross compilation and bdist_wininst; I >> have modified build_ext very slightly to fix a small bug in cross >> compilation related to library order. > > Please post your bug report + patch at http://bugs.python.org or it will > be lost. > OK done -- Robin Becker From królewna at ee.pl Thu Mar 18 08:58:32 2010 From: królewna at ee.pl (=?UTF-8?B?a3LDs2xld25h?=) Date: Thu, 18 Mar 2010 13:58:32 +0100 Subject: sqlite3, memory db and multithreading Message-ID: The problem is simple: I have multiple threads within one program. At least 2 threads have to have access to in-memory sqlite database. It is not possible to pass sqlite objects to those threads because an exception is rised: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id -1219066176 and this is thread id -1224475792 Is there any EASY way to use this in-memory db in many threads? Creating another connection is not a solution as it creates completely new db instead of connecting to the existing one. -- Best regards princess From christian at dowski.com Thu Mar 18 09:40:59 2010 From: christian at dowski.com (Christian) Date: Thu, 18 Mar 2010 06:40:59 -0700 (PDT) Subject: Feeding differeent data types to a class instance? References: <3189fde6-bd5e-4ee2-8a8e-41c55cf9f926@q23g2000yqd.googlegroups.com> Message-ID: <72c18de4-0161-435f-a083-01d69151323a@x1g2000prb.googlegroups.com> On Mar 14, 2:16?pm, kuru wrote: > Hi > > Thank you so much for all these great suggestions. I will have time > today to try all these and see which one works best for me Answers to your question have spread onto the Python blogosphere as well. http://pythonconquerstheuniverse.wordpress.com/2010/03/17/multiple-constructors-in-a-python-class/ http://blog.dowski.com/2010/03/17/my-take-on-multiple-constructors/ That second one is my response. Christian From tundra at tundraware.com Thu Mar 18 09:43:14 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Thu, 18 Mar 2010 08:43:14 -0500 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: <3rl777-q1m2.ln1@ozzie.tundraware.com> <4fr777-43o2.ln1@ozzie.tundraware.com> Message-ID: On 3/18/2010 3:54 AM, Tim Golden wrote: > On 17/03/2010 20:43, Tim Daneliuk wrote: >> The intent is just to provide as similar as possible a user experience. >>> From a coding POV, it is surely simpler to just use 'winuser' and >>> 'wingroup', >> but I am sort of philosophically wired to not throw information away if >> it's a available from the OS. > > It's hardly worth disputing I suppose, but I would argue that simply > presenting the owner & group of a file in Windows is actually doing > a disservice to the user of the app. It's cluttering up the display > with information which is essentially useless. Pretty much the only > time I ever look at a file owner is when I have some knotty security > issue and I need to assess who might have WRITE_DAC permission. The > group - never; it really is a relic. > > The file owner & group simply don't play the same role in Windows > security that they do in *nix. The trouble is that there isn't a > simple alternative: most files, even with default security, will > have two or three groups involved in their security at different > levels. > >> BTW, wanna beta test a really cool CLI mass file renaming tool????? ;) > > Sure -- I'll have a look. But I can't promise any great amount of > time at present :) > > TJG > I will announce the Beta for 'tren' here and you (and anyone else) can have at it. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From chris at simplistix.co.uk Thu Mar 18 09:44:53 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Mar 2010 13:44:53 +0000 Subject: converting a timezone-less datetime to seconds since the epoch In-Reply-To: <50697b2c1003160713x7641d2cfn52a5e5ca199e26de@mail.gmail.com> References: <4B9F8BE0.2050808@simplistix.co.uk> <50697b2c1003160713x7641d2cfn52a5e5ca199e26de@mail.gmail.com> Message-ID: <4BA22E55.9040006@simplistix.co.uk> Hey Chris, Chris Rebert wrote: >> def timestamp(dttm): >> return time.mktime(dttm.timetuple()) > > from calendar import timegm > > def timestamp(dttm): > return timegm(dttm.utctimetuple()) > #the *utc*timetuple change is just for extra consistency > #it shouldn't actually make a difference here Ah, right. What on earth is timegm doing in calendar? No way I ever would have thought to look there... I wonder what the best way to get this stuff documented in the datetime modules docs is? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From googler.1.webmaster at spamgourmet.com Thu Mar 18 09:58:00 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 18 Mar 2010 06:58:00 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> Message-ID: <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> > Funny that you (being the OP) ask *me* what kind of line information *you* > want. > > Stefan Well, I need the line/file information of Python : From 1 at depikt.net Thu Mar 18 10:24:52 2010 From: 1 at depikt.net (DreiJane) Date: Thu, 18 Mar 2010 07:24:52 -0700 (PDT) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> <4B9A9624.7040200@v.loewis.de> <8aa22e57-f152-4dc7-88da-cf6879de41f7@q16g2000yqq.googlegroups.com> Message-ID: Hello, i've used reportlabs over two years now and was content with its quality. These days i have turned to cairo and can only recommend to do so: It is still easier to use (than the well-designed reportlabs tools) and an engine working in a lot of other software too, for example firefox. Reasons for this: reportlabs do not even answer question about the date to upgrade to Python3. Since Platypus isn't complete, i had to do a lot with the primitves in the canvas object after all - that part of my code got even shorter with cairo. For me - working with pygtk - that spares two installations also. To repear myself: I love cairo. Regards, Joost From alt.mcarter at googlemail.com Thu Mar 18 10:45:54 2010 From: alt.mcarter at googlemail.com (Mark Carter) Date: Thu, 18 Mar 2010 07:45:54 -0700 (PDT) Subject: Install 2.6.4 as non-admin on Windows Message-ID: <60c2ac2f-0472-4790-a879-533845bcedb5@q16g2000yqq.googlegroups.com> How do I install python 2.6.4 on Windows without admin privileges? Can I install it on a machine I control, zip up the contents, copy it across to an admin-restricted machine, and set up a couple of environemtn variables? Does python install files to system directories, making this impossible? From 1 at depikt.net Thu Mar 18 10:49:29 2010 From: 1 at depikt.net (DreiJane) Date: Thu, 18 Mar 2010 07:49:29 -0700 (PDT) Subject: sqlite3, memory db and multithreading References: Message-ID: <57dc1ce8-1ac7-4d72-aafc-6fe7920144c2@c16g2000yqd.googlegroups.com> Hello, i cannot help you directly with sqlite2 in the Standardlib, since i am used to work with Roger Binns's apsw. After a short experiment with pysqlite leading to data loss - caused by one of the unclearer exception messages of sqlite3 and me having a bad day - i at once turned back to apsw. And so far i haven't done much with threads. Principally sqlite connections (sqlite3 objects in the C-API) can be used over multiple threads - and connections to :memory: make no difference. There are additional parameters to open() giving fine- tuned control. And apsw is promising a true reflection of sqlite's C- API. Regards, Joost From eglyph at gmail.com Thu Mar 18 11:23:44 2010 From: eglyph at gmail.com (eglyph at gmail.com) Date: Thu, 18 Mar 2010 08:23:44 -0700 (PDT) Subject: Install 2.6.4 as non-admin on Windows References: <60c2ac2f-0472-4790-a879-533845bcedb5@q16g2000yqq.googlegroups.com> Message-ID: <3ab6c32c-3516-407c-8f89-da666fed86a5@z11g2000yqz.googlegroups.com> On 18 ???, 16:45, Mark Carter wrote: > How do I install python 2.6.4 on Windows without admin privileges? > > Can I install it on a machine I control, zip up the contents, copy it > across to an admin-restricted machine, and set up a couple of > environemtn variables? Does python install files to system > directories, making this impossible? The only file written to a system folder is python2x.dll (I think it's not true for python2.6 any longer), so your approach is perfectly valid if you can put this dll into a folder where it can be found by the system. PortablePython does this almost the same. -- regards, eGlyph From alt.mcarter at googlemail.com Thu Mar 18 11:36:11 2010 From: alt.mcarter at googlemail.com (Mark Carter) Date: Thu, 18 Mar 2010 08:36:11 -0700 (PDT) Subject: Install 2.6.4 as non-admin on Windows References: <60c2ac2f-0472-4790-a879-533845bcedb5@q16g2000yqq.googlegroups.com> <3ab6c32c-3516-407c-8f89-da666fed86a5@z11g2000yqz.googlegroups.com> Message-ID: <99e3568c-0d48-46da-8483-6726b9cc9f58@l25g2000yqd.googlegroups.com> On 18 Mar, 15:23, "egl... at gmail.com" wrote: > The only file written to a system folder is python2x.dll (I think it's > not true for python2.6 any longer), so your approach is perfectly > valid if you can put this dll into a folder where it can be found by > the system. Thanks. That sounds easy enough to do. I guess it's the same deal with win32all. From filip.popravi.stojmenovic at fer.hr Thu Mar 18 12:17:11 2010 From: filip.popravi.stojmenovic at fer.hr (drstoka) Date: Thu, 18 Mar 2010 17:17:11 +0100 Subject: Need to create subprocess... Message-ID: Hello, I have to run a program as a child process inside my python program and redirect it's output through a pipe to a parent program process. So, I wrote this: pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout and it works great. Now, in parent program I need to wait for a some time and if a child (example_program) does not finish in that time, kill the child. How do I do that? Please help. From sccolbert at gmail.com Thu Mar 18 12:28:53 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Mar 2010 12:28:53 -0400 Subject: C++ code generation In-Reply-To: <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> References: <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> Message-ID: <7f014ea61003180928q4763a819ic548364e2811952d@mail.gmail.com> I think Stefan was telling you, in a nice way, to stop spamming every thread about code generation with a plug for your project. 2010/3/17 CHEN Guang > >> ----- Original Message ----- > >> From: "Dan Goodman" > >> > >>> I'm doing some C++ code generation using Python, and would be > interested > >>> in any comments on the approach I'm taking. > >> > >> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not > C++) > > > > It would be nice if you could start reading the posts before you answer, > > and then try to give an answer that fits the question. > > > > Stefan > > I have read the post, may be I lost some words and made you misunderstand. > I meant: > PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not > C++), if you find it useful, > welcome to take a look. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.arnold at sas.com Thu Mar 18 12:38:34 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 18 Mar 2010 12:38:34 -0400 Subject: multiprocessing on freebsd References: Message-ID: "Martin P. Hellwig" wrote in message news:hnrabj$c4v$1 at news.eternal-september.org... > On 03/17/10 13:30, Tim Arnold wrote: >> Hi, >> I'm checking to see if multiprocessing works on freebsd for any >> version of python. My server is about to get upgraded from 6.3 to 8.0 >> and I'd sure like to be able to use multiprocessing. >> >> I think the minimal test would be: >> --------------------- >> import multiprocessing >> q = multiprocessing.Queue() >> --------------------- >> >> with 6.3, I get >> >> File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line >> 212, in Queue >> from multiprocessing.queues import Queue >> File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, >> in >> from multiprocessing.synchronize import Lock, BoundedSemaphore, >> Semaphore, Condition >> File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line >> 33, in >> " function, see issue 3770.") >> ImportError: This platform lacks a functioning sem_open >> implementation, therefore, the required synchronization primitives >> needed will not function, see issue 3770. >> > > Build mine from ports, with the following options (notice SEM & PTH): > [martin at aspire8930 /usr/home/martin]$ cat /var/db/ports/python26/options > # This file is auto-generated by 'make config'. > # No user-servicable parts inside! > # Options for python26-2.6.4 > _OPTIONS_READ=python26-2.6.4 > WITH_THREADS=true > WITHOUT_HUGE_STACK_SIZE=true > WITH_SEM=true > WITH_PTH=true > WITH_UCS4=true > WITH_PYMALLOC=true > WITH_IPV6=true > WITHOUT_FPECTL=true > > [martin at aspire8930 /usr/home/martin]$ uname -a > FreeBSD aspire8930 8.0-STABLE FreeBSD 8.0-STABLE #3: Wed Feb 3 17:01:18 > GMT 2010 martin at aspire8930:/usr/obj/usr/src/sys/ASPIRE8930 amd64 > [martin at aspire8930 /usr/home/martin]$ python > Python 2.6.4 (r264:75706, Mar 17 2010, 18:44:24) > [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. > >>> import multiprocessing as mp > >>> queue = mp.Queue() > >>> > > hth > -- > mph Hi Martin, thanks very much for posting that. All I can say is YAY! I'm really looking forward to my machine's upgrade now! thanks, --Tim From stefan_ml at behnel.de Thu Mar 18 12:43:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 17:43:28 +0100 Subject: C-API PyObject_Call In-Reply-To: <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: moerchendiser2k3, 18.03.2010 14:58: >> Funny that you (being the OP) ask *me* what kind of line information *you* >> want. >> >> Stefan > > Well, I need the line/file information of Python : Then please explain what kind of Python line number you expect to find in C code. Hint: providing details often results in getting helpful answers. Stefan From jjposner at optimum.net Thu Mar 18 12:48:35 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 18 Mar 2010 12:48:35 -0400 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> <4B97B092.4060901@optimum.net> Message-ID: <4BA25963.1060802@optimum.net> On 3/10/2010 8:37 PM, Gabriel Genellina wrote: > En Wed, 10 Mar 2010 11:45:38 -0300, John Posner > escribi?: > >> As I promised/threatened, here's the *start* of a write-up on >> properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'd use 'function' instead of 'procedure', as this last word is very > uncommon in Python literature (also, "the procedure's return value..." may > look very strange to some people). I was trying to avoid the function-vs-method swamp, and so I used "procedure". I agree that it was an unfortunate strategy. In a rewrite, I'm using "function" for the most part > > I'm unsure if one should make a distinction 'storage attribute' vs. > 'method attribute', or even if it makes things actually more clear. Agreed -- I was trying too hard to be helpful, and introduced unnecessary terminology. > ... I > think you could present the motivating idea first ("I want to execute some > code when accessing an attribute") and only later talk about properties That was my intention. I hope it comes across more clearly in the rewrite. > and descriptors (as written, the reader still doesn't know how to define a > simple property and you've already talked about deleting attributes...) That doesn't bother me. It's OK to describe capabilities -- but not give how-to's -- in an overview section. And Edward Cherlin wrote: > I find that it will explain things to those who already understand > most of the concepts. However, I felt as though I were being led > through a maze without knowing where we were headed. ... > Who is your expected audience? I was headed toward having the reader *really* understand the @property decorator. And I was intending that reader to be a non-advanced Python user -- say, at the CS 101 level. I'm now convinced that such a goal was "a bridge too far". It has a lot moving parts, including a prerequisite that is a major topic in itself -- the descriptor protocol. That puts the goal way beyond reach. There's another draft at: http://www.jjposner.net/media/python-properties-0318.pdf Many thanks for your comments, John From martin.hellwig at dcuktec.org Thu Mar 18 13:25:33 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 18 Mar 2010 17:25:33 +0000 Subject: Need to create subprocess... In-Reply-To: References: Message-ID: On 03/18/10 16:17, drstoka wrote: > Hello, > > I have to run a program as a child process inside my python program and > redirect it's output through a pipe to a parent program process. > So, I wrote this: > > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout > > and it works great. > > Now, in parent program I need to wait for a some time and if a child > (example_program) does not finish in that time, kill the child. > > How do I do that? Please help. > > Try searching around for "threading.thread python" it should give you some clues, if you can't work through the info (it can be a bit hard to digest), just post here an example of your test code along with what you expected and what didn't happen. -- mph From pmaupin at gmail.com Thu Mar 18 13:30:01 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 18 Mar 2010 10:30:01 -0700 (PDT) Subject: Need to create subprocess... References: Message-ID: <7f37f154-e3f1-4666-8298-0bf352ebc480@r1g2000yqj.googlegroups.com> On Mar 18, 11:17?am, "drstoka" wrote: > Hello, > > I have to run a program as a child process inside my python program and > redirect it's output through a pipe to a parent program process. > So, I wrote this: > > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout > > and it works great. > > Now, in parent program I need to wait for a some time and if a child > (example_program) does not finish in that time, kill the child. > > How do I do that? Please help. I have a module that does this and more, but it only works on Linux: http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/execmgr.py For usage examples, you can just execute it. Also, see autotest.py in the same directory. Regards, Pat From jlundell at pobox.com Thu Mar 18 14:01:18 2010 From: jlundell at pobox.com (JLundell) Date: Thu, 18 Mar 2010 11:01:18 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> Message-ID: <25fb9401-74df-44fd-bc91-796a6b128151@a31g2000prd.googlegroups.com> On Mar 17, 5:12?pm, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 16:34:35 -0700,JLundellwrote: > > It's also unfortunate that Python doesn't have an approximately-equal > > operator; it'd come in handy for floating-point applications while > > preserving hash. If only there were a ~= or ? operator I could overload. > > And ~ is unary, so no joy. > > Not everything needs to be a built-in, or an operator. This might be > useful for you: > > http://code.activestate.com/recipes/577124-approximately-equal/ > > Feedback welcome. > > -- > Steven Thanks, Steven. I'd considered and rejected that a while ago, but on reconsideration it's sounding like a better idea. Aside from preserving the semantics of =, it makes the use of approximate equality explicit in the code, and that's a plus for what I'm doing. I'll give it a shot. From news1234 at free.fr Thu Mar 18 15:29:37 2010 From: news1234 at free.fr (News123) Date: Thu, 18 Mar 2010 20:29:37 +0100 Subject: did anybody play with python and window mobile broadband? In-Reply-To: References: <4ba1f067$0$4589$426a74cc@news.free.fr> Message-ID: <4ba27f21$0$23458$426a74cc@news.free.fr> Hi Sanjiva, Sanjiva P. wrote: > On 03/18/2010 10:20 AM, News123 wrote: >> I'm looking for examples: >> - how to connect/disconnect a mobile broadband device (currently I use >> rasdial. not sure it's the best solution) >> - to obtain the device's current mode (GPRS / EDGE / . . . ) >> - to obtain the current signal level >> >> Thanks a lot for any pointers > > Well no examples,but most or all of it should work through AT commands. Thanks, yes AT commands would be fine. How can I send AT commands, while another application / connection mnager is using the modem? I just don't know how to send AT commands to a connected modem. > > Did you try plugging the mobile broadband interface in? What do you mean with pluggging in? ctypes? or something else? bye N From news1234 at free.fr Thu Mar 18 15:32:23 2010 From: news1234 at free.fr (News123) Date: Thu, 18 Mar 2010 20:32:23 +0100 Subject: did anybody play with python and window mobile broadband? In-Reply-To: <9fa65dc9-e9fc-4a35-a796-2e56980b63ac@t23g2000yqt.googlegroups.com> References: <4ba1f067$0$4589$426a74cc@news.free.fr> <9fa65dc9-e9fc-4a35-a796-2e56980b63ac@t23g2000yqt.googlegroups.com> Message-ID: <4ba27fc7$0$23458$426a74cc@news.free.fr> Hy Eglyph, eglyph at gmail.com wrote: > On 18 ???, 11:20, News123 wrote: >> I'd like to use a mobile broadband device with a windows python app. >> Did anybody play already with python and the window mobile broadband >> interface? >> > > There was a discussion on this subject in some local forum recently. I > assume you're using PythonCE, right? No I'm using C-Python on a small windows PC (Atom) with a USB Boradband modem. Could you forward me the discussion in case you remember the forum? > > The best solution proposed there was to use ctypes and WinAPI. You can > find a relatively high level APIs to set up a connection (without need > to go too low level with AT commands) and make your own wrapper. > > A good starting point can be found here: http://msdn.microsoft.com/en-us/library/bb416346.aspx > (it's not the only way to to things, btw). Thanks, I'll read into it. bye N From wingusr at gmail.com Thu Mar 18 15:36:20 2010 From: wingusr at gmail.com (TP) Date: Thu, 18 Mar 2010 12:36:20 -0700 Subject: highlight words by regex in pdf files using python In-Reply-To: <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> References: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> Message-ID: On Wed, Mar 17, 2010 at 7:53 AM, Peng Yu wrote: > On Tue, Mar 16, 2010 at 11:12 PM, Patrick Maupin wrote: >> On Mar 4, 6:57?pm, Peng Yu wrote: >>> I don't find a general pdf library in python that can do any >>> operations on pdfs. >>> >>> I want to automatically highlight certain words (using regex) in a >>> pdf. Could somebody let me know if there is a tool to do so in python? >> >> The problem with PDFs is that they can be quite complicated. ?There is >> the outer container structure, which isn't too bad (unless the >> document author applied encryption or fancy multi-object compression), >> but then inside the graphics elements, things could be stored as >> regular ASCII, or as fancy indexes into font-specific tables. ?Not >> rocket science, but the only industrial-strength solution for this is >> probably reportlab's pagecatcher. >> >> I have a library which works (primarily with the outer container) for >> reading and writing, called pdfrw. ?I also maintain a list of other >> PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries ?It >> may be that pdfminer (link on that page) will do what you want -- it >> is certainly trying to be complete as a PDF reader. ?But I've never >> personally used pdfminer. >> >> One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools >> will read in preexisting PDFs and write them out to a reportlab >> canvas. ?This works quite well on a few very simple ASCII PDFs, but >> the font handling needs a lot of work and probably won't work at all >> right now on unicode. ?(But if you wanted to improve it, I certainly >> would accept patches or give you commit rights!) >> >> That pdfrw example does graphics reasonably well. ?I was actually >> going down that path for getting better vector graphics into rst2pdf >> (both uniconvertor and svglib were broken for my purposes), but then I >> realized that the PDF spec allows you to include a page from another >> PDF quite easily (the spec calls it a form xObject), so you don't >> actually need to parse down into the graphics stream for that. ?So, >> right now, the best way to do vector graphics with rst2pdf is either >> to give it a preexisting PDF (which it passes off to pdfrw for >> conversion into a form xObject), or to give it a .svg file and invoke >> it with -e inkscape, and then it will use inkscape to convert the svg >> to a pdf and then go through the same path. > > Thank you for your long reply! But I'm not sure if you get my question or not. > > Acrobat can highlight certain words in pdfs. I could add notes to the > highlighted words as well. However, I find that I frequently end up > with highlighting some words that can be expressed by a regular > expression. > > To improve my productivity, I don't want do this manually in Acrobat > but rather do it in an automatic way, if there is such a tool > available. People in reportlab mailing list said this is not possible > with reportlab. And I don't see PyPDF can do this. If you know there > is an API to for this purpose, please let me know. Thank you! > > Regards, > Peng > -- > http://mail.python.org/mailman/listinfo/python-list > Take a look at the Acrobat SDK (http://www.adobe.com/devnet/acrobat/?view=downloads). In particular see the Acrobat Interapplication Communication information at http://www.adobe.com/devnet/acrobat/interapplication_communication.html. "Spell-checking a document" shows how to spell check a PDF using visual basic at http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=IAC_DevApp_OLE_Support.100.17.html "Working with annotations" shows how to add an annotation with visual basic at http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=IAC_DevApp_OLE_Support.100.16.html. Presumably combining the two examples with Python's win32com should allow you to do what you want. From bettylive at gmail.com Thu Mar 18 15:51:47 2010 From: bettylive at gmail.com (=?ISO-8859-1?Q?Bet=FCl?=) Date: Thu, 18 Mar 2010 21:51:47 +0200 Subject: importing python project in my application Message-ID: Hello All, I am new this mail list. I try to embedding python in C++. I want to use this project's class http://gamera.informatik.hsnr.de/ It is a framework in python. I want use Gamera 's classes,functions..etc in my c++ project. I have information about embedding python in c++ but i just want to learn that "how can i import to Gamera into the my c++ project"? Please, help me. it can be more questions after this :) Best Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From magicus23REMOVE-THIS at gmail.com Thu Mar 18 16:44:18 2010 From: magicus23REMOVE-THIS at gmail.com (furlan) Date: Thu, 18 Mar 2010 20:44:18 +0000 (UTC) Subject: question about tkinter References: Message-ID: On Wed, 17 Mar 2010 09:32:46 -0400, robert schaefer wrote: > Peter, > > Most of my life has been dealing with recalcitrant HAL's in one guise or > another. These days, I think HAL has permanently taken up residence in > Toyota's engine and brakes. "Stop the car Dave? Have you changed my oil > or even washed me lately?" Some serious "sneak paths" are going on. Don't know if this will help and I had in a file in my Solutions folder from 2008 the following: If Tkinter does not seem to be loaded run: sudo yum -y install python-tools which will install Tkinter and dependencies. HTH ciao, f -- aa #2301 "I often work by avoidance." -- Brian Eno From sluggoster at gmail.com Thu Mar 18 16:52:00 2010 From: sluggoster at gmail.com (Mike Orr) Date: Thu, 18 Mar 2010 13:52:00 -0700 (PDT) Subject: Need advice on starting a Python group References: Message-ID: On Mar 11, 7:57?am, gb345 wrote: > I'm hoping to get advice from anyone with prior experience setting > up a Python group. > > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. ?Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. ?Last time just he and I showed up. > > The second problem is getting content. ?The format we'd envisioned > for this group was centered around code review (though not limited > to it). ?The idea was that at every meeting a different member > would show some code. ?This could be for any of a number of reasons, > such as, for example, 1) illustrate a cool module or technique; 2) > present a scientific research problem and how they used Python to > solve it, or get help solving it; 3) get general feedback (e.g. on > code clarity, software usability, module architecture, etc.). ?But > in principle just about anything is OK: e.g. a talk on favorite > Python resources, or a comparison of Python with some other language, > or an overview of Python gotchas would all be fair game. I've been involved in a Python users group since 2000, and have attended or heard about a few others. The ones that have 20+ attendees have a speaker every month. Our group is usually a show-and-tell and open discussion, so we get around six people each month (but not the same six). We've decided to solicit more talks as a way to increase attendance. I have never heard of a Python group focusing on code review, so I don't know what attendance to expect for that. One problem is that much of people's code is private at their workplace, and they can't bring it to a meeting. I'd suggest expanding the focus a bit: code review, writing unit tests for each other, pair programming, some open "How do I do this in Python?" discussions, etc. You're also limiting the pool of potential attendees by targeting one institution. There are only a subset there who are interested in Python, a smaller subset who can attend meetings, and an even smaller subset who are willing to attend meetings even if they can. A citywide group or at least bringing in other institutions would hopefully increase attendance. Although it may be harder to keep the scientific focus with that. But on the other hand, here the specialized groups are getting more attendance than the general groups are. The local Plone and Django groups get more people than the Python group does. --Mike From mail at hellmutweber.de Thu Mar 18 17:05:37 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Thu, 18 Mar 2010 22:05:37 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: Message-ID: <4BA295A1.70207@hellmutweber.de> Am 11.03.2010 12:14, schrieb Peter Otten: > Hellmut Weber wrote: > >> Logging works very well giving the filename and line number of the point >> where it is called. As long as I use the loggers directly. >> BUT when I have to wrap the logger call in some other function, I always >> get file name and line number of the call of the logger inside the >> wrapping function. >> >> Is there a possibility to get this information in this situation too? > > The official way is probably to write a custom Logger class that overrides > the findCaller() method. > > Below is a hack that monkey-patches the logging._srcfile attribute to ignore > user-specified modules in the call stack: > > $ cat wrapper.py > import logging > import os > import sys > > logger = logging.getLogger() > > class SrcFile(object): > def __init__(self, exclude_files): > self.files = set(exclude_files) > def __eq__(self, other): > return other in self.files > > def fixname(filename): > if filename.lower().endswith((".pyc", ".pyo")): > filename = filename[:-4] + ".py" > return os.path.normcase(filename) > > if "--monkey" in sys.argv: > print "patching" > logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) > > def warn(*args, **kw): > logger.warn(*args, **kw) > > $ cat main.py > import logging > logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") > import wrapper > wrapper.warn("foo") > wrapper.warn("bar") > wrapper.warn("baz") > > $ python main.py > wrapper.py<23>: foo > wrapper.py<23>: bar > wrapper.py<23>: baz > > $ python main.py --monkey > patching > main.py<4>: foo > main.py<5>: bar > main.py<6>: baz > > $ python -V > Python 2.6.4 > > Peter Hi Peter, your hack is exactly what I was looking for. It permits to configure my logging messages as I want, e.g. using different colors for different classes of messages. I do not yet understand all details WHY it is working but suppose some study of the logging module will help me to understand. Thank you very much -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From tjreedy at udel.edu Thu Mar 18 17:13:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Mar 2010 17:13:18 -0400 Subject: Nested Scopes unintended behaviour ? In-Reply-To: <921f09da-bf41-4306-aca5-19baa70dd2b2@e7g2000yqf.googlegroups.com> References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> <921f09da-bf41-4306-aca5-19baa70dd2b2@e7g2000yqf.googlegroups.com> Message-ID: On 3/18/2010 6:21 AM, Michael Sparks wrote: > After hearing it's expected behaviour in 2.6 it's clear that assigning > a name to a value declares the variable to be local, unless there is a global/nonlocal declaration and that unlike > much of python (but like yield) this appears based on static analysis > of the function declaration, rather than dynamic. The language definition requires two passes after parsing. One collects names and determines their scope (and looks for yield). The second generates code. This allows the local namespace to be implemented as an array rather than a dict, so that local name lookup is an array index operation rather than a dict lookup operation. This is somewhat made visible by the dis module >>> from dis import dis >>> a = 1 >>> def f(): b = 2 return a,b >>> dis(f) 2 0 LOAD_CONST 1 (2) 3 STORE_FAST 0 (b) 3 6 LOAD_GLOBAL 0 (a) 9 LOAD_FAST 0 (b) 12 BUILD_TUPLE 2 15 RETURN_VALUE STORE/LOAD_FAST means store/load_local. Constants (2 in this case) are stored in the same array. There is apparently a separate array of global names, as opposed to local values. Terry Jan Reedy From aahz at pythoncraft.com Thu Mar 18 18:06:00 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Mar 2010 15:06:00 -0700 Subject: sqlite3, memory db and multithreading References: Message-ID: In article , =?UTF-8?B?a3LDs2xld25h?= wrote: > >The problem is simple: I have multiple threads within one program. At >least 2 threads have to have access to in-memory sqlite database. It is >not possible to pass sqlite objects to those threads because an >exception is rised: > >ProgrammingError: SQLite objects created in a thread can only be used in >that same thread.The object was created in thread id -1219066176 and >this is thread id -1224475792 > >Is there any EASY way to use this in-memory db in many threads? Creating >another connection is not a solution as it creates completely new db >instead of connecting to the existing one. You probably need to serialize access to the database through one thread. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From slais-www at ucl.ac.uk Thu Mar 18 18:29:41 2010 From: slais-www at ucl.ac.uk (djc) Date: Thu, 18 Mar 2010 22:29:41 +0000 Subject: should writing Unicode files be so slow Message-ID: I have a simple program to read a text (.csv) file and split it into several smaller files. Tonight I decided to write a unicode variant and was surprised at the difference in performance. Is there a better way? > from __future__ import with_statement > import codecs > > def _rowreader(filename, separator='\t'): > """Generator for iteration over potentially large file.""" > with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as tabfile: > for row in tabfile: > yield [v.strip() for v in row.split(separator)] > > def generator_of_output(source_of_lines): > for line in source_of_lines: > for result in some_function(line): > yield result > > def coroutine(outfile_prefix, outfile_suffix, sep='\t'): > outfile = '%s_%s.txt'% (outfile_prefix, outfile_suffix) > with codecs.open(outfile, 'w', 'utf-8') as out_part: > while True: > line = (yield) > out_part.write(sep.join(line) + '\n') > > def _file_to_files(infile, outfile_prefix, column, sep): > column_values = dict() > for line in _rowreader(infile, sep): > outfile_suffix = line[column].strip('\'\"') > if outfile_suffix in column_values: > column_values[outfile_suffix].send(line) > else: > file_writer = coroutine(outfile_prefix, outfile_suffix, sep) > file_writer.next() > file_writer.send(line) > column_values[outfile_suffix] = file_writer > for file_writer in column_values.itervalues(): > file_writer.close() the plain version is the same except for > with open(filename, 'rU') as tabfile: > with open(outfile, 'wt') as out_part: The difference: > "uid","timestamp","taskid","inputid","value" > "15473178739336026589","2010-02-18T20:50:15+0000","11696870405","73827093507","83523277829" > "15473178739336026589","2010-02-18T20:50:15+0000","11696870405","11800677379","12192844803" > "15473178739336026589","2010-02-18T20:50:15+0000","11696870405","31231839235","52725552133" > > sysweb at Bembo:~/UCLC/bbc/wb2$ wc -l wb.csv > 9293271 wb.csv > > normal version > sysweb at Bembo:~/UCLC$ time ~/UCL/toolkit/file_splitter.py -o tt --separator comma -k 2 wb.csv > > real 0m43.714s > user 0m37.370s > sys 0m2.732s > > unicode version > sysweb at Bembo:~/UCLC$ time ./file_splitter.py -o t --separator comma -k 2 wb.csv > > real 4m8.695s > user 3m19.236s > sys 0m39.262s -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From davea at ieee.org Thu Mar 18 19:13:59 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Mar 2010 18:13:59 -0500 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: <4BA2B3B7.70309@ieee.org> Alf P. Steinbach wrote: > * Dave Angel: >> Stefan Behnel wrote: >>>
MikeLisanke at gmail.com, 17.03.2010 10:08: >>>> Its interesting you've mentioned the hard work involved in this >>>> interface (binding to an EXE instead of a DLL). A year or more ago I >>>> was looking at interfacing IPMITOOL to python. Do to the problems >>>> incurred with swig/python I switched to a running the process through >>>> its command-line interface. I always felt the problems in interfacing >>>> python to an EXE should be worked on (to minimize them), making the >>>> direct use of an EXE API's a routine task. I understand some of the >>>> problems using an EXE (not running all of its startup code but >>>> enough for its proper operation). Have you found this a recurring >>>> question? Thanks. >>> >>> I think the point here is that executable binaries are not supposed >>> to be used as libraries. Libraries are. That's the difference >>> between a DLL and an executable in the first place. To run an >>> executable, execute it. The subprocess module is the tool of choice >>> here. To use a DLL, link against it. >>> >>> Stefan >>> >> There's no real reason parts of an exe cannot be exported, same as a >> dll. They are in fact the same structure. And in fact many other >> files in the Windows environment are also the same structure, from >> fonts to ocx's >> >> Saying they're "not supposed to be used" is like saying that a python >> module should not have an >> >> if __name__ == "__main__": >> >> section. After all, who could want to both run a file, and import >> the same file?? > > A Windows DLL has defined initialization and cleanup per process and > per thread. > > This means that e.g. static variables can be properly initialized when > you load the DLL in order to use its functions (I'm skipping > discussion of subtle problems, but that's the essence). > > A Windows EXE has (only) a single entry point which is for process > startup. It invokes the EXE's behavior-as-a-program. There is no way > to use it to e.g. initialize static variables in order to use exported > functions. > > Hence Mike Lisanke's idea of "not running all of its startup code but > enough for its proper operation" is generally not possible. > > An EXE can be used as a kind of server, /if/ it is designed for that. > In particular it can be a COM server, allowing access of its > functionality from any COM-enabled binding, which for Python would > mean OLE Automation (COM, OLE, Automation: this is Microsoft > technology, we're talking Windows EXEs here). But a Python binding to > EXEs in general can't, as far as I can see, make assumptions about any > particular kind of server being implemented by the EXE. > > > Cheers & hth., > > - Alf > > I'm not talking about COM servers, which run in a separate process. Only about calling functionality that happens to be encoded in an .EXE file. You're trying to generalize what I said. I never said you could call into any .EXE file, just that calling into one is not infeasible. You're describing using an .EXE written using the Microsoft C compiler and/or libraries, not a Windows .EXE in general. In any case, whenever you link to a module written in a different environment, you'll have restrictions. Chief among them is the use of a compatible memory model, the stack conventions, the allocators, and so on.. Solving the thread issue is probably the easiest one to fix. I'm not recommending it, just refuting the "not supposed to" quote above. DaveA From alfps at start.no Thu Mar 18 19:56:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 19 Mar 2010 00:56:35 +0100 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: * Dave Angel: > Alf P. Steinbach wrote: >> * Dave Angel: >>> Stefan Behnel wrote: >>>>
MikeLisanke at gmail.com, 17.03.2010 10:08: >>>>> Its interesting you've mentioned the hard work involved in this >>>>> interface (binding to an EXE instead of a DLL). A year or more ago I >>>>> was looking at interfacing IPMITOOL to python. Do to the problems >>>>> incurred with swig/python I switched to a running the process through >>>>> its command-line interface. I always felt the problems in interfacing >>>>> python to an EXE should be worked on (to minimize them), making the >>>>> direct use of an EXE API's a routine task. I understand some of the >>>>> problems using an EXE (not running all of its startup code but >>>>> enough for its proper operation). Have you found this a recurring >>>>> question? Thanks. >>>> >>>> I think the point here is that executable binaries are not supposed >>>> to be used as libraries. Libraries are. That's the difference >>>> between a DLL and an executable in the first place. To run an >>>> executable, execute it. The subprocess module is the tool of choice >>>> here. To use a DLL, link against it. >>>> >>>> Stefan >>>> >>> There's no real reason parts of an exe cannot be exported, same as a >>> dll. They are in fact the same structure. And in fact many other >>> files in the Windows environment are also the same structure, from >>> fonts to ocx's >>> >>> Saying they're "not supposed to be used" is like saying that a python >>> module should not have an >>> >>> if __name__ == "__main__": >>> >>> section. After all, who could want to both run a file, and import >>> the same file?? >> >> A Windows DLL has defined initialization and cleanup per process and >> per thread. >> >> This means that e.g. static variables can be properly initialized when >> you load the DLL in order to use its functions (I'm skipping >> discussion of subtle problems, but that's the essence). >> >> A Windows EXE has (only) a single entry point which is for process >> startup. It invokes the EXE's behavior-as-a-program. There is no way >> to use it to e.g. initialize static variables in order to use exported >> functions. >> >> Hence Mike Lisanke's idea of "not running all of its startup code but >> enough for its proper operation" is generally not possible. >> >> An EXE can be used as a kind of server, /if/ it is designed for that. >> In particular it can be a COM server, allowing access of its >> functionality from any COM-enabled binding, which for Python would >> mean OLE Automation (COM, OLE, Automation: this is Microsoft >> technology, we're talking Windows EXEs here). But a Python binding to >> EXEs in general can't, as far as I can see, make assumptions about any >> particular kind of server being implemented by the EXE. >> > I'm not talking about COM servers, which run in a separate process. > Only about calling functionality that happens to be encoded in an .EXE > file. > > You're trying to generalize what I said. I never said you could call > into any .EXE file, just that calling into one is not infeasible. Well, true. And I'm sorry if my reply sounded as a misrepresentation. I haven't tried this calling-a-function-in-an-exe (since 16-bit Windows, that is!, but that was very different), but I can imagine two such cases: (1) a function f is exported by the EXE, and f doesn't depend on anything but its arguments and does not use any static storage, or (2) a DLL loaded by the EXE calls back into the EXE, which could work because then everything's initialized (however, there are better ways). But these are very special cases where one really has to know what one is doing. As Gabriel Genellina wrote up-thread, "you *could* do that if you work hard enough, but that's not how things are usually done". That said, in Windows the least uncommon reason to load an EXE as a DLL is, IME, to access resource data in the EXE. Tip for that: the module handle, casted to appropriate pointer type, points to the start of the loaded image (great for accessing e.g. version info resource). I think this is still undocumented... > You're describing using an .EXE written using the Microsoft C compiler > and/or libraries, not a Windows .EXE in general. In any case, whenever > you link to a module written in a different environment, you'll have > restrictions. Chief among them is the use of a compatible memory model, > the stack conventions, the allocators, and so on.. Solving the thread > issue is probably the easiest one to fix. > > I'm not recommending it, just refuting the "not supposed to" quote above. Again, I'm sorry if my reply sounded as a misrepresentation. I just tried to make the solution-constraining technical facts available, addressing Mike's "making the direct use of an EXE API's a routine task". I think we're all in (violent?) agreement on this. :-) Cheers, - Alf From clockworksaint at gmail.com Thu Mar 18 20:13:32 2010 From: clockworksaint at gmail.com (Weeble) Date: Thu, 18 Mar 2010 17:13:32 -0700 (PDT) Subject: GC is very expensive: am I doing something wrong? Message-ID: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> I am loading a dictionary from a text file and constructing a trie data structure in memory. However, it takes longer than I'm happy with - about 12 seconds on my computer. I profiled it, came up with some clever ideas to cut down on the work (such as by exploiting the fact that the dictionary is sorted) and was only able to shave a small fraction of the time off. However, then I tried calling gc.disable() before loading the trie and it halved the running time! I was surprised. Is that normal? I thought that the cost of garbage collection would be in some way proportional to the amount of garbage created, but I didn't think I was creating any: as far as I can tell the only objects deallocated during the load are strings, which could not be participating in cycles. I have spent a lot of time in C#, where the standard advice is not to mess about with the garbage collector because you'll probably just make things worse. Does that advice apply in Python? Is it a bad idea to call gc.disable() before loading the trie and then enable it again afterwards? Does the fact that the garbage collector is taking so much time indicate I'm doing something particularly bad here? Is there some way to give the garbage collector a hint that the whole trie is going to be long-lived and get it promoted straight to generation 2 rather than scanning it over and over? $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> $ time python -c "import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m12.523s user 0m12.380s sys 0m0.140s $ time python -c "import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m12.592s user 0m12.480s sys 0m0.110s $ time python -c "import gc;gc.disable();import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m6.176s user 0m5.980s sys 0m0.190s $ time python -c "import gc;gc.disable();import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m6.331s user 0m5.530s sys 0m0.170s === trie.py === class Trie(object): __slots__=("root", "active") def __init__(self): self.root=[] self.active=False def insert(self, word): if len(word) == 0: self.active=True else: head = word[0] for ch, child in reversed(self.root): if ch == head: child.insert(word[1:]) return child = Trie() self.root.append((head, child)) child.insert(word[1:]) def seek(self, word): if len(word) == 0: return self head = word[0] for ch, child in self.root: if ch == head: return child.seek(word[1:]) return EMPTY_TRIE def load(self, file): for line in file: self.insert(line.strip().lower()) def empty(self): return (not self.root) and not self.active def endings(self, prefix=""): if self.active: yield prefix for ch, child in self.root: for ending in child.endings(prefix+ch): yield ending EMPTY_TRIE = Trie() From contact at xavierho.com Thu Mar 18 20:24:22 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 19 Mar 2010 10:24:22 +1000 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: <2d56febf1003181724t377741eem900a456d73b58cac@mail.gmail.com> Weeble, Try to use the full arguments of insert(i, x), instead of using list slices. Every time you create a slice, Python copies the list into a new memory location with the sliced copy. That's probably a big performance impact there if done recursively. My 2cp, Xav On Fri, Mar 19, 2010 at 10:13 AM, Weeble wrote: > I am loading a dictionary from a text file and constructing a trie > data structure in memory. However, it takes longer than I'm happy with > - about 12 seconds on my computer. I profiled it, came up with some > clever ideas to cut down on the work (such as by exploiting the fact > that the dictionary is sorted) and was only able to shave a small > fraction of the time off. However, then I tried calling gc.disable() > before loading the trie and it halved the running time! I was > surprised. Is that normal? I thought that the cost of garbage > collection would be in some way proportional to the amount of garbage > created, but I didn't think I was creating any: as far as I can tell > the only objects deallocated during the load are strings, which could > not be participating in cycles. > > I have spent a lot of time in C#, where the standard advice is not to > mess about with the garbage collector because you'll probably just > make things worse. Does that advice apply in Python? Is it a bad idea > to call gc.disable() before loading the trie and then enable it again > afterwards? Does the fact that the garbage collector is taking so much > time indicate I'm doing something particularly bad here? Is there some > way to give the garbage collector a hint that the whole trie is going > to be long-lived and get it promoted straight to generation 2 rather > than scanning it over and over? > > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > $ time python -c "import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m12.523s > user 0m12.380s > sys 0m0.140s > $ time python -c "import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m12.592s > user 0m12.480s > sys 0m0.110s > $ time python -c "import gc;gc.disable();import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m6.176s > user 0m5.980s > sys 0m0.190s > $ time python -c "import gc;gc.disable();import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m6.331s > user 0m5.530s > sys 0m0.170s > > > === trie.py === > > class Trie(object): > __slots__=("root", "active") > def __init__(self): > self.root=[] > self.active=False > def insert(self, word): > if len(word) == 0: > self.active=True > else: > head = word[0] > for ch, child in reversed(self.root): > if ch == head: > child.insert(word[1:]) > return > child = Trie() > self.root.append((head, child)) > child.insert(word[1:]) > def seek(self, word): > if len(word) == 0: > return self > head = word[0] > for ch, child in self.root: > if ch == head: > return child.seek(word[1:]) > return EMPTY_TRIE > def load(self, file): > for line in file: > self.insert(line.strip().lower()) > def empty(self): > return (not self.root) and not self.active > def endings(self, prefix=""): > if self.active: > yield prefix > for ch, child in self.root: > for ending in child.endings(prefix+ch): > yield ending > > EMPTY_TRIE = Trie() > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Mar 18 20:33:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Mar 2010 20:33:40 -0400 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: On 3/18/2010 8:13 PM, Weeble wrote: > I thought that the cost of garbage > collection would be in some way proportional to the amount of garbage > created, but I didn't think I was creating any: as far as I can tell > the only objects deallocated during the load are strings, which could > not be participating in cycles. > > I have spent a lot of time in C#, where the standard advice is not to > mess about with the garbage collector because you'll probably just > make things worse. Does that advice apply in Python? Is it a bad idea > to call gc.disable() before loading the trie and then enable it again > afterwards? I believe not. It is known that certain patterns of object creation and destruction can lead to bad gc behavior. No one has discovered a setting of the internal tuning parameters for which there are no bad patterns and I suspect there are not any such. This does not negate Xavier's suggestion that a code change might also solve your problem. tjr From brandonc530 at gmail.com Thu Mar 18 21:00:47 2010 From: brandonc530 at gmail.com (Brandon Conner) Date: Thu, 18 Mar 2010 20:00:47 -0500 Subject: Truoble With A Search Script for ImageBin.org Message-ID: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> Hey Pythoners, its my first post here, yay! I'm trying to develop a script that will return the results of a POST request that should list all images uploaded by a user. However, when i run the script, i get returned the HTML of the page with the search form. I am wondering what am i doing incorrectly? Is it something I'm doing or is the imagebin server rejecting my request? here's the code: import urllib import urllib2 url = 'http://imagebin.org/index.php?page=search' values = {'search_for' : 'blah', 'field' : 'Nickname'} data = urllib.urlencode(values) request = urllib2.Request(url, data) response = urllib2.urlopen(request) page = response.read() print page tks, pythons great -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu Mar 18 21:49:56 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Mar 2010 12:49:56 +1100 Subject: should writing Unicode files be so slow References: Message-ID: <8739zxw057.fsf@benfinney.id.au> djc writes: > I have a simple program to read a text (.csv) file Could you please: * simplify it further: make a minimal version that demonstrates the difference you're seeing, without any extraneous stuff that doesn't appear to affect the result. * make it complete: the code you've shown doesn't do anything except define some functions. In other words: please reduce it to a complete, minimal example that we can run to see the same behaviour you're seeing. -- \ ?If we ruin the Earth, there is no place else to go. This is | `\ not a disposable world, and we are not yet able to re-engineer | _o__) other planets.? ?Carl Sagan, _Cosmos_, 1980 | Ben Finney From clp2 at rebertia.com Thu Mar 18 22:07:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Mar 2010 19:07:05 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003181907x515d29bdsad5208b59420a472@mail.gmail.com> On Thu, Mar 18, 2010 at 12:49 AM, Lawrence D'Oliveiro wrote: > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. My apologies to you then. In my own defense, I will say this is the first complaint I can recall getting about unmungeing the "To:" header when replying to someone on python-list. To ensure your address's privacy in the future, either using a disposable address or putting a /completely/ invalid and unrelated address in the "To:" header are some possible options. Regards, Chris -- This is one of the pitfalls of mail-news gateways I suppose. From steve at holdenweb.com Thu Mar 18 22:43:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Mar 2010 22:43:38 -0400 Subject: Truoble With A Search Script for ImageBin.org In-Reply-To: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> References: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> Message-ID: Brandon Conner wrote: > Hey Pythoners, > > its my first post here, yay! > > I'm trying to develop a script that will return the results of a POST > request that should list all images uploaded by a user. However, when i > run the script, i get returned the HTML of the page with the search > form. I am wondering what am i doing incorrectly? Is it something I'm > doing or is the imagebin server rejecting my request? > > here's the code: > > import urllib > import urllib2 > url = 'http://imagebin.org/index.php?page=search' > values = {'search_for' : 'blah', 'field' : 'Nickname'} > data = urllib.urlencode(values) > request = urllib2.Request(url, data) > response = urllib2.urlopen(request) > page = response.read() > print page > > tks, pythons great > You need to tell the browser (in an HTTP header) that what you are sending is HTML. Try putting print "Content-Type: text/html\n" at the start of your script. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From john at castleamber.com Thu Mar 18 22:50:51 2010 From: john at castleamber.com (John Bokma) Date: Thu, 18 Mar 2010 20:50:51 -0600 Subject: import antigravity References: Message-ID: <87iq8tc9dg.fsf@castleamber.com> Lawrence D'Oliveiro writes: > In message , Chris > Rebert wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Ha ha ha! Get a life. You're using a non-existant tld. I recommend to use .invalid instead, e.g. ldo at geek-central.gen.nz.invalid And Chris can make sure that his unobfuscating code doesn't run if the tld is invalid. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From cs at zip.com.au Thu Mar 18 22:57:19 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 19 Mar 2010 13:57:19 +1100 Subject: Truoble With A Search Script for ImageBin.org In-Reply-To: References: Message-ID: <20100319025719.GA20465@cskk.homeip.net> On 18Mar2010 22:43, Steve Holden wrote: | Brandon Conner wrote: | > I'm trying to develop a script that will return the results of a POST | > request that should list all images uploaded by a user. However, when i | > run the script, i get returned the HTML of the page with the search | > form. I am wondering what am i doing incorrectly? Is it something I'm | > doing or is the imagebin server rejecting my request? | > | > here's the code: | > | > import urllib | > import urllib2 | > url = 'http://imagebin.org/index.php?page=search' | > values = {'search_for' : 'blah', 'field' : 'Nickname'} | > data = urllib.urlencode(values) | > request = urllib2.Request(url, data) | > response = urllib2.urlopen(request) | > page = response.read() | > print page | > | > tks, pythons great | > | You need to tell the browser (in an HTTP header) that what you are | sending is HTML. Try putting | | print "Content-Type: text/html\n" | | at the start of your script. I think it may need to be "application/x-www-form-urlencoded", not text/html. But otherwise, yes, missing Content-Type. And the request method needs to be POST; I expect the code above will be using GET unless told not to. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There's no trick to being a humorist when you have the whole government working for you. - Will Rogers From rowland at river2sea.org Thu Mar 18 23:25:48 2010 From: rowland at river2sea.org (Rowland Smith) Date: Thu, 18 Mar 2010 23:25:48 -0400 Subject: example of ssl with SimpleXMLRPCServer in 2.6? Message-ID: <2010031823254816807-rowland@river2seaorg> Anyone have an example of using the new ssl module with SimpleXMLRPCServer in 2.6? Thanks, -- -Rowland From timr at probo.com Fri Mar 19 00:13:25 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Mar 2010 21:13:25 -0700 Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: Dave Angel wrote: >> >There's no real reason parts of an exe cannot be exported, same as a >dll. They are in fact the same structure. And in fact many other files >in the Windows environment are also the same structure, from fonts to ocx's Well, there IS a fundamental difference. EXEs and DLLs and the like do all have the same format. They all have a "transfer address", where execution begins. That's the key problem. With a DLL, the transfer address goes to a DllMain, where certain DLL initialization is done, preparing the other entry points for use. With an EXE, the transfer address goes to "main". So, when you load an EXE as a DLL, you will be RUNNING the program. That's is usually not what you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nagle at animats.com Fri Mar 19 00:33:52 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Mar 2010 21:33:52 -0700 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: <4ba2fa0d$0$1598$742ec2ed@news.sonic.net> kr?lewna wrote: > The problem is simple: I have multiple threads within one program. At > least 2 threads have to have access to in-memory sqlite database. It is > not possible to pass sqlite objects to those threads because an > exception is rised: > > ProgrammingError: SQLite objects created in a thread can only be used in > that same thread.The object was created in thread id -1219066176 and > this is thread id -1224475792 > > Is there any EASY way to use this in-memory db in many threads? Creating > another connection is not a solution as it creates completely new db > instead of connecting to the existing one. Recognize that sqlite is for "lite" database work. If you're running some massively concurrent database application, you need something heavier, like MySQL or Postgres. "sqlite" has a simplistic locking strategy. Locking is done by file-level locking, and you can have one UPDATE/INSERT operations, or any numnber of SELECTs, at a time. Lock conflicts are handled by wait and retry, which is slow. The big databases are much smarter about figuring out which operations can safely be done in parallel, do much more query optimization, and handle high transaction volumes much better than sqlite. You use sqlite for configuration files, your personal databases, and other small stuff. You run your Web 2.0 site on MySQL or Postgres. You run your Fortune 1000 company on Oracle. John Nagle From pmaupin at gmail.com Fri Mar 19 00:44:19 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 18 Mar 2010 21:44:19 -0700 (PDT) Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: <7a3a0709-2325-45a3-9cb5-381a7a1ff31f@t41g2000yqt.googlegroups.com> On Mar 18, 7:13?pm, Weeble wrote: > I am loading a dictionary from a text file and constructing a trie > data structure in memory. However, it takes longer than I'm happy with > - about 12 seconds on my computer. I profiled it, came up with some > clever ideas to cut down on the work (such as by exploiting the fact > that the dictionary is sorted) and was only able to shave a small > fraction of the time off. However, then I tried calling gc.disable() > before loading the trie and it halved the running time! I was > surprised. Is that normal? I thought that the cost of garbage > collection would be in some way proportional to the amount of garbage > created, but I didn't think I was creating any: as far as I can tell > the only objects deallocated during the load are strings, which could > not be participating in cycles. Well, you are creating and destroying a lot of objects in the process, so that will provoke the garbage collector. But you are also doing reversing and searching, and that's slow. Does your application really need to be able to keep things in order like this, or do you just want to know if a word is in the dictionary? If you just want to load up a dictionary and be able to see if words are in it, I would use a dict instead of a list. Even if you want to be able to print out the data in order, you might consider using a dict instead of a list. The print operation could use one sort at the end, instead of searching all the nodes on insertion. You could also use a character that doesn't appear in your data as a sentinel, and then you don't need a separate active indicator -- every leaf node will be empty and be referred to by the sentinel character. You are also doing a lot of recursive operations that could be done without recursing. Finally, do you really need to keep an additional object around for each node in the tree? I have modified your trie code to use a dict and a sentinel, while keeping basically the same API. This may or may not be the best way to do this, depending on your other code which uses this data structure. It could also probably be made faster by removing the setdefault, and not re-building objects when you need them, and even this implementation will load faster if you disable the gc, but in any case, this might give you some ideas about how to make your code go faster. Regards, Pat from collections import defaultdict class TrieTop(object): sentinel = ' ' # Something not in the data def __init__(self, data=None): def defaultrecurse(): return defaultdict(defaultrecurse) if data is None: data = defaultrecurse() self.data = data def insert(self, word): data = self.data for ch in word: data = data[ch] data[self.sentinel] def seek(self, word): data = self.data for ch in word: data = data.get(ch) if data is None: return EMPTY_TRIE return TrieTop(data) def load(self, file): for line in file: self.insert(line.strip().lower()) def empty(self): return (not self.data) def endings(self, prefix=""): def recurse(data, prefix): if not data: yield prefix[:-1] return for ch, data in data.iteritems(): for result in recurse(data, prefix + ch): yield result return sorted(recurse(self.data, prefix)) EMPTY_TRIE = TrieTop() From anand.ibmgsi at gmail.com Fri Mar 19 02:03:21 2010 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Fri, 19 Mar 2010 11:33:21 +0530 Subject: Bug in Python APscheduler module. Message-ID: <1a3a139e1003182303j218f3dc8x32896e2fe2119c5f@mail.gmail.com> Hi , I looked everywhere and could find no mention of this(might be looking in the wrong places point me please..). the Python package Advanced python scheduler seems to have a bug with the unschedule func. When passing the function of an object it doesn't remove it from the scheduler. but works fine with a normal function. Please find my test script attached and guide me... from apscheduler.scheduler import Scheduler def test_func(): print "test func" class test_class(): def test_class1(self): print "test class" def main(): sched=Scheduler() sched.start() tc=test_class() tc.test_class1() print sched.add_interval_job(test_func,minutes=1) print sched.add_interval_job(tc.test_class1,minutes=1) print sched.add_interval_job(test_func,seconds=20) print "jobs b4 unschedule" print sched.jobs # sched.unschedule_func(test_func) sched.unschedule_func(tc.test_class1) print "jobs after unschedule" print sched.jobs sched.shutdown() if __name__=='__main__': main() ~ ~ ~ ~ ============================================== Anand J http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Mar 19 02:51:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 02:51:20 -0400 Subject: Bug in Python APscheduler module. In-Reply-To: <1a3a139e1003182303j218f3dc8x32896e2fe2119c5f@mail.gmail.com> References: <1a3a139e1003182303j218f3dc8x32896e2fe2119c5f@mail.gmail.com> Message-ID: On 3/19/2010 2:03 AM, anand jeyahar wrote: > Hi , > I looked everywhere and could find no mention of this(might be > looking in the wrong places point me please..). the Python package > Advanced python scheduler seems to have a bug with the unschedule func. The site for that package http://apscheduler.nextday.fi/ has links for Getting Help and Reporting Bugs. From alfps at start.no Fri Mar 19 03:01:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 19 Mar 2010 08:01:46 +0100 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: * Tim Roberts: > Dave Angel wrote: >> There's no real reason parts of an exe cannot be exported, same as a >> dll. They are in fact the same structure. And in fact many other files >> in the Windows environment are also the same structure, from fonts to ocx's This is a bit off-topic, but your explanation is incorrect in some key respects, so (no offense) to avoid readers getting an incorrect impression: > Well, there IS a fundamental difference. EXEs and DLLs and the like do all > have the same format. They all have a "transfer address" Commonly called an "entry point". This is the term you need to know about when e.g. linking object files. >, where execution > begins. That's the key problem. With a DLL, the transfer address goes to > a DllMain, where certain DLL initialization is done, preparing the other > entry points for use. Right, modulo terminology: there's only one "entry point" in a PE format file. > With an EXE, the transfer address goes to "main". Sorry, no, the EXE entry point goes to a routine of no arguments. Typically, in C and C++ that's a run time library routine (e.g. with Microsoft's run time library mainCRTStartup or one of its cousins) which in turn calls the C/C++ "main", while in Pascal it runs the main program, so on. Note that the EXE entry point is probably still incorrectly documented as requiring WinMain signature -- it's the most infamous Microsoft documentation screw-up. > So, when you load an EXE as a DLL, you will be RUNNING the program. Sorry, no, that's not what happens. The Windows API LoadLibrary(Ex) knows the difference between an EXE and a DLL. It's documented as handling both sub-formats, and it does. > That's is usually not what you want. If that had happened then it would be a problem, yes. Happily it doesn't happen. I've discussed the real problems else-thread. Cheers & hth., - Alf From daniele.esposti at gmail.com Fri Mar 19 03:20:32 2010 From: daniele.esposti at gmail.com (Expo) Date: Fri, 19 Mar 2010 00:20:32 -0700 (PDT) Subject: sqlite3, memory db and multithreading References: Message-ID: <155a70fb-0e4e-43a8-8e4c-0f4475573035@t20g2000yqe.googlegroups.com> On Mar 18, 1:58?pm, kr?lewna wrote: > The problem is simple: I have multiple threads within one program. At > least 2 threads have to have access to in-memory sqlite database. It is > not possible to pass sqlite objects to those threads because an > exception is rised: > > ProgrammingError: SQLite objects created in a thread can only be used in > that same thread.The object was created in thread id -1219066176 and > this is thread id -1224475792 > > Is there any EASY way to use this in-memory db in many threads? Creating > another connection is not a solution as it creates completely new db > instead of connecting to the existing one. > You can put the SQLite database into a Singleton class and use a semaphore to serialize the access to methods which writes to the database. From dr.cg at 126.com Fri Mar 19 03:49:28 2010 From: dr.cg at 126.com (CHEN Guang) Date: Fri, 19 Mar 2010 15:49:28 +0800 (CST) Subject: C++ code generation In-Reply-To: <7f014ea61003180928q4763a819ic548364e2811952d@mail.gmail.com> References: <7f014ea61003180928q4763a819ic548364e2811952d@mail.gmail.com> <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> Message-ID: <90858a.6e02.1277565f46c.Coremail.dr.cg@126.com> Plug? Any evidence to say that? As long as this thread concerned, is there any answer more closed to the topic "C++ code generation" than mine? I think Stefan was telling you, in a nice way, to stop spamming every thread about code generation with a plug for your project. 2010/3/17 CHEN Guang >> ----- Original Message ----- >> From: "Dan Goodman" >> >>> I'm doing some C++ code generation using Python, and would be interested >>> in any comments on the approach I'm taking. >> >> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) > > It would be nice if you could start reading the posts before you answer, > and then try to give an answer that fits the question. > > Stefan I have read the post, may be I lost some words and made you misunderstand. I meant: PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not C++), if you find it useful, welcome to take a look. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Mar 19 03:56:46 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Mar 2010 08:56:46 +0100 Subject: logging: local functions ==> loss of lineno References: Message-ID: Hellmut Weber wrote: > your hack is exactly what I was looking for. > It permits to configure my logging messages as I want, e.g. using > different colors for different classes of messages. > > I do not yet understand all details WHY it is working but suppose some > study of the logging module will help me to understand. Have a look at Logger.findCaller() in logging/__init__.py. To find the calling function it does something like for frame in walk_callstack(): if filename_of(frame) == _srcfile: continue return filename_lineno_and_functionname_of(frame) The _srcfile is normally logging/__init__.py, and it is skipped because a user typically is interested only in what happens outside the logging package. My hack under the hood changes filename_of(frame) == _srcfile from a string comparison to a filename_of(frame) in set_of_files containment test (see SrcFile.__eq__() posted above). Peter From nbvfour at gmail.com Fri Mar 19 04:05:03 2010 From: nbvfour at gmail.com (nbv4) Date: Fri, 19 Mar 2010 01:05:03 -0700 (PDT) Subject: installing something to a virtualenv when it's already in site-packages Message-ID: I have ipython installed via apt. I can go to the command line and type 'ipython' and it will work. If I try to install ipython to a virtualenv, I get this: $ pip install -E env/ ipython Requirement already satisfied: ipython in /usr/share/pyshared Installing collected packages: ipython Successfully installed ipython I want ipython in both site-packages as well as in my virtualenv. This is bad because when I activate the virtualenv, site-packages disappears and ipython is not available. A work around is to uninstall ipython from apt, install to the virtualenv, then reinstall in apt. Is there a better way? From darkrho at gmail.com Fri Mar 19 04:26:56 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 19 Mar 2010 04:26:56 -0400 Subject: installing something to a virtualenv when it's already in site-packages In-Reply-To: References: Message-ID: <4eca3f41003190126mc625306m59608d638253d91c@mail.gmail.com> On Fri, Mar 19, 2010 at 4:05 AM, nbv4 wrote: > I have ipython installed via apt. I can go to the command line and > type 'ipython' and it will work. If I try to install ipython to a > virtualenv, I get this: > > $ pip install -E env/ ipython > Requirement already satisfied: ipython in /usr/share/pyshared > Installing collected packages: ipython > Successfully installed ipython > > I want ipython in both site-packages as well as in my virtualenv. This > is bad because when I activate the virtualenv, site-packages > disappears and ipython is not available. A work around is to uninstall > ipython from apt, install to the virtualenv, then reinstall in apt. Is > there a better way? I use -U (--upgrade) to force the installation within virtualenv. e.g: $ pip install -E env/ -U ipython Regards, Rolando From pankaj.kr at gmail.com Fri Mar 19 05:03:54 2010 From: pankaj.kr at gmail.com (Pankaj) Date: Fri, 19 Mar 2010 02:03:54 -0700 (PDT) Subject: exp_continue Message-ID: <1669b997-c4bf-43fc-a2e0-3d5c99cb0524@v34g2000prm.googlegroups.com> I am using pexpect module in python I would like to know how I can use exp_continue here. what is the alternative of exp_continue of perl/tcl in pexpect. From nilly16 at yahoo.com Fri Mar 19 05:37:35 2010 From: nilly16 at yahoo.com (Jimbo) Date: Fri, 19 Mar 2010 02:37:35 -0700 (PDT) Subject: Why this compile error? Message-ID: Hello Can you help me figure out why I am getting this compile error with my program. The error occurs right at the bottom of my code & I have commented where it occurs. The error is: [QUOTE]Expected an indented block[/QUOTE] [CODE]""" *Stock Data Builder* Algorithm: - Search website for stock - Get website HTML source code - Search code for target stock data(price,dividends) - Add data to text file """ import sys # Functions def getSource(URL, sourceBuffer): """ Retrieve HTML source code from websitr URL & save in sourceBuffer """ return sourceBuffer def getData(targetData, dataBuffer): """ Searches the string dataBuffer for the occurence of target data & returns that whole line """ def writeToFile(textFile, dataBuffer): """ Writes data in string dataBuffer to text file """ # CHANGE this to try except to catch errors fileT = open(textFile,'a') fileT.write(dataBuffer) return True; # function succeeded def writeToFile(textFile, dataList): """ Writes data in List dataList to text file """ # CHANGE this to try except to catch errors fileT = open(textFile,'a') for element in dataList: fileT.write(element) return True; # function succeeded # Main program loop def main(): programEnd = False; while (programEnd == False): #ERROR HERE?? - Error="Expected an indented block" main()[/CODE] From bruno.42.desthuilliers at websiteburo.invalid Fri Mar 19 06:04:11 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Mar 2010 11:04:11 +0100 Subject: Why this compile error? In-Reply-To: References: Message-ID: <4ba34c10$0$29759$426a74cc@news.free.fr> Jimbo a ?crit : > Hello > > Can you help me figure out why I am getting this compile error with my > program. The error occurs right at the bottom of my code & I have > commented where it occurs. > > The error is: > [QUOTE]Expected an indented block[/QUOTE] > > [CODE] (snip) > # Main program loop > def main(): > programEnd = False; > > while (programEnd == False): > #ERROR HERE?? - Error="Expected an indented block" Indeed. You *need* a stamement in the while block. If you want a noop, then use the 'pass' statement: while programEnd == False: pass But note that as-is, this will go into an infinite loop. From eckhardt at satorlaser.com Fri Mar 19 06:11:18 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 19 Mar 2010 11:11:18 +0100 Subject: Why this compile error? References: Message-ID: <67vb77-sb6.ln1@satorlaser.homedns.org> Jimbo wrote: > Can you help me figure out why I am getting this compile error with my > program. The error occurs right at the bottom of my code & I have > commented where it occurs. [...] > def main(): > programEnd = False; > > while (programEnd == False): > #ERROR HERE?? - Error="Expected an indented block" > main()[/CODE] Was the comment there before or not? In any case, I believe a comment doesn't qualify as indented block, if you want to leave the block empty use 'pass' instead. Also, make sure you don't mix tabs and spaces, which is also a popular way to confuse Python. BTW: "while" doesn't need brackets, that's a C-ism. ;) Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From jeanmichel at sequans.com Fri Mar 19 06:39:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Mar 2010 11:39:57 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: <4BA295A1.70207@hellmutweber.de> References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BA3547D.7080107@sequans.com> Hellmut Weber wrote: > Am 11.03.2010 12:14, schrieb Peter Otten: >> Hellmut Weber wrote: >> >>> Logging works very well giving the filename and line number of the >>> point >>> where it is called. As long as I use the loggers directly. >>> BUT when I have to wrap the logger call in some other function, I >>> always >>> get file name and line number of the call of the logger inside the >>> wrapping function. >>> >>> Is there a possibility to get this information in this situation too? >> >> The official way is probably to write a custom Logger class that >> overrides >> the findCaller() method. >> >> Below is a hack that monkey-patches the logging._srcfile attribute to >> ignore >> user-specified modules in the call stack: >> >> $ cat wrapper.py >> import logging >> import os >> import sys >> >> logger = logging.getLogger() >> >> class SrcFile(object): >> def __init__(self, exclude_files): >> self.files = set(exclude_files) >> def __eq__(self, other): >> return other in self.files >> >> def fixname(filename): >> if filename.lower().endswith((".pyc", ".pyo")): >> filename = filename[:-4] + ".py" >> return os.path.normcase(filename) >> >> if "--monkey" in sys.argv: >> print "patching" >> logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) >> >> def warn(*args, **kw): >> logger.warn(*args, **kw) >> >> $ cat main.py >> import logging >> logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") >> import wrapper >> wrapper.warn("foo") >> wrapper.warn("bar") >> wrapper.warn("baz") >> >> $ python main.py >> wrapper.py<23>: foo >> wrapper.py<23>: bar >> wrapper.py<23>: baz >> >> $ python main.py --monkey >> patching >> main.py<4>: foo >> main.py<5>: bar >> main.py<6>: baz >> >> $ python -V >> Python 2.6.4 >> >> Peter > > Hi Peter, > your hack is exactly what I was looking for. > It permits to configure my logging messages as I want, e.g. using > different colors for different classes of messages. > > I do not yet understand all details WHY it is working but suppose some > study of the logging module will help me to understand. > > Thank you very much > _scrFile is a private attribute of the logging module. Don't change it. As you said yourself, 'The official way is probably to write a custom Logger class that overrides the findCaller() method' JM From peter_peyman_puk at yahoo.ca Fri Mar 19 06:47:53 2010 From: peter_peyman_puk at yahoo.ca (Peyman Askari) Date: Fri, 19 Mar 2010 03:47:53 -0700 (PDT) Subject: Importing modules Message-ID: <180153.53663.qm@web43402.mail.sp1.yahoo.com> I want to write a function which imports modules the first time, and reloads them afterwards, but I am running into problems with global variables and exec. I will include a full script, but let me elaborate first. Essentially what you need is def import_or_reload(): ?"""assume we want to load or reload sys""" ?if 'sys' in dir(): ? reload(sys) else: ? import sys but this runs into the problem that sys is imported within the local scope of the function, so you insert a global statement def import_or_reload2(): ?"""Add 'global sys'""" ?global sys ?if 'sys' in dir(): ? reload(sys) else: ? import sys 'sys' is still not in dir() as dir() pertains to the local scope of the function, but one can get around this by creating a local modules list and adding the imported modules to it def import_or_reload3(): ?"""Add 'global modules'""" ?global sys ?global modules ?if 'sys' in modules: ? reload(sys) else: ? import sys ? modules.append('sys') now lets add a parameter to the function signature, so any module name can be passed as an argument and loaded def import_or_reload4(module_name): ?"""Add exec""" ? exec 'global %s'%module_name ?global modules ?if module_name in modules: ? exec 'reload(%s)'%module_name else: ? exec 'import %s'%module_name ? exec 'modules.append(\'%s\')'%module_name but this doesn't work as global does not cooperate with exec is there a __reload__('X') function like there is an __import__(?X?) function? Also is there a better way to import modules at run time? Cheers and here is the test script in case you can't access the attachment def a(): ??? global modules ??? global sys ??? import sys ??? modules.append('sys') def b(): ??? global modules ??? global sys ??? reload(sys) def c(module_name): ??? global modules ??? exec 'global %s'%module_name ??? exec 'import %s'%module_name ??? modules.append(module_name) def test(): ??? global modules ??? global sys ??? #create the module list to contain all the modules ??? modules=[] ??? print 'originally dir() returns:' ??? print dir() ??? a() ??? print 'function a() properly imports the following module:' ??? print sys ??? print 'is %s in %s->%s'%('sys',modules,'sys' in modules) ??? ??? b() ??? print 'function b() properly reloads the following module:' ??? print sys ??? print 'is %s still in %s->%s'%('sys',modules,'sys' in modules) ??? try: ??? ??? c('os') ??? ??? print 'function c() properly imports the following module:' ??? except: ??? ??? print 'function c() failed to import module os' ??? ??? print 'is %s in %s->%s'%('os',modules,'os' in modules) ??? try: ??? ??? print os ??? ??? print 'is %s still in %s->%s'%('os',modules,'os' in modules) ??? except: ??? ??? print 'os was loaded, but is not visible outside of the scope of c()' --- On Fri, 3/19/10, python-list-request at python.org wrote: From: python-list-request at python.org Subject: Python-list Digest, Vol 78, Issue 192 To: python-list at python.org Received: Friday, March 19, 2010, 7:05 AM Send Python-list mailing list submissions to ??? python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit ??? http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to ??? python-list-request at python.org You can reach the person managing the list at ??? python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: ???1. Re: import antigravity (John Bokma) ???2. Re: Truoble With A Search Script for ImageBin.org ? ? ? (Cameron Simpson) ???3. example of ssl with SimpleXMLRPCServer in 2.6? (Rowland Smith) ???4. Re: multiprocessing on freebsd (Tim Arnold) ???5. Re: Python bindings tutorial (Tim Roberts) ???6. Re: sqlite3, memory db and multithreading (John Nagle) ???7. Re: GC is very expensive: am I doing something wrong? ? ? ? (Patrick Maupin) ???8. Bug in Python APscheduler module. (anand jeyahar) ???9. Re: Bug in Python APscheduler module. (Terry Reedy) ? 10. Re: Python bindings tutorial (Alf P. Steinbach) -- http://mail.python.org/mailman/listinfo/python-list __________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test5.py Type: text/x-python Size: 1044 bytes Desc: not available URL: From królewna at ee.pl Fri Mar 19 06:55:57 2010 From: królewna at ee.pl (=?ISO-8859-1?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 11:55:57 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: <57dc1ce8-1ac7-4d72-aafc-6fe7920144c2@c16g2000yqd.googlegroups.com> References: <57dc1ce8-1ac7-4d72-aafc-6fe7920144c2@c16g2000yqd.googlegroups.com> Message-ID: W dniu 18.03.2010 15:49, DreiJane pisze: > Principally sqlite connections (sqlite3 objects in the C-API) can be > used over multiple threads - and connections to :memory: make no > difference. There are additional parameters to open() giving fine- > tuned control. And apsw is promising a true reflection of sqlite's C- > API. It's my fault not saying what am I using to connect to sqlite db. It's sqlite3 module. So there is no open() function etc. As for now I'm not interested in rewriting my program to use apsw so is there any possible way of working this out with sqlite3? -- best regards princess From królewna at ee.pl Fri Mar 19 06:56:54 2010 From: królewna at ee.pl (=?UTF-8?B?a3LDs2xld25h?=) Date: Fri, 19 Mar 2010 11:56:54 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: W dniu 18.03.2010 23:06, Aahz pisze: > > You probably need to serialize access to the database through one thread. sqlite3 objects are not pickable so it's not proper way. -- best regards princess From królewna at ee.pl Fri Mar 19 07:04:16 2010 From: królewna at ee.pl (=?ISO-8859-1?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 12:04:16 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: <155a70fb-0e4e-43a8-8e4c-0f4475573035@t20g2000yqe.googlegroups.com> References: <155a70fb-0e4e-43a8-8e4c-0f4475573035@t20g2000yqe.googlegroups.com> Message-ID: W dniu 19.03.2010 08:20, Expo pisze: > > You can put the SQLite database into a Singleton class and use a > semaphore to serialize the access to methods which writes to the > database. I've tried this out but doesnt work. Still gives an error like: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id -1216280896 and this is thread id -1217107088 -- best regards princess From mail at timgolden.me.uk Fri Mar 19 07:10:29 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 19 Mar 2010 11:10:29 +0000 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: <4BA35BA5.5020805@timgolden.me.uk> On 19/03/2010 10:56, kr?lewna wrote: > W dniu 18.03.2010 23:06, Aahz pisze: >> >> You probably need to serialize access to the database through one thread. > > sqlite3 objects are not pickable so it's not proper way. Is it possible you've misunderstood the meaning of the word "serialize" here? What's being suggested isn't serialising (ie marshalling, pickling) the data; rather, serialising the *access*, ie pushing all db requests into a queue which is read by one thread which manages the only db connection. TJG From królewna at ee.pl Fri Mar 19 07:24:11 2010 From: królewna at ee.pl (=?ISO-8859-1?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 12:24:11 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: W dniu 19.03.2010 12:10, Tim Golden pisze: > Is it possible you've misunderstood the meaning of the word "serialize" > here? It's not possible, it just happened :) > What's being suggested isn't serialising (ie marshalling, pickling) > the data; rather, serialising the *access*, ie pushing all db requests into > a queue which is read by one thread which manages the only db connection. That would make structure of program much more complicated. I would have to create queue for putting there queries and some other extra variables/structure to receive output from db and some more for controlling the execution flow of awaiting threads. -- best regards princess From kamil at lucem.pl Fri Mar 19 07:48:17 2010 From: kamil at lucem.pl (Kamil Wasilewski) Date: Fri, 19 Mar 2010 12:48:17 +0100 Subject: python-daemon PID file Message-ID: Hi all, Im trying to get a daemon up and running but have been tripping on every stone along the way, this last one however i cant manage to get by. versions: Python 2.5.2 python-daemon-1.5.5 Debian Linux 2.6.26-2-686 Some of the problems ive run into: import daemon with daemon.DaemonContext(): do_main_program() doesnt work on my version of Python 2.5.2 so im using import daemon import grp import pwd diablo.uid = pwd.getpwnam('nobody').pw_uid diablo.gid = grp.getgrnam('nogroup').gr_gid daemon.__enter__() main() daemon.__exit__() Next I had problems with Initd starting the daemon because i forgot to chmod it to 755. The final problem is with the PID file and getting a correct PID written. Initially there was no file being created, so i thought i needed the --make-pidfile option in start-stop-daemon, but ive since learned that the daemon should create and edit the file, not s-s-d as it inserts the PID of the parent process, which is not the correct PID of the final daemon. So i added to my daemon: import lockfile daemon.DaemonContext(pidfile=lockfile.FileLock('/var/run/mydaemon.pid'),) which didnt start the daemon at all as i created the pid file as root, and was setting the Daemon to run as nobody,nogroup so it was dieing silently. Im running it as root for now to see if i can get a correct pid in the pid file. However no PID file is created, and if i create one its not populated with a PID. In summary: I cant get a PID file created or pupulated with a PID by python-daemon. Anyone see something that im doing wrong? ive been sitting on this way too long. I looked at the python-daemon source and i cant see where the pid is inserted into the pid file, only where it __enter__'s the lockfile so is this missing? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From slais-www at ucl.ac.uk Fri Mar 19 08:08:19 2010 From: slais-www at ucl.ac.uk (djc) Date: Fri, 19 Mar 2010 12:08:19 +0000 Subject: should writing Unicode files be so slow In-Reply-To: <8739zxw057.fsf@benfinney.id.au> References: <8739zxw057.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > djc writes: > >> I have a simple program to read a text (.csv) file > > Could you please: > > * simplify it further: make a minimal version that demonstrates the > difference you're seeing, without any extraneous stuff that doesn't > appear to affect the result. > > * make it complete: the code you've shown doesn't do anything except > define some functions. > > In other words: please reduce it to a complete, minimal example that we > can run to see the same behaviour you're seeing. > It is the minimal example. The only thing omited is the opt.parse code that calls _file_to_files(infile, outfile_prefix, column, sep): -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From __peter__ at web.de Fri Mar 19 08:24:41 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Mar 2010 13:24:41 +0100 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Jean-Michel Pichavant wrote: > Hellmut Weber wrote: >> Am 11.03.2010 12:14, schrieb Peter Otten: >>> Hellmut Weber wrote: >>> >>>> Logging works very well giving the filename and line number of the >>>> point >>>> where it is called. As long as I use the loggers directly. >>>> BUT when I have to wrap the logger call in some other function, I >>>> always >>>> get file name and line number of the call of the logger inside the >>>> wrapping function. >>>> >>>> Is there a possibility to get this information in this situation too? >>> >>> The official way is probably to write a custom Logger class that >>> overrides >>> the findCaller() method. >>> >>> Below is a hack that monkey-patches the logging._srcfile attribute to >>> ignore >>> user-specified modules in the call stack: >>> >>> $ cat wrapper.py >>> import logging >>> import os >>> import sys >>> >>> logger = logging.getLogger() >>> >>> class SrcFile(object): >>> def __init__(self, exclude_files): >>> self.files = set(exclude_files) >>> def __eq__(self, other): >>> return other in self.files >>> >>> def fixname(filename): >>> if filename.lower().endswith((".pyc", ".pyo")): >>> filename = filename[:-4] + ".py" >>> return os.path.normcase(filename) >>> >>> if "--monkey" in sys.argv: >>> print "patching" >>> logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) >>> >>> def warn(*args, **kw): >>> logger.warn(*args, **kw) >>> >>> $ cat main.py >>> import logging >>> logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") >>> import wrapper >>> wrapper.warn("foo") >>> wrapper.warn("bar") >>> wrapper.warn("baz") >>> >>> $ python main.py >>> wrapper.py<23>: foo >>> wrapper.py<23>: bar >>> wrapper.py<23>: baz >>> >>> $ python main.py --monkey >>> patching >>> main.py<4>: foo >>> main.py<5>: bar >>> main.py<6>: baz >>> >>> $ python -V >>> Python 2.6.4 >>> >>> Peter >> >> Hi Peter, >> your hack is exactly what I was looking for. >> It permits to configure my logging messages as I want, e.g. using >> different colors for different classes of messages. >> >> I do not yet understand all details WHY it is working but suppose some >> study of the logging module will help me to understand. >> >> Thank you very much >> > _scrFile is a private attribute of the logging module. Don't change it. > > As you said yourself, 'The official way is probably to write a custom > Logger class that overrides > the findCaller() method' OK, I tried the this approach, too: import logging import os import sys from logging import currentframe def fixname(filename): if filename.lower().endswith((".pyc", ".pyo")): filename = filename[:-4] + ".py" return os.path.normcase(filename) class MyLogger(logging.Logger): exclude_files = set([logging._srcfile, fixname(__file__)]) def findCaller(self): """ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ f = currentframe() #On some versions of IronPython, currentframe() returns None if #IronPython isn't run with -X:Frames. if f is not None: f = f.f_back rv = "(unknown file)", 0, "(unknown function)" while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) if filename in self.exclude_files: f = f.f_back continue rv = (filename, f.f_lineno, co.co_name) break return rv if "--custom-logger" in sys.argv: print "setting custom logger" logging.setLoggerClass(MyLogger) logging.root = MyLogger("root", logging.WARNING) logger = logging.getLogger() def warn(*args, **kw): logger.warn(*args, **kw) I had to duplicate the original findCaller() method with only one line changed. This means I have now some code duplication and I still have to monitor future changes in the logging source. In this case the "official way" seems to be more intrusive than the "hack". Peter From davea at ieee.org Fri Mar 19 08:25:15 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Mar 2010 07:25:15 -0500 Subject: Importing modules In-Reply-To: <180153.53663.qm@web43402.mail.sp1.yahoo.com> References: <180153.53663.qm@web43402.mail.sp1.yahoo.com> Message-ID: <4BA36D2B.2000507@ieee.org> Peyman Askari wrote: > I want to write a function which imports modules the first time, and reloads them afterwards, but I am running into problems with global variables and exec. I will include a full script, but let me elaborate first. > > Essentially what you need is > > def import_or_reload(): > """assume we want to load or reload sys""" > if 'sys' in dir(): > reload(sys) > else: > import sys > > but this runs into the problem that sys is imported within the local scope of the function, so you insert a global statement > > > > def import_or_reload2(): > > """Add 'global sys'""" > global sys > > if 'sys' in dir(): > > reload(sys) > > else: > > import sys > > 'sys' is still not in dir() as dir() pertains to the local scope of the function, but one can get around this by creating a local modules list and adding the imported modules to it > > > > > > def import_or_reload3(): > > > """Add 'global modules'""" > > global sys > global modules > > > > if 'sys' in modules: > > > reload(sys) > > > else: > > > import sys > modules.append('sys') > > now lets add a parameter to the function signature, so any module name can be passed as an argument and loaded > > > > > > def import_or_reload4(module_name): > > > > """Add exec""" > > > exec 'global %s'%module_name > > global modules > > > > > > if module_name in modules: > > > > exec 'reload(%s)'%module_name > > > > else: > > > > exec 'import %s'%module_name > > exec 'modules.append(\'%s\')'%module_name > > but this doesn't work as global does not cooperate with exec > is there a __reload__('X') function like there is an __import__(?X?) function? > > Also is there a better way to import modules at run time? > > Cheers and here is the test script in case you can't access the attachment > > def a(): > global modules > global sys > import sys > > modules.append('sys') > > def b(): > global modules > global sys > > reload(sys) > > def c(module_name): > global modules > exec 'global %s'%module_name > exec 'import %s'%module_name > > modules.append(module_name) > > def test(): > global modules > global sys > > #create the module list to contain all the modules > modules=[] > > print 'originally dir() returns:' > print dir() > > a() > print 'function a() properly imports the following module:' > print sys > print 'is %s in %s->%s'%('sys',modules,'sys' in modules) > > b() > print 'function b() properly reloads the following module:' > print sys > print 'is %s still in %s->%s'%('sys',modules,'sys' in modules) > > try: > c('os') > print 'function c() properly imports the following module:' > except: > print 'function c() failed to import module os' > print 'is %s in %s->%s'%('os',modules,'os' in modules) > > try: > print os > print 'is %s still in %s->%s'%('os',modules,'os' in modules) > except: > print 'os was loaded, but is not visible outside of the scope of c()' > --- On Fri, 3/19/10, python-list-request at python.org wrote: > > From: python-list-request at python.org > Subject: Python-list Digest, Vol 78, Issue 192 > To: python-list at python.org > Received: Friday, March 19, 2010, 7:05 AM > > (When starting a new thread, create a new message addressed to python-list at python.org, do not just reply to an existing message, (or digest, which you did here). Some people actually try to follow threads, and the software to do that uses more information than just the message subject) First comment. I would seriously try to avoid using reload() in production code. The problems that can result are subtle. I use it for debugging sessions, but not in real programs. But I'll assume you have a use case (which would have been good to explain), and have rejected the other possibilities. Next, I'll point out that reloading sys isn't desirable, and it's one of the specifically proscribed modules for reloading. But probably you weren't really using sys, you were just sanitizing the code since you knew we all had sys. Next, if your reason for reloading is that you just changed the module programmatically, and it might have been loaded by some other module (as sys is, for example, long before your code starts), then you're not checking in the right place. Instead of looking at your own global space, you should be looking at sys.modules to decide whether something has been loaded. Perhaps the function you're looking for is imp.load_module() DaveA From ben+python at benfinney.id.au Fri Mar 19 08:56:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Mar 2010 23:56:49 +1100 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> Message-ID: <87ljdov59q.fsf@benfinney.id.au> djc writes: > Ben Finney wrote: > > Could you please: > > > > * simplify it further: make a minimal version that demonstrates the > > difference you're seeing, without any extraneous stuff that doesn't > > appear to affect the result. > > > > * make it complete: the code you've shown doesn't do anything except > > define some functions. > > > > In other words: please reduce it to a complete, minimal example that we > > can run to see the same behaviour you're seeing. > > It is the minimal example. The only thing omited is the opt.parse code > that calls _file_to_files(infile, outfile_prefix, column, sep): What happens, then, when you make a smaller program that deals with only one file? What happens when you make a smaller program that only reads the file, and doesn't write any? Or a different program that only writes a file, and doesn't read any? It's these sort of reductions that will help narrow down exactly what the problem is. Do make sure that each example is also complete (i.e. can be run as is by someone who uses only that code with no additions). -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From googler.1.webmaster at spamgourmet.com Fri Mar 19 09:12:34 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 19 Mar 2010 06:12:34 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: In my case I call a funcion and I would like to get the line where the function returned. for instance: def my_function(): return 3 So I would like to get line 2(in C) somehow. From jeanmichel at sequans.com Fri Mar 19 09:49:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Mar 2010 14:49:22 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BA380E2.8060306@sequans.com> Peter Otten wrote: > Jean-Michel Pichavant wrote: > > >> Hellmut Weber wrote: >> >>> Am 11.03.2010 12:14, schrieb Peter Otten: >>> >>>> Hellmut Weber wrote: >>>> >>>> >>>>> Logging works very well giving the filename and line number of the >>>>> point >>>>> where it is called. As long as I use the loggers directly. >>>>> BUT when I have to wrap the logger call in some other function, I >>>>> always >>>>> get file name and line number of the call of the logger inside the >>>>> wrapping function. >>>>> >>>>> Is there a possibility to get this information in this situation too? >>>>> >>>> The official way is probably to write a custom Logger class that >>>> overrides >>>> the findCaller() method. >>>> >>>> Below is a hack that monkey-patches the logging._srcfile attribute to >>>> ignore >>>> user-specified modules in the call stack: >>>> >>>> $ cat wrapper.py >>>> import logging >>>> import os >>>> import sys >>>> >>>> logger = logging.getLogger() >>>> >>>> class SrcFile(object): >>>> def __init__(self, exclude_files): >>>> self.files = set(exclude_files) >>>> def __eq__(self, other): >>>> return other in self.files >>>> >>>> def fixname(filename): >>>> if filename.lower().endswith((".pyc", ".pyo")): >>>> filename = filename[:-4] + ".py" >>>> return os.path.normcase(filename) >>>> >>>> if "--monkey" in sys.argv: >>>> print "patching" >>>> logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) >>>> >>>> def warn(*args, **kw): >>>> logger.warn(*args, **kw) >>>> >>>> $ cat main.py >>>> import logging >>>> logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") >>>> import wrapper >>>> wrapper.warn("foo") >>>> wrapper.warn("bar") >>>> wrapper.warn("baz") >>>> >>>> $ python main.py >>>> wrapper.py<23>: foo >>>> wrapper.py<23>: bar >>>> wrapper.py<23>: baz >>>> >>>> $ python main.py --monkey >>>> patching >>>> main.py<4>: foo >>>> main.py<5>: bar >>>> main.py<6>: baz >>>> >>>> $ python -V >>>> Python 2.6.4 >>>> >>>> Peter >>>> >>> Hi Peter, >>> your hack is exactly what I was looking for. >>> It permits to configure my logging messages as I want, e.g. using >>> different colors for different classes of messages. >>> >>> I do not yet understand all details WHY it is working but suppose some >>> study of the logging module will help me to understand. >>> >>> Thank you very much >>> >>> >> _scrFile is a private attribute of the logging module. Don't change it. >> >> As you said yourself, 'The official way is probably to write a custom >> Logger class that overrides >> the findCaller() method' >> > > OK, I tried the this approach, too: > > import logging > import os > import sys > > from logging import currentframe > > def fixname(filename): > if filename.lower().endswith((".pyc", ".pyo")): > filename = filename[:-4] + ".py" > return os.path.normcase(filename) > > class MyLogger(logging.Logger): > exclude_files = set([logging._srcfile, fixname(__file__)]) > > def findCaller(self): > """ > Find the stack frame of the caller so that we can note the source > file name, line number and function name. > """ > f = currentframe() > #On some versions of IronPython, currentframe() returns None if > #IronPython isn't run with -X:Frames. > if f is not None: > f = f.f_back > rv = "(unknown file)", 0, "(unknown function)" > while hasattr(f, "f_code"): > co = f.f_code > filename = os.path.normcase(co.co_filename) > if filename in self.exclude_files: > f = f.f_back > continue > rv = (filename, f.f_lineno, co.co_name) > break > return rv > > if "--custom-logger" in sys.argv: > print "setting custom logger" > logging.setLoggerClass(MyLogger) > logging.root = MyLogger("root", logging.WARNING) > > logger = logging.getLogger() > def warn(*args, **kw): > logger.warn(*args, **kw) > > I had to duplicate the original findCaller() method with only one line > changed. This means I have now some code duplication and I still have to > monitor future changes in the logging source. > > In this case the "official way" seems to be more intrusive than the "hack". > > Peter You are still accessing the private attribute of the module logging. My previous remark was misleading, in fact there's nothing you can do about it. _srcfile is not meant to be used elsewhere than in the logging module itself. However, I don't wanna sound like I'm rejecting this solution, 1st the OP is satisified with it and since this solution is working, it is still more helpful than anyone noticing that you've accessed a private attribute (some will successfully argue that python allows to do so). At the very begining of this thread I've provided a complete different approach, instead of using the builtin 'filename' and 'lineno' field of the logging, use custom fileds with the extra parameter. It has also some drawbacks but could be a possible alternative. Cheers, JM in test.py: import logging import inspect _logger = logging.getLogger(__name__) class Foo: def __init__(self): self._logger = _logger def info(self, msg): # this is the method you don't want to appear in the logs, instead the lineno and filename of this method caller previousFrame = inspect.currentframe().f_back self._logger.info(msg, extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename}) if __name__ == '__main__': _logger.handlers=[] _logger.addHandler(logging.StreamHandler()) _logger.handlers[-1].setFormatter(logging.Formatter('file %(custom_filename)s line %(custom_lineno)d : %(message)s')) _logger.setLevel(logging.DEBUG) foo = Foo() foo.info('a foo info') In [3]: run test.py file test.py line 20 : a foo info From królewna at ee.pl Fri Mar 19 09:58:22 2010 From: królewna at ee.pl (=?ISO-8859-2?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 14:58:22 +0100 Subject: SOLUTION In-Reply-To: References: Message-ID: I have found the solution. I dont know why in python documentation there is not a single word about this option. I've found it in pysqlite doc site. So we have to add a new keyword argument to connection function and we will be able to create cursors out of it in different thread. So use: sqlite.connect(":memory:", check_same_thread = False) works out perfectly for me. Of course from now on me need to take care of safe multithreading access to the db. Anyway thx all for trying to help. -- best regards princess From stefan_ml at behnel.de Fri Mar 19 10:11:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Mar 2010 15:11:42 +0100 Subject: C-API PyObject_Call In-Reply-To: References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: moerchendiser2k3, 19.03.2010 14:12: > In my case I call a funcion and I would like to get the line > where the function returned. > > for instance: > > > def my_function(): > return 3 > > So I would like to get line 2(in C) somehow. Ok, so you're looking for the C-level trace function in CPython, I guess. Could you explain why you want to know the line number? Stefan From python at hope.cz Fri Mar 19 11:32:32 2010 From: python at hope.cz (Johny) Date: Fri, 19 Mar 2010 08:32:32 -0700 (PDT) Subject: What is pkg-config for ? Message-ID: Can anyone explain what is pkg-config for?ANd how can I find it in Windows? Thanks From peter_peyman_puk at yahoo.ca Fri Mar 19 13:09:09 2010 From: peter_peyman_puk at yahoo.ca (Peter Peyman Puk) Date: Fri, 19 Mar 2010 17:09:09 +0000 Subject: Importing v reloading modules modules In-Reply-To: <4BA3A738.1050401@ieee.org> References: <202203.80122.qm@web43401.mail.sp1.yahoo.com> <4BA3A738.1050401@ieee.org> Message-ID: <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> Hello I submitted this earlier today, but I was not clear enough, so I am posting it again. I am running a simulator written in python. The simulator has a small TextView (actually a SourceView) widget which lets the user writes scripts, and when they are satisfied they can execute that script to get results. For arguments sake, we write a simple script and save it as A.py and we import it and execute it more or less like so. import A #assume there is a function called test() in module A A.test() Then the user modifies the contents of A.py and saves it again (to A.py) now all we have to do is the following if 'A' in dir(): reload(A) else: import A A.test() But since the user chooses the file name, and not me, the programmer, the module names will vary. Let's assume the module names are loaded and stored in the list module_names, and we iterate over them, and pass them as arguments to a function to import or reload each model as appropriate def import_or_reload(module_name): if module_name in sys.modules: #somehow reload else: #somehow import does anyone know how to deal with the reload and import as they both present problems since module_name is a string, and to reload something along the lines of the below must be executed exec 'reload(%s)'%module_name and then we also have to deal with the scope issue since the loaded module will be local and not global. I can execute something like so exec 'global %s'%module_name but that does not work very well with exec any suggestions? Cheers Peyman From slais-www at ucl.ac.uk Fri Mar 19 13:18:17 2010 From: slais-www at ucl.ac.uk (djc) Date: Fri, 19 Mar 2010 17:18:17 +0000 Subject: should writing Unicode files be so slow In-Reply-To: <87ljdov59q.fsf@benfinney.id.au> References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > What happens, then, when you make a smaller program that deals with only > one file? > > What happens when you make a smaller program that only reads the file, > and doesn't write any? Or a different program that only writes a file, > and doesn't read any? > > It's these sort of reductions that will help narrow down exactly what > the problem is. Do make sure that each example is also complete (i.e. > can be run as is by someone who uses only that code with no additions). > The program reads one csv file of 9,293,271 lines. 869M wb.csv It creates set of files containing the same lines but where each output file in the set contains only those lines where the value of a particular column is the same, the number of output files will depend on the number of distinct values in that column In the example that results in 19 files 74M tt_11696870405.txt 94M tt_18762175493.txt 15M tt_28668070915.txt 12M tt_28673313795.txt 15M tt_28678556675.txt 11M tt_28683799555.txt 12M tt_28689042435.txt 15M tt_28694285315.txt 7.3M tt_28835845125.txt 6.8M tt_28842136581.txt 12M tt_28848428037.txt 11M tt_28853670917.txt 12M tt_28858913797.txt 15M tt_28864156677.txt 11M tt_28869399557.txt 11M tt_28874642437.txt 283M tt_31002203141.txt 259M tt_33335282691.txt 45 2010-03-19 17:00 tt_taskid.txt changing with open(filename, 'rU') as tabfile: to with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as tabfile: and with open(outfile, 'wt') as out_part: to with codecs.open(outfile, 'w', 'utf-8') as out_part: causes a program that runs in 43 seconds to take 4 minutes to process the same data. In this particular case that is not very important, any unicode strings in the data are not worth troubling over and I have already spent more time satisfying curiousity that will ever be required to process the dataset in future. But I have another project in hand where not only is the unicode significant but the files are very much larger. Scale up the problem and the difference between 4 hours and 24 become a matter worth some attention. -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From incensedprey at gmail.com Fri Mar 19 13:42:53 2010 From: incensedprey at gmail.com (Kevin Adams) Date: Fri, 19 Mar 2010 10:42:53 -0700 (PDT) Subject: [python3] Message-ID: Greetings! Please forgive me if im posting this to the wrong group. I'm new to Python, learning Python3 from the O'rielly "Learning Python" book. Reading about operator overloading, specifically __getitem__. I put together a small bit of code to do some experimenting and threw in a timer so i can see it do its thing. For some reason the time.sleep(x) function doesnt work when my print function includes "end=''". Thanks in advance for any help. ---code--- class TestClass(): def __init__(self): self.data = "I was far from home and the spell of the eastern sea was upon me." def __getitem__(self,i): return self.data[i] import time if __name__ == "__main__": me = TestClass() for x in me: print(x,end='') #if i remove the 'end=''' it performs as i'd expect time.sleep(int(2)) From tjreedy at udel.edu Fri Mar 19 14:02:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 14:02:02 -0400 Subject: Importing v reloading modules modules In-Reply-To: <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> References: <202203.80122.qm@web43401.mail.sp1.yahoo.com> <4BA3A738.1050401@ieee.org> <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> Message-ID: Reload is effectively deprecated in 2.x and removed in 3.x, so I recommend not using it. Deleting an entry from sys.modules should force recreation with an import. Just make sure all other references are also gone so that the module object can be deleted. The following shows how to import by name in string and globally from within a function. def f(): global itertools itertools = __import__('itertools') f() print(itertools) # 3.1 # Terry Jan Reedy From steve at holdenweb.com Fri Mar 19 14:17:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Mar 2010 14:17:31 -0400 Subject: [python3] In-Reply-To: References: Message-ID: Kevin Adams wrote: > Greetings! > > Please forgive me if im posting this to the wrong group. > > I'm new to Python, learning Python3 from the O'rielly "Learning > Python" book. Reading > about operator overloading, specifically __getitem__. I put together > a small bit of code to > do some experimenting and threw in a timer so i can see it do its > thing. For some reason > the time.sleep(x) function doesnt work when my print function includes > "end=''". > > Thanks in advance for any help. > > Try the following changes: > ---code--- > > class TestClass(): > def __init__(self): > self.data = "I was far from home and the spell of the eastern > sea was upon me." > > def __getitem__(self,i): > return self.data[i] > > > import time import sys > > if __name__ == "__main__": > > me = TestClass() > for x in me: > print(x,end='') #if i remove the 'end=''' it performs as i'd > expect sys.stdout.flush() > time.sleep(int(2)) > It may just be that the output is being held in buffers until the program terminates. the fluch() methof pushes it straight out. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From krister.svanlund at gmail.com Fri Mar 19 14:19:04 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 19 Mar 2010 19:19:04 +0100 Subject: [python3] In-Reply-To: References: Message-ID: <2cf430a61003191119h688fef20u528f7e154680c00c@mail.gmail.com> On Fri, Mar 19, 2010 at 6:42 PM, Kevin Adams wrote: > Greetings! > > Please forgive me if im posting this to the wrong group. > > I'm new to Python, learning Python3 from the O'rielly "Learning > Python" book. ?Reading > about operator overloading, specifically __getitem__. ? I put together > a small bit of code to > do some experimenting and threw in a timer so i can see it do its > thing. ?For some reason > the time.sleep(x) function doesnt work when my print function includes > "end=''". > > Thanks in advance for any help. > > > ---code--- > > class TestClass(): > ? ?def __init__(self): > ? ? ? ?self.data = "I was far from home and the spell of the eastern > sea was upon me." > > ? ?def __getitem__(self,i): > ? ? ? ?return self.data[i] > > > import time > > if __name__ == "__main__": > > ? ?me = TestClass() > ? ?for x in me: > ? ? ? ?print(x,end='') ?#if i remove the 'end=''' ?it performs as i'd > expect > ? ? ? ?time.sleep(int(2)) > > -- > http://mail.python.org/mailman/listinfo/python-list > I'm guessing wildly here but I think you have to flush the output. Can't remember how right now but it won't take much googling for it. From tjreedy at udel.edu Fri Mar 19 14:21:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 14:21:34 -0400 Subject: [python3] In-Reply-To: References: Message-ID: On 3/19/2010 1:42 PM, Kevin Adams wrote: > Please forgive me if im posting this to the wrong group. Just the right place. I would suggest a more informative title in the future though. 'Problem with print and sleep.', for instance. > > I'm new to Python, learning Python3 from the O'rielly "Learning > Python" book. Reading > about operator overloading, specifically __getitem__. I put together > a small bit of code to > do some experimenting and threw in a timer so i can see it do its > thing. Good idea. Welcome to Python. > For some reason > the time.sleep(x) function doesnt work when my print function includes > "end=''". I cut your code, pasted it into IDLE edit window, and made two minor modifications. For me (3.1, winxp) it works perfectly either way -- chars print at 1 sec intervals either vertically or horizonatally. So I am not sure what you are claiming. > > Thanks in advance for any help. > > > ---code--- > > class TestClass(): > def __init__(self): > self.data = "I was far from home and the spell of the eastern > sea was upon me." I shortened string > > def __getitem__(self,i): > return self.data[i] > > import time > > if __name__ == "__main__": > > me = TestClass() > for x in me: > print(x,end='') #if i remove the 'end=''' it performs as i'd > expect > time.sleep(int(2)) int(2) == 2, so delete irrelevant call, and 1 sec is enough Terry Jan Reedy From incensedprey at gmail.com Fri Mar 19 14:46:40 2010 From: incensedprey at gmail.com (Kevin Adams) Date: Fri, 19 Mar 2010 11:46:40 -0700 (PDT) Subject: [python3] References: Message-ID: <5780a357-08a2-4393-9b2d-e07e4bb14b83@q16g2000yqq.googlegroups.com> On Mar 19, 2:21?pm, Terry Reedy wrote: > On 3/19/2010 1:42 PM, Kevin Adams wrote: > > > Please forgive me if im posting this to the wrong group. > > Just the right place. I would suggest a more informative title in the > future though. 'Problem with print and sleep.', for instance. > > > > > I'm new to Python, learning Python3 from the O'rielly "Learning > > Python" book. ?Reading > > about operator overloading, specifically __getitem__. ? I put together > > a small bit of code to > > do some experimenting and threw in a timer so i can see it do its > > thing. > > Good idea. Welcome to Python. > > > ?For some reason > > the time.sleep(x) function doesnt work when my print function includes > > "end=''". > > I cut your code, pasted it into IDLE edit window, and made two minor > modifications. For me (3.1, winxp) it works perfectly either way -- > chars print at 1 sec intervals either vertically or horizonatally. So I > am not sure what you are claiming. > > > > > Thanks in advance for any help. > > > ---code--- > > > class TestClass(): > > ? ? ?def __init__(self): > > ? ? ? ? ?self.data = "I was far from home and the spell of the eastern > > sea was upon me." > > I shortened string > > > > > ? ? ?def __getitem__(self,i): > > ? ? ? ? ?return self.data[i] > > > import time > > > if __name__ == "__main__": > > > ? ? ?me = TestClass() > > ? ? ?for x in me: > > ? ? ? ? ?print(x,end='') ?#if i remove the 'end=''' ?it performs as i'd > > expect > > ? ? ? ? ?time.sleep(int(2)) > > int(2) == 2, so delete irrelevant call, and 1 sec is enough > > Terry Jan Reedy Thanks to all!!! It did indeed turn out to be a need to flush the stdout. K ps. sorry for the brief subject, i wasnt finish and hit send before comming back to it. From heintest at web.de Fri Mar 19 14:46:45 2010 From: heintest at web.de (=?ISO-8859-15?Q?Hans_M=FCller?=) Date: Fri, 19 Mar 2010 19:46:45 +0100 Subject: Reserving binary Buffer for struct.pack_into() of exact length Message-ID: <4ba3c6ce$0$6990$9b4e6d93@newsspool4.arcor-online.net> Hello, I need some buffers, which are beeing concatenated an then send via the socket() function. My problem is that create_string_buffer() creates a buffer which ist one byte too long (for a \0 char). But when I concatenate some of these buffers to a long one to be transfered, the extra byte is corrupting the resulting buffer. Of course I could slice the buffer before being concatended, but this looks ugly to me. Is there a way to create a writeable buffer object without the \0 byte ? Thanks a lot Hans From tjreedy at udel.edu Fri Mar 19 15:02:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 15:02:56 -0400 Subject: [python3] In-Reply-To: References: Message-ID: On 3/19/2010 2:17 PM, Steve Holden wrote: > Kevin Adams wrote: >> Greetings! >> >> Please forgive me if im posting this to the wrong group. >> >> I'm new to Python, learning Python3 from the O'rielly "Learning >> Python" book. Reading >> about operator overloading, specifically __getitem__. I put together >> a small bit of code to >> do some experimenting and threw in a timer so i can see it do its >> thing. For some reason >> the time.sleep(x) function doesnt work when my print function includes >> "end=''". >> >> Thanks in advance for any help. >> >> > Try the following changes: > >> ---code--- >> >> class TestClass(): >> def __init__(self): >> self.data = "I was far from home and the spell of the eastern >> sea was upon me." >> >> def __getitem__(self,i): >> return self.data[i] >> >> >> import time > > import sys >> >> if __name__ == "__main__": >> >> me = TestClass() >> for x in me: >> print(x,end='') #if i remove the 'end=''' it performs as i'd >> expect > sys.stdout.flush() > >> time.sleep(int(2)) > > It may just be that the output is being held in buffers until the > program terminates. the fluch() methof pushes it straight out. The IDLE Shell window must get print output back from the pythonw process without buffering. When I cut and pasted from IDLE editor to standard interpreter window, output was bunched after several seconds. OP should have started with short string and minimal delay so output would not take a whole minute. Flushing fixed problem in standard interpreter. I will have to remember that testing partial line output in IDLE does not show how it will act elsewhere. Kevin: when reporting a problem, be more specific as to what 'does not work' means. Terry Jan Reedy From emile at fenx.com Fri Mar 19 16:33:00 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 19 Mar 2010 13:33:00 -0700 Subject: Reserving binary Buffer for struct.pack_into() of exact length In-Reply-To: <4ba3c6ce$0$6990$9b4e6d93@newsspool4.arcor-online.net> References: <4ba3c6ce$0$6990$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On 3/19/2010 11:46 AM Hans M?ller said... > Hello, > > I need some buffers, which are beeing concatenated an then send via the > socket() function. > My problem is that create_string_buffer() creates a buffer which ist one > byte too long (for a \0 char). But when I concatenate some of these > buffers to a long one to be transfered, the extra byte is corrupting the > resulting buffer. > Of course I could slice the buffer before being concatended, but > this looks ugly to me. > Is there a way to create a writeable buffer object without the \0 byte ? > > Thanks a lot > > Hans >>> p = create_string_buffer(5) >>> p.raw='hello' >>> p.value 'hello' From saimapk81 at gmail.com Fri Mar 19 17:03:41 2010 From: saimapk81 at gmail.com (saima81) Date: Fri, 19 Mar 2010 14:03:41 -0700 (PDT) Subject: "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com Message-ID: "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com From brandonc530 at gmail.com Fri Mar 19 17:10:54 2010 From: brandonc530 at gmail.com (Brandon C) Date: Fri, 19 Mar 2010 16:10:54 -0500 Subject: Truoble With A Search Script for ImageBin.org In-Reply-To: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> References: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> Message-ID: <3020ae661003191410i2f5e831et16dbd6fbf9e67e4d@mail.gmail.com> *grumble* *grumble* *grumble* oops, sorry ... my mistake it turns out that i misspelled one of the values and left another one out. here's the working script now for anyone who may care: import urllib import urllib2 url = 'http://imagebin.org/index.php?page=search' values = {'search_for' : 'blah', 'field' : 'nickname', 'mode' : 'search'} data = urllib.urlencode(values) request = urllib2.Request(url, data) response = urllib2.urlopen(request) page = response.read() print page the value of 'field' is 'nickname, not 'Nickname'; and i left out the 'mode' one tks for yalls help -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Mar 19 17:12:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 18:12:14 -0300 Subject: What is pkg-config for ? References: Message-ID: En Fri, 19 Mar 2010 12:32:32 -0300, Johny escribi?: > Can anyone explain what is pkg-config for?ANd how can I find it in > Windows? Go to http://www.google.com/ Enter "pkg-config windows" (without quotes) in the input box. Press the Search button. You'll get this site at the top, or near it: http://pkg-config.freedesktop.org/wiki/ I fail to see how is this relevant to Python... -- Gabriel Genellina From brandonc530 at gmail.com Fri Mar 19 18:02:25 2010 From: brandonc530 at gmail.com (Brandon C) Date: Fri, 19 Mar 2010 17:02:25 -0500 Subject: script to upload file using POST form Message-ID: <3020ae661003191502r1b87844fj3af5a0ccd45a3120@mail.gmail.com> got another question for yall wonderful minds; how can i upload a file to a server that uses a POST form? here's the link to the form that i'd like to be able to upload a file: http://imagebin.org/index.php?page=add tks -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Mar 19 18:23:59 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 19:23:59 -0300 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: En Fri, 19 Mar 2010 14:18:17 -0300, djc escribi?: > Ben Finney wrote: > >> What happens, then, when you make a smaller program that deals with only >> one file? >> >> What happens when you make a smaller program that only reads the file, >> and doesn't write any? Or a different program that only writes a file, >> and doesn't read any? >> >> It's these sort of reductions that will help narrow down exactly what >> the problem is. Do make sure that each example is also complete (i.e. >> can be run as is by someone who uses only that code with no additions). >> > > > The program reads one csv file of 9,293,271 lines. > 869M wb.csv > It creates set of files containing the same lines but where > each > output file in the set contains only those lines where the value of a > particular column is the same, the number of output files will depend on > the number of distinct values in that column In the example that results > in 19 files > > changing > with open(filename, 'rU') as tabfile: > to > with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as tabfile: > > and > with open(outfile, 'wt') as out_part: > to > with codecs.open(outfile, 'w', 'utf-8') as out_part: > > causes a program that runs in > 43 seconds to take 4 minutes to process the same data. In this particular > case that is not very important, any unicode strings in the data are > not > worth troubling over and I have already spent more time satisfying > curiousity that will ever be required to process the dataset in > future. But I have another project in hand where not only is the > unicode significant but the files are very much larger. Scale up the > problem and the difference between 4 hours and 24 become a matter worth > some attention. Ok. Your test program is too large to determine what's going on. Try to determine first *which* part is slow: - reading: measure the time it takes only to read a file, with open() and codecs.open() It might be important the density of non-ascii characters and their relative code points (as utf-8 is much more efficient for ASCII data than, say, Hanzi) - processing: measure the time it takes the processing part (fed with str vs unicode data) - writing: measure the time it takes only to write a file, with open() and codecs.open() Only then one can focus on optimizing the bottleneck. -- Gabriel Genellina From barry at python.org Fri Mar 19 18:56:55 2010 From: barry at python.org (Barry Warsaw) Date: Fri, 19 Mar 2010 18:56:55 -0400 Subject: RELEASED Python 2.6.5 Message-ID: <20100319185655.26e1bf1a@heresy> On behalf of the Python community, I'm happy to announce the availability of Python 2.6.5 final. This is the latest production-ready version in the Python 2.6 series. Python 2.6.5 fixes dozens of issues in the core, built-in modules, libraries, and documentation since Python 2.6.4 was released back in October 2009. We highly recommend that you upgrade to Python 2.6.5. Please see the NEWS file for all the gory details. http://www.python.org/download/releases/2.6.5/NEWS.txt Source tarballs and the Windows installers can be downloaded from the Python 2.6.5 page. The Mac OS X disk image will be uploaded soon. http://www.python.org/download/releases/2.6.5/ For more information on Python 2.6 in general, please see http://docs.python.org/whatsnew/2.6.html Please report bugs for any Python version in the Python tracker. http://bugs.python.org Enjoy, -Barry Barry Warsaw barry at python.org Python 2.6 Release Manager (on behalf of the entire python-dev team) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From ben+python at benfinney.id.au Fri Mar 19 19:01:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Mar 2010 10:01:44 +1100 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: <87d3yzvrtz.fsf@benfinney.id.au> "Gabriel Genellina" writes: > Ok. Your test program is too large to determine what's going on. Try > to determine first *which* part is slow: Right. This is done by the diagnostic technique of writing *new*, minimal, complete programs that exercise each piece of the functionality separately. You're not tinkering with the existing program that's misbehaving; you're trying to *recreate* the misbehaviour under a simpler environment. Hope that helps. Feel free to continue posting complete minimal programs that exercise one thing and show behaviour you're unsure about. -- \ ?We now have access to so much information that we can find | `\ support for any prejudice or opinion.? ?David Suzuki, 2008-06-27 | _o__) | Ben Finney From gagsl-py2 at yahoo.com.ar Fri Mar 19 19:04:01 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 20:04:01 -0300 Subject: script to upload file using POST form References: <3020ae661003191502r1b87844fj3af5a0ccd45a3120@mail.gmail.com> Message-ID: En Fri, 19 Mar 2010 19:02:25 -0300, Brandon C escribi?: > got another question for yall wonderful minds; how can i upload a file > to a > server that uses a POST form? > > here's the link to the form that i'd like to be able to upload a file: > http://imagebin.org/index.php?page=add Unfortunately it isn't as easy as it should be: http://bugs.python.org/issue3244 -- Gabriel Genellina From steve at holdenweb.com Fri Mar 19 19:32:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Mar 2010 19:32:44 -0400 Subject: Python Documentation website layout changed? In-Reply-To: <4BA120A9.3060001@holdenweb.com> References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> <4BA120A9.3060001@holdenweb.com> Message-ID: Steve Holden wrote: > Andrej Mitrovic wrote: >> On Mar 17, 6:41 pm, Andrej Mitrovic >> wrote: >>> Hi, >>> >>> What happened to the sidebar on the left of the documentation website? >>> It seems to be gone: >>> >>> http://docs.python.org/py3k/index.html >>> >>> I found it quite useful since I can quickly swap between Python2/3 >>> documentation, and between other parts of the documentation as well. >> Edit: It looks like only the Python 3 pages are affected, the Python 2 >> pages are the same as before: >> >> http://docs.python.org/index.html >> >> Might be a bug? > > I'll ask. Georg - is this known behavior or a temporary problem? > It's a bug. Georg is on it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From solipsis at pitrou.net Fri Mar 19 20:19:07 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 20 Mar 2010 00:19:07 +0000 (UTC) Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: Le Fri, 19 Mar 2010 17:18:17 +0000, djc a ?crit?: > > changing > with open(filename, 'rU') as tabfile: to > with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as > tabfile: > > and > with open(outfile, 'wt') as out_part: to > with codecs.open(outfile, 'w', 'utf-8') as out_part: > > causes a program that runs in > 43 seconds to take 4 minutes to process the same data. codecs.open() (and the object it returns) is slow as it is written in pure Python. Accelerated reading and writing of unicode files is available in Python 2.7 and 3.1, using the new `io` module. Regards Antoine. From speeze.pearson at gmail.com Fri Mar 19 20:20:31 2010 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Fri, 19 Mar 2010 17:20:31 -0700 (PDT) Subject: Tuples vs. variable-length argument lists Message-ID: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> Hi! This might be more of a personal-preference question than anything, but here goes: when is it appropriate for a function to take a list or tuple as input, and when should it allow a varying number of arguments? It seems as though the two are always interchangeable. For a simple example... def subtract( x, nums ): return x - sum( nums ) ... works equally well if you define it as "subtract( x, *nums )" and put an asterisk in front of any lists/tuples you pass it. I can't think of any situation where you couldn't convert from one form to the other with just a star or a pair of parentheses. Is there a generally accepted convention for which method to use? Is there ever actually a big difference between the two that I'm not seeing? From gagsl-py2 at yahoo.com.ar Fri Mar 19 21:28:12 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 22:28:12 -0300 Subject: Importing v reloading modules modules References: <202203.80122.qm@web43401.mail.sp1.yahoo.com> <4BA3A738.1050401@ieee.org> <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> Message-ID: En Fri, 19 Mar 2010 14:09:09 -0300, Peter Peyman Puk escribi?: > I am running a simulator written in python. The simulator has a small > TextView (actually a SourceView) widget which lets the user writes > scripts, and when they are satisfied they can execute that script to get > results. For arguments sake, we write a simple script and save it as > A.py and we import it and execute it more or less like so. > > import A > > #assume there is a function called test() in module A > A.test() > > > Then the user modifies the contents of A.py and saves it again (to A.py) > now all we have to do is the following > > if 'A' in dir(): > reload(A) > else: > import A > > A.test() Terry Reedy already gave you an answer for this import problem. I'd like to go one step back and question whether using import/modules is the right thing here. Clearly A.py is not a module but a script (that's the word you used) - and one does not *import* a script but *executes* it. That is, instead of using import/__import__, use exec (or execfile) within a known namespace: import __builtin__ ns = {'__builtins__': __builtin__.__dict__} exec contents_of_textview in ns # any change made to ns is visible here -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Mar 19 21:54:58 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 22:54:58 -0300 Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> Message-ID: En Wed, 17 Mar 2010 09:42:06 -0300, Pascal Chambon escribi?: > traceback functions indeed allow the manipulation of exception > tracebacks, > but the root problem is that anyway, since that traceback is incomplete, > your "traceback.format_exc().splitlines()" will only provide frames for > callee (downward) functions, not caller (upward) ones, starting from the > exception catching frame. Either I don't understand what you mean, or I can't reproduce it: import logging def a(): return b() def b(): return c() def c(): return d() def d(): raise ValueError def main(): logging.basicConfig(level=logging.DEBUG) try: a() except: logging.exception("An error") main() Output: D:\temp>python test_logging.py ERROR:root:An error Traceback (most recent call last): File "test_logging.py", line 10, in main try: a() File "test_logging.py", line 3, in a def a(): return b() File "test_logging.py", line 4, in b def b(): return c() File "test_logging.py", line 5, in c def c(): return d() File "test_logging.py", line 6, in d def d(): raise ValueError ValueError -- Gabriel Genellina From googler.1.webmaster at spamgourmet.com Fri Mar 19 21:58:28 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 19 Mar 2010 18:58:28 -0700 (PDT) Subject: Simple lock Message-ID: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Hi, I have a common question about locks: class SetPointer { private: void *ptr; MY_LOCK lock; public: void SetPointer(void *p) { Lock(this->lock); this->ptr = p; } void *GetPointer() { Lock(this->lock); return this->ptr; } }; Just a question, is this lock redundant, when the Pointer can be set/ get from different threads? Thanks a lot!! Bye, moerchendiser2k3 From googler.1.webmaster at spamgourmet.com Fri Mar 19 22:01:45 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 19 Mar 2010 19:01:45 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: <7597f6a5-5fe0-4a69-9f9b-f0d96f4499d1@g26g2000yqn.googlegroups.com> Yes, the user is able to set a file which contains a function that does what the user wants. But in a case, I expect a special return value of this function. So, I need to tell him, in which file/line the error occured, otherwise he dont know where to look. Imagine he set 20 files, and all of them have implemented a special function. So he wouldnt know where to check for the error. Bye, moerchendiser2k3 From ben+python at benfinney.id.au Fri Mar 19 22:24:57 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Mar 2010 13:24:57 +1100 Subject: Simple lock References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Message-ID: <878w9nvifa.fsf@benfinney.id.au> moerchendiser2k3 writes: > I have a common question about locks: You'd be best to ask in a forum related to the language you're using. This (?comp.lang.python?) is a forum for users of the Python language. -- \ ?If you can do no good, at least do no harm.? ?_Slapstick_, | `\ Kurt Vonnegut | _o__) | Ben Finney From clp2 at rebertia.com Fri Mar 19 22:25:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Mar 2010 19:25:27 -0700 Subject: Simple lock In-Reply-To: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Message-ID: <50697b2c1003191925l6fd1c19alf4f8cdf31053b547@mail.gmail.com> On Fri, Mar 19, 2010 at 6:58 PM, moerchendiser2k3 wrote: > > Thanks a lot!! Bye, moerchendiser2k3 This is the **Python** mailinglist/newsgroup; and your question isn't about Python. The C++ one is over there: http://groups.google.com/group/comp.lang.c++.moderated/topics Regards, Chris From python at mrabarnett.plus.com Fri Mar 19 22:31:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Mar 2010 02:31:23 +0000 Subject: Simple lock In-Reply-To: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Message-ID: <4BA4337B.6050301@mrabarnett.plus.com> moerchendiser2k3 wrote: > Hi, > > I have a common question about locks: > > class SetPointer > { > private: > void *ptr; > > MY_LOCK lock; > > > public: > void SetPointer(void *p) > { > Lock(this->lock); > this->ptr = p; > } > > void *GetPointer() > { > Lock(this->lock); > return this->ptr; > } > }; > > > Just a question, is this lock redundant, when the Pointer can be set/ > get from different threads? > Thanks a lot!! Bye, moerchendiser2k3 1. That's C++. What does it have to do with Python? 2. The value you're accessing is a simple pointer which you're either setting or getting, so a lock shouldn't be necessary. 3. You're locking, but never unlocking. The sequence should be: lock, do stuff, unlock. From nilly16 at yahoo.com Fri Mar 19 23:04:08 2010 From: nilly16 at yahoo.com (Jimbo) Date: Fri, 19 Mar 2010 20:04:08 -0700 (PDT) Subject: Best Way to extract Numbers from String Message-ID: Hello I am trying to grab some numbers from a string containing HTML text. Can you suggest any good functions that I could use to do this? What would be the easiest way to extract the following numbers from this string... My String has this layout & I have commented what I want to grab: [CODE] """
43.200 0.040 43.150 43.200 43.130 43.290 43.100 7,450,447 Options Warrants & Structured Products CFDs XD Recent
43.200 0.040 43.150 43.200 43.130 43.200 0.040 43.150 43.200 43.130 43.290 43.100 7,450,447 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/optionPrices.do? > by=underlyingCode&underlyingCode=BHP&expiryDate=&optionType=">Options a> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/warrantPrices.do? > by=underlyingAsxCode&underlyingCode=BHP">Warrants & Structured > Products ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/cfdPrices.do? > by=underlyingAsxCode&underlyingCode=BHP">CFDs< img > src="/images/chart.gif" border="0" height="15" width="15"> > XD > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Recent >
43.200 0.040 43.150 43.200 43.130 43.290 43.100 7,450,447 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/optionPrices.do? > > by=underlyingCode&underlyingCode=BHP&expiryDate=&optionType=">Options > a> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/warrantPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">Warrants & Structured > > Products > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/cfdPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">CFDs< img > > src="/images/chart.gif" border="0" height="15" width="15"> > > XD > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Recent > >
43.200 0.040 > 43.150 43.200 43.130 43.290 43.100 7,450,447 > > href="/asx/markets/optionPrices.do? > > by=underlyingCode&underlyingCode=BHP&expiryDate=&optionType=">Options > a> > > href="/asx/markets/warrantPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">Warrants & Structured > > Products > href="/asx/markets/cfdPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">CFDs< > img > > src="/images/chart.gif" border="0" height="15" width="15"> > > href="/research/announcements/status_notes.htm#XD">XD > > href="/asx/statistics/announcements.do? > > by=asxCode&asxCode=BHP&timeframe=D&period=W">Recent > >
([\d\.,]+)\s*%s' ASXurl = 'http://www.asx.com.au/asx/markets/priceLookup.do? by=asxCodes&asxCodes=' class stock: code = "" purchasePrice = 0 purchaseQuantity = 0 price = [] # list of recent prices recentBid = [] # list of recent bids for stock recentOffer = [] # list of recent offers for stock stockVol = [] # list of stock quantity available on market def __init__(self): """ Default Constructor """ self.code = "" self.purchasePrice = 0 self.purchaseQuantity = 0 def constructor(self, stockCode, purPrice, purQuant): """ Constructor """ self.code = stockCode self.purchasePrice = purPrice self.purchaseQuantity = purQuant def setData(self, stockCode, purPrice, purQuant, priceList, reBidList, reOffList, popList): """ Defines & implements the objects' public variables """ self.code = stockCode self.purchasePrice = purPrice self.purchaseQuantity = purQuant self.price = priceList self.recentBid = reBidList self.recentOffer = reOffList self.stockVol = popList self.printStats() def updateData(self, priceEle, bidEle, offerEle, populEle): """ Adds data to stock object's lists """ self.price.append(priceEle) self.recentBid.append(bidEle) self.recentOffer.append(offerEle) self.stockVol.append(populEle) def printStats(self): """ Output Stock attributes """ print("Stock Code: "+self.code) print("Stock Purchase Price: "+str(self.purchasePrice)) print("Stock Quantity Owned: "+str(self.purchaseQuantity)) print("***Initial Investment Value: "+str(self.purchasePrice*self.purchaseQuantity)) if not(len(self.price) <= 0): print("Stock Current Price: "+str(self.price[-1])) print("Recent Bid: "+str(self.recentBid[-1])) print("Recent Offer: "+str(self.recentOffer[-1])) print("Total Stock Volume in market: "+str(self.stockVol[-1])) print("***Present Investment Value: "+str(self.price[-1]*self.purchaseQuantity)) print("\n") ### Functions ### def connectDatabase(dbLocation, dbName, tableName): """ Establish & Return connection to SQLite Database """ try: if not (os.path.exists(dbLocation)): os.mkdir(dbLocation) # create folder/dir os.chdir(dbLocation) # change directory focus to dbLocation conn = sqlite3.connect(dbLocation+dbName) cur = conn.cursor() try: createTableQ = "CREATE TABLE IF NOT EXISTS "+tableName +" (code varchar PRIMARY KEY, purchase_price float, purchase_quantity float, purchase_date varchar);" cur.execute(createTableQ) conn.commit() except: pass return conn except IOError or OSError: print "Connection to database failed" return False def retrieveStockDatabase(conn, tableName): """ Read SQLite3 database & extract stock data into StockList """ stockList = [] stockQuery = "select recent_price, recent_offer, recent_bid, stock_volume from ? ;" cur = conn.cursor() cur.execute("select code, purchase_price, purchase_quantity from "+tableName+";") for row in cur.fetchall(): newStock = stock() newStock.code = row[0] newStock.purchasePrice = row[1] newStock.purchaseQuantity = row[2] cur.execute(stockQuery,[newStock.code]) for rw in cur.fetchall(): newStock.price.append(rw[0]) newStock.recentOffer.append(rw[1]) newStock.recentBid.append(rw[2]) newStock.stockVol.append(rw[3]) stockList.append(newStock) return stockList def getDate(): """ Return todays date in format DD:MM:YYYY """ time = datetime.datetime.now() date = time.strftime("%d:%m:%Y") # string format time (%y) return date def newStockDatabase(conn, stockTable, stock): """ Add a new stock to SQLite database if not already there We save the stocks code, purchase price, quantity purchased & date of purchase. """ cur = conn.cursor() try: createTableQ = "create table "+stock.code+" (date varchar PRIMARY KEY, recent_price float, recent_offer float, recent_bid float, stock_volume double);" stockQuery = "insert into "+stockTable+" values(?, ?, ?, ?);" cur.execute(createTableQ) cur.execute(stockQuery, [stock.code,stock.purchasePrice,stock.purchaseQuant,getDate()]) conn.commit() except IOError or OSError: print "Table may already exist or bad SQLite connection." return False def webFormat(URL): if (URL.startswith("http://")==False): URL = "http://"+URL return URL def getSource(URL): """ Retrieve HTML source code from website URL & save in sourceBuffer """ try: URL = webFormat(URL) # make sure URL contains essential "http://" sourceBuffer = urllib2.urlopen(URL) print '\nResponse code = ',sourceBuffer.code print 'Response headers = ',sourceBuffer.info() print 'Actual URL = ',sourceBuffer.geturl() sourceCode = sourceBuffer.read() sourceBuffer.close() return sourceCode except IOError: # URLError print "Function Failed: Reasons could be invalid URL name \nOR \nHTML protocol message transfer failure." return False # function failed def getTargetText(targetStrtData, targetEndData, dataBuffer): """ Grabs target text that lies inside 'dataBuffer' string between targetStrtData & targetEndData """ try: result = dataBuffer.split(targetStrtData) result.pop(0) result = result[0].split(targetEndData) result.pop(1) print result return result except IOError: print "Function Failed: Reasons could be targetStrtData and/or targetEndData is not present in dataBuffer." def getStockData(htmlText, selectedStock): """ Extract stock data(stock code,price,etc) from htmlText """ try: # Here I extract my number data from HTML text tempList = [] for string in htmlText: for i in string.split('>'): for e in i.split(): if ('.' in e and e[0].isdigit()): tempList.append(float(e)) elif (',' in e and e[0].isdigit() ): # remove ',' chars e = e.replace(',','') tempList.append(float(e)) selectedStock.updateData(tempList[0],tempList[2],tempList[3],tempList[7]) except IOError: # is this the correct error I should be trying to catch here?? print "Function Failed: Reasons could be: sites HTML data has changed. Consult author of program." return False def createStockTracker(stockCode,stockPrice,stockQuant, stockList): """ Add a new stock to the database to track """ newStock = stock() newStock.constructor(stockCode,stockPrice,stockQuant) stockList.append(newStock) return stockList def writeStockToDatabase(conn, stock): """ Write ONLY this Stock's attributes to SQLite Database """ cur = conn.cursor() date = getDate() tableName = stock.code stockquery = "insert into "+tableName+" values(?, ?, ?, ?, ?);" cur.execute(query,[date,stock.price[-1], stock.recentOffer[-1], stock.recentBid[-1], stock.stockVol[-1]]) conn.commit() def writeAllToDatabase(conn, stockList): """ Enter recent Stock attributes into SQLite Database """ cur = conn.cursor() date = getDate() for stock in stockList: tableName = stock.code stockquery = "insert into "+tableName+" values(?, ?, ?, ?, ?);" cur.execute(query,[date,stock.price[-1], stock.recentOffer[-1], stock.recentBid[-1], stock.stockVol[-1]]) conn.commit() ### Input Functions ### def inputNewStock(): """ """ print "*Please note only an Australian Securities Exchange(ASX) listed stock can be tracked in Version 1.0." badInput = True while (badInput == True): try: code = raw_input("Please enter the ASX code for the stock you wish to track: ") price = input("Please enter the individual stock value for "+code+": ") quantity = input("Please enter the number/quantity of stocks purchased: ") if (len(code)>3): badInput = True else : badInput = False return True except IOError: if (raw_input("Incorrect input. Note: ASX code cannot be more than 3 chars. Press 'x' to exit or anything else to try again")=='x'): return False badInput = True # this I am not sure if necessary to loop correctly ### Main program loop ### def main(): programEnd = False; dbLocation = "C:\Users\Sam\Desktop\StockApp/" dbName = "stockData.db" stockTable = "stocks" conn = connectDatabase(dbLocation,dbName,stockTable) stockList = retrieveStockDatabase(conn,stockTable) for s in stockList: s.printStats() while (programEnd == False): decision = input(menu) # Print Menu if (decision==1): if not(inputNewStock()==False): stockList = createStockTracker(acode,price,quantity,stockList) newStockDatabase(conn,stockTable,stockList[-1]) print("\n** New Stock **") stockList[-1].printStats() print "The stock "+code+" was successfully added to our database. \nNow every time the program runs it will automatically track this stock & obtain its stock attributes\n\n" # TO DO: # get new stock recent Data from internet etc. # add stock data to data base; elif (decision==2): if (len(stockList)>0): for Stock in stockList: URL = ASXurl+Stock.code sourceCode = getSource(URL) targetData = getTargetText(target % (Stock.code,Stock.code),"
%s' > ASXurl = 'http://www.asx.com.au/asx/markets/priceLookup.do? > by=asxCodes&asxCodes=' > > class stock: > code = "" > purchasePrice = 0 > purchaseQuantity = 0 > price = [] # list of recent prices > recentBid = [] # list of recent bids for stock > recentOffer = [] # list of recent offers for stock > stockVol = [] # list of stock quantity available on > market This will be variables belonging to the class itself, not instances of it. > def __init__(self): > """ Default Constructor """ > self.code = "" > self.purchasePrice = 0 > self.purchaseQuantity = 0 > > def constructor(self, stockCode, purPrice, purQuant): > """ Constructor """ > self.code = stockCode > self.purchasePrice = purPrice > self.purchaseQuantity = purQuant > > def setData(self, stockCode, purPrice, purQuant, priceList, > reBidList, reOffList, popList): > """ Defines & implements the objects' public variables """ > self.code = stockCode > self.purchasePrice = purPrice > self.purchaseQuantity = purQuant > self.price = priceList > self.recentBid = reBidList > self.recentOffer = reOffList > self.stockVol = popList > > self.printStats() > > def updateData(self, priceEle, bidEle, offerEle, populEle): > """ Adds data to stock object's lists """ > self.price.append(priceEle) > self.recentBid.append(bidEle) > self.recentOffer.append(offerEle) > self.stockVol.append(populEle) > > def printStats(self): > """ Output Stock attributes """ > > print("Stock Code: "+self.code) In Python 2 'print' is a statement, so it doesn't need its arguments to be enclosed in (). You could also use Python's string formatting: print "Stock Code: %s" % self.code > print("Stock Purchase Price: "+str(self.purchasePrice)) > print("Stock Quantity Owned: "+str(self.purchaseQuantity)) > print("***Initial Investment Value: > "+str(self.purchasePrice*self.purchaseQuantity)) > if not(len(self.price) <= 0): 'not' has a lower priority than '<=', and this can be simplified anyway: if len(self.price) > 0: or even: if self.price: because empty containers (eg lists) are treated as False, non-empty ones as True, by 'if' and 'while' statements. > print("Stock Current Price: "+str(self.price[-1])) > print("Recent Bid: "+str(self.recentBid[-1])) > print("Recent Offer: "+str(self.recentOffer[-1])) > print("Total Stock Volume in market: > "+str(self.stockVol[-1])) > print("***Present Investment Value: > "+str(self.price[-1]*self.purchaseQuantity)) > print("\n") > > > ### Functions ### > def connectDatabase(dbLocation, dbName, tableName): > """ Establish & Return connection to SQLite Database """ > > try: > if not (os.path.exists(dbLocation)): > os.mkdir(dbLocation) # create folder/dir > > os.chdir(dbLocation) # change directory focus to > dbLocation It's normally easier to use absolute paths instead of changing the current directory. > conn = sqlite3.connect(dbLocation+dbName) It's better to join paths using os.path.join() because that will insert any directory separators for you. > cur = conn.cursor() > try: > createTableQ = "CREATE TABLE IF NOT EXISTS "+tableName > +" (code varchar PRIMARY KEY, purchase_price float, purchase_quantity > float, purchase_date varchar);" > cur.execute(createTableQ) > conn.commit() > except: > pass DON'T USE BARE EXCEPTS, especially if you're just going to ignore the exception. Exceptions can be raised for a variety of reasons, including one you didn't expect due to bugs, so catch only what you expect. > return conn > except IOError or OSError: The result of: IOError or OSError is: IOError What you want is: except (IOError, OSError): Note: the parentheses are necessary here, otherwise it it would mean "catch an IOError exception and then bind it to the name 'OSError'". > print "Connection to database failed" > return False > Some times you return the connection, and other times False. A more usual value than False in such cases is None (unless you're returning True or False). > def retrieveStockDatabase(conn, tableName): > """ Read SQLite3 database & extract stock data into StockList """ > > stockList = [] > stockQuery = "select recent_price, recent_offer, recent_bid, > stock_volume from ? ;" > cur = conn.cursor() > cur.execute("select code, purchase_price, purchase_quantity from > "+tableName+";") > > for row in cur.fetchall(): > newStock = stock() > newStock.code = row[0] > newStock.purchasePrice = row[1] > newStock.purchaseQuantity = row[2] > cur.execute(stockQuery,[newStock.code]) > for rw in cur.fetchall(): > newStock.price.append(rw[0]) > newStock.recentOffer.append(rw[1]) > newStock.recentBid.append(rw[2]) > newStock.stockVol.append(rw[3]) > stockList.append(newStock) > > return stockList > > def getDate(): > """ Return todays date in format DD:MM:YYYY """ > time = datetime.datetime.now() > date = time.strftime("%d:%m:%Y") # string format time (%y) > return date > > def newStockDatabase(conn, stockTable, stock): > """ Add a new stock to SQLite database if not already there > We save the stocks code, purchase price, quantity purchased > & date of purchase. """ > cur = conn.cursor() > try: > createTableQ = "create table "+stock.code+" (date varchar > PRIMARY KEY, recent_price float, recent_offer float, recent_bid float, > stock_volume double);" > stockQuery = "insert into "+stockTable+" > values(?, ?, ?, ?);" > cur.execute(createTableQ) > cur.execute(stockQuery, > [stock.code,stock.purchasePrice,stock.purchaseQuant,getDate()]) > conn.commit() > except IOError or OSError: > print "Table may already exist or bad SQLite connection." > return False > > def webFormat(URL): > > if (URL.startswith("http://")==False): > URL = "http://"+URL > Better as: if not URL.startswith("http://"): The conditions of 'if' and 'while' statements don't need to enclosed in parentheses like in C, Java, etc. > return URL > > def getSource(URL): > """ Retrieve HTML source code from website URL & > save in sourceBuffer """ > > try: > URL = webFormat(URL) # make sure URL contains essential > "http://" > sourceBuffer = urllib2.urlopen(URL) > print '\nResponse code = ',sourceBuffer.code > print 'Response headers = ',sourceBuffer.info() > print 'Actual URL = ',sourceBuffer.geturl() > sourceCode = sourceBuffer.read() > sourceBuffer.close() > return sourceCode > > except IOError: # URLError > print "Function Failed: Reasons could be invalid URL name \nOR > \nHTML protocol message transfer failure." > return False # function failed > > def getTargetText(targetStrtData, targetEndData, dataBuffer): > """ Grabs target text that lies inside 'dataBuffer' string > between targetStrtData & targetEndData """ > > try: > result = dataBuffer.split(targetStrtData) > result.pop(0) > result = result[0].split(targetEndData) > result.pop(1) > print result > return result > except IOError: > print "Function Failed: Reasons could be targetStrtData and/or > targetEndData is not present in dataBuffer." > You haven't given a return statement for when there's an error, so it'll return None. It's probably clearer if you write a function in Python either as a _function_ which _always_ returns a value or as a _procedure_ which _never_ returns a value. In Python the preference is for a function to raise an exception to indicate an error instead of returning a flag. > def getStockData(htmlText, selectedStock): > """ Extract stock data(stock code,price,etc) from htmlText """ > try: > # Here I extract my number data from HTML text > tempList = [] > for string in htmlText: > for i in string.split('>'): > for e in i.split(): > if ('.' in e and e[0].isdigit()): > tempList.append(float(e)) > elif (',' in e and e[0].isdigit() ): > # remove ',' chars > e = e.replace(',','') > tempList.append(float(e)) > > > selectedStock.updateData(tempList[0],tempList[2],tempList[3],tempList[7]) > > except IOError: # is this the correct error I should be trying to > catch here?? > print "Function Failed: Reasons could be: sites HTML data has > changed. Consult author of program." > return False > > def createStockTracker(stockCode,stockPrice,stockQuant, stockList): > """ Add a new stock to the database to track """ > newStock = stock() > newStock.constructor(stockCode,stockPrice,stockQuant) > stockList.append(newStock) > return stockList > > def writeStockToDatabase(conn, stock): > """ Write ONLY this Stock's attributes to SQLite Database """ > > cur = conn.cursor() > date = getDate() > > tableName = stock.code > stockquery = "insert into "+tableName+" values(?, ?, ?, ?, ?);" > cur.execute(query,[date,stock.price[-1], stock.recentOffer[-1], > stock.recentBid[-1], stock.stockVol[-1]]) > conn.commit() > > def writeAllToDatabase(conn, stockList): > """ Enter recent Stock attributes into SQLite Database """ > > cur = conn.cursor() > date = getDate() > > for stock in stockList: > tableName = stock.code > stockquery = "insert into "+tableName+" > values(?, ?, ?, ?, ?);" > cur.execute(query,[date,stock.price[-1], > stock.recentOffer[-1], stock.recentBid[-1], stock.stockVol[-1]]) > conn.commit() > > ### Input Functions ### > def inputNewStock(): > """ """ > print "*Please note only an Australian Securities Exchange(ASX) > listed stock can be tracked in Version 1.0." > badInput = True > > while (badInput == True): Better as: while badInput: > try: > code = raw_input("Please enter the ASX code for the > stock you wish to track: ") If you assign to a name in a function then that name will be treated as a local name (variable) unless you say it's global in the function, therefore 'code', etc, won't been seen outside this function. > price = input("Please enter the individual stock value > for "+code+": ") > quantity = input("Please enter the number/quantity of > stocks purchased: ") > if (len(code)>3): > badInput = True > else : badInput = False > return True This will check the length, setting badInput accordingly, and then return True. > except IOError: I don't see anything in the 'try' block that will raise IOError. > if (raw_input("Incorrect input. Note: ASX code cannot be > more than 3 chars. Press 'x' to exit or anything else to try > again")=='x'): > return False > badInput = True # this I am not sure if necessary to loop > correctly > You're not explicitly returning anything from the function when the loop exits, so it would return None. > > ### Main program loop ### > def main(): > programEnd = False; > dbLocation = "C:\Users\Sam\Desktop\StockApp/" If your string contains literal backslashes then use raw strings instead. Raw strings can end in a backslash, but that shouldn't matter in the script if you're joining paths together using os.path.join(). > dbName = "stockData.db" > stockTable = "stocks" > > conn = connectDatabase(dbLocation,dbName,stockTable) > stockList = retrieveStockDatabase(conn,stockTable) > > for s in stockList: > s.printStats() > > while (programEnd == False): Better as: while not programEnd: > > decision = input(menu) # Print Menu input() is often considered a bad function to use because it's equivalent to eval(raw_input()), so the user could enter any expression. It's better to use int(raw_input()) in this case and then catch the ValueError if what was entered isn't an int. > > if (decision==1): > > if not(inputNewStock()==False): A double-negative, equivalent to: if inputNewStock() != False: It would be more Pythonic if you had inputNewStock() return the code, etc, or raise an exception if there was an error. You could then catch that exception in a 'try' block. > stockList = > createStockTracker(acode,price,quantity,stockList) > newStockDatabase(conn,stockTable,stockList[-1]) > print("\n** New Stock **") > stockList[-1].printStats() > print "The stock "+code+" was successfully added to > our database. \nNow every time the program runs it will automatically > track this stock & obtain its stock attributes\n\n" > # TO DO: > # get new stock recent Data from internet etc. > # add stock data to data base; > elif (decision==2): > if (len(stockList)>0): Better as: if stockList: > for Stock in stockList: > URL = ASXurl+Stock.code > sourceCode = getSource(URL) > targetData = getTargetText(target % > (Stock.code,Stock.code),"

Pregiatissima Azienda,
Sottoponiamo alla Vostra cortese attenzione la rivista di turismo, cultura, arte e spettacolo “ITALIA WEEKEND”.

Resa ancora più bella nella sua nuova veste grafica essa rappresenta un magazine completo da cui trarre idee, spunti e suggerimenti sugli innumerevoli itinerari d’arte, percorsi turistici ed enogastronomici del nostro Paese.

Le sue rubriche, redatte anche in lingua inglese, affrontano temi interessanti volti a soddisfare la curiosità delle lettrici e dei lettori che amano la nostra Penisola.

È distribuita gratuitamente su tutto il territorio nazionale e, in particolar modo nei luoghi più famosi d’Italia.

È presente, inoltre, nelle molteplici manifestazioni organizzate nel corso dell’anno nelle varie regioni italiane; in tali occasioni la rivista, è distribuita a tutto il pubblico presente, dando di conseguenza una maggiore visibilità agli inserzionisti.

La capillarità della distribuzione sul territorio italiano, supportata anche da una versione on line che raggiunge centinaia di migliaia di utenti anche all'estero, e la peculiarità della rivista volta a un settore strategico per l’intero Paese, continua a suscitare ampi consensi da parte di numerose aziende e operatori economici del settore turistico.

Il magazine, oltre ad avere i normali spazi pubblicitari, dà la possibilità agli inserzionisti di poter disporre, grazie alla cellofanatura esterna, d’ulteriori strumenti promozionali quali: brochure, dvd e così via.

Nella speranza di potervi annoverare tra i nostri inserzionisti, e ringraziandovi per l’attenzione prestataci, porgiamo i nostri più cordiali saluti.

ulteriori informazioni su www.italiainweekend.it/iwk
 

Ai sensi del D.Lgs 196/2003 informiamo che il Suo indirizzo e-mail è stato reperito attraverso
fonti di pubblico dominio o attraverso e-mail o adesioni da noi ricevute.
Tutti i destinatari della mail sono in copia nascosta (D.Lgs 196/2003). Qualora il messaggio pervenga
anche a persona non interessata, preghiamo volercelo cortesemente segnalare rispondendo
CANCELLAMI all'indirizzo cancellami at italiainweekend.it precisando l'indirizzo
che si desidera sia immediatamente rimosso dalla mailing list. Tendiamo ad
evitare fastidiosi MULTIPLI INVII, ma laddove ciò avvenisse preghiamo di
segnalarcelo e ce ne scusiamo sin d'ora. Grazie.
From news123 at free.fr Tue Mar 2 19:30:26 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 01:30:26 +0100 Subject: Image.frombuffer and warning Message-ID: <4b8dada2$0$6285$426a74cc@news.free.fr> Hi, I am using the PIL function from_buffer in python 2.6.4 I am having the line im2 = Image.frombuffer('L',(wx,wy),buf) I receive the warning: > ./pytest.py:63: RuntimeWarning: the frombuffer defaults may change in a future release; for portability, change the call to read: > frombuffer(mode, size, data, 'raw', mode, 0, 1) > im2 = Image.frombuffer('L',(wx,wy),buf) Naively I assumed, that changing my code to im2 = Image.frombuffer('L',(wx,wy),buf,'raw','L',0,1) should fix the issue: However I receive exactly the same error as before. What am I doing wrong? thanks a lot in advance and bye N From no.email at nospam.invalid Tue Mar 2 19:33:50 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 02 Mar 2010 16:33:50 -0800 Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: <7x4okyb5w1.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > (3) which implies that all JSON files are valid RSON files. > > If you reject the logical conclusion that RSON must therefore also be too > hard to edit, then perhaps JSON isn't too hard to edit either. I would say that JSON is hard to edit because, among other things, it has no comment syntax. It's quite difficult to maintain a hand-edited JSON file, or figure out what to edit into it, if it can't have any comments in it describing what it's doing. JSON is a serialization format for machine to machine communication, not intended for hand editing. Simply adding a comment syntax to JSON would go a long way towards making it easier to edit. From news123 at free.fr Tue Mar 2 19:38:21 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 01:38:21 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back Message-ID: <4b8daf7d$0$2868$426a74cc@news.free.fr> Hi, I created a grayscale image with PIL. Now I would like to write a C function, which reads a;most all pixels and will modify a few of them. My current approach is: - transform the image to a string() - create a byte array huge enough to contain the resulting image - call my c_function, which copies over the entire image in order to modify a few pixels How can I achieve this with the least amount of copies? ########## Python code snippet ################ im = Image.open('grayscalefile_onebyteperpixel') wx,wy = im.size # create a string in order to pass it to my function # I'm afraid this involves copying so want to get rid of it im_as_string = im.tostring() # create a byte array in order to store my result new_img_array = array.array('B', [0]*(wx*wy) ) # my function which should just change some pixels has # to copy all unmodified pixels my_extension.my_func(wx,wy,im_as_string,new_img_array) im = Image.frombuffer('L',(wx,wy),new_img_array) show(im2) ############ C wrapper code snippet ############### int wx,wy; Py_buffer img; Py_buffer new_img; Py_buffer table; unsigned char *img_ptr; unsigned char *new_img_ptr; int ok = PyArg_ParseTuple(args, "iis*w*",&wx,&wy,&img,&new_img); img_ptr = (unsigned char *) img.buf; new_img_ptr = (unsigned char *) new_img.buf; my_func(wx,wy,img_ptr,new_img_ptr); Thanks in advance for any suggestions to make this more efficient. bye N From python at mrabarnett.plus.com Tue Mar 2 19:53:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 00:53:22 +0000 Subject: Multiprocessing problem In-Reply-To: <4B8D7C23.7050905@sidefx.com> References: <4B8D7C23.7050905@sidefx.com> Message-ID: <4B8DB302.1010102@mrabarnett.plus.com> Matt Chaput wrote: > Hi, > > I'm having a problem with the multiprocessing package. > > I'm trying to use a simple pattern where a supervisor object starts a > bunch of worker processes, instantiating them with two queues (a job > queue for tasks to complete and an results queue for the results). The > supervisor puts all the jobs in the "job" queue, then join()s the > workers, and then pulls all the completed results off the "results" queue. > > (I don't think I can just use something like Pool.imap_unordered for > this because the workers need to be objects with state.) > > Here's a simplified example: > > http://pastie.org/850512 > > The problem is that seemingly randomly, but almost always, the worker > processes will deadlock at some point and stop working before they > complete. This will leave the whole program stalled forever. This seems > more likely the more work each worker does (to the point where adding > the time.sleep(0.01) as seen in the example code above guarantees it). > The problem seems to occur on both Windows and Mac OS X. > > I've tried many random variations of the code (e.g. using JoinableQueue, > calling cancel_join_thread() on one or both queues even though I have no > idea what it does, etc.) but keep having the problem. > > Am I just using multiprocessing wrong? Is this a bug? Any advice? > There's a difference between multithreading and multiprocessing. In multithreading the threads share the same address space, so objects can be passed between the threads simply by passing references to those objects. In multiprocessing, however, the process don't share an address space, so the objects themselves need to be transferred between the processes via pipes, but the pipes have a limited capacity. If the main process doesn't get the results from the queue until the worker processes terminate, and the worker processes don't terminate until they've put their results in the queue, and the pipe consequently fills up, then deadlock can result. From python at mrabarnett.plus.com Tue Mar 2 20:00:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 01:00:11 +0000 Subject: Queue peek? In-Reply-To: <1267567723.4101.28.camel@localhost.localdomain> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> Message-ID: <4B8DB49B.8070008@mrabarnett.plus.com> John Krukoff wrote: > On Tue, 2010-03-02 at 22:54 +0100, mk wrote: > >> No need to use synchro primitives like locks? >> >> I know that it may work, but that strikes me as somehow wrong... I'm >> used to using things like Lock().acquire() and Lock().release() when >> accessing shared data structures, whatever they are. > > > This is one of those places where the GIL is a good thing, and makes > your life simpler. You could consider it that the interpreter does the > locking for you for such primitive operations, if you like. I suppose it depends on the complexity of the data structure. A dict's methods are threadsafe, for example, but if you have a data structure where access leads to multiple method calls then collectively they need a lock. From matt at whoosh.ca Tue Mar 2 20:07:49 2010 From: matt at whoosh.ca (Matt Chaput) Date: Tue, 02 Mar 2010 20:07:49 -0500 Subject: Multiprocessing problem In-Reply-To: <4B8DB302.1010102@mrabarnett.plus.com> References: <4B8D7C23.7050905@sidefx.com> <4B8DB302.1010102@mrabarnett.plus.com> Message-ID: <4B8DB665.2080602@whoosh.ca> > If the main process doesn't get the results from the queue until the > worker processes terminate, and the worker processes don't terminate > until they've put their results in the queue, and the pipe consequently > fills up, then deadlock can result. The queue never fills up... on platforms with qsize() I can see this. I remove items from the results queue as I add to the job queue, and if I add timeouts everywhere the workers never raise Empty and the supervisor never raises Full. They just deadlock. I've rewritten the code so the worker threads don't push information back while they run, they just write to a temporary file which the supervisor can read, which avoids the issue. But if anyone can tell me what I was doing wrong for future reference, I'd greatly appreciate it. Thanks, Matt From jcb at iteris.com Tue Mar 2 20:45:31 2010 From: jcb at iteris.com (Metalone) Date: Tue, 2 Mar 2010 17:45:31 -0800 (PST) Subject: Multiprocessing.Pipe is not concurrently bi-directional (design flaw?) Message-ID: <7dbf688d-a86f-4e8d-a183-59673ed28f29@m35g2000prh.googlegroups.com> I wanted to use Multiprocessing.Pipe and Multiprocessing.Process to peform Actor style communication. However, I just can't get what I need done, and I think it is due to inherit problems with the design of Pipe. If I have a process like this def process1(conn): while True: msg = conn.recv() if msg == 'go': res = go() # this is a long running function conn.send(res) # send result back to caller elif msg == 'stop': stop() # this is intended to stop the go() function, for example using deciding to abort operation. In this code the 'stop' message cannot be received, because the code is in the long running go() function. So lets change it. def process1(conn): while True: msg = conn.recv() if msg == 'go': t = threading.Thread(target=go, args=(conn,)) t.start() elif msg == 'stop': stop() # this is intended to stop the go() function. Now the thread-1 is waiting on the blocking recv(). If the go() function completes on thread-2, it wants to send its result via the connection object, but it can't because the connection is in use. Trying to work around this gets complicated. For example, using a second process and a second connection object to read the 'stop' message, and then changing a shared memory flag to stop the go() function. Pipes not being concurrently bi-directional appears to be a design flaw to me. pyCSP appears to be an interesting approach, but it does not support communication across O.S. processes on Win32. From jcb at iteris.com Tue Mar 2 21:11:27 2010 From: jcb at iteris.com (Metalone) Date: Tue, 2 Mar 2010 18:11:27 -0800 (PST) Subject: Multiprocessing.Pipe is not concurrently bi-directional (design flaw?) References: <7dbf688d-a86f-4e8d-a183-59673ed28f29@m35g2000prh.googlegroups.com> Message-ID: <8f0cf159-bfb4-4def-82c7-9a99bd9cbebe@z10g2000prh.googlegroups.com> Well, I just realized that I could use a separate pipe to send the result back. This might work ok. From pmaupin at gmail.com Tue Mar 2 21:26:38 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 2 Mar 2010 18:26:38 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: On Mar 2, 5:36?pm, Steven D'Aprano wrote: > You seem to be taking the position that if you start with a config file > config.json, it is "too hard to edit", but then by renaming it to > config.rson it magically becomes easier to edit. That *is* ludicrous. No, but that seems to be the position you keep trying to ascribe to me: "Wait a minute... if JSON is too hard to edit, and RSON is a *superset* of JSON, that means by definition every JSON file is also a valid RSON file. Since JSON is too hard to manually edit, so is RSON." > Perhaps what you mean to say is that JSON *can be* (not is) too hard to > edit, and RSON *can be* too hard to edit too, but RSON has additional > benefits, including being easier to edit *sometimes*. I have said as much, in multiple prior postings on this thread, if you care to look. > So far you have done (in my opinion) a really poor job of explaining what > those benefits are. That's certainly a valid complaint, and I can certainly believe that's true (and I'm going to be working on the doc some more), but instead of making this complaint, you made the (still silly IMO) assertion that a superset has to be as unreadable as the base set. > You've bad-mouthed existing config formats, then > tried to convince us that RSON is almost exactly the same as one of those formats apart from a couple of trivial changes of spelling (True for true, etc.). This is conflating two different issues. In a lame attempt to show the silliness of the argument that the superset must be as bad as the subset, I was trying to explain that, if you make a very few changes, Python is a superset of JSON. However, my lame attempt at this was obviously as poorly thought out as some of the rest of my words, because it started an additional discussion that wasn't really germane to the real issues about configuration files. > In my opinion, if you're going to get any traction with RSON, you need to > demonstrate some examples of where JSON actually is hard to write, and > show how RSON makes it easier. It's not good enough showing badly written > JSON, it has to be examples that can't be written less badly given the > constraints of JSON. Agreed, and I will be working on that. Best regards, Pat From python at mrabarnett.plus.com Tue Mar 2 21:37:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 02:37:23 +0000 Subject: Multiprocessing.Pipe is not concurrently bi-directional (design flaw?) In-Reply-To: <8f0cf159-bfb4-4def-82c7-9a99bd9cbebe@z10g2000prh.googlegroups.com> References: <7dbf688d-a86f-4e8d-a183-59673ed28f29@m35g2000prh.googlegroups.com> <8f0cf159-bfb4-4def-82c7-9a99bd9cbebe@z10g2000prh.googlegroups.com> Message-ID: <4B8DCB63.80201@mrabarnett.plus.com> Metalone wrote: > Well, I just realized that I could use a separate pipe to send the > result back. This might work ok. Or you could call .poll on the pipe and sleep if there's no input yet. From victor.stinner at haypocalc.com Tue Mar 2 21:37:44 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Wed, 3 Mar 2010 03:37:44 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> Message-ID: <201003030337.44915.victor.stinner@haypocalc.com> Le dimanche 28 f?vrier 2010 23:40:59, Daniel Fetchinson a ?crit : > >>I guess they also have some kind of a sandbox if they let people run > >>python on their machines, I'm not sure if it's open source though. > > > > Thing is, I'm sure that Google uses a critical backstop to any > > Python-based sandbox: something like a chroot jail. The Python sandbox > > is mostly there to inform you about what you can and can't do; the real > > security is provided by the OS. > > I see, makes perfect sense. This then raises the question whether it's > important to have a 100% fool proof python sandbox without help from > the OS, or this goal is not only too ambitious but also not really a > useful one. This is just impossible :-) PHP tried that but it's too hard to write an exhaustive blacklist because too much code have to be modified. If you require a 100% fool proof sandbox, you have to use a sandbox between the Python process and the OS (and not inside the Python process). > One aspect might be that one might want to have a platform > independent way of sandboxing, perhaps. The problem have to be splitted in two parts: protect access to OS resources (files, network, etc.) and protect access to Python objects (eg. create a read only view of objects injected to the sandbox). An "OS sandbox" can not protect objects inside the Python object. And pysandbox cannot protect all access to OS resources (but I try to do that :-)). pysandbox is a possible solution to the second problem: control Python object space. -- Victor Stinner http://www.haypocalc.com/ From victor.stinner at haypocalc.com Tue Mar 2 21:42:51 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Wed, 3 Mar 2010 03:42:51 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002281743.07452.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> <201002281743.07452.victor.stinner@haypocalc.com> Message-ID: <201003030342.51801.victor.stinner@haypocalc.com> Le dimanche 28 f?vrier 2010 17:43:07, Victor Stinner a ?crit : > Yes, Google AppEngine has its Python sandbox and the source code is > available online. I don't know the license. I found 7 vulnerabilities in 1 > hour :-) I contacted Google security team. (...) There are other > differences, but I prefer to wait for the answer from > Google before telling you more :) Google answered me. I misunderstood AppEngine sandbox. It's not a Python sandbox. AppEngine sandbox is just a tool helping developers to test programs without the "real" (OS) sandbox. Their Python sandbox *emulates* the real sandbox, and so it's completly different to pysandbox. -- Victor Stinner http://www.haypocalc.com/ From alfps at start.no Tue Mar 2 21:54:20 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 03:54:20 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: * Patrick Maupin: > On Mar 2, 5:36 pm, Steven D'Aprano cybersource.com.au> wrote: >> You seem to be taking the position that if you start with a config file >> config.json, it is "too hard to edit", but then by renaming it to >> config.rson it magically becomes easier to edit. That *is* ludicrous. > > No, but that seems to be the position you keep trying to ascribe to > me: "Wait a minute... if JSON is too hard to edit, and RSON is a > *superset* of JSON, that means by definition every JSON file is also a > valid RSON file. Since JSON is too hard to manually edit, so is > RSON." Just a heads-up: IME it's next to impossible (maybe actually impossible) to convince Steven that your position is not the one he ascribes to you. At least not without an extremely lengthy debate veering off on multiple similar tangents plus some that one would never dream of. So I'd give up on that. Anyway, I agree with the sentiments expressed by many in this thread that what's important is the established "eco-culture", not the editability. Thus, even though XML isn't all that editable it's what I'd choose by default for rich configuration information, regardless of whether some simpler to edit alternative existed. Simply because there are so many XML tools out there, and people know about XML. It's like MS-DOS once became popular in spite of being extremely technically imperfect for its purpose, and then Windows... :-) Cheers, - Alf From ftp-wg-owner at hethmon.com Tue Mar 2 21:58:11 2010 From: ftp-wg-owner at hethmon.com (ftp-wg-owner at hethmon.com) Date: Wed, 3 Mar 2010 09:58:11 +0700 Subject: Xgyxkcxxpy Message-ID: <20100303025835.EE602EE9AB@mail.python.org> Dear user of python.org, We have received reports that your e-mail account was used to send a large amount of spam during this week. Most likely your computer was compromised and now contains a trojaned proxy server. We recommend you to follow instruction in order to keep your computer safe. Best wishes, python.org technical support team. -------------- next part -------------- A non-text attachment was scrubbed... Name: instruction.zip Type: application/octet-stream Size: 29356 bytes Desc: not available URL: From barry at python.org Tue Mar 2 22:17:44 2010 From: barry at python.org (Barry Warsaw) Date: Tue, 2 Mar 2010 22:17:44 -0500 Subject: Python 2.6.5 release candidate 1 now available Message-ID: <20100302221744.7ee4d3dd@heresy.wooz.org> Hello everyone, The source tarballs and Windows installer for Python 2.6.5 release candidate 1 are now available: http://www.python.org/download/releases/2.6.5/ Please download them, install them, and try to use them with your favorite projects and environments. If no regressions are found, we will do the final release on Monday March 15, 2010. Please test the release candidate as much as possible in the meantime, and help make 2.6.5 a rock solid release! Thanks, -Barry P.S. The Mac installer will hopefully be available soon. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From max at alcyone.com Tue Mar 2 22:20:34 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 02 Mar 2010 19:20:34 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: Patrick Maupin wrote: > On Mar 2, 5:36 pm, Steven D'Aprano cybersource.com.au> wrote: >> You seem to be taking the position that if you start with a config file >> config.json, it is "too hard to edit", but then by renaming it to >> config.rson it magically becomes easier to edit. That *is* ludicrous. > > No, but that seems to be the position you keep trying to ascribe to > me: "Wait a minute... if JSON is too hard to edit, and RSON is a > *superset* of JSON, that means by definition every JSON file is also a > valid RSON file. Since JSON is too hard to manually edit, so is > RSON." Huh? That's the argument being used against you, not the argument being ascribed to you. You're getting confused about something, somewhere. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis I wonder if heaven got a ghetto -- Tupac Shakur From prakash.stack at gmail.com Tue Mar 2 22:25:32 2010 From: prakash.stack at gmail.com (prakash jp) Date: Wed, 3 Mar 2010 08:55:32 +0530 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: <4b79e28c$0$4610$426a74cc@news.free.fr> References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: <805f59d51003021925s27c8c489o9a25c23caef22fda@mail.gmail.com> Hi all, plz find the attachment, thats how u register services Pythonically: Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: services.bmp Type: image/bmp Size: 2107062 bytes Desc: not available URL: From pmaupin at gmail.com Tue Mar 2 22:35:20 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 2 Mar 2010 19:35:20 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> Message-ID: <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> On Mar 2, 9:20?pm, Erik Max Francis wrote: > Patrick Maupin wrote: > > On Mar 2, 5:36 pm, Steven D'Aprano > cybersource.com.au> wrote: > >> You seem to be taking the position that if you start with a config file > >> config.json, it is "too hard to edit", but then by renaming it to > >> config.rson it magically becomes easier to edit. That *is* ludicrous. > > > No, but that seems to be the position you keep trying to ascribe to > > me: "Wait a minute... if JSON is too hard to edit, and RSON is a > > *superset* of JSON, that means by definition every JSON file is also a > > valid RSON file. ?Since JSON is too hard to manually edit, so is > > RSON." > > Huh? ?That's the argument being used against you, not the argument being > ascribed to you. ?You're getting confused about something, somewhere. > > -- > Erik Max Francis && m... at alcyone.com &&http://www.alcyone.com/max/ > ? San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis > ? ?I wonder if heaven got a ghetto > ? ? -- Tupac Shakur Yes, it is very confusing. Steven used that purported argument against me, and then since I disagreed with it, it apparently meant that I was arguing that changing the file extension type (which I've never even proposed or discussed, btw) from json to rson somehow magically makes a preexisting file all better. I have a headache now, and it will only get worse, so that's really all I have left to say about this issue. Best regards, Pat From prakash.stack at gmail.com Tue Mar 2 22:36:42 2010 From: prakash.stack at gmail.com (prakash jp) Date: Wed, 3 Mar 2010 09:06:42 +0530 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: <881a0df5-872f-4c19-a989-fe3ffe775655@k2g2000pro.googlegroups.com> References: <4b79e28c$0$4610$426a74cc@news.free.fr> <881a0df5-872f-4c19-a989-fe3ffe775655@k2g2000pro.googlegroups.com> Message-ID: <805f59d51003021936y53af0759q663fbd131c7fa432@mail.gmail.com> Code of SmallestService.py is at: http://book.opensourceproject.org.cn/lamp/python/pythonwin/ Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From lie.1296 at gmail.com Tue Mar 2 22:51:52 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 03 Mar 2010 14:51:52 +1100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <4b8ddcf6$1@dnews.tpgi.com.au> On 02/25/2010 06:16 AM, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Out of curiosity: > > def gen_rand_string(length): > prng = random.SystemRandom() > chars = [] > for i in range(length): > chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) > return ''.join(chars) > > if __name__ == "__main__": > chardict = {} > for i in range(10000): > ## w = gen_rand_word(10) > w = gen_rand_string(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > > > s 3966 > d 3912 > g 3909 > h 3905 > a 3901 > u 3900 > q 3891 > m 3888 > k 3884 > b 3878 > x 3875 > v 3867 > w 3864 > y 3851 > l 3825 > z 3821 > c 3819 > e 3819 > r 3816 > n 3808 > o 3797 > f 3795 > t 3784 > p 3765 > j 3730 > i 3704 > > Better, although still not perfect. > I give you this: I give you this: import itertools def gen(): valid_chars = 'abcdefghijklmnopqrstuvwxyz' for char in itertools.repeat(valid_chars): yield char gen = gen() def gen_rand_string(length): chars = (next(gen) for i in range(length)) return ''.join(chars) since it gives me a perfect distribution of letters, it must be a very secure random password generation scheme. From lie.1296 at gmail.com Tue Mar 2 22:59:01 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 03 Mar 2010 14:59:01 +1100 Subject: cpan for python? In-Reply-To: <2010030214473616807-tomfsessile@gmailcom> References: <2010030214473616807-tomfsessile@gmailcom> Message-ID: <4b8ddea4$1@dnews.tpgi.com.au> On 03/03/2010 09:47 AM, TomF wrote: > On 2010-03-02 13:14:50 -0800, R Fritz said: > >> On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: >>> >>> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: >>> >>>> Is there something like cpan for python? I like python's syntax, but >>>> Iuse perl because of cpan and the tremendous modules that it has. -- >>> >>> Please search the mailing list archives. >>> >>> This subject has been discussed to absolute death. >> >> But somehow the question is not in the FAQ, though the answer is. See: >> >> >> > > There > is also a program called cpan, distributed with Perl. It is used for > searching, downloading, installing and testing modules from the CPAN > repository. It's far more extensive than setuptools. AFAIK the python > community has developed nothing like it. python have easy_install From john at castleamber.com Tue Mar 2 23:58:47 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Mar 2010 22:58:47 -0600 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> Message-ID: <87ljea9f20.fsf@castleamber.com> Lie Ryan writes: > On 03/03/2010 09:47 AM, TomF wrote: [..] >> There >> is also a program called cpan, distributed with Perl. It is used for >> searching, downloading, installing and testing modules from the CPAN >> repository. It's far more extensive than setuptools. AFAIK the python >> community has developed nothing like it. > > python have easy_install How easy is it to /remove/ something? ;-) (Last time I checked I read something like "manually remove the .egg"... -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 00:00:37 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 05:00:37 GMT Subject: Draft PEP on RSON configuration file format References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> Message-ID: On Tue, 02 Mar 2010 19:35:20 -0800, Patrick Maupin wrote: > Yes, it is very confusing. Steven used that purported argument against > me, and then since I disagreed with it, it apparently meant that I was > arguing that changing the file extension type (which I've never even > proposed or discussed, btw) from json to rson My argument is *figurative*, not literal. > somehow magically makes a preexisting file all better. You might not have intended that ludicrous conclusion, but it was implied by some of your posts, particularly the early ones. Of course I don't think that you *actually* believe the conclusion. I believe that, whatever the real or imagined benefit of RSON over JSON, in this thread you have attempted to over-sell RSON while giving relatively little justification for it. I wish you every success in your project, but think that it is off-topic for a Python discussion group. -- Steven From ben+python at benfinney.id.au Wed Mar 3 00:17:16 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Mar 2010 16:17:16 +1100 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> Message-ID: <873a0ix9ur.fsf@benfinney.id.au> Lie Ryan writes: > On 03/03/2010 09:47 AM, TomF wrote: > > There is also a program called cpan, distributed with Perl. It is > > used for searching, downloading, installing and testing modules from > > the CPAN repository. It's far more extensive than setuptools. AFAIK > > the python community has developed nothing like it. > > python have easy_install Indeed. And that program is nothing like the Perl ?cpan? program. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard Stallman, 2002 | Ben Finney From greg.ewing at canterbury.ac.nz Wed Mar 3 00:18:28 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 18:18:28 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> Message-ID: <7v695nFa0fU1@mid.individual.net> MRAB wrote: > BTW, the first programming I did was in hexadecimal (C4xx was "LDI xx"). Hey, a SC/MP! That was my first programming language, too. What sort of machine was it in? -- Greg From greg.ewing at canterbury.ac.nz Wed Mar 3 00:30:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 18:30:00 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: <7v69rcFcmeU1@mid.individual.net> Grant Edwards wrote: > Just a mediocre copy of the CP/M filesystem, which was in turn > copied from DEC's RSTS or RSX. It was actually an improvement over CP/M's file system. CP/M didn't have hierarchical directories or timestamps and recorded file sizes in 128-byte blocks rather than bytes. -- Greg From max at alcyone.com Wed Mar 3 00:36:42 2010 From: max at alcyone.com (Erik Max Francis) Date: Tue, 02 Mar 2010 21:36:42 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> References: <4eb68968-ba7e-44ce-86ec-46dfa6ab1b24@z11g2000yqz.googlegroups.com> <4b8da0f4$0$8783$c3e8da3@news.astraweb.com> <9f3569ec-aaef-451a-a275-2459e693927f@g26g2000yqn.googlegroups.com> Message-ID: <__adnWP-2__2aBDWnZ2dnUVZ_h2dnZ2d@giganews.com> Patrick Maupin wrote: > On Mar 2, 9:20 pm, Erik Max Francis wrote: >> Patrick Maupin wrote: >>> On Mar 2, 5:36 pm, Steven D'Aprano >> cybersource.com.au> wrote: >>>> You seem to be taking the position that if you start with a config file >>>> config.json, it is "too hard to edit", but then by renaming it to >>>> config.rson it magically becomes easier to edit. That *is* ludicrous. >>> No, but that seems to be the position you keep trying to ascribe to >>> me: "Wait a minute... if JSON is too hard to edit, and RSON is a >>> *superset* of JSON, that means by definition every JSON file is also a >>> valid RSON file. Since JSON is too hard to manually edit, so is >>> RSON." >> Huh? That's the argument being used against you, not the argument being >> ascribed to you. You're getting confused about something, somewhere. > > Yes, it is very confusing. Steven used that purported argument > against me, and then since I disagreed with it, it apparently meant > that I was arguing that changing the file extension type (which I've > never even proposed or discussed, btw) from json to rson somehow > magically makes a preexisting file all better. No, that was not the point he was making. You should reread more carefully (and be aware of sarcasm). -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis Perfect situations must go wrong -- Florence, _Chess_ From greg.ewing at canterbury.ac.nz Wed Mar 3 00:40:00 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 18:40:00 +1300 Subject: Docstrings considered too complicated In-Reply-To: <877hpuxpdf.fsf@benfinney.id.au> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> Message-ID: <7v6ae4Ff37U1@mid.individual.net> Ben Finney wrote: > Just as customers should demand both that a building be built to do its > job well, *and* that its architectural plans meet measurable, testable > industry standards of quality for independent re-use at some > indeterminate later date. A problem is that it's very hard to come up with *measurable* standards of code quality. There's no equivalent in the software world of specifying a grade of steel or type of sand. The things that really matter are all subjective. -- Greg From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 00:48:49 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 05:48:49 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> Message-ID: On Wed, 03 Mar 2010 18:40:00 +1300, Gregory Ewing wrote: > Ben Finney wrote: > >> Just as customers should demand both that a building be built to do its >> job well, *and* that its architectural plans meet measurable, testable >> industry standards of quality for independent re-use at some >> indeterminate later date. > > A problem is that it's very hard to come up with *measurable* standards > of code quality. > > There's no equivalent in the software world of specifying a grade of > steel or type of sand. The things that really matter are all subjective. True, but one can look at "best practice", or even "standard practice". For Python coders, using docstrings is standard practice if not best practice. Using strings as comments is not. Or one can simply use *reason*: what justification is there for putting comments in strings at the top of the function? The only one I can see is if you are writing for an embedded device, you may want to remove doc strings to save memory -- and even that is implementation dependent. What justification is there for putting docstrings in functions? Code becomes self-documenting, you can run Python tools that extract and run doctests, standard tools in the standard library work, other coders will immediately understand what you have done, and (unlike the behaviour of string-comments) the behaviour of docstrings is guaranteed by the language. Unless you are writing for an embedded devise, there is NO objective reason for putting comments in strings above the function, and MANY objective reasons for putting them into docstrings. Okay, this isn't quite the same as measuring the strength of concrete under compression, but it's not a subjective choice like "tea or coffee?". -- Steven From greg.ewing at canterbury.ac.nz Wed Mar 3 01:14:41 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 19:14:41 +1300 Subject: Queue peek? In-Reply-To: References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> Message-ID: <7v6cf4FnnrU1@mid.individual.net> MRAB wrote: > I suppose it depends on the complexity of the data structure. A dict's > methods are threadsafe, for example, but if you have a data structure > where access leads to multiple method calls then collectively they need > a lock. It also depends on the nature of the objects being used as dict keys. Dict operations invoke the hashing and comparison methods of the keys, which in general can execute arbitrary Python code. If the keys are elementary built-in types such as strings or ints, then dict operations will *probably* be atomic. But I think I'd use a lock anyway, to be on the safe side. -- Greg From groups at sonic.net Wed Mar 3 01:18:11 2010 From: groups at sonic.net (Isaac) Date: Tue, 2 Mar 2010 22:18:11 -0800 Subject: Need bluez/python ( PyBluez) method to access BlueZ data- Please Help! Message-ID: <4b8dff1e$0$22093$742ec2ed@news.sonic.net> Hi, I need to access data that is handled and stored in the BlueZ file system, but is, unfortunately, not available via the current BlueZ D-Bus API. That is, the data I need is parsed by BlueZ, but not provided in the current D-Bus signal. I need a method or interface that does not rely on the D-Bus API and can directly access the BlueZ file system to get this parsed data. Can PyBlueZ do this? If not, any suggestions would be immensely appreciated. Thanks! Isaac From greg.ewing at canterbury.ac.nz Wed Mar 3 01:23:27 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 19:23:27 +1300 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <7v6cviFq18U1@mid.individual.net> Alf P. Steinbach wrote: > * Tracubik: > >> iterations=0; >> count=0; >> REPEAT; >> iterations = iterations+1; >> ... >> IF (genericCondition) THEN count=count+1; >> ... >> CASE count OF: >> 1: m = 1 >> 2: m = 10 >> 3: m = 100 > > Uhm, is this syntactically valid Pascal? As I recall, every Pascal > construct was delimited in some way. I think it's okay. Pascal's control structures such as if-then and while-do mostly take single statements and didn't have an ending keyword. If you want multiple statements in the body you have to put begin-end around them. Putting a semicolon after REPEAT is stylistically a bit odd, but it's not wrong. -- Greg From timr at probo.com Wed Mar 3 01:34:29 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 02 Mar 2010 22:34:29 -0800 Subject: python 2.6: how to modify a PIL image from C without copying forth and back References: <4b8daf7d$0$2868$426a74cc@news.free.fr> Message-ID: <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> News123 wrote: > >I created a grayscale image with PIL. > >Now I would like to write a C function, which reads a;most all pixels >and will modify a few of them. > >My current approach is: >- transform the image to a string() >- create a byte array huge enough to contain the resulting image >- call my c_function, which copies over the entire image in order > to modify a few pixels >How can I achieve this with the least amount of copies? If it were me, I'd be tempted to go peek at the source code for PIL, then pass the Image object to my C routine and poke at the innards to find the buffer with the pixels. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From admin at mail.psa-software.com Wed Mar 3 01:41:53 2010 From: admin at mail.psa-software.com (EVZYN) Date: Wed, 3 Mar 2010 07:41:53 +0100 Subject: =?windows-1251?B?7+7x7O7y8OXy/CDv7vDt7iD06Ov87CDv8O4g6vPt6Ovo7ePz8Q==?= Message-ID: <828A25931378487BB0D14EA4A0EFFCE8@server> An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Wed Mar 3 01:52:02 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 03 Mar 2010 19:52:02 +1300 Subject: Writing an assembler in Python In-Reply-To: References: Message-ID: <7v6el6F1ddU1@mid.individual.net> > In article , > Giorgos Tzampanakis wrote: > >>I'm implementing a CPU that will run on an FPGA. I want to have a >>(dead) simple assembler that will generate the machine code for >>me. I want to use Python for that. Are there any libraries that >>can help me with the parsing of the assembly code? I wrote a PIC assembler in Python once. I didn't bother with any parsing libraries. I used a regular expression to split the input into tokens, then wrote ad-hoc parsing code in Python. -- Greg From pankaj.kr at gmail.com Wed Mar 3 02:03:31 2010 From: pankaj.kr at gmail.com (Pankaj) Date: Tue, 2 Mar 2010 23:03:31 -0800 (PST) Subject: timeout restart in pexpect Message-ID: I am using pexpect to automate some procedures. My procedures are time cosuming, some messages coming out from that, in failure cases it will not output anything. So I would like to give small timeout value but when some message is received, it should restart the timeout, similar like "restart_timeout_upon_receive" in perl. Is it possible in Python using pexpect ? From i3enhamin at gmail.com Wed Mar 3 02:06:13 2010 From: i3enhamin at gmail.com (Ben Racine) Date: Tue, 2 Mar 2010 23:06:13 -0800 Subject: nonunique string replacements Message-ID: <6E340E6F-59D9-4E26-9491-F0891AD9B6F0@gmail.com> All, Say I have a string "l" ... l = 'PBUSH 201005 K 1. 1. 1. 1. 1. 1.' And I want to replace the first " 1." with a "500.2" and the second " 1." with " 5.2" ... What pythonic means would you all recommend? Note the whitespace is equal between the existing substring and the replacement string. Many thanks, Ben Racine i3enhamin at gmail.com From anand.shashwat at gmail.com Wed Mar 3 02:36:13 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 3 Mar 2010 13:06:13 +0530 Subject: nonunique string replacements In-Reply-To: <6E340E6F-59D9-4E26-9491-F0891AD9B6F0@gmail.com> References: <6E340E6F-59D9-4E26-9491-F0891AD9B6F0@gmail.com> Message-ID: >>> s = 'PBUSH 201005 K 500 1. 1. 1. 1. 1.' #Your original string here >>> l #Create your desired list ['500.2', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7'] >>> lsep = s.count(' 1.') #Count the occurrence of seperators >>> for i in range(lsep): #Replace all of them by values in list l, one by one ... f = s.find(' 1.') ... s = s[:f] + l[i] + s[f+3:] ... >>> s #Your final string 'PBUSH 201005 K 500 500.2 5.2 5.3 5.4 5.5' ~l0nwlf On Wed, Mar 3, 2010 at 12:36 PM, Ben Racine wrote: > All, > > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? > > Note the whitespace is equal between the existing substring and the > replacement string. > > Many thanks, > Ben Racine > i3enhamin at gmail.com > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Wed Mar 3 03:09:35 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 3 Mar 2010 09:09:35 +0100 Subject: case do problem In-Reply-To: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <6faf39c91003030009h10ad0737xec87012ec5f0395@mail.gmail.com> On Tue, Mar 2, 2010 at 6:46 PM, Tracubik wrote: > and, generally > speaking, the try..except block slow down the execution of the program or > not? Try...except tends to be slow when the exception does occur, fast when it does not. Apart from that, if these fraction-of-a-fraction-of-a-second gains are important to you, Python is not the programming language for you. In Python, it seems to be common to do optimization after rather than during the main coding, and then only when it is necessary and only where it matters. That is: 1. Program your solution without looking much at speed issues 2. Check if it is fast enough. If so, ready. 3. If not, see which parts of the program are being slow 4. Optimize only those parts of the program that have been identified in step 3 -- Andr? Engels, andreengels at gmail.com From tomf.sessile at gmail.com Wed Mar 3 03:23:16 2010 From: tomf.sessile at gmail.com (TomF) Date: Wed, 3 Mar 2010 00:23:16 -0800 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> Message-ID: <2010030300231675249-tomfsessile@gmailcom> On 2010-03-02 19:59:01 -0800, Lie Ryan said: > On 03/03/2010 09:47 AM, TomF wrote: >> On 2010-03-02 13:14:50 -0800, R Fritz said: >> >>> On 2010-02-28 06:31:56 -0800, ssteinerX at gmail.com said: >>>> >>>> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: >>>> >>>>> Is there something like cpan for python? I like python's syntax, but >>>>> Iuse perl because of cpan and the tremendous modules that it has. -- >>>> >>>> Please search the mailing list archives. >>>> >>>> This subject has been discussed to absolute death. >>> >>> But somehow the question is not in the FAQ, though the answer is. See: >>> >>> There >>> >> is also a program called cpan, distributed with Perl. It is used for >> searching, downloading, installing and testing modules from the CPAN >> repository. It's far more extensive than setuptools. AFAIK the python >> community has developed nothing like it. > > python have easy_install easy_install is part of setuptools. As I said, nothing like cpan. -Tom From lipun4u at gmail.com Wed Mar 3 03:33:17 2010 From: lipun4u at gmail.com (asit) Date: Wed, 3 Mar 2010 00:33:17 -0800 (PST) Subject: process mp3 file Message-ID: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> Somebody suggest me a python library for processing mp3 file. Here I don't want to play the file. Thank you From __peter__ at web.de Wed Mar 3 03:39:54 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Mar 2010 09:39:54 +0100 Subject: case do problem References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: Tracubik wrote: > hi, i've to convert from Pascal this code: program loop; function generic_condition: boolean; begin generic_condition := random > 0.7 end; procedure loop; var iterations, count, m: integer; begin iterations := 0; count := 0; m := 0; repeat iterations := iterations+1; (*...*) writeln(iterations:2, count:2, m:4); (*...*) if generic_condition then inc(count); (*...*) case count of 1: m := 1; 2: m := 10; 3: m := 100 end until (count = 4) or (iterations = 20) end; begin loop; writeln("That's all, folks") end. Hey, I have a Pascal compiler just one apt-get away ;) Here's how I'd translate the above, without trying to be too clever: from random import random def generic_condition(): return random() > 0.7 def loop(): count = 0 m = 0 lookup = {1: 1, 2: 10, 3: 100} for iterations in range(20): # off by one # ... print "%2d %1d %3d" % (iterations, count, m) # ... if generic_condition(): count += 1 # ... m = lookup.get(count, m) if count == 4: break if __name__ == "__main__": loop() print "That's all, folks" Something must be wrong with me today because I find the Pascal code /more/ readable... Peter From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 03:42:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 08:42:01 GMT Subject: nonunique string replacements References: Message-ID: On Tue, 02 Mar 2010 23:06:13 -0800, Ben Racine wrote: > All, > > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? l = l.replace(" 1.", "500.2", 1) l = l.replace(" 1.", "5.2", 1) -- Steven From news123 at free.fr Wed Mar 3 03:43:21 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 09:43:21 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> References: <4b8daf7d$0$2868$426a74cc@news.free.fr> <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> Message-ID: <4b8e2129$0$8262$426a34cc@news.free.fr> Hi Tim, Tim Roberts wrote: > News123 wrote: >> I created a grayscale image with PIL. >> >> Now I would like to write a C function, which reads a;most all pixels >> and will modify a few of them. >> >> My current approach is: >> - transform the image to a string() >> - create a byte array huge enough to contain the resulting image >> - call my c_function, which copies over the entire image in order >> to modify a few pixels >> How can I achieve this with the least amount of copies? > > If it were me, I'd be tempted to go peek at the source code for PIL, then > pass the Image object to my C routine and poke at the innards to find the > buffer with the pixels. Yes, this might be an option Somehow though it didn't feel right for me to depend on internal non documented data types, which might change between releases of PIL. N From __peter__ at web.de Wed Mar 3 03:49:38 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Mar 2010 09:49:38 +0100 Subject: nonunique string replacements References: Message-ID: Ben Racine wrote: > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? With regular expressions: >>> import re >>> replacements = iter(["one", "two", "three"]) >>> re.compile("replaceme").sub(lambda m: next(replacements), "foo replaceme bar replaceme baz replaceme bang") 'foo one bar two baz three bang' With string methods: >>> replacements = iter(["", "one", "two", "three"]) >>> "".join(a + b for a, b in zip(replacements, "foo replaceme bar replaceme baz replaceme bang".split("replaceme"))) 'foo one bar two baz three bang' Peter From __peter__ at web.de Wed Mar 3 04:05:02 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Mar 2010 10:05:02 +0100 Subject: Image.frombuffer and warning References: <4b8dada2$0$6285$426a74cc@news.free.fr> Message-ID: News123 wrote: > I am using the PIL function from_buffer in python 2.6.4 > > I am having the line > im2 = Image.frombuffer('L',(wx,wy),buf) > > > I receive the warning: >> ./pytest.py:63: RuntimeWarning: the frombuffer defaults may change in > a future release; for portability, change the call to read: >> frombuffer(mode, size, data, 'raw', mode, 0, 1) >> im2 = Image.frombuffer('L',(wx,wy),buf) > > > Naively I assumed, that changing my code to > > > im2 = Image.frombuffer('L',(wx,wy),buf,'raw','L',0,1) > > > should fix the issue: > > However I receive exactly the same error as before. > > What am I doing wrong? I cannot reproduce the problem: $ cat frombuffer.py import sys import Image wx = 3 wy = 2 buf = "a"*wx*wy if "--fixed" in sys.argv: Image.frombuffer("L", (wx, wy), buf, "raw", "L", 0, 1) else: Image.frombuffer("L", (wx, wy), buf) $ python frombuffer.py frombuffer.py:9: RuntimeWarning: the frombuffer defaults may change in a future release; for portability, change the call to read: frombuffer(mode, size, data, 'raw', mode, 0, 1) Image.frombuffer("L", (wx, wy), buf) $ python frombuffer.py --fixed $ python -c"import Image; print Image.VERSION" 1.1.6 $ python -V Python 2.6.4 Peter From stefan_ml at behnel.de Wed Mar 3 04:10:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 10:10:22 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: <4b8daf7d$0$2868$426a74cc@news.free.fr> References: <4b8daf7d$0$2868$426a74cc@news.free.fr> Message-ID: News123, 03.03.2010 01:38: > I created a grayscale image with PIL. > > Now I would like to write a C function, which reads a;most all pixels > and will modify a few of them. > > My current approach is: > - transform the image to a string() > - create a byte array huge enough to contain the resulting image > - call my c_function, which copies over the entire image in order > to modify a few pixels > How can I achieve this with the least amount of copies? Take a look at Cython instead, it will allow you to access PIL's image buffer directly, instead of copying the data. It will also simplify and speed up your C wrapper code. Stefan From deets at nospam.web.de Wed Mar 3 04:17:57 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Mar 2010 10:17:57 +0100 Subject: conditional import into global namespace In-Reply-To: References: <16651e81003021031h3831d4b3i844f331f3d301042@mail.gmail.com> Message-ID: <7v6nq5Ffv2U1@mid.uni-berlin.de> Am 02.03.10 21:41, schrieb mk: > Jerry Hill wrote: >> Just import subprocess at the top of your module. If subprocess >> hasn't been imported yet, it will be imported when your module is >> loaded. If it's already been imported, your module will use the >> cached version that's already been imported. >> >> In other words, it sounds like Python already does what you want. You >> don't need to do anything special. > > Oh, thanks! > > Hmm it's different than dealing with packages I guess -- IIRC, in > packages only code in package's __init__.py was executed? I don't understand this. But there is no difference regarding caching & execution between packages and modules. Importing a package will execute the __init__.py, yes. But only once. As will importing modules execute them, but only once. All subsequent imports will just return the created module-object. Unless you import something under a new name! That is, you can alter the sys.path and then import a package/module under a different name - python won't detect that. Simplest example ist this: ---- test.py ---- class Foo(object): pass if __name__ == "__main__": import test # import ourselves # this holds, because we have # __main__.Foo and test.Foo assert Foo is not test.Foo ---- test.py ---- However, unless you mess with python, this is none of your concern. Diez From orenelrad at gmail.com Wed Mar 3 04:27:16 2010 From: orenelrad at gmail.com (Oren Elrad) Date: Wed, 3 Mar 2010 04:27:16 -0500 Subject: Interest check in some delicious syntactic sugar for "except:pass" Message-ID: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Howdy all, longtime appreciative user, first time mailer-inner. I'm wondering if there is any support (tepid better than none) for the following syntactic sugar: silence: ........ block -------------------------> try: ........block except: ........pass The logic here is that there are a ton of "except: pass" statements[1] floating around in code that do not need to be there. Meanwhile, the potential keyword 'silence' does not appear to be in significant use as a variable[2], or an alternative keyword might be imagined ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of 'silence' since that is precisely what it does to the block (that is, you have to inflect it as a verb, not a noun -- you are telling the block to be silent). Finally, since this is the purest form of syntactic sugar, I cannot fathom any parsing, interpreting or other complications that would arise. I appreciate any feedback, including frank statements that you'd rather not trifle with such nonsense. ~Oren [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy From news123 at free.fr Wed Mar 3 04:37:43 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 10:37:43 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: References: <4b8daf7d$0$2868$426a74cc@news.free.fr> Message-ID: <4b8e2de8$0$21576$426a74cc@news.free.fr> Hi Stefan, Stefan Behnel wrote: > News123, 03.03.2010 01:38: >> I created a grayscale image with PIL. >> >> Now I would like to write a C function, which reads a;most all pixels >> and will modify a few of them. >> >> My current approach is: >> - transform the image to a string() >> - create a byte array huge enough to contain the resulting image >> - call my c_function, which copies over the entire image in order >> to modify a few pixels >> How can I achieve this with the least amount of copies? > > Take a look at Cython instead, it will allow you to access PIL's image > buffer directly, instead of copying the data. It will also simplify and > speed up your C wrapper code. > > Stefan > I don't know Cython. Having looked at the web site I'm not entirely sure, I understood your suggestion. Do you mean - to stay with Python 2.6 and to implement only my extension in Cython. This might be very attractive. If yes, can you recommend some url's / tutorials / etc. which might help to implement a cython extension for python2.6. which reads and modifies a pixel of a PIL image. or do you mean - to switch entirely from Python 2.6 to Cython. I would be reluctant to do so, as I have already a lot of existing code. and I do not have the time to check the entire code base for portability issues thanks in advance N From phil at freehackers.org Wed Mar 3 04:40:24 2010 From: phil at freehackers.org (BlueBird) Date: Wed, 3 Mar 2010 01:40:24 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Feb 24, 9:23?pm, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? If they are generating their doc with doxygen, I think it's the right choice. See: http://www.stack.nl/~dimitri/doxygen/docblocks.html#pythonblocks Oops, after a second look, doxygen needs comments before the function, not doc strings. Philippe From news123 at free.fr Wed Mar 3 04:44:26 2010 From: news123 at free.fr (News123) Date: Wed, 03 Mar 2010 10:44:26 +0100 Subject: Image.frombuffer and warning In-Reply-To: References: <4b8dada2$0$6285$426a74cc@news.free.fr> Message-ID: <4b8e2f7a$0$13729$426a74cc@news.free.fr> Hi Peter, Peter Otten wrote: > News123 wrote: > I cannot reproduce the problem: > > $ cat frombuffer.py > import sys > import Image > wx = 3 > wy = 2 > buf = "a"*wx*wy > if "--fixed" in sys.argv: > Image.frombuffer("L", (wx, wy), buf, "raw", "L", 0, 1) > else: > Image.frombuffer("L", (wx, wy), buf) > > $ python frombuffer.py > frombuffer.py:9: RuntimeWarning: the frombuffer defaults may change in a > future release; for portability, change the call to read: > frombuffer(mode, size, data, 'raw', mode, 0, 1) > Image.frombuffer("L", (wx, wy), buf) > $ python frombuffer.py --fixed > $ python -c"import Image; print Image.VERSION" > 1.1.6 > $ python -V > Python 2.6.4 > > Peter You're absolutely right. It was my error. I shouldn't do any lat night coding :-(. I fixed one frombuffer() statement, but overlooked a second one in my code :-( Apologies N From pankaj.kr at gmail.com Wed Mar 3 04:50:27 2010 From: pankaj.kr at gmail.com (Pankaj) Date: Wed, 3 Mar 2010 01:50:27 -0800 (PST) Subject: exp_internal in pexpect Message-ID: <4aa75aa4-e89b-40b9-b84a-c25ecf907815@l12g2000prg.googlegroups.com> how to enable expect log in pexpect ? (similar as exp_internal in expect) From stefan_ml at behnel.de Wed Mar 3 05:10:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 11:10:21 +0100 Subject: python 2.6: how to modify a PIL image from C without copying forth and back In-Reply-To: <4b8e2de8$0$21576$426a74cc@news.free.fr> References: <4b8daf7d$0$2868$426a74cc@news.free.fr> <4b8e2de8$0$21576$426a74cc@news.free.fr> Message-ID: News123, 03.03.2010 10:37: > Stefan Behnel wrote: >> Take a look at Cython instead, it will allow you to access PIL's image >> buffer directly, instead of copying the data. It will also simplify and >> speed up your C wrapper code. > > I don't know Cython. Having looked at the web site I'm not entirely > sure, I understood your suggestion. > > Do you mean > - to stay with Python 2.6 and to implement only my extension in Cython. Absolutely. > This might be very attractive. If yes, can you recommend some url's / > tutorials / etc. which might help to implement a cython extension for > python2.6. which reads and modifies a pixel of a PIL image. Check out the tutorial on the web site, and ask on the cython-users mailing list about integration with PIL. I'm sure you'll get some useful examples. Here's something closely related, although it doesn't really use PIL (but the mechanisms are the same): http://wiki.cython.org/examples/mandelbrot > or do you mean > - to switch entirely from Python 2.6 to Cython. I would be reluctant to > do so, as I have already a lot of existing code. and I do not have the > time to check the entire code base for portability issues The nice thing about Cython is that you always have a normal CPython interpreter running, so you can split your code between the interpreter and the compiler at any level of granularity. However, the advice was really to write your image processing algorithm in Cython, not your entire program. Stefan From geoff.bache at jeppesen.com Wed Mar 3 05:14:08 2010 From: geoff.bache at jeppesen.com (geoffbache) Date: Wed, 3 Mar 2010 02:14:08 -0800 (PST) Subject: PYTHONPATH and eggs Message-ID: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Hi all, I have a very simple problem that seems to have no simple solution. I have a module which is installed centrally and lives in a Python egg. I have experimented with some minor changes to it and would like to set my PYTHONPATH to pick up my local copy of it, but don't want to have to figure out how to build my own version of the "egg" if possible. Unfortunately, the location from PYTHONPATH ends up after the eggs in sys.path so I can't persuade Python to import my version. The only way I've found to fix it is to copy the main script and manually hack sys.path at the start of it which isn't really very nice. I wonder if there is any better way as I can't be the first person to want to do this, surely? I've seen this issue has been discussed elsewhere and flagged as a problem (e.g. http://mail.python.org/pipermail/distutils-sig/2009-January/010755.html) but I've been unable to find any suggestions for workarounds or indications whether this will be/has been fixed. Regards, Geoff Bache From clp2 at rebertia.com Wed Mar 3 05:25:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 02:25:02 -0800 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <50697b2c1003030225j28c18507r619cf15aeddb8c41@mail.gmail.com> On Wed, Mar 3, 2010 at 1:27 AM, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. So, why exactly should the language /encourage/ unnecessary error silencing? (which is what the proposed sugar would do) > I appreciate any feedback Applicable rules of The Zen[1] that the proposal arguably violates: *Special cases aren't special enough to break the rules. *There should be one-- and preferably only one --obvious way to do it. Cheers, Chris -- http://blog.rebertia.com [1]: http://www.python.org/dev/peps/pep-0020/ From clp2 at rebertia.com Wed Mar 3 05:25:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 02:25:42 -0800 Subject: process mp3 file In-Reply-To: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> Message-ID: <50697b2c1003030225p2b32662ct960ad477d9d3c8f5@mail.gmail.com> On Wed, Mar 3, 2010 at 12:33 AM, asit wrote: > Somebody suggest me a python library for processing mp3 file. ?Here I > don't want to play the file. Define "processing". Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Wed Mar 3 05:40:56 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 03 Mar 2010 05:40:56 -0500 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <4B8E3CB8.70302@ieee.org> Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. > > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. > > ~Oren > > [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en > [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy > > I presume you know that there's a feature freeze on for Python. So such an idea wouldn't be considered for at least a couple of years. But that shouldn't inhibit such discussions. I wonder if you're intending that silence: denotes a block in which all exceptions would be ignored. And that any calls made from there that threw exceptions would also be ignored. If so, it's a bad idea. Only if you could qualify it to a particular exception list might it be reasonable. As it stands, it's just as bad as the bare try/except that you were already given. Do you really want to ignore syntax errors, skip bad data, and ignore missing files, and generally plow down whatever execution path happens to result? Just my opinion. DaveA From lipun4u at gmail.com Wed Mar 3 05:43:38 2010 From: lipun4u at gmail.com (asit) Date: Wed, 3 Mar 2010 02:43:38 -0800 (PST) Subject: process mp3 file References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> Message-ID: <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> > Define "processing". getting the title, song name, etc of the file and updating in a database From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 05:56:03 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 11:56:03 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> Message-ID: <4b8e4041$0$17447$426a34cc@news.free.fr> Eike Welk a ?crit : > John Posner wrote: >> I've updated the text at this location: >> >> > http://cl1p.net/bruno_0301.rst/ > > I think this is a very useful writeup! > > It would be perfect with a little bit of introduction that says: > 1. - What it is: "The rough details of method look-up"; > 2. - which contains some of the questions that that made that authors write > the text. This way people with similar questions can find it with Google. > John, do you think you could something with the following ? """ "Is it a function ? is it a method ? No, it's... " - or : What's in a Python method ? Python newcomers often have hard time understanding the "magic" behind Python's methods - and truth is that Python's object model can be a bit peculiar when compared to most mainstream (or not-so-mainstream) OOPLs. As a matter of fact, there are quite a few threads on c.l.py with either direct or indirect questions about what makes a Python method, and I must have explained the whole mechanism at least 3 or 4 times there. The following text is an edited version of my last attempt, as edited, corrected and published by John Posner, MayHisNameBePraised(tm). This text isn't meant as a replacement for neither the official FineManual(tm)[XXX : relevant link] nor the very excellent - if somehow technical - 'Descriptors how-to' [XXX : relevant link]. It's mostly a brief but hopefully helpful overview of what exactly is a Python method, and how Python magically inserts the 'self' or 'cls' argument to method calls. """ Feel free to edit / amend / rewrite / trash at will - you're now officially in charge of publishing this text !-) From andreengels at gmail.com Wed Mar 3 06:02:32 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 3 Mar 2010 12:02:32 +0100 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <6faf39c91003030302l30105064n675b449b45ac1968@mail.gmail.com> On Wed, Mar 3, 2010 at 10:27 AM, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. > > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. I would be against this, because "except: pass" is a terrible code smell. Usage of exceptions can roughly be divided into two areas: 1. Cases where you do know quite well what might go wrong 2. Cases where all kind of stuff might go wrong, including things you perhaps did not think of, and want to deal with all of them In the first case, you should not use a blanket "except", but a more specific one, catching only the specific error or errors you are dealing with. In the second case, a blanket except might well be correct, but in that case, you should not want to pass over the error silently. Usually you will want to notify the user that an error has occurred. Even if that is not the case, you want to make some kind of logging of the error, so that you have the chance of finding it if it is indeed an unexpected (and therefore undoubtedly also unintended) error. Doing a pass over an exception is not a bad thing in itself, but one should only do it when one _knows_ that it is the right action to take. If you have a general exception, you don't know _what_ has gone wrong, so you sure as hell cannot be sure about what's the best action to take. Doing nothing might well be your best guess, but even in that case I want to know that your program has been guessing when I use it. -- Andr? Engels, andreengels at gmail.com From clp2 at rebertia.com Wed Mar 3 06:06:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 03:06:55 -0800 Subject: process mp3 file In-Reply-To: <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> Message-ID: <50697b2c1003030306g1939a4bbg799e4f158f99f4c4@mail.gmail.com> On Wed, Mar 3, 2010 at 2:43 AM, asit wrote: >> Define "processing". > > getting the title, song name, etc of the file and updating in a > database You'd want an ID3 tag library then. Here's one: http://eyed3.nicfit.net/ Cheers, Chris -- http://blog.rebertia.com From durumdara at gmail.com Wed Mar 3 06:12:12 2010 From: durumdara at gmail.com (durumdara at gmail.com) Date: Wed, 03 Mar 2010 12:12:12 +0100 Subject: easy install failed Message-ID: <4B8E440C.2070204@gmail.com> Hi! Windows, Py2.6. I read about Pyda and Spider. I used Pyscripter, Geany, ULIPAD, and COntext, and Netbeans with Python; but I want to try these products. But easy_install failed on get them: C:\Python26\Scripts>easy_install.exe pida Searching for pida Reading http://pypi.python.org/simple/pida/ Reading http://pida.co.uk/ Reading http://pida.co.uk/download/ Reading http://pida.vm.bytemark.co.uk/ Reading http://code.google.com/p/pida/downloads/list Reading http://pida.berlios.de Reading http://pida.berlios.de/index.php/PIDA:Downloads Reading http://pida.berlios.de/downloads/ Best match: pida 0.6beta3 Downloading http://pypi.python.org/packages/source/p/pida/pida-0.6beta3.tar.gz#m d5=ecd790f5dd6f77eb4ebfc719f8e26114 Processing pida-0.6beta3.tar.gz Running pida-0.6beta3\setup.py -q bdist_egg --dist-dir c:\docume~1\chris\locals~ 1\temp\easy_install-vd4hql\pida-0.6beta3\egg-dist-tmp-9zwwxx error: A rendszer nem tal?lja a megadott f?jlt {The system cannot found the file} Many of packages are not installed on my system, because of "file" or "path" not found. For example: C:\Python26\Scripts>easy_install.exe kiwi Searching for kiwi Reading http://pypi.python.org/simple/kiwi/ Reading http://www.ivy.fr/kiwi Best match: kiwi 0.8.6 Downloading http://www.ivy.fr/kiwi/kiwi-0.8.6.tar.gz Processing kiwi-0.8.6.tar.gz error: Couldn't find a setup script in c:\docume~1\chris\locals~1\temp\easy_inst all-dxia7w\kiwi-0.8.6.tar.gz May these packages not have "setup.py"? Or not working in Windows? Or they have binaries somewhere, like pywin32, and wxpython? THanks for your help: dd -------------- next part -------------- An HTML attachment was scrubbed... URL: From orenelrad at gmail.com Wed Mar 3 06:47:28 2010 From: orenelrad at gmail.com (Oren Elrad) Date: Wed, 3 Mar 2010 06:47:28 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" Message-ID: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> To all that responded, thanks for the prompt response folks, your criticisms are well taken. Coming from Cland, one is inculcated with the notion that if the programmer wants to shoot himself in the foot the language ought not to prevent that (or even should return him a loaded magnum with the safety off and the hair-trigger pulled). My apologies for not immediately grokking the cultural difference in pytown. With that said, let me at least offer a token defense of my position. By way of motivation, I wrote that email after copying/pasting the following a few times around a project until I wrote it into def SilentlyDelete() and its cousin SilentlyRmdir() """ code involving somefile """ try: ........os.remove(somefile) except: .......pass # The bloody search indexer has got the file and I can't delete it. Nothing to be done. Certainly the parade of horribles (bad files! corrupt data! syntax errors!) is a tad melodramatic. Either os.remove() succeeds or it doesn't and the execution path (in the estimation of this programmer, at least) is not at all impacted by whether it succeeds or fails. I know with certainty at compile time what exceptions might be raised and what the consequences of passing them are and there is no sense pestering the user or sweating over it. Nor can I see the logic, as was suggested, in writing "except OSError:" since (seems to me) mere surplusage -- it neither causes a semantic difference in the way the program runs nor provides anything useful to the reader. Now, perhaps this is a special case that is not nearly special enough to warrant its own syntactic sugar, I granted that much, but >30,000 examples in Google Code cannot be considered to be a complete corner case either. Briefly skimming those results, most of them seem to be of this flavor, not the insane programmer that wants to write "silence: CommitDBChangesEmailWifeAndAdjustBankAccount()" nor novices that aren't aware of what they might be ignoring. At any rate (and since this is far more words than I had intended), I want to reiterate that the criticism is well-taken as a cultural matter. I just don't want everyone to think I'm bloody insane or that I'm not aware this is playing with fire. Maybe we can put it in module "YesImSureJustBloodyDoItAlreadyGoddamnit" and prints an ASCII skull and crossbones to the console when imported? :-P ~ Oren PS. I did like Dave's suggestions that one might want to write "silence Type1 Type2:" which I suppose goes a long way towards alleviating the concern that the programmer doesn't know what he's missing. Doesn't quite meet my desire (both syntaxes would be nice, of course) to avoid the verbiage involved with explaining to the compiler (or the next reader) something that it knows well enough by now (or ought to know, at least). From tibor.beck at hotmail.com Wed Mar 3 06:57:13 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Wed, 3 Mar 2010 03:57:13 -0800 (PST) Subject: monkey patching with @classmethod Message-ID: Hi, is there some well-known problems with class method monkey patching? I've got this error message: unbound method get_pocet_neocislovanych() must be called with Pozemok instance as first argument (got Subjekt instance instead) The method is declared as: @classmethod @monkeypatch(Dokument) def get_pocet_neocislovanych(cls, subjekt): return cls.objects.filter(subjekt = subjekt, cislo__isnull = True).count() # or pass, this line is not important and the monkey patch decorator is declared as: def monkeypatch(cls): def decorator(func): setattr(cls, func.__name__, func) return func return decorator If I move the method to class declaration (whitout monkey patching), everything is ok, but only if I've restarted the server. From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 07:09:12 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 13:09:12 +0100 Subject: monkey patching with @classmethod In-Reply-To: References: Message-ID: <4b8e5161$0$23009$426a74cc@news.free.fr> gentlestone a ?crit : > Hi, is there some well-known problems with class method monkey > patching? > > I've got this error message: > > unbound method get_pocet_neocislovanych() must be called with Pozemok > instance as first argument (got Subjekt instance instead) > The method is declared as: > @classmethod > @monkeypatch(Dokument) > def get_pocet_neocislovanych(cls, subjekt): > return cls.objects.filter(subjekt = subjekt, cislo__isnull = > True).count() # or pass, this line is not important > > and the monkey patch decorator is declared as: > def monkeypatch(cls): > def decorator(func): > setattr(cls, func.__name__, func) > return func > return decorator The decorators are applied in order. So you first add the yet undecorated function as an attribute of the class, then pass the function to classmethod. FWIW, this monkeypatch decorator is IMHO a plain waste of time. The following code does the same thing and is (IMHO again) *much* more readable: def get_pocet_neocislovanych(cls, subjekt): return cls.objects.filter( subjekt=subjekt, cislo__isnull= True ).count() # or pass, this line is not important Dokument.get_pocet_neocislovanych=@classmethod(get_pocet_neocislovanych) Also, Django's BestPractice(tm) is to define such "query" methods on the model's manager, not as a classmethod of the model. My 2 cents From tibor.beck at hotmail.com Wed Mar 3 07:11:30 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Wed, 3 Mar 2010 04:11:30 -0800 (PST) Subject: monkey patching with @classmethod References: Message-ID: <1a134530-386e-47e4-9c63-385f8014c838@q15g2000yqj.googlegroups.com> On 3. Mar., 12:57 h., gentlestone wrote: > Hi, is there some well-known problems with class method monkey > patching? > > I've got this error message: > > unbound method get_pocet_neocislovanych() must be called with Pozemok > instance as first argument (got Subjekt instance instead) > > The method is declared as: > @classmethod > @monkeypatch(Dokument) > def get_pocet_neocislovanych(cls, subjekt): > ? ? return cls.objects.filter(subjekt = subjekt, cislo__isnull = > True).count() # or pass, this line is not important > > and the monkey patch decorator is declared as: > def monkeypatch(cls): > ? ? def decorator(func): > ? ? ? ? setattr(cls, func.__name__, func) > ? ? ? ? return func > ? ? return decorator > > If I move the method to class declaration (whitout monkey patching), > everything is ok, but only if I've restarted the server. for complexity, there is a code I call the method: def _application_menu(request, subjekt, aplikacia_url_name): return render_to_response('subjekty/aplikacia.html', { 'subjekt' : subjekt, 'aplikacia_url_name' : aplikacia_url_name, 'aplikacia_dictionary' : aplikacia_dictionary(aplikacia_url_name), 'listy' : [ (dokument_url_name, dict( get_verbose_name_plural = dokument.get_verbose_name_plural(), get_pocet_neocislovanych = dokument.get_pocet_neocislovanych(subjekt), get_pocet_celkom = dokument.get_pocet_celkom(subjekt), )) for dokument_url_name, dokument in aplikacia_dictionary(aplikacia_url_name)['listy'] ], }, context_instance = RequestContext(request)) unfortunately, sometimes it works, sometimes not, I cannot imagine the reason, why and when it works and not - even whitout monkey patching seems like some black magic From albert at spenarnc.xs4all.nl Wed Mar 3 07:43:34 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 03 Mar 2010 12:43:34 GMT Subject: Which mock library do you prefer? References: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: In article , Lacrima wrote: >On Feb 16, 10:30=A0pm, Ben Finney wrote: >> Lacrima writes: >> > And I have already refused to write totally isolated tests, because it >> > looks like a great waste of time. >> >> It only looks like that until you chase your tail in a long, fruitless >> debugging session because (you later realise) the behaviour of one test >> is being affected by another. Test isolation is essential to ensure that >> your tests are doing what you think they're doing. >> >> -- >> =A0\ =A0 =A0 =A0 =93A =91No=92 uttered from deepest conviction is better = >and greater | >> =A0 `\ =A0 =A0 =A0 than a =91Yes=92 merely uttered to please, or what is = >worse, to | >> _o__) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0avoid tr= >ouble.=94 =97Mohandas K. Gandhi | >> Ben Finney > >Hi! > >Right, isolation is essential. But I can't decide to which extent I >should propagate isolation. >For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, >author suggests that if you do unittesting you should isolate the >smallest units of code from each other. For example, if you have a >class: >Class SomeClass(object): > def method1(self): > return 5 > def method2(self): > return self.method1 + 10 > >According to the book, if you want to test method2, you should isolate >it from method1 and class instance('self'). >Other books are not so strict... > >And what should I follow as newbie? > >Currently, I don't create mocks of units if they are within the same >class with the unit under test. If that is not right approach, please, >explain what are best practices... I am just learning TDD.. Unit testing is a concept that goes well with functions without side effects. If you have classes, that doesn't work so well. For classes use cases are the way to go. Think about it. The whole state of an object can affect the way a method works. So effectively for a unit test you have to put the object in a whole special fully controlled state. The point of an object is that it can't have just any state, but only those attained by calling methods properly. So you may find yourself artificially imposing states on an object with great effort, and expecting error detection where the errors cannot in fact occur etc. etc. Not that coming up with good use cases is easy, but at least they are naturally related to your objects. > >with regards, >Maxim Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From olof.bjarnason at gmail.com Wed Mar 3 07:45:28 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 3 Mar 2010 13:45:28 +0100 Subject: Working group for Python CPAN-equivalence? Message-ID: Hi everybody! The "Where is CPAN for Python?" question keeps popping up, with answers ranging from "There is no CPAN for Python" and "We already have CPAN for Python" (confusing). I'm wondering - is there any work being done identifying .. (1) what is so good with CPAN? (2) how can it be brought to the Python world? Is there a working group/initiative for this? Web page? Discussion group? /Olof From stefan_ml at behnel.de Wed Mar 3 07:52:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 13:52:07 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: Message-ID: Olof Bjarnason, 03.03.2010 13:45: > The "Where is CPAN for Python?" question keeps popping up, with > answers ranging from "There is no CPAN for Python" and "We already > have CPAN for Python" (confusing). It confuses me that you call this "confusing". > I'm wondering - is there any work being done identifying .. > > (1) what is so good with CPAN? > (2) how can it be brought to the Python world? > > Is there a working group/initiative for this? Web page? Discussion group? I think the right place to discuss any deficiencies of PyPI compared to CPAN is the distutils-sig mailing list. Stefan From python.list at tim.thechases.com Wed Mar 3 07:55:54 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Mar 2010 06:55:54 -0600 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <4B8E5C5A.9020407@tim.thechases.com> Oren Elrad wrote: > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass The general response to "except: pass" from the Old Ones on the python list (and those younger ones who tend to prescribe good style) is a fairly immediate "don't use bare excepts". So endorsing this "silence" syntax would be tantamount to condoning bare excepts. I'm not sure you'll find much support. http://www.google.com/search?q=site%3Amail.python.org+%22bare+excepts%22 (I've had problems with Google finding all posts to c.l.p on m.p.o recently, so this may only be a recent representative sample) -tkc From stefan_ml at behnel.de Wed Mar 3 07:56:19 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 13:56:19 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: Message-ID: Stefan Behnel, 03.03.2010 13:52: > Olof Bjarnason, 03.03.2010 13:45: >> The "Where is CPAN for Python?" question keeps popping up, with >> answers ranging from "There is no CPAN for Python" and "We already >> have CPAN for Python" (confusing). > > It confuses me that you call this "confusing". > > >> I'm wondering - is there any work being done identifying .. >> >> (1) what is so good with CPAN? >> (2) how can it be brought to the Python world? >> >> Is there a working group/initiative for this? Web page? Discussion group? > > I think the right place to discuss any deficiencies of PyPI compared to > CPAN is the distutils-sig mailing list. Ah, and the catalog-sig, if it's really related to the index rather than packages and package distribution. Stefan From olof.bjarnason at gmail.com Wed Mar 3 07:59:00 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 3 Mar 2010 13:59:00 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: Message-ID: 2010/3/3 Stefan Behnel : > Olof Bjarnason, 03.03.2010 13:45: >> >> The "Where is CPAN for Python?" question keeps popping up, with >> answers ranging from "There is no CPAN for Python" and "We already >> have CPAN for Python" (confusing). > > It confuses me that you call this "confusing". How come? > > >> I'm wondering - is there any work being done identifying .. >> >> (1) what is so good with CPAN? >> (2) how can it be brought to the Python world? >> >> Is there a working group/initiative for this? Web page? Discussion group? > > I think the right place to discuss any deficiencies of PyPI compared to CPAN > is the distutils-sig mailing list. Thanks. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://olofb.wordpress.com From ben+python at benfinney.id.au Wed Mar 3 08:08:20 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 00:08:20 +1100 Subject: Which mock library do you prefer? References: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: <87wrxtv9h7.fsf@benfinney.id.au> Albert van der Horst writes: > Unit testing is a concept that goes well with functions without side > effects. If you have classes, that doesn't work so well. How so? Unit tests are ideal for testing classes, in my experience; they can be inspected and tested as a distinct unit of code. > For classes use cases are the way to go. That's a category error. Use cases are good for *functional* testing; that is, testing of the system as a whole, with the focus on specific uses to which the system needs to be put. They're quite orthogonal. Neither interferes with the other. It's best to have both. > Think about it. The whole state of an object can affect the way a > method works. So effectively for a unit test you have to put the > object in a whole special fully controlled state. That's right. This is called a ?test fixture?, and it's a central concept of unit testing. There is explicit support in xUnit-style unit test libraries (like Python's ?unittest?) for test fixtures. -- \ ?When I was a kid I used to pray every night for a new bicycle. | `\ Then I realised that the Lord doesn't work that way so I stole | _o__) one and asked Him to forgive me.? ?Emo Philips | Ben Finney From lie.1296 at gmail.com Wed Mar 3 08:09:20 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 04 Mar 2010 00:09:20 +1100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> Message-ID: <4b8e5f9f$1@dnews.tpgi.com.au> On 03/03/2010 04:48 PM, Steven D'Aprano wrote: > Or one can simply use *reason*: what justification is there for putting > comments in strings at the top of the function? The only one I can see is > if you are writing for an embedded device, you may want to remove doc > strings to save memory -- and even that is implementation dependent. Python already have a well-defined mechanism to remove docstrings with the -O flag; there is really no other reason but plain ignorance and inflexibility to think in other language than . From lie.1296 at gmail.com Wed Mar 3 08:19:56 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 04 Mar 2010 00:19:56 +1100 Subject: There should be one-- and preferably only one --obvious way to do it (was "Interest check in some delicious syntactic sugar for "except:pass"") In-Reply-To: References: Message-ID: <4b8e621b@dnews.tpgi.com.au> On 03/03/2010 08:27 PM, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ......... block > > -------------------------> > > try: > .........block > except: > .........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. Given that python HATE bare-except (and `pass`-block bare except is even worse) and given python's idiosyncrasies "There should be one-- and preferably only one --obvious way to do it", "Errors should never pass silently"; the chance for `silence` keyword is precisely zero. > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. There are lots of reason why bare-except is bad, one being is that it makes it way too easy to ignore errors that you don't actually want to silence; and given that bare-excepts would prevent Ctrl+C (Interrupt) from working. Sorry, but IMHO we shouldn't make syntax sugar for bad practices. From ben+python at benfinney.id.au Wed Mar 3 08:21:14 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 00:21:14 +1100 Subject: Working group for Python CPAN-equivalence? References: Message-ID: <87r5o1v8vp.fsf@benfinney.id.au> Olof Bjarnason writes: > Hi everybody! > > The "Where is CPAN for Python?" question keeps popping up, with > answers ranging from "There is no CPAN for Python" and "We already > have CPAN for Python" (confusing). Caused in no small measure by the fact that Perl people mean at least two distinct things by ?Where is CPAN for Python??: * The central package registry, CPAN, with metadata in a standard queryable format, and all registered packages redundantly mirrored and available for installation at user-specified versions. We have an equivalent in PyPI, though it's incomplete since many *registered* packages are not actually hosted *at* PyPI. * The command-line tool, ?cpan?, used for performing operations on the set of locally-installed Perl packages, and for package maintainers performing operations on the repository. We have nothing like this. The Distutils library does a small part of the job, and the third-party ?easy_install? program works for those which use the Setuptools extensions; but there's nothing at all equivalent to Perl's ?cpan? tool. Often, Perl people asking simply ?Where is CPAN for Python?? are asking about a third thing: * The unified, mature, actively-maintained, seamless combination of the CPAN repository and the ?cpan? tool, that work together as a single reliable system to such an extent that one can sensibly talk about them *both* as one thing, ?CPAN?. This one we're a *long* way from with Python, IMO. Much work has been going on over the last year or so, and it's encouraging to see; but so much of that work is dealing with the legacy burden of Distutils that I get weary seeing how far there is to go. -- \ ?A child of five could understand this. Fetch me a child of | `\ five.? ?Groucho Marx | _o__) | Ben Finney From zhushazang at yahoo.com.br Wed Mar 3 08:32:30 2010 From: zhushazang at yahoo.com.br (Zhu Sha Zang) Date: Wed, 03 Mar 2010 10:32:30 -0300 Subject: Eric4 vs Python3.1 Message-ID: <4B8E64EE.9040707@yahoo.com.br> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Someone using Eric4 to program with Python3/3.1? What can i do, because he insist to use only Python2.6.4. Att -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkuOZO4ACgkQ35zeJy7JhCjdFACfZrjVa+8O9fu/7FEPr6mVeaEg Rm0AmgM+XtuxFH1zUnfkaphF+MgPy3pf =MVeJ -----END PGP SIGNATURE----- From tibor.beck at hotmail.com Wed Mar 3 08:45:27 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Wed, 3 Mar 2010 05:45:27 -0800 (PST) Subject: monkey patching with @classmethod References: <4b8e5161$0$23009$426a74cc@news.free.fr> Message-ID: <0b3928bb-04e6-402a-9842-680b621ae256@x22g2000yqx.googlegroups.com> On 3. Mar., 13:09 h., Bruno Desthuilliers wrote: > gentlestone a ?crit : > > > > > Hi, is there some well-known problems with class method monkey > > patching? > > > I've got this error message: > > > unbound method get_pocet_neocislovanych() must be called with Pozemok > > instance as first argument (got Subjekt instance instead) > > The method is declared as: > > @classmethod > > @monkeypatch(Dokument) > > def get_pocet_neocislovanych(cls, subjekt): > > ? ? return cls.objects.filter(subjekt = subjekt, cislo__isnull = > > True).count() # or pass, this line is not important > > > and the monkey patch decorator is declared as: > > def monkeypatch(cls): > > ? ? def decorator(func): > > ? ? ? ? setattr(cls, func.__name__, func) > > ? ? ? ? return func > > ? ? return decorator > > The decorators are applied in order. So you first add the yet > undecorated function as an attribute of the class, then pass the > function to classmethod. > > FWIW, this monkeypatch decorator is IMHO a plain waste of time. The > following code does the same thing and is (IMHO again) *much* more readable: > > def get_pocet_neocislovanych(cls, subjekt): > ? ? ? return cls.objects.filter( > ? ? ? ? ?subjekt=subjekt, > ? ? ? ? ?cislo__isnull= True > ? ? ? ? ?).count() # or pass, this line is not important > > Dokument.get_pocet_neocislovanych=@classmethod(get_pocet_neocislovanych) > > Also, Django's BestPractice(tm) is to define such "query" methods on the > ? model's manager, not as a classmethod of the model. > > My 2 cents thx, I changed my definitions to manager style and have no more problems seems to be safe to use manager instead classmethod - do not know why :-) From benjamin.kaplan at case.edu Wed Mar 3 08:48:37 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Mar 2010 08:48:37 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: On Wed, Mar 3, 2010 at 6:47 AM, Oren Elrad wrote: > To all that responded, thanks for the prompt response folks, your > criticisms are well taken. Coming from Cland, one is inculcated with > the notion that if the programmer wants to shoot himself in the foot > the language ought not to prevent that (or even should return him a > loaded magnum with the safety off and the hair-trigger pulled). My > apologies for not immediately grokking the cultural difference in > pytown. > > With that said, let me at least offer a token defense of my position. > By way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. > > Certainly the parade of horribles (bad files! corrupt data! syntax > errors!) is a tad melodramatic. Either os.remove() succeeds or it > doesn't and the execution path (in the estimation of this programmer, > at least) is not at all impacted by whether it succeeds or fails. I > know with certainty at compile time what exceptions might be raised > and what the consequences of passing them are and there is no sense > pestering the user or sweating over it. Nor can I see the logic, as > was suggested, in writing "except OSError:" since (seems to me) mere > surplusage -- it neither causes a semantic difference in the way the > program runs nor provides anything useful to the reader. > > What if the user presses Ctrl-C to try to quit the program? Your bare except is catching the KeyboardInterrupts and ignoring them. -------------- next part -------------- An HTML attachment was scrubbed... URL: From desktopsbyduck at gmail.com Wed Mar 3 08:49:34 2010 From: desktopsbyduck at gmail.com (RICHARD MOORE) Date: Wed, 3 Mar 2010 05:49:34 -0800 (PST) Subject: RICHARD MOORE wants to stay in touch on LinkedIn Message-ID: <1313196773.7301341.1267624174377.JavaMail.app@ech3-cdn11.prod> LinkedIn ------------ I'd like to add you to my professional network on LinkedIn. - RICHARD MOORE Confirm that you know RICHARD MOORE https://www.linkedin.com/e/isd/1117171902/jlHq1JKw/EML-invg_56/ ------ (c) 2010, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From desktopsbyduck at gmail.com Wed Mar 3 08:50:07 2010 From: desktopsbyduck at gmail.com (RICHARD MOORE) Date: Wed, 3 Mar 2010 05:50:07 -0800 (PST) Subject: RICHARD MOORE wants to stay in touch on LinkedIn Message-ID: <1916304926.7302790.1267624207959.JavaMail.app@ech3-cdn11.prod> LinkedIn ------------ I'd like to add you to my professional network on LinkedIn. - RICHARD MOORE Confirm that you know RICHARD MOORE https://www.linkedin.com/e/isd/1117171902/jlHq1JKw/EML-invg_56/ ------ (c) 2010, LinkedIn Corporation -------------- next part -------------- An HTML attachment was scrubbed... URL: From yyfgv at yahoo.com.ar Wed Mar 3 09:00:16 2010 From: yyfgv at yahoo.com.ar (Publicidad para Todos) Date: 03 Mar 2010 11:00:16 -0300 Subject: Tu mailing llega ahora a todos lados Message-ID: <20100303105936.0C607419FF28A41A@yahoo.com.ar> An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Wed Mar 3 09:33:30 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 3 Mar 2010 15:33:30 +0100 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: > By way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. You just found the right solution: define a function for something that you do repeatedly. No need to change the language. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From subhakolkata1234 at gmail.com Wed Mar 3 09:36:23 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Wed, 3 Mar 2010 06:36:23 -0800 (PST) Subject: Few early questions on Class Message-ID: <24aeb097-6376-46b8-a3ff-df4a04d49a3c@y7g2000prc.googlegroups.com> Dear Group, I was practising some early example of class if you can kindly let me know where I was going wrong. I am pasting directly from IDLE. There may be slight indentation problem. I am using Python 2.6.4 on Windows XP Service Pack 3. The Code and the output: >>> class Student: def _init_(self,name): self.name=name self.attendance=0 self.marks=[] number_of_marks=len(self.marks) print number_of_marks >>> b=Student("Bobby") Traceback (most recent call last): File "", line 1, in b=Student("Bobby") TypeError: this constructor takes no arguments >>> Class Shape: SyntaxError: invalid syntax >>> class Shape: def _init_(self,x,y): self.x=x self.y=y description="This Shape is not been described Yet" author="Nobody has Claimed it Yet" def area(self): return self*x+self*y def perimeter(self): return 2*self.x+2*self*y >>> rectangle=Shape(100,45) Traceback (most recent call last): File "", line 1, in rectangle=Shape(100,45) TypeError: this constructor takes no arguments >>> rectangle=Shape() >>> print rectangle.area() Traceback (most recent call last): File "", line 1, in print rectangle.area() AttributeError: Shape instance has no attribute 'area' >>> Best Regards, Subhabrata. From pranav.choudhary at gmail.com Wed Mar 3 09:41:25 2010 From: pranav.choudhary at gmail.com (pranav) Date: Wed, 3 Mar 2010 06:41:25 -0800 (PST) Subject: save CRL to a file (M2Crypto.X509.CRL object) Message-ID: I do not see an option to save M2Crypto.X509.CRL object to a file. Am I overlooking something? Thanks From python at mrabarnett.plus.com Wed Mar 3 09:42:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 14:42:00 +0000 Subject: Docstrings considered too complicated In-Reply-To: <7v695nFa0fU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> Message-ID: <4B8E7538.2080003@mrabarnett.plus.com> Gregory Ewing wrote: > MRAB wrote: > >> BTW, the first programming I did was in hexadecimal (C4xx was "LDI xx"). > > Hey, a SC/MP! That was my first programming language, > too. What sort of machine was it in? > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment display, which I had to solder together, and also make my own power supply. I had the extra RAM and the I/O chip, so that's 256B (including the memory used by the monitor) + 256B additional RAM + 128B more in the I/O chip. From jmg3000 at gmail.com Wed Mar 3 09:42:24 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Wed, 3 Mar 2010 06:42:24 -0800 (PST) Subject: Few early questions on Class References: <24aeb097-6376-46b8-a3ff-df4a04d49a3c@y7g2000prc.googlegroups.com> Message-ID: <7277b1d5-e1b5-4afc-a9a4-9e45e9e4ff80@z11g2000yqz.googlegroups.com> Hi Subhabrata, s/_init_/__init__/ From python at mrabarnett.plus.com Wed Mar 3 09:45:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 14:45:06 +0000 Subject: case do problem In-Reply-To: <7v6cviFq18U1@mid.individual.net> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> <7v6cviFq18U1@mid.individual.net> Message-ID: <4B8E75F2.8090608@mrabarnett.plus.com> Gregory Ewing wrote: > Alf P. Steinbach wrote: >> * Tracubik: > > >>> iterations=0; >>> count=0; >>> REPEAT; >>> iterations = iterations+1; >>> ... >>> IF (genericCondition) THEN count=count+1; >>> ... >>> CASE count OF: >>> 1: m = 1 >>> 2: m = 10 >>> 3: m = 100 >> >> Uhm, is this syntactically valid Pascal? As I recall, every Pascal >> construct was delimited in some way. > > I think it's okay. Pascal's control structures such as > if-then and while-do mostly take single statements and > didn't have an ending keyword. If you want multiple > statements in the body you have to put begin-end around > them. > > Putting a semicolon after REPEAT is stylistically a > bit odd, but it's not wrong. > There shouldn't be a colon after the 'OF', and the cases themselves should be separated by semicolons (the case-statement itself ends with 'end'). From python.list at tim.thechases.com Wed Mar 3 09:49:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 03 Mar 2010 08:49:27 -0600 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: <4B8E76F7.20809@tim.thechases.com> Oren Elrad wrote: > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. I admit there are times I've done something similar, usually with what I call my "int0" and "float0" utility functions which roughly translate to "give me a stinkin' int/float and if something goes wrong, give me 0, but the return result better darn well be an int/float!" functions. But as you describe and was later commended as a right-ish way to approach it, abstracting that off into a function with minimal code in the try: block is the right way to go. -tkc def int0(v): """converts v to a int, or returns 0 if it can't""" try: return int(v) except: # usually a ValueError but catch all cases try: # int("1.1") fails so try float()ing it first return int(round(float(v))) except: return 0 def float0(v): """converts v to a float, or returns 0 if it can't""" try: return float(v) except: return 0.0 From electriclightheads at gmail.com Wed Mar 3 09:50:09 2010 From: electriclightheads at gmail.com ('2+) Date: Wed, 3 Mar 2010 23:50:09 +0900 Subject: pyao makes the right sound but why? Message-ID: <1078018b1003030650g499e4a7bvfaab763be485755c@mail.gmail.com> with my soy.py tofu = soy.Bean() x = tofu.pattern(44100 * 3) creates x which is an array('h') and len(x) = 44100 * 6 this x is a stereo groove pattern that lasts 3 sec if samplerate is set to 44100 and since wave.py could save it to a_file.wav i was wondering if dev = ao.AudioDevice('alsa') dev.play(x) could launch me a semi realtime dj kinda sys luckily .. it does seem to be making the right sound but why? the default of the samplerate and that 16bit happened to match with my thing x? o but if i do dev.play(x, len(x)) it only plays the half of the pattern and dev.play(x, 2 * len(x)) does the right thing and the 2nd 4th 6th .. play gives me ALSA underrun, at least 0ms 3rd, 5th, 7th does it fine /usr/share/doc/python-pyao doesn't teach me the answer does somebody know more about pyao? -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From spamfresser at ch3ka.de Wed Mar 3 09:50:19 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 03 Mar 2010 15:50:19 +0100 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: References: Message-ID: Am 03.03.2010 12:47, schrieb Oren Elrad: > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. You don't know that what you stated in your comment is true. All you know is that there was an exception. To find the reason, you have to inspect the exception. You escpecially do NOT know whether the file is removed or not. OK, os.remove() might be a CPython builtin (not sure ATM), but in general all sort of crazy things can happen here, like ImportError raised by code in the lib or so. And of course: a bare except: also catches ^C or SystemExit. That is almost certainly *not* what you want, right? To your first question about a "silenced" keyword: you could emulate this with context managers I guess. Something like (untested, just a quick mockup how it could look): class silenced: def __init__(self, *silenced): self.exceptions=tuple(silenced) #just to be explicit def __enter__(self): return self #dito1 def __exit__(self, type, value, traceback): for ex in self.exceptions: if isinstance(value, ex): return True #supresses exception So: with silenced(os.Error): os.remove(somefile) Would translate to: try: os.remove(somefile) except os.Error: pass One nice thing about this approach would be that you can alias a set of exceptions with this: idontcareabouttheseerrors=silenced(TypeError, ValueError, PEBCAKError, SyntaxError, EndOfWorldError, 1D10T_Error) with idontcareabouttheseerrors: do_stuff() Regards, Michael From michaelveloz at gmail.com Wed Mar 3 09:57:56 2010 From: michaelveloz at gmail.com (Veloz) Date: Wed, 3 Mar 2010 06:57:56 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> <7v6cf4FnnrU1@mid.individual.net> Message-ID: <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> On Mar 3, 1:14?am, Gregory Ewing wrote: > MRAB wrote: > > I suppose it depends on the complexity of the data structure. A dict's > > methods are threadsafe, for example, but if you have a data structure > > where access leads to multiple method calls then collectively they need > > a lock. > > It also depends on the nature of the objects being used > as dict keys. Dict operations invoke the hashing and > comparison methods of the keys, which in general can > execute arbitrary Python code. > > If the keys are elementary built-in types such as > strings or ints, then dict operations will *probably* > be atomic. But I think I'd use a lock anyway, to be > on the safe side. > > -- > Greg Unless I missed where you guys were going, I think we got off the main point. The main question at hand was this: what's the best way (heck, any way) to implement a sort of "peek" whereby a number of processes can write results to some common "object" and some other process can "peek" into this object, looking for specific items they're interested in? I've tried doing this with a queue, as follows: children all write results to queue, each result has an identifier. Another interested party, which wants to know if identifier XXX has been placed in the queue, removes all the items, one by one from the queue, "keeps" the one matching the identifier (if found) and puts the rest of the items back on the queue, so other interested parties can also look through it. This is not a good solution, but it illustrates what I'm trying to achieve.. I'm looking at multiprocessing.Manager, ctypes, etc, but nothing's really jumped out. I also tried creating my own list class which uses locks to provide a "peek and remove" method, but I don't have a good way to share an instance of this object across processes. Any thoughts would be welcomed! Michael From jjposner at optimum.net Wed Mar 3 09:58:46 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 09:58:46 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8e4041$0$17447$426a34cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: On 3/3/2010 5:56 AM, Bruno Desthuilliers wrote: > Eike Welk a ?crit : >> John Posner wrote: >>> I've updated the text at this location: >>> >>> > http://cl1p.net/bruno_0301.rst/ >> >> I think this is a very useful writeup! >> It would be perfect with a little bit of introduction that says: >> 1. - What it is: "The rough details of method look-up"; >> 2. - which contains some of the questions that that made that authors >> write the text. This way people with similar questions can find it >> with Google. >> > > John, do you think you could something with the following ? Sure thing, Bruno. I'll incorporate/edit your new text below into a Python Wiki entry. The headings in the Documentation table of contents page (http://wiki.python.org/moin/Documentation) seem pretty sober, so I plan to use a straightforward title: FromFunctionsToMethods ... instead of the clearly superior ... ItsAFunctionItsAMethodItsAUseOfTheDescriptorProtocol Does this article belong in the "Advanced Topics" section of the page? I'm not sure, but I'll place it there for now. (Alternative suggestions welcome!) > > """ > "Is it a function ? is it a method ? No, it's... " - or : What's in a > Python method ? > > Python newcomers often have hard time understanding the "magic" behind > Python's methods - and truth is that Python's object model can be a bit > peculiar when compared to most mainstream (or not-so-mainstream) OOPLs. > As a matter of fact, there are quite a few threads on c.l.py with either > direct or indirect questions about what makes a Python method, and I > must have explained the whole mechanism at least 3 or 4 times there. The > following text is an edited version of my last attempt, as edited, > corrected and published by John Posner, MayHisNameBePraised(tm). > > This text isn't meant as a replacement for neither the official > FineManual(tm)[XXX : relevant link] nor the very excellent - if somehow > technical - 'Descriptors how-to' [XXX : relevant link]. It's mostly a > brief but hopefully helpful overview of what exactly is a Python method, > and how Python magically inserts the 'self' or 'cls' argument to method > calls. > """ > > Feel free to edit / amend / rewrite / trash at will - you're now > officially in charge of publishing this text !-) > Yow, the mantle of responsibility weighs heavily upon my poor shoulders! Film at 11, John From jmg3000 at gmail.com Wed Mar 3 10:04:08 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Wed, 3 Mar 2010 07:04:08 -0800 (PST) Subject: Working group for Python CPAN-equivalence? References: Message-ID: <67f0da3c-9c4d-4080-8821-3acbfada1d4f@o30g2000yqb.googlegroups.com> On Mar 3, 7:45?am, Olof Bjarnason wrote: > Hi everybody! > > The "Where is CPAN for Python?" question keeps popping up, with > answers ranging from "There is no CPAN for Python" and "We already > have CPAN for Python" (confusing). > > I'm wondering - is there any work being done identifying .. > > (1) what is so good with CPAN? > (2) how can it be brought to the Python world? > > Is there a working group/initiative for this? Web page? Discussion group? Hi Olof, Discussions about that often take place on the distutils-sig and catalog-sig MLs. People are currently working on making the Cheeseshop even better and the situation is improving. Have a look at [Tarek's blog](http:// tarekziade.wordpress.com/) for more info. ---John From invalid at invalid.invalid Wed Mar 3 10:05:54 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 15:05:54 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: On 2010-03-03, Gregory Ewing wrote: > Grant Edwards wrote: > >> Just a mediocre copy of the CP/M filesystem, which was in turn >> copied from DEC's RSTS or RSX. > > It was actually an improvement over CP/M's file > system. CP/M didn't have hierarchical directories Neither did the original MS-DOS filesystem. > or timestamps and recorded file sizes in 128-byte blocks > rather than bytes. I thought that was true of the original MS-DOS filesystem as well, but I wouldn't bet money on it. -- Grant Edwards grant.b.edwards Yow! I like the way ONLY at their mouths move ... They gmail.com look like DYING OYSTERS From jmg3000 at gmail.com Wed Mar 3 10:10:07 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Wed, 3 Mar 2010 07:10:07 -0800 (PST) Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> Message-ID: <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> On Mar 2, 11:58?pm, John Bokma wrote: > Lie Ryan writes: > > On 03/03/2010 09:47 AM, TomF wrote: > > [..] > > >> There > >> is also a program called cpan, distributed with Perl. ?It is used for > >> searching, downloading, installing and testing modules from the CPAN > >> repository. ?It's far more extensive than setuptools. ?AFAIK the python > >> community has developed nothing like it. > > > python have easy_install > > How easy is it to /remove/ something? ;-) (Last time I checked I read > something like "manually remove the .egg"... > Have a look at [pip](http://cheeseshop.python.org/pypi/pip). It should support uninstalling packages. ---John From alfps at start.no Wed Mar 3 10:10:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 16:10:26 +0100 Subject: A "scopeguard" for Python Message-ID: For C++ Petru Marginean once invented the "scope guard" technique (elaborated on by Andrei Alexandrescu, they published an article about it in DDJ) where all you need to do to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception, is to declare a ScopeGuard w/desired action. The C++ ScopeGuard was/is for those situations where you don't have proper classes with automatic cleanup, which happily is seldom the case in good C++ code, but languages like Java and Python don't support automatic cleanup and so the use case for something like ScopeGuard is ever present. For use with a 'with' statement and possibly suitable 'lambda' arguments: class Cleanup: def __init__( self ): self._actions = [] def call( self, action ): assert( is_callable( action ) ) self._actions.append( action ) def __enter__( self ): return self def __exit__( self, x_type, x_value, x_traceback ): while( len( self._actions ) != 0 ): try: self._actions.pop()() except BaseException as x: raise AssertionError( "Cleanup: exception during cleanup" ) from I guess the typical usage would be what I used it for, a case where the cleanup action (namely, changing back to an original directory) apparently didn't fit the standard library's support for 'with', like with Cleanup as at_cleanup: # blah blah chdir( somewhere ) at_cleanup.call( lambda: chdir( original_dir ) ) # blah blah Another use case might be where one otherwise would get into very deep nesting of 'with' statements with every nested 'with' at the end, like a degenerate tree that for all purposes is a list. Then the above, or some variant, can help to /flatten/ the structure. To get rid of that silly & annoying nesting. :-) Cheers, - Alf (just sharing, it's not seriously tested code) From spamfresser at ch3ka.de Wed Mar 3 10:15:27 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 03 Mar 2010 16:15:27 +0100 Subject: Is this secure? In-Reply-To: <4b8ddcf6$1@dnews.tpgi.com.au> References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> <4b8ddcf6$1@dnews.tpgi.com.au> Message-ID: Am 03.03.2010 04:51, schrieb Lie Ryan: > import itertools > def gen(): > valid_chars = 'abcdefghijklmnopqrstuvwxyz' > for char in itertools.repeat(valid_chars): > yield char > > gen = gen() > def gen_rand_string(length): > chars = (next(gen) for i in range(length)) > return ''.join(chars) > > since it gives me a perfect distribution of letters, It does not. Only if not (length(valid_chars) % length) Regards, Michael From redazione at italiainweekend.it Wed Mar 3 10:18:23 2010 From: redazione at italiainweekend.it (ItaliaWeekend) Date: Wed, 3 Mar 2010 16:18:23 +0100 Subject: PAGINE DI UNA ITALIA MERAVIGLIOSA Message-ID: <01f6f7b5$40240$efa56794340972@pavillon-pc> An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Mar 3 10:19:56 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 15:19:56 +0000 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> References: <35e00b331003030127y11b4964ev8c71417a2599eeec@mail.gmail.com> Message-ID: <4B8E7E1C.7090002@mrabarnett.plus.com> Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. Meanwhile, the > potential keyword 'silence' does not appear to be in significant use > as a variable[2], or an alternative keyword might be imagined > ('quiet', 'hush', 'stfu') but I somewhat like the verbiness of > 'silence' since that is precisely what it does to the block (that is, > you have to inflect it as a verb, not a noun -- you are telling the > block to be silent). Finally, since this is the purest form of > syntactic sugar, I cannot fathom any parsing, interpreting or other > complications that would arise. > > I appreciate any feedback, including frank statements that you'd > rather not trifle with such nonsense. > > ~Oren > > [1] http://www.google.com/codesearch?q=except%3A\spass&hl=en > [2] http://www.google.com/codesearch?hl=en&lr=&q=silence+lang%3Apy Bare excepts are a very bad idea. And you want syntactic sugar for them? Aargh! :-) From invalid at invalid.invalid Wed Mar 3 10:30:36 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 15:30:36 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: On 2010-03-03, Grant Edwards wrote: > On 2010-03-03, Gregory Ewing wrote: >> Grant Edwards wrote: >> >>> Just a mediocre copy of the CP/M filesystem, which was in turn >>> copied from DEC's RSTS or RSX. >> >> It was actually an improvement over CP/M's file system. CP/M >> didn't have hierarchical directories > > Neither did the original MS-DOS filesystem. > >> or timestamps and recorded file sizes in 128-byte blocks >> rather than bytes. > > I thought that was true of the original MS-DOS filesystem as > well, but I wouldn't bet money on it. I definitely remember that old MS-DOS programs would treat Ctrl-Z as an EOF marker when it was read from a text file and would terminate a text file with a Ctrl-Z when writing one. I don't know if that was because the underlying filesystem was still did everything in blocks or if it was because those MS-DOS programs were direct ports of CP/M programs. I would have sworn that the orignal MS-DOS file API was FCB based and worked almost exactly like CP/M. IIRC, the "byte stream" API showed up (in the OS) sever versions later. The byte stream API was implemented by many compiler vendor's C libraries on top of the block-oriented FCB API. -- Grant Edwards grant.b.edwards Yow! I had a lease on an at OEDIPUS COMPLEX back in gmail.com '81 ... From mrmakent at gmail.com Wed Mar 3 10:39:05 2010 From: mrmakent at gmail.com (Mike Kent) Date: Wed, 3 Mar 2010 07:39:05 -0800 (PST) Subject: A "scopeguard" for Python References: Message-ID: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup From efruttero at hotmail.com Wed Mar 3 10:40:48 2010 From: efruttero at hotmail.com (efruttero at hotmail.com) Date: Wed, 3 Mar 2010 07:40:48 -0800 (PST) Subject: Smalltalk-like categories for methods ? Message-ID: <8f66e5eb-3dda-4f7a-b607-cd7f2ea0e16b@c16g2000yqd.googlegroups.com> Hello, Is there an IDE that supports methods categories/classification, either through some comment convention, annotation, or any other mean ? Thanks in advance, Eric Fruttero From steve at holdenweb.com Wed Mar 3 10:42:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Mar 2010 10:42:20 -0500 Subject: Queue peek? In-Reply-To: <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> <7v6cf4FnnrU1@mid.individual.net> <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> Message-ID: Veloz wrote: > On Mar 3, 1:14 am, Gregory Ewing wrote: >> MRAB wrote: >>> I suppose it depends on the complexity of the data structure. A dict's >>> methods are threadsafe, for example, but if you have a data structure >>> where access leads to multiple method calls then collectively they need >>> a lock. >> It also depends on the nature of the objects being used >> as dict keys. Dict operations invoke the hashing and >> comparison methods of the keys, which in general can >> execute arbitrary Python code. >> >> If the keys are elementary built-in types such as >> strings or ints, then dict operations will *probably* >> be atomic. But I think I'd use a lock anyway, to be >> on the safe side. >> >> -- >> Greg > > Unless I missed where you guys were going, I think we got off the main > point. The main question at hand was this: what's the best way (heck, > any way) to implement a sort of "peek" whereby a number of processes > can write results to some common "object" and some other process can > "peek" into this object, looking for specific items they're interested > in? > > I've tried doing this with a queue, as follows: children all write > results to queue, each result has an identifier. Another interested > party, which wants to know if identifier XXX has been placed in the > queue, removes all the items, one by one from the queue, "keeps" the > one matching the identifier (if found) and puts the rest of the items > back on the queue, so other interested parties can also look through > it. > > This is not a good solution, but it illustrates what I'm trying to > achieve.. > > I'm looking at multiprocessing.Manager, ctypes, etc, but nothing's > really jumped out. > > I also tried creating my own list class which uses locks to provide a > "peek and remove" method, but I don't have a good way to share an > instance of this object across processes. > > Any thoughts would be welcomed! > Michael Sounds to me like you are using one queue when you should be using several. If a single process wants to distribute information to multiple clients, have a queue for each client. This makes it easy for each client to find out if it has work (if it does its queue is non-empty), Is this helpful, or a red herring? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mwilson at the-wire.com Wed Mar 3 10:43:25 2010 From: mwilson at the-wire.com (Mel) Date: Wed, 03 Mar 2010 10:43:25 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: Tim Chase wrote: > I admit there are times I've done something similar, usually with > what I call my "int0" and "float0" utility functions which > roughly translate to "give me a stinkin' int/float and if > something goes wrong, give me 0, but the return result better > darn well be an int/float!" functions. But as you describe and > was later commended as a right-ish way to approach it, > abstracting that off into a function with minimal code in the > try: block is the right way to go. [ ... ] > def int0(v): > """converts v to a int, or returns 0 if it can't""" > try: > return int(v) > except: # usually a ValueError but catch all cases > try: > # int("1.1") fails so try float()ing it first > return int(round(float(v))) > except: > return 0 > > def float0(v): > """converts v to a float, or returns 0 if it can't""" > try: > return float(v) > except: > return 0.0 I think replacing `except:` with `except StandardError:` would work as well, and be correct, too. Mel. From mrkafk at gmail.com Wed Mar 3 10:46:37 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 16:46:37 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7x635fdcth.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Patrick Maupin writes: >> One of my complaints. If you had read the document you would have >> seen others. I actually have several complaints about YAML, but I >> tried to write a cogent summary. > Yaml sucks, but seems to have gotten some traction regardless. > Therefore the Python principle of "there should be one and only one > obvious way to do it" says: don't try to replace the existing thing if > your new thing is only slightly better. With all due respect, Paul, and with thanks for all the help you've given me, I have to disagree here: this is a really, really complicated matter and I think there is a case even for making things slightly better. I think this is a matter of "investment period", so to speak: is it short or long? In short term, it absolutely makes no sense to produce even slight improvement. But in the long run it will almost certainly pay off to switch to smth even somewhat better implementation (say, imaginary "20%" if you get my drift): suppose we stay with sucky format for 10 years. Wouldn't it make sense to implement a new one and be "in red" in terms of effort expended versus saved for 3 years, but then be "in black" for the following 7 years? > Just deal with the existing > thing's imperfections or make improvements to it. OK, but how? How would you make up e.g. for JSON's lack of comments? Producing accompanying ".json-comment" format and writing libraries that parse the comments and interleave them with JSON file for producing human-readable commented output? I think the effort required by all parties, both developers and users, before they produced smth like this and learned to use this widely and comprehensively, for this manner of improvement would be so high that it would be actually cheaper to dump the thing and develop smth new that has built-in support for comments. If you mean some other method of improving existing things like formats, well let's hear it; but I for one don't see any worth doing to significant extent really, other than dumping the thing or producing next, improved version at least. Improvement: other than making basic tools like parsing libraries editors, what improvements can you realistically make? And such improvements in and of themselves are not very expensive: my GPL Notepad++ has syntax highlighting for YAML (on top of gazillion other languages), and there are parsing libraries for it. So where's this terrible cost to it? OTOH, if YAML produces net benefit for as few as, say, 200 people in real world, the effort to make it has been well worth it. > If you can make a > really powerful case that your new thing is 1000x better than the old > thing, that's different, but I don't think we're seeing that here. Perhaps in ideal world we would be able to develop smth good or at least decent without long series of abominations preceding it. But I don't think we live in such world and I don't think it's possible to produce a decent format (or language) without decades of having to deal with abominations first. We learn as we go along, there's no way but to produce whatever works best at the moment, learning from it, dumping it and then doing smth better. I don't think e.g. Python could be produced without C, COBOL and Fortran preceding it: it's important not only to know how to do it, but also how (and why) not to do it, and learning that can't be done without producing some sort of abomination. I'd argue that abominations are inevitable price of progress and evolution. > Also, XML is used for pretty much everything in the Java world. It > sucks too, but it is highly standardized, it observably gets the job > done, there are tons of structure editors for it, etc. Frankly > I'd rather have stayed with it than deal with Yaml. http://myarch.com/why-xml-is-bad-for-humans http://www.ibm.com/developerworks/xml/library/x-sbxml.html Such reasons alone are enough to consider dumping XML for smth better. Today I had to hand-edit XML config files for two programs (no other option). The files were rather large, complicated and doing it frankly sucked. I also have to maintain a few applications that internally use XML as data format: while they are tolerable, they still leave smth to be desired, as those applications are really slow for larger datasets, their users systematically make errors (like forgetting to attach DTD before editing), and working across various versions of Windows is still not perfect. If somebody out there invents smth that is better than XML "only" by half, I'm all for it. > There are too many of these damn formats. We should ban all but one of > them (I don't much care which one). And making even more of them is not > the answer. I think this is a situation of "beware of what you wish for". Suppose those alternative formats disappeared and you'd have no tools, however imperfect, to use them: I think that in many, many contexts deficiencies of "the" format would be so painful that most developers would just write their own "private" ones, and everyone would be even worse off than they are now. I wouldn't worry too much about "stretching scarce resources thin" either: abominations completely unfit to live waste little in the way of resources, and we learn a deal off them too. There are demonstrable benefits to this too: I for one am happy that ReST is available for me and I don't have to learn a behemoth such as DocBook to write documentation. (imaginary dialog: Paul: "eat your greens and learn your DocBook!" Me: "but I don't like it and there's too much of it..." ;-) OK me off the soapbox. Regards, mk From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 10:48:43 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 16:48:43 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: <4b8e84d2$0$10157$426a74cc@news.free.fr> John Posner a ?crit : > On 3/3/2010 5:56 AM, Bruno Desthuilliers wrote: >> Eike Welk a ?crit : >>> John Posner wrote: >>>> I've updated the text at this location: >>>> >>>> > http://cl1p.net/bruno_0301.rst/ >>> >>> I think this is a very useful writeup! >>> It would be perfect with a little bit of introduction that says: >>> 1. - What it is: "The rough details of method look-up"; >>> 2. - which contains some of the questions that that made that authors >>> write the text. This way people with similar questions can find it >>> with Google. >>> >> >> John, do you think you could something with the following ? > > Sure thing, Bruno. I'll incorporate/edit your new text below into a > Python Wiki entry. The headings in the Documentation table of contents > page (http://wiki.python.org/moin/Documentation) seem pretty sober, so I > plan to use a straightforward title: > > FromFunctionsToMethods What about "TheMagicBehindMethods" ? Mmm, not sure, so do what you think is best. > ... instead of the clearly superior ... > > ItsAFunctionItsAMethodItsAUseOfTheDescriptorProtocol > > Does this article belong in the "Advanced Topics" section of the page? > I'm not sure, but I'll place it there for now. (Alternative suggestions > welcome!) I spotted this: http://www.python.org/doc/faq/programming/#what-is-a-method http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls Our text is probably a bit too long for a direct inclusion in the FAQ, so I'd say it should go in the AdvancedTopics, and be linked from the FAQ. > > Yow, the mantle of responsibility weighs heavily upon my poor shoulders! !-) Thanks for doing the grunt work. From alfps at start.no Wed Mar 3 10:56:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 16:56:25 +0100 Subject: A "scopeguard" for Python In-Reply-To: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Mike Kent: > What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup by the way, that's one advantage: a "with Cleanup" is difficult to get wrong, while a "try" is easy to get wrong, as you did here --- another general advantage is as for the 'with' statement generally > original_dir = os.getcwd() > try: > os.chdir(somewhere) > # Do other stuff also, the "do other stuff" can be a lot of code and also, with more than one action the try-else introduces a lot of nesting > finally: > os.chdir(original_dir) > # Do other cleanup cheers & hth., - alf From mrkafk at gmail.com Wed Mar 3 11:10:08 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 17:10:08 +0100 Subject: Queue peek? In-Reply-To: <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> <1267567723.4101.28.camel@localhost.localdomain> <7v6cf4FnnrU1@mid.individual.net> <8bbd0a04-9a13-4f36-91c7-80f07bee0952@y17g2000yqd.googlegroups.com> Message-ID: Veloz wrote: > Unless I missed where you guys were going, I think we got off the main > point. The main question at hand was this: what's the best way (heck, > any way) to implement a sort of "peek" whereby a number of processes > can write results to some common "object" and some other process can > "peek" into this object, looking for specific items they're interested > in? I have used threads so far and not multiprocessing (much), so I'll describe it using threads: If I were you, I'd do it the simplest possible way, with dictionary and lock, in the following way: 1. Have shared "queue" of tasks, say, a dictionary. 2. Each worker thread and central "queue manager" access the queue in the same manner: ...do your stuff, prepare yourself acquire a lock update or read value from queue ...don't do much here to be able release lock quickly release the lock ...process value If you had your dictionary simple, it could work like Daniel Stutzbach wrote, that updates are thread safe and perhaps you could even dispense with locks and just read the dictionary; and if you wanted to use locks, for "peek"ing you could write a function that could e.g. acquire a lock, do a copy of the queue, release the lock, and return the copy to the object wanting to examine the queue. I have used this approach (although with a list, not a dictionary -- I haven't had the need to do extensive searching by keys) and so far it has worked for me. Regards, mk From steve at REMOVE-THIS-cybersource.com.au Wed Mar 3 11:10:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 16:10:50 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <4b8e8a0a$0$27863$c3e8da3@news.astraweb.com> On Wed, 03 Mar 2010 15:30:36 +0000, Grant Edwards wrote: > I definitely remember that old MS-DOS programs would treat Ctrl-Z as an > EOF marker when it was read from a text file and would terminate a text > file with a Ctrl-Z when writing one. I believe that Windows (at least up to Windows XP) still supports using ctrl-Z as EOF when reading text files. -- Steven From darcy at druid.net Wed Mar 3 11:12:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 11:12:48 -0500 Subject: Docstrings considered too complicated In-Reply-To: <4B8E7538.2080003@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> Message-ID: <20100303111248.7f40d659.darcy@druid.net> On Wed, 03 Mar 2010 14:42:00 +0000 MRAB wrote: > Gregory Ewing wrote: > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment > display, which I had to solder together, and also make my own power > supply. I had the extra RAM and the I/O chip, so that's 256B (including > the memory used by the monitor) + 256B additional RAM + 128B more in the > I/O chip. In case some of you youngsters think that there is a typo in the above, no, he means a total of 640 bytes. In today's terms that would be approx 0.0000006GB. Makes me want to go down to the basement and fire up the Altair. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From alfps at start.no Wed Mar 3 11:14:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 17:14:29 +0100 Subject: Docstrings considered too complicated In-Reply-To: <4b8e8a0a$0$27863$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> <4b8e8a0a$0$27863$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Wed, 03 Mar 2010 15:30:36 +0000, Grant Edwards wrote: > >> I definitely remember that old MS-DOS programs would treat Ctrl-Z as an >> EOF marker when it was read from a text file and would terminate a text >> file with a Ctrl-Z when writing one. > > I believe that Windows (at least up to Windows XP) still supports using > ctrl-Z as EOF when reading text files. It does, at least when the Ctrl Z is the sole contents of a "line". And it's a pain. :-( As a practical matter, when entering text in a console window the F6 key generates Ctrl Z. Cheers, - Alf From steve at REMOVE-THIS-cybersource.com.au Wed Mar 3 11:16:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 03 Mar 2010 16:16:55 GMT Subject: Re Interest check in some delicious syntactic sugar for "except:pass" References: Message-ID: <4b8e8b77$0$27863$c3e8da3@news.astraweb.com> On Wed, 03 Mar 2010 06:47:28 -0500, Oren Elrad wrote: > With that said, let me at least offer a token defense of my position. By > way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I can't > delete it. Nothing to be done. Or: (1) you forgot to import the os module (2) the os module (or os.remove) was rebound or monkey-patched to something unexpected (3) you have a bug in your code and somefile=23 (say) instead of the filename you're expecting (4) the user hit the interrupt key just at that instance (5) somefile doesn't exist (6) somefile does exist, but you don't have write-permission for it (7) the disk is mounted read-only (8) you don't have a search indexer and something else has gone wrong Hiding all those different errors is, quite frankly, shoddy work. #1-3 certainly shouldn't be hidden, as they are bugs in your program. #4 shouldn't be hidden, ignoring the user's interrupt command is bad, and rude if it is deliberate. #5 probably shouldn't be hidden either, as it most likely indicates a program bug, but some rare applications may be okay with ignoring it. And #6-8 should be told to the user, so they can fix the problem. -- Steven From floris.bruynooghe at gmail.com Wed Mar 3 11:17:32 2010 From: floris.bruynooghe at gmail.com (Floris Bruynooghe) Date: Wed, 3 Mar 2010 08:17:32 -0800 (PST) Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> Message-ID: <137d7aa5-a305-4091-a244-904b680d3b56@t41g2000yqt.googlegroups.com> On Mar 2, 6:18?pm, Raymond Hettinger wrote: > On Mar 2, 8:29?am, Veloz wrote: > > > Hi all > > I'm looking for a queue that I can use with multiprocessing, which has > > a peek method. > > > I've seen some discussion about queue.peek but don't see anything in > > the docs about it. > > > Does python have a queue class with peek semantics? > > Am curious about your use case? ?Why peek at something > that could be gone by the time you want to use it. > > ? val = q.peek() > ? if something_i_want(val): > ? ? ? ?v2 = q.get() ? ? ? ? # this could be different than val > > Wouldn't it be better to just get() the value and return if you don't > need it? > > ? val = q.peek() > ? if not something_i_want(val): > ? ? ? q.put(val) What I have found myself wanting when thinking of this pattern is a "q.put_at_front_of_queue(val)" method. I've never actually used this because of not having such a method. Not that it's that much of an issue as I've never been completely stuck and usually found a way to solve whatever I was trying to do without peeking, which could be argued as a better design in the first place. I was just wondering if other people ever missed the "q.put_at_front_of_queue()" method or if it is just me. Regards Floris PS: assuming "val = q.get()" on the first line From johnfilben at yahoo.com Wed Mar 3 11:19:08 2010 From: johnfilben at yahoo.com (John Filben) Date: Wed, 3 Mar 2010 08:19:08 -0800 (PST) Subject: Sort Big File Help Message-ID: <374400.23537.qm@web33805.mail.mud.yahoo.com> I am new to Python but have used many other (mostly dead) languages in the past.? I want to be able to process *.txt and *.csv files.? I can now read that and then change them as needed ? mostly just take a column and do some if-then to create a new variable.? My problem is sorting these files: 1.)??? How do I sort file1.txt by position and write out file1_sorted.txt; for example, if all the records are 100 bytes long and there is a three digit id in the position 0-2; here would be some sample data: a.?????? 001JohnFilben?? b.????? 002Joe? Smith?.. 2.)??? How do I sort file1.csv by column name; for example, if all the records have three column headings, ?id?, ?first_name?, ?last_name?; ?here would be some sample data: a.?????? Id, first_name,last_name b.????? 001,John,Filben c.?????? 002,Joe, Smith 3.)??? What about if I have millions of records and I am processing on a laptop with a large external drive ? basically, are there space considerations? What are the work arounds. Any help would be appreciated. Thank you. ?John Filben Cell Phone - 773.401.2822 Email - johnfilben at yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Wed Mar 3 11:22:06 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 3 Mar 2010 11:22:06 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <4eb0089f1003030822t2a7ec46au57a03de266a4d630@mail.gmail.com> On Wed, Mar 3, 2010 at 10:30 AM, Grant Edwards wrote: > On 2010-03-03, Grant Edwards wrote: > I definitely remember that old MS-DOS programs would treat > Ctrl-Z as an EOF marker when it was read from a text file and > would terminate a text file with a Ctrl-Z when writing one. Actually cmd.exe (at least on Windows XP) still treats Ctrl-Z as an EOF marker. From mrkafk at gmail.com Wed Mar 3 11:26:19 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 17:26:19 +0100 Subject: taking python enterprise level?... In-Reply-To: <20100302015813.5397655e.darcy@druid.net> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > I keep seeing this statement but nothing to back it up. I have created > many apps that run on Python with a PostgreSQL database with a fully > normalized schema and I can assure you that database joins were never > my problem unless I made a badly constructed query or left off a > critical index. I too have done that (Python/PGSQL), even adding a complicated layer of SQLAlchemy on top of it and have not had issue with this: when I profiled one of my apps, it turned out that it spent most of its computation time... rendering HTML. Completely unexpected: I expected DB to be bottleneck (although it might be that with huge datasets this might change). Having said that, re evidence that joins are bad: from what I've *heard* about Hibernate in Java from people who used it (I haven't used Hibernate apart from "hello world"), in case of complicated object hierarchies it supposedly generates a lot of JOINs and that supposedly kills DB performance. So there *may* be some evidence that joins are indeed bad in practice. If someone has smth specific/interesting on the subject, please post. Regards, mk From phil at freehackers.org Wed Mar 3 11:32:12 2010 From: phil at freehackers.org (BlueBird) Date: Wed, 3 Mar 2010 08:32:12 -0800 (PST) Subject: SOAP 1.2 Python client ? Message-ID: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Hi, I am looking for a SOAP 1.2 python client. To my surprise, it seems that this does not exist. Does anybody know about this ? The following clients seem to be both unmaintained and still supporting only SOAP 1.1 : - SUDS - zsi - SOAPy cheers, Philippe From jjposner at optimum.net Wed Mar 3 11:32:55 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 11:32:55 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: On 3/3/2010 9:58 AM, John Posner wrote: > Film at 11, > John > Done -- see http://wiki.python.org/moin/FromFunctionToMethod -John From showell30 at yahoo.com Wed Mar 3 11:37:54 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 3 Mar 2010 08:37:54 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <7071cfa0-0485-4192-b3ee-8e12d9f1fca2@f17g2000prh.googlegroups.com> On Mar 3, 7:46?am, mk wrote: > Paul Rubin wrote: > > Patrick Maupin writes: > >> One of my complaints. ?If you had read the document you would have > >> seen others. ?I actually have several complaints about YAML, but I > >> tried to write a cogent summary. > > Yaml sucks, but seems to have gotten some traction regardless. > > Therefore the Python principle of "there should be one and only one > > obvious way to do it" says: don't try to replace the existing thing if > > your new thing is only slightly better. ? > > With all due respect, Paul, and with thanks for all the help you've > given me, I have to disagree here: this is a really, really complicated > matter and I think there is a case even for making things slightly better. > > I think this is a matter of "investment period", so to speak: is it > short or long? In short term, it absolutely makes no sense to produce > even slight improvement. > > But in the long run it will almost certainly pay off to switch to smth > even somewhat better implementation (say, imaginary "20%" if you get my > drift): suppose we stay with sucky format for 10 years. Wouldn't it make > sense to implement a new one and be "in red" in terms of effort expended > versus saved for 3 years, but then be "in black" for the following 7 years? > I think ten years is about the right horizon to be looking down. Anything further than ten years is probably so speculative as to have lots of diminishing returns, although I admire people who have really BIG ideas and are starting on them now. (The particular context of this thread doesn't lead to big ideas, unless I just lack imagination.) I think it's wrong, though, only to look five years ahead. If the only goal was to make software development easier in 2015, then I'd say, by all means, let's pick the current best-of-breed tools and simply perfect them as much as we can. This is a worthwhile goal regardless of your ultimate time horizon, and that effort tends to happen anyway, since so many people rightly live in the here and now. Somewhere in the 2020s, though, I predict that a lot of technologies are either going to finally die off, or at least be restricted to the niches that they serve well. Take Java, for example. I think it will be still be used, and people will still even be writing new programs in it, but it will be rightly scorned in a lot of places where it is now embraced. Some of this won't actually be due to technological advances, but just changes in perception. For example, I predict lots of programs that people now write in Java will be written in Python, even if the core language of Python remains fairly stable. Beyond just changing mindsets, though, I think evolution is inevitable. Some subset of Python tools will almost certainly develop features that are more friendly to the Java mindset, but work in Python, and this will help move folks from Java to Python. I also think that Java will be supplanted for lots of use cases by some languages invented after 2000. Maybe Scala will become more mainstream. Maybe Go will turn into more of an enterprise-y platform. Who knows? With regard to XML, I think at a bare minimum, folks will stop using XML for use cases that YAML, JSON, and maybe even RSON serve better today. I bet that at least one of YAML and JSON survives in some form, and my money is on JSON, but I bet there will also be some new competing formats. I also think that we'll still have multiple formats that are only marginally better than each other for general use cases, but which people will still choose for specific reasons. Developers *love* good tools almost as much as they hate confusion-- there will always be tension between having too many choices and not enough. Going back to Paul's statement, I agree that "there should be one and only one obvious way to do it" in Python, but I don't think the philosophy applies to the greater ecosystem of software development. In our generation I think we have the live with the confusion and chaos that comes from a plethora of tools, and that's just part of progress. Ironically, I think the tools that survive will be very focused in their own right; it's just that we'll still have many to choose from. Going back to XML, I found myself using it last night for a completely inappropriate use case. It so happens that it would have been about 100% better if it had simply been written in JSON, so there was no compelling need for yet another alternative. But if the inventers of JSON had been complacent about XML, we wouldn't even have that as an option. And, of course, there is nothing radical at all about JSON--I am pretty sure it was just a common sense realization about the inadequacies of current technologies that led to its development, and I'm sure early versions of it were pretty raw. Without having looked into RSON, I am sure it's the same mindset that drives its invention-- current tools exist that can get the some done, but we can do better. Whether RSON is really an improvement or not is an orthogonal issue to whether we should strive for improvement. From michaelveloz at gmail.com Wed Mar 3 11:39:18 2010 From: michaelveloz at gmail.com (Veloz) Date: Wed, 3 Mar 2010 08:39:18 -0800 (PST) Subject: When to lock data items returned by multiprocessing.Manager? Message-ID: <4428d674-7fa7-4095-a93d-75ea31a81d9a@15g2000yqi.googlegroups.com> So I'm using a multiprocessing.Manager instance in my main app and asking it to create a dictionary, which I am providing to instances of the application that I'm forking off with Process. The Processes and main app will be reading/writing to the dictionary. It's not clear to me what I have to "lock" and what I don't have to lock. Any ideas? I'm thinking that what Manager brings to the table is the ability to share the dictionary but it may not provide anything to control concurrent access to it, and thus I should lock all operations I perform on it.. But I don't know this for a fact. Any input is welcomed on this!! Michael From thudfoo at opensuse.us Wed Mar 3 11:43:24 2010 From: thudfoo at opensuse.us (member thudfoo) Date: Wed, 3 Mar 2010 08:43:24 -0800 Subject: Writing an assembler in Python In-Reply-To: <7v6el6F1ddU1@mid.individual.net> References: <7v6el6F1ddU1@mid.individual.net> Message-ID: <3d881a311003030843x14217f0aua4005dbe58caf630@mail.gmail.com> On Tue, Mar 2, 2010 at 10:52 PM, Gregory Ewing wrote: >> In article , >> Giorgos Tzampanakis ? wrote: >> >>> I'm implementing a CPU that will run on an FPGA. I want to have a >>> (dead) simple assembler that will generate the machine code for >>> me. I want to use Python for that. Are there any libraries that >>> can help me with the parsing of the assembly code? > > I wrote a PIC assembler in Python once. I didn't bother > with any parsing libraries. I used a regular expression > to split the input into tokens, then wrote ad-hoc > parsing code in Python. > > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > I used Plex. The lexer is here: http://pastebin.com/9Rm4rDfu The target for the assembler is a toy single-byte processor. From darcy at druid.net Wed Mar 3 11:46:03 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 11:46:03 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <20100303114603.7021e9ba.darcy@druid.net> On Wed, 3 Mar 2010 15:05:54 +0000 (UTC) Grant Edwards wrote: > > It was actually an improvement over CP/M's file > > system. CP/M didn't have hierarchical directories > > Neither did the original MS-DOS filesystem. I think that it always had a hierarchical file system although I am not sure about 86-DOS or QDOS on which is was based. > > or timestamps and recorded file sizes in 128-byte blocks > > rather than bytes. > > I thought that was true of the original MS-DOS filesystem as > well, but I wouldn't bet money on it. And that is why text files in MS-DOS and CP/M before it end with ^Z. They needed a way to tell where the end of the information was. Why they used ^Z (SUB - Substitute) instead of ^C (ETX - End of TeXt) or even ^D (EOT - End Of Transmission) is anyone's guess. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From robert.kern at gmail.com Wed Mar 3 12:00:04 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 11:00:04 -0600 Subject: A "scopeguard" for Python In-Reply-To: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 09:39 AM, Mike Kent wrote: > What's the compelling use case for this vs. a simple try/finally? > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup A custom-written context manager looks nicer and can be more readable. from contextlib import contextmanager import os @contextmanager def pushd(path): original_dir = os.getcwd() os.chdir(path) try: yield finally: os.chdir(original_dir) with pushd(somewhere): ... I don't think a general purpose ScopeGuard context manager has any such benefits over the try: finally:, though. -- 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 From jjposner at optimum.net Wed Mar 3 12:02:10 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 12:02:10 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8e84d2$0$10157$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e84d2$0$10157$426a74cc@news.free.fr> Message-ID: On 3/3/2010 10:48 AM, Bruno Desthuilliers wrote: > > I spotted this: > > http://www.python.org/doc/faq/programming/#what-is-a-method > http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls > > > Our text is probably a bit too long for a direct inclusion in the FAQ, > so I'd say it should go in the AdvancedTopics, and be linked from the FAQ. Linking from the FAQ means changing the official Python documentation, which requires lots of hoop-jumping-through. I suggest that we content ourselves with using the Wiki -- at least for now. > > Thanks for doing the grunt work. Pas de quoi. -John From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 3 12:03:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 18:03:37 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> Message-ID: <4b8e9660$0$21812$426a34cc@news.free.fr> John Posner a ?crit : > On 3/3/2010 9:58 AM, John Posner wrote: > >> Film at 11, >> John >> > > Done -- see http://wiki.python.org/moin/FromFunctionToMethod Done and well done !-) Thanks again for the good job John. PS : Do you think it could be possible to add link to this page from the relevant FAQ items ? http://www.python.org/doc/faq/programming/#what-is-a-method http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls From nagle at animats.com Wed Mar 3 12:05:44 2010 From: nagle at animats.com (John Nagle) Date: Wed, 03 Mar 2010 09:05:44 -0800 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <87r5o1v8vp.fsf@benfinney.id.au> References: <87r5o1v8vp.fsf@benfinney.id.au> Message-ID: <4b8e929d$0$1585$742ec2ed@news.sonic.net> Ben Finney wrote: > Olof Bjarnason writes: > >> Hi everybody! >> >> The "Where is CPAN for Python?" question keeps popping up, with >> answers ranging from "There is no CPAN for Python" and "We already >> have CPAN for Python" (confusing). > > Caused in no small measure by the fact that Perl people mean at least > two distinct things by ?Where is CPAN for Python??: > > * The central package registry, CPAN, with metadata in a standard > queryable format, and all registered packages redundantly mirrored and > available for installation at user-specified versions. > > We have an equivalent in PyPI, though it's incomplete since many > *registered* packages are not actually hosted *at* PyPI. CPAN is a repository. PyPi is an collection of links. CPAN has over 260 mirrors. PyPi has none. CPAN enforces standard organization on packages. PyPi does not. CPAN has quality control, with testers and a test reporting system. PyPi does not. John Nagle From emannion at gmail.com Wed Mar 3 12:05:47 2010 From: emannion at gmail.com (enda man) Date: Wed, 3 Mar 2010 09:05:47 -0800 (PST) Subject: using subprocess.Popen env parameter Message-ID: <47f5881a-a7bd-4a57-8e2d-ae27cfbf3a9a@x22g2000yqx.googlegroups.com> Hi, I want to use the env parameter to subprocess.Popen to pass in a path to a location the process needs to run, I do have a env variable already called MS_VC_PATH and I want to add to it, not set up more in the PATH variable. ///// ms_vc_path=os.environ['MS_VC_PATH'] cl_path = ms_vc_path + '\VC\bin' lib_vc_path = ms_vc_path + '\VC\lib' myenv = os.environ myenv["PATH"] = cl_path + ";" + lib_vc_path + ";" + myenv["PATH"] subprocess.Popen("midl /D \"_DEBUG\" /nologo /char signed /env win32 / Oicf /tlb \"ActivexPlugin.tlb\" /h \"ActivexPlugin_i.h\" /iid \"ActivexPlugin_i.c\" /proxy \"ActivexPlugin_p.c\" /error stub_data ActivexPlugin.idl", env=myenv) /// but it seems that midl can not see the new path I am sending to it using the env variable, am I using env correctly? here is my output: midl : command line error MIDL1005 : cannot find C preprocessor cl.exe Any help? EM From skylarking11 at gmail.com Wed Mar 3 12:06:27 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 3 Mar 2010 09:06:27 -0800 (PST) Subject: Installing Scrapy on Mac OS X 10.6 Message-ID: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> Has anyone successfully installed Scrapy ( http://scrapy.org ) on a Mac OS X machine running 10.6.x? The Documentaion says Mac OS X ships an libxml2 version too old to be used by Scrapy...But doesn't say which version of OS X.. I am wondering if the version of libxml2 is also not compatible.. From robert.kern at gmail.com Wed Mar 3 12:09:11 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 11:09:11 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: > * Mike Kent: >> What's the compelling use case for this vs. a simple try/finally? > > if you thought about it you would mean a simple "try/else". "finally" is > always executed. which is incorrect for cleanup Eh? Failed execution doesn't require cleanup? The example you gave is definitely equivalent to the try: finally: that Mike posted. The actions are always executed in your example, not just when an exception isn't raised. From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the try: finally: syntax is for. The with statement allows you to encapsulate repetitive boilerplate into context managers, but a general purpose context manager like your Cleanup class doesn't take advantage of this. -- 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 From alfps at start.no Wed Mar 3 12:09:53 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 18:09:53 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 09:39 AM, Mike Kent wrote: >> What's the compelling use case for this vs. a simple try/finally? >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup > > A custom-written context manager looks nicer and can be more readable. > > from contextlib import contextmanager > import os > > @contextmanager > def pushd(path): > original_dir = os.getcwd() > os.chdir(path) > try: > yield > finally: > os.chdir(original_dir) > > > with pushd(somewhere): > ... > > > I don't think a general purpose ScopeGuard context manager has any such > benefits over the try: finally:, though. I don't think that's a matter of opinion, since one is correct while the other is incorrect. Cheers, - ALf From invalid at invalid.invalid Wed Mar 3 12:15:02 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 17:15:02 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: On 2010-03-03, D'Arcy J.M. Cain wrote: > On Wed, 3 Mar 2010 15:05:54 +0000 (UTC) > Grant Edwards wrote: >> > It was actually an improvement over CP/M's file >> > system. CP/M didn't have hierarchical directories >> >> Neither did the original MS-DOS filesystem. > > I think that it always had a hierarchical file system The hierarchical file system wasn't introduced until MS-DOS 2.0. Versions prior to that were flat filesystem just like CP/M. >From http://en.wikipedia.org/wiki/File_Allocation_Table At the time FAT12 was introduced, DOS did not support hierarchical directories, and the maximum number of files was typically limited to a few dozen. Hierarchical directories were introduced in MS-DOS version 2.0. -- Grant Edwards grant.b.edwards Yow! I wonder if I could at ever get started in the gmail.com credit world? From alfps at start.no Wed Mar 3 12:18:44 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 18:18:44 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >> * Mike Kent: >>> What's the compelling use case for this vs. a simple try/finally? >> >> if you thought about it you would mean a simple "try/else". "finally" is >> always executed. which is incorrect for cleanup > > Eh? Failed execution doesn't require cleanup? The example you gave is > definitely equivalent to the try: finally: that Mike posted. Sorry, that's incorrect: it's not. With correct code (mine) cleanup for action A is only performed when action A succeeds. With incorrect code cleanup for action A is performed when A fails. > The actions > are always executed in your example, Sorry, that's incorrect. > [The actions are] not [executed] just when an exception isn't raised. Sorry, that's incorrect. > From your post, the scope guard technique is used "to ensure some > desired cleanup at the end of a scope, even when the scope is exited via > an exception." This is precisely what the try: finally: syntax is for. You'd have to nest it. That's ugly. And more importantly, now two people in this thread (namely you and Mike) have demonstrated that they do not grok the try functionality and manage to write incorrect code, even arguing that it's correct when informed that it's not, so it's a pretty fragile construct, like goto. > The with statement allows you to encapsulate repetitive boilerplate into > context managers, but a general purpose context manager like your > Cleanup class doesn't take advantage of this. I'm sorry but that's pretty meaningless. It's like: "A house allows you to encapsulate a lot of stinking garbage, but your house doesn't take advantage of that, it's disgustingly clean". Hello. Cheers & hth., - Alf From xahlee at gmail.com Wed Mar 3 12:36:26 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 3 Mar 2010 09:36:26 -0800 (PST) Subject: NoSQL Movement? Message-ID: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> recently i wrote a blog article on The NoSQL Movement at http://xahlee.org/comp/nosql.html i'd like to post it somewhere public to solicit opinions, but in the 20 min or so, i couldn't find a proper newsgroup, nor private list that my somewhat anti-NoSQL Movement article is fitting. So, i thought i'd post here to solicit some opinins from the programer community i know. Here's the plain text version ----------------------------- The NoSQL Movement Xah Lee, 2010-01-26 In the past few years, there's new fashionable thinking about anti relational database, now blessed with a rhyming term: NoSQL. Basically, it considers that relational database is outdated, and not ?horizontally? scalable. I'm quite dubious of these claims. According to Wikipedia Scalability article, verticle scalability means adding more resource to a single node, such as more cpu, memory. (You can easily do this by running your db server on a more powerful machine.), and ?Horizontal scalability? means adding more machines. (and indeed, this is not simple with sql databases, but again, it is the same situation with any software, not just database. To add more machines to run one single software, the software must have some sort of grid computing infrastructure built-in. This is not a problem of the software per se, it is just the way things are. It is not a problem of databases.) I'm quite old fashioned when it comes to computer technology. In order to convience me of some revolutionary new-fangled technology, i must see improvement based on math foundation. I am a expert of SQL, and believe that relational database is pretty much the gist of database with respect to math. Sure, a tight definition of relations of your data may not be necessary for many applications that simply just need store and retrieve and modify data without much concern about the relations of them. But still, that's what relational database technology do too. You just don't worry about normalizing when you design your table schema. The NoSQL movement is really about scaling movement, about adding more machines, about some so-called ?cloud computing? and services with simple interfaces. (like so many fashionable movements in the computing industry, often they are not well defined.) It is not really about anti relation designs in your data. It's more about adding features for practical need such as providing easy-to-user APIs (so you users don't have to know SQL or Schemas), ability to add more nodes, provide commercial interface services to your database, provide parallel systems that access your data. Of course, these needs are all done by any big old relational database companies such as Oracle over the years as they constantly adopt the changing industry's needs and cheaper computing power. If you need any relations in your data, you can't escape relational database model. That is just the cold truth of math. Importat data, such as used in the bank transactions, has relations. You have to have tight relational definitions and assurance of data integrity. Here's a second hand quote from Microsoft's Technical Fellow David Campbell. Source I've been doing this database stuff for over 20 years and I remember hearing that the object databases were going to wipe out the SQL databases. And then a little less than 10 years ago the XML databases were going to wipe out.... We actually ... you know... people inside Microsoft, [have said] 'let's stop working on SQL Server, let's go build a native XML store because in five years it's all going....' LOL. That's exactly my thought. Though, i'd have to have some hands on experience with one of those new database services to see what it's all about. -------------------- Amazon S3 and Dynamo Look at Structured storage. That seems to be what these nosql databases are. Most are just a key-value pair structure, or just storage of documents with no relations. I don't see how this differ from a sql database using one single table as schema. Amazon's Amazon S3 is another storage service, which uses Amazon's Dynamo (storage system), indicated by Wikipedia to be one of those NoSQL db. Looking at the S3 and Dynamo articles, it appears the db is just a Distributed hash table system, with added http access interface. So, basically, little or no relations. Again, i don't see how this is different from, say, MySQL with one single table of 2 columns, added with distributed infrastructure. (distributed database is often a integrated feature of commercial dbs, e.g. Wikipedia Oracle database article cites Oracle Real Application Clusters ) Here's a interesting quote on S3: Bucket names and keys are chosen so that objects are addressable using HTTP URLs: * http://s3.amazonaws.com/bucket/key * http://bucket.s3.amazonaws.com/key * http://bucket/key (where bucket is a DNS CNAME record pointing to bucket.s3.amazonaws.com) Because objects are accessible by unmodified HTTP clients, S3 can be used to replace significant existing (static) web hosting infrastructure. So this means, for example, i can store all my images in S3, and in my html document, the inline images are just normal img tags with normal urls. This applies to any other type of file, pdf, audio, but html too. So, S3 becomes the web host server as well as the file system. Here's Amazon's instruction on how to use it as image server. Seems quite simple: How to use Amazon S3 for hosting web pages and media files? Source -------------------- Google BigTable Another is Google's BigTable. I can't make much comment. To make a sensible comment, one must have some experience of actually implementing a database. For example, a file system is a sort of database. If i created a scheme that allows me to access my data as files in NTFS that are distributed over hundreds of PC, communicated thru http running Apache. This will let me access my files. To insert, delete, data, one can have cgi scripts on each machine. Would this be considered as a new fantastic NoNoSQL? --------------------- comments can also be posted to http://xahlee.blogspot.com/2010/01/nosql-movement.html Thanks. Xah ? http://xahlee.org/ ? From dragonx562 at googlemail.com Wed Mar 3 12:37:45 2010 From: dragonx562 at googlemail.com (luaisn haus) Date: Wed, 3 Mar 2010 09:37:45 -0800 (PST) Subject: =?ISO-8859-1?Q?kredit_haus_=2C_eigenheimzulage_einkommensgrenzen_=2C_fi?= =?ISO-8859-1?Q?nanzamt_eigenheimzulage_=2C_kredit_f=FCr_haus_kauf_=2C_kredit_auf?= =?ISO-8859-1?Q?_haus_=2C_immobilienkredit_ohne_=2C_finanzierung_eines_hauses_=2C?= Message-ID: <3b3b51d7-5963-4f78-b103-54ac7ce9f2ed@c16g2000yqd.googlegroups.com> kredit haus , eigenheimzulage einkommensgrenzen , finanzamt eigenheimzulage , kredit f?r haus kauf , kredit auf haus , immobilienkredit ohne , finanzierung eines hauses , + + +++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA IMMOBILIEN +++ + http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL + + + + kredit f?r haus kauf darlehen f?r immobilien finanzierung von immobilien hypotheken darlehen rechner zinskonditionen hypotheken hypothek zins eigenheimzulage vom staat hausfinanzierung im hausfinanzierung ?sterreich anschlussfinanzierung hypothek kredit f?r ein haus haus kaufen darlehen deutsche kreditbank f?r baufinanzierung zins f?r baufinanzierung immobilienkredit berechnung baufinanzierung lebensversicherung kreditrechner baufinanzierung zinstrend baufinanzierung eigenheimzulage beantragen k?ndigung bauspardarlehen g?nstige hypothekenkredite hypothekenkredit schweiz zinsen hausfinanzierung baufinanzierung ohne eigenkapital hartz iv eigenheimzulage eigenheimzulage 10e From affdfsdfdsfsd at b.com Wed Mar 3 12:38:19 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 03 Mar 2010 17:38:19 GMT Subject: case do problem References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <4b8e9e8b$0$1121$4fafbaef@reader3.news.tin.it> Il Wed, 03 Mar 2010 09:39:54 +0100, Peter Otten ha scritto: > Tracubik wrote: > >> hi, i've to convert from Pascal this code: > > program loop; > > function generic_condition: boolean; > begin > generic_condition := random > 0.7 > end; > > procedure loop; > var > iterations, count, m: integer; > begin > iterations := 0; > count := 0; > m := 0; > repeat > iterations := iterations+1; > (*...*) > writeln(iterations:2, count:2, m:4); > (*...*) > if generic_condition then > inc(count); > (*...*) > case count of > 1: m := 1; > 2: m := 10; > 3: m := 100 > end > until (count = 4) or (iterations = 20) > end; > > begin > loop; > writeln("That's all, folks") > end. > > Hey, I have a Pascal compiler just one apt-get away ;) > > Here's how I'd translate the above, without trying to be too clever: > > from random import random > > def generic_condition(): > return random() > 0.7 > > def loop(): > count = 0 > m = 0 > lookup = {1: 1, 2: 10, 3: 100} > for iterations in range(20): # off by one > # ... > print "%2d %1d %3d" % (iterations, count, m) # ... > if generic_condition(): > count += 1 > # ... > m = lookup.get(count, m) > if count == 4: > break > > if __name__ == "__main__": > loop() > print "That's all, folks" > > Something must be wrong with me today because I find the Pascal code > /more/ readable.. i was think the same, Pascal seem to generate a great more readable code. I'm a newbie, so my opinion is probably wrong, but i still think that don't have CASE OF and REPEAT UNTIL code block return in difficult-to- read code. > > Peter Nico From wanderer at dialup4less.com Wed Mar 3 12:39:48 2010 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 3 Mar 2010 09:39:48 -0800 (PST) Subject: Pylint Argument number differs from overridden method Message-ID: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Pylint W0221 gives the warning Argument number differs from overridden method. Why is this a problem? I'm overriding the method to add additional functionality. This def GetRays(self, angle, pt, lmbda = 0.6): """ """ angle, x, y, Rays, Power = self.ARefract(angle, pt[0], pt[1], lmbda) pt1 = (x, y) return Rays, Power, angle, pt1 def ARefract(self, angle, x, y, lmbda = 0.6): """ """ Nt = self.Mat.NtGet(lmbda) self.NtSet(Nt) angle, x, y, Rays, Power = self.Refract(angle, x, y) return angle, x, y, Rays, Power Over rides this def GetRays(self, angle, pt): """ """ angle, x, y, Rays, Power = self.Refract(angle, pt[0], pt[1]) pt1 = (x, y) return Rays, Power, angle, pt1 Thanks From gandalf at shopzeus.com Wed Mar 3 12:41:37 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Wed, 03 Mar 2010 18:41:37 +0100 Subject: Instance factory - am I doing this right? Message-ID: <4B8E9F51.1040203@shopzeus.com> This is just an interesting code pattern that I have recently used: class CacheStorage(object): """Generic cache storage class.""" @classmethod def get_factory(cls,*args,**kwargs): """Create factory for a given set of cache storage creation parameters.""" class CacheStorageFactory(cls): _construct_args = args _construct_kwargs = kwargs def __init__(self): cls.__init__(self, *self._construct_args,**self._construct_kwargs) return CacheStorageFactory Then, I can create subclasses like: class GdbmCacheStorage(CacheStorage): """Gdbm cache storage class. @param basedir: Base directory where gdbm files should be stored. @param basename: Base name for logging and creating gdbm files. """ def __init__(self,basedir,basename): ..... blablabla place initialization code here class MemoryCacheStorage(CacheStorage): """In-Memory cache storage class. Please note that keys and values are always mashal-ed. E.g. when you cache an object, it makes a deep copy. """ def __init__(self): ..... blablabla place initialization code here And the finally, I can create a factory that can create cache storage instances for storing data in gdbm in a given directory: cache_factory = GdbmCacheStorage.get_factory("~gandalf/db","test") print cache_factory # print cache_factory() OR I can create a factory that can create instances for storing data in memory: cache_factory = MemoryCacheStorage.get_factory() print cache_factory # print cache_factory() # <__main__.CacheStorageFactory object at 0x8250c6c> Now, here is my question. Am I right in doing this? Or are there better language tools to be used in Python for the same thing? This whole thing about creating factories looks a bit odd for me. Is it Pythonic enough? Thanks, Laszlo From larudwer at freenet.de Wed Mar 3 12:49:36 2010 From: larudwer at freenet.de (larudwer) Date: Wed, 3 Mar 2010 18:49:36 +0100 Subject: Multiprocessing problem References: Message-ID: Hello Matt I think the problem is here: for n in xrange(100000): outqueue.put(str(n)) <-- fill the queue with 100000 elements try: r = inqueue.get_nowait() <-- queue is still empty because processes need some time to start results.append(r) except Empty: pass <-- causing 100000 passes .... print "-" for task in tasks: outqueue.put(None) <-- put even more data in the queue ... # in the meantime the processes start to run and are trying to put data # in to the output queue. However this queue might fill up, and lock # all processes that try to write data in the already filled up queue print "joining" for task in tasks: task.join() <-- can never succeed because processes are waiting for someone reading the result queue print "joined" This example works: from Queue import Empty, Full from multiprocessing import Queue, Process from base64 import b64encode import time, random class Worker(Process): def __init__(self, inqueue, outqueue): Process.__init__(self) self.inqueue = inqueue self.outqueue = outqueue def run(self): inqueue = self.inqueue outqueue = self.outqueue c = 0 while True: arg = inqueue.get() if arg is None: break c += 1 b = b64encode(arg) outqueue.put(b) # Clean-up code goes here outqueue.put(c) class Supervisor(object): def __init__(self): pass def go(self): outqueue = Queue() inqueue = Queue() tasks = [Worker(outqueue, inqueue) for _ in xrange(4)] for task in tasks: task.start() results = [] print "*" for n in xrange(100000): outqueue.put(str(n)) print "-" for task in tasks: outqueue.put(None) print "emptying queue" try: while True: r = inqueue.get_nowait() results.append(r) except Empty: pass print "done" print len(results) print "joining" for task in tasks: task.join() print "joined" if __name__ == "__main__": s = Supervisor() s.go() From tim.wintle at teamrubber.com Wed Mar 3 12:50:02 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 03 Mar 2010 17:50:02 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: <1267638602.988.19.camel@localhost> On Wed, 2010-03-03 at 17:26 +0100, mk wrote: > > So there *may* be some evidence that joins are indeed bad in > practice. > If someone has smth specific/interesting on the subject, please post. I have found joins to cause problems in a few cases - I'm talking about relatively large tables though - roughly order 10^8 rows. I'm on Mysql normally, but that shouldn't make any difference - I've seen almost the same situation on Oracle consider this simple example: /* Table A */ CREATE TABLE TableA ( project_id BIGINT NOT NULL, cost INT, date DATETIME, PRIMARY KEY (project_id, date) ); /* Table projects */ CREATE TABLE projects ( client_id BIGINT NOT NULL, project_id BIGINT NOT NULL, INDEX(client_id) ); ... now the index on TableA has been optimised for queries against date ranges on specific project ids which should more or less be sequential (under a load of other assumptions) - but that reduces the efficiency of the query under a join with the table "projects". If you denormalise the table, and update the first index to be on (client_id, project_id, date) it can end up running far more quickly - assuming you can access the first mapping anyway - so you're still storing the first table, with stored procedures to ensure you still have correct data in all tables. I'm definitely glossing over the details - but I've definitely got situations where I've had to choose denormalisation over purity of data. Rolled-up data tables are other situations - where you know half your queries are grouping by field "A" it's sometimes a requirement to store that. Tim From mrkafk at gmail.com Wed Mar 3 12:52:41 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 18:52:41 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100303111248.7f40d659.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > Makes me want to go down to the basement and fire up the Altair. :-) Please don't, or else I fire up that univ Yugoslavian copy of VAX with Pascal compiler (where I wrote my first program) and I will start my first program of ping-pong. It was a few hundred lines but took 5 minutes to compile; "VAX" was theoretically multitasking, but when more than 3 people were trying to do smth on it simultaneously, it was basically seizing up. Regards, mk From e_d_k at yahoo.com Wed Mar 3 13:01:27 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 3 Mar 2010 10:01:27 -0800 (PST) Subject: Docstrings considered too complicated In-Reply-To: <20100303114603.7021e9ba.darcy@druid.net> Message-ID: <539252.91463.qm@web58904.mail.re1.yahoo.com> --- On Wed, 3/3/10, D'Arcy J.M. Cain wrote: > They needed a way to tell where the end of the information > was.? Why > they used ^Z (SUB - Substitute) instead of ^C (ETX - End of > TeXt) or > even ^D (EOT - End Of Transmission) is anyone's guess. That has always puzzled me to. ETX and EOT were well established, why no use one of them? I'd love to know what they were thinking. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From john at castleamber.com Wed Mar 3 13:04:39 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Mar 2010 12:04:39 -0600 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> Message-ID: <877hpt46yw.fsf@castleamber.com> John Gabriele writes: > On Mar 2, 11:58?pm, John Bokma wrote: >> Lie Ryan writes: >> > On 03/03/2010 09:47 AM, TomF wrote: >> >> [..] >> >> >> There >> >> is also a program called cpan, distributed with Perl. ?It is used for >> >> searching, downloading, installing and testing modules from the CPAN >> >> repository. ?It's far more extensive than setuptools. ?AFAIK the python >> >> community has developed nothing like it. >> >> > python have easy_install >> >> How easy is it to /remove/ something? ;-) (Last time I checked I read >> something like "manually remove the .egg"... >> > > Have a look at [pip](http://cheeseshop.python.org/pypi/pip). It should > support uninstalling packages. Thanks John. However: "Known exceptions include pure-distutils packages installed with python setup.py install" I want to remove something that I installed that way (because it's installation procedure seems to be broken; opensocial) I understand that this can't be blamed on pip, but it's odd that in this century it's still hard to install/uninstall modules :-( -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at holdenweb.com Wed Mar 3 13:14:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Mar 2010 13:14:18 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: mk wrote: > D'Arcy J.M. Cain wrote: >> I keep seeing this statement but nothing to back it up. I have created >> many apps that run on Python with a PostgreSQL database with a fully >> normalized schema and I can assure you that database joins were never >> my problem unless I made a badly constructed query or left off a >> critical index. > > I too have done that (Python/PGSQL), even adding a complicated layer of > SQLAlchemy on top of it and have not had issue with this: when I > profiled one of my apps, it turned out that it spent most of its > computation time... rendering HTML. Completely unexpected: I expected DB > to be bottleneck (although it might be that with huge datasets this > might change). > > Having said that, re evidence that joins are bad: from what I've *heard* > about Hibernate in Java from people who used it (I haven't used > Hibernate apart from "hello world"), in case of complicated object > hierarchies it supposedly generates a lot of JOINs and that supposedly > kills DB performance. > > So there *may* be some evidence that joins are indeed bad in practice. > If someone has smth specific/interesting on the subject, please post. > I suspect that this myth is propagated from the distributed database world: joining tables across two different servers can indeed be problematic from a performance point of view. However, the classic advice in database design is to start with a normalized design and then vary it only if you need to for performance reasons (which will also involve taking a hit on the coding side, especially if updates are involved). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at mrabarnett.plus.com Wed Mar 3 13:15:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 18:15:14 +0000 Subject: Docstrings considered too complicated In-Reply-To: <20100303114603.7021e9ba.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> <20100303114603.7021e9ba.darcy@druid.net> Message-ID: <4B8EA732.60408@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Wed, 3 Mar 2010 15:05:54 +0000 (UTC) > Grant Edwards wrote: >>> It was actually an improvement over CP/M's file >>> system. CP/M didn't have hierarchical directories >> Neither did the original MS-DOS filesystem. > > I think that it always had a hierarchical file system although I am not > sure about 86-DOS or QDOS on which is was based. > [snip] MS-DOS had a hierarchical file system from version 2.0. From mrkafk at gmail.com Wed Mar 3 13:20:00 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 19:20:00 +0100 Subject: Sort Big File Help In-Reply-To: <374400.23537.qm@web33805.mail.mud.yahoo.com> References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: John Filben wrote: > I am new to Python but have used many other (mostly dead) languages in > the past. I want to be able to process *.txt and *.csv files. I can > now read that and then change them as needed ? mostly just take a column > and do some if-then to create a new variable. My problem is sorting > these files: > > 1.) How do I sort file1.txt by position and write out > file1_sorted.txt; for example, if all the records are 100 bytes long and > there is a three digit id in the position 0-2; here would be some sample > data: > > a. 001JohnFilben?? > > b. 002Joe Smith?.. Use a dictionary: linedict = {} for line in f: key = line[:3] linedict[key] = line[3:] # or alternatively 'line' if you want to include key in the line anyway sortedlines = [] for key in linedict.keys().sort(): sortedlines.append(linedict[key]) (untested) This is the simplest, and probably inefficient approach. But it should work. > > 2.) How do I sort file1.csv by column name; for example, if all the > records have three column headings, ?id?, ?first_name?, ?last_name?; > here would be some sample data: > > a. Id, first_name,last_name > > b. 001,John,Filben > > c. 002,Joe, Smith This is more complicated: I would make a list of lines, where each line is a list split according to columns (like ['001', 'John', 'Filben']), and then I would sort this list using operator.itemgetter, like this: lines.sort(key = operator.itemgetter(num)) # where num is the number of column, starting with 0 of course Read up on operator.*, it's very useful. > > 3.) What about if I have millions of records and I am processing on a > laptop with a large external drive ? basically, are there space > considerations? What are the work arounds. The simplest is to use smth like SQLite: define a table, fill it up, and then do SELECT with ORDER BY. But with a million records I wouldn't worry about it, it should fit in RAM. Observe: >>> a={} >>> for i in range(1000000): ... a[i] = 'spam'*10 ... >>> sys.getsizeof(a) 25165960 So that's what, 25 MB? Although I have to note that TEMPORARY ram usage in Python process on my machine did go up to 113MB. Regards, mk From detlev at die-offenbachs.de Wed Mar 3 13:23:16 2010 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Wed, 03 Mar 2010 19:23:16 +0100 Subject: Eric4 vs Python3.1 References: Message-ID: Zhu Sha Zang wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Someone using Eric4 to program with Python3/3.1? > > What can i do, because he insist to use only Python2.6.4. You can tell it the file extension to use for Python3 files or better yet use eric5, which is the Python3 port of eric4 with enhancements. Detlev > > Att > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.14 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkuOZO4ACgkQ35zeJy7JhCjdFACfZrjVa+8O9fu/7FEPr6mVeaEg > Rm0AmgM+XtuxFH1zUnfkaphF+MgPy3pf > =MVeJ > -----END PGP SIGNATURE----- -- Detlev Offenbach detlev at die-offenbachs.de From R.Brodie at rl.ac.uk Wed Mar 3 13:29:06 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Wed, 3 Mar 2010 18:29:06 -0000 Subject: Docstrings considered too complicated References: Message-ID: "Ed Keith" wrote in message news:mailman.215.1267639293.23598.python-list at python.org... > That has always puzzled me to. ETX and EOT were well established, > why no use one of them? I'd love to know what they were thinking. It goes back to ancient PDP operating systems, so may well predate Unix, depending which exact OS was the first to use it. From python at mrabarnett.plus.com Wed Mar 3 13:34:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 18:34:51 +0000 Subject: Docstrings considered too complicated In-Reply-To: <20100303111248.7f40d659.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: <4B8EABCB.6050303@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Wed, 03 Mar 2010 14:42:00 +0000 > MRAB wrote: >> Gregory Ewing wrote: >> Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment >> display, which I had to solder together, and also make my own power >> supply. I had the extra RAM and the I/O chip, so that's 256B (including >> the memory used by the monitor) + 256B additional RAM + 128B more in the >> I/O chip. > > In case some of you youngsters think that there is a typo in the above, > no, he means a total of 640 bytes. In today's terms that would be > approx 0.0000006GB. > > Makes me want to go down to the basement and fire up the Altair. :-) > There was partial address decoding, so the blocks appeared at several different places in the address space, the blocks weren't contiguous (normal RAM at 0xFxx, extra at 0xBxx), and the external address bus was 12 bits. Not only that, I discovered that one of the bits in the extra RAM was faulty - stuck at 0 (or was it 1)? But I was still able to play Nim and Duck Shoot (after keying it in)! :-) From mrkafk at gmail.com Wed Mar 3 13:47:14 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 19:47:14 +0100 Subject: memory usage, temporary and otherwise Message-ID: Obviously, don't try this on low-memory machine: >>> a={} >>> for i in range(10000000): ... a[i]='spam'*10 ... >>> import sys >>> sys.getsizeof(a) 201326728 >>> id(a[1]) 3085643936L >>> id(a[100]) 3085713568L >>> ids={} >>> for i in range(len(a)): ... ids[id(a[i])]=True ... >>> len(ids.keys()) 10000000 Hm, apparently Python didn't spot that 'spam'*10 in a's values is really the same string, right? So sys.getsizeof returns some 200MB for this dictionary. But according to top RSS of the python process is 300MB. ps auxw says the same thing (more or less). Why the 50% overhead? (and I would swear that a couple of times RSS according to top grew to 800MB). Regards, mk From alfps at start.no Wed Mar 3 13:51:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 19:51:23 +0100 Subject: Sample code usable Tkinter listbox In-Reply-To: References: Message-ID: * Alf P. Steinbach: > In case Someone Else(TM) may need this. > > This code is just how it currently looks, what I needed for my code, so > it's not a full-fledged or even tested class. > > But it works. That code evolved a little to cover more Tk listbox quirks (thanks to Ratingrick for the "activestyle"): class UsableListbox( t.Frame ): def __init__( self, parent_widget ): t.Frame.__init__( self, parent_widget ) scrollbar = t.Scrollbar( self, orient = "vertical" ) self.lb = t.Listbox( self, exportselection = 0, activestyle = "none", selectmode = "browse", yscrollcommand = scrollbar.set ) scrollbar.config( command = self.lb.yview ) scrollbar.pack( side = "right", fill = "y" ) self.lb.pack( side = "left", fill = "both", expand = 1 ) def current_index( self ): indices = self.lb.curselection() assert( len( indices ) <= 1 ) # TODO: about multi-selection. return None if len( indices ) == 0 else int( indices[0] ) def item_at( self, i ): assert( 0 <= i < self.item_count() ) return "" if i is None else self.lb.get( i ) def current( self ): #return self.lb.get( "active" ) # Incorrect with mousing return self.item_at( self.current_index() ) def item_count( self ): return self.lb.size() def clear( self ): self.lb.delete( 0, "end" ) def append( self, item ): self.lb.insert( "end", item ) return self.item_count() - 1 def scroll_into_view( self, i ): self.lb.see( i ) def select_item( self, i ): assert( 0 <= i < self.item_count() ) old_i = self.current_index(); self.scroll_into_view( i ) if old_i is not None and old_i == i: return self.lb.selection_set( i ) if old_i is not None: self.lb.selection_clear( old_i ) def add_selection_event_handler( self, handler ): "An event handler takes one argument, a Tkinter Event" return self.lb.bind( "<>", handler ) Cheers, - Alf From robert.kern at gmail.com Wed Mar 3 13:51:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 12:51:34 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>> * Mike Kent: >>>> What's the compelling use case for this vs. a simple try/finally? >>> >>> if you thought about it you would mean a simple "try/else". "finally" is >>> always executed. which is incorrect for cleanup >> >> Eh? Failed execution doesn't require cleanup? The example you gave is >> definitely equivalent to the try: finally: that Mike posted. > > Sorry, that's incorrect: it's not. > > With correct code (mine) cleanup for action A is only performed when > action A succeeds. > > With incorrect code cleanup for action A is performed when A fails. Oh? $ cat cleanup.py class Cleanup: def __init__( self ): self._actions = [] def call( self, action ): assert( callable( action ) ) self._actions.append( action ) def __enter__( self ): return self def __exit__( self, x_type, x_value, x_traceback ): while( len( self._actions ) != 0 ): try: self._actions.pop()() except BaseException as x: raise AssertionError( "Cleanup: exception during cleanup" ) def print_(x): print x with Cleanup() as at_cleanup: at_cleanup.call(lambda: print_("Cleanup executed without an exception.")) with Cleanup() as at_cleanup: at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) raise RuntimeError() $ python cleanup.py Cleanup executed without an exception. Cleanup execute with an exception. Traceback (most recent call last): File "cleanup.py", line 28, in raise RuntimeError() RuntimeError >> The actions are always executed in your example, > > Sorry, that's incorrect. Looks like it to me. >> From your post, the scope guard technique is used "to ensure some >> desired cleanup at the end of a scope, even when the scope is exited >> via an exception." This is precisely what the try: finally: syntax is >> for. > > You'd have to nest it. That's ugly. And more importantly, now two people > in this thread (namely you and Mike) have demonstrated that they do not > grok the try functionality and manage to write incorrect code, even > arguing that it's correct when informed that it's not, so it's a pretty > fragile construct, like goto. Uh-huh. >> The with statement allows you to encapsulate repetitive boilerplate >> into context managers, but a general purpose context manager like your >> Cleanup class doesn't take advantage of this. > > I'm sorry but that's pretty meaningless. It's like: "A house allows you > to encapsulate a lot of stinking garbage, but your house doesn't take > advantage of that, it's disgustingly clean". Hello. No, I'm saying that your Cleanup class is about as ugly as the try: finally:. It just shifts the ugliness around. There is a way to use the with statement to make things look better and more readable in certain situations, namely where there is some boilerplate that you would otherwise repeat in many places using try: finally:. You can encapsulate that repetitive code into a class or a @contextmanager generator and just call the contextmanager. A generic context manager where you register callables doesn't replace any boilerplate. You still repeat all of the cleanup code everywhere. What's more, because you have to shove everything into a callable, you have significantly less flexibility than the try: finally:. I will admit that you can put the cleanup code closer to the code that needs to get cleaned up, but you pay a price for that. -- 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 From mrkafk at gmail.com Wed Mar 3 13:54:52 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 19:54:52 +0100 Subject: Generic singleton Message-ID: Hello, So I set out to write generic singleton, i.e. the one that would do a singleton with attributes of specified class. At first: class Singleton(object): instance = None def __new__(cls, impclass, *args, **kwargs): if cls.instance is None: cls.instance = impclass.__new__(impclass, *args, **kwargs) return cls.instance s1 = Singleton(dict) s2 = Singleton(dict) s1['spam']='wonderful' print s1, s2 print id(s1) == id(s2) Now, this works. But this obviously doesn't allow class of singleton to be changed, or a new singleton for another class to be created. So: class Singleton(object): instd = {} def __new__(cls, impclass, *args, **kwargs): impid = id(impclass) if not cls.instd.has_key(impid): cls.instd[impid] = impclass.__new__(impclass, *args, **kwargs) return cls.instd[impid] s1 = Singleton(dict) s2 = Singleton(dict) s1['spam']='wonderful' s3 = Singleton(list) s4 = Singleton(list) s3.append('eggs') print id(s1) == id(s2) print id(s3) == id(s4) print s1, s2, s3, s4 Questions: 1. Is this safe? That is, does every builtin class have unique id? I have found this in docs: hashable .. All of Python?s immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Well ok, hashable they're not; but apparently at least dict and list have id()? >>> id(list) 135709728 >>> id(dict) 135714560 >>> id(dict) 135714560 >>> c=dict >>> id(c) 135714560 2. Drawbacks? 3. Better/fancier way to do this? Regards, mk From python at mrabarnett.plus.com Wed Mar 3 14:09:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 19:09:18 +0000 Subject: NoSQL Movement? In-Reply-To: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <4B8EB3DE.8070003@mrabarnett.plus.com> Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > at http://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. > > So, i thought i'd post here to solicit some opinins from the programer > community i know. > [snip] Couldn't find a relevant newsgroup, so decided to inflict it on a number of others... From philip at semanchuk.com Wed Mar 3 14:15:26 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 14:15:26 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> Message-ID: <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> On Mar 3, 2010, at 11:26 AM, mk wrote: > D'Arcy J.M. Cain wrote: >> I keep seeing this statement but nothing to back it up. I have >> created >> many apps that run on Python with a PostgreSQL database with a fully >> normalized schema and I can assure you that database joins were never >> my problem unless I made a badly constructed query or left off a >> critical index. > > I too have done that (Python/PGSQL), even adding a complicated layer > of SQLAlchemy on top of it and have not had issue with this: when I > profiled one of my apps, it turned out that it spent most of its > computation time... rendering HTML. Completely unexpected: I > expected DB to be bottleneck (although it might be that with huge > datasets this might change). > > Having said that, re evidence that joins are bad: from what I've > *heard* about Hibernate in Java from people who used it (I haven't > used Hibernate apart from "hello world"), in case of complicated > object hierarchies it supposedly generates a lot of JOINs and that > supposedly kills DB performance. > > So there *may* be some evidence that joins are indeed bad in > practice. If someone has smth specific/interesting on the subject, > please post. It's an unprovable assertion, or a meaningless one depending on how one defines the terms. You could also say "there *may* be some evidence that Python lists are bad in practice". Python lists and SQL JOINs are like any part of a language or toolkit. They're good tools for solving certain classes of problems. They can also be misapplied to problems that they're not so good at. Sometimes they're a performance bottleneck, even when solving the problems for which they're best. Sometimes the best way to solve a performance bottleneck is to redesign your app/system so you don't need to solve that kind of problem anymore (hence the join-less databases). Other times, the cure is worse than the disease and you're better off throwing hardware at the problem. My $.02 Philip From mrkafk at gmail.com Wed Mar 3 14:21:29 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:21:29 +0100 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7071cfa0-0485-4192-b3ee-8e12d9f1fca2@f17g2000prh.googlegroups.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7071cfa0-0485-4192-b3ee-8e12d9f1fca2@f17g2000prh.googlegroups.com> Message-ID: Steve Howell wrote: > Somewhere in the 2020s, though, I predict that a lot of technologies > are either going to finally die off, or at least be restricted to the > niches that they serve well. Take Java, for example. I think it will > be still be used, and people will still even be writing new programs > in it, but it will be rightly scorned in a lot of places where it is > now embraced. Some of this won't actually be due to technological > advances, but just changes in perception. For example, I predict lots > of programs that people now write in Java will be written in Python, > even if the core language of Python remains fairly stable. A friend of mine, and a good Java programmer, says caustically: "Java is COBOL of the future". Where I work we develop a huge application in Websphere (IBM Java-based application server). The problems with legacy code made project manager joke "perhaps we should rewrite this in Python". Perhaps some day it will not be a joke anymore? Personally, I chose to stay away from Java, even though it would temporarily help me: the amount of time & effort it takes to master the necessary toolset is *huge*, and my scarce time is better spent elsewhere, on more productive tools, and I really, really do not want lots of my limited time to go down the drain in a few years. Take EJB for example: even its creators realized they've overdone it with EJB 2 and simplified somewhat EJB 3 and switched to annotations instead of gazillion XML formats. But still I dread the thought of having to spend so much time learning it before I can do a few lines of productive work in it. In a way it's horrible: all this gargantuan effort in a few years will be completely wasted, down the drain. All those developer hours and dollars wasted.. In a way, C wasn't as bad as Java has been: at least many of C libs, with new bindings, still live on and do work. > Going back to Paul's statement, I agree that "there should be one and > only one obvious way to do it" in Python, but I don't think the > philosophy applies to the greater ecosystem of software development. +1 Note that when it comes to bigger tools or frameworks, even in the world of Python things are not "one obvious way", e.g. Django for quick and dirty and small apps, and Pylons for big and powerful apps. There may be "one obvious way to do it" in a very, very narrow context, but when contexts widen, like, say: "what is web framework I should choose?" the answers diverge, because answer has to be variation of "it depends on your situation". > Whether RSON is really an improvement or not is an orthogonal issue to > whether we should strive for improvement. +1 Regards, mk From alfps at start.no Wed Mar 3 14:32:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 20:32:25 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>> * Mike Kent: >>>>> What's the compelling use case for this vs. a simple try/finally? >>>> >>>> if you thought about it you would mean a simple "try/else". >>>> "finally" is >>>> always executed. which is incorrect for cleanup >>> >>> Eh? Failed execution doesn't require cleanup? The example you gave is >>> definitely equivalent to the try: finally: that Mike posted. >> >> Sorry, that's incorrect: it's not. >> >> With correct code (mine) cleanup for action A is only performed when >> action A succeeds. >> >> With incorrect code cleanup for action A is performed when A fails. > > Oh? > > $ cat cleanup.py > > class Cleanup: > def __init__( self ): > self._actions = [] > > def call( self, action ): > assert( callable( action ) ) > self._actions.append( action ) > > def __enter__( self ): > return self > > def __exit__( self, x_type, x_value, x_traceback ): > while( len( self._actions ) != 0 ): > try: > self._actions.pop()() > except BaseException as x: > raise AssertionError( "Cleanup: exception during cleanup" ) > > def print_(x): > print x > > with Cleanup() as at_cleanup: > at_cleanup.call(lambda: print_("Cleanup executed without an > exception.")) > > with Cleanup() as at_cleanup: *Here* is where you should 1) Perform the action for which cleanup is needed. 2) Let it fail by raising an exception. > at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) > raise RuntimeError() With an exception raised here cleanup should of course be performed. And just in case you didn't notice: the above is not a test of the example I gave. > $ python cleanup.py > Cleanup executed without an exception. > Cleanup execute with an exception. > Traceback (most recent call last): > File "cleanup.py", line 28, in > raise RuntimeError() > RuntimeError > >>> The actions are always executed in your example, >> >> Sorry, that's incorrect. > > Looks like it to me. I'm sorry, but you're 1) not testing my example which you're claiming that you're testing, and 2) not even showing anything about your earlier statements, which were just incorrect. You're instead showing that my code works as it should for the case that you're testing, which is a bit unnecessary since I knew that, but thanks anyway. I'm not sure what that shows, except that you haven't grokked this yet. >>> From your post, the scope guard technique is used "to ensure some >>> desired cleanup at the end of a scope, even when the scope is exited >>> via an exception." This is precisely what the try: finally: syntax is >>> for. >> >> You'd have to nest it. That's ugly. And more importantly, now two people >> in this thread (namely you and Mike) have demonstrated that they do not >> grok the try functionality and manage to write incorrect code, even >> arguing that it's correct when informed that it's not, so it's a pretty >> fragile construct, like goto. > > Uh-huh. Yeah. Consider that you're now for the third time failing to grasp the concept of cleanup for a successful operation. >>> The with statement allows you to encapsulate repetitive boilerplate >>> into context managers, but a general purpose context manager like your >>> Cleanup class doesn't take advantage of this. >> >> I'm sorry but that's pretty meaningless. It's like: "A house allows you >> to encapsulate a lot of stinking garbage, but your house doesn't take >> advantage of that, it's disgustingly clean". Hello. > > No, I'm saying that your Cleanup class is about as ugly as the try: > finally:. It just shifts the ugliness around. There is a way to use the > with statement to make things look better and more readable in certain > situations, namely where there is some boilerplate that you would > otherwise repeat in many places using try: finally:. You can encapsulate > that repetitive code into a class or a @contextmanager generator and > just call the contextmanager. A generic context manager where you > register callables doesn't replace any boilerplate. You still repeat all > of the cleanup code everywhere. What's more, because you have to shove > everything into a callable, you have significantly less flexibility than > the try: finally:. Sorry, but that's meaningless again. You're repeating that my house has no garbage in it. And you complain that it would be work to add garbage to it. Why do you want that garbage? I think it's nice without it! > I will admit that you can put the cleanup code closer to the code that > needs to get cleaned up, but you pay a price for that. Yes, that's an additional point, and important. I forgot to mention it. Thanks! Cheers & hth., - Alf From bthate at gmail.com Wed Mar 3 14:33:02 2010 From: bthate at gmail.com (Bart Thate) Date: Wed, 3 Mar 2010 11:33:02 -0800 (PST) Subject: GZRBOT 0.2 BETA1 released Message-ID: <9e26a4b7-cec6-4f73-bcd2-5fe95aa8647c@y17g2000yqd.googlegroups.com> Hello World ! Welcome to the world of Active API ;] Google released their new Wave API so i quickly ported GZRBOT to the new API. Now we can finally push to waves instead of using polling. This makes pushing feeds to waves possible, and this is one of the main things GZRBOT can do. We now use pubsubhubbub service provided by superfeedr.com to fetch our RSS and Atom feeds for us and have them pushed to the bot, which we then forward to the waves that have been subscribed ( or jabber clients for that matter) This release is BETA1 which doesnt mean the code is fixed yet as BETA2,3,4 and RC1, 2, 3 etc are still ahead before 0.2 is released. So this is kind of bleeding edge and you might want to wait for 0.2.1 or so ;] If you like to play around with wave/jabber bots on GAE then this is the bot for you. Code is at the mercurial repo: hg clone http://gzrbot.googlecode.com/hg Or download the tarball at http://gzrbot.googlecode.com Basic documentation is at http://gozerbot.org/gzrdoc and i made a wave available if you want to try the bot with me or have questions and such: https://wave.google.com/wave/#restored:wave:googlewave.com!w%252B51rssVscD Hope you enjoy it ! Bart about GZRBOT: GZRBOT is a general purpose bot for wave, web and xmpp. It uses a plugin structure to provide easy programming of commands and callbacks, allowing you to implement your own "killer plugin". GZRBOT comes with some plugins provided, for example: - Hubbub plugin that uses superfeedr.com to get RSS feed pushed instead of pulling them ourselves. This lowers the load on the bot considerably. A max of 1000 feeds is for free. - Watcher plugin that let you watch waves, get notified in jabber when your waves updates. (the bots sends the updated txt) - Wave plugin that provides help with wave management. I'm working on wave cloning after say x blips, so that larger conversations can be created in google wave. UNDER DEVELOPMENT - This is mostly needed for the last plugin i want to mention and that is the gozernet plugin. The plugin allows for relaying of events between GZRBOT (Wave/Web/XMPP) and GOZERBOT (IRC/Jabber). IRC and Wave can be bridged this way. UNDER DEVELOPMENT GZRBOT is free code (BSD) and can be cloned as needed ;] note: as of 0.2 GZRBOT uses the new v2 Wave API and thus needs registration with google. From robert.kern at gmail.com Wed Mar 3 14:33:43 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 13:33:43 -0600 Subject: Pylint Argument number differs from overridden method In-Reply-To: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Message-ID: On 2010-03-03 11:39 AM, Wanderer wrote: > Pylint W0221 gives the warning > Argument number differs from overridden method. > > Why is this a problem? I'm overriding the method to add additional > functionality. There are exceptions to every guideline. Doing this could easily be a mistake, so it's one of the many things that Pylint checks for. Silence the warning if you like. -- 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 From stefan_ml at behnel.de Wed Mar 3 14:35:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Mar 2010 20:35:01 +0100 Subject: SOAP 1.2 Python client ? In-Reply-To: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: BlueBird, 03.03.2010 17:32: > I am looking for a SOAP 1.2 python client. To my surprise, it seems > that this does not exist. Does anybody know about this ? SOAP may be an overly bloated protocol, but it's certainly not black magic. It's not hard to do manually if you really need to: http://effbot.org/zone/element-soap.htm Stefan From steve at holdenweb.com Wed Mar 3 14:38:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Mar 2010 14:38:16 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: mk wrote: > D'Arcy J.M. Cain wrote: > >> Makes me want to go down to the basement and fire up the Altair. :-) > > Please don't, or else I fire up that univ Yugoslavian copy of VAX with > Pascal compiler (where I wrote my first program) and I will start my > first program of ping-pong. > > It was a few hundred lines but took 5 minutes to compile; "VAX" was > theoretically multitasking, but when more than 3 people were trying to > do smth on it simultaneously, it was basically seizing up. > > Regards, > mk > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk on a VAX 11/750. The only bitmapped display we had available was a Three Rivers PERQ, connected by a 9600bps serial line. We left it running at seven o'clock one evening, and by nine am the next day it had brought up about two thirds of the initial VM loader screen ... You tell these young kids, and they just don't believe you! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mrkafk at gmail.com Wed Mar 3 14:39:35 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:39:35 +0100 Subject: taking python enterprise level?... In-Reply-To: <1267638602.988.19.camel@localhost> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> Message-ID: Hello Tim, Pardon the questions but I haven't had the need to use denormalization yet, so: Tim Wintle wrote: > /* Table A */ > CREATE TABLE TableA ( > project_id BIGINT NOT NULL, > cost INT, > date DATETIME, > PRIMARY KEY (project_id, date) > ); > > /* Table projects */ > CREATE TABLE projects ( > client_id BIGINT NOT NULL, > project_id BIGINT NOT NULL, > INDEX(client_id) > ); > > > .... now the index on TableA has been optimised for queries against date > ranges on specific project ids which should more or less be sequential > (under a load of other assumptions) - but that reduces the efficiency of > the query under a join with the table "projects". > > If you denormalise the table, and update the first index to be on > (client_id, project_id, date) it can end up running far more quickly - IOW you basically merged the tables like follows? CREATE TABLE projects ( client_id BIGINT NOT NULL, project_id BIGINT NOT NULL, cost INT, date DATETIME, INDEX(client_id, project_id, date) ); From what you write further in the mail I conclude that you have not eliminated the first table, just made table projects look like I wrote above, right? (and used stored procedures to make sure that both tables contain the relevant data for client_id and project_id columns in both tables) Have you had some other joins on denormalized keys? i.e. in example how the join of hypothetical TableB with projects on projects.client_id behave with such big tables? (bc I assume that you obviously can't denormalize absolutely everything, so this implies the need of doing some joins on denormalized columns like client_id). > assuming you can access the first mapping anyway - ? I'm not clear on what you mean here. > so you're still > storing the first table, with stored procedures to ensure you still have > correct data in all tables. Regards, mk From mrkafk at gmail.com Wed Mar 3 14:44:08 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:44:08 +0100 Subject: Docstrings considered too complicated In-Reply-To: <539252.91463.qm@web58904.mail.re1.yahoo.com> References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: Ed Keith wrote: > --- On Wed, 3/3/10, D'Arcy J.M. Cain wrote: > >> They needed a way to tell where the end of the information >> was. Why >> they used ^Z (SUB - Substitute) instead of ^C (ETX - End of >> TeXt) or >> even ^D (EOT - End Of Transmission) is anyone's guess. > > That has always puzzled me to. ETX and EOT were well established, why no use one of them? I'd love to know what they were thinking. Probably nothing: what many people do with confronted with a problem. It reminds me of why Windows uses backslashes for path separation instead of slashes: what I've *heard*, and do not know if it's true, it's because Gates fancied using / for options switch instead of -, and to hell with established practice. Regards, mk From arnodel at googlemail.com Wed Mar 3 14:44:41 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 03 Mar 2010 19:44:41 +0000 Subject: Generic singleton References: Message-ID: mk writes: [...] > hashable > .. > All of Python?s immutable built-in objects are hashable, while no > mutable containers (such as lists or dictionaries) are. > > Well ok, hashable they're not; but apparently at least dict and list > have id()? lists and dicts are not hashable, but their types are: >>> hash(dict) 4296155808 >>> hash(list) 4296151808 So just use the type as the key to the dictionary you maintain in your singleton. But the question is what you use your singleton for. -- Arnaud From mrkafk at gmail.com Wed Mar 3 14:46:24 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 20:46:24 +0100 Subject: cpan for python? In-Reply-To: <877hpt46yw.fsf@castleamber.com> References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> <877hpt46yw.fsf@castleamber.com> Message-ID: John Bokma wrote: > I want to remove something that I installed that way (because it's > installation procedure seems to be broken; opensocial) I understand that > this can't be blamed on pip, but it's odd that in this century it's > still hard to install/uninstall modules :-( Have you looked in a file easy-install.pth in site-packages? In my experience it's enough to delete the line for package from there and delete package's egg or directory. I agree that this is kind of backward, though. Regards, mk From MLMDev at Comcast.net Wed Mar 3 14:54:04 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Wed, 3 Mar 2010 14:54:04 -0500 Subject: CGI, POST, and file uploads In-Reply-To: References: Message-ID: <67C7A291-6790-4B10-8797-D95F8AD36F9C@Comcast.net> On Mar 2, 2010, at 4:48 PM, I wrote: > Can someone tell me how to upload the contents of a (relatively > small) file using an HTML form and CGI in Python 3.1? As far as I > can tell from a half-day of experimenting, browsing, and searching > the Python issue tracker, this is broken. followed by a detailed example demonstrating the problem. Having hear no response, let me clarify that this request was preliminary to filing a bug report -- I wanted to make sure I wasn't missing something here. If nothing else, this failure should be documented rather than the 3.1 library documentation continuing to describe how to upload file contents with POST. If someone thinks there is a way to make this work in 3.1, or that it isn't a bug because CGI is hopeless (i.e., non-WSGI-compliant), or that the documentation shouldn't be changed, please respond. I'd rather have this particular discussion here than in the bug tracking system. Meanwhile, let me heartily recommend the Bottle Web Framework (http://bottle.paws.de ) for its simplicity, flexibility, and power. Very cool stuff. To make it work in Python3.1, do the following: 1. run 2to3 on bottle.py (the only file there is to download) 2. copy or move the resulting bottle.py to the site-libs directory in your Python installation's library directory 3. don't use request.GET.getone or request.POST.getone -- instead of getone, use get (the protocol changed to that of the Mapping ABC from the collections module) 4. the contents of a file will be returned inside a cgi.FieldStorage object, so you need to add '.value' after the call to get in that case From drobinow at gmail.com Wed Mar 3 14:54:27 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 3 Mar 2010 14:54:27 -0500 Subject: Docstrings considered too complicated In-Reply-To: <539252.91463.qm@web58904.mail.re1.yahoo.com> References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: <4eb0089f1003031154j78cc7d22kf18ae339fe8c686@mail.gmail.com> On Wed, Mar 3, 2010 at 1:01 PM, Ed Keith wrote: > --- On Wed, 3/3/10, D'Arcy J.M. Cain ?wrote: > >> They needed a way to tell where the end of the information >> was.? Why >> they used ^Z (SUB - Substitute) instead of ^C (ETX - End of >> TeXt) or >> even ^D (EOT - End Of Transmission) is anyone's guess. > > That has always puzzled me to. ETX and EOT were well established, why no use one of them? I'd love to know what they were thinking. There were numerous incompatible and primitive transfer protocols in those days. They probably wanted to pick something that was NOT well established so it would pass through without, for example, causing End Of Transmission. From python at mrabarnett.plus.com Wed Mar 3 14:59:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 19:59:22 +0000 Subject: Sort Big File Help In-Reply-To: References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: <4B8EBF9A.6080603@mrabarnett.plus.com> mk wrote: > John Filben wrote: >> I am new to Python but have used many other (mostly dead) languages in >> the past. I want to be able to process *.txt and *.csv files. I can >> now read that and then change them as needed ? mostly just take a >> column and do some if-then to create a new variable. My problem is >> sorting these files: >> >> 1.) How do I sort file1.txt by position and write out >> file1_sorted.txt; for example, if all the records are 100 bytes long >> and there is a three digit id in the position 0-2; here would be some >> sample data: >> >> a. 001JohnFilben?? >> >> b. 002Joe Smith?.. > > Use a dictionary: > > linedict = {} > for line in f: > key = line[:3] > linedict[key] = line[3:] # or alternatively 'line' if you want to > include key in the line anyway > > sortedlines = [] > for key in linedict.keys().sort(): > sortedlines.append(linedict[key]) > > (untested) > > This is the simplest, and probably inefficient approach. But it should > work. > [snip] Simpler would be: lines = f.readlines() lines.sort(key=lambda line: line[ : 3]) or even: lines = sorted(f.readlines(), key=lambda line: line[ : 3])) From invalid at invalid.invalid Wed Mar 3 15:02:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Mar 2010 20:02:28 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: On 2010-03-03, mk wrote: >> That has always puzzled me to. ETX and EOT were well established, why >> no use one of them? I'd love to know what they were thinking. > > Probably nothing: what many people do with confronted with a problem. > > It reminds me of why Windows uses backslashes for path separation > instead of slashes: what I've *heard*, and do not know if it's true, > it's because Gates fancied using / for options switch instead of -, > and to hell with established practice. Using / for the option switch _was_ the established practice (if you came from a DEC background the way that CP/M and DOS did). -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From benjamin.kaplan at case.edu Wed Mar 3 15:12:31 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Mar 2010 15:12:31 -0500 Subject: Installing Scrapy on Mac OS X 10.6 In-Reply-To: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> References: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> Message-ID: On Wed, Mar 3, 2010 at 12:06 PM, Sky Larking wrote: > Has anyone successfully installed Scrapy ( http://scrapy.org ) on a > Mac OS X machine running 10.6.x? The Documentaion says > Mac OS X ships an libxml2 version too old to be used by Scrapy...But > doesn't say which version of OS X.. I am wondering if the version of > libxml2 is also not compatible.. > > > -- > http://mail.python.org/mailman/listinfo/python-list > Looks like it's shipping with 2.7.3. Scrappy requires 2.6.28 so it should work but I haven't tried. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Mar 3 15:18:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 15:18:26 -0500 Subject: Re Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> References: <35e00b331003030347x30f3f2faua96a9b72814743da@mail.gmail.com> Message-ID: On 3/3/2010 6:47 AM, Oren Elrad wrote: > With that said, let me at least offer a token defense of my position. > By way of motivation, I wrote that email after copying/pasting the > following a few times around a project until I wrote it into def > SilentlyDelete() and its cousin SilentlyRmdir() > > """ code involving somefile """ > try: > ........os.remove(somefile) > except: > .......pass # The bloody search indexer has got the file and I > can't delete it. Nothing to be done. > > Certainly the parade of horribles (bad files! corrupt data! syntax > errors!) is a tad melodramatic. Either os.remove() succeeds or it > doesn't and the execution path (in the estimation of this programmer, > at least) is not at all impacted by whether it succeeds or fails. I > know with certainty at compile time what exceptions might be raised > and what the consequences of passing them are and there is no sense > pestering the user or sweating over it. Nor can I see the logic, as > was suggested, in writing "except OSError:" since (seems to me) mere > surplusage -- it neither causes a semantic difference in the way the > program runs nor provides anything useful to the reader. Suppose you misspell 'somefile' or 'remove' (or the file gets corrupted somehow -- which unfortunate can happen). Now you suppress the NameError or AttributeError, which is a mistake. Suppose someone copies your code into a context where 'os' is not imported or where 'os' is a variable (for bone type, for instance). More bad error suppression. Bare excepts seem ok for experimental, draft, or throwaway code, but somewhat dubious for production code. For anyone reading your code a few years from now, 'except OSError' would be clearer that that is all you mean to pass on. Wrapping the code in a function makes the overhead of adding 'OSError' trivial. It also makes it trivial to do something different, like adding the file to a collection to be retried later. It also reduces the points of possible corruption to one instead of many. Terry Jan Reedy From tjreedy at udel.edu Wed Mar 3 15:47:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 15:47:11 -0500 Subject: Which mock library do you prefer? In-Reply-To: References: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: On 3/3/2010 7:43 AM, Albert van der Horst wrote: >> Right, isolation is essential. But I can't decide to which extent I >> should propagate isolation. >> For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, >> author suggests that if you do unittesting you should isolate the >> smallest units of code from each other. For example, if you have a >> class: >> Class SomeClass(object): >> def method1(self): >> return 5 >> def method2(self): >> return self.method1 + 10 >> >> According to the book, if you want to test method2, you should isolate >> it from method1 and class instance('self'). >> Other books are not so strict... >> >> And what should I follow as newbie? Pretty much any test assumes that basic things other than the tested object work correctly. For instance, any test of method2 will assume that '+' works correctly. The dependency graph between methods in a class will nearly always be acyclic. So I would start with the 'leaf' methods and work up. In the above case, test method1 first and then method2. The dependence of the test of method2 on the correctness of method1 is hardly worse, to me, then its dependence on the correctness of int.__add__. It is just the the responsibility for the latter falls on the developers, and *their* suite of tests. Whenever any code test fails, there are two possibilities. The code itself is buggy, or something it depends on is buggy. I see two reasons for isolation and mock units: test resource saving (especially time) and independent development. If you are developing ClassA and someone else is developing ClassB, you might want to test ClassA even though it depends on ClassB and classB is not ready yet. This consideration is much less likely to apply to method2 versus method1 of a coherent class. My current opinions. Terry Jan Reedy From cartercc at gmail.com Wed Mar 3 15:54:53 2010 From: cartercc at gmail.com (ccc31807) Date: Wed, 3 Mar 2010 12:54:53 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: On Mar 3, 12:36?pm, Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > athttp://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. I only read the first two paragraphs of your article, so I can't respond to it. I've halfway followed the NoSQL movement. My day job is a database manager and I so SQL databases for a living, as well as Perl. I see a lot of abuse of relational databases in the Real World, as well as a lot of abuse for non-SQL alternatives, e.g., (mis)using Excel for a database. The big, enterprise database we have at work is built on IBM UniQuery, which is a non-SQL flat file database product, so I've had a lot of experience with big non-SQL database work. I've also developed a marked preference for plain text databases. For a lot of applications they are simpler, easier, and better. I've also had some experience with XML databases, and find that they are ideal for applications with 'ragged' data. As with anything else, you need to match the tool to the job. Yes, I feel that relational database technology has been much used, and much abused. However, one of my favorite applications is Postgres, and I think it's absolutely unbeatable where you have to store data and perform a large number of queries. Finally, with regard to Structured Query Language itself, I find that it's well suited to its purpose. I hand write a lot of SQL statements for various purposes, and while like any language you find it exceedingly difficult to express concepts that you can think, it mostly allows the expression of most of what you want to say. CC. From mrkafk at gmail.com Wed Mar 3 15:58:15 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 21:58:15 +0100 Subject: taking python enterprise level?... In-Reply-To: <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> Message-ID: Philip Semanchuk wrote: >> So there *may* be some evidence that joins are indeed bad in practice. >> If someone has smth specific/interesting on the subject, please post. > > It's an unprovable assertion, or a meaningless one depending on how one > defines the terms. You could also say "there *may* be some evidence that > Python lists are bad in practice". Python lists and SQL JOINs are like > any part of a language or toolkit. They're good tools for solving > certain classes of problems. They can also be misapplied to problems > that they're not so good at. Sometimes they're a performance bottleneck, > even when solving the problems for which they're best. Sometimes the > best way to solve a performance bottleneck is to redesign your > app/system so you don't need to solve that kind of problem anymore > (hence the join-less databases). Other times, the cure is worse than the > disease and you're better off throwing hardware at the problem. Look, I completely agree with what you're saying, but: that doesn't change the possibility that joins may be expensive in comparison to other SQL operations. This is the phrase I should have used perhaps; 'expensive in comparison with other SQL operations' instead of 'bad'. Example from my app, where I behaved "by the book" (I hope) and normalized my data: $ time echo "\c hrs; SELECT hosts.ip, reservation.start_date, architecture.architecture, os_kind.os_kind, os_rel.os_rel, os_version.os_version, project.project, email.email FROM hosts INNER JOIN project ON project.id = hosts.project_id INNER JOIN architecture ON hosts.architecture_id = architecture.id INNER JOIN os_kind ON os_kind.id = hosts.os_kind_id INNER JOIN os_rel ON hosts.os_rel_id = os_rel.id INNER JOIN os_version ON hosts.os_version_id = os_version.id INNER JOIN reservation_hosts ON hosts.id = reservation_hosts.host_id INNER JOIN reservation on reservation.id = reservation_hosts.reservation_id INNER JOIN email ON reservation.email_id = email.id ;" | psql > /dev/null real 0m0.099s user 0m0.015s sys 0m0.005s $ time echo "\c hrs; > SELECT hosts.ip FROM hosts; > SELECT reservation.start_date FROM reservation; > SELECT architecture.architecture FROM architecture; > SELECT os_rel.os_rel FROM os_rel; > SELECT os_version.os_version FROM os_version; > SELECT project.project FROM project; > SELECT email.email FROM email; > " | psql > /dev/null real 0m0.046s user 0m0.008s sys 0m0.004s Note: I've created indexes on those tables, both on data columns like hosts.ip and on .id columns. So yes, joins apparently are at least twice as expensive as simple selects without joins, on a small dataset. Not a drastic increase in cost, but smth definitely shows. It would be interesting to see what happens when row numbers increase to large numbers, but I have no such data. Regards, mk From arnodel at googlemail.com Wed Mar 3 15:58:39 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 03 Mar 2010 20:58:39 +0000 Subject: Sort Big File Help References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: MRAB writes: > mk wrote: >> John Filben wrote: >>> I am new to Python but have used many other (mostly dead) languages >>> in the past. I want to be able to process *.txt and *.csv files. >>> I can now read that and then change them as needed ? mostly just >>> take a column and do some if-then to create a new variable. My >>> problem is sorting these files: >>> >>> 1.) How do I sort file1.txt by position and write out >>> file1_sorted.txt; for example, if all the records are 100 bytes >>> long and there is a three digit id in the position 0-2; here would >>> be some sample data: >>> >>> a. 001JohnFilben?? >>> >>> b. 002Joe Smith?.. >> >> Use a dictionary: >> >> linedict = {} >> for line in f: >> key = line[:3] >> linedict[key] = line[3:] # or alternatively 'line' if you want >> to include key in the line anyway >> >> sortedlines = [] >> for key in linedict.keys().sort(): >> sortedlines.append(linedict[key]) >> >> (untested) >> >> This is the simplest, and probably inefficient approach. But it >> should work. >> > [snip] > Simpler would be: > > lines = f.readlines() > lines.sort(key=lambda line: line[ : 3]) > > or even: > > lines = sorted(f.readlines(), key=lambda line: line[ : 3])) Or even: lines = sorted(f) -- Arnaud From tjreedy at udel.edu Wed Mar 3 16:00:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 16:00:11 -0500 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <4b8e929d$0$1585$742ec2ed@news.sonic.net> References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: On 3/3/2010 12:05 PM, John Nagle wrote: >> We have an equivalent in PyPI, though it's incomplete since many >> *registered* packages are not actually hosted *at* PyPI. > > CPAN is a repository. PyPi is an collection of links. As Ben said, PyPI currently is also a respository and not just links to other repositories. > CPAN has over 260 mirrors. PyPi has none. A mirroring system has been or is being set up with at least a couple of mirrors for things that are hosted at PyPI. > CPAN enforces standard organization on packages. PyPi does not. > > CPAN has quality control, with testers and a test reporting system. > PyPi does not. People who are familiar with and like CPAN are free to help improve PyPI. Those of us not familiar with it may not know what we are missing, or have little idea about what works with CPAN. Terry Jan Reedy From malaclypse2 at gmail.com Wed Mar 3 16:02:02 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 3 Mar 2010 16:02:02 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <16651e81003031302s6aac798al2864c8b742d577c3@mail.gmail.com> On Wed, Mar 3, 2010 at 2:32 PM, Alf P. Steinbach wrote: > I'm not sure what that shows, except that you haven't grokked this yet. Maybe you could give us an example of how your code should be used, and how it differs from the other examples people have given? And maybe a quick example of why you would not want to clean up after a failed operation? I've been trying to follow along, and I don't get it either. I guess that makes me at least the third person that doesn't understand what you're trying to get across. -- Jerry From robert.kern at gmail.com Wed Mar 3 16:02:31 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 15:02:31 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>> * Mike Kent: >>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>> >>>>> if you thought about it you would mean a simple "try/else". >>>>> "finally" is >>>>> always executed. which is incorrect for cleanup >>>> >>>> Eh? Failed execution doesn't require cleanup? The example you gave is >>>> definitely equivalent to the try: finally: that Mike posted. >>> >>> Sorry, that's incorrect: it's not. >>> >>> With correct code (mine) cleanup for action A is only performed when >>> action A succeeds. >>> >>> With incorrect code cleanup for action A is performed when A fails. >> >> Oh? >> >> $ cat cleanup.py >> >> class Cleanup: >> def __init__( self ): >> self._actions = [] >> >> def call( self, action ): >> assert( callable( action ) ) >> self._actions.append( action ) >> >> def __enter__( self ): >> return self >> >> def __exit__( self, x_type, x_value, x_traceback ): >> while( len( self._actions ) != 0 ): >> try: >> self._actions.pop()() >> except BaseException as x: >> raise AssertionError( "Cleanup: exception during cleanup" ) >> >> def print_(x): >> print x >> >> with Cleanup() as at_cleanup: >> at_cleanup.call(lambda: print_("Cleanup executed without an exception.")) >> >> with Cleanup() as at_cleanup: > > *Here* is where you should > > 1) Perform the action for which cleanup is needed. > > 2) Let it fail by raising an exception. > > >> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >> raise RuntimeError() > > With an exception raised here cleanup should of course be performed. > > And just in case you didn't notice: the above is not a test of the > example I gave. > > >> $ python cleanup.py >> Cleanup executed without an exception. >> Cleanup execute with an exception. >> Traceback (most recent call last): >> File "cleanup.py", line 28, in >> raise RuntimeError() >> RuntimeError >> >>>> The actions are always executed in your example, >>> >>> Sorry, that's incorrect. >> >> Looks like it to me. > > I'm sorry, but you're > > 1) not testing my example which you're claiming that you're testing, and Then I would appreciate your writing a complete, runnable example that demonstrates the feature you are claiming. Because it's apparently not "ensur[ing] some desired cleanup at the end of a scope, even when the scope is exited via an exception" that you talked about in your original post. Your sketch of an example looks like mine: with Cleanup as at_cleanup: # blah blah chdir( somewhere ) at_cleanup.call( lambda: chdir( original_dir ) ) # blah blah The cleanup function gets registered immediately after the first chdir() and before the second "blah blah". Even if an exception is raised in the second "blah blah", then the cleanup function will still run. This would be equivalent to a try: finally: # blah blah #1 chdir( somewhere ) try: # blah blah #2 finally: chdir( original_dir ) and not a try: else: # blah blah #1 chdir( somewhere ) try: # blah blah #2 else: chdir( original_dir ) Now, I assumed that the behavior with respect to exceptions occurring in the first "blah blah" weren't what you were talking about because until the chdir(), there is nothing to clean up. There is no way that the example you gave translates to a try: else: as you claimed in your response to Mike Kent. > 2) not even showing anything about your earlier statements, which were > just incorrect. > > You're instead showing that my code works as it should for the case that > you're testing, which is a bit unnecessary since I knew that, but thanks > anyway. It's the case you seem to be talking about in your original post. You seem to have changed your mind about what you want to talk about. That's fine. We don't have to stick with the original topic, but I do ask you to acknowledge that you originally were talking about a feature that "ensure[s] some desired cleanup at the end of a scope, even when the scope is exited via an exception." Do you acknowledge this? > I'm not sure what that shows, except that you haven't grokked this yet. > > >>>> From your post, the scope guard technique is used "to ensure some >>>> desired cleanup at the end of a scope, even when the scope is exited >>>> via an exception." This is precisely what the try: finally: syntax is >>>> for. >>> >>> You'd have to nest it. That's ugly. And more importantly, now two people >>> in this thread (namely you and Mike) have demonstrated that they do not >>> grok the try functionality and manage to write incorrect code, even >>> arguing that it's correct when informed that it's not, so it's a pretty >>> fragile construct, like goto. >> >> Uh-huh. > > Yeah. Consider that you're now for the third time failing to grasp the > concept of cleanup for a successful operation. Oh, I do. But if I didn't want it to run on an exception, I'd just write the code without any try:s or with:s at all. # blah blah #1 chdir( somewhere ) # blah blah #2 chdir( original_dir ) >>>> The with statement allows you to encapsulate repetitive boilerplate >>>> into context managers, but a general purpose context manager like your >>>> Cleanup class doesn't take advantage of this. >>> >>> I'm sorry but that's pretty meaningless. It's like: "A house allows you >>> to encapsulate a lot of stinking garbage, but your house doesn't take >>> advantage of that, it's disgustingly clean". Hello. >> >> No, I'm saying that your Cleanup class is about as ugly as the try: >> finally:. It just shifts the ugliness around. There is a way to use >> the with statement to make things look better and more readable in >> certain situations, namely where there is some boilerplate that you >> would otherwise repeat in many places using try: finally:. You can >> encapsulate that repetitive code into a class or a @contextmanager >> generator and just call the contextmanager. A generic context manager >> where you register callables doesn't replace any boilerplate. You >> still repeat all of the cleanup code everywhere. What's more, because >> you have to shove everything into a callable, you have significantly >> less flexibility than the try: finally:. > > Sorry, but that's meaningless again. You're repeating that my house has > no garbage in it. No, I'm repeatedly saying that I think your solution stinks. I think it's ugly. I think it's restrictive. I think it does not improve on the available solutions. > And you complain that it would be work to add garbage > to it. Why do you want that garbage? I think it's nice without it! And you are entitled to that opinion. I am giving you mine. -- 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 From mrkafk at gmail.com Wed Mar 3 16:11:40 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:11:40 +0100 Subject: Generic singleton In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: > mk writes: > [...] >> hashable >> .. >> All of Python?s immutable built-in objects are hashable, while no >> mutable containers (such as lists or dictionaries) are. >> >> Well ok, hashable they're not; but apparently at least dict and list >> have id()? > > lists and dicts are not hashable, but their types are: Oh. >>>> hash(dict) > 4296155808 >>>> hash(list) > 4296151808 > > So just use the type as the key to the dictionary you maintain in your > singleton. Hmm I have tested it and it seems to work. > But the question is what you use your singleton for. Well, partly this was for sake of learning; but partially I was thinking whether singleton as such may be useful for implementing "global queue of tasks" for worker threads in a large program: instead of handing down over and over the same reference to the global queue of tasks, classes or functions could call Singleton() and be done with it. Or I could make my life simpler and use global variable. :-) I will soon need to write such program, with remote calls from pyro (most probably), many worker threads, short-running jobs and long-running jobs, etc. Regards, mk From wanderer at dialup4less.com Wed Mar 3 16:15:07 2010 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 3 Mar 2010 13:15:07 -0800 (PST) Subject: Pylint Argument number differs from overridden method References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Message-ID: <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> On Mar 3, 2:33?pm, Robert Kern wrote: > On 2010-03-03 11:39 AM, Wanderer wrote: > > > Pylint W0221 gives the warning > > Argument number differs from overridden method. > > > Why is this a problem? I'm overriding the method to add additional > > functionality. > > There are exceptions to every guideline. Doing this could easily be a mistake, > so it's one of the many things that Pylint checks for. Silence the warning if > you like. > > -- > 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 Thanks I was just wondering if I was overlooking something about inheritance. From tjreedy at udel.edu Wed Mar 3 16:17:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Mar 2010 16:17:11 -0500 Subject: Pylint Argument number differs from overridden method In-Reply-To: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> Message-ID: On 3/3/2010 12:39 PM, Wanderer wrote: > Pylint W0221 gives the warning > Argument number differs from overridden method. > > Why is this a problem? It *could* indicate a mistake. Lint programs, by definition, are nitpicky, and flag things that are possible problems even though syntactically correct. I'm overriding the method to add additional > functionality. > > This > def GetRays(self, angle, pt, lmbda = 0.6): > """ > """ > > angle, x, y, Rays, Power = self.ARefract(angle, pt[0], pt[1], > lmbda) > pt1 = (x, y) > > return Rays, Power, angle, pt1 > > > def ARefract(self, angle, x, y, lmbda = 0.6): > """ > """ > > Nt = self.Mat.NtGet(lmbda) > self.NtSet(Nt) > angle, x, y, Rays, Power = self.Refract(angle, x, y) > > return angle, x, y, Rays, Power > > > > Over rides this > > def GetRays(self, angle, pt): > """ > """ > > angle, x, y, Rays, Power = self.Refract(angle, pt[0], pt[1]) > pt1 = (x, y) > > return Rays, Power, angle, pt1 > > > Thanks From mrkafk at gmail.com Wed Mar 3 16:19:04 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:19:04 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: Steve Holden wrote: > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk > on a VAX 11/750. The only bitmapped display we had available was a Three > Rivers PERQ, connected by a 9600bps serial line. We left it running at > seven o'clock one evening, and by nine am the next day it had brought up > about two thirds of the initial VM loader screen ... > > You tell these young kids, and they just don't believe you! For the uncouth yobs, err, culturally-challenged: http://www.youtube.com/watch?v=Xe1a1wHxTyo (Four Yorkshiremen) Regards, mk From nad at acm.org Wed Mar 3 16:22:59 2010 From: nad at acm.org (Ned Deily) Date: Wed, 03 Mar 2010 13:22:59 -0800 Subject: Installing Scrapy on Mac OS X 10.6 References: <9b08574f-0410-45bc-89af-0d3cf7d21819@e7g2000yqf.googlegroups.com> Message-ID: In article <9b08574f-0410-45bc-89af-0d3cf7d21819 at e7g2000yqf.googlegroups.com>, Sky Larking wrote: > Has anyone successfully installed Scrapy ( http://scrapy.org ) on a > Mac OS X machine running 10.6.x? The Documentaion says > Mac OS X ships an libxml2 version too old to be used by Scrapy...But > doesn't say which version of OS X.. I am wondering if the version of > libxml2 is also not compatible.. A similar question came up on Stack Overflow recently: http://stackoverflow.com/questions/2353957/do-i-need-32bit-libxml2-for-py thon-on-snow-leopard/ -- Ned Deily, nad at acm.org From darcy at druid.net Wed Mar 3 16:23:14 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 16:23:14 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> Message-ID: <20100303162314.a46484cf.darcy@druid.net> On Wed, 03 Mar 2010 20:39:35 +0100 mk wrote: > > If you denormalise the table, and update the first index to be on > > (client_id, project_id, date) it can end up running far more quickly - Maybe. Don't start with denormalization. Write it properly and only consider changing if profiling suggests that that is your bottleneck. With a decent database engine and proper design it will hardly ever be. > From what you write further in the mail I conclude that you have not > eliminated the first table, just made table projects look like I wrote > above, right? (and used stored procedures to make sure that both tables > contain the relevant data for client_id and project_id columns in both > tables) Note that rather than speeding things up this could actually slow things down depending on your usage. If you do lots of updates and you have to write extra information every time then that's worse than a few extra reads, especially since read data can be cached but written data must be pushed to disk immediately in an ACID database. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From darcy at druid.net Wed Mar 3 16:29:29 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 16:29:29 -0500 Subject: Old farts playing with their toys (was: Docstrings...) In-Reply-To: <4B8EABCB.6050303@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> <4B8EABCB.6050303@mrabarnett.plus.com> Message-ID: <20100303162929.560a17d3.darcy@druid.net> On Wed, 03 Mar 2010 18:34:51 +0000 MRAB wrote: > But I was still able to play Nim and Duck Shoot (after keying it in)! Did you ever play Star Trek with sound effects? I was never able to get it to work but supposedly if you put an AM radio tuned to a specific frequency near the side with the I/O card it would generate static that was supposed to be the sound of explosions. Of course, the explosions were happening in a vaccum so maybe the silence was accurate. :-) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From bdesth.quelquechose at free.quelquepart.fr Wed Mar 3 16:34:46 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 22:34:46 +0100 Subject: Generic singleton In-Reply-To: References: Message-ID: <4b8ee36f$0$22040$426a74cc@news.free.fr> mk a ?crit : > > does every builtin class have unique id? Classes are objects. And every object *within a python process* has it's own unique id. For a definition of "unique" being "unique amongst the objects living in the process at a given time" - IOW, if an object is garbage-collected, it's id can (and will) be reused. For the record, in CPython, the id value is the address of the (virtual) memory location where the object lives (not that you could do anything of this info from within Python - no pointers here). From alfps at start.no Wed Mar 3 16:35:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 03 Mar 2010 22:35:09 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>> * Mike Kent: >>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>> >>>>>> if you thought about it you would mean a simple "try/else". >>>>>> "finally" is >>>>>> always executed. which is incorrect for cleanup >>>>> >>>>> Eh? Failed execution doesn't require cleanup? The example you gave is >>>>> definitely equivalent to the try: finally: that Mike posted. >>>> >>>> Sorry, that's incorrect: it's not. >>>> >>>> With correct code (mine) cleanup for action A is only performed when >>>> action A succeeds. >>>> >>>> With incorrect code cleanup for action A is performed when A fails. >>> >>> Oh? >>> >>> $ cat cleanup.py >>> >>> class Cleanup: >>> def __init__( self ): >>> self._actions = [] >>> >>> def call( self, action ): >>> assert( callable( action ) ) >>> self._actions.append( action ) >>> >>> def __enter__( self ): >>> return self >>> >>> def __exit__( self, x_type, x_value, x_traceback ): >>> while( len( self._actions ) != 0 ): >>> try: >>> self._actions.pop()() >>> except BaseException as x: >>> raise AssertionError( "Cleanup: exception during cleanup" ) >>> >>> def print_(x): >>> print x >>> >>> with Cleanup() as at_cleanup: >>> at_cleanup.call(lambda: print_("Cleanup executed without an >>> exception.")) >>> >>> with Cleanup() as at_cleanup: >> >> *Here* is where you should >> >> 1) Perform the action for which cleanup is needed. >> >> 2) Let it fail by raising an exception. >> >> >>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>> raise RuntimeError() >> >> With an exception raised here cleanup should of course be performed. >> >> And just in case you didn't notice: the above is not a test of the >> example I gave. >> >> >>> $ python cleanup.py >>> Cleanup executed without an exception. >>> Cleanup execute with an exception. >>> Traceback (most recent call last): >>> File "cleanup.py", line 28, in >>> raise RuntimeError() >>> RuntimeError >>> >>>>> The actions are always executed in your example, >>>> >>>> Sorry, that's incorrect. >>> >>> Looks like it to me. >> >> I'm sorry, but you're >> >> 1) not testing my example which you're claiming that you're testing, and > > Then I would appreciate your writing a complete, runnable example that > demonstrates the feature you are claiming. Because it's apparently not > "ensur[ing] some desired cleanup at the end of a scope, even when the > scope is exited via an exception" that you talked about in your original > post. > > Your sketch of an example looks like mine: > > with Cleanup as at_cleanup: > # blah blah > chdir( somewhere ) > at_cleanup.call( lambda: chdir( original_dir ) ) > # blah blah > > The cleanup function gets registered immediately after the first chdir() > and before the second "blah blah". Even if an exception is raised in the > second "blah blah", then the cleanup function will still run. This would > be equivalent to a try: finally: > > # blah blah #1 > chdir( somewhere ) > try: > # blah blah #2 > finally: > chdir( original_dir ) Yes, this is equivalent code. The try-finally that you earlier claimed was equivalent, was not. > and not a try: else: > > # blah blah #1 > chdir( somewhere ) > try: > # blah blah #2 > else: > chdir( original_dir ) This example is however meaningless except as misdirection. There are infinitely many constructs that include try-finally and try-else, that the with-Cleanup code is not equivalent to. It's dumb to show one such. Exactly what are you trying to prove here? Your earlier claims are still incorrect. > Now, I assumed that the behavior with respect to exceptions occurring in > the first "blah blah" weren't what you were talking about because until > the chdir(), there is nothing to clean up. > > There is no way that the example you gave translates to a try: else: as > you claimed in your response to Mike Kent. Of course there is. Note that Mike wrapped the action A within the 'try': original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup The 'finally' he used, shown above, yields incorrect behavior. Namely cleanup always, while 'else', in that code, can yield correct behavior /provided/ that it's coded correctly: original_dir = os.getcwd() try: os.chdir(somewhere) except Whatever: # whatever, e.g. logging raise else: try: # Do other stuff finally: os.chdir(original_dir) # Do other cleanup >> 2) not even showing anything about your earlier statements, which were >> just incorrect. >> >> You're instead showing that my code works as it should for the case that >> you're testing, which is a bit unnecessary since I knew that, but thanks >> anyway. > > It's the case you seem to be talking about in your original post. What's this "seems"? Are you unable to read that very short post? > You > seem to have changed your mind about what you want to talk about. That's > fine. And what's this claim about me changing any topic? > We don't have to stick with the original topic Why not stick with the original topic? >, but I do ask you > to acknowledge that you originally were talking about a feature that > "ensure[s] some desired cleanup at the end of a scope, even when the > scope is exited via an exception." Yes, that's what it does. Which is I why I wrote that. This should not be hard to grok. > Do you acknowledge this? This seems like pure noise, to cover up that you were sputing a lot of incorrect statements earlier. >> I'm not sure what that shows, except that you haven't grokked this yet. >> >> >>>>> From your post, the scope guard technique is used "to ensure some >>>>> desired cleanup at the end of a scope, even when the scope is exited >>>>> via an exception." This is precisely what the try: finally: syntax is >>>>> for. >>>> >>>> You'd have to nest it. That's ugly. And more importantly, now two >>>> people >>>> in this thread (namely you and Mike) have demonstrated that they do not >>>> grok the try functionality and manage to write incorrect code, even >>>> arguing that it's correct when informed that it's not, so it's a pretty >>>> fragile construct, like goto. >>> >>> Uh-huh. >> >> Yeah. Consider that you're now for the third time failing to grasp the >> concept of cleanup for a successful operation. > > Oh, I do. But if I didn't want it to run on an exception, I'd just write > the code without any try:s or with:s at all. > > # blah blah #1 > chdir( somewhere ) > # blah blah #2 > chdir( original_dir ) Yes, but what's that got to do with anything? >>>>> The with statement allows you to encapsulate repetitive boilerplate >>>>> into context managers, but a general purpose context manager like your >>>>> Cleanup class doesn't take advantage of this. >>>> >>>> I'm sorry but that's pretty meaningless. It's like: "A house allows you >>>> to encapsulate a lot of stinking garbage, but your house doesn't take >>>> advantage of that, it's disgustingly clean". Hello. >>> >>> No, I'm saying that your Cleanup class is about as ugly as the try: >>> finally:. It just shifts the ugliness around. There is a way to use >>> the with statement to make things look better and more readable in >>> certain situations, namely where there is some boilerplate that you >>> would otherwise repeat in many places using try: finally:. You can >>> encapsulate that repetitive code into a class or a @contextmanager >>> generator and just call the contextmanager. A generic context manager >>> where you register callables doesn't replace any boilerplate. You >>> still repeat all of the cleanup code everywhere. What's more, because >>> you have to shove everything into a callable, you have significantly >>> less flexibility than the try: finally:. >> >> Sorry, but that's meaningless again. You're repeating that my house has >> no garbage in it. > > No, I'm repeatedly saying that I think your solution stinks. I think > it's ugly. I think it's restrictive. I think it does not improve on the > available solutions. First you'd have to understand it, simple as it is. >> And you complain that it would be work to add garbage >> to it. Why do you want that garbage? I think it's nice without it! > > And you are entitled to that opinion. I am giving you mine. Well, I'm sorry, but while you are entitled to an opinion it's not an opinion that carries any weight: first you need to get your facts and claims straight. So far only this latest posting of yours has been free of directly incorrect statements. But you still have a lot of statements that just show total incomprehension, like your example of achieving no cleanup in the case of an exception. Cheers & hth., - Alf From darcy at druid.net Wed Mar 3 16:37:16 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 3 Mar 2010 16:37:16 -0500 Subject: DOS Follies (Was: Docstrings...) In-Reply-To: References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: <20100303163716.d54a6e5d.darcy@druid.net> On Wed, 03 Mar 2010 20:44:08 +0100 mk wrote: > It reminds me of why Windows uses backslashes for path separation > instead of slashes: what I've *heard*, and do not know if it's true, > it's because Gates fancied using / for options switch instead of -, and > to hell with established practice. That was because CP/M used slashes for options and DOS copied that. By the time hierarchy was added it was too late to change. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From e_d_k at yahoo.com Wed Mar 3 16:43:13 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Wed, 3 Mar 2010 13:43:13 -0800 (PST) Subject: Docstrings considered too complicated In-Reply-To: <4eb0089f1003031154j78cc7d22kf18ae339fe8c686@mail.gmail.com> Message-ID: <720139.74191.qm@web58902.mail.re1.yahoo.com> --- On Wed, 3/3/10, David Robinow wrote: > From: David Robinow > Subject: Re: Docstrings considered too complicated > To: python-list at python.org > Date: Wednesday, March 3, 2010, 2:54 PM > On Wed, Mar 3, 2010 at 1:01 PM, Ed > Keith > wrote: > > --- On Wed, 3/3/10, D'Arcy J.M. Cain ?wrote: > > > >> They needed a way to tell where the end of the > information > >> was.? Why > >> they used ^Z (SUB - Substitute) instead of ^C (ETX > - End of > >> TeXt) or > >> even ^D (EOT - End Of Transmission) is anyone's > guess. > > > > That has always puzzled me to. ETX and EOT were well > established, why no use one of them? I'd love to know what > they were thinking. > > There were numerous incompatible and primitive transfer > protocols in > those days. They probably wanted to pick something that was > NOT well > established so it would pass through without, for example, > causing End > Of Transmission. That makes a lot of sense. -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From python at mrabarnett.plus.com Wed Mar 3 16:45:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 03 Mar 2010 21:45:46 +0000 Subject: Old farts playing with their toys In-Reply-To: <20100303162929.560a17d3.darcy@druid.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> <4B8EABCB.6050303@mrabarnett.plus.com> <20100303162929.560a17d3.darcy@druid.net> Message-ID: <4B8ED88A.60502@mrabarnett.plus.com> D'Arcy J.M. Cain wrote: > On Wed, 03 Mar 2010 18:34:51 +0000 > MRAB wrote: >> But I was still able to play Nim and Duck Shoot (after keying it in)! > > Did you ever play Star Trek with sound effects? I was never able to > get it to work but supposedly if you put an AM radio tuned to a > specific frequency near the side with the I/O card it would generate > static that was supposed to be the sound of explosions. > > Of course, the explosions were happening in a vaccum so maybe the > silence was accurate. :-) > A computer with sound? Heresy! :-) There was some hardware that could be added to provide some sort of video output, IIRC. Aha, here it is: http://en.wikipedia.org/wiki/MK14 and also here: http://www.nvg.ntnu.no/sinclair/computers/mk14/mk14_photos.htm The top-left picture looks like it has all its chips, so is the fully-expanded version. Oh, I forgot about the red reset button! From bdesth.quelquechose at free.quelquepart.fr Wed Mar 3 16:46:08 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 22:46:08 +0100 Subject: memory usage, temporary and otherwise In-Reply-To: References: Message-ID: <4b8ee61a$0$26644$426a74cc@news.free.fr> mk a ?crit : > > Obviously, don't try this on low-memory machine: > >>>> a={} >>>> for i in range(10000000): Note that in Python 2, this will build a list of 10000000 int objects. You may want to use xrange instead... > ... a[i]='spam'*10 > ... >>>> import sys >>>> sys.getsizeof(a) > 201326728 >>>> id(a[1]) > 3085643936L >>>> id(a[100]) > 3085713568L > >>>> ids={} >>>> for i in range(len(a)): And this build yet another list of 10000000 int objects. > ... ids[id(a[i])]=True > ... >>>> len(ids.keys()) > 10000000 > > Hm, apparently Python didn't spot that 'spam'*10 in a's values is really > the same string, right? Seems not. FWIW, Python does some caching on some values of some immutable types (small ints, some strings etc), but this is implementation dependant so you shouldn't rely on it. > So sys.getsizeof returns some 200MB for this dictionary. But according > to top RSS of the python process is 300MB. ps auxw says the same thing > (more or less). > > Why the 50% overhead? (and I would swear that a couple of times RSS > according to top grew to 800MB). (overly simplified) When an object is garbage-collected, the memory is not necessarily "returned" to the system - and the system doesn't necessarily claim it back neither until it _really_ needs it. This avoid a _lot_ of possibly useless work for both the python interpreter (keeping already allocated memory costs less than immediatly returning it, just to try and allocate some more memory a couple instructions later) and the system (ditto - FWIW, how linux handles memory allocations is somewhat funny, if you ever programmed in C). HTH From mrkafk at gmail.com Wed Mar 3 16:46:53 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:46:53 +0100 Subject: Sort Big File Help In-Reply-To: References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: John, there's an error in my program, I forgot that list.sort() method doesn't return the list (it sorts in place). So it should look like: #!/usr/bin/python def sortit(fname): fo = open(fname) linedict = {} for line in fo: key = line[:3] linedict[key] = line sortedlines = [] keys = linedict.keys() keys.sort() for key in keys: sortedlines.append(linedict[key]) return sortedlines if __name__ == '__main__': sortit('testfile.txt') MRAB's solution is obviously better, provided you know about Python's lambda. Regards, mk From bdesth.quelquechose at free.quelquepart.fr Wed Mar 3 16:47:55 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 03 Mar 2010 22:47:55 +0100 Subject: memory usage, temporary and otherwise In-Reply-To: <4b8ee61a$0$26644$426a74cc@news.free.fr> References: <4b8ee61a$0$26644$426a74cc@news.free.fr> Message-ID: <4b8ee685$0$26644$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > mk a ?crit : (snip) >> So sys.getsizeof returns some 200MB for this dictionary. But according >> to top RSS of the python process is 300MB. ps auxw says the same thing >> (more or less). >> >> Why the 50% overhead? Oh, and yes - the interpreter itself, the builtins, and all imported modules also eat some space... (snip) From mrkafk at gmail.com Wed Mar 3 16:52:35 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Mar 2010 22:52:35 +0100 Subject: Sort Big File Help In-Reply-To: <4B8EBF9A.6080603@mrabarnett.plus.com> References: <374400.23537.qm@web33805.mail.mud.yahoo.com> <4B8EBF9A.6080603@mrabarnett.plus.com> Message-ID: MRAB wrote: > [snip] > Simpler would be: > > lines = f.readlines() > lines.sort(key=lambda line: line[ : 3]) > > or even: > > lines = sorted(f.readlines(), key=lambda line: line[ : 3])) Sure, but a complete newbie (I have this impression about OP) doesn't have to know about lambda. I expected my solution to be slower, but it's not (on a file with 100,000 random string lines): # time ./sort1.py real 0m0.386s user 0m0.372s sys 0m0.014s # time ./sort2.py real 0m0.303s user 0m0.286s sys 0m0.017s sort1.py: #!/usr/bin/python def sortit(fname): lines = open(fname).readlines() lines.sort(key = lambda x: x[:3]) if __name__ == '__main__': sortit('testfile.txt') sort2.py: #!/usr/bin/python def sortit(fname): fo = open(fname) linedict = {} for line in fo: key = line[:3] linedict[key] = line sortedlines = [] keys = linedict.keys() keys.sort() for key in keys: sortedlines.append(linedict[key]) return sortedlines if __name__ == '__main__': sortit('testfile.txt') Any idea why? After all, I'm "manually" doing quite a lot: allocating key in a dict, then sorting dict's keys, then iterating over keys and accessing dict value. Regards, mk From toby at telegraphics.com.au Wed Mar 3 16:55:58 2010 From: toby at telegraphics.com.au (toby) Date: Wed, 3 Mar 2010 13:55:58 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> On Mar 3, 3:54?pm, ccc31807 wrote: > On Mar 3, 12:36?pm, Xah Lee wrote: > > > recently i wrote a blog article on The NoSQL Movement > > athttp://xahlee.org/comp/nosql.html > > > i'd like to post it somewhere public to solicit opinions, but in the > > 20 min or so, i couldn't find a proper newsgroup, nor private list > > that my somewhat anti-NoSQL Movement article is fitting. > > I only read the first two paragraphs of your article, so I can't > respond to it. > > I've halfway followed the NoSQL movement. My day job is a database > manager and I so SQL databases for a living, as well as Perl. I see a > lot of abuse of relational databases in the Real World, as well as a > lot of abuse for non-SQL alternatives, e.g., (mis)using Excel for a > database. The big, enterprise database we have at work is built on IBM > UniQuery, which is a non-SQL flat file database product, so I've had a > lot of experience with big non-SQL database work. > > I've also developed a marked preference for plain text databases. For > a lot of applications they are simpler, easier, and better. I've also > had some experience with XML databases, and find that they are ideal > for applications with 'ragged' data. > > As with anything else, you need to match the tool to the job. Yes, I > feel that relational database technology has been much used, and much > abused. However, one of my favorite applications is Postgres, and I > think it's absolutely unbeatable It is beatable outside of its sweetspot, like any system. NoSQL is not so much about "beating" relational databases, as simply a blanket term for useful non-relational technologies. There's not much point in reading Xah beyond the heading of his manifesto, as it is no more relevant to be "anti-NoSQL" as to be "anti-integers" because they don't store fractions. > where you have to store data and "relational data" > perform a large number of queries. Why does the number matter? > > Finally, with regard to Structured Query Language itself, I find that > it's well suited to its purpose. I hand write a lot of SQL statements > for various purposes, and while like any language you find it > exceedingly difficult to express concepts that you can think, it > mostly allows the expression of most of what you want to say. > > CC. From usenot at geekmail.INVALID Wed Mar 3 16:58:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 3 Mar 2010 22:58:40 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: <20100303225840.21bd3108@geekmail.INVALID> On Wed, 03 Mar 2010 22:19:04 +0100 mk wrote: > For the uncouth yobs, err, culturally-challenged: > > http://www.youtube.com/watch?v=Xe1a1wHxTyo > > (Four Yorkshiremen) > http://www.youtube.com/watch?v=-eDaSvRO9xA That's the definitive version. I mean, if you're going to talk vintage, talk vintage. /W -- INVALID? DE! From vinay_sajip at yahoo.co.uk Wed Mar 3 16:59:25 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 3 Mar 2010 13:59:25 -0800 (PST) Subject: Version 0.3.8 of the Python config module has been released. Message-ID: <9cc4c234-2c60-4f4e-b059-d8448ea8b8b4@d27g2000yqf.googlegroups.com> Version 0.3.8 of the Python config module has been released. What Does It Do? ================ The config module allows you to implement a hierarchical configuration scheme with support for mappings and sequences, cross-references between one part of the configuration and another, the ability to flexibly access real Python objects, facilities for configurations to include and cross-reference one another, simple expression evaluation and the ability to change, save, cascade and merge configurations. You can easily integrate with command line options using optparse. This module has been developed on python 2.3 but should work on version 2.2 or greater. A test suite using unittest is included in the distribution. A very simple configuration file (simple.cfg): # starts here message: Hello, world! #ends here a very simple program to use it: from config import Config cfg = Config(file('simple.cfg')) print cfg.message results in: Hello, world! Configuration files are key-value pairs, but the values can be containers that contain further values. A simple example - with the example configuration file: messages: [ { stream : `sys.stderr` message: 'Welcome' name: 'Harry' } { stream : `sys.stdout` message: 'Welkom' name: 'Ruud' } { stream : $messages[0].stream message: 'Bienvenue' name: Yves } ] a program to read the configuration would be: from config import Config f = file('simple.cfg') cfg = Config(f) for m in cfg.messages: s = '%s, %s' % (m.message, m.name) try: print >> m.stream, s except IOError, e: print e which, when run, would yield the console output: Welcome, Harry Welkom, Ruud Bienvenue, Yves The above example just scratches the surface. There's more information about this module available at http://www.red-dove.com/config-doc/ Comprehensive API documentation is available at http://www.red-dove.com/config/index.html As always, your feedback is most welcome (especially bug reports, patches and suggestions for improvement). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. Changes since the last release posted on comp.lang.python[.announce]: ===================================================== Fixed parsing bug which caused failure for negative numbers in sequences. Improved resolution logic. From jgardner at jonathangardner.net Wed Mar 3 17:16:24 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:16:24 -0800 Subject: Sort Big File Help In-Reply-To: <374400.23537.qm@web33805.mail.mud.yahoo.com> References: <374400.23537.qm@web33805.mail.mud.yahoo.com> Message-ID: <6cc20cea1003031416l2a16a5fdl2199aa379982983e@mail.gmail.com> On Wed, Mar 3, 2010 at 8:19 AM, John Filben wrote: > I am new to Python but have used many other (mostly dead) languages in the > past.? I want to be able to process *.txt and *.csv files.? I can now read > that and then change them as needed ? mostly just take a column and do some > if-then to create a new variable.? My problem is sorting these files: > > 1.)??? How do I sort file1.txt by position and write out file1_sorted.txt; > for example, if all the records are 100 bytes long and there is a three > digit id in the position 0-2; here would be some sample data: > > a.?????? 001JohnFilben?? > > b.????? 002Joe? Smith?.. > > 2.)??? How do I sort file1.csv by column name; for example, if all the > records have three column headings, ?id?, ?first_name?, ?last_name?; ?here > would be some sample data: > > a.?????? Id, first_name,last_name > > b.????? 001,John,Filben > > c.?????? 002,Joe, Smith > > 3.)??? What about if I have millions of records and I am processing on a > laptop with a large external drive ? basically, are there space > considerations? What are the work arounds. > > Any help would be appreciated. Thank you. > You may also want to look at the GNU tools "sort" and "cut". If your job is to process files, I'd recommend tools designed to process files for the task. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Wed Mar 3 17:17:24 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:17:24 -0800 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> On Wed, Mar 3, 2010 at 1:00 PM, Terry Reedy wrote: > > People who are familiar with and like CPAN are free to help improve PyPI. > Those of us not familiar with it may not know what we are missing, or have > little idea about what works with CPAN. > CPAN also covers up some deficiencies in Perl that Python doesn't suffer from. I am sure we could do well not to replicate those features. Regardless, Python's packages are distributed in a number of ways. PyPI is only one of them. Fedora and Ubuntu are two other ways. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Wed Mar 3 17:18:00 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:18:00 -0800 Subject: Generic singleton In-Reply-To: References: Message-ID: <6cc20cea1003031418w5ad6f59ah91562243a2cc4afb@mail.gmail.com> On Wed, Mar 3, 2010 at 1:11 PM, mk wrote: > > Or I could make my life simpler and use global variable. :-) > Ding ding ding! 90% of Design Patterns is making Java suck less. Other languages don't necessarily suffer from Java's design flaws. -- Jonathan Gardner jgardner at jonathangardner.net From ben+python at benfinney.id.au Wed Mar 3 17:21:32 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 09:21:32 +1100 Subject: There should be one-- and preferably only one --obvious way to do it References: <4b8e621b@dnews.tpgi.com.au> Message-ID: <87iq9dujv7.fsf@benfinney.id.au> Lie Ryan writes: > There are lots of reason why bare-except is bad, one being is that it > makes it way too easy to ignore errors that you don't actually want to > silence; and given that bare-excepts would prevent Ctrl+C (Interrupt) > from working. Sorry, but IMHO we shouldn't make syntax sugar for bad > practices. Right. Another way I've seen this expressed is ?It should be easy to do the right thing, and awkward to do the wrong thing?. -- \ ?Everyone is entitled to their own opinions, but they are not | `\ entitled to their own facts.? ?US Senator Pat Moynihan | _o__) | Ben Finney From jgardner at jonathangardner.net Wed Mar 3 17:23:25 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 14:23:25 -0800 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <6cc20cea1003031423v4410119dh767610e78ba3eb6e@mail.gmail.com> On Wed, Mar 3, 2010 at 12:54 PM, ccc31807 wrote: > > As with anything else, you need to match the tool to the job. Yes, I > feel that relational database technology has been much used, and much > abused. However, one of my favorite applications is Postgres, and I > think it's absolutely unbeatable where you have to store data and > perform a large number of queries. > Let me elaborate on this point for those who haven't experienced this for themselves. When you are starting a new project and you don't have a definitive picture of what the data is going to look like or how it is going to be queried, SQL databases (like PostgreSQL) will help you quickly formalize and understand what your data needs to do. In this role, these databases are invaluable. I can see no comparable tool in the wild, especially not OODBMS. As you grow in scale, you may eventually reach a point where the database can't keep up with you. Either you need to partition the data across machines or you need more specialized and optimized query plans. When you reach that point, there are a number of options that don't include an SQL database. I would expect your project to move those parts of the data away from an SQL database and towards a more specific solution. I see it as a sign of maturity with sufficiently scaled software that they no longer use an SQL database to manage their data. At some point in the project's lifetime, the data is understood well enough that the general nature of the SQL database is unnecessary. -- Jonathan Gardner jgardner at jonathangardner.net From ben+python at benfinney.id.au Wed Mar 3 17:30:35 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 09:30:35 +1100 Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: <87eik1ujg4.fsf@benfinney.id.au> Terry Reedy writes: > On 3/3/2010 12:05 PM, John Nagle wrote: > > CPAN is a repository. PyPi is an collection of links. > > As Ben said, PyPI currently is also a respository and not just links > to other repositories. It's a repository with holes. Just because a package is registered is no indication that the package is available from PyPI. > > CPAN has over 260 mirrors. PyPi has none. > > A mirroring system has been or is being set up with at least a couple > of mirrors for things that are hosted at PyPI. And that caveat is a big problem. Since PyPI allows registration of packages that are not themselves hosted at PyPI (often because their license terms are too restrictive for PyPI to redistribute the work), the mirror system will miss them. So there will be package-shaped holes in the PyPI mirror, meaning that even well-specified dependencies and a reliable mirror network will not be enough to make dependencies reliably satisfiable. > > CPAN enforces standard organization on packages. PyPi does not. This is, I think, something we don't need as much in Python; there is a fundamental difference between Perl's deeply nested namespace hierarchy and Python's inherently flat hierarchy. > > CPAN has quality control, with testers and a test reporting system. > > PyPi does not. > > People who are familiar with and like CPAN are free to help improve > PyPI. Those of us not familiar with it may not know what we are > missing, or have little idea about what works with CPAN. An important first step would be to reject from PyPI any package that isn't available for automated testing on the servers. That requires, AFAICT, rejecting any package without the source package uploaded. -- \ ?Oh, I realize it's a penny here and a penny there, but look at | `\ me: I've worked myself up from nothing to a state of extreme | _o__) poverty.? ?Groucho Marx | Ben Finney From ben+python at benfinney.id.au Wed Mar 3 17:32:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 09:32:21 +1100 Subject: cpan for python? References: <2010030214473616807-tomfsessile@gmailcom> <4b8ddea4$1@dnews.tpgi.com.au> <87ljea9f20.fsf@castleamber.com> <45b1599f-a05b-4132-9e75-89a52757e71b@q21g2000yqm.googlegroups.com> <877hpt46yw.fsf@castleamber.com> Message-ID: <87aaupujd6.fsf@benfinney.id.au> John Bokma writes: > I want to remove something that I installed [with its Distutils build > system] (because it's installation procedure seems to be broken; > opensocial) I understand that this can't be blamed on pip, but it's > odd that in this century it's still hard to install/uninstall modules > :-( That's because of the last-century legacy of Distutils's design. -- \ ?Imagine a world without hypothetical situations.? ?anonymous | `\ | _o__) | Ben Finney From peter at www.pjb.com.au Wed Mar 3 17:37:02 2010 From: peter at www.pjb.com.au (Peter Billam) Date: 03 Mar 2010 22:37:02 GMT Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: On 2010-03-03, John Nagle wrote: > Ben Finney wrote: >> Olof Bjarnason writes: >>> The "Where is CPAN for Python?" question keeps popping up, with >>> answers ranging from "There is no CPAN for Python" and "We already >>> have CPAN for Python" (confusing). >> >> Caused in no small measure by the fact that Perl people mean at >> least two distinct things by ?Where is CPAN for Python??: >> * The central package registry, CPAN, with metadata in a standard >> queryable format, and all registered packages redundantly mirrored >> and available for installation at user-specified versions. >> We have an equivalent in PyPI, though it's incomplete since >> many *registered* packages are not actually hosted *at* PyPI. > > CPAN is a repository. PyPi is an collection of links. > CPAN has over 260 mirrors. PyPi has none. > CPAN enforces standard organization on packages. PyPi does not. > CPAN has quality control, with testers and a test reporting system. > PyPi does not. One important thing that CPAN does _not_ have is a formalised "I put this module up for adoption" mechanism. Debian has one, for example. It's necessary, because not having one leads to many (in the long run, all) modules becoming unmaintained and abandoned, even though they worked perfectly well and were very useful to people... It would also be nice to be able to get module download stats. A very important thing about CPAN modules is the consistent basic install method: perl Makefile.PL ; make ; make install I'm not sure if the Perl code that runs CPAN is free software... (?) Regards, (CPAN author) Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From philip at semanchuk.com Wed Mar 3 17:40:36 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 17:40:36 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> Message-ID: <0C9B223A-D32A-474C-80E3-7F912447170F@semanchuk.com> On Mar 3, 2010, at 3:58 PM, mk wrote: > Philip Semanchuk wrote: >>> So there *may* be some evidence that joins are indeed bad in >>> practice. If someone has smth specific/interesting on the subject, >>> please post. >> It's an unprovable assertion, or a meaningless one depending on how >> one defines the terms. You could also say "there *may* be some >> evidence that Python lists are bad in practice". Python lists and >> SQL JOINs are like any part of a language or toolkit. They're good >> tools for solving certain classes of problems. They can also be >> misapplied to problems that they're not so good at. Sometimes >> they're a performance bottleneck, even when solving the problems >> for which they're best. Sometimes the best way to solve a >> performance bottleneck is to redesign your app/system so you don't >> need to solve that kind of problem anymore (hence the join-less >> databases). Other times, the cure is worse than the disease and >> you're better off throwing hardware at the problem. > > Look, I completely agree with what you're saying, but: that doesn't > change the possibility that joins may be expensive in comparison to > other SQL operations. This is the phrase I should have used perhaps; > 'expensive in comparison with other SQL operations' instead of 'bad'. Well OK, but that's a very different argument. Yes, joins can be expensive. They're often still the best option, though. The first step people usually take to get away from joins is denormalization which can improve SELECT performance at the expense of slowing down INSERTs, UPDATEs, and DELETEs, not to mention complicating one's code and data model. Is that a worthwhile trade? Depends on the application. As I said, sometimes the cure is worse than the disease. Don't worry about joins until you know they're a problem. As Knuth said, premature optimization is the root of all evil. Good luck Philip PS - Looks like you're using Postgres -- excellent choice. I miss using it. From me at privacy.net Wed Mar 3 17:41:37 2010 From: me at privacy.net (Avid Fan) Date: Wed, 03 Mar 2010 22:41:37 GMT Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: Jonathan Gardner wrote: > > I see it as a sign of maturity with sufficiently scaled software that > they no longer use an SQL database to manage their data. At some point > in the project's lifetime, the data is understood well enough that the > general nature of the SQL database is unnecessary. > I am really struggling to understand this concept. Is it the normalised table structure that is in question or the query language? Could you give some sort of example of where SQL would not be the way to go. The only things I can think of a simple flat file databases. From drobinow at gmail.com Wed Mar 3 18:16:47 2010 From: drobinow at gmail.com (David Robinow) Date: Wed, 3 Mar 2010 18:16:47 -0500 Subject: Docstrings considered too complicated In-Reply-To: References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: <4eb0089f1003031516u473ce06ejb705feb85ece66a7@mail.gmail.com> On Wed, Mar 3, 2010 at 3:02 PM, Grant Edwards wrote: > On 2010-03-03, mk wrote: > >>> That has always puzzled me to. ETX and EOT were well established, why >>> no use one of them? I'd love to know what they were thinking. >> >> Probably nothing: what many people do with confronted with a problem. >> >> It reminds me of why Windows uses backslashes for path separation >> instead of slashes: what I've *heard*, and do not know if it's true, >> it's because Gates fancied using / for options switch instead of -, >> and to hell with established practice. > > Using / for the option switch _was_ the established practice (if you > came from a DEC background the way that CP/M and DOS did). Quite true. And the early DEC systems predated Unix (although not by much) From jml at mumak.net Wed Mar 3 18:25:36 2010 From: jml at mumak.net (Jonathan Lange) Date: Wed, 3 Mar 2010 23:25:36 +0000 Subject: Twisted 10.0.0 released Message-ID: On behalf of Twisted Matrix Laboratories, I am honored to announce the release of Twisted 10.0. Highlights include: * Improved documentation, including "Twisted Web in 60 seconds" * Faster Perspective Broker applications * A new Windows installer that ships without zope.interface * Twisted no longer supports Python 2.3 * Over one hundred closed tickets For more information, see the NEWS file. It's stable, backwards compatible, well tested and in every way an improvement. Download it now from: http://tmrc.mit.edu/mirror/twisted/Twisted/10.0/Twisted-10.0.0.tar.bz2 or http://tmrc.mit.edu/mirror/twisted/Twisted/10.0/Twisted-10.0.0.win32-py2.5.msi Many thanks to Jean-Paul Calderone and Chris Armstrong, whose work on release automation tools and answers to numerous questions made this possible. Thanks also to the supporters of the Twisted Software Foundation and to the many contributors for this release. jml From robert.kern at gmail.com Wed Mar 3 18:28:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Mar 2010 17:28:35 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>>> * Robert Kern: >>>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>>> * Mike Kent: >>>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>>> >>>>>>> if you thought about it you would mean a simple "try/else". >>>>>>> "finally" is >>>>>>> always executed. which is incorrect for cleanup >>>>>> >>>>>> Eh? Failed execution doesn't require cleanup? The example you gave is >>>>>> definitely equivalent to the try: finally: that Mike posted. >>>>> >>>>> Sorry, that's incorrect: it's not. >>>>> >>>>> With correct code (mine) cleanup for action A is only performed when >>>>> action A succeeds. >>>>> >>>>> With incorrect code cleanup for action A is performed when A fails. >>>> >>>> Oh? >>>> >>>> $ cat cleanup.py >>>> >>>> class Cleanup: >>>> def __init__( self ): >>>> self._actions = [] >>>> >>>> def call( self, action ): >>>> assert( callable( action ) ) >>>> self._actions.append( action ) >>>> >>>> def __enter__( self ): >>>> return self >>>> >>>> def __exit__( self, x_type, x_value, x_traceback ): >>>> while( len( self._actions ) != 0 ): >>>> try: >>>> self._actions.pop()() >>>> except BaseException as x: >>>> raise AssertionError( "Cleanup: exception during cleanup" ) >>>> >>>> def print_(x): >>>> print x >>>> >>>> with Cleanup() as at_cleanup: >>>> at_cleanup.call(lambda: print_("Cleanup executed without an >>>> exception.")) >>>> >>>> with Cleanup() as at_cleanup: >>> >>> *Here* is where you should >>> >>> 1) Perform the action for which cleanup is needed. >>> >>> 2) Let it fail by raising an exception. >>> >>> >>>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>>> raise RuntimeError() >>> >>> With an exception raised here cleanup should of course be performed. >>> >>> And just in case you didn't notice: the above is not a test of the >>> example I gave. >>> >>> >>>> $ python cleanup.py >>>> Cleanup executed without an exception. >>>> Cleanup execute with an exception. >>>> Traceback (most recent call last): >>>> File "cleanup.py", line 28, in >>>> raise RuntimeError() >>>> RuntimeError >>>> >>>>>> The actions are always executed in your example, >>>>> >>>>> Sorry, that's incorrect. >>>> >>>> Looks like it to me. >>> >>> I'm sorry, but you're >>> >>> 1) not testing my example which you're claiming that you're testing, and >> >> Then I would appreciate your writing a complete, runnable example that >> demonstrates the feature you are claiming. Because it's apparently not >> "ensur[ing] some desired cleanup at the end of a scope, even when the >> scope is exited via an exception" that you talked about in your >> original post. >> >> Your sketch of an example looks like mine: >> >> with Cleanup as at_cleanup: >> # blah blah >> chdir( somewhere ) >> at_cleanup.call( lambda: chdir( original_dir ) ) >> # blah blah >> >> The cleanup function gets registered immediately after the first >> chdir() and before the second "blah blah". Even if an exception is >> raised in the second "blah blah", then the cleanup function will still >> run. This would be equivalent to a try: finally: >> >> # blah blah #1 >> chdir( somewhere ) >> try: >> # blah blah #2 >> finally: >> chdir( original_dir ) > > Yes, this is equivalent code. > > The try-finally that you earlier claimed was equivalent, was not. Okay, but just because of the position of the chdir(), right? >> and not a try: else: >> >> # blah blah #1 >> chdir( somewhere ) >> try: >> # blah blah #2 >> else: >> chdir( original_dir ) > > This example is however meaningless except as misdirection. There are > infinitely many constructs that include try-finally and try-else, that > the with-Cleanup code is not equivalent to. It's dumb to show one such. > > Exactly what are you trying to prove here? I'm just showing you what I thought you meant when you told Mike that he should have used a try/else instead of try/finally. > Your earlier claims are still incorrect. > >> Now, I assumed that the behavior with respect to exceptions occurring >> in the first "blah blah" weren't what you were talking about because >> until the chdir(), there is nothing to clean up. >> >> There is no way that the example you gave translates to a try: else: >> as you claimed in your response to Mike Kent. > > Of course there is. > > Note that Mike wrapped the action A within the 'try': > > > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup > > > > The 'finally' he used, shown above, yields incorrect behavior. > > Namely cleanup always, while 'else', in that code, can yield correct > behavior /provided/ that it's coded correctly: > > > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > except Whatever: > # whatever, e.g. logging > raise > else: > try: > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup > Ah, okay. Now we're getting somewhere. Now, please note that you did not have any except: handling in your original example. So Mike made a try: finally: example to attempt to match the semantics of your code. When you tell him that he should 'mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup', can you understand why we might think that you were saying that try: finally: was wrong and that you were proposing that your code was equivalent to some try: except: else: suite? >>> 2) not even showing anything about your earlier statements, which were >>> just incorrect. >>> >>> You're instead showing that my code works as it should for the case that >>> you're testing, which is a bit unnecessary since I knew that, but thanks >>> anyway. >> >> It's the case you seem to be talking about in your original post. > > What's this "seems"? Are you unable to read that very short post? I say "seems" because my understandings of what you meant in your original post and your response to Mike disagreed with one another. Now I see that your later posts were talking about minor discrepancy about which errors you wanted caught by the finally: and which you didn't. I was confused because it seemed that you were saying that try: finally: was completely wrong and that "try/else" was right. It confused me and at least one other person. >> , but I do ask you to acknowledge that you originally were talking >> about a feature that "ensure[s] some desired cleanup at the end of a >> scope, even when the scope is exited via an exception." > > Yes, that's what it does. > > Which is I why I wrote that. > > This should not be hard to grok. > > >> Do you acknowledge this? > > This seems like pure noise, to cover up that you were sputing a lot of > incorrect statements earlier. No, I'm just trying to clarify what you are trying to say. The above statement did not appear to accord with your later statement: 'if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup.' It turns out that what you really meant was that it would be incorrect for cleanup to be executed when an error occurred in the chdir() itself. Now, I happen to disagree with that. There are a couple of ways to do this kind of cleanup depending on the situation. Basically, you have several different code blocks: # 1. Record original state. # 2. Modify state. # 3. Do stuff requiring the modified state. # 4. Revert to the original state. Depending on where errors are expected to occur, and how the state needs to get modified and restored, there are different ways of arranging these blocks. The one Mike showed: # 1. Record original state. try: # 2. Modify state. # 3. Do stuff requiring the modified state. finally: # 4. Revert to the original state. And the one you prefer: # 1. Record original state. # 2. Modify state. try: # 3. Do stuff requiring the modified state. finally: # 4. Revert to the original state. These differ in what happens when an error occurs in block #2, the modification of the state. In Mike's, the cleanup code runs; in yours, it doesn't. For chdir(), it really doesn't matter. Reverting to the original state is harmless whether the original chdir() succeeds or fails, and chdir() is essentially atomic so if it raises an exception, the state did not change and nothing needs to be cleaned up. However, not all block #2s are atomic. Some are going to fail partway through and need to be cleaned up even though they raised an exception. Fortunately, cleanup can frequently be written to not care whether the whole thing finished or not. Both formulations can be correct (and both work perfectly fine with the chdir() example being used). Sometimes one is better than the other, and sometimes not. You can achieve both ways with either your Cleanup class or with try: finally:. I am still of the opinion that Cleanup is not an improvement over try: finally: and has the significant ugliness of forcing cleanup code into callables. This significantly limits what you can do in your cleanup code. -- 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 From eike.welk at gmx.net Wed Mar 3 18:33:29 2010 From: eike.welk at gmx.net (Eike Welk) Date: Thu, 04 Mar 2010 00:33:29 +0100 Subject: Method / Functions - What are the differences? References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > John Posner a ?crit : >> Done -- see http://wiki.python.org/moin/FromFunctionToMethod > > Done and well done !-) > Thanks again for the good job John. I like it too, thanks to both of you! I have two small ideas for improvement: - Swap the first two paragraphs. First say what it is, and then give the motivation. - The section about the descriptor protocol is a bit difficult to understand. But judging from the official descriptor documentation, it seems to be hard to explain: The official documentation is nearly incomprehensible (IMHO). From philip at semanchuk.com Wed Mar 3 18:43:30 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 18:43:30 -0500 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> Message-ID: <882E7C2F-08E5-491A-A74C-572E37F333D1@semanchuk.com> On Mar 3, 2010, at 5:17 PM, Jonathan Gardner wrote: > On Wed, Mar 3, 2010 at 1:00 PM, Terry Reedy wrote: >> >> People who are familiar with and like CPAN are free to help improve >> PyPI. >> Those of us not familiar with it may not know what we are missing, >> or have >> little idea about what works with CPAN. >> > > > CPAN also covers up some deficiencies in Perl that Python doesn't > suffer from. I am sure we could do well not to replicate those > features. > > Regardless, Python's packages are distributed in a number of ways. > PyPI is only one of them. Fedora and Ubuntu are two other ways. Do Fedora & Ubuntu's package managers offer modules that appear in CPAN? In other words, if I was a Perl user under Ubuntu would I use the pkg manager to add a Perl module, or CPAN, or would both work? Thanks Philip From thewellsoliver at gmail.com Wed Mar 3 18:45:51 2010 From: thewellsoliver at gmail.com (Wells) Date: Wed, 3 Mar 2010 15:45:51 -0800 (PST) Subject: Question about typing: ints/floats Message-ID: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> This seems sort of odd to me: >>> a = 1 >>> a += 1.202 >>> a 2.202 Indicates that 'a' was an int that was implicitly casted to a float. But: >>> a = 1 >>> b = 3 >>> a / b 0 This does not implicitly do the casting, it treats 'a' and 'b' as integers, and the result as well. Changing 'b' to 3.0 will yield a float as a result (0.33333333333333331) Is there some way to explain the consistency here? Does python implicitly change the casting when you add variables of a different numeric type? Anyway, just curiosity more than anything else. Thanks! From zeeshan.quireshi at gmail.com Wed Mar 3 18:50:19 2010 From: zeeshan.quireshi at gmail.com (Zeeshan Quireshi) Date: Wed, 3 Mar 2010 15:50:19 -0800 (PST) Subject: Passing FILE * types using ctypes Message-ID: Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass it a FILE *pointer, how do i open a file in Python and convert it to a FILE *pointer. Or do i have to call the C library using ctypes first, get the pointer and then pass it to my function. Also, is there any automated way to convert c struct and enum definitions to ctypes data types. Zeeshan From zeeshan.quireshi at gmail.com Wed Mar 3 18:53:27 2010 From: zeeshan.quireshi at gmail.com (Zeeshan Quireshi) Date: Wed, 3 Mar 2010 15:53:27 -0800 (PST) Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Mar 3, 6:45?pm, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Does python > implicitly change the casting when you add variables of a different > numeric type? > > Anyway, just ?curiosity more than anything else. Thanks! Python, like most other languages performs only integer division when both the operands are ints. So only if one of the types is a flot or you explicitly cast your expression to be a double, then the value will be a fraction. otherwise you will the quotient. From rhodri at wildebst.demon.co.uk Wed Mar 3 18:56:00 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 03 Mar 2010 23:56:00 -0000 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: On Wed, 03 Mar 2010 19:38:16 -0000, Steve Holden wrote: > mk wrote: >> D'Arcy J.M. Cain wrote: >> >>> Makes me want to go down to the basement and fire up the Altair. :-) >> >> Please don't, or else I fire up that univ Yugoslavian copy of VAX with >> Pascal compiler (where I wrote my first program) and I will start my >> first program of ping-pong. >> >> It was a few hundred lines but took 5 minutes to compile; "VAX" was >> theoretically multitasking, but when more than 3 people were trying to >> do smth on it simultaneously, it was basically seizing up. >> >> Regards, >> mk >> > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk > on a VAX 11/750. The only bitmapped display we had available was a Three > Rivers PERQ, connected by a 9600bps serial line. We left it running at > seven o'clock one evening, and by nine am the next day it had brought up > about two thirds of the initial VM loader screen ... > > You tell these young kids, and they just don't believe you! There's old, and then there's old. http://sms.cam.ac.uk/media/739532 is a film of EDSAC being programmed in 1951, with a commentary added by Maurice Wilkes in 1976. Maybe just a bit before my time (by a decade or so :-) -- Rhodri James *-* Wildebeeste Herder to the Masses From jjposner at optimum.net Wed Mar 3 18:56:07 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 03 Mar 2010 18:56:07 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> Message-ID: <4B8EF717.3070701@optimum.net> On 3/3/2010 6:33 PM, Eike Welk wrote: > > I have two small ideas for improvement: > - Swap the first two paragraphs. First say what it is, and then give the > motivation. No problem -- since this is a Wiki, you can perform the swap yourself! (If you haven't done it in a day or so, I'll do the deed.) > - The section about the descriptor protocol is a bit difficult to > understand. But judging from the official descriptor documentation, it seems > to be hard to explain: The official documentation is nearly incomprehensible > (IMHO). I empathize -- it took me a while to grok descriptors. I was thinking today about "doing a Bruno", and producing similar pieces on: * properties created with the @property decorator * the descriptor protocol I'll try to produce something over the next couple of days. -John From jgardner at jonathangardner.net Wed Mar 3 19:10:14 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Mar 2010 16:10:14 -0800 Subject: PYTHONPATH and eggs In-Reply-To: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> References: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Message-ID: <6cc20cea1003031610i6f79fd4fndac249ba27ca44c6@mail.gmail.com> On Wed, Mar 3, 2010 at 2:14 AM, geoffbache wrote: > > I have a very simple problem that seems to have no simple solution. > > I have a module which is installed centrally and lives in a Python > egg. I have experimented with some minor changes to it and would like > to set my PYTHONPATH to pick up my local copy of it, but don't want to > have to figure out how to build my own version of the "egg" if > possible. > > Unfortunately, the location from PYTHONPATH ends up after the eggs in > sys.path so I can't persuade Python to import my version. The only way > I've found to fix it is to copy the main script and manually hack > sys.path at the start of it which isn't really very nice. I wonder if > there is any better way as I can't be the first person to want to do > this, surely? > > I've seen this issue has been discussed elsewhere and flagged as a > problem (e.g. > http://mail.python.org/pipermail/distutils-sig/2009-January/010755.html) > > but I've been unable to find any suggestions for workarounds or > indications whether this will be/has been fixed. > Sounds like you might need to use virtualenv to setup python environments that you can control. -- Jonathan Gardner jgardner at jonathangardner.net From rhodri at wildebst.demon.co.uk Wed Mar 3 19:11:26 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 04 Mar 2010 00:11:26 -0000 Subject: Interest check in some delicious syntactic sugar for "except:pass" References: Message-ID: On Wed, 03 Mar 2010 09:27:16 -0000, Oren Elrad wrote: > Howdy all, longtime appreciative user, first time mailer-inner. > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > silence: > ........ block > -------------------------> > try: > ........block > except: > ........pass -100 This catches Control-C interrupts, sys.exit(), subtle typos in the code, and sundry other errors that actually you *did* want to know about. Silence isn't so much golden as pyritic. -- Rhodri James *-* Wildebeeste Herder to the Masses From mensanator at aol.com Wed Mar 3 19:27:50 2010 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Mar 2010 16:27:50 -0800 (PST) Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Mar 3, 5:45?pm, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Not in Python 3.1: Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> a = 1 >>> b = 3 >>> a/b 0.3333333333333333 > Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Yes, use Python 3.1. > Does python > implicitly change the casting when you add variables of a different > numeric type? Sometimes. Floats and ints are compatible. But this doesn't work: >>> '3' + 1 Traceback (most recent call last): File "", line 1, in '3' + 1 TypeError: Can't convert 'int' object to str implicitly > > Anyway, just ?curiosity more than anything else. Thanks! From alfps at start.no Wed Mar 3 19:49:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 01:49:45 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>>>> * Robert Kern: >>>>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>>>> * Mike Kent: >>>>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>>>> >>>>>>>> if you thought about it you would mean a simple "try/else". >>>>>>>> "finally" is >>>>>>>> always executed. which is incorrect for cleanup >>>>>>> >>>>>>> Eh? Failed execution doesn't require cleanup? The example you >>>>>>> gave is >>>>>>> definitely equivalent to the try: finally: that Mike posted. >>>>>> >>>>>> Sorry, that's incorrect: it's not. >>>>>> >>>>>> With correct code (mine) cleanup for action A is only performed when >>>>>> action A succeeds. >>>>>> >>>>>> With incorrect code cleanup for action A is performed when A fails. >>>>> >>>>> Oh? >>>>> >>>>> $ cat cleanup.py >>>>> >>>>> class Cleanup: >>>>> def __init__( self ): >>>>> self._actions = [] >>>>> >>>>> def call( self, action ): >>>>> assert( callable( action ) ) >>>>> self._actions.append( action ) >>>>> >>>>> def __enter__( self ): >>>>> return self >>>>> >>>>> def __exit__( self, x_type, x_value, x_traceback ): >>>>> while( len( self._actions ) != 0 ): >>>>> try: >>>>> self._actions.pop()() >>>>> except BaseException as x: >>>>> raise AssertionError( "Cleanup: exception during cleanup" ) >>>>> >>>>> def print_(x): >>>>> print x >>>>> >>>>> with Cleanup() as at_cleanup: >>>>> at_cleanup.call(lambda: print_("Cleanup executed without an >>>>> exception.")) >>>>> >>>>> with Cleanup() as at_cleanup: >>>> >>>> *Here* is where you should >>>> >>>> 1) Perform the action for which cleanup is needed. >>>> >>>> 2) Let it fail by raising an exception. >>>> >>>> >>>>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>>>> raise RuntimeError() >>>> >>>> With an exception raised here cleanup should of course be performed. >>>> >>>> And just in case you didn't notice: the above is not a test of the >>>> example I gave. >>>> >>>> >>>>> $ python cleanup.py >>>>> Cleanup executed without an exception. >>>>> Cleanup execute with an exception. >>>>> Traceback (most recent call last): >>>>> File "cleanup.py", line 28, in >>>>> raise RuntimeError() >>>>> RuntimeError >>>>> >>>>>>> The actions are always executed in your example, >>>>>> >>>>>> Sorry, that's incorrect. >>>>> >>>>> Looks like it to me. >>>> >>>> I'm sorry, but you're >>>> >>>> 1) not testing my example which you're claiming that you're testing, >>>> and >>> >>> Then I would appreciate your writing a complete, runnable example that >>> demonstrates the feature you are claiming. Because it's apparently not >>> "ensur[ing] some desired cleanup at the end of a scope, even when the >>> scope is exited via an exception" that you talked about in your >>> original post. >>> >>> Your sketch of an example looks like mine: >>> >>> with Cleanup as at_cleanup: >>> # blah blah >>> chdir( somewhere ) >>> at_cleanup.call( lambda: chdir( original_dir ) ) >>> # blah blah >>> >>> The cleanup function gets registered immediately after the first >>> chdir() and before the second "blah blah". Even if an exception is >>> raised in the second "blah blah", then the cleanup function will still >>> run. This would be equivalent to a try: finally: >>> >>> # blah blah #1 >>> chdir( somewhere ) >>> try: >>> # blah blah #2 >>> finally: >>> chdir( original_dir ) >> >> Yes, this is equivalent code. >> >> The try-finally that you earlier claimed was equivalent, was not. > > Okay, but just because of the position of the chdir(), right? Yes, since it yields different results. >>> and not a try: else: >>> >>> # blah blah #1 >>> chdir( somewhere ) >>> try: >>> # blah blah #2 >>> else: >>> chdir( original_dir ) >> >> This example is however meaningless except as misdirection. There are >> infinitely many constructs that include try-finally and try-else, that >> the with-Cleanup code is not equivalent to. It's dumb to show one such. >> >> Exactly what are you trying to prove here? > > I'm just showing you what I thought you meant when you told Mike that he > should have used a try/else instead of try/finally. > >> Your earlier claims are still incorrect. >> >>> Now, I assumed that the behavior with respect to exceptions occurring >>> in the first "blah blah" weren't what you were talking about because >>> until the chdir(), there is nothing to clean up. >>> >>> There is no way that the example you gave translates to a try: else: >>> as you claimed in your response to Mike Kent. >> >> Of course there is. >> >> Note that Mike wrapped the action A within the 'try': >> >> >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup >> >> >> >> The 'finally' he used, shown above, yields incorrect behavior. >> >> Namely cleanup always, while 'else', in that code, can yield correct >> behavior /provided/ that it's coded correctly: >> >> >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> except Whatever: >> # whatever, e.g. logging >> raise >> else: >> try: >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup >> > > Ah, okay. Now we're getting somewhere. Now, please note that you did not > have any except: handling in your original example. So Mike made a try: > finally: example to attempt to match the semantics of your code. When > you tell him that he should 'mean a simple "try/else". "finally" is > always executed. which is incorrect for cleanup', can you understand why > we might think that you were saying that try: finally: was wrong and > that you were proposing that your code was equivalent to some try: > except: else: suite? No, not really. His code didn't match the semantics. Changing 'finally' to 'else' could make it equivalent. >>>> 2) not even showing anything about your earlier statements, which were >>>> just incorrect. >>>> >>>> You're instead showing that my code works as it should for the case >>>> that >>>> you're testing, which is a bit unnecessary since I knew that, but >>>> thanks >>>> anyway. >>> >>> It's the case you seem to be talking about in your original post. >> >> What's this "seems"? Are you unable to read that very short post? > > I say "seems" because my understandings of what you meant in your > original post and your response to Mike disagreed with one another. Now > I see that your later posts were talking about minor discrepancy about > which errors you wanted caught by the finally: and which you didn't. It's absolutely not a minor discrepancy whether some code is executed or not. It can have arbitrarily large effect. And from my point of view the discussion of that snippet has not been about what errors I "want" caught by the 'finally'; it's been about whether two snippets of code yield the same effect or not: Mike's code was incorrect not because it did something else, but because as code that did something else it was not an equivalent to the code that I posted. > I > was confused because it seemed that you were saying that try: finally: > was completely wrong and that "try/else" was right. It confused me and > at least one other person. > >>> , but I do ask you to acknowledge that you originally were talking >>> about a feature that "ensure[s] some desired cleanup at the end of a >>> scope, even when the scope is exited via an exception." >> >> Yes, that's what it does. >> >> Which is I why I wrote that. >> >> This should not be hard to grok. >> >> >>> Do you acknowledge this? >> >> This seems like pure noise, to cover up that you were sputing a lot of >> incorrect statements earlier. > > No, I'm just trying to clarify what you are trying to say. The above > statement did not appear to accord with your later statement: 'if you > thought about it you would mean a simple "try/else". "finally" is always > executed. which is incorrect for cleanup.' It turns out that what you > really meant was that it would be incorrect for cleanup to be executed > when an error occurred in the chdir() itself. > > Now, I happen to disagree with that. Well, I was pretty unclear, almost hint-like, sorry about that, mea culpa, but you have it slightly wrong. You wrote then "The example you gave is definitely equivalent to the try: finally: that Mike posted." And it isn't. > There are a couple of ways to do > this kind of cleanup depending on the situation. Basically, you have > several different code blocks: > > # 1. Record original state. > # 2. Modify state. > # 3. Do stuff requiring the modified state. > # 4. Revert to the original state. > > Depending on where errors are expected to occur, and how the state needs > to get modified and restored, there are different ways of arranging > these blocks. The one Mike showed: > > # 1. Record original state. > try: > # 2. Modify state. > # 3. Do stuff requiring the modified state. > finally: > # 4. Revert to the original state. > > And the one you prefer: > > # 1. Record original state. > # 2. Modify state. > try: > # 3. Do stuff requiring the modified state. > finally: > # 4. Revert to the original state. > > These differ in what happens when an error occurs in block #2, the > modification of the state. In Mike's, the cleanup code runs; in yours, > it doesn't. For chdir(), it really doesn't matter. Reverting to the > original state is harmless whether the original chdir() succeeds or > fails, and chdir() is essentially atomic so if it raises an exception, > the state did not change and nothing needs to be cleaned up. > > However, not all block #2s are atomic. Some are going to fail partway > through and need to be cleaned up even though they raised an exception. > Fortunately, cleanup can frequently be written to not care whether the > whole thing finished or not. Yeah, and there are some systematic ways to handle these things. You might look up Dave Abraham's levels of exception safety. Mostly his approach boils down to making operations effectively atomic so as to reduce the complexity: ideally, if an operation raises an exception, then it has undone any side effects. Of course it can't undo the launching of an ICBM, for example... But ideally, if it could, then it should. If you call the possibly failing operation "A", then that systematic approach goes like this: if A fails, then it has cleaned up its own mess, but if A succeeds, then it's the responsibility of the calling code to clean up if the higher level (multiple statements) operation that A is embedded in, fails. And that's what Marginean's original C++ ScopeGuard was designed for, and what the corresponding Python Cleanup class is designed for. > Both formulations can be correct (and both work perfectly fine with the > chdir() example being used). Sometimes one is better than the other, and > sometimes not. You can achieve both ways with either your Cleanup class > or with try: finally:. > > I am still of the opinion that Cleanup is not an improvement over try: > finally: and has the significant ugliness of forcing cleanup code into > callables. This significantly limits what you can do in your cleanup code. Uhm, not really. :-) As I see it. But for any given task one should use the most practical tool, and I'm certainly not claiming that Cleanup will always be that: it's just another weapon to employ in the correctness war -- although I think it's a powerful one. Cheers, - Alf From clp2 at rebertia.com Wed Mar 3 20:06:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 3 Mar 2010 17:06:01 -0800 Subject: Question about typing: ints/floats In-Reply-To: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: <50697b2c1003031706l6043430fv14e72203d7915a4f@mail.gmail.com> On Wed, Mar 3, 2010 at 3:45 PM, Wells wrote: > This seems sort of odd to me: > >>>> a = 1 >>>> a += 1.202 >>>> a > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. Remember Python is dynamically typed. Values have types, but variables don't (I could do a = "foo" at the end of your code and Python won't complain). But yes, internally, Python converted the int to a float before doing the addition. > But: > >>>> a = 1 >>>> b = 3 >>>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) This has been fixed in Python v3.x You can request the new behavior in earlier versions using a magic import: >>> from __future__ import division >>> a = 1 >>> b = 3 >>> a / b 0.33333333333333331 Cheers, Chris -- http://blog.rebertia.com From anand.shashwat at gmail.com Wed Mar 3 20:06:54 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Mar 2010 06:36:54 +0530 Subject: Question about typing: ints/floats In-Reply-To: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: yes you can also try: >>> float(a)/b 0.33333333333333331 On Thu, Mar 4, 2010 at 5:15 AM, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Does python > implicitly change the casting when you add variables of a different > numeric type? > > Anyway, just curiosity more than anything else. Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Mar 3 20:13:50 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Mar 2010 20:13:50 -0500 Subject: Question about typing: ints/floats In-Reply-To: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Wed, Mar 3, 2010 at 6:45 PM, Wells wrote: > This seems sort of odd to me: > > >>> a = 1 > >>> a += 1.202 > >>> a > 2.202 > > Indicates that 'a' was an int that was implicitly casted to a float. > But: > > >>> a = 1 > >>> b = 3 > >>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a > float as a result (0.33333333333333331) > > Is there some way to explain the consistency here? Does python > implicitly change the casting when you add variables of a different > numeric type? > > Anyway, just curiosity more than anything else. Thanks! > -- > Python doesn't cast anything. Variable names in python do not have types. It's the objects bound to the names that have types. a += 1.202 does not change a in place. It is exactly the same thing as writing a = a + 1.202 In Python (like many other languages), int + float returns a float. That float is then assigned to the name "a". In Python 2, all operations with two int operands return an int, including division. This was changed in Python 3 so that 1 / 3 will return a float and 1 // 3 will do integer division. > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Mar 3 20:28:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Mar 2010 01:28:25 +0000 Subject: Question about typing: ints/floats In-Reply-To: References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: <4B8F0CB9.3070708@mrabarnett.plus.com> Zeeshan Quireshi wrote: > On Mar 3, 6:45 pm, Wells wrote: >> This seems sort of odd to me: >> >>>>> a = 1 >>>>> a += 1.202 >>>>> a >> 2.202 >> >> Indicates that 'a' was an int that was implicitly casted to a float. >> But: >> >>>>> a = 1 >>>>> b = 3 >>>>> a / b >> 0 >> >> This does not implicitly do the casting, it treats 'a' and 'b' as >> integers, and the result as well. Changing 'b' to 3.0 will yield a >> float as a result (0.33333333333333331) >> >> Is there some way to explain the consistency here? Does python >> implicitly change the casting when you add variables of a different >> numeric type? >> >> Anyway, just curiosity more than anything else. Thanks! > > Python, like most other languages performs only integer division when > both the operands are ints. So only if one of the types is a flot or > you explicitly cast your expression to be a double, then the value > will be a fraction. otherwise you will the quotient. int + int gives int float + float gives float int + float gives float float + int gives float Similarly for '-' and '*'. Division causes a problem because what is int / int? Should it behave like the others and give an int? That would mean that 1 / 2 == 0, which can be confusing for newbies. In older languages (Fortran, for example) integer divided by integer using the normal division operator '/' was integer, and this is what C and those influenced by it do. Newer languages return a float instead of an integer because it causes less confusion (1 / 2 == 0.5 is less confusing than 1 / 2 == 0), but also provide a special integer division operator. In Python v2.x '/' does integer division, but from Python v3.x '/' does float division and uses '//' for integer division. ('//' is also available in later versions of 2.x.) From chris.lieb at gmail.com Wed Mar 3 20:33:00 2010 From: chris.lieb at gmail.com (Chris Lieb) Date: Wed, 3 Mar 2010 17:33:00 -0800 (PST) Subject: Failure in test_hashlib.py and test_hmac.py Message-ID: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> I am building Python 2.6.4 on a shared server and am encountering test failures in test_hashlib.py and test_hmac.py, specifically concerning sha512. I recompiled Python with --with-pydebug and CLFAGS=CPPFLAGS="- g" and ran the tests in GDB and got the following results: ---------------------------------------------------------------------------- GNU gdb 6.6.50.20070726-cvs Copyright (C) 2007 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-suse-linux"... Using host libthread_db library "/lib64/libthread_db.so.1". (gdb) run test_hashlib.py Starting program: /export/users1/chris.lieb/packages/python/bin/ python2.6 test_hashlib.py test_case_md5_0 (__main__.HashLibTestCase) ... ok test_case_md5_1 (__main__.HashLibTestCase) ... ok test_case_md5_2 (__main__.HashLibTestCase) ... ok test_case_md5_huge (__main__.HashLibTestCase) ... ok test_case_md5_uintmax (__main__.HashLibTestCase) ... ok test_case_sha1_0 (__main__.HashLibTestCase) ... ok test_case_sha1_1 (__main__.HashLibTestCase) ... ok test_case_sha1_2 (__main__.HashLibTestCase) ... ok test_case_sha1_3 (__main__.HashLibTestCase) ... ok test_case_sha224_0 (__main__.HashLibTestCase) ... ok test_case_sha224_1 (__main__.HashLibTestCase) ... ok test_case_sha224_2 (__main__.HashLibTestCase) ... ok test_case_sha224_3 (__main__.HashLibTestCase) ... ok test_case_sha256_0 (__main__.HashLibTestCase) ... ok test_case_sha256_1 (__main__.HashLibTestCase) ... ok test_case_sha256_2 (__main__.HashLibTestCase) ... ok test_case_sha256_3 (__main__.HashLibTestCase) ... ok test_case_sha384_0 (__main__.HashLibTestCase) ... ok test_case_sha384_1 (__main__.HashLibTestCase) ... ok test_case_sha384_2 (__main__.HashLibTestCase) ... ok test_case_sha384_3 (__main__.HashLibTestCase) ... ok test_case_sha512_0 (__main__.HashLibTestCase) ... FAIL test_case_sha512_1 (__main__.HashLibTestCase) ... FAIL test_case_sha512_2 (__main__.HashLibTestCase) ... FAIL test_case_sha512_3 (__main__.HashLibTestCase) ... FAIL test_hexdigest (__main__.HashLibTestCase) ... Program received signal SIGSEGV, Segmentation fault. Cannot remove breakpoints because program is no longer writable. It might be running in another process. Further execution is probably impossible. 0x00002ba86ffbb463 in ?? () (gdb) bt #0 0x00002ba86ffbb463 in ?? () #1 0x000000000046993d in PyString_FromStringAndSize ( str=0x7fff71c67800 "???\203???5~??????T(P???m\200\a??? ???\005\vW \025???\203???!???l??????G??????<] \205 5?????? \203\030???\207~???/c???1???GAz\201???82z???'???>???x???q???\177", size=1054484473) at Objects/stringobject.c:90 #2 0x00002ba87030d59a in ?? () #3 0x0000000000000000 in ?? () ----------------------------------------------------------------------------------------- GNU gdb 6.6.50.20070726-cvs Copyright (C) 2007 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-suse-linux"... Using host libthread_db library "/lib64/libthread_db.so.1". (gdb) run test_hmac.py Starting program: /export/users1/chris.lieb/packages/python/bin/ python2.6 test_hmac.py test_legacy_block_size_warnings (__main__.TestVectorsTestCase) ... ok test_md5_vectors (__main__.TestVectorsTestCase) ... ok test_sha224_rfc4231 (__main__.TestVectorsTestCase) ... ok test_sha256_rfc4231 (__main__.TestVectorsTestCase) ... ok test_sha384_rfc4231 (__main__.TestVectorsTestCase) ... ok test_sha512_rfc4231 (__main__.TestVectorsTestCase) ... Program received signal SIGSEGV, Segmentation fault. Cannot remove breakpoints because program is no longer writable. It might be running in another process. Further execution is probably impossible. 0x00002b483844e4c7 in ?? () (gdb) bt #0 0x00002b483844e4c7 in ?? () #1 0x000000000046993d in PyString_FromStringAndSize ( str=0x7ffff84f6730 "\026C3D???\235D\t???\025??????[??????G??? \032bG????????~???\235\t\233aP", size=4108309188) at Objects/stringobject.c:90 #2 0x00002b48387e159a in ?? () #3 0x0000000000000000 in ?? () -------------------------------------------------------------------- In the case of test_hashlib.py, it segfaulted on the first sha512 test when I didn't have the debugging options enabled. Only after enabling debugging did I get FAIL's for the sha512 tests. Does anyone know what is causing these failures? From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 21:00:02 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Mar 2010 02:00:02 GMT Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Wed, 03 Mar 2010 15:45:51 -0800, Wells wrote: > But: > >>>> a = 1 >>>> b = 3 >>>> a / b > 0 > > This does not implicitly do the casting, it treats 'a' and 'b' as > integers, and the result as well. Changing 'b' to 3.0 will yield a float > as a result (0.33333333333333331) This is design flaw in older versions of Python, that the / operator for ints performs integer division rather than floating point division. In Python 2.5 and beyond, you can fix this by calling from __future__ import division at the top of your module, and then / will perform float division with int arguments, and you can use // for integer division. Or upgrade to Python 3.1, where this is the default behaviour and there is no need for the from __future__ call. -- Steven From debatem1 at gmail.com Wed Mar 3 21:04:32 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 3 Mar 2010 21:04:32 -0500 Subject: Passing FILE * types using ctypes In-Reply-To: References: Message-ID: On Wed, Mar 3, 2010 at 6:50 PM, Zeeshan Quireshi wrote: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. Or do i have to call the C library using ctypes first, > get the pointer and then pass it to my function. Something along these lines should work: class FILE(ctypes.structure): pass FILE_p = ctypes.POINTER(FILE) ...but I haven't tested it. You can also use a c_void_p. > Also, is there any automated way to convert c struct and enum > definitions to ctypes data types. for structures: http://code.activestate.com/recipes/576734-c-struct-decorator/?in=user-4170000 for functions: http://code.activestate.com/recipes/576731-c-function-decorator/?in=user-4170000 Geremy Condra From john at castleamber.com Wed Mar 3 21:11:25 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Mar 2010 20:11:25 -0600 Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> Message-ID: <871vg0bzua.fsf@castleamber.com> Philip Semanchuk writes: > Do Fedora & Ubuntu's package managers offer modules that appear in > CPAN? Yes, I've installed so far all Perl modules I need that way (sudo apt-get install ...) > In other words, if I was a Perl user under Ubuntu would I use > the pkg manager to add a Perl module, or CPAN, or would both work? Both would work, but I would make very sure to use a separate installation directory for modules installed via CPAN. AFAIK there are also programs that pack CPAN modules/bundles into something the package manager can use to install. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 21:14:18 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Mar 2010 02:14:18 GMT Subject: Generic singleton References: Message-ID: On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote: > Hello, > > So I set out to write generic singleton, i.e. the one that would do a > singleton with attributes of specified class. At first: Groan. What is it with the Singleton design pattern? It is one of the least useful design patterns, and yet it's *everywhere* in Java and C++ world. I suspect because it allows people to have all the bugs and difficulties of global variables, while still pretending to be virtuous for not using global variables. But maybe I'm cynical... There are a ton of recipes out there for Python Singletons. Don't forget to check out the Borg pattern, which gives more or less the same effect using a radically different approach. Then, my advice is to forget all about them. In my experience, I have never needed to code my own Singleton class in anything except toy examples. YMMV. > print id(s1) == id(s2) Or, more concisely: s1 is s2 > class Singleton(object): > > instd = {} > > def __new__(cls, impclass, *args, **kwargs): > impid = id(impclass) Yuck. Why are you using the id of the class as the key, instead of the class itself? class Singleton(object): instd = {} def __new__(cls, impclass, *args, **kwargs): if not impclass in cls.instd: cls.instd[impclass] = impclass.__new__( impclass, *args, **kwargs) return cls.instd[impclass] > Questions: > > 1. Is this safe? That is, does every builtin class have unique id? I > have found this in docs: Why are you limiting yourself to builtin classes? ALL objects, whether classes or builtins or strings or ints or instances of a class you built yourself, have a unique id that lasts for the lifespan of the object. But that is certainly not what you care about. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Mar 3 21:18:23 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Mar 2010 02:18:23 GMT Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: On Wed, 03 Mar 2010 17:06:01 -0800, Chris Rebert wrote: > But yes, internally, Python converted the int to a float before doing > the addition. [pedantic] To be precise, Python created a *new* float from the int, leaving the original int alone. Because ints and floats are objects, if Python actually converted the int to a float, this would happen: >>> n = 1 >>> m = n >>> x = 2.0 + n >>> print x 3.0 >>> print n 1.0 >>> "abc"[m] Traceback (most recent call last): File "", line 1, in TypeError: string indices must be integers and the world would rapidly be destroyed. Fortunately this does not happen. [/pedantic] -- Steven From cournape at gmail.com Wed Mar 3 21:24:24 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 4 Mar 2010 11:24:24 +0900 Subject: PYTHONPATH and eggs In-Reply-To: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> References: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Message-ID: <5b8d13221003031824g6e26c9bbsc5a5fd52bbcd323e@mail.gmail.com> On Wed, Mar 3, 2010 at 7:14 PM, geoffbache wrote: > Unfortunately, the location from PYTHONPATH ends up after the eggs in > sys.path so I can't persuade Python to import my version. The only way > I've found to fix it is to copy the main script and manually hack > sys.path at the start of it which isn't really very nice. I wonder if > there is any better way as I can't be the first person to want to do > this, surely? One way is to never install things as eggs: I have a script hard_install which forces things to always install with --single-externally-managed blablabla. This has worked very well for me, but may not always be applicable (in particular if you are on a platform where building things from sources is difficult). cheers, David From roy at panix.com Wed Mar 3 21:28:03 2010 From: roy at panix.com (Roy Smith) Date: Wed, 03 Mar 2010 21:28:03 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> Message-ID: In article , "D'Arcy J.M. Cain" wrote: > On Wed, 03 Mar 2010 14:42:00 +0000 > MRAB wrote: > > Gregory Ewing wrote: > > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment > > display, which I had to solder together, and also make my own power > > supply. I had the extra RAM and the I/O chip, so that's 256B (including > > the memory used by the monitor) + 256B additional RAM + 128B more in the > > I/O chip. > > In case some of you youngsters think that there is a typo in the above, > no, he means a total of 640 bytes. In today's terms that would be > approx 0.0000006GB. 640 bytes! Man, did you have it easy. When I was a kid, we had to walk 10 miles uphill to school in the snow, oh, wait, wrong story. When I was a kid, we had a D2 kit (http://tinyurl.com/yfgyq4u). We had 256 bytes of RAM. And we thought we were lucky! Some of the other kids, if they wanted to store a number, they had to scratch the bits into stone tablets with their bare hands... When's the last time you had a computer where the instruction manual warned you against wearing silk or nylon clothing? From srikrishnamohan at gmail.com Wed Mar 3 21:30:21 2010 From: srikrishnamohan at gmail.com (km) Date: Thu, 4 Mar 2010 11:30:21 +0900 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: Hi, this would be a good place to start http://en.wikipedia.org/wiki/NoSQL http://nosql-database.org/ HTH, Krishna On Thu, Mar 4, 2010 at 7:41 AM, Avid Fan wrote: > Jonathan Gardner wrote: > > >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is understood well enough that the >> general nature of the SQL database is unnecessary. >> >> > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the query > language? > > Could you give some sort of example of where SQL would not be the way to > go. The only things I can think of a simple flat file databases. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From falk at mauve.rahul.net Wed Mar 3 21:50:23 2010 From: falk at mauve.rahul.net (Edward A. Falk) Date: Thu, 4 Mar 2010 02:50:23 +0000 (UTC) Subject: DOS Follies (Was: Docstrings...) References: <20100303114603.7021e9ba.darcy@druid.net> <539252.91463.qm@web58904.mail.re1.yahoo.com> Message-ID: In article , D'Arcy J.M. Cain wrote: >On Wed, 03 Mar 2010 20:44:08 +0100 >mk wrote: >> It reminds me of why Windows uses backslashes for path separation >> instead of slashes: what I've *heard*, and do not know if it's true, >> it's because Gates fancied using / for options switch instead of -, and >> to hell with established practice. > >That was because CP/M used slashes for options and DOS copied that. By >the time hierarchy was added it was too late to change. And CP/M got it from the various PDP-11 operating systems. I *think* that Tops-10 had it as well. In fact, I think using / to delimit commandline options goes back to the PDP-8. -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From philip at semanchuk.com Wed Mar 3 21:53:19 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 3 Mar 2010 21:53:19 -0500 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <161DBC13-9917-47E4-99FA-0D04AFC7DC44@semanchuk.com> On Mar 3, 2010, at 5:41 PM, Avid Fan wrote: > Jonathan Gardner wrote: > >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some >> point >> in the project's lifetime, the data is understood well enough that >> the >> general nature of the SQL database is unnecessary. > > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the > query language? > > Could you give some sort of example of where SQL would not be the > way to go. The only things I can think of a simple flat file > databases. Well, Zope is backed by an object database rather than a relational one. From jackdied at gmail.com Wed Mar 3 22:43:01 2010 From: jackdied at gmail.com (Jack Diederich) Date: Wed, 3 Mar 2010 22:43:01 -0500 Subject: NoSQL Movement? In-Reply-To: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: On Wed, Mar 3, 2010 at 12:36 PM, Xah Lee wrote: [snip] Xah Lee is a longstanding usenet troll. Don't feed the trolls. From jackdied at gmail.com Wed Mar 3 22:59:55 2010 From: jackdied at gmail.com (Jack Diederich) Date: Wed, 3 Mar 2010 22:59:55 -0500 Subject: Generic singleton In-Reply-To: <6cc20cea1003031418w5ad6f59ah91562243a2cc4afb@mail.gmail.com> References: <6cc20cea1003031418w5ad6f59ah91562243a2cc4afb@mail.gmail.com> Message-ID: On Wed, Mar 3, 2010 at 5:18 PM, Jonathan Gardner wrote: > On Wed, Mar 3, 2010 at 1:11 PM, mk wrote: >> >> Or I could make my life simpler and use global variable. :-) >> > > Ding ding ding! > > 90% of Design Patterns is making Java suck less. > > Other languages don't necessarily suffer from Java's design flaws. The original "Gang of Four" book was about C++ and not Java. The fact that you can casually assert that "Design Patterns" are about Java says something not entirely kosher about Java ;) -Jack From blueskykind02 at gmail.com Thu Mar 4 00:23:10 2010 From: blueskykind02 at gmail.com (yamamoto) Date: Wed, 3 Mar 2010 21:23:10 -0800 (PST) Subject: python SUDS library Message-ID: <28ed0127-8b71-4327-954c-c9100b4768de@v20g2000prb.googlegroups.com> Hi, I tried to make a simple script with SUD library for caching torrent files. it doenst work! [versions] suds: 0.4, python: 2.6.4 [code] from suds.client import Client import base64 path = 'sample.torrent' doc = open(path, 'rb').read() encoded_doc = base64.b64encode(doc) url = 'http://torrage.com/api/torrage.wsdl' client = Client(url, cache=None) print client hash = client.service.cacheTorrent(encoded_doc) print hash [result] Suds ( https://fedorahosted.org/suds/ ) version: 0.4 (beta) build: R663-20100303 Service ( CacheService ) tns="urn:Torrage" Prefixes (0) Ports (1): (CachePort) Methods (1): cacheTorrent(xs:string torrent, ) Types (0): Traceback (most recent call last): File "C:\Documents and Settings\yamamoto\workspace\python\console \extract.py", line 13, in result = client.service.cacheTorrent(encoded_doc) File "C:\Python26\lib\site-packages\suds\client.py", line 539, in __call__ return client.invoke(args, kwargs) File "C:\Python26\lib\site-packages\suds\client.py", line 598, in invoke result = self.send(msg) File "C:\Python26\lib\site-packages\suds\client.py", line 627, in send result = self.succeeded(binding, reply.message) File "C:\Python26\lib\site-packages\suds\client.py", line 659, in succeeded r, p = binding.get_reply(self.method, reply) File "C:\Python26\lib\site-packages\suds\bindings\binding.py", line 143, in get_reply replyroot = sax.parse(string=reply) File "C:\Python26\lib\site-packages\suds\sax\parser.py", line 136, in parse sax.parse(source) File "C:\Python26\lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python26\lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python26\lib\xml\sax\expatreader.py", line 211, in feed self._err_handler.fatalError(exc) File "C:\Python26\lib\xml\sax\handler.py", line 38, in fatalError raise exception xml.sax._exceptions.SAXParseException: :2:0: junk after document element this is a php code provided by torrage cacheTorrent(base64_encode(file_get_contents("my.torrent"))); ?> any suggestions? thanks in advance From waldemar.osuch at gmail.com Thu Mar 4 00:25:29 2010 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Wed, 3 Mar 2010 21:25:29 -0800 (PST) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: On Mar 3, 9:32?am, BlueBird wrote: > Hi, > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > that this does not exist. Does anybody know about this ? > > The following clients seem to be both unmaintained and still > supporting only SOAP 1.1 : > > - SUDS suds unmaintained? I beg to differ. > - zsi > - SOAPy > > cheers, > > Philippe From geoff.bache at jeppesen.com Thu Mar 4 03:20:57 2010 From: geoff.bache at jeppesen.com (geoffbache) Date: Thu, 4 Mar 2010 00:20:57 -0800 (PST) Subject: PYTHONPATH and eggs References: <86ee3b75-b3f5-4172-90c8-e90f0e50b89f@a18g2000yqc.googlegroups.com> Message-ID: On Mar 4, 3:24?am, David Cournapeau wrote: > On Wed, Mar 3, 2010 at 7:14 PM, geoffbache wrote: > > Unfortunately, the location from PYTHONPATH ends up after the eggs in > > sys.path so I can't persuade Python to import my version. The only way > > I've found to fix it is to copy the main script and manually hack > > sys.path at the start of it which isn't really very nice. I wonder if > > there is any better way as I can't be the first person to want to do > > this, surely? > > One way is to never install things as eggs: I have a script > hard_install which forces things to always install with > --single-externally-managed blablabla. This has worked very well for > me, but may not always be applicable (in particular if you are on a > platform where building things from sources is difficult). Thanks for the tips. Is your script generic at all? I wonder if you'd be prepared to share it? Figuring out virtualenv would also be an option, as would figuring out how to build my own egg, but both these solutions feel like overkill to me just to enable a small bit of tweaking. /Geoff From asimurzin at gmail.com Thu Mar 4 03:25:21 2010 From: asimurzin at gmail.com (=?UTF-8?B?0JDQvdC00YDQtdC5INCh0LjQvNGD0YDQt9C40L0=?=) Date: Thu, 4 Mar 2010 00:25:21 -0800 (PST) Subject: Don't work __getattr__ with __add__ Message-ID: It is object of the class A, in conteiner's class tmpA. Not all method from A are in the tmpA. So for exapmle: A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I can to call simple method, such as change(), bit __add__ - don't work. If to remove inheritance from object, the code work's. Help me, please #-------------------------------------- class A(object): def __init__( self, x, y ): self.x = x self.y = y pass #------- def __add__( self, arg ): tmp1 = self.x + arg.x tmp2 = self.y + arg.y return tmpA( A( tmp1, tmp2 ) ) def change( self, x, y ): self.x = x self.y = y pass pass #------------------------------------------ class tmpA( object ): def __init__( self, theA ): self.A = theA pass #------- def __call__( self ): return self.A #------- def __coerce__( self, *args ): return None #------- def __getattr__( self, *args ): name = args[ 0 ] try: attr = None exec "attr = self.__call__().%s" % name return attr except : raise AttributeError #-------------------------------------- class B( object ): def __init__( self, x, y): self.x = x self.y = y pass #------------------------------------- a=A( 1,2 ) b=B( 3,4 ) tmp_a = a + b #well tmp_a.change( 0, 0 ) # very well !!! v = tmp_a + b #TypeError: "unsupported operand type(s) for +: 'tmpA' and 'B'" From clp2 at rebertia.com Thu Mar 4 03:38:58 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Mar 2010 00:38:58 -0800 Subject: Don't work __getattr__ with __add__ In-Reply-To: References: Message-ID: <50697b2c1003040038l2d778448i7667d9b75a691dd@mail.gmail.com> On Thu, Mar 4, 2010 at 12:25 AM, ?????? ???????? wrote: > It is object of the class A, in conteiner's class tmpA. Not all method > from A are in the tmpA. So for exapmle: > A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I > can to call simple method, ?such as change(), bit __add__ - ?don't > work. If to remove inheritance from object, the code work's. Help me, > please Some clarity has been lost in translation, but I think I get what you're saying. __add__ and the other double-underscore special methods are not looked up using __getattr__ or __getattribute__, hence trying to do addition on tmpA, which does not define an __add__ method, fails. For a full explanation, read: http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes Cheers, Chris -- http://blog.rebertia.com From no.email at nospam.invalid Thu Mar 4 03:52:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 00:52:03 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> Message-ID: <7xlje8lb9o.fsf@ruckus.brouhaha.com> mk writes: > OK, but how? How would you make up e.g. for JSON's lack of comments? Modify the JSON standard so that "JSON 2.0" allows comments. > OTOH, if YAML produces net benefit for as few as, say, 200 people in > real world, the effort to make it has been well worth it. Not if 200,000 other people have to deal with it but don't receive the benefit. > http://myarch.com/why-xml-is-bad-for-humans > http://www.ibm.com/developerworks/xml/library/x-sbxml.html You might like this one too: http://www.schnada.de/grapt/eriknaggum-xmlrant.html > > I also have to maintain a few applications that internally use XML as > data format: while they are tolerable, they still leave smth to be > desired, as those applications are really slow for larger datasets, I thought we were talking about configuration files, not "larger datasets". > There are demonstrable benefits to this too: I for one am happy that > ReST is available for me and I don't have to learn a behemoth such as > DocBook to write documentation. DocBook is so far off my radar I'd have never thought of it. I just now learned that it's not Windows-only. There is already POD, Pydoc, Texinfo, a billion or so flavors of wiki markup, vanilla LaTeX, and most straightforwardly of all, plain old ascii. ReST was another solution in search of a problem. From asimurzin at gmail.com Thu Mar 4 03:54:13 2010 From: asimurzin at gmail.com (Andrey Simurzin) Date: Thu, 4 Mar 2010 00:54:13 -0800 (PST) Subject: Don't work __getattr__ with __add__ References: Message-ID: On 4 ???, 11:38, Chris Rebert wrote: > On Thu, Mar 4, 2010 at 12:25 AM, ?????? ???????? wrote: > > It is object of the class A, in conteiner's class tmpA. Not all method > > from A are in the tmpA. So for exapmle: > > A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I > > can to call simple method, ?such as change(), bit __add__ - ?don't > > work. If to remove inheritance from object, the code work's. Help me, > > please > > Some clarity has been lost in translation, but I think I get what you're saying. > __add__ and the other double-underscore special methods are not looked > up using __getattr__ or __getattribute__, hence trying to do addition > on tmpA, which does not define an __add__ method, fails. > > For a full explanation, read:http://docs.python.org/reference/datamodel.html#special-method-lookup... > > Cheers, > Chris > --http://blog.rebertia.com Thank you very much From greg.ewing at canterbury.ac.nz Thu Mar 4 05:01:06 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:01:06 +1300 Subject: My four-yorkshireprogrammers contribution In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> Message-ID: <7v9e3rFl7mU1@mid.individual.net> MRAB wrote: > Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment > display, which I had to solder together, and also make my own power > supply. I had the extra RAM and the I/O chip, so that's 256B (including > the memory used by the monitor) + 256B additional RAM + 128B more in the > I/O chip. Luxury! Mine was a Miniscamp, based on a design published in Electronics Australia in the 70s. 256 bytes RAM, 8 switches for input, 8 LEDs for output. No ROM -- program had to be toggled in each time. Looked something like this: http://oldcomputermuseum.com/mini_scamp.html except that mine wasn't built from a kit and didn't look quite as professional as that one. It got expanded in various ways, of course ("hacked" would be a more accurate word). Memory expanded to 1.5KB, hex keyboard and display (built into an old calculator case), cassette tape interface based on a circuit scrounged from another magazine article (never quite got it to work properly, wouldn't go at more than about 4 bytes/sec, probably because I used resistors and capacitors salvaged from old TV sets). Still no ROM, though. Had to toggle in a bootstrap to load the keyboard/display monitor (256 bytes) from tape. Somewhere along the way I replaced the CPU with a 6800 - much nicer instruction set! (Note for newtimers -- that's *two* zeroes, not three.) During that period, my holy grail was alphanumeric I/O. I was envious of people who wrote articles about hooking surplus teleprinters, paper tape equipment and other such cool hardware to their homebrew micros -- sadly, no such thing was available in NZ. Then one day a breakthrough came -- a relative who worked in the telephone business (government-owned in NZ at the time) managed to get me an old teleprinter. It was Baudot, not ASCII, which meant uppercase only, not much punctuation, and an annoyingly stateful protocol involving letters/figures shift characters, but it was heaps better than nothing. A bit of hackery, of both hardware and software varieties, and I got it working. It was as noisy as hell, but I could input and output ACTUAL LETTERS! It was AMAZING! As a proof of concept, I wrote an extremely small BASIC interpreter that used one-character keywords. The amount of room left over for a program was even smaller, making it completely useless. But it worked, and I had fun writing it. One thing I never really got a grip on with that computer was a decent means of program storage. Towards the end of it's life, I was experimenting with trying to turn an old 8-track cartridge player into a random access block storage device, using a tape loop. I actually got it to work, more or less, and wrote a small "TOS" (Tape Operating System) for it that could store and retrieve files. But it was never reliable enough to be practical. By that stage, umpteen layers of hackery using extremely dubious construction techniques had turned the machine into something of a Frankenstein monster. Calling it a bird's nest would have been an insult to most birds. I wish I'd taken some photos, they would have been good for scaring potential future grandchildren. My next computer was a Dick Smith Super 80 (*not* System 80, which would have been a much better machine), Z80-based, built from a kit. I had a lot of fun hacking around with that, too... but that's another story! -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:05:10 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:05:10 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: <7v9ebdFmfiU1@mid.individual.net> D'Arcy J.M. Cain wrote: > And that is why text files in MS-DOS and CP/M before it end with ^Z. > They needed a way to tell where the end of the information was. Why > they used ^Z (SUB - Substitute) instead of ^C (ETX - End of TeXt) or > even ^D (EOT - End Of Transmission) is anyone's guess. Well, ^C is what people used for interrupting their BASIC programs. And ^D would have made it almost compatible with unix, which would have been far too sensible! My guess is that it was chosen for its mnemonic value -- end of alphabet, end of file. Also remember there were programs like Wordstar that used control key combinations for all manner of things. It might have been the only key left on the keyboard that wasn't used for anything else. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:09:01 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:09:01 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: Message-ID: <7v9eimFnnoU1@mid.individual.net> Richard Brodie wrote: > It goes back to ancient PDP operating systems, so may well > predate Unix, depending which exact OS was the first to use it. Yes, I think it was used in RT-11, which also had block-oriented disk files. There were two kinds of devices in RT-11, character and block, and the APIs for dealing with them were quite different. They hadn't fully got their heads around the concept of "device independent I/O" in those days, although they were trying. -- Greg From spamfresser at ch3ka.de Thu Mar 4 05:09:06 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 11:09:06 +0100 Subject: case do problem In-Reply-To: <4b8e9e8b$0$1121$4fafbaef@reader3.news.tin.it> References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> <4b8e9e8b$0$1121$4fafbaef@reader3.news.tin.it> Message-ID: Am 03.03.2010 18:38, schrieb Tracubik: > Il Wed, 03 Mar 2010 09:39:54 +0100, Peter Otten ha scritto: >> def loop(): >> count = 0 >> m = 0 >> lookup = {1: 1, 2: 10, 3: 100} >> for iterations in range(20): # off by one >> # ... >> print "%2d %1d %3d" % (iterations, count, m) # ... >> if generic_condition(): >> count += 1 >> # ... >> m = lookup.get(count, m) >> if count == 4: >> break >> >> if __name__ == "__main__": >> loop() >> print "That's all, folks" >> >> Something must be wrong with me today because I find the Pascal code >> /more/ readable.. > > i was think the same, Pascal seem to generate a great more readable code. > I'm a newbie, so my opinion is probably wrong, but i still think that > don't have CASE OF and REPEAT UNTIL code block return in difficult-to- > read code. That is probably a side-effect of literal code translation. No one would write something like you did when he writes in python the first place. >> Tracubik wrote: >> >>> hi, i've to convert from Pascal this code: >> >> program loop; >> >> function generic_condition: boolean; >> begin >> generic_condition := random> 0.7 >> end; >> >> procedure loop; >> var >> iterations, count, m: integer; >> begin >> iterations := 0; >> count := 0; >> m := 0; >> repeat >> iterations := iterations+1; >> (*...*) >> writeln(iterations:2, count:2, m:4); >> (*...*) >> if generic_condition then >> inc(count); >> (*...*) >> case count of >> 1: m := 1; >> 2: m := 10; >> 3: m := 100 >> end >> until (count = 4) or (iterations = 20) >> end; >> >> begin >> loop; >> writeln("That's all, folks") >> end. Hmmm lets see... We have somewhat obscure and complicated logic. If we cannot get rid of it, lets hide it: class Loop: def __init__(self, maxiterations=0, maxcount=1, m=0): assert generic_condition.__call__ self.maxiterations = maxiterations self.maxcount = maxcount self.m=m self.count=0 self.iterations=0 def __iter__(self): while True: yield self.next() def next(self): self.iterations+=1 if self.iterations > self.maxiterations: raise StopIteration if generic_condition(): self.count += 1 if self.count >= self.maxcount: raise StopIteration self.m = (None,1,10,100)[self.count] return self, self.m ##### So we have: #from complicatedlogic import Loop from random import random def generic_condition(): return random() > 0.7 if __name__ == '__main__': for loop, m in Loop(maxiterations=20, maxcount=4): print("%2d %1d %3d" % (loop.iterations, loop.count, m)) print("That's all, folks") better? worse? I honestly do not know. Note that while this is valid py3 and runs as intended, there might be some off-by-one or something left. Also, this is of course not production level code ;) Regards, Michael From greg.ewing at canterbury.ac.nz Thu Mar 4 05:15:23 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:15:23 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> Message-ID: <7v9eukFpu2U1@mid.individual.net> Steve Holden wrote: > Puts me in mind of Mario Wolczko's early attempts to implement SmallTalk > on a VAX 11/750. The only bitmapped display we had available was a Three > Rivers PERQ, connected by a 9600bps serial line. We left it running at > seven o'clock one evening, and by nine am the next day it had brought up > about two thirds of the initial VM loader screen ... A couple of my contemporary postgraduate students worked on getting Smalltalk to run on an Apple Lisa. Their first attempt at a VM implementation was written in Pascal, and it wasn't very efficient. I remember walking into their room one day and seeing one of them sitting there watching it boot, drawing stuff on the screen v...e...r...y... s...l...o...w...l...y... At least their display was wired directly to the machine running the code. I hate to think what bitmapped graphics at 9600 baud would be like! -- Greg From nanyaks at googlemail.com Thu Mar 4 05:30:15 2010 From: nanyaks at googlemail.com (simn_stv) Date: Thu, 4 Mar 2010 02:30:15 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> Message-ID: <81d62813-c768-4f9e-aa50-d6d007a9b1e6@19g2000yqu.googlegroups.com> till i think i absolutely need to trade-off easier and less complicated code, better db structure (from a relational perspective) and generally less "head aches" for speed, i think i'll stick with the joins for now!...;) the thought of denormalization really doesnt appeal to me... From karen.wang at avant-port.com.cn Thu Mar 4 05:38:08 2010 From: karen.wang at avant-port.com.cn (Karen Wang) Date: Thu, 4 Mar 2010 18:38:08 +0800 Subject: How to login https sever with inputing account name and password? Message-ID: <20100304103731.740AC40E@smtpcom.263xmail.com> Hi all, I want to use python to access to https server, like "https://212.218.229.10/chinatest/" If open it from IE, will see the pop-up login windows like this I tried several ways but always only get page for" HTTP Error 401.2 - Unauthorized" error. ( myusername and mypassword are all correct) Below is my code: import urllib2 values = { 'user' : "myusername", "pass' : "mypassword" } data = urllib2.urlencode(values) t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) print t.read() where I am wrong ? Thank you very much. Best Regards Karen Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 17890 bytes Desc: not available URL: From greg.ewing at canterbury.ac.nz Thu Mar 4 05:38:22 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:38:22 +1300 Subject: Old farts playing with their toys In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <4B8E7538.2080003@mrabarnett.plus.com> <20100303111248.7f40d659.darcy@druid.net> <4B8EABCB.6050303@mrabarnett.plus.com> Message-ID: <7v9g9hF1hrU1@mid.individual.net> D'Arcy J.M. Cain wrote: > Did you ever play Star Trek with sound effects? Not on that machine, but I played a version on an Apple II that had normal speaker-generated sounds. I can still remember the sound that a photon torpedo (a # character IIRC) made as it lurched its way drunkenly across the sector and hit its target. Bwoop... bwoop... bwoop... bwoop... bwoop... bwoowoowoowoowoop! (Yes, a photon torpedo makes exactly five bwoops when it explodes. Apparently.) I carried a listing of it around with me for many years afterwards, and attempted to port it to various machines, with varying degrees of success. The most successful port was for a BBC Master that I picked up in a junk shop one day. But I couldn't get the sounds right, because the BBC's sound hardware was too intelligent. The Apple made sounds by directly twiddling the output bit connected to the loudspeaker, but you can't do that with a BBC -- you have to go through its fancy 3-voice waveform generating chip. And I couldn't get it to ramp up the pitch rapidly enough to make a proper photon-torpedo "bwoop" sound. :-( I also discovered that the lovely low-pitched beep that the original game used to make at the command prompt had a lot to do with the resonant properties of the Apple II's big plastic case. Playing a square wave through something too high-fidelity doesn't sound the same at all. > I was never able to > get it to work but supposedly if you put an AM radio tuned to a > specific frequency near the side with the I/O card it would generate > static that was supposed to be the sound of explosions. > > Of course, the explosions were happening in a vaccum so maybe the > silence was accurate. :-) Something like that might possibly happen for real. I could imagine an explosion in space radiating electromagnetic noise that would sound explosion-like if you picked it up on a radio. This might explain why the Enterprise crew could hear things exploding when they shot them. They were listening in at RF! -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:38:31 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:38:31 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> Message-ID: <7v9g9qF1nkU1@mid.individual.net> Steven D'Aprano wrote: > True, but one can look at "best practice", or even "standard practice". > For Python coders, using docstrings is standard practice if not best > practice. Using strings as comments is not. In that particular case, yes, it would be possible to objectively examine the code and determine whether docstrings were being used as opposed to above-the-function comments. However, that's only a very small part of what goes to make good code. Much more important are questions like: Are the comments meaningful and helpful? Is the code reasonably self-explanatory outside of the comments? Is it well modularised, and common functionality factored out where appropriate? Are couplings between different parts minimised? Does it make good use of library code instead of re-inventing things? Is it free of obvious security flaws? You can't *measure* these things. You can't objectively boil them down to a number and say things like "This code is 78.3% good; the customer requires it to be at least 75% good, so it meets the requirements in that area." That's the way in which I believe that software engineering is fundamentally different from hardware engineering. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 4 05:43:20 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:43:20 +1300 Subject: Adding to a module's __dict__? In-Reply-To: References: <0773959a-2ae7-4515-8196-67a50748f98f@e23g2000yqd.googlegroups.com> Message-ID: <7v9girF3b8U1@mid.individual.net> Roy Smith wrote: > The idea is I want to put in the beginning of the module: > > declare('XYZ_FOO', 0, "The foo property") > declare('XYZ_BAR', 1, "The bar property") > declare('XYZ_BAZ', 2, "reserved for future use") Okay, that seems like a passable excuse. One thing to watch out for is that if your 'declare' function is defined in a different module, when it calls globals() it will get the globals of the module it's defined in, not the one it's being called from. There's a hackish way of getting around that, but it might be better to put all of these symbols in a module of their own and import them from it. The declare() function can then be defined in that same module so that it accesses the right globals. -- Greg From jeanmichel at sequans.com Thu Mar 4 05:45:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 11:45:19 +0100 Subject: Pylint Argument number differs from overridden method In-Reply-To: <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> Message-ID: <4B8F8F3F.8010501@sequans.com> Wanderer wrote: > On Mar 3, 2:33 pm, Robert Kern wrote: > >> On 2010-03-03 11:39 AM, Wanderer wrote: >> >> >>> Pylint W0221 gives the warning >>> Argument number differs from overridden method. >>> >>> Why is this a problem? I'm overriding the method to add additional >>> functionality. >>> >> There are exceptions to every guideline. Doing this could easily be a mistake, >> so it's one of the many things that Pylint checks for. Silence the warning if >> you like. >> >> -- >> 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 >> > > Thanks I was just wondering if I was overlooking something about > inheritance. > This is only my opinion but you get this warning because of 2 disctinct issues: 1/ you just made a basic mistake in your signature and need to correct it 2/ you did not make any mistake in the signature, but this warning may reveal a (small) flaw in your class design. I don't know the exact context for your code, but it's better to have a consistant interface over your methods and mask the implementation details from the user. In your case, the getRays method may always ask for the lambda parameters and just ignore it for one of its implementation. And don't write empty doctrings to trick pylint. Either write them, or remove this rule, you are loosing all the tool benefits. JM From jpiitula at ling.helsinki.fi Thu Mar 4 05:46:06 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Mar 2010 12:46:06 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml Message-ID: Dear group, I am observing weird semi-erratic behaviour that involves Python 3 and lxml, is extremely sensitive to changes in the input data, and only occurs when I name a partial result. I would like some help with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml version?) The test script regress/Tribug is at the end of this message, with a snippet to show the form of regress/tridata.py where the XML is. What I observe is this. Parsing an XML document (wrapped in BytesIO) with lxml.etree.parse and then extracting certain elements with xpath sometimes fails so that I get three times the correct number of elements. On the first run of the script, it fails in one way, and on each subsequent run in another way: subsequent runs are repeatable. Second, the bug only occurs when I give a name to the result from lxml.etree.parse! This is seen below in the lines labeled "name1" or "name2" that sometimes exhibit the bug, and lines labeled "nest1" or "nest2" that never do. That is, this fails in some complex way: result = etree.parse(BytesIO(body)) n = len(result.xpath(title)) This fails to fail: n = len(etree.parse(BytesIO(body)).xpath(title)) I have failed to observe the error interactively. I believe the erroneus result lists are of the form [x x x y y y z z z] when they should be [x y z] but I do not know if the x's are identical or copies. I will know more later, of course, when I have written more complex tests, unless somebody can lead me to a more profitable way of debugging this. Two versions of the test runs follow, before and after a trivial change to the test data. Since the numbers are repeated n's of the above snippets, they should all be the same: 5 observed 1000 times. A first run after removing regress/tridata.pyc: [1202] $ regress/Tribug name1: size 5 observed 969 times name1: size 15 observed 31 times name2: size 5 observed 1000 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times All subsequent runs, with regress/tridata.pyc recreated: [1203] $ regress/Tribug name1: size 5 observed 1000 times name2: size 5 observed 978 times name2: size 15 observed 22 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times Adding an empty comment to the XML document; a first run: [1207] $ regress/Tribug name1: size 5 observed 992 times name1: size 15 observed 8 times name2: size 5 observed 1000 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times And subsequent runs: [1208] $ regress/Tribug name1: size 5 observed 991 times name1: size 15 observed 9 times name2: size 5 observed 998 times name2: size 15 observed 2 times nest1: size 5 observed 1000 times nest2: size 5 observed 1000 times ---start of regress/Tribug--- #! /bin/env python3 # -*- mode: Python; -*- from io import BytesIO from lxml import etree from tridata import body, title def naming(): sizes = dict() for k in range(0,1000): result = etree.parse(BytesIO(body)) n = len(result.xpath(title)) sizes[n] = 1 + sizes.get(n, 0) return sizes def nesting(): sizes = dict() for k in range(0,1000): n = len(etree.parse(BytesIO(body)).xpath(title)) sizes[n] = 1 + sizes.get(n, 0) return sizes def report(label, sizes): for size, count in sizes.items(): print('{}: size {} observed {} times' .format(label, size, count)) report('name1', naming()) report('name2', naming()) report('nest1', nesting()) report('nest2', nesting()) ---end of regress/Tribug--- The file regress/tridata.py contains only the two constants. I omit most of the XML. It would be several screenfuls. ---start of regress/tridata.py--- body = b''' References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <137d7aa5-a305-4091-a244-904b680d3b56@t41g2000yqt.googlegroups.com> Message-ID: <7v9gv5F3b8U2@mid.individual.net> Floris Bruynooghe wrote: > I was just wondering if > other people ever missed the "q.put_at_front_of_queue()" method or if > it is just me. Sounds like you don't want a queue, but a stack. Or maybe a double-ended queue. -- Greg From jeanmichel at sequans.com Thu Mar 4 05:50:06 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 11:50:06 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <4B8F905E.1090704@sequans.com> Alf P. Steinbach wrote: >> From your post, the scope guard technique is used "to ensure some >> desired cleanup at the end of a scope, even when the scope is exited >> via an exception." This is precisely what the try: finally: syntax is >> for. > > You'd have to nest it. That's ugly. And more importantly, now two > people in this thread (namely you and Mike) have demonstrated that > they do not grok the try functionality and manage to write incorrect > code, even arguing that it's correct when informed that it's not, so > it's a pretty fragile construct, like goto. You want to execute some cleanup when things go wrong, use try except. You want to do it when things go right, use try else. You want to cleanup no matter what happen, use try finally. There is no need of any Cleanup class, except for some technical alternative concern. JM From greg.ewing at canterbury.ac.nz Thu Mar 4 05:58:35 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 04 Mar 2010 23:58:35 +1300 Subject: case do problem In-Reply-To: References: <4b8d4ee4$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: <7v9hfeF8hsU1@mid.individual.net> Peter Otten wrote: > Something must be wrong with me today because I find the Pascal code /more/ > readable... Actually I don't find either of them very readable. The control flow is pretty convoluted either way. It might be better if it used real-life variable and function names to give some context, though. -- Greg From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 4 05:59:00 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Mar 2010 11:59:00 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> Message-ID: <4b8f9267$0$17832$426a74cc@news.free.fr> Eike Welk a ?crit : > Bruno Desthuilliers wrote: >> John Posner a ?crit : >>> Done -- see http://wiki.python.org/moin/FromFunctionToMethod >> Done and well done !-) >> Thanks again for the good job John. > > I like it too, thanks to both of you! > > I have two small ideas for improvement: > - Swap the first two paragraphs. First say what it is, and then give the > motivation. Mmm... As far as I'm concerned, I like it the way its. John ? > - The section about the descriptor protocol is a bit difficult to > understand. I may eventually try to rework it a bit when I'll have time (death march here currently, duh...) > But judging from the official descriptor documentation, it seems > to be hard to explain Not that easy, indeed. I once posted on c.l.py a longer explanation of the whole lookup rule stuff, that IIRC included a "naive python implementation" example. Might be worth trying to google for it and turning it into another "overview" article. >: The official documentation is nearly incomprehensible > (IMHO). I should probably have a look at it !-) From greg.ewing at canterbury.ac.nz Thu Mar 4 06:21:01 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 00:21:01 +1300 Subject: Working group for Python CPAN-equivalence? In-Reply-To: References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> Message-ID: <7v9ipdFfcsU1@mid.individual.net> Peter Billam wrote: > A very important thing about CPAN modules is the consistent > basic install method: perl Makefile.PL ; make ; make install Well, we more or less have that with Python, too: python setup.py install It may not always work smoothly, but it's the one obvious thing to try when you've downloaded a Python package in source form. -- Greg From olof.bjarnason at gmail.com Thu Mar 4 06:45:39 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Thu, 4 Mar 2010 12:45:39 +0100 Subject: Working group for Python CPAN-equivalence? In-Reply-To: <7v9ipdFfcsU1@mid.individual.net> References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <7v9ipdFfcsU1@mid.individual.net> Message-ID: 2010/3/4 Gregory Ewing : > Peter Billam wrote: > >> A very important thing about CPAN modules is the consistent >> basic install method: ? perl Makefile.PL ; make ; make install > > Well, we more or less have that with Python, too: > > ?python setup.py install > > It may not always work smoothly, but it's the > one obvious thing to try when you've downloaded > a Python package in source form. > > -- > Greg > -- > http://mail.python.org/mailman/listinfo/python-list > I want to say thanks to all that have given information regarding the original question - for example the blog mention was valuable, aswell as the disctintion between CPAN and cpan. It was definately *not* my intention to start another "Where is CPAN for Python?"-thread, but it seems we're already there. :) -- http://olofb.wordpress.com From mrkafk at gmail.com Thu Mar 4 06:50:45 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 12:50:45 +0100 Subject: Generic singleton In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > Groan. What is it with the Singleton design pattern? It is one of the > least useful design patterns, and yet it's *everywhere* in Java and C++ > world. It's useful when larking about in language internals for learning purposes, for instance. I don't recall ever actually having significant need for it. >> def __new__(cls, impclass, *args, **kwargs): >> impid = id(impclass) > > Yuck. Why are you using the id of the class as the key, instead of the > class itself? Bc I didn't know whether it was safe to do that: like Arnaud pointed out, the *type* of bultins is hashable. Regards, mk From mrkafk at gmail.com Thu Mar 4 06:56:17 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 12:56:17 +0100 Subject: memory usage, temporary and otherwise In-Reply-To: <4b8ee61a$0$26644$426a74cc@news.free.fr> References: <4b8ee61a$0$26644$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > mk a ?crit : >> Obviously, don't try this on low-memory machine: >> >>>>> a={} >>>>> for i in range(10000000): > Note that in Python 2, this will build a list of 10000000 int objects. > You may want to use xrange instead... Huh? I was under impression that some time after 2.0 range was made to work "under the covers" like xrange when used in a loop? Or is it 3.0 that does that? > And this build yet another list of 10000000 int objects. Well this explains much of the overhead. > (overly simplified) > > When an object is garbage-collected, the memory is not necessarily > "returned" to the system - and the system doesn't necessarily claim it > back neither until it _really_ needs it. > > This avoid a _lot_ of possibly useless work for both the python > interpreter (keeping already allocated memory costs less than immediatly > returning it, just to try and allocate some more memory a couple > instructions later) and the system (ditto - FWIW, how linux handles > memory allocations is somewhat funny, if you ever programmed in C). Ah! That explains a lot. Thanks to you, I have again expanded my knowledge of Python! Hmm I would definitely like to read smth on how CPython handles memory on Python wiki. Thanks for that doc on wiki on "functions & methods" to you and John Posner, I'm reading it every day like a bible. ;-) Regards, mk From ben+python at benfinney.id.au Thu Mar 4 06:57:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Mar 2010 22:57:30 +1100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> <7v9g9qF1nkU1@mid.individual.net> Message-ID: <87ocj4ti39.fsf@benfinney.id.au> Gregory Ewing writes: > However, that's only a very small part of what goes to make good code. > Much more important are questions like: Are the comments meaningful > and helpful? Is the code reasonably self-explanatory outside of the > comments? Is it well modularised, and common functionality factored > out where appropriate? Are couplings between different parts > minimised? Does it make good use of library code instead of > re-inventing things? Is it free of obvious security flaws? > > You can't *measure* these things. You can't objectively boil them down > to a number and say things like "This code is 78.3% good; the customer > requires it to be at least 75% good, so it meets the requirements in > that area." That doesn't reduce the value of automating and testing those measures we *can* make. > That's the way in which I believe that software engineering is > fundamentally different from hardware engineering. Not at all. There are many quality issues in hardware engineering that defy simple measurement; that does not reduce the value of standardising quality minima for those measures that *can* be achieved simply. -- \ ?Spam will be a thing of the past in two years' time.? ?Bill | `\ Gates, 2004-01-24 | _o__) | Ben Finney From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 4 06:59:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Mar 2010 12:59:27 +0100 Subject: Interest check in some delicious syntactic sugar for "except:pass" In-Reply-To: References: Message-ID: <4b8fa091$0$24833$426a74cc@news.free.fr> Oren Elrad a ?crit : > Howdy all, longtime appreciative user, first time mailer-inner. > > I'm wondering if there is any support (tepid better than none) for the > following syntactic sugar: > > silence: > ........ block > > -------------------------> > > try: > ........block > except: > ........pass > Hopefully not. > The logic here is that there are a ton of "except: pass" statements[1] > floating around in code that do not need to be there. s/do not need to be/NEVER should have been at first/ From mrkafk at gmail.com Thu Mar 4 07:01:38 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 13:01:38 +0100 Subject: NoSQL Movement? In-Reply-To: <6cc20cea1003031423v4410119dh767610e78ba3eb6e@mail.gmail.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003031423v4410119dh767610e78ba3eb6e@mail.gmail.com> Message-ID: Jonathan Gardner wrote: > When you are starting a new project and you don't have a definitive > picture of what the data is going to look like or how it is going to > be queried, SQL databases (like PostgreSQL) will help you quickly > formalize and understand what your data needs to do. In this role, > these databases are invaluable. I can see no comparable tool in the > wild, especially not OODBMS. FWIW, I talked to my promoting professor about the subject, and he claimed that there's quite a number of papers on OODBMS that point to fundamental problems with constructing capable query languages for OODBMS. Sadly, I have not had time to get & read those sources. Regards, mk From duncan.booth at invalid.invalid Thu Mar 4 07:21:26 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 12:21:26 GMT Subject: Generic singleton References: Message-ID: Steven D'Aprano wrote: > On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote: > >> Hello, >> >> So I set out to write generic singleton, i.e. the one that would do a >> singleton with attributes of specified class. At first: > > Groan. What is it with the Singleton design pattern? It is one of the > least useful design patterns, and yet it's *everywhere* in Java and C++ > world. It is also *everywhere* in the Python world. Unlike Java and C++, Python even has its own built-in type for singletons. If you want a singleton in Python use a module. So the OP's original examples become: --- file singleton.py --- foo = {} bar = [] --- other.py --- from singleton import foo as s1 from singleton import foo as s2 from singleton import bar as s3 from singleton import bar as s4 ... and then use them as you wish. -- Duncan Booth http://kupuguy.blogspot.com From duncan.booth at invalid.invalid Thu Mar 4 07:24:52 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 12:24:52 GMT Subject: memory usage, temporary and otherwise References: Message-ID: mk wrote: > Hm, apparently Python didn't spot that 'spam'*10 in a's values is really > the same string, right? If you want it to spot that then give it a hint that it should be looking for identical strings: >>> a={} >>> for i in range(10000000): ... a[i]=intern('spam'*10) should reduce your memory use somewhat. -- Duncan Booth http://kupuguy.blogspot.com From J.Fine at open.ac.uk Thu Mar 4 07:30:12 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Thu, 04 Mar 2010 12:30:12 +0000 Subject: WANTED: A good name for the pair (args, kwargs) Message-ID: Hi We can call a function fn using val = fn(*args, **kwargs) I'm looking for a good name for the pair (args, kwargs). Any suggestions? Here's my use case: def doit(fn , wibble, expect): args, kwargs = wibble actual = fn(*args, **kwargs) if actual != expect: # Something has gone wrong. pass This is part of a test runner. For now I'll use argpair, but if anyone has a better idea, I'll use it. -- Jonathan From mrkafk at gmail.com Thu Mar 4 07:34:39 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 13:34:39 +0100 Subject: taking python enterprise level?... In-Reply-To: <0C9B223A-D32A-474C-80E3-7F912447170F@semanchuk.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <973824D8-3020-44A8-B2DA-501FF530457B@semanchuk.com> <0C9B223A-D32A-474C-80E3-7F912447170F@semanchuk.com> Message-ID: Philip Semanchuk wrote: > Well OK, but that's a very different argument. Yes, joins can be > expensive. They're often still the best option, though. The first step > people usually take to get away from joins is denormalization which can > improve SELECT performance at the expense of slowing down INSERTs, > UPDATEs, and DELETEs, not to mention complicating one's code and data > model. Is that a worthwhile trade? I'd say that in more than 99% of situations: NO. More than that: if I haven't normalized my data as it should have been normalized, I wouldn't be able to do complicated querying that I really, really have to be able to do due to business logic. A few of my queries have a few hundred lines each with many sub-queries and multiple many-to-many joins: I *dread the thought* what would happen if I had to reliably do it in a denormalized db and still ensure data integrity across all the business logic contexts. And performance is still more than good enough: so there's no point for me, as of the contexts I normally work in, to denormalize data at all. It's just interesting for me to see what happens in that <1% of situations. > Depends on the application. As I > said, sometimes the cure is worse than the disease. > > Don't worry about joins until you know they're a problem. As Knuth said, > premature optimization is the root of all evil. Sure -- the cost of joins is just interesting to me as a 'corner case'. I don't have datasets large enough for this to matter in the first place (and I probably won't have them that huge). > PS - Looks like you're using Postgres -- excellent choice. I miss using it. If you can, I'd recommend using SQLAlchemy layer on top of Oracle/Mysql/Sqlite, if that's what you have to use: this *largely* insulates you from the problems below and it does the job of translating into a peculiar dialect very well. For my purposes, SQLAlchemy worked wonderfully: it's very flexible, it has middle-level sql expression language if normal querying is not flexible enough (and normal querying is VERY flexible), it has a ton of nifty features like autoloading and rarely fails bc of some lower-level DB quirk AND its high-level object syntax is so similar to SQL that you quickly & intuitively grasp it. (and if you have to/prefer writing some query in "low-level" SQL, as I have done a few times, it's still easy to make SQLAlchemy slurp the result into objects provided you ensure there are all of the necessary columns in the query result) Regards, mk From spamfresser at ch3ka.de Thu Mar 4 07:41:22 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 13:41:22 +0100 Subject: How to login https sever with inputing account name and password? In-Reply-To: References: Message-ID: Am 04.03.2010 11:38, schrieb Karen Wang: > Hi all, > > I want to use python to access to https server, like > "https://212.218.229.10/chinatest/" > > If open it from IE, will see the pop-up login windows like this > > > > I tried several ways but always only get page for" HTTP Error 401.2 - > Unauthorized" error. ( myusername and mypassword are all correct) > > Below is my code: > > import urllib2 > > values = { > > 'user' : "myusername", > > "pass' : "mypassword" } > > data = urllib2.urlencode(values) > > t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) > > print t.read() > > where I am wrong ? AFAIR does urlopen() expect the password to be Base64-encoded, not urlencoded. You might also need to add an AUTH-Line. But this all does not matter, as there is more than one AUTH-Method you'd have to implement them all, but fortunately urllib2.HTTPBasicAuthHandler and urllib2.HTTPBasicAuthHandler exist. So use them: import urllib2 passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, theurl, username, password) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) urllib2.install_opener(opener) pagehandle = urllib2.urlopen(theurl) (taken from http://www.voidspace.org.uk/python/articles/authentication.shtml ) Further reference: http://www.python.org/doc/2.5.2/lib/module-urllib2.html http://www.python.org/doc/2.5.2/lib/urllib2-examples.html HTH, Michael From william302888 at gmail.com Thu Mar 4 07:42:50 2010 From: william302888 at gmail.com (jack) Date: Thu, 4 Mar 2010 04:42:50 -0800 (PST) Subject: 15541 - Best, Cheapest Web-Hosting, Domain at $1.99! Message-ID: <0ec7cefa-ea65-43c0-8d2e-8bdb4b56fb7a@t17g2000prg.googlegroups.com> World's Cheapest Rate Hosting, 99.9% Uptime US Based Dedicated Server, Fast Customer Service Register Domain only at $1.99 per Year 3 Month Hosting Free with 1 year Package http://hostwebspaces.com/ From python.list at tim.thechases.com Thu Mar 4 07:50:14 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Mar 2010 06:50:14 -0600 Subject: WANTED: A good name for the pair (args, kwargs) In-Reply-To: References: Message-ID: <4B8FAC86.4020605@tim.thechases.com> Jonathan Fine wrote: > We can call a function fn using > val = fn(*args, **kwargs) > > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > For now I'll use argpair, but if anyone has a better idea, I'll use it. In the legacy of C and Java (okay, that doesn't carry _much_ weight with me), I'd go with "varargs" to refer to the pair of (args, kwargs) -tkc From anand.shashwat at gmail.com Thu Mar 4 07:54:27 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Mar 2010 18:24:27 +0530 Subject: How to login https sever with inputing account name and password? In-Reply-To: References: Message-ID: You may also want to look into mechanize module. On Thu, Mar 4, 2010 at 6:11 PM, Michael Rudolf wrote: > Am 04.03.2010 11:38, schrieb Karen Wang: > > Hi all, >> >> I want to use python to access to https server, like >> "https://212.218.229.10/chinatest/" >> >> If open it from IE, will see the pop-up login windows like this >> >> >> >> I tried several ways but always only get page for" HTTP Error 401.2 - >> Unauthorized" error. ( myusername and mypassword are all correct) >> >> Below is my code: >> >> import urllib2 >> >> values = { >> >> 'user' : "myusername", >> >> "pass' : "mypassword" } >> >> data = urllib2.urlencode(values) >> >> t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) >> >> print t.read() >> >> where I am wrong ? >> > > AFAIR does urlopen() expect the password to be Base64-encoded, not > urlencoded. > > You might also need to add an AUTH-Line. But this all does not matter, as > there is more than one AUTH-Method you'd have to implement them all, but > fortunately urllib2.HTTPBasicAuthHandler and urllib2.HTTPBasicAuthHandler > exist. > > So use them: > > import urllib2 > passman = urllib2.HTTPPasswordMgrWithDefaultRealm() > passman.add_password(None, theurl, username, password) > authhandler = urllib2.HTTPBasicAuthHandler(passman) > opener = urllib2.build_opener(authhandler) > urllib2.install_opener(opener) > pagehandle = urllib2.urlopen(theurl) > > (taken from > http://www.voidspace.org.uk/python/articles/authentication.shtml ) > > Further reference: > http://www.python.org/doc/2.5.2/lib/module-urllib2.html > http://www.python.org/doc/2.5.2/lib/urllib2-examples.html > > HTH, > Michael > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan.booth at invalid.invalid Thu Mar 4 08:10:34 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 13:10:34 GMT Subject: NoSQL Movement? References: Message-ID: Avid Fan wrote: > Jonathan Gardner wrote: > >> >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is understood well enough that the >> general nature of the SQL database is unnecessary. >> > > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the query > language? > > Could you give some sort of example of where SQL would not be the way to > go. The only things I can think of a simple flat file databases. Probably one of the best known large non-sql databases is Google's bigtable. Xah Lee of course dismissed this as he decided to write how bad non-sql databases are without actually looking at the prime example. If you look at some of the uses of bigtable you may begin to understand the tradeoffs that are made with sql. When you use bigtable you have records with fields, and you have indices, but there are limitations on the kinds of queries you can perform: in particular you cannot do joins, but more subtly there is no guarantee that the index is up to date (so you might miss recent updates or even get data back from a query when the data no longer matches the query). By sacrificing some of SQL's power, Google get big benefits: namely updating data is a much more localised option. Instead of an update having to lock the indices while they are updated, updates to different records can happen simultaneously possibly on servers on the opposite sides of the world. You can have many, many servers all using the same data although they may not have identical or completely consistent views of that data. Bigtable impacts on how you store the data: for example you need to avoid reducing data to normal form (no joins!), its much better and cheaper just to store all the data you need directly in each record. Also aggregate values need to be at least partly pre-computed and stored in the database. Boiling this down to a concrete example, imagine you wanted to implement a system like twitter. Think carefully about how you'd handle a sufficiently high rate of new tweets reliably with a sql database. Now think how you'd do the same thing with bigtable: most tweets don't interact, so it becomes much easier to see how the load is spread across the servers: each user has the data relevant to them stored near the server they are using and index changes propagate gradually to the rest of the system. -- Duncan Booth http://kupuguy.blogspot.com From eric.brunel.pragmadev at gmail.com Thu Mar 4 08:20:43 2010 From: eric.brunel.pragmadev at gmail.com (eb303) Date: Thu, 4 Mar 2010 05:20:43 -0800 (PST) Subject: Instance factory - am I doing this right? References: Message-ID: On Mar 3, 6:41?pm, Laszlo Nagy wrote: > This is just an interesting code pattern that I have recently used: > > class CacheStorage(object): > ? ? """Generic cache storage class.""" > ? ? @classmethod > ? ? def get_factory(cls,*args,**kwargs): > ? ? ? ? """Create factory for a given set of cache storage creation > parameters.""" > ? ? ? ? class CacheStorageFactory(cls): > ? ? ? ? ? ? _construct_args = args > ? ? ? ? ? ? _construct_kwargs = kwargs > ? ? ? ? ? ? def __init__(self): > ? ? ? ? ? ? ? ? cls.__init__(self, > ? ? ? ? ? ? ? ? ? ? *self._construct_args,**self._construct_kwargs) > ? ? ? ? return CacheStorageFactory > > Then, I can create subclasses like: > > class GdbmCacheStorage(CacheStorage): > ? ? """Gdbm cache storage class. > > ? ? @param basedir: Base directory where gdbm files should be stored. > ? ? @param basename: Base name for logging and creating gdbm files. > ? ? """ > ? ? def __init__(self,basedir,basename): > ? ? ? ? ? ..... blablabla place initialization code here > > class MemoryCacheStorage(CacheStorage): > ? ? """In-Memory cache storage class. > > ? ? Please note that keys and values are always mashal-ed. > ? ? E.g. when you cache an object, it makes a deep copy. > ? ? """ > ? ? def __init__(self): > ? ? ? ? ? ..... blablabla place initialization code here > > And the finally, I can create a factory that can create cache storage > instances for storing data in gdbm in a given directory: > > cache_factory = GdbmCacheStorage.get_factory("~gandalf/db","test") > print cache_factory # > print cache_factory() > > OR I can create a factory that can create instances for storing data in > memory: > > cache_factory = MemoryCacheStorage.get_factory() > print cache_factory # > print cache_factory() # <__main__.CacheStorageFactory object at 0x8250c6c> > > Now, here is my question. Am I right in doing this? Or are there better > language tools to be used in Python for the same thing? This whole thing > about creating factories looks a bit odd for me. Is it Pythonic enough? > > Thanks, > > ? ?Laszlo Seems you try to reinvent functools: class GdbmCacheStorage(object): def __init__(self,basedir,basename): ... cache_factory = functools.partial(GdbmCacheStorage, "~gandalf/db", "test") print cache_factory() Is it what you're after? I didn't see the point in creating a "cached factory" for MemoryCacheStorage though, since it has no constructor parameters to cache anyway. So doing 'cache_factory = MemoryCacheStorage' in your example would do exactly the same thing as what you did. HTH - Eric - From phd at phd.pp.ru Thu Mar 4 08:34:05 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Thu, 4 Mar 2010 16:34:05 +0300 Subject: SQLObject 0.11.4 Message-ID: <20100304133404.GB4443@phd.pp.ru> Hello! I'm pleased to announce version 0.11.4, a minor bugfix release of 0.11 branch of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.11.4 News and changes: http://sqlobject.org/News.html What's New ========== News since 0.11.3 ----------------- * Fixed a bug in inheritance - if creation of the row failed and if the connection is not a transaction and is in autocommit mode - remove parent row(s). * Do not set _perConnection flag if get() or _init() is passed the same connection; this is often the case with select(). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From jjposner at optimum.net Thu Mar 4 08:35:05 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 04 Mar 2010 08:35:05 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b8f9267$0$17832$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4b8f9267$0$17832$426a74cc@news.free.fr> Message-ID: <4B8FB709.9080609@optimum.net> On 3/4/2010 5:59 AM, Bruno Desthuilliers wrote: >> >> I have two small ideas for improvement: - Swap the first two >> paragraphs. First say what it is, and then give the motivation. > > Mmm... As far as I'm concerned, I like it the way its. John ? I think it doesn't make very much difference. But in the end, I believe it's the student, not the teacher, who gets to decide what's comprehensible. What *does* make a difference, IMHO, is getting more people to participate in the process of shining lights into Python's darker corners. That's why I encouraged (and still encourage) Eike to roll up the sleeves and wade into these waters. Metaphor-mixingly yours, John From no.email at nospam.invalid Thu Mar 4 08:37:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 05:37:59 -0800 Subject: WANTED: A good name for the pair (args, kwargs) References: Message-ID: <7x8wa85hs8.fsf@ruckus.brouhaha.com> Jonathan Fine writes: > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > Here's my use case: > def doit(fn , wibble, expect): > args, kwargs = wibble > actual = fn(*args, **kwargs) I think this may have been broken in 3.x, but in 2.6 the compiler will unpack directly if you put a tuple structure in the arg list: def doit(fn, (args, kwargs), expect): actual = fn(*args, **kwargs) Otherwise I'd just say "all_args" or some such. Or just "args" which you unpack into "pos_args" (positional args) and "kw_args". From phd at phd.pp.ru Thu Mar 4 08:41:46 2010 From: phd at phd.pp.ru (Oleg Broytman) Date: Thu, 4 Mar 2010 16:41:46 +0300 Subject: SQLObject 0.12.2 Message-ID: <20100304134146.GF4443@phd.pp.ru> Hello! I'm pleased to announce version 0.12.2, a bugfix release of branch 0.12 of SQLObject. What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.12.2 News and changes: http://sqlobject.org/News.html What's New ========== News since 0.12.1 ----------------- * Fixed a bug in inheritance - if creation of the row failed and if the connection is not a transaction and is in autocommit mode - remove parent row(s). * Do not set _perConnection flag if get() or _init() is passed the same connection; this is often the case with select(). For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phd.pp.ru/ phd at phd.pp.ru Programmers don't die, they just GOSUB without RETURN. From bieffe62 at gmail.com Thu Mar 4 08:45:40 2010 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Thu, 4 Mar 2010 05:45:40 -0800 (PST) Subject: Passing FILE * types using ctypes References: Message-ID: On Mar 4, 12:50?am, Zeeshan Quireshi wrote: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. Or do i have to call the C library using ctypes first, > get the pointer and then pass it to my function. > > Also, is there any automated way to convert c struct and enum > definitions to ctypes data types. > > Zeeshan Python file objects have a method fileno() whic returns the 'C file descriptor', i.e. the number used by low level IO in python as well as in C. I would use this as interface between python and C and then in the C function using fdopen to get a FILE * for an already open file for which you have a file descriptor. If you don't want change the C interface, you could try using fdopen in python by loading the standard C library ang using ctypes to call the function. (I tried briefly but always get 0 from fdopen ). But if you can change the C code, why not to pass the file name? The idea of opening the file in python and manage it in C feels a bit icky ... Ciao ---- FB From cartercc at gmail.com Thu Mar 4 09:21:49 2010 From: cartercc at gmail.com (ccc31807) Date: Thu, 4 Mar 2010 06:21:49 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: On Mar 3, 4:55?pm, toby wrote: > > ?where you have to store data and > > "relational data" Data is neither relational nor unrelational. Data is data. Relationships are an artifact, something we impose on the data. Relations are for human convenience, not something inherent in the data itself. > > perform a large number of queries. > > Why does the number matter? Have you ever had to make a large number of queries to an XML database? In some ways, an XML database is the counterpart to a relational database in that the data descriptions constitute the relations. However, since the search is to the XML elements, and you can't construct indicies for XML databases in the same way you can with relational databases, a large search can take much longer that you might expect. CC. From jmg3000 at gmail.com Thu Mar 4 09:39:51 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Thu, 4 Mar 2010 06:39:51 -0800 (PST) Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <6cc20cea1003031417i15b66bcdi454bba5a9c642d95@mail.gmail.com> <871vg0bzua.fsf@castleamber.com> Message-ID: <8506d9dc-2e6d-4f66-9d55-8173f47f7d4e@i25g2000yqm.googlegroups.com> On Mar 3, 9:11?pm, John Bokma wrote: > Philip Semanchuk writes: > > > In other words, if I was a Perl user under Ubuntu would I use > > the pkg manager to add a Perl module, or CPAN, or would both work? > > Both would work, but I would make very sure to use a separate > installation directory for modules installed via CPAN. What's worked best for me is: use *only* the apt system to install modules into your system Perl (`/usr/bin/perl`) and use *only* cpan/ cpanp/cpanm to install modules into *your own* Perl (for example, you may have installed into `/opt`). > AFAIK there are also programs that pack CPAN modules/bundles into > something the package manager can use to install. Right. If you really want to install a module for which there's no Debian package, and you don't want to install your own Perl, this is a good route to take. Incidentally, this is the same way I recommend handling the situation with Python: Use only aptitude to install packages for your system Python, and use only pip to install packages into your own Python (which you built and installed elsewhere, ex., `/opt/py-2.6.4`). ---John From mrkafk at gmail.com Thu Mar 4 09:47:22 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 15:47:22 +0100 Subject: NoSQL Movement? In-Reply-To: References: Message-ID: Duncan Booth wrote: > If you look at some of the uses of bigtable you may begin to understand > the tradeoffs that are made with sql. When you use bigtable you have > records with fields, and you have indices, but there are limitations on > the kinds of queries you can perform: in particular you cannot do joins, > but more subtly there is no guarantee that the index is up to date (so > you might miss recent updates or even get data back from a query when > the data no longer matches the query). Hmm, I do understand that bigtable is used outside of traditional 'enterprisey' contexts, but suppose you did want to do an equivalent of join; is it at all practical or even possible? I guess when you're forced to use denormalized data, you have to simultaneously update equivalent columns across many tables yourself, right? Or is there some machinery to assist in that? > By sacrificing some of SQL's power, Google get big benefits: namely > updating data is a much more localised option. Instead of an update > having to lock the indices while they are updated, updates to different > records can happen simultaneously possibly on servers on the opposite > sides of the world. You can have many, many servers all using the same > data although they may not have identical or completely consistent views > of that data. And you still have the global view of the table spread across, say, 2 servers, one located in Australia, second in US? > Bigtable impacts on how you store the data: for example you need to > avoid reducing data to normal form (no joins!), its much better and > cheaper just to store all the data you need directly in each record. > Also aggregate values need to be at least partly pre-computed and stored > in the database. So you basically end up with a few big tables or just one big table really? Suppose on top of 'tweets' table you have 'dweebs' table, and tweets and dweebs sometimes do interact. How would you find such interacting pairs? Would you say "give me some tweets" to tweets table, extract all the dweeb_id keys from tweets and then retrieve all dweebs from dweebs table? > Boiling this down to a concrete example, imagine you wanted to implement > a system like twitter. Think carefully about how you'd handle a > sufficiently high rate of new tweets reliably with a sql database. Now > think how you'd do the same thing with bigtable: most tweets don't > interact, so it becomes much easier to see how the load is spread across > the servers: each user has the data relevant to them stored near the > server they are using and index changes propagate gradually to the rest > of the system. I guess that in a purely imaginary example, you could also combine two databases? Say, a tweet bigtable db contains tweet, but with column of classical customer_id key that is also a key in traditional RDBMS referencing particular customer? Regards, mk From tim.wintle at teamrubber.com Thu Mar 4 10:23:33 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 04 Mar 2010 15:23:33 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> Message-ID: <1267716213.23300.7.camel@localhost> On Wed, 2010-03-03 at 20:39 +0100, mk wrote: > Hello Tim, > > Pardon the questions but I haven't had the need to use denormalization > yet, so: > IOW you basically merged the tables like follows? > > CREATE TABLE projects ( > client_id BIGINT NOT NULL, > project_id BIGINT NOT NULL, > cost INT, > date DATETIME, > INDEX(client_id, project_id, date) > ); Yup > From what you write further in the mail I conclude that you have not > eliminated the first table, just made table projects look like I wrote > above, right? (and used stored procedures to make sure that both tables > contain the relevant data for client_id and project_id columns in both > tables) Yup > Have you had some other joins on denormalized keys? i.e. in example how > the join of hypothetical TableB with projects on projects.client_id > behave with such big tables? (bc I assume that you obviously can't > denormalize absolutely everything, so this implies the need of doing > some joins on denormalized columns like client_id). For these joins (for SELECT statements) this _can_ end up running faster - of course all of this depends on what kind of queries you normally end up getting and the distribution of data in the indexes. I've never written anything that started out with a schema like this, but several have ended up getting denormalised as the projects have matured and query behaviour has been tested > > assuming you can access the first mapping anyway - > > ? I'm not clear on what you mean here. I'm refering to not eliminating the first table as you concluded > > Regards, > mk > From tim.wintle at teamrubber.com Thu Mar 4 10:29:23 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 04 Mar 2010 15:29:23 +0000 Subject: taking python enterprise level?... In-Reply-To: <20100303162314.a46484cf.darcy@druid.net> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> <6fd094d0-0fef-4aa2-aee7-49e8b39de3ad@g19g2000yqe.googlegroups.com> <778d3ba3-cbc0-49b3-b816-1260e0295bcf@f35g2000yqd.googlegroups.com> <20100302015813.5397655e.darcy@druid.net> <1267638602.988.19.camel@localhost> <20100303162314.a46484cf.darcy@druid.net> Message-ID: <1267716563.23300.13.camel@localhost> On Wed, 2010-03-03 at 16:23 -0500, D'Arcy J.M. Cain wrote: > On Wed, 03 Mar 2010 20:39:35 +0100 > mk wrote: > > > If you denormalise the table, and update the first index to be on > > > (client_id, project_id, date) it can end up running far more quickly - > > Maybe. Don't start with denormalization. Write it properly and only > consider changing if profiling suggests that that is your bottleneck. Quite - and I'd add to cache reads as much in front end machines as is permissible in your use case before considering denormalisation. > With a decent database engine and proper design it will hardly ever be. I completely agree - I'm simply responding to the request for an example where denormalisation may be a good idea. Tim From jmg3000 at gmail.com Thu Mar 4 10:47:11 2010 From: jmg3000 at gmail.com (John Gabriele) Date: Thu, 4 Mar 2010 07:47:11 -0800 (PST) Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <87eik1ujg4.fsf@benfinney.id.au> Message-ID: <1f9fcfb3-204c-48c6-8142-9f7c2607b917@t20g2000yqe.googlegroups.com> On Mar 3, 5:30?pm, Ben Finney wrote: > > Terry Reedy writes: > > > On 3/3/2010 12:05 PM, John Nagle wrote: > > > > CPAN enforces standard organization on packages. PyPi does not. > > This is, I think, something we don't need as much in Python; there is a > fundamental difference between Perl's deeply nested namespace hierarchy > and Python's inherently flat hierarchy. What do you think that difference is? Both use nested namespaces. My understanding is that if 2 different dists contain like-named packages, and if a user installs both of them, they all just go to the same place in the user's site-packages dir. One difference I see is that the CPAN has a *lot* of dist's which constitute a very large number of modules. Keeping them organized by a semi-agreed-upon hierarchy of packages seems like a great organizational tool. ---John From robert.kern at gmail.com Thu Mar 4 10:48:41 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 09:48:41 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: >>>>> * Robert Kern: >>>>>> On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: >>>>>>> * Robert Kern: >>>>>>>> On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: >>>>>>>>> * Mike Kent: >>>>>>>>>> What's the compelling use case for this vs. a simple try/finally? >>>>>>>>> >>>>>>>>> if you thought about it you would mean a simple "try/else". >>>>>>>>> "finally" is >>>>>>>>> always executed. which is incorrect for cleanup >>>>>>>> >>>>>>>> Eh? Failed execution doesn't require cleanup? The example you >>>>>>>> gave is >>>>>>>> definitely equivalent to the try: finally: that Mike posted. >>>>>>> >>>>>>> Sorry, that's incorrect: it's not. >>>>>>> >>>>>>> With correct code (mine) cleanup for action A is only performed when >>>>>>> action A succeeds. >>>>>>> >>>>>>> With incorrect code cleanup for action A is performed when A fails. >>>>>> >>>>>> Oh? >>>>>> >>>>>> $ cat cleanup.py >>>>>> >>>>>> class Cleanup: >>>>>> def __init__( self ): >>>>>> self._actions = [] >>>>>> >>>>>> def call( self, action ): >>>>>> assert( callable( action ) ) >>>>>> self._actions.append( action ) >>>>>> >>>>>> def __enter__( self ): >>>>>> return self >>>>>> >>>>>> def __exit__( self, x_type, x_value, x_traceback ): >>>>>> while( len( self._actions ) != 0 ): >>>>>> try: >>>>>> self._actions.pop()() >>>>>> except BaseException as x: >>>>>> raise AssertionError( "Cleanup: exception during cleanup" ) >>>>>> >>>>>> def print_(x): >>>>>> print x >>>>>> >>>>>> with Cleanup() as at_cleanup: >>>>>> at_cleanup.call(lambda: print_("Cleanup executed without an >>>>>> exception.")) >>>>>> >>>>>> with Cleanup() as at_cleanup: >>>>> >>>>> *Here* is where you should >>>>> >>>>> 1) Perform the action for which cleanup is needed. >>>>> >>>>> 2) Let it fail by raising an exception. >>>>> >>>>> >>>>>> at_cleanup.call(lambda: print_("Cleanup execute with an exception.")) >>>>>> raise RuntimeError() >>>>> >>>>> With an exception raised here cleanup should of course be performed. >>>>> >>>>> And just in case you didn't notice: the above is not a test of the >>>>> example I gave. >>>>> >>>>> >>>>>> $ python cleanup.py >>>>>> Cleanup executed without an exception. >>>>>> Cleanup execute with an exception. >>>>>> Traceback (most recent call last): >>>>>> File "cleanup.py", line 28, in >>>>>> raise RuntimeError() >>>>>> RuntimeError >>>>>> >>>>>>>> The actions are always executed in your example, >>>>>>> >>>>>>> Sorry, that's incorrect. >>>>>> >>>>>> Looks like it to me. >>>>> >>>>> I'm sorry, but you're >>>>> >>>>> 1) not testing my example which you're claiming that you're >>>>> testing, and >>>> >>>> Then I would appreciate your writing a complete, runnable example that >>>> demonstrates the feature you are claiming. Because it's apparently not >>>> "ensur[ing] some desired cleanup at the end of a scope, even when the >>>> scope is exited via an exception" that you talked about in your >>>> original post. >>>> >>>> Your sketch of an example looks like mine: >>>> >>>> with Cleanup as at_cleanup: >>>> # blah blah >>>> chdir( somewhere ) >>>> at_cleanup.call( lambda: chdir( original_dir ) ) >>>> # blah blah >>>> >>>> The cleanup function gets registered immediately after the first >>>> chdir() and before the second "blah blah". Even if an exception is >>>> raised in the second "blah blah", then the cleanup function will still >>>> run. This would be equivalent to a try: finally: >>>> >>>> # blah blah #1 >>>> chdir( somewhere ) >>>> try: >>>> # blah blah #2 >>>> finally: >>>> chdir( original_dir ) >>> >>> Yes, this is equivalent code. >>> >>> The try-finally that you earlier claimed was equivalent, was not. >> >> Okay, but just because of the position of the chdir(), right? > > Yes, since it yields different results. > >>>> and not a try: else: >>>> >>>> # blah blah #1 >>>> chdir( somewhere ) >>>> try: >>>> # blah blah #2 >>>> else: >>>> chdir( original_dir ) >>> >>> This example is however meaningless except as misdirection. There are >>> infinitely many constructs that include try-finally and try-else, that >>> the with-Cleanup code is not equivalent to. It's dumb to show one such. >>> >>> Exactly what are you trying to prove here? >> >> I'm just showing you what I thought you meant when you told Mike that >> he should have used a try/else instead of try/finally. >> >>> Your earlier claims are still incorrect. >>> >>>> Now, I assumed that the behavior with respect to exceptions occurring >>>> in the first "blah blah" weren't what you were talking about because >>>> until the chdir(), there is nothing to clean up. >>>> >>>> There is no way that the example you gave translates to a try: else: >>>> as you claimed in your response to Mike Kent. >>> >>> Of course there is. >>> >>> Note that Mike wrapped the action A within the 'try': >>> >>> >>> >>> original_dir = os.getcwd() >>> try: >>> os.chdir(somewhere) >>> # Do other stuff >>> finally: >>> os.chdir(original_dir) >>> # Do other cleanup >>> >>> >>> >>> The 'finally' he used, shown above, yields incorrect behavior. >>> >>> Namely cleanup always, while 'else', in that code, can yield correct >>> behavior /provided/ that it's coded correctly: >>> >>> >>> >>> original_dir = os.getcwd() >>> try: >>> os.chdir(somewhere) >>> except Whatever: >>> # whatever, e.g. logging >>> raise >>> else: >>> try: >>> # Do other stuff >>> finally: >>> os.chdir(original_dir) >>> # Do other cleanup >>> >> >> Ah, okay. Now we're getting somewhere. Now, please note that you did >> not have any except: handling in your original example. So Mike made a >> try: finally: example to attempt to match the semantics of your code. >> When you tell him that he should 'mean a simple "try/else". "finally" >> is always executed. which is incorrect for cleanup', can you >> understand why we might think that you were saying that try: finally: >> was wrong and that you were proposing that your code was equivalent to >> some try: except: else: suite? > > No, not really. His code didn't match the semantics. Changing 'finally' > to 'else' could make it equivalent. Okay, please show me what you mean by "changing 'finally' to 'else'." I think you are being hinty again. It's not helpful. The most straightforward interpretation of those words means that you literally just want to remove the word 'finally' and replace it with 'else' in Mike's example. Obviously you don't mean that because it is a syntax error. try: else: is not a construct in Python. There is a try: except: else:, but there is no point to doing that if you don't have anything in the except: clause. Neither Mike's example nor your original one have any except: clause. Why do you think that we would interpret those words to mean that you wanted the example you give just above? >>>>> 2) not even showing anything about your earlier statements, which were >>>>> just incorrect. >>>>> >>>>> You're instead showing that my code works as it should for the case >>>>> that >>>>> you're testing, which is a bit unnecessary since I knew that, but >>>>> thanks >>>>> anyway. >>>> >>>> It's the case you seem to be talking about in your original post. >>> >>> What's this "seems"? Are you unable to read that very short post? >> >> I say "seems" because my understandings of what you meant in your >> original post and your response to Mike disagreed with one another. >> Now I see that your later posts were talking about minor discrepancy >> about which errors you wanted caught by the finally: and which you >> didn't. > > It's absolutely not a minor discrepancy whether some code is executed or > not. It can have arbitrarily large effect. And from my point of view the > discussion of that snippet has not been about what errors I "want" > caught by the 'finally'; it's been about whether two snippets of code > yield the same effect or not: Mike's code was incorrect not because it > did something else, but because as code that did something else it was > not an equivalent to the code that I posted. > > >> I was confused because it seemed that you were saying that try: >> finally: was completely wrong and that "try/else" was right. It >> confused me and at least one other person. >> >>>> , but I do ask you to acknowledge that you originally were talking >>>> about a feature that "ensure[s] some desired cleanup at the end of a >>>> scope, even when the scope is exited via an exception." >>> >>> Yes, that's what it does. >>> >>> Which is I why I wrote that. >>> >>> This should not be hard to grok. >>> >>> >>>> Do you acknowledge this? >>> >>> This seems like pure noise, to cover up that you were sputing a lot of >>> incorrect statements earlier. >> >> No, I'm just trying to clarify what you are trying to say. The above >> statement did not appear to accord with your later statement: 'if you >> thought about it you would mean a simple "try/else". "finally" is >> always executed. which is incorrect for cleanup.' It turns out that >> what you really meant was that it would be incorrect for cleanup to be >> executed when an error occurred in the chdir() itself. >> >> Now, I happen to disagree with that. > > Well, I was pretty unclear, almost hint-like, sorry about that, mea > culpa, but you have it slightly wrong. You wrote then "The example you > gave is definitely equivalent to the try: finally: that Mike posted." > And it isn't. I agree that it does behave differently with respect to when an exception is raised in chdir(). I was wrong on that point. I thought you were claiming that it behaved differently when there was an exception in the "# Do other stuff" block because you were being (and are still being) unclear. >> There are a couple of ways to do this kind of cleanup depending on the >> situation. Basically, you have several different code blocks: >> >> # 1. Record original state. >> # 2. Modify state. >> # 3. Do stuff requiring the modified state. >> # 4. Revert to the original state. >> >> Depending on where errors are expected to occur, and how the state >> needs to get modified and restored, there are different ways of >> arranging these blocks. The one Mike showed: >> >> # 1. Record original state. >> try: >> # 2. Modify state. >> # 3. Do stuff requiring the modified state. >> finally: >> # 4. Revert to the original state. >> >> And the one you prefer: >> >> # 1. Record original state. >> # 2. Modify state. >> try: >> # 3. Do stuff requiring the modified state. >> finally: >> # 4. Revert to the original state. >> >> These differ in what happens when an error occurs in block #2, the >> modification of the state. In Mike's, the cleanup code runs; in yours, >> it doesn't. For chdir(), it really doesn't matter. Reverting to the >> original state is harmless whether the original chdir() succeeds or >> fails, and chdir() is essentially atomic so if it raises an exception, >> the state did not change and nothing needs to be cleaned up. >> >> However, not all block #2s are atomic. Some are going to fail partway >> through and need to be cleaned up even though they raised an >> exception. Fortunately, cleanup can frequently be written to not care >> whether the whole thing finished or not. > > Yeah, and there are some systematic ways to handle these things. You > might look up Dave Abraham's levels of exception safety. Mostly his > approach boils down to making operations effectively atomic so as to > reduce the complexity: ideally, if an operation raises an exception, > then it has undone any side effects. > > Of course it can't undo the launching of an ICBM, for example... > > But ideally, if it could, then it should. I agree. Atomic operations like chdir() help a lot. But this is Python, and exceptions can happen in many different places. If you're not just calling an extension module function that makes a known-atomic system call, you run the risk of not having an atomic operation. > If you call the possibly failing operation "A", then that systematic > approach goes like this: if A fails, then it has cleaned up its own > mess, but if A succeeds, then it's the responsibility of the calling > code to clean up if the higher level (multiple statements) operation > that A is embedded in, fails. > > And that's what Marginean's original C++ ScopeGuard was designed for, > and what the corresponding Python Cleanup class is designed for. And try: finally:, for that matter. >> Both formulations can be correct (and both work perfectly fine with >> the chdir() example being used). Sometimes one is better than the >> other, and sometimes not. You can achieve both ways with either your >> Cleanup class or with try: finally:. >> >> I am still of the opinion that Cleanup is not an improvement over try: >> finally: and has the significant ugliness of forcing cleanup code into >> callables. This significantly limits what you can do in your cleanup >> code. > > Uhm, not really. :-) As I see it. Well, not being able to affect the namespace is a significant limitation. Sometimes you need to delete objects from the namespace in order to ensure that their refcounts go to zero and their cleanup code gets executed. Tracebacks will keep the namespace alive and all objects in it. -- 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 From alfps at start.no Thu Mar 4 10:48:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 16:48:41 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Jean-Michel Pichavant: > Alf P. Steinbach wrote: >>> From your post, the scope guard technique is used "to ensure some >>> desired cleanup at the end of a scope, even when the scope is exited >>> via an exception." This is precisely what the try: finally: syntax is >>> for. >> >> You'd have to nest it. That's ugly. And more importantly, now two >> people in this thread (namely you and Mike) have demonstrated that >> they do not grok the try functionality and manage to write incorrect >> code, even arguing that it's correct when informed that it's not, so >> it's a pretty fragile construct, like goto. > > You want to execute some cleanup when things go wrong, use try except. > You want to do it when things go right, use try else. You want to > cleanup no matter what happen, use try finally. > > There is no need of any Cleanup class, except for some technical > alternative concern. Have you considered that your argument applies to the "with" construct? You have probably not realized that. But let me force it on you: when would you use "with"? Check if that case is covered by your argument above. Now that you've been told about the "with" angle, don't you think it's a kind of weakness in your argument that it calls for removing "with" from the language? I recommend that you think about why your argument is invalid. Or, as I like to say, why your argument is completely bogus. Cheers & hth., - Alf From joe.hrbek at gmail.com Thu Mar 4 10:57:18 2010 From: joe.hrbek at gmail.com (Sneaky Wombat) Date: Thu, 4 Mar 2010 07:57:18 -0800 (PST) Subject: loop over list and process into groups Message-ID: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> [ {'vlan_or_intf': 'VLAN2021'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2022'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi7/33'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2051'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'}, {'vlan_or_intf': 'VLAN2052'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'},] I want it to be converted to: [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] I was going to write a def to loop through and look for certain pre- compiled regexs, and then put them in a new dictionary and append to a list, but I'm having trouble thinking of a good way to capture each dictionary. Each dictionary will have a key that is the vlan and the value will be a list of interfaces that participate in that vlan. Each list will be variable, many containing only one interface and some containing many interfaces. I thought about using itertools, but i only use that for fixed data. I don't know of a good way to loop over variably sized data. I was wondering if anyone had any ideas about a good way to convert this list or dictionary into the right format that I need. The solution I come up with will most likely be ugly and error prone, so I thought i'd ask this python list while I work. Hopefully I learn a better way to solve this problem. Thanks! I also have the data in a list, [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] From robert.kern at gmail.com Thu Mar 4 11:04:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 10:04:02 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: > * Jean-Michel Pichavant: >> Alf P. Steinbach wrote: >>>> From your post, the scope guard technique is used "to ensure some >>>> desired cleanup at the end of a scope, even when the scope is exited >>>> via an exception." This is precisely what the try: finally: syntax >>>> is for. >>> >>> You'd have to nest it. That's ugly. And more importantly, now two >>> people in this thread (namely you and Mike) have demonstrated that >>> they do not grok the try functionality and manage to write incorrect >>> code, even arguing that it's correct when informed that it's not, so >>> it's a pretty fragile construct, like goto. >> >> You want to execute some cleanup when things go wrong, use try except. >> You want to do it when things go right, use try else. You want to >> cleanup no matter what happen, use try finally. >> >> There is no need of any Cleanup class, except for some technical >> alternative concern. > > Have you considered that your argument applies to the "with" construct? > > You have probably not realized that. > > But let me force it on you: when would you use "with"? When there is a specific context manager that removes the need for boilerplate. > Check if that case is covered by your argument above. > > Now that you've been told about the "with" angle, don't you think it's a > kind of weakness in your argument that it calls for removing "with" from > the language? No, it only argues that "with Cleanup():" is supernumerary. -- 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 From python at mrabarnett.plus.com Thu Mar 4 11:14:01 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Mar 2010 16:14:01 +0000 Subject: My four-yorkshireprogrammers contribution In-Reply-To: <7v9e3rFl7mU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> Message-ID: <4B8FDC49.5070801@mrabarnett.plus.com> Gregory Ewing wrote: > MRAB wrote: > >> Mk14 from Science of Cambridge, a kit with hex keypad and 7-segment >> display, which I had to solder together, and also make my own power >> supply. I had the extra RAM and the I/O chip, so that's 256B (including >> the memory used by the monitor) + 256B additional RAM + 128B more in the >> I/O chip. > > Luxury! Mine was a Miniscamp, based on a design published in > Electronics Australia in the 70s. 256 bytes RAM, 8 switches > for input, 8 LEDs for output. No ROM -- program had to be > toggled in each time. > > Looked something like this: > > http://oldcomputermuseum.com/mini_scamp.html > > except that mine wasn't built from a kit and didn't look > quite as professional as that one. > [snip] By the standards of just a few years later, that's not so much a microcomputer as a nanocomputer! I was actually interested in electronics at the time, and it was such things as Mk14 which lead me into computing. From jeanmichel at sequans.com Thu Mar 4 11:32:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 17:32:10 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <4B8FE08A.60005@sequans.com> Alf P. Steinbach wrote: > * Jean-Michel Pichavant: >> Alf P. Steinbach wrote: >>>> From your post, the scope guard technique is used "to ensure some >>>> desired cleanup at the end of a scope, even when the scope is >>>> exited via an exception." This is precisely what the try: finally: >>>> syntax is for. >>> >>> You'd have to nest it. That's ugly. And more importantly, now two >>> people in this thread (namely you and Mike) have demonstrated that >>> they do not grok the try functionality and manage to write incorrect >>> code, even arguing that it's correct when informed that it's not, so >>> it's a pretty fragile construct, like goto. >> >> You want to execute some cleanup when things go wrong, use try >> except. You want to do it when things go right, use try else. You >> want to cleanup no matter what happen, use try finally. >> >> There is no need of any Cleanup class, except for some technical >> alternative concern. > > Have you considered that your argument applies to the "with" construct? > > You have probably not realized that. > > But let me force it on you: when would you use "with"? > > Check if that case is covered by your argument above. > > Now that you've been told about the "with" angle, don't you think it's > a kind of weakness in your argument that it calls for removing "with" > from the language? > > I recommend that you think about why your argument is invalid. > > Or, as I like to say, why your argument is completely bogus. > > > Cheers & hth., > > - Alf I am using python 2.5, so I know nothing about the with statement, and it may possible my arguments apply to it, you could remove it from the language, it wouldn't bother me at all. I just don't see in what you've written (adding a class, with some __entry__, __exit__ protocol, using a with statement) what cannot be achieved with a try statement in its simpliest form. Try except may be lame and noobish, but it works, is easy to read and understood at first glance. It looks like to me that 'with' statements are like decorators: overrated. Sometimes people could write simple readable code, but yet they're tempted by the geek side of programming: using complex constructs when there's no need to. I myself cannot resist sometimes ;-) JM From steve at holdenweb.com Thu Mar 4 11:32:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 11:32:11 -0500 Subject: How to login https sever with inputing account name and password? In-Reply-To: <20100304103731.740AC40E@smtpcom.263xmail.com> References: <20100304103731.740AC40E@smtpcom.263xmail.com> Message-ID: Karen Wang wrote: > Hi all, > > I want to use python to access to https server, like > ?https://212.218.229.10/chinatest/? > > If open it from IE, will see the pop-up login windows like this > > I tried several ways but always only get page for? HTTP Error 401.2 ? > Unauthorized? error. ( myusername and mypassword are all correct) > > Below is my code: > > import urllib2 > > values = { > > 'user' : "myusername", > > ?pass' : "mypassword" } > > data = urllib2.urlencode(values) > > t = urllib2.urlopen('https://212.218.229.10/chinatest/',data) > > print t.read() > > where I am wrong ? > Read the HTTP standard. The authentication data has to be send as HTTP headers, not as the data to a POST request. The dialog box you see is the browser attempting to collect the data it needs to put in the header. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at bdurham.com Thu Mar 4 11:37:31 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 04 Mar 2010 11:37:31 -0500 Subject: My four-yorkshireprogrammers contribution In-Reply-To: <4B8FDC49.5070801@mrabarnett.plus.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> <4B8FDC49.5070801@mrabarnett.plus.com> Message-ID: <1267720651.17005.1363119347@webmail.messagingengine.com> Not to out do you guys, but over here in the states, I started out with a Radio Shack 'computer' that consisted of 10 slideable switches and 10 flashlight bulbs. You ran wires betweens the slideable switches to create 'programs'. Wish I could remember what this thing was called - my google-fu fails me. This was approx 1976 when Popular Science's ELF-1 with 256 bytes was quite a sensation. Cheers, Malcolm From magnicida at gmail.com Thu Mar 4 11:51:21 2010 From: magnicida at gmail.com (Juan Pedro Bolivar Puente) Date: Thu, 04 Mar 2010 18:51:21 +0200 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: On 04/03/10 16:21, ccc31807 wrote: > On Mar 3, 4:55 pm, toby wrote: >>> where you have to store data and >> >> "relational data" > > Data is neither relational nor unrelational. Data is data. > Relationships are an artifact, something we impose on the data. > Relations are for human convenience, not something inherent in the > data itself. > No, relations are data. "Data is data" says nothing. Data is information. Actually, all data are relations: relating /values/ to /properties/ of /entities/. Relations as understood by the "relational model" is nothing else but assuming that properties and entities are first class values of the data system and the can also be related. JP From mrkafk at gmail.com Thu Mar 4 11:55:10 2010 From: mrkafk at gmail.com (mk) Date: Thu, 04 Mar 2010 17:55:10 +0100 Subject: loop over list and process into groups In-Reply-To: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: Sneaky Wombat wrote: > I was going to write a def to loop through and look for certain pre- > compiled regexs, and then put them in a new dictionary and append to a > list, regexes are overkill in this case I think. > [ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] Why not construct an intermediate dictionary? elems = [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] def makeintermdict(elems): vd = {} vlan = None for el in elems: if el.startswith('VLAN'): vlan = el.replace('VLAN','') elif el == 'Interface': vd[vlan] = [] else: vd[vlan].append(el) return vd def makelist(interm): finlist = [] for k in interm.keys(): finlist.append({k:interm[k]}) return finlist if __name__ == "__main__": intermediate = makeintermdict(elems) print intermediate finlist = makelist(intermediate) print 'final', finlist {'4068': ['Gi9/6'], '4069': ['Gi9/6'], '4065': ['Gi9/6', 'Po2', 'Po3', 'Po306']} final [{'4068': ['Gi9/6']}, {'4069': ['Gi9/6']}, {'4065': ['Gi9/6', 'Po2', 'Po3', 'Po306']}] I hope this is not your homework. :-) Regards, mk From alfps at start.no Thu Mar 4 11:56:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 17:56:34 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >> * Robert Kern: [snip] >>> can you >>> understand why we might think that you were saying that try: finally: >>> was wrong and that you were proposing that your code was equivalent to >>> some try: except: else: suite? >> >> No, not really. His code didn't match the semantics. Changing 'finally' >> to 'else' could make it equivalent. > > Okay, please show me what you mean by "changing 'finally' to 'else'." I > think you are being hinty again. It's not helpful. [snip middle of this paragraph] > Why do you think that we would interpret those words > to mean that you wanted the example you give just above? There's an apparent discrepancy between your call for an example and your subsequent (in the same paragraph) reference to the example given. But as to why I assumed that that example, or a similar correct one, would be implied, it's the only meaningful interpretation. Adopting a meaningless interpretation when a meaningful exists is generally just adversarial, but in this case I was, as you pointed out, extremely unclear, and I'm sorry: I should have given such example up front. Will try to do so. [snip] > >>> There are a couple of ways to do this kind of cleanup depending on the >>> situation. Basically, you have several different code blocks: >>> >>> # 1. Record original state. >>> # 2. Modify state. >>> # 3. Do stuff requiring the modified state. >>> # 4. Revert to the original state. >>> >>> Depending on where errors are expected to occur, and how the state >>> needs to get modified and restored, there are different ways of >>> arranging these blocks. The one Mike showed: >>> >>> # 1. Record original state. >>> try: >>> # 2. Modify state. >>> # 3. Do stuff requiring the modified state. >>> finally: >>> # 4. Revert to the original state. >>> >>> And the one you prefer: >>> >>> # 1. Record original state. >>> # 2. Modify state. >>> try: >>> # 3. Do stuff requiring the modified state. >>> finally: >>> # 4. Revert to the original state. >>> >>> These differ in what happens when an error occurs in block #2, the >>> modification of the state. In Mike's, the cleanup code runs; in yours, >>> it doesn't. For chdir(), it really doesn't matter. Reverting to the >>> original state is harmless whether the original chdir() succeeds or >>> fails, and chdir() is essentially atomic so if it raises an exception, >>> the state did not change and nothing needs to be cleaned up. >>> >>> However, not all block #2s are atomic. Some are going to fail partway >>> through and need to be cleaned up even though they raised an >>> exception. Fortunately, cleanup can frequently be written to not care >>> whether the whole thing finished or not. >> >> Yeah, and there are some systematic ways to handle these things. You >> might look up Dave Abraham's levels of exception safety. Mostly his >> approach boils down to making operations effectively atomic so as to >> reduce the complexity: ideally, if an operation raises an exception, >> then it has undone any side effects. >> >> Of course it can't undo the launching of an ICBM, for example... >> >> But ideally, if it could, then it should. > > I agree. Atomic operations like chdir() help a lot. But this is Python, > and exceptions can happen in many different places. If you're not just > calling an extension module function that makes a known-atomic system > call, you run the risk of not having an atomic operation. > >> If you call the possibly failing operation "A", then that systematic >> approach goes like this: if A fails, then it has cleaned up its own >> mess, but if A succeeds, then it's the responsibility of the calling >> code to clean up if the higher level (multiple statements) operation >> that A is embedded in, fails. >> >> And that's what Marginean's original C++ ScopeGuard was designed for, >> and what the corresponding Python Cleanup class is designed for. > > And try: finally:, for that matter. Not to mention "with". Some other poster made the same error recently in this thread; it is a common fallacy in discussions about programming, to assume that since the same can be expressed using lower level constructs, those are all that are required. If adopted as true it ultimately means the removal of all control structures above the level of "if" and "goto" (except Python doesn't have "goto"). >>> Both formulations can be correct (and both work perfectly fine with >>> the chdir() example being used). Sometimes one is better than the >>> other, and sometimes not. You can achieve both ways with either your >>> Cleanup class or with try: finally:. >>> >>> I am still of the opinion that Cleanup is not an improvement over try: >>> finally: and has the significant ugliness of forcing cleanup code into >>> callables. This significantly limits what you can do in your cleanup >>> code. >> >> Uhm, not really. :-) As I see it. > > Well, not being able to affect the namespace is a significant > limitation. Sometimes you need to delete objects from the namespace in > order to ensure that their refcounts go to zero and their cleanup code > gets executed. Just a nit (I agree that a lambda can't do this, but as to what's required): assigning None is sufficient for that[1]. However, note that the current language doesn't guarantee such cleanup, at least as far as I know. So while it's good practice to support it, to do everything to let it happen, it's presumably bad practice to rely on it happening. > Tracebacks will keep the namespace alive and all objects > in it. Thanks!, I hadn't thought of connecting that to general cleanup actions. It limits the use of general "with" in the same way. Cheers, - Alf Notes: [1] An 'except' clause deletes variables, but since it has no knowledge of the code it's placed in the only alternatives would be a presumably costly check of prior existence, or letting it pollute the namespace. From robert.kern at gmail.com Thu Mar 4 12:00:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 11:00:32 -0600 Subject: A "scopeguard" for Python In-Reply-To: <4B8FE08A.60005@sequans.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <4B8FE08A.60005@sequans.com> Message-ID: On 2010-03-04 10:32 AM, Jean-Michel Pichavant wrote: > Alf P. Steinbach wrote: >> * Jean-Michel Pichavant: >>> Alf P. Steinbach wrote: >>>>> From your post, the scope guard technique is used "to ensure some >>>>> desired cleanup at the end of a scope, even when the scope is >>>>> exited via an exception." This is precisely what the try: finally: >>>>> syntax is for. >>>> >>>> You'd have to nest it. That's ugly. And more importantly, now two >>>> people in this thread (namely you and Mike) have demonstrated that >>>> they do not grok the try functionality and manage to write incorrect >>>> code, even arguing that it's correct when informed that it's not, so >>>> it's a pretty fragile construct, like goto. >>> >>> You want to execute some cleanup when things go wrong, use try >>> except. You want to do it when things go right, use try else. You >>> want to cleanup no matter what happen, use try finally. >>> >>> There is no need of any Cleanup class, except for some technical >>> alternative concern. >> >> Have you considered that your argument applies to the "with" construct? >> >> You have probably not realized that. >> >> But let me force it on you: when would you use "with"? >> >> Check if that case is covered by your argument above. >> >> Now that you've been told about the "with" angle, don't you think it's >> a kind of weakness in your argument that it calls for removing "with" >> from the language? >> >> I recommend that you think about why your argument is invalid. >> >> Or, as I like to say, why your argument is completely bogus. >> >> >> Cheers & hth., >> >> - Alf > I am using python 2.5, so I know nothing about the with statement, You can try it out using "from __future__ import with_statement". > and > it may possible my arguments apply to it, you could remove it from the > language, it wouldn't bother me at all. > I just don't see in what you've written (adding a class, with some > __entry__, __exit__ protocol, using a with statement) what cannot be > achieved with a try statement in its simpliest form. > > Try except may be lame and noobish, but it works, is easy to read and > understood at first glance. > It looks like to me that 'with' statements are like decorators: > overrated. Sometimes people could write simple readable code, but yet > they're tempted by the geek side of programming: using complex > constructs when there's no need to. I myself cannot resist sometimes ;-) PEP 343 is a good introduction to the real uses of the with: statement. http://www.python.org/dev/peps/pep-0343/ Basically, it allows you to package up your initialization and cleanup code into objects, stick them in your library, unit test them thoroughly, etc. so you don't have to repeat them everywhere and possibly get them wrong. It's DRY in action. Where Alf's Cleanup class goes wrong, in my opinion, is that it does not package up any code to avoid repetition. You still repeat the same cleanup code everywhere you use it, so it is no better than try: finally:. It is not a real use case of the with: statement. -- 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 From alfps at start.no Thu Mar 4 12:02:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 18:02:23 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: >> * Jean-Michel Pichavant: >>> Alf P. Steinbach wrote: >>>>> From your post, the scope guard technique is used "to ensure some >>>>> desired cleanup at the end of a scope, even when the scope is exited >>>>> via an exception." This is precisely what the try: finally: syntax >>>>> is for. >>>> >>>> You'd have to nest it. That's ugly. And more importantly, now two >>>> people in this thread (namely you and Mike) have demonstrated that >>>> they do not grok the try functionality and manage to write incorrect >>>> code, even arguing that it's correct when informed that it's not, so >>>> it's a pretty fragile construct, like goto. >>> >>> You want to execute some cleanup when things go wrong, use try except. >>> You want to do it when things go right, use try else. You want to >>> cleanup no matter what happen, use try finally. >>> >>> There is no need of any Cleanup class, except for some technical >>> alternative concern. >> >> Have you considered that your argument applies to the "with" construct? >> >> You have probably not realized that. >> >> But let me force it on you: when would you use "with"? > > When there is a specific context manager that removes the need for > boilerplate. That's "cleanup no matter what happen". >> Check if that case is covered by your argument above. >> >> Now that you've been told about the "with" angle, don't you think it's a >> kind of weakness in your argument that it calls for removing "with" from >> the language? > > No, it only argues that "with Cleanup():" is supernumerary. I don't know what "supernumerary" means, but to the degree that the argument says anything about a construct that is not 'finally', it says the same about general "with". So whatever you mean by supernumerary, you're saying that the argument implies that "with" is supernumerary. This is starting to look like some earlier discussions in this group, where even basic logic is denied. Cheers, - Alf From robert.kern at gmail.com Thu Mar 4 12:20:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 11:20:20 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >>> * Robert Kern: > [snip] >>>> can you >>>> understand why we might think that you were saying that try: finally: >>>> was wrong and that you were proposing that your code was equivalent to >>>> some try: except: else: suite? >>> >>> No, not really. His code didn't match the semantics. Changing 'finally' >>> to 'else' could make it equivalent. >> >> Okay, please show me what you mean by "changing 'finally' to 'else'." >> I think you are being hinty again. It's not helpful. > [snip middle of this paragraph] >> Why do you think that we would interpret those words to mean that you >> wanted the example you give just above? > > There's an apparent discrepancy between your call for an example and > your subsequent (in the same paragraph) reference to the example given. > > But as to why I assumed that that example, or a similar correct one, > would be implied, it's the only meaningful interpretation. > > Adopting a meaningless interpretation when a meaningful exists is > generally just adversarial, but in this case I was, as you pointed out, > extremely unclear, and I'm sorry: I should have given such example up > front. Will try to do so. Thank you. I appreciate it. > [snip] >> >>>> There are a couple of ways to do this kind of cleanup depending on the >>>> situation. Basically, you have several different code blocks: >>>> >>>> # 1. Record original state. >>>> # 2. Modify state. >>>> # 3. Do stuff requiring the modified state. >>>> # 4. Revert to the original state. >>>> >>>> Depending on where errors are expected to occur, and how the state >>>> needs to get modified and restored, there are different ways of >>>> arranging these blocks. The one Mike showed: >>>> >>>> # 1. Record original state. >>>> try: >>>> # 2. Modify state. >>>> # 3. Do stuff requiring the modified state. >>>> finally: >>>> # 4. Revert to the original state. >>>> >>>> And the one you prefer: >>>> >>>> # 1. Record original state. >>>> # 2. Modify state. >>>> try: >>>> # 3. Do stuff requiring the modified state. >>>> finally: >>>> # 4. Revert to the original state. >>>> >>>> These differ in what happens when an error occurs in block #2, the >>>> modification of the state. In Mike's, the cleanup code runs; in yours, >>>> it doesn't. For chdir(), it really doesn't matter. Reverting to the >>>> original state is harmless whether the original chdir() succeeds or >>>> fails, and chdir() is essentially atomic so if it raises an exception, >>>> the state did not change and nothing needs to be cleaned up. >>>> >>>> However, not all block #2s are atomic. Some are going to fail partway >>>> through and need to be cleaned up even though they raised an >>>> exception. Fortunately, cleanup can frequently be written to not care >>>> whether the whole thing finished or not. >>> >>> Yeah, and there are some systematic ways to handle these things. You >>> might look up Dave Abraham's levels of exception safety. Mostly his >>> approach boils down to making operations effectively atomic so as to >>> reduce the complexity: ideally, if an operation raises an exception, >>> then it has undone any side effects. >>> >>> Of course it can't undo the launching of an ICBM, for example... >>> >>> But ideally, if it could, then it should. >> >> I agree. Atomic operations like chdir() help a lot. But this is >> Python, and exceptions can happen in many different places. If you're >> not just calling an extension module function that makes a >> known-atomic system call, you run the risk of not having an atomic >> operation. >> >>> If you call the possibly failing operation "A", then that systematic >>> approach goes like this: if A fails, then it has cleaned up its own >>> mess, but if A succeeds, then it's the responsibility of the calling >>> code to clean up if the higher level (multiple statements) operation >>> that A is embedded in, fails. >>> >>> And that's what Marginean's original C++ ScopeGuard was designed for, >>> and what the corresponding Python Cleanup class is designed for. >> >> And try: finally:, for that matter. > > Not to mention "with". > > Some other poster made the same error recently in this thread; it is a > common fallacy in discussions about programming, to assume that since > the same can be expressed using lower level constructs, those are all > that are required. > > If adopted as true it ultimately means the removal of all control > structures above the level of "if" and "goto" (except Python doesn't > have "goto"). What I'm trying to explain is that the with: statement has a use even if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: does not mean that the with: statement doesn't improve on try: finally:. >>>> Both formulations can be correct (and both work perfectly fine with >>>> the chdir() example being used). Sometimes one is better than the >>>> other, and sometimes not. You can achieve both ways with either your >>>> Cleanup class or with try: finally:. >>>> >>>> I am still of the opinion that Cleanup is not an improvement over try: >>>> finally: and has the significant ugliness of forcing cleanup code into >>>> callables. This significantly limits what you can do in your cleanup >>>> code. >>> >>> Uhm, not really. :-) As I see it. >> >> Well, not being able to affect the namespace is a significant >> limitation. Sometimes you need to delete objects from the namespace in >> order to ensure that their refcounts go to zero and their cleanup code >> gets executed. > > Just a nit (I agree that a lambda can't do this, but as to what's > required): assigning None is sufficient for that[1]. Yes, but no callable is going to allow you to assign None to names in that namespace, either. Not without sys._getframe() hackery, in any case. > However, note that the current language doesn't guarantee such cleanup, > at least as far as I know. > > So while it's good practice to support it, to do everything to let it > happen, it's presumably bad practice to rely on it happening. > > >> Tracebacks will keep the namespace alive and all objects in it. > > Thanks!, I hadn't thought of connecting that to general cleanup actions. > > It limits the use of general "with" in the same way. Not really. It's easy to write context managers that do that. You put the initialization code in the __enter__() method, assign whatever objects you want to keep around through the with: clause as attributes on the manager, then delete those attributes in the __exit__(). Or, you use the @contextmanager decorator to turn a generator into a context manager, and you just assign to local variables and del them in the finally: clause. What you can't do is write a generic context manager where the initialization happens inside the with: clause and the cleanup actions are registered callables. That does not allow you to affect the namespace. -- 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 From lbolla at gmail.com Thu Mar 4 12:29:46 2010 From: lbolla at gmail.com (lbolla) Date: Thu, 4 Mar 2010 09:29:46 -0800 (PST) Subject: memory usage, temporary and otherwise References: Message-ID: <41c42ec5-1939-48f8-84e3-b8748161b524@g28g2000yqh.googlegroups.com> On Mar 4, 12:24?pm, Duncan Booth wrote: > > ?>>> a={} > ?>>> for i in range(10000000): > ... ? ? a[i]=intern('spam'*10) > "intern": another name borrowed from Lisp? From robert.kern at gmail.com Thu Mar 4 12:30:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 11:30:03 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 11:02 AM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: >>> * Jean-Michel Pichavant: >>>> Alf P. Steinbach wrote: >>>>>> From your post, the scope guard technique is used "to ensure some >>>>>> desired cleanup at the end of a scope, even when the scope is exited >>>>>> via an exception." This is precisely what the try: finally: syntax >>>>>> is for. >>>>> >>>>> You'd have to nest it. That's ugly. And more importantly, now two >>>>> people in this thread (namely you and Mike) have demonstrated that >>>>> they do not grok the try functionality and manage to write incorrect >>>>> code, even arguing that it's correct when informed that it's not, so >>>>> it's a pretty fragile construct, like goto. >>>> >>>> You want to execute some cleanup when things go wrong, use try except. >>>> You want to do it when things go right, use try else. You want to >>>> cleanup no matter what happen, use try finally. >>>> >>>> There is no need of any Cleanup class, except for some technical >>>> alternative concern. >>> >>> Have you considered that your argument applies to the "with" construct? >>> >>> You have probably not realized that. >>> >>> But let me force it on you: when would you use "with"? >> >> When there is a specific context manager that removes the need for >> boilerplate. > > That's "cleanup no matter what happen". For the "# Do stuff" block, yes. For the initialization block, you can write a context manager to do it either way, as necessary. >>> Check if that case is covered by your argument above. >>> >>> Now that you've been told about the "with" angle, don't you think it's a >>> kind of weakness in your argument that it calls for removing "with" from >>> the language? >> >> No, it only argues that "with Cleanup():" is supernumerary. > > I don't know what "supernumerary" means, http://www.merriam-webster.com/dictionary/supernumerary > but to the degree that the > argument says anything about a construct that is not 'finally', it says > the same about general "with". He's ignorant of the use cases of the with: statement, true. Given only your example of the with: statement, it is hard to fault him for thinking that try: finally: wouldn't suffice. -- 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 From joe.hrbek at gmail.com Thu Mar 4 12:41:45 2010 From: joe.hrbek at gmail.com (Sneaky Wombat) Date: Thu, 4 Mar 2010 09:41:45 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: On Mar 4, 10:55?am, mk wrote: > Sneaky Wombat wrote: > > I was going to write a def to loop through and look for certain pre- > > compiled regexs, and then put them in a new dictionary and append to a > > list, > > regexes are overkill in this case I think. > > > [ 'VLAN4065', > > ?'Interface', > > ?'Gi9/6', > > ?'Po2', > > ?'Po3', > > ?'Po306', > > ?'VLAN4068', > > ?'Interface', > > ?'Gi9/6', > > ?'VLAN4069', > > ?'Interface', > > ?'Gi9/6',] > > Why not construct an intermediate dictionary? > > elems = [ 'VLAN4065', > ? 'Interface', > ? 'Gi9/6', > ? 'Po2', > ? 'Po3', > ? 'Po306', > ? 'VLAN4068', > ? 'Interface', > ? 'Gi9/6', > ? 'VLAN4069', > ? 'Interface', > ? 'Gi9/6',] > > def makeintermdict(elems): > ? ? ?vd = {} > ? ? ?vlan = None > ? ? ?for el in elems: > ? ? ? ? ?if el.startswith('VLAN'): > ? ? ? ? ? ? ?vlan = el.replace('VLAN','') > ? ? ? ? ?elif el == 'Interface': > ? ? ? ? ? ? ?vd[vlan] = [] > ? ? ? ? ?else: > ? ? ? ? ? ? ?vd[vlan].append(el) > ? ? ?return vd > > def makelist(interm): > ? ? ?finlist = [] > ? ? ?for k in interm.keys(): > ? ? ? ? ?finlist.append({k:interm[k]}) > ? ? ?return finlist > > if __name__ == "__main__": > ? ? ?intermediate = makeintermdict(elems) > ? ? ?print intermediate > ? ? ?finlist = makelist(intermediate) > ? ? ?print 'final', finlist > > {'4068': ['Gi9/6'], '4069': ['Gi9/6'], '4065': ['Gi9/6', 'Po2', 'Po3', > 'Po306']} > final [{'4068': ['Gi9/6']}, {'4069': ['Gi9/6']}, {'4065': ['Gi9/6', > 'Po2', 'Po3', 'Po306']}] > > I hope this is not your homework. :-) > > Regards, > mk Thanks mk, My approach was a lot more complex than yours, but your's is better. I like itertools and was using islice to create tuples for (start,end) string slicing. Too much work though. Thanks! -j From gneuner2 at comcast.net Thu Mar 4 12:44:23 2010 From: gneuner2 at comcast.net (George Neuner) Date: Thu, 04 Mar 2010 12:44:23 -0500 Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: <6iqvo5hvlnpci5oi5rgs1ohpj085s12o6n@4ax.com> On Thu, 04 Mar 2010 18:51:21 +0200, Juan Pedro Bolivar Puente wrote: >On 04/03/10 16:21, ccc31807 wrote: >> On Mar 3, 4:55 pm, toby wrote: >>>> where you have to store data and >>> >>> "relational data" >> >> Data is neither relational nor unrelational. Data is data. >> Relationships are an artifact, something we impose on the data. >> Relations are for human convenience, not something inherent in the >> data itself. >> > >No, relations are data. "Data is data" says nothing. Data is >information. Actually, all data are relations: relating /values/ to >/properties/ of /entities/. Relations as understood by the "relational >model" is nothing else but assuming that properties and entities are >first class values of the data system and the can also be related. Well ... sort of. Information is not data but rather the understanding of something represented by the data. The term "information overload" is counter-intuitive ... it really means an excess of data for which there is little understanding. Similarly, at the level to which you are referring, a relation is not data but simply a theoretical construct. At this level testable properties or instances of the relation are data, but the relation itself is not. The relation may be data at a higher level. George From spamfresser at ch3ka.de Thu Mar 4 12:50:32 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 18:50:32 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Am 04.03.2010 18:20, schrieb Robert Kern: > > What I'm trying to explain is that the with: statement has a use even if > Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: > does not mean that the with: statement doesn't improve on try: finally:. Yes, the with-statement rocks :) I suggested such a thing a few days ago in another thread, where OP wanted a "silent" keyword like: silent: do_stuff() would be equivalent to: try: do_stuff() except: pass Of course catching *all* exceptions was a bad idea, so I came up with the code below and now I actually like it and use it myself :) ---------snip--------- To your first question about a "silenced" keyword: you could emulate this with context managers I guess. Something like (untested, just a quick mockup how it could look): class silenced: def __init__(self, *silenced): self.exceptions=tuple(silenced) #just to be explicit def __enter__(self): return self #dito def __exit__(self, type, value, traceback): for ex in self.exceptions: if isinstance(value, ex): return True #supresses exception So: with silenced(os.Error): os.remove(somefile) Would translate to: try: os.remove(somefile) except os.Error: pass One nice thing about this approach would be that you can alias a set of exceptions with this: idontcareabouttheseerrors=silenced(TypeError, ValueError, PEBCAKError, SyntaxError, EndOfWorldError, 1D10T_Error) with idontcareabouttheseerrors: do_stuff() Regards, Michael From cartercc at gmail.com Thu Mar 4 12:52:06 2010 From: cartercc at gmail.com (ccc31807) Date: Thu, 4 Mar 2010 09:52:06 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: <7bfeffcd-722e-4df4-8455-7710207d9c7e@a18g2000yqc.googlegroups.com> On Mar 4, 11:51?am, Juan Pedro Bolivar Puente wrote: > No, relations are data. This depends on your definition of 'data.' I would say that relationships is information gleaned from the data. > "Data is data" says nothing. Data is > information. To me, data and information are not the same thing, and in particular, data is NOT information. To me, information consists of the sifting, sorting, filtering, and rearrangement of data that can be useful in completing some task. As an illustration, consider some very large collection of ones and zeros -- the information it contains depends on whether it's views as a JPEG, an EXE, XML, WAV, or other sort of information processing device. Whichever way it's processed, the 'data' (the ones and zeros) stay the same, and do not constitute 'information' in their raw state. > Actually, all data are relations: relating /values/ to > /properties/ of /entities/. Relations as understood by the "relational > model" is nothing else but assuming that properties and entities are > first class values of the data system and the can also be related. Well, this sort of illustrates my point. The 'values' of 'properties' relating to specific 'entities' depends on how one processes the data, which can be processed various ways. For example, 10000001 can either be viewed as the decimal number 65 or the alpha character 'A' but the decision as to how to view this value isn't inherent in the data itself, but only as an artifact of our use of the data to turn it into information. CC. From spamfresser at ch3ka.de Thu Mar 4 12:55:18 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 04 Mar 2010 18:55:18 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Am 04.03.2010 17:32, schrieb Jean-Michel Pichavant: > It looks like to me that 'with' statements are like decorators: overrated. Oh no, you just insulted my favourite two python features, followed immediately by generators, iterators and list comprehensions / generator expressions :p No, really: they *are* great ;D Regards, Michael From gnewsg at gmail.com Thu Mar 4 12:57:40 2010 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 4 Mar 2010 09:57:40 -0800 (PST) Subject: ANN: psutil 0.1.3 released Message-ID: <39a8f505-2caa-4592-a359-9731e20002eb@y17g2000yqd.googlegroups.com> Hi, I'm pleased to announce the 0.1.3 release of psutil: http://code.google.com/p/psutil === About === psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by tools like ps, top and Windows task manager. It currently supports Linux, OS X, FreeBSD and Windows with Python versions from 2.4 to 3.1 by using a unique code base. === Major enhancements === * Python 3 support * per-process username * suspend / resume process * per-process current working directory (Windows and Linux only) * added support for Windows 7 and FreeBSD 64 bit === Links === * Home page: http://code.google.com/p/psutil * Mailing list: http://groups.google.com/group/psutil/topics * Source tarball: http://psutil.googlecode.com/files/psutil-0.1.3.tar.gz * OS X installer: http://psutil.googlecode.com/files/psutil-0.1.3-py2.6-macosx10.4.dmg * Windows Installer (Python 2.6): http://psutil.googlecode.com/files/psutil-0.1.3.win32-py2.6.exe * Windows Installer (Python 3.1): http://psutil.googlecode.com/files/psutil-0.1.3.win32-py3.1.exe * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Thanks --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ From lbolla at gmail.com Thu Mar 4 12:59:21 2010 From: lbolla at gmail.com (lbolla) Date: Thu, 4 Mar 2010 09:59:21 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> On Mar 4, 3:57?pm, Sneaky Wombat wrote: > [ {'vlan_or_intf': 'VLAN2021'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Po1'}, > ?{'vlan_or_intf': 'Po306'}, > ?{'vlan_or_intf': 'VLAN2022'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Gi7/33'}, > ?{'vlan_or_intf': 'Po1'}, > ?{'vlan_or_intf': 'Po306'}, > ?{'vlan_or_intf': 'VLAN2051'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Gi9/6'}, > ?{'vlan_or_intf': 'VLAN2052'}, > ?{'vlan_or_intf': 'Interface'}, > ?{'vlan_or_intf': 'Gi9/6'},] > > I want it to be converted to: > > [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] > > I was going to write a def to loop through and look for certain pre- > compiled regexs, and then put them in a new dictionary and append to a > list, but I'm having trouble thinking of a good way to capture each > dictionary. ?Each dictionary will have a key that is the vlan and the > value will be a list of interfaces that participate in that vlan. > Each list will be variable, many containing only one interface and > some containing many interfaces. > > I thought about using itertools, but i only use that for fixed data. > I don't know of a good way to loop over variably sized data. ?I was > wondering if anyone had any ideas about a good way to convert this > list or dictionary into the right format that I need. ?The solution I > come up with will most likely be ugly and error prone, so I thought > i'd ask this python list while I work. ?Hopefully I learn a better way > to solve this problem. > > Thanks! > > I also have the data in a list, > > [ 'VLAN4065', > ?'Interface', > ?'Gi9/6', > ?'Po2', > ?'Po3', > ?'Po306', > ?'VLAN4068', > ?'Interface', > ?'Gi9/6', > ?'VLAN4069', > ?'Interface', > ?'Gi9/6',] =================================== from itertools import groupby data = \ [ {'vlan_or_intf': 'VLAN2021'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2022'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi7/33'}, {'vlan_or_intf': 'Po1'}, {'vlan_or_intf': 'Po306'}, {'vlan_or_intf': 'VLAN2051'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'}, {'vlan_or_intf': 'VLAN2052'}, {'vlan_or_intf': 'Interface'}, {'vlan_or_intf': 'Gi9/6'},] def clean_up(lst): return [d.values()[0] for d in data if d.values()[0] != 'Interface'] out = {} for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): if k: key = list(g)[0].replace('VLAN','') else: out[key] = list(g) print out =================================== hth, L. From tjreedy at udel.edu Thu Mar 4 13:03:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Mar 2010 13:03:29 -0500 Subject: memory usage, temporary and otherwise In-Reply-To: References: <4b8ee61a$0$26644$426a74cc@news.free.fr> Message-ID: On 3/4/2010 6:56 AM, mk wrote: > Bruno Desthuilliers wrote: > Huh? I was under impression that some time after 2.0 range was made to > work "under the covers" like xrange when used in a loop? Or is it 3.0 > that does that? 3.0. From john at castleamber.com Thu Mar 4 13:06:15 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Mar 2010 12:06:15 -0600 Subject: Working group for Python CPAN-equivalence? References: <87r5o1v8vp.fsf@benfinney.id.au> <4b8e929d$0$1585$742ec2ed@news.sonic.net> <87eik1ujg4.fsf@benfinney.id.au> Message-ID: <87zl2oufl4.fsf@castleamber.com> Ben Finney writes: > Terry Reedy writes: > >> On 3/3/2010 12:05 PM, John Nagle wrote: >> > CPAN is a repository. PyPi is an collection of links. >> >> As Ben said, PyPI currently is also a respository and not just links >> to other repositories. [..] >> > CPAN enforces standard organization on packages. PyPi does not. > > This is, I think, something we don't need as much in Python; there is a > fundamental difference between Perl's deeply nested namespace hierarchy > and Python's inherently flat hierarchy. Perl's hierarchy is 2 (e.g. Text::Balanced) or 3 levels deep (e.g. Text::Ngram::LanguageDetermine), rarely deeper (Text::Editor::Vip::Buffer::Plugins::Display). Which is in general most likely just one level deeper than Python. Perl is not Java. And I think that one additional level (or more) is a /must/ when you have 17,530 (at the time of writing) modules. If Python wants it's own CPAN it might be a good first move to not have modules named "xmlrpclib", "wave", "keyword", "zlib", etc. But I don't see that happen soon :-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at holdenweb.com Thu Mar 4 13:07:33 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 13:07:33 -0500 Subject: memory usage, temporary and otherwise In-Reply-To: References: Message-ID: Duncan Booth wrote: > mk wrote: > >> Hm, apparently Python didn't spot that 'spam'*10 in a's values is really >> the same string, right? > > If you want it to spot that then give it a hint that it should be looking > for identical strings: > > >>> a={} > >>> for i in range(10000000): > ... a[i]=intern('spam'*10) > > should reduce your memory use somewhat. > Better still, hoist the constant value out of the loop: >>> a={} >>> const = 'spam'*10 >>> for i in range(10000000): ... a[i] = const regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Mar 4 13:14:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 13:14:35 -0500 Subject: WANTED: A good name for the pair (args, kwargs) In-Reply-To: References: Message-ID: Jonathan Fine wrote: > Hi > > We can call a function fn using > val = fn(*args, **kwargs) > > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > Here's my use case: > def doit(fn , wibble, expect): > args, kwargs = wibble > actual = fn(*args, **kwargs) > if actual != expect: > # Something has gone wrong. > pass > > This is part of a test runner. > > For now I'll use argpair, but if anyone has a better idea, I'll use it. > Not being able to find any existing names I called *args the sequence-parameter and **kwarg the dict-parameter. For your use, though, you might choose something like the "generic parameter pair). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Thu Mar 4 13:22:32 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Mar 2010 19:22:32 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <4B8FFA68.20000@sequans.com> Michael Rudolf wrote: > Am 04.03.2010 17:32, schrieb Jean-Michel Pichavant: >> It looks like to me that 'with' statements are like decorators: >> overrated. > > Oh no, you just insulted my favourite two python features, followed > immediately by generators, iterators and list comprehensions / > generator expressions :p > > No, really: they *are* great ;D > > Regards, > Michael They are great, and because of that greatness some of us, including me, tend to use them where there's no point doing so. I would never state that decorators are useless anyway, not in this list, I value my life too much :-) (I'll give it a try in the perl list) JM From alfps at start.no Thu Mar 4 13:37:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 19:37:23 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] >>> >>>> If you call the possibly failing operation "A", then that systematic >>>> approach goes like this: if A fails, then it has cleaned up its own >>>> mess, but if A succeeds, then it's the responsibility of the calling >>>> code to clean up if the higher level (multiple statements) operation >>>> that A is embedded in, fails. >>>> >>>> And that's what Marginean's original C++ ScopeGuard was designed for, >>>> and what the corresponding Python Cleanup class is designed for. >>> >>> And try: finally:, for that matter. >> >> Not to mention "with". >> >> Some other poster made the same error recently in this thread; it is a >> common fallacy in discussions about programming, to assume that since >> the same can be expressed using lower level constructs, those are all >> that are required. >> >> If adopted as true it ultimately means the removal of all control >> structures above the level of "if" and "goto" (except Python doesn't >> have "goto"). > > What I'm trying to explain is that the with: statement has a use even if > Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: > does not mean that the with: statement doesn't improve on try: finally:. That's a different argument, essentially that you see no advantage for your current coding patterns. It's unconnected to the argument I responded to. The argument that I responded to, that the possibility of expressing things at the level of try:finally: means that a higher level construct is superfluous, is still meaningless. >>>>> Both formulations can be correct (and both work perfectly fine with >>>>> the chdir() example being used). Sometimes one is better than the >>>>> other, and sometimes not. You can achieve both ways with either your >>>>> Cleanup class or with try: finally:. >>>>> >>>>> I am still of the opinion that Cleanup is not an improvement over try: >>>>> finally: and has the significant ugliness of forcing cleanup code into >>>>> callables. This significantly limits what you can do in your cleanup >>>>> code. >>>> >>>> Uhm, not really. :-) As I see it. >>> >>> Well, not being able to affect the namespace is a significant >>> limitation. Sometimes you need to delete objects from the namespace in >>> order to ensure that their refcounts go to zero and their cleanup code >>> gets executed. >> >> Just a nit (I agree that a lambda can't do this, but as to what's >> required): assigning None is sufficient for that[1]. > > Yes, but no callable is going to allow you to assign None to names in > that namespace, either. Not without sys._getframe() hackery, in any case. > >> However, note that the current language doesn't guarantee such cleanup, >> at least as far as I know. >> >> So while it's good practice to support it, to do everything to let it >> happen, it's presumably bad practice to rely on it happening. >> >> >>> Tracebacks will keep the namespace alive and all objects in it. >> >> Thanks!, I hadn't thought of connecting that to general cleanup actions. >> >> It limits the use of general "with" in the same way. > > Not really. Sorry, it limits general 'with' in /exactly/ the same way. > It's easy to write context managers that do that [delete objects from the namespace]. Sorry, no can do, as far as I know; your following example quoted below is an example of /something else/. And adding on top of irrelevancy, for the pure technical aspect it can be accomplished in the same way using Cleanup (I provide an example below). However, doing that would generally be worse than pointless since with good coding practices the objects would become unreferenced anyway. > You put > the initialization code in the __enter__() method, assign whatever > objects you want to keep around through the with: clause as attributes > on the manager, then delete those attributes in the __exit__(). Analogously, if one were to do this thing, then it could be accomplished using a Cleanup context manager as follows: foo = lambda: None foo.x = create_some_object() at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) ... except that 1) for a once-only case this is less code :-) 2) it is a usage that I wouldn't recommend; instead I recommend adopting good coding practices where object references aren't kept around. > Or, you > use the @contextmanager decorator to turn a generator into a context > manager, and you just assign to local variables and del them in the > finally: clause. Uhm, you don't need a 'finally' clause when you define a context manager. Additionally, you don't need to 'del' the local variables in @contextmanager decorated generator. The local variables cease to exist automatically. > What you can't do is write a generic context manager where the > initialization happens inside the with: clause and the cleanup actions > are registered callables. That does not allow you to affect the namespace. If you mean that you can't introduce direct local variables and have them deleted by "registered callables" in a portable way, then right. But I can't think of any example where that would be relevant; in particular what matters for supporting on-destruction cleanup is whether you keep any references or not, not whether you have a local variable of any given name. And I think "with" is quite useful even with that restriction. Cheers, - Alf From pemerson at gmail.com Thu Mar 4 13:39:30 2010 From: pemerson at gmail.com (Pete Emerson) Date: Thu, 4 Mar 2010 10:39:30 -0800 (PST) Subject: Evaluate my first python script, please Message-ID: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is "perlesque" This script parses /etc/hosts for hostnames, and based on terms given on the command line (argv), either prints the list of hostnames that match all the criteria, or uses ssh to connect to the host if the number of matches is unique. I am looking for advice along the lines of "an easier way to do this" or "a more python way" (I'm sure that's asking for trouble!) or "people commonly do this instead" or "here's a slick trick" or "oh, interesting, here's my version to do the same thing". I am aware that there are performance improvements and error checking that could be made, such as making sure the file exists and is readable and precompiling the regular expressions and not calculating how many sys.argv arguments there are more than once. I'm not hyper concerned with performance or idiot proofing for this particular script. Thanks in advance. ######################################################## #!/usr/bin/python import sys, fileinput, re, os filename = '/etc/hosts' hosts = [] for line in open(filename, 'r'): match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) if match is None or re.search('^(?:float|localhost)\.', line): continue hostname = match.group(1) count = 0 for arg in sys.argv[1:]: for section in hostname.split('.'): if section == arg: count = count + 1 break if count == len(sys.argv) - 1: hosts.append(hostname) if len(hosts) == 1: os.system("ssh -A " + hosts[0]) else: print '\n'.join(hosts) From as at sci.fi Thu Mar 4 13:43:19 2010 From: as at sci.fi (Anssi Saari) Date: Thu, 04 Mar 2010 20:43:19 +0200 Subject: pyao makes the right sound but why? References: Message-ID: "'2+" writes: > dev = ao.AudioDevice('alsa') > dev.play(x) > > could launch me a semi realtime dj kinda sys > luckily .. it does seem to be making the right sound > but why? > the default of the samplerate and that 16bit happened to match with my thing x? Yes, that seems to be the case from help(ao). But I couldn't run tofu = soy.Bean() since it seems to want tit01.wav. Do you make that available somewhere? From tim.wintle at teamrubber.com Thu Mar 4 14:07:24 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 04 Mar 2010 19:07:24 +0000 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <1267729644.11093.11.camel@localhost> On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". (1) I would wrap it all in a function def main(): # your code here if __name__ == "__main__": main() (2) PEP8 (python style guidelines) suggests one import per line (3) I'd use four spaces as tab width (4) I'd change this: > for arg in sys.argv[1:]: > for section in hostname.split('.'): > if section == arg: > count = count + 1 > break to something more like: for section in hostname.split("."): if section in sys.argv[1:]: count += 1 (although as you suggested I'd only calculate sys.argv[1:] once) ... or you could replace whole section between the for loop and hosts.append with: if sorted(hostname.split(".")) == sorted(sys.argv[1:]): host.append(hostname) , at a slight loss of clarity - but I think I'd stick with the more verbose version personally. Tim From stefan_ml at behnel.de Thu Mar 4 14:10:47 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 04 Mar 2010 20:10:47 +0100 Subject: Partly erratic wrong behaviour, Python 3, lxml In-Reply-To: References: Message-ID: Jussi Piitulainen, 04.03.2010 11:46: > I am observing weird semi-erratic behaviour that involves Python 3 and > lxml, is extremely sensitive to changes in the input data, and only > occurs when I name a partial result. I would like some help with this, > please. (Python 3.1.1; GNU/Linux; how do I find lxml version?) Here's how to find the version: http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do I'll give your test code a try when I get to it. However, note that the best place to discuss this is the lxml mailing list: http://codespeak.net/mailman/listinfo/lxml-dev Stefan From duncan.booth at invalid.invalid Thu Mar 4 14:15:42 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Mar 2010 19:15:42 GMT Subject: NoSQL Movement? References: Message-ID: mk wrote: > Duncan Booth wrote: > >> If you look at some of the uses of bigtable you may begin to >> understand the tradeoffs that are made with sql. When you use >> bigtable you have records with fields, and you have indices, but >> there are limitations on the kinds of queries you can perform: in >> particular you cannot do joins, but more subtly there is no guarantee >> that the index is up to date (so you might miss recent updates or >> even get data back from a query when the data no longer matches the >> query). > > Hmm, I do understand that bigtable is used outside of traditional > 'enterprisey' contexts, but suppose you did want to do an equivalent > of join; is it at all practical or even possible? > > I guess when you're forced to use denormalized data, you have to > simultaneously update equivalent columns across many tables yourself, > right? Or is there some machinery to assist in that? Or you avoid having to do that sort of update at all. There are many applications which simply wouldn't be applicable to bigtable. My point was that to make best use of bigtable you may have to make different decisions when designing the software. > >> By sacrificing some of SQL's power, Google get big benefits: namely >> updating data is a much more localised option. Instead of an update >> having to lock the indices while they are updated, updates to >> different records can happen simultaneously possibly on servers on >> the opposite sides of the world. You can have many, many servers all >> using the same data although they may not have identical or >> completely consistent views of that data. > > And you still have the global view of the table spread across, say, 2 > servers, one located in Australia, second in US? > More likely spread across a few thousand servers. The data migrates round the servers as required. As I understand it records are organised in groups: when you create a record you can either make it a root record or you can give it a parent record. So for example you might make all the data associated with a specific user live with the user record as a parent (or ancestor). When you access any of that data then all of it is copied onto a server near the application as all records under a common root are always stored together. >> Bigtable impacts on how you store the data: for example you need to >> avoid reducing data to normal form (no joins!), its much better and >> cheaper just to store all the data you need directly in each record. >> Also aggregate values need to be at least partly pre-computed and >> stored in the database. > > So you basically end up with a few big tables or just one big table > really? One. Did I mention that bigtable doesn't require you to have the same columns in every record? The main use of bigtable (outside of Google's internal use) is Google App Engine and that apparently uses one table. Not one table per application, one table total. It's a big table. > > Suppose on top of 'tweets' table you have 'dweebs' table, and tweets > and dweebs sometimes do interact. How would you find such interacting > pairs? Would you say "give me some tweets" to tweets table, extract > all the dweeb_id keys from tweets and then retrieve all dweebs from > dweebs table? If it is one tweet to many dweebs? Dweeb.all().filter("tweet =", tweet.key()) or: GqlQuery("SELECT * FROM Dweeb WHERE tweet = :tweet", tweet=tweet) or just make the tweet the ancestor of all its dweebs. Columns may be scalars or lists, so if it is some tweets to many dweebs you can do basically the same thing. Dweeb.all().filter("tweets =", tweet.key()) but if there are too many tweets in the list that could be a problem. If you want dweebs for several tweets you could select with "tweet IN " the list of tweets or do a separate query for each (not much difference, as I understand it the IN operator just expands into several queries internally anyway). From pruebauno at latinmail.com Thu Mar 4 14:18:49 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 4 Mar 2010 11:18:49 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> Message-ID: <865d59ab-585b-4908-be0d-e891d0a0a08b@t23g2000yqt.googlegroups.com> lbolla wrote: > On Mar 4, 3:57?pm, Sneaky Wombat wrote: > > [ {'vlan_or_intf': 'VLAN2021'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Po1'}, > > ?{'vlan_or_intf': 'Po306'}, > > ?{'vlan_or_intf': 'VLAN2022'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Gi7/33'}, > > ?{'vlan_or_intf': 'Po1'}, > > ?{'vlan_or_intf': 'Po306'}, > > ?{'vlan_or_intf': 'VLAN2051'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Gi9/6'}, > > ?{'vlan_or_intf': 'VLAN2052'}, > > ?{'vlan_or_intf': 'Interface'}, > > ?{'vlan_or_intf': 'Gi9/6'},] > > > > I want it to be converted to: > > > > [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] > > > > I was going to write a def to loop through and look for certain pre- > > compiled regexs, and then put them in a new dictionary and append to a > > list, but I'm having trouble thinking of a good way to capture each > > dictionary. ?Each dictionary will have a key that is the vlan and the > > value will be a list of interfaces that participate in that vlan. > > Each list will be variable, many containing only one interface and > > some containing many interfaces. > > > > I thought about using itertools, but i only use that for fixed data. > > I don't know of a good way to loop over variably sized data. ?I was > > wondering if anyone had any ideas about a good way to convert this > > list or dictionary into the right format that I need. ?The solution I > > come up with will most likely be ugly and error prone, so I thought > > i'd ask this python list while I work. ?Hopefully I learn a better way > > to solve this problem. > > > > Thanks! > > > > I also have the data in a list, > > > > [ 'VLAN4065', > > ?'Interface', > > ?'Gi9/6', > > ?'Po2', > > ?'Po3', > > ?'Po306', > > ?'VLAN4068', > > ?'Interface', > > ?'Gi9/6', > > ?'VLAN4069', > > ?'Interface', > > ?'Gi9/6',] > > > > =================================== > > from itertools import groupby > > data = \ > [ {'vlan_or_intf': 'VLAN2021'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Po1'}, > {'vlan_or_intf': 'Po306'}, > {'vlan_or_intf': 'VLAN2022'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Gi7/33'}, > {'vlan_or_intf': 'Po1'}, > {'vlan_or_intf': 'Po306'}, > {'vlan_or_intf': 'VLAN2051'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Gi9/6'}, > {'vlan_or_intf': 'VLAN2052'}, > {'vlan_or_intf': 'Interface'}, > {'vlan_or_intf': 'Gi9/6'},] > > def clean_up(lst): > return [d.values()[0] for d in data if d.values()[0] != 'Interface'] > > out = {} > for k, g in groupby(clean_up(data) , key=lambda s: > s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') > else: > out[key] = list(g) > > print out > =================================== > > hth, > L. Good use of groupby. Here is what I ended up coming up: from itertools import groupby laninfo=[ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] def splitgrp(s, f=[False]): f[0]^=s.startswith('VLAN') return f[0] lanlst=(list(g) for k,g in groupby(laninfo,key=splitgrp)) out={item[0][4:]:item[2:] for item in lanlst} print(out) From db3l.net at gmail.com Thu Mar 4 14:21:58 2010 From: db3l.net at gmail.com (David Bolen) Date: Thu, 04 Mar 2010 14:21:58 -0500 Subject: Generic singleton References: Message-ID: Duncan Booth writes: > It is also *everywhere* in the Python world. Unlike Java and C++, Python > even has its own built-in type for singletons. > > If you want a singleton in Python use a module. > > So the OP's original examples become: > > --- file singleton.py --- > foo = {} > bar = [] > > --- other.py --- > from singleton import foo as s1 > from singleton import foo as s2 > from singleton import bar as s3 > from singleton import bar as s4 > > ... and then use them as you wish. In the event you do use a module as a singleton container, I would advocate sticking with fully qualified names, avoiding the use of "from" imports or any other local namespace caching of references. Other code sharing the module may not update things as expected, e.g.: import singleton singleton.foo = {} at which point you've got two objects around - one in the singleton.py module namespace, and the s1/s2 referenced object in other.py. If you're confident of the usage pattern of all the using code, it may not be critical. But consistently using "singleton.foo" (or an import alias like s.foo) is a bit more robust, sticking with only one namespace to reach the singleton. -- David From python at mrabarnett.plus.com Thu Mar 4 14:30:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Mar 2010 19:30:55 +0000 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <4B900A6F.40104@mrabarnett.plus.com> Pete Emerson wrote: > I've written my first python program, and would love suggestions for > improvement. > > I'm a perl programmer and used a perl version of this program to guide > me. So in that sense, the python is "perlesque" > > This script parses /etc/hosts for hostnames, and based on terms given > on the command line (argv), either prints the list of hostnames that > match all the criteria, or uses ssh to connect to the host if the > number of matches is unique. > > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". > > I am aware that there are performance improvements and error checking > that could be made, such as making sure the file exists and is > readable and precompiling the regular expressions and not calculating > how many sys.argv arguments there are more than once. I'm not hyper > concerned with performance or idiot proofing for this particular > script. > > Thanks in advance. > > ######################################################## > #!/usr/bin/python > > import sys, fileinput, re, os > > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) Use 'raw' strings for regular expressions. 'Normal' Python string literals use backslashes in escape sequences (eg, '\n'), but so do regular expressions, and regular expressions are passed to the 're' module in strings, so that can lead to a profusion of backslashes! You could either escape the backslashes: match = re.search('\\d+\\.\\d+\\.\\d+\\.\\d+\s+(\\S+)', line) or use a raw string: match = re.search(r'\d+\.\d+\.\d+\.\d+\s+(\S+)', line) A raw string literal is just like a normal string literal, except that backslashes aren't special. > if match is None or re.search('^(?:float|localhost)\.', line): > continue It would be more 'Pythonic' to say "not match". if not match or re.search(r'^(?:float|localhost)\.', line): > hostname = match.group(1) > count = 0 > for arg in sys.argv[1:]: > for section in hostname.split('.'): > if section == arg: > count = count + 1 Shorter is: count += 1 > break > if count == len(sys.argv) - 1: > hosts.append(hostname) > > if len(hosts) == 1: > os.system("ssh -A " + hosts[0]) > else: > print '\n'.join(hosts) You're splitting the hostname repeatedly. You could split it just once, outside the outer loop, and maybe make it into a set. You could then have: host_parts = set(hostname.split('.')) count = 0 for arg in sys.argv[1:]: if arg in host_parts: count += 1 Incidentally, the re module contains a cache, so the regular expressions won't be recompiled every time (unless you have a lot of them and the re module flushes the cache). From robert.kern at gmail.com Thu Mar 4 14:37:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 13:37:29 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: > [snippety] >>>> >>>>> If you call the possibly failing operation "A", then that systematic >>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>> mess, but if A succeeds, then it's the responsibility of the calling >>>>> code to clean up if the higher level (multiple statements) operation >>>>> that A is embedded in, fails. >>>>> >>>>> And that's what Marginean's original C++ ScopeGuard was designed for, >>>>> and what the corresponding Python Cleanup class is designed for. >>>> >>>> And try: finally:, for that matter. >>> >>> Not to mention "with". >>> >>> Some other poster made the same error recently in this thread; it is a >>> common fallacy in discussions about programming, to assume that since >>> the same can be expressed using lower level constructs, those are all >>> that are required. >>> >>> If adopted as true it ultimately means the removal of all control >>> structures above the level of "if" and "goto" (except Python doesn't >>> have "goto"). >> >> What I'm trying to explain is that the with: statement has a use even >> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >> finally: does not mean that the with: statement doesn't improve on >> try: finally:. > > That's a different argument, essentially that you see no advantage for > your current coding patterns. > > It's unconnected to the argument I responded to. > > The argument that I responded to, that the possibility of expressing > things at the level of try:finally: means that a higher level construct > is superfluous, is still meaningless. I am attacking your premise that the "with Cleanup():" construct is higher level than try: finally:. It isn't. It provides the same level of abstraction as try: finally:. This is distinct from the accepted uses of the with: statement which *are* higher level than try: finally: and which do confer practical benefits over using try: finally: despite being syntactical sugar for try: finally:. >>>>>> Both formulations can be correct (and both work perfectly fine with >>>>>> the chdir() example being used). Sometimes one is better than the >>>>>> other, and sometimes not. You can achieve both ways with either your >>>>>> Cleanup class or with try: finally:. >>>>>> >>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>> try: >>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>> into >>>>>> callables. This significantly limits what you can do in your cleanup >>>>>> code. >>>>> >>>>> Uhm, not really. :-) As I see it. >>>> >>>> Well, not being able to affect the namespace is a significant >>>> limitation. Sometimes you need to delete objects from the namespace in >>>> order to ensure that their refcounts go to zero and their cleanup code >>>> gets executed. >>> >>> Just a nit (I agree that a lambda can't do this, but as to what's >>> required): assigning None is sufficient for that[1]. >> >> Yes, but no callable is going to allow you to assign None to names in >> that namespace, either. Not without sys._getframe() hackery, in any case. >> >>> However, note that the current language doesn't guarantee such cleanup, >>> at least as far as I know. >>> >>> So while it's good practice to support it, to do everything to let it >>> happen, it's presumably bad practice to rely on it happening. >>> >>> >>>> Tracebacks will keep the namespace alive and all objects in it. >>> >>> Thanks!, I hadn't thought of connecting that to general cleanup actions. >>> >>> It limits the use of general "with" in the same way. >> >> Not really. > > Sorry, it limits general 'with' in /exactly/ the same way. > >> It's easy to write context managers that do that [delete objects from >> the namespace]. > > Sorry, no can do, as far as I know; your following example quoted below > is an example of /something else/. Okay, so what do you mean by 'the use of general "with"'? I'm talking about writing a context manager or using the @contextmanager decorator to do some initialization and then later cleaning up that initialization. That cleaning up may entail deleting an object. You are correct that the context manager can't affect the namespace of the with: clause, but that's not the initialization that it would need to clean up. Yes, you can write code with a with: statement where you try to clean up stuff that happened inside of the clause (you did), but that's not how the with: statement was ever intended to be used nor is it good practice to do so because of that limitation. Context managers are designed to initialize specific things, then clean them up. I thought you were talking about the uses of the with: statement as described in PEP-343, not every possible misuse of the with: statement. > And adding on top of irrelevancy, for the pure technical aspect it can > be accomplished in the same way using Cleanup (I provide an example below). > > However, doing that would generally be worse than pointless since with > good coding practices the objects would become unreferenced anyway. > > >> You put the initialization code in the __enter__() method, assign >> whatever objects you want to keep around through the with: clause as >> attributes on the manager, then delete those attributes in the >> __exit__(). > > Analogously, if one were to do this thing, then it could be accomplished > using a Cleanup context manager as follows: > > foo = lambda: None > foo.x = create_some_object() > at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) > > ... except that > > 1) for a once-only case this is less code :-) Not compared to a try: finally:, it isn't. > 2) it is a usage that I wouldn't recommend; instead I recommend adopting > good > coding practices where object references aren't kept around. Many of the use cases of the with: statement involve creating an object (like a lock or a transaction object), keeping it around for the duration of the "# Do stuff" block, and then finalizing it. >> Or, you use the @contextmanager decorator to turn a generator into a >> context manager, and you just assign to local variables and del them >> in the finally: clause. > > Uhm, you don't need a 'finally' clause when you define a context manager. When you use the @contextmanager decorator, you almost always do. See the Examples section of PEP 343: http://www.python.org/dev/peps/pep-0343/ > Additionally, you don't need to 'del' the local variables in > @contextmanager decorated generator. > > The local variables cease to exist automatically. True. >> What you can't do is write a generic context manager where the >> initialization happens inside the with: clause and the cleanup actions >> are registered callables. That does not allow you to affect the >> namespace. > > If you mean that you can't introduce direct local variables and have > them deleted by "registered callables" in a portable way, then right. > > But I can't think of any example where that would be relevant; in > particular what matters for supporting on-destruction cleanup is whether > you keep any references or not, not whether you have a local variable of > any given name. Well, local variables keep references to objects. Variable assignment followed by deletion is a very readable way to keep an object around for a while then remove it later. If you have to go through less readable contortions to keep the object around when it needs to be and clean it up later, then that is a mark against your approach. -- 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 From steve at holdenweb.com Thu Mar 4 14:49:27 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Mar 2010 14:49:27 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Robert Kern: [...] >> No, it only argues that "with Cleanup():" is supernumerary. > > I don't know what "supernumerary" means, but to the degree that the > argument says anything about a construct that is not 'finally', it says > the same about general "with". > So rather than look up the meaning if a word you aren't familiar with you will argue against its use in generic style? > So whatever you mean by supernumerary, you're saying that the argument > implies that "with" is supernumerary. > > This is starting to look like some earlier discussions in this group, > where even basic logic is denied. > Why not just stick to the facts and forget about the earlier discussions? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From pruebauno at latinmail.com Thu Mar 4 14:54:55 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 4 Mar 2010 11:54:55 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <9b598cad-3069-49a9-b2d0-378e973a8ce2@x22g2000yqx.googlegroups.com> On Mar 4, 2:30?pm, MRAB wrote: > Pete Emerson wrote: > > I've written my first python program, and would love suggestions for > > improvement. > > > I'm a perl programmer and used a perl version of this program to guide > > me. So in that sense, the python is "perlesque" > > > This script parses /etc/hosts for hostnames, and based on terms given > > on the command line (argv), either prints the list of hostnames that > > match all the criteria, or uses ssh to connect to the host if the > > number of matches is unique. > > > I am looking for advice along the lines of "an easier way to do this" > > or "a more python way" (I'm sure that's asking for trouble!) or > > "people commonly do this instead" or "here's a slick trick" or "oh, > > interesting, here's my version to do the same thing". > > > I am aware that there are performance improvements and error checking > > that could be made, such as making sure the file exists and is > > readable and precompiling the regular expressions and not calculating > > how many sys.argv arguments there are more than once. I'm not hyper > > concerned with performance or idiot proofing for this particular > > script. > > > Thanks in advance. > > > ######################################################## > > #!/usr/bin/python > > > import sys, fileinput, re, os > > > filename = '/etc/hosts' > > > hosts = [] > > > for line in open(filename, 'r'): > > ? ?match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > > Use 'raw' strings for regular expressions. > > 'Normal' Python string literals use backslashes in escape sequences (eg, > '\n'), but so do regular expressions, and regular expressions are passed > to the 're' module in strings, so that can lead to a profusion of > backslashes! > > You could either escape the backslashes: > > ? ? ? ? match = re.search('\\d+\\.\\d+\\.\\d+\\.\\d+\s+(\\S+)', line) > > or use a raw string: > > ? ? ? ? match = re.search(r'\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > > A raw string literal is just like a normal string literal, except that > backslashes aren't special. > > > ? ?if match is None or re.search('^(?:float|localhost)\.', line): > > continue > > It would be more 'Pythonic' to say "not match". > > ? ? ? ? if not match or re.search(r'^(?:float|localhost)\.', line): > > > ? ?hostname = match.group(1) > > ? ?count = 0 > > ? ?for arg in sys.argv[1:]: > > ? ? ? ? ? ?for section in hostname.split('.'): > > ? ? ? ? ? ? ? ? ? ?if section == arg: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?count = count + 1 > > Shorter is: > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? count += 1 > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?break > > ? ?if count == len(sys.argv) - 1: > > ? ? ? ? ? ?hosts.append(hostname) > > > if len(hosts) == 1: > > ? ?os.system("ssh -A " + hosts[0]) > > else: > > ? ?print '\n'.join(hosts) > > You're splitting the hostname repeatedly. You could split it just once, > outside the outer loop, and maybe make it into a set. You could then > have: > > ? ? ? ? ?host_parts = set(hostname.split('.')) > ? ? ? ? count = 0 > ? ? ? ? for arg in sys.argv[1:]: > ? ? ? ? ? ? ? ? if arg in host_parts: > ? ? ? ? ? ? ? ? ? ? ? ? count += 1 > > Incidentally, the re module contains a cache, so the regular expressions > won't be recompiled every time (unless you have a lot of them and the re > module flushes the cache). I think that you really just need a set intersection for the count part and this should work: host_parts = set(hostname.split('.')) count = len(host_parts.intersection(sys.argv[1:])) From knipknap at gmail.com Thu Mar 4 14:55:21 2010 From: knipknap at gmail.com (knipknap) Date: Thu, 4 Mar 2010 11:55:21 -0800 (PST) Subject: ANNOUNCE: Exscript 2.0 Message-ID: <18ffe924-0068-42dc-ad36-da3c0ba07308@z35g2000yqd.googlegroups.com> Introduction ------------- Exscript is a Python module and template processor for automating Telnet or SSH sessions. Exscript supports a wide range of features, such as parallelization, AAA authentication methods, TACACS, and a very simple template language. Please refer to the project page for updated documentation (see the links at the bottom of this announcement). New since 0.9.16 ------------------ Exscript 2.0 is without a doubt the most awesome release of Exscript ever. It is well tested and has already proven to be robust, so use in a production environment is encouraged. Changes in this release: * Exscript's Python API has been completely overhauled and made a lot simpler. The new API is well documented [1][2]. * Countless utilities for network administrators using Python were added. For example, it is now trivial to generate reports and emails, logging is more configurable, new functions for reading and writing input and output files were added, and user interaction was simplified. * The number of dependencies was reduced to make the installation easier. * Exscript is now almost 100% unit tested. That means greatly enhanced stability and reliability. * Support for threading was improved, leading to better performance when using a large number of parallel connections. * The SSH support was greatly improved. * Exscript now includes some useful Tkinter widgets for monitoring the Exscript Queue. * Support for Pseudo devices: It is now possible to emulate a fake device that behaves like a router. This can come in handy for testing. * Of course, a huge number of bugs was also fixed. I expect this release to be the most stable one to date. It was also well tested in production and has handled hundreds of thousands of Telnet connections in the past few months. Dependencies ------------- * Python 2.2 or greater * Python-crypto * paramiko (optional, for SSH2 support) * Python-pexpect (optional, for SSH1 support) * OpenSSH (optional, for SSH1 support) Download Exscript ------------------ Release: http://github.com/knipknap/exscript/downloads Git: http://code.google.com/p/exscript/source Links ------ [1] Exscript Documentation: http://wiki.github.com/knipknap/exscript/documentation [2] Exscript Python API: http://knipknap.github.com/exscript/api/ [3] Installation Guide: http://wiki.github.com/knipknap/exscript/installation-guide [4] Exscript home page: http://wiki.github.com/knipknap/exscript/ [5] Mailing list: http://groups.google.com/group/exscript [6] Bug tracker: http://github.com/knipknap/exscript/issues [7] Browse the source: http://github.com/knipknap/exscript From mrmakent at gmail.com Thu Mar 4 15:48:30 2010 From: mrmakent at gmail.com (Mike Kent) Date: Thu, 4 Mar 2010 12:48:30 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <915588d0-e4fd-42d0-b5b5-3506700924ae@q16g2000yqq.googlegroups.com> On Mar 3, 10:56?am, "Alf P. Steinbach" wrote: > * Mike Kent: > > > What's the compelling use case for this vs. a simple try/finally? > > if you thought about it you would mean a simple "try/else". "finally" is always > executed. which is incorrect for cleanup > > by the way, that's one advantage: > > a "with Cleanup" is difficult to get wrong, while a "try" is easy to get wrong, > as you did here > > ? ?--- > > another general advantage is as for the 'with' statement generally > > > ? ?original_dir = os.getcwd() > > ? ?try: > > ? ? ? ?os.chdir(somewhere) > > ? ? ? ?# Do other stuff > > also, the "do other stuff" can be a lot of code > > and also, with more than one action the try-else introduces a lot of nesting > > > ? ?finally: > > ? ? ? ?os.chdir(original_dir) > > ? ? ? ?# Do other cleanup > > cheers & hth., > > - alf Wrong? In what way is my example wrong? It cleanly makes sure that the current working directory is the same after the try/finally as it was before it. Suboptimal, perhaps, in that the chdir in the finally part is always executed, even if the chdir in the try part failed to change the working directory. That is a clear advantage to the code you presented, in that you have the ability to register an 'undo' function only if the 'do' code succeeded. Your code also avoids a problem with many nested try/ finally blocks. But for the simple chdir example you gave, I think 'wrong' isn't the word you were looking for regarding the try/finally example I gave. Anyway, I'll keep your code in mind the next time I want to avoid a bunch of nested try/finally blocks. From wanderer at dialup4less.com Thu Mar 4 15:49:08 2010 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 4 Mar 2010 12:49:08 -0800 (PST) Subject: Pylint Argument number differs from overridden method References: <2484ca6e-0eb9-4e0c-a7db-d035badab711@t20g2000yqe.googlegroups.com> <9ca2e014-f238-4b55-8ace-f884b2112a19@z11g2000yqz.googlegroups.com> Message-ID: On Mar 4, 5:45?am, Jean-Michel Pichavant wrote: > Wanderer wrote: > > On Mar 3, 2:33 pm, Robert Kern wrote: > > >> On 2010-03-03 11:39 AM, Wanderer wrote: > > >>> Pylint W0221 gives the warning > >>> Argument number differs from overridden method. > > >>> Why is this a problem? I'm overriding the method to add additional > >>> functionality. > > >> There are exceptions to every guideline. Doing this could easily be a mistake, > >> so it's one of the many things that Pylint checks for. Silence the warning if > >> you like. > > >> -- > >> 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 > > > Thanks I was just wondering if I was overlooking something about > > inheritance. > > This is only my opinion but you get this warning because of 2 disctinct > issues: > 1/ you just made a basic mistake in your signature and need to correct it > 2/ you did not make any mistake in the signature, but this warning may > reveal a (small) flaw in your class design. > > I don't know the exact context for your code, but it's better to have a > consistant interface over your methods and mask the implementation > details from the user. > In your case, the getRays method may always ask for the lambda > parameters and just ignore it for one of its implementation. > > And don't write empty doctrings to trick pylint. Either write them, or > remove this rule, you are loosing all the tool benefits. > > JM Okay different example. I'm not really using inheritance here but its the same idea. The wx.SpinCtrl is annoyingly integer. I want decimal values. so I created dSpinCtrl. It adds the argument places. It's a drop in replacement for SpinCtrl. (okay its not, because I didn't create all the members). If you replace SpinCtrl with dSpinCtrl the program should work the same because the new argument places has a default value. I don't see a problem with more arguments. Less arguments would be a problem. Expanding functionality from a base class is what I thought inheritance is about. class dSpinCtrl(): """Adds decimal values to SpinCtrl. Almost a drop in replacement for SpinCtrl. Adds 'places' variable for number of places after decimal point """ def __init__ (self, parent, iD = ID_SPIN, value = wx.EmptyString, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.SP_ARROW_KEYS, dmin = -100.0, dmax = 100.0, dinitial = 0.0, places = 0): From sccolbert at gmail.com Thu Mar 4 16:00:02 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 4 Mar 2010 16:00:02 -0500 Subject: loop over list and process into groups In-Reply-To: <865d59ab-585b-4908-be0d-e891d0a0a08b@t23g2000yqt.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> <865d59ab-585b-4908-be0d-e891d0a0a08b@t23g2000yqt.googlegroups.com> Message-ID: <7f014ea61003041300j98500a2y89f414878753b397@mail.gmail.com> Man, deja-vu, I could have sworn I read this thread months ago... On Thu, Mar 4, 2010 at 2:18 PM, nn wrote: > > > lbolla wrote: > > On Mar 4, 3:57 pm, Sneaky Wombat wrote: > > > [ {'vlan_or_intf': 'VLAN2021'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Po1'}, > > > {'vlan_or_intf': 'Po306'}, > > > {'vlan_or_intf': 'VLAN2022'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Gi7/33'}, > > > {'vlan_or_intf': 'Po1'}, > > > {'vlan_or_intf': 'Po306'}, > > > {'vlan_or_intf': 'VLAN2051'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Gi9/6'}, > > > {'vlan_or_intf': 'VLAN2052'}, > > > {'vlan_or_intf': 'Interface'}, > > > {'vlan_or_intf': 'Gi9/6'},] > > > > > > I want it to be converted to: > > > > > > [{'2021':['Po1','Po306']},{'2022':['Gi7/33','Po1','Po306']},etc etc] > > > > > > I was going to write a def to loop through and look for certain pre- > > > compiled regexs, and then put them in a new dictionary and append to a > > > list, but I'm having trouble thinking of a good way to capture each > > > dictionary. Each dictionary will have a key that is the vlan and the > > > value will be a list of interfaces that participate in that vlan. > > > Each list will be variable, many containing only one interface and > > > some containing many interfaces. > > > > > > I thought about using itertools, but i only use that for fixed data. > > > I don't know of a good way to loop over variably sized data. I was > > > wondering if anyone had any ideas about a good way to convert this > > > list or dictionary into the right format that I need. The solution I > > > come up with will most likely be ugly and error prone, so I thought > > > i'd ask this python list while I work. Hopefully I learn a better way > > > to solve this problem. > > > > > > Thanks! > > > > > > I also have the data in a list, > > > > > > [ 'VLAN4065', > > > 'Interface', > > > 'Gi9/6', > > > 'Po2', > > > 'Po3', > > > 'Po306', > > > 'VLAN4068', > > > 'Interface', > > > 'Gi9/6', > > > 'VLAN4069', > > > 'Interface', > > > 'Gi9/6',] > > > > > > > > =================================== > > > > from itertools import groupby > > > > data = \ > > [ {'vlan_or_intf': 'VLAN2021'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Po1'}, > > {'vlan_or_intf': 'Po306'}, > > {'vlan_or_intf': 'VLAN2022'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Gi7/33'}, > > {'vlan_or_intf': 'Po1'}, > > {'vlan_or_intf': 'Po306'}, > > {'vlan_or_intf': 'VLAN2051'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Gi9/6'}, > > {'vlan_or_intf': 'VLAN2052'}, > > {'vlan_or_intf': 'Interface'}, > > {'vlan_or_intf': 'Gi9/6'},] > > > > def clean_up(lst): > > return [d.values()[0] for d in data if d.values()[0] != > 'Interface'] > > > > out = {} > > for k, g in groupby(clean_up(data) , key=lambda s: > > s.startswith('VLAN')): > > if k: > > key = list(g)[0].replace('VLAN','') > > else: > > out[key] = list(g) > > > > print out > > =================================== > > > > hth, > > L. > > Good use of groupby. Here is what I ended up coming up: > > from itertools import groupby > laninfo=[ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] > > def splitgrp(s, f=[False]): > f[0]^=s.startswith('VLAN') > return f[0] > lanlst=(list(g) for k,g in groupby(laninfo,key=splitgrp)) > out={item[0][4:]:item[2:] for item in lanlst} > print(out) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at gmail.com Thu Mar 4 16:12:01 2010 From: mrmakent at gmail.com (Mike Kent) Date: Thu, 4 Mar 2010 13:12:01 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> On Mar 4, 12:30?pm, Robert Kern wrote: > He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. > Given only your > example of the with: statement, it is hard to fault him for thinking that try: > finally: wouldn't suffice. Damn me with faint praise, will you? I'm kinda amazed at the drama my innocent request for the use case elicited. From what I've gotten so far from this thread, for the actual example Mr. Steinbach used, the only disadvantage to my counter- example using try/finally is that the chdir in the finally part will always be executed, even if the chdir in the try part did not succeed. I concede that, and was aware of it when I wrote it. For the simple example given, I did not consider it compelling. A more complex example, that would have required multiple, nested try/finally blocks, would show the advantages of Mr Steinbach's recipe more clearly. However, I fail to understand his response that I must have meant try/ else instead, as this, as Mr. Kern pointed out, is invalid syntax. Perhaps Mr. Steinbach would like to give an example? From jjposner at optimum.net Thu Mar 4 16:17:20 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 04 Mar 2010 16:17:20 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4B8EF717.3070701@optimum.net> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> Message-ID: <4b902338$0$31260$607ed4bc@cv.net> On 3/3/2010 6:56 PM, John Posner wrote: > > ... I was thinking > today about "doing a Bruno", and producing similar pieces on: > > * properties created with the @property decorator > > * the descriptor protocol > > I'll try to produce something over the next couple of days. > Starting to think about a writeup on Python properties, I've discovered that the official Glossary [1] lacks an entry for "property" -- it's missing in both Py2 and Py3! Here's a somewhat long-winded definition -- comments, please: --------------------------------------------- An attribute, *a*, of an object, *obj*, is said to be implemented as a property if the standard ways of accessing the attribute: * evaluation: print obj.a * assignment: obj.a = 42 * deletion: del obj.a ... cause methods of a user-defined *property object* to be invoked. The attribute is created as a class attribute, not an instance attribute. Example: class Widget: # create "color" as class attribute, not within __init__() color = <> def __init__(self, ...): # do not define "self.color" instance attribute The property object can be created with the built-in function property(), which in some cases can be coded as a decorator: @property. The property object can also be an instance of a class that implements the descriptor protocol. --------------------------------------------- Tx, John [1] http://docs.python.org/glossary.html From mrmakent at gmail.com Thu Mar 4 16:19:44 2010 From: mrmakent at gmail.com (Mike Kent) Date: Thu, 4 Mar 2010 13:19:44 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On Mar 3, 12:00?pm, Robert Kern wrote: > On 2010-03-03 09:39 AM, Mike Kent wrote: > > > What's the compelling use case for this vs. a simple try/finally? > > > ? ? original_dir = os.getcwd() > > ? ? try: > > ? ? ? ? os.chdir(somewhere) > > ? ? ? ? # Do other stuff > > ? ? finally: > > ? ? ? ? os.chdir(original_dir) > > ? ? ? ? # Do other cleanup > > A custom-written context manager looks nicer and can be more readable. > > from contextlib import contextmanager > import os > > @contextmanager > def pushd(path): > ? ? ?original_dir = os.getcwd() > ? ? ?os.chdir(path) > ? ? ?try: > ? ? ? ? ?yield > ? ? ?finally: > ? ? ? ? ?os.chdir(original_dir) > > with pushd(somewhere): > ? ? ?... Robert, I like the way you think. That's a perfect name for that context manager! However, you can clear one thing up for me... isn't the inner try/finally superfluous? My understanding was that there was an implicit try/finally already done which will insure that everything after the yield statement was always executed. From news123 at free.fr Thu Mar 4 16:24:59 2010 From: news123 at free.fr (News123) Date: Thu, 04 Mar 2010 22:24:59 +0100 Subject: _winreg and access registry settings of another user Message-ID: <4b90252b$0$17806$426a34cc@news.free.fr> Hi, I habe administrator privilege on a window host and would like to write a script setting some registry entries for other users. There are potentially at least two wo ways of doing this: 1.) start a subprocess as other user and change the regitrey for CURRENT_USER However I don't know how to start a process (or ideally just a thread) as another user with python. 2.) Load the 'hive' of the othe user and chnage the registry. It seems, that one has to load the 'hive' of a different user in order to have access to somebody eleses registry entries. I did not find any documetnation of how to load a 'hive' wit the library _winreg or another python library/ Did anybody else try already something similiar? thanks in advance for pointers bye N From jpiitula at ling.helsinki.fi Thu Mar 4 16:40:39 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Mar 2010 23:40:39 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml References: Message-ID: Stefan Behnel writes: > Jussi Piitulainen, 04.03.2010 11:46: > > I am observing weird semi-erratic behaviour that involves Python 3 > > and lxml, is extremely sensitive to changes in the input data, and > > only occurs when I name a partial result. I would like some help > > with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml > > version?) > > Here's how to find the version: > > http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do Ok, thank you. Here's the results: >>> print(et.LXML_VERSION, et.LIBXML_VERSION, ... et.LIBXML_COMPILED_VERSION, et.LIBXSLT_VERSION, ... et.LIBXSLT_COMPILED_VERSION) (2, 2, 4, 0) (2, 6, 26) (2, 6, 26) (1, 1, 17) (1, 1, 17) > I'll give your test code a try when I get to it. However, note that > the best place to discuss this is the lxml mailing list: > > http://codespeak.net/mailman/listinfo/lxml-dev Thank you. Two things, however. First, I snipped out most of the XML document in that post, so it won't be runnable as is. As I think I said, my attempts to edit it down to size made the bug hide itself. Second, it's very sensitive to any changes in that XML. Oh, and a third thing. I'm not at all sure yet that the bug is in lxml. It seems to me that Python itself does impossible things - I hope I'm just being blind to something obvious, really. But if you like to try it out, I'll post the full test data as a followup to this. It's just bogus test data. From deets at nospam.web.de Thu Mar 4 16:43:12 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Mar 2010 22:43:12 +0100 Subject: python SUDS library In-Reply-To: <28ed0127-8b71-4327-954c-c9100b4768de@v20g2000prb.googlegroups.com> References: <28ed0127-8b71-4327-954c-c9100b4768de@v20g2000prb.googlegroups.com> Message-ID: <7vanrgF97hU1@mid.uni-berlin.de> Am 04.03.10 06:23, schrieb yamamoto: > Hi, > I tried to make a simple script with SUD library for caching torrent > files. it doenst work! > > [versions] > suds: 0.4, python: 2.6.4 > > [code] > from suds.client import Client > import base64 > > path = 'sample.torrent' > doc = open(path, 'rb').read() > encoded_doc = base64.b64encode(doc) > url = 'http://torrage.com/api/torrage.wsdl' > client = Client(url, cache=None) > print client > hash = client.service.cacheTorrent(encoded_doc) > print hash > > [result] > > Suds ( https://fedorahosted.org/suds/ ) version: 0.4 (beta) build: > R663-20100303 > > Service ( CacheService ) tns="urn:Torrage" > Prefixes (0) > Ports (1): > (CachePort) > Methods (1): > cacheTorrent(xs:string torrent, ) > Types (0): > > Traceback (most recent call last): > File "C:\Documents and Settings\yamamoto\workspace\python\console > \extract.py", line 13, in > result = client.service.cacheTorrent(encoded_doc) > File "C:\Python26\lib\site-packages\suds\client.py", line 539, in > __call__ > return client.invoke(args, kwargs) > File "C:\Python26\lib\site-packages\suds\client.py", line 598, in > invoke > result = self.send(msg) > File "C:\Python26\lib\site-packages\suds\client.py", line 627, in > send > result = self.succeeded(binding, reply.message) > File "C:\Python26\lib\site-packages\suds\client.py", line 659, in > succeeded > r, p = binding.get_reply(self.method, reply) > File "C:\Python26\lib\site-packages\suds\bindings\binding.py", line > 143, in get_reply > replyroot = sax.parse(string=reply) > File "C:\Python26\lib\site-packages\suds\sax\parser.py", line 136, > in parse > sax.parse(source) > File "C:\Python26\lib\xml\sax\expatreader.py", line 107, in parse > xmlreader.IncrementalParser.parse(self, source) > File "C:\Python26\lib\xml\sax\xmlreader.py", line 123, in parse > self.feed(buffer) > File "C:\Python26\lib\xml\sax\expatreader.py", line 211, in feed > self._err_handler.fatalError(exc) > File "C:\Python26\lib\xml\sax\handler.py", line 38, in fatalError > raise exception > xml.sax._exceptions.SAXParseException::2:0: junk after > document element > > > this is a php code provided by torrage > $client = new SoapClient("http://torrage.com/api/ > torrage.wsdl"); > $infoHash = $client- >> cacheTorrent(base64_encode(file_get_contents("my.torrent"))); > ?> > > any suggestions? Looks like the XML is malformed. Can you post it? You can insert print-statements into the library to do so, eg in line 143 of suds.bindings.binding. Diez Diez From jpiitula at ling.helsinki.fi Thu Mar 4 16:47:49 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 04 Mar 2010 23:47:49 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml References: Message-ID: This is the full data file on which my regress/Tribug exhibits the behaviour that I find incomprehensible, described in the first post in this thread. The comment in the beginning of the file below was written before I commented out some records in the data, so the actual numbers now are not ten expected, thirty sometimes observed, but the wrong number is always the correct number tripled (5 and 15, I think). ---regress/tridata.py follows--- # Exercise lxml.etree.parse(body).xpath(title) # which I think should always return a list of # ten elements but sometimes returns thirty, # with each of the ten in triplicate. And this # seems impossible to me. Yet I see it happening. body = b''' 2010-03-02T09:38:47Z http://localhost/pmh/que
jrc32003R0055-pl.xml/2/0 2004-08-15T19:45:00Z pl
Rozporządzenie
jrc32003R0055-pl.xml/3/1 2004-08-15T19:45:00Z pl
dnia
jrc32003R0055-pl.xml/3/2 2004-08-15T19:45:00Z pl
13
jrc32003R0055-pl.xml/3/3 2004-08-15T19:45:00Z pl
stycznia
jrc32003R0055-pl.xml/3/4 2004-08-15T19:45:00Z pl
2003
''' title = '//*[name()="record"]//*[name()="dc:title"]' From jgardner at jonathangardner.net Thu Mar 4 16:54:45 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 4 Mar 2010 13:54:45 -0800 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <6cc20cea1003041354s3cb5011cmbbaf39eefed7a4e4@mail.gmail.com> On Thu, Mar 4, 2010 at 10:39 AM, Pete Emerson wrote: > > #!/usr/bin/python > More common: #!/usr/bin/env python > import sys, fileinput, re, os > > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > ? ? ? ?match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > ? ? ? ?if match is None or re.search('^(?:float|localhost)\.', line): > continue > ? ? ? ?hostname = match.group(1) In Python, we use REs as a last resort. See "dir("")" or "help("")" for why we don't use REs if we can avoid them. The above is better represented with: try: ipaddr, hostnames = line.split(None, 1) except IndexError: continue if line.find('float') >=0 or line.find('localhost') >= 0: continue > ? ? ? ?count = 0 > ? ? ? ?for arg in sys.argv[1:]: > ? ? ? ? ? ? ? ?for section in hostname.split('.'): > ? ? ? ? ? ? ? ? ? ? ? ?if section == arg: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?count = count + 1 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?break > ? ? ? ?if count == len(sys.argv) - 1: > ? ? ? ? ? ? ? ?hosts.append(hostname) > You can use the "else" in a "for". as well. for arg in sys.argv[1:]: for section in hostname.split('.'): if section == arg: break else: # Run only if for completes naturally hosts.append(hostname) It may be clearer to do set arithmetic as well. > if len(hosts) == 1: > ? ? ? ?os.system("ssh -A " + hosts[0]) You probably want one of the os.exec* methods instead, since you aren't going to do anything after this. > else: > ? ? ? ?print '\n'.join(hosts) Rather, the idiom is usually: for host in hosts: print host -- Jonathan Gardner jgardner at jonathangardner.net From mensanator at aol.com Thu Mar 4 17:21:16 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Mar 2010 14:21:16 -0800 (PST) Subject: _winreg and access registry settings of another user References: <4b90252b$0$17806$426a34cc@news.free.fr> Message-ID: <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> On Mar 4, 3:24?pm, News123 wrote: > Hi, > > I habe administrator privilege ?on a window host and would like to write > a script setting some registry entries for other users. Why? Are you writing a virus? > > There are potentially at least two wo ways of doing this: > > 1.) start a subprocess as other user and change the regitrey for > CURRENT_USER > > However I don't know how to start a process (or ideally just a thread) > as another user with python. > > 2.) Load the 'hive' of the othe user and chnage the registry. > > It seems, that one has to load the 'hive' of a different user in order > to have access to somebody eleses registry entries. > > I did not find any documetnation of how to load a 'hive' wit the library > _winreg or another python library/ > > Did anybody else try already something similiar? > > thanks in advance for pointers > > bye > > N From fabiofz at gmail.com Thu Mar 4 17:25:20 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 4 Mar 2010 19:25:20 -0300 Subject: Pydev 1.5.5 Released Message-ID: Hi All, Pydev 1.5.5 has been released Details on Pydev: http://pydev.org Details on its development: http://pydev.blogspot.com Release Highlights: ------------------------------- * Predefined completions available for code completion: * Predefined completions may be created for use when sources are not available * Can also be used for providing better completions for compiled modules (e.g.: PyQt, wx, etc.) * Defined in .pypredef files (which are plain Python code) * Provides a way for generating those from a QScintilla .api file (experimental) * See Predefined Completions in manual for more info * Pydev Package Explorer: * Showing the contents of the PYTHONPATH from the interpreter for each project * Shows the folder containing the python interpreter executable (to browse for docs, scripts, etc) * Allows opening files in the interpreter PYTHONPATH (even inside zip files) * Editor options: * Find/replace dialog has option to search in currently opened editors * Move line up/down can move considering Python indentation (not default) * Simple token completions can have a space or a space and colon added when applied. E.g.: print, if, etc (not default) * Refactoring: * Fixed InvalidThreadAccess on refactoring * Fixed problem doing refactoring on external files (no file was found) * Globals Browser (Ctrl+Shift+T): * No longer throwing NullPointerException when the interpreter is no longer available for a previously found token * General: * When creating a new pydev project, the user will be asked before changing to the pydev perspective * Only files under source folders are analyzed (files in the external source folders would be analyzed if they happened to be in the Eclipse workspace) * Interactive console now works properly on non-english systems * Hover working over tokens from compiled modules (e.g.: file, file.readlines) * JYTHONPATH environment variable is set on Jython (previously only the PYTHONPATH was set) * Fixed path translation issues when using remote debugger * Fixed issue finding definition for a method of a locally created token What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, refactor, debug and many others. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer Aptana http://aptana.com/python Pydev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com From alfps at start.no Thu Mar 4 17:27:03 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Mar 2010 23:27:03 +0100 Subject: A "scopeguard" for Python In-Reply-To: <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: * Mike Kent: > On Mar 4, 12:30 pm, Robert Kern wrote: > >> He's ignorant of the use cases of the with: statement, true. > > Ouch! Ignorant of the use cases of the with statement, am I? > Odd, I use it all the time. > >> Given only your >> example of the with: statement, it is hard to fault him for thinking that try: >> finally: wouldn't suffice. > > Damn me with faint praise, will you? > > I'm kinda amazed at the drama my innocent request for the use case > elicited. From what I've gotten so far from this thread, for the > actual example Mr. Steinbach used, the only disadvantage to my counter- > example using try/finally is that the chdir in the finally part will > always be executed, even if the chdir in the try part did not > succeed. I concede that, and was aware of it when I wrote it. For > the simple example given, I did not consider it compelling. Uhm, well. My example was: with Cleanup as at_cleanup: # blah blah chdir( somewhere ) at_cleanup.call( lambda: chdir( original_dir ) ) # blah blah It was not intended to compel, rather just to illustrate usage. :-) And you asked about comparing that with ... original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup .. which does something different, namely, always executing the os.chdir(original_dir) or more generally the action-specific cleanup. The action-specific cleanup might be much more costly than a chdir, and/or, in the case where the action failed, incorrect. In the same number of lines and with fewer keystrokes you could have written code that was equivalent to the code I posted and that you wanted to compare with, e.g. ... original_dir = os.getcwd() os.chdir(somewhere) try: # Do other stuff finally: os.chdir(original_dir) # Do other cleanup ... so given how easy it is to write such an equivalent code snippet, I assumed that the different behavior was /not/ intended, that instead, you'd attempted to write equivalent code but made a slight error in the translation to lower level construct -- but impossible to say exactly what. Now you write that you were "aware of [the different behavior] when I wrote it", and that just baffles me: why not then, as a basis of sound comparision, write the equivalent code shown above, the same number of lines as what you wrote? > A more > complex example, that would have required multiple, nested try/finally > blocks, would show the advantages of Mr Steinbach's recipe more > clearly. > > However, I fail to understand his response that I must have meant try/ > else instead, as this, as Mr. Kern pointed out, is invalid syntax. > Perhaps Mr. Steinbach would like to give an example? OK. Assuming that you wanted the chdir to be within a try block (which it was in your code), then to get code equivalent to my code, for the purpose of a comparision of codes that do the same, you'd have to write something like ... original_dir = os.getcwd() try: os.chdir(somewhere) except Whatever: # E.g. log it. raise else: try: # Do other stuff finally: os.chdir(original_dir) # Do other cleanup ... which would be a more general case. I've also given this example in response to Robert earlier in the thread. Although I haven't tried it I believe it's syntactically valid. If not, then the relevant typo should just be fixed. :-) I have no idea which construct Robert thought was syntactically invalid. I think that if he's written that, then it must have been something he thought of. Cheers & hth., - Alf From sjdevnull at yahoo.com Thu Mar 4 17:55:07 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 4 Mar 2010 14:55:07 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <692c83be-0075-470f-a970-8e5c5c301eb0@g7g2000yqe.googlegroups.com> On Mar 4, 1:39?pm, Pete Emerson wrote: > I've written my first python program, and would love suggestions for > improvement. > > I'm a perl programmer and used a perl version of this program to guide > me. So in that sense, the python is "perlesque" > > This script parses /etc/hosts for hostnames, and based on terms given > on the command line (argv), either prints the list of hostnames that > match all the criteria, or uses ssh to connect to the host if the > number of matches is unique. > > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". > > I am aware that there are performance improvements and error checking > that could be made, such as making sure the file exists and is > readable and precompiling the regular expressions and not calculating > how many sys.argv arguments there are more than once. I'm not hyper > concerned with performance or idiot proofing for this particular > script. > > Thanks in advance. > > ######################################################## > #!/usr/bin/python > > import sys, fileinput, re, os 'Some people, when confronted with a problem, think "I know, I?ll use regular expressions." Now they have two problems.' ? Jamie Zawinski Seriously, regexes can be very useful but there's no need for them here. Simpler is usually better, and easier to understand. > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > ? ? ? ? match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > ? ? ? ? if match is None or re.search('^(?:float|localhost)\.', line): > continue > ? ? ? ? hostname = match.group(1) I find this much clearer without regexes: try: ip, hostname = line.strip().split(None, 1) except IndexError: continue # I think this is equivalent to your re, but I'm not sure it's what # you actually meant... #if line.startswith("float.") or line.startswith("localhost."): # continue # I'm going with: if hostname.startswith("float.") or hostname.startswith("localhost"): continue > ? ? ? ? count = 0 > ? ? ? ? for arg in sys.argv[1:]: > ? ? ? ? ? ? ? ? for section in hostname.split('.'): > ? ? ? ? ? ? ? ? ? ? ? ? if section == arg: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? count = count + 1 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break > ? ? ? ? if count == len(sys.argv) - 1: > ? ? ? ? ? ? ? ? hosts.append(hostname) A perfect application of sets. #initialize at program outset args = set(sys.argv[1:]) ... hostparts = set(hostname.split(".")) if hostparts & args: hosts.append(hostname) Full program: import sys import os filename = '/etc/hosts' hosts = [] args = set(sys.argv[1:]) for line in open(filename, 'r'): # Parse line into ip address and hostname, skipping bogus lines try: ipaddr, hostname = line.strip().split(None, 1) except ValueError: continue if hostname.startswith("float.") or hostname.startswith("localhost."): continue # Add to hosts if it matches at least one argument hostparts = set(hostname.split(".")) if hostparts & args: hosts.append(hostname) # If there's only one match, ssh to it--otherwise print out the matches if len(hosts) == 1: os.system("ssh -A %s"%hosts[0]) else: for host in hosts: print host From python at bdurham.com Thu Mar 4 18:10:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 04 Mar 2010 18:10:06 -0500 Subject: Looking for the mysterious zlib.py* files in Python 2.6.4 (32-bit) for Windows In-Reply-To: <1267743672.16774.1363182565@webmail.messagingengine.com> References: <1267743672.16774.1363182565@webmail.messagingengine.com> Message-ID: <1267744206.18232.1363186281@webmail.messagingengine.com> In the process of building an EXE with py2exe, I noticed that there's no physical zlib files anywhere on my workstation. I can import zlib and use this module's features without problem. But when I query zlib.__file__, I get back an empty string. Where does the zlib code live? Is zlib a in 2.6? The reason I question its '' status is that when analyzing my 2.6 based Py2exe produced executables with DependencyWalker, I see references to a zlib.pyd file that doesn't exist anywhere on my system. I wonder if this is something I should be concerned about? Can someone explain this mystery to me? Thank you, Malcolm From alfps at start.no Thu Mar 4 18:52:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 00:52:04 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >> [snippety] >>>>> >>>>>> If you call the possibly failing operation "A", then that systematic >>>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>>> mess, but if A succeeds, then it's the responsibility of the calling >>>>>> code to clean up if the higher level (multiple statements) operation >>>>>> that A is embedded in, fails. >>>>>> >>>>>> And that's what Marginean's original C++ ScopeGuard was designed for, >>>>>> and what the corresponding Python Cleanup class is designed for. >>>>> >>>>> And try: finally:, for that matter. >>>> >>>> Not to mention "with". >>>> >>>> Some other poster made the same error recently in this thread; it is a >>>> common fallacy in discussions about programming, to assume that since >>>> the same can be expressed using lower level constructs, those are all >>>> that are required. >>>> >>>> If adopted as true it ultimately means the removal of all control >>>> structures above the level of "if" and "goto" (except Python doesn't >>>> have "goto"). >>> >>> What I'm trying to explain is that the with: statement has a use even >>> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >>> finally: does not mean that the with: statement doesn't improve on >>> try: finally:. >> >> That's a different argument, essentially that you see no advantage for >> your current coding patterns. >> >> It's unconnected to the argument I responded to. >> >> The argument that I responded to, that the possibility of expressing >> things at the level of try:finally: means that a higher level construct >> is superfluous, is still meaningless. > > I am attacking your premise that the "with Cleanup():" construct is > higher level than try: finally:. It isn't. It provides the same level of > abstraction as try: finally:. > > This is distinct from the accepted uses of the with: statement which > *are* higher level than try: finally: and which do confer practical > benefits over using try: finally: despite being syntactical sugar for > try: finally:. > >>>>>>> Both formulations can be correct (and both work perfectly fine with >>>>>>> the chdir() example being used). Sometimes one is better than the >>>>>>> other, and sometimes not. You can achieve both ways with either your >>>>>>> Cleanup class or with try: finally:. >>>>>>> >>>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>>> try: >>>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>>> into >>>>>>> callables. This significantly limits what you can do in your cleanup >>>>>>> code. >>>>>> >>>>>> Uhm, not really. :-) As I see it. >>>>> >>>>> Well, not being able to affect the namespace is a significant >>>>> limitation. Sometimes you need to delete objects from the namespace in >>>>> order to ensure that their refcounts go to zero and their cleanup code >>>>> gets executed. >>>> >>>> Just a nit (I agree that a lambda can't do this, but as to what's >>>> required): assigning None is sufficient for that[1]. >>> >>> Yes, but no callable is going to allow you to assign None to names in >>> that namespace, either. Not without sys._getframe() hackery, in any >>> case. >>> >>>> However, note that the current language doesn't guarantee such cleanup, >>>> at least as far as I know. >>>> >>>> So while it's good practice to support it, to do everything to let it >>>> happen, it's presumably bad practice to rely on it happening. >>>> >>>> >>>>> Tracebacks will keep the namespace alive and all objects in it. >>>> >>>> Thanks!, I hadn't thought of connecting that to general cleanup >>>> actions. >>>> >>>> It limits the use of general "with" in the same way. >>> >>> Not really. >> >> Sorry, it limits general 'with' in /exactly/ the same way. >> >>> It's easy to write context managers that do that [delete objects from >>> the namespace]. >> >> Sorry, no can do, as far as I know; your following example quoted below >> is an example of /something else/. > > Okay, so what do you mean by 'the use of general "with"'? I'm talking > about writing a context manager or using the @contextmanager decorator > to do some initialization and then later cleaning up that > initialization. That cleaning up may entail deleting an object. You are > correct that the context manager can't affect the namespace of the with: > clause, but that's not the initialization that it would need to clean up. > > Yes, you can write code with a with: statement where you try to clean up > stuff that happened inside of the clause (you did), but that's not how > the with: statement was ever intended to be used nor is it good practice > to do so because of that limitation. Context managers are designed to > initialize specific things, then clean them up. I thought you were > talking about the uses of the with: statement as described in PEP-343, > not every possible misuse of the with: statement. I'm not the one talking about removing variables or that "it's easy to write context managers that do that". You are the one talking about that. So I have really not much to add. It seems that you're now agreeing with me that former is not good practice and that the latter is impossible to do portably, but you now argue against your earlier stand as if that was something that I had put forward. It's a bit confusing when you argue against your own statements. >> And adding on top of irrelevancy, for the pure technical aspect it can >> be accomplished in the same way using Cleanup (I provide an example >> below). >> >> However, doing that would generally be worse than pointless since with >> good coding practices the objects would become unreferenced anyway. >> >> >>> You put the initialization code in the __enter__() method, assign >>> whatever objects you want to keep around through the with: clause as >>> attributes on the manager, then delete those attributes in the >>> __exit__(). >> >> Analogously, if one were to do this thing, then it could be accomplished >> using a Cleanup context manager as follows: >> >> foo = lambda: None >> foo.x = create_some_object() >> at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) >> >> ... except that >> >> 1) for a once-only case this is less code :-) > > Not compared to a try: finally:, it isn't. Again, this context shifting is bewildering. As you can see, quoted above, you were talking about a situation where you would have defined a context manager, presumably because a 'try' would not in your opinion be simpler for whatever it was that you had in mind. But you are responding to the code I offered as if it was an alternative to something where you would find a 'try' to be simplest. >> 2) it is a usage that I wouldn't recommend; instead I recommend adopting >> good >> coding practices where object references aren't kept around. > > Many of the use cases of the with: statement involve creating an object > (like a lock or a transaction object), keeping it around for the > duration of the "# Do stuff" block, and then finalizing it. > >>> Or, you use the @contextmanager decorator to turn a generator into a >>> context manager, and you just assign to local variables and del them >>> in the finally: clause. >> >> Uhm, you don't need a 'finally' clause when you define a context manager. > > When you use the @contextmanager decorator, you almost always do. See > the Examples section of PEP 343: > > http://www.python.org/dev/peps/pep-0343/ > >> Additionally, you don't need to 'del' the local variables in >> @contextmanager decorated generator. >> >> The local variables cease to exist automatically. > > True. > >>> What you can't do is write a generic context manager where the >>> initialization happens inside the with: clause and the cleanup actions >>> are registered callables. That does not allow you to affect the >>> namespace. >> >> If you mean that you can't introduce direct local variables and have >> them deleted by "registered callables" in a portable way, then right. >> >> But I can't think of any example where that would be relevant; in >> particular what matters for supporting on-destruction cleanup is whether >> you keep any references or not, not whether you have a local variable of >> any given name. > > Well, local variables keep references to objects. Variable assignment > followed by deletion is a very readable way to keep an object around for > a while then remove it later. If you have to go through less readable > contortions to keep the object around when it needs to be and clean it > up later, then that is a mark against your approach. Sorry, as with the places noted above, I can't understand what you're trying to say here. I don't recommend coding practices where you keep object references around, and you have twice quoted that above. I don't have any clue what "contortions" you are talking about, it must be something that you imagine. Cheers, - Alf (three times baffled) From mentifex at myuw.net Thu Mar 4 18:52:36 2010 From: mentifex at myuw.net (Forthminder) Date: Thu, 4 Mar 2010 15:52:36 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <5b3da248-0ccb-4451-a322-0fcabe744b41@k5g2000pra.googlegroups.com> Google AI Challenge post-mortem report by the winner is at http://a1k0n.net/blah/archives/2010/03/index.html#e2010-03-04T14_00_21.txt Mentifex -- http://cyborg.blogspot.com http://code.google.com/p/mindforth/wiki/AiHasBeenSolved From pengyu.ut at gmail.com Thu Mar 4 18:57:35 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Thu, 4 Mar 2010 15:57:35 -0800 (PST) Subject: highlight words by regex in pdf files using python Message-ID: I don't find a general pdf library in python that can do any operations on pdfs. I want to automatically highlight certain words (using regex) in a pdf. Could somebody let me know if there is a tool to do so in python? From pemerson at gmail.com Thu Mar 4 18:59:58 2010 From: pemerson at gmail.com (Pete Emerson) Date: Thu, 4 Mar 2010 15:59:58 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <692c83be-0075-470f-a970-8e5c5c301eb0@g7g2000yqe.googlegroups.com> Message-ID: Great responses, thank you all very much. I read Jonathan Gardner's solution first and investigated sets. It's clearly superior to my first cut. I love the comment about regular expressions. In perl, I've reached for regexes WAY too much. That's a big lesson learned too, and from my point of view not because of performance (although that's most likely a bonus) but because of code readability. Here's the version I have now. It looks quite similar to sjdevnull's. Further comments appreciated, and thanks again. #!/usr/bin/env python import sys, fileinput, os filename = '/etc/hosts' hosts = [] search_terms = set(sys.argv[1:]) for line in open(filename, 'r'): if line.startswith('#'): continue try: hostname = line.strip().split('\t')[2] # The host I want is always at the 3rd tab. except IndexError: continue if hostname.startswith('float.') or hostname.startswith('localhost.'): continue if search_terms <= set(hostname.split('.')): # same as if search_terms.issubset(hostname.split('.')): hosts.append(hostname) if len(hosts) == 1: os.execl("/usr/bin/ssh", '-A', hosts[0]) else: for host in hosts: print host From nobody at nowhere.com Thu Mar 4 19:05:10 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Mar 2010 00:05:10 +0000 Subject: Challenge: escape from the pysandbox References: <201002261329.33740.victor.stinner@haypocalc.com> Message-ID: On Wed, 03 Mar 2010 03:37:44 +0100, Victor Stinner wrote: >> I see, makes perfect sense. This then raises the question whether it's >> important to have a 100% fool proof python sandbox without help from >> the OS, or this goal is not only too ambitious but also not really a >> useful one. > > This is just impossible :-) PHP tried that but it's too hard to write an > exhaustive blacklist because too much code have to be modified. If you > require a 100% fool proof sandbox, you have to use a sandbox between the > Python process and the OS (and not inside the Python process). It's entirely feasible to implement a perfect sandbox at the language level. But you have to design this in from the beginning. If you try to retro-fit it, you end up either failing or with an entirely different language. A black-list approach won't work; you have to deny by default then white-list "safe" functionality. From nobody at nowhere.com Thu Mar 4 19:09:39 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Mar 2010 00:09:39 +0000 Subject: using subprocess.Popen env parameter References: <47f5881a-a7bd-4a57-8e2d-ae27cfbf3a9a@x22g2000yqx.googlegroups.com> Message-ID: On Wed, 03 Mar 2010 09:05:47 -0800, enda man wrote: > cl_path = ms_vc_path + '\VC\bin' The backslash is used as an escape character within string literals. Either use raw strings: cl_path = ms_vc_path + r'\VC\bin' or escape the backslashes: cl_path = ms_vc_path + '\\VC\\bin' or use os.path.join(): cl_path = os.path.join(ms_vc_path, 'VC', 'bin') From strombrg at gmail.com Thu Mar 4 19:25:30 2010 From: strombrg at gmail.com (Dan Stromberg) Date: Thu, 4 Mar 2010 16:25:30 -0800 (PST) Subject: Fast GUI pipemeter: gprog References: <619ab895-87a9-4b40-b45e-b12299304b38@z1g2000prc.googlegroups.com> <1686070.lZ2vcFHjTE@xkzjympik> Message-ID: On Mar 4, 1:15?pm, pk wrote: > Dan Stromberg wrote: > > In case you're interested, I've put a fast GUI pipemeter (measures how > > fast data is moving through a pipe or redirect and gives two estimates > > of time-to-completion - one based on the entire transfer so far, and > > one based on a user-specifiable number of blocks) up at: > > >http://stromberg.dnsalias.org/~dstromberg/gprog/ > > > It uses a dual process design (to make things a bit faster on dual > > core or better systems) with a cache oblivious algorithm (to self-tune > > block sizes for good performance) - I've seen it sustain over 2 > > gigabits/second, and that despite Linux' /dev/zero insisting on a tiny > > blocksize. ?I wasn't able to construct a RAM disk large enough to get > > anything like a sustained result with larger blocksizes than what > > Linux' /dev/zero likes - that is, not without springing for a new > > machine with a huge amount of RAM. ?IOW, your disk or network will > > very likely be the bottleneck, not the tool. > > > I hope it helps someone. > > This sounds similar to "pv", although pv does not have a GUI. Um, yes, pv is similar and has a pretty nice character cell GUI as it were. I suppose I'd neglected to mention that I put a list of similar tools at the beginning of the gprog page, including pv. Thanks for making sure we were aware of pv. Interesting that pv seems to be successfully getting 128K blocks out of /dev/zero. For some reason, gprog always gets back 16K blocks from /dev/zero, even when requesting blocks of sizes substantially larger. gprog automatically detects this and just starts asking for 16K. Python folk: Any guesses why a simple file.read(blocksize) would have such an affinity for returning 16K when redirected from /dev/zero? If I run the program against a file on disk, it gets larger blocksizes fine. From hwmeder at alumni.unc.edu Thu Mar 4 19:45:47 2010 From: hwmeder at alumni.unc.edu (Harold Meder) Date: Thu, 4 Mar 2010 19:45:47 -0500 Subject: Python Opportunity at OPNET Message-ID: <3a102d3b1003041645o54bb6823k7f3c66ab3c49eaef@mail.gmail.com> I stumbled across this Job Postingat OPNET. I hope that it is acceptable to post this type of info on this mailing list. I do not know any further information regarding this opportunity. Harold Meder. -------------- next part -------------- An HTML attachment was scrubbed... URL: From electriclightheads at gmail.com Thu Mar 4 19:48:19 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 5 Mar 2010 09:48:19 +0900 Subject: pyao makes the right sound but why? In-Reply-To: References: Message-ID: <1078018b1003041648v1060ddd6ibc482b22ab4c0b2d@mail.gmail.com> omg! u r actually testin my dirty code?! tnx that's great! to create an instance soy.py depends on(needs all of em): http://sarigama.namaste.jp/oil/tit01.wav http://sarigama.namaste.jp/oil/tit02.wav http://sarigama.namaste.jp/oil/tit03.wav http://sarigama.namaste.jp/oil/tit04.wav http://sarigama.namaste.jp/oil/tit05.wav http://sarigama.namaste.jp/oil/tit06.wav http://sarigama.namaste.jp/oil/tit07.wav and the easiest way to get the pattern is instance.pattern(howmanyframes) the object updates itself with .sing() and can affect each other with .jam_with(other_instance) this design is to (in the future) create somethang together with someone who would upload a short.wav on his site (to contrubute .. or maybe without willin to ;)) have to study urllib(?) for things to come have to experiment more with picklin aspects too but this is my attempt to beat the "listenin to mp3s" culture btw. where's that help(ao)? On Fri, Mar 5, 2010 at 3:43 AM, Anssi Saari wrote: > "'2+" writes: > >> dev = ao.AudioDevice('alsa') >> dev.play(x) >> >> could launch me a semi realtime dj kinda sys >> luckily .. it does seem to be making the right sound >> but why? >> the default of the samplerate and that 16bit happened to match with my thing x? > > Yes, that seems to be the case from help(ao). But I couldn't run > tofu = soy.Bean() since it seems to want tit01.wav. Do you make that > available somewhere? > -- > http://mail.python.org/mailman/listinfo/python-list > -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From howe.steven at gmail.com Thu Mar 4 19:55:24 2010 From: howe.steven at gmail.com (Steven Howe) Date: Thu, 04 Mar 2010 16:55:24 -0800 Subject: Python Opportunity at OPNET In-Reply-To: <3a102d3b1003041645o54bb6823k7f3c66ab3c49eaef@mail.gmail.com> References: <3a102d3b1003041645o54bb6823k7f3c66ab3c49eaef@mail.gmail.com> Message-ID: <4B90567C.7010305@gmail.com> On 03/04/2010 04:45 PM, Harold Meder wrote: > I stumbled across this Job Posting > at > OPNET. > I hope that it is acceptable to post this type of info on this mailing > list. > I do not know any further information regarding this opportunity. > > Harold Meder. Harold, Thats just a net looking to scoop up people. There's no job there. Just a staffing house looking for resumes in expectation for the job market to pickup. Staffing houses rip tech people off. sph -------------- next part -------------- An HTML attachment was scrubbed... URL: From electriclightheads at gmail.com Thu Mar 4 19:58:14 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 5 Mar 2010 09:58:14 +0900 Subject: pyao makes the right sound but why? In-Reply-To: <1078018b1003041648v1060ddd6ibc482b22ab4c0b2d@mail.gmail.com> References: <1078018b1003041648v1060ddd6ibc482b22ab4c0b2d@mail.gmail.com> Message-ID: <1078018b1003041658h786c2b6s29f5588bc65cb944@mail.gmail.com> o .. but u can use ur own tits.wav if it is 44100 mono 16bit and picklin n uploading the tofu n having lots of those on the net 2 increase vegetrians is what soy.py wanted to mean On Fri, Mar 5, 2010 at 9:48 AM, '2+ wrote: > omg! u r actually testin my dirty code?! > tnx that's great! > to create an instance > soy.py depends on(needs all of em): > > http://sarigama.namaste.jp/oil/tit01.wav > http://sarigama.namaste.jp/oil/tit02.wav > http://sarigama.namaste.jp/oil/tit03.wav > http://sarigama.namaste.jp/oil/tit04.wav > http://sarigama.namaste.jp/oil/tit05.wav > http://sarigama.namaste.jp/oil/tit06.wav > http://sarigama.namaste.jp/oil/tit07.wav > > and the easiest way to get the pattern is instance.pattern(howmanyframes) > the object updates itself with .sing() > and can affect each other with .jam_with(other_instance) > > this design is to (in the future) create somethang together > with someone who would upload a short.wav on his site (to contrubute > .. or maybe without willin to ;)) > have to study urllib(?) for things to come > have to experiment more with picklin aspects too > but this is my attempt to beat the > "listenin to mp3s" culture > > btw. where's that help(ao)? > > On Fri, Mar 5, 2010 at 3:43 AM, Anssi Saari wrote: >> "'2+" writes: >> >>> dev = ao.AudioDevice('alsa') >>> dev.play(x) >>> >>> could launch me a semi realtime dj kinda sys >>> luckily .. it does seem to be making the right sound >>> but why? >>> the default of the samplerate and that 16bit happened to match with my thing x? >> >> Yes, that seems to be the case from help(ao). But I couldn't run >> tofu = soy.Bean() since it seems to want tit01.wav. Do you make that >> available somewhere? >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > > -- > SaRiGaMa's Oil Vending Orchestra > is podcasting: > http://sarigama.namaste.jp/podcast/rss.xml > -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From robert.kern at gmail.com Thu Mar 4 20:04:30 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 19:04:30 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 15:19 PM, Mike Kent wrote: > On Mar 3, 12:00 pm, Robert Kern wrote: >> On 2010-03-03 09:39 AM, Mike Kent wrote: >> >>> What's the compelling use case for this vs. a simple try/finally? >> >>> original_dir = os.getcwd() >>> try: >>> os.chdir(somewhere) >>> # Do other stuff >>> finally: >>> os.chdir(original_dir) >>> # Do other cleanup >> >> A custom-written context manager looks nicer and can be more readable. >> >> from contextlib import contextmanager >> import os >> >> @contextmanager >> def pushd(path): >> original_dir = os.getcwd() >> os.chdir(path) >> try: >> yield >> finally: >> os.chdir(original_dir) >> >> with pushd(somewhere): >> ... > > Robert, I like the way you think. That's a perfect name for that > context manager! However, you can clear one thing up for me... isn't > the inner try/finally superfluous? My understanding was that there > was an implicit try/finally already done which will insure that > everything after the yield statement was always executed. No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. This raises the exception inside the generator at the yield statement. -- 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 From alfps at start.no Thu Mar 4 20:59:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 02:59:31 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Robert Kern: > [...] >>> No, it only argues that "with Cleanup():" is supernumerary. >> I don't know what "supernumerary" means, but to the degree that the >> argument says anything about a construct that is not 'finally', it says >> the same about general "with". >> > So rather than look up the meaning if a word you aren't familiar with > you will argue against its use in generic style? I haven't argued against the use of the word. I haven't done so in generic style, and I haven't argued against generic style use of the word, whatever it is you're trying to say. And I see that you're out trolling again, Steve Holden, implying all sorts of things that are untrue, as is evidently still your style. >> So whatever you mean by supernumerary, you're saying that the argument >> implies that "with" is supernumerary. >> >> This is starting to look like some earlier discussions in this group, >> where even basic logic is denied. >> > Why not just stick to the facts and forget about the earlier discussions? For yet another example, here you are implying that I'm not sticking to facts, which, again, is untrue, a technique that you should be ashamed of, Steve Holden. And since you're now injecting some Steve Holden'sk noise into this debate, chances are that in your points- and win/lose fixation you think I have scored a point immediately upthread, something which you think needs drowning in noise. Cheers, - Alf From breamoreboy at yahoo.co.uk Thu Mar 4 21:01:37 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 05 Mar 2010 02:01:37 +0000 Subject: Looking for the mysterious zlib.py* files in Python 2.6.4 (32-bit) for Windows In-Reply-To: <1267744206.18232.1363186281@webmail.messagingengine.com> References: <1267743672.16774.1363182565@webmail.messagingengine.com> <1267744206.18232.1363186281@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: > In the process of building an EXE with py2exe, I noticed that > there's no physical zlib files anywhere on my workstation. > > I can import zlib and use this module's features without problem. > But when I query zlib.__file__, I get back an empty string. > > Where does the zlib code live? Is zlib a in 2.6? > > The reason I question its '' status is that when > analyzing my 2.6 based Py2exe produced executables with > DependencyWalker, I see references to a zlib.pyd file that > doesn't exist anywhere on my system. I wonder if this is > something I should be concerned about? > > Can someone explain this mystery to me? > > Thank you, > Malcolm c:\Users\Mark>python Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import zlib >>> help(zlib) Help on built-in module zlib: NAME zlib FILE (built-in) [snip the rest of the help output] IIRC a pyd file is really a DLL, but for a built-in its included into in this case python26.dll. HTH. Mark Lawrence From dsblizzard at gmail.com Thu Mar 4 21:10:59 2010 From: dsblizzard at gmail.com (DSblizzard) Date: Thu, 4 Mar 2010 18:10:59 -0800 (PST) Subject: Problem with modules reloading Message-ID: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> I have had already following question: "How to use *.py modules instead of *.pyc?" Last time I when asked that question I resolved problem by using one big .py file. And answers doesn't work in my case. Now I ought to use several files and almost the same problem arises again. Admit I have 2 modules: m2.py and m1.py in m2.py: from m1.py import * def foo2(): foo1() foo2() in m1.py: # empty After copying m2.py contents directly to python.exe: "NameError: global name 'foo1' is not defined" Then I define foo1 in m1 and copy following lines to python.exe: from m1.py import * foo2() Nothing changes, the same error, and .pyc files, if I have deleted them doesn't created again. What is the solution? From timx at nospam.dev.null Thu Mar 4 21:20:02 2010 From: timx at nospam.dev.null (Tim X) Date: Fri, 05 Mar 2010 13:20:02 +1100 Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> Message-ID: <87sk8f1pd9.fsf@lion.rapttech.com.au> ccc31807 writes: > On Mar 3, 4:55?pm, toby wrote: >> > ?where you have to store data and >> >> "relational data" > > Data is neither relational nor unrelational. Data is data. > Relationships are an artifact, something we impose on the data. > Relations are for human convenience, not something inherent in the > data itself. > >> > perform a large number of queries. >> >> Why does the number matter? > > Have you ever had to make a large number of queries to an XML > database? In some ways, an XML database is the counterpart to a > relational database in that the data descriptions constitute the > relations. However, since the search is to the XML elements, and you > can't construct indicies for XML databases in the same way you can > with relational databases, a large search can take much longer that > you might expect. > Most XML databases are just a re-vamp of hierarchical databases, which are one of the two common formats that came before relational databases. Hierarchical, network and relational databases all have their uses. Some 'xml' databases, like existsdb have some pretty powerful indexing technologies. while they are different to relational db indexing because they are based around hierarchies rather than relations, they do provide the ability to do fast queries in the same way that indexes in relational databases allow fast queries over relations. Both solutions can do fast queries, they are just optimised for different types of queries. Likewise, other database technologies that tend to fall into this category, such as couch and mungo are aimed at applications and problems that aren't suitable for the relational db model and are better suited to the types of applications they have been designed for. As usual, Xah's rantings are of little substance here. Yes, he is right that 'nosql' is essentially just another buzzword like 'web 2.0', but so what? This is an industry that loves its buzzwords.Often its just marketing hype or some convenience holder for a vague 'concept' some journalist, consultant or blogger wants to wank on about. You cannot hate or love 'nosql' without defining exactly what you mean by the term. Xah starts by acknowledging the term is ill defined and then goes on to say how he doesn't like it because it lacks the mathematical precision of the relational algebra that underpins the relational model. It seems somewhat ironic to put forward an argument focusing on the importance of precision when you fail to be precise regarding the thing your arguing against. His point is further weakened by the failure to realise that SQL and the relational model and relational algebra are different things. Not having SQL doesn't automatically mean you cannot have a relational model or operations that are based on relational algebra. SQL is just the convenient query language and while it has succeeded where other languages have not, its just one way of interacting with a relational database. As a language SQL isn't even 'pure' in that it has operations that don't fit with the relational algebra that he claims is so important and includes facillities that are really business convenience operations that actually corrupt the mathematical model and purity that is the basis of his poorly formed argument. He also overlooks the fact that none of the successful relational databases have remained true to either the relational model or the underlying theory. All of the major RDMS have corrupted things for marketing, performance or maintenance reasons. Only a very few vendors have stayed true to the relational model and none of them have achieved much in the way of market share, I wonder why? All Xah is doing is being the nets equivalent of radios 'shock jock'. He searches for some topical issue, identifies a stance that he feels will elicit the greatest number of emotional responses and lobs it into the crowd. He rarely hangs around to debate his claims. When he does, he tends to just yell and shout and more often than not, uses personal attack to defend his statements rather than arguing the topic. His analysis is usually shallow and based on popularism If someone disagrees, they are a moron or a fool and if they agree, they are a genius just like him. Just like true radio shock jocks, some willl love him and some will hate him. The only things we can be certain about are that reaction is a much hier motivator for his posts than conviction, there is probably an inverse relationship between IQ and support for his arguments and that his opinion probably has the same longevity as the term nosql. Now if we can just get back to debating important topics like why medical reform is the start of communism, how single mothers are leeching of tax payers, the positive aspects of slavery, why blacks are all criminals, how governments are evil, the holocaust conspiricy, why all muslims are terrorists, the benefits of global warming, the bad science corrupting our children's innocence and stop wasting time debating this technology stuff and please people, listen to your harts and follow your gut - don't let your intellect or so called facts get in the way, trust your emotions. Tim -- tcross (at) rapttech dot com dot au From python at bdurham.com Thu Mar 4 21:24:57 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 04 Mar 2010 21:24:57 -0500 Subject: Looking for the mysterious zlib.py* files in Python 2.6.4 (32-bit) for Windows In-Reply-To: References: <1267743672.16774.1363182565@webmail.messagingengine.com><1267744206.18232.1363186281@webmail.messagingengine.com> Message-ID: <1267755897.13084.1363210547@webmail.messagingengine.com> > IIRC a pyd file is really a DLL, but for a built-in its included into in this case python26.dll. Mystery solved! Thanks Mark! Regards, Malcolm From steve at REMOVE-THIS-cybersource.com.au Thu Mar 4 21:55:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 02:55:46 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> <7v9g9qF1nkU1@mid.individual.net> Message-ID: <4b9072b2$0$27863$c3e8da3@news.astraweb.com> On Thu, 04 Mar 2010 23:38:31 +1300, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> True, but one can look at "best practice", or even "standard practice". >> For Python coders, using docstrings is standard practice if not best >> practice. Using strings as comments is not. > > In that particular case, yes, it would be possible to objectively > examine the code and determine whether docstrings were being used as > opposed to above-the-function comments. > > However, that's only a very small part of what goes to make good code. > Much more important are questions like: Are the comments meaningful and > helpful? Is the code reasonably self-explanatory outside of the > comments? Is it well modularised, and common functionality factored out > where appropriate? Are couplings between different parts minimised? Does > it make good use of library code instead of re-inventing things? Is it > free of obvious security flaws? > > You can't *measure* these things. You can't objectively boil them down > to a number and say things like "This code is 78.3% good; the customer > requires it to be at least 75% good, so it meets the requirements in > that area." > > That's the way in which I believe that software engineering is > fundamentally different from hardware engineering. You are conflating two independent questions: (a) Can we objectively judge the goodness of code, or is it subjective? (b) Is goodness of code quantitative, or is it qualitative? You can turn any qualitative measurement into a quantitative measurement by turning it into a score from 0 to 10 (say). Instead of "best/good/ average/poor/crap" just rate it from 1 through 5, and now you have a measurement that can be averaged and compared with other measurements. The hard part is turning subjective judgements ("are these comments useful, or are they pointless or misleading?") into objective judgements. It may be that there is no entirely objective way to measure such things. But we can make quasi-objective judgements, by averaging out all the individual quirks of subjective judgement: (1) Take 10 independent judges who are all recognised as good Python coders by their peers, and ask them to give a score of 1-5 for the quality of the comments, where 1 means "really bad" and 5 means "really good". If the average score is 4 or higher, gain a point. If the average score is 3 or lower, lose a point. (2) Take 10 independent judges, as above, and rate the code on how self- explanatory it is. An average score of 3 or higher gives a point; an average of under 2 loses a point. (Note that I'm more forgiving of non-self-explanatory code than I am of bad comments. Better to have no comments than bad ones!) And so on, through all the various metrics you want to measure. If the total number of points exceeds some threshold, the software passes, otherwise it fails, and you have a nice list of all the weak areas that need improvement. You can do fancy things too, like discard the highest and lowest score from the ten judges (to avoid an unusually strict, or unusually slack, judge from distorting the scores). If this all seems too expensive, then you can save money by having fewer judges, perhaps even as few as a single code reviewer who is trusted to meet whatever standards you are hoping to apply. Or have the judges rate randomly selected parts of the code rather than all of it. This will severely penalise code that isn't self-explanatory and modular, as the judges will not be able to understand it and consequently give it a low score. Of course, there is still a subjective component to this. But it is a replicable metric: any group of ten judges should give quite similar scores, up to whatever level of confidence you want, and one can perform all sorts of objective statistical tests on them to determine whether deviations are due by chance or not. To do all this on the cheap, you could even pass it through something like PyLint, which gives you an objective (but not very complete) measurement of code quality. The real problem isn't that defining code quality can't be done, but that it can't be done *cheaply*. There are cheap methods, but they aren't very good, and good methods, but they're very expensive. -- Steven From weasle182222 at googlemail.com Thu Mar 4 22:09:57 2010 From: weasle182222 at googlemail.com (lucky-villa) Date: Thu, 4 Mar 2010 19:09:57 -0800 (PST) Subject: baufinanzierung berechnung , eigentumswohnungen finanzieren , eigenheimzulage verdienstgrenze , eigenheimzulage unentgeltliche , bauspardarlehen in anspruch nehmen , immobilienfinanzierung von , eigenheimzulage ab 2009 , Message-ID: baufinanzierung berechnung , eigentumswohnungen finanzieren , eigenheimzulage verdienstgrenze , eigenheimzulage unentgeltliche , bauspardarlehen in anspruch nehmen , immobilienfinanzierung von , eigenheimzulage ab 2009 , + + +++ GUENSTIGE KREDITE ONLINE +++ KREDITE IM INTERNET OHNE SCHUFA IMMOBILIEN +++ + http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL http://WWW.IMMOBILIEN-KREDIT-ONLINE.NL + + + + haus finanzierung online die eigenheimzulage g?nstiges bauspardarlehen einer immobilienfinanzierung haus finanzieren in bauspardarlehen schw?bisch hall eigenheimzulage forum forderungsentkleidete hypothek immobilienkredit rechner erststellige hypothek immobilienfinanzierung dr hall bauspardarlehen eigenheimzulage ?berweisungstermin zins?bersicht baufinanzierung hypothek formel eigenheimzulage pdf hypothekenkredit schweiz immobilienkredite vergleich eigenheimzulage berlin baufinanzierung ?sterreich immobilien finanzierung ohne eigenkapital bauspardarlehen raika immobilienkredit test immobilien krediten eigenheimzulage 15 baufinanzierung vergleich From rami.chowdhury at gmail.com Thu Mar 4 22:11:39 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 4 Mar 2010 19:11:39 -0800 Subject: Problem with modules reloading In-Reply-To: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> References: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> Message-ID: On Mar 4, 2010, at 18:10 , DSblizzard wrote: > I have had already following question: > "How to use *.py modules instead of *.pyc?" > > Last time I when asked that question I resolved problem by using one > big .py file. And answers doesn't work in my case. Now I ought to use > several files and almost the same problem arises again. Admit I have 2 > modules: m2.py and m1.py > > in m2.py: > from m1.py import * > > def foo2(): > foo1() > > foo2() > > in m1.py: > > # empty > > After copying m2.py contents directly to python.exe: > "NameError: global name 'foo1' is not defined" > > Then I define foo1 in m1 and copy following lines to python.exe: > from m1.py import * > foo2() > When you execute the import statement again, Python checks to see which module you are importing from, sees that you have already imported that module, and doesn't reload it. So nothing changes. If you need to reload m1, then use the reload() function: reload(m1) It's generally a good idea to avoid statements like "from m1 import *", to avoid confusion and keep your namespaces separate. So if you had defined m2.py like this... import m1 def foo2(): m1.foo1() ...then "reload(m1)" would solve your problem straight away. > Nothing changes, the same error, and .pyc files, if I have deleted > them doesn't created again. > > What is the solution? > -- > http://mail.python.org/mailman/listinfo/python-list From hawccer at gmail.com Thu Mar 4 22:30:17 2010 From: hawccer at gmail.com (Adhitya Jiwa Pratama) Date: Fri, 5 Mar 2010 10:30:17 +0700 Subject: No subject Message-ID: From steve at REMOVE-THIS-cybersource.com.au Thu Mar 4 22:32:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 03:32:46 GMT Subject: Generic singleton References: Message-ID: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> On Thu, 04 Mar 2010 12:21:26 +0000, Duncan Booth wrote: > Steven D'Aprano wrote: > >> On Wed, 03 Mar 2010 19:54:52 +0100, mk wrote: >> >>> Hello, >>> >>> So I set out to write generic singleton, i.e. the one that would do a >>> singleton with attributes of specified class. At first: >> >> Groan. What is it with the Singleton design pattern? It is one of the >> least useful design patterns, and yet it's *everywhere* in Java and C++ >> world. > > It is also *everywhere* in the Python world. Unlike Java and C++, Python > even has its own built-in type for singletons. > > If you want a singleton in Python use a module. I was wondering who would be the first to point that out :) You are, of course, correct that the preferred way to solve the Singleton problem is with a module. (The other preferred way is with the Borg pattern, which is kind of a reverse-Singleton.) Using classes works too: so long as you do not instantiate it, but use it as an object in its own right, a class is also a singleton. However, I don't think it's quite right to say that modules *are* Singletons, although I accept that this is now getting into a tedious argument about terminology. A singleton is an instance of a class which can only have a single instance. This is not true of modules: >>> import string, math >>> type(string) is type(math) True >>> string is math False Wikipedia points out that the Singleton pattern is normally understood to exclude static structures which merely happen to be created once: "Note the distinction between a simple static instance of a class and a singleton..." http://en.wikipedia.org/wiki/Singleton_pattern Each individual module is a static instance of the module class which merely happens to be instantiated once. (You can subvert Python's import machinery to create multiple copies of a module, but normally this doesn't happen.) So *technically* modules are not singletons, although they behave just like them and give all the benefits, and disadvantages, of such. And as you say, the preferred Pythonic solution to the requirement for a Singleton is usually a module. Python does have it's own singletons, like None, True and False. For some reason, they behave quite differently: NoneType fails if you try to instantiate it again, while bool returns the appropriate existing singleton: >>> NoneType = type(None) >>> NoneType() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances >>> bool(45) True I wonder why NoneType doesn't just return None? -- Steven From robert.kern at gmail.com Thu Mar 4 22:35:13 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 21:35:13 -0600 Subject: A "scopeguard" for Python In-Reply-To: <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: On 2010-03-04 15:12 , Mike Kent wrote: > On Mar 4, 12:30 pm, Robert Kern wrote: > >> He's ignorant of the use cases of the with: statement, true. > > Ouch! Ignorant of the use cases of the with statement, am I? > Odd, I use it all the time. No, I was referring to Jean-Michel, who was not familiar with the with: statement. >> Given only your >> example of the with: statement, it is hard to fault him for thinking that try: >> finally: wouldn't suffice. > > Damn me with faint praise, will you? Also talking about Jean-Michel. :-) -- 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 From robert.kern at gmail.com Thu Mar 4 22:42:32 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 21:42:32 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: On 2010-03-04 16:27 , Alf P. Steinbach wrote: > * Mike Kent: >> However, I fail to understand his response that I must have meant try/ >> else instead, as this, as Mr. Kern pointed out, is invalid syntax. >> Perhaps Mr. Steinbach would like to give an example? > > OK. > > Assuming that you wanted the chdir to be within a try block (which it > was in your code), then to get code equivalent to my code, for the > purpose of a comparision of codes that do the same, you'd have to write > something like ... > > original_dir = os.getcwd() > try: > os.chdir(somewhere) > except Whatever: > # E.g. log it. > raise > else: > try: > # Do other stuff > finally: > os.chdir(original_dir) > # Do other cleanup > > ... which would be a more general case. > > I've also given this example in response to Robert earlier in the > thread. Although I haven't tried it I believe it's syntactically valid. > If not, then the relevant typo should just be fixed. :-) > > I have no idea which construct Robert thought was syntactically invalid. > I think that if he's written that, then it must have been something he > thought of. I was just trying to interpret what you meant by "Changing 'finally' to 'else' could make it equivalent." As far as I can tell, that has only one possible interpretation going by the plain meaning of the words, and it isn't yours. Since you always seem to refer to "try/else" as if it were an independent construct and not part of "try: except: else:" and no one else introduced except: clause, I must reiterate that your communications have been fabulously misleading. -- 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 From timr at probo.com Thu Mar 4 22:44:34 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 04 Mar 2010 19:44:34 -0800 Subject: python 2.6: how to modify a PIL image from C without copying forth and back References: <4b8daf7d$0$2868$426a74cc@news.free.fr> <8m0so5d5lmgg3dombnssflnt1jh6h0ka3v@4ax.com> <4b8e2129$0$8262$426a34cc@news.free.fr> Message-ID: News123 wrote: > >Yes, this might be an option >Somehow though it didn't feel right for me to depend on internal non >documented data types, which might change between releases of PIL. That's absolutely true. If performance is a priority, somethimes you have to do things that are "dirty". Just include lots of comments saying what you did and why. Personally, because so much of PIL is in C, I would judge internal changes to be unlikely. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at REMOVE-THIS-cybersource.com.au Thu Mar 4 23:01:21 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 04:01:21 GMT Subject: Problem with modules reloading References: <1ff10567-1a40-4008-a7f6-035afdf9b727@g10g2000yqh.googlegroups.com> Message-ID: <4b908210$0$27863$c3e8da3@news.astraweb.com> On Thu, 04 Mar 2010 18:10:59 -0800, DSblizzard wrote: > I have had already following question: "How to use *.py modules instead > of *.pyc?" > > Last time I when asked that question I resolved problem by using one big > .py file. I think you are confused. .pyc files are Python compiled byte-code files. You don't use them, Python does. When you import a module, Python *automatically* compiles it and creates a .pyc file, which is then used to speed up loading next time you run Python and import the same module. If you delete the .pyc file, it is quietly recreated next time you import the module again. Using "one big .py file" or not, this has nothing to do with whether Python loads the module from source-code or byte-code. Just ignore the .pyc files. > And answers doesn't work in my case. Now I ought to use > several files and almost the same problem arises again. Admit I have 2 > modules: m2.py and m1.py > > in m2.py: > from m1.py import * That won't work, because Python looks for a package called "m1" which contains a module called "py". The only way that line can succeed is if you have a directory called "m1" containing two files called "__init__.py" and "py.py", like this: m1/ m1/__init__.py m1/py.py Python will then load __init__.py, then load py.py. Since I'm pretty sure you don't have that directory, the above line cannot possible work. > What is the solution? Don't use "from module import *", it is confusing and doesn't work with reload(module) at all. You shouldn't use reload(module) except for experimentation in the interactive interpreter. You should work through the part of the tutorial that talks about modules and imports. http://docs.python.org/tutorial/ http://docs.python.org/tutorial/modules.html Good luck! -- Steven From robert.kern at gmail.com Thu Mar 4 23:01:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Mar 2010 22:01:44 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-04 17:52 , Alf P. Steinbach wrote: > * Robert Kern: >> On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: >>> * Robert Kern: >>>> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>>>> * Robert Kern: >>>>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >>> [snippety] >>>>>> >>>>>>> If you call the possibly failing operation "A", then that systematic >>>>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>>>> mess, but if A succeeds, then it's the responsibility of the calling >>>>>>> code to clean up if the higher level (multiple statements) operation >>>>>>> that A is embedded in, fails. >>>>>>> >>>>>>> And that's what Marginean's original C++ ScopeGuard was designed >>>>>>> for, >>>>>>> and what the corresponding Python Cleanup class is designed for. >>>>>> >>>>>> And try: finally:, for that matter. >>>>> >>>>> Not to mention "with". >>>>> >>>>> Some other poster made the same error recently in this thread; it is a >>>>> common fallacy in discussions about programming, to assume that since >>>>> the same can be expressed using lower level constructs, those are all >>>>> that are required. >>>>> >>>>> If adopted as true it ultimately means the removal of all control >>>>> structures above the level of "if" and "goto" (except Python doesn't >>>>> have "goto"). >>>> >>>> What I'm trying to explain is that the with: statement has a use even >>>> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >>>> finally: does not mean that the with: statement doesn't improve on >>>> try: finally:. >>> >>> That's a different argument, essentially that you see no advantage for >>> your current coding patterns. >>> >>> It's unconnected to the argument I responded to. >>> >>> The argument that I responded to, that the possibility of expressing >>> things at the level of try:finally: means that a higher level construct >>> is superfluous, is still meaningless. >> >> I am attacking your premise that the "with Cleanup():" construct is >> higher level than try: finally:. It isn't. It provides the same level >> of abstraction as try: finally:. >> >> This is distinct from the accepted uses of the with: statement which >> *are* higher level than try: finally: and which do confer practical >> benefits over using try: finally: despite being syntactical sugar for >> try: finally:. >> >>>>>>>> Both formulations can be correct (and both work perfectly fine with >>>>>>>> the chdir() example being used). Sometimes one is better than the >>>>>>>> other, and sometimes not. You can achieve both ways with either >>>>>>>> your >>>>>>>> Cleanup class or with try: finally:. >>>>>>>> >>>>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>>>> try: >>>>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>>>> into >>>>>>>> callables. This significantly limits what you can do in your >>>>>>>> cleanup >>>>>>>> code. >>>>>>> >>>>>>> Uhm, not really. :-) As I see it. >>>>>> >>>>>> Well, not being able to affect the namespace is a significant >>>>>> limitation. Sometimes you need to delete objects from the >>>>>> namespace in >>>>>> order to ensure that their refcounts go to zero and their cleanup >>>>>> code >>>>>> gets executed. >>>>> >>>>> Just a nit (I agree that a lambda can't do this, but as to what's >>>>> required): assigning None is sufficient for that[1]. >>>> >>>> Yes, but no callable is going to allow you to assign None to names in >>>> that namespace, either. Not without sys._getframe() hackery, in any >>>> case. >>>> >>>>> However, note that the current language doesn't guarantee such >>>>> cleanup, >>>>> at least as far as I know. >>>>> >>>>> So while it's good practice to support it, to do everything to let it >>>>> happen, it's presumably bad practice to rely on it happening. >>>>> >>>>> >>>>>> Tracebacks will keep the namespace alive and all objects in it. >>>>> >>>>> Thanks!, I hadn't thought of connecting that to general cleanup >>>>> actions. >>>>> >>>>> It limits the use of general "with" in the same way. >>>> >>>> Not really. >>> >>> Sorry, it limits general 'with' in /exactly/ the same way. >>> >>>> It's easy to write context managers that do that [delete objects from >>>> the namespace]. >>> >>> Sorry, no can do, as far as I know; your following example quoted below >>> is an example of /something else/. >> >> Okay, so what do you mean by 'the use of general "with"'? I'm talking >> about writing a context manager or using the @contextmanager decorator >> to do some initialization and then later cleaning up that >> initialization. That cleaning up may entail deleting an object. You >> are correct that the context manager can't affect the namespace of the >> with: clause, but that's not the initialization that it would need to >> clean up. >> >> Yes, you can write code with a with: statement where you try to clean >> up stuff that happened inside of the clause (you did), but that's not >> how the with: statement was ever intended to be used nor is it good >> practice to do so because of that limitation. Context managers are >> designed to initialize specific things, then clean them up. I thought >> you were talking about the uses of the with: statement as described in >> PEP-343, not every possible misuse of the with: statement. > > I'm not the one talking about removing variables or that "it's easy to > write context managers that do that". > > You are the one talking about that. > > So I have really not much to add. > > It seems that you're now agreeing with me that former is not good > practice and that the latter is impossible to do portably, but you now > argue against your earlier stand as if that was something that I had put > forward. No, I'm still saying that sometimes you do need to remove variables that you initialized in the initialization section. Writing a purpose-built context manager which encapsulates the initialization and finalization allows you to do this easily. Putting the initialization section inside the with: clause, as you do, and requiring cleanup code to be put into callables makes this hard. > It's a bit confusing when you argue against your own statements. > >>> And adding on top of irrelevancy, for the pure technical aspect it can >>> be accomplished in the same way using Cleanup (I provide an example >>> below). >>> >>> However, doing that would generally be worse than pointless since with >>> good coding practices the objects would become unreferenced anyway. >>> >>> >>>> You put the initialization code in the __enter__() method, assign >>>> whatever objects you want to keep around through the with: clause as >>>> attributes on the manager, then delete those attributes in the >>>> __exit__(). >>> >>> Analogously, if one were to do this thing, then it could be accomplished >>> using a Cleanup context manager as follows: >>> >>> foo = lambda: None >>> foo.x = create_some_object() >>> at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) >>> >>> ... except that >>> >>> 1) for a once-only case this is less code :-) >> >> Not compared to a try: finally:, it isn't. > > Again, this context shifting is bewildering. As you can see, quoted > above, you were talking about a situation where you would have defined a > context manager, presumably because a 'try' would not in your opinion be > simpler for whatever it was that you had in mind. But you are responding > to the code I offered as if it was an alternative to something where you > would find a 'try' to be simplest. I have consistently put forward that for once-only cases, try: finally: is a preferable construct to "with Cleanup():". I also put forward that for repetitive cases, a purpose-built context manager is preferable. I note that for both try: finally: and a purpose-built context manager, modifying the namespace is easy to do while it is difficult and less readable to do with "with Cleanup():". Since you were claiming that the "generic with:" would have the same problem as "with Cleanup():" I was trying to explain for why all of the intended use cases of the with: statement (the purpose-built context managers), there is no problem. Capisce? >>> 2) it is a usage that I wouldn't recommend; instead I recommend adopting >>> good >>> coding practices where object references aren't kept around. >> >> Many of the use cases of the with: statement involve creating an >> object (like a lock or a transaction object), keeping it around for >> the duration of the "# Do stuff" block, and then finalizing it. >> >>>> Or, you use the @contextmanager decorator to turn a generator into a >>>> context manager, and you just assign to local variables and del them >>>> in the finally: clause. >>> >>> Uhm, you don't need a 'finally' clause when you define a context >>> manager. >> >> When you use the @contextmanager decorator, you almost always do. See >> the Examples section of PEP 343: >> >> http://www.python.org/dev/peps/pep-0343/ >> >>> Additionally, you don't need to 'del' the local variables in >>> @contextmanager decorated generator. >>> >>> The local variables cease to exist automatically. >> >> True. >> >>>> What you can't do is write a generic context manager where the >>>> initialization happens inside the with: clause and the cleanup actions >>>> are registered callables. That does not allow you to affect the >>>> namespace. >>> >>> If you mean that you can't introduce direct local variables and have >>> them deleted by "registered callables" in a portable way, then right. >>> >>> But I can't think of any example where that would be relevant; in >>> particular what matters for supporting on-destruction cleanup is whether >>> you keep any references or not, not whether you have a local variable of >>> any given name. >> >> Well, local variables keep references to objects. Variable assignment >> followed by deletion is a very readable way to keep an object around >> for a while then remove it later. If you have to go through less >> readable contortions to keep the object around when it needs to be and >> clean it up later, then that is a mark against your approach. > > Sorry, as with the places noted above, I can't understand what you're > trying to say here. I don't recommend coding practices where you keep > object references around, Then how do you clean up locks and transaction objects and similar things if you don't keep them around during the code suite? Creating an object, keeping it around while executing a specific chunk of code, and finalizing it safely is a prime use case for these kinds of constructs. > and you have twice quoted that above. I don't > have any clue what "contortions" you are talking about, it must be > something that you imagine. These are the contortions: foo = lambda: None foo.x = create_some_object() at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) -- 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 From chris.lieb at gmail.com Thu Mar 4 23:07:12 2010 From: chris.lieb at gmail.com (Chris Lieb) Date: Thu, 4 Mar 2010 20:07:12 -0800 (PST) Subject: Failure in test_hashlib.py and test_hmac.py References: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> Message-ID: <545b8abb-72a3-4527-b290-d937cfce5470@t23g2000yqt.googlegroups.com> On Mar 3, 8:33?pm, Chris Lieb wrote: > I am building Python 2.6.4 on a shared server and am encountering test > failures in test_hashlib.py and test_hmac.py, specifically concerning > sha512. ?I recompiled Python with --with-pydebug and CLFAGS=CPPFLAGS="- > g" and ran the tests in GDB and got the following results: > > ---------------------------------------------------------------------------- > > GNU gdb 6.6.50.20070726-cvs > Copyright (C) 2007 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and > you are > welcome to change it and/or distribute copies of it under certain > conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. ?Type "show warranty" for > details. > This GDB was configured as "x86_64-suse-linux"... > Using host libthread_db library "/lib64/libthread_db.so.1". > (gdb) run test_hashlib.py > Starting program: /export/users1/chris.lieb/packages/python/bin/ > python2.6 test_hashlib.py > test_case_md5_0 (__main__.HashLibTestCase) ... ok > test_case_md5_1 (__main__.HashLibTestCase) ... ok > test_case_md5_2 (__main__.HashLibTestCase) ... ok > test_case_md5_huge (__main__.HashLibTestCase) ... ok > test_case_md5_uintmax (__main__.HashLibTestCase) ... ok > test_case_sha1_0 (__main__.HashLibTestCase) ... ok > test_case_sha1_1 (__main__.HashLibTestCase) ... ok > test_case_sha1_2 (__main__.HashLibTestCase) ... ok > test_case_sha1_3 (__main__.HashLibTestCase) ... ok > test_case_sha224_0 (__main__.HashLibTestCase) ... ok > test_case_sha224_1 (__main__.HashLibTestCase) ... ok > test_case_sha224_2 (__main__.HashLibTestCase) ... ok > test_case_sha224_3 (__main__.HashLibTestCase) ... ok > test_case_sha256_0 (__main__.HashLibTestCase) ... ok > test_case_sha256_1 (__main__.HashLibTestCase) ... ok > test_case_sha256_2 (__main__.HashLibTestCase) ... ok > test_case_sha256_3 (__main__.HashLibTestCase) ... ok > test_case_sha384_0 (__main__.HashLibTestCase) ... ok > test_case_sha384_1 (__main__.HashLibTestCase) ... ok > test_case_sha384_2 (__main__.HashLibTestCase) ... ok > test_case_sha384_3 (__main__.HashLibTestCase) ... ok > test_case_sha512_0 (__main__.HashLibTestCase) ... FAIL > test_case_sha512_1 (__main__.HashLibTestCase) ... FAIL > test_case_sha512_2 (__main__.HashLibTestCase) ... FAIL > test_case_sha512_3 (__main__.HashLibTestCase) ... FAIL > test_hexdigest (__main__.HashLibTestCase) ... > Program received signal SIGSEGV, Segmentation fault. > Cannot remove breakpoints because program is no longer writable. > It might be running in another process. > Further execution is probably impossible. > 0x00002ba86ffbb463 in ?? () > (gdb) bt > #0 ?0x00002ba86ffbb463 in ?? () > #1 ?0x000000000046993d in PyString_FromStringAndSize ( > ? ? str=0x7fff71c67800 " \203 5~? T(P m\200\a \005\vW > \025 \203 ! l G <] > \205 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?5 > \203\030 \207~ /c 1 GAz\201 82z ' > x q \177", > size=1054484473) > ? ? at Objects/stringobject.c:90 > #2 ?0x00002ba87030d59a in ?? () > #3 ?0x0000000000000000 in ?? () > > ----------------------------------------------------------------------------------------- > > GNU gdb 6.6.50.20070726-cvs > Copyright (C) 2007 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and > you are > welcome to change it and/or distribute copies of it under certain > conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. ?Type "show warranty" for > details. > This GDB was configured as "x86_64-suse-linux"... > Using host libthread_db library "/lib64/libthread_db.so.1". > (gdb) run test_hmac.py > Starting program: /export/users1/chris.lieb/packages/python/bin/ > python2.6 test_hmac.py > test_legacy_block_size_warnings (__main__.TestVectorsTestCase) ... ok > test_md5_vectors (__main__.TestVectorsTestCase) ... ok > test_sha224_rfc4231 (__main__.TestVectorsTestCase) ... ok > test_sha256_rfc4231 (__main__.TestVectorsTestCase) ... ok > test_sha384_rfc4231 (__main__.TestVectorsTestCase) ... ok > test_sha512_rfc4231 (__main__.TestVectorsTestCase) ... > Program received signal SIGSEGV, Segmentation fault. > Cannot remove breakpoints because program is no longer writable. > It might be running in another process. > Further execution is probably impossible. > 0x00002b483844e4c7 in ?? () > (gdb) bt > #0 ?0x00002b483844e4c7 in ?? () > #1 ?0x000000000046993d in PyString_FromStringAndSize ( > ? ? str=0x7ffff84f6730 "\026C3D \235D\t \025 [ G > \032bG? ~ \235\t\233aP", > ? ? size=4108309188) at Objects/stringobject.c:90 > #2 ?0x00002b48387e159a in ?? () > #3 ?0x0000000000000000 in ?? () > > -------------------------------------------------------------------- > > In the case of test_hashlib.py, it segfaulted on the first sha512 test > when I didn't have the debugging options enabled. ?Only after enabling > debugging did I get FAIL's for the sha512 tests. > > Does anyone know what is causing these failures? Does anyone have any tips or insights for trying to debug this issue? Any help is greatly appreciated. -- Chris Lieb From showell30 at yahoo.com Thu Mar 4 23:14:42 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 20:14:42 -0800 (PST) Subject: Generic singleton References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> Message-ID: <866ef5a6-119d-4962-bf99-57915d3a59d5@g28g2000prb.googlegroups.com> On Mar 4, 7:32?pm, Steven D'Aprano wrote: > > Python does have it's own singletons, like None, True and False. For some > reason, they behave quite differently: NoneType fails if you try to > instantiate it again, while bool returns the appropriate existing > singleton: > > >>> NoneType = type(None) > >>> NoneType() > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: cannot create 'NoneType' instances>>> bool(45) > > True > > I wonder why NoneType doesn't just return None? > It's an interesting question. Just to elaborate on your example: >>> type(None)() Traceback (most recent call last): File "", line 1, in TypeError: cannot create 'NoneType' instances >>> type(True)(False) False >>> type(False)(True) True I suspect that the answer is just that None is special. There is probably just no compelling use case where you want to clone None in a one-liner. To make None work like True/False in certain use cases you'd want something like this: def clone(val): if val is None: return None else: return type(val)(val) The same method would work against some non-singletons as well, although I'm not sure what the desired semantics would actually be: for value in [None, False, True, 42, [1, 2, 3]]: print clone(value) From showell30 at yahoo.com Thu Mar 4 23:37:50 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 20:37:50 -0800 (PST) Subject: A "scopeguard" for Python References: Message-ID: On Mar 3, 7:10?am, "Alf P. Steinbach" wrote: > For C++ Petru Marginean once invented the "scope guard" technique (elaborated on > by Andrei Alexandrescu, they published an article about it in DDJ) where all you > need to do to ensure some desired cleanup at the end of a scope, even when the > scope is exited via an exception, is to declare a ScopeGuard w/desired action. > > The C++ ScopeGuard was/is for those situations where you don't have proper > classes with automatic cleanup, which happily is seldom the case in good C++ > code, but languages like Java and Python don't support automatic cleanup and so > the use case for something like ScopeGuard is ever present. > > For use with a 'with' statement and possibly suitable 'lambda' arguments: > > > class Cleanup: > ? ? ?def __init__( self ): > ? ? ? ? ?self._actions = [] > > ? ? ?def call( self, action ): > ? ? ? ? ?assert( is_callable( action ) ) > ? ? ? ? ?self._actions.append( action ) > > ? ? ?def __enter__( self ): > ? ? ? ? ?return self > > ? ? ?def __exit__( self, x_type, x_value, x_traceback ): > ? ? ? ? ?while( len( self._actions ) != 0 ): > ? ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ? ?self._actions.pop()() > ? ? ? ? ? ? ?except BaseException as x: > ? ? ? ? ? ? ? ? ?raise AssertionError( "Cleanup: exception during cleanup" ) from > > > I guess the typical usage would be what I used it for, a case where the cleanup > action (namely, changing back to an original directory) apparently didn't fit > the standard library's support for 'with', like > > ? ?with Cleanup as at_cleanup: > ? ? ? ?# blah blah > ? ? ? ?chdir( somewhere ) > ? ? ? ?at_cleanup.call( lambda: chdir( original_dir ) ) > ? ? ? ?# blah blah > > Another use case might be where one otherwise would get into very deep nesting > of 'with' statements with every nested 'with' at the end, like a degenerate tree > that for all purposes is a list. Then the above, or some variant, can help to > /flatten/ the structure. To get rid of that silly & annoying nesting. :-) > > Cheers, > > - Alf (just sharing, it's not seriously tested code) Hi Alf, I think I understand the notion you're going after here. You have multiple cleanup steps that you want to defer till the end, and there is some possibility that things will go wrong along the way, but you want to clean up as much as you can. And, of course, flatter is better. Is this sort of what you are striving for? class Cleanup: def __init__( self ): self._actions = [] def call( self, action ): self._actions.append( action ) def __enter__( self ): return self def __exit__( self, x_type, x_value, x_traceback ): while( len( self._actions ) != 0 ): try: self._actions.pop()() except BaseException as x: raise AssertionError( "Cleanup: exception during cleanup" ) def clean_the_floor(): print('clean the floor') def carouse(num_bottles, accident): with Cleanup() as at_cleanup: at_cleanup.call(clean_the_floor) for i in range(num_bottles): def take_down(i=i): print('take one down', i) at_cleanup.call(take_down) if i == accident: raise Exception('oops!') print ('put bottle on wall', i) carouse(10, None) carouse(5, 3) From showell30 at yahoo.com Fri Mar 5 00:12:17 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 21:12:17 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> Message-ID: On Mar 4, 12:52?am, Paul Rubin wrote: > mk writes: > > OK, but how? How would you make up e.g. for JSON's lack of comments? > > Modify the JSON standard so that "JSON 2.0" allows comments. If you don't control the JSON standard, providing a compelling alternative to JSON might be the best way to force JSON to accomodate a wider audience. It might just be that the people behind JSON deliberately avoid comments, because it's not in the scope of the problem they are trying to solve. Hence another need for alternatives. > > OTOH, if YAML produces net benefit for as few as, say, 200 people in > > real world, the effort to make it has been well worth it. > > Not if 200,000 other people have to deal with it but don't receive the > benefit. > How many hundreds of thousands of people have had to deal with XML without receiving its benefits? Do well-established standards get an exemption from the rule that software is not allowed to annoy non- willing users of it? From ken at seehart.com Fri Mar 5 00:33:26 2010 From: ken at seehart.com (Ken Seehart) Date: Thu, 04 Mar 2010 21:33:26 -0800 Subject: IMAP mail filters tool Message-ID: <4B9097A6.2050600@seehart.com> I'm thinking of possibly making a simple client-agnostic tool for filtering and processing IMAP email. I'm a Thunderbird user, but I'm interested in a tool that is not client software specific. So I am is checking for prior art. Does anyone know of a filter tool with most of these features? * Written and customizable with python * IMAP based * Runs on client (i.e. without installing anything on the server) * Runs completely independent of client software (though could be launched from any email client that can support it) * Automatically suggests new rules based on manual movement of emails into folders (based on comparison of all header data across all existing folders) * Take arbitrary actions in response to rules (e.g. universally denying access to spam senders to all online cheese shops) * Capable of serving as a prototyping framework for things like spam filtering * General filtering functionality, not particularly focused on spam * Posts and updates rules to server via IMAP (i.e. by sending and automagically processing a special email message). Typical work-flow would be aimed at users who like to automatically sort their email prior to reading it. The goal is to have nearly all email sorted into folders so that most mail remaining in the Inbox is likely to be leftover spam missed by whatever spam filters are being used. In other words, the filters tend to effectively serve as white lists. Examples of unusual rules that don't seem to be supported by most email clients: * When you send an email, add the recipient to a filter such that email from that recipient goes to a "Unfiltered Replies" folder if it does not match any other filter. * Receiving email with certain fields matching certain regular expressions could automatically create a new folder and filter e.g.: o List-Id: "SF Bay Area Python group " yields a new folder "Lists/SF Bay Area Python group" with a corresponding rule o X-Launchpad-Bug: "product=phatch; milestone=..." yields a new folder "Bugs/Phatch" with a corresponding rule o X-Bugzilla-Product: "Shrubbery" yields a new folder "Bugs/Shrubbery" with a corresponding rule Thanks, Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Fri Mar 5 00:36:06 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 18:36:06 +1300 Subject: Draft PEP on RSON configuration file format In-Reply-To: <7xlje8lb9o.fsf@ruckus.brouhaha.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> Message-ID: <7vbiuqF4utU1@mid.individual.net> Paul Rubin wrote: > ReST was another solution in search of a problem. I think the basic idea behind ReST is quite good, i.e. understanding as markup various typographical conventions that make sense in plain text, such as underlined headings, bullets, numbered paragraphs. Unfortunately it went overboard with a slew of cryptic codes for footnotes, hyperlinks, etc. that nobody would naturally think to use in a plain text document. -- Greg From showell30 at yahoo.com Fri Mar 5 00:36:51 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 4 Mar 2010 21:36:51 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> Message-ID: <696158a0-dccf-4fa2-b6ab-bb1c4cb2e219@m35g2000prh.googlegroups.com> On Mar 4, 9:36?pm, Gregory Ewing wrote: > Paul Rubin wrote: > > ReST was another solution in search of a problem. > > I think the basic idea behind ReST is quite good, i.e. > understanding as markup various typographical conventions > that make sense in plain text, such as underlined > headings, bullets, numbered paragraphs. > > Unfortunately it went overboard with a slew of cryptic > codes for footnotes, hyperlinks, etc. that nobody would > naturally think to use in a plain text document. > The same thing happened with YAML to a certain extent, from my perspective. YAML was never meant to be an exact alternative to XML, but its basic premise was sound--use indentation for more elegant syntax, and model its semantics more toward how data actually gets used internally by scripting languages in particular. But there is also some featuritis with YAML that makes it hard to digest and needlessly cumbersome to implement. JSON is not perfect by any means, but I consider it to be a more useful descendant of XML and YAML, even if it did not directly borrow from either. (YAML and JSON are certainly similar, but that could be a coincidental convergence.) Even if YAML itself has not been a resounding success, it set the bar to a certain degree. From aahz at pythoncraft.com Fri Mar 5 01:00:50 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Mar 2010 22:00:50 -0800 Subject: WANTED: A good name for the pair (args, kwargs) References: Message-ID: In article , Tim Chase wrote: >Jonathan Fine wrote: >> >> We can call a function fn using >> val = fn(*args, **kwargs) >> >> I'm looking for a good name for the pair (args, kwargs). Any suggestions? >> >> For now I'll use argpair, but if anyone has a better idea, I'll use it. > >In the legacy of C and Java (okay, that doesn't carry _much_ weight >with me), I'd go with "varargs" to refer to the pair of (args, kwargs) Ditto -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From nagle at animats.com Fri Mar 5 01:35:45 2010 From: nagle at animats.com (John Nagle) Date: Thu, 04 Mar 2010 22:35:45 -0800 Subject: NoSQL Movement? In-Reply-To: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <4b90a1f8$0$1629$742ec2ed@news.sonic.net> Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > at http://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. Too much rant, not enough information. There is an argument against using full relational databases for some large-scale applications, ones where the database is spread over many machines. If the database can be organized so that each transaction only needs to talk to one database machine, the locking problems become much simpler. That's what BigTable is really about. For many web applications, each user has more or less their own data, and most database activity is related to a single user. Such applications can easily be scaled up with a system that doesn't have inter-user links. There can still be inter-user references, but without a consistency guarantee. They may lead to dead data, like Unix/Linux symbolic links. This is a mechanism adequate for most "social networking" sites. There are also some "consistent-eventually" systems, where a query can see old data. For non-critical applications, those can be very useful. This isn't a SQL/NoSQL thing; MySQL asynchronous replication is a "consistent-eventually" system. Wikipedia uses that for the "special" pages which require database lookups. If you allow general joins across any tables, you have to have all the very elaborate interlocking mechanisms of a distributed database. The serious database systems (MySQL Cluster and Oracle, for example) do offer that, but there are usually substantial complexity penalties, and the databases have to be carefully organized to avoid excessive cross-machine locking. If you don't need general joins, a system which doesn't support them is far simpler. John Nagle From greg.ewing at canterbury.ac.nz Fri Mar 5 01:54:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 19:54:48 +1300 Subject: NoSQL Movement? In-Reply-To: References: Message-ID: <7vbnieFovtU1@mid.individual.net> Duncan Booth wrote: > Did I mention that bigtable doesn't require you to have the same > columns in every record? The main use of bigtable (outside of Google's > internal use) is Google App Engine and that apparently uses one table. > > Not one table per application, one table total. It's a big table. Seems to me in that situation the term "table" ceases to have any meaning. If every record can have its own unique structure, and data from completely unrelated applications can all be thrown in together, there's no more reason to call it a "table" than, say, "file", "database" or "big pile of data". -- Greg From news123 at free.fr Fri Mar 5 02:21:30 2010 From: news123 at free.fr (News123) Date: Fri, 05 Mar 2010 08:21:30 +0100 Subject: _winreg and accessing registry settings of another user In-Reply-To: <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> References: <4b90252b$0$17806$426a34cc@news.free.fr> <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> Message-ID: <4b90b0fa$0$8332$426a74cc@news.free.fr> Mensanator wrote: > On Mar 4, 3:24 pm, News123 wrote: >> Hi, >> >> I have administrator privilege on a window host and would like to write >> a script setting some registry entries for other users. > > Why? Are you writing a virus? > Writing a virus in python???? Why not? though I didn't think about it as ideal choice of implementing viruses. For my script to run I have to run it explicitly as administrator (as being required by Vista / Win7). My script shall be part of installing and configuring a PC with some default settings with the minimal amount of human administrator interactions. The steps: - install windows - install python - setup one admin account and one or more user accounts (without admin privileges) - run a script, that preconfigures registry settings for some users. As mentioned before I see at least two possible ways and achieving this but lack information for either. 1.) run a sub process or thread as another user (the user wouldn't even have a password during the installation phase) and change the registry from this thread. I have no experience of running 'suid' under windows. 2.) being able to load the 'hive' of another user into the registry and be therefore able to change his settings. I didn't find a function allowing _winreg to load additional 'hives' bye N From greg.ewing at canterbury.ac.nz Fri Mar 5 02:33:44 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 20:33:44 +1300 Subject: Generic singleton In-Reply-To: References: Message-ID: <7vbprcF49gU1@mid.individual.net> mk wrote: > Or I could make my life simpler and use global variable. :-) Indeed. You actually *have* a global variable already, you've just hidden it inside another object. That doesn't make it any less global, though. If you want to defer creation of the object until the first time it's used, use a function that creates an instance the first time it's called. Your Singleton class is really just an overly elaborate way of implementing such a function. -- Greg From no.email at nospam.invalid Fri Mar 5 02:46:46 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 23:46:46 -0800 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> Message-ID: <7xvddbqkgp.fsf@ruckus.brouhaha.com> Steve Howell writes: >> Modify the JSON standard so that "JSON 2.0" allows comments. > > If you don't control the JSON standard, providing a compelling > alternative to JSON might be the best way to force JSON to accomodate > a wider audience. Ehh, either the JSON standardizers care about this issue or else they don't. JSON (as currently defined) is a machine-to-machine serialization format and just isn't that good a choice for handwritten files. Adding a comment specification is a small perturbation that might be accepted into the standard, but a big departure like RSON is a whole nother creature. > How many hundreds of thousands of people have had to deal with XML > without receiving its benefits? Do well-established standards get an > exemption from the rule that software is not allowed to annoy non- > willing users of it? We already have to deal with XML. So using XML for config files doesn't require anyone to deal with any lousy formats that they didn't have to deal with before. So the basic answer to your question about well-established standards is yes: one annoying but standardized format is better than multiple annoying unstandardized ones. From no.email at nospam.invalid Fri Mar 5 02:50:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Mar 2010 23:50:15 -0800 Subject: Failure in test_hashlib.py and test_hmac.py References: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> Message-ID: <7xr5nzqkaw.fsf@ruckus.brouhaha.com> Chris Lieb writes: > I am building Python 2.6.4 on a shared server and am encountering test > failures in test_hashlib.py and test_hmac.py, You should certainly file a bug report (bugs.python.org). If you want to debug it yourself and include a patch, that's great. Otherwise, just file the report. In the case of test_hashlib.py, it segfaulted on the first sha512 test when I didn't have the debugging options enabled. Only after enabling debugging did I get FAIL's for the sha512 tests. Does anyone know what is causing these failures? Please be precise about the hw and compiler versions. From stefan_ml at behnel.de Fri Mar 5 03:03:36 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 05 Mar 2010 09:03:36 +0100 Subject: Partly erratic wrong behaviour, Python 3, lxml In-Reply-To: References: Message-ID: Jussi Piitulainen, 04.03.2010 22:40: > Stefan Behnel writes: >> Jussi Piitulainen, 04.03.2010 11:46: >>> I am observing weird semi-erratic behaviour that involves Python 3 >>> and lxml, is extremely sensitive to changes in the input data, and >>> only occurs when I name a partial result. I would like some help >>> with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml >>> version?) >> >> Here's how to find the version: >> >> http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do > > Ok, thank you. Here's the results: > > >>> print(et.LXML_VERSION, et.LIBXML_VERSION, > ... et.LIBXML_COMPILED_VERSION, et.LIBXSLT_VERSION, > ... et.LIBXSLT_COMPILED_VERSION) > (2, 2, 4, 0) (2, 6, 26) (2, 6, 26) (1, 1, 17) (1, 1, 17) I can't reproduce this with the latest lxml trunk (and Py3.2 trunk) and libxml2 2.7.6, even after running your test script for quite a while. I'd try to upgrade the libxml2 version. Stefan From lipun4u at gmail.com Fri Mar 5 03:04:13 2010 From: lipun4u at gmail.com (asit) Date: Fri, 5 Mar 2010 00:04:13 -0800 (PST) Subject: indentation error Message-ID: Consider the following code import stat, sys, os, string, commands try: pattern = raw_input("Enter the file pattern to search for :\n") commandString = "find " + pattern commandOutput = commands.getoutput(commandString) findResults = string.split(commandOutput, "\n") print "Files : " print commandOutput print "=============================" for file in findResults: mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE]) print "\nPermissions for file", file, ":" for level in "USR", "GRP", "OTH": for perm in "R", "W", "X": if mode & getattr(stat,"S_I"+perm+level): print level, " has ", perm, " permission" else: print level, " does NOT have ", perm, " permission" except: print "There was a problem - check the message above" According to me, indentation is ok. but the python interpreter gives an indentation error [asit ~/py] $ python search.py File "search.py", line 7 findResults = string.split(commandOutput, "\n") ^ IndentationError: unindent does not match any outer indentation level From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 03:05:16 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 08:05:16 GMT Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> Message-ID: <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 18:36:06 +1300, Gregory Ewing wrote: > Paul Rubin wrote: >> ReST was another solution in search of a problem. > > I think the basic idea behind ReST is quite good, i.e. understanding as > markup various typographical conventions that make sense in plain text, > such as underlined headings, bullets, numbered paragraphs. > > Unfortunately it went overboard with a slew of cryptic codes for > footnotes, hyperlinks, etc. that nobody would naturally think to use in > a plain text document. I use footnotes all the time[1] in plain text documents and emails. I don't think there's anything bizarre about it at all. [1] When I say "all the time", I actually mean occasionally. -- Steven From jimgardener at gmail.com Fri Mar 5 03:05:18 2010 From: jimgardener at gmail.com (jimgardener) Date: Fri, 5 Mar 2010 00:05:18 -0800 (PST) Subject: comparing two lists Message-ID: hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst=['jon','arya','ned','bran'] newlst=['jaime','jon','cersei'] newlyadded=set(newlst)-set(oldlst) removed=set(oldlst)-set(newlst) unchanged=set(oldlst)& set(newlst) print '%d were newly added= %s'%(len(newlyadded),list(newlyadded)) print '%d were removed=%s'%(len(removed),list(removed)) print '%d were unchanged=%s'%(len(unchanged),list(unchanged)) this produces the output -------------- 2 were newly added= ['jaime', 'cersei'] 3 were removed=['ned', 'arya', 'bran'] 1 were unchanged=['jon'] From greg.ewing at canterbury.ac.nz Fri Mar 5 03:10:01 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 21:10:01 +1300 Subject: Passing FILE * types using ctypes In-Reply-To: References: Message-ID: <7vbrveFegeU1@mid.individual.net> Francesco Bochicchio wrote: > Python file objects have a method fileno() whic returns the 'C file > descriptor', i.e. the number used by low level IO in python as well as > in C. > I would use this as interface between python and C and then in the C > function using fdopen to get a FILE * for an already open file for > which you have a file descriptor. But note that this will be a *new* stdio file buffer attached to the same file descriptor, not the same one that the Python file object is using. This may or may not be a problem depending on what you're trying to do. If you need the same FILE * that Python is using, you may need to use ctypes to extract it out of the file object. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 5 03:25:47 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 05 Mar 2010 21:25:47 +1300 Subject: Docstrings considered too complicated In-Reply-To: <4b9072b2$0$27863$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100227191040.6c77f2d8@geekmail.INVALID> <759ebd7f-c5c5-4f8f-9d5b-06ec6e5180b8@m27g2000prl.googlegroups.com> <20100301140943.4edca16b@geekmail.INVALID> <4b8be8f7$1@dnews.tpgi.com.au> <20100301182255.3de59bc6@geekmail.INVALID> <20100301212954.7aa0b99d@geekmail.INVALID> <87eik3zmi8.fsf@benfinney.id.au> <20100302184056.743a71e7@geekmail.INVALID> <20100302225156.67171851@geekmail.INVALID> <877hpuxpdf.fsf@benfinney.id.au> <7v6ae4Ff37U1@mid.individual.net> <7v9g9qF1nkU1@mid.individual.net> <4b9072b2$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vbssvFjgcU1@mid.individual.net> Steven D'Aprano wrote: > (a) Can we objectively judge the goodness of code, or is it subjective? > > (b) Is goodness of code quantitative, or is it qualitative? Yes, I'm not really talking about numeric vs. non-numeric, but objective vs. subjective. The measurement doesn't have to yield a numeric result, it just has to be doable by some objective procedure. If you can build a machine to do it, then it's objective. If you have to rely on the judgement of a human, then it's subjective. > But we can make quasi-objective judgements, by averaging out all the > individual quirks of subjective judgement: > > (1) Take 10 independent judges who are all recognised as good Python > coders by their peers, and ask them to give a score of 1-5 for the > quality of the comments... Yes, but this is an enormous amount of effort to go to, and at the end of the day, the result is only reliable in a statistical sense. This still seems to me to be qualitatively different from something like testing the tensile strength of a piece of steel. You can apply a definite procedure and obtain a definite result, and no human judgement is required at all. -- Greg From mjoachimiak at gmail.com Fri Mar 5 03:30:49 2010 From: mjoachimiak at gmail.com (Michael Joachimiak) Date: Fri, 5 Mar 2010 10:30:49 +0200 Subject: ImportError: No module named glib Message-ID: <7c857e8c1003050030x39b75c98veace4ef8eebe606a@mail.gmail.com> I am too new to python. If anybody has an idea what to do please help. when I use import glib in my code I get this: >>> import glib Traceback (most recent call last): File "", line 1, in ImportError: No module named glib :~$ python -V Python 2.6.4 /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version 2.18.0-0ubuntu2 :~$ pkg-config glib-2.0 --cflags --libs -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 From eckhardt at satorlaser.com Fri Mar 5 03:32:17 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 05 Mar 2010 09:32:17 +0100 Subject: indentation error References: Message-ID: asit wrote: > pattern = raw_input("Enter the file pattern to search for :\n") > commandString = "find " + pattern > commandOutput = commands.getoutput(commandString) > findResults = string.split(commandOutput, "\n") > print "Files : " > print commandOutput > print "=============================" > for file in findResults: > mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE]) > print "\nPermissions for file", file, ":" > for level in "USR", "GRP", "OTH": > for perm in "R", "W", "X": > if mode & getattr(stat,"S_I"+perm+level): > print level, " has ", perm, " permission" > else: > print level, " does NOT have ", perm, " > permission" [...] > According to me, indentation is ok. but the python interpreter gives > an indentation error > > [asit ~/py] $ python search.py > File "search.py", line 7 > findResults = string.split(commandOutput, "\n") > ^ > IndentationError: unindent does not match any outer indentation level Hard to tell, since your posting was already line-broken which already changes the correctness. In any case, watch for tabs/spaces, many editors have an option to display whitespace. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From r1chardj0n3s at gmail.com Fri Mar 5 03:39:49 2010 From: r1chardj0n3s at gmail.com (Richard Jones) Date: Fri, 5 Mar 2010 19:39:49 +1100 Subject: 10th Python Game Programming Challenge in three weeks Message-ID: <249b6faa1003050039n17e16b0p80ef8474c2d94167@mail.gmail.com> The 10th Python Game Programming Challenge (http://pyweek.org/) will run from the 28th of March to the 4th of April. The PyWeek challenge: - Invites entrants to write a game in one week from scratch either as an individual or in a team, - Is intended to be challenging and fun, - Will hopefully increase the public body of game tools, code and expertise, - Will let a lot of people actually finish a game, and - May inspire new projects (with ready made teams!) Come along and play, it's lots of fun :) Richard From gh at ghaering.de Fri Mar 5 03:40:50 2010 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 5 Mar 2010 09:40:50 +0100 Subject: [ANN] pysqlite 2.6.0 released Message-ID: <496f9fbb1003050040k7c057e2s1941d216eb46ce5b@mail.gmail.com> pysqlite 2.6.0 released ======================= Release focus: Synchronize with sqlite3 module in Python trunk. pysqlite is a DB-API 2.0-compliant database interface for SQLite. SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. Go to http://pysqlite.googlecode.com/ for downloads, online documentation and for reporting bugs. Changes ======= - pysqlite can now be built against Python versions without thread support - PyDict_SetItem is now checked so you cannot shoot yourself in the foot, even if you try to - More checks for closed connections were added to avoid possible segfaults Compatibility ============= Warning: pysqlite is not supported for Python < 2.5 any longer. This release still builds against Python 2.3 and 2.4, but I won't bother with these in the future. From vlastimil.brom at gmail.com Fri Mar 5 03:50:03 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 5 Mar 2010 09:50:03 +0100 Subject: comparing two lists In-Reply-To: References: Message-ID: <9fdb569a1003050050y5705dd4bi6e757e59adb40d66@mail.gmail.com> 2010/3/5 jimgardener : > hi > I have two lists of names.I need to find the difference between these > two lists.I tried to do it using sets.But I am wondering if there is a > better way to do it.Please tell me if there is a more elegant way. > thanks, > jim > > my code snippet follows.. > > oldlst=['jon','arya','ned','bran'] > newlst=['jaime','jon','cersei'] > > newlyadded=set(newlst)-set(oldlst) > removed=set(oldlst)-set(newlst) > unchanged=set(oldlst)& set(newlst) > print '%d were newly added= %s'%(len(newlyadded),list(newlyadded)) > print '%d were removed=%s'%(len(removed),list(removed)) > print '%d were unchanged=%s'%(len(unchanged),list(unchanged)) > > this produces the output > -------------- > 2 were newly added= ['jaime', 'cersei'] > 3 were removed=['ned', 'arya', 'bran'] > 1 were unchanged=['jon'] > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, I guess for lists with unique items and order insignificant this is just fine; you may also check difflib, if it suits your needs; there are multiple comparing and displaying possibilities, e.g.: >>> import difflib >>> print "\n".join(difflib.unified_diff(['jon','arya','ned','bran'], ['jaime','jon','cersei'])) --- +++ @@ -1,4 +1,3 @@ +jaime jon -arya -ned -bran +cersei >>> hth, vbr From duncan.booth at invalid.invalid Fri Mar 5 04:07:49 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2010 09:07:49 GMT Subject: NoSQL Movement? References: <7vbnieFovtU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > Duncan Booth wrote: >> Did I mention that bigtable doesn't require you to have the same >> columns in every record? The main use of bigtable (outside of Google's >> internal use) is Google App Engine and that apparently uses one table. >> >> Not one table per application, one table total. It's a big table. > > Seems to me in that situation the term "table" ceases to > have any meaning. If every record can have its own unique > structure, and data from completely unrelated applications > can all be thrown in together, there's no more reason to > call it a "table" than, say, "file", "database" or "big > pile of data". > I think it depends on how you look at things. AppEngine uses a programming model which behaves very much as though you do have multiple tables: you use Django's programming model to wrap each record in a class, or you can use Gql query languages which looks very similar to SQL and again the class names appear in the place of table names. So conceptually thinking of it as separate tables make a lot of sense, but the underlying implementation is apparently a single table where records simply have a type field that is used to instantiate the proper class on the Python side (and another hidden application field to prevent you accessing another application's data). Also of course records with the same type still may not all have the same columns if you change the class definition between runs, so even at this level they aren't tables in the strict SQL sense. There may of course be other applications using bigtable where the bigtable(s) look much more like ordinary tables, but I don't know what they are. >From your suggested terms, I'd agree you could call it a database rather than a table but I think it's too structured for "file" or "big pile of data" to be appropriate. -- Duncan Booth http://kupuguy.blogspot.com From magnicida at gmail.com Fri Mar 5 04:37:04 2010 From: magnicida at gmail.com (Juan Pedro Bolivar Puente) Date: Fri, 05 Mar 2010 11:37:04 +0200 Subject: NoSQL Movement? In-Reply-To: <7bfeffcd-722e-4df4-8455-7710207d9c7e@a18g2000yqc.googlegroups.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <26bd4a5c-4d66-4597-a0ee-b4990f468e68@g26g2000yqn.googlegroups.com> <7bfeffcd-722e-4df4-8455-7710207d9c7e@a18g2000yqc.googlegroups.com> Message-ID: <4B90D0C0.7020508@gmail.com> On 04/03/10 19:52, ccc31807 wrote: > On Mar 4, 11:51 am, Juan Pedro Bolivar Puente > wrote: >> No, relations are data. > > This depends on your definition of 'data.' I would say that > relationships is information gleaned from the data. > >> "Data is data" says nothing. Data is >> information. > > To me, data and information are not the same thing, and in particular, > data is NOT information. To me, information consists of the sifting, > sorting, filtering, and rearrangement of data that can be useful in > completing some task. As an illustration, consider some very large > collection of ones and zeros -- the information it contains depends on > whether it's views as a JPEG, an EXE, XML, WAV, or other sort of > information processing device. Whichever way it's processed, the > 'data' (the ones and zeros) stay the same, and do not constitute > 'information' in their raw state. > >> Actually, all data are relations: relating /values/ to >> /properties/ of /entities/. Relations as understood by the "relational >> model" is nothing else but assuming that properties and entities are >> first class values of the data system and the can also be related. > > Well, this sort of illustrates my point. The 'values' of 'properties' > relating to specific 'entities' depends on how one processes the data, > which can be processed various ways. For example, 10000001 can either > be viewed as the decimal number 65 or the alpha character 'A' but the > decision as to how to view this value isn't inherent in the data > itself, but only as an artifact of our use of the data to turn it into > information. > Well, it depends as you said on the definition of information; actually your definition of data fits into the information-theorical definition of information as sequence of symbols... But I understand that in other context /information/ can also mean the next level of abstraction on top of /data/, in the same way as /knowledge/ is the next level of abstraction on top of information; lets ground or basis on that. In any case, your definition and George's still support my point of view where relations are data: they are stored in the computer as a sequence of ones and zeroes and is indistinguishable from any other thing in the data space in that sense. Of course, it is a key data to be able to recover information and specially to add new information consistently to the data storage... That SQL includes special syntax for manipulating relations should not hide this fact; and one can still query the relational information in the same way one would query non-relational data in most DBMS anyway... Anyway I'm sorry for drifting the conversation away... Going back to the main topic, I agree with the general view on this thread that relational databases (information-bases ? ;) and non-relational ones are there to do some different jobs. It is just by carefully examining a problem that we can define which one fits it better; with relational databases having the clear advantage that is mathematically grounded basis makes its fitness for most problems quite clear, while the preference for non-relational systems is a more technical and empirical problem of the trade-offs of consistency vs scalability and so on. JP From no.email at nospam.invalid Fri Mar 5 04:45:54 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Mar 2010 01:45:54 -0800 Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <5e9126f7-f9e2-4c38-8dd5-dc174204fd71@d27g2000yqf.googlegroups.com> Message-ID: <7xhbov2jal.fsf@ruckus.brouhaha.com> lbolla writes: > for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') This is the nicest solution, I think. Mine was more cumbersome. From mail at timgolden.me.uk Fri Mar 5 04:59:17 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 05 Mar 2010 09:59:17 +0000 Subject: _winreg and accessing registry settings of another user In-Reply-To: <4b90b0fa$0$8332$426a74cc@news.free.fr> References: <4b90252b$0$17806$426a34cc@news.free.fr> <917f4593-f50e-424c-a21b-04c376e77164@33g2000yqj.googlegroups.com> <4b90b0fa$0$8332$426a74cc@news.free.fr> Message-ID: <4B90D5F5.4040802@timgolden.me.uk> On 05/03/2010 07:21, News123 wrote: > My script shall be part of installing and configuring a PC with some > default settings with the minimal amount of human administrator > interactions. > > The steps: > - install windows > - install python > - setup one admin account and one or more user accounts (without admin > privileges) > - run a script, that preconfigures registry settings for some users. > 2.) being able to load the 'hive' of another user into the registry and > be therefore able to change his settings. I didn't find a function > allowing _winreg to load additional 'hives' You can use a combination of the win32security, win32api and win32profile modules from the pywin32 package for this: import win32security import win32api import win32profile username = "USERNAME" domain = "DOMAIN" password = "PASSWORD" hUser = win32security.LogonUser ( username, domain, password, win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT ) hReg = win32profile.LoadUserProfile ( hUser, {"UserName" : "fozrestore"} ) try: print win32api.RegEnumKeyExW (hReg) finally: win32profile.UnloadUserProfile (hUser, hReg) TJG From phil at freehackers.org Fri Mar 5 05:01:06 2010 From: phil at freehackers.org (BlueBird) Date: Fri, 5 Mar 2010 02:01:06 -0800 (PST) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: On 3 mar, 20:35, Stefan Behnel wrote: > BlueBird, 03.03.2010 17:32: > > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > > that this does not exist. Does anybody know about this ? > > SOAP may be an overly bloated protocol, but it's certainly not black magic. > It's not hard to do manually if you really need to: > > http://effbot.org/zone/element-soap.htm But this requires a goog knowloedge of SOAP, in order to parse everything correctly. The reason I want to use a ready-made client is that I have about zero knowledge about SOAP, and even more in the differences between SOAP 1.1 and 1.2 . cheers, Philippe From aurelien.gourrier at yahoo.fr Fri Mar 5 05:35:42 2010 From: aurelien.gourrier at yahoo.fr (=?iso-8859-1?Q?Aur=E9_Gourrier?=) Date: Fri, 5 Mar 2010 10:35:42 +0000 (GMT) Subject: Proper way to return an instance of a class from a class method ? Message-ID: <918065.487.qm@web23104.mail.ird.yahoo.com> Dear all, I have what will probably sound as stupid questions for experienced Python users... which I am not, hence my seeking for some help. ------------ QUESTION 1: I've implemeted a class which defines a container with 2 lists of data (with some specific format). Some of the methods simply transform these data and therefore return a new container of 2 lists. I want to be able to use these results without having to re-instanciate them, so I return them as instances of the class: class MyClass: def __init__(self, data): #various checks for the format and content of data (data = [x,y] where x and y are 2 lists of floats) self.data = data def transformdata(self): newdata = transform(data) return MyClass(newdata) In this way I can do: x = list1 y = list2 data = MyClass([x,y]) moddata = data.transformdata() moddata2 = moddata.transformdata() Is that the correct way to go (i.e. is this pythonic) ? What I want to avoid is: moddata = data.transformdata() moddata2 = MyClass(moddata).transformdata() ------------ QUESTION 2: If I go this way, I have a second problem: if I create a new class which inherits from the previous, I would expect/like the methods from the initial class to return instances from the new class: class MyClass2(MyClass): def othermethods(self): return MyClass2(whatever) Then I get: x = list1 y = list2 data = MyClass2([x,y]) finaldata = data.transformdata() My problem is that finaldata is (of course) an instance of MyClass and not MyClass2. How do I deal with this ? All help will be much appreciated... Cheers, Aur? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Mar 5 05:44:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 11:44:57 +0100 Subject: Evaluate my first python script, please In-Reply-To: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <4B90E0A9.6000600@sequans.com> Pete Emerson wrote: > I've written my first python program, and would love suggestions for > improvement. > > I'm a perl programmer and used a perl version of this program to guide > me. So in that sense, the python is "perlesque" > > This script parses /etc/hosts for hostnames, and based on terms given > on the command line (argv), either prints the list of hostnames that > match all the criteria, or uses ssh to connect to the host if the > number of matches is unique. > > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to do the same thing". > > I am aware that there are performance improvements and error checking > that could be made, such as making sure the file exists and is > readable and precompiling the regular expressions and not calculating > how many sys.argv arguments there are more than once. I'm not hyper > concerned with performance or idiot proofing for this particular > script. > > Thanks in advance. > > ######################################################## > #!/usr/bin/python > > import sys, fileinput, re, os > > filename = '/etc/hosts' > > hosts = [] > > for line in open(filename, 'r'): > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > if match is None or re.search('^(?:float|localhost)\.', line): > continue > hostname = match.group(1) > count = 0 > for arg in sys.argv[1:]: > for section in hostname.split('.'): > if section == arg: > count = count + 1 > break > if count == len(sys.argv) - 1: > hosts.append(hostname) > > if len(hosts) == 1: > os.system("ssh -A " + hosts[0]) > else: > print '\n'.join(hosts) > You've already been given good advices. Unlike some of those, I don't think using regexp an issue in any way. Yes they are not readable, for sure, I 100% agree to that statement, but you can make them readable very easily. # not readable match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # readable match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # match '192.168.200.1 (foo123)' I gladly understand ppl that are not willing to use regexp (or as last resort), but for a perl guy, that should not be an issue. JM From bruno.42.desthuilliers at websiteburo.invalid Fri Mar 5 05:54:28 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Mar 2010 11:54:28 +0100 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <4b90e2d0$0$10096$426a34cc@news.free.fr> Philip Semanchuk a ?crit : > > On Mar 3, 2010, at 5:41 PM, Avid Fan wrote: > >> Jonathan Gardner wrote: >> >>> I see it as a sign of maturity with sufficiently scaled software that >>> they no longer use an SQL database to manage their data. At some point >>> in the project's lifetime, the data is understood well enough that the >>> general nature of the SQL database is unnecessary. >> >> I am really struggling to understand this concept. >> >> Is it the normalised table structure that is in question or the query >> language? >> >> Could you give some sort of example of where SQL would not be the way >> to go. The only things I can think of a simple flat file databases. > > Well, Zope is backed by an object database rather than a relational one. And it ended up being a *major* PITA on all Zope projects I've worked on... From mblume at socha.net Fri Mar 5 05:54:49 2010 From: mblume at socha.net (mblume) Date: 05 Mar 2010 10:54:49 GMT Subject: ImportError: No module named glib References: Message-ID: <4b90e2f9$0$4046$5402220f@news.sunrise.ch> Am Fri, 05 Mar 2010 10:30:49 +0200 schrieb Michael Joachimiak: > I am too new to python. > If anybody has an idea what to do please help. when I use > > import glib > > in my code I get this: > >>>> import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib > Shot in the dark: maybe "import pyglib"? Hint: you can look around in /usr/lib/python to see what files can be imported. HTH Martin From azt113 at gmail.com Fri Mar 5 06:39:54 2010 From: azt113 at gmail.com (Ines T) Date: Fri, 5 Mar 2010 11:39:54 +0000 (UTC) Subject: Selecting MAX from a list Message-ID: I need to select a maximum number from a list and then call the variable that identifies that number, for example: x1,x2=1, y1,y2=4, z1,z2=3 So I need first to find 4 and then to take y to do additional operations as y-z. I will appreciate your SOON help! From santhosh.vkumar at gmail.com Fri Mar 5 06:41:00 2010 From: santhosh.vkumar at gmail.com (Santhosh Kumar) Date: Fri, 5 Mar 2010 17:11:00 +0530 Subject: Speech to Text Message-ID: <404c076d1003050341w327ceec7x63cfb0c01469d35d@mail.gmail.com> Hi All, I am trying to find is there is any way to covert "speech to Text" with Python in UBUNTU. I googled whr I found Many Text to speech. Some one please assist me. -- With Regards, Never Say No, Santhosh V.Kumar +919840411410 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Mar 5 06:46:54 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Mar 2010 12:46:54 +0100 Subject: ImportError: No module named glib References: Message-ID: Michael Joachimiak wrote: > I am too new to python. > If anybody has an idea what to do please help. > when I use > > import glib > > in my code I get this: > >>>> import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib > > :~$ python -V > Python 2.6.4 > > /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version > 2.18.0-0ubuntu2 > > :~$ pkg-config glib-2.0 --cflags --libs > -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 After the following random walk through my system $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import glib >>> glib.__file__ '/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.pyc' In the above __init__.py: ... from glib._glib import * _PyGLib_API = _glib._PyGLib_API del _glib ... >>> import sys >>> sys.modules["glib._glib"] >>> $ dpkg -S _glib.so python-gobject: /usr/lib/pyshared/python2.5/gtk-2.0/glib/_glib.so python-gobject: /usr/lib/pyshared/python2.6/gtk-2.0/glib/_glib.so $ ... I believe that you have to install the python-gobject package. Peter From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 06:48:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 11:48:35 GMT Subject: indentation error References: Message-ID: <4b90ef93$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 00:04:13 -0800, asit wrote: > Consider the following code [snip] > According to me, indentation is ok. but the python interpreter gives an > indentation error You can trust the interpreter. There *is* an indentation error. Most likely you have mixed spaces and tabs. Try: python -t -t search.py instead. (Yes, -t twice.) On an unrelated note, your code snippet shows a very poor coding style. Firstly, bare "except" clauses are VERY bad practice: it will mask bugs in your code. Secondly, you should wrap the smallest amount of code in the try block as you need. Something like this is probably better: pattern = raw_input("Enter the file pattern to search for :\n") commandString = "find " + pattern commandOutput = commands.getoutput(commandString) findResults = string.split(commandOutput, "\n") print "Files : " print commandOutput print "=============================" for file in findResults: try: mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE]) except (IOError, OSError): # Print a useless error message so your users will hate you. print "There was a problem with %s" % file continue print "\nPermissions for file", file, ":" for level in "USR", "GRP", "OTH": for perm in "R", "W", "X": if mode & getattr(stat,"S_I"+perm+level): print level, " has ", perm, " permission" else: print level, " does NOT have ", perm, "permission" -- Steven From anand.shashwat at gmail.com Fri Mar 5 06:54:19 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Mar 2010 17:24:19 +0530 Subject: Selecting MAX from a list In-Reply-To: References: Message-ID: On Fri, Mar 5, 2010 at 5:09 PM, Ines T wrote: > I need to select a maximum number from a list use max() > and then call the variable that > identifies that number, for example: > x1,x2=1, y1,y2=4, z1,z2=3 > you mean x1 = y1 = 1 or x1, y1 = 1, 1 right ? > So I need first to find 4 and then to take y to do additional operations as > y-z. > Well, I guess you got the idea > I will appreciate your SOON help! > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Fri Mar 5 06:56:34 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 12:56:34 +0100 Subject: NoSQL Movement? In-Reply-To: <4b90e2d0$0$10096$426a34cc@news.free.fr> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90e2d0$0$10096$426a34cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> Well, Zope is backed by an object database rather than a relational one. > > And it ended up being a *major* PITA on all Zope projects I've worked on... Care to write a few sentences on nature of problems with zodb? I was flirting with the thought of using it on some project. Regards, mk From clp2 at rebertia.com Fri Mar 5 07:01:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 04:01:32 -0800 Subject: Proper way to return an instance of a class from a class method ? In-Reply-To: <918065.487.qm@web23104.mail.ird.yahoo.com> References: <918065.487.qm@web23104.mail.ird.yahoo.com> Message-ID: <50697b2c1003050401h466d7f36t63b5f713d5271e4f@mail.gmail.com> On Fri, Mar 5, 2010 at 2:35 AM, Aur? Gourrier wrote: > QUESTION 2: > If I go this way, I have a second problem: if I create a new class which > inherits from the previous, I would expect/like the methods from the initial > class to return instances from the new class: > > class MyClass2(MyClass): > > ??? def othermethods(self): > ??? ??? return MyClass2(whatever) > > Then I get: > > x = list1 > y = list2 > data = MyClass2([x,y]) > finaldata = data.transformdata() > > My problem is that finaldata is (of course) an instance of MyClass and not > MyClass2. How do I deal with this ? Get the object's actual class at runtime and use that. #in MyClass def transformdata(self): newdata = transform(data) return self.__class__(newdata) When called on an instance of the subclass, self.__class__ will be MyClass2 and everything will work out. Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Fri Mar 5 07:15:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Mar 2010 13:15:59 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: <4b902338$0$31260$607ed4bc@cv.net> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> Message-ID: <4b90f5eb$0$9148$426a74cc@news.free.fr> John Posner a ?crit : > On 3/3/2010 6:56 PM, John Posner wrote: >> >> ... I was thinking >> today about "doing a Bruno", and producing similar pieces on: >> >> * properties created with the @property decorator >> >> * the descriptor protocol >> >> I'll try to produce something over the next couple of days. >> > > Starting to think about a writeup on Python properties, I've discovered > that the official Glossary [1] lacks an entry for "property" -- it's > missing in both Py2 and Py3! > > Here's a somewhat long-winded definition -- comments, please: > > --------------------------------------------- > An attribute, *a*, of an object, *obj*, is said to be implemented as a > property if the standard ways of accessing the attribute: > > * evaluation: print obj.a > * assignment: obj.a = 42 > * deletion: del obj.a > > ... cause methods of a user-defined *property object* to be invoked. Hmmm... a couple remarks: 1/ "property" is actually the name of a Python builtin type. It's also pretty much used in general OO litterature for what we name "attributes". So I think it would be better to avoid confusion between "property" as the builtin type, "property" as synonym for attribute, and "property" as the more specific concept of "computed attribute" - which is what you're describing here. As far as I'm concerned, I prefer to stick to "computed attribute" for the generic case, and only use "property" when the computed attribute is actually implemented using the builtin property type. 2/ depending on how the computed attribute is implemented, the computation needs not happen on ALL get/set/del access - you can have non-binding descriptors (that is, not implementing __set__). Also, the "standard" access also include getattr(), setattr() and delattr() (might be worth a note). > The > attribute /attribute/user-defined object/ here ? > is created as a class attribute, not an instance attribute. > Example: > > class Widget: > # create "color" as class attribute, not within __init__() > color = <> > > def __init__(self, ...): > # do not define "self.color" instance attribute Yes you can, and it's even actually pretty common: # example.py from somewhere import RGBColor class Foo(object): def _get_color(self): return str(self._color) def _set_color(self, val): self._color = RGBColor.from_string(val) color = property(fget=_get_color, fset=_set_color) def __init__(self, colorvalue): self.color = colorvalue > The property object can be created with the built-in function > property(), It's actually a type, not a function. > which in some cases can be coded as a decorator: @property. > The property object can also be an instance of a class that implements > the descriptor protocol. The "property object" IS an instance of a class that implements the descriptor protocol. The property type is just a "generic" descriptor: # naive (and incomplete) python implementation of the property type class property(object): def __init__(self, fget, fset=None, fdel=None) self._fget = fget self._fset = fset self._fdel = fdel def __get__(self, instance, cls): if instance is None: return self return self._fget(instance) def __set__(self, instance, value): if not self._fset: raise AttributeError("can't set attribute") self._fset(instance, value) def __del__(self): if not self._fdel: raise AttributeError("can't delete attribute") self._fdel(instance) As far as I'm concerned, I'd "plan" such a paper as: """ What's a property ? It's a computed attribute implemented using the builtin "property" type. Ok, so far it doesn't help much. So 1/ what's a computed attribute, and 2/ what is the property type ? 1/ your above explanation about what's a computed attribute in general, then a brief explanation of how computed attributes are implemented in python -> IOW, the descriptor protocol 2/ my above snippet !-) """ I think the way you started explaining computed attributes wrt/ attribute access could be a pretty good way to explain the descriptor protocol, since the mapping from get/set/del access to __get__, __set__, and __del__ magic methods is then pretty obvious. But YMMV of course, so by all mean feel free to discard all or parts of the above remarks !-) HTH From lbolla at gmail.com Fri Mar 5 07:19:23 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 5 Mar 2010 04:19:23 -0800 (PST) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> Message-ID: <13753751-d0af-48df-b78d-5b371109e05c@t41g2000yqt.googlegroups.com> On Mar 5, 10:01?am, BlueBird wrote: > On 3 mar, 20:35, Stefan Behnel wrote: > > > BlueBird, 03.03.2010 17:32: > > > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > > > that this does not exist. Does anybody know about this ? > > > SOAP may be an overly bloated protocol, but it's certainly not black magic. > > It's not hard to do manually if you really need to: > > >http://effbot.org/zone/element-soap.htm > > But this requires a goog knowloedge of SOAP, in order to parse > everything correctly. The reason I want to use a ready-made client is > that I have about zero knowledge about SOAP, and even more in the > differences between SOAP 1.1 and 1.2 . > > cheers, > > Philippe I use a thin custom-made python wrapper around gSoap[1], which is tens of times faster than ZSI. L. [1] http://www.cs.fsu.edu/~engelen/soapdoc2.html From jeanmichel at sequans.com Fri Mar 5 07:20:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 13:20:04 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: <4B90F6F4.5010202@sequans.com> Robert Kern wrote: > On 2010-03-04 15:12 , Mike Kent wrote: >> On Mar 4, 12:30 pm, Robert Kern wrote: >> >>> He's ignorant of the use cases of the with: statement, true. >> >> Ouch! Ignorant of the use cases of the with statement, am I? >> Odd, I use it all the time. > > No, I was referring to Jean-Michel, who was not familiar with the > with: statement. > >>> Given only your >>> example of the with: statement, it is hard to fault him for thinking >>> that try: >>> finally: wouldn't suffice. >> >> Damn me with faint praise, will you? > > Also talking about Jean-Michel. :-) > I confirm, I am the ignoramus (what a strange word) in this story :-) JM From lbolla at gmail.com Fri Mar 5 07:24:51 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 5 Mar 2010 04:24:51 -0800 (PST) Subject: Selecting MAX from a list References: Message-ID: On Mar 5, 11:39?am, Ines T wrote: > I need to select a maximum number from a list and then call the variable that > identifies that number, for example: > x1,x2=1, y1,y2=4, z1,z2=3 > So I need first to find 4 and then to take y to do additional operations as y-z. It's not clear what you are supposed to do, but wouldn't a combination of "max" and "index" do? x = [3,2,1,4,5,2,3] max(x) # 5 x.index(5) # 4 > I will appreciate your SOON help! And, by the way, politeness is free! From alfps at start.no Fri Mar 5 08:06:55 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 14:06:55 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 17:52 , Alf P. Steinbach wrote: >> * Robert Kern: >>> On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: >>>> * Robert Kern: >>>>> On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: >>>>>> * Robert Kern: >>>>>>> On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: >>>> [snippety] >>>>>>> >>>>>>>> If you call the possibly failing operation "A", then that >>>>>>>> systematic >>>>>>>> approach goes like this: if A fails, then it has cleaned up its own >>>>>>>> mess, but if A succeeds, then it's the responsibility of the >>>>>>>> calling >>>>>>>> code to clean up if the higher level (multiple statements) >>>>>>>> operation >>>>>>>> that A is embedded in, fails. >>>>>>>> >>>>>>>> And that's what Marginean's original C++ ScopeGuard was designed >>>>>>>> for, >>>>>>>> and what the corresponding Python Cleanup class is designed for. >>>>>>> >>>>>>> And try: finally:, for that matter. >>>>>> >>>>>> Not to mention "with". >>>>>> >>>>>> Some other poster made the same error recently in this thread; it >>>>>> is a >>>>>> common fallacy in discussions about programming, to assume that since >>>>>> the same can be expressed using lower level constructs, those are all >>>>>> that are required. >>>>>> >>>>>> If adopted as true it ultimately means the removal of all control >>>>>> structures above the level of "if" and "goto" (except Python doesn't >>>>>> have "goto"). >>>>> >>>>> What I'm trying to explain is that the with: statement has a use even >>>>> if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: >>>>> finally: does not mean that the with: statement doesn't improve on >>>>> try: finally:. >>>> >>>> That's a different argument, essentially that you see no advantage for >>>> your current coding patterns. >>>> >>>> It's unconnected to the argument I responded to. >>>> >>>> The argument that I responded to, that the possibility of expressing >>>> things at the level of try:finally: means that a higher level construct >>>> is superfluous, is still meaningless. >>> >>> I am attacking your premise that the "with Cleanup():" construct is >>> higher level than try: finally:. It isn't. It provides the same level >>> of abstraction as try: finally:. >>> >>> This is distinct from the accepted uses of the with: statement which >>> *are* higher level than try: finally: and which do confer practical >>> benefits over using try: finally: despite being syntactical sugar for >>> try: finally:. >>> >>>>>>>>> Both formulations can be correct (and both work perfectly fine >>>>>>>>> with >>>>>>>>> the chdir() example being used). Sometimes one is better than the >>>>>>>>> other, and sometimes not. You can achieve both ways with either >>>>>>>>> your >>>>>>>>> Cleanup class or with try: finally:. >>>>>>>>> >>>>>>>>> I am still of the opinion that Cleanup is not an improvement over >>>>>>>>> try: >>>>>>>>> finally: and has the significant ugliness of forcing cleanup code >>>>>>>>> into >>>>>>>>> callables. This significantly limits what you can do in your >>>>>>>>> cleanup >>>>>>>>> code. >>>>>>>> >>>>>>>> Uhm, not really. :-) As I see it. >>>>>>> >>>>>>> Well, not being able to affect the namespace is a significant >>>>>>> limitation. Sometimes you need to delete objects from the >>>>>>> namespace in >>>>>>> order to ensure that their refcounts go to zero and their cleanup >>>>>>> code >>>>>>> gets executed. >>>>>> >>>>>> Just a nit (I agree that a lambda can't do this, but as to what's >>>>>> required): assigning None is sufficient for that[1]. >>>>> >>>>> Yes, but no callable is going to allow you to assign None to names in >>>>> that namespace, either. Not without sys._getframe() hackery, in any >>>>> case. >>>>> >>>>>> However, note that the current language doesn't guarantee such >>>>>> cleanup, >>>>>> at least as far as I know. >>>>>> >>>>>> So while it's good practice to support it, to do everything to let it >>>>>> happen, it's presumably bad practice to rely on it happening. >>>>>> >>>>>> >>>>>>> Tracebacks will keep the namespace alive and all objects in it. >>>>>> >>>>>> Thanks!, I hadn't thought of connecting that to general cleanup >>>>>> actions. >>>>>> >>>>>> It limits the use of general "with" in the same way. >>>>> >>>>> Not really. >>>> >>>> Sorry, it limits general 'with' in /exactly/ the same way. >>>> >>>>> It's easy to write context managers that do that [delete objects from >>>>> the namespace]. >>>> >>>> Sorry, no can do, as far as I know; your following example quoted below >>>> is an example of /something else/. >>> >>> Okay, so what do you mean by 'the use of general "with"'? I'm talking >>> about writing a context manager or using the @contextmanager decorator >>> to do some initialization and then later cleaning up that >>> initialization. That cleaning up may entail deleting an object. You >>> are correct that the context manager can't affect the namespace of the >>> with: clause, but that's not the initialization that it would need to >>> clean up. >>> >>> Yes, you can write code with a with: statement where you try to clean >>> up stuff that happened inside of the clause (you did), but that's not >>> how the with: statement was ever intended to be used nor is it good >>> practice to do so because of that limitation. Context managers are >>> designed to initialize specific things, then clean them up. I thought >>> you were talking about the uses of the with: statement as described in >>> PEP-343, not every possible misuse of the with: statement. >> >> I'm not the one talking about removing variables or that "it's easy to >> write context managers that do that". >> >> You are the one talking about that. >> >> So I have really not much to add. >> >> It seems that you're now agreeing with me that former is not good >> practice and that the latter is impossible to do portably, but you now >> argue against your earlier stand as if that was something that I had put >> forward. > > No, I'm still saying that sometimes you do need to remove variables that > you initialized in the initialization section. Writing a purpose-built > context manager which encapsulates the initialization and finalization > allows you to do this easily. Putting the initialization section inside > the with: clause, as you do, and requiring cleanup code to be put into > callables makes this hard. > >> It's a bit confusing when you argue against your own statements. >> >>>> And adding on top of irrelevancy, for the pure technical aspect it can >>>> be accomplished in the same way using Cleanup (I provide an example >>>> below). >>>> >>>> However, doing that would generally be worse than pointless since with >>>> good coding practices the objects would become unreferenced anyway. >>>> >>>> >>>>> You put the initialization code in the __enter__() method, assign >>>>> whatever objects you want to keep around through the with: clause as >>>>> attributes on the manager, then delete those attributes in the >>>>> __exit__(). >>>> >>>> Analogously, if one were to do this thing, then it could be >>>> accomplished >>>> using a Cleanup context manager as follows: >>>> >>>> foo = lambda: None >>>> foo.x = create_some_object() >>>> at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) >>>> >>>> ... except that >>>> >>>> 1) for a once-only case this is less code :-) >>> >>> Not compared to a try: finally:, it isn't. >> >> Again, this context shifting is bewildering. As you can see, quoted >> above, you were talking about a situation where you would have defined a >> context manager, presumably because a 'try' would not in your opinion be >> simpler for whatever it was that you had in mind. But you are responding >> to the code I offered as if it was an alternative to something where you >> would find a 'try' to be simplest. > > I have consistently put forward that for once-only cases, try: finally: > is a preferable construct to "with Cleanup():". I also put forward that > for repetitive cases, a purpose-built context manager is preferable. I > note that for both try: finally: and a purpose-built context manager, > modifying the namespace is easy to do while it is difficult and less > readable to do with "with Cleanup():". Since you were claiming that the > "generic with:" would have the same problem as "with Cleanup():" I was > trying to explain for why all of the intended use cases of the with: > statement (the purpose-built context managers), there is no problem. > Capisce? > >>>> 2) it is a usage that I wouldn't recommend; instead I recommend >>>> adopting >>>> good >>>> coding practices where object references aren't kept around. >>> >>> Many of the use cases of the with: statement involve creating an >>> object (like a lock or a transaction object), keeping it around for >>> the duration of the "# Do stuff" block, and then finalizing it. >>> >>>>> Or, you use the @contextmanager decorator to turn a generator into a >>>>> context manager, and you just assign to local variables and del them >>>>> in the finally: clause. >>>> >>>> Uhm, you don't need a 'finally' clause when you define a context >>>> manager. >>> >>> When you use the @contextmanager decorator, you almost always do. See >>> the Examples section of PEP 343: >>> >>> http://www.python.org/dev/peps/pep-0343/ >>> >>>> Additionally, you don't need to 'del' the local variables in >>>> @contextmanager decorated generator. >>>> >>>> The local variables cease to exist automatically. >>> >>> True. >>> >>>>> What you can't do is write a generic context manager where the >>>>> initialization happens inside the with: clause and the cleanup actions >>>>> are registered callables. That does not allow you to affect the >>>>> namespace. >>>> >>>> If you mean that you can't introduce direct local variables and have >>>> them deleted by "registered callables" in a portable way, then right. >>>> >>>> But I can't think of any example where that would be relevant; in >>>> particular what matters for supporting on-destruction cleanup is >>>> whether >>>> you keep any references or not, not whether you have a local >>>> variable of >>>> any given name. >>> >>> Well, local variables keep references to objects. Variable assignment >>> followed by deletion is a very readable way to keep an object around >>> for a while then remove it later. If you have to go through less >>> readable contortions to keep the object around when it needs to be and >>> clean it up later, then that is a mark against your approach. >> >> Sorry, as with the places noted above, I can't understand what you're >> trying to say here. I don't recommend coding practices where you keep >> object references around, > > Then how do you clean up locks and transaction objects and similar > things if you don't keep them around during the code suite? Creating an > object, keeping it around while executing a specific chunk of code, and > finalizing it safely is a prime use case for these kinds of constructs. Where you need a scope, create a scope. That is, put the logic in a routine. However, most objects aren't of the sort the requiring to become unreferenced. Those that require cleanup can be cleaned up and left as zombies, like calling 'close' on a file. And so in the general case what you're discussing, how to get rid of object references, is a non-issue -- irrelevant. >> and you have twice quoted that above. I don't >> have any clue what "contortions" you are talking about, it must be >> something that you imagine. > > These are the contortions: > > foo = lambda: None > foo.x = create_some_object() > at_cleanup.call( lambda o = foo: delattr( o, "x" ) ) That's code that demonstrates something very different, in response to your description of doing this. Since I half suspected that it could be taken out of context I followed that immediately with 2) it is a usage that I wouldn't recommend; instead I recommend adopting good coding practices where object references aren't kept around. I'm sorry but I don't know how to make that more clear. Cheers & hth., - Alf From alfps at start.no Fri Mar 5 08:09:08 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 14:09:08 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> <6af3c613-3439-484b-83f1-49213f1ed574@k17g2000yqb.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-04 16:27 , Alf P. Steinbach wrote: >> * Mike Kent: > >>> However, I fail to understand his response that I must have meant try/ >>> else instead, as this, as Mr. Kern pointed out, is invalid syntax. >>> Perhaps Mr. Steinbach would like to give an example? >> >> OK. >> >> Assuming that you wanted the chdir to be within a try block (which it >> was in your code), then to get code equivalent to my code, for the >> purpose of a comparision of codes that do the same, you'd have to write >> something like ... >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> except Whatever: >> # E.g. log it. >> raise >> else: >> try: >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup >> >> ... which would be a more general case. >> >> I've also given this example in response to Robert earlier in the >> thread. Although I haven't tried it I believe it's syntactically valid. >> If not, then the relevant typo should just be fixed. :-) >> >> I have no idea which construct Robert thought was syntactically invalid. >> I think that if he's written that, then it must have been something he >> thought of. > > I was just trying to interpret what you meant by "Changing 'finally' to > 'else' could make it equivalent." Oh yes, in the article where I gave the example of that, shown above. Hey, discussing previous discussion is silly. Cheers, - ALf From mrkafk at gmail.com Fri Mar 5 08:26:13 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 14:26:13 +0100 Subject: loop over list and process into groups In-Reply-To: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <4B910675.60909@gmail.com> Sneaky Wombat wrote: > [ 'VLAN4065', > 'Interface', > 'Gi9/6', > 'Po2', > 'Po3', > 'Po306', > 'VLAN4068', > 'Interface', > 'Gi9/6', > 'VLAN4069', > 'Interface', > 'Gi9/6',] Hey, I just invented a cute ;-) two-liner using list comprehensions: # alist = list above tmp, dk = [], {} [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) for x in alist if x != 'Interface'] No need to use a nuke like itertools to kill a fly. ;-) Regards, mk From raghavendra.gv.vanam at gmail.com Fri Mar 5 08:32:21 2010 From: raghavendra.gv.vanam at gmail.com (vanam) Date: Fri, 5 Mar 2010 05:32:21 -0800 (PST) Subject: process mp3 file References: <6fc7b483-c9a9-4581-991c-f816a2701526@g8g2000pri.googlegroups.com> <9ab3890c-14b9-4031-96c1-6f991469c9ae@m35g2000prh.googlegroups.com> Message-ID: On Mar 3, 3:43?pm, asit wrote: > > Define "processing". > > getting the title, song name, etc of the file and updating in a > database Other possibility can be passing out the extension of the file and directory where the files are present, using os.walk we can extract the file name by filtering the .mp3 extension. From duncan.booth at invalid.invalid Fri Mar 5 08:38:51 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2010 13:38:51 GMT Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: Jean-Michel Pichavant wrote: > You've already been given good advices. > Unlike some of those, I don't think using regexp an issue in any way. > Yes they are not readable, for sure, I 100% agree to that statement, but > you can make them readable very easily. > > # not readable > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) > > > # readable > match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # match > '192.168.200.1 (foo123)' > > I gladly understand ppl that are not willing to use regexp (or as last > resort), but for a perl guy, that should not be an issue. The problem with your comment is that just by existing it means people will be misled into thinking the regex is being used to match strings like '192.168.200.1 (foo123)' when in fact the OP is expecting to match strings like '192.168.200.1 foo123' i.e. you may mislead some people into thinking the parentheses are part of what is being matched when they're actually grouping within the regex. Another problem with either regular expression line is that it makes it less easy to see that it doesn't do what the OP wanted. /etc/hosts contains lines with an IP address followed by multiple hostnames. It may also contain comments either as complete lines or at the end of lines. The code given will miss hostnames after the first and will include hostnames in commented out lines. -- Duncan Booth http://kupuguy.blogspot.com From mehgcap at gmail.com Fri Mar 5 08:41:37 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 5 Mar 2010 08:41:37 -0500 Subject: python on a thumb drive? Message-ID: Hello all, My name is Alex. I am pretty new to Python, but I really like it. I am trying to put my python and pythonw executables on my thumb drive, along with packages, using Moveable Python, but I cannot figure out how to run scripts using it. I would rather use a shell than the script runner gui since it does not seem to work. Any suggestions? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From jeanmichel at sequans.com Fri Mar 5 09:28:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 15:28:49 +0100 Subject: Evaluate my first python script, please In-Reply-To: References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <4B911521.20302@sequans.com> Duncan Booth wrote: > Jean-Michel Pichavant wrote: > > >> You've already been given good advices. >> Unlike some of those, I don't think using regexp an issue in any way. >> Yes they are not readable, for sure, I 100% agree to that statement, but >> you can make them readable very easily. >> >> # not readable >> match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) >> >> >> # readable >> match = re.search('\d+\.\d+\.\d+\.\d+\s+(\S+)', line) # match >> '192.168.200.1 (foo123)' >> >> I gladly understand ppl that are not willing to use regexp (or as last >> resort), but for a perl guy, that should not be an issue. >> > > The problem with your comment is that just by existing it means people will > be misled into thinking the regex is being used to match strings like > '192.168.200.1 (foo123)' > when in fact the OP is expecting to match strings like > '192.168.200.1 foo123' > > i.e. you may mislead some people into thinking the parentheses are part of > what is being matched when they're actually grouping within the regex. > > Another problem with either regular expression line is that it makes it > less easy to see that it doesn't do what the OP wanted. /etc/hosts contains > lines with an IP address followed by multiple hostnames. It may also > contain comments either as complete lines or at the end of lines. The code > given will miss hostnames after the first and will include hostnames in > commented out lines. > > And tell me how not using regexp will ensure the /etc/hosts processing is correct ? The non regexp solutions provided in this thread did not handled what you rightfully pointed out about host list and commented lines. And FYI, the OP pattern does match '192.168.200.1 (foo123)' ... Ok that's totally unfair :D You're right I made a mistake. Still the comment is absolutely required (provided it's correct). JM From jpiitula at ling.helsinki.fi Fri Mar 5 09:43:47 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 05 Mar 2010 16:43:47 +0200 Subject: Partly erratic wrong behaviour, Python 3, lxml References: Message-ID: Stefan Behnel writes: > Jussi Piitulainen, 04.03.2010 22:40: > > Stefan Behnel writes: > >> Jussi Piitulainen, 04.03.2010 11:46: > >>> I am observing weird semi-erratic behaviour that involves Python 3 > >>> and lxml, is extremely sensitive to changes in the input data, and > >>> only occurs when I name a partial result. I would like some help > >>> with this, please. (Python 3.1.1; GNU/Linux; how do I find lxml > >>> version?) > >> > >> Here's how to find the version: > >> > >> http://codespeak.net/lxml/FAQ.html#i-think-i-have-found-a-bug-in-lxml-what-should-i-do > > > > Ok, thank you. Here's the results: > > > > >>> print(et.LXML_VERSION, et.LIBXML_VERSION, > > ... et.LIBXML_COMPILED_VERSION, et.LIBXSLT_VERSION, > > ... et.LIBXSLT_COMPILED_VERSION) > > (2, 2, 4, 0) (2, 6, 26) (2, 6, 26) (1, 1, 17) (1, 1, 17) > > I can't reproduce this with the latest lxml trunk (and Py3.2 trunk) > and libxml2 2.7.6, even after running your test script for quite a > while. I'd try to upgrade the libxml2 version. Thank you much. I suppose that is good news. It's a big server with many users - I will ask the administrators to consider an upgrade when I get around to it. Turns out that lxml documentation warns not to use libxml2 version 2.6.27 if I want to use xpath, and that is just a bit newer than we have. On that cue, I seem to have found a workaround: I replaced the xpath expression with findall(titlef) where titlef = ( '//{http://www.openarchives.org/OAI/2.0/}record' '//{http://purl.org/dc/elements/1.1}title' ) In the previously broken naming() function I now have: result = etree.parse(BytesIO(body)) n = len(result.findall(titlef)) And in the previously working nesting() function: n = len(etree.parse(BytesIO(body)).findall(titlef)) With these changes, the test script gives consistently the result that I expect, and the more complicated real test script where I first met the problem also appears to work without a hitch. So, this works. The other, broken behaviour is totally scary, though. From duncan.booth at invalid.invalid Fri Mar 5 10:00:07 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Mar 2010 15:00:07 GMT Subject: Evaluate my first python script, please References: Message-ID: Jean-Michel Pichavant wrote: > And tell me how not using regexp will ensure the /etc/hosts processing > is correct ? The non regexp solutions provided in this thread did not > handled what you rightfully pointed out about host list and commented > lines. It won't make is automatically correct, but I'd guess that written without being so dependent on regexes might have made someone point out those deficiencies sooner. The point being that casual readers of the code won't take the time to decode the regex, they'll glance over it and assume it does something or other sensible. If I was writing that code, I'd read each line, strip off comments and leading whitespace (so you can use re.match instead of re.search), split on whitespace and take all but the first field. I might check that the field I'm ignoring it something like a numeric ip address, but if I did want to do then I'd include range checking for valid octets so still no regex. The whole of that I'd wrap in a generator so what you get back is a sequence of host names. However that's just me. I'm not averse to regular expressions, I've written some real mammoths from time to time, but I do avoid them when there are simpler clearer alternatives. > And FYI, the OP pattern does match '192.168.200.1 (foo123)' > ... > Ok that's totally unfair :D You're right I made a mistake. Still the > comment is absolutely required (provided it's correct). > Yes, the comment would have been good had it been correct. I'd also go for a named group as that provides additional context within the regex. Also if there are several similar regular expressions in the code, or if they get too complex I'd build them up in parts. e.g. OCTET = r'(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])' ADDRESS = (OCTET + r'\.') * 3 + OCTET HOSTNAME = r'[-a-zA-Z0-9]+(?:\.[-a-zA-Z0-9]+)*' # could use \S+ but my Linux manual says # alphanumeric, dash and dots only ... and so on ... which provides another way of documenting the intentions of the regex. BTW, I'm not advocating that here, the above patterns would be overkill, but in more complex situations thats what I'd do. -- Duncan Booth http://kupuguy.blogspot.com From jjposner at optimum.net Fri Mar 5 10:10:51 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Mar 2010 10:10:51 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b90f5eb$0$9148$426a74cc@news.free.fr> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> Message-ID: <4b911ee0$0$4988$607ed4bc@cv.net> On 3/5/2010 7:15 AM, Bruno Desthuilliers wrote: > John Posner a ?crit : >> On 3/3/2010 6:56 PM, John Posner wrote: >>> >>> ... I was thinking >>> today about "doing a Bruno", and producing similar pieces on: >>> >>> * properties created with the @property decorator >>> >>> * the descriptor protocol >>> >>> I'll try to produce something over the next couple of days. >>> >> >> Starting to think about a writeup on Python properties, I've >> discovered that the official Glossary [1] lacks an entry for >> "property" -- it's missing in both Py2 and Py3! >> >> Here's a somewhat long-winded definition -- comments, please: >> >> --------------------------------------------- >> An attribute, *a*, of an object, *obj*, is said to be implemented as a >> property if the standard ways of accessing the attribute: >> >> * evaluation: print obj.a >> * assignment: obj.a = 42 >> * deletion: del obj.a >> >> ... cause methods of a user-defined *property object* to be invoked. > > Hmmm... a couple remarks: > > 1/ "property" is actually the name of a Python builtin type. It's also > pretty much used in general OO litterature for what we name > "attributes". So I think it would be better to avoid confusion between > "property" as the builtin type, "property" as synonym for attribute, and > "property" as the more specific concept of "computed attribute" - which > is what you're describing here. > > As far as I'm concerned, I prefer to stick to "computed attribute" for > the generic case, and only use "property" when the computed attribute is > actually implemented using the builtin property type. Yes, I had already decided that the first sentence of the glossary definition needs to be, "A property is a computed attribute". > > 2/ depending on how the computed attribute is implemented, the > computation needs not happen on ALL get/set/del access - you can have > non-binding descriptors (that is, not implementing __set__). Yes, but IMHO that information belongs in the full writeup, not in the glossary definition. I've added the phrase "some or all" in the glossary definition (see below). > Also, the "standard" access also include getattr(), setattr() and > delattr() (might be worth a note). > >> The attribute > > /attribute/user-defined object/ here ? > >> is created as a class attribute, not an instance attribute. Example: >> >> class Widget: >> # create "color" as class attribute, not within __init__() >> color = <> >> >> def __init__(self, ...): >> # do not define "self.color" instance attribute > > Yes you can, and it's even actually pretty common: Of course -- and I realize that I was introducing confusion, rather than enlightenment, with my example. I think the point is too subtle for a (necessarily short) glossary definition, so I'm removing the example from the definition. > > # example.py > from somewhere import RGBColor > > class Foo(object): > def _get_color(self): > return str(self._color) > def _set_color(self, val): > self._color = RGBColor.from_string(val) > color = property(fget=_get_color, fset=_set_color) > > def __init__(self, colorvalue): > self.color = colorvalue [OFF-TOPIC] Wow, Thunderbird 3.0.2 nuked the indentation in the code above. :-( > > >> The property object can be created with the built-in function property(), > > It's actually a type, not a function. Ah, yes. Thanks. > >> which in some cases can be coded as a decorator: @property. The >> property object can also be an instance of a class that implements the >> descriptor protocol. > > The "property object" IS an instance of a class that implements the > descriptor protocol. The property type is just a "generic" descriptor: > > # naive (and incomplete) python implementation of the property type > > class property(object): > def __init__(self, fget, fset=None, fdel=None) > self._fget = fget > self._fset = fset > self._fdel = fdel > > def __get__(self, instance, cls): > if instance is None: > return self > return self._fget(instance) > > def __set__(self, instance, value): > if not self._fset: > raise AttributeError("can't set attribute") > self._fset(instance, value) > > def __del__(self): > if not self._fdel: > raise AttributeError("can't delete attribute") > self._fdel(instance) Good stuff for the full writeup on properties. > As far as I'm concerned, I'd "plan" such a paper as: > > """ > What's a property ? It's a computed attribute implemented using the > builtin "property" type. > > Ok, so far it doesn't help much. So > 1/ what's a computed attribute, and > 2/ what is the property type ? > > 1/ your above explanation about what's a computed attribute in general, > then a brief explanation of how computed attributes are implemented in > python -> IOW, the descriptor protocol > > 2/ my above snippet !-) I agree. I'm not sure whether the "brief explanation of how computed attributes are implemented in Python" belongs in the *properties* writeup or the *descriptors* writeup. (I think they should be separate, to avoid making readers brains explode.) I'll make the (initial) call when/if I get that far! > > """ > > I think the way you started explaining computed attributes wrt/ > attribute access could be a pretty good way to explain the descriptor > protocol, since the mapping from get/set/del access to __get__, __set__, > and __del__ magic methods is then pretty obvious. > > But YMMV of course, so by all mean feel free to discard all or parts of > the above remarks !-) > > HTH Here's my leaner, meaner glossary definition of *property*: ------------------- A property is a computed attribute: an attribute, a, of an object, obj, is said to be implemented as a property if some or all of the standard ways of accessing the attribute: * evaluation: result = obj.a * assignment: obj.a = 42 * deletion: del obj.a ... cause methods of another user-defined object to be invoked. This other object can be an instance of the built-in type *property*, or as an instance of a class that implements the descriptor protocol. ------------------- Many thanks, Bruno -- again! -John From J.Fine at open.ac.uk Fri Mar 5 10:19:45 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Fri, 05 Mar 2010 15:19:45 +0000 Subject: WANTED: A good name for the pair (args, kwargs) In-Reply-To: References: Message-ID: Jonathan Fine wrote: > Hi > > We can call a function fn using > val = fn(*args, **kwargs) > > I'm looking for a good name for the pair (args, kwargs). Any suggestions? > > Here's my use case: > def doit(fn , wibble, expect): > args, kwargs = wibble > actual = fn(*args, **kwargs) > if actual != expect: > # Something has gone wrong. > pass > > This is part of a test runner. > > For now I'll use argpair, but if anyone has a better idea, I'll use it. Thank you, Tim, Paul, Steve and Aahz for your suggestions. I'm now preferring: def test_apply(object, argv, valv): args, kwargs = argv expect, exceptions = valv # Inside try: except: actual = object(*args, **kwargs) # Check against expect, exceptions. best regards Jonathan From pemerson at gmail.com Fri Mar 5 10:53:06 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 07:53:06 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> Message-ID: <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Thanks for your response, further questions inline. On Mar 4, 11:07?am, Tim Wintle wrote: > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > I am looking for advice along the lines of "an easier way to do this" > > or "a more python way" (I'm sure that's asking for trouble!) or > > "people commonly do this instead" or "here's a slick trick" or "oh, > > interesting, here's my version to do the same thing". > > (1) I would wrap it all in a function > > def main(): > ? ? # your code here > > if __name__ == "__main__": > ? ? main() Is this purely aesthetic reasons, or will I appreciate this when I write my own modules, or something else? > > (2) PEP8 (python style guidelines) suggests one import per line > > (3) I'd use four spaces as tab width > > (4) > I'd change this: > > > ? ? for arg in sys.argv[1:]: > > ? ? ? ? for section in hostname.split('.'): > > ? ? ? ? ? ? if section == arg: > > ? ? ? ? ? ? ? ? count = count + 1 > > ? ? ? ? ? ? ? ? break > > to something more like: > > ? ? for section in hostname.split("."): > ? ? ? ? if section in sys.argv[1:]: > ? ? ? ? ? ? count += 1 Ah, yes, I like that. It moves towards the set notation I've wound up with. Definitely more readable to me. > > (although as you suggested I'd only calculate sys.argv[1:] once) > > ... or you could replace whole section between the for loop and > hosts.append with: > > ? ? if sorted(hostname.split(".")) == sorted(sys.argv[1:]): > ? ? ? ? host.append(hostname) This doesn't actually work, because I'm not looking for a one to one mapping of args to sections of hostname, but rather a subset. So passing in 'prod sfo' would register a match for '001.webapp.prod.sfo'. From pemerson at gmail.com Fri Mar 5 10:55:00 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 07:55:00 -0800 (PST) Subject: Evaluate my first python script, please References: Message-ID: <6c76b898-9137-49d7-94a0-efd63fc82aed@c37g2000prb.googlegroups.com> On Mar 5, 7:00?am, Duncan Booth wrote: > Jean-Michel Pichavant wrote: > > And tell me how not using regexp will ensure the /etc/hosts processing > > is correct ? The non regexp solutions provided in this thread did not > > handled what you rightfully pointed out about host list and commented > > lines. > > It won't make is automatically correct, but I'd guess that written without > being so dependent on regexes might have made someone point out those > deficiencies sooner. The point being that casual readers of the code won't > take the time to decode the regex, they'll glance over it and assume it > does something or other sensible. > > If I was writing that code, I'd read each line, strip off comments and > leading whitespace (so you can use re.match instead of re.search), split on > whitespace and take all but the first field. I might check that the field > I'm ignoring it something like a numeric ip address, but if I did want to > do then I'd include range checking for valid octets so still no regex. > > The whole of that I'd wrap in a generator so what you get back is a > sequence of host names. > > However that's just me. I'm not averse to regular expressions, I've written > some real mammoths from time to time, but I do avoid them when there are > simpler clearer alternatives. > > > And FYI, the OP pattern does match '192.168.200.1 (foo123)' > > ... > > Ok that's totally unfair :D You're right I made a mistake. ?Still the > > comment is absolutely required (provided it's correct). > > Yes, the comment would have been good had it been correct. I'd also go for > a named group as that provides additional context within the regex. > > Also if there are several similar regular expressions in the code, or if > they get too complex I'd build them up in parts. e.g. > > OCTET = r'(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])' > ADDRESS = (OCTET + r'\.') * 3 + OCTET > HOSTNAME = r'[-a-zA-Z0-9]+(?:\.[-a-zA-Z0-9]+)*' > ? # could use \S+ but my Linux manual says > ? # alphanumeric, dash and dots only > ... and so on ... > > which provides another way of documenting the intentions of the regex. > > BTW, I'm not advocating that here, the above patterns would be overkill, > but in more complex situations thats what I'd do. > > -- > Duncan Boothhttp://kupuguy.blogspot.com All good comments here. The takeaway for my lazy style of regexes (which makes it harder for non-regex fiends to read, regardless of the language) is that there are ways to make regexes much more readable to the untrained eye. Duncan, I like your method of defining sections of the regex outside the regex itself, even if it's a one time use. From john at castleamber.com Fri Mar 5 10:55:11 2010 From: john at castleamber.com (John Bokma) Date: Fri, 05 Mar 2010 09:55:11 -0600 Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> Message-ID: <87sk8ercf4.fsf@castleamber.com> Steven D'Aprano writes: > On Fri, 05 Mar 2010 18:36:06 +1300, Gregory Ewing wrote: > >> Paul Rubin wrote: >>> ReST was another solution in search of a problem. >> >> I think the basic idea behind ReST is quite good, i.e. understanding as >> markup various typographical conventions that make sense in plain text, >> such as underlined headings, bullets, numbered paragraphs. >> >> Unfortunately it went overboard with a slew of cryptic codes for >> footnotes, hyperlinks, etc. that nobody would naturally think to use in >> a plain text document. > > I use footnotes all the time[1] in plain text documents and emails. I > don't think there's anything bizarre about it at all. http://docutils.sourceforge.net/docs/user/rst/quickref.html#footnotes [#]_. .. [#] the keyword is ReST. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From showell30 at yahoo.com Fri Mar 5 11:01:12 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 5 Mar 2010 08:01:12 -0800 (PST) Subject: Draft PEP on RSON configuration file format References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7xvddbqkgp.fsf@ruckus.brouhaha.com> Message-ID: On Mar 4, 11:46?pm, Paul Rubin wrote: > > Ehh, either the JSON standardizers care about this issue or else they > don't. ?JSON (as currently defined) is a machine-to-machine > serialization format and just isn't that good a choice for handwritten > files. ?Adding a comment specification is a small perturbation that > might be accepted into the standard, but a big departure like RSON is a > whole nother creature. > > > How many hundreds of thousands of people have had to deal with XML > > without receiving its benefits? ?Do well-established standards get an > > exemption from the rule that software is not allowed to annoy non- > > willing users of it? > > We already have to deal with XML. ?So using XML for config files doesn't > require anyone to deal with any lousy formats that they didn't have to > deal with before. ?So the basic answer to your question about > well-established standards is yes: one annoying but standardized format > is better than multiple annoying unstandardized ones. Does this mean we should stick with XML until the end of time? From tim.wintle at teamrubber.com Fri Mar 5 11:07:22 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 05 Mar 2010 16:07:22 +0000 Subject: Evaluate my first python script, please In-Reply-To: <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Message-ID: <1267805242.29768.7.camel@localhost> On Fri, 2010-03-05 at 07:53 -0800, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07 am, Tim Wintle wrote: > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a more python way" (I'm sure that's asking for trouble!) or > > > "people commonly do this instead" or "here's a slick trick" or "oh, > > > interesting, here's my version to do the same thing". > > > > (1) I would wrap it all in a function > > > > def main(): > > # your code here > > > > if __name__ == "__main__": > > main() > > Is this purely aesthetic reasons, or will I appreciate this when I > write my own modules, or something else? It's for when you reuse this code. Consider it's in "mymodule.py" (so run with ./mymodule.py) - if you then make a "tests.py" (for example) you can "import mymodule" without it automatically running your code. re-writing it def main(args): #your code if __name__ == "__main__": main(sys.argv[1:]) would obviously be more sensible for actually writing tests. > > ... or you could replace whole section between the for loop and > > hosts.append with: > > > > if sorted(hostname.split(".")) == sorted(sys.argv[1:]): > > host.append(hostname) > > This doesn't actually work, because I'm not looking for a one to one > mapping of args to sections of hostname, but rather a subset. So > passing in 'prod sfo' would register a match for '001.webapp.prod.sfo'. Ah - good point - I guess the the set intersection technique someone else mentioned is best in that case. Tim From chris.lieb at gmail.com Fri Mar 5 11:08:56 2010 From: chris.lieb at gmail.com (Chris Lieb) Date: Fri, 5 Mar 2010 08:08:56 -0800 (PST) Subject: Failure in test_hashlib.py and test_hmac.py References: <175865db-f64a-4633-8e36-ab4a5a5eaccf@x22g2000yqx.googlegroups.com> <7xr5nzqkaw.fsf@ruckus.brouhaha.com> Message-ID: On Mar 5, 2:50?am, Paul Rubin wrote: > Chris Lieb writes: > > I am building Python 2.6.4 on a shared server and am encountering test > > failures in test_hashlib.py and test_hmac.py, > > You should certainly file a bug report (bugs.python.org). ?If you want > to debug it yourself and include a patch, that's great. ?Otherwise, just > file the report. > > ? ? In the case of test_hashlib.py, it segfaulted on the first sha512 test > ? ? when I didn't have the debugging options enabled. ?Only after enabling > ? ? debugging did I get FAIL's for the sha512 tests. > > ? ? Does anyone know what is causing these failures? > > Please be precise about the hw and compiler versions. I have created this as bug 8073 [http://bugs.python.org/issue8073] From python.list at tim.thechases.com Fri Mar 5 11:28:41 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Mar 2010 10:28:41 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7xvddbqkgp.fsf@ruckus.brouhaha.com> Message-ID: <4B913139.7000704@tim.thechases.com> Steve Howell wrote: > On Mar 4, 11:46 pm, Paul Rubin wrote: >> We already have to deal with XML. So using XML for config files doesn't >> require anyone to deal with any lousy formats that they didn't have to >> deal with before. So the basic answer to your question about >> well-established standards is yes: one annoying but standardized format >> is better than multiple annoying unstandardized ones. > > > Does this mean we should stick with XML until the end of time? > One word: COBOL :-) -tkc From mrmakent at gmail.com Fri Mar 5 11:29:59 2010 From: mrmakent at gmail.com (Mike Kent) Date: Fri, 5 Mar 2010 08:29:59 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On Mar 4, 8:04?pm, Robert Kern wrote: > No, the try: finally: is not implicit. See the source for > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > with: block, it will push it into the generator using its .throw() method. This > raises the exception inside the generator at the yield statement. Wow, I just learned something new. My understanding of context managers was that the __exit__ method was guaranteed to be executed regardless of how the context was left. I have often written my own context manager classes, giving them the __enter__ and __exit__ methods. I had mistakenly assumed that the @contextmanager decorator turned a generator function into a context manager with the same behavior as the equivalent context manager class. Now I learn that, no, in order to have the 'undo' code executed in the presence of an exception, you must write your own try/finally block in the generator function. This raises the question in my mind: What's the use case for using @contextmanager rather than wrapping your code in a context manager class that defines __enter__ and __exit__, if you still have to manager your own try/finally block? From showell30 at yahoo.com Fri Mar 5 11:38:27 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 5 Mar 2010 08:38:27 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <38c910f9-0ab5-44cf-8cdc-128d5720324c@f17g2000prh.googlegroups.com> On Mar 5, 8:29?am, Mike Kent wrote: > On Mar 4, 8:04?pm, Robert Kern wrote: > > > No, the try: finally: is not implicit. See the source for > > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > > with: block, it will push it into the generator using its .throw() method. This > > raises the exception inside the generator at the yield statement. > > Wow, I just learned something new. ?My understanding of context > managers was that the __exit__ method was guaranteed to be executed > regardless of how the context was left. ?I have often written my own > context manager classes, giving them the __enter__ and __exit__ > methods. ?I had mistakenly assumed that the @contextmanager decorator > turned a generator function into a context manager with the same > behavior as the equivalent context manager class. ?Now I learn that, > no, in order to have the 'undo' code executed in the presence of an > exception, you must write your own try/finally block in the generator > function. > > This raises the question in my mind: What's the use case for using > @contextmanager rather than wrapping your code in a context manager > class that defines __enter__ and __exit__, if you still have to > manager your own try/finally block? Unless I am misunderstanding the question, the use case is that you still only have to write the context manager once, and you might get multiple uses out of it where the with-enclosed code blocks work at a higher level of abstraction. I actually don't use @contextmanager yet, mainly because I did not know it existed until recently, but also because I find the __enter__/ __exit__ paradigm straightforward enough to just hand code them that way. From pruebauno at latinmail.com Fri Mar 5 11:41:24 2010 From: pruebauno at latinmail.com (nn) Date: Fri, 5 Mar 2010 08:41:24 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <7a1d6fe9-d2c8-4c7e-8173-1e6b4d010f6a@g26g2000yqn.googlegroups.com> mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > 'Interface', > > 'Gi9/6', > > 'Po2', > > 'Po3', > > 'Po306', > > 'VLAN4068', > > 'Interface', > > 'Gi9/6', > > 'VLAN4069', > > 'Interface', > > 'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > > # alist = list above > > tmp, dk = [], {} > [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or > (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) for x in alist > if x != 'Interface'] > > No need to use a nuke like itertools to kill a fly. ;-) > > Regards, > mk Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) [(dk.setdefault(x,[]) or tmp.append(x)) if x.startswith('VLAN') else dk[tmp[-1]].append(x) for x in alist if x != 'Interface'] From showell30 at yahoo.com Fri Mar 5 11:49:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 5 Mar 2010 08:49:41 -0800 (PST) Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On Mar 4, 5:04?pm, Robert Kern wrote: > On 2010-03-04 15:19 PM, Mike Kent wrote: > > > > > On Mar 3, 12:00 pm, Robert Kern ?wrote: > >> On 2010-03-03 09:39 AM, Mike Kent wrote: > > >>> What's the compelling use case for this vs. a simple try/finally? > > >>> ? ? ?original_dir = os.getcwd() > >>> ? ? ?try: > >>> ? ? ? ? ?os.chdir(somewhere) > >>> ? ? ? ? ?# Do other stuff > >>> ? ? ?finally: > >>> ? ? ? ? ?os.chdir(original_dir) > >>> ? ? ? ? ?# Do other cleanup > > >> A custom-written context manager looks nicer and can be more readable. > > >> from contextlib import contextmanager > >> import os > > >> @contextmanager > >> def pushd(path): > >> ? ? ? original_dir = os.getcwd() > >> ? ? ? os.chdir(path) > >> ? ? ? try: > >> ? ? ? ? ? yield > >> ? ? ? finally: > >> ? ? ? ? ? os.chdir(original_dir) > > >> with pushd(somewhere): > >> ? ? ? ... > > > Robert, I like the way you think. ?That's a perfect name for that > > context manager! ?However, you can clear one thing up for me... isn't > > the inner try/finally superfluous? ?My understanding was that there > > was an implicit try/finally already done which will insure that > > everything after the yield statement was always executed. > > No, the try: finally: is not implicit. See the source for > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > with: block, it will push it into the generator using its .throw() method. This > raises the exception inside the generator at the yield statement. > See also: http://docs.python.org/library/contextlib.html The closing() helper can be used to automatically call thing.close() even after an exception. If you do not use the closing() helper and take on the responsibility yourself of doing try/finally within your generator, I think you still gain some overall simplicity: 1) You don't need to do try/finally in your with blocks, of course. 2) The generator itself probably reads more straightforwardly then a hand-coded class with __enter__ and __exit__. For point #2, I think there are probably different aesthetics. Generators are more concise, but they are also a bit mind-bending. From tjreedy at udel.edu Fri Mar 5 11:57:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 11:57:13 -0500 Subject: Generic singleton In-Reply-To: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 3/4/2010 10:32 PM, Steven D'Aprano wrote: > Python does have it's own singletons, like None, True and False. True and False are not singletons. > For some reason, they behave quite differently: Because they are quite different. > NoneType fails if you try to instantiate it again, Because trying 'type(None)()' was probably judged to be more likely to be a bug than something useful. > while bool returns the appropriate existing singleton: [sic] Branching on boolean values (which are no more singletons than 0, 1, ...) is basic to computing. > I wonder why NoneType doesn't just return None? What would you have NoneType(x) do? Or the special case NoneType(None)? The issue has come up as to whether object(x) should ignore or raise. In 3.x, it raises. TypeError: object.__new__() takes no parameters but I believe this is changed from at least some 2.x versions that ignored (apparently by 'accident'). Terry Jan Reedy From robert.kern at gmail.com Fri Mar 5 12:00:22 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 11:00:22 -0600 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: On 2010-03-05 10:29 AM, Mike Kent wrote: > On Mar 4, 8:04 pm, Robert Kern wrote: > >> No, the try: finally: is not implicit. See the source for >> contextlib.GeneratorContextManager. When __exit__() gets an exception from the >> with: block, it will push it into the generator using its .throw() method. This >> raises the exception inside the generator at the yield statement. > > Wow, I just learned something new. My understanding of context > managers was that the __exit__ method was guaranteed to be executed > regardless of how the context was left. It is. @contextmanager turns a specially-written generator into a context manager with an __exit__ that does different things depending on whether or not and exception was raised. By pushing the exception into the generator, it lets the author decide what to do. It may catch a subset of exceptions, or no exceptions, or use a finally:. They all have use cases although finally: is the usual one. > I have often written my own > context manager classes, giving them the __enter__ and __exit__ > methods. I had mistakenly assumed that the @contextmanager decorator > turned a generator function into a context manager with the same > behavior as the equivalent context manager class. Basically, it does. __exit__() is given the exception information. When you write such a class, you can decide what to do with the exception. You can silence it, immediately reraise it, conditionally reraise it, log it and then reraise it, etc. Pushing the exception into the generator keeps this flexibility and the equivalence. If it removed that choice, then it would not be equivalent. > Now I learn that, > no, in order to have the 'undo' code executed in the presence of an > exception, you must write your own try/finally block in the generator > function. > > This raises the question in my mind: What's the use case for using > @contextmanager rather than wrapping your code in a context manager > class that defines __enter__ and __exit__, if you still have to > manager your own try/finally block? The @contextmanager generator implementations are often shorter and easier to read, in my opinion, partly because they use the try: finally: syntax that most of us are very familiar with. I have to think less when I read it because it looks so similar to the equivalent code that you would normally write. The point of context managers isn't to remove the use of try: finally: entirely, but to implement it once so that it can be reused cleanly. You only have to write the one try: finally: in the generator and reuse it simply with the with: statement in many places. -- 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 From lbolla at gmail.com Fri Mar 5 12:09:08 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 5 Mar 2010 09:09:08 -0800 (PST) Subject: loop over list and process into groups References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> Message-ID: <8de6ccfb-c096-4f16-ad99-1bce5dfb12d0@j27g2000yqn.googlegroups.com> On Mar 5, 1:26?pm, mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > ?'Interface', > > ?'Gi9/6', > > ?'Po2', > > ?'Po3', > > ?'Po306', > > ?'VLAN4068', > > ?'Interface', > > ?'Gi9/6', > > ?'VLAN4069', > > ?'Interface', > > ?'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > > # alist = list above > > tmp, dk = [], {} > [(x.startswith('VLAN') and (dk.setdefault(x,[]) or tmp.append(x))) or > (not x.startswith('VLAN') and dk[tmp[-1]].append(x)) ? ?for x in alist > if x != 'Interface'] > > No need to use a nuke like itertools to kill a fly. ;-) > > Regards, > mk It looks like Perl ;-) From mrkafk at gmail.com Fri Mar 5 12:10:54 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 18:10:54 +0100 Subject: loop over list and process into groups In-Reply-To: <7a1d6fe9-d2c8-4c7e-8173-1e6b4d010f6a@g26g2000yqn.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <7a1d6fe9-d2c8-4c7e-8173-1e6b4d010f6a@g26g2000yqn.googlegroups.com> Message-ID: nn wrote: > Oh my! You could have at least used some "if else" to make it a little > bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk From mrkafk at gmail.com Fri Mar 5 12:14:16 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 18:14:16 +0100 Subject: isinstance(False, int) Message-ID: >>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Regards, mk From mrkafk at gmail.com Fri Mar 5 12:16:12 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 18:16:12 +0100 Subject: loop over list and process into groups In-Reply-To: <8de6ccfb-c096-4f16-ad99-1bce5dfb12d0@j27g2000yqn.googlegroups.com> References: <3e1272ac-aed5-44a4-b40e-fc6dec350a77@k17g2000yqb.googlegroups.com> <8de6ccfb-c096-4f16-ad99-1bce5dfb12d0@j27g2000yqn.googlegroups.com> Message-ID: lbolla wrote: > It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regards, mk From tjreedy at udel.edu Fri Mar 5 12:17:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 12:17:43 -0500 Subject: comparing two lists In-Reply-To: References: Message-ID: On 3/5/2010 3:05 AM, jimgardener wrote: > hi > I have two lists of names.I need to find the difference between these > two lists.I tried to do it using sets.But I am wondering if there is a > better way to do it.Please tell me if there is a more elegant way. > thanks, > jim > > my code snippet follows.. > > oldlst=['jon','arya','ned','bran'] > newlst=['jaime','jon','cersei'] > > newlyadded=set(newlst)-set(oldlst) > removed=set(oldlst)-set(newlst) > unchanged=set(oldlst)& set(newlst) Except for the duplicate calls to set, this is fine. If order and duplication are irrelevant (and hashability is guaranteed), use sets to start with. > print '%d were newly added= %s'%(len(newlyadded),list(newlyadded)) > print '%d were removed=%s'%(len(removed),list(removed)) > print '%d were unchanged=%s'%(len(unchanged),list(unchanged)) > > this produces the output > -------------- > 2 were newly added= ['jaime', 'cersei'] > 3 were removed=['ned', 'arya', 'bran'] > 1 were unchanged=['jon'] From tjreedy at udel.edu Fri Mar 5 12:26:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 12:26:00 -0500 Subject: ImportError: No module named glib In-Reply-To: <7c857e8c1003050030x39b75c98veace4ef8eebe606a@mail.gmail.com> References: <7c857e8c1003050030x39b75c98veace4ef8eebe606a@mail.gmail.com> Message-ID: On 3/5/2010 3:30 AM, Michael Joachimiak wrote: > I am too new to python. > If anybody has an idea what to do please help. > when I use > > import glib > > in my code I get this: > >>>> import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib glib is not in Python's stdlib so it must be loaded somewhere the interpreter can find it. Do >>> import sys >>> sys.path and see if it is in any of the listed directories. Perhaps you need to import pyglib? Terry Jan Reedy > :~$ python -V > Python 2.6.4 > > /usr/lib/libpyglib-2.0-python2.6.so.0.0.0 exists in version 2.18.0-0ubuntu2 > > :~$ pkg-config glib-2.0 --cflags --libs > -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 From kamil at lucem.pl Fri Mar 5 12:44:02 2010 From: kamil at lucem.pl (Kamil Wasilewski) Date: Fri, 5 Mar 2010 18:44:02 +0100 Subject: Escaping variable names Message-ID: <11910654174.20100305184402@lucem.pl> Hi, Ive got an issue where a variable name needs to have a minus sign (-) in it. #Python 2.6 from SOAPpy import WSDL wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl" server = WSDL.Proxy(wsdlFile) server.soapproxy.config.argsOrdering = {'doGetCountries': ['country-code', 'webapi-key'] } server.doGetCountries(country-code=COUNTRYID}, webapi-key=WEBAPIKEY) The above method allows me to specify the order and name of variables being sent, but i have a problem since the variables have a "-" sign in the middle, is there a way to escape it in the variable name or get around the problem? Thanks! From steve at holdenweb.com Fri Mar 5 13:00:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Mar 2010 13:00:09 -0500 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: mk wrote: >>>> isinstance(False, int) > True >>>> >>>> isinstance(True, int) > True > > Huh? > >>>> >>>> issubclass(bool, int) > True > > Huh?! > >>> 3+True 4 >>> 3+False 3 >>> Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it would be a good ideal for Booleans to be a subclass of integers. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:01:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:01:11 GMT Subject: Generic singleton References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4b9146e6$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: > On 3/4/2010 10:32 PM, Steven D'Aprano wrote: > >> Python does have it's own singletons, like None, True and False. > > True and False are not singletons. Duotons? Doubletons? >>> t1 = bool(1) >>> t2 = bool(1) >>> t1 is t2 True >>> t1 is t2 is bool("this is also true") is bool(['so', 'is', 'this']) True They're described as singletons in the PEP, so if you want to argue with Guido, go right ahead... *grin* http://www.python.org/dev/peps/pep-0285/ > > For some reason, they behave quite differently: > > Because they are quite different. Well, list("hello world") and list("goodbye now") are quite different too, but they behave very similarly. > > NoneType fails if you try to instantiate it again, > > Because trying 'type(None)()' was probably judged to be more likely to > be a bug than something useful. Obviously people are unlikely to write type(None)(), but they are likely to do something like: result = call_some_function(args) more_code_here() blah_blah_blah() new_obj = type(result)() do_something_with(new_obj) If result happens to end up being None, I'm not convinced that the caller would rather have an exception than get the obvious None. If result happened to be 0, wouldn't you rather get 0 than have it blow up? I don't see why None should be any different. > > while bool returns the appropriate existing singleton: [sic] > > Branching on boolean values (which are no more singletons than 0, 1, > ...) is basic to computing. What does that have to do with the price of fish? I didn't mention anything about branching on bools. Once a singleton class has been instantiated the first time, you have a choice if the user tries to instantiate it again. You can do what NoneType does, and raise an error. Or you can do what bool does, and return the existing instance. Obviously, the behaviour of bool is far more useful. So I wonder why NoneType doesn't do the same. >> I wonder why NoneType doesn't just return None? > > What would you have NoneType(x) do? The same thing any function of zero arguments does when it gets called with one argument. > Or the special case NoneType(None)? Why would that be a special case? If NoneType takes no arguments, and you supply an argument, then it is an error regardless of what that argument happens to be. -- Steven From peloko45 at gmail.com Fri Mar 5 13:01:40 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 5 Mar 2010 10:01:40 -0800 (PST) Subject: Slicing [N::-1] Message-ID: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> What does a slice as [N::-1] ? It looks that in the first it reverses the slice and then it shows only N items, right? Could you add an example to get the same result without use `::` to see it more clear? Thanks in advance From arnodel at googlemail.com Fri Mar 5 13:03:49 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Mar 2010 18:03:49 +0000 Subject: isinstance(False, int) References: Message-ID: mk writes: >>>> isinstance(False, int) > True >>>> >>>> isinstance(True, int) > True > > Huh? > >>>> >>>> issubclass(bool, int) > True > > Huh?! > > Regards, > mk Yes, and: >>> True + False 1 In fact: >>> 1 == True True >>> 0 == False True So what's your question? -- Arnaud From apt.shansen at gmail.com Fri Mar 5 13:06:15 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 5 Mar 2010 10:06:15 -0800 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <7a9c25c21003051006q571c5e45r49c47e82fe2a2f7f@mail.gmail.com> On Fri, Mar 5, 2010 at 9:14 AM, mk wrote: > >>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? > > >>> > >>> issubclass(bool, int) > True > > Huh?! > Huh, what? http://www.python.org/dev/peps/pep-0285/ --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:07:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:07:29 GMT Subject: isinstance(False, int) References: Message-ID: <4b914860$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: >>>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? Yes. Do you have an actual question? > >>> issubclass(bool, int) > True > > Huh?! Exactly. Bools are a late-comer to Python. For historical and implementation reasons, they are a subclass of int, because it was normal for people to use 0 and 1 as boolean flags, and so making False == 0 and True == 1 was the least likely to break code. E.g. back in the day, you would have something like: {2:None}.has_key(2) -> 1 So folks would do: print "The key is", ["missing", "present"][d.has_key(key)] Which still works even now that has_key returns True or False rather than 1 or 0. -- Steven From arnodel at googlemail.com Fri Mar 5 13:12:05 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Mar 2010 18:12:05 +0000 Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: Joan Miller writes: > What does a slice as [N::-1] ? > > It looks that in the first it reverses the slice and then it shows > only N items, right? > > Could you add an example to get the same result without use `::` to > see it more clear? > > Thanks in advance >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] >>> [l[i] for i in range(7, -1, -1)] [7, 6, 5, 4, 3, 2, 1, 0] -- Arnaud From jeanmichel at sequans.com Fri Mar 5 13:14:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 19:14:30 +0100 Subject: Escaping variable names In-Reply-To: <11910654174.20100305184402@lucem.pl> References: <11910654174.20100305184402@lucem.pl> Message-ID: <4B914A06.8010204@sequans.com> Kamil Wasilewski wrote: > Hi, > > Ive got an issue where a variable name needs to have a minus sign (-) in it. > > #Python 2.6 > from SOAPpy import WSDL > wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl" > server = WSDL.Proxy(wsdlFile) > server.soapproxy.config.argsOrdering = {'doGetCountries': ['country-code', 'webapi-key'] } > server.doGetCountries(country-code=COUNTRYID}, webapi-key=WEBAPIKEY) > > The above method allows me to specify the order and name of variables being sent, but i have a problem since the variables have a "-" sign in the middle, is there a way to escape it in the variable name or get around the problem? > > Thanks! > > def foo(*args, **kwargs): print kwargs['country-code'] params = {'country-code': 'hello word'} foo(**params) JM From sjdevnull at yahoo.com Fri Mar 5 13:19:37 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Fri, 5 Mar 2010 10:19:37 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Message-ID: On Mar 5, 10:53?am, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07?am, Tim Wintle wrote: > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a more python way" (I'm sure that's asking for trouble!) or > > > "people commonly do this instead" or "here's a slick trick" or "oh, > > > interesting, here's my version to do the same thing". > > > (1) I would wrap it all in a function > > > def main(): > > ? ? # your code here > > > if __name__ == "__main__": > > ? ? main() > > Is this purely aesthetic reasons, or will I appreciate this when I > write my own modules, or something else? Suppose the above code is in mymodule.py. By wrapping main() you can: 1. Have another module do: import mymodule ... (so some stuff, perhaps munge sys.argv) mymodule.main() 2. If mymodule has a small function in it, someone else can import it and call that function 3. You can run pylint, pychecker and other source-code checkers that need to be able to import your module to check it (I wouldn't be surprised if recent versions of one or the other of those don't require imports, and some checkers like pyflakes certainly don't). 4. You can easily have a unit tester call into the module etc. > > (2) PEP8 (python style guidelines) suggests one import per line > > > (3) I'd use four spaces as tab width +1 on both; it's good to get into the habit of writing standard- looking Python code. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:22:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:22:59 GMT Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: <4b914c02$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 10:01:40 -0800, Joan Miller wrote: > What does a slice as [N::-1] ? Why don't you try it? >>> s = "abcdefgh" >>> s[4::-1] 'edcba' The rules for extended slicing are not explained very well in the docs, and can be confusing. In my experience, apart from [::-1] it is best to always use a positive stride (the third number). -- Steven From darkrho at gmail.com Fri Mar 5 13:27:48 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 5 Mar 2010 14:27:48 -0400 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4eca3f41003051027nb22f3daxc418eeda3ad0a83b@mail.gmail.com> On Fri, Mar 5, 2010 at 2:00 PM, Steve Holden wrote: [...] > > Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it > would be a good ideal for Booleans to be a subclass of integers. > I would never figured out >>> bool.__bases__ (,) Doesn't have side effects not knowing that False/True are ints? Regards, Rolando From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 13:28:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 18:28:06 GMT Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: <4b914d35$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: >>>> l = range(10) >>>> l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>> l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] >>>> [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] Where does the first -1 come from? Slices are supposed to have default values of 0 and len(seq): >>> l[7::1] [7, 8, 9] >>> [l[i] for i in range(7, len(l), 1)] [7, 8, 9] >>> [l[i] for i in range(7, len(l), -1)] [] I don't believe the actual behaviour is documented anywhere. -- Steven From python at mrabarnett.plus.com Fri Mar 5 13:30:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Mar 2010 18:30:06 +0000 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4B914DAE.60209@mrabarnett.plus.com> mk wrote: > >>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? > > >>> > >>> issubclass(bool, int) > True > > Huh?! > Python didn't have Booleans originally, 0 and 1 were used instead. When bool was introduced it was made a subclass of int so that existing code wouldn't break. From mrkafk at gmail.com Fri Mar 5 13:32:32 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 19:32:32 +0100 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: >>>> 1 == True > True >>>> 0 == False > True > > So what's your question? Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, but not in Python.. Although I can understand the rationale after skimming PEP 285, I still don't like it very much. Regards, mk From anand.shashwat at gmail.com Fri Mar 5 13:33:21 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 6 Mar 2010 00:03:21 +0530 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: On Fri, Mar 5, 2010 at 11:42 PM, Arnaud Delobelle wrote: > Joan Miller writes: > > > What does a slice as [N::-1] ? > > > > It looks that in the first it reverses the slice and then it shows > > only N items, right? > > > > Could you add an example to get the same result without use `::` to > > see it more clear? > > > > Thanks in advance > > >>> l = range(10) > >>> l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] > >>> [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] > >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] >>> list(reversed(l))[-8:] [7, 6, 5, 4, 3, 2, 1, 0] ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Fri Mar 5 13:33:46 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 10:33:46 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> Message-ID: <464239a8-d78f-4d64-97ba-539f5c8cca26@g11g2000yqe.googlegroups.com> On Mar 5, 12:01?pm, Joan Miller wrote: > What does a slice as [N::-1] ? Starts at position N and returns all items to the start of the list in reverse order. > > It looks that in the first it reverses the slice and then it shows > only N items, right? Wrong. It shows N+1 items. Remember, counting starts from 0. > > Could you add an example to get the same result without use `::` to > see it more clear? for i in range(8,-1,-1):print(a[i],end=' ') although I doubt this is more clear. > > Thanks in advance From pemerson at gmail.com Fri Mar 5 13:50:31 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 10:50:31 -0800 (PST) Subject: Evaluate my first python script, please References: <86d51bc0-10ca-4168-a5a1-9bc2a33a19d7@x1g2000prb.googlegroups.com> <75a58067-9554-496b-ba38-1a3a8023d866@w27g2000pre.googlegroups.com> Message-ID: On Mar 5, 10:19?am, "sjdevn... at yahoo.com" wrote: > On Mar 5, 10:53?am, Pete Emerson wrote: > > > > > > > Thanks for your response, further questions inline. > > > On Mar 4, 11:07?am, Tim Wintle wrote: > > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > > I am looking for advice along the lines of "an easier way to do this" > > > > or "a more python way" (I'm sure that's asking for trouble!) or > > > > "people commonly do this instead" or "here's a slick trick" or "oh, > > > > interesting, here's my version to do the same thing". > > > > (1) I would wrap it all in a function > > > > def main(): > > > ? ? # your code here > > > > if __name__ == "__main__": > > > ? ? main() > > > Is this purely aesthetic reasons, or will I appreciate this when I > > write my own modules, or something else? > > Suppose the above code is in mymodule.py. ?By wrapping main() you can: > 1. Have another module do: > import mymodule > ... (so some stuff, perhaps munge sys.argv) > mymodule.main() > 2. If mymodule has a small function in it, someone else can import it > and call that function > 3. You can run pylint, pychecker and other source-code checkers that > need to be able to import your module to check it (I wouldn't be > surprised if recent versions of one or the other of those don't > require imports, and some checkers like pyflakes certainly don't). > 4. You can easily have a unit tester call into the module > > etc. > > > > (2) PEP8 (python style guidelines) suggests one import per line > > > > (3) I'd use four spaces as tab width > > +1 on both; it's good to get into the habit of writing standard- > looking Python code. Agreed, noted, and appreciated, with the caveat that using spaces instead of tabs might border on an emacs vs. vi flamewar in some circles. I personally will use spaces going forward. From mensanator at aol.com Fri Mar 5 13:52:28 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 10:52:28 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Mar 5, 12:28?pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: > >>>> l = range(10) > >>>> l > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>>> l[7::-1] > > [7, 6, 5, 4, 3, 2, 1, 0] > >>>> [l[i] for i in range(7, -1, -1)] > > [7, 6, 5, 4, 3, 2, 1, 0] > > Where does the first -1 come from? Slices are supposed to have default > values of 0 and len(seq): The only way to get a 0 from a reverse range() is to have a bound of -1. > > >>> l[7::1] > [7, 8, 9] > >>> [l[i] for i in range(7, len(l), 1)] > [7, 8, 9] > >>> [l[i] for i in range(7, len(l), -1)] > > [] > > I don't believe the actual behaviour is documented anywhere. Well, it's implied. If the stopping bound in a reverse range() is greater than the starting bound, you get an empty return. > > -- > Steven From jeanmichel at sequans.com Fri Mar 5 13:54:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Mar 2010 19:54:10 +0100 Subject: isinstance(False, int) In-Reply-To: <4b914860$0$27863$c3e8da3@news.astraweb.com> References: <4b914860$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4B915352.8010709@sequans.com> Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: > > >>>>> isinstance(False, int) >>>>> >> True >> >>> >> >>> isinstance(True, int) >> True >> >> Huh? >> > > Yes. Do you have an actual question? > > > >> >>> issubclass(bool, int) >> True >> >> Huh?! >> > > Exactly. > > Bools are a late-comer to Python. For historical and implementation > reasons, they are a subclass of int, because it was normal for people to > use 0 and 1 as boolean flags, and so making False == 0 and True == 1 was > the least likely to break code. > > E.g. back in the day, you would have something like: > > {2:None}.has_key(2) -> 1 > > So folks would do: > > print "The key is", ["missing", "present"][d.has_key(key)] > > Which still works even now that has_key returns True or False rather than > 1 or 0. > > > Despite there are good reasons for bool to be int, the newcomer 'wtf' reaction at first glance is legitimate. Starting python from scratch, booleans would have not been a subclass of int (just guessing though), 'cause it makes no sense from a design POV. Booleans are not ints, 0 does not *mean* False and veracity is not quantification. JM From darkrho at gmail.com Fri Mar 5 14:01:23 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 5 Mar 2010 15:01:23 -0400 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4eca3f41003051101q4d2c6debo1c2701d924769b31@mail.gmail.com> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: > Arnaud Delobelle wrote: > >>>>> 1 == True >> >> True >>>>> >>>>> 0 == False >> >> True >> >> So what's your question? > > Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, > but not in Python.. Although I can understand the rationale after skimming > PEP 285, I still don't like it very much. > So, the pythonic way to check for True/False should be: >>> 1 is True False >>> 0 is False False instead of ==, right? Regards, Rolando From robert.kern at gmail.com Fri Mar 5 14:10:18 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 13:10:18 -0600 Subject: Slicing [N::-1] In-Reply-To: <4b914d35$0$27863$c3e8da3@news.astraweb.com> References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 12:28 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: > >>>>> l = range(10) >>>>> l >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>>> l[7::-1] >> [7, 6, 5, 4, 3, 2, 1, 0] >>>>> [l[i] for i in range(7, -1, -1)] >> [7, 6, 5, 4, 3, 2, 1, 0] > > Where does the first -1 come from? Slices are supposed to have default > values of 0 and len(seq): Rather, they have 0 and len(seq), respectively, when the step is positive, and len(seq)-1 and -1 when the step is negative. >>>> l[7::1] > [7, 8, 9] >>>> [l[i] for i in range(7, len(l), 1)] > [7, 8, 9] >>>> [l[i] for i in range(7, len(l), -1)] > [] > > > I don't believe the actual behaviour is documented anywhere. True, I don't think it is. -- 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 From alfps at start.no Fri Mar 5 14:13:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 20:13:23 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Mike Kent: > On Mar 4, 8:04 pm, Robert Kern wrote: > >> No, the try: finally: is not implicit. See the source for >> contextlib.GeneratorContextManager. When __exit__() gets an exception from the >> with: block, it will push it into the generator using its .throw() method. This >> raises the exception inside the generator at the yield statement. > > Wow, I just learned something new. My understanding of context > managers was that the __exit__ method was guaranteed to be executed > regardless of how the context was left. I have often written my own > context manager classes, giving them the __enter__ and __exit__ > methods. I had mistakenly assumed that the @contextmanager decorator > turned a generator function into a context manager with the same > behavior as the equivalent context manager class. Now I learn that, > no, in order to have the 'undo' code executed in the presence of an > exception, you must write your own try/finally block in the generator > function. > > This raises the question in my mind: What's the use case for using > @contextmanager rather than wrapping your code in a context manager > class that defines __enter__ and __exit__, if you still have to > manager your own try/finally block? Robert Kern and Steve Howell have already given given good answers. As it happened this was news to me also, because I'm not that well-versed in Python and it seems contrary to the purpose of providing a simpler way to write a simple init-cleanup wrapper. But additionally, if you want that, then you can define it, e.g. # Py3 def simplecleanup( generator_func ): class SimpleCleanup: def __init__( self, *args, **kwargs ): self.generator = generator_func( *args, **kwargs ) def __enter__( self ): self.generator.send( None ) return self def __exit__( self, x_type, x_obj, x_traceback ): try: self.generator.send( x_obj ) # x_obj is None if no exception except StopIteration: pass # Expected return SimpleCleanup @simplecleanup def hello_goodbye( name ): print( "Hello, {}!".format( name ) ) yield print( "Goodbye {}!".format( name ) ) try: with hello_goodbye( "Mary" ): print( "Talk talk talk..." ) raise RuntimeError( "Offense" ) except: pass print() @simplecleanup def sensitive_hello_goodbye( name ): print( "Hello, {}!".format( name ) ) x = yield if x is not None: print( "Uh oh, {}!".format( x ) ) print( "Good day {}!".format( name ) ) else: print( "C u, {}!".format( name ) ) try: with sensitive_hello_goodbye( "Jane" ): print( "Talk talk talk..." ) raise RuntimeError( "Offense" ) except: pass Cheers, - Alf From wongjoekmeu at yahoo.com Fri Mar 5 14:21:32 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Fri, 5 Mar 2010 11:21:32 -0800 (PST) Subject: start function in new process Message-ID: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Hello all, I would like to run a python function completely in a new process. For example I have a parent process. That parent process needs to start a child process in which the function is called. After the child process is finished however I want that the child process should stop and then only the parent process remain. When I start the function I want to pass arguments also which include a function reference. I tried os.fork() as I need to write it in linux. However it seems like the child process remain alive. I discovered this when I loop through the function. I see that the child process continue with the loop and starts again a new grand child untill the loop is finished. See code snippet. f() is the function I want to run in a new process. It got as one of the input a refence to a function c(). Function g() I called in a loop for 3 times. Now it seems that when child process get started in the function g() it return to the loop and it calls g() itself and starts itself a nwe child process. I do not want thant. I want the child process to perform the function f() and just finished. Does anyone know how I can achieve this ? def c(): print "function c" def f(a,b, d): # function I want to run in a new child process print a, b d() def g(): pidID = os.fork() if pidID == 0: # child do something here f(2,3,c) else: # parent do something here print "Parent for i in range(3): g() From pemerson at gmail.com Fri Mar 5 14:24:44 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 11:24:44 -0800 (PST) Subject: Conditional based on whether or not a module is being used Message-ID: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? Suppose I have the following: import foo import foobar print foo() print foobar() ########### foo.py def foo: return 'foo' ########### foobar.py def foobar: if foo.has_been_loaded(): # This is not right! return foo() + 'bar' # This might need to be foo.foo() ? else: return 'bar' If someone is using foo module, I want to take advantage of its features and use it in foobar, otherwise, I want to do something else. In other words, I don't want to create a dependency of foobar on foo. My failed search for solving this makes me wonder if I'm approaching this all wrong. Thanks in advance, Pete From alfps at start.no Fri Mar 5 14:34:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Mar 2010 20:34:00 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: Message-ID: * Steve Howell: > On Mar 3, 7:10 am, "Alf P. Steinbach" wrote: >> For C++ Petru Marginean once invented the "scope guard" technique (elaborated on >> by Andrei Alexandrescu, they published an article about it in DDJ) where all you >> need to do to ensure some desired cleanup at the end of a scope, even when the >> scope is exited via an exception, is to declare a ScopeGuard w/desired action. >> >> The C++ ScopeGuard was/is for those situations where you don't have proper >> classes with automatic cleanup, which happily is seldom the case in good C++ >> code, but languages like Java and Python don't support automatic cleanup and so >> the use case for something like ScopeGuard is ever present. >> >> For use with a 'with' statement and possibly suitable 'lambda' arguments: >> >> >> class Cleanup: >> def __init__( self ): >> self._actions = [] >> >> def call( self, action ): >> assert( is_callable( action ) ) >> self._actions.append( action ) >> >> def __enter__( self ): >> return self >> >> def __exit__( self, x_type, x_value, x_traceback ): >> while( len( self._actions ) != 0 ): >> try: >> self._actions.pop()() >> except BaseException as x: >> raise AssertionError( "Cleanup: exception during cleanup" ) from >> >> >> I guess the typical usage would be what I used it for, a case where the cleanup >> action (namely, changing back to an original directory) apparently didn't fit >> the standard library's support for 'with', like >> >> with Cleanup as at_cleanup: >> # blah blah >> chdir( somewhere ) >> at_cleanup.call( lambda: chdir( original_dir ) ) >> # blah blah >> >> Another use case might be where one otherwise would get into very deep nesting >> of 'with' statements with every nested 'with' at the end, like a degenerate tree >> that for all purposes is a list. Then the above, or some variant, can help to >> /flatten/ the structure. To get rid of that silly & annoying nesting. :-) >> >> Cheers, >> >> - Alf (just sharing, it's not seriously tested code) > > Hi Alf, I think I understand the notion you're going after here. You > have multiple cleanup steps that you want to defer till the end, and > there is some possibility that things will go wrong along the way, but > you want to clean up as much as you can. And, of course, flatter is > better. > > Is this sort of what you are striving for? > > class Cleanup: > def __init__( self ): > self._actions = [] > > def call( self, action ): > self._actions.append( action ) > > def __enter__( self ): > return self > > def __exit__( self, x_type, x_value, x_traceback ): > while( len( self._actions ) != 0 ): > try: > self._actions.pop()() > except BaseException as x: > raise AssertionError( "Cleanup: exception during > cleanup" ) > > def clean_the_floor(): > print('clean the floor') > > def carouse(num_bottles, accident): > with Cleanup() as at_cleanup: > at_cleanup.call(clean_the_floor) > for i in range(num_bottles): > def take_down(i=i): > print('take one down', i) > at_cleanup.call(take_down) > if i == accident: > raise Exception('oops!') > print ('put bottle on wall', i) > > carouse(10, None) > carouse(5, 3) He he. I think you meant: > def carouse(num_bottles, accident): > with Cleanup() as at_cleanup: > at_cleanup.call(clean_the_floor) > for i in range(num_bottles): > def take_down(i=i): > print('take one down', i) > if i == accident: > raise Exception('oops!') > print ('put bottle on wall', i) > at_cleanup.call(take_down) I'm not sure. It's interesting & fun. But hey, it's Friday evening. Regarding the "clean the floor", Marginean's original ScopeGuard has a 'dismiss' method (great for e.g. implementing transactions). There's probably also much other such functionality that can be added. The original use case for Cleanup, I just posted this in case people could find it useful, was a harness for testing that C++ code /fails/ as it should, , where Cleanup is used at line 479. Some discussion of that in Usenet message and associated thread , "Unit testing of expected failures -- what do you use?" in [comp.lang.c++]. Another similar approach was discussed by Carlo Milanesi in , but he supplied this reference after I'd done the above. Mainly the difference is that he defines a custom mark-up language with corresponding source preprocessing, while I use the ordinary C++ preprocessor. There are advantages and disadvantages to both approaches. Cheers, - Alf From pemerson at gmail.com Fri Mar 5 14:39:41 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 11:39:41 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <63c618d8-3088-48fc-abbb-9eb06bb4eb54@f17g2000prh.googlegroups.com> On Mar 5, 11:24?am, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > ? ? return 'foo' > > ########### foobar.py > def foobar: > ? ? if foo.has_been_loaded(): # This is not right! > ? ? ? ? return foo() + 'bar' ? ? ?# This might need to be foo.foo() ? > ? ? else: > ? ? ? ? return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > > Thanks in advance, > Pete Aha, progress. Comments appreciated. Perhaps there's a different and more conventional way of doing it than this? def foobar(): import sys if 'foomodule' in sys.modules.keys(): import foomodule return foomodule.foo() + 'bar' else: return 'bar' From martin.hellwig at dcuktec.org Fri Mar 5 14:40:25 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 19:40:25 +0000 Subject: start function in new process In-Reply-To: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Message-ID: On 03/05/10 19:21, wongjoekmeu at yahoo.com wrote: Any specific reason why threading.Thread or multiprocessing is not suitable to solve your problem? -- mph From wongjoekmeu at yahoo.com Fri Mar 5 14:45:53 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Fri, 5 Mar 2010 11:45:53 -0800 (PST) Subject: start function in new process References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Message-ID: <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> On 5 mrt, 20:40, "Martin P. Hellwig" wrote: > On 03/05/10 19:21, wongjoek... at yahoo.com wrote: > > Any specific reason why threading.Thread or multiprocessing is not > suitable to solve your problem? > > -- > mph Because I got a memory leak in my function f(). It uses scipy, numpy, pylab, and I am not planning to solve the memory leak because its too complicated. So I thought of just calling the function then when it is finished the process is gone and all memory is released. With threading I don't think I would solve this problem. I am not sure though. From mrkafk at gmail.com Fri Mar 5 14:46:43 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 20:46:43 +0100 Subject: isinstance(False, int) In-Reply-To: <4eca3f41003051027nb22f3daxc418eeda3ad0a83b@mail.gmail.com> References: <4eca3f41003051027nb22f3daxc418eeda3ad0a83b@mail.gmail.com> Message-ID: Rolando Espinoza La Fuente wrote: > Doesn't have side effects not knowing that False/True are ints? It does, in fact I was wondering why my iterator didn't work until I figured issubclass(bool, int) is true. Regards, mk From steve at holdenweb.com Fri Mar 5 14:51:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Mar 2010 14:51:39 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > return 'foo' > > ########### foobar.py > def foobar: > if foo.has_been_loaded(): # This is not right! > return foo() + 'bar' # This might need to be foo.foo() ? > else: > return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > > Thanks in advance, > Pete One way would be if "foo" in sys.modules: # foo was imported However that won't get you all the way, since sys.modules["foo"] will be set even if the importing statement was from foo import this, that, the_other So you might want to add foo = sys.modules["foo"] inside the function. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Mar 5 14:52:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Mar 2010 14:52:46 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > By the way, the above statements are never going to work, because modules aren't callable. Maybe you want print foo.foo() print foobar.foobar() regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 14:53:43 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 19:53:43 GMT Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <4b916146$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 11:24:44 -0800, Pete Emerson wrote: > In a module, how do I create a conditional that will do something based > on whether or not another module has been loaded? try: import foo except ImportError: foo = None def function(): if foo: return foo.func() else: do_something_else() Or, alternatively: try: import foo except ImportError: import alternative_foo as foo # This better succeed! def function(): return foo.func() -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 14:54:22 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 19:54:22 GMT Subject: isinstance(False, int) References: Message-ID: <4b91616d$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >> Arnaud Delobelle wrote: >> >>>>>> 1 == True >>> >>> True >>>>>> >>>>>> 0 == False >>> >>> True >>> >>> So what's your question? >> >> Well nothing I'm just kind of bewildered: I'd expect smth like that in >> Perl, but not in Python.. Although I can understand the rationale after >> skimming PEP 285, I still don't like it very much. >> >> > So, the pythonic way to check for True/False should be: > >>>> 1 is True > False Why do you need to check for True/False? But if you need to, yes, that is one way. Another would be: isinstance(flag, bool) But generally, you can use any object as a flag without caring if it is actually True or False. -- Steven From mrkafk at gmail.com Fri Mar 5 14:55:14 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Mar 2010 20:55:14 +0100 Subject: imap vs map Message-ID: Hello everyone, I re-wrote more "slowly" an example at the end of http://wordaligned.org/articles/essential-python-reading-list This example finds anagrams in the text file. ==== from itertools import groupby, imap from operator import itemgetter from string import ascii_lowercase, ascii_uppercase, punctuation, maketrans, translate data = open(r"c:\temp\words.txt", "rt").read() trtable = maketrans(ascii_uppercase, ascii_lowercase) words = translate(data, trtable, deletions = punctuation) words = list(set(words.split())) sw = sorted(words, key=sorted) gb = groupby(sw, sorted) print map(list, imap(itemgetter(1), gb)) === words.txt: === Word Aligned three space sensitive programming Feed Logo tins Essential Python post Reading List stop course there times isnt capes === Now, when I execute above, it works: [['capes', 'space'], ['aligned'], ['reading'], ['essential'], ['programming'], ['course'], ['feed'], ['word'], ['there', 'three'], ['sensitive'], ['times'], ['logo'], ['python'], ['list'], ['isnt', 'tins'], ['stop', 'post']] However, when I change the last line to: print map(list, map(itemgetter(1), gb)) It stops working: [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ['post']] Why? I was under impression that the only difference between map and imap is that imap returns iterator allowing to produce a list, while map returns equivalent list? Regards, mk From python at mrabarnett.plus.com Fri Mar 5 14:57:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Mar 2010 19:57:34 +0000 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <4B91622E.5000208@mrabarnett.plus.com> Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > return 'foo' > > ########### foobar.py > def foobar: > if foo.has_been_loaded(): # This is not right! > return foo() + 'bar' # This might need to be foo.foo() ? > else: > return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > Look for its name in sys.modules, for example: 'foo' in sys.modules From martin.hellwig at dcuktec.org Fri Mar 5 15:02:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 20:02:34 +0000 Subject: start function in new process In-Reply-To: <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> Message-ID: On 03/05/10 19:45, wongjoekmeu at yahoo.com wrote: > On 5 mrt, 20:40, "Martin P. Hellwig" > wrote: >> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: >> >> Any specific reason why threading.Thread or multiprocessing is not >> suitable to solve your problem? >> >> -- >> mph > > Because I got a memory leak in my function f(). It uses scipy, numpy, > pylab, and I am not planning to solve the memory leak because its too > complicated. So I thought of just calling the function then when it is > finished the process is gone and all memory is released. With > threading I don't think I would solve this problem. I am not sure > though. I would be surprised if you can't do the same with subprocess/multiprocessing, since you seem to know how to identify the memory leak it shouldn't be a problem scripting out a test to see if it works this way. I would be interested though in your findings. -- mph From martin.hellwig at dcuktec.org Fri Mar 5 15:06:09 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 20:06:09 +0000 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: On 03/05/10 19:24, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. > > Thanks in advance, > Pete Hmm how about the module is available, just not imported yet, I would assume that you still would like to use the module then. Perhaps playing around with the imp module might get you what you mean instead of what you say? -- mph From wongjoekmeu at yahoo.com Fri Mar 5 15:09:39 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Fri, 5 Mar 2010 12:09:39 -0800 (PST) Subject: start function in new process References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> Message-ID: <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> On 5 mrt, 21:02, "Martin P. Hellwig" wrote: > On 03/05/10 19:45, wongjoek... at yahoo.com wrote: > > > > > On 5 mrt, 20:40, "Martin P. Hellwig" > > wrote: > >> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: > >> > >> Any specific reason why threading.Thread or multiprocessing is not > >> suitable to solve your problem? > > >> -- > >> mph > > > Because I got a memory leak in my function f(). It uses scipy, numpy, > > pylab, and I am not planning to solve the memory leak because its too > > complicated. So I thought of just calling the function then when it is > > finished the process is gone and all memory is released. With > > threading I don't think I would solve this problem. I am not sure > > though. > > I would be surprised if you can't do the same with > subprocess/multiprocessing, since you seem to know how to identify the > memory leak it shouldn't be a problem scripting out a test to see if it > works this way. I would be interested though in your findings. > > -- > mph I can't use multiprocessing module since it comes only with python 2.6 and I am bound to python2.4. But subprocess does exist in python2.4, but the question now is, how do I achieve that ? Any example ? From clp2 at rebertia.com Fri Mar 5 15:17:58 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 12:17:58 -0800 Subject: Conditional based on whether or not a module is being used In-Reply-To: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> On 3/5/10, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ########### foo.py > def foo: > return 'foo' > > ########### foobar.py > def foobar: > if foo.has_been_loaded(): # This is not right! > return foo() + 'bar' # This might need to be foo.foo() ? > else: > return 'bar' > > If someone is using foo module, I want to take advantage of its > features and use it in foobar, otherwise, I want to do something else. > In other words, I don't want to create a dependency of foobar on foo. > > My failed search for solving this makes me wonder if I'm approaching > this all wrong. Just try importing foo, and then catch the exception if it's not installed. #foobar.py try: import foo except ImportError: FOO_PRESENT = False else: FOO_PRESENT = True if FOO_PRESENT: def foobar(): return foo.foo() + 'bar' else: def foobar(): return 'bar' You could alternately do the `if FOO_PRESENT` check inside the function body rather than defining separate versions of the function. Cheers, Chris -- http://blog.rebertia.com From earnmoney9421 at gmail.com Fri Mar 5 15:20:23 2010 From: earnmoney9421 at gmail.com (Google Adsense) Date: Fri, 5 Mar 2010 12:20:23 -0800 (PST) Subject: Buy Genuine Google Adsense Account only for Rs.200/- for indian people. For more details visit http://www.buygoogleadsense.tk/ We also provide procedure for creating unlimited google adsense account trick . Message-ID: <4074fe88-d923-4383-81df-a8b22a0766a6@g28g2000yqh.googlegroups.com> Buy Genuine Google Adsense Account only for Rs.200/- for indian people. For more details visit http://www.buygoogleadsense.tk/ We also provide procedure for creating unlimited google adsense account trick . From pemerson at gmail.com Fri Mar 5 15:25:37 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 12:25:37 -0800 Subject: Conditional based on whether or not a module is being used In-Reply-To: <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> Message-ID: <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > On 3/5/10, Pete Emerson wrote: >> In a module, how do I create a conditional that will do something >> based on whether or not another module has been loaded? >> >> Suppose I have the following: >> >> import foo >> import foobar >> >> print foo() >> print foobar() >> >> ########### foo.py >> def foo: >> ? ?return 'foo' >> >> ########### foobar.py >> def foobar: >> ? ?if foo.has_been_loaded(): # This is not right! >> ? ? ? ?return foo() + 'bar' ? ? ?# This might need to be foo.foo() ? >> ? ?else: >> ? ? ? ?return 'bar' >> >> If someone is using foo module, I want to take advantage of its >> features and use it in foobar, otherwise, I want to do something else. >> In other words, I don't want to create a dependency of foobar on foo. >> >> My failed search for solving this makes me wonder if I'm approaching >> this all wrong. > > Just try importing foo, and then catch the exception if it's not installed. > > #foobar.py > try: > ? ?import foo > except ImportError: > ? ?FOO_PRESENT = False > else: > ? ?FOO_PRESENT = True > > if FOO_PRESENT: > ? ?def foobar(): > ? ? ? ?return foo.foo() + 'bar' > else: > ? ?def foobar(): > ? ? ? ?return 'bar' > > > You could alternately do the `if FOO_PRESENT` check inside the > function body rather than defining separate versions of the function. > > Cheers, > Chris > -- > http://blog.rebertia.com > Except I want to use the module only if the main program is using it too, not just if it's available for use. I think that I found a way in my follow-up post to my own message, but not sure it's the best way or conventional. Pete From pemerson at gmail.com Fri Mar 5 15:31:16 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 12:31:16 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: <9769b00a-8d85-43ed-98e9-f921dc71c217@s36g2000prh.googlegroups.com> On Mar 5, 12:06?pm, "Martin P. Hellwig" wrote: > On 03/05/10 19:24, Pete Emerson wrote: > > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > > If someone is using foo module, I want to take advantage of its > > features and use it in foobar, otherwise, I want to do something else. > > In other words, I don't want to create a dependency of foobar on foo. > > > My failed search for solving this makes me wonder if I'm approaching > > this all wrong. > > > Thanks in advance, > > Pete > > Hmm how about the module is available, just not imported yet, I would > assume that you still would like to use the module then. > Perhaps playing around with the imp module might get you what you mean > instead of what you say? > > -- > mph I can certainly see why one might want to use it if it's available but not yet imported. In that case I could do a try / exception block. But in this case, I actually don't want to use the module unless the main program is doing it too. But you've got me thinking, I need to make sure that's really the desired behavior. Pete From pemerson at gmail.com Fri Mar 5 15:31:40 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 12:31:40 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: On Mar 5, 11:57?am, MRAB wrote: > Pete Emerson wrote: > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > Suppose I have the following: > > > import foo > > import foobar > > > print foo() > > print foobar() > > > ########### foo.py > > def foo: > > ? ? return 'foo' > > > ########### foobar.py > > def foobar: > > ? ? if foo.has_been_loaded(): # This is not right! > > ? ? ? ? return foo() + 'bar' ? ? ?# This might need to be foo.foo() ? > > ? ? else: > > ? ? ? ? return 'bar' > > > If someone is using foo module, I want to take advantage of its > > features and use it in foobar, otherwise, I want to do something else. > > In other words, I don't want to create a dependency of foobar on foo. > > > My failed search for solving this makes me wonder if I'm approaching > > this all wrong. > > Look for its name in sys.modules, for example: > > ? ? ?'foo' in sys.modules Excellent, this is what I finally discovered, although I was looking for 'foo' in sys.modules.keys(), which apparently isn't necessary. From jgardner at jonathangardner.net Fri Mar 5 15:39:58 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 5 Mar 2010 12:39:58 -0800 Subject: start function in new process In-Reply-To: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> Message-ID: <6cc20cea1003051239h2983a3cbw68f54bcf547367a8@mail.gmail.com> You're really close. See inline comment below. On Fri, Mar 5, 2010 at 11:21 AM, wongjoekmeu at yahoo.com wrote: > > def c(): > ? ?print "function c" > > def f(a,b, d): > ? ?# function I want to run in a new child process > ? ?print a, b > ? ?d() > > def g(): > ? ?pidID = os.fork() > ? ?if pidID == 0: > ? ? ? ?# child do something here > ? ? ? ?f(2,3,c) You'll need to exit here -- not return. http://docs.python.org/library/os.html#os._exit > ? ?else: > ? ? ? ?# parent do something here > ? ? ? ?print "Parent > > for i in range(3): > ? ?g() > -- Jonathan Gardner jgardner at jonathangardner.net From martin.hellwig at dcuktec.org Fri Mar 5 15:40:55 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Mar 2010 20:40:55 +0000 Subject: start function in new process In-Reply-To: <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> Message-ID: On 03/05/10 20:09, wongjoekmeu at yahoo.com wrote: > On 5 mrt, 21:02, "Martin P. Hellwig" > wrote: >> On 03/05/10 19:45, wongjoek... at yahoo.com wrote: >> >> >> >>> On 5 mrt, 20:40, "Martin P. Hellwig" >>> wrote: >>>> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: >>>> >>>> Any specific reason why threading.Thread or multiprocessing is not >>>> suitable to solve your problem? >> >>>> -- >>>> mph >> >>> Because I got a memory leak in my function f(). It uses scipy, numpy, >>> pylab, and I am not planning to solve the memory leak because its too >>> complicated. So I thought of just calling the function then when it is >>> finished the process is gone and all memory is released. With >>> threading I don't think I would solve this problem. I am not sure >>> though. >> >> I would be surprised if you can't do the same with >> subprocess/multiprocessing, since you seem to know how to identify the >> memory leak it shouldn't be a problem scripting out a test to see if it >> works this way. I would be interested though in your findings. >> >> -- >> mph > > I can't use multiprocessing module since it comes only with python 2.6 > and I am bound to python2.4. But subprocess does exist in python2.4, > but the question now is, how do I achieve that ? Any example ? Sure, for example if I want to check the openssl version (didn't specify I need to provide a useful example :-) I would normally do on the command line: [martin at aspire8930 /usr/home/martin/Desktop]$ /usr/bin/openssl version OpenSSL 0.9.8k 25 Mar 2009 The python subprocess equivalent is: [martin at aspire8930 /usr/home/martin/Desktop]$ python Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess as _sp >>> ssl_version = _sp.Popen(['/usr/bin/openssl', 'version'], stdout=_sp.PIPE) >>> print(ssl_version.stdout.readlines()) ['OpenSSL 0.9.8k 25 Mar 2009\n'] >>> quit() [martin at aspire8930 /usr/home/martin/Desktop]$ If you get any error in the Popen part, you probably did not use the full path or an illegal parameter. If you get a long wait in the readlines part, this usually means that there is either nothing written to stdout or something is still being written (I am not sure about this part though, it has been a while). hth -- mph From robert.kern at gmail.com Fri Mar 5 15:49:40 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 14:49:40 -0600 Subject: start function in new process In-Reply-To: <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> Message-ID: On 2010-03-05 14:09 PM, wongjoekmeu at yahoo.com wrote: > I can't use multiprocessing module since it comes only with python 2.6 > and I am bound to python2.4. It is available as a third party package for Python 2.4: http://pypi.python.org/pypi/multiprocessing -- 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 From jackdied at gmail.com Fri Mar 5 15:58:01 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 5 Mar 2010 15:58:01 -0500 Subject: isinstance(False, int) In-Reply-To: <4b91616d$0$27863$c3e8da3@news.astraweb.com> References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > >> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >>> Arnaud Delobelle wrote: >>> >>>>>>> 1 == True >>>> >>>> True >>>>>>> >>>>>>> 0 == False >>>> >>>> True >>>> >>>> So what's your question? >>> >>> Well nothing I'm just kind of bewildered: I'd expect smth like that in >>> Perl, but not in Python.. Although I can understand the rationale after >>> skimming PEP 285, I still don't like it very much. >>> >>> >> So, the pythonic way to check for True/False should be: >> >>>>> 1 is True >> False > > Why do you need to check for True/False? > You should never check for "is" False/True but always check for equality. The reason is that many types support the equality (__eq__) and boolen (__bool__ in 3x) protocols. If you check equality these will be invoked, if you check identity ("is") they won't. -Jack From info at wingware.com Fri Mar 5 16:00:48 2010 From: info at wingware.com (Wingware) Date: Fri, 05 Mar 2010 16:00:48 -0500 Subject: ANN: Wing IDE 3.2.5 Released Message-ID: <4B917100.9000401@wingware.com> Hi, Wingware has released version 3.2.5 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional code editor with vi, emacs, and other configurable key bindings, auto-completion, call tips, a powerful graphical debugger, integrated version control and unit testing, search, and many other features. The IDE runs on Windows, Linux, and OS X and can be used to develop Python code for web, GUI, and embedded scripting applications. This release includes the following minor features and improvements: * Several vi and brief keyboard mode fixes (see change log for details) * Support recent git versions * Fixed output buffering on OS X for debug process and in OS Commands * Fixed debugger support for Stackless 3.0 and 3.1 * Improve input() handling and other debugger support for Python 3.x * Iterator support for sys.stdin * Avoid losing focus on Debug Probe when stepping in debugger * Fix potential for crashing debug process on certain file names * Don't crash when copying non-ascii text in OS command output * Added delete, duplicate, and swap line operations to Source menu * Added rename-current-file command * Many other minor features and bug fixes; See the change log at http://wingware.com/pub/wingide/3.2.5/CHANGELOG.txt for details *Wing 3.2 Highlights* Versions 3.2.x of Wing IDE include the following new features not present in version 3.1: * Support for Python 3.0 and 3.1 * Rewritten version control integration with support for Subversion, CVS, Bazaar, git, Mercurial, and Perforce (*) * Added 64-bit Debian, RPM, and tar file installers for Linux * File management in Project view (**) * Auto-completion in the editor obtains completion data from live runtime when the debugger is active (**) * Perspectives: Create and save named GUI layouts and optionally automatically transition when debugging is started (*) * Improved support for Cython and Pyrex (*.pyx files) * Added key binding documentation to the manual * Added Restart Debugging item in Debug menu and tool bar (**) * Improved OS Commands and Bookmarks tools (*) * Support for debugging 64-bit Python on OS X (*)'d items are available in Wing IDE Professional only. (**)'d items are available in Wing IDE Personal and Professional only. The release also contains many other minor features and bug fixes; see the change log for details: http://wingware.com/pub/wingide/3.2.5/CHANGELOG.txt *Downloads* Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial license can be obtained directly from the product when launched. Wing IDE 101 can be used free of charge. Wing IDE Pro 3.2.5 http://wingware.com/downloads/wingide/3.2 Wing IDE Personal 3.2.5 http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 3.2.5 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment for the Python programming language. It provides powerful debugging, editing, code intelligence, testing, version control, and search capabilities that reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE 3.2 supports Python versions 2.0.x through 3.1.x. *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Version 2.x licenses cost 1/2 the normal price to upgrade. Upgrade a 2.x license: https://wingware.com/store/upgrade Purchase a 3.x license: https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From clp2 at rebertia.com Fri Mar 5 16:14:53 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 13:14:53 -0800 Subject: Conditional based on whether or not a module is being used In-Reply-To: <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: <50697b2c1003051314p6d69eb41hbc407f7cf7e8866@mail.gmail.com> On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: >> On 3/5/10, Pete Emerson wrote: >>> In a module, how do I create a conditional that will do something >>> based on whether or not another module has been loaded? >>> If someone is using foo module, I want to take advantage of its >>> features and use it in foobar, otherwise, I want to do something else. >>> In other words, I don't want to create a dependency of foobar on foo. >>> >>> My failed search for solving this makes me wonder if I'm approaching >>> this all wrong. >> >> Just try importing foo, and then catch the exception if it's not installed. > Except I want to use the module only if the main program is using it > too, not just if it's available for use. I think that I found a way in > my follow-up post to my own message, but not sure it's the best way or > conventional. What is your use case for this behavior exactly? You've piqued my curiosity. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Fri Mar 5 16:25:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:25:46 -0500 Subject: Generic singleton In-Reply-To: <4b9146e6$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 3/5/2010 1:01 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: > >> On 3/4/2010 10:32 PM, Steven D'Aprano wrote: >> >>> Python does have it's own singletons, like None, True and False. >> >> True and False are not singletons. > > Duotons? Doubletons? The latter is what I use. > >>>> t1 = bool(1) >>>> t2 = bool(1) >>>> t1 is t2 > True >>>> t1 is t2 is bool("this is also true") is bool(['so', 'is', 'this']) > True > > They're described as singletons in the PEP, so if you want to argue with > Guido, go right ahead... *grin* > http://www.python.org/dev/peps/pep-0285/ Guido already made the argument ;-) when he followed 'The values False and True will be singletons, like None.' with 'Because the type has two values, perhaps these should be called "doubletons"? '. I agree with him here. By 'singleton', I believe he meant 'keyword constants' with guaranteed 'isness'. Ie, "True is True' and 'False is False', like 'None is None', are guaranteed in the language def to be true (True) whereas '0 is 0' and "'' is ''" and '() is ()' are not, even if they happen to be in a particular implementation. None of this determine the behavior of the respective null and boolean classes. If Python had the strict bools that some wanted, bool(x) would not be legal. >> > For some reason, they behave quite differently: >> >> Because they are quite different. > > Well, list("hello world") and list("goodbye now") are quite different > too, but they behave very similarly. > > >> > NoneType fails if you try to instantiate it again, >> >> Because trying 'type(None)()' was probably judged to be more likely to >> be a bug than something useful. > Obviously people are unlikely to write type(None)(), but they are likely > to do something like: > > result = call_some_function(args) > more_code_here() > blah_blah_blah() > new_obj = type(result)() > do_something_with(new_obj) > > If result happens to end up being None, I'm not convinced that the caller > would rather have an exception than get the obvious None. If result > happened to be 0, wouldn't you rather get 0 than have it blow up? I don't > see why None should be any different. This is your strongest argument. It has nothing to do in particular with (the dubious analogy with) bool. Here is a draft of what you might post to python-ideas list, or even the tracker. " Make type(None) return None The built-in classes of CPython nearly all follow the (undocumented?) design rule that if class C has a null instance, C() returns that (usually unique) null (False) instance. Hence, for instance, one can write nulls = [type(x)() for x in obs] to map the objects in obs to their null counterparts. This works for object of at least the following classes: bool, int, float, complex, str, bytes, bytearray, tuple, list, set, frozenset, dict, decimal.Decimal, fractions.Fraction, collections.deque, and collections.defaultdict. The one glaring exception is type(None), which raises a TypeError instead of returning the null value None. This anomaly could be easily corrected, and the rule documented in, for instance, Lib Ref 5.1. Truth Value Testing. Possible objection 1: None is a special singleton. Answer 1: False is special too, and 'bool() is False' is true. Possible objection 2: code that depends on no return would break. Answer 2: at least one other class was changed during the 2.x series to conform to the rule. (xxx which?) " I am pretty sure other classes *were* changed, but cannot specifically remember which. I would look a bit at the tracker and archives for any negative pronouncements between posting. >> > while bool returns the appropriate existing singleton: [sic] >> >> Branching on boolean values (which are no more singletons than 0, 1, >> ...) is basic to computing. > > What does that have to do with the price of fish? I didn't mention > anything about branching on bools. Every use of 'if', 'and', and 'or' implicitly calls bool, and people often call it explicitly. There is almost no use case, other than such as the above, for calling the type of None. > Once a singleton class has been instantiated the first time, you have a > choice if the user tries to instantiate it again. You can do what > NoneType does, and raise an error. Or you can do what bool does, and > return the existing instance. > > Obviously, the behaviour of bool is far more useful. The behavior of bool is necessary. > So I wonder why NoneType doesn't do the same. It predated bool by at least a decade. The choice was pretty inconsequential, especially then, either way. >>> I wonder why NoneType doesn't just return None? >> >> What would you have NoneType(x) do? > > The same thing any function of zero arguments does when it gets called > with one argument. > >> Or the special case NoneType(None)? > > Why would that be a special case? If NoneType takes no arguments, and you > supply an argument, then it is an error regardless of what that argument > happens to be. I agree. I asked because there were objections to correcting object(x) to raise instead of ignore. Terry Jan Reedy From tjreedy at udel.edu Fri Mar 5 16:27:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:27:56 -0500 Subject: isinstance(False, int) In-Reply-To: <4B914DAE.60209@mrabarnett.plus.com> References: <4B914DAE.60209@mrabarnett.plus.com> Message-ID: On 3/5/2010 1:30 PM, MRAB wrote: > mk wrote: >> >>> isinstance(False, int) >> True >> >>> >> >>> isinstance(True, int) >> True >> >> Huh? >> >> >>> >> >>> issubclass(bool, int) >> True >> >> Huh?! >> > Python didn't have Booleans originally, 0 and 1 were used instead. When > bool was introduced it was made a subclass of int so that existing code > wouldn't break. And because it is useful to make it so. Terry Jan Reedy From pemerson at gmail.com Fri Mar 5 16:29:48 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 13:29:48 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: On Mar 5, 1:14?pm, Chris Rebert wrote: > On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > >> On 3/5/10, Pete Emerson wrote: > >>> In a module, how do I create a conditional that will do something > >>> based on whether or not another module has been loaded? > > >>> If someone is using foo module, I want to take advantage of its > >>> features and use it in foobar, otherwise, I want to do something else. > >>> In other words, I don't want to create a dependency of foobar on foo. > > >>> My failed search for solving this makes me wonder if I'm approaching > >>> this all wrong. > > >> Just try importing foo, and then catch the exception if it's not installed. > > > Except I want to use the module only if the main program is using it > > too, not just if it's available for use. I think that I found a way in > > my follow-up post to my own message, but not sure it's the best way or > > conventional. > > What is your use case for this behavior exactly? You've piqued my curiosity. > > Cheers, > Chris > --http://blog.rebertia.com I have written my first module called "logger" that logs to syslog via the syslog module but also allows for logging to STDOUT in debug mode at multiple levels (to increase verbosity depending on one's need), or both. I've looked at the logging module and while it might suit my needs, it's overkill for me right now (I'm still *very* much a python newbie). I want to write other modules, and my thinking is that it makes sense for those modules to use the "logger" module to do the logging, if and only if the parent using the other modules is also using the logger module. In other words, I don't want to force someone to use the "logger" module just so they can use my other modules, even if the "logger" module is installed ... but I also want to take advantage of it if I'm using it. Now that I've written that, I'm not sure that makes a whole lot of sense. It seems like I could say, "hey, this person has the 'logger' module available, let's use it!". Thoughts? From p.c.j.kleiweg at rug.nl Fri Mar 5 16:34:00 2010 From: p.c.j.kleiweg at rug.nl (Peter Kleiweg) Date: Fri, 5 Mar 2010 22:34:00 +0100 Subject: How to send utf-8 mail in Python 3? Message-ID: I try to send e-mail from Python 3.1.1 Encoding as iso-8859-1 goes fine. But encoding as utf-8 doesn't work. What am I doing wrong? Python 3.1.1 (r311:74480, Oct 2 2009, 11:50:52) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from email.mime.text import MIMEText >>> text = 'H\u00e9' >>> msg = MIMEText(text, 'plain', 'iso-8859-1') >>> print(msg.as_string()) Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable H=E9 >>> msg = MIMEText(text, 'plain', 'utf-8') Traceback (most recent call last): File "/my/opt/Python-3/lib/python3.1/email/message.py", line 269, in set_charset cte(self) TypeError: 'str' object is not callable During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/my/opt/Python-3/lib/python3.1/email/mime/text.py", line 30, in __init__ self.set_payload(_text, _charset) File "/my/opt/Python-3/lib/python3.1/email/message.py", line 234, in set_payload self.set_charset(charset) File "/my/opt/Python-3/lib/python3.1/email/message.py", line 271, in set_charset self._payload = charset.body_encode(self._payload) File "/my/opt/Python-3/lib/python3.1/email/charset.py", line 380, in body_encode return email.base64mime.body_encode(string) File "/my/opt/Python-3/lib/python3.1/email/base64mime.py", line 94, in body_encode enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii") TypeError: must be bytes or buffer, not str >>> -- Peter Kleiweg From gherron at islandtraining.com Fri Mar 5 16:42:01 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Mar 2010 13:42:01 -0800 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4B917AA9.7070207@islandtraining.com> Mensanator wrote: > On Mar 5, 12:28 pm, Steven D'Aprano cybersource.com.au> wrote: > >> On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: >> >>>>>> l = range(10) >>>>>> l >>>>>> >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> >>>>>> l[7::-1] >>>>>> >>> [7, 6, 5, 4, 3, 2, 1, 0] >>> >>>>>> [l[i] for i in range(7, -1, -1)] >>>>>> >>> [7, 6, 5, 4, 3, 2, 1, 0] >>> >> Where does the first -1 come from? Slices are supposed to have default >> values of 0 and len(seq): >> > > The only way to get a 0 from a reverse range() is to have a bound of > -1. > Not quite. An empty second bound goes all the way to the zero index: >>> range(9)[2::-1] [2, 1, 0] Gary Herron > >>>>> l[7::1] >>>>> >> [7, 8, 9] >> >>>>> [l[i] for i in range(7, len(l), 1)] >>>>> >> [7, 8, 9] >> >>>>> [l[i] for i in range(7, len(l), -1)] >>>>> >> [] >> >> I don't believe the actual behaviour is documented anywhere. >> > > Well, it's implied. If the stopping bound in a reverse range() > is greater than the starting bound, you get an empty return. > > >> -- >> Steven >> > > From nyamatongwe+thunder at gmail.com Fri Mar 5 16:45:54 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Fri, 05 Mar 2010 21:45:54 GMT Subject: Passing FILE * types using ctypes In-Reply-To: References: Message-ID: Zeeshan Quireshi: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. For this to work, your library should have been compiled with the same compiler as Python and possibly the same compiler options such as choice of runtime library. Otherwise, they may differ in the content and layout of FILE and also in behaviour. On Unix, this may not be a problem because of the shared runtime but on Windows it can cause crashes. Neil From tjreedy at udel.edu Fri Mar 5 16:46:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:46:23 -0500 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 3/5/2010 2:10 PM, Robert Kern wrote: > Rather, they have 0 and len(seq), respectively, when the step is > positive, and len(seq)-1 and -1 when the step is negative. >> I don't believe the actual behaviour is documented anywhere. > > True, I don't think it is. There are at least two open issues. http://bugs.python.org/issue1446619 http://bugs.python.org/issue7460 From tjreedy at udel.edu Fri Mar 5 16:51:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 16:51:25 -0500 Subject: isinstance(False, int) In-Reply-To: <4B915352.8010709@sequans.com> References: <4b914860$0$27863$c3e8da3@news.astraweb.com> <4B915352.8010709@sequans.com> Message-ID: On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote: > Steven D'Aprano wrote: > Despite there are good reasons for bool to be int, the newcomer 'wtf' > reaction at first glance is legitimate. > Starting python from scratch, booleans would have not been a subclass of > int (just guessing though), 'cause it makes no sense from a design POV. You are just guessing. I would argue for what we have. An example of its usefulness: >>> scores =[True, False, True, True, False] >>> score = sum(scores) >>> score 3 Bools are also usefully used as sequence indexes. Terry Jan Reedy From arnodel at googlemail.com Fri Mar 5 17:00:16 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Mar 2010 22:00:16 +0000 Subject: imap vs map References: Message-ID: mk writes: > Hello everyone, > > I re-wrote more "slowly" an example at the end of > http://wordaligned.org/articles/essential-python-reading-list > > > This example finds anagrams in the text file. > > ==== > from itertools import groupby, imap > from operator import itemgetter > > from string import ascii_lowercase, ascii_uppercase, punctuation, > maketrans, translate > > data = open(r"c:\temp\words.txt", "rt").read() > > trtable = maketrans(ascii_uppercase, ascii_lowercase) > > words = translate(data, trtable, deletions = punctuation) > > words = list(set(words.split())) > > sw = sorted(words, key=sorted) > > gb = groupby(sw, sorted) > > print map(list, imap(itemgetter(1), gb)) > === > > words.txt: > === > Word Aligned > three > space sensitive programming > Feed Logo tins > Essential Python post Reading List > stop course there > times isnt > capes > === > > Now, when I execute above, it works: > > [['capes', 'space'], ['aligned'], ['reading'], ['essential'], > ['programming'], ['course'], ['feed'], ['word'], ['there', 'three'], > ['sensitive'], ['times'], ['logo'], ['python'], ['list'], ['isnt', > tins'], ['stop', 'post']] > > > However, when I change the last line to: > > print map(list, map(itemgetter(1), gb)) > > It stops working: > > [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], ['post']] > > Why? I was under impression that the only difference between map and > imap is that imap returns iterator allowing to produce a list, while > map returns equivalent list? > > Regards, > mk >From the itertools docs [1]: The returned group is itself an iterator that shares the underlying iterable with groupby(). Because the source is shared, when the groupby() object is advanced, the previous group is no longer visible. So, if that data is needed later, it should be stored as a list: (example follows) So when you use: print map(list, imap(itemgetter(1), gb)) each group is stored as a list *before* the groupby() object is advanced, so that's ok. However, when you use: print map(list, map(itemgetter(1), gb)) the groupby() object is advanced to the end *before* each group is stored as a list. According the the docs quoted above, this renders each group no longer visible. It is for the same reason that the following are different: >>> def foo(): ... for i in range(5): ... yield lambda: i ... >>> map(lambda f: f(), imap(lambda x: x, foo())) [0, 1, 2, 3, 4] >>> map(lambda f: f(), map(lambda x: x, foo())) [4, 4, 4, 4, 4] Although looking back at it, I don't know if this will help you :) [1] http://docs.python.org/library/itertools.html#itertools.groupby -- Arnaud From robert.kern at gmail.com Fri Mar 5 17:09:17 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 16:09:17 -0600 Subject: isinstance(False, int) In-Reply-To: References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 14:58 PM, Jack Diederich wrote: > On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano > wrote: >> On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: >> >>> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >>>> Arnaud Delobelle wrote: >>>> >>>>>>>> 1 == True >>>>> >>>>> True >>>>>>>> >>>>>>>> 0 == False >>>>> >>>>> True >>>>> >>>>> So what's your question? >>>> >>>> Well nothing I'm just kind of bewildered: I'd expect smth like that in >>>> Perl, but not in Python.. Although I can understand the rationale after >>>> skimming PEP 285, I still don't like it very much. >>>> >>>> >>> So, the pythonic way to check for True/False should be: >>> >>>>>> 1 is True >>> False >> >> Why do you need to check for True/False? >> > > You should never check for "is" False/True but always check for > equality. The reason is that many types support the equality (__eq__) > and boolen (__bool__ in 3x) protocols. If you check equality these > will be invoked, if you check identity ("is") they won't. It depends on what you're doing. mk seems to want to distinguish booleans from other objects from some reason. -- 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 From robert.kern at gmail.com Fri Mar 5 17:12:39 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 16:12:39 -0600 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 13:10 PM, Robert Kern wrote: > On 2010-03-05 12:28 PM, Steven D'Aprano wrote: >> On Fri, 05 Mar 2010 18:12:05 +0000, Arnaud Delobelle wrote: >> >>>>>> l = range(10) >>>>>> l >>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>>>> l[7::-1] >>> [7, 6, 5, 4, 3, 2, 1, 0] >>>>>> [l[i] for i in range(7, -1, -1)] >>> [7, 6, 5, 4, 3, 2, 1, 0] >> >> Where does the first -1 come from? Slices are supposed to have default >> values of 0 and len(seq): > > Rather, they have 0 and len(seq), respectively, when the step is > positive, and len(seq)-1 and -1 when the step is negative. Well, not entirely true. [N:-1:-1] obviously doesn't work for this. Rather, leaving the second argument in the slice empty means "go to the end if step > 0 or go to the beginning if step < 0". There is no explicit translation of the latter because there is no numerical index for the element before the first element. -- 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 From tjreedy at udel.edu Fri Mar 5 17:16:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 05 Mar 2010 17:16:00 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: On 3/5/2010 4:29 PM, Pete Emerson wrote: > On Mar 5, 1:14 pm, Chris Rebert wrote: > I want to write other modules, and my thinking is that it makes sense > for those modules to use the "logger" module to do the logging, if and > only if the parent using the other modules is also using the logger > module. > > In other words, I don't want to force someone to use the "logger" > module just so they can use my other modules, even if the "logger" > module is installed ... but I also want to take advantage of it if I'm > using it. > > Now that I've written that, I'm not sure that makes a whole lot of > sense. It seems like I could say, "hey, this person has the 'logger' > module available, let's use it!". Except in unusual cases, where merely importing a modules uses substantial resources, I would say that if it is available, use it. From aahz at pythoncraft.com Fri Mar 5 17:45:34 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Mar 2010 14:45:34 -0800 Subject: Draft PEP on RSON configuration file format References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274 <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Message-ID: In article <7xwrxv4vv7.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > >ReST is another abomination that should never have gotten off the >ground. It is one of the reasons I react so negatively to your >config format proposal. It just sounds like more of the same. Really? What should we use instead of reST? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 18:07:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 23:07:52 GMT Subject: Generic singleton References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4b918ec8$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 16:25:46 -0500, Terry Reedy wrote: > On 3/5/2010 1:01 PM, Steven D'Aprano wrote: >> On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: >> >>> On 3/4/2010 10:32 PM, Steven D'Aprano wrote: >>> >>>> Python does have it's own singletons, like None, True and False. >>> >>> True and False are not singletons. >> >> Duotons? Doubletons? > > The latter is what I use. The Wikipedia article on Singleton states that it is acceptable to generalise "Singleton" to allow multiple instances. http://en.wikipedia.org/wiki/Singleton_pattern While Doubleton or even Tripleton sound cute, once you get to large counts it all starts getting ugly and horrible. "Polyton"? Blah. [...] > This is your strongest argument. It has nothing to do in particular with > (the dubious analogy with) bool. Here is a draft of what you might post > to python-ideas list, or even the tracker. Oh, you have misunderstood me. I'm not particularly concerned about NoneType's behaviour, and certainly not concerned enough to champion the change against any opposition (let alone through the moratorium!). I wanted to understand why the difference existed. Python has at least two other singletons, Ellipsis and NotImplemented, and both behave like None. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 18:09:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Mar 2010 23:09:58 GMT Subject: isinstance(False, int) References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4b918f46$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: >>> So, the pythonic way to check for True/False should be: >>> >>>>>> 1 is True >>> False >> >> Why do you need to check for True/False? >> >> > You should never check for "is" False/True but always check for > equality. The reason is that many types support the equality (__eq__) > and boolen (__bool__ in 3x) protocols. If you check equality these will > be invoked, if you check identity ("is") they won't. Never say never. If you specifically want to test for True or False themselves, accepting no substitutes, then using "is" is the obvious way, and using "==" is clearly and obviously wrong because it does accept substitutes: >>> 1.0 == True True >>> decimal.Decimal(0, 1) == False True -- Steven From jackdied at gmail.com Fri Mar 5 18:48:39 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 5 Mar 2010 18:48:39 -0500 Subject: isinstance(False, int) In-Reply-To: <4b918f46$0$27863$c3e8da3@news.astraweb.com> References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> <4b918f46$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: > >>>> So, the pythonic way to check for True/False should be: >>>> >>>>>>> 1 is True >>>> False >>> >>> Why do you need to check for True/False? >>> >>> >> You should never check for "is" False/True but always check for >> equality. ?The reason is that many types support the equality (__eq__) >> and boolen (__bool__ in 3x) protocols. ?If you check equality these will >> be invoked, if you check identity ("is") they won't. > > Never say never. > > If you specifically want to test for True or False themselves, accepting > no substitutes, then using "is" is the obvious way, and using "==" is > clearly and obviously wrong because it does accept substitutes: > >>>> 1.0 == True > True >>>> decimal.Decimal(0, 1) == False > True Yes, obviously if you _really_ mean to test if something has the object identity of True or False then an "is" test is the way to go. I'm just not sure why you would ever do that. Also, I'm not sure how your assertion matches up with the examples; The examples test for equality with a float that returns true for __eq__ and a Decimal that returns false for __eq__. Both "1.0" and "Decimal(0, 1)" will return False if the test is "is True" or "is False." -Jack From clp2 at rebertia.com Fri Mar 5 18:59:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 15:59:39 -0800 Subject: Draft PEP on RSON configuration file format In-Reply-To: References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> On Fri, Mar 5, 2010 at 2:45 PM, Aahz wrote: > In article <7xwrxv4vv7.fsf at ruckus.brouhaha.com>, > Paul Rubin wrote: >> >>ReST is another abomination that should never have gotten off the >>ground. It is one of the reasons I react so negatively to your >>config format proposal. It just sounds like more of the same. > > Really? What should we use instead of reST? Markdown, Textile, or possibly Creole; reST has so little use outside of Python as to be nearly Python-specific. It'd be nice not to have to learn yet another markup language without good reason. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mensanator at aol.com Fri Mar 5 19:09:06 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 16:09:06 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: On Mar 5, 3:42?pm, Gary Herron wrote: > Mensanator wrote: > > > The only way to get a 0 from a reverse range() is to have a bound of > > -1. > > Not quite. ?An empty second bound goes all the way to the zero index: Not the same thing. You're using the bounds of the slice index. I was refering to the bounds of the range() function. >>> for a in range(9,-9,-1):print(a,end=' ') 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 To get that to stop at 0, you use a -1 as the bounds: >>> for a in range(9,-1,-1):print(a,end=' ') 9 8 7 6 5 4 3 2 1 0 Your slice notation only works if the last (first?) number in the range happens to be 0. What if the range bounds were variables? You may still want to force the range's last number to be 0 by using a constant like range(a,-1,-1) rather than just take the last number of range(a,b,-1) by using slice notation. > > ?>>> range(9)[2::-1] > [2, 1, 0] > > Gary Herron From clp2 at rebertia.com Fri Mar 5 19:18:29 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Mar 2010 16:18:29 -0800 Subject: isinstance(False, int) In-Reply-To: References: <4b914860$0$27863$c3e8da3@news.astraweb.com> <4B915352.8010709@sequans.com> Message-ID: <50697b2c1003051618n7b37aee6t74bd8f9edc5d21f5@mail.gmail.com> On Fri, Mar 5, 2010 at 1:51 PM, Terry Reedy wrote: > On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote: >> Steven D'Aprano wrote: > >> Despite there are good reasons for bool to be int, the newcomer 'wtf' >> reaction at first glance is legitimate. >> Starting python from scratch, booleans would have not been a subclass of >> int (just guessing though), 'cause it makes no sense from a design POV. > > You are just guessing. I would argue for what we have. An example of its > usefulness: > >>>> scores =[True, False, True, True, False] >>>> score = sum(scores) >>>> score > 3 > > Bools are also usefully used as sequence indexes. Arguably, these sorts of uses only require bool to be /convertible/ to int, not to necessarily be a /subclass/ of int. Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Fri Mar 5 19:34:26 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Mar 2010 16:34:26 -0800 Subject: Slicing [N::-1] In-Reply-To: References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: <4B91A312.9060608@islandtraining.com> Mensanator wrote: > On Mar 5, 3:42 pm, Gary Herron wrote: > >> Mensanator wrote: >> >> >>> The only way to get a 0 from a reverse range() is to have a bound of >>> -1. >>> >> Not quite. An empty second bound goes all the way to the zero index: >> > > Not the same thing. You're using the bounds of the slice index. > I was refering to the bounds of the range() function. > > >>>> for a in range(9,-9,-1):print(a,end=' ') >>>> > 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 > > To get that to stop at 0, you use a -1 as the bounds: > > >>>> for a in range(9,-1,-1):print(a,end=' ') >>>> > 9 8 7 6 5 4 3 2 1 0 > > Your slice notation only works if the last (first?) number in > the range happens to be 0. What if the range bounds were variables? > You may still want to force the range's last number to be 0 by > using a constant like range(a,-1,-1) rather than just take > the last number of range(a,b,-1) by using slice notation. > All true and valid of course, but I was just contridicting the "the ONLY way to get a 0" (emphasis mine) part of the statement. Gary Herron > >> >>> range(9)[2::-1] >> [2, 1, 0] >> >> Gary Herron >> From greg.ewing at canterbury.ac.nz Fri Mar 5 20:06:37 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:06:37 +1300 Subject: Draft PEP on RSON configuration file format In-Reply-To: <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> References: <66d0a0af-1ae7-4849-8e2a-fe80d4d49023@d2g2000yqa.googlegroups.com> <7xljebyl56.fsf@ruckus.brouhaha.com> <3aa65bd6-6b6f-42f0-aeec-1e70e5047da0@o3g2000yqb.googlegroups.com> <7xhbozrfy4.fsf@ruckus.brouhaha.com> <9c33fd40-7fe8-4274-84e4-9a9b5585d69f@19g2000yqu.googlegroups.com> <7x635fdcth.fsf@ruckus.brouhaha.com> <7xlje8lb9o.fsf@ruckus.brouhaha.com> <7vbiuqF4utU1@mid.individual.net> <4b90bb3c$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vdnhhFo9jU1@mid.individual.net> Steven D'Aprano wrote: > I use footnotes all the time[1] in plain text documents and emails. I > don't think there's anything bizarre about it at all. It's not the use of footnotes I'm talking about, it's the cryptic character sequences used to mark them up in ReST. Nobody would come up with them on their own without having read the fine print of an ReST manual. -- Greg From robert.kern at gmail.com Fri Mar 5 20:08:01 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 19:08:01 -0600 Subject: isinstance(False, int) In-Reply-To: References: <4b91616d$0$27863$c3e8da3@news.astraweb.com> <4b918f46$0$27863$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-05 17:48 PM, Jack Diederich wrote: > On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano > wrote: >> On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: >> >>>>> So, the pythonic way to check for True/False should be: >>>>> >>>>>>>> 1 is True >>>>> False >>>> >>>> Why do you need to check for True/False? >>>> >>>> >>> You should never check for "is" False/True but always check for >>> equality. The reason is that many types support the equality (__eq__) >>> and boolen (__bool__ in 3x) protocols. If you check equality these will >>> be invoked, if you check identity ("is") they won't. >> >> Never say never. >> >> If you specifically want to test for True or False themselves, accepting >> no substitutes, then using "is" is the obvious way, and using "==" is >> clearly and obviously wrong because it does accept substitutes: >> >>>>> 1.0 == True >> True >>>>> decimal.Decimal(0, 1) == False >> True > > > Yes, obviously if you _really_ mean to test if something has the > object identity of True or False then an "is" test is the way to go. > I'm just not sure why you would ever do that. Also, I'm not sure how > your assertion matches up with the examples; The examples test for > equality with a float that returns true for __eq__ and a Decimal that > returns false for __eq__. No, both comparisons return True. Decimal(0,1) is equal in value to 0 (and thus False). Comparing it to False using __eq__ returns True. > Both "1.0" and "Decimal(0, 1)" will return > False if the test is "is True" or "is False." Yes. That is exactly what he is asserting. -- 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 From no.email at nospam.invalid Fri Mar 5 20:10:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Mar 2010 17:10:14 -0800 Subject: Draft PEP on RSON configuration file format References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> Message-ID: <7xocj2fe6h.fsf@ruckus.brouhaha.com> Robert Kern writes: >> Markdown, Textile, or possibly Creole;... > I believe ReST predates all of those mentioned. Texinfo and POD are certainly older than ReST. I'm not sure about MediaWiki markup, but it's gotten so much traction that Markdown should probably be abandoned in its favor even if Markdown is older. From robert.kern at gmail.com Fri Mar 5 20:15:46 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Mar 2010 19:15:46 -0600 Subject: Draft PEP on RSON configuration file format In-Reply-To: <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> References: <7xhbozrfy4.fsf@ruckus.brouhaha.com> <7xwrxv4vv7.fsf@ruckus.brouhaha.com> <50697b2c1003051559k1fdca9e8xd7c394f1c177eedb@mail.gmail.com> Message-ID: On 2010-03-05 17:59 PM, Chris Rebert wrote: > On Fri, Mar 5, 2010 at 2:45 PM, Aahz > wrote: > > In article <7xwrxv4vv7.fsf at ruckus.brouhaha.com > >, > > Paul Rubin wrote: > >> > >>ReST is another abomination that should never have gotten off the > >>ground. It is one of the reasons I react so negatively to your > >>config format proposal. It just sounds like more of the same. > > > > Really? What should we use instead of reST? > > Markdown, Textile, or possibly Creole; reST has so little use outside of > Python as to be nearly Python-specific. > It'd be nice not to have to learn yet another markup language without > good reason. I believe ReST predates all of those mentioned. -- 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 From greg.ewing at canterbury.ac.nz Fri Mar 5 20:19:03 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:19:03 +1300 Subject: My four-yorkshireprogrammers contribution In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> Message-ID: <7vdo8sFrelU1@mid.individual.net> MRAB wrote: > By the standards of just a few years later, that's not so much a > microcomputer as a nanocomputer! Although not quite as nano as another design published in EA a couple of years earlier, the EDUC-8: http://www.sworld.com.au/steven/educ-8/ It had a *maximum* of 256 bytes -- due to the architecture, there was no way of addressing any more. Also it was divided into 16-byte pages, with indirect addressing required to access anything in a different page from the instruction. Programming for it must have been rather challenging. As far as I know, the EDUC-8 is unique in being the only computer design ever published in a hobby magazine that *wasn't* based on a microprocessor -- it was all built out of 9000 and 7400 series TTL logic chips! -- Greg From pemerson at gmail.com Fri Mar 5 20:22:14 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 17:22:14 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? Message-ID: I've been wrestling with dicts. I hope at the very least what I discovered helps someone else out, but I'm interested in hearing from more learned python users. I found out that adding a two dimensional element without defining first dimension existing doesn't work: >>> data = {} >>> data['one']['two'] = 'three' Traceback (most recent call last): File "", line 1, in KeyError: 'one' >>> data['one'] = {} >>> data['one']['two'] = 'three' >>> print data {'one': {'two': 'three'}} And through some research, I discovered collections.defaultdict (new in Python 2.5, FWIW): >>> import collections >>> data = collections.defaultdict(dict) >>> data['one']['two'] = 'three' >>> print data defaultdict(, {'one': {'two': 'three'}}) Why isn't the behavior of collections.defaultdict the default for a dict? Am I just revelling in my bad perl habits by not wanting to declare a previous level first? Is this sort of "more rigid" way of doing things common throughout python, and is it best that I not fight it, but embrace it? Your thoughts and comments are very much appreciated. I think my brain already knows some of the answers, but my heart ... well, perl and I go way back. Loving python so far, though. Pete From greg.ewing at canterbury.ac.nz Fri Mar 5 20:39:25 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:39:25 +1300 Subject: Generic singleton In-Reply-To: <4b9146e6$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vdpf2FqgU1@mid.individual.net> I think the important difference between None and booleans wrt singleton behaviour is that things are often compared with None using "is", so it's quite important that there only be one instance of NoneType around, and it makes sense not to give people the false impression that they can create another one. Re-using predefined True and False instances is more of a performance optimisation, however -- they're not usually compared for identity, or even compared at all for that matter. So there's no particular reason to disallow calling bool(). In fact, there's an excellent reason to *allow* calling it: not only is bool a type, it's also often used as a function to coerce things to a boolean value: >>> bool(['hello']) True There's no equivalent reason to make NoneType callable, as coercing something to None makes very little sense. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 5 20:45:58 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 06 Mar 2010 14:45:58 +1300 Subject: Generic singleton In-Reply-To: <4b918ec8$0$27863$c3e8da3@news.astraweb.com> References: <4b907b5e$0$27863$c3e8da3@news.astraweb.com> <4b9146e6$0$27863$c3e8da3@news.astraweb.com> <4b918ec8$0$27863$c3e8da3@news.astraweb.com> Message-ID: <7vdpraF2glU1@mid.individual.net> Steven D'Aprano wrote: > While Doubleton or even Tripleton sound cute, once you get to large > counts it all starts getting ugly and horrible. "Polyton"? Blah. Tupleton? -- Greg From usenot at geekmail.INVALID Fri Mar 5 21:02:58 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 6 Mar 2010 03:02:58 +0100 Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <20100306030258.01d324b7@geekmail.INVALID> On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > > >>> data = {} > >>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "", line 1, in > KeyError: 'one' Yeah, because that key 'one' indexes what exactly? > [snip] > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > > [snip] > > Why isn't the behavior of collections.defaultdict the default for a > dict? Because explicit is better than implicit. How should Python know what you want to fill your dict with? It could be anything that takes string indices. Only two lines of code remove all the guesswork. > Am I just revelling in my bad perl habits by not wanting to declare a > previous level first? Yes. Python pretty much never guesses (not that I knew of anyway). I think that is good, because it's just too easy to overlook some magic the language does and spend an hour trying to understand why that Toyota hit that wall. > Is this sort of "more rigid" way of doing things common throughout > python, and is it best that I not fight it, but embrace it? > Seriously, what answer do you expect? ;) When has fighting a language ever brought about something really cool. (I'm really looking forward to the geeky humorous replies this is bound to sprout.) > Your thoughts and comments are very much appreciated. I think my brain > already knows some of the answers, but my heart ... well, perl and I > go way back. Loving python so far, though. > Welcome on board. Have you typed "import this" in the command prompt yet? -- INVALID? DE! From mensanator at aol.com Fri Mar 5 21:09:59 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Mar 2010 18:09:59 -0800 (PST) Subject: Slicing [N::-1] References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> Message-ID: <83e3ccd0-29d6-4aec-8590-a38e6daba56d@g26g2000yqn.googlegroups.com> On Mar 5, 6:34?pm, Gary Herron wrote: > Mensanator wrote: > > On Mar 5, 3:42 pm, Gary Herron wrote: > > >> Mensanator wrote: > > >>> The only way to get a 0 from a reverse range() is to have a bound of > >>> -1. > > >> Not quite. ?An empty second bound goes all the way to the zero index: > > > Not the same thing. You're using the bounds of the slice index. > > I was refering to the bounds of the range() function. > > >>>> for a in range(9,-9,-1):print(a,end=' ') > > > 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 > > > To get that to stop at 0, you use a -1 as the bounds: > > >>>> for a in range(9,-1,-1):print(a,end=' ') > > > 9 8 7 6 5 4 3 2 1 0 > > > Your slice notation only works if the last (first?) number in > > the range happens to be 0. What if the range bounds were variables? > > You may still want to force the range's last number to be 0 by > > using a constant like range(a,-1,-1) rather than just take > > the last number of range(a,b,-1) by using slice notation. > > All true ?and valid of course, but I was just contridicting the "the > ONLY way to get a 0" (emphasis mine) part of the statement. Does it still contradict if you do not use the '::' as the OP requested? > > Gary Herron > > > > > > >> ?>>> range(9)[2::-1] > >> [2, 1, 0] > > >> Gary Herron- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - From usenot at geekmail.INVALID Fri Mar 5 21:10:03 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 6 Mar 2010 03:10:03 +0100 Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <20100306031003.1018aab2@geekmail.INVALID> On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson wrote: > [snip] > >>> data['one'] = {} > >>> data['one']['two'] = 'three' > >>> print data > {'one': {'two': 'three'}} > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > > >>> import collections > >>> data = collections.defaultdict(dict) > >>> data['one']['two'] = 'three' > >>> print data > defaultdict(, {'one': {'two': 'three'}}) > > [snip] > Your thoughts and comments are very much appreciated. I think my brain > already knows some of the answers, but my heart ... well, perl and I > go way back. Loving python so far, though. > Oh, by the way: That defaultdict route is a pretty solid solution. Not sure what problem you're trying to solve -- depending on your usecase, there might be a better approach. If you're just asking hypothetically and you're trying to apply a Perl idiom to Python, there probably *is* a better solution. /W -- INVALID? DE! From ckaynor at zindagigames.com Fri Mar 5 21:20:42 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 5 Mar 2010 18:20:42 -0800 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: References: Message-ID: On Fri, Mar 5, 2010 at 5:22 PM, Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > > >>> data = {} > >>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "", line 1, in > KeyError: 'one' > >>> data['one'] = {} > >>> data['one']['two'] = 'three' > >>> print data > {'one': {'two': 'three'}} > > Perhaps a better idiom for what you are doing would be to use tuples as the keys: (I don't have a handy Python interpreter, so untested) data = {} data[('one', 'two')] = 'three' -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Mar 5 21:26:39 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 06 Mar 2010 02:26:39 +0000 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: References: Message-ID: <4B91BD5F.1020304@mrabarnett.plus.com> Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > >>>> data = {} >>>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "", line 1, in > KeyError: 'one' >>>> data['one'] = {} >>>> data['one']['two'] = 'three' >>>> print data > {'one': {'two': 'three'}} > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > >>>> import collections >>>> data = collections.defaultdict(dict) >>>> data['one']['two'] = 'three' >>>> print data > defaultdict(, {'one': {'two': 'three'}}) > > Why isn't the behavior of collections.defaultdict the default for a > dict? > Am I just revelling in my bad perl habits by not wanting to declare a > previous level first? > Is this sort of "more rigid" way of doing things common throughout > python, and is it best that I not fight it, but embrace it? > > Your thoughts and comments are very much appreciated. I think my brain > already knows some of the answers, but my heart ... well, perl and I > go way back. Loving python so far, though. > Someone once wrote about a case where he was porting a frontend from Perl to Python. It called a backend and parsed the result. Sometimes converting one of the fields to a number would raise a ValueError because it would contain "ERR" instead of a number, which Perl, of course, would silently convert to 0! Python is all about refusing to guess, and complaining if there's an error. :-) From pemerson at gmail.com Fri Mar 5 21:30:47 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 18:30:47 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? References: <20100306031003.1018aab2@geekmail.INVALID> Message-ID: <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> On Mar 5, 6:10?pm, Andreas Waldenburger wrote: > On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson > > > > > > wrote: > > [snip] > > >>> data['one'] = {} > > >>> data['one']['two'] = 'three' > > >>> print data > > {'one': {'two': 'three'}} > > > And through some research, I discovered collections.defaultdict (new > > in Python 2.5, FWIW): > > > >>> import collections > > >>> data = collections.defaultdict(dict) > > >>> data['one']['two'] = 'three' > > >>> print data > > defaultdict(, {'one': {'two': 'three'}}) > > > [snip] > > Your thoughts and comments are very much appreciated. I think my brain > > already knows some of the answers, but my heart ... well, perl and I > > go way back. Loving python so far, though. > > Oh, by the way: That defaultdict route is a pretty solid solution. Not > sure what problem you're trying to solve -- depending on your usecase, > there might be a better approach. > > If you're just asking hypothetically and you're trying to apply a > Perl idiom to Python, there probably *is* a better solution. > > /W > > -- > INVALID? DE! I found out about the need to declare the higher level as I was reading in a JSON struct into a dict and then adding a new entry at a lower level. Mostly just proof of concept stuff as I'm learning python. I'm not sure that the use of defaultdict is really warranted for me anywhere just yet. Mostly, I don't want to convert my perl to python, that seems very counterproductive. Thank you very much for your insight. I was a little frightened of doing "import this" ("Hey, kid, run rm - rf / and see what happens!"), but did, and the words are wise. :) Pete From alfps at start.no Fri Mar 5 21:32:48 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Mar 2010 03:32:48 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Robert Kern: > On 2010-03-03 09:39 AM, Mike Kent wrote: >> What's the compelling use case for this vs. a simple try/finally? >> >> original_dir = os.getcwd() >> try: >> os.chdir(somewhere) >> # Do other stuff >> finally: >> os.chdir(original_dir) >> # Do other cleanup > > A custom-written context manager looks nicer and can be more readable. > > from contextlib import contextmanager > import os > > @contextmanager > def pushd(path): > original_dir = os.getcwd() > os.chdir(path) > try: > yield > finally: > os.chdir(original_dir) > > > with pushd(somewhere): > ... > > > I don't think a general purpose ScopeGuard context manager has any such > benefits over the try: finally:, though. class pushd( Cleanup ): def __init__( self, path ): original_dir = os.getcwd() os.chdir( path ) self._actions.append( lambda: os.chdir( original_dir ) ) Disclaimer: haven't tested this, but it just occurred to me that for such small init/cleanup wrappers the Cleanup class provides a nice alternative to @contextmanager, as above: fewer lines, and perhaps even more clear code. :-) Cheers, - Alf From no.email at nospam.invalid Fri Mar 5 21:53:46 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 05 Mar 2010 18:53:46 -0800 Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <7xlje6rwhx.fsf@ruckus.brouhaha.com> Pete Emerson writes: > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > >>>> data = {} >>>> data['one']['two'] = 'three' You can use a tuple as a subscript if you want: data = {} data['one','two'] = 'three' From gherron at islandtraining.com Fri Mar 5 22:05:20 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Mar 2010 19:05:20 -0800 Subject: Slicing [N::-1] In-Reply-To: <83e3ccd0-29d6-4aec-8590-a38e6daba56d@g26g2000yqn.googlegroups.com> References: <90fc5b42-b83a-41fc-9b1a-929d88a649cc@g19g2000yqe.googlegroups.com> <4b914d35$0$27863$c3e8da3@news.astraweb.com> <83e3ccd0-29d6-4aec-8590-a38e6daba56d@g26g2000yqn.googlegroups.com> Message-ID: <4B91C670.3060305@islandtraining.com> Mensanator wrote: > On Mar 5, 6:34 pm, Gary Herron wrote: > >> Mensanator wrote: >> >>> On Mar 5, 3:42 pm, Gary Herron wrote: >>> >>>> Mensanator wrote: >>>> >>>>> The only way to get a 0 from a reverse range() is to have a bound of >>>>> -1. >>>>> >>>> Not quite. An empty second bound goes all the way to the zero index: >>>> >>> Not the same thing. You're using the bounds of the slice index. >>> I was refering to the bounds of the range() function. >>> >>>>>> for a in range(9,-9,-1):print(a,end=' ') >>>>>> >>> 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 >>> >>> To get that to stop at 0, you use a -1 as the bounds: >>> >>>>>> for a in range(9,-1,-1):print(a,end=' ') >>>>>> >>> 9 8 7 6 5 4 3 2 1 0 >>> >>> Your slice notation only works if the last (first?) number in >>> the range happens to be 0. What if the range bounds were variables? >>> You may still want to force the range's last number to be 0 by >>> using a constant like range(a,-1,-1) rather than just take >>> the last number of range(a,b,-1) by using slice notation. >>> >> All true and valid of course, but I was just contridicting the "the >> ONLY way to get a 0" (emphasis mine) part of the statement. >> > > Does it still contradict if you do not use the '::' as the OP > requested? > Not to my knowledge... I believe your statement is true in all cases which explicitly state the stop value. > >> Gary Herron >> >> >> >> >> >> >>>> >>> range(9)[2::-1] >>>> [2, 1, 0] >>>> >>>> Gary Herron- Hide quoted text - >>>> >> - Show quoted text -- Hide quoted text - >> >> - Show quoted text - >> > > From steve at REMOVE-THIS-cybersource.com.au Fri Mar 5 23:24:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Mar 2010 04:24:32 GMT Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: <4b91d900$0$27863$c3e8da3@news.astraweb.com> On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > Why isn't the behavior of collections.defaultdict the default for a > dict? Why would it be? If you look up a key in a dict: addressbook['Barney Rubble'] and you don't actually have Barney's address, should Python guess and make something up? In general, looking up a missing key is an error, and errors should never pass silently unless explicitly silenced. And for those cases where missing keys are not errors, you're spoiled for choice: dict.get dict.setdefault collections.defaultdict try: dict[key] except KeyError: do something else Or even: if key in dict: dict[key] else: do something else -- Steven From pemerson at gmail.com Sat Mar 6 00:36:39 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 21:36:39 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? References: <4b91d900$0$27863$c3e8da3@news.astraweb.com> Message-ID: <6048eb76-9dca-4509-ad7e-f65040128ebb@b36g2000pri.googlegroups.com> On Mar 5, 8:24?pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > > Why isn't the behavior of collections.defaultdict the default for a > > dict? > > Why would it be? > > If you look up a key in a dict: > > addressbook['Barney Rubble'] > > and you don't actually have Barney's address, should Python guess and > make something up? > > In general, looking up a missing key is an error, and errors should never > pass silently unless explicitly silenced. > > And for those cases where missing keys are not errors, you're spoiled for > choice: > > dict.get > dict.setdefault > collections.defaultdict > > try: > ? ? dict[key] > except KeyError: > ? ? do something else > > Or even: > > if key in dict: > ? ? dict[key] > else: > ? ? do something else > > -- > Steven My frame of reference for the past 10 < N < 15 years has been doing this sort of assignment in perl: $hash{key1}{key2} = value I definitely agree that looking up a missing key should give an error. The lazy perl programmer in me just wants to make an assignment to a missing second key without defining the first key first. I'm not saying it's right, I'm saying that it's something I'm trying to unlearn, as I'm being convinced that it's the "best way" to do it in python. I'll take a look at dict.get and dict.setdefault, thank you for those. I'm learning, and you're all very helpful, and I appreciate it! Pete From pemerson at gmail.com Sat Mar 6 00:42:37 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 5 Mar 2010 21:42:37 -0800 (PST) Subject: best practices: is collections.defaultdict my friend or not? References: Message-ID: On Mar 5, 6:26?pm, MRAB wrote: > Pete Emerson wrote: > > I've been wrestling with dicts. I hope at the very least what I > > discovered helps someone else out, but I'm interested in hearing from > > more learned python users. > > > I found out that adding a two dimensional element without defining > > first dimension existing doesn't work: > > >>>> data = {} > >>>> data['one']['two'] = 'three' > > Traceback (most recent call last): > > ? File "", line 1, in > > KeyError: 'one' > >>>> data['one'] = {} > >>>> data['one']['two'] = 'three' > >>>> print data > > {'one': {'two': 'three'}} > > > And through some research, I discovered collections.defaultdict (new > > in Python 2.5, FWIW): > > >>>> import collections > >>>> data = collections.defaultdict(dict) > >>>> data['one']['two'] = 'three' > >>>> print data > > defaultdict(, {'one': {'two': 'three'}}) > > > Why isn't the behavior of collections.defaultdict the default for a > > dict? > > Am I just revelling in my bad perl habits by not wanting to declare a > > previous level first? > > Is this sort of "more rigid" way of doing things common throughout > > python, and is it best that I not fight it, but embrace it? > > > Your thoughts and comments are very much appreciated. I think my brain > > already knows some of the answers, but my heart ... well, perl and I > > go way back. Loving python so far, though. > > Someone once wrote about a case where he was porting a frontend from > Perl to Python. It called a backend and parsed the result. Sometimes > converting one of the fields to a number would raise a ValueError > because it would contain "ERR" instead of a number, which Perl, of > course, would silently convert to 0! > > Python is all about refusing to guess, and complaining if there's an > error. :-) Perl is quite an amazing language, but it also definitely allows for sloppy habits and poor coding behaviors, particularly for someone such as me whose perl is completely self taught. I think that's why this time around with python I'm trying to learn my prior experience and seek help in areas where I suspect there is improvement to be made. I'm really liking the rigid flexibility I'm experiencing with python so far. I'm thinking it's time for me to get a python reference or two, just to kill a few trees. If anyone has any strong feelings about what belongs in a "beginner but already learning quickly" library, please toss them my way. I'll grep around the 'net for opinions on it, too. Pete From darcy at druid.net Sat Mar 6 01:55:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 6 Mar 2010 01:55:48 -0500 Subject: My four-yorkshireprogrammers contribution In-Reply-To: <7vdo8sFrelU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> <4B89D8BE.2040905@mrabarnett.plus.com> <4B8B9845.70604@sequans.com> <7v695nFa0fU1@mid.individual.net> <7v9e3rFl7mU1@mid.individual.net> <7vdo8sFrelU1@mid.individual.net> Message-ID: <20100306015548.4e510039.darcy@druid.net> On Sat, 06 Mar 2010 14:19:03 +1300 Gregory Ewing wrote: > MRAB wrote: > > By the standards of just a few years later, that's not so much a > > microcomputer as a nanocomputer! > > Although not quite as nano as another design published > in EA a couple of years earlier, the EDUC-8: Byte Magazine once published plans for building a computer that had one instruction. I believe it was a six bit address so that would make it a max of 64 bytes. If I recall, the single instruction was "SUBTRACT AND JUMP ON CARRY." Now that's nano! -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From pmaupin at gmail.com Sat Mar 6 02:21:45 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Fri, 5 Mar 2010 23:21:45 -0800 (PST) Subject: Initial RSON prototype parser in subversion References: Message-ID: I have not yet added indentation sensitivity to the parser (although the tokenizer saves the indentation information for the parser), but the initial prototype parses all of JSON plus a lot of syntax enhancements (comments, hex/binary/octal numbers, relaxed quoting requirements for strings, trailing comments allowed, triple-quoted strings, etc.) I have also started the rson-discuss group on google for further discussions on the actual syntax and initial implementation, if anyone is interested, and have posted a message there with a bit more information about the prototype status. The project page is at http://code.google.com/p/rson/ Best regards, Pat From strombrg at gmail.com Sat Mar 6 03:21:59 2010 From: strombrg at gmail.com (Dan Stromberg) Date: Sat, 6 Mar 2010 00:21:59 -0800 (PST) Subject: Fast GUI pipemeter: gprog References: <619ab895-87a9-4b40-b45e-b12299304b38@z1g2000prc.googlegroups.com> <1686070.lZ2vcFHjTE@xkzjympik> Message-ID: <44626216-1aeb-491b-9ee4-c0ed79a7ab88@b9g2000pri.googlegroups.com> On Mar 4, 4:25?pm, Dan Stromberg wrote: > Python folk: Any guesses why a simple file.read(blocksize) would have > such an affinity for returning 16K when redirected from /dev/zero? ?If > I run the program against a file on disk, it gets larger blocksizes > fine. Never mind - it was a bug in my code. Now on a slower machine, it runs about 2.5 times faster than it did on the faster machine. From wongjoekmeu at yahoo.com Sat Mar 6 04:45:46 2010 From: wongjoekmeu at yahoo.com (wongjoekmeu at yahoo.com) Date: Sat, 6 Mar 2010 01:45:46 -0800 (PST) Subject: start function in new process References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> Message-ID: <04188082-bc7f-4b65-bfde-dc7abe5e8123@t41g2000yqt.googlegroups.com> On 5 mrt, 21:40, "Martin P. Hellwig" wrote: > On 03/05/10 20:09, wongjoek... at yahoo.com wrote: > > > > > On 5 mrt, 21:02, "Martin P. Hellwig" > > wrote: > >> On 03/05/10 19:45, wongjoek... at yahoo.com wrote: > > >>> On 5 mrt, 20:40, "Martin P. Hellwig" > >>> wrote: > >>>> On 03/05/10 19:21, wongjoek... at yahoo.com wrote: > >>>> > >>>> Any specific reason why threading.Thread or multiprocessing is not > >>>> suitable to solve your problem? > > >>>> -- > >>>> mph > > >>> Because I got a memory leak in my function f(). It uses scipy, numpy, > >>> pylab, and I am not planning to solve the memory leak because its too > >>> complicated. So I thought of just calling the function then when it is > >>> finished the process is gone and all memory is released. With > >>> threading I don't think I would solve this problem. I am not sure > >>> though. > > >> I would be surprised if you can't do the same with > >> subprocess/multiprocessing, since you seem to know how to identify the > >> memory leak it shouldn't be a problem scripting out a test to see if it > >> works this way. I would be interested though in your findings. > > >> -- > >> mph > > > I can't use multiprocessing module since it comes only with python 2.6 > > and I am bound to python2.4. But subprocess does exist in python2.4, > > but the question now is, how do I achieve that ? Any example ? > > Sure, for example if I want to check the openssl version (didn't specify > I need to provide a useful example :-) > > I would normally do on the command line: > [martin at aspire8930 /usr/home/martin/Desktop]$ /usr/bin/openssl version > OpenSSL 0.9.8k 25 Mar 2009 > > The python subprocess equivalent is: > [martin at aspire8930 /usr/home/martin/Desktop]$ python > Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) > [GCC 4.2.1 20070719 ?[FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> import subprocess as _sp > ?>>> ssl_version = _sp.Popen(['/usr/bin/openssl', 'version'], > stdout=_sp.PIPE) > ?>>> print(ssl_version.stdout.readlines()) > ['OpenSSL 0.9.8k 25 Mar 2009\n'] > ?>>> quit() > [martin at aspire8930 /usr/home/martin/Desktop]$ > > If you get any error in the Popen part, you probably did not use the > full path or an illegal parameter. > > If you get a long wait in the readlines part, this usually means that > there is either nothing written to stdout or something is still being > written (I am not sure about this part though, it has been a while). > > hth > -- > mph Yes, I saw this example also before. HOwever what I want is to call an internal function which gets a reference of another internal function as input and not calling an external program. Do you have any example on that with subprocess module ? Thanks. From isso.moh at gmail.com Sat Mar 6 05:39:09 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Sat, 6 Mar 2010 11:39:09 +0100 Subject: compiler with python Message-ID: hey, How can I construct a compiler with python just for informatiom ., I have habit to construct it with C language, sorry for my english ;-) -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From acm at muc.de Sat Mar 6 06:20:11 2010 From: acm at muc.de (Alan Mackenzie) Date: Sat, 6 Mar 2010 11:20:11 +0000 (UTC) Subject: Building Python-2.6.4 on G/L: can't build in _ssl support. Message-ID: Hi, Python! I build Python-2.6.4 on my GNU/Linux (Debian Sarge) box. I get a warning message "Failed to find the necessary bits to build these modules: .... _ssl ... RTFS to find out what!". I need _ssl for an application. So, I look at setup.py in the top directory. It seems that _ssl needs to find certain .h files, but is looking in /usr/local/ssl and /usr/contrib (or subdirectories thereof). These look like highly non-standard directories. Either something is hugely amiss, or I'm missing some vital nugget of information (possibly through not being a Python hacker). Would somebody please give me a tip to get this sorted out? Thanks! -- Alan Mackenzie (Nuremberg, Germany). From davea at ieee.org Sat Mar 6 06:37:12 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Mar 2010 06:37:12 -0500 Subject: compiler with python In-Reply-To: References: Message-ID: <4B923E68.1000104@ieee.org> mohamed issolah wrote: > hey, > > How can I construct a compiler with python just for informatiom ., I have > habit to construct it with C language, > > sorry for my english ;-) > You need to tell us what you're really trying to do, what tools you're willing to use, and probably why you want it. And if you're not sure about your English, keep the sentence structure straightforward. Let me make a couple of wild guesses: You want to design and build a compiler that takes xml information as its source code, and compiles those xml files into Intel x86 machine code. The compiler and the resulting executable needs to run on an x86 Linux machine. Your previous experience was in doing this sort of thing in C, but you want to try it with Python instead. You want to do it without using the lxml libraries. You want to build a python compiler, that takes python source code and produces Java byte code files. You'd like to do this in C, but don't want to use any of the available existing CPython or Jython source code. Your goal is not to make a commercially viable product, but to learn as much as possible in the process. DaveA From python at hope.cz Sat Mar 6 06:53:53 2010 From: python at hope.cz (Johny) Date: Sat, 6 Mar 2010 03:53:53 -0800 (PST) Subject: Import problem Message-ID: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> I have this directory structure C: \A __init__.py amodule.py \B __init__.py bmodule.py \D __init__.py dmodule.py and I want to import bmodule.py C:\>cd \ C:\>python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> from A.B import bmodule I am bmodule >>> C:\> so far so good. Now I would like to import bmodule but if the current directory is \D subdirectory. C:> cd \A\B\D C:\A\B\D> C:\A\B\D>python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append('C:\\A') >>> from A.B import bmodule Traceback (most recent call last): File "", line 1, in ImportError: No module named A.B C:\> so I can not import a module from the parent directory? Or where did I make an error? Thanks for help L. From martin.hellwig at dcuktec.org Sat Mar 6 07:28:25 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 06 Mar 2010 12:28:25 +0000 Subject: start function in new process In-Reply-To: <04188082-bc7f-4b65-bfde-dc7abe5e8123@t41g2000yqt.googlegroups.com> References: <121035de-e4be-4967-824a-dbd57d20f2f6@q16g2000yqq.googlegroups.com> <86d891a9-b6aa-4de9-a0f5-314867fdf75d@q21g2000yqm.googlegroups.com> <3f2cc4f0-b21a-4886-a81c-5b503610ac2d@e7g2000yqf.googlegroups.com> <04188082-bc7f-4b65-bfde-dc7abe5e8123@t41g2000yqt.googlegroups.com> Message-ID: On 03/06/10 09:45, wongjoekmeu at yahoo.com wrote: > > Yes, I saw this example also before. HOwever what I want is to call an > internal function which gets a reference of another internal function > as input and not calling an external program. Do you have any example > on that with subprocess module ? > Thanks. Well yes that is possible but you would more or less be just reinventing parts of the multiprocessing module, so I would use that one (at the location Robert Kern suggested). -- mph From isso.moh at gmail.com Sat Mar 6 08:07:30 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Sat, 6 Mar 2010 14:07:30 +0100 Subject: compiler with python Message-ID: hey, I want to create a compiler which transform a code like pascal code (that what I do in C) to "quad" In C, I use BISON and FLEX tools. -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From kse.listed.co1 at gmail.com Sat Mar 6 08:33:34 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Sat, 6 Mar 2010 05:33:34 -0800 (PST) Subject: "olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" " Message-ID: "olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" ""olivia wilde" "olivia williams" "olivia" "olivia" "olivia" "virgin women" "virgin girl test" on http://sexyandpretty-girls.blogspot.com/ "torrie wilson playboy march 2004" "torrie wilson" "torrie wilson no clothes" "torrie wilson 2009" " From steve at REMOVE-THIS-cybersource.com.au Sat Mar 6 09:48:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Mar 2010 14:48:24 GMT Subject: Import problem References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4b926b37$0$27829$c3e8da3@news.astraweb.com> On Sat, 06 Mar 2010 03:53:53 -0800, Johny wrote: >>>> import sys >>>> sys.path.append('C:\\A') >>>> from A.B import bmodule > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named A.B The current directory is irrelevant, except that it is automatically added to the PYTHONPATH. That's why you can import A.B when the current directory is C. You are trying to import module B from package A *inside* directory C:\A, but there is no such package A inside C:\A. You need to add C to the path, and then it should work. -- Steven From bdesth.quelquechose at free.quelquepart.fr Sat Mar 6 10:04:53 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Sat, 06 Mar 2010 16:04:53 +0100 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: References: Message-ID: <4b927c8e$0$10093$426a74cc@news.free.fr> Pete Emerson a ?crit : (snip) > I'm really liking the rigid flexibility I'm experiencing with python > so far. "rigid flexibility" !-) +1 QOTW - and welcome on board BTW. From ijcsorgeditor at gmail.com Sat Mar 6 10:31:48 2010 From: ijcsorgeditor at gmail.com (editor ijcs) Date: Sat, 6 Mar 2010 07:31:48 -0800 (PST) Subject: Call for Paper The International Journal of Computer Science (IJCS) Message-ID: <50313c59-a5bf-4f12-8c6f-e0c413c68084@k18g2000prf.googlegroups.com> Call for Paper The International Journal of Computer Science (IJCS) publishes original papers on all subjects relevant to computer science, communication network, and information systems. The highest priority will be given to those contributions concerned with a discussion of the background of a practical problem, the establishment of an appropriate model, the determination of a solution, approximate or exact, analytical or numerical, and a discussion of the relevance of the results when applied to the real-life problem. Paper submissions are invited in the area of computer science, in particular the technological advances and research results in the fields of theoretical, experimental, applied electronics, computer science, communication network and Information technology. Topics of interest include but are not limited to the following: Computer Science * Parallel Processing and Distributed Computing * Foundations of High-performance Computing * Graph Theory and Analysis of Algorithms * Artificial Intelligences and Pattern/Image Recognitions * Neural Networks and Biomedical Simulations * Virtual Visions and Virtual Simulations * Data Mining, Web Image Mining and Applications * Data Base Management & Information Retrievals Adaptive Systems * Bifurcation, Biocybernetics & Bioinformatics * Blind Systems, Neural Networks &Control Systems * Cryptosystems &Data Compression * Evolutional Computation &Fuzzy Systems * Image Processing and Image Recognition, Modeling & Optimization * Speech Processing, Speech Synthesis & Speech Recognition * Video Signal Processing, Watermarking & Wavelet Transform * All topics related Computer Science Communication Network * Quantum Computing & Coding * Error Controls Agent Computing & Multi-Agents Systems * Defining Spectrum Rights and Open Spectrum Solutions * Quality of Services and Communication Protocols * Satellite and Optical Communication Systems * 3G/4G Network Evolutions & CDMA/GSM Communication Protocols * Mobile Computing, Transmission/Switching/Distribution technologies * Communication Theory & Signal Processing for Communications * Wireless Communications, Wireless & Mobile Networking * Optical Networks and Systems &Next-Generation Networking and Internet * Communication QoS &Reliability and Modeling * Ad-hoc, Sensor & Mesh Networking * Multimedia Services, Communication Software & Services * Communication and Information System Security * System control and network/service management * Network and Internet protocols and standards * Client-server, distributed & Web-based communication systems * Broadband and multimedia systems & applications * Trials of advanced systems and services * Any topics related Communication Network Information and Systems * Cryptography and Foundation of Computer Security * Authentication/Authorization Issues * IDS/Firewall, Anti-Spam mail & Anti-virus issues * Biometric authentication & algorithms * Fingerprint /Hand/Biometrics Recognitions and Technologies * IC-card Security, OTP & Key Management Issues * E-commerce, Ubiquitous & RFID Applications * Metadata, Meta Modeling, XML & Data Management * Knowledge Management, Web Security & Privacy * Cyber Threats, Web Services & Web Engineering * Web Intelligence, Protocols & Standards * Proxies and Servers * Multimedia Applications * Ontology and the Semantic Web * B2B, B2C and C2C * E-Business System Design and Development, E-Payment * Portal Strategies, Social Networks and Information Systems * Social and Legal Issues and Digital Ecology * E-Governance, E-Learning and Virtual Classrooms * E-Entertainment, E-Journalism * Any topics related Information systems Electronics * Circuits & Devices * Communication Networks & Systems * Communications & Information Processing * Digital Signal Processing & Electrical Engineering Communications * Electromagnetics & Microwaves * Instrumentation * Measurement & Testing * Nanoscience & Nanotechnology * Optics & Optoelectronic Effects * Devices, Systems &Semiconductors * Systems & Control Engineering * Telecommunications * Any topics related Electronics International Journal of Computer Science (IJCS) ISSN: 1884-9083 Website: https://sites.google.com/site/ijcsorg/ Manuscript submission to: ijcsorgeditor at gmail.com All submitted papers will be judged based on their quality by the technical committee and reviewers. Papers that describe research and experimentation are encouraged. All paper submissions will be handled electronically and detailed instructions on submission procedure are available on IJCS web pages. Researchers and authors are invited to participate in the peer-review process of IJCS papers if your research interest matches with the themes of Call for Papers. For other information, please contact IJCS Managing Editor. From jaihindharjun at gmail.com Sat Mar 6 10:40:19 2010 From: jaihindharjun at gmail.com (karan arjun) Date: Sat, 6 Mar 2010 07:40:19 -0800 (PST) Subject: intersting datt with girls.......sign in to this website Message-ID: RE U WANT RUSSIAN GIRL FRIENDS... WEBPAGE ---> http://123maza.com/hashan/ From davea at ieee.org Sat Mar 6 10:56:19 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Mar 2010 10:56:19 -0500 Subject: compiler with python In-Reply-To: References: <4B923E68.1000104@ieee.org> Message-ID: <4B927B23.2090009@ieee.org> mohamed issolah wrote: > > 2010/3/6 Dave Angel > > >> mohamed issolah wrote: >> >> >>> hey, >>> >>> How can I construct a compiler with python just for informatiom ., I have >>> habit to construct it with C language, >>> >>> sorry for my english ;-) >>> >>> >>> >> You need to tell us what you're really trying to do, what tools you're >> willing to use, and probably why you want it. And if you're not sure about >> your English, keep the sentence structure straightforward. >> >> Let me make a couple of wild guesses: >> >> > > > >> You want to design and build a compiler that takes xml information as its >> source code, and compiles those xml files into Intel x86 machine code. The >> compiler and the resulting executable needs to run on an x86 Linux machine. >> Your previous experience was in doing this sort of thing in C, but you want >> to try it with Python instead. You want to do it without using the lxml >> libraries. >> >> You want to build a python compiler, that takes python source code and >> produces Java byte code files. You'd like to do this in C, but don't want >> to use any of the available existing CPython or Jython source code. Your >> goal is not to make a commercially viable product, but to learn as much as >> possible in the process. >> >> >> DaveA >> >> > > hey, > > I want to create a compiler which transform a code like pascal code (that > what I do in C) to "quad" > In C, I use BISON and FLEX tools. > > > I've forwarded your message to the list, and fixed your top-posting by moving your response to the bottom. I don't have a clue what "quad" is, unless it's a synonym for Forth. You haven't specified the OS you'll be using to run the compiler, nor the one you're targeting, so some of these choices may not be useful. For example, the first one is Linux only. http://www.freenet.org.nz/python/pybison/ PyBison - Python binding for Bison/Flex http://freshmeat.net/projects/yeanpypa/ http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ Or you could go here, which has links to (most of) these and others. http://wiki.python.org/moin/LanguageParsing DaveA From soniyaa1111 at gmail.com Sat Mar 6 11:15:22 2010 From: soniyaa1111 at gmail.com (soniyaa 1111) Date: Sat, 6 Mar 2010 08:15:22 -0800 (PST) Subject: Shop online without credit card Message-ID: Shop online without credit card. It?s only @ http://www.shoppingreps.com?SourceId=1259 Membership is absolutely free. Join and enjoy your shopping. For more details visit http://www.shoppingreps.com?SourceId=1259 From as at sci.fi Sat Mar 6 11:24:24 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 06 Mar 2010 18:24:24 +0200 Subject: Building Python-2.6.4 on G/L: can't build in _ssl support. References: Message-ID: Alan Mackenzie writes: > Hi, Python! > > I build Python-2.6.4 on my GNU/Linux (Debian Sarge) box. I get a warning > message "Failed to find the necessary bits to build these modules: .... > _ssl ... RTFS to find out what!". At a guess, you're missing libssl-dev. You might consider installing python2.6 or python2.6-minimal from unstable or testing too. > I need _ssl for an application. So, I look at setup.py in the top > directory. It seems that _ssl needs to find certain .h files, but is > looking in /usr/local/ssl and /usr/contrib (or subdirectories thereof). > These look like highly non-standard directories. Looks to me like it looks in those non-standard directories, but in addition to normal /usr/include. From peloko45 at gmail.com Sat Mar 6 13:33:17 2010 From: peloko45 at gmail.com (Joan Miller) Date: Sat, 6 Mar 2010 10:33:17 -0800 (PST) Subject: Escape curly bracket together to a variable extension Message-ID: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> How to escape the first '}' in the next string? s = "}\n{0}".format('foo') From alfps at start.no Sat Mar 6 13:38:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Mar 2010 19:38:23 +0100 Subject: Escape curly bracket together to a variable extension In-Reply-To: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> References: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> Message-ID: * Joan Miller: > How to escape the first '}' in the next string? > > s = "}\n{0}".format('foo') s = "}}\n{0}".format('foo') Cheers & hth., - Alf From gherron at islandtraining.com Sat Mar 6 13:41:44 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 06 Mar 2010 10:41:44 -0800 Subject: Escape curly bracket together to a variable extension In-Reply-To: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> References: <09858188-74d3-44be-b66f-1f97bca51500@33g2000yqj.googlegroups.com> Message-ID: <4B92A1E8.8020407@islandtraining.com> Joan Miller wrote: > How to escape the first '}' in the next string? > > s = "}\n{0}".format('foo') > >>> "}}\n{0}".format('foo') '}\nfoo' Gary Herron From helps4indian at gmail.com Sat Mar 6 15:47:39 2010 From: helps4indian at gmail.com (coolboy8) Date: Sat, 6 Mar 2010 12:47:39 -0800 (PST) Subject: Cash for structured settlement Message-ID: <9a25f256-c9fd-41a2-a0b2-933c42c95d8c@p3g2000pra.googlegroups.com> Visit Here http://alturl.com/vz8b From howe.steven at gmail.com Sat Mar 6 16:13:19 2010 From: howe.steven at gmail.com (Steven Howe) Date: Sat, 06 Mar 2010 13:13:19 -0800 Subject: compiler with python In-Reply-To: <4B927B23.2090009@ieee.org> References: <4B923E68.1000104@ieee.org> <4B927B23.2090009@ieee.org> Message-ID: <4B92C56F.60407@gmail.com> Is it possible he's talking about a 'quad core'? as in a CPU? In that case I think he wants to optimize a python program for a multiprocessor core with four processors. sph On 03/06/2010 07:56 AM, Dave Angel wrote: > mohamed issolah wrote: >> >> 2010/3/6 Dave Angel >> >>> mohamed issolah wrote: >>> >>>> hey, >>>> >>>> How can I construct a compiler with python just for informatiom ., >>>> I have >>>> habit to construct it with C language, >>>> >>>> sorry for my english ;-) >>>> >>>> >>> You need to tell us what you're really trying to do, what tools you're >>> willing to use, and probably why you want it. And if you're not >>> sure about >>> your English, keep the sentence structure straightforward. >>> >>> Let me make a couple of wild guesses: >>> >> >> >>> You want to design and build a compiler that takes xml information >>> as its >>> source code, and compiles those xml files into Intel x86 machine >>> code. The >>> compiler and the resulting executable needs to run on an x86 Linux >>> machine. >>> Your previous experience was in doing this sort of thing in C, but >>> you want >>> to try it with Python instead. You want to do it without using the >>> lxml >>> libraries. >>> >>> You want to build a python compiler, that takes python source code and >>> produces Java byte code files. You'd like to do this in C, but >>> don't want >>> to use any of the available existing CPython or Jython source code. >>> Your >>> goal is not to make a commercially viable product, but to learn as >>> much as >>> possible in the process. >>> >>> >>> DaveA >>> >> >> hey, >> >> I want to create a compiler which transform a code like pascal code >> (that >> what I do in C) to "quad" >> In C, I use BISON and FLEX tools. >> >> > I've forwarded your message to the list, and fixed your top-posting by > moving your response to the bottom. I don't have a clue what "quad" > is, unless it's a synonym for Forth. > > You haven't specified the OS you'll be using to run the compiler, nor > the one you're targeting, so some of these choices may not be useful. > For example, the first one is Linux only. > > http://www.freenet.org.nz/python/pybison/ > PyBison - Python binding for Bison/Flex > > http://freshmeat.net/projects/yeanpypa/ > http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html > > http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ > > Or you could go here, which has links to (most of) these and others. > http://wiki.python.org/moin/LanguageParsing > > DaveA From alfps at start.no Sat Mar 6 16:29:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Mar 2010 22:29:04 +0100 Subject: compiler with python In-Reply-To: References: <4B923E68.1000104@ieee.org> <4B927B23.2090009@ieee.org> Message-ID: Since Mohamed is talking about compilation I think it's more likely he's talking about an intermediate program represention based on quad tuples like (OP, DESTINATION, ARG1, ARG2) Cheers, - Alf * Steven Howe: > Is it possible he's talking about a 'quad core'? as in a CPU? In that > case I think he wants > to optimize a python program for a multiprocessor core with four > processors. > > sph > > > On 03/06/2010 07:56 AM, Dave Angel wrote: >> mohamed issolah wrote: >>> >>> 2010/3/6 Dave Angel >>> >>>> mohamed issolah wrote: >>>> >>>>> hey, >>>>> >>>>> How can I construct a compiler with python just for informatiom ., >>>>> I have >>>>> habit to construct it with C language, >>>>> >>>>> sorry for my english ;-) >>>>> >>>>> >>>> You need to tell us what you're really trying to do, what tools you're >>>> willing to use, and probably why you want it. And if you're not >>>> sure about >>>> your English, keep the sentence structure straightforward. >>>> >>>> Let me make a couple of wild guesses: >>>> >>> >>> >>>> You want to design and build a compiler that takes xml information >>>> as its >>>> source code, and compiles those xml files into Intel x86 machine >>>> code. The >>>> compiler and the resulting executable needs to run on an x86 Linux >>>> machine. >>>> Your previous experience was in doing this sort of thing in C, but >>>> you want >>>> to try it with Python instead. You want to do it without using the >>>> lxml >>>> libraries. >>>> >>>> You want to build a python compiler, that takes python source code and >>>> produces Java byte code files. You'd like to do this in C, but >>>> don't want >>>> to use any of the available existing CPython or Jython source code. >>>> Your >>>> goal is not to make a commercially viable product, but to learn as >>>> much as >>>> possible in the process. >>>> >>>> >>>> DaveA >>>> >>> >>> hey, >>> >>> I want to create a compiler which transform a code like pascal code >>> (that >>> what I do in C) to "quad" >>> In C, I use BISON and FLEX tools. >>> >>> >> I've forwarded your message to the list, and fixed your top-posting by >> moving your response to the bottom. I don't have a clue what "quad" >> is, unless it's a synonym for Forth. >> >> You haven't specified the OS you'll be using to run the compiler, nor >> the one you're targeting, so some of these choices may not be useful. >> For example, the first one is Linux only. >> >> http://www.freenet.org.nz/python/pybison/ >> PyBison - Python binding for Bison/Flex >> >> http://freshmeat.net/projects/yeanpypa/ >> http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html >> >> http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ >> >> Or you could go here, which has links to (most of) these and others. >> http://wiki.python.org/moin/LanguageParsing >> >> DaveA From isso.moh at gmail.com Sat Mar 6 17:00:44 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Sat, 6 Mar 2010 23:00:44 +0100 Subject: compiler with python Message-ID: hey, yes quad = quad tuple like ("+",x1,x2,temp) I work in linux example : my parser with flex : -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: token.l Type: application/octet-stream Size: 1196 bytes Desc: not available URL: From benjamin at python.org Sat Mar 6 17:13:46 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Mar 2010 16:13:46 -0600 Subject: [RELEASED] Python 3.1.2 release candidate Message-ID: <1afaf6161003061413k646e972eta515d9322793e208@mail.gmail.com> On behalf of the Python development team, I'm pleased to announce a release candidate for the second bugfix release of the Python 3.1 series, Python 3.1.2. This bug fix release fixes numerous issues found in 3.1.1. This release candidate has been released to solicit testing and feedback over an possible regressions from 3.1.1. Please consider testing it with your library or application and reporting an bugs you encounter. This will help make the final 3.1.2 release, planned in 2 weeks time, all the more stable. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.2rc1 visit: http://www.python.org/download/releases/3.1.2/ A list of changes in 3.1.2rc1 can be found here: http://svn.python.org/projects/python/tags/r312rc1/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.2's contributors) From vinay_sajip at yahoo.co.uk Sat Mar 6 17:38:57 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 6 Mar 2010 14:38:57 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> On Mar 5, 9:29?pm, Pete Emerson wrote: > > I have written my first module called "logger" that logs to syslog via > the syslog module but also allows forloggingto STDOUT in debug mode > at multiple levels (to increase verbosity depending on one's need), or > both. I've looked at theloggingmodule and while it might suit my > needs, it's overkill for me right now (I'm still *very* much a python > newbie). > Overkill in what sense? You just need to write a few lines of code to be able to use the logging package which comes with Python: import logging, logging.handlers, sys logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) logging.getLogger().addHandler(logging.handlers.SysLogHandler()) # default logs to syslog at (localhost, 514) with facility LOG_USER # you can change the default to use e.g. Unix domain sockets and a different facility So you're experienced enough and have time enough to write your own logger module, but too much of a newbie to use a module which is part of Python's included batteries? If you're writing something like logging to learn about it and what the issues are, that's fair enough. But I can't see what you mean by overkill, exactly. The three lines above (or thereabouts) will, I believe, let you log to syslog and to stdout...which is what you say you want to do. > I want to write other modules, and my thinking is that it makes sense > for those modules to use the "logger" module to do thelogging, if and > only if the parent using the other modules is also using the logger > module. > > In other words, I don't want to force someone to use the "logger" > module just so they can use my other modules, even if the "logger" > module is installed ... but I also want to take advantage of it if I'm > using it. > > Now that I've written that, I'm not sure that makes a whole lot of > sense. It seems like I could say, "hey, this person has the 'logger' > module available, let's use it!". > > Thoughts? Well, the logging package is available in Python and ready for use and pretty much battle tested, so why not use that? Are you planning to use third-party libraries in your Python work, or write everything yourself? If you are planning to use third party libraries, how would their logging be hooked into your logger module? And if not, is it good to have two logging systems in parallel? Of course as the maintainer of Python's logging package, you'd expect me to be biased in favour of it. You maybe shouldn't let that sway you ;-) Regards, Vinay Sajip From benjamin at python.org Sat Mar 6 17:41:33 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Mar 2010 16:41:33 -0600 Subject: [RELEASED] Python 2.7 alpha 4 Message-ID: <1afaf6161003061441j5621bbe7jdb8ba4c22f81f46e@mail.gmail.com> On behalf of the Python development team, I'm overjoyed to announce the fourth alpha release of Python 2.7. Python 2.7 is scheduled (by Guido and Python-dev) to be the last major version in the 2.x series. Though more major releases have not been absolutely ruled out, it's likely that the 2.7 release will an extended period of maintenance for the 2.x series. 2.7 includes many features that were first released in Python 3.1. The faster io module, the new nested with statement syntax, improved float repr, set literals, dictionary views, and the memoryview object have been backported from 3.1. Other features include an ordered dictionary implementation, unittests improvements, a new sysconfig module, and support for ttk Tile in Tkinter. For a more extensive list of changes in 2.7, see http://doc.python.org/dev/whatsnew/2.7.html or Misc/NEWS in the Python distribution. To download Python 2.7 visit: http://www.python.org/download/releases/2.7/ Please note that this is a development release, intended as a preview of new features for the community, and is thus not suitable for production use. The 2.7 documentation can be found at: http://docs.python.org/2.7 Please consider trying Python 2.7 with your code and reporting any bugs you may notice to: http://bugs.python.org Enjoy! -- Benjamin Peterson 2.7 Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From rantingrick at gmail.com Sat Mar 6 17:46:29 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 6 Mar 2010 14:46:29 -0800 (PST) Subject: Sample code usable Tkinter listbox References: Message-ID: <95cc4ed4-20fa-4198-a354-d6734083c2d7@g11g2000yqe.googlegroups.com> Opps: found a few errors in that last ScrolledListbox class, try this one... import Tkinter as tk from Tkconstants import * class ScrolledList(tk.Listbox): def __init__(self, master, **kw): self.frame = tk.Frame(master) self.frame.rowconfigure(0, weight=1) self.frame.columnconfigure(0, weight=1) self.hbar = tk.Scrollbar(self.frame, orient=HORIZONTAL) self.block = tk.Frame(self.frame, width=18, height=18) self.block.grid(row=1, column=1) self.vbar = tk.Scrollbar(self.frame, orient=VERTICAL) kw.setdefault('activestyle', 'none') kw.setdefault('highlightthickness', 0) kw.setdefault('pack', 0) if kw.pop('pack') == 1: self.frame.pack(fill=BOTH, expand=1) tk.Listbox.__init__(self, self.frame, **kw) self.grid(row=0, column=0, sticky=N+S+E+W) self.hbar.configure(command=self.xview) self.vbar.configure(command=self.yview) self.config( yscrollcommand=self.vbar.set, xscrollcommand=self.hbar.set ) self.hbar.grid(row=1, column=0, sticky=W+E) self.vbar.grid(row=0, column=1, sticky=N+S) self.pack = lambda **kw: self.frame.pack(**kw) self.grid = lambda **kw: self.frame.grid(**kw) self.place = lambda **kw: self.frame.place(**kw) self.pack_config = lambda **kw: self.frame.pack_config(**kw) self.grid_config = lambda **kw: self.frame.grid_config(**kw) self.place_config = lambda **kw: self.frame.place_config(**kw) self.pack_configure = lambda **kw: self.frame.pack_config(**kw) self.grid_configure = lambda **kw: self.frame.grid_config(**kw) self.place_configure = lambda **kw: self.frame.place_config(**kw) def gets(self): return self.get(0, END) def sets(self, arg): self.delete(0, END) try: arg = arg.strip('\n').splitlines() except AttributeError: pass if hasattr(arg, '__getitem__'): for item in arg: self.insert(END, str(item)) else: raise TypeError("Scrolledlist.sets() requires a string or iterable of strings") if __name__ == '__main__': root = tk.Tk() listbox = ScrolledList(root, width=50, height=10, pack=1) #listbox.sets(1.25) #listbox.sets('1\n2\n3\n4\n5\n\n\n') listbox.sets(range(100)) #listbox.grid(row=0, column=0) root.mainloop() From pemerson at gmail.com Sat Mar 6 18:13:33 2010 From: pemerson at gmail.com (Pete Emerson) Date: Sat, 6 Mar 2010 15:13:33 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> Message-ID: <9c6a8d26-b71e-4cb8-92d0-49af8728bec4@u15g2000prd.googlegroups.com> On Mar 6, 2:38?pm, Vinay Sajip wrote: > On Mar 5, 9:29?pm, Pete Emerson wrote: > > > > > I have written my first module called "logger" that logs to syslog via > > the syslog module but also allows forloggingto STDOUT in debug mode > > at multiple levels (to increase verbosity depending on one's need), or > > both. I've looked at theloggingmodule and while it might suit my > > needs, it's overkill for me right now (I'm still *very* much a python > > newbie). > > Overkill in what sense? You just need to write a few lines of code to > be able to use the logging package which comes with Python: > > import logging, logging.handlers, sys > logging.basicConfig(level=logging.DEBUG, stream=sys.stdout) > logging.getLogger().addHandler(logging.handlers.SysLogHandler()) > # default logs to syslog at (localhost, 514) with facility LOG_USER > # you can change the default to use e.g. Unix domain sockets and a > different facility > > So you're experienced enough and have time enough to write your own > logger module, but too much of a newbie to use a module which is part > of Python's included batteries? If you're writing something like > logging to learn about it and what the issues are, that's fair enough. > But I can't see what you mean by overkill, exactly. The three lines > above (or thereabouts) will, I believe, let you log to syslog and to > stdout...which is what you say you want to do. > > > I want to write other modules, and my thinking is that it makes sense > > for those modules to use the "logger" module to do thelogging, if and > > only if the parent using the other modules is also using the logger > > module. > > > In other words, I don't want to force someone to use the "logger" > > module just so they can use my other modules, even if the "logger" > > module is installed ... but I also want to take advantage of it if I'm > > using it. > > > Now that I've written that, I'm not sure that makes a whole lot of > > sense. It seems like I could say, "hey, this person has the 'logger' > > module available, let's use it!". > > > Thoughts? > > Well, the logging package is available in Python and ready for use and > pretty much battle tested, so why not use that? Are you planning to > use third-party libraries in your Python work, or write everything > yourself? If you are planning to use third party libraries, how would > their logging be hooked into your logger module? And if not, is it > good to have two logging systems in parallel? > > Of course as the maintainer of Python's logging package, you'd expect > me to be biased in favour of it. You maybe shouldn't let that sway > you ;-) > > Regards, > > Vinay Sajip Thanks for your insights, Vinay, and thank you also for writing packages such as logging. The word 'overkill' was a poor choice on my part! I should have said, "I don't quite understand the logging module yet, but I am comfortable with the syslog module's two functions, openlog and syslog". I wrote my own logger module *partly* to gain the experience, and partly to do the following: 1) In debug mode, send what would have gone to syslog to STDOUT or STDERR 2) In non-debug mode, use /dev/log or localhost:514 depending on what is set 3) Allow for multiple levels of logging beyond INFO, WARNING, CRIT ... essentially allow multiple levels of INFO depending on how much detail is desired. A high level of messaging when programs are running poorly is desired, but when programs are running smoothly, I don't need to send as much to syslog. I started in with your logging package, but I think I simply got ahead of myself. I definitely agree that writing my own wrappers around syslog to do what I want might be a duplication of effort. At this point I think I'm ready to go back to your logging package and see what I can do; if you have words of advice regarding 1-3 above, I'd certainly appreciate it. Now I'll go to your example above and see what it does. Thank you! Pete From igouy2 at yahoo.com Sat Mar 6 18:53:25 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 15:53:25 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? Message-ID: At the command prompt: python b.py 8 works fine on both XP and Vista python b.python 8 works on XP (and Linux) but on Vista python b.python 8 ImportError: No module named b ? From news123 at free.fr Sat Mar 6 18:53:39 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 00:53:39 +0100 Subject: async notification handling w/o threads/polling (similiar to kill -hup)? Message-ID: <4b92eb03$0$22022$426a74cc@news.free.fr> Hi, I'd like to notify python processes asynchronously. at notification time a callback should be called The solution should be working on linux and Windows. I could add a wrapper to switch between a windows / linux implementation though If possible I'd like to avoid - having to poll for an external event - having to add a thread. - changing my existing code I thought about using signal and os.kill() However windows does not to have SIGHUP , SIGUSR1 or SIGUSR2. So I'm not sure, which signal I could use with windows. Apart from that there's one minor problem with signals which might speak against using signal All blocking io calls might be interrupted, which is not desirable in my case. Do you have any suggestions for Linux / WIndows or both? #### example code with signals ################# #### a blocking io call here reading a named pipe #### would be interrupted import signal a = 0 def handler(signum,frame): global a a += 1 signal.signal(signal.SIGUSR1,handler) print "hi" p = open("namedpipe") while True: v = p.read(2) print "V:",a,len(v) if len(v) != 2: break print "var a changed, but read() was interrupted :-(" bye N From clp2 at rebertia.com Sat Mar 6 19:02:43 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Mar 2010 16:02:43 -0800 Subject: python b.python 8 works on XP but not on Vista? In-Reply-To: References: Message-ID: <50697b2c1003061602y31e26526q878f0c5a9e5573c5@mail.gmail.com> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > At the command prompt: > > ? python b.py 8 > works fine on both XP and Vista > > ? python b.python 8 > works on XP (and Linux) > > but on Vista > > ? python b.python 8 > > ImportError: No module named b > > ? Code please. Also, .python is not a standard extension for Python files, so why are you using it anyway? Cheers, Chris -- http://blog.rebertia.com From news123 at free.fr Sat Mar 6 19:17:25 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 01:17:25 +0100 Subject: async notification handling w/o threads/polling (similiar to kill -hup)? In-Reply-To: <4b92eb03$0$22022$426a74cc@news.free.fr> References: <4b92eb03$0$22022$426a74cc@news.free.fr> Message-ID: <4b92f095$0$20648$426a74cc@news.free.fr> News123 wrote: > Hi, > > I'd like to notify python processes asynchronously. > at notification time a callback should be called > > The solution should be working on linux and Windows. > > I could add a wrapper to switch between a windows / linux implementation > though > > If possible I'd like to avoid > - having to poll for an external event > - having to add a thread. Well having a blocking thread would be fine though. what I'd really want to avoid is any polling. > - changing my existing code > > I thought about using signal and os.kill() > However windows does not to have SIGHUP , SIGUSR1 or SIGUSR2. > So I'm not sure, which signal I could use with windows. > > > Apart from that there's one minor problem with signals > which might speak against using signal > All blocking io calls might be interrupted, which is not desirable in my > case. > > Do you have any suggestions for > Linux / WIndows or both? > > > #### example code with signals ################# > #### a blocking io call here reading a named pipe > #### would be interrupted > import signal > a = 0 > def handler(signum,frame): > global a > a += 1 > > signal.signal(signal.SIGUSR1,handler) > print "hi" > p = open("namedpipe") > while True: > v = p.read(2) > print "V:",a,len(v) > if len(v) != 2: break > > print "var a changed, but read() was interrupted :-(" > > > bye > > > N From igouy2 at yahoo.com Sat Mar 6 19:42:42 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 16:42:42 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? References: Message-ID: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> On Mar 6, 4:02?pm, Chris Rebert wrote: > On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > > At the command prompt: > > > ? python b.py 8 > > works fine on both XP and Vista > > > ? python b.python 8 > > works on XP (and Linux) > > > but on Vista > > > ? python b.python 8 > > > ImportError: No module named b > > > ? > > Code please. It's the same code in both cases, I simply renamed "b.python" as "b.py" as a test. > Also, .python is not a standard extension for Python > files, so why are you using it anyway? Because it's useful for what I'm doing. Given python 2.6.4 has no problem with a non-standard extension on MS XP and Linux - why does python 2.6.4 have this problem with a non- standard extension on MS Vista? From timr at probo.com Sat Mar 6 19:49:33 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 06 Mar 2010 16:49:33 -0800 Subject: indentation error References: Message-ID: asit wrote: > >According to me, indentation is ok. but the python interpreter gives >an indentation error > >[asit ~/py] $ python search.py > File "search.py", line 7 > findResults = string.split(commandOutput, "\n") > ^ >IndentationError: unindent does not match any outer indentation level The most likely cause is mixing spaces with tabs. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clp2 at rebertia.com Sat Mar 6 19:53:30 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 6 Mar 2010 16:53:30 -0800 Subject: python b.python 8 works on XP but not on Vista? In-Reply-To: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> Message-ID: <50697b2c1003061653g14a3584if8358500149a2715@mail.gmail.com> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: > On Mar 6, 4:02?pm, Chris Rebert wrote: >> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: >> > At the command prompt: >> >> > ? python b.py 8 >> > works fine on both XP and Vista >> >> > ? python b.python 8 >> > works on XP (and Linux) >> >> > but on Vista >> >> > ? python b.python 8 >> >> > ImportError: No module named b >> >> > ? >> >> Code please. > > > It's the same code in both cases, I simply renamed "b.python" as > "b.py" as a test. The code in b.py matters. I /suspect/ it's importing itself somehow (probably indirectly), and Python doesn't look for ".python" files when importing, so it fails with an ImportError. But since you haven't shown the code, I can only guess. For that matter, the full exception Traceback would be more helpful than the code; please include it as well. Cheers, Chris -- http://blog.rebertia.com From igouy2 at yahoo.com Sat Mar 6 20:23:37 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 17:23:37 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> Message-ID: <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> On Mar 6, 4:53?pm, Chris Rebert wrote: > On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: > > On Mar 6, 4:02?pm, Chris Rebert wrote: > >> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > >> > At the command prompt: > > >> > ? python b.py 8 > >> > works fine on both XP and Vista > > >> > ? python b.python 8 > >> > works on XP (and Linux) > > >> > but on Vista > > >> > ? python b.python 8 > > >> > ImportError: No module named b > > >> > ? > > >> Code please. > > > It's the same code in both cases, I simply renamed "b.python" as > > "b.py" as a test. > > The code in b.py matters. I /suspect/ it's importing itself somehow > (probably indirectly), and Python doesn't look for ".python" files > when importing, so it fails with an ImportError. But since you haven't > shown the code, I can only guess. Yes the code in b.py matters. Why it matters is that there was another difference between XP and Vista - the XP machine was single core but the Vista machine was multi core - and the code behaves differently in each case. Thanks. From ssteinerx at gmail.com Sat Mar 6 21:10:02 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 6 Mar 2010 21:10:02 -0500 Subject: python b.python 8 works on XP but not on Vista? In-Reply-To: <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> Message-ID: On Mar 6, 2010, at 8:23 PM, Isaac Gouy wrote: > On Mar 6, 4:53 pm, Chris Rebert wrote: >> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: >>> On Mar 6, 4:02 pm, Chris Rebert wrote: >>>> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: >>>>> At the command prompt: >> >>>>> python b.py 8 >>>>> works fine on both XP and Vista >> >>>>> python b.python 8 >>>>> works on XP (and Linux) >> >>>>> but on Vista >> >>>>> python b.python 8 >> >>>>> ImportError: No module named b >> >>>>> ? >> >>>> Code please. >> >>> It's the same code in both cases, I simply renamed "b.python" as >>> "b.py" as a test. >> >> The code in b.py matters. I /suspect/ it's importing itself somehow >> (probably indirectly), and Python doesn't look for ".python" files >> when importing, so it fails with an ImportError. But since you haven't >> shown the code, I can only guess. > > Yes the code in b.py matters. > > Why it matters is that there was another difference between XP and > Vista - the XP machine was single core but the Vista machine was multi > core - and the code behaves differently in each case. Yes, and the XP machine's case was blue, therefore case color is important, too. S From steve at REMOVE-THIS-cybersource.com.au Sat Mar 6 21:50:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 02:50:02 GMT Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> Message-ID: <4b93145a$0$8816$c3e8da3@news.astraweb.com> On Sat, 06 Mar 2010 21:10:02 -0500, ssteinerX at gmail.com wrote: > On Mar 6, 2010, at 8:23 PM, Isaac Gouy wrote: > >> On Mar 6, 4:53 pm, Chris Rebert wrote: >>> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: >>>> On Mar 6, 4:02 pm, Chris Rebert wrote: >>>>> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: >>>>>> At the command prompt: >>> >>>>>> python b.py 8 >>>>>> works fine on both XP and Vista >>> >>>>>> python b.python 8 >>>>>> works on XP (and Linux) >>> >>>>>> but on Vista >>> >>>>>> python b.python 8 >>> >>>>>> ImportError: No module named b >>> >>>>>> ? >>> >>>>> Code please. >>> >>>> It's the same code in both cases, I simply renamed "b.python" as >>>> "b.py" as a test. >>> >>> The code in b.py matters. I /suspect/ it's importing itself somehow >>> (probably indirectly), and Python doesn't look for ".python" files >>> when importing, so it fails with an ImportError. But since you haven't >>> shown the code, I can only guess. >> >> Yes the code in b.py matters. >> >> Why it matters is that there was another difference between XP and >> Vista - the XP machine was single core but the Vista machine was multi >> core - and the code behaves differently in each case. > > Yes, and the XP machine's case was blue, therefore case color is > important, too. Don't forget that the XP machine was on the left hand side of the desk, and the Vista machine on the right. I suspect Isaac needs to physically move the Vista machine to the left side, and it will work perfectly. Either that, or stop pissing around and show us the actual stack trace so we can actually help. Isaac, stop *guessing* what the problem is. If you have to guess, try to make your guesses realistic. It's not likely anything to do with the CPU. If anything, Python's search path is different on your Vista and XP machines. -- Steven From igouy2 at yahoo.com Sat Mar 6 22:04:56 2010 From: igouy2 at yahoo.com (Isaac Gouy) Date: Sat, 6 Mar 2010 19:04:56 -0800 (PST) Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> <4b93145a$0$8816$c3e8da3@news.astraweb.com> Message-ID: On Mar 6, 6:50?pm, Steven D'Aprano wrote: > On Sat, 06 Mar 2010 21:10:02 -0500, sstein... at gmail.com wrote: > > On Mar 6, 2010, at 8:23 PM, Isaac Gouy wrote: > > >> On Mar 6, 4:53 pm, Chris Rebert wrote: > >>> On Sat, Mar 6, 2010 at 4:42 PM, Isaac Gouy wrote: > >>>> On Mar 6, 4:02 pm, Chris Rebert wrote: > >>>>> On Sat, Mar 6, 2010 at 3:53 PM, Isaac Gouy wrote: > >>>>>> At the command prompt: > > >>>>>> ? python b.py 8 > >>>>>> works fine on both XP and Vista > > >>>>>> ? python b.python 8 > >>>>>> works on XP (and Linux) > > >>>>>> but on Vista > > >>>>>> ? python b.python 8 > > >>>>>> ImportError: No module named b > > >>>>>> ? > > >>>>> Code please. > > >>>> It's the same code in both cases, I simply renamed "b.python" as > >>>> "b.py" as a test. > > >>> The code in b.py matters. I /suspect/ it's importing itself somehow > >>> (probably indirectly), and Python doesn't look for ".python" files > >>> when importing, so it fails with an ImportError. But since you haven't > >>> shown the code, I can only guess. > > >> Yes the code in b.py matters. > > >> Why it matters is that there was another difference between XP and > >> Vista - the XP machine was single core but the Vista machine was multi > >> core - and the code behaves differently in each case. > > > Yes, and the XP machine's case was blue, therefore case color is > > important, too. > > Don't forget that the XP machine was on the left hand side of the desk, > and the Vista machine on the right. I suspect Isaac needs to physically > move the Vista machine to the left side, and it will work perfectly. > > Either that, or stop pissing around and show us the actual stack trace so > we can actually help. Isaac, stop *guessing* what the problem is. > > If you have to guess, try to make your guesses realistic. It's not likely > anything to do with the CPU. If anything, Python's search path is > different on your Vista and XP machines. > > -- > Steven That was "Thanks." as in problem solved. When the code switches on multiprocessing.cpu_count() - single core vs multicore matters. From sumerc at gmail.com Sat Mar 6 22:51:38 2010 From: sumerc at gmail.com (k3xji) Date: Sat, 6 Mar 2010 19:51:38 -0800 (PST) Subject: yappi v0.42 released Message-ID: <4795dfc3-e852-4466-bfe6-c39ef4a900ce@q15g2000yqj.googlegroups.com> Hi all, yappi(yet another python profiler with multithreading support) released. See: http://code.google.com/p/yappi/ Thanks, From steve at REMOVE-THIS-cybersource.com.au Sat Mar 6 23:23:13 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 04:23:13 GMT Subject: python b.python 8 works on XP but not on Vista? References: <5e6d069d-9116-4a53-914e-594b656c4269@q2g2000pre.googlegroups.com> <226a6de2-4626-4a5d-9653-6211284c9ce4@t31g2000prh.googlegroups.com> <4b93145a$0$8816$c3e8da3@news.astraweb.com> Message-ID: <4b932a30$0$8816$c3e8da3@news.astraweb.com> On Sat, 06 Mar 2010 19:04:56 -0800, Isaac Gouy wrote: > That was "Thanks." as in problem solved. > > When the code switches on multiprocessing.cpu_count() - single core vs > multicore matters. I'm glad you solved your problem. Out of curiosity, what was the fault? Not the condition that leads to the fault, but the actual fault? My guess is that it was a difference in sys.path, leading to the b module not being found. Am I close? -- Steven From ping.nsr.yeh at gmail.com Sun Mar 7 01:53:40 2010 From: ping.nsr.yeh at gmail.com (Ping) Date: Sat, 6 Mar 2010 22:53:40 -0800 (PST) Subject: Asynchronous HTTP client Message-ID: Hi, I'm trying to find a way to create an asynchronous HTTP client so I can get responses from web servers in a way like async_http_open('http://example.com/', callback_func) # immediately continues, and callback_func is called with response as arg when it is ready It seems twisted can do it, but I hesitate to bring in such a big package as a dependency because my client should be light. Asyncore and asynchat are lighter but they don't speak HTTP. The asynchttp project on sourceforge is a fusion between asynchat and httplib, but it hasn't been updated since 2001 and is seriously out of sync with httplib. I'd appreciate it if anyone can shed some lights on this. Thanks, Ping From breamoreboy at yahoo.co.uk Sun Mar 7 04:33:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Mar 2010 09:33:22 +0000 Subject: best practices: is collections.defaultdict my friend or not? In-Reply-To: <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> References: <20100306031003.1018aab2@geekmail.INVALID> <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> Message-ID: Pete Emerson wrote: > On Mar 5, 6:10 pm, Andreas Waldenburger > wrote: >> On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson >> >> >> >> >> >> wrote: >>> [snip] >>>>>> data['one'] = {} >>>>>> data['one']['two'] = 'three' >>>>>> print data >>> {'one': {'two': 'three'}} >>> And through some research, I discovered collections.defaultdict (new >>> in Python 2.5, FWIW): >>>>>> import collections >>>>>> data = collections.defaultdict(dict) >>>>>> data['one']['two'] = 'three' >>>>>> print data >>> defaultdict(, {'one': {'two': 'three'}}) >>> [snip] >>> Your thoughts and comments are very much appreciated. I think my brain >>> already knows some of the answers, but my heart ... well, perl and I >>> go way back. Loving python so far, though. >> Oh, by the way: That defaultdict route is a pretty solid solution. Not >> sure what problem you're trying to solve -- depending on your usecase, >> there might be a better approach. >> >> If you're just asking hypothetically and you're trying to apply a >> Perl idiom to Python, there probably *is* a better solution. >> >> /W >> >> -- >> INVALID? DE! > > I found out about the need to declare the higher level as I was > reading in a JSON struct into a dict and then adding a new entry at a > lower level. Mostly just proof of concept stuff as I'm learning > python. I'm not sure that the use of defaultdict is really warranted > for me anywhere just yet. Mostly, I don't want to convert my perl to > python, that seems very counterproductive. Thank you very much for > your insight. > > I was a little frightened of doing "import this" ("Hey, kid, run rm - > rf / and see what happens!"), but did, and the words are wise. :) > > Pete After reading the words of wisdom try "import this" a second time and watch what happens, it's quite interesting if you're not expecting the output. Mark Lawrence. From contact at xavierho.com Sun Mar 7 04:59:00 2010 From: contact at xavierho.com (Xavier Ho) Date: Sun, 7 Mar 2010 19:59:00 +1000 Subject: Curiosity stirkes me on 'import this'. Message-ID: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> I took a look at the 'this' module to see where the file is stored. This is probably old news to some people, but was new to me. print this.s Gur Mra bs Clguba, ol Gvz Crgref Ornhgvshy vf orggre guna htyl. Rkcyvpvg vf orggre guna vzcyvpvg. Fvzcyr vf orggre guna pbzcyrk. Pbzcyrk vf orggre guna pbzcyvpngrq. Syng vf orggre guna arfgrq. Fcnefr vf orggre guna qrafr. Ernqnovyvgl pbhagf. Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf. Nygubhtu cenpgvpnyvgl orngf chevgl. Reebef fubhyq arire cnff fvyragyl. Hayrff rkcyvpvgyl fvyraprq. Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff. Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg. Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu. Abj vf orggre guna arire. Nygubhtu arire vf bsgra orggre guna *evtug* abj. Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn. Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn. Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr! And some other attributes in 'this' module as well, that decodes the string. I'm curious. Was this encoded purely for fun? *grins* Cheers, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: contact at xavierho.com Website: http://xavierho.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From peloko45 at gmail.com Sun Mar 7 05:32:28 2010 From: peloko45 at gmail.com (Joan Miller) Date: Sun, 7 Mar 2010 02:32:28 -0800 (PST) Subject: Problem with regular expression Message-ID: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> I would to convert the first string to upper case. But this regular expression is not matching the first string between quotes. re.sub("'(?P\w+)': [^{]", "\gFOO", str) # string to non-matching 'foo': { # strings to matching 'bar': 'bar2' 'bar': None 'bar': 0 'bar': True So, i.e., from the first string I would to get: 'BAR': 'bar2' Any help? please Thanks in advance From steve at holdenweb.com Sun Mar 7 07:34:41 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Mar 2010 07:34:41 -0500 Subject: Conditional based on whether or not a module is being used In-Reply-To: <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> Message-ID: Vinay Sajip wrote: [...] > Well, the logging package is available in Python and ready for use and > pretty much battle tested, so why not use that? Are you planning to > use third-party libraries in your Python work, or write everything > yourself? If you are planning to use third party libraries, how would > their logging be hooked into your logger module? And if not, is it > good to have two logging systems in parallel? > > Of course as the maintainer of Python's logging package, you'd expect > me to be biased in favour of it. You maybe shouldn't let that sway > you ;-) > Vinay: My own impression of the logging module, formed from trying to use its documentation in the past, is that it's somewhat unapproachable, and difficult to use for simple purposes. I am happy to say that now I see the current (3.1) documentation it has improved to the point where I would be happy to try using it again. Thanks for your long-term maintenance of this package. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From news123 at free.fr Sun Mar 7 07:52:13 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 13:52:13 +0100 Subject: Problem with regular expression In-Reply-To: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: <4b93a17d$0$22009$426a74cc@news.free.fr> Hi Joan, Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > > re.sub("'(?P\w+)': [^{]", "\gFOO", str) > > # string to non-matching > 'foo': { > > # strings to matching > 'bar': 'bar2' > 'bar': None > 'bar': 0 > 'bar': True > > So, i.e., from the first string I would to get: > 'BAR': 'bar2' > I'm a little slow today and don't exactly understand your question. Could you perhaps add some examples of input lines and what you would like to extract? example: input = "first word to Upper" output = "FIRST word to Upper" bye N > > Any help? please > Thanks in advance From steve at holdenweb.com Sun Mar 7 08:03:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Mar 2010 08:03:08 -0500 Subject: Problem with regular expression In-Reply-To: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > > re.sub("'(?P\w+)': [^{]", "\gFOO", str) > > # string to non-matching > 'foo': { > > # strings to matching > 'bar': 'bar2' > 'bar': None > 'bar': 0 > 'bar': True > > So, i.e., from the first string I would to get: > 'BAR': 'bar2' > > > Any help? please > Thanks in advance Well your pattern is identifying the right bits, but re.sub() replaces everything it matches: >>> import re >>> strings = """\ ... 'bar': 'bar2' ... 'bar': None ... 'bar': 0 ... 'bar': True""".split("\n") >>> for s in strings: ... print re.sub("'(?P\w+)': [^{]", "\gFOO", s) ... barFOObar2' barFOOone barFOO barFOOrue >>> What you need to fix is the replacement. Take a look at the documentation for re.sub: you will need to provide a function to apply the upper-case transformation, and the example there should show you how. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From lie.1296 at gmail.com Sun Mar 7 08:12:23 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 08 Mar 2010 00:12:23 +1100 Subject: Asynchronous HTTP client In-Reply-To: References: Message-ID: <4b93a660$1@dnews.tpgi.com.au> On 03/07/2010 05:53 PM, Ping wrote: > Hi, > > I'm trying to find a way to create an asynchronous HTTP client so I > can get responses from web servers in a way like > > async_http_open('http://example.com/', callback_func) > # immediately continues, and callback_func is called with response > as arg when it is ready > > It seems twisted can do it, but I hesitate to bring in such a big > package as a dependency because my client should be light. Asyncore > and asynchat are lighter but they don't speak HTTP. The asynchttp > project on sourceforge is a fusion between asynchat and httplib, but > it hasn't been updated since 2001 and is seriously out of sync with > httplib. > > I'd appreciate it if anyone can shed some lights on this. If you want something quite lightweight, you can spawn a thread for the call: import threading, urllib class AsyncOpen(threading.Thread): def __init__(self, url, callback): super(AsyncOpen, self).__init__() self.url = url self.callback = callback def run(self): # of course change urllib to httplib-something-something content = urllib.urlopen(self.url).read() self.callback(content) def asyncopen(url, callback): AsyncOpen(url, callback).start() def cb(content): print content asyncopen('http://www.google.com', cb) From exarkun at twistedmatrix.com Sun Mar 7 08:16:04 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 07 Mar 2010 13:16:04 -0000 Subject: Asynchronous HTTP client In-Reply-To: References: Message-ID: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> On 06:53 am, ping.nsr.yeh at gmail.com wrote: >Hi, > >I'm trying to find a way to create an asynchronous HTTP client so I >can get responses from web servers in a way like > > async_http_open('http://example.com/', callback_func) > # immediately continues, and callback_func is called with response >as arg when it is ready > >It seems twisted can do it, but I hesitate to bring in such a big >package as a dependency because my client should be light. Asyncore >and asynchat are lighter but they don't speak HTTP. The asynchttp >project on sourceforge is a fusion between asynchat and httplib, but >it hasn't been updated since 2001 and is seriously out of sync with >httplib. Why should it be "light"? In what way would using Twisted cause problems for you? Jean-Paul From python.list at tim.thechases.com Sun Mar 7 08:35:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Mar 2010 07:35:31 -0600 Subject: Problem with regular expression In-Reply-To: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: <4B93ABA3.7090608@tim.thechases.com> Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > > re.sub("'(?P\w+)': [^{]", "\gFOO", str) Well, my first thought is that you're not using raw strings, so you're not using the regexps and replacements you think you are. r"'(?P\w+)': [^{]" will match the lines of interest. The replacement will eat the opening & closing single-quote, colon, and first character. > # string to non-matching > 'foo': { > > # strings to matching > 'bar': 'bar2' > 'bar': None > 'bar': 0 > 'bar': True > > So, i.e., from the first string I would to get: > 'BAR': 'bar2' I think you'd have to use a function/lambda to do the case-conversion: re.sub( r"'(?P\w+)(?=': [^{])", lambda m: "'" + m.group('id').upper(), string_of_interest ) Or you could just forgo regexps and use regular string functions like split(), startswith(), and upper() -tkc From googler.1.webmaster at spamgourmet.com Sun Mar 7 08:50:59 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sun, 7 Mar 2010 05:50:59 -0800 (PST) Subject: time_struct Message-ID: <23dbe409-60ed-4f6f-bd38-4336e4f1b3d0@f8g2000yqn.googlegroups.com> Hi, can anyone tell me how to return a time_struct from the timemodule in my own C-Module? Is that possible? I can just find one function in timefuncs.h, but it doesnt return any PyObject. Thanks in advance. moerchendiser2k3 From ptmcg at austin.rr.com Sun Mar 7 09:10:55 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sun, 7 Mar 2010 06:10:55 -0800 (PST) Subject: Problem with regular expression References: <2dd22712-057a-42a7-9f21-349a56094339@c16g2000yqd.googlegroups.com> Message-ID: <2694479f-fce9-48ff-9264-fa35fdf103b3@z35g2000yqd.googlegroups.com> On Mar 7, 4:32?am, Joan Miller wrote: > I would to convert the first string to upper case. But this regular > expression is not matching the first string between quotes. > Is using pyparsing overkill? Probably. But your time is valuable, and pyparsing let's you knock this out in less time than it probably took to write your original post. Use pyparsing's pre-defined expression sglQuotedString to match your entry key in quotes: key = sglQuotedString Add a parse action to convert to uppercase: key.setParseAction(lambda tokens:tokens[0].upper()) Now define the rest of your entry value (be sure to add the negative lookahead so we *don't* match your foo entry): entry = key + ":" + ~Literal("{") If I put your original test cases into a single string named 'data', I can now use transformString to convert all of your keys that don't point to '{'ed values: print entry.transformString(data) Giving me: # string to non-matching 'foo': { # strings to matching 'BAR': 'bar2' 'BAR': None 'BAR': 0 'BAR': True Here's the whole script: from pyparsing import sglQuotedString, Literal key = sglQuotedString key.setParseAction(lambda tokens:tokens[0].upper()) entry = key + ":" + ~Literal("{") print entry.transformString(data) And I'll bet that if you come back to this code in 3 months, you'll still be able to figure out what it does! -- Paul From ping.nsr.yeh at gmail.com Sun Mar 7 09:40:36 2010 From: ping.nsr.yeh at gmail.com (pingooo) Date: Sun, 7 Mar 2010 22:40:36 +0800 Subject: Asynchronous HTTP client In-Reply-To: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> References: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> Message-ID: <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> 2010/3/7 > On 06:53 am, ping.nsr.yeh at gmail.com wrote: > >> Hi, >> >> I'm trying to find a way to create an asynchronous HTTP client so I >> can get responses from web servers in a way like >> >> async_http_open('http://example.com/', callback_func) >> # immediately continues, and callback_func is called with response >> as arg when it is ready >> >> It seems twisted can do it, but I hesitate to bring in such a big >> package as a dependency because my client should be light. Asyncore >> and asynchat are lighter but they don't speak HTTP. The asynchttp >> project on sourceforge is a fusion between asynchat and httplib, but >> it hasn't been updated since 2001 and is seriously out of sync with >> httplib. >> > > Why should it be "light"? In what way would using Twisted cause problems > for you? > > Jean-Paul > I'm writing an open source python client for a web service. The client may be used in all kinds of environments - Linux, Mac OS X, Windows, web hosting, etc by others. It is not impossible to have twisted as a dependency, but that makes deployment a larger job than simply uploading a Python file. I'm willing to use twisted, but I'd like to explore lighter alternatives first. Thanks, Ping -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun Mar 7 09:57:02 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 07 Mar 2010 15:57:02 +0100 Subject: compiler with python In-Reply-To: References: Message-ID: mohamed issolah, 06.03.2010 14:07: > I want to create a compiler which transform a code like pascal code (that > what I do in C) to "quad" > In C, I use BISON and FLEX tools. Hi, please stop starting new threads for the same topic. Instead, reply to responses you get. Stefan From exarkun at twistedmatrix.com Sun Mar 7 09:57:07 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sun, 07 Mar 2010 14:57:07 -0000 Subject: Asynchronous HTTP client In-Reply-To: <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> References: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> Message-ID: <20100307145707.2792.1316685222.divmod.xquotient.1369@localhost.localdomain> On 02:40 pm, ping.nsr.yeh at gmail.com wrote: >2010/3/7 >>On 06:53 am, ping.nsr.yeh at gmail.com wrote: >>>Hi, >>> >>>I'm trying to find a way to create an asynchronous HTTP client so I >>>can get responses from web servers in a way like >>> >>> async_http_open('http://example.com/', callback_func) >>> # immediately continues, and callback_func is called with response >>>as arg when it is ready >>> >>>It seems twisted can do it, but I hesitate to bring in such a big >>>package as a dependency because my client should be light. Asyncore >>>and asynchat are lighter but they don't speak HTTP. The asynchttp >>>project on sourceforge is a fusion between asynchat and httplib, but >>>it hasn't been updated since 2001 and is seriously out of sync with >>>httplib. >> >>Why should it be "light"? In what way would using Twisted cause >>problems >>for you? >> >>Jean-Paul > >I'm writing an open source python client for a web service. The client >may >be used in all kinds of environments - Linux, Mac OS X, Windows, web >hosting, etc by others. It is not impossible to have twisted as a >dependency, but that makes deployment a larger job than simply >uploading a >Python file. Twisted is packaged for many Linux distributions (perhaps most of them). Many web hosts provide it. It's also shipped with OS X. Windows may be an issue, but note that there's a binary Windows installer (as of 10.0, an MSI, so installation can be easily automated). >I'm willing to use twisted, but I'd like to explore lighter >alternatives >first. Jean-Paul From vicente.soler at gmail.com Sun Mar 7 10:05:26 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 07:05:26 -0800 (PST) Subject: a simple def how-to Message-ID: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Hello, My script starts like this: book=readFromExcelRange('book') house=readFromExcelRange('house') table=readFromExcelRange('table') read=readFromExcelRange('read') ... But I would like to have something equivalent, like... ranges=['book','house','table','read'] for i in ranges: var[i]=readFromExcelRange(i) which does not work. I assume I should be using globals() instead of var, but I do not know how to write my script. Can anybody help? From breamoreboy at yahoo.co.uk Sun Mar 7 10:16:25 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Mar 2010 15:16:25 +0000 Subject: compiler with python In-Reply-To: References: <4B923E68.1000104@ieee.org> <4B927B23.2090009@ieee.org> Message-ID: Alf and Steven Howe, please don't top post, it makes it all but impossible to follow a thread. Darn!:) Mark Lawrence. Alf P. Steinbach wrote: > Since Mohamed is talking about compilation I think it's more likely he's > talking about an intermediate program represention based on quad tuples > like > > (OP, DESTINATION, ARG1, ARG2) > > Cheers, > > - Alf > > > * Steven Howe: >> Is it possible he's talking about a 'quad core'? as in a CPU? In that >> case I think he wants >> to optimize a python program for a multiprocessor core with four >> processors. >> >> sph >> >> >> On 03/06/2010 07:56 AM, Dave Angel wrote: >>> mohamed issolah wrote: >>>> >>>> 2010/3/6 Dave Angel >>>> >>>>> mohamed issolah wrote: >>>>> >>>>>> hey, >>>>>> >>>>>> How can I construct a compiler with python just for informatiom ., >>>>>> I have >>>>>> habit to construct it with C language, >>>>>> >>>>>> sorry for my english ;-) >>>>>> >>>>>> >>>>> You need to tell us what you're really trying to do, what tools you're >>>>> willing to use, and probably why you want it. And if you're not >>>>> sure about >>>>> your English, keep the sentence structure straightforward. >>>>> >>>>> Let me make a couple of wild guesses: >>>>> >>>> >>>> >>>>> You want to design and build a compiler that takes xml information >>>>> as its >>>>> source code, and compiles those xml files into Intel x86 machine >>>>> code. The >>>>> compiler and the resulting executable needs to run on an x86 Linux >>>>> machine. >>>>> Your previous experience was in doing this sort of thing in C, but >>>>> you want >>>>> to try it with Python instead. You want to do it without using the >>>>> lxml >>>>> libraries. >>>>> >>>>> You want to build a python compiler, that takes python source code and >>>>> produces Java byte code files. You'd like to do this in C, but >>>>> don't want >>>>> to use any of the available existing CPython or Jython source >>>>> code. Your >>>>> goal is not to make a commercially viable product, but to learn as >>>>> much as >>>>> possible in the process. >>>>> >>>>> >>>>> DaveA >>>>> >>>> >>>> hey, >>>> >>>> I want to create a compiler which transform a code like pascal code >>>> (that >>>> what I do in C) to "quad" >>>> In C, I use BISON and FLEX tools. >>>> >>>> >>> I've forwarded your message to the list, and fixed your top-posting >>> by moving your response to the bottom. I don't have a clue what >>> "quad" is, unless it's a synonym for Forth. >>> >>> You haven't specified the OS you'll be using to run the compiler, nor >>> the one you're targeting, so some of these choices may not be >>> useful. For example, the first one is Linux only. >>> >>> http://www.freenet.org.nz/python/pybison/ >>> PyBison - Python binding for Bison/Flex >>> >>> http://freshmeat.net/projects/yeanpypa/ >>> http://www.slash-me.net/dev/snippets/yeanpypa/documentation.html >>> >>> http://www.python.org/community/sigs/retired/parser-sig/towards-standard/ >>> >>> >>> Or you could go here, which has links to (most of) these and others. >>> http://wiki.python.org/moin/LanguageParsing >>> >>> DaveA From jjposner at optimum.net Sun Mar 7 10:23:35 2010 From: jjposner at optimum.net (John Posner) Date: Sun, 07 Mar 2010 10:23:35 -0500 Subject: a simple def how-to In-Reply-To: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: <4b93c4ce$0$31278$607ed4bc@cv.net> On 3/7/2010 10:05 AM, vsoler wrote: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) > > which does not work. I assume I should be using globals() instead of > var, but I do not know how to write my script. > > Can anybody help? var = [] # create empty list for i in ranges: var.append(readFromExcelRange(i)) -or- var = [ readFromExcelRange(i) for i in ranges ] -or- var = map(readFromExcelRange, ranges) -John From usenot at geekmail.INVALID Sun Mar 7 10:23:48 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 7 Mar 2010 16:23:48 +0100 Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: <20100307162348.0995f801@geekmail.INVALID> On Sun, 7 Mar 2010 07:05:26 -0800 (PST) vsoler wrote: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) > > which does not work. I assume I should be using globals() instead of > var, but I do not know how to write my script. > > Can anybody help? One additional line, and it works (all the following code is untested, I might have goofed it up somewhere, but you get the idea): ranges=['book','house','table','read'] var = {} for i in ranges: var[i]=readFromExcelRange(i) Or, more succinctly: var = dict((i, readFromExcelRange(i)) for i in ranges) although that looks a bit crowded. Perhaps rd = readFromExcelRange var = dict((i, rd(i)) for i in ranges) looks better, but not by much, IMO. In Python 3 you can also just say var = {i:readFromExcelRange(i) for i in ranges} (I think. I don't have Python 3.) This looks comparatively neat, because there are no nesting parens. And just in case you think it's a good idea to meddle with globals and create actual "variables": it's not. You absolutely want dictionaries here. It's basically a bad idea to create names *implicitly* that you're going to use *explicitly*. (That is, it is in Python anyway, because it does not provide a clean and clear way of doing this. Other languages might provide that sort of thing, and it might be awesome, but in Python, no sir.) /W -- INVALID? DE! From vicente.soler at gmail.com Sun Mar 7 10:57:30 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 07:57:30 -0800 (PST) Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> <20100307162348.0995f801@geekmail.INVALID> Message-ID: <9c89873d-15a4-42bc-b30d-572a7111263d@t23g2000yqt.googlegroups.com> On 7 mar, 16:23, Andreas Waldenburger wrote: > On Sun, 7 Mar 2010 07:05:26 -0800 (PST) vsoler > > > > wrote: > > Hello, > > > My script starts like this: > > > book=readFromExcelRange('book') > > house=readFromExcelRange('house') > > table=readFromExcelRange('table') > > read=readFromExcelRange('read') > > ... > > > But I would like to have something equivalent, like... > > > ranges=['book','house','table','read'] > > for i in ranges: > > ? ? var[i]=readFromExcelRange(i) > > > which does not work. I assume I should be using globals() instead of > > var, but I do not know how to write my script. > > > Can anybody help? > > One additional line, and it works (all the following code is untested, > I might have goofed it up somewhere, but you get the idea): > > ranges=['book','house','table','read'] > var = {} > for i in ranges: > ? ? var[i]=readFromExcelRange(i) > > Or, more succinctly: > > var = dict((i, readFromExcelRange(i)) for i in ranges) > > although that looks a bit crowded. Perhaps > > rd = readFromExcelRange > var = dict((i, rd(i)) for i in ranges) > > looks better, but not by much, IMO. > > In Python 3 you can also just say > > var = {i:readFromExcelRange(i) for i in ranges} > > (I think. I don't have Python 3.) This looks comparatively neat, > because there are no nesting parens. > > And just in case you think it's a good idea to meddle with globals and > create actual "variables": it's not. You absolutely want dictionaries > here. It's basically a bad idea to create names *implicitly* that > you're going to use *explicitly*. (That is, it is in Python anyway, > because it does not provide a clean and clear way of doing this. Other > languages might provide that sort of thing, and it might be awesome, > but in Python, no sir.) > > /W > > -- > INVALID? DE! Thank you Andreas. Your comprehensive answer makes a lot of sense to me. From vicente.soler at gmail.com Sun Mar 7 10:59:30 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 07:59:30 -0800 (PST) Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> <4b93c4ce$0$31278$607ed4bc@cv.net> Message-ID: <63b9d9e5-cd46-4e96-b8e5-e791ad6e9a1e@i25g2000yqm.googlegroups.com> On 7 mar, 16:23, John Posner wrote: > On 3/7/2010 10:05 AM, vsoler wrote: > > > > > Hello, > > > My script starts like this: > > > book=readFromExcelRange('book') > > house=readFromExcelRange('house') > > table=readFromExcelRange('table') > > read=readFromExcelRange('read') > > ... > > > But I would like to have something equivalent, like... > > > ranges=['book','house','table','read'] > > for i in ranges: > > ? ? ?var[i]=readFromExcelRange(i) > > > which does not work. I assume I should be using globals() instead of > > var, but I do not know how to write my script. > > > Can anybody help? > > var = [] ? ?# create empty list > for i in ranges: > ? ? ?var.append(readFromExcelRange(i)) > > ? -or- > > var = [ readFromExcelRange(i) for i in ranges ] > > ? -or- > > var = map(readFromExcelRange, ranges) > > -John John, Thank you for your help. Perhaps the solution you are suggesting is not exactly what I was looking for, but helped anyway. From jjposner at optimum.net Sun Mar 7 11:16:36 2010 From: jjposner at optimum.net (John Posner) Date: Sun, 07 Mar 2010 11:16:36 -0500 Subject: a simple def how-to In-Reply-To: <63b9d9e5-cd46-4e96-b8e5-e791ad6e9a1e@i25g2000yqm.googlegroups.com> References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> <4b93c4ce$0$31278$607ed4bc@cv.net> <63b9d9e5-cd46-4e96-b8e5-e791ad6e9a1e@i25g2000yqm.googlegroups.com> Message-ID: <4B93D164.3060309@optimum.net> On 3/7/2010 10:59 AM, vsoler wrote: > > Thank you for your help. Perhaps the solution you are suggesting is > not exactly what I was looking for, but helped anyway. Oops, I was thinking list, not dict. Too fast, and not enough coffee! -John From vicente.soler at gmail.com Sun Mar 7 11:23:13 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 08:23:13 -0800 (PST) Subject: Duplicate keys in dict? Message-ID: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Hello, My code snippet reads data from excel ranges. First row and first column are column headers and row headers respectively. After reding the range I build a dict. ................'A'..............'B' 'ab'............3................5 'cd'............7................2 'cd'............9................1 'ac'............7................2 d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... However, as you can see there are two rows that start with 'cd', and dicts, AFAIK do not accept duplicates. What is the best workaround for this? Should I discard dicts? Should I somehow have under 'cd'... a list of values? One of the difficulties I find here is that I want to be able to easily sum all the values for each row key: 'ab', 'cd' and 'ac'. However, using lists inside dicts makes it a difficult issue for me. What is the best approach for this problem? Can anybody help? From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 11:42:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 16:42:59 GMT Subject: a simple def how-to References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: <4b93d793$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 07:05:26 -0800, vsoler wrote: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) > > which does not work. I assume I should be using globals() instead of > var, but I do not know how to write my script. > > Can anybody help? Yes. Use a dict instead. ranges=['book','house','table','read'] data = {} for name in ranges: data[name] = readFromExcelRange(name) # and later... item = 'table' print "The range '%s' is %s" % (item, data[item]) -- Steven From news123 at free.fr Sun Mar 7 11:46:02 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 17:46:02 +0100 Subject: Duplicate keys in dict? In-Reply-To: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Message-ID: <4b93d84b$0$10084$426a74cc@news.free.fr> vsoler wrote: > Hello, > > My code snippet reads data from excel ranges. First row and first > column are column headers and row headers respectively. After reding > the range I build a dict. > > ................'A'..............'B' > 'ab'............3................5 > 'cd'............7................2 > 'cd'............9................1 > 'ac'............7................2 > > d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... > > However, as you can see there are two rows that start with 'cd', and > dicts, AFAIK do not accept duplicates. Normall dicts are used if you want to access your data at a later point in time by the key name. Do you want to be able to do this? Then what would you expect to receive for d[('cd','A')] ? The first value? the second value? both values? Could you perhaps change further occurences of 'cd' with 'cd1' , 'cd2' , 'cd3', ... ? Not knowing your exact context makes it difficult to suggest solutions? perhaps you could switch to a list containing a tuple of (rowname,rowdict) l = [ ('ab', { 'A': 3 , 'B': 5 } ), 'cd', { 'A': 7 , 'B': 2 } ), 'cd', { 'A': 9 , 'B': 1 } ), 'ac', { ... } ] bye N > > What is the best workaround for this? Should I discard dicts? Should I > somehow have under 'cd'... a list of values? > > One of the difficulties I find here is that I want to be able to > easily sum all the values for each row key: 'ab', 'cd' and 'ac'. > However, using lists inside dicts makes it a difficult issue for me. > > What is the best approach for this problem? Can anybody help? From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 11:53:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Mar 2010 16:53:55 GMT Subject: Duplicate keys in dict? References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Message-ID: <4b93da23$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 08:23:13 -0800, vsoler wrote: > Hello, > > My code snippet reads data from excel ranges. First row and first column > are column headers and row headers respectively. After reding the range > I build a dict. > > ................'A'..............'B' > 'ab'............3................5 > 'cd'............7................2 > 'cd'............9................1 > 'ac'............7................2 > > d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... > > However, as you can see there are two rows that start with 'cd', and > dicts, AFAIK do not accept duplicates. > One of the difficulties I find here is that I want to be able to easily > sum all the values for each row key: 'ab', 'cd' and 'ac'. However, > using lists inside dicts makes it a difficult issue for me. Given the sample above, what answer do you expect for summing the 'cd' row? There are four reasonable answers: 7 + 2 = 9 9 + 1 = 10 7 + 2 + 9 + 1 = 19 Error You need to decide what you want to do before asking how to do it. -- Steven From vicente.soler at gmail.com Sun Mar 7 12:13:13 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 7 Mar 2010 09:13:13 -0800 (PST) Subject: Duplicate keys in dict? References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> <4b93da23$0$8836$c3e8da3@news.astraweb.com> Message-ID: <70b3224d-a8d1-4182-8609-0b96270fa13e@33g2000yqj.googlegroups.com> On 7 mar, 17:53, Steven D'Aprano wrote: > On Sun, 07 Mar 2010 08:23:13 -0800, vsoler wrote: > > Hello, > > > My code snippet reads data from excel ranges. First row and first column > > are column headers and row headers respectively. After reding the range > > I build a dict. > > > ................'A'..............'B' > > 'ab'............3................5 > > 'cd'............7................2 > > 'cd'............9................1 > > 'ac'............7................2 > > > d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... > > > However, as you can see there are two rows that start with 'cd', and > > dicts, AFAIK do not accept duplicates. > > One of the difficulties I find here is that I want to be able to easily > > sum all the values for each row key: ?'ab', 'cd' and 'ac'. However, > > using lists inside dicts makes it a difficult issue for me. > > Given the sample above, what answer do you expect for summing the 'cd' > row? There are four reasonable answers: > > 7 + 2 = 9 > 9 + 1 = 10 > 7 + 2 + 9 + 1 = 19 > Error > > You need to decide what you want to do before asking how to do it. > > -- > Steven Steven, What I need is that sum(('cd','A')) gives me 16, sum(('cd','B')) gives me 3. I apologize for not having made it clear. From rjngrj2010 at gmail.com Sun Mar 7 12:16:04 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 7 Mar 2010 09:16:04 -0800 (PST) Subject: importerror: module Gnuplot missing Message-ID: Hi, I need help. I am trying to follow examples from a book "Python Scripting for Computational Science" and the examples are all plotted using Gnuplot. When I run the programs I get error saying "importerror Gnuplot module missing". I have installed Gnuplot in C:\My Programs\gnuplot directory (running on WinME). I have installed python 2.5 and Gnuplot 4.2. I have also installed Gnuplot-py-1.8 in Python's site-packages. All paths are correctly set as I can see from sys.path argument i.e., path for gnuplot is set and so also the python path and scripting path which is where book examples reside. Many examples did run well until it came down to plotting... I also ran 'python test.py' from Gnuplot-py-1.8 directory and strangely it runs and then asks me to press return to see result. The screen then freezes and the computer hangs. I have to reboot it again. Some one suggested in the old archives that I should change in the utils the code import Gnuplot,utils to import utils from _Gnuplot import Gnuplot I have tried it but same result. Window freezes and my "C:\Windows\ " directory gets filled with fff #...tmp files. I have no idea what are those. My other attempts: 1. Is there an issue how one names the directory - gnuplot versus Gnuplot etc... 2. I have done things like >>> from numpy import oldnumeric. And the test runs fine. 3. "python setup.py" install for installing Gnuplot-py-1.8 also ran fine. 4. I could from "\gnuplot\bin" directory open wgnuplot and in the Gnuplot window could plot sinx/x. 5. I also have a pgnuplot application 6. Is the gnuplot version incompatible with Python 2.5 and its associated older numpy versions.. I have seen several similar "missing Gnuplot" reports in the archive but did not find any resolution to those. I will appreciate any help, Thanks gujax From stefan_ml at behnel.de Sun Mar 7 12:17:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 07 Mar 2010 18:17:01 +0100 Subject: a simple def how-to In-Reply-To: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> References: <092afce7-8365-4d52-a08b-e69c07771684@z35g2000yqd.googlegroups.com> Message-ID: vsoler, 07.03.2010 16:05: > Hello, > > My script starts like this: > > book=readFromExcelRange('book') > house=readFromExcelRange('house') > table=readFromExcelRange('table') > read=readFromExcelRange('read') > ... > > But I would like to have something equivalent, like... > > ranges=['book','house','table','read'] > for i in ranges: > var[i]=readFromExcelRange(i) Note that the name "i" is rather badly chosen as it generally implies a totally different thing (integer) than what you use it for (names of ranges). "ranges" seems to fall into the same bucket, but I guess that's just because I can't extract the meaning from your code snippet (which is not a good sign). Try to use expressive names in your code, so that people who look at it for the first time get an idea about what it does with what kind of data. Stefan From karun.madhan at gmail.com Sun Mar 7 13:09:47 2010 From: karun.madhan at gmail.com (madhan) Date: Sun, 7 Mar 2010 10:09:47 -0800 (PST) Subject: click me Message-ID: please clic it it will be usefull to you http://123maza.com/78/healthyfitness/ From miraclesoul at hotmail.com Sun Mar 7 13:55:24 2010 From: miraclesoul at hotmail.com (Fahad Ahmad) Date: Sun, 7 Mar 2010 18:55:24 +0000 Subject: Calculating very large exponents in python Message-ID: Dear All, i am writing my crytographic scheme in python, i am just a new user to it. I have written the complete code, the only point i am stuck it is that i am using 256 exponentiation which is normal in crytography but python just hangs on it. g**x [where both g and x are 256 bit numbers , in decimal they are around 77] after reading several forums, i just come to know it can be done using numpy, i have installed python(x,y) has has both numpy and scipy installed but i am not able to make it happen. any idea which library, module, or piece of code can solve this mystery :S sorry for bad english "People come and go no one remembers them for life but it is the time spent with them that become Sweet memories that are remembered for life hope I leave some memories behind " _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. http://clk.atdmt.com/GBL/go/201469229/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Mar 7 14:11:18 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Mar 2010 13:11:18 -0600 Subject: Duplicate keys in dict? In-Reply-To: <70b3224d-a8d1-4182-8609-0b96270fa13e@33g2000yqj.googlegroups.com> References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> <4b93da23$0$8836$c3e8da3@news.astraweb.com> <70b3224d-a8d1-4182-8609-0b96270fa13e@33g2000yqj.googlegroups.com> Message-ID: <4B93FA56.20100@tim.thechases.com> vsoler wrote: > On 7 mar, 17:53, Steven D'Aprano cybersource.com.au> wrote: >> On Sun, 07 Mar 2010 08:23:13 -0800, vsoler wrote: >>> Hello, >>> My code snippet reads data from excel ranges. First row and first column >>> are column headers and row headers respectively. After reding the range >>> I build a dict. >>> ................'A'..............'B' >>> 'ab'............3................5 >>> 'cd'............7................2 >>> 'cd'............9................1 >>> 'ac'............7................2 >>> d={('ab','A'): 3, ('ab','B'): 5, ('cd','A'): 7, ... >>> However, as you can see there are two rows that start with 'cd', and >>> dicts, AFAIK do not accept duplicates. >>> One of the difficulties I find here is that I want to be able to easily >>> sum all the values for each row key: 'ab', 'cd' and 'ac'. However, >>> using lists inside dicts makes it a difficult issue for me. > > What I need is that sum(('cd','A')) gives me 16, sum(('cd','B')) gives > me 3. But you really *do* want lists inside the dict if you want to be able to call sum() on them. You want to map the tuple ('cd','A') to the list [7,9] so you can sum the results. And if you plan to sum the results, it's far easier to have one-element lists and just sum them, instead of having to special case "if it's a list, sum it, otherwise, return the value". So I'd use something like import csv f = file(INFILE, 'rb') r = csv.reader(f, ...) headers = r.next() # discard the headers d = defaultdict(list) for (label, a, b) in r: d[(label, 'a')].append(int(a)) d[(label, 'b')].append(int(b)) # ... for (label, col), value in d.iteritems(): print label, col, 'sum =', sum(value) Alternatively, if you don't need to store the intermediate values, and just want to store the sums, you can accrue them as you go along: d = defaultdict(int) for (label, a, b) in r: d[(label, 'a')] += int(a) d[(label, 'b')] += int(b) # ... for (label, col), value in d.iteritems(): print label, col, 'sum =', value Both are untested, but I'm pretty sure they're both viable, modulo my sleep-deprived eyes. -tkc From python at rgbaz.eu Sun Mar 7 14:26:57 2010 From: python at rgbaz.eu (PythonAB) Date: Sun, 7 Mar 2010 20:26:57 +0100 Subject: Bluetooth Message-ID: Hello, I'm writing a script that has to connect a bluetooth device with a 3D application. On my search for a bluetooth module i ran into this: http://www.python.org/download/releases/2.4/notes/ where it says: "The socket module now supports Bluetooth sockets, if the system has " Yet I can't find anything at all in the socket manuals nor anywhere else on the site... Does the socket module really support Bluetooth out of the box? I've used socket before but never read anything about bluetooth... Maybe I need to get the bluetooth.h file, but i have no idea what I am supposed to do with it... Can anyone shed some light on this for me please? thanks in advance, gr Arno -------------- next part -------------- An HTML attachment was scrubbed... URL: From debatem1 at gmail.com Sun Mar 7 15:40:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Sun, 7 Mar 2010 15:40:59 -0500 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad wrote: > Dear All, > > i am writing my crytographic scheme in python, i am just a new user to it. > I have written the complete code, the only point i am stuck it is that i am > using 256 exponentiation which is normal in crytography but python just > hangs on it. > > g**x? [where both g and x are 256 bit numbers , in decimal they are around > 77] > > after reading several forums, i just come to know it can be done using > numpy, i have installed python(x,y) has has both numpy and scipy installed > but i am not able to make it happen. > > any idea which library, module, or piece of code can solve this mystery :S > > sorry for bad english A couple of things: 1) if you're working with modular exponentiation, remember that pow() takes three arguments, ie: a = 222222222222222222222222222 b = 5555555555555555555555555555 pow(a, b, 1200) will calculate the correct answer (768) very quickly, while a**b % 1200 has not terminated in the time it took me to compose this email. 2) sage has a lot of excellent tools for crypto/cryptanalysis that you may want to take a look at. 3) not saying you don't know what you're doing, but be careful when rolling your own cryptosystems- even very good cryptographers make implementation mistakes! Geremy Condra From vlastimil.brom at gmail.com Sun Mar 7 16:04:42 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 7 Mar 2010 22:04:42 +0100 Subject: negative "counts" in collections.Counter? Message-ID: <9fdb569a1003071304x7265b331o58dc407c2a51307d@mail.gmail.com> Hi all, I'd like to ask about the possibility of negative "counts" in collections.Counter (using Python 3.1); I believe, my usecase is rather trivial, basically I have the word frequencies of two texts and I want do compare them (e.g. to see what was added and removed between different versions of a text). This is simple enough to do with own code, but I thought, this would be exactly the case for Counter... However, as the Counter only returns positive counts, one has to get the difference in both directions and combine them afterwards, maybe something like: >>> c1=collections.Counter("aabcddd") >>> c2=collections.Counter("abbbd") >>> added_c2 = c2-c1 >>> removed_c2 = c1-c2 >>> negative_added_c2 = dict((k, v*-1) for (k, v) in removed_c2.items()) >>> changed_c2 = dict(added_c2) >>> changed_c2.update(negative_added_c2) >>> changed_c2 {'a': -1, 'c': -1, 'b': 2, 'd': -2} >>> It seems to me, that with negative counts allowed in Counter, this would simply be the matter of a single difference: changed_c2 = c2 - c1 Is there a possibility to make the Counter work this way (other than replacing its methods in a subclass, which might be comparable to writing the naive counting class itself)? Are there maybe some reasons I missed to disable negative counts here? (As I could roughly understand, the Counter isn't quite limited to the mathematical notion of multiset; it seems to accept negative counts, but its methods only output the positive part). Is this kind of task - a comparison in both directions - an unusual one, or is it simply not the case for Counter? Thanks in advance, vbr From news123 at free.fr Sun Mar 7 16:08:39 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:08:39 +0100 Subject: killing own process in windows Message-ID: <4b9415d7$0$19558$426a74cc@news.free.fr> Hi, How can I kill my own process? Some multithreaded programs, that I have are unable to stop when ctrl-C is pressed. Some can't be stopped with sys.exit() So I'd just like to terminate my own program. Examples of non killable (not killable with CTRL-C) programs: - A program, that started an XMLRPC server with serve_forever - a program, that started a multiprocessing.Manager with serve_forever thanks in advance for some ideas. N From news123 at free.fr Sun Mar 7 16:26:41 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:26:41 +0100 Subject: stopping a multiprocessing.managers.BaseManager nicely (looks like a hack) Message-ID: <4b941a11$0$23919$426a74cc@news.free.fr> Hi, I have following program from multiprocessing.managers import BaseManager def myfunc(): return 3 class MyManager(BaseManager): pass MyManager.register('myfunc',callable = myfunc) m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') server = m.get_server() server.serve_forever() I'd like to replace server.serve_forever() with something, which is abortable. After digging in the sources I came up with following (in my opinion) inelegant, but working solution. I just copied the Server.serve_forever() function from multiprocessing/managers.py and changed two lines. Does anybody have a better idea than this: # ------------------------------------------------ import multiprocessing.managers from multiprocessing.managers import BaseManager def serve_till_stop(self): ''' Run the server forever ''' #current_process()._manager_server = self # this lin removed multiprocessing.managers.current_process()._manager_server = self # this line added try: try: #while 1: # this line removed while self.running: # this line added try: c = self.listener.accept() except (OSError, IOError): continue t = threading.Thread(target=self.handle_request, args=(c,)) t.daemon = True t.start() except (KeyboardInterrupt, SystemExit): pass finally: self.stop = 999 self.listener.close() def myfunc(): return 3 def stopme(): server.running = False class MyManager(BaseManager): pass MyManager.register('myfunc',callable = myfunc) m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') server = m.get_server() server.running = True serve_till_stop(server) thanks in advance and bye N From martin.hellwig at dcuktec.org Sun Mar 7 16:28:16 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 07 Mar 2010 21:28:16 +0000 Subject: killing own process in windows In-Reply-To: <4b9415d7$0$19558$426a74cc@news.free.fr> References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: On 03/07/10 21:08, News123 wrote: > Hi, > > > How can I kill my own process? > > Some multithreaded programs, that I have are unable to stop when ctrl-C > is pressed. > Some can't be stopped with sys.exit() > > So I'd just like to terminate my own program. > > > Examples of non killable (not killable with CTRL-C) programs: > - A program, that started an XMLRPC server with serve_forever > - a program, that started a multiprocessing.Manager with serve_forever > > > thanks in advance for some ideas. > > > N If it is just the xml rpc server you want to kill, there might be better ways. For example look at: http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py with perhaps special interest at the comment on lines 172-174. -- mph From news123 at free.fr Sun Mar 7 16:47:51 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:47:51 +0100 Subject: stopping a multiprocessing.managers.BaseManager nicely (looks like a hack) In-Reply-To: <4b941a11$0$23919$426a74cc@news.free.fr> References: <4b941a11$0$23919$426a74cc@news.free.fr> Message-ID: <4b941f07$0$14923$426a34cc@news.free.fr> My fix has certain problems: News123 wrote: > Hi, > > > I have following program > > from multiprocessing.managers import BaseManager > def myfunc(): return 3 > class MyManager(BaseManager): pass > MyManager.register('myfunc',callable = myfunc) > m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') > server = m.get_server() > server.serve_forever() > > > I'd like to replace server.serve_forever() with something, which is > abortable. > > After digging in the sources I came up with following (in my opinion) > inelegant, but working solution. > > I just copied the Server.serve_forever() function from > multiprocessing/managers.py and changed two lines. > > > Does anybody have a better idea than this: > # ------------------------------------------------ > import multiprocessing.managers > from multiprocessing.managers import BaseManager > def serve_till_stop(self): > ''' > Run the server forever > ''' > #current_process()._manager_server = self # this lin removed > multiprocessing.managers.current_process()._manager_server = self # > this line added > try: > try: > #while 1: # this line removed > while self.running: # this line added > try: > c = self.listener.accept() > except (OSError, IOError): > continue > t = threading.Thread(target=self.handle_request, args=(c,)) > t.daemon = True > t.start() > except (KeyboardInterrupt, SystemExit): > pass > finally: > self.stop = 999 > self.listener.close() Problems will now occur on he client side. The server terminates now immediately after the function stopme has been called. The client however wants still to perform a few requests, before it considers calling of stopme done. So I still don't have a solution :-( > > > def myfunc(): return 3 > def stopme(): server.running = False > class MyManager(BaseManager): pass > MyManager.register('myfunc',callable = myfunc) > m = MyManager(address=('127.0.0.1', 50000),authkey='abracadabra') > server = m.get_server() > server.running = True > serve_till_stop(server) > > thanks in advance and bye > > > N > > From news123 at free.fr Sun Mar 7 16:54:28 2010 From: news123 at free.fr (News123) Date: Sun, 07 Mar 2010 22:54:28 +0100 Subject: killing own process in windows In-Reply-To: References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: <4b942094$0$25784$426a74cc@news.free.fr> Hi Martin. Hellwig wrote: > On 03/07/10 21:08, News123 wrote: >> Hi, >> >> >> How can I kill my own process? >> >> Some multithreaded programs, that I have are unable to stop when ctrl-C >> is pressed. >> Some can't be stopped with sys.exit() >> >> So I'd just like to terminate my own program. >> >> >> Examples of non killable (not killable with CTRL-C) programs: >> - A program, that started an XMLRPC server with serve_forever >> - a program, that started a multiprocessing.Manager with serve_forever >> >> > If it is just the xml rpc server you want to kill, there might be better > ways. For example look at: > http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py > > with perhaps special interest at the comment on lines 172-174. I Thanks. this looks like a good solution for an XMLRPC server. However when playing with different server modules I fall over and over again over code, that can't be shutdown nicely. Currently I'm still struggling with multiprocessing.managers,BaseManager bye N From arnodel at googlemail.com Sun Mar 7 17:21:27 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 07 Mar 2010 22:21:27 +0000 Subject: negative "counts" in collections.Counter? References: Message-ID: Vlastimil Brom writes: > Hi all, > I'd like to ask about the possibility of negative "counts" in > collections.Counter (using Python 3.1); > I believe, my usecase is rather trivial, basically I have the word > frequencies of two texts and I want do compare them (e.g. to see what > was added and removed between different versions of a text). > > This is simple enough to do with own code, but I thought, this would > be exactly the case for Counter... > However, as the Counter only returns positive counts, one has to get > the difference in both directions and combine them afterwards, maybe > something like: > >>>> c1=collections.Counter("aabcddd") >>>> c2=collections.Counter("abbbd") >>>> added_c2 = c2-c1 >>>> removed_c2 = c1-c2 >>>> negative_added_c2 = dict((k, v*-1) for (k, v) in removed_c2.items()) >>>> changed_c2 = dict(added_c2) >>>> changed_c2.update(negative_added_c2) >>>> changed_c2 > {'a': -1, 'c': -1, 'b': 2, 'd': -2} >>>> > > It seems to me, that with negative counts allowed in Counter, this > would simply be the matter of a single difference: > changed_c2 = c2 - c1 > > Is there a possibility to make the Counter work this way (other than > replacing its methods in a subclass, which might be comparable to > writing the naive counting class itself)? > Are there maybe some reasons I missed to disable negative counts here? > (As I could roughly understand, the Counter isn't quite limited to the > mathematical notion of multiset; it seems to accept negative counts, > but its methods only output the positive part). > Is this kind of task - a comparison in both directions - an unusual > one, or is it simply not the case for Counter? Every time I have needed something like collections.Counter, I have wanted the behaviour you require too. As a result, I have never used collections.Counter. Instead I have used plain dictionaries or my own class. I don't understand why the Counter's + and - operators behave as they do. Here is an example from the docs: >>> c = Counter(a=3, b=1) >>> d = Counter(a=1, b=2) >>> c + d # add two counters together: c[x] + d[x] Counter({'a': 4, 'b': 3}) >>> c - d # subtract (keeping only positive counts) Counter({'a': 2}) >>> c & d # intersection: min(c[x], d[x]) Counter({'a': 1, 'b': 1}) >>> c | d # union: max(c[x], d[x]) Counter({'a': 3, 'b': 2}) If + and - just added or subtracted the multiplicities of elements, keeping negative multiplicites, we would get: >>> c - d Counter({'a':2, 'b':-1}) Which I think is useful in many cases. But we could still get the result of current c - d very simply: >>> (c - d) | Counter() # | Counter() removes negative multiplicities Counter({'a':2}) Altogether more versatile and coherent IMHO. -- Arnaud From martin.hellwig at dcuktec.org Sun Mar 7 17:27:48 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 07 Mar 2010 22:27:48 +0000 Subject: killing own process in windows In-Reply-To: <4b942094$0$25784$426a74cc@news.free.fr> References: <4b9415d7$0$19558$426a74cc@news.free.fr> <4b942094$0$25784$426a74cc@news.free.fr> Message-ID: On 03/07/10 21:54, News123 wrote: > Hi Martin. > Hellwig wrote: >> On 03/07/10 21:08, News123 wrote: >>> Hi, >>> >>> >>> How can I kill my own process? >>> >>> Some multithreaded programs, that I have are unable to stop when ctrl-C >>> is pressed. >>> Some can't be stopped with sys.exit() >>> >>> So I'd just like to terminate my own program. >>> >>> >>> Examples of non killable (not killable with CTRL-C) programs: >>> - A program, that started an XMLRPC server with serve_forever >>> - a program, that started a multiprocessing.Manager with serve_forever >>> >>> >> If it is just the xml rpc server you want to kill, there might be better >> ways. For example look at: >> http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py >> >> with perhaps special interest at the comment on lines 172-174. > I > > > > Thanks. this looks like a good solution for an XMLRPC server. > However when playing with different server modules I fall over and over > again over code, that can't be shutdown nicely. > > Currently I'm still struggling with multiprocessing.managers,BaseManager > > bye > > N I haven't used the multiprocessing module yet, but generally speaking I believe that everything in python that is server-like inherits from SocketServer BaseServer. Probably for you to have all servers behave in a way you expect, is to override functionality there, for example in: http://docs.python.org/library/socketserver.html?highlight=baseserver#SocketServer.BaseServer the function: handle_request Though from looking at the source the function serve_forever is just an while loop over handle request (blocking or no-blocking), so might be a better candidate to replace. But you still might find that some tcp connections remain open, so unless you want to go down to the socket level and explicit close the socket, there is not much you can do about that. For the client side, socket timeout is you enemy, I found something rather long as default (300 seconds in the xml-rpc client) but yours might be different (it is probably a Python defined standard default, but I haven't checked that). Sounds to me like you will be busy reading up on it now :-) Oh and just a word to prevent over-engineering, if both the server and client is written by you, a lot of problems you anticipate will probably never occur because that would require a rogue server or client. Unless of course you like making rogue server/clients :-) -- mph From lists at cheimes.de Sun Mar 7 17:36:54 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 07 Mar 2010 23:36:54 +0100 Subject: killing own process in windows In-Reply-To: <4b9415d7$0$19558$426a74cc@news.free.fr> References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: News123 wrote: > Hi, > > > How can I kill my own process? > > Some multithreaded programs, that I have are unable to stop when ctrl-C > is pressed. > Some can't be stopped with sys.exit() You have to terminate the XMP-RPC server or the manager first. Check the docs! You can terminate a Python process with os._exit() but I recommend that you find another way. os._exit() is a hard termination. It kills the process without running any cleanup code like atexit handlers and Python's internal cleanups. Open files aren't flushed to disk etc. Christian From news123 at free.fr Sun Mar 7 18:01:39 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 00:01:39 +0100 Subject: killing own process in windows In-Reply-To: References: <4b9415d7$0$19558$426a74cc@news.free.fr> Message-ID: <4b943053$0$25136$426a74cc@news.free.fr> Hi Cristian, Christian Heimes wrote: > News123 wrote: >> Hi, >> >> >> How can I kill my own process? >> >> Some multithreaded programs, that I have are unable to stop when ctrl-C >> is pressed. >> Some can't be stopped with sys.exit() > > You have to terminate the XMP-RPC server or the manager first. Check the > docs! > > You can terminate a Python process with os._exit() but I recommend that > you find another way. os._exit() is a hard termination. It kills the > process without running any cleanup code like atexit handlers and > Python's internal cleanups. Open files aren't flushed to disk etc. > This is exactly the problem: Neither the XMLRPC server nor the manager can be stopped both serve forever. The doc doesn't really help. For the XMLRPC server there are tricks to subclass it and to change the behaviour, as indicated by Martin. for the manager I did not find a clean solution (Plese see my other thread "stopping a multiprocessing.manage.....") I'm surprised, that there are no 'canned' solution to stop servers remotely or just by pressing ctrl-C I consider this being quite useful for certain kinds of applications. I prefer to ask a server to shutdown, than to just kill him. Am interactive program, which also acts like a server should be able to shutdown its server thread from the main thread in order to quit nicely. Baseserver has even a shutdown method(), but it cannot be called if were started with serve_forever(). N From googler.1.webmaster at spamgourmet.com Sun Mar 7 18:29:42 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Sun, 7 Mar 2010 15:29:42 -0800 (PST) Subject: time_struct References: <23dbe409-60ed-4f6f-bd38-4336e4f1b3d0@f8g2000yqn.googlegroups.com> Message-ID: any ideas? From rjngrj2010 at gmail.com Sun Mar 7 18:33:16 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 7 Mar 2010 15:33:16 -0800 (PST) Subject: Window crash/freeze after "python test.py" in \Gnuplot Message-ID: <3d586615-f79c-4657-bcaf-58287d5c8917@g11g2000yqe.googlegroups.com> Hi, My computer OS is Win ME, and I am running a Py2.5 version. Gnuplot is v4.2, Gnuplot_py is v1.8. However, whenever I give a command "python test.py" to test Gnuplot_py, I sometimes get message " #Gnuplot.................for enjoyment #press return to open a window >.. >clear terminal ....#####test function####### and then computer hangs. I never see any windows appearing. A blue screen appears with request for cntrl-alt-del. I cannot exactly determine the messages because the crash occurs relatively fast therefore some sentences above may not be accurate. I have tried this with many scripts which use Gnuplot for plotting but it results in same crashes e.g. demo.py in gnuplot_py. I really have no clue what should be my next step. Any help will be appreicated. I however, can run Gnuplot by typing "pgnuplot" or "wgnuplot" in the command shell and it opens a Gnuplot window. Therefore, it looks like some incompatibility between gnuplot_py, python2.5? Thanks, gujax From floaiza2 at gmail.com Sun Mar 7 18:55:14 2010 From: floaiza2 at gmail.com (floaiza) Date: Sun, 7 Mar 2010 15:55:14 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <182de09d-417b-4ad7-8351-23a44e26fea6@15g2000yqi.googlegroups.com> I don't think there is any doubt about the value of relational databases, particularly on the Internet. The issue in my mind is how to leverage all the information that resides in the "deep web" using strictly the relational database paradigm. Because that paradigm imposes a tight and rigid coupling between semantics and syntax when you attempt to efficiently "merge" or "federate" data from disparate sources you can find yourself spending a lot of time and money building mappings and maintaining translators. That's why approaches that try to separate syntax from the semantics are now becoming so popular, but, again, as others have said, it is not a matter of replacing one with the other, but of figuring out how best to exploit what each technology offers. I base my remarks on some initial explorations I have made on the use of RDF Triple Stores, which, by the way, use RDBMSs to persist the triples, but which offer a really high degree of flexibility WRT the merging and federating of data from different semantic spaces. The way I hope things will move forward is that eventually it will become inexpensive and easy to "expose" as RDF triples all the relevant data that now sits in special-purpose databases. (just an opinion) Francisco On Mar 3, 12:36?pm, Xah Lee wrote: > recently i wrote a blog article on The NoSQL Movement > athttp://xahlee.org/comp/nosql.html > > i'd like to post it somewhere public to solicit opinions, but in the > 20 min or so, i couldn't find a proper newsgroup, nor private list > that my somewhat anti-NoSQL Movement article is fitting. > > So, i thought i'd post here to solicit some opinins from the programer > community i know. > > Here's the plain text version > > ----------------------------- > The NoSQL Movement > > Xah Lee, 2010-01-26 > > In the past few years, there's new fashionable thinking about anti > relational database, now blessed with a rhyming term: NoSQL. > Basically, it considers that relational database is outdated, and not > ?horizontally? scalable. I'm quite dubious of these claims. > > According to Wikipedia Scalability article, verticle scalability means > adding more resource to a single node, such as more cpu, memory. (You > can easily do this by running your db server on a more powerful > machine.), and ?Horizontal scalability? means adding more machines. > (and indeed, this is not simple with sql databases, but again, it is > the same situation with any software, not just database. To add more > machines to run one single software, the software must have some sort > of grid computing infrastructure built-in. This is not a problem of > the software per se, it is just the way things are. It is not a > problem of databases.) > > I'm quite old fashioned when it comes to computer technology. In order > to convience me of some revolutionary new-fangled technology, i must > see improvement based on math foundation. I am a expert of SQL, and > believe that relational database is pretty much the gist of database > with respect to math. Sure, a tight definition of relations of your > data may not be necessary for many applications that simply just need > store and retrieve and modify data without much concern about the > relations of them. But still, that's what relational database > technology do too. You just don't worry about normalizing when you > design your table schema. > > The NoSQL movement is really about scaling movement, about adding more > machines, about some so-called ?cloud computing? and services with > simple interfaces. (like so many fashionable movements in the > computing industry, often they are not well defined.) It is not really > about anti relation designs in your data. It's more about adding > features for practical need such as providing easy-to-user APIs (so > you users don't have to know SQL or Schemas), ability to add more > nodes, provide commercial interface services to your database, provide > parallel systems that access your data. Of course, these needs are all > done by any big old relational database companies such as Oracle over > the years as they constantly adopt the changing industry's needs and > cheaper computing power. If you need any relations in your data, you > can't escape relational database model. That is just the cold truth of > math. > > Importat data, such as used in the bank transactions, has relations. > You have to have tight relational definitions and assurance of data > integrity. > > Here's a second hand quote from Microsoft's Technical Fellow David > Campbell. Source > > ? ? I've been doing this database stuff for over 20 years and I > ? ? remember hearing that the object databases were going to wipe out > ? ? the SQL databases. And then a little less than 10 years ago the > ? ? XML databases were going to wipe out.... We actually ... you > ? ? know... people inside Microsoft, [have said] 'let's stop working > ? ? on SQL Server, let's go build a native XML store because in five > ? ? years it's all going....' > > LOL. That's exactly my thought. > > Though, i'd have to have some hands on experience with one of those > new database services to see what it's all about. > > -------------------- > Amazon S3 and Dynamo > > Look at Structured storage. That seems to be what these nosql > databases are. Most are just a key-value pair structure, or just > storage of documents with no relations. I don't see how this differ > from a sql database using one single table as schema. > > Amazon's Amazon S3 is another storage service, which uses Amazon's > Dynamo (storage system), indicated by Wikipedia to be one of those > NoSQL db. Looking at the S3 and Dynamo articles, it appears the db is > just a Distributed hash table system, with added http access > interface. So, basically, little or no relations. Again, i don't see > how this is different from, say, MySQL with one single table of 2 > columns, added with distributed infrastructure. (distributed database > is often a integrated feature of commercial dbs, e.g. Wikipedia Oracle > database article cites Oracle Real Application Clusters ) > > Here's a interesting quote on S3: > > ? ? Bucket names and keys are chosen so that objects are addressable > ? ? using HTTP URLs: > > ? ? ? ? *http://s3.amazonaws.com/bucket/key > ? ? ? ? *http://bucket.s3.amazonaws.com/key > ? ? ? ? *http://bucket/key(where bucket is a DNS CNAME record > pointing to bucket.s3.amazonaws.com) > > ? ? Because objects are accessible by unmodified HTTP clients, S3 can > ? ? be used to replace significant existing (static) web hosting > ? ? infrastructure. > > So this means, for example, i can store all my images in S3, and in my > html document, the inline images are just normal img tags with normal > urls. This applies to any other type of file, pdf, audio, but html > too. So, S3 becomes the web host server as well as the file system. > > Here's Amazon's instruction on how to use it as image server. Seems > quite simple: How to use Amazon S3 for hosting web pages and media > files? Source > > -------------------- > Google BigTable > > Another is Google's BigTable. I can't make much comment. To make a > sensible comment, one must have some experience of actually > implementing a database. For example, a file system is a sort of > database. If i created a scheme that allows me to access my data as > files in NTFS that are distributed over hundreds of PC, communicated > thru http running Apache. This will let me access my files. To insert, > delete, data, one can have cgi scripts on each machine. Would this be > considered as a new fantastic NoNoSQL? > > --------------------- > > comments can also be posted tohttp://xahlee.blogspot.com/2010/01/nosql-movement.html > > Thanks. > > ? Xah > ?http://xahlee.org/ > > ? From moc.liamg at synabp.reverse_the_string Sun Mar 7 19:18:13 2010 From: moc.liamg at synabp.reverse_the_string (=?UTF-8?B?UGF3ZcWCIEJhbnnFmw==?=) Date: Mon, 08 Mar 2010 01:18:13 +0100 Subject: running a program on many processors Message-ID: Hello, I have already read about Python and multiprocessing which allows using many processors. The idea is to split a program into separate tasks and run each of them on a separate processor. However I want to run a Python program doing a single simple task on many processors so that their cumulative power is available to the program as if there was one huge CPU instead of many separate ones. Is it possible? How can it be achieved? Best regards, Pawe? From deets at nospam.web.de Sun Mar 7 19:28:48 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 08 Mar 2010 01:28:48 +0100 Subject: running a program on many processors In-Reply-To: References: Message-ID: <7vium2FgvmU1@mid.uni-berlin.de> Am 08.03.10 01:18, schrieb Pawe? Bany?: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? That's impossible to answer without knowing anything about your actual task. Not everything is parallelizable, or algorithms suffer from penalties if parallelization is overdone. So in essence, what you've read already covers it: if your "simple task" is dividable in several, independent sub-tasks that don't need serialization, multiprocessing is your friend. Diez From g.bogle at auckland.no.spam.ac.nz Sun Mar 7 19:49:07 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 08 Mar 2010 13:49:07 +1300 Subject: running a program on many processors References: Message-ID: Pawe? Bany? wrote: ... How can it be achieved? Very carefully. From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 20:08:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 01:08:32 GMT Subject: running a program on many processors References: Message-ID: <4b944e10$0$8836$c3e8da3@news.astraweb.com> On Mon, 08 Mar 2010 01:18:13 +0100, Pawe? Bany? wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be > achieved? Try Parallel Python. http://www.parallelpython.com/ I haven't used it, but it looks interesting. However, the obligatory warning against premature optimization: any sort of parallel execution (including even lightweight threads) is hard to build and much harder to debug. You should make sure that the potential performance benefits are worth the pain before you embark on the job: are you sure that the naive, single process version isn't fast enough? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 20:14:43 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 01:14:43 GMT Subject: best practices: is collections.defaultdict my friend or not? References: <20100306031003.1018aab2@geekmail.INVALID> <3ae40c74-7bee-4c6c-9ed2-7a73675f8040@v20g2000prb.googlegroups.com> Message-ID: <4b944f83$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 09:33:22 +0000, Mark Lawrence wrote: >> I was a little frightened of doing "import this" ("Hey, kid, run rm - >> rf / and see what happens!"), but did, and the words are wise. >> >> Pete > > After reading the words of wisdom try "import this" a second time and > watch what happens, it's quite interesting if you're not expecting the > output. You weren't expecting to get the Python prompt? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 20:46:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 01:46:28 GMT Subject: negative "counts" in collections.Counter? References: Message-ID: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 22:21:27 +0000, Arnaud Delobelle wrote: > Vlastimil Brom writes: > >> Hi all, >> I'd like to ask about the possibility of negative "counts" in >> collections.Counter (using Python 3.1); I believe, my usecase is rather >> trivial, basically I have the word frequencies of two texts and I want >> do compare them (e.g. to see what was added and removed between >> different versions of a text). [...] > Every time I have needed something like collections.Counter, I have > wanted the behaviour you require too. As a result, I have never used > collections.Counter. Instead I have used plain dictionaries or my own > class. Vlastimil and Arnaud, It looks like Counter already has negative counts in Python 3.1: >>> import collections >>> c = collections.Counter({'red': 2, 'green': 0, 'blue': -5}) >>> c['blue'] -= 1 >>> c Counter({'red': 2, 'green': 0, 'blue': -6}) >>> c['blue'] += 1 >>> c Counter({'red': 2, 'green': 0, 'blue': -5}) But the + and - operators destroy negative and zero counts: >>> c + collections.Counter({'blue': 1}) Counter({'red': 2}) I can't imagine what the use-case for that behaviour is. Given that Counter supports negative counts, it looks to me that the behaviour of __add__ and __sub__ is fundamentally flawed. You should raise a bug report (feature enhancement) on the bug tracker. http://bugs.python.org/ Given that this will change the documented behaviour, it will help if you give a short, simple idiom for removing zero and negative elements, Arnaud's trick with | Counter(). When you raise the report, please post an update here. -- Steven From gagsl-py2 at yahoo.com.ar Sun Mar 7 21:00:41 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Mar 2010 23:00:41 -0300 Subject: A "scopeguard" for Python References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach escribi?: > Sorry, as with the places noted above, I can't understand what you're > trying to say here. Regarding your posts, neither can I. All the time. Sorry, deciphering your posts would force me to spend much more time than available and I can't afford that - so I'm blocking your messages from now on. -- Gabriel Genellina From martin.hellwig at dcuktec.org Sun Mar 7 21:08:39 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 02:08:39 +0000 Subject: running a program on many processors In-Reply-To: References: Message-ID: On 03/08/10 00:18, Pawe? Bany? wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? > > Best regards, > > Pawe? As far as I know, the Python VM (cpython) will not analyze your code and automatically spread parts over different processing units. I did read, two years or so ago, that AMD was looking in to something that does just what you say on a cpu level, that is present itself as one logical cpu but underneath there are multiple physical ones. I wouldn't hold my breath though waiting for it. -- mph From monkey at joemoney.net Sun Mar 7 21:10:00 2010 From: monkey at joemoney.net (monkeys paw) Date: Sun, 07 Mar 2010 21:10:00 -0500 Subject: write to remote ile Message-ID: I can xfer a file from a remote server using: import urllib2 as u x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') for line in x: print line How can i write a file to the remote server? I tried: x = u.url.open('http://joemoney.net/somefile.txt', 'w') but that does not work From martin.hellwig at dcuktec.org Sun Mar 7 21:20:20 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 02:20:20 +0000 Subject: write to remote ile In-Reply-To: References: Message-ID: On 03/08/10 02:10, monkeys paw wrote: > I can xfer a file from a remote server using: > > import urllib2 as u > x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') > > for line in x: > print line > > > How can i write a file to the remote server? > > I tried: > > x = u.url.open('http://joemoney.net/somefile.txt', 'w') > > but that does not work How do you normally (i.e. without python) put files on a remote server? -- mph From jmheralds at gmail.com Sun Mar 7 21:32:08 2010 From: jmheralds at gmail.com (James Heralds) Date: Sun, 7 Mar 2010 18:32:08 -0800 (PST) Subject: Call for papers: SETP-10, USA, July 2010 Message-ID: <84762688-eaf6-4e4e-a903-791e7e2bc2c7@j27g2000yqn.googlegroups.com> It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Call for papers: SETP-10, USA, July 2010 The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. ? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) ? International Conference on Automation, Robotics and Control Systems (ARCS-10) ? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) ? International Conference on Computer Communications and Networks (CCN-10) ? International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) ? International Conference on High Performance Computing Systems (HPCS-10) ? International Conference on Information Security and Privacy (ISP-10) ? International Conference on Image and Video Processing and Computer Vision (IVPCV-10) ? International Conference on Software Engineering Theory and Practice (SETP-10) ? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World? Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining ? all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. Sincerely James Heralds From python at bdurham.com Sun Mar 7 21:41:30 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 07 Mar 2010 21:41:30 -0500 Subject: Best practice way to detect internet connectivity under Python 2.6/Windows Message-ID: <1268016090.13219.1363604225@webmail.messagingengine.com> Is the best pratice way to detect internet connectivity under Windows (using Python 2.6) simply to attempt to access a known internet website using urllib or urlib2 wrapped in a try/except construct? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From monkey at joemoney.net Sun Mar 7 21:51:22 2010 From: monkey at joemoney.net (monkeys paw) Date: Sun, 07 Mar 2010 21:51:22 -0500 Subject: write to remote ile In-Reply-To: References: Message-ID: On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: > On 03/08/10 02:10, monkeys paw wrote: >> I can xfer a file from a remote server using: >> >> import urllib2 as u >> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >> >> for line in x: >> print line >> >> >> How can i write a file to the remote server? >> >> I tried: >> >> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >> >> but that does not work > > How do you normally (i.e. without python) put files on a remote server? > Using FTP, i'm really having a brain cramp here, but i'm new to python From martin.hellwig at dcuktec.org Sun Mar 7 21:53:46 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 02:53:46 +0000 Subject: write to remote ile In-Reply-To: References: Message-ID: On 03/08/10 02:51, monkeys paw wrote: > On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: >> On 03/08/10 02:10, monkeys paw wrote: >>> I can xfer a file from a remote server using: >>> >>> import urllib2 as u >>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >>> >>> for line in x: >>> print line >>> >>> >>> How can i write a file to the remote server? >>> >>> I tried: >>> >>> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >>> >>> but that does not work >> >> How do you normally (i.e. without python) put files on a remote server? >> > Using FTP, i'm really having a brain cramp here, but i'm new to python We all been there, in some for or other ;-), anyway you might want to have a look at this: http://docs.python.org/library/ftplib.html -- mph From missive at hotmail.com Sun Mar 7 22:01:02 2010 From: missive at hotmail.com (Lee Harr) Date: Mon, 8 Mar 2010 07:31:02 +0430 Subject: [ANNC] pynguin-0.2 (python turtle graphics application) Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues adding basic functionality and ??? corrects some annoyances. If you are interested, ??? please take a look and let me know what you think. Pynguin is tested with Python 2.6.4 and uses PyQt (4.6) ??? for its GUI elements. Pynguin is released under GPLv3. Changes in pynguin-0.2: ??? - added fill mode ??? - added basic auto-indent in editor ??? - added quick links to recent documents ??? - added quick links to example files ??? - even out speeds when drawing short line segments ??? - added animated circle drawing ??? - now exports entire drawing, even if not visible on screen ??? - fixed initial drawing speed to match menu ??? - fixed-width fonts in editor and interactive interpreter ??? - added classic turtle image ??? - file browser now starts in user's home directory ??? - removed scrollbars on graphic view ??? - now extends lines when animating _________________________________________________________________ Hotmail: Trusted email with Microsoft?s powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969 From greg.ewing at canterbury.ac.nz Sun Mar 7 22:09:12 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 08 Mar 2010 16:09:12 +1300 Subject: Reverse engineering CRC? Message-ID: <7vj7fdFnnjU1@mid.individual.net> Given some known data/crc pairs, how feasible is it to figure out the polynomial being used to generate the crc? In the case I'm looking at, it appears that the crc size may be at least 24 bits, so just trying all possible polynomials probably isn't doable. An article I found hints at the possibility of using GCDs to make the search more efficient, but doesn't go into any details. Anyone know of any literature about this? If it helps, I have the ability to generate test cases with known message contents to some extent, although I don't have complete control over the contents. Also it's a manual process, so generating large numbers of them automatically isn't an option. -- Greg From python at bdurham.com Sun Mar 7 22:09:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 07 Mar 2010 22:09:44 -0500 Subject: IMAP mail filters tool In-Reply-To: <4B9097A6.2050600@seehart.com> References: <4B9097A6.2050600@seehart.com> Message-ID: <1268017784.16962.1363607281@webmail.messagingengine.com> Ken, Check out Zed Shaw's very cool Lamson project. http://lamsonproject.org/ Malcolm ----- Original message ----- From: "Ken Seehart" To: python-list at python.org Date: Thu, 04 Mar 2010 21:33:26 -0800 Subject: IMAP mail filters tool I'm thinking of possibly making a simple client-agnostic tool for filtering and processing IMAP email. I'm a Thunderbird user, but I'm interested in a tool that is not client software specific. So I am is checking for prior art. Does anyone know of a filter tool with most of these features? * Written and customizable with python * IMAP based * Runs on client (i.e. without installing anything on the server) * Runs completely independent of client software (though could be launched from any email client that can support it) * Automatically suggests new rules based on manual movement of emails into folders (based on comparison of all header data across all existing folders) * Take arbitrary actions in response to rules (e.g. universally denying access to spam senders to all online cheese shops) * Capable of serving as a prototyping framework for things like spam filtering * General filtering functionality, not particularly focused on spam * Posts and updates rules to server via IMAP (i.e. by sending and automagically processing a special email message). Typical work-flow would be aimed at users who like to automatically sort their email prior to reading it. The goal is to have nearly all email sorted into folders so that most mail remaining in the Inbox is likely to be leftover spam missed by whatever spam filters are being used. In other words, the filters tend to effectively serve as white lists. Examples of unusual rules that don't seem to be supported by most email clients: * When you send an email, add the recipient to a filter such that email from that recipient goes to a "Unfiltered Replies" folder if it does not match any other filter. * Receiving email with certain fields matching certain regular expressions could automatically create a new folder and filter e.g.: + List-Id: "SF Bay Area Python group " yields a new folder "Lists/SF Bay Area Python group" with a corresponding rule + X-Launchpad-Bug: "product=phatch; milestone=..." yields a new folder "Bugs/Phatch" with a corresponding rule + X-Bugzilla-Product: "Shrubbery" yields a new folder "Bugs/Shrubbery" with a corresponding rule Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 22:41:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 03:41:35 GMT Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <4b9471ee$0$8836$c3e8da3@news.astraweb.com> On Mon, 08 Mar 2010 16:09:12 +1300, Gregory Ewing wrote: > Given some known data/crc pairs, how feasible is it to figure out the > polynomial being used to generate the crc? Can you just ask the application developer what CRC is being used? Or look at the source code? Disassemble the binary? > In the case I'm looking at, it appears that the crc size may be at least > 24 bits, so just trying all possible polynomials probably isn't doable. "At least"? Can't you tell by looking at them? A good place to start is here: http://en.wikipedia.org/wiki/Cyclic_redundancy_check http://en.wikipedia.org/wiki/List_of_checksum_algorithms You can at least eliminate known CRCs. There doesn't appear to be any 24- bit CRCs in common use, and very few other 24-bit checksums either, so you're probably looking at a custom CRC. > An article I found hints at the possibility of using GCDs to make the > search more efficient, but doesn't go into any details. Anyone know of > any literature about this? If you're reduced to trying to determine the polynomial from a sample of checksums, that's a curve fitting problem. There are various ways to fit polynomials through a set of known points, but as far as I know none of them are designed for reverse-engineering CRCs. You may be able to find something about curve-fitting using discrete maths (i.e. where all values are limited to integers) or with constraints. You should probably take this to somewhere like sci.crypt. Here's a thread from a few years back which might give you some hints: http://www.derkeiler.com/Newsgroups/sci.crypt/2008-07/msg00035.html Or here: http://stackoverflow.com/questions/401231/determining-crc-algorithm-from- data-crc-embedded-application -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 7 22:44:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 03:44:24 GMT Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <4b947298$0$8836$c3e8da3@news.astraweb.com> On Mon, 08 Mar 2010 16:09:12 +1300, Gregory Ewing wrote: > Given some known data/crc pairs, how feasible is it to figure out the > polynomial being used to generate the crc? Google is your friend: http://www.woodmann.com/fravia/crctut1.htm -- Steven From satishgroups1 at gmail.com Sun Mar 7 23:43:09 2010 From: satishgroups1 at gmail.com (satish groups) Date: Sun, 7 Mar 2010 20:43:09 -0800 (PST) Subject: Evaluating Income Property Message-ID: <3b8d2ac9-5e77-4910-9774-203cf1c6cd29@s25g2000prd.googlegroups.com> Income property is becoming more attractive to investors looking for a better return on their money. With today's low interest rates, income- producing properties such as apartments and duplexes can produce exciting returns. As with any type of property, the value of income property is what someone is willing to pay for it. But, the main determinant of value for income property is the net income it will produce. As we'll see later, the income approach should closely correlate with the market value under normal market conditions. Buyers of residential income property will want to know the answers to several questions not normally asked by home buyers. First, what is the amount of cash flow the property will generate? Second, how much actual net income will it produce? Third, are the tax benefits that the property will provide the investor? Cash flow can be described as the amount of money collected as rental income each month. http://greatincomeproperties.com/ From dr.cg at 126.com Mon Mar 8 00:08:56 2010 From: dr.cg at 126.com (CHEN Guang) Date: Mon, 8 Mar 2010 13:08:56 +0800 (CST) Subject: The C language like the Python, by the Python and for the Python --- PythoidC Message-ID: <1f91f2e.86f9.1273c2d0993.Coremail.dr.cg@126.com> Hi, if you are interested in C-Python mixed programming, please take a look at: http://pythoidc.googlecode.com PythoidC is the C language like the Python, by the Python and for the Python import c c.include(c.h.stdio) c.include(c.h.stdlib) '''Annotation is free!''' int fib(int n): if(n<=2): return1 else: return fib(n-1)+ fib(n-2) int main(int argc,char**argv): int n //C style annotation n=c.stdlib.atoi(argv[1]) c.stdio.printf('fibonacci(%d)=%d\n', n, fib(n)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Mon Mar 8 01:31:00 2010 From: python at rcn.com (Raymond Hettinger) Date: Sun, 7 Mar 2010 22:31:00 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: On Mar 7, 5:46?pm, Steven D'Aprano wrote: > Given that Counter supports negative counts, it looks to me that the > behaviour of __add__ and __sub__ is fundamentally flawed. You should > raise a bug report (feature enhancement) on the bug tracker. It isn't a bug. I designed it that way. There were several possible design choices, each benefitting different use cases. FWIW, here is the reasoning behind the design. The basic approach to Counter() is to be a dict subclass that supplies zero for missing values. This approach places almost no restrictions on what can be stored in it. You can store floats, decimals, fractions, etc. Numbers can be positive, negative, or zero. This design leaves users with a good deal of flexibility, but more importantly it keeps the API very close to regular dictionaries (thus lowering the learning curve). It also makes basic counter operations very fast. The update() method differs from regular dictionaries because dict.update() isn't very helpful in a counter context. Instead, it allows one counter to update another. Like the other basic counter operations, it places no restrictions on type (i.e. it works on with ints, floats, decimals, fractions, etc). or on sign (positive, negative, or zero). The only requirement is that the values support addition. The basic API also adds some convenience methods. The most_common() method tries to not be restrictive. It only requires the count values be orderable. For obvious reasons, the elements() method *does* have restrictions and won't work with float values and won't emit entries with non-positive counts. Beyond the basic API listed above which is straight-forward, the area where there were more interesting design choices were the Counter-to-Counter operations (__add__, __sub__, __or__, and __and__). One possible choice (the one preferred by the OP) was to has addition and subtraction be straight adds and subtracts without respect to sign and to not support __and__ and __or__. Straight addition was already supported via the update() method. But no direct support was provided for straight subtractions that leave negative values. Sorry about that. Instead the choice was to implement the four methods as multiset operations. As such, they need to correspond to regular set operations. For example, with sets: set('abc') - set('cde') # gives set('ab') Notice how subtracting 'e' did not produce a negative result? Now with multisets, we want the same result: Counter({'a':1, 'b':1, 'c':1'}) - Counter({'c':1, 'd':1, 'e':1}) So the design decision was to support multiset operations that produces only results with positive counts. These multiset-style mathematical operations are discussed in: Knuth's TAOCP Volume II section 4.6.3 exercise 19 and at http://en.wikipedia.org/wiki/Multiset . Also C++ has multisets that support only positive counts. So, there you have it. There design tries to be as unrestrictive as possible. When a choice had to be made, it favored multisets over behaviors supporting negative values. Fortunately, it is trivially easy to extend the class to add any behavior you want. class MyCounter(Counter): def __sub__(self, other): result = self.copy() for elem, cnt in other.items(): result[elem] -= cnt Hopes this gives you some insight into the design choices. Raymond Hettinger From stefan_ml at behnel.de Mon Mar 8 02:08:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Mar 2010 08:08:35 +0100 Subject: The C language like the Python, by the Python and for the Python --- PythoidC In-Reply-To: <1f91f2e.86f9.1273c2d0993.Coremail.dr.cg@126.com> References: <1f91f2e.86f9.1273c2d0993.Coremail.dr.cg@126.com> Message-ID: CHEN Guang, 08.03.2010 06:08: > Hi, if you are interested in C-Python mixed programming, please take a look at: > http://pythoidc.googlecode.com > PythoidC is the C language like the Python, by the Python and for the Python It looks a bit dangerous to me to parse C header files only with regular expressions. For Cython, some people seem to be using gcc-xml instead, and some have reported that clang is really nice to play with. However, none of those has made its way into Cython yet, mostly due to the dependency it would add. I don't know if tcc (which you seem to depend on) has anything comparable, but I doubt it. Just out of curiosity, is this syntax converter actually used for any real projects? Stefan From miraclesoul at hotmail.com Mon Mar 8 02:15:18 2010 From: miraclesoul at hotmail.com (Fahad Ahmad) Date: Mon, 8 Mar 2010 07:15:18 +0000 Subject: Calculating very large exponents in python In-Reply-To: References: , Message-ID: Thanks Geremy, That has been an absolute bump........... GOD i cant sit on my chair, it has worked even on 512 bit number and with no time.......... superb i would say. lastly, i am using the code below to calculate Largest Prime factor of a number: print ('''===============================================================================''' ''' CALCULATE HIGHEST PRIME FACTOR ''' '''===============================================================================''') #!/usr/bin/env python def highest_prime_factor(n): if isprime(n): return n for x in xrange(2,n ** 0.5 + 1): if not n % x: return highest_prime_factor(n/x) def isprime(n): for x in xrange(2,n ** 0.5 + 1): if not n % x: return False return True if __name__ == "__main__": import time start = time.time() print highest_prime_factor(1238162376372637826) print time.time() - start the code works with a bit of delay on the number : "1238162376372637826" but extending it to (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) makes python go crazy. Is there any way just like above, i can have it calculated it in no time. thanks for the support. > Date: Sun, 7 Mar 2010 15:40:59 -0500 > Subject: Re: Calculating very large exponents in python > From: debatem1 at gmail.com > To: miraclesoul at hotmail.com > CC: python-list at python.org > > On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad wrote: > > Dear All, > > > > i am writing my crytographic scheme in python, i am just a new user to it. > > I have written the complete code, the only point i am stuck it is that i am > > using 256 exponentiation which is normal in crytography but python just > > hangs on it. > > > > g**x [where both g and x are 256 bit numbers , in decimal they are around > > 77] > > > > after reading several forums, i just come to know it can be done using > > numpy, i have installed python(x,y) has has both numpy and scipy installed > > but i am not able to make it happen. > > > > any idea which library, module, or piece of code can solve this mystery :S > > > > sorry for bad english > > A couple of things: > > 1) if you're working with modular exponentiation, remember that pow() takes > three arguments, ie: > > a = 222222222222222222222222222 > b = 5555555555555555555555555555 > pow(a, b, 1200) > > will calculate the correct answer (768) very quickly, while > > a**b % 1200 > > has not terminated in the time it took me to compose this > email. > > 2) sage has a lot of excellent tools for crypto/cryptanalysis that you > may want to take a look at. > > 3) not saying you don't know what you're doing, but be careful when > rolling your own cryptosystems- even very good cryptographers make > implementation mistakes! > > Geremy Condra _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. http://clk.atdmt.com/GBL/go/201469230/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Mon Mar 8 02:38:55 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Mar 2010 08:38:55 +0100 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: * Gabriel Genellina: > En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach > escribi?: > >> Sorry, as with the places noted above, I can't understand what you're >> trying to say here. > > Regarding your posts, neither can I. All the time. Sorry, deciphering > your posts would force me to spend much more time than available and I > can't afford that - so I'm blocking your messages from now on. You could just ask if there was anything you didn't understand. Even with as little you quote readers can see my approach to that problem: asking. But your response, both the out of context quoting and your comment, seems solely designed to convey a negative impression instead of addressing any technical issue. Cheers, - Alf From stefan_ml at behnel.de Mon Mar 8 02:42:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Mar 2010 08:42:38 +0100 Subject: running a program on many processors In-Reply-To: References: Message-ID: Martin P. Hellwig, 08.03.2010 03:08: > I did read, two years or so ago, that AMD was looking in to something > that does just what you say on a cpu level, that is present itself as > one logical cpu but underneath there are multiple physical ones. I > wouldn't hold my breath though waiting for it. Many (desktop/server) CPUs actually do the opposite today - they present themselves as one physical CPU per core with more than one (commonly two) logical CPUs. This was introduced because modern CPUs have so many independent parts (integer arithmetic, floating point, SSE, memory access) that it's hard to keep all of them busy with a single process (which usually does either integer arithmetic *or* floating point, for example, rarely both in parallel). With multiple processes running on the same core, it becomes a lot easier to find independent operations that can be sent to different parts of the core in parallel. Automatically splitting single-threaded code over multiple cores is something that compilers (that see the full source code) should be able to do a lot better than hardware (which only sees a couple of basic operations at a time). http://en.wikipedia.org/wiki/Vectorization_%28computer_science%29 Expecting this to work for an interpreted Python program is somewhat unrealistic, IMHO. If you need data parallel execution, use something like map-reduce or Copperhead instead of relying on the CPU to figure out what's happening inside of a virtual machine. http://fperez.org/py4science/ucb/talks/20091118_copperhead_bcatanzaro.pdf Stefan From taskinoor.hasan at csebuet.org Mon Mar 8 02:48:00 2010 From: taskinoor.hasan at csebuet.org (Taskinoor Hasan) Date: Mon, 8 Mar 2010 13:48:00 +0600 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: <79153a2e1003072348r16fd4427i7ea2b3fbdd626c91@mail.gmail.com> First of all, you simply can't use this straight approach of primality testing for very very big numbers. There are a number of algorithms, both deterministic and random. Please Google for them (and don't forget to check Wikipedia too). Study the random algorithms to check whether they can be applied in your situation, since they are faster. And another implementation issue. Try to avoid many recursive calls. It's always possible to convert a recursive function to a non-recursive one and that will be faster if your recursion is too long. Hope it helps. Regards Taskinoor Hasan (Sajid) On Mon, Mar 8, 2010 at 1:15 PM, Fahad Ahmad wrote: > Thanks Geremy, > > That has been an absolute bump........... GOD i cant sit on my chair, it > has worked even on 512 bit number and with no time.......... > superb i would say. > > lastly, i am using the code below to calculate Largest Prime factor of a > number: > > print > ('''===============================================================================''' > ''' CALCULATE HIGHEST PRIME > FACTOR ''' > > '''===============================================================================''') > > #!/usr/bin/env python > def highest_prime_factor(n): > if isprime(n): > return n > for x in xrange(2,n ** 0.5 + 1): > if not n % x: > return highest_prime_factor(n/x) > def isprime(n): > for x in xrange(2,n ** 0.5 + 1): > if not n % x: > return False > return True > if __name__ == "__main__": > import time > start = time.time() > print highest_prime_factor(1238162376372637826) > print time.time() - start > > the code works with a bit of delay on the number : "1238162376372637826" > but extending it to > (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) > makes python go crazy. Is there any way just like above, i can have it > calculated it in no time. > > > thanks for the support. > > > > > > Date: Sun, 7 Mar 2010 15:40:59 -0500 > > Subject: Re: Calculating very large exponents in python > > From: debatem1 at gmail.com > > To: miraclesoul at hotmail.com > > CC: python-list at python.org > > > > > On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad > wrote: > > > Dear All, > > > > > > i am writing my crytographic scheme in python, i am just a new user to > it. > > > I have written the complete code, the only point i am stuck it is that > i am > > > using 256 exponentiation which is normal in crytography but python just > > > hangs on it. > > > > > > g**x [where both g and x are 256 bit numbers , in decimal they are > around > > > 77] > > > > > > after reading several forums, i just come to know it can be done using > > > numpy, i have installed python(x,y) has has both numpy and scipy > installed > > > but i am not able to make it happen. > > > > > > any idea which library, module, or piece of code can solve this mystery > :S > > > > > > sorry for bad english > > > > A couple of things: > > > > 1) if you're working with modular exponentiation, remember that pow() > takes > > three arguments, ie: > > > > a = 222222222222222222222222222 > > b = 5555555555555555555555555555 > > pow(a, b, 1200) > > > > will calculate the correct answer (768) very quickly, while > > > > a**b % 1200 > > > > has not terminated in the time it took me to compose this > > email. > > > > 2) sage has a lot of excellent tools for crypto/cryptanalysis that you > > may want to take a look at. > > > > 3) not saying you don't know what you're doing, but be careful when > > rolling your own cryptosystems- even very good cryptographers make > > implementation mistakes! > > > > Geremy Condra > > ------------------------------ > Hotmail: Powerful Free email with security by Microsoft. Get it now. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.cg at 126.com Mon Mar 8 03:49:15 2010 From: dr.cg at 126.com (CHEN Guang) Date: Mon, 8 Mar 2010 16:49:15 +0800 (CST) Subject: The C language like the Python, by the Python and for the Python--- PythoidC In-Reply-To: References: Message-ID: <195722f.da8d.1273cf6bb23.Coremail.dr.cg@126.com> Dear Stefan, Thanks a lot for your interest in PythoidC. Yes, PythoidC takes regular expression to parse C header files, but there is no danger at all, because, the parsed result is only used for introspecting and auto-completion, has noting to do with syntax converting and compiling. I just improved PythoidC to a satisfying version for me, up to now, all the projects with PythoidC are experimental or educational. PythoidC is mainly used to deal with simple but time consuming tasks in Python project, as you see, PythoidC file can be imported the same any Python files. Oliver ( ChenGuang ) ? CHEN Guang, 08.03.2010 06:08: > Hi, if you are interested in C-Python mixed programming, please take a look at: > http://pythoidc.googlecode.com > PythoidC is the C language like the Python, by the Python and for the Python It looks a bit dangerous to me to parse C header files only with regular expressions. For Cython, some people seem to be using gcc-xml instead, and some have reported that clang is really nice to play with. However, none of those has made its way into Cython yet, mostly due to the dependency it would add. I don't know if tcc (which you seem to depend on) has anything comparable, but I doubt it. Just out of curiosity, is this syntax converter actually used for any real projects? Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 8 03:53:47 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 08 Mar 2010 09:53:47 +0100 Subject: isinstance(False, int) In-Reply-To: References: Message-ID: <4b94baf3$0$20649$426a74cc@news.free.fr> Rolando Espinoza La Fuente a ?crit : > On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >> Arnaud Delobelle wrote: >> >>>>>> 1 == True >>> True >>>>>> 0 == False >>> True >>> >>> So what's your question? >> Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, >> but not in Python.. Although I can understand the rationale after skimming >> PEP 285, I still don't like it very much. >> > > So, the pythonic way to check for True/False should be: > >>>> 1 is True > False > >>>> 0 is False > False > > instead of ==, right? Nope. The pythonic way is to check for truth value - not for True or False -, and to only use the identity test when wanting to test for identity. From fox.joe87 at gmail.com Mon Mar 8 03:59:14 2010 From: fox.joe87 at gmail.com (Mahesh) Date: Mon, 8 Mar 2010 00:59:14 -0800 (PST) Subject: libc Sleep api performs a busy waiting Message-ID: Hi, I am having a problem while using sleep function from libc , the thread in which i am calling it is getting struck and not allowing other threads to execute. Here is a simple code that i am trying to exeute import threading import time import dl def dummy1(): a=dl.open('/lib/libc.so.6') print "in thread 1 Start" a.call('sleep',2) #time.sleep(2) print "in thread 1 End" def dummy2(): print "in thread 2 Start" time.sleep(1) print "in thread 2 End" newThread1=threading.Thread(None,dummy1) newThread2=threading.Thread(None,dummy2) newThread1.start() newThread2.start() print "in main" The out put of this program is (In this case thread 1 even though i am calling a sleep function its not allowing other threads to execute, other threads execute only after the completion of first thread) in thread 1 Start in thread 1 End in thread 2 Start in main in thread 2 End where as if i use time.sleep instead of a.call(sleep) the out put is (which i guess is right behaviour, because it start the threads and suspends them because the have sleep , and continue executing the main thread) in thread 1 Start in thread 2 Start in main in thread 2 End in thread 1 End From processor.dev1l at gmail.com Mon Mar 8 04:26:58 2010 From: processor.dev1l at gmail.com (Processor-Dev1l) Date: Mon, 8 Mar 2010 01:26:58 -0800 (PST) Subject: running a program on many processors References: Message-ID: <112ea184-1e81-45aa-b5ed-73d6ded7a460@d2g2000yqa.googlegroups.com> On Mar 8, 1:18?am, Pawe? Bany? wrote: > Hello, > > I have already read about Python and multiprocessing which allows using > many processors. The idea is to split a program into separate tasks and > run each of them on a separate processor. However I want to run a Python > program doing a single simple task on many processors so that their > cumulative power is available to the program as if there was one huge > CPU instead of many separate ones. Is it possible? How can it be achieved? > > Best regards, > > Pawe? I can suggest you to try some .NET language (like c#, Boo <-- python- like, or maybe even IronPython). Reason is that .NET languages do analyze the code and split them into logical parts that run across threads. From fox.joe87 at gmail.com Mon Mar 8 04:30:45 2010 From: fox.joe87 at gmail.com (Joe Fox) Date: Mon, 8 Mar 2010 15:00:45 +0530 Subject: libc Sleep api performs a busy waiting Message-ID: <27e52ad11003080130v7664d951p3ba92bd692efe0ad@mail.gmail.com> Hi , I am having a problem while using sleep function from libc , the thread in which i am calling it is getting struck and not allowing other threads to execute. Here is a simple code that i am trying to exeute import threading import time import dl def dummy1(): a=dl.open('/lib/libc.so.6') print "in thread 1 Start" a.call('sleep',2) #time.sleep(2) print "in thread 1 End" def dummy2(): print "in thread 2 Start" time.sleep(1) print "in thread 2 End" newThread1=threading.Thread(None,dummy1) newThread2=threading.Thread(None,dummy2) newThread1.start() newThread2.start() print "in main" The out put of this program is (In this case thread 1 even though i am calling a sleep function its not allowing other threads to execute, other threads execute only after the completion of first thread) in thread 1 Start in thread 1 End in thread 2 Start in main in thread 2 End where as if i use time.sleep instead of a.call(sleep) the out put is (which i guess is right behaviour, because it start the threads and suspends them because the have sleep , and continue executing the main thread) in thread 1 Start in thread 2 Start in main in thread 2 End in thread 1 End Can any of you point me how to over come this.? Thanks Mahesh -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Mon Mar 8 05:13:09 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Mar 2010 05:13:09 -0500 Subject: Reverse engineering CRC? In-Reply-To: <4b947298$0$8836$c3e8da3@news.astraweb.com> References: <7vj7fdFnnjU1@mid.individual.net> <4b947298$0$8836$c3e8da3@news.astraweb.com> Message-ID: <4B94CDB5.9010506@ieee.org> Steven D'Aprano wrote: > On Mon, 08 Mar 2010 16:09:12 +1300, Gregory Ewing wrote: > > >> Given some known data/crc pairs, how feasible is it to figure out the >> polynomial being used to generate the crc? >> > > Google is your friend: > > http://www.woodmann.com/fravia/crctut1.htm > > That page was interesting to read, especially since I've implemented the three algorithms - CRC16, CRC32, and the reversed version of CRC16, all in the long-distant past. However, if there's anything in there about how to derive the polynomial algorithm from (a few) samples I missed it entirely. Instead, what it calls reverse engineering is figuring out how to modify a message to force it to have a desired CRC value (when the CRC polynomial is already known). DaveA From mail at timgolden.me.uk Mon Mar 8 05:38:52 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Mar 2010 10:38:52 +0000 Subject: Best practice way to detect internet connectivity under Python 2.6/Windows In-Reply-To: <1268016090.13219.1363604225@webmail.messagingengine.com> References: <1268016090.13219.1363604225@webmail.messagingengine.com> Message-ID: <4B94D3BC.8040808@timgolden.me.uk> On 08/03/2010 02:41, python at bdurham.com wrote: > Is the best pratice way to detect internet connectivity under > Windows (using Python 2.6) simply to attempt to access a known > internet website using urllib or urlib2 wrapped in a try/except > construct? Well, in theory you could use the Internet API: http://msdn.microsoft.com/en-us/library/aa383996%28VS.85%29.aspx which is exposed via the win32inet module: http://timgolden.me.uk/pywin32-docs/win32inet.html but I'd just do a socket connection to port 80 (or some known port on some known server) with a reasonable timeout. TJG From fetchinson at googlemail.com Mon Mar 8 05:53:25 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 8 Mar 2010 11:53:25 +0100 Subject: Curiosity stirkes me on 'import this'. In-Reply-To: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> References: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> Message-ID: > I took a look at the 'this' module to see where the file is stored. This is > probably old news to some people, but was new to me. > > print this.s > Gur Mra bs Clguba, ol Gvz Crgref > > Ornhgvshy vf orggre guna htyl. > Rkcyvpvg vf orggre guna vzcyvpvg. > Fvzcyr vf orggre guna pbzcyrk. > Pbzcyrk vf orggre guna pbzcyvpngrq. > Syng vf orggre guna arfgrq. > Fcnefr vf orggre guna qrafr. > Ernqnovyvgl pbhagf. > Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf. > Nygubhtu cenpgvpnyvgl orngf chevgl. > Reebef fubhyq arire cnff fvyragyl. > Hayrff rkcyvpvgyl fvyraprq. > Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff. > Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg. > Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu. > Abj vf orggre guna arire. > Nygubhtu arire vf bsgra orggre guna *evtug* abj. > Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn. > Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn. > Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr! > > And some other attributes in 'this' module as well, that decodes the string. > I'm curious. Was this encoded purely for fun? Yes. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From greg.ewing at canterbury.ac.nz Mon Mar 8 06:06:36 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Mar 2010 00:06:36 +1300 Subject: Reverse engineering CRC? In-Reply-To: <4b9471ee$0$8836$c3e8da3@news.astraweb.com> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> Message-ID: <7vk3eiFtivU1@mid.individual.net> Steven D'Aprano wrote: > Can you just ask the application developer what CRC is being used? Or > look at the source code? Disassemble the binary? There's no source, and the binary is enormous. I could ask, but I wouldn't hold out much hope of them being willing to tell me. >>it appears that the crc size may be at least >>24 bits, so just trying all possible polynomials probably isn't doable. > > "At least"? Can't you tell by looking at them? It's not entirely clear exactly which bytes are part of the CRC. There are 3 adjacent bytes in the header of the file that change when I modify the contents, which led me to think it was a 24-bit CRC. But I now believe that one of them is not part of the CRC, and it's actually 16 bits. Using pycrc, I've now tried all possible 16-bit polynomials, with various combinations of bit and byte reversal, but I haven't found one that works consistently, so I'm wondering whether it's using some non-standard algorithm. -- Greg From vlastimil.brom at gmail.com Mon Mar 8 06:13:31 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 8 Mar 2010 12:13:31 +0100 Subject: negative "counts" in collections.Counter? In-Reply-To: References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <9fdb569a1003080313mf6c8d9cr932678c11c4e80e4@mail.gmail.com> 2010/3/8 Raymond Hettinger : > On Mar 7, 5:46?pm, Steven D'Aprano cybersource.com.au> wrote: >> Given that Counter supports negative counts, it looks to me that the >> behaviour of __add__ and __sub__ is fundamentally flawed. You should >> raise a bug report (feature enhancement) on the bug tracker. > > It isn't a bug. ?I designed it that way. > There were several possible design choices, > each benefitting different use cases. >... > One possible choice (the one preferred by the OP) was to > has addition and subtraction be straight adds and subtracts > without respect to sign and to not support __and__ and __or__. > Straight addition was already supported via the update() method. > But no direct support was provided for straight subtractions > that leave negative values. ?Sorry about that. > > Instead the choice was to implement the four methods as > multiset operations. ?As such, they need to correspond > to regular set operations. ?For example, with sets: > >... > Hopes this gives you some insight into the design choices. > > > Raymond Hettinger > Thank you very much for the exhaustive explanation Raymond! I very much suspected, there would be some exact reasoning behind it, as these negative counts are explicitly handled in the code of these methods. I just happened to expect the straightforward addition and subtraction and possibly the zero truncation or an exception in incompatible cases (like elements() with floats, currently). This way also the negative part would be available and the truncation possible. I am by far not able to follow all of the mathematical background, but even for zero-truncating multiset, I would expect the truncation on input rather than on output of some operations. E.g. the following seems surprising to me in context of the discarded negatives by addition or subtraction: >>> c1=collections.Counter({'a': -11, 'b': -8}) >>> c2=collections.Counter({'a': 3}) >>> c2-c1 Counter({'a': 14, 'b': 8}) >>> Probably a kind of negative_update() or some better named method will be handy, like the one you supplied or simply the current module code without the newcount > 0: ... condition. Or would it be an option to have a keyword argument like zero_truncate=False which would influence this behaviour? Or is some other method than elements() incompatible with negative counts? (I actually can imagine comparing negative counts on both sides. e.g. in a secondary comparison of two wordlists with specific removed items - comparing to the "master" list.) Additionally, were issubset and issuperset considered for this interface (not sure whether symmetric_difference would be applicable)? Anyway, I recognise, that I can easily use a custom class for these tasks, if these usecases are rare or non-standard for this general collection object. Thanks again, vbr From kshipras at packtpub.com Mon Mar 8 06:25:07 2010 From: kshipras at packtpub.com (Kshipra Singh) Date: Mon, 8 Mar 2010 16:55:07 +0530 Subject: Opportunity to author Python books- Packt Publishing. Message-ID: Hi All, I am writing to you for Packt Publishing, the publishers computer related books. We are planning to extend our catalogue of cookbooks and are currently inviting "Python" fanatics interested in writing a cookbook. So, if you love "Python" and are interested in writing a cookbook, please contact us with your book ideas at author at packtpub.com. Even if you do not have a book idea and are simply interested in authoring a cookbook, we are keen to hear from you. More details about the opportunity are available at: http://authors.packtpub.com/content/python-fanatics-invited-write-packt Thanks Kshipra Singh Author Relationship Manager Packt Publishing www.PacktPub.com Skype: kshiprasingh15 Twitter: http://twitter.com/kshipras Interested in becoming an author? Visit http://authors.packtpub.com for all the information you need about writing for Packt. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Mon Mar 8 06:34:11 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 08 Mar 2010 22:34:11 +1100 Subject: Curiosity stirkes me on 'import this'. References: <2d56febf1003070159o5346701ema0ba72a43066ace2@mail.gmail.com> Message-ID: <871vfv11zg.fsf@benfinney.id.au> Daniel Fetchinson writes: > > I'm curious. Was this encoded purely for fun? > > Yes. For some more fun, try measuring the ?this? module source code against the principles in the Zen. -- \ ?Leave nothing to chance. Overlook nothing. Combine | `\ contradictory observations. Allow yourself enough time.? | _o__) ?Hippocrates | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Mon Mar 8 07:21:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Mar 2010 12:21:18 GMT Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> On Sun, 07 Mar 2010 22:31:00 -0800, Raymond Hettinger wrote: > On Mar 7, 5:46?pm, Steven D'Aprano cybersource.com.au> wrote: >> Given that Counter supports negative counts, it looks to me that the >> behaviour of __add__ and __sub__ is fundamentally flawed. You should >> raise a bug report (feature enhancement) on the bug tracker. > > It isn't a bug. I designed it that way. There were several possible > design choices, each benefitting different use cases. Thanks for the explanation Raymond. A few comments follow: > FWIW, here is the reasoning behind the design. > > The basic approach to Counter() is to be a dict subclass that supplies > zero for missing values. This approach places almost no restrictions > on what can be stored in it. You can store floats, decimals, fractions, > etc. Numbers can be positive, negative, or zero. Another way of using default values in a dict. That's five that I know of: dict.get, dict.setdefault, dict.pop, collections.defaultdict, and collections.Counter. And the Perl people criticise Python for having "only one way to do it" *wink* (That's not meant as a criticism, merely an observation.) [...] > One possible choice (the one preferred by the OP) was to has addition > and subtraction be straight adds and subtracts without respect to sign > and to not support __and__ and __or__. Straight addition was already > supported via the update() method. But no direct support was provided > for straight subtractions that leave negative values. Sorry about that. Would you consider a feature enhancement adding an additional method, analogous to update(), to perform subtractions? I recognise that it's easy to subclass and do it yourself, but there does seem to be some demand for it, and it is an obvious feature given that Counter does support negative counts. > Instead the choice was to implement the four methods as multiset > operations. As such, they need to correspond to regular set operations. Personally, I think the behaviour of + and - would be far less surprising if the class was called Multiset. Intuitively, one would expect counters to be limited to ints, and to support negative counts when adding and subtracting. In hindsight, do you think that Multiset would have been a better name? -- Steven From steve at holdenweb.com Mon Mar 8 07:28:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Mar 2010 07:28:06 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Gabriel Genellina: >> En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach >> escribi?: >> >>> Sorry, as with the places noted above, I can't understand what you're >>> trying to say here. >> >> Regarding your posts, neither can I. All the time. Sorry, deciphering >> your posts would force me to spend much more time than available and I >> can't afford that - so I'm blocking your messages from now on. > > > You could just ask if there was anything you didn't understand. > > Even with as little you quote readers can see my approach to that > problem: asking. > > But your response, both the out of context quoting and your comment, > seems solely designed to convey a negative impression instead of > addressing any technical issue. > This isn't an isolated case, Alf. Physician, heal thyself. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Mar 8 07:33:57 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Mar 2010 07:33:57 -0500 Subject: libc Sleep api performs a busy waiting In-Reply-To: References: Message-ID: Mahesh wrote: > Hi, > > I am having a problem while using sleep function from libc , the > thread in which i am calling it is getting struck and not allowing > other threads to execute. Here is a simple code that i am trying to > exeute > > import threading > import time > import dl > > > def dummy1(): > a=dl.open('/lib/libc.so.6') > print "in thread 1 Start" > a.call('sleep',2) > #time.sleep(2) > print "in thread 1 End" > > def dummy2(): > print "in thread 2 Start" > time.sleep(1) > print "in thread 2 End" > newThread1=threading.Thread(None,dummy1) > newThread2=threading.Thread(None,dummy2) > newThread1.start() > newThread2.start() > > print "in main" > > > > The out put of this program is (In this case thread 1 even though i > am calling a sleep function its not allowing other threads to execute, > other threads execute only after the completion of first thread) > > in thread 1 Start > in thread 1 End > in thread 2 Start > in main > in thread 2 End > > > where as if i use time.sleep instead of a.call(sleep) the out put is > (which i guess is right behaviour, because it start the threads and > suspends them because the have sleep , and continue executing the main > thread) > in thread 1 Start > in thread 2 Start > in main > in thread 2 End > in thread 1 End > > Why not just use the time module's sleep function? Unlike the libc code it releases Python's GIL (global interpreter lock), thus allowing other threads to run. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Mon Mar 8 08:02:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Mar 2010 14:02:46 +0100 Subject: Conditional based on whether or not a module is being used In-Reply-To: References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> Message-ID: <4B94F576.6050708@sequans.com> Pete Emerson wrote: > On Mar 5, 1:14 pm, Chris Rebert wrote: > >> On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: >> >>> On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: >>> >>>> On 3/5/10, Pete Emerson wrote: >>>> >>>>> In a module, how do I create a conditional that will do something >>>>> based on whether or not another module has been loaded? >>>>> >> >> >>>>> If someone is using foo module, I want to take advantage of its >>>>> features and use it in foobar, otherwise, I want to do something else. >>>>> In other words, I don't want to create a dependency of foobar on foo. >>>>> >>>>> My failed search for solving this makes me wonder if I'm approaching >>>>> this all wrong. >>>>> >>>> Just try importing foo, and then catch the exception if it's not installed. >>>> >> >> >>> Except I want to use the module only if the main program is using it >>> too, not just if it's available for use. I think that I found a way in >>> my follow-up post to my own message, but not sure it's the best way or >>> conventional. >>> >> What is your use case for this behavior exactly? You've piqued my curiosity. >> >> Cheers, >> Chris >> --http://blog.rebertia.com >> > > I have written my first module called "logger" that logs to syslog via > the syslog module but also allows for logging to STDOUT in debug mode > at multiple levels (to increase verbosity depending on one's need), or > both. I've looked at the logging module and while it might suit my > needs, it's overkill for me right now (I'm still *very* much a python > newbie). > > I want to write other modules, and my thinking is that it makes sense > for those modules to use the "logger" module to do the logging, if and > only if the parent using the other modules is also using the logger > module. > > In other words, I don't want to force someone to use the "logger" > module just so they can use my other modules, even if the "logger" > module is installed ... but I also want to take advantage of it if I'm > using it. > > Now that I've written that, I'm not sure that makes a whole lot of > sense. It seems like I could say, "hey, this person has the 'logger' > module available, let's use it!". > > Thoughts? > The logging module is not overkill, use it. It can be simple if you want it to be, and can be more complex if you need advanced logging features. All the "what if the application is not using my logger module" is dealt with by the logging module. And I'm not its designer in any way, so my advice is completely objective :-) It's definitely worth spending some time ramping up with it. JM From davea at ieee.org Mon Mar 8 08:07:27 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Mar 2010 08:07:27 -0500 Subject: Reverse engineering CRC? In-Reply-To: <7vk3eiFtivU1@mid.individual.net> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> Message-ID: <4B94F68F.3000100@ieee.org> Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Can you just ask the application developer what CRC is being used? Or >> look at the source code? Disassemble the binary? > > There's no source, and the binary is enormous. I could ask, > but I wouldn't hold out much hope of them being willing to > tell me. > >>> it appears that the crc size may be at least >>> 24 bits, so just trying all possible polynomials probably isn't doable. >> >> "At least"? Can't you tell by looking at them? > > It's not entirely clear exactly which bytes are part of the > CRC. There are 3 adjacent bytes in the header of the file > that change when I modify the contents, which led me to > think it was a 24-bit CRC. But I now believe that one of > them is not part of the CRC, and it's actually 16 bits. > > Using pycrc, I've now tried all possible 16-bit polynomials, > with various combinations of bit and byte reversal, but I > haven't found one that works consistently, so I'm wondering > whether it's using some non-standard algorithm. > Or even some other standard algorithm. If you know so little about the value, how do you even know it's a CRC ? Could it be a ones-complement sum, such as used in Ethernet? Is the problem really worth it? The possibilities are practically unbounded. And if the developer is really determined to make it difficult, they could be doing multiple passes over the data, in which case probably disassembly (or subtle debug tracing) may be your best bet. DaveA Dave From jeanmichel at sequans.com Mon Mar 8 08:10:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Mar 2010 14:10:48 +0100 Subject: Import problem In-Reply-To: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4B94F758.9080101@sequans.com> Johny wrote: > I have this directory structure > > C: > \A > __init__.py > amodule.py > > \B > __init__.py > bmodule.py > > \D > __init__.py > dmodule.py > > and I want to import bmodule.py > C:\>cd \ > > C:\>python > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> from A.B import bmodule >>>> > I am bmodule > > C:\> > > so far so good. Now I would like to import bmodule but if the current > directory is \D subdirectory. > > C:> cd \A\B\D > C:\A\B\D> > C:\A\B\D>python > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sys >>>> sys.path.append('C:\\A') >>>> from A.B import bmodule >>>> > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named A.B > > C:\> > > so I can not import a module from the parent directory? Or where did I > make an error? > Thanks for help > > L. > try import sys sys.path.append('C:\\') from A.B import bmodule JM From earnmoney9421 at gmail.com Mon Mar 8 08:40:03 2010 From: earnmoney9421 at gmail.com (Google Adsense) Date: Mon, 8 Mar 2010 05:40:03 -0800 (PST) Subject: What to do if anything bites. Message-ID: What to do if anything bites. Check our bites treatment at http://108ambulance.blogspot.com/2010/03/108-ambulance-home-page.html From aotto1968 at users.sourceforge.net Mon Mar 8 08:43:46 2010 From: aotto1968 at users.sourceforge.net (Andreas Otto) Date: Mon, 08 Mar 2010 14:43:46 +0100 Subject: ANNOUNCE: Major Feature Release - NHI1-0.7, PLMK-1.6 and libmsgque-4.5 Message-ID: Dear User, ANNOUNCE: Major Feature Release ==================================== libmsgque: Application-Server-Toolkit for C, C++, JAVA, C#, TCL, PERL, PYTHON, VB.NET PLMK: Programming-Language-Microkernel NHI1: Non-Human-Intelligence #1 SUMMARY ======= This is a 'major-feature-release' to add 'longtime-transaction' support. A 'longtime-transaction' is a transaction with a possible infinite time period between the start and the end. A 'longtime-transaction' is always a 'persistent-transaction' too. The 'persistent' support is available as an in-memory solution on the 'application-server' or in an additional 'bidirectional-filter' available for the next release. A typical scenario for a 'longtime-transaction' is: * A user with a client connect to the server and start a 'longtime-transaction' job. After a while the user shutdown the client and leave the office. At the next morning the user start the client again and the results are send from the server to the client. * On a space mission the time-overhead between transaction start and end is large. It is usually not possible to keep the client-server-connection open all the time. * On a military action-system the enemy try to interrupted the client-server-connection to disable data communication. To use a 'longtime-transaction' the results are send to a 'client-service' registered with MqServiceCreate. This service and addtional data (I call this data 'local-context-data') have to be added to the 'longterm-transaction' package to be available in the result. On the 'link-target' the 'local-context-data' is initial stripped from the 'data-package' and is later added to the results again. The 'local-context-data' is added to the 'data-package' with MqSendT_START and MqSendT_END. The 'local-context-data' is read from the 'data-package' with MqReadT_START and MqReadT_END. LINKS ===== libmsgque: > http://nhi1.berlios.de/theLink/index.htm NHI1: > http://nhi1.berlios.de/ DOWNLOAD: > http://developer.berlios.de/projects/nhi1/ mfg Andreas Otto (aotto1968) From ssteinerx at gmail.com Mon Mar 8 09:03:21 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 8 Mar 2010 09:03:21 -0500 Subject: A "scopeguard" for Python In-Reply-To: References: <57a0a876-31c5-4b02-8c2d-d45f3c922901@z35g2000yqd.googlegroups.com> Message-ID: <759A6420-DC8E-4282-8667-6C851D5E0AC8@gmail.com> On Mar 8, 2010, at 7:28 AM, Steve Holden wrote: >> >> But your response, both the out of context quoting and your comment, >> seems solely designed to convey a negative impression instead of >> addressing any technical issue. >> > This isn't an isolated case, Alf. Physician, heal thyself. As far as I can tell, this happens on every thread Alf is involved in at one point or another. I'm sure it's "everyone else." S From xahlee at gmail.com Mon Mar 8 10:12:05 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 8 Mar 2010 07:12:05 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> Message-ID: <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> many people mentioned scalibility... though i think it is fruitful to talk about at what size is the NoSQL databases offer better scalability than SQL databases. For example, consider, if you are within world's top 100th user of database in terms of database size, such as Google, then it may be that the off-the-shelf tools may be limiting. But how many users really have such massive size of data? note that google's need for database today isn't just a seach engine. It's db size for google search is probably larger than all the rest of search engine company's sizes combined. Plus, there's youtube (vid hosting), gmail, google code (source code hosting), google blog, orkut (social networking), picasa (photo hosting), etc, each are all ranked within top 5 or so with respective competitors in terms of number of accounts... so, google's datasize is probably number one among the world's user of databases, probably double or triple than the second user with the most large datasize. At that point, it seems logical that they need their own db, relational or not. Xah ? http://xahlee.org/ ? On Mar 4, 10:35?pm, John Nagle wrote: > Xah Lee wrote: > > recently i wrote a blog article on The NoSQL Movement > > athttp://xahlee.org/comp/nosql.html > > > i'd like to post it somewhere public to solicit opinions, but in the > > 20 min or so, i couldn't find a proper newsgroup, nor private list > > that my somewhat anti-NoSQL Movement article is fitting. > > ? ? Too much rant, not enough information. > > ? ? There is an argument against using full relational databases for > some large-scale applications, ones where the database is spread over > many machines. ?If the database can be organized so that each transaction > only needs to talk to one database machine, the locking problems become > much simpler. ?That's what BigTable is really about. > > ? ? For many web applications, each user has more or less their own data, > and most database activity is related to a single user. ?Such > applications can easily be scaled up with a system that doesn't > have inter-user links. ?There can still be inter-user references, > but without a consistency guarantee. ?They may lead to dead data, > like Unix/Linux symbolic links. ?This is a mechanism adequate > for most "social networking" sites. > > ? ? There are also some "consistent-eventually" systems, where a query > can see old data. ?For non-critical applications, those can be > very useful. ?This isn't a SQL/NoSQL thing; MySQL asynchronous > replication is a "consistent-eventually" system. ?Wikipedia uses > that for the "special" pages which require database lookups. > > ? ? If you allow general joins across any tables, you have to have all > the very elaborate interlocking mechanisms of a distributed database. > The serious database systems (MySQL Cluster and Oracle, for example) > do offer that, but there are usually > substantial complexity penalties, and the databases have to be carefully > organized to avoid excessive cross-machine locking. ?If you don't need > general joins, a system which doesn't support them is far simpler. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle From rolf.oltmans at gmail.com Mon Mar 8 10:36:13 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 8 Mar 2010 07:36:13 -0800 (PST) Subject: Converting HTML to PDF using Python? Message-ID: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> Hi Python superstars, Guys, any ideas on how to convert HTML files to PDF files? Or as an alternative, how to convert HTML files to an image file(jpeg/png/etc)? Ideally, the converted PDF/Image file should like exactly like the way HTML file looks in the browser. I really have no idea about this so I will really appreciate all the help. Thanks in advance and kindly pardon my ignorance. Thanks, Oltmans From clp2 at rebertia.com Mon Mar 8 11:16:45 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Mar 2010 08:16:45 -0800 Subject: negative "counts" in collections.Counter? In-Reply-To: <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> Message-ID: <50697b2c1003080816m46752277of34e9bf4bd9670d6@mail.gmail.com> On Mon, Mar 8, 2010 at 4:21 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Sun, 07 Mar 2010 22:31:00 -0800, Raymond Hettinger wrote: >> On Mar 7, 5:46 pm, Steven D'Aprano > cybersource.com.au> wrote: >>> Given that Counter supports negative counts, it looks to me that the >>> behaviour of __add__ and __sub__ is fundamentally flawed. You should >>> raise a bug report (feature enhancement) on the bug tracker. >> >> It isn't a bug. I designed it that way. There were several possible >> design choices, each benefitting different use cases. >> Instead the choice was to implement the four methods as multiset >> operations. As such, they need to correspond to regular set operations. > > Personally, I think the behaviour of + and - would be far less surprising > if the class was called Multiset. Intuitively, one would expect counters > to be limited to ints, and to support negative counts when adding and > subtracting. In hindsight, do you think that Multiset would have been a > better name? Of course I'm not Raymond, but I'd encourage reading the original announcement thread where that and related issues were discussed: http://mail.python.org/pipermail/python-list/2009-January/1189466.html To summarize the arguments against "Multiset": * the API is primarily dict-like, not set-like ** related to this, len() and .items() don't behave in what is arguably an "intuitive" way for multisets * the API allows for negative counts; sets don't normally allow negative multiplicities The same pretty much also goes for why "Bag" wouldn't be an appropriate name. Finally, it leaves the names available for when a proper Bag/Multiset is added. :) Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanelson at gmail.com Mon Mar 8 12:06:25 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Mon, 8 Mar 2010 17:06:25 +0000 Subject: Trouble with quotes Message-ID: Hi, I've written some (primitive) code to parse some apache logfies and establish if apache has appended a session cookie to the end. We're finding that some browsers don't and apache doesn't just append a "-" - it just omits it. It's working fine, but for an edge case: Couldn't match 192.168.1.107 - - [24/Feb/2010:20:30:44 +0100] "GET http://sekrit.com/node/175523 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:31:15 +0100] "GET http://sekrit.com/node/175521 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:32:07 +0100] "GET http://sekrit.com/node/175520 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:32:33 +0100] "GET http://sekrit.com/node/175522 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [24/Feb/2010:20:33:01 +0100] "GET http://sekrit.com/node/175527 HTTP/1.1" 200 - "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" Couldn't match 192.168.1.107 - - [25/Feb/2010:17:01:54 +0100] "GET http://sekrit.com/search/results/ HTTP/1.0" 200 - "http://sekrit.com/search/results/"guideline%20grids"&page=1" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" Couldn't match 192.168.1.107 - - [25/Feb/2010:17:02:15 +0100] "GET http://sekrit.com/search/results/ HTTP/1.0" 200 - "http://sekrit.com/search/results/"guideline%20grids"&page=1" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" If there are " " inside the request string, my regex breaks. Here's the code: #!/usr/bin/env python import re pattern = r'(?P^(-|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(, [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})*){1}) (?P(\S*)) (?P(\S*)) (?P(\[[^\]]+\])) (?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?) (?P(\S*)) (?P(\S*)) (?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?) (?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?)( )?(?P(\"([^"\\]*(?:\\.[^"\\]*)*)\")?)' regex = re.compile(pattern) lines = 0 no_cookies = 0 unmatched = 0 for line in open('/home/stephen/scratch/test-data.txt'): lines +=1 line = line.strip() match = regex.match(line) if match: data = match.groupdict() if data['SiteIntelligenceCookie'] == '': no_cookies +=1 else: print "Couldn't match ", line unmatched +=1 print "I analysed %s lines." % (lines,) print "There were %s lines with missing Site Intelligence cookies." % (no_cookies,) print "I was unable to process %s lines." % (unmatched,) How can I make the regex a bit more resilient so it doesn't break when " " is embedded? -- Stephen Nelson-Smith Technical Director Atalanta Systems Ltd www.atalanta-systems.com From martin.hellwig at dcuktec.org Mon Mar 8 12:40:07 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Mon, 08 Mar 2010 17:40:07 +0000 Subject: Trouble with quotes In-Reply-To: References: Message-ID: On 03/08/10 17:06, Stephen Nelson-Smith wrote: > Hi, > > I've written some (primitive) code to parse some apache logfies and > establish if apache has appended a session cookie to the end. We're > finding that some browsers don't and apache doesn't just append a "-" > - it just omits it. > > It's working fine, but for an edge case: > > Couldn't match 192.168.1.107 - - [24/Feb/2010:20:30:44 +0100] "GET > http://sekrit.com/node/175523 HTTP/1.1" 200 - > "http://sekrit.com/search/results/"3%2B2%20course"" "Mozilla/4.0 > (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.4)" I didn't try to mentally parse the regex pattern (I like to keep reasonably sane). However from the sounds of it the script barfs when there is a quoted part in the second URL part. So how about doing a simple string.replace('/"','') & string.replace('" ','') before doing your re foo? -- mph From cmpython at gmail.com Mon Mar 8 12:51:51 2010 From: cmpython at gmail.com (CM) Date: Mon, 8 Mar 2010 09:51:51 -0800 (PST) Subject: Converting HTML to PDF using Python? References: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> Message-ID: <4bd454b4-1f00-425a-aa37-cd3a63f7fe8f@z4g2000yqa.googlegroups.com> On Mar 8, 10:36?am, Oltmans wrote: > Hi Python superstars, > > Guys, any ideas on how to convert HTML files to PDF files? Or as an > alternative, how to convert HTML files to an image file(jpeg/png/etc)? > Ideally, the converted PDF/Image file should like exactly like the way > HTML file looks in the browser. > > I really have no idea about this so I will really appreciate all the > help. Thanks in advance and kindly pardon my ignorance. > > Thanks, > Oltmans http://lmgtfy.com/?q=python+html+to+pdf From dinov at microsoft.com Mon Mar 8 13:44:37 2010 From: dinov at microsoft.com (Dino Viehland) Date: Mon, 8 Mar 2010 18:44:37 +0000 Subject: ssl, v23 client, v3 server... Message-ID: <1A472770E042064698CB5ADC83A12ACD393F30FD@TK5EX14MBXC118.redmond.corp.microsoft.com> In the ssl module docs (and in the tests) it says that if you have a client specifying PROTOCOL_SSLv23 (so it'll use v2 or v3) and a server specifying PROTOCOL_SSLv3 (so it'll only use v3) that you cannot connect between the two. Why doesn't this end up using SSL v3 for the communication? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Mar 8 13:48:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Mar 2010 13:48:01 -0500 Subject: Converting HTML to PDF using Python? In-Reply-To: <4bd454b4-1f00-425a-aa37-cd3a63f7fe8f@z4g2000yqa.googlegroups.com> References: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> <4bd454b4-1f00-425a-aa37-cd3a63f7fe8f@z4g2000yqa.googlegroups.com> Message-ID: On 3/8/2010 12:51 PM, CM wrote: > On Mar 8, 10:36 am, Oltmans wrote: >> Hi Python superstars, >> >> Guys, any ideas on how to convert HTML files to PDF files? Or as an >> alternative, how to convert HTML files to an image file(jpeg/png/etc)? >> Ideally, the converted PDF/Image file should like exactly like the way >> HTML file looks in the browser. How an HTML file looks in *a* (not *the*) browser depends on the browser, its settings, and window size. That is both a virtue and a reason for the invention of pdf format. >> I really have no idea about this so I will really appreciate all the >> help. Thanks in advance and kindly pardon my ignorance. >> >> Thanks, >> Oltmans > > http://lmgtfy.com/?q=python+html+to+pdf From debatem1 at gmail.com Mon Mar 8 14:05:34 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Mar 2010 14:05:34 -0500 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > Thanks Geremy, > > That has been an absolute bump........... GOD i cant sit on my chair, it has > worked even on 512 bit number and with no time.......... > superb i would say. > > lastly, i am using the code below to calculate Largest Prime factor of a > number: > > print > ('''===============================================================================''' > ?????? '''????????????? CALCULATE? HIGHEST PRIME > FACTOR????????????????????????????????? ''' > > '''===============================================================================''') > > #!/usr/bin/env python > def highest_prime_factor(n): > ?? if isprime(n): > ????? return n > ?? for x in xrange(2,n ** 0.5 + 1): > ????? if not n % x: > ???????? return highest_prime_factor(n/x) > def isprime(n): > ?? for x in xrange(2,n ** 0.5 + 1): > ????? if not n % x: > ???????? return False > ?? return True > if? __name__ == "__main__": > ?? import time > ?? start = time.time() > ?? print highest_prime_factor(1238162376372637826) > ?? print time.time() - start > > the code works with a bit of delay on the number : "1238162376372637826" but > extending it to > (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) > ?makes python go crazy. Is there any way just like above, i can have it > calculated it in no time. > > > thanks for the support. If you're just looking for the largest prime factor I would suggest using a fermat factorization attack. In the example you gave, it returns nearly immediately. Geremy Condra From debatem1 at gmail.com Mon Mar 8 14:08:48 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Mar 2010 14:08:48 -0500 Subject: Calculating very large exponents in python In-Reply-To: References: Message-ID: On Mon, Mar 8, 2010 at 2:05 PM, geremy condra wrote: > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: >> Thanks Geremy, >> >> That has been an absolute bump........... GOD i cant sit on my chair, it has >> worked even on 512 bit number and with no time.......... >> superb i would say. >> >> lastly, i am using the code below to calculate Largest Prime factor of a >> number: >> >> print >> ('''===============================================================================''' >> ?????? '''????????????? CALCULATE? HIGHEST PRIME >> FACTOR????????????????????????????????? ''' >> >> '''===============================================================================''') >> >> #!/usr/bin/env python >> def highest_prime_factor(n): >> ?? if isprime(n): >> ????? return n >> ?? for x in xrange(2,n ** 0.5 + 1): >> ????? if not n % x: >> ???????? return highest_prime_factor(n/x) >> def isprime(n): >> ?? for x in xrange(2,n ** 0.5 + 1): >> ????? if not n % x: >> ???????? return False >> ?? return True >> if? __name__ == "__main__": >> ?? import time >> ?? start = time.time() >> ?? print highest_prime_factor(1238162376372637826) >> ?? print time.time() - start >> >> the code works with a bit of delay on the number : "1238162376372637826" but >> extending it to >> (109026109913291424366305511581086089650628117463925776754560048454991130443047109026109913291424366305511581086089650628117463925776754560048454991130443047) >> ?makes python go crazy. Is there any way just like above, i can have it >> calculated it in no time. >> >> >> thanks for the support. > > If you're just looking for the largest prime factor I would suggest using > a fermat factorization attack. In the example you gave, it returns > nearly immediately. > > Geremy Condra > Allow me to add a very important caveat to my previous statement: a fermat factorization is primarily useful if you know that your number is a large semiprime, such as an RSA modulus, which I assume you are. Otherwise, make sure and test for primality. Geremy Con From duncan.booth at invalid.invalid Mon Mar 8 14:14:37 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Mar 2010 19:14:37 GMT Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: Xah Lee wrote: > For example, consider, if you are within world's top 100th user of > database in terms of database size, such as Google, then it may be > that the off-the-shelf tools may be limiting. But how many users > really have such massive size of data? You've totally missed the point. It isn't the size of the data you have today that matters, it's the size of data you could have in several years' time. Maybe today you've got 10 users each with 10 megabytes of data, but you're aspiring to become the next twitter/facebook or whatever. It's a bit late as you approach 100 million users (and a petabyte of data) to discover that your system isn't scalable: scalability needs to be built in from day one. From bob.aalsma at aalsmacons.nl Mon Mar 8 14:15:32 2010 From: bob.aalsma at aalsmacons.nl (BobAalsma) Date: Mon, 8 Mar 2010 11:15:32 -0800 (PST) Subject: Newbie question: python versions differ per user? Message-ID: <8a04bbfd-9c48-4397-8c81-c159dc1b8977@33g2000yqj.googlegroups.com> I'm on Mac OS X 10.5.8 and downloaded 2.6.4 Mac Installer Disk Image as/in(?) the sys admin user. For this user Pyhton 2.6.4 is now the current version. I want to use Python outside the sys asdmin user. However, all other users still use Python 2.5.1 (Apple delivered). The sys admin user looks in /Library/Frameworks/Python.framework/ Versions/2.6/lib/... The other users look in /System/Library/Frameworks/ Python.framework/Version/2.5/lib/... I could not find any questions on this matter, so am I the only one? Did I do something wrong? I assumed the paths for all users would be modified - too easy? From dickinsm at gmail.com Mon Mar 8 14:21:14 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Mon, 8 Mar 2010 11:21:14 -0800 (PST) Subject: Calculating very large exponents in python References: Message-ID: [Replying to Geremy's reply because the OP's post didn't show up in my newsreader.] On Mar 7, 8:40?pm, geremy condra wrote: > On Sun, Mar 7, 2010 at 1:55 PM, Fahad Ahmad wrote: > > Dear All, > > > i am writing my crytographic scheme in python, i am just a new user to it. > > I have written the complete code, the only point i am stuck it is that i am > > using 256 exponentiation which is normal in crytography but python just > > hangs on it. > > > g**x? [where both g and x are 256 bit numbers , in decimal they are around > > 77] No library can solve this problem. If g and x are both 256-bit numbers then the result of g**x will have on the order of 10**79 bits, which matches estimates of the number of particles in the universe. I can only imagine that you actually want g**x % m for some m, in which case three-argument pow is your friend, as Geremy pointed out. -- Mark From python at rcn.com Mon Mar 8 14:24:02 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Mar 2010 11:24:02 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> Message-ID: <06ddd3cf-d3dd-4e5d-9789-53a4f8a4bced@b5g2000prd.googlegroups.com> [Steven D'Aprano] > Thanks for the explanation Raymond. A few comments follow: You're welcome :-) > Would you consider a feature enhancement adding an additional method, > analogous to update(), to perform subtractions? I recognise that it's > easy to subclass and do it yourself, but there does seem to be some > demand for it, and it is an obvious feature given that Counter does > support negative counts. Will continue to mull it over. Instinct says that conflating two models can be worse for usability than just picking one of the models and excluding the other. If I had it to do over, there is a reasonable case that elementwise vector methods (__add__, __sub__, and __mul__) may have been a more useful choice than multiset methods (__add__, __sub__, __and__, __or__). That being said, the multiset approach was the one that was chosen. It was indicated for people who have experience with bags or multisets in other languages. It was also consistent with the naming of the class as tool for counting things (i.e. it handles counting numbers right out of the box). No explicit support is provided for negative values, but it isn't actively hindered either. For applications needing elementwise vector operations and signed arithmetic, arguably they should be using a more powerful toolset, perhaps supporting a full-range of elementwise binary and unary operations and a dotproduct() method. Someone should write that class and post it to the ASPN Cookbook to see if there is any uptake. > Personally, I think the behaviour of + and - would be far less surprising > if the class was called Multiset. Intuitively, one would expect counters > to be limited to ints, and to support negative counts when adding and > subtracting. In hindsight, do you think that Multiset would have been a > better name? The primary use case for Counter() is to count things (using the counting numbers). The term Multiset is more obscure and only applies to the four operations that eliminate non-positive results. So, I'm somewhat happy with the current name. FWIW, the notion of "what is surprising" often depends on the observer's background and on the problem they are currently trying to solve. If you need negative counts, then Counter.__sub__() is surprising. If your app has no notion of a negative count, then it isn't. The docs, examples, and docstrings are very clear about the behavior, so the "surprise" is really about wanting it to do something other than what it currently does ;-) Raymond From daniel at stutzbachenterprises.com Mon Mar 8 15:30:23 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Mon, 8 Mar 2010 14:30:23 -0600 Subject: negative "counts" in collections.Counter? In-Reply-To: <06ddd3cf-d3dd-4e5d-9789-53a4f8a4bced@b5g2000prd.googlegroups.com> References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <4b94ebbd$0$8762$c3e8da3@news.astraweb.com> <06ddd3cf-d3dd-4e5d-9789-53a4f8a4bced@b5g2000prd.googlegroups.com> Message-ID: On Mon, Mar 8, 2010 at 1:24 PM, Raymond Hettinger wrote: > Instinct says that conflating two models can be worse for usability > than just picking one of the models and excluding the other. > Toward that end, shouldn't Counter do one (and only one) of the follow? 1) Disallow non-positive counts (like a Multiset/Bag) 2) Allow them when subtracting In other words, to avoid conflating two models the following two examples should produce the same output: >>> c = Counter({'red': 1}) >>> c['red'] -= 2 >>> c Counter({'red': -1}) >>> c = Counter({'red': 1}) >>> c2 = Counter({'red': 2}) >>> c - c2 Counter() -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From monkey at joemoney.net Mon Mar 8 15:30:39 2010 From: monkey at joemoney.net (monkeys paw) Date: Mon, 08 Mar 2010 15:30:39 -0500 Subject: write to remote ile In-Reply-To: References: Message-ID: On 3/7/2010 9:53 PM, Martin P. Hellwig wrote: > On 03/08/10 02:51, monkeys paw wrote: >> On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: >>> On 03/08/10 02:10, monkeys paw wrote: >>>> I can xfer a file from a remote server using: >>>> >>>> import urllib2 as u >>>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >>>> >>>> for line in x: >>>> print line >>>> >>>> >>>> How can i write a file to the remote server? >>>> >>>> I tried: >>>> >>>> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >>>> >>>> but that does not work >>> >>> How do you normally (i.e. without python) put files on a remote server? >>> >> Using FTP, i'm really having a brain cramp here, but i'm new to python > > We all been there, in some for or other ;-), anyway you might want to > have a look at this: > http://docs.python.org/library/ftplib.html > Tried this, the storlines doesn't work, everything else OK from ftplib import FTP ftp = FTP('joemoney.net') ftp.login('secret','pw') ftp.retrlines('LIST') # list directory contents ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error> File "ftp.py", line 5, in ftp.storlines('STOR', 'sf.xml') File "C:\Python26\lib\ftplib.py", line 470, in storlines conn = self.transfercmd(cmd) File "C:\Python26\lib\ftplib.py", line 356, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "C:\Python26\lib\ftplib.py", line 327, in ntransfercmd resp = self.sendcmd(cmd) File "C:\Python26\lib\ftplib.py", line 243, in sendcmd return self.getresp() File "C:\Python26\lib\ftplib.py", line 218, in getresp raise error_perm, resp ftplib.error_perm: 501 No file name The file exists in the same directory as ftp.py From python at rcn.com Mon Mar 8 16:44:34 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Mar 2010 13:44:34 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: [Vlastimil Brom] > Thank you very much for the exhaustive explanation Raymond! You're welcome. > I am by far not able to follow all of the mathematical background, but > even for zero-truncating multiset, I would expect the truncation on > input rather than on output of some operations. I debated about this and opted for be-loose-in-receiving-and-strict-on- output. One thought is that use cases for multisets would have real multisets as inputs (no negative counts) and as outputs. The user controls the inputs, and the method only has a say in what its outputs are. Also, truncating input would complicate the mathematical definition of what is happening. Compare: r = a[x] - b[x] if r > 0: emit(r) vs. r = max(0, a[x]) - max(0, b[x]) if r > 0: emit(r) Also, the design parallels what is done in the decimal module where rounding is applied only to the results of operations, not to the inputs. > Probably a kind of negative_update() ?or some better named method will > be handy, like the one you supplied or simply the current module code > without the newcount > 0: ... condition. See my other post on this subject. There is no doubt that such a method would be handy for signed arithmetic. The question is whether conflating two different models hurts the API more than it helps. Right now, the Counter() class has no explicit support for negative values. It is designed around natural numbers and counting numbers. > Or would it be an option to > have a keyword argument like zero_truncate=False which would influence > this behaviour? Guido's thoughts on behavior flags is that they are usually a signal that you need two different classes. That is why itertools has ifilter() and ifilterfalse() or izip() and izip_longest() instead of having behavior flags. In this case, we have an indication that what you really want is a separate class supporting elementwise binary and unary operations on vectors (where the vector fields are accessed by a dictionary key instead of a positional value). > Additionally, were issubset and issuperset considered for this > interface (not sure whether symmetric_difference would be applicable)? If the need arises, these could be included. Right now, you can get the same result with: "if a - b: ..." FWIW, I never liked those two method names. Can't remember whether a.issubset(b) means "a is a subset of b" or "b issubset of a'. Raymond From news123 at free.fr Mon Mar 8 17:06:34 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:06:34 +0100 Subject: Import problem In-Reply-To: <4b926b37$0$27829$c3e8da3@news.astraweb.com> References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b926b37$0$27829$c3e8da3@news.astraweb.com> Message-ID: <4b9574ea$0$435$426a74cc@news.free.fr> Hi Steven, Steven D'Aprano wrote: > On Sat, 06 Mar 2010 03:53:53 -0800, Johny wrote: > >>>>> import sys >>>>> sys.path.append('C:\\A') >>>>> from A.B import bmodule >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named A.B > > The current directory is irrelevant, except that it is automatically > added to the PYTHONPATH. That's why you can import A.B when the current > directory is C. Minor currection: It doesn't seem to be the current directory, but the directory, where the script is located in, which is auto-appended to the pythonpath Please see following example: $ python -V Python 2.6.4 $ mkdir A $ touch A/__init__ $ # create A/blla.py an A/blo.py $ cat A/bla.py print "I am bla" import A.blo print "and I found blo",dir(A.blo) $ cat A/blo.py avar = 3 print "I am blo" $ python A/bla.py I am bla Traceback (most recent call last): File "A/bla.py", line 2, in import A.blo ImportError: No module named A.blo However: $ cat alternative_bla.py import sys sys.path.append(".") print "I am bla" import A.blo print "and I found blo",dir(A.blo) $ python A/alternativ_bla.py I am bla I am blo and I found blo ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'avar'] bye N From greg.ewing at canterbury.ac.nz Mon Mar 8 17:16:24 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Mar 2010 11:16:24 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> Message-ID: <7vlameF7goU1@mid.individual.net> Dave Angel wrote: > If you know so little about the > value, how do you even know it's a CRC ? Could it be a ones-complement > sum, such as used in Ethernet? I'm going by the fact that the application reports a "CRC mismatch" when it's wrong. I can't be sure that what it calls a "CRC" is really a true CRC, but it's more than a simple sum, because changing one bit in the file results in a completely different value. > Is the problem really worth it? Probably not -- it looks like fixing the problem I'm trying to fix by hand will be faster in the long run. I just thought it might turn out to be a solved problem and someone could point me to an algorithm for it, but it seems not. -- Greg From news123 at free.fr Mon Mar 8 17:21:08 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:21:08 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4B957854.3070201@free.fr> Jean-Michel Pichavant wrote: > Johny wrote: >> I have this directory structure >> >> C: >> \A >> __init__.py >> amodule.py >> >> \B >> __init__.py >> bmodule.py >> >> \D >> __init__.py >> dmodule.py >> >> and I want to import bmodule.py >> C:\>cd \ >> >> C:\>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> from A.B import bmodule >>>>> >> I am bmodule >> C:\> >> >> so far so good. Now I would like to import bmodule but if the current >> directory is \D subdirectory. >> >> C:> cd \A\B\D >> C:\A\B\D> >> C:\A\B\D>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import sys >>>>> sys.path.append('C:\\A') >>>>> from A.B import bmodule >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named A.B >> >> C:\> >> >> so I can not import a module from the parent directory? Or where did I >> make an error? >> Thanks for help >> >> L. >> > try > > import sys > sys.path.append('C:\\') > from A.B import bmodule > is there any 'automatic' way of finding the top level directory?basically the 'top level directory is the first directory going upwards, that doesn't contain a __init__.py file. of course you could do this 'manually' by doing: # assume, that this module is A.amodule import sys import os # I'd love to have a similiar automatic construct if __name__ == "__main__": level = 1 # or function locating how far to go up before # finding a dir, whcih does not contain a __init__.py mydir = os.path.split(__file__)[0] topdir = os.path.join( mydir,*(("..",)*level)) abstop = os.path.abspath(topdir) sys.path.append(abstop) ## now you can import with the normal module paths import A.blo print "and I found blo",dir(A.blo) bye N From news123 at free.fr Mon Mar 8 17:21:26 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:21:26 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> Message-ID: <4b957866$0$17135$426a34cc@news.free.fr> Jean-Michel Pichavant wrote: > Johny wrote: >> I have this directory structure >> >> C: >> \A >> __init__.py >> amodule.py >> >> \B >> __init__.py >> bmodule.py >> >> \D >> __init__.py >> dmodule.py >> >> and I want to import bmodule.py >> C:\>cd \ >> >> C:\>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> from A.B import bmodule >>>>> >> I am bmodule >> C:\> >> >> so far so good. Now I would like to import bmodule but if the current >> directory is \D subdirectory. >> >> C:> cd \A\B\D >> C:\A\B\D> >> C:\A\B\D>python >> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >> (Intel)] on win >> 32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>>>> import sys >>>>> sys.path.append('C:\\A') >>>>> from A.B import bmodule >>>>> >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: No module named A.B >> >> C:\> >> >> so I can not import a module from the parent directory? Or where did I >> make an error? >> Thanks for help >> >> L. >> > try > > import sys > sys.path.append('C:\\') > from A.B import bmodule > is there any 'automatic' way of finding the top level directory?basically the 'top level directory is the first directory going upwards, that doesn't contain a __init__.py file. of course you could do this 'manually' by doing: # assume, that this module is A.amodule import sys import os # I'd love to have a similiar automatic construct if __name__ == "__main__": level = 1 # or function locating how far to go up before # finding a dir, whcih does not contain a __init__.py mydir = os.path.split(__file__)[0] topdir = os.path.join( mydir,*(("..",)*level)) abstop = os.path.abspath(topdir) sys.path.append(abstop) ## now you can import with the normal module paths import A.blo print "and I found blo",dir(A.blo) bye N From greg.ewing at canterbury.ac.nz Mon Mar 8 17:22:28 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Mar 2010 11:22:28 +1300 Subject: negative "counts" in collections.Counter? In-Reply-To: References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <7vlb1qF9jaU1@mid.individual.net> Raymond Hettinger wrote: > Instead the choice was to implement the four methods as > multiset operations. As such, they need to correspond > to regular set operations. Seems to me you're trying to make one data type do the work of two, and ending up with something inconsistent. I think you should be providing two types: one is a multiset, which disallows negative counts altogether; the other behaves like a sparse vector with appropriate arithmetic operations. -- Greg From vlastimil.brom at gmail.com Mon Mar 8 17:24:43 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 8 Mar 2010 23:24:43 +0100 Subject: negative "counts" in collections.Counter? In-Reply-To: References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> Message-ID: <9fdb569a1003081424j405d2bdblc2dc96a5ae6fa910@mail.gmail.com> 2010/3/8 Raymond Hettinger : ... [snip detailed explanations] >... > In this case, we have an indication that what you really want is > a separate class supporting elementwise binary and unary operations > on vectors (where the vector fields are accessed by a dictionary > key instead of a positional value). > > >> Additionally, were issubset and issuperset considered for this >> interface (not sure whether symmetric_difference would be applicable)? > > If the need arises, these could be included. ?Right now, you > can get the same result with: ?"if a - b: ..." > > FWIW, I never liked those two method names. ?Can't remember whether > a.issubset(b) means "a is a subset of b" or "b issubset of a'. > > > Raymond > -- > Thanks for the further remarks Raymond, initially I thought while investigating new features of python 3, this would be a case for replacing the "home made" solutions with the standard module functionality. Now I can see, it probably wouldn't be an appropriate decision in this case, as the expected usage of Counter with its native methods is different. As for the issubset, issuperset method names, I am glad, a far more skilled person has the same problem like me :-) In this case the operators appear to be clearer than the method names... regards, vbr From news123 at free.fr Mon Mar 8 17:25:24 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:25:24 +0100 Subject: libc Sleep api performs a busy waiting In-Reply-To: References: Message-ID: <4b957954$0$17135$426a34cc@news.free.fr> Hi Steve, Steve Holden wrote: > Mahesh wrote: >> Hi, >> >> I am having a problem while using sleep function from libc , the >> thread in which i am calling it is getting struck and not allowing >> other threads to execute. Here is a simple code that i am trying to >> exeute >> >> import threading >> import time >> import dl >> >> >> def dummy1(): >> a=dl.open('/lib/libc.so.6') >> print "in thread 1 Start" >> a.call('sleep',2) >> #time.sleep(2) >> print "in thread 1 End" >> >> def dummy2(): >> print "in thread 2 Start" >> time.sleep(1) >> print "in thread 2 End" >> newThread1=threading.Thread(None,dummy1) >> newThread2=threading.Thread(None,dummy2) >> newThread1.start() >> newThread2.start() >> >> print "in main" >> >> >> >> The out put of this program is (In this case thread 1 even though i >> am calling a sleep function its not allowing other threads to execute, >> other threads execute only after the completion of first thread) >> >> in thread 1 Start >> in thread 1 End >> in thread 2 Start >> in main >> in thread 2 End >> >> >> where as if i use time.sleep instead of a.call(sleep) the out put is >> (which i guess is right behaviour, because it start the threads and >> suspends them because the have sleep , and continue executing the main >> thread) >> in thread 1 Start >> in thread 2 Start >> in main >> in thread 2 End >> in thread 1 End >> >> > Why not just use the time module's sleep function? Unlike the libc code > it releases Python's GIL (global interpreter lock), thus allowing other > threads to run. > I fully agree for the given example. Especcially time.sleep allows even sub second sleeps. Out of curiousity though: Is there any way to perform a call(), that releases the GIL before calling the function? It would avoid writing a wrapper? bye N From news123 at free.fr Mon Mar 8 17:26:32 2010 From: news123 at free.fr (News123) Date: Mon, 08 Mar 2010 23:26:32 +0100 Subject: What to do if anything bites. In-Reply-To: References: Message-ID: <4b957998$0$17135$426a34cc@news.free.fr> Google Adsense wrote: > What to do if anything bites. > > Check our bites treatment at > > http://108ambulance.blogspot.com/2010/03/108-ambulance-home-page.html Pythons don't bite From dimitri.pater at gmail.com Mon Mar 8 17:34:06 2010 From: dimitri.pater at gmail.com (dimitri pater - serpia) Date: Mon, 8 Mar 2010 23:34:06 +0100 Subject: related lists mean value Message-ID: Hi, I have two related lists: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] what I need is a list representing the mean value of 'a', 'b' and 'c' while maintaining the number of items (len): w = [1.5, 1.5, 8, 4, 4, 4] I have looked at iter(tools) and next(), but that did not help me. I'm a bit stuck here, so your help is appreciated! thanks! Dimitri From python at rcn.com Mon Mar 8 17:44:38 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Mar 2010 14:44:38 -0800 (PST) Subject: negative "counts" in collections.Counter? References: <4b9456f4$0$8836$c3e8da3@news.astraweb.com> <7vlb1qF9jaU1@mid.individual.net> Message-ID: <34e15f30-8f7c-4f0f-82b7-6a65fe91ec88@w27g2000pre.googlegroups.com> [Gregory Ewing] > I think you should be providing two types: one is a > multiset, which disallows negative counts altogether; > the other behaves like a sparse vector with appropriate > arithmetic operations. That is pretty close to what I said above: """ In this case, we have an indication that what you really want is a separate class supporting elementwise binary and unary operations on vectors (where the vector fields are accessed by a dictionary key instead of a positional value). """ The first and foremost goal of the class was to provide a simple counting capability along the lines of: class Counter(dict): def __init__(self, iterable=()): for elem in iterable: self[elem] += 1 def __missing__(self, key): return 0 Note, there is no "disallowing negatives" or even any insistence that the "counts" are actually numbers. In that respect, it was a consenting adults class from the start. It is short, simple, and fast. The other methods were mostly just "extras" to make the tool more useful. Each adds its own minimal restrictions: elements() requires integer counts most_common() requires that counts be orderable multiset operations are defined for non-negative values We could have kept this same design and wrapped every dictionary method so that it would raise an exception for any count that was not a positive integer. That would have slowed down the class, increased the code volume, and precluded some uses that are currently possible. IMO, that would not have been a win and it would not have helped the OP who was seeking a more vector-like tool for signed-number operations. Anyway, it is what it is. The tool is released and most users seem to be happy with what we have. Raymond From python at mrabarnett.plus.com Mon Mar 8 17:48:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Mar 2010 22:48:13 +0000 Subject: write to remote ile In-Reply-To: References: Message-ID: <4B957EAD.7070304@mrabarnett.plus.com> monkeys paw wrote: > On 3/7/2010 9:53 PM, Martin P. Hellwig wrote: >> On 03/08/10 02:51, monkeys paw wrote: >>> On 3/7/2010 9:20 PM, Martin P. Hellwig wrote: >>>> On 03/08/10 02:10, monkeys paw wrote: >>>>> I can xfer a file from a remote server using: >>>>> >>>>> import urllib2 as u >>>>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') >>>>> >>>>> for line in x: >>>>> print line >>>>> >>>>> >>>>> How can i write a file to the remote server? >>>>> >>>>> I tried: >>>>> >>>>> x = u.url.open('http://joemoney.net/somefile.txt', 'w') >>>>> >>>>> but that does not work >>>> >>>> How do you normally (i.e. without python) put files on a remote server? >>>> >>> Using FTP, i'm really having a brain cramp here, but i'm new to python >> >> We all been there, in some for or other ;-), anyway you might want to >> have a look at this: >> http://docs.python.org/library/ftplib.html >> > > Tried this, the storlines doesn't work, everything else OK > > from ftplib import FTP > ftp = FTP('joemoney.net') > ftp.login('secret','pw') > ftp.retrlines('LIST') # list directory contents > ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error> > The documentation says: FTP.storlines(cmd, file, callback=None) where 'cmd' is the FTP command, 'STOR sf.xml' ('sf.xl' is the path of the file on the server) and 'file' is the open (local) source file. From invalid at invalid.invalid Mon Mar 8 18:06:35 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Mar 2010 23:06:35 +0000 (UTC) Subject: Converting HTML to PDF using Python? References: <1ca0597c-b5c7-496c-8636-2dd1359592be@y7g2000prc.googlegroups.com> Message-ID: On 2010-03-08, Oltmans wrote: > Guys, any ideas on how to convert HTML files to PDF files? os.system("w3m -dump %s | a2ps -B --borders=no -o - | ps2pdf - %s" % (infile,outfile)) -- Grant Edwards grant.b.edwards Yow! Am I accompanied by a at PARENT or GUARDIAN? gmail.com From python at mrabarnett.plus.com Mon Mar 8 18:15:44 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Mar 2010 23:15:44 +0000 Subject: related lists mean value In-Reply-To: References: Message-ID: <4B958520.8000701@mrabarnett.plus.com> dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! > Try doing it in 2 passes. First pass: count the number of times each string occurs in 'y' and the total for each (zip/izip and defaultdict are useful for these). Second pass: create the result list containing the mean values. From clp2 at rebertia.com Mon Mar 8 18:22:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Mar 2010 15:22:39 -0800 Subject: related lists mean value In-Reply-To: References: Message-ID: <50697b2c1003081522p565ed44fxd68761c0b19bcfc7@mail.gmail.com> On Mon, Mar 8, 2010 at 2:34 PM, dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! from __future__ import division def group(keys, values): #requires None not in keys groups = [] cur_key = None cur_vals = None for key, val in zip(keys, values): if key != cur_key: if cur_key is not None: groups.append((cur_key, cur_vals)) cur_vals = [val] cur_key = key else: cur_vals.append(val) groups.append((cur_key, cur_vals)) return groups def average(lst): return sum(lst) / len(lst) def process(x, y): result = [] for key, vals in group(y, x): avg = average(vals) for i in xrange(len(vals)): result.append(avg) return result x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] print process(x, y) #=> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] It could be tweaked to use itertools.groupby(), but it would probably be less efficient/clear. Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Mon Mar 8 18:24:07 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Mar 2010 18:24:07 -0500 Subject: Reverse engineering CRC? In-Reply-To: <7vlameF7goU1@mid.individual.net> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: <4B958717.7040708@ieee.org> Gregory Ewing wrote: >
Dave > Angel wrote: >> If you know so little about the value, how do you even know it's a >> CRC ? Could it be a ones-complement sum, such as used in Ethernet? > > I'm going by the fact that the application reports a > "CRC mismatch" when it's wrong. I can't be sure that what > it calls a "CRC" is really a true CRC, but it's more than > a simple sum, because changing one bit in the file results > in a completely different value. > >> Is the problem really worth it? > > Probably not -- it looks like fixing the problem I'm trying > to fix by hand will be faster in the long run. I just thought > it might turn out to be a solved problem and someone could > point me to an algorithm for it, but it seems not. > If you assume it's done in a single pass, and you know which byte is the end of the buffer, I'd think you could learn a lot by just tweaking that last byte. But I still think you'd want to automate your testing, presumably by some keystroke-stuffer. DaveA From mensanator at aol.com Mon Mar 8 18:32:14 2010 From: mensanator at aol.com (Mensanator) Date: Mon, 8 Mar 2010 15:32:14 -0800 (PST) Subject: Python 3.1.2 release candidate References: Message-ID: <90da6fb8-e555-4a74-bf13-14878f60f5d4@g11g2000yqe.googlegroups.com> On Mar 6, 4:13?pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm pleased to announce a release > candidate for the second bugfix release of the Python 3.1 series, Python 3.1.2. > > This bug fix release fixes numerous issues found in 3.1.1. ?This release > candidate has been released to solicit testing and feedback over an possible > regressions from 3.1.1. ?Please consider testing it with your library or > application and reporting an bugs you encounter. ?This will help make the final > 3.1.2 release, planned in 2 weeks time, all the more stable. > > The Python 3.1 version series focuses on the stabilization and optimization of > the features and changes that Python 3.0 introduced. ?For example, the new I/O > system has been rewritten in C for speed. ?File system APIs that use unicode > strings now handle paths with undecodable bytes in them. Other features include > an ordered dictionary implementation, a condensed syntax for nested with > statements, and support for ttk Tile in Tkinter. ?For a more extensive list of > changes in 3.1, seehttp://doc.python.org/3.1/whatsnew/3.1.htmlor Misc/NEWS in > the Python distribution. > > To download Python 3.1.2rc1 visit: > > ? ? ?http://www.python.org/download/releases/3.1.2/ > > A list of changes in 3.1.2rc1 can be found here: > > ? ? ?http://svn.python.org/projects/python/tags/r312rc1/Misc/NEWS > > The 3.1 documentation can be found at: > > ? ? ?http://docs.python.org/3.1 > > Bugs can always be reported to: > > ? ? ?http://bugs.python.org Hey, it finally let me register. Turned out the e-mail to confirm registry was getting marked Spam. I pulled it out of the Spam box and completed the registration. Of course, the reason I needed to register is because IDLE will *still* not end a process properly in Windows. see issue 8093 > > Enjoy! > > -- > Benjamin Peterson > Release Manager > benjamin at python.org > (on behalf of the entire python-dev team and 3.1.2's contributors) From dimitri.pater at gmail.com Mon Mar 8 18:47:12 2010 From: dimitri.pater at gmail.com (dimitri pater - serpia) Date: Tue, 9 Mar 2010 00:47:12 +0100 Subject: related lists mean value In-Reply-To: <50697b2c1003081522p565ed44fxd68761c0b19bcfc7@mail.gmail.com> References: <50697b2c1003081522p565ed44fxd68761c0b19bcfc7@mail.gmail.com> Message-ID: thanks Chris and MRAB! Looks good, I'll try it out On Tue, Mar 9, 2010 at 12:22 AM, Chris Rebert wrote: > On Mon, Mar 8, 2010 at 2:34 PM, dimitri pater - serpia > wrote: >> Hi, >> >> I have two related lists: >> x = [1 ,2, 8, 5, 0, 7] >> y = ['a', 'a', 'b', 'c', 'c', 'c' ] >> >> what I need is a list representing the mean value of 'a', 'b' and 'c' >> while maintaining the number of items (len): >> w = [1.5, 1.5, 8, 4, 4, 4] >> >> I have looked at iter(tools) and next(), but that did not help me. I'm >> a bit stuck here, so your help is appreciated! > > from __future__ import division > > def group(keys, values): > ? ?#requires None not in keys > ? ?groups = [] > ? ?cur_key = None > ? ?cur_vals = None > ? ?for key, val in zip(keys, values): > ? ? ? ?if key != cur_key: > ? ? ? ? ? ?if cur_key is not None: > ? ? ? ? ? ? ? ?groups.append((cur_key, cur_vals)) > ? ? ? ? ? ?cur_vals = [val] > ? ? ? ? ? ?cur_key = key > ? ? ? ?else: > ? ? ? ? ? ?cur_vals.append(val) > ? ?groups.append((cur_key, cur_vals)) > ? ?return groups > > def average(lst): > ? ?return sum(lst) / len(lst) > > def process(x, y): > ? ?result = [] > ? ?for key, vals in group(y, x): > ? ? ? ?avg = average(vals) > ? ? ? ?for i in xrange(len(vals)): > ? ? ? ? ? ?result.append(avg) > ? ?return result > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > print process(x, y) > #=> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > > It could be tweaked to use itertools.groupby(), but it would probably > be less efficient/clear. > > Cheers, > Chris > -- > http://blog.rebertia.com > -- --- You can't have everything. Where would you put it? -- Steven Wright --- please visit www.serpia.org From aahz at pythoncraft.com Mon Mar 8 20:47:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Mar 2010 17:47:58 -0800 Subject: Queue peek? References: <26348e98-9b81-45fe-85b4-7788eba176c9@j27g2000yqn.googlegroups.com> <58f61382-ac79-46fb-8612-a3c9fde297dc@c16g2000yqd.googlegroups.com> Message-ID: In article <58f61382-ac79-46fb-8612-a3c9fde297dc at c16g2000yqd.googlegroups.com>, Veloz wrote: > >The "peek" parts comes in when the user comes back later to see if >their report has done. That is, in my page controller logic, I'd like >to look through the complete queue and see if the specific report has >been finished (I could tell by matching up the ID of the original >request to the ID in the completed queue). If there was an item in the >queue matching the ID, it would be removed. Here's the question: what happens when the user refreshes the "report done" page? The problem with the way you're doing it is that checking for report done is a one-shot operation. You probably want to use a database to cache this and have some kind of cache expiration. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From jjposner at optimum.net Mon Mar 8 21:39:59 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 08 Mar 2010 21:39:59 -0500 Subject: related lists mean value In-Reply-To: References: Message-ID: <4B95B4FF.1070407@optimum.net> On 3/8/2010 5:34 PM, dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! Nobody expects object-orientation (or the Spanish Inquisition): #------------------------- from collections import defaultdict class Tally: def __init__(self, id=None): self.id = id self.total = 0 self.count = 0 x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c'] # gather data tally_dict = defaultdict(Tally) for i in range(len(x)): obj = tally_dict[y[i]] obj.id = y[i] obj.total += x[i] obj.count += 1 # process data result_list = [] for key in sorted(tally_dict): obj = tally_dict[key] mean = 1.0 * obj.total / obj.count result_list.extend([mean] * obj.count) print result_list #------------------------- -John From jjposner at optimum.net Mon Mar 8 21:43:58 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 08 Mar 2010 21:43:58 -0500 Subject: related lists mean value In-Reply-To: <4B95B4FF.1070407@optimum.net> References: <4B95B4FF.1070407@optimum.net> Message-ID: <4B95B5EE.90302@optimum.net> On 3/8/2010 9:39 PM, John Posner wrote: > # gather data > tally_dict = defaultdict(Tally) > for i in range(len(x)): > obj = tally_dict[y[i]] > obj.id = y[i] <--- statement redundant, remove it > obj.total += x[i] > obj.count += 1 -John From jjposner at optimum.net Mon Mar 8 21:53:41 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 08 Mar 2010 21:53:41 -0500 Subject: related lists mean value In-Reply-To: <4B95B5EE.90302@optimum.net> References: <4B95B4FF.1070407@optimum.net> <4B95B5EE.90302@optimum.net> Message-ID: <4B95B835.4050805@optimum.net> On 3/8/2010 9:43 PM, John Posner wrote: > On 3/8/2010 9:39 PM, John Posner wrote: > > >> obj.id = y[i] <--- statement redundant, remove it Sorry for the thrashing! It's more correct to say that the Tally class doesn't require an "id" attribute at all. So the code becomes: #--------- from collections import defaultdict class Tally: def __init__(self): self.total = 0 self.count = 0 x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c'] # gather data tally_dict = defaultdict(Tally) for i in range(len(x)): obj = tally_dict[y[i]] obj.total += x[i] obj.count += 1 # process data result_list = [] for key in sorted(tally_dict): obj = tally_dict[key] mean = 1.0 * obj.total / obj.count result_list.extend([mean] * obj.count) print result_list #--------- -John From df.trash at gmail.com Mon Mar 8 22:35:50 2010 From: df.trash at gmail.com (tdan) Date: Mon, 8 Mar 2010 19:35:50 -0800 (PST) Subject: remove element with ElementTree Message-ID: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> I have been using ElementTree to write an app, and would like to simply remove an element. But in ElementTree, you must know both the parent and the child element to do this. There is no getparent() function, so I am stuck if I only have an element. I am iterating over a table and getting all
tags, checking their text, and conditionally deleting them: def RemoveElementWithText( topEl, subEl, text ): for el in topEl.getiterator( subEl ): if el.text = text: break else: el = None return el RemoveElementWithText( table, 'td', 'sometext' ) My table is like so: ...
... Is there any way to do this in ElementTree? I see lxml.etree does this nicely, but I want to use python's standard library. From fox.joe87 at gmail.com Mon Mar 8 23:13:58 2010 From: fox.joe87 at gmail.com (Joe Fox) Date: Tue, 9 Mar 2010 09:43:58 +0530 Subject: libc Sleep api performs a busy waiting In-Reply-To: References: Message-ID: <27e52ad11003082013h658cf7deu761e7d14198af9f1@mail.gmail.com> Hi, actually i have simplified my scenario a lot here , In my actual case , i have to call a C-api which blocks on c select , in a separate thread. my thread is getting struck in that api , and thus blocking all the other threads. Can you point to something which will help me call this blocking C-api call without my thread getting struck. Thanks Mahesh On Mon, Mar 8, 2010 at 6:03 PM, Steve Holden wrote: > Mahesh wrote: > > Hi, > > > > I am having a problem while using sleep function from libc , the > > thread in which i am calling it is getting struck and not allowing > > other threads to execute. Here is a simple code that i am trying to > > exeute > > > > import threading > > import time > > import dl > > > > > > def dummy1(): > > a=dl.open('/lib/libc.so.6') > > print "in thread 1 Start" > > a.call('sleep',2) > > #time.sleep(2) > > print "in thread 1 End" > > > > def dummy2(): > > print "in thread 2 Start" > > time.sleep(1) > > print "in thread 2 End" > > newThread1=threading.Thread(None,dummy1) > > newThread2=threading.Thread(None,dummy2) > > newThread1.start() > > newThread2.start() > > > > print "in main" > > > > > > > > The out put of this program is (In this case thread 1 even though i > > am calling a sleep function its not allowing other threads to execute, > > other threads execute only after the completion of first thread) > > > > in thread 1 Start > > in thread 1 End > > in thread 2 Start > > in main > > in thread 2 End > > > > > > where as if i use time.sleep instead of a.call(sleep) the out put is > > (which i guess is right behaviour, because it start the threads and > > suspends them because the have sleep , and continue executing the main > > thread) > > in thread 1 Start > > in thread 2 Start > > in main > > in thread 2 End > > in thread 1 End > > > > > Why not just use the time module's sleep function? Unlike the libc code > it releases Python's GIL (global interpreter lock), thus allowing other > threads to run. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mehgcap at gmail.com Mon Mar 8 23:22:27 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 8 Mar 2010 23:22:27 -0500 Subject: imported var not being updated Message-ID: Hello all: I have a project with many pyw files. One file holds a variable and a function that I find myself using across many other pyw files, so I called it helpers.pyw. The variable is "mostRecent", which is a string and is meant to hold a string so I know what the program most recently output; in all the other pyw files, every time the program outputs something, I include the line helpers.mostRecent=output where output is a string and helpers has been imported. The problem is that mostRecent does not seem to be updated at all, and I cannot figure out why. I declare it with empty quotes initially, but the program should keep updating it. Everytime I go to see what its value is, though, it is still apparently empty. Here is a basic sample: randomFile.pyw --- import helpers def something(): output="I am the most recently output string!" helpers.mostRecent=output #end def file2.pyw --- from helpers import mostRecent print(mostRecent) #prints nothing Any thoughts on what I am doing wrong? Thanks!! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gherron at islandtraining.com Mon Mar 8 23:55:01 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Mar 2010 20:55:01 -0800 Subject: imported var not being updated In-Reply-To: References: Message-ID: <4B95D4A5.6050504@islandtraining.com> Alex Hall wrote: > Hello all: > I have a project with many pyw files. One file holds a variable and a > function that I find myself using across many other pyw files, so I > called it helpers.pyw. The variable is "mostRecent", which is a string > and is meant to hold a string so I know what the program most recently > output; in all the other pyw files, every time the program outputs > something, I include the line > helpers.mostRecent=output > where output is a string and helpers has been imported. > > The problem is that mostRecent does not seem to be updated at all, and > I cannot figure out why. I declare it with empty quotes initially, but > the program should keep updating it. Everytime I go to see what its > value is, though, it is still apparently empty. Here is a basic > sample: > > randomFile.pyw > --- > import helpers > > def something(): > output="I am the most recently output string!" > helpers.mostRecent=output > #end def > > file2.pyw > --- > from helpers import mostRecent > > print(mostRecent) #prints nothing > > Any thoughts on what I am doing wrong? Thanks!! > The form of import you are using from helpers import mostRecent makes a *new* binding to the value in the module that's doing the import. Rebinding the var in a different module does not affect this. It's similar to this: a = 'string' b = a a = 'another string' won't affect b's value. What you can do, is not make a separate binding, but reach into the helpers module to get the value there. Like this: import helpers print helpers.mostRecent That will work as you hope. Gary Herron From mehgcap at gmail.com Mon Mar 8 23:59:00 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 8 Mar 2010 23:59:00 -0500 Subject: imported var not being updated In-Reply-To: <4B95D4A5.6050504@islandtraining.com> References: <4B95D4A5.6050504@islandtraining.com> Message-ID: Thanks, it worked as expected. I guess I figured that Python would read my mind and realize that I wanted mostRecent to act globally for the program, imported as a copy or accessed in its own namespace (right term?) Oh well, the day computers can read thoughts like that is the day programmers are out of a job... Thanks again. On 3/8/10, Gary Herron wrote: > Alex Hall wrote: >> Hello all: >> I have a project with many pyw files. One file holds a variable and a >> function that I find myself using across many other pyw files, so I >> called it helpers.pyw. The variable is "mostRecent", which is a string >> and is meant to hold a string so I know what the program most recently >> output; in all the other pyw files, every time the program outputs >> something, I include the line >> helpers.mostRecent=output >> where output is a string and helpers has been imported. >> >> The problem is that mostRecent does not seem to be updated at all, and >> I cannot figure out why. I declare it with empty quotes initially, but >> the program should keep updating it. Everytime I go to see what its >> value is, though, it is still apparently empty. Here is a basic >> sample: >> >> randomFile.pyw >> --- >> import helpers >> >> def something(): >> output="I am the most recently output string!" >> helpers.mostRecent=output >> #end def >> >> file2.pyw >> --- >> from helpers import mostRecent >> >> print(mostRecent) #prints nothing >> >> Any thoughts on what I am doing wrong? Thanks!! >> > > The form of import you are using > from helpers import mostRecent > makes a *new* binding to the value in the module that's doing the > import. Rebinding the var in a different module does not affect this. > It's similar to this: > > a = 'string' > b = a > a = 'another string' > > won't affect b's value. > > What you can do, is not make a separate binding, but reach into the > helpers module to get the value there. Like this: > > import helpers > print helpers.mostRecent > > That will work as you hope. > > Gary Herron > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gagsl-py2 at yahoo.com.ar Tue Mar 9 01:03:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Mar 2010 03:03:36 -0300 Subject: How to determine if threads are active in an application? References: <1267222230.24180.1362126901@webmail.messagingengine.com> Message-ID: En Fri, 26 Feb 2010 19:10:30 -0300, escribi?: > Is there technique to determine if threads are active in a Python > application? > > The only technique I can think of is to check sys.modules for > thread and threading. But this will only show whether these > modules were imported - not whether there are actually background > threads running. I've just read your post. Look at threading.activeCount() - this returns only those threads created using the threading module. If that's not enough, you'll have to use some OS-specific functions. -- Gabriel Genellina From see at sig.for.address Tue Mar 9 01:14:37 2010 From: see at sig.for.address (Victor Eijkhout) Date: Tue, 9 Mar 2010 00:14:37 -0600 Subject: scipy sparse matrix question Message-ID: <1jf28jr.7abra61nwu04pN%see@sig.for.address> I can't find any detailed information about scipy.sparse. My specific question: what does "for x in A" give me when A is a sparse matrix? It seems to yield all nonzero locations, but in what kind of form? Very specifically: how do I get the (i,j) coordinates and the value from x? Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From casevh at gmail.com Tue Mar 9 01:39:30 2010 From: casevh at gmail.com (casevh) Date: Mon, 8 Mar 2010 22:39:30 -0800 (PST) Subject: Calculating very large exponents in python References: Message-ID: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> [also replying to Geremy since the OP's message doesn't appear...] On Mar 8, 11:05?am, geremy condra wrote: > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > > Thanks Geremy, > > > That has been an absolute bump........... GOD i cant sit on my chair, it has > > worked even on 512 bit number and with no time.......... > > superb i would say. > > > lastly, i am using the code below to calculate Largest Prime factor of a > > number: > > > print > > ('''=======================================================================?========''' > > ?????? '''????????????? CALCULATE? HIGHEST PRIME > > FACTOR????????????????????????????????? ''' > > > '''========================================================================?=======''') > > > #!/usr/bin/env python > > def highest_prime_factor(n): > > ?? if isprime(n): > > ????? return n > > ?? for x in xrange(2,n ** 0.5 + 1): > > ????? if not n % x: > > ???????? return highest_prime_factor(n/x) > > def isprime(n): > > ?? for x in xrange(2,n ** 0.5 + 1): > > ????? if not n % x: > > ???????? return False > > ?? return True > > if? __name__ == "__main__": > > ?? import time > > ?? start = time.time() > > ?? print highest_prime_factor(1238162376372637826) > > ?? print time.time() - start > > > the code works with a bit of delay on the number : "1238162376372637826" but > > extending it to > > (10902610991329142436630551158108608965062811746392577675456004845499113044?304710902610991329142436630551158108608965062811746392577675456004845499113?0443047) > > ?makes python go crazy. Is there any way just like above, i can have it > > calculated it in no time. > > > thanks for the support. > > If you're just looking for the largest prime factor I would suggest using > a fermat factorization attack. In the example you gave, it returns > nearly immediately. > > Geremy Condra- Hide quoted text - > > - Show quoted text - For a Python-based solution, you might want to look at pyecm (http:// sourceforge.net/projects/pyecm/) On a system with gmpy installed also, pyecm found the following factors: 101, 521, 3121, 9901, 36479, 300623, 53397071018461, 1900381976777332243781 There still is a 98 digit unfactored composite: 60252507174568243758911151187828438446814447653986842279796823262165159406500174226172705680274911 Factoring this remaining composite using ECM may not be practical. casevh From faheem_imt at yahoo.com Tue Mar 9 02:51:57 2010 From: faheem_imt at yahoo.com (Faheem) Date: Mon, 8 Mar 2010 23:51:57 -0800 (PST) Subject: How to detect C Function block using python Message-ID: <769249.71022.qm@web62401.mail.re1.yahoo.com> Hey All, I'm new in this community. I am?writing?a static?analyzer?for validating C Code using python and for that?I'm looking for a python module/API that will detect Function block of a given C-File.?I know simple function can be detected using push "{" and poping it if character "}" is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Thanks!Faheem -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Tue Mar 9 03:17:51 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 9 Mar 2010 00:17:51 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> Message-ID: <42062deb-785a-4955-9ce0-d9fb7a26455d@j27g2000yqn.googlegroups.com> On Mar 7, 12:34?pm, Steve Holden wrote: > My own impression of theloggingmodule, formed from trying to use its > documentation in the past, is that it's somewhat unapproachable, and > difficult to use for simple purposes. > > I am happy to say that now I see the current (3.1) documentation it has > improved to the point where I would be happy to try using it again. > Thanks for your long-term maintenance of this package. > Hi Steve, Thanks for the positive feedback. The initial documentation for the logging package, because it lives in the library section of the overall documentation, was focused more on completeness of coverage for reference usage, rather than a more tutorial-based approach. Thanks to work by Doug Hellmann and others, the documentation has grown, over time, more accessible to Python novices. It's still not perfect, and I hope to be able to improve its clarity in the future, by getting help where possible from people who are better at technical writing than I am. I'm reviewing the documentation at the moment, as it happens, and it still seems hard to be able to put together a structure which is good for everyone. A full treatment, it seems to me, would talk a little about the detail of why things work as they do; but a lot of the time, people are just interested in getting going with the package, and less interested in the whys and wherefores. But for people trying to do more than the basics, that deeper understanding is sometimes necessary. The hard part is satisfying all audiences in one document! Regards, Vinay Sajip From stephane at harobed.org Tue Mar 9 03:30:05 2010 From: stephane at harobed.org (KLEIN =?iso-8859-1?q?St=E9phane?=) Date: Tue, 9 Mar 2010 08:30:05 +0000 (UTC) Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? Message-ID: Hi, Today, I've show this static web site generating tools writed in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane From kishoreinme at gmail.com Tue Mar 9 03:39:15 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 00:39:15 -0800 (PST) Subject: pyserial script doesnt execute properly Message-ID: hello there Iam using python 2.5.4 pyserial 2.4 pywin32-214 on windows 7 i hav a small test script written to query a serial device (arduino) and get back reply appropriately ////file: test.py import serial print 'hi' ser=serial.Serial(port='\\.\COM2', baudrate=9600) ser.close() ser.open() ser.write('1') ser.readline() ser.readline() ser.close() the device waits for '1' through its serial interface and print two lines if it gets '1' "Some Data found" and "Header received" the script works on IDLE well when given one line at a time but when given in command line as python test.py it prints hi and wait forever can anyone help? thanks in advance From vinay_sajip at yahoo.co.uk Tue Mar 9 03:54:03 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 9 Mar 2010 00:54:03 -0800 (PST) Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <50697b2c1003051217p4f55af01lbc0ce435a0cb9207@mail.gmail.com> <14a5cd5e1003051225j1d596aa2nfe9eb1047037f19d@mail.gmail.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> <9c6a8d26-b71e-4cb8-92d0-49af8728bec4@u15g2000prd.googlegroups.com> Message-ID: <80645b57-b586-400e-8a8d-0ec97f3c8455@b30g2000yqd.googlegroups.com> On Mar 6, 11:13 pm, Pete Emerson wrote: > > 1) In debug mode, send what would have gone to syslog to STDOUT or > STDERR > 2) In non-debug mode, use /dev/log or localhost:514 depending on what > is set > 3) Allow for multiple levels ofloggingbeyond INFO, WARNING, CRIT ... > essentially allow multiple levels of INFO depending on how much detail > is desired. A high level of messaging when programs are running > poorly is desired, but when programs are running smoothly, I don't > need to send as much to syslog. By "debug mode", do you mean the value of the __debug__ variable, or something else (e.g. a flag in your application)? You could certainly do something like (in your logging initialization code): if __debug__: handler = logging.StreamHandler() else: #use domain socket, UDP, etc. handler = logging.handlers.SocketHandler(...) logger.addHandler(handler) where logger is the root logger or some other high-level logger in your application. By the way, are you aware that accessing syslog via openlog etc. may not thread-safe, at least in some environments? Search the Web for "syslog openlog thread" for more info. You can certainly add additional levels to logging (see addLevelName), but I'm not sure that's what you really need. Generally, I find that when there are problems to be debugged, I get more benefits from using the logger hierarchy: I keep the level at logging.DEBUG but just log different things to different loggers. Just as a fr'instance, if I were logging the parsing of HTTP requests, I might use loggers named 'request', 'request.headers', 'request.headers.cookies', 'request.body', 'request.body.multipart' etc. When everything is working well, I have the verbosity of these loggers turned low by e.g. setting the level for the 'request' logger to WARNING or higher; when I want to debug header processing in more detail I might set the level of the 'request.headers' logger to DEBUG, which would output events from request header processing (but not the body), or just turn up the 'request.headers.cookies' level to look in more detail at what's happening during processing "Cookie:" headers. Regards, Vinay Sajip From stephane at harobed.org Tue Mar 9 03:57:32 2010 From: stephane at harobed.org (KLEIN =?ISO-8859-1?Q?St=E9phane?=) Date: Tue, 09 Mar 2010 09:57:32 +0100 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? Message-ID: <1268125052.7405.1.camel@stephane-macbook> Hi, Today, I've show this static web site generating tools write in ruby : * http://webgen.rubyforge.org/index.html * http://nanoc.stoneship.org/about/ * http://webby.rubyforge.org/tutorial/ I like this tools, I'm wonder if there are similar tools in Python ? I know Sphinx, but this tools is oriented documentation. Thanks for your information, Stephane -- St?phane Klein Blog : http://harobed.org Jabber : stephane.klein at jabber.fr From news123 at free.fr Tue Mar 9 04:19:56 2010 From: news123 at free.fr (News123) Date: Tue, 09 Mar 2010 10:19:56 +0100 Subject: pyserial script doesnt execute properly In-Reply-To: References: Message-ID: <4b9612bc$0$6059$426a74cc@news.free.fr> Hi, kishore wrote: > hello there > > Iam using python 2.5.4 > pyserial 2.4 > pywin32-214 > > on windows 7 > > > i hav a small test script written to query a serial device (arduino) > and get back reply appropriately > > > > ////file: test.py > > import serial > print 'hi' > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > ser.close() > ser.open() > ser.write('1') > ser.readline() > ser.readline() > ser.close() > > > > the device waits for '1' through its serial interface and print two > lines if it gets '1' > > "Some Data found" and "Header received" > > > the script works on IDLE well when given one line at a time > > but when given in command line as python test.py it prints hi and wait > forever > Unfortunately I don't remember exacty, but try following: close IDLE and try then to start the script from the command line. I remember having had a problem with idle, that it did not always close the UART port (especially, when an error (e.g. syntax) occured before the close statement) bye N From justin.mailinglists at gmail.com Tue Mar 9 04:34:52 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Tue, 9 Mar 2010 01:34:52 -0800 (PST) Subject: remove element with ElementTree References: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> Message-ID: <8ad6319f-97f1-46b7-b89e-d455bd89ad03@b9g2000pri.googlegroups.com> On Mar 9, 11:35?am, tdan wrote: > I have been using ElementTree to write an app, and would like to > simply remove an element. > But in ElementTree, you must know both the parent and the child > element to do this. > There is no getparent() function, so I am stuck if I only have an > element. > see http://effbot.org/zone/element.htm#accessing-parents From dorzey at googlemail.com Tue Mar 9 05:21:49 2010 From: dorzey at googlemail.com (dorzey) Date: Tue, 9 Mar 2010 02:21:49 -0800 (PST) Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? References: Message-ID: <058ebe77-de1b-4814-917a-57e6e65e2d03@t23g2000yqt.googlegroups.com> On Mar 9, 8:57?am, KLEIN St?phane wrote: > Hi, > > Today, I've show this static web site generating tools write in ruby : > > ?*http://webgen.rubyforge.org/index.html > ?*http://nanoc.stoneship.org/about/ > ?*http://webby.rubyforge.org/tutorial/ > > I like this tools, I'm wonder if there are similar tools in Python ? > > I know Sphinx, but this tools is oriented documentation. > > Thanks for your information, > Stephane I'm only aware of Hyde (http://ringce.com/hyde) Paul From spamfresser at ch3ka.de Tue Mar 9 05:30:26 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 09 Mar 2010 11:30:26 +0100 Subject: related lists mean value In-Reply-To: References: Message-ID: Am 08.03.2010 23:34, schrieb dimitri pater - serpia: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] This kinda looks like you used the wrong data structure. Maybe you should have used a dict, like: {'a': [1, 2], 'c': [5, 0, 7], 'b': [8]} ? > I have looked at iter(tools) and next(), but that did not help me. I'm > a bit stuck here, so your help is appreciated! As said, I'd have used a dict in the first place, so lets transform this straight forward into one: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] # initialize dict d={} for idx in set(y): d[idx]=[] #collect values for i, idx in enumerate(y): d[idx].append(x[i]) print("d is now a dict of lists: %s" % d) #calculate average for key, values in d.items(): d[key]=sum(values)/len(values) print("d is now a dict of averages: %s" % d) # build the final list w = [ d[key] for key in y ] print("w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) Output is: d is now a dict of lists: {'a': [1, 2], 'c': [5, 0, 7], 'b': [8]} d is now a dict of averages: {'a': 1.5, 'c': 4.0, 'b': 8.0} w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Could have used a defaultdict to avoid dict initialisation, though. Or write a custom class: x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] class A: def __init__(self): self.store={} def add(self, key, number): if key in self.store: self.store[key].append(number) else: self.store[key] = [number] a=A() # collect data for idx, val in zip(y,x): a.add(idx, val) # build the final list: w = [ sum(a.store[key])/len(a.store[key]) for key in y ] print("w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) Produces same output, of course. Note that those solutions are both not very efficient, but who cares ;) > thanks! No Problem, Michael From javier.collado at gmail.com Tue Mar 9 05:43:05 2010 From: javier.collado at gmail.com (Javier Collado) Date: Tue, 9 Mar 2010 11:43:05 +0100 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: <058ebe77-de1b-4814-917a-57e6e65e2d03@t23g2000yqt.googlegroups.com> References: <058ebe77-de1b-4814-917a-57e6e65e2d03@t23g2000yqt.googlegroups.com> Message-ID: > I'm only aware of Hyde (http://ringce.com/hyde) There are also jekyll and cyrax: http://github.com/mojombo/jekyll/ http://pypi.python.org/pypi/cyrax/0.1.5 I haven't tried any of them, but it looks like cyrax is in active development and its design was inspired in both jekyll and hyde. Best regards, Javier From spamfresser at ch3ka.de Tue Mar 9 06:11:35 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 09 Mar 2010 12:11:35 +0100 Subject: related lists mean value (golfed) In-Reply-To: References: Message-ID: OK, I golfed it :D Go ahead and kill me ;) x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(a,b,v={}): try: v[a].append(b) except: v[a]=[b] def g(a): return sum(v[a])/len(v[a]) return g w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]] print("w is now the list of averages, corresponding with y:\n \ \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) Output: w is now the list of averages, corresponding with y: x: [1, 2, 8, 5, 0, 7] y: ['a', 'a', 'b', 'c', 'c', 'c'] w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Regards, Michael From steve at holdenweb.com Tue Mar 9 06:18:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Mar 2010 06:18:06 -0500 Subject: What to do if anything bites. In-Reply-To: <4b957998$0$17135$426a34cc@news.free.fr> References: <4b957998$0$17135$426a34cc@news.free.fr> Message-ID: News123 wrote: > Google Adsense wrote: >> What to do if anything bites. >> >> Check our bites treatment at >> >> http://... > > Pythons don't bite First, if you have to respond to spam please omit the URL that the spammer is trying to bring to Google's attention as well as direct readers. Secondly, do you realise you are posting from an address that has been "suspended due to inactivity"? Otherwise you would have received this message privately. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bob at leaddevice.com Tue Mar 9 06:23:59 2010 From: bob at leaddevice.com (BobAalsma) Date: Tue, 9 Mar 2010 03:23:59 -0800 (PST) Subject: Newbie question: python versions differ per user? References: <8a04bbfd-9c48-4397-8c81-c159dc1b8977@33g2000yqj.googlegroups.com> Message-ID: On Mar 8, 8:15?pm, BobAalsma wrote: > I'm on Mac OS X 10.5.8 and downloaded 2.6.4 Mac Installer Disk Image > as/in(?) the sys admin user. For this user Pyhton 2.6.4 is now the > current version. > I want to use Python outside the sys asdmin user. However, all other > users still use Python 2.5.1 (Apple delivered). > > The sys admin user looks in /Library/Frameworks/Python.framework/ > Versions/2.6/lib/... > The other users look in ? ? ? ?/System/Library/Frameworks/ > Python.framework/Version/2.5/lib/... > > I could not find any questions on this matter, so am I the only one? > Did I do something wrong? > I assumed the paths for all users would be modified - too easy? OK, sorry, found out. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Tue Mar 9 06:28:23 2010 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Tue, 9 Mar 2010 11:28:23 +0000 (UTC) Subject: Are there in Python some static web site generating tools like?webgen, nanoc or webby in Ruby ? References: Message-ID: KLEIN St?phane wrote: > Hi, > > Today, I've show this static web site generating tools write in ruby : > > * http://webgen.rubyforge.org/index.html > * http://nanoc.stoneship.org/about/ > * http://webby.rubyforge.org/tutorial/ > > I like this tools, I'm wonder if there are similar tools in Python ? > rst2web -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From __peter__ at web.de Tue Mar 9 07:02:12 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Mar 2010 13:02:12 +0100 Subject: related lists mean value (golfed) References: Message-ID: Michael Rudolf wrote: > OK, I golfed it :D > Go ahead and kill me ;) > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > def f(a,b,v={}): > try: v[a].append(b) > except: v[a]=[b] > def g(a): return sum(v[a])/len(v[a]) > return g > w = [g(i) for g,i in [(f(i,v),i) for i,v in zip(y,x)]] > > print("w is now the list of averages, corresponding with y:\n \ > \n x: %s \n y: %s \n w: %s \n" % (x, y, w)) > > Output: > w is now the list of averages, corresponding with y: > > x: [1, 2, 8, 5, 0, 7] > y: ['a', 'a', 'b', 'c', 'c', 'c'] > w: [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] >>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] Peter From dr.cg at 126.com Tue Mar 9 07:19:22 2010 From: dr.cg at 126.com (CHEN Guang) Date: Tue, 9 Mar 2010 20:19:22 +0800 (CST) Subject: How to detect C Function block using python Message-ID: <19912fa.87bc.12742dd77f8.Coremail.dr.cg@126.com> In the source code of PythoidC ( http://pythoidc.googlecode.com ), I wrote a Parser for C header files with Python regular expression, not only functions but also structs macros. May be of some help. Hey All, I'm new in this community. I am writing a static analyzer for validating C Code using python and for that I'm looking for a python module/API that will detect Function block of a given C-File. I know simple function can be detected using push "{" and poping it if character "}" is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Thanks! Faheem -------------- next part -------------- An HTML attachment was scrubbed... URL: From yinon.me at gmail.com Tue Mar 9 07:27:59 2010 From: yinon.me at gmail.com (Yinon Ehrlich) Date: Tue, 9 Mar 2010 04:27:59 -0800 (PST) Subject: Duplicate keys in dict? References: <21f87f60-fea2-417a-a092-64363b5b280e@y11g2000yqh.googlegroups.com> Message-ID: <98e3cd64-063c-47e1-b671-04fd3fa16c71@z11g2000yqz.googlegroups.com> On Mar 7, 6:23?pm, vsoler wrote: > Hello, > > My code snippet reads data from excel ranges. First row and first > column are column headers and row headers respectively. After reding > the range I build a dict. > > What is the best approach for this problem? Can anybody help? Have you tried xlread ? (http://www.python-excel.org/) Best, -- Yinon From efiish at gmail.com Tue Mar 9 08:51:05 2010 From: efiish at gmail.com (Lan Qing) Date: Tue, 9 Mar 2010 21:51:05 +0800 Subject: a newbie's question Message-ID: Hi all, I'm a newbie of python programming language. I have used c/c++ for 5 years, and one year experience in Lua programming language. Can any one give me some advice on learning python. Think you for any help!! best regards!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From casevh at gmail.com Tue Mar 9 08:54:15 2010 From: casevh at gmail.com (casevh) Date: Tue, 9 Mar 2010 05:54:15 -0800 (PST) Subject: Calculating very large exponents in python References: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> Message-ID: On Mar 8, 10:39?pm, casevh wrote: > [also replying to Geremy since the OP's message doesn't appear...] > > On Mar 8, 11:05?am, geremy condra wrote: > > > > > > > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > > > Thanks Geremy, > > > > That has been an absolute bump........... GOD i cant sit on my chair, it has > > > worked even on 512 bit number and with no time.......... > > > superb i would say. > > > > lastly, i am using the code below to calculate Largest Prime factor of a > > > number: > > > > print > > > ('''=======================================================================??========''' > > > ?????? '''????????????? CALCULATE? HIGHEST PRIME > > > FACTOR????????????????????????????????? ''' > > > > '''========================================================================??=======''') > > > > #!/usr/bin/env python > > > def highest_prime_factor(n): > > > ?? if isprime(n): > > > ????? return n > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return highest_prime_factor(n/x) > > > def isprime(n): > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return False > > > ?? return True > > > if? __name__ == "__main__": > > > ?? import time > > > ?? start = time.time() > > > ?? print highest_prime_factor(1238162376372637826) > > > ?? print time.time() - start > > > > the code works with a bit of delay on the number : "1238162376372637826" but > > > extending it to > > > (10902610991329142436630551158108608965062811746392577675456004845499113044??30471090261099132914243663055115810860896506281174639257767545600484549911?3?0443047) > > > ?makes python go crazy. Is there any way just like above, i can have it > > > calculated it in no time. > > > > thanks for the support. > > > If you're just looking for the largest prime factor I would suggest using > > a fermat factorization attack. In the example you gave, it returns > > nearly immediately. > > > Geremy Condra- Hide quoted text - > > > - Show quoted text - > > For a Python-based solution, you might want to look at pyecm (http:// > sourceforge.net/projects/pyecm/) > > On a system with gmpy installed also, pyecm found the following > factors: > > 101, 521, 3121, 9901, 36479, 300623, 53397071018461, > 1900381976777332243781 > > There still is a 98 digit unfactored composite: > > 602525071745682437589111511878284384468144476539868422797968232621651594065?00174226172705680274911 > > Factoring this remaining composite using ECM may not be practical. > > casevh- Hide quoted text - > > - Show quoted text - After a few hours, the remaining factors are 6060517860310398033985611921721 and 9941808367425935774306988776021629111399536914790551022447994642391 casevh From mehgcap at gmail.com Tue Mar 9 08:55:39 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 9 Mar 2010 08:55:39 -0500 Subject: odd error Message-ID: Hi all, In the same program I wrote about yesterday, I have a dictionary of keystrokes which are captured. I just tried adding a new one, bringing the total to 11. Here are entries 10 and 11; 10 has been working fine for months. 10 : (57, win32con.MOD_CONTROL), 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) Now, though, when I press ctrl-shift-c (keystroke 11), nothing happens. Pressing any other keystroke after that will crash the program with some sort of Python internal com server exception that I have never seen before. When set to a keystroke I already use, such as #10, the function called by #11 works just fine. Does anyone see a problem with the above syntax? The trouble almost definitely has to be there; again, using an already-working keystroke instead of making a new one works perfectly, it is just when I add this new one that things break. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From simon at brunningonline.net Tue Mar 9 09:00:42 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 9 Mar 2010 14:00:42 +0000 Subject: a newbie's question In-Reply-To: References: Message-ID: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> On 9 March 2010 13:51, Lan Qing wrote: > Hi all, > ?? ? ?I'm a newbie of python programming language. Welcome! > I have used c/c++ for 5 > years, and one year experience in Lua programming language. Can any one give > me some advice on learning python. Think you for any help!! You'll find some useful starting points here - . -- Cheers, Simon B. From ssteinerx at gmail.com Tue Mar 9 09:04:53 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 9 Mar 2010 09:04:53 -0500 Subject: Opportunity to author Python books- Packt Publishing. In-Reply-To: References: Message-ID: <8E3C96A7-D2AF-4E5F-89CB-74E2F92668D0@gmail.com> On Mar 8, 2010, at 6:25 AM, Kshipra Singh wrote: I would be delighted to write a cookbook on the stuff I use every day: python for administering cloud servers. Thanks, S aka/Steve Steiner aka/ssteinerX > Hi All, > > I am writing to you for Packt Publishing, the publishers computer related books. > > We are planning to extend our catalogue of cookbooks and are currently inviting "Python" fanatics interested in writing a cookbook. So, if you love "Python" and are interested in writing a cookbook, please contact us with your book ideas atauthor at packtpub.com. Even if you do not have a book idea and are simply interested in authoring a cookbook, we are keen to hear from you. > > More details about the opportunity are available at: http://authors.packtpub.com/content/python-fanatics-invited-write-packt > > Thanks > Kshipra Singh > Author Relationship Manager > Packt Publishing > www.PacktPub.com > > Skype: kshiprasingh15 > Twitter: http://twitter.com/kshipras > > Interested in becoming an author? Visit http://authors.packtpub.com for all the information you need about writing for Packt. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Mar 9 09:09:01 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 09 Mar 2010 09:09:01 -0500 Subject: Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime Message-ID: <1268143741.31835.1363885481@webmail.messagingengine.com> We've decided to build a re-usable *general purpose* PY2EXE "runtime" that can be shared by a number of scripts vs. distributing a monolithic EXE for each of our scripts. A list of the Python 2.6.4 compatible modules/packages we decided to include (and exclude) in our "runtime" follows my signature. Any suggestions on additions or deletions appreciated. Thanks, Malcolm 3rd party modules/packages: - jsonpickle - win32api - winshell We've included all modules from the Python standard library EXCEPT the following: http://www.python.org/doc/2.6.4/modindex.html - aifc - audioop - bsddb - Carbon - dbhash - distutils - dumbdbm - netrc - plistlib - robotparser - ScrolledText - shelve - sunau - tabnanny - Tix - Tkinter - turtle - whichdb -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Tue Mar 9 09:18:42 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Mar 2010 09:18:42 -0500 Subject: imported var not being updated In-Reply-To: References: Message-ID: <4B9658C2.1040707@optimum.net> On 3/8/2010 11:55 PM, Gary Herron wrote: > > The form of import you are using > from helpers import mostRecent > makes a *new* binding to the value in the module that's doing the > import. > What you can do, is not make a separate binding, but reach into the > helpers module to get the value there. Like this: > > import helpers > print helpers.mostRecent > Gary, are you asserting that in these separate situations: one.py: from helpers import mostRecent x = mostRecent two.py: import helpers x = helpers.mostRecent ... the name "x" will be bound to different objects? Tx, John From xahlee at gmail.com Tue Mar 9 09:24:42 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 9 Mar 2010 06:24:42 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: <13c167f4-5e37-48a0-a480-3494c212035c@k5g2000pra.googlegroups.com> On Mar 8, 11:14?am, Duncan Booth wrote: > Xah Lee wrote: > > For example, consider, if you are within world's top 100th user of > > database in terms of database size, such as Google, then it may be > > that the off-the-shelf tools may be limiting. But how many users > > really have such massive size of data? > > You've totally missed the point. It isn't the size of the data you have > today that matters, it's the size of data you could have in several years' > time. so, you saying, in several years, we'd all become the world's top 100 database users in terms of size, like Google? Xah ? http://xahlee.org/ ? From benjamin.kaplan at case.edu Tue Mar 9 09:25:38 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 9 Mar 2010 09:25:38 -0500 Subject: imported var not being updated In-Reply-To: <4B9658C2.1040707@optimum.net> References: <4B9658C2.1040707@optimum.net> Message-ID: On Tue, Mar 9, 2010 at 9:18 AM, John Posner wrote: > On 3/8/2010 11:55 PM, Gary Herron wrote: > > > >> The form of import you are using >> from helpers import mostRecent >> makes a *new* binding to the value in the module that's doing the >> import. >> > > > > > What you can do, is not make a separate binding, but reach into the >> helpers module to get the value there. Like this: >> >> import helpers >> print helpers.mostRecent >> >> > Gary, are you asserting that in these separate situations: > > one.py: > > from helpers import mostRecent > x = mostRecent > > two.py: > > import helpers > x = helpers.mostRecent > > > ... the name "x" will be bound to different objects? > > Tx, > John > > No. the name x will be bound to the same object. It's the other way that gives a problem from helpers import mostRecent works like import helpers mostRecent = helpers.mostRecent del helpers so when you do mostRecent = x it rebinds "mostRecent" in the current scope but doesn't affect helpers.mostRecent, the name in the "helpers" module. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Mar 9 09:27:49 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 09 Mar 2010 09:27:49 -0500 Subject: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime In-Reply-To: <1268143741.31835.1363885481@webmail.messagingengine.com> References: <1268143741.31835.1363885481@webmail.messagingengine.com> Message-ID: <1268144869.2338.1363892987@webmail.messagingengine.com> We've decided to build a re-usable *general purpose* PY2EXE "runtime" that can be shared by a number of scripts vs. distributing a monolithic EXE for each of our scripts. A list of the Python 2.6.4 compatible modules/packages we decided to include (and exclude) in our "runtime" follows my signature. Any suggestions on additions or deletions appreciated. Thanks, Malcolm 3rd party modules/packages: - jsonpickle - wmi <--- forgot this one in my original post - win32api - winshell We've included all modules from the Python standard library EXCEPT the following: http://www.python.org/doc/2.6.4/modindex.html - aifc - audioop - bsddb - Carbon - dbhash - distutils - dumbdbm - netrc - plistlib - robotparser - ScrolledText - shelve - sunau - tabnanny - Tix - Tkinter - turtle - whichdb From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 9 09:48:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Mar 2010 15:48:59 +0100 Subject: imported var not being updated In-Reply-To: <4B9658C2.1040707@optimum.net> References: <4B9658C2.1040707@optimum.net> Message-ID: <4b965fde$0$14410$426a74cc@news.free.fr> John Posner a ?crit : > On 3/8/2010 11:55 PM, Gary Herron wrote: > >> >> The form of import you are using >> from helpers import mostRecent >> makes a *new* binding to the value in the module that's doing the >> import. > > > >> What you can do, is not make a separate binding, but reach into the >> helpers module to get the value there. Like this: >> >> import helpers >> print helpers.mostRecent >> > > Gary, are you asserting that in these separate situations: > > one.py: > > from helpers import mostRecent > x = mostRecent > > two.py: > > import helpers > x = helpers.mostRecent > > > ... the name "x" will be bound to different objects? Nope. What he's saying is that one.x and two.x are two different names - each living in it's own namespace - that happen to be bound to the same object. Now rebiding one.x to a different object will _of course_ have no impact on the object two.x is bound to. That's exactly the same as: one = dict() two = dict() # one['x'] and two['x'] refer to the same object one['x'] = two['x'] = ["foo", "bar"] print one['x'], two['x'], one['x'] is two['x'] # mutating one['x'], visible in two['x'] # (of course since it's the same object) one['x'].append("baaz") print one['x'], two['x'], one['x'] is two['x'] # now rebind one['x'] one['x'] = 42 # obvious result: one['x'] and two['x'] now refer to 2 different objects print one['x'], two['x'], one['x'] is two['x'] If in doubt about namespaces, think dicts. Namespaces are like dicts - and are often nothing else that a plain old dict FWIW. HTH From spamfresser at ch3ka.de Tue Mar 9 10:00:00 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 09 Mar 2010 16:00:00 +0100 Subject: related lists mean value (golfed) In-Reply-To: References: Message-ID: Am 09.03.2010 13:02, schrieb Peter Otten: >>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] > [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > Peter ... pwned. Should be the fastest and shortest way to do it. I tried to do something like this, but my brain hurt while trying to visualize list comprehension evaluation orders ;) Regards, Michael From kishoreinme at gmail.com Tue Mar 9 10:01:22 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 07:01:22 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: On Mar 9, 2:19?pm, News123 wrote: > Hi, > > > > kishore wrote: > > hello there > > > Iam using python 2.5.4 > > pyserial ?2.4 > > pywin32-214 > > > on windows 7 > > > i hav a small test script written to query a serial device (arduino) > > and get back reply appropriately > > > ////file: test.py > > > import serial > > print 'hi' > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > ser.close() > > ser.open() > > ser.write('1') > > ser.readline() > > ser.readline() > > ser.close() > > > the device waits for '1' through its serial interface and print two > > lines if it gets '1' > > > "Some Data found" and "Header received" > > > the script works on IDLE well when given one line at a time > > > but when given in command line as python test.py it prints hi and wait > > forever > > Unfortunately I don't remember exacty, but try following: > > close IDLE and try then to start the script from the command line. > I remember having had a problem with idle, that it did not always close > the UART port > (especially, when an error (e.g. syntax) occured before the close statement) > > bye > > N Thanks for your response i tried closing idle and the following code prints port opened Write failed code: import serial import time ser=serial.Serial(port='\\.\COM2', baudrate=9600) if ser: print 'port opened' ser.open() if ser.write('1'): print 'Write success' else: print 'write failed' time.sleep(1) a=ser.readline() time.sleep(1) b=ser.readline() print b ser.close() I believe this might be a serial port access error. how to solve this? Any suggestions? From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 9 10:02:04 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Mar 2010 16:02:04 +0100 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90e2d0$0$10096$426a34cc@news.free.fr> Message-ID: <4b9662ee$0$9131$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: >>> Well, Zope is backed by an object database rather than a relational one. >> >> And it ended up being a *major* PITA on all Zope projects I've worked >> on... > > Care to write a few sentences on nature of problems with zodb? I was > flirting with the thought of using it on some project. Would require more than a few sentences. But mostly, it's about the very nature of the Zodb : it's a giant graph of Python objects. So : 1/ your "data" are _very_ tightly dependant on the language and applicative code 2/ you have to hand-write each and every graph traversal 3/ accessing a given object usually loads quite a few others in memory I once thought the Zodb was cool. From stefan_ml at behnel.de Tue Mar 9 10:07:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Mar 2010 16:07:54 +0100 Subject: remove element with ElementTree In-Reply-To: <8ad6319f-97f1-46b7-b89e-d455bd89ad03@b9g2000pri.googlegroups.com> References: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> <8ad6319f-97f1-46b7-b89e-d455bd89ad03@b9g2000pri.googlegroups.com> Message-ID: Justin Ezequiel, 09.03.2010 10:34: > On Mar 9, 11:35 am, tdan wrote: >> I have been using ElementTree to write an app, and would like to >> simply remove an element. >> But in ElementTree, you must know both the parent and the child >> element to do this. >> There is no getparent() function, so I am stuck if I only have an >> element. > > see http://effbot.org/zone/element.htm#accessing-parents Also note that there is an independent ElementTree implementation called lxml.etree, which has parent pointers. Stefan From showell30 at yahoo.com Tue Mar 9 10:21:15 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 07:21:15 -0800 (PST) Subject: related lists mean value References: <4B95B4FF.1070407@optimum.net> Message-ID: <5574554b-1d62-4faf-bb89-34cb431741cd@q2g2000pre.googlegroups.com> On Mar 8, 6:39?pm, John Posner wrote: > On 3/8/2010 5:34 PM, dimitri pater - serpia wrote: > > > Hi, > > > I have two related lists: > > x = [1 ,2, 8, 5, 0, 7] > > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > > what I need is a list representing the mean value of 'a', 'b' and 'c' > > while maintaining the number of items (len): > > w = [1.5, 1.5, 8, 4, 4, 4] > > > I have looked at iter(tools) and next(), but that did not help me. I'm > > a bit stuck here, so your help is appreciated! > > Nobody expects object-orientation (or the Spanish Inquisition): > Heh. Yep, I avoided OO for this. Seems like a functional problem. My solution is functional on the outside, imperative on the inside. You could add recursion here, but I don't think it would be as straightforward. def num_dups_at_head(lst): assert len(lst) > 0 val = lst[0] i = 1 while i < len(lst) and lst[i] == val: i += 1 return i def smooth(x, y): result = [] while x: cnt = num_dups_at_head(y) avg = sum(x[:cnt]) * 1.0 / cnt result += [avg] * cnt x = x[cnt:] y = y[cnt:] return result > #------------------------- > from collections import defaultdict > > class Tally: > ? ? ?def __init__(self, id=None): > ? ? ? ? ?self.id = id > ? ? ? ? ?self.total = 0 > ? ? ? ? ?self.count = 0 > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c'] > > # gather data > tally_dict = defaultdict(Tally) > for i in range(len(x)): > ? ? ?obj = tally_dict[y[i]] > ? ? ?obj.id = y[i] > ? ? ?obj.total += x[i] > ? ? ?obj.count += 1 > > # process data > result_list = [] > for key in sorted(tally_dict): > ? ? ?obj = tally_dict[key] > ? ? ?mean = 1.0 * obj.total / obj.count > ? ? ?result_list.extend([mean] * obj.count) > print result_list > #------------------------- From kishoreinme at gmail.com Tue Mar 9 10:30:32 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 07:30:32 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: <6596caf4-8d36-40b4-8e8d-a5ed2a18f245@z1g2000prc.googlegroups.com> On Mar 9, 8:01?pm, kishore wrote: > On Mar 9, 2:19?pm, News123 wrote: > > > > > Hi, > > > kishore wrote: > > > hello there > > > > Iam using python 2.5.4 > > > pyserial ?2.4 > > > pywin32-214 > > > > on windows 7 > > > > i hav a small test script written to query a serial device (arduino) > > > and get back reply appropriately > > > > ////file: test.py > > > > import serial > > > print 'hi' > > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > > ser.close() > > > ser.open() > > > ser.write('1') > > > ser.readline() > > > ser.readline() > > > ser.close() > > > > the device waits for '1' through its serial interface and print two > > > lines if it gets '1' > > > > "Some Data found" and "Header received" > > > > the script works on IDLE well when given one line at a time > > > > but when given in command line as python test.py it prints hi and wait > > > forever > > > Unfortunately I don't remember exacty, but try following: > > > close IDLE and try then to start the script from the command line. > > I remember having had a problem with idle, that it did not always close > > the UART port > > (especially, when an error (e.g. syntax) occured before the close statement) > > > bye > > > N > > Thanks for your response > i tried closing idle and the following code prints > port opened > Write failed > > code: > > import serial > import time > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > if ser: > ? ? ? ? print 'port opened' > ser.open() > if ser.write('1'): > ? ? ? ? print 'Write success' > else: > ? ? ? ? print 'write failed' > > time.sleep(1) > > a=ser.readline() > time.sleep(1) > b=ser.readline() > print b > ser.close() > > I believe this might be a serial port access error. > how to solve this? > Any suggestions? have found one more person with same problem but no solution http://mail.python.org/pipermail/python-win32/2009-January/008613.html From eckhardt at satorlaser.com Tue Mar 9 10:40:59 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 09 Mar 2010 16:40:59 +0100 Subject: odd error References: Message-ID: Alex Hall wrote: > Now, though, when I press ctrl-shift-c (keystroke 11), nothing > happens. Control-C sends a special signal to the console, like Control-Break. > Pressing any other keystroke after that will crash the program > with some sort of Python internal com server exception that I > have never seen before. Neither do I, in particular since you don't share that rare gem with us. ;) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From kishoreinme at gmail.com Tue Mar 9 10:42:21 2010 From: kishoreinme at gmail.com (kishore) Date: Tue, 9 Mar 2010 07:42:21 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: <2c849953-6556-4f5b-b88c-1fae6e4f27ce@t20g2000yqe.googlegroups.com> On Mar 9, 8:01?pm, kishore wrote: > On Mar 9, 2:19?pm, News123 wrote: > > > > > Hi, > > > kishore wrote: > > > hello there > > > > Iam using python 2.5.4 > > > pyserial ?2.4 > > > pywin32-214 > > > > on windows 7 > > > > i hav a small test script written to query a serial device (arduino) > > > and get back reply appropriately > > > > ////file: test.py > > > > import serial > > > print 'hi' > > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > > ser.close() > > > ser.open() > > > ser.write('1') > > > ser.readline() > > > ser.readline() > > > ser.close() > > > > the device waits for '1' through its serial interface and print two > > > lines if it gets '1' > > > > "Some Data found" and "Header received" > > > > the script works on IDLE well when given one line at a time > > > > but when given in command line as python test.py it prints hi and wait > > > forever > > > Unfortunately I don't remember exacty, but try following: > > > close IDLE and try then to start the script from the command line. > > I remember having had a problem with idle, that it did not always close > > the UART port > > (especially, when an error (e.g. syntax) occured before the close statement) > > > bye > > > N > > Thanks for your response > i tried closing idle and the following code prints > port opened > Write failed > > code: > > import serial > import time > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > if ser: > ? ? ? ? print 'port opened' > ser.open() > if ser.write('1'): > ? ? ? ? print 'Write success' > else: > ? ? ? ? print 'write failed' > > time.sleep(1) > > a=ser.readline() > time.sleep(1) > b=ser.readline() > print b > ser.close() > > I believe this might be a serial port access error. > how to solve this? > Any suggestions? have found one more person with same problem but no solution http://mail.python.org/pipermail/python-win32/2009-January/008613.html From stefan_ml at behnel.de Tue Mar 9 10:45:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Mar 2010 16:45:48 +0100 Subject: remove element with ElementTree In-Reply-To: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> References: <790217d6-e230-44e8-9aa1-4f8c7a66170c@g7g2000yqe.googlegroups.com> Message-ID: tdan, 09.03.2010 04:35: > I have been using ElementTree to write an app, and would like to > simply remove an element. > But in ElementTree, you must know both the parent and the child > element to do this. > There is no getparent() function, so I am stuck if I only have an > element. > > I am iterating over a table and getting all tags, checking their > text, and conditionally deleting them: > > def RemoveElementWithText( topEl, subEl, text ): Note that all-camel-case names are rather unusual for function names and rather used for class names. See PEP 8 for a style guide. > for el in topEl.getiterator( subEl ): > if el.text = text: > break > else: > el = None > return el > > RemoveElementWithText( table, 'td', 'sometext' ) > > My table is like so: > > > ... > # I need to grab this number only # I need to grab this number only # I need to grab this number only """[/CODE] From gagsl-py2 at yahoo.com.ar Fri Mar 19 23:09:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Mar 2010 00:09:46 -0300 Subject: Simple lock References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> <4BA4337B.6050301@mrabarnett.plus.com> Message-ID: En Fri, 19 Mar 2010 23:31:23 -0300, MRAB escribi?: > moerchendiser2k3 wrote: >> class SetPointer >> { >> private: >> void *ptr; >> MY_LOCK lock; >> public: >> void SetPointer(void *p) >> { >> Lock(this->lock); >> this->ptr = p; >> } > 3. You're locking, but never unlocking. The sequence should be: lock, do > stuff, unlock. Just FYI: C++ doesn't have try/finally, and such behavior is usually emulated using a local object. When it goes out of scope, it is automatically destroyed, meaning that the object destructor is called. Whatever you would write in a "finally" clause, in C++ goes into a destructor. Of course C++ guys would never say they're "emulating" try/finally, instead they declare RAII as *the* Only and Right Way :) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Fri Mar 19 23:20:38 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 03:20:38 GMT Subject: Tuples vs. variable-length argument lists References: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> Message-ID: <4ba43f05$0$27838$c3e8da3@news.astraweb.com> On Fri, 19 Mar 2010 17:20:31 -0700, Spencer Pearson wrote: > Hi! > > This might be more of a personal-preference question than anything, but > here goes: when is it appropriate for a function to take a list or tuple > as input, and when should it allow a varying number of arguments? That depends on the function as well as your personal preference. Of course, you can also follow the lead of max and min and accept both: >>> max(1, 2, 3, 4) == max([1, 2, 3, 4]) True You need to consider which is more "natural" for the semantics of the function. > It seems as though the two are always interchangeable. Not always. Consider sum(a, b, c, d). Should that be "sum the sequence [a, b, c, d]" or "sum the sequence [a, b, c] with initial value d"? You might ask what difference it makes, but it may make a big difference: * if a...d are floats, there may be differences in rounding errors between a+b+c+d and d+a+b+c * if a...d are lists, the order that you do the addition matters: ["a", "b", "c"] + ["d"] != ["d"] + ["a", "b", "c"] * even if a...d are integers, it may make a big difference for performance. Perhaps not for a mere four arguments, but watch: >>> n = 10**1000000 >>> seq = [n] + range(10001) >>> from timeit import Timer >>> t1 = Timer("sum(seq)", "from __main__ import n, seq; seq.append(-n)") >>> t2 = Timer("sum(seq, -n)", "from __main__ import n, seq") >>> min(t1.repeat(number=1)) 6.1270790100097656 >>> min(t2.repeat(number=1)) 0.012988805770874023 In the first case, all the intermediate calculations are done using a million digit long int, in the second case it is not. [...] > I can't think > of any situation where you couldn't convert from one form to the other > with just a star or a pair of parentheses. Of course you can convert, but consider that this is doing a conversion. Perhaps that's unnecessary work for your specific function? You are packing and unpacking a sequence into a tuple. Whether this is a good thing or a bad thing depends on the function. > Is there a generally accepted convention for which method to use? Is > there ever actually a big difference between the two that I'm not > seeing? If you think of the function as operating on a single argument which is a sequence of arbitrary length, then it is best written to take a single sequence argument. If you think of the function as operating on an arbitrary number of arguments, then it is best written to take an arbitrary number of arguments. If you think it doesn't matter, then choose whichever model is less work for you. If neither seems better than the other, then choose arbitrarily. If you don't like the idea of making an arbitrary choice, or if your users complain, then support both models (if possible). -- Steven From gagsl-py2 at yahoo.com.ar Fri Mar 19 23:21:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 20 Mar 2010 00:21:44 -0300 Subject: Best Way to extract Numbers from String References: Message-ID: En Sat, 20 Mar 2010 00:04:08 -0300, Jimbo escribi?: > I am trying to grab some numbers from a string containing HTML text. > Can you suggest any good functions that I could use to do this? What > would be the easiest way to extract the following numbers from this > string... > > My String has this layout & I have commented what I want to grab: > [CODE] """ > > > > # > I need to grab this number only > > # > I need to grab this number only I'd use BeautifulSoup [1] to handle bad formed HTML like that. [1] http://www.crummy.com/software/BeautifulSoup/ -- Gabriel Genellina From python at mrabarnett.plus.com Fri Mar 19 23:38:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Mar 2010 03:38:27 +0000 Subject: Simple lock In-Reply-To: References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> <4BA4337B.6050301@mrabarnett.plus.com> Message-ID: <4BA44333.8010308@mrabarnett.plus.com> Gabriel Genellina wrote: > En Fri, 19 Mar 2010 23:31:23 -0300, MRAB > escribi?: >> moerchendiser2k3 wrote: > >>> class SetPointer >>> { >>> private: >>> void *ptr; >>> MY_LOCK lock; >>> public: >>> void SetPointer(void *p) >>> { >>> Lock(this->lock); >>> this->ptr = p; >>> } > >> 3. You're locking, but never unlocking. The sequence should be: lock, do >> stuff, unlock. > > Just FYI: C++ doesn't have try/finally, and such behavior is usually > emulated using a local object. When it goes out of scope, it is > automatically destroyed, meaning that the object destructor is called. > Whatever you would write in a "finally" clause, in C++ goes into a > destructor. > > Of course C++ guys would never say they're "emulating" try/finally, > instead they declare RAII as *the* Only and Right Way :) > Lock() doesn't look like a declaration, but a function call (although it's been a while since I last did C++!). In the past I've written some C++ code where try..finally... would've been useful... *sigh* From alfps at start.no Sat Mar 20 00:15:08 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 20 Mar 2010 05:15:08 +0100 Subject: Simple lock In-Reply-To: References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> <4BA4337B.6050301@mrabarnett.plus.com> Message-ID: * MRAB: > Gabriel Genellina wrote: >> En Fri, 19 Mar 2010 23:31:23 -0300, MRAB >> escribi?: >>> moerchendiser2k3 wrote: >> >>>> class SetPointer >>>> { >>>> private: >>>> void *ptr; >>>> MY_LOCK lock; >>>> public: >>>> void SetPointer(void *p) >>>> { >>>> Lock(this->lock); >>>> this->ptr = p; >>>> } >> >>> 3. You're locking, but never unlocking. The sequence should be: lock, do >>> stuff, unlock. >> >> Just FYI: C++ doesn't have try/finally, and such behavior is usually >> emulated using a local object. When it goes out of scope, it is >> automatically destroyed, meaning that the object destructor is called. >> Whatever you would write in a "finally" clause, in C++ goes into a >> destructor. >> >> Of course C++ guys would never say they're "emulating" try/finally, >> instead they declare RAII as *the* Only and Right Way :) >> > Lock() doesn't look like a declaration, but a function call (although > it's been a while since I last did C++!). Right. But the OP is clearly a beginner who has yet to learn conventions (like all uppercase reserved for macros) and good versus bad programming constructs (like using void*), and who is even confusing C++ with Python. So it might just be that 'Lock' is a macro, and then it can expand to anything. > In the past I've written some C++ code where try..finally... would've > been useful... *sigh* Check out Marginean and Alexandrescu's ScopeGuard. Old DDJ-article. For MSVC you may want to change use of __LINE__ in that code, to MS-specific __COUNTER__. Fwiw. I can't remember ever needing 'finally' in C++ code. It indicates a lack of encapsulation of entitites that should clean up themselves. Simple smart pointers etc. can help. E.g., check out Boost library. Cheers & hth., even if a little off-topic, - Alf From kse.listed.co1 at gmail.com Sat Mar 20 00:18:15 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Fri, 19 Mar 2010 21:18:15 -0700 (PDT) Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" Message-ID: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" From aahz at pythoncraft.com Sat Mar 20 00:39:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Mar 2010 21:39:38 -0700 Subject: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime References: <1268143741.31835.1363885481@webmail.messagingengine.com> Message-ID: In article , wrote: > >We've decided to build a re-usable *general purpose* PY2EXE "runtime" >that can be shared by a number of scripts vs. distributing a monolithic >EXE for each of our scripts. It's not clear what the purpose of this is. You can build several scripts against the same py2exe backend. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From Brian.Mingus at Colorado.EDU Sat Mar 20 00:41:42 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Fri, 19 Mar 2010 22:41:42 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> On Fri, Mar 19, 2010 at 10:18 PM, Naeem wrote: > "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY > FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY > RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" > "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" > "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" > -- > http://mail.python.org/mailman/listinfo/python-list > Guys, I know it is a lot of work to moderate a large mailing list. But still, with so many of us surely we can pull it off? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 02:23:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 06:23:14 GMT Subject: Writing tests for the Python bug tracker Message-ID: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> I have two reported bugs in the bug tracker waiting on tests: http://bugs.python.org/issue8128 http://bugs.python.org/issue4037 Are there any guidelines for writing tests for the standard library and language? I've googled, but found nothing useful: lots of guidelines for writing tests, and of course I've read PEP 8, but I'm not sure if there are conventions for tests I'm missing. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 02:52:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 06:52:08 GMT Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4ba47098$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 06:23:14 +0000, Steven D'Aprano wrote: > Are there any guidelines for writing tests for the standard library and > language? I've googled, but found nothing useful: lots of guidelines for > writing tests, and of course I've read PEP 8, but I'm not sure if there > are conventions for tests I'm missing. I've found this: http://docs.python.org/library/test.html and I've written a small test: $ cat test_unicode_interpolation.py # For testing http://bugs.python.org/issue8128 import test.test_support import unittest class K(unicode): def __str__(self): return "Surprise!" class UnicodeInterpolationTest(unittest.TestCase): def test_interpolation(self): self.assertEquals(u'%s' % K('some text'), 'Surprise!') def test_main(): test.test_support.run_unittest(UnicodeInterpolationTest) if __name__ == "__main__": test_main() but when I try running the test, I get an error: $ python test_unicode_interpolation.py Options: {'delimiter': None} str of options.delimiter = None repr of options.delimiter = None len of options.delimiter Traceback (most recent call last): File "test_unicode_interpolation.py", line 3, in import test.test_support File "/home/steve/python/test.py", line 8, in print "len of options.delimiter", len(options.delimiter) TypeError: object of type 'NoneType' has no len() What am I doing wrong? (By the way, I'm expecting the unit test above to fail.) -- Steven From exarkun at twistedmatrix.com Sat Mar 20 03:07:58 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sat, 20 Mar 2010 07:07:58 -0000 Subject: Writing tests for the Python bug tracker In-Reply-To: <4ba47098$0$27838$c3e8da3@news.astraweb.com> References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> <4ba47098$0$27838$c3e8da3@news.astraweb.com> Message-ID: <20100320070758.2792.893406088.divmod.xquotient.1775@localhost.localdomain> On 06:52 am, steve at remove-this-cybersource.com.au wrote: > >but when I try running the test, I get an error: > >$ python test_unicode_interpolation.py >Options: {'delimiter': None} >str of options.delimiter = None >repr of options.delimiter = None >len of options.delimiter >Traceback (most recent call last): > File "test_unicode_interpolation.py", line 3, in > import test.test_support > File "/home/steve/python/test.py", line 8, in > print "len of options.delimiter", len(options.delimiter) >TypeError: object of type 'NoneType' has no len() > > >What am I doing wrong? Take a careful look at the stack being reported. Then, think of a better name than "test" for your file. Jean-Paul From greg.ewing at canterbury.ac.nz Sat Mar 20 03:32:23 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 20 Mar 2010 20:32:23 +1300 Subject: to pass self or not to pass self In-Reply-To: References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: <80jbd2Fhd3U1@mid.individual.net> Patrick Maupin wrote: > Actually, I think I overstated my case -- there is some special logic > for len and built-in objects, I think. Yes, len() invokes the C-level sq_len slot of the type object, which for built-in types points directly to the C function implementing the len() operation for that type. So len() on a string doesn't involve looking up a __len__ attribute or creating a bound method at all. The only reason a __len__ attribute exists at all for built-in types is to give Python code the illusion that C-coded and Python-coded classes work the same way. Most of the time it's never used. If you try the same test using a method that doesn't have a corresponding type slot (basically anything without a double_underscore name) you will probably see a small improvement. -- Greg From __peter__ at web.de Sat Mar 20 04:36:22 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Mar 2010 09:36:22 +0100 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Jean-Michel Pichavant wrote: > You are still accessing the private attribute of the module logging. Just reading it is a significantly more conservative approach than setting it to an object with an unusual notion of equality ;) > My previous remark was misleading, in fact there's nothing you can do > about it. How about replacing logging._srcfile with fixname(logging.__file__)? > _srcfile is not meant to be used elsewhere than in the logging module > itself. > However, I don't wanna sound like I'm rejecting this solution, 1st the > OP is satisified with it and since this solution is working, it is still > more helpful than anyone noticing that you've accessed a private > attribute (some will successfully argue that python allows to do so). Yeah, I had hoped that I could get away without drawing the "consenting adults" wildcard... > At the very begining of this thread I've provided a complete different > approach, instead of using the builtin 'filename' and 'lineno' field of > the logging, use custom fileds with the extra parameter. > > It has also some drawbacks but could be a possible alternative. Having two filename/lineno sets ist likely to confuse. Peter From hawat.thufir at gmail.com Sat Mar 20 05:17:14 2010 From: hawat.thufir at gmail.com (Thufir) Date: Sat, 20 Mar 2010 09:17:14 GMT Subject: google token Message-ID: I'd like to acquire a token, as below, but from Java: def get_token(self,force=False) : '''Return a tokey. A token is a special string that is used like a session identification, but that expire rather quickly.''' if ( force or (self._token == None) ) : feedurl = CONST.URI_PREFIXE_API + CONST.API_TOKEN + '? client=' + CONST.AGENT # print feedurl self._token = self._web.get(feedurl) return self._token http://pyrfeed.googlecode.com/svn/trunk/lib/GoogleReader/reader.py Basically, that's just a GET on a particular URL, and the returned string is saved as _token? thanks, Thufir From stefan_ml at behnel.de Sat Mar 20 05:44:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Mar 2010 10:44:39 +0100 Subject: C-API PyObject_Call In-Reply-To: <7597f6a5-5fe0-4a69-9f9b-f0d96f4499d1@g26g2000yqn.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> <7597f6a5-5fe0-4a69-9f9b-f0d96f4499d1@g26g2000yqn.googlegroups.com> Message-ID: moerchendiser2k3, 20.03.2010 03:01: > Yes, the user is able to set a file which contains a function that > does what the user wants. > But in a case, I expect a special return value of this function. Ah, ok, that was the important piece of information that you omitted from your previous posts. So what you actually do is call a user provided function and you want to report errors back to the user if the function does not behave as expected by the (plugin) interface, and not only when it raises an exception itself. You might want to read this: http://catb.org/~esr/faqs/smart-questions.html > So, I need to tell him, in which file/line the error occured, > otherwise he dont know where to look. > > Imagine he set 20 files, and all of them have implemented a special > function. So he wouldnt know where to check for the error. Well, you can easily get at the module file path and the function name through introspection of the function, just as you would in Python. That should be enough information to present to the user. I don't see why you would want to add the exact line number of the return statement. The inner workings of the user function you call are up to the user, after all. Again, take a look at Cython, where you can do the introspection in Python code. Stefan From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 05:53:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 09:53:33 GMT Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> <4ba47098$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4ba49b1d$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 07:07:58 +0000, exarkun wrote: >>What am I doing wrong? > > Take a careful look at the stack being reported. Then, think of a > better name than "test" for your file. Doh! *face-palm* I was shadowing the test package with a long forgotten test module. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 06:12:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 10:12:40 GMT Subject: google token References: Message-ID: <4ba49f98$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 09:17:14 +0000, Thufir wrote: > I'd like to acquire a token, as below, but from Java: Perhaps you should be asking a Java discussion group? This group is for discussing Python. -- Steven From dickinsm at gmail.com Sat Mar 20 06:56:51 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Mar 2010 03:56:51 -0700 (PDT) Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> Message-ID: <556adeb4-ac03-4dfe-92a5-814821fd5bfb@z4g2000yqa.googlegroups.com> On Mar 20, 6:23?am, Steven D'Aprano wrote: > I have two reported bugs in the bug tracker waiting on tests: > > http://bugs.python.org/issue8128http://bugs.python.org/issue4037 > > Are there any guidelines for writing tests for the standard library and > language? Not that I can think of, beyond those you've already mentioned. I mostly just copy the style of existing tests (though there are definitely some test_*** files that aren't particularly well written). For quick questions, you might get good answers by asking on the #python-dev freenode IRC channel: a good few of the people interested in testing (esp. Michael Foord, Ezio Melotti) can often be found there. -- Mark From dickinsm at gmail.com Sat Mar 20 07:00:31 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Mar 2010 04:00:31 -0700 (PDT) Subject: Writing tests for the Python bug tracker References: <4ba469d2$0$27838$c3e8da3@news.astraweb.com> <4ba47098$0$27838$c3e8da3@news.astraweb.com> Message-ID: <218770fd-9928-4dfd-9c9c-6fdecbafbaee@k17g2000yqb.googlegroups.com> On Mar 20, 6:52?am, Steven D'Aprano wrote: > I've found this: > > http://docs.python.org/library/test.html > > and I've written a small test: > > $ cat test_unicode_interpolation.py > # For testinghttp://bugs.python.org/issue8128 > > import test.test_support > import unittest > > class K(unicode): > ? ? def __str__(self): return "Surprise!" > > class UnicodeInterpolationTest(unittest.TestCase): > ? ? def test_interpolation(self): > ? ? ? ? self.assertEquals(u'%s' % K('some text'), 'Surprise!') > > def test_main(): > ? ? test.test_support.run_unittest(UnicodeInterpolationTest) > > if __name__ == "__main__": > ? ? test_main() This looks like a fine start to me. I have a feeling that the current fashion is for assertEqual rather than assertEquals, but I might be wrong. :) -- Mark From chambon.pascal at gmail.com Sat Mar 20 07:31:47 2010 From: chambon.pascal at gmail.com (Pascal Chambon) Date: Sat, 20 Mar 2010 12:31:47 +0100 Subject: Precedence of py, pyd, so, egg, and folder modules/packages when importing Message-ID: <4BA4B223.90207@gmail.com> Hello, I've run into a slight issue when turning my package hierarchy into a parallel hierarchy of compiled cython extensions. Fue to the compilation process, pure python and C modules must have the basename, and they're located in the same folders. Is there any way for me to ensure that, if both modules sets are installed by an user, the compiled, faster module will ALWAYS be imported instead of the pure python one ? Or am I forced to remove pure-python sources when cython ones must be used ? More generally, is there any certainty about the precedence of the misc. module types, when several of them are in the same path ? I have found nothing about it online. Thanks for the attention, regards, Pascal From news1234 at free.fr Sat Mar 20 08:16:08 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 13:16:08 +0100 Subject: accessing variable of the __main__ module Message-ID: <4ba4bc88$0$29961$426a74cc@news.free.fr> Hi, I wondered about the best way, that a module's function could determine the existance and value of variables in the __main__ module. What I came up with is: ########### main.py ########## import mod A = 4 if __name__ == "__main__": mod.f() ########### mod.py ########## def f(): try: from __main__ import A except ImportError as e: A = "does not exist" print "__main__.A" ,A Is there anything better / more pythonic? Thanks in advance and bye N From python at bdurham.com Sat Mar 20 08:46:49 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 20 Mar 2010 08:46:49 -0400 Subject: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime In-Reply-To: References: <1268143741.31835.1363885481@webmail.messagingengine.com> Message-ID: <1269089209.14921.1365809185@webmail.messagingengine.com> Aahz, >> We've decided to build a re-usable *general purpose* PY2EXE "runtime" >> that can be shared by a number of scripts vs. distributing a monolithic >> EXE for each of our scripts. > It's not clear what the purpose of this is. You can build several > scripts against the same py2exe backend. Yes you can, but with our technique we only build and distribute our py2exe backend *once*. Our goal was to build a custom Python runtime that we could build and deploy once and then augment with the many scripts we distribute and update. By including the full Python standard library (minus non-Windows and certain deprecated modules) and a few additional 3rd party modules/packages (win32, wmi, jsonpickle, etc) our script distribution has become significantly easier, faster and more robust - especially for scripts that may make dynamic module imports missed by py2exe. Script updates are incredibly fast because our clients only download the scripts themselves (packaged as standalone zip files). Not that disk space is a concern any more, but our client footprint is significantly smaller without every script being a single file exe. I recognize that this technique might not work for everyone, but it has worked out extremely well for us. Malcolm ----- Original message ----- From: "Aahz" To: python-list at python.org Date: 19 Mar 2010 21:39:38 -0700 Subject: Re: (updated) Choosing a collection of common modules/packages for a general purpose reusable PY2EXE runtime In article , wrote: > >We've decided to build a re-usable *general purpose* PY2EXE "runtime" >that can be shared by a number of scripts vs. distributing a monolithic >EXE for each of our scripts. It's not clear what the purpose of this is. You can build several scripts against the same py2exe backend. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer -- http://mail.python.org/mailman/listinfo/python-list From alfps at start.no Sat Mar 20 08:47:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 20 Mar 2010 13:47:41 +0100 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4bc88$0$29961$426a74cc@news.free.fr> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> Message-ID: * News123: > > I wondered about the best way, that a module's function could determine > the existance and value of variables in the __main__ module. > > > What I came up with is: > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": mod.f() > ########### mod.py ########## > def f(): > try: > from __main__ import A > except ImportError as e: > A = "does not exist" > print "__main__.A" ,A > > Is there anything better / more pythonic? I don't know if this is what you're after, because it's design level instead of technical-Python level. But consider the knowledge distribution above. I see it as like a doctor (main program) telling a nurse (mod.f) to please do something for which the nurse would require some ImportantFact, which the good doctor absent-mindedly forgets to tell the nurse. Trying to do as told the nurse discovers that she needs the ImportantFact, and knowing that it might be available in one of the doctor's files she breaks into his office, finds the PC up and running with the doctor logged in, hurray!, and starts looking... I think the doctor should just give the nurse the ImportantFact right away, not be so absent-minded and unavailable for query later. And I think that if the nurse isn't told the ImportantFact and discovers that she needs it to do what she's told, then the proper thing to do is not to break into the doctor's office and go browsing in his files to possibly find what she needs. For example, she might instead raise an exception. Don't know how they do that in hospitals, though. Cheers & hth., - Alf From luismgz at gmail.com Sat Mar 20 08:51:25 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Sat, 20 Mar 2010 05:51:25 -0700 (PDT) Subject: Best Way to extract Numbers from String References: Message-ID: On Mar 20, 12:04?am, Jimbo wrote: > Hello > > I am trying to grab some numbers from a string containing HTML text. > Can you suggest any good functions that I could use to do this? What > would be the easiest way to extract the following numbers from this > string... > > My String has this layout & I have commented what I want to grab: > [CODE] """ > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > I need to grab this number only > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > I need to grab this number only > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I need to > grab this number only > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? """[/CODE] You should use BeautifulSoup or perhaps regular expressions. Or if you are not very smart, lik me, just try a brute force approach: >>> for i in s.split('>'): for e in i.split(): if '.' in e and e[0].isdigit(): print (e) 43.200 0.040 43.150 43.200 43.130 43.290 43.100 >>> From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 09:05:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 13:05:41 GMT Subject: accessing variable of the __main__ module References: <4ba4bc88$0$29961$426a74cc@news.free.fr> Message-ID: <4ba4c824$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 13:16:08 +0100, News123 wrote: > Hi, > > > I wondered about the best way, that a module's function could determine > the existance and value of variables in the __main__ module. > > > What I came up with is: > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": mod.f() > ########### mod.py ########## > def f(): > try: > from __main__ import A > except ImportError as e: > A = "does not exist" > print "__main__.A" ,A > > Is there anything better / more pythonic? First problem: You try to import from "__main__", but the other module is called "main". __main__ is a special name, which Python understands as meaning "this module that you are in now". For example: $ cat test_main.py x = "something special" import __main__ # magic alias for this module print __main__.x $ python test_main.py something special So inside "mod.py", the line "from __main__ import A" tries to import A from mod.py, not from main.py. You need to say "from main import A" instead. But if you do this, it creates a second problem: you have a circular import, which is generally considered a Bad Thing. The problem is that: (1) module main tries to import module mod (2) module mod tries to import module main (3) but main is still waiting for mod to be imported Now, in your case you escape that trap, because the import is inside a function, so it doesn't occur until you call the function. But it is still considered poor practice: it is best to avoid circular imports unless you really, really need them. The question is, why does module mod.py care what is happening in main.py? It is better for mod.py to be self-contained, and not care about main.py at all. If it needs A, let the caller pass A to it: ########### main.py ########## import mod A = 4 if __name__ == "__main__": mod.f(__name__, A) ########### mod.py ########## def f(caller, A): print "%s.A: %s" % (caller, A) -- Steven From news1234 at free.fr Sat Mar 20 09:32:03 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 14:32:03 +0100 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4c824$0$27838$c3e8da3@news.astraweb.com> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> <4ba4c824$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4ba4ce53$0$28677$426a34cc@news.free.fr> Hi Steven, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 13:16:08 +0100, News123 wrote: > >> Hi, >> >> >> I wondered about the best way, that a module's function could determine >> the existance and value of variables in the __main__ module. >> >> >> What I came up with is: >> ########### main.py ########## >> import mod >> A = 4 >> if __name__ == "__main__": mod.f() >> ########### mod.py ########## >> def f(): >> try: >> from __main__ import A >> except ImportError as e: >> A = "does not exist" >> print "__main__.A" ,A >> >> Is there anything better / more pythonic? > > > First problem: > > You try to import from "__main__", but the other module is called "main". > __main__ is a special name, which Python understands as meaning "this > module that you are in now". For example: My choice of names was perhaps not very smart. I could have called main.py also mytoplevel.py > > $ cat test_main.py > x = "something special" > import __main__ # magic alias for this module > print __main__.x > > $ python test_main.py > something special > > So inside "mod.py", the line "from __main__ import A" tries to import A > from mod.py, not from main.py. You need to say "from main import A" > instead. > I think you're wrong, my above code seems to work. __main__ refers not to the current module, but to the urrent 'top-level-module' so from __main__ import A tries to import from the top level module which is in my case main.py. > But if you do this, it creates a second problem: you have a circular > import, which is generally considered a Bad Thing. The problem is that: > > (1) module main tries to import module mod > (2) module mod tries to import module main > (3) but main is still waiting for mod to be imported > > Now, in your case you escape that trap, because the import is inside a > function, so it doesn't occur until you call the function. But it is > still considered poor practice: it is best to avoid circular imports > unless you really, really need them. > > > The question is, why does module mod.py care what is happening in > main.py? It is better for mod.py to be self-contained, and not care about > main.py at all. If it needs A, let the caller pass A to it: The reason is pure lazyness. I would like to 'try' something quickly. I have a module used by many different python programs. In case the __main__ module contains a certain object I'd like to extract information from this object if not not. This is for debug, not for 'production'. I'd prefer to change only one file and not many. > > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": > mod.f(__name__, A) > > ########### mod.py ########## > def f(caller, A): > print "%s.A: %s" % (caller, A) > > > N From news1234 at free.fr Sat Mar 20 09:38:43 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 14:38:43 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port Message-ID: <4ba4cfe3$0$7060$426a74cc@news.free.fr> I'm having a small multiprocessing manager: # ########################## import socket,sys from multiprocessing.managers import BaseManager mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') try: srvr = mngr.get_server() except socket.error as e: print "probably address already in use" sys.exit() print "serving" srvr.serve_forever() Under linux this script can only be run once. The second call will raise an exception, as the previous program is already listening to pot 8089. Under Windows however the program can be started twice. and will print twice "serving". This surprises me Howver only one of them will successfully listen and respond to connections, but I don't get an exception. Is this to be expected? I'd like to be sure, that the manager is only started once and that it can be started anytime it's not up. N From gatoygata2 at gmail.com Sat Mar 20 09:54:53 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sat, 20 Mar 2010 06:54:53 -0700 (PDT) Subject: How User-defined method objects are created? Message-ID: I'm trying to understand the description of method object creation in the python 2.6 language reference (3.2. The standard type hierarchy) with little success. The points knocking me are: "User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object, an unbound user-defined method object, or a class method object. When the attribute is a user-defined method object, a new method object is only created if the class from which it is being retrieved is the same as, or a derived class of, the class stored in the original method object; otherwise, the original method object is used as it is." It is a bit of a tongue-twister for me. What the last sentence means? Please, I beg for a simple example of the different objects (user defined function, user defined method, class method) refered. Are maybe the refered objects exemplified by : #python 3.1 class Klass(): def met(self): print('method') def func(): print('function') @classmethod def kmet(klass): print('classmethod') or it is talking about another thing? What is the difference with python 3 where there is no mention to the unbound user-defined method object (same section in python 3 language reference): "User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object or a class method object." I'm trying to learn, however the task is revealing as an enormous undertaking :-) JA From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 10:04:41 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 14:04:41 GMT Subject: accessing variable of the __main__ module References: <4ba4bc88$0$29961$426a74cc@news.free.fr> <4ba4c824$0$27838$c3e8da3@news.astraweb.com> <4ba4ce53$0$28677$426a34cc@news.free.fr> Message-ID: <4ba4d5f9$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 14:32:03 +0100, News123 wrote: >> You try to import from "__main__", but the other module is called >> "main". __main__ is a special name, which Python understands as meaning >> "this module that you are in now". For example: > > My choice of names was perhaps not very smart. I could have called > main.py also mytoplevel.py [...] > I think you're wrong, my above code seems to work. __main__ refers not > to the current module, but to the urrent 'top-level-module' > so > from __main__ import A tries to import from the top level module which > is in my case main.py. Hmmm... it looks like you are correct and I made a mistake. This isn't something that the documentation is clear about, but here are a set of test files: $ cat A.py import __main__ import B print __main__, B, B.__main__ $ cat B.py import __main__ $ python A.py Here is the documentation: http://docs.python.org/library/__main__.html which is pretty sparse. -- Steven From irmen.NOSPAM at xs4all.nl Sat Mar 20 10:17:50 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sat, 20 Mar 2010 15:17:50 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: <4ba4cfe3$0$7060$426a74cc@news.free.fr> References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> Message-ID: <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> On 20-3-2010 14:38, News123 wrote: > I'm having a small multiprocessing manager: > > # ########################## > import socket,sys > from multiprocessing.managers import BaseManager > > mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') > try: > srvr = mngr.get_server() > except socket.error as e: > print "probably address already in use" > sys.exit() > print "serving" > srvr.serve_forever() > > > Under linux this script can only be run once. > The second call will raise an exception, as the previous program is > already listening to pot 8089. > > > Under Windows however the program can be started twice. > and will print twice "serving". This surprises me My guess is that somewhere in the multiprocessing package the SO_REUSEADDR option is used on the socket. And that option has different semantics on Windows than it has on other operating systems. At least one of them being the possibility of multiple bindings on the same port without getting an error. See http://bugs.python.org/issue2550. Also see the code comments to bind_port in Lib/test/test_support.py, that suggests using SO_EXCLUSIVEADDRUSE instead under Windows, but that is not much use to you unless you monkeypatch the multiprocessing package code. Hope this helps -irmen From davea at ieee.org Sat Mar 20 10:50:17 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 20 Mar 2010 09:50:17 -0500 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4ce53$0$28677$426a34cc@news.free.fr> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> <4ba4c824$0$27838$c3e8da3@news.astraweb.com> <4ba4ce53$0$28677$426a34cc@news.free.fr> Message-ID: <4BA4E0A9.3050804@ieee.org> News123 wrote: > > Steven D'Aprano wrote: > >> >> Now, in your case you escape that trap, because the import is inside a >> function, so it doesn't occur until you call the function. But it is >> still considered poor practice: it is best to avoid circular imports >> unless you really, really need them. >> >> >> The question is, why does module mod.py care what is happening in >> main.py? It is better for mod.py to be self-contained, and not care about >> main.py at all. If it needs A, let the caller pass A to it: >> > > > The reason is pure lazyness. > I would like to 'try' something quickly. > > I have a module used by many different python programs. > > In case the __main__ module contains a certain object I'd like to > extract information from this object if not not. > > This is for debug, not for 'production'. > > I'd prefer to change only one file and not many. > > > First, the practical response: yes, it'll work, and if this is really for debug, it's fine. However, realize that many times "debug things" make it into the wild. Any time recursion of imports occurs, it's a sign of trouble. And doing it right isn't usually much harder than studying the hazards of the recursion. In the particular case you're doing, I think there are at least three better solutions: 1) Pass A as an argument to a function call, for example f(A). 2) Put A into a separate module that both main.py and mod.py import 3) Explicitly add A to mod.py's global space. mod.A = A written in main.py, before calling the function mod.x(). HTH DaveA From news1234 at free.fr Sat Mar 20 10:52:05 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 15:52:05 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> Message-ID: <4ba4e115$0$18400$426a74cc@news.free.fr> Hi Irmen, Irmen de Jong wrote: > On 20-3-2010 14:38, News123 wrote: >> I'm having a small multiprocessing manager: >> >> # ########################## >> import socket,sys >> from multiprocessing.managers import BaseManager >> >> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') >> try: >> srvr = mngr.get_server() >> except socket.error as e: >> print "probably address already in use" >> sys.exit() >> print "serving" >> srvr.serve_forever() >> >> Under Windows however the program can be started twice. >> and will print twice "serving". This surprises me > > > My guess is that somewhere in the multiprocessing package the > SO_REUSEADDR option is used on the socket. And that option has different > semantics on Windows than it has on other operating systems. At least > one of them being the possibility of multiple bindings on the same port > without getting an error. > See http://bugs.python.org/issue2550. > Also see the code comments to bind_port in Lib/test/test_support.py, > that suggests using SO_EXCLUSIVEADDRUSE instead under Windows, but that > is not much use to you unless you monkeypatch the multiprocessing > package code. > Yes this might be. Then I think, that I should report it either as bug / enhancement request. However I am not at all aware of the issue reporting process concerning python. (special site / module developer, PEP . . . ) For the short term: I wonder now how to solve my problem that only one manager is started and the second one should just aborts. Some days ago I started a discussion in the thread "how to start a python script only once". I hoped, that the listening socket of the manager would just take care of the issue. N From duncan.booth at invalid.invalid Sat Mar 20 12:24:37 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 20 Mar 2010 16:24:37 GMT Subject: How User-defined method objects are created? References: Message-ID: Joaquin Abian wrote: > "User-defined method objects may be created when getting an attribute > of a class (perhaps via an instance of that class), if that attribute > is a user-defined function object, an unbound user-defined method > object, or a class method object. When the attribute is a user-defined > method object, a new method object is only created if the class from > which it is being retrieved is the same as, or a derived class of, the > class stored in the original method object; otherwise, the original > method object is used as it is." > > It is a bit of a tongue-twister for me. What the last sentence means? > Please, I beg for a simple example of the different objects (user > defined function, user defined method, class method) refered. >>> class A(object): def foo(self): pass >>> class B(object): def bar(self): pass >>> B.baz = B.bar >>> B.foo = A.foo >>> instance = B() >>> B.foo >>> B.bar >>> B.baz >>> instance.foo >>> instance.bar > >>> instance.baz > >>> B.__dict__['bar'] >>> B.__dict__['baz'] >>> B.__dict__['foo'] So, we have a function 'bar' stored in B's dict. When you access the function as the attribute B.bar Python 2.x will create an unbound method object. When you access the function through instance.bar Python creates a bound method. Note that every time you access instance.bar it creates another new method object: >>> instance.bar is instance.bar False B.baz is an unbound method stored directly in B's dict. When you access instance.baz you get a new bound method object (it's at the same memory location as the previous one but that's only because the lifetimes don't overlap). Somewhat suprisingly the same also happens if you access B.baz: it creates a new unbound method from the existing unbound method: >>> B.bar is B.__dict__['bar'] False B.foo is an unbound method stored directly in B's dict, but it is a method of an A and B doesn't subclass A, so when you try to access B.foo you just get the stored unbound method it isn't converted into a new object. From tjreedy at udel.edu Sat Mar 20 12:33:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Mar 2010 12:33:01 -0400 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: <4ba4e115$0$18400$426a74cc@news.free.fr> References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> <4ba4e115$0$18400$426a74cc@news.free.fr> Message-ID: On 3/20/2010 10:52 AM, News123 wrote: > Hi Irmen, > > > Irmen de Jong wrote: >> On 20-3-2010 14:38, News123 wrote: >>> I'm having a small multiprocessing manager: >>> >>> # ########################## >>> import socket,sys >>> from multiprocessing.managers import BaseManager >>> >>> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') >>> try: >>> srvr = mngr.get_server() >>> except socket.error as e: >>> print "probably address already in use" >>> sys.exit() >>> print "serving" >>> srvr.serve_forever() >>> >>> Under Windows however the program can be started twice. >>> and will print twice "serving". This surprises me >> >> >> My guess is that somewhere in the multiprocessing package the >> SO_REUSEADDR option is used on the socket. And that option has different >> semantics on Windows than it has on other operating systems. At least >> one of them being the possibility of multiple bindings on the same port >> without getting an error. >> See http://bugs.python.org/issue2550. >> Also see the code comments to bind_port in Lib/test/test_support.py, >> that suggests using SO_EXCLUSIVEADDRUSE instead under Windows, but that >> is not much use to you unless you monkeypatch the multiprocessing >> package code. >> > > Yes this might be. > > > Then I think, that I should report it either as bug / enhancement I agree. I would guess that the difference is not intentional. > request. However I am not at all aware of the issue reporting process > concerning python. (special site / module developer, PEP . . . ) bugs.python.org Terry Jan Reedy From tjreedy at udel.edu Sat Mar 20 12:39:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 20 Mar 2010 12:39:44 -0400 Subject: How User-defined method objects are created? In-Reply-To: References: Message-ID: On 3/20/2010 9:54 AM, Joaquin Abian wrote: > I'm trying to understand the description of method object creation in > the python 2.6 language reference (3.2. The standard type hierarchy) > with little success. The points knocking me are: > > "User-defined method objects may be created when getting an attribute > of a class (perhaps via an instance of that class), if that attribute > is a user-defined function object, an unbound user-defined method > object, or a class method object. When the attribute is a user-defined > method object, a new method object is only created if the class from > which it is being retrieved is the same as, or a derived class of, the > class stored in the original method object; otherwise, the original > method object is used as it is." > > It is a bit of a tongue-twister for me. What the last sentence means? > Please, I beg for a simple example of the different objects (user > defined function, user defined method, class method) refered. > Are maybe the refered objects exemplified by : > > #python 3.1 > class Klass(): > > def met(self): > print('method') > > def func(): > print('function') > > @classmethod > def kmet(klass): > print('classmethod') > > or it is talking about another thing? > What is the difference with python 3 where there is no mention to the > unbound user-defined method object (same section in python 3 language > reference): Python3 does not have unbound method objects. Klass.met above is just a function.l > "User-defined method objects may be created when getting an attribute > of a class (perhaps via an instance of that class), if that attribute > is a user-defined function object or a class method object." > > I'm trying to learn, however the task is revealing as an enormous > undertaking :-) One can successfully use the language in the normal way without understanding every detail of every oddball corner case. Recent 2.x is complicated by duplication (two user object systems) and back-compatibility constraints. Most new users do not need to bother with obsolete complications. Terry Jan Reedy From waugustynski at gmail.com Sat Mar 20 13:00:47 2010 From: waugustynski at gmail.com (waugust) Date: Sat, 20 Mar 2010 10:00:47 -0700 (PDT) Subject: Ubuntu install problems Message-ID: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever I apt-get install anything It ends with a series of python (dependency?) errors. Anybody got any idea? > aptget libgcj-common Reading package lists... Done Building dependency tree Reading state information... Done libgcj-common is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded. 26 not fully installed or removed. After this operation, 0B of additional disk space will be used. Setting up libgcj-common (1:4.4.1-1ubuntu2) ... Compiling /usr/lib/python3.1/dist-packages/ aotcompile.py ... File "/usr/lib/python3.1/dist-packages/aotcompile.py", line 115 raise Error, "nothing to do" ^ SyntaxError: invalid syntax Compiling /usr/lib/python3.1/dist-packages/classfile.py ... File "/usr/lib/python3.1/dist-packages/classfile.py", line 30 raise TypeError, type(arg) ^ SyntaxError: invalid syntax pycentral: pycentral pkginstall: error byte-compiling files (2) pycentral pkginstall: error byte-compiling files (2) dpkg: error processing libgcj-common (--configure): subprocess installed post-installation script returned error exit status 1 dpkg: dependency problems prevent configuration of libgcj10: libgcj10 depends on libgcj-common (>= 1:4.1.1-21); however: Package libgcj-common is not configured yet. dpkg: error processing libgcj10 (-- configure): dependency problems - leaving unconfigured dpkg: dependency problems prevent configuration of libgcj-bc: It snowballs down from there for: No apport report written because MaxReports is reached already Errors were encountered while processing: libgcj-common libgcj10 libgcj-bc ant-gcj ant-optional-gcj python-transaction python-zconfig python-zdaemon python-zope.exceptions python-zope.testing python-zope.proxy python-zodb python-zope.component gaphor gcj-4.4-jre-lib python-speechd python-pyatspi gnome-orca python-configglue python-telepathy python-ubuntuone-storageprotocol python-ubuntuone-client telepathy-butterfly ubuntuone-client ubuntuone-client-gnome python-zope.hookable E: Sub-process /usr/bin/dpkg returned an error code (1) From news1234 at free.fr Sat Mar 20 13:11:25 2010 From: news1234 at free.fr (News123) Date: Sat, 20 Mar 2010 18:11:25 +0100 Subject: why is there now execption for windows? trying to listen twice to the same port In-Reply-To: References: <4ba4cfe3$0$7060$426a74cc@news.free.fr> <4ba4d910$0$22939$e4fe514c@news.xs4all.nl> <4ba4e115$0$18400$426a74cc@news.free.fr> Message-ID: <4ba501bd$0$7193$426a74cc@news.free.fr> Terry Reedy wrote: > On 3/20/2010 10:52 AM, News123 wrote: >> Hi Irmen, >> >> >> Irmen de Jong wrote: >>> On 20-3-2010 14:38, News123 wrote: >>>> I'm having a small multiprocessing manager: >>>> >>>> # ########################## >>>> import socket,sys >>>> from multiprocessing.managers import BaseManager >>>> >>>> mngr = BaseManager(address=('127.0.0.1',8089),authkey='verysecret') >>>> try: >>>> srvr = mngr.get_server() >>>> except socket.error as e: >>>> print "probably address already in use" >>>> sys.exit() >>>> print "serving" >>>> srvr.serve_forever() >>>> >>>> Under Windows however the program can be started twice. >>>> and will print twice "serving". This surprises me >>> . . . >> >> Then I think, that I should report it either as bug / enhancement > > I agree. I would guess that the difference is not intentional. > >> request. However I am not at all aware of the issue reporting process >> concerning python. (special site / module developer, PEP . . . ) > > bugs.python.org > Thanks, I created an account and submitted the issue N From benjamin.kaplan at case.edu Sat Mar 20 13:15:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 20 Mar 2010 13:15:16 -0400 Subject: Ubuntu install problems In-Reply-To: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> Message-ID: On Sat, Mar 20, 2010 at 1:00 PM, waugust wrote: > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. > Whenever I apt-get install anything It ends with a series of python > (dependency?) errors. Anybody got any idea? > > aptget libgcj-common > Reading package lists... > Done > Building dependency > tree > Reading state information... > Done > libgcj-common is already the newest > version. > 0 upgraded, 0 newly installed, 0 to remove and 6 not > upgraded. > 26 not fully installed or > removed. > After this operation, 0B of additional disk space will be > used. > Setting up libgcj-common > (1:4.4.1-1ubuntu2) ... > Compiling /usr/lib/python3.1/dist-packages/ > aotcompile.py ... > File "/usr/lib/python3.1/dist-packages/aotcompile.py", line > 115 > raise Error, "nothing to > do" > > ^ > SyntaxError: invalid > syntax > > Compiling /usr/lib/python3.1/dist-packages/classfile.py ... > File "/usr/lib/python3.1/dist-packages/classfile.py", line 30 > raise TypeError, type(arg) > ^ > SyntaxError: invalid syntax > > Did you set /usr/bin/python to Python 3.1? It needs to stay as the system default Python (in this case 2.6) or else lots of stuff breaks. You're getting those syntax errors because of the difference between Python 2.x (which the scripts were written for) and Python 3.x (which is being run) -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sat Mar 20 13:24:45 2010 From: aahz at pythoncraft.com (Aahz) Date: 20 Mar 2010 10:24:45 -0700 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: In article <4B9E0C1F.9020003 at canterbury.ac.nz>, Gregory Ewing wrote: > >It turned out to be a very standard CRC algorithm, complicated >by the presence of a few extra bytes of data being checked that >didn't appear explicitly in the file anywhere. > >In the process I developed some very general techniques for >solving this kind of problem, which I've written about here >if anyone's interested: > >http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html Excellent essay! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 13:25:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Mar 2010 17:25:03 GMT Subject: Ubuntu install problems References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> Message-ID: <4ba504ef$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 10:00:47 -0700, waugust wrote: > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever > I apt-get install anything It ends with a series of python (dependency?) > errors. Anybody got any idea? It looks like apt-get is supposed to be using 2.6 or 2.5, but somehow is running 3.1 instead. If you run "python -V", what does it say? -- Steven From python at mrabarnett.plus.com Sat Mar 20 13:26:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Mar 2010 17:26:58 +0000 Subject: Ubuntu install problems In-Reply-To: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> Message-ID: <4BA50562.1010600@mrabarnett.plus.com> waugust wrote: > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. > Whenever I apt-get install anything It ends with a series of python > (dependency?) errors. Anybody got any idea? >> aptget libgcj-common > Reading package lists... > Done > Building dependency > tree > Reading state information... > Done > libgcj-common is already the newest > version. > 0 upgraded, 0 newly installed, 0 to remove and 6 not > upgraded. > 26 not fully installed or > removed. > After this operation, 0B of additional disk space will be > used. > Setting up libgcj-common > (1:4.4.1-1ubuntu2) ... > Compiling /usr/lib/python3.1/dist-packages/ > aotcompile.py ... > File "/usr/lib/python3.1/dist-packages/aotcompile.py", line > 115 > raise Error, "nothing to > do" > > ^ > SyntaxError: invalid > syntax > > Compiling /usr/lib/python3.1/dist-packages/classfile.py ... > File "/usr/lib/python3.1/dist-packages/classfile.py", line 30 > raise TypeError, type(arg) > ^ > SyntaxError: invalid syntax > [snip] In Python 2 an exception can be raised with the old-style: raise Error, "nothing to do" or the new-style: raise Error("nothing to do") In Python 3 the old style is not supported (it was abandoned as part of the general clean-up). Another related change is that the old-style: except Error, e: in Python 2 has been completely replaced by the new-style: except Error as e: in Python 3 (also available in Python 2.6). From waugustynski at gmail.com Sat Mar 20 13:40:08 2010 From: waugustynski at gmail.com (waugust) Date: Sat, 20 Mar 2010 10:40:08 -0700 (PDT) Subject: Ubuntu install problems References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> <4ba504ef$0$27838$c3e8da3@news.astraweb.com> Message-ID: <658a97c1-02d0-4158-a3b0-b82f1e66254a@q26g2000prh.googlegroups.com> On Mar 20, 10:25?am, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 10:00:47 -0700, waugust wrote: > > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever > > I apt-get install anything It ends with a series of python (dependency?) > > errors. ?Anybody got any idea? > > It looks like apt-get is supposed to be using 2.6 or 2.5, but somehow is > running 3.1 instead. > > If you run "python -V", what does it say? > > -- > Steven >python -V Python 2.6.4 odd..yeah, I uninstalled all of the listed packages and started to install again and got the same problem... From saimapk81 at gmail.com Sat Mar 20 14:03:00 2010 From: saimapk81 at gmail.com (saima81) Date: Sat, 20 Mar 2010 11:03:00 -0700 (PDT) Subject: "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ Message-ID: <9df66e21-4011-447c-9816-fc7f79416c4b@a37g2000prd.googlegroups.com> "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ "JOBS IN FINLAND" "JOBS FINLAND" "FINLAND JOBS" "ACCOUNTS JOBS IN FINLAND" "FINANCE JOBS IN FINLAND" "AGRI JPBS IN FINLAND" "MEDICAL JOBS IN FINLAND" ON JOBS http://jobs-in-finland.blogspot.com/ V From agoretoy at gmail.com Sat Mar 20 14:55:26 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 20 Mar 2010 12:55:26 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: what do i do to remove this crap? how do i moderate it? why not gpg sign messages on python-list that way you know your authorized to post and spammers will have one more vector to deal with, there in stopping the not so leet -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From Brian.Mingus at Colorado.EDU Sat Mar 20 15:27:10 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sat, 20 Mar 2010 13:27:10 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Moderating this stuff requires moderating all messages. It would take a team of volunteers. On Sat, Mar 20, 2010 at 12:55 PM, alex goretoy wrote: > what do i do to remove this crap? how do i moderate it? > > why not gpg sign messages on python-list that way you know your authorized > to post and spammers will have one more vector to deal with, there in > stopping the not so leet > -Alex Goretoy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Sat Mar 20 15:37:48 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sat, 20 Mar 2010 15:37:48 -0400 Subject: "EURO GIRLS" "MISS EUROPE" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: <20100320153748.95f9cb49.darcy@druid.net> On Sat, 20 Mar 2010 12:55:26 -0600 alex goretoy wrote: > what do i do to remove this crap? how do i moderate it? First, please remove spam URLs when following up. You left them in the subject. Maybe it's time to stop gatewaying the newsgroup to the mailing list. As a test I have moved all Python posts from gmail.com with a Newsgroup header into a separate folder and so far 99% of the spam lands there. Once you do that you can also enforce that posts can only come from subscribed addresses. I find that that cuts out almost 100% of the spam. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From agoretoy at gmail.com Sat Mar 20 15:54:18 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 20 Mar 2010 13:54:18 -0600 Subject: "EURO GIRLS" "MISS EUROPE" In-Reply-To: <20100320153748.95f9cb49.darcy@druid.net> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <20100320153748.95f9cb49.darcy@druid.net> Message-ID: On Sat, Mar 20, 2010 at 1:37 PM, D'Arcy J.M. Cain wrote: > aybe it's time to stop gatewaying the newsgroup to the mailing list. > As a test I have moved all Python posts from gmail.com with a > Newsgroup header into > ok thx, I'm learning as I go along -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From mmanns at gmx.net Sat Mar 20 17:30:09 2010 From: mmanns at gmx.net (Martin Manns) Date: Sat, 20 Mar 2010 22:30:09 +0100 Subject: [ANN] Pyspread 0.1 released Message-ID: Pyspread 0.1 released ===================== After a long and eventful Alpha period, pyspread has finally reached Beta stage. I thank all contributors and testers who have helped getting pyspread to this point. About: ------ Pyspread is a cross-platform Python spreadsheet application. It is based on and written in the programming language Python. Instead of spreadsheet formulas, Python expressions are entered into the spreadsheet cells. Each expression returns a Python object that can be accessed from other cells. These objects can represent anything including lists or matrices. Stability and compatibility --------------------------- Pyspread runs pretty stable in CPython. Please note that old save files are not compatible. Load them in the old version and copy the code to a new version of pyspread via the clipboard. Being in Beta means increased code stability. Save files are now going to be downwards compatible. However, major beta releases (e. g. 0.1 to 0.2) may still break compatibility. Such a change may occur only after being announced in the previous major beta release. New features ------------ * New macro editor dialog. * Macros can now contain any Python code. * Macros load and save files are now plain text files. * Macros are now saved within the pys-file. * Macros files are now signed and included in the trusted file concept. Bug fixes --------- * Cells can now be correctly accessed with negative index (BUG 2965144) Homepage -------- http://pyspread.sourceforge.net Enjoy Martin From gatoygata2 at gmail.com Sat Mar 20 17:32:40 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sat, 20 Mar 2010 14:32:40 -0700 (PDT) Subject: How User-defined method objects are created? References: Message-ID: On Mar 20, 5:39?pm, Terry Reedy wrote: > On 3/20/2010 9:54 AM, Joaquin Abian wrote: > > > > > I'm trying to understand the description of method object creation in > > the python 2.6 language reference (3.2. The standard type hierarchy) > > with little success. The points knocking me are: > > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object, an unbound user-defined method > > object, or a class method object. When the attribute is a user-defined > > method object, a new method object is only created if the class from > > which it is being retrieved is the same as, or a derived class of, the > > class stored in the original method object; otherwise, the original > > method object is used as it is." > > > It is a bit of a tongue-twister for me. What the last sentence means? > > Please, I beg for a simple example of the different objects (user > > defined function, user defined method, class method) refered. > > Are maybe the refered objects exemplified by : > > > #python 3.1 > > class Klass(): > > > ? ?def met(self): > > ? ? ? ? ? ?print('method') > > > ? ? ? ? def func(): > > ? ? ? ? ? ?print('function') > > > ? ? ? ? @classmethod > > ? ?def kmet(klass): > > ? ? ? ? ? ?print('classmethod') > > > or it is talking about another thing? > > What is the difference with python 3 where there is no mention to the > > unbound user-defined method object (same section in python 3 language > > reference): > > Python3 does not have unbound method objects. Klass.met above is just a > function.l > > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object or a class method object." > > > I'm trying to learn, however the task is revealing as an enormous > > undertaking :-) > > One can successfully use the language in the normal way without > understanding every detail of every oddball corner case. Recent 2.x is > complicated by duplication (two user object systems) and > back-compatibility constraints. Most new users do not need to bother > with obsolete complications. > > Terry Jan Reedy Terry, Right, I was just reading about this difference in 2 vs 3 in Lutz's book. Well, in fact in my case I'm not a newcomer to python (neither a professional). I have been programming for more than 4 years in python mainly medium size scientific data management applications. Currently I can write at a moderate speed and Im familiar with properties, decorators, etc. That's why it is so frustrating went I get lost in the language reference manual in a matter I wrongly though was a simple stuff. Thanks for your helpful comments. JA From gatoygata2 at gmail.com Sat Mar 20 17:41:36 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sat, 20 Mar 2010 14:41:36 -0700 (PDT) Subject: How User-defined method objects are created? References: Message-ID: <6e791682-f44c-43f1-948f-44e59e78c9f9@z4g2000yqa.googlegroups.com> On Mar 20, 5:24?pm, Duncan Booth wrote: > Joaquin Abian wrote: > > "User-defined method objects may be created when getting an attribute > > of a class (perhaps via an instance of that class), if that attribute > > is a user-defined function object, an unbound user-defined method > > object, or a class method object. When the attribute is a user-defined > > method object, a new method object is only created if the class from > > which it is being retrieved is the same as, or a derived class of, the > > class stored in the original method object; otherwise, the original > > method object is used as it is." > > > It is a bit of a tongue-twister for me. What the last sentence means? > > Please, I beg for a simple example of the different objects (user > > defined function, user defined method, class method) refered. > >>> class A(object): > > ? ? ? ? def foo(self): pass > > >>> class B(object): > > ? ? ? ? def bar(self): pass > > >>> B.baz = B.bar > >>> B.foo = A.foo > >>> instance = B() > >>> B.foo > > >>> B.bar > > >>> B.baz > > >>> instance.foo > > >>> instance.bar > > >>>> instance.baz > > >>>> B.__dict__['bar'] > > >>> B.__dict__['baz'] > > >>> B.__dict__['foo'] > > > > So, we have a function 'bar' stored in B's dict. When you access the > function as the attribute B.bar Python 2.x will create an unbound method > object. When you access the function through instance.bar Python creates a > bound method. Note that every time you access instance.bar it creates > another new method object: > > >>> instance.bar is instance.bar > > False > > B.baz is an unbound method stored directly in B's dict. When you access > instance.baz you get a new bound method object (it's at the same memory > location as the previous one but that's only because the lifetimes don't > overlap). Somewhat suprisingly the same also happens if you access B.baz: > it creates a new unbound method from the existing unbound method: > > >>> B.bar is B.__dict__['bar'] > > False > > B.foo is an unbound method stored directly in B's dict, but it is a method > of an A and B doesn't subclass A, so when you try to access B.foo you just > get the stored unbound method it isn't converted into a new object. Thanks Duncan, I think I got the idea. Your explanation together with the comment from Terry about the absence of unbound method objects in python 3 cleared some dust from my neuron(s) Thanks! JA From no.email at please.post Sat Mar 20 18:15:54 2010 From: no.email at please.post (kj) Date: Sat, 20 Mar 2010 22:15:54 +0000 (UTC) Subject: How to automate accessor definition? Message-ID: I need to create a class solely for the purpose of encapsulating a large number of disparate data items. At the moment I have no plans for any methods for this class other than the bazillion accessors required to access these various instance variables. (In case it matters, this class is meant to be a private helper class internal to a module, and it won't be subclassed.) What is "best practice" for implementing this sort of class *succinctly* (i.e. without a lot of repetitive accessor code)? Also, one more question concerning syntax. Suppose that i represents an instance of this class. Is it possible to define the class to support this syntax val = i.field i.field += 6 ...rather than this one val = i.get_field() i.set_field(i.get_field() + 6) ? TIA! ~K From nilly16 at yahoo.com Sat Mar 20 18:39:30 2010 From: nilly16 at yahoo.com (Jimbo) Date: Sat, 20 Mar 2010 15:39:30 -0700 (PDT) Subject: Best Way to extract Numbers from String References: Message-ID: <61a6901b-40ce-4b7e-aa90-19696fcb9303@h35g2000pri.googlegroups.com> On Mar 20, 11:51?pm, Luis M. Gonz?lez wrote: > On Mar 20, 12:04?am, Jimbo wrote: > > > > > > > Hello > > > I am trying to grab some numbers from a string containing HTML text. > > Can you suggest any good functions that I could use to do this? What > > would be the easiest way to extract the following numbers from this > > string... > > > My String has this layout & I have commented what I want to grab: > > [CODE] """ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > > I need to grab this number only > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # > > I need to grab this number only > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # I need to > > grab this number only > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? ? ? """[/CODE] > > You should use BeautifulSoup or perhaps regular expressions. > Or if you are not very smart, lik me, just try a brute force approach: > > >>> for i in s.split('>'): > > ? ? ? ? for e in i.split(): > ? ? ? ? ? ? ? ? if '.' in e and e[0].isdigit(): > ? ? ? ? ? ? ? ? ? ? ? ? print (e) > > 43.200 > 0.040 > 43.150 > 43.200 > 43.130 > 43.290 > 43.100 > > > > - Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Thanks very much, I'm going to look at regular expressions but that for your code, it shows me how I can do it iwth standard python :) From clp2 at rebertia.com Sat Mar 20 18:54:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Mar 2010 15:54:20 -0700 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: <50697b2c1003201554v3294b545sd2c53bd203111e5@mail.gmail.com> On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: > I need to create a class solely for the purpose of encapsulating > a large number of disparate data items. ?At the moment I have no > plans for any methods for this class other than the bazillion > accessors required to access these various instance variables. > (In case it matters, this class is meant to be a private helper > class internal to a module, and it won't be subclassed.) If it's just a completely dumb struct-like class, you might consider something like: http://docs.python.org/library/collections.html#collections.namedtuple > What is "best practice" for implementing this sort of class > *succinctly* (i.e. without a lot of repetitive accessor code)? Is there any good reason you can't just use straight instance variables? Python ain't Java; vanilla, boilerplate accessor methods should almost always be avoided. > Also, one more question concerning syntax. ?Suppose that i represents > an instance of this class. ?Is it possible to define the class to > support this syntax > > ?val = i.field > ?i.field += 6 > > ...rather than this one > > ?val = i.get_field() > ?i.set_field(i.get_field() + 6) > > ? Yes, using the magic of the property() function: http://docs.python.org/library/functions.html#property Cheers, Chris -- http://blog.rebertia.com From waugustynski at gmail.com Sat Mar 20 19:32:51 2010 From: waugustynski at gmail.com (waugust) Date: Sat, 20 Mar 2010 16:32:51 -0700 (PDT) Subject: Ubuntu install problems References: <99adedf9-e02d-4c71-983b-8901b9fa6791@w39g2000prd.googlegroups.com> <4ba504ef$0$27838$c3e8da3@news.astraweb.com> <658a97c1-02d0-4158-a3b0-b82f1e66254a@q26g2000prh.googlegroups.com> Message-ID: On Mar 20, 10:40?am, waugust wrote: > On Mar 20, 10:25?am, Steven D'Aprano > cybersource.com.au> wrote: > > On Sat, 20 Mar 2010 10:00:47 -0700, waugust wrote: > > > I have 2.5 (for GAE), 2.6 (Ubuntu default), and 3.1 installed. Whenever > > > I apt-get install anything It ends with a series of python (dependency?) > > > errors. ?Anybody got any idea? > > > It looks like apt-get is supposed to be using 2.6 or 2.5, but somehow is > > running 3.1 instead. > > > If you run "python -V", what does it say? > > > -- > > Steven > >python -V > > Python 2.6.4 > > odd..yeah, I uninstalled all of the listed packages and started to > install again and got the same problem... So I put this up to the Ubuntu (lunchpad, apt) community support board: https://answers.launchpad.net/ubuntu/+source/apt/+question/105025 Possible bug with the python-central package (Ubuntu x86 9.10)?? dunno. From fordhaivat at gmail.com Sat Mar 20 20:51:44 2010 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 20 Mar 2010 20:51:44 -0400 Subject: Best Way to extract Numbers from String In-Reply-To: References: Message-ID: Its an extremely bad idea to use regex for HTML. You want to change one tiny little thing and you have to write the regex all over again. if its a throwaway script, then go ahead. 2010/3/20 Luis M. Gonz?lez > On Mar 20, 12:04 am, Jimbo wrote: > > Hello > > > > I am trying to grab some numbers from a string containing HTML text. > > Can you suggest any good functions that I could use to do this? What > > would be the easiest way to extract the following numbers from this > > string... > > > > My String has this layout & I have commented what I want to grab: > > [CODE] """ > > > > > > > > # > > I need to grab this number only > > > > # > > I need to grab this number only > > > # I need to > > grab this number only > > > > > > > > > > > > > > > > """[/CODE] > > > You should use BeautifulSoup or perhaps regular expressions. > Or if you are not very smart, lik me, just try a brute force approach: > > >>> for i in s.split('>'): > for e in i.split(): > if '.' in e and e[0].isdigit(): > print (e) > > > 43.200 > 0.040 > 43.150 > 43.200 > 43.130 > 43.290 > 43.100 > >>> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fordhaivat at gmail.com Sat Mar 20 20:53:45 2010 From: fordhaivat at gmail.com (Someone Something) Date: Sat, 20 Mar 2010 20:53:45 -0400 Subject: How to automate accessor definition? In-Reply-To: <50697b2c1003201554v3294b545sd2c53bd203111e5@mail.gmail.com> References: <50697b2c1003201554v3294b545sd2c53bd203111e5@mail.gmail.com> Message-ID: Just initialize everything in the constructor, unless you have *really *good reason not to do that. On Sat, Mar 20, 2010 at 6:54 PM, Chris Rebert wrote: > On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: > > I need to create a class solely for the purpose of encapsulating > > a large number of disparate data items. At the moment I have no > > plans for any methods for this class other than the bazillion > > accessors required to access these various instance variables. > > (In case it matters, this class is meant to be a private helper > > class internal to a module, and it won't be subclassed.) > > If it's just a completely dumb struct-like class, you might consider > something like: > http://docs.python.org/library/collections.html#collections.namedtuple > > > What is "best practice" for implementing this sort of class > > *succinctly* (i.e. without a lot of repetitive accessor code)? > > Is there any good reason you can't just use straight instance > variables? Python ain't Java; vanilla, boilerplate accessor methods > should almost always be avoided. > > > Also, one more question concerning syntax. Suppose that i represents > > an instance of this class. Is it possible to define the class to > > support this syntax > > > > val = i.field > > i.field += 6 > > > > ...rather than this one > > > > val = i.get_field() > > i.set_field(i.get_field() + 6) > > > > ? > > Yes, using the magic of the property() function: > http://docs.python.org/library/functions.html#property > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Mar 20 22:31:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Mar 2010 02:31:32 GMT Subject: How to automate accessor definition? References: Message-ID: <4ba58503$0$27838$c3e8da3@news.astraweb.com> On Sat, 20 Mar 2010 22:15:54 +0000, kj wrote: > I need to create a class solely for the purpose of encapsulating a large > number of disparate data items. There's a built-in for that. It's called "dict". Syntax for item access is a tiny bit different, but still very common: data['foo'] instead of data.foo If you need to customize item access, you need to modify __getitem__, __setitem__ and __delitem__ instead of __getattr__ etc., but otherwise they are nearly identical. Ignoring a few complications due to slots and inheritance, attribute access is built on top of item access, so you won't notice any performance hit (and you might see a tiny performance benefit). > At the moment I have no plans for any > methods for this class other than the bazillion accessors required to > access these various instance variables. Huh? If you have instance variables, why don't you refer to them by name? x = MyClass() # create an instance y = MyClass() # another variable bound to an instance z = MyClass() # etc. print x, y, z > (In case it matters, this class > is meant to be a private helper class internal to a module, and it won't > be subclassed.) > > What is "best practice" for implementing this sort of class *succinctly* > (i.e. without a lot of repetitive accessor code)? Leave the repetitive accessor code out. Python isn't Java. http://dirtsimple.org/2004/12/python-is-not-java.html > Also, one more question concerning syntax. Suppose that i represents an > instance of this class. Is it possible to define the class to support > this syntax > > val = i.field > i.field += 6 Classes already support that. >>> class C(object): ... pass ... >>> i = C() >>> i.field = 42 >>> val = i.field >>> i.field += 6 >>> print (val, i.field) 42 48 > ...rather than this one > > val = i.get_field() > i.set_field(i.get_field() + 6) > > ? Good grief! No wonder Java coders are so unproductive :( -- Steven From gregory.j.baker at gmail.com Sat Mar 20 23:37:53 2010 From: gregory.j.baker at gmail.com (Novocastrian_Nomad) Date: Sat, 20 Mar 2010 20:37:53 -0700 (PDT) Subject: Best Way to extract Numbers from String References: <61a6901b-40ce-4b7e-aa90-19696fcb9303@h35g2000pri.googlegroups.com> Message-ID: Regular expression are very powerful, and I use them a lot in my paying job (unfortunately not with Python). You are however, basically using a second programing language, which can be difficult to master. Does this give you the desired result? import re matches = re.findall('', code) for match in matches: print match resulting in this output: 43.150 43.200 43.130 43.290 43.100 7,450,447 From renws1990 at gmail.com Sun Mar 21 03:23:26 2010 From: renws1990 at gmail.com (Ren Wenshan) Date: Sun, 21 Mar 2010 00:23:26 -0700 (PDT) Subject: How to keep effects of image filters going for some seconds? Message-ID: Hello, every pythoner. Firstly, I want to mention that English is my second language, so maybe there are some sentences which makes you confused, sorry. I have been learning Panda3D, an open source 3D engine, these days. Now, I'm trying to write a small game for fun and practice. However, I've ran into a problem. I want to make some speical effects and there is my code: def ventose(self): global potato_HP if potato_HP[0] == 1 and potato_HP[1] == 0: if random() > .30: self.filters.setCartoonInk(separation = 0.8) self.robotVincent.resetHead.start() self.decreaseVincentHP() Wait(3) self.fliters.delCartoonInk() However, it doesn't work, the CartoonInk effect will never been shown in my game and I don't want my game to wait three seconds, what I need is to keep the effect for a period of time while the game run as well. Besides that, I also want to show a counting back like "3", then "2", then "1", finally "Go". As a beginner, I don't know how to do them properly. Please give me some directions, thank you. ----------------------------- Vincent Ren From jah.alarm at gmail.com Sun Mar 21 06:11:05 2010 From: jah.alarm at gmail.com (Jah_Alarm) Date: Sun, 21 Mar 2010 03:11:05 -0700 (PDT) Subject: nonuniform sampling with replacement Message-ID: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> I've got a vector length n of integers (some of them are repeating), and I got a selection probability vector of the same length. How will I sample with replacement k (<=n) values with the probabilty vector. In Matlab this function is randsample. I couldn't find anything to this extent in Scipy or Numpy. thanks for the help Alex From donn.ingle at gmail.com Sun Mar 21 07:08:07 2010 From: donn.ingle at gmail.com (donn) Date: Sun, 21 Mar 2010 13:08:07 +0200 Subject: How to keep effects of image filters going for some seconds? In-Reply-To: References: Message-ID: <4BA5FE17.20909@gmail.com> On 21/03/2010 09:23, Ren Wenshan wrote: > I have been learning Panda3D, an open source 3D engine, Ask on the Panda3D forums, you will get good help there. \d From alfps at start.no Sun Mar 21 08:03:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 21 Mar 2010 13:03:00 +0100 Subject: nonuniform sampling with replacement In-Reply-To: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: * Jah_Alarm: > I've got a vector length n of integers (some of them are repeating), > and I got a selection probability vector of the same length. How will > I sample with replacement k (<=n) values with the probabilty vector. > In Matlab this function is randsample. I couldn't find anything to > this extent in Scipy or Numpy. #Py3 import operator # itemgetter import random from collections import defaultdict def normalized_to_sum( s, v ): current_s = sum( v ) c = s/current_s return [c*x for x in v] class ValueSampler: def __init__( self, values, probabilities ): assert len( values ) == len( probabilities ) get2nd = operator.itemgetter( 1 ) v_p = sorted( zip( values, probabilities ), key = get2nd, reverse = True ) v_ap = []; sum = 0; for (v, p) in v_p: v_ap.append( (v, p + sum) ); sum += p self._data = v_ap def __call__( self, p ): return self.choice( p ) def choice( self, p ): data = self._data; i_v = 0; i_p = 1; assert 0 <= p <= 1 assert len( data ) > 0, "Sampler: Sampling from empty value set" low = 0; high = len( data ) - 1; if p > data[high][i_p]: return data[high][i_p] # Float values workaround. while low != high: mid = (low + high)//2 if p > data[mid][i_p]: low = mid + 1 else: high = mid return data[low][i_v] def main(): v = [3, 1, 4, 1, 5, 9, 2, 6, 5, 4]; p = normalized_to_sum( 1, [2, 7, 1, 8, 2, 8, 1, 8, 2, 8] ) sampler = ValueSampler( v, p ) probabilities = defaultdict( lambda: 0.0 ) for (i, value) in enumerate( v ): probabilities[value] += p[i] print( probabilities ) print() frequencies = defaultdict( lambda: 0.0 ) n = 100000 for i in range( n ): value = sampler( random.random() ) frequencies[value] += 1/n print( frequencies ) main() Cheers & hth., - Alf Disclaimer: I just cooked it up and just cooked up binary searches usually have bugs. They usually need to be exercised and fixed. But I think you get the idea. Note also that division differs in Py3 and Py2. This is coded for Py3. From __peter__ at web.de Sun Mar 21 08:27:44 2010 From: __peter__ at web.de (Peter Otten) Date: Sun, 21 Mar 2010 13:27:44 +0100 Subject: nonuniform sampling with replacement References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: Jah_Alarm wrote: > I've got a vector length n of integers (some of them are repeating), > and I got a selection probability vector of the same length. How will > I sample with replacement k (<=n) values with the probabilty vector. > In Matlab this function is randsample. I couldn't find anything to > this extent in Scipy or Numpy. If all else fails you can do it yourself: import random import bisect def iter_sample_with_replacement(values, weights): _random = random.random _bisect = bisect.bisect acc_weights = [] sigma = 0 for w in weights: sigma += w acc_weights.append(sigma) while 1: yield values[_bisect(acc_weights, _random()*sigma)] def sample_with_replacement(k, values, weights): return list(islice(iter_sample_with_replacement(values, weights), k)) if __name__ == "__main__": from itertools import islice N = 10**6 values = range(4) weights = [2, 3, 4, 1] histo = [0] * len(values) for v in islice(iter_sample_with_replacement(values, weights), N): histo[v] += 1 print histo print sample_with_replacement(30, values, weights) Peter From alfps at start.no Sun Mar 21 08:28:15 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 21 Mar 2010 13:28:15 +0100 Subject: nonuniform sampling with replacement In-Reply-To: References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: * Alf P. Steinbach: > * Jah_Alarm: >> I've got a vector length n of integers (some of them are repeating), >> and I got a selection probability vector of the same length. How will >> I sample with replacement k (<=n) values with the probabilty vector. >> In Matlab this function is randsample. I couldn't find anything to >> this extent in Scipy or Numpy. > > [snip] > > > > Disclaimer: I just cooked it up and just cooked up binary searches > usually have bugs. They usually need to be exercised and fixed. But I > think you get the idea. Note also that division differs in Py3 and Py2. > This is coded for Py3. Sorry, I realized this just now: the name "p" in the choice() method is utterly misleading, which you can see from the call; it's a random number not a probability. I guess my fingers just repeated what they typed earlier. Cheeers, - Alf (repeat typist) From slais-www at ucl.ac.uk Sun Mar 21 10:29:58 2010 From: slais-www at ucl.ac.uk (djc) Date: Sun, 21 Mar 2010 14:29:58 +0000 Subject: should writing Unicode files be so slow In-Reply-To: References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: Antoine Pitrou wrote: > Le Fri, 19 Mar 2010 17:18:17 +0000, djc a ?crit : >> changing >> with open(filename, 'rU') as tabfile: to >> with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as >> tabfile: >> >> and >> with open(outfile, 'wt') as out_part: to >> with codecs.open(outfile, 'w', 'utf-8') as out_part: >> >> causes a program that runs in >> 43 seconds to take 4 minutes to process the same data. > > codecs.open() (and the object it returns) is slow as it is written in > pure Python. > > Accelerated reading and writing of unicode files is available in Python > 2.7 and 3.1, using the new `io` module. Thank you, for a clear and to the point explanation. I shall concentrate on finding an optimal time to upgrade from Python 2.6. -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From ra21vi at gmail.com Sun Mar 21 10:43:27 2010 From: ra21vi at gmail.com (Ravi Kumar) Date: Sun, 21 Mar 2010 14:43:27 +0000 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: <9a63e8921003210743t30fac328oed4a5b336ebcda19@mail.gmail.com> On Sat, Mar 20, 2010 at 7:27 PM, Brian J Mingus wrote: > Moderating this stuff requires moderating all messages. It would take a > team of volunteers. > You are right... Form the team of volunteers. More people in it, better it would be - since no one would have to be dedicated. -- -=Ravi=- -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sun Mar 21 11:02:45 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Mar 2010 08:02:45 -0700 (PDT) Subject: Clearing memory (namespace) before running code Message-ID: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> Hi, Is there a way to erase/delete/clear memory before a piece of code is run? Otherwise, the objects of the previous run are re-usable, and may bring confusion to the tester. Thank you From steve at holdenweb.com Sun Mar 21 11:11:18 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 11:11:18 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> Message-ID: Brian J Mingus wrote: > [... duplicating the spam and thereby lending it further Google juice ...] > -- > http://mail.python.org/mailman/listinfo/python-list > > Guys, I know it is a lot of work to moderate a large mailing list. But > still, with so many of us surely we can pull it off? > It's actually not as easy as you might think. If someone can propose a *practical* scheme for moderation of this high-volume list the PSF might consider such a proposal, but there would need to be considerable evidence that the scheme would work without delaying traffic. Since the spam that's getting through actually represents a tiny fraction of one percent of the spam that the list is bombarded with I personally feel that there would be very little positive return for a relatively large investment of effort, and that any volunteer time would be better spent making other contributions to the Python community. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Mar 21 11:13:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 11:13:44 -0400 Subject: Clearing memory (namespace) before running code In-Reply-To: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> References: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> Message-ID: vsoler wrote: > Hi, > > Is there a way to erase/delete/clear memory before a piece of code is > run? > > Otherwise, the objects of the previous run are re-usable, and may > bring confusion to the tester. > > Thank you You mean clear a *namespace*? That might be possible if you have access to the specific module whose namespace you want to clear. I presume this is related to earlier questions about reloading modules? This is yet another reason why you might want to consider running each module in its own process each time the user submits it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From joncle at googlemail.com Sun Mar 21 11:18:01 2010 From: joncle at googlemail.com (Jon Clements) Date: Sun, 21 Mar 2010 08:18:01 -0700 (PDT) Subject: Clearing memory (namespace) before running code References: <0756022b-3893-4558-ab06-79bb467f1da4@b30g2000yqd.googlegroups.com> Message-ID: <42678333-5b0f-43bb-9488-7e127d078083@l25g2000yqd.googlegroups.com> On 21 Mar, 15:02, vsoler wrote: > Hi, > > Is there a way to erase/delete/clear memory before a piece of code is > run? > > Otherwise, the objects of the previous run are re-usable, and may > bring confusion to the tester. > > Thank you I'm guessing you're using some sort of IDE? For instance, in IDLE if the [Python Shell] window is not closed, the session is kept. However, there is a menu option 'Shell' which has 'Restart Shell'. If you don't see a 'Shell' menu option, then make sure IDLE isn't being started with the -n option. However I would have thought the 'tester' would be running from a terminal/command line/double click jobby, so that a single Python session is executed and just runs -- rather than want to use it interactively afterwards. hth Jon. From deets at nospam.web.de Sun Mar 21 12:08:58 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: 21 Mar 2010 16:08:58 GMT Subject: How to automate accessor definition? References: Message-ID: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> kj wrote: > > > > > > > I need to create a class solely for the purpose of encapsulating > a large number of disparate data items. At the moment I have no > plans for any methods for this class other than the bazillion > accessors required to access these various instance variables. > (In case it matters, this class is meant to be a private helper > class internal to a module, and it won't be subclassed.) > > What is "best practice" for implementing this sort of class > *succinctly* (i.e. without a lot of repetitive accessor code)? > > Also, one more question concerning syntax. Suppose that i represents > an instance of this class. Is it possible to define the class to > support this syntax > > val = i.field > i.field += 6 > > ...rather than this one > > val = i.get_field() > i.set_field(i.get_field() + 6) > > ? You don't. Python is not Java. So just use instance attributes, and if you need bhavior when accessing an attribute, introduce a property. Diez From zookog at gmail.com Sun Mar 21 12:55:41 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Sun, 21 Mar 2010 10:55:41 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus wrote: > Moderating this stuff requires moderating all messages. Not quite. GNU Mailman comes with nice features to ease this task. You can configure it so that everyone who is currently subscribed can post freely, but new subscribers get a "moderated" bit set on them. The first time this new subscriber attempts to post to the list, a human moderator has to inspect their message and decide whether to approve it or deny it. If they human moderator approves it, they can also on the same web form remove the "moderated" bit from that poster. Therefore, the volunteer work required would be inspecting the *first* post from each *new* subscriber to see if that post is spam. Regards, Zooko From no.email at please.post Sun Mar 21 12:57:40 2010 From: no.email at please.post (kj) Date: Sun, 21 Mar 2010 16:57:40 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: In <639908184290880449.447600deets-nospam.web.de at news.hansenet.de> Diez B. Roggisch writes: >You don't. Python is not Java. So just use instance attributes, and if >you need bhavior when accessing an attribute, introduce a property. Just accessing attributes looks a bit dangerous to me, due to bugs like typing i.typo = 'foo' when what you meant is i.type = 'foo' I tried fixing this by mucking with __setattr__, but I didn't hit on a satisfactory solution (basically, I couldn't find a good, self-maintaining, way to specify the attributes that were OK to set from those that weren't). Is there anything built-in? Regarding properties, is there a built-in way to memoize them? For example, suppose that the value of a property is obtained by parsing the contents of a file (specified in another instance attribute). It would make no sense to do this parsing more than once. Is there a standard idiom for memoizing the value once it is determined for the first time? Thanks! ~K From no.email at please.post Sun Mar 21 13:02:30 2010 From: no.email at please.post (kj) Date: Sun, 21 Mar 2010 17:02:30 +0000 (UTC) Subject: How to automate accessor definition? References: Message-ID: In Chris Rebert writes: >On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: >> I need to create a class solely for the purpose of encapsulating >> a large number of disparate data items. =C2=A0At the moment I have no >> plans for any methods for this class other than the bazillion >> accessors required to access these various instance variables. >> (In case it matters, this class is meant to be a private helper >> class internal to a module, and it won't be subclassed.) >If it's just a completely dumb struct-like class, you might consider >something like: >http://docs.python.org/library/collections.html#collections.namedtuple Very cool. Thanks! The class I have in mind is *almost* that dumb, but performance is a consideration in this case, which may rule out namedtuple. But I'm glad to learn about it; there are many places where I can put them to good use. ~K From benjamin at python.org Sun Mar 21 13:12:08 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sun, 21 Mar 2010 12:12:08 -0500 Subject: [RELEASED] Python 3.1.2 Message-ID: <1afaf6161003211012r30bc0e77ub5dfe9f248668525@mail.gmail.com> On behalf of the Python development team, I'm joyful to announce the second bugfix release of the Python 3.1 series, Python 3.1.2. This bug fix release fixes numerous issues found in 3.1.1, and is considered a production release. The Python 3.1 version series focuses on the stabilization and optimization of the features and changes that Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. Other features include an ordered dictionary implementation, a condensed syntax for nested with statements, and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in the Python distribution. To download Python 3.1.2 visit: http://www.python.org/download/releases/3.1.2/ A list of changes in 3.1.2 can be found here: http://svn.python.org/projects/python/tags/r312/Misc/NEWS The 3.1 documentation can be found at: http://docs.python.org/3.1 Bugs can always be reported to: http://bugs.python.org Enjoy! -- Benjamin Peterson Release Manager benjamin at python.org (on behalf of the entire python-dev team and 3.1.2's contributors) From steve at holdenweb.com Sun Mar 21 13:12:23 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 13:12:23 -0400 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: kj wrote: > In Chris Rebert writes: > >> On Sat, Mar 20, 2010 at 3:15 PM, kj wrote: >>> I need to create a class solely for the purpose of encapsulating >>> a large number of disparate data items. =C2=A0At the moment I have no >>> plans for any methods for this class other than the bazillion >>> accessors required to access these various instance variables. >>> (In case it matters, this class is meant to be a private helper >>> class internal to a module, and it won't be subclassed.) > >> If it's just a completely dumb struct-like class, you might consider >> something like: >> http://docs.python.org/library/collections.html#collections.namedtuple > > Very cool. Thanks! The class I have in mind is *almost* that > dumb, but performance is a consideration in this case, which may > rule out namedtuple. But I'm glad to learn about it; there are > many places where I can put them to good use. > You may well find that namedtuple is faster than what you put together yourself, as the collections module is implemented in C. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at please.post Sun Mar 21 13:25:08 2010 From: no.email at please.post (kj) Date: Sun, 21 Mar 2010 17:25:08 +0000 (UTC) Subject: How to automate accessor definition? References: <4ba58503$0$27838$c3e8da3@news.astraweb.com> Message-ID: In <4ba58503$0$27838$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >On Sat, 20 Mar 2010 22:15:54 +0000, kj wrote: >> I need to create a class solely for the purpose of encapsulating a large >> number of disparate data items. >There's a built-in for that. It's called "dict". Syntax for item access >is a tiny bit different, but still very common: >data['foo'] >instead of >data.foo I find the latter more readable than the former. All those extra elements (the brackets and the quotes, vs the single dot) add Perl-like visual noise to the code, IMHO. And dicts are vulnerable to this sort of bug: data['typo'] = type(foobar) Also, AFAIK, initialization of a dictionary is never as simple as i = myclass(*fields) But in a sense you're right: aside from these objections, *functionality-wise* what I'm looking for is not very different from a dictionary, or a C struct. >> At the moment I have no plans for any >> methods for this class other than the bazillion accessors required to >> access these various instance variables. >Huh? If you have instance variables, why don't you refer to them by name? I'm sorry, I used the wrong terminology. I see now that the correct term is "(instance) attribute", not "instance variable". >Leave the repetitive accessor code out. Python isn't Java. >http://dirtsimple.org/2004/12/python-is-not-java.html Thanks for the link! The bit about "Guido's time machine" is pretty funny. ~K From benjamin.kaplan at case.edu Sun Mar 21 13:38:42 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 21 Mar 2010 13:38:42 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: On Sun, Mar 21, 2010 at 12:55 PM, Zooko O'Whielacronx wrote: > On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus > wrote: >> Moderating this stuff requires moderating all messages. > > Not quite. GNU Mailman comes with nice features to ease this task. You > can configure it so that everyone who is currently subscribed can post > freely, but new subscribers get a "moderated" bit set on them. The > first time this new subscriber attempts to post to the list, a human > moderator has to inspect their message and decide whether to approve > it or deny it. If they human moderator approves it, they can also on > the same web form remove the "moderated" bit from that poster. > > Therefore, the volunteer work required would be inspecting the *first* > post from each *new* subscriber to see if that post is spam. > > Regards, > > Zooko The spam isn't coming through the mailing list. It's coming through the Google Groups mirror of the Usenet newsgroup. I don't think Mailman can do anything about that. From pmaupin at gmail.com Sun Mar 21 13:42:34 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 21 Mar 2010 10:42:34 -0700 (PDT) Subject: RSON 0.06 released Message-ID: <0b40fdf6-3fdd-4962-9994-c7c0936c588a@x12g2000yqx.googlegroups.com> I am pleased to announce the release of RSON 0.06. The goal of the RSON project is to create a file format that is easy to edit, diff, and version control, that is a superset of JSON and smaller than YAML. I consider this release to be feature complete on the file format, and I believe the pure Python 2.x decoder (parser) to be production worthy (for users who do not need the speed of a C based decoder). The project is at: http://rson.googlecode.com/ The manual with syntax examples is at: http://rson.googlecode.com/files/rson_0_06_manual.pdf Discussions at: http://groups.google.com/group/rson-discuss From ale.marino78 at gmail.com Sun Mar 21 14:12:18 2010 From: ale.marino78 at gmail.com (Alessandro Marino) Date: Sun, 21 Mar 2010 19:12:18 +0100 Subject: Regexp problem when parsing a string Message-ID: <9b9cf8321003211112q2333fb74h29e9a805053d1a13@mail.gmail.com> I'm a beginner and I was trying to write a program to parse recursively all file names in a directory specified as parameter. The problem is that I get a "None" printed to stdout when a file is positively matched. While when the file name doesn't match the regexp the output seems ok. C:\>c:\python.exe g:\a.py sample ====> foo - bar.txt , first part is: foo None skipping: foo.txt Instead I expect an output like this one: C:\>c:\python.exe g:\a.py sample ====> foo - bar.txt , first part is: foo None skipping: foo.txt Could anyone help me to figure out why "None" appears in the putput? Thanks and regards, Ale -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: a.py Type: application/octet-stream Size: 448 bytes Desc: not available URL: From andrej.mitrovich at gmail.com Sun Mar 21 14:14:16 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sun, 21 Mar 2010 11:14:16 -0700 (PDT) Subject: Python Documentation website layout changed? References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> <4BA120A9.3060001@holdenweb.com> Message-ID: <3116d122-3a7e-47d6-9bc9-574825ac7391@q23g2000yqd.googlegroups.com> On Mar 20, 12:32?am, Steve Holden wrote: > Steve Holden wrote: > > Andrej Mitrovic wrote: > >> On Mar 17, 6:41 pm, Andrej Mitrovic > >> wrote: > >>> Hi, > > >>> What happened to the sidebar on the left of the documentation website? > >>> It seems to be gone: > > >>>http://docs.python.org/py3k/index.html > > >>> I found it quite useful since I can quickly swap between Python2/3 > >>> documentation, and between other parts of the documentation as well. > >> Edit: It looks like only the Python 3 pages are affected, the Python 2 > >> pages are the same as before: > > >>http://docs.python.org/index.html > > >> Might be a bug? > > > I'll ask. Georg - is this known behavior or a temporary problem? > > It's a bug. Georg is on it. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > See PyCon Talks from Atlanta 2010 ?http://pycon.blip.tv/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ Looks like it's fixed now. Thanks Georg & Steve! From steve at REMOVE-THIS-cybersource.com.au Sun Mar 21 14:18:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Mar 2010 18:18:57 GMT Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: <4ba66311$0$27838$c3e8da3@news.astraweb.com> On Sun, 21 Mar 2010 16:57:40 +0000, kj wrote: > Just accessing attributes looks a bit dangerous to me, due to bugs like > typing > > i.typo = 'foo' > > when what you meant is > > i.type = 'foo' That's the price you pay for using a dynamic language like Python with no declarations. But honestly, the price isn't very high, particularly if you use an editor or IDE with auto-completion. I can't think of the last time I had an error due to the above sort of mistake. Besides, is that error really so much more likely than this? i.type = 'fpo' when you meant 'foo'? The compiler can't protect you from that error, not in any language. > I tried fixing this by mucking with __setattr__, but I didn't hit on a > satisfactory solution (basically, I couldn't find a good, > self-maintaining, way to specify the attributes that were OK to set from > those that weren't). Is there anything built-in? No. You could abuse __slots__, but it really is abuse: __slots__ are a memory optimization, not a typo-checker. In Python 3.x, you can (untested) replace the class __dict__ with a custom type that has more smarts. At the cost of performance. This doesn't work in 2.x though, as the class __dict__ is always a regular dictionary. Something like this might work, at some minor cost of performance: # Untested def __setattr__(self, name, value): if hasattr(self, name): super(MyClassName, self).__setattr__(name, value) else: raise TypeError('cannot create new attributes') Then, in your __init__ method, to initialise an attribute use: self.__dict__['attr'] = value to bypass the setattr. Or you can use something like PyChecker or PyLint to analyse your code and warm about likely typos. But really, it's not a common form of error. YMMV. > Regarding properties, is there a built-in way to memoize them? For > example, suppose that the value of a property is obtained by parsing the > contents of a file (specified in another instance attribute). It would > make no sense to do this parsing more than once. Is there a standard > idiom for memoizing the value once it is determined for the first time? Google for "Python memoization cookbook". This will get you started: http://code.activestate.com/recipes/52201/ Then just apply the memoize decorator to the property getter. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 21 14:26:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Mar 2010 18:26:59 GMT Subject: Regexp problem when parsing a string References: Message-ID: <4ba664f3$0$27838$c3e8da3@news.astraweb.com> On Sun, 21 Mar 2010 19:12:18 +0100, Alessandro Marino wrote: > Could anyone help me to figure out why "None" appears in the putput? I get: "Attachment not shown: MIME type application/octet-stream; filename a.py" Posting attachments to Usenet is tricky. Many newsgroups filter out anything they think isn't text, or even any attachment at all. Some news clients do the same thing. If you have too much code to include directly in your post, then you should put it up on a website somewhere and just include the link. Without looking at your code, I'd guess that using regular expressions is the wrong approach. Perhaps you should look at the glob module, and possibly os.walk. -- Steven From python at mrabarnett.plus.com Sun Mar 21 14:31:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Mar 2010 18:31:31 +0000 Subject: Regexp problem when parsing a string In-Reply-To: <9b9cf8321003211112q2333fb74h29e9a805053d1a13@mail.gmail.com> References: <9b9cf8321003211112q2333fb74h29e9a805053d1a13@mail.gmail.com> Message-ID: <4BA66603.1010303@mrabarnett.plus.com> Alessandro Marino wrote: > I'm a beginner and I was trying to write a program to > parse recursively all file names in a directory specified as parameter. > The problem is that I get a "None" printed to stdout when a file is > positively matched. While when the file name doesn't match the regexp > the output seems ok. > > C:\>c:\python.exe g:\a.py sample > ====> foo - bar.txt , first part is: foo > None > skipping: foo.txt > > Instead I expect an output like this one: > > C:\>c:\python.exe g:\a.py sample > ====> foo - bar.txt , first part is: foo > None > skipping: foo.txt > > Could anyone help me to figure out why "None" appears in the putput? > > Thanks and regards, > Ale > It's caused by: print saveData(file, m) The function saveData() returns None, which is then printed. From lists at cheimes.de Sun Mar 21 14:37:03 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 21 Mar 2010 19:37:03 +0100 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: Steve Holden wrote: > You may well find that namedtuple is faster than what you put together > yourself, as the collections module is implemented in C. But namedtuple isn't, Steve. Namedtuple is a class generator that creates fast and efficient classes. From pmaupin at gmail.com Sun Mar 21 14:40:42 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 21 Mar 2010 11:40:42 -0700 (PDT) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: <7938941f-8d42-4b46-8b68-8f28c95df0c7@e1g2000yqh.googlegroups.com> On Mar 21, 11:57?am, kj wrote: > > Just accessing attributes looks a bit dangerous to me, due to bugs > like typing > > ? i.typo = 'foo' > > when what you meant is > > ? i.type = 'foo' > > I tried fixing this by mucking with __setattr__, but I didn't hit > on a satisfactory solution (basically, I couldn't find a good, > self-maintaining, way to specify the attributes that were OK to > set from those that weren't). ?Is there anything built-in? > If you *really* want static typing and validation for attributes in Python, you might check out enthought traits: http://code.enthought.com/projects/traits/ Regards, Pat From steve at holdenweb.com Sun Mar 21 14:47:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 14:47:32 -0400 Subject: How to automate accessor definition? In-Reply-To: References: Message-ID: Christian Heimes wrote: > Steve Holden wrote: >> You may well find that namedtuple is faster than what you put together >> yourself, as the collections module is implemented in C. > > But namedtuple isn't, Steve. Namedtuple is a class generator that > creates fast and efficient classes. > Ah, right, thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From aonlazio at gmail.com Sun Mar 21 14:52:36 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Sun, 21 Mar 2010 14:52:36 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: Relax guys, let have fun once in a while On Sat, Mar 20, 2010 at 12:18 AM, Naeem wrote: > "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY > FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY > RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" > "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" > "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD""EURO GIRLS" "MISS > EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on > www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY > GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" > "SEXY BOLLYWOOD""EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" > "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com > "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK > GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" > -- > http://mail.python.org/mailman/listinfo/python-list > -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Mar 21 15:01:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 15:01:53 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: AON LAZIO wrote: > Relax guys, let have fun once in a while > [further repetition of the spamming URLs] facepalm. > > > -- > Passion is my style > Style? You call that style? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From Brian.Mingus at Colorado.EDU Sun Mar 21 15:11:29 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Sun, 21 Mar 2010 13:11:29 -0600 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: <9839a05c1003211211u2fd34964i33f8328b61bab3e8@mail.gmail.com> On Sun, Mar 21, 2010 at 10:55 AM, Zooko O'Whielacronx wrote: > On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus > wrote: > > Moderating this stuff requires moderating all messages. > > Not quite. GNU Mailman comes with nice features to ease this task. You > can configure it so that everyone who is currently subscribed can post > freely, but new subscribers get a "moderated" bit set on them. The > first time this new subscriber attempts to post to the list, a human > moderator has to inspect their message and decide whether to approve > it or deny it. If they human moderator approves it, they can also on > the same web form remove the "moderated" bit from that poster. > > Therefore, the volunteer work required would be inspecting the *first* > post from each *new* subscriber to see if that post is spam. > > Regards, > > Zooko > I like this approach, but I like even better simply disabling the usenet gateway. I can't find the message now but someone mentioned it would almost completely get rid of the spam problem. I disagree with Steve Holden that since it's only ~1% we should just ignore it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sun Mar 21 15:57:50 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Mar 2010 12:57:50 -0700 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> Message-ID: <50697b2c1003211257i3b674a20ib3d335d465e9639@mail.gmail.com> On Sun, Mar 21, 2010 at 12:01 PM, Steve Holden wrote: > AON LAZIO wrote: >> Relax guys, let have fun once in a while >> > [further repetition of the spamming URLs] > > facepalm. Fortunately, Google has now shut down the spam blog anyway. Cheers, Chris From omrihsan at gmail.com Sun Mar 21 16:44:49 2010 From: omrihsan at gmail.com (Omer Ihsan) Date: Sun, 21 Mar 2010 13:44:49 -0700 (PDT) Subject: device identification Message-ID: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> i have installed pyusb now and run the sample usbenum.py....i have 3 usb ports on my PC but the results show 6 outputs to dev.filename..they are numbers like 001 or 005 etc.... and they changed when i plugged in devices...(i am no good with the usb standards)....i just want to identify each device/port... what parameter in the example would help me.... From darcy at druid.net Sun Mar 21 17:00:06 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 21 Mar 2010 17:00:06 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: <50697b2c1003211257i3b674a20ib3d335d465e9639@mail.gmail.com> References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <50697b2c1003211257i3b674a20ib3d335d465e9639@mail.gmail.com> Message-ID: <20100321170006.03056484.darcy@druid.net> On Sun, 21 Mar 2010 12:57:50 -0700 Chris Rebert wrote: > Fortunately, Google has now shut down the spam blog anyway. Until next time. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From aahz at pythoncraft.com Sun Mar 21 17:34:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 21 Mar 2010 14:34:28 -0700 Subject: Method / Functions - What are the differences? References: <4B8EF717.3070701@optimum.net> < Message-ID: In article , John Posner wrote: > >Bruno (and anyone else interested) -- > >As I promised/threatened, here's the *start* of a write-up on >properties, aimed at non-advanced Python programmers: > > http://www.jjposner.net/media/python-properties-0310.pdf I'm interested, but not interested enough to download a PDF and fire up a PDF reader. Are you really using features that require PDF instead of just writing a web page? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From tjreedy at udel.edu Sun Mar 21 18:00:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 18:00:59 -0400 Subject: How to keep effects of image filters going for some seconds? In-Reply-To: References: Message-ID: On 3/21/2010 3:23 AM, Ren Wenshan wrote: > Hello, every pythoner. > > Firstly, I want to mention that English is my second language, so > maybe there are some sentences which makes you confused, sorry. > > I have been learning Panda3D, an open source 3D engine, these days. > Now, I'm trying to write a small game for fun and practice. However, > I've ran into a problem. > > I want to make some speical effects and there is my code: > > def ventose(self): > > global potato_HP > > if potato_HP[0] == 1 and potato_HP[1] == 0: > if random()> .30: > self.filters.setCartoonInk(separation = 0.8) > self.robotVincent.resetHead.start() > self.decreaseVincentHP() > Wait(3) > self.fliters.delCartoonInk() > > However, it doesn't work, the CartoonInk effect will never been shown > in my game and I don't want my game to wait three seconds, what I need > is to keep the effect for a period of time while the game run as well. The generic answer is to turn CartoonInk on and set a timed event for now+ 3 secs to turn it off. You will have to understand how to interact with the Panda event loop. For a more specific answer, follow Donn's advice -- Panda forum. I know there was one when I looked at Panda a year ago. > Besides that, I also want to show a counting back like "3", then "2", > then "1", finally "Go". Ok, instead to events set 1 sec in future. Terry Jan Reedy From tjreedy at udel.edu Sun Mar 21 18:06:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 18:06:05 -0400 Subject: "EURO GIRLS" "MISS EUROPE" "MISS FRENCH" "FRENCH" "PRETTY GIRLS" "SEXY FRENCH GIRLS" on www.sexyandpretty-girls.blogspot.com "SEXY RUSSIAN GIRLS" "SEXY GREEK GIRLS" "SEXY DUTCH GIRLS" "SEXY UK GIRLS" "SEXY HOLLYWOOD GIRLS" "SEXY BOLLYWOOD" In-Reply-To: References: <6abd158d-aba6-4ea1-9d9d-015472cc36f6@t9g2000prh.googlegroups.com> <9839a05c1003192141u360ff77bx8bd0e063c345055e@mail.gmail.com> <9839a05c1003201227o5112a1f1i9de3a77ba7c613ab@mail.gmail.com> Message-ID: On 3/21/2010 12:55 PM, Zooko O'Whielacronx wrote: > On Sat, Mar 20, 2010 at 1:27 PM, Brian J Mingus > wrote: >> Moderating this stuff requires moderating all messages. > > Not quite. GNU Mailman comes with nice features to ease this task. You > can configure it so that everyone who is currently subscribed can post > freely, but new subscribers get a "moderated" bit set on them. The > first time this new subscriber attempts to post to the list, a human > moderator has to inspect their message and decide whether to approve > it or deny it. If they human moderator approves it, they can also on > the same web form remove the "moderated" bit from that poster. > > Therefore, the volunteer work required would be inspecting the *first* > post from each *new* subscriber to see if that post is spam. The first time I post to *any* mailing list from gmane, gmane holds the message until I respond to an email. So python-list could pass new posts from gmane while at least auto-querying anything from google. From tjreedy at udel.edu Sun Mar 21 18:10:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 18:10:44 -0400 Subject: [RELEASED] Python 3.1.2 In-Reply-To: <1afaf6161003211012r30bc0e77ub5dfe9f248668525@mail.gmail.com> References: <1afaf6161003211012r30bc0e77ub5dfe9f248668525@mail.gmail.com> Message-ID: On 3/21/2010 1:12 PM, Benjamin Peterson wrote: > On behalf of the Python development team, I'm joyful to announce the second > bugfix release of the Python 3.1 series, Python 3.1.2. Thanks for the work. > This bug fix release fixes numerous issues found in 3.1.1, and is considered a > production release. > > The Python 3.1 version series focuses on the stabilization and optimization of > the features and changes that Python 3.0 introduced. For example, the new I/O > system has been rewritten in C for speed. File system APIs that use unicode > strings now handle paths with undecodable bytes in them. Other features include > an ordered dictionary implementation, a condensed syntax for nested with > statements, and support for ttk Tile in Tkinter. For a more extensive list of > changes in 3.1, see http://doc.python.org/3.1/whatsnew/3.1.html or Misc/NEWS in > the Python distribution. > > To download Python 3.1.2 visit: > > http://www.python.org/download/releases/3.1.2/ > > A list of changes in 3.1.2 can be found here: > > http://svn.python.org/projects/python/tags/r312/Misc/NEWS There seem to be about a hundred fixes. > The 3.1 documentation can be found at: > > http://docs.python.org/3.1 > > Bugs can always be reported to: > > http://bugs.python.org From steve at holdenweb.com Sun Mar 21 18:44:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 21 Mar 2010 18:44:11 -0400 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4B8EF717.3070701@optimum.net> < Message-ID: Aahz wrote: > In article , > John Posner wrote: >> Bruno (and anyone else interested) -- >> >> As I promised/threatened, here's the *start* of a write-up on >> properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested, but not interested enough to download a PDF and fire up > a PDF reader. Are you really using features that require PDF instead of > just writing a web page? For us standard browser users it's a single click, of course. Are you really forced to use an environment that can't start a PDF reader by clicking on a link? I appreciate that some people are disabled in ways that rule out reading a PDF, but since John has gone to some personal trouble to write this document he's surely entitled to choose his medium ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From janssen at parc.xerox.com Sun Mar 21 18:50:13 2010 From: janssen at parc.xerox.com (Bill Janssen) Date: Sun, 21 Mar 2010 15:50:13 PDT Subject: using Python distutils bdist_msi to create installer for large complicated package Message-ID: <61250.1269211813@parc.com> Martin, I've been re-thinking the UpLib Windows installer technology, and it occurred to me to wonder why I can't just use the nice bdist_msi module in Python to build my packages. I took a look, and it seems almost doable. Presumably you wrote it? UpLib is a big package, with lots of Python and Java and C programs, and for Windows I package it with lots of other programs like those from xpdf. All of this is installed in C:\Program Files\UpLib\VERSION\, in bin, lib, share, and so forth subdirectories. If I autogenerated a setup.py file which described everything as "data_files", it should be simple to package everything up in a Cab, and bdist_msi apparently also provides the ability to add pre- and post-install scripts. Everything I need, really. There are a couple of Python-specific options in the code: the "Product Name" is prefixed with the python version, and in the GUI, the default location is the location of a Python distro. If the package had a "--non-python" option which would defeat these, and perhaps also set "no-target-optimize" and "no-target-compile" to True, it would be a simple but pretty general-purpose packager module. I'll subclass it and play around a bit. Bill From ben+python at benfinney.id.au Sun Mar 21 18:50:58 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 22 Mar 2010 09:50:58 +1100 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: <87bpehthkd.fsf@benfinney.id.au> djc writes: > I shall concentrate on finding an optimal time to upgrade from Python > 2.6. Note that Python 2.7, though nearly ready, is not yet released . -- \ ?? Nature ? is seen to do all things Herself and through | `\ herself of own accord, rid of all gods.? ?Titus Lucretius | _o__) Carus, c. 40 BCE | Ben Finney From martin at v.loewis.de Sun Mar 21 19:00:30 2010 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 22 Mar 2010 00:00:30 +0100 Subject: using Python distutils bdist_msi to create installer for large complicated package In-Reply-To: <61250.1269211813@parc.com> References: <61250.1269211813@parc.com> Message-ID: <4BA6A50E.9060108@v.loewis.de> > I've been re-thinking the UpLib Windows installer technology, and it > occurred to me to wonder why I can't just use the nice bdist_msi module > in Python to build my packages. I took a look, and it seems almost > doable. Presumably you wrote it? Correct. > UpLib is a big package, with lots of Python and Java and C programs, and > for Windows I package it with lots of other programs like those from > xpdf. All of this is installed in C:\Program Files\UpLib\VERSION\, in > bin, lib, share, and so forth subdirectories. If I autogenerated a > setup.py file which described everything as "data_files", it should be > simple to package everything up in a Cab, and bdist_msi apparently also > provides the ability to add pre- and post-install scripts. Everything > I need, really. > > There are a couple of Python-specific options in the code: the "Product > Name" is prefixed with the python version, and in the GUI, the default > location is the location of a Python distro. If the package had a > "--non-python" option which would defeat these, and perhaps also set > "no-target-optimize" and "no-target-compile" to True, it would be a > simple but pretty general-purpose packager module. I'd rather recommend to base this off msilib directly, instead of trying to subvert bdist_msi to do what you want. There is actually quite a lot python-specifics in bdist_msi. If you find this too tedious to use, please propose *base classes* that could become part of msilib, rather than trying to create *subclasses* of the bdist_msi classes. Regards, Martin From john at castleamber.com Sun Mar 21 19:10:01 2010 From: john at castleamber.com (John Bokma) Date: Sun, 21 Mar 2010 17:10:01 -0600 Subject: Method / Functions - What are the differences? References: <4B8EF717.3070701@optimum.net> Message-ID: <87pr2xjmpi.fsf@castleamber.com> aahz at pythoncraft.com (Aahz) writes: > In article , > John Posner wrote: >> >>Bruno (and anyone else interested) -- >> >>As I promised/threatened, here's the *start* of a write-up on >>properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested, but not interested enough to download a PDF and fire up > a PDF reader. Are you really using features that require PDF instead of > just writing a web page? http://docs.google.com/viewer?url=http%3A%2F%2Fwww.jjposner.net%2Fmedia%2Fpython-properties-0310.pdf Hth, -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From hjgdjfdkjhdfkhjkl at gmail.com Sun Mar 21 19:28:08 2010 From: hjgdjfdkjhdfkhjkl at gmail.com (jhghjg jhgjh) Date: Sun, 21 Mar 2010 16:28:08 -0700 (PDT) Subject: sell:nike shoes$32,ed hardy(items),jean$30,handbag$35 Message-ID: http://www.etootoo.com free shipping competitive price

wholesale nikeshoes
nike wholesale
china wholesale jordan sneakers
wholesale jordans
cheap jordans
authentic jordans
wholesale Nike dunks
cheap nike dunks
nike dunk for cheap
discount nike dunks
cheap nike air force one sneaker in u.sl
cheap wholesale air force one
air force 1s 25th wholesale
cheap air force ls,air force ones wholesale
cheap wholesale nike air max,wholesale nike shox
r3,shox r4,shox r5,shox oz,shox nz,shox tl3
cheap wholesale bape shoes
cheap jeans wholesale
bags wholesale
From jjposner at optimum.net Sun Mar 21 19:28:43 2010 From: jjposner at optimum.net (John Posner) Date: Sun, 21 Mar 2010 19:28:43 -0400 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4B8EF717.3070701@optimum.net> < Message-ID: <4BA6ABAB.5060807@optimum.net> On 3/21/2010 5:34 PM, Aahz wrote: > In article, > John Posner wrote: >> >> Bruno (and anyone else interested) -- >> >> As I promised/threatened, here's the *start* of a write-up on >> properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested, but not interested enough to download a PDF and fire up > a PDF reader. Are you really using features that require PDF instead of > just writing a web page? No, I compose text using a WYSIWYG editor, and I assumed that PDF was a convenient format for others. I've been working on the writeup, and marking it up for use on the Python Wiki. So I've gone ahead and published it: http://wiki.python.org/moin/ComputedAttributesUsingPropertyObjects For good measure, I've also been working on an updated writeup for "property" in the "Built-in Functions" section of the official Python docs. A draft is in HTML format at: http://cl1p.net/jjp_python_property_ref.html/ Thanks for your interest! All comments are most welcome. -John From ldo at geek-central.gen.new_zealand Sun Mar 21 19:36:35 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 22 Mar 2010 12:36:35 +1300 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: In message , Terry Reedy wrote: > No one has discovered a setting > of the internal tuning parameters for which there are no bad patterns > and I suspect there are not any such. This does not negate Xavier's > suggestion that a code change might also solve your problem. Could it be that for implementing a structure like a trie as the OP is, where a lot of CPU cycles can be spent manipulating the structure, a high- level language like Python, Perl or Ruby just gets in the way? My feeling would be, try to get the language to do as much of the work for you as possible. If you can?t do that, then you might be better off with a lower-level language. From twentyqstns at gmail.com Sun Mar 21 19:47:59 2010 From: twentyqstns at gmail.com (twenty questions) Date: Sun, 21 Mar 2010 16:47:59 -0700 (PDT) Subject: add an entry to twentyquestions.org (please) Message-ID: <73490ec3-5d3f-417a-b0fc-c697cd0fb08a@30g2000yqi.googlegroups.com> add an entry to http://www.twentyquestions.org (please) From rasky at develer.com Sun Mar 21 19:50:00 2010 From: rasky at develer.com (Giovanni Bajo) Date: Mon, 22 Mar 2010 00:50:00 +0100 Subject: [ANN] PyInstaller 1.4 Message-ID: <1269215400.3170.12.camel@ozzu> Hello, I'm happy to announce PyInstaller 1.4, the first formal release after several years of quiet development. http://www.pyinstaller.org === What it is === PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. It's similar to py2exe/py2app, but it is multiplatform and with many advanced features. The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. === Features === * Packaging of Python programs into standard executables, that work on computers without Python installed. * Multiplatform: works under Windows, Linux and Irix. Experimental Mac OS X support available. * Multiversion: works under any version of Python from 1.5 up to 2.6. NOTE: Support for Python 2.6+ on Windows is not included in this release yet. Please see this page for a working patch: http://www.pyinstaller.org/wiki/Python26Win * Flexible packaging mode: * Single directory: build a directory containing an executable plus all the external binary modules (.dll, .pyd, .so) used by the program. * Single file: build a single executable file, totally self-contained, which runs without any external dependency. * Custom: you can automate PyInstaller to do whatever packaging mode you want through a simple script file in Python. * Explicit intelligent support for many 3rd-packages (for hidden imports, external data files, etc.), to make them work with PyInstaller out-of-the-box. * Full single-file EGG support: .egg files are automatically packaged by PyInstaller as-is, so that all features are supported at runtime as well (entry points, etc.). * Automatic support for binary libraries used through ctypes (see http://www.pyinstaller.org/wiki/CtypesDependencySupport for details). * Support for automatic binary packing through the well-known UPX compressor. * Support for code-signing executables on Windows. * Optional console mode (see standard output and standard error at runtime). * Selectable executable icon (Windows only). * Fully configurable version resource section in executable (Windows only). * Support for building COM servers (Windows only). === ChangeLog === For those already using older versions of PyInstaller, the full changelog for this release can be found here: http://www.pyinstaller.org/browser/tags/1.4/doc/CHANGES.txt === Feedback === We're eager to listent to your feedback on using PyInstaller: Ticketing system: http://www.pyinstaller.org/newticket Mailing list: http://groups-beta.google.com/group/PyInstaller -- Giovanni Bajo :: Develer S.r.l. rasky at develer.com :: http://www.develer.com Blog: http://giovanni.bajo.it Last post: ctypes support in PyInstaller From janssen at parc.com Sun Mar 21 19:52:35 2010 From: janssen at parc.com (Bill Janssen) Date: Sun, 21 Mar 2010 16:52:35 PDT Subject: using Python distutils bdist_msi to create installer for large complicated package In-Reply-To: <4BA6A50E.9060108@v.loewis.de> References: <61250.1269211813@parc.com> <4BA6A50E.9060108@v.loewis.de> Message-ID: <63771.1269215555@parc.com> Martin v. L?wis wrote: > > I've been re-thinking the UpLib Windows installer technology, and it > > occurred to me to wonder why I can't just use the nice bdist_msi module > > in Python to build my packages. I took a look, and it seems almost > > doable. Presumably you wrote it? > > Correct. > > > UpLib is a big package, with lots of Python and Java and C programs, and > > for Windows I package it with lots of other programs like those from > > xpdf. All of this is installed in C:\Program Files\UpLib\VERSION\, in > > bin, lib, share, and so forth subdirectories. If I autogenerated a > > setup.py file which described everything as "data_files", it should be > > simple to package everything up in a Cab, and bdist_msi apparently also > > provides the ability to add pre- and post-install scripts. Everything > > I need, really. > > > > There are a couple of Python-specific options in the code: the "Product > > Name" is prefixed with the python version, and in the GUI, the default > > location is the location of a Python distro. If the package had a > > "--non-python" option which would defeat these, and perhaps also set > > "no-target-optimize" and "no-target-compile" to True, it would be a > > simple but pretty general-purpose packager module. > > I'd rather recommend to base this off msilib directly, instead of trying > to subvert bdist_msi to do what you want. Yes, that was the first thing I looked at. But as you've pointed out in the past, it requires a lot of MSI know-how to use that library directly. For a variety of applications, you've already embedded most if not all of that know-how in the bdist_msi class. And subclassing is the indicated way to build on distutils, isn't it? > There is actually quite a lot python-specifics in bdist_msi. Well, sort of. If a setup only references "data_files" -- no Python packages, no extensions -- it's pretty generic. The "add_find_python" method seems the most python-specific. I'd remove a lot of that in the generic case. And, of course, modify "run" so that the product name isn't prefixed with "Python x.y". > If you find this too tedious to use, > please propose *base classes* that could become part of msilib, rather > than trying to create *subclasses* of the bdist_msi classes. Yes, good idea. For example, all those panels that are in get_ui could be added by a InstallerBaseGUI class of some sort. But still, just a few mods to bdist_msi could go a long way. For instance, you've already pulled out "get_installer_filename". I'd add a similar method, "get_product_name", which would typically just return the user-specific name, but in the default case could prefix the product name with Python 2.6. Bill From mailers at oranged.to Sun Mar 21 20:12:00 2010 From: mailers at oranged.to (Jimmy Stewpot) Date: Mon, 22 Mar 2010 00:12:00 +0000 (UTC) Subject: Best practise for dual stack programming in python Message-ID: <58492962.583.1269216720829.JavaMail.root@poops.oranged.to> Hello, The organisation that I currently work for has a large number of 'legacy' tools and scripts which rely entirely on IPv4. Many of them have been written and not documented etc. The organisation is in the process of moving to a dual stack environment over the next 3 months. With that in mind many of our scripts need to be rewritten and documented. I have been looking at moving from a mix of languages over to a standard which at this point is looking like it will be Python (because I am most familiar with it). I have never done any dual stack coding so I am interested to know if there are any good resources for developing dual stack python code? I have had a look around and have found very little on the python web page which makes me worry. Does anyone have any recommendations on web pages to read or books to look at? Any additional advice would be really appreciated. Regards, Jimmy Stewpot. From no.email at please.post Sun Mar 21 21:36:19 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 01:36:19 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba66311$0$27838$c3e8da3@news.astraweb.com> Message-ID: In <4ba66311$0$27838$c3e8da3 at news.astraweb.com> Steven D'Aprano writes: >Then, in your __init__ method, to initialise an attribute use: > self.__dict__['attr'] = value >to bypass the setattr. Ah, that's the trick! Thanks! ~K From ben+python at benfinney.id.au Sun Mar 21 21:46:07 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 22 Mar 2010 12:46:07 +1100 Subject: add an entry to twentyquestions.org (please) References: <73490ec3-5d3f-417a-b0fc-c697cd0fb08a@30g2000yqi.googlegroups.com> Message-ID: <8739ztt9gg.fsf@benfinney.id.au> twenty questions writes: > add an entry to http://www.twentyquestions.org (please) Don't spam groups with your off-topic begging for a closed database silo (please) -- \ ?Our nylons cost more than common, but you'll find that they | `\ are best in the long run.? ?shop, Tokyo | _o__) | Ben Finney From agoretoy at gmail.com Sun Mar 21 22:04:15 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 21 Mar 2010 20:04:15 -0600 Subject: execute bash builtins in python In-Reply-To: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: Thank you for the great suggestions. Steve Holden that is a good one, I will try to adapt my application to your suggestion. This way I don't have to source .bashrc when it could do all that for me including other things that it does in the background. Thank you so much. Nobody, I was not aware of that shell arg thing, thank you. Ipython is ok, but in this case I would have to force another dependency, which I'm trying to keep those as low as possible for such a small application. In fact, I'm gonna remove desktopcouch (couchdb) as one of the deps in the next release of courtesyflush. Expect the next release sometime late next week, if you interested in the app. find it on launchpad. :) Enjoy. Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Mar 21 22:39:44 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 21 Mar 2010 22:39:44 -0400 Subject: Best practise for dual stack programming in python In-Reply-To: <58492962.583.1269216720829.JavaMail.root@poops.oranged.to> References: <58492962.583.1269216720829.JavaMail.root@poops.oranged.to> Message-ID: On 3/21/2010 8:12 PM, Jimmy Stewpot wrote: > Hello, > > The organisation that I currently work for has a large number of > 'legacy' tools and scripts which rely entirely on IPv4. Many of them > have been written and not documented etc. The organisation is in the > process of moving to a dual stack environment over the next 3 months. > With that in mind many of our scripts need to be rewritten and > documented. I have been looking at moving from a mix of languages > over to a standard which at this point is looking like it will be > Python (because I am most familiar with it). I have never done any > dual stack coding so I am interested to know if there are any good > resources for developing dual stack python code? I have had a look > around and have found very little on the python web page which makes > me worry. Does anyone have any recommendations on web pages to read > or books to look at? There are at least 2 ip address libraries which handle both ip4 and ip6. One is Google's package, http://pypi.python.org/pypi/ipaddr/2.0.0 I forget the name of the other, which covers a bit more than the above with a slightly different conceptual model. Would these help. Terry Jan Reedy From sam at tregar.com Sun Mar 21 23:08:36 2010 From: sam at tregar.com (Sam Tregar) Date: Sun, 21 Mar 2010 23:08:36 -0400 Subject: [ANN] onlinepayment v1.0.0 released In-Reply-To: References: Message-ID: onlinepayment v1.0.0 - a generic Python API for making online payments This module provides an API wrapper around a variety of payment providers. Using this module you can write code that will work the same regardless of the payment provider in use. Examples:: from onlinepayment import OnlinePayment # connect to authorize.net, setup auth with login and key auth= { 'login': 'YOUR LOGIN HERE', 'key': 'YOUR KEY HERE' } op = OnlinePayment('authnet', test_mode=True, auth=auth) # or for paypal, setup auth with user, pass, vendor and product: auth= { 'username': 'YOUR USERNAME HERE', 'password': 'YOUR PASSWORD HERE', 'vendor': 'YOUR VENDOR HERE', 'product': 'YOUR PRODUCT HERE' } # connect to PayPal op = OnlinePayment('paypal', test_mode=True, auth=auth) # charge a card try: result = op.sale(first_name = 'Joe', last_name = 'Example', address = '100 Example Ln.', city = 'Exampleville', state = 'NY', zip = '10001', amount = '2.00', card_num = '4007000000027', exp_date = '0530', card_code = '1234') except conn.TransactionDeclined: # do something when the transaction fails except conn.CardExpired: # tell the user their card is expired except conn.ProcessorException: # handle all other possible processor-generated exceptions generically # examine result, the values returned here are processor-specific success = result.success code = result.code message = result.message trans_id = result.trans_id # you can get the raw data returned by the underlying processor too orig = result.orig Installation ============ Before you can use this module you must install one or more payment processors. To install the PayPal payflowpro package:: # easy_install pytz # easy_install python-payflowpro To install the zc.authorizedotnet package and the authorize package (for recurring support):: # easy_install zc.authorizedotnet # easy_install authorize If you want authorize.net support you'll need to install a patched version of zc.ssl. Hopefully someday this will be released by the Zope devs, but so far I haven't heard anything back. Download the zc.ssl source package from http://pypi.python.org/pypi/zc.ssl/, then unpack:: # tar zxvf zc.ssl-1.1.tar.gz # cd zc.ssl-1.1 Now download and apply my zc-ssl-timeout.patch:: # wget http://python-onlinepayment.googlecode.com/svn/trunk/zc-ssl-timeout.patch # patch -p1 < /zc-ssl-timeout.patch And install the patched module:: # python setup.py install (You may also need to edit setup.py and remove the 'ssl-for-setuptools' dependecy. I did, although it may be a quirk of my Python install rather than a general problem.) Once you have a payment processor you can install this module:: # easy_install onlinepayment For more information see: http://pypi.python.org/pypi/onlinepayment/1.0.0 -------------- next part -------------- An HTML attachment was scrubbed... URL: From maymunbeyin at gmail.com Sun Mar 21 23:45:51 2010 From: maymunbeyin at gmail.com (kuru) Date: Sun, 21 Mar 2010 20:45:51 -0700 (PDT) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <3c11d8e6-ea2d-43d6-a9c9-5c23a52fba8f@l25g2000yqd.googlegroups.com> Thanks for the shell. It is nice alternative , however I am not ready to give up Ipython :) If the code ends with a comment line your shell is giving an error. Feature request: It would be nice to have numbered lines in the code section, it makes it hard to find problem line Feature request: Loading an actual Python file rather than copy pasting keep up the good work From zookog at gmail.com Mon Mar 22 01:09:46 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Sun, 21 Mar 2010 23:09:46 -0600 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: Folks: I failed to make something sufficiently clear in my original message about StringChain. The use case that I am talking about is not simply that you need to accumulate a sequence of incoming chunks of data, concatenate them together, and then process the entire result. If that is all you need to do then indeed you can accumulate the incoming strings in a list and then run ''.join(thelist) when you have received all of them and are ready to process them. But the use case that I am talking about is where you need to accumulate new incoming strings into your buffer while alternately processing leading prefixes of the buffer. The typical example is that sequences of bytes are arriving on your TCP socket and you are processing the stream incrementally. You need to process the leading prefixes of the stream as soon as you can (e.g. as soon as a line followed by a newline has accumulated, or as soon as another complete element in your data format has accumulated, etc.); you can't simply wait until the bytes stop coming and then concatenate the entire collection together at once. This is exactly the current situation in foolscap [1] which is causing a performance problem in Tahoe-LAFS [2]. To illustrate what I mean I cooked up some benchmarks showing the task of "accumulate a bunch of things then consume them in a single gulp" versus the task of "alternate between accumulating and consuming" (with accumulation going faster than consumption until the input stream runs dry). I implemented a few data structures for benchmarking: StringChain, the naive "accumulatorstr += newstr" approach (named "Stringy" in the benchmarks), one based on cStringIO (named "StringIOy"), one based on accumulating the new strings into a list and then doing ''.join(accumulatorlist) whenever you need to consume a leading prefix (called "SimplerStringChain"). Below are the abbreviated results of the benchmark. You can easily run this benchmark yourself by following the README.txt in the StringChain source package [3]. These results show that for the load imposed by this benchmark StringChain is the only one of the four that scales and that it is also nice and fast. The left-hand column is the total number of bytes that were run through it. The results are shown in nanoseconds per byte in exponential notation. ("e+01" means times 10, "e+02" means times 100, and "e+03" means times 1000, etc.) Each result is the best of 10 tries, or of 5 tries for the tasks which were taking too long to run it 10 times. Regards, Zooko [1] http://foolscap.lothar.com/trac/ticket/149 [2] http://allmydata.org/pipermail/tahoe-dev/2010-March/004181.html [3] http://tahoe-lafs.org/trac/stringchain impl: StringChain task: _accumulate_then_one_gulp 10000 best: 2.694e+00 50000 best: 2.742e+00 100000 best: 2.310e+00 500000 best: 2.040e+00 1000000 best: 1.988e+00 5000000 best: 2.193e+00 task: _alternate_str 10000 best: 6.509e+00 50000 best: 4.559e+00 100000 best: 4.308e+00 500000 best: 4.070e+00 1000000 best: 3.991e+00 5000000 best: 4.000e+00 impl: SimplerStringChain task: _accumulate_then_one_gulp 10000 best: 1.407e+00 50000 best: 2.317e+00 100000 best: 2.012e+00 500000 best: 1.902e+00 1000000 best: 1.897e+00 5000000 best: 2.104e+00 task: _alternate_str 10000 best: 4.888e+00 50000 best: 5.198e+00 100000 best: 1.750e+01 500000 best: 6.233e+01 1000000 best: 1.134e+02 5000000 best: 7.599e+02 impl: StringIOy task: _accumulate_then_one_gulp 10000 best: 4.196e+00 50000 best: 5.522e+00 100000 best: 4.499e+00 500000 best: 3.756e+00 1000000 best: 4.176e+00 5000000 best: 5.414e+00 task: _alternate_str 10000 best: 5.484e+00 50000 best: 7.863e+00 100000 best: 2.126e+01 500000 best: 6.972e+01 1000000 best: 1.219e+02 5000000 best: 9.463e+02 task: _accumulate_then_one_gulp 10000 best: 1.502e+00 50000 best: 1.420e+01 100000 best: 2.245e+01 500000 best: 8.577e+01 1000000 best: 2.295e+02 5000000 best: 1.326e+03 task: _alternate_str 10000 best: 3.290e+00 50000 best: 4.220e+00 100000 best: 1.665e+01 500000 best: 6.281e+01 1000000 best: 1.127e+02 5000000 best: 7.626e+02 From mws42262 at yahoo.com Mon Mar 22 01:29:57 2010 From: mws42262 at yahoo.com (sam) Date: Sun, 21 Mar 2010 22:29:57 -0700 (PDT) Subject: ------->>>FREE MAC<<<------- Message-ID: <26c5c978-e176-4ff4-afb5-68eef6c466b7@33g2000yqj.googlegroups.com> http://michellemichaeldiscounts.com/16801.html From aram1980 at gmail.com Mon Mar 22 03:22:01 2010 From: aram1980 at gmail.com (Aram Ter-Sarkissov) Date: Mon, 22 Mar 2010 00:22:01 -0700 (PDT) Subject: nonuniform sampling with replacement References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: On 22 ???, 01:28, "Alf P. Steinbach" wrote: > * Alf P. Steinbach: > > > > > * Jah_Alarm: > >> I've got a vector length n of integers (some of them are repeating), > >> and I got a selection probability vector of the same length. How will > >> I sample with replacement k (<=n) values with the probabilty vector. > >> In Matlab this function is randsample. I couldn't find anything to > >> this extent in Scipy or Numpy. > > > > [snip] > > > > > Disclaimer: I just cooked it up and just cooked up binary searches > > usually have bugs. They usually need to be exercised and fixed. But I > > think you get the idea. Note also that division differs in Py3 and Py2. > > This is coded for Py3. > > Sorry, I realized this just now: the name "p" in the choice() method is utterly > misleading, which you can see from the call; it's a random number not a > probability. I guess my fingers just repeated what they typed earlier. > > Cheeers, > > - Alf (repeat typist) thanks a lot alex From aram1980 at gmail.com Mon Mar 22 03:24:16 2010 From: aram1980 at gmail.com (Aram Ter-Sarkissov) Date: Mon, 22 Mar 2010 00:24:16 -0700 (PDT) Subject: nonuniform sampling with replacement References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: On 22 ???, 01:27, Peter Otten <__pete... at web.de> wrote: > Jah_Alarm wrote: > > I've got a vector length n of integers (some of them are repeating), > > and I got a selection probability vector of the same length. How will > > I sample with replacement k (<=n) values with the probabilty vector. > > In Matlab this function is randsample. I couldn't find anything to > > this extent in Scipy or Numpy. > > If all else fails you can do it yourself: > > import random > import bisect > > def iter_sample_with_replacement(values, weights): > ? ? _random = random.random > ? ? _bisect = bisect.bisect > > ? ? acc_weights = [] > ? ? sigma = 0 > ? ? for w in weights: > ? ? ? ? sigma += w > ? ? ? ? acc_weights.append(sigma) > ? ? while 1: > ? ? ? ? yield values[_bisect(acc_weights, _random()*sigma)] > > def sample_with_replacement(k, values, weights): > ? ? return list(islice(iter_sample_with_replacement(values, weights), k)) > > if __name__ == "__main__": > ? ? from itertools import islice > ? ? N = 10**6 > ? ? values = range(4) > ? ? weights = [2, 3, 4, 1] > > ? ? histo = [0] * len(values) > ? ? for v in islice(iter_sample_with_replacement(values, weights), N): > ? ? ? ? histo[v] += 1 > ? ? print histo > ? ? print sample_with_replacement(30, values, weights) > > Peter thanks a lot, Alex From agoretoy at gmail.com Mon Mar 22 03:32:36 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Mar 2010 01:32:36 -0600 Subject: execute bash builtins in python In-Reply-To: References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: I do have a problem however that I don't know how to solve. My application dies abruptly at random times because of this and I get this output error in the terminal: bash: line 0: declare: write error: Broken pipe and sometimes it crashes and I get this output error; this one maybe gtk related, yes? *** glibc detected *** /usr/bin/python: double free or corruption (fasttop): 0xb650fa78 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0x17aff1] /lib/tls/i686/cmov/libc.so.6[0x17c6f2] /lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x17f7cd] /lib/libglib-2.0.so.0(g_free+0x36)[0x7a3196] /usr/lib/libgdk-x11-2.0.so.0[0x27faba] /usr/lib/libgdk-x11-2.0.so.0(gdk_region_union+0x8e)[0x28129e] /usr/lib/libgdk-x11-2.0.so.0[0x28e26c] /usr/lib/libgdk-x11-2.0.so.0(gdk_window_invalidate_maybe_recurse+0x243)[0x28eb33] /usr/lib/libgdk-x11-2.0.so.0(gdk_window_invalidate_maybe_recurse+0x206)[0x28eaf6] /usr/lib/libgtk-x11-2.0.so.0[0x28b5893] /usr/lib/libgtk-x11-2.0.so.0[0x28b6cff] /usr/lib/libgtk-x11-2.0.so.0(gtk_widget_queue_resize+0x75)[0x28bcaa5] /usr/lib/libgtk-x11-2.0.so.0[0x288b557] /usr/lib/libgobject-2.0.so.0(g_cclosure_marshal_VOID__BOXED+0x88)[0x320068] /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x1b2)[0x313072] /usr/lib/libgobject-2.0.so.0[0x3287a8] /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x7bd)[0x329b2d] /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x26)[0x329fb6] /usr/lib/libgtk-x11-2.0.so.0(gtk_tree_model_row_deleted+0x9a)[0x28751da] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_remove+0x114)[0x278e9e4] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_clear+0x90)[0x278eab0] /usr/lib/pymodules/python2.6/gtk-2.0/gtk/_gtk.so[0x10b64a1] /usr/bin/python(PyEval_EvalFrameEx+0x4175)[0x80dbfd5] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python(PyEval_EvalCodeEx+0x7d2)[0x80dddf2] /usr/bin/python[0x816014c] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python[0x80684ac] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python(PyEval_CallObjectWithKeywords+0x42)[0x80d6ef2] /usr/bin/python(PyObject_CallObject+0x20)[0x80612a0] /usr/lib/pymodules/python2.6/gtk-2.0/gobject/_gobject.so[0xd4503e] /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x1b2)[0x313072] /usr/lib/libgobject-2.0.so.0[0x3287a8] /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x7bd)[0x329b2d] /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x26)[0x329fb6] /usr/lib/libgtk-x11-2.0.so.0[0x26fb8dc] /usr/lib/libgobject-2.0.so.0(g_cclosure_marshal_VOID__BOXED+0x88)[0x320068] /usr/lib/libgobject-2.0.so.0(g_closure_invoke+0x1b2)[0x313072] /usr/lib/libgobject-2.0.so.0[0x3287a8] /usr/lib/libgobject-2.0.so.0(g_signal_emit_valist+0x7bd)[0x329b2d] /usr/lib/libgobject-2.0.so.0(g_signal_emit+0x26)[0x329fb6] /usr/lib/libgtk-x11-2.0.so.0(gtk_tree_model_row_deleted+0x9a)[0x28751da] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_remove+0x114)[0x278e9e4] /usr/lib/libgtk-x11-2.0.so.0(gtk_list_store_clear+0x90)[0x278eab0] /usr/lib/pymodules/python2.6/gtk-2.0/gtk/_gtk.so[0x10b64a1] /usr/bin/python(PyEval_EvalFrameEx+0x4175)[0x80dbfd5] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python[0x815de2f] /usr/bin/python(PyEval_EvalFrameEx+0x95f)[0x80d87bf] /usr/bin/python(PyEval_EvalCodeEx+0x7d2)[0x80dddf2] /usr/bin/python[0x816022f] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python(PyEval_EvalFrameEx+0x30b9)[0x80daf19] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python(PyEval_EvalFrameEx+0x5524)[0x80dd384] /usr/bin/python(PyEval_EvalCodeEx+0x7d2)[0x80dddf2] /usr/bin/python[0x816014c] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python[0x80684ac] /usr/bin/python(PyObject_Call+0x4a)[0x806120a] /usr/bin/python(PyEval_CallObjectWithKeywords+0x42)[0x80d6ef2] /usr/bin/python[0x8107d88] ======= Memory map: ======== 00110000-0024e000 r-xp 00000000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 0024e000-0024f000 ---p 0013e000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 0024f000-00251000 r--p 0013e000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 00251000-00252000 rw-p 00140000 08:06 688127 /lib/tls/i686/cmov/ libc-2.10.1.so 00252000-00255000 rw-p 00000000 00:00 0 00255000-002e7000 r-xp 00000000 08:06 198090 /usr/lib/libgdk-x11-2.0.so.0.1800.3 002e7000-002e9000 r--p 00092000 08:06 198090 /usr/lib/libgdk-x11-2.0.so.0.1800.3 002e9000-002ea000 rw-p 00094000 08:06 198090 /usr/lib/libgdk-x11-2.0.so.0.1800.3 002ea000-00305000 r-xp 00000000 08:06 198967 /usr/lib/libatk-1.0.so.0.2809.1 00305000-00306000 r--p 0001b000 08:06 198967 /usr/lib/libatk-1.0.so.0.2809.1 00306000-00307000 rw-p 0001c000 08:06 198967 /usr/lib/libatk-1.0.so.0.2809.1 00307000-00308000 rwxp 00000000 00:00 0 00308000-00344000 r-xp 00000000 08:06 196888 /usr/lib/libgobject-2.0.so.0.2200.3 00344000-00345000 r--p 0003b000 08:06 196888 /usr/lib/libgobject-2.0.so.0.2200.3 00345000-00346000 rw-p 0003c000 08:06 196888 /usr/lib/libgobject-2.0.so.0.2200.3 00346000-00351000 r-xp 00000000 08:06 199652 /usr/lib/libpangocairo-1.0.so.0.2600.0 00351000-00352000 r--p 0000a000 08:06 199652 /usr/lib/libpangocairo-1.0.so.0.2600.0 00352000-00353000 rw-p 0000b000 08:06 199652 /usr/lib/libpangocairo-1.0.so.0.2600.0 00353000-003e6000 r-xp 00000000 08:06 197035 /usr/lib/libgio-2.0.so.0.2200.3 003e6000-003e7000 r--p 00092000 08:06 197035 /usr/lib/libgio-2.0.so.0.2200.3 003e7000-003e8000 rw-p 00093000 08:06 197035 /usr/lib/libgio-2.0.so.0.2200.3 003e8000-003e9000 rw-p 00000000 00:00 0 003e9000-003eb000 r-xp 00000000 08:06 198888 /usr/lib/libXcomposite.so.1.0.0 003eb000-003ec000 r--p 00001000 08:06 198888 /usr/lib/libXcomposite.so.1.0.0 003ec000-003ed000 rw-p 00002000 08:06 198888 /usr/lib/libXcomposite.so.1.0.0 003ed000-003ef000 r-xp 00000000 08:06 198892 /usr/lib/libXdamage.so.1.1.0 003ef000-003f0000 rw-p 00001000 08:06 198892 /usr/lib/libXdamage.so.1.1.0 003f0000-003f4000 r-xp 00000000 08:06 198898 /usr/lib/libXfixes.so.3.1.0 003f4000-003f5000 r--p 00003000 08:06 198898 /usr/lib/libXfixes.so.3.1.0 003f5000-003f6000 rw-p 00004000 08:06 198898 /usr/lib/libXfixes.so.3.1.0 003f6000-00404000 r-xp 00000000 08:06 198896 /usr/lib/libXext.so.6.4.0 00404000-00405000 r--p 0000d000 08:06 198896 /usr/lib/libXext.so.6.4.0 00405000-00406000 rw-p 0000e000 08:06 198896 /usr/lib/libXext.so.6.4.0 00406000-0040e000 r-xp 00000000 08:06 198918 /usr/lib/libXrender.so.1.3.0 0040e000-0040f000 r--p 00007000 08:06 198918 /usr/lib/libXrender.so.1.3.0 0040f000-00410000 rw-p 00008000 08:06 198918 /usr/lib/libXrender.so.1.3.0 00410000-00425000 r-xp 00000000 08:06 688141 /lib/tls/i686/cmov/ libpthread-2.10.1.so 00425000-00426000 r--p 00014000 08:06 688141 /lib/tls/i686/cmov/ libpthread-2.10.1.so 00426000-00427000 rw-p 00015000 08:06 688141 /lib/tls/i686/cmov/ libpthread-2.10.1.so 00427000-00429000 rw-p 00000000 00:00 0 00429000-0042b000 r-xp 00000000 08:06 198906 /usr/lib/libXinerama.so.1.0.0 0042b000-0042c000 rw-p 00001000 08:06 198906 /usr/lib/libXinerama.so.1.0.0 0042c000-00435000 r-xp 00000000 08:06 198904 /usr/lib/libXi.so.6.0.0 00435000-00436000 r--p 00008000 08:06 198904 /usr/lib/libXi.so.6.0.0 00436000-00437000 rw-p 00009000 08:06 198904 /usr/lib/libXi.so.6.0.0 00437000-00440000 r-xp 00000000 08:06 198890 /usr/lib/libXcursor.so.1.0.2 00440000-00441000 r--p 00008000 08:06 198890 /usr/lib/libXcursor.so.1.0.2 00441000-00442000 rw-p 00009000 08:06 198890 /usr/lib/libXcursor.so.1.0.2 00442000-00452000 r-xp 00000000 08:06 688142 /lib/tls/i686/cmov/ libresolv-2.10.1.so 00452000-00453000 r--p 00010000 08:06 688142 /lib/tls/i686/cmov/ libresolv-2.10.1.so 00453000-00454000 rw-p 00011000 08:06 688142 /lib/tls/i686/cmov/ libresolv-2.10.1.so 00454000-00456000 rw-p 00000000 00:00 0 00456000-0045e000 r-xp 00000000 08:06 199193 /usr/lib/libfusion-1.2.so.0.7.0 0045e000-0045f000 r--p 00007000 08:06 199193 /usr/lib/libfusion-1.2.so.0.7.0 0045f000-00460000 rw-p 00008000 08:06 199193 /usr/lib/libfusion-1.2.so.0.7.0 00460000-00463000 r-xp 00000000 08:06 199911 /usr/lib/libxcb-render-util.so.0.0.0 00463000-00464000 r--p 00002000 08:06 199911 /usr/lib/libxcb-render-util.so.0.0.0 00464000-00465000 rw-p 00003000 08:06 199911 /usr/lib/libxcb-render-util.so.0.0.0 00465000-0046c000 r-xp 00000000 08:06 199913 /usr/lib/libxcb-render.so.0.0.0 0046c000-0046d000 r--p 00007000 08:06 199913 /usr/lib/libxcb-render.so.0.0.0 0046d000-0046e000 rw-p 00008000 08:06 199913 /usr/lib/libxcb-render.so.0.0.0 0046e000-00486000 r-xp 00000000 08:06 198092 /usr/lib/libgdk_pixbuf-2.0.so.0.1800.3 00486000-00487000 r--p 00017000 08:06 198092 /usr/lib/libgdk_pixbuf-2.0.so.0.1800.3 00487000-00488000 rw-p 00018000 08:06 198092 /usr/lib/libgdk_pixbuf-2.0.so.0.1800.3 00488000-004ff000 r-xp 00000000 08:06 196251 /usr/lib/libcairo.so.2.10800.8 004ff000-00501000 r--p 00076000 08:06 196251 /usr/lib/libcairo.so.2.10800.8 00501000-00502000 rw-p 00078000 08:06 196251 /usr/lib/libcairo.so.2.10800.8 00502000-00548000 r-xp 00000000 08:06 199650 /usr/lib/libpango-1.0.so.0.2600.0 00548000-00549000 r--p 00045000 08:06 199650 /usr/lib/libpango-1.0.so.0.2600.0 00549000-0054a000 rw-p 00046000 08:06 199650 /usr/lib/libpango-1.0.so.0.2600.0 0054a000-0054e000 r-xp 00000000 08:06 198894 /usr/lib/libXdmcp.so.6.0.0 0054e000-0054f000 rw-p 00003000 08:06 198894 /usr/lib/libXdmcp.so.6.0.0 0054f000-00550000 r-xp 00000000 08:06 230770 /usr/lib/gtk-2.0/2.10.0/loaders/svg_loader.so 00550000-00551000 r--p 00001000 08:06 230770 /usr/lib/gtk-2.0/2.10.0/loaders/svg_loader.so 00551000-00552000 rw-p 00002000 08:06 230770 /usr/lib/gtk-2.0/2.10.0/loaders/svg_loader.so 00552000-00566000 r-xp 00000000 08:06 670607 /lib/libz.so.1.2.3.3 00566000-00567000 r--p 00013000 08:06 670607 /lib/libz.so.1.2.3.3 00567000-00568000 rw-p 00014000 08:06 670607 /lib/libz.so.1.2.3.3 00568000-00581000 r-xp 00000000 08:06 670575 /lib/libselinux.so.1 00581000-00582000 r--p 00018000 08:06 670575 /lib/libselinux.so.1 00582000-00583000 rw-p 00019000 08:06 670575 /lib/libselinux.so.1 00583000-005c7000 r-xp 00000000 08:06 199680 /usr/lib/libpixman-1.so.0.14.0 005c7000-005c9000 r--p 00043000 08:06 199680 /usr/lib/libpixman-1.so.0.14.0 005c9000-005ca000 rw-p 00045000 08:06 199680 /usr/lib/libpixman-1.so.0.14.0 005ca000-005e0000 r-xp 00000000 08:06 199106 /usr/lib/libdirect-1.2.so.0.7.0 Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Mar 22 03:42:07 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 22 Mar 2010 08:42:07 +0100 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: Lawrence D'Oliveiro, 22.03.2010 00:36: > Terry Reedy wrote: >> No one has discovered a setting >> of the internal tuning parameters for which there are no bad patterns >> and I suspect there are not any such. This does not negate Xavier's >> suggestion that a code change might also solve your problem. > > Could it be that for implementing a structure like a trie as the OP is, > where a lot of CPU cycles can be spent manipulating the structure, a high- > level language like Python, Perl or Ruby just gets in the way? I would rather say that the specific problem of the trie data structure is that it has extremely little benefit over other available data structures. There may still be a couple of niches where it makes sense to consider it as an alternative, but given that dicts are so heavily optimised in Python, it'll be hard for tries to compete even when written in a low-level language. Remember that the original use case was to load a dictionary from a text file. For this use case, a trie can be very wasteful in terms of memory and rather CPU cache unfriendly on traversal, whereas hash values are a) rather fast to calculate for a string, and b) often just calculated once and then kept alive in the string object for later reuse. > My feeling would be, try to get the language to do as much of the work for > you as possible. If you can?t do that, then you might be better off with a > lower-level language. I agree with the first sentence, but I'd like to underline the word 'might' in the second. As this newsgroup shows, very often it's enough to look for a better algorithmic approach first. Stefan From agoretoy at gmail.com Mon Mar 22 04:01:15 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Mar 2010 02:01:15 -0600 Subject: execute bash builtins in python In-Reply-To: References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: for the broken pipe error, perhaps theres a different way I can get shell output other than using subprocess? I need the output of alias command into a string and output of declare command into a string as well, I would like to also avoid creating of a single liner script to make this happen if at all possible Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Mar 22 04:07:49 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Mar 2010 08:07:49 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Sun, 21 Mar 2010 23:09:46 -0600, Zooko O'Whielacronx wrote: > But the use case that I am talking about is where you need to accumulate > new incoming strings into your buffer while alternately processing > leading prefixes of the buffer. [...] > Below are the abbreviated results of the benchmark. You can easily run > this benchmark yourself by following the README.txt in the StringChain > source package [3]. These results show that for the load imposed by this > benchmark StringChain is the only one of the four that scales and that > it is also nice and fast. I was reading this email, and thinking "Why do you need this StringChain data structure, from the description it sounds like a job for collections.deque?" And funnily enough, following the links you supplied I came across this: "You can get the package from http://pypi.python.org/pypi/stringchain or with darcs get http://tahoe-lafs.org/source/stringchain/trunk. It has unit tests. It is in pure Python (it uses collections.deque and string)." http://tahoe-lafs.org/trac/stringchain Perhaps you should have said that it was a wrapper around deque giving richer functionality, rather than giving the impression that it was a brand new data structure invented by you. People are naturally going to be more skeptical about a newly invented data structure than one based on a reliable, component like deque. In any case, it looks to me that the StringChain data structure itself is a little too application specific for me to be personally interested in it. Maybe you should consider linking to it on PyPI and seeing if there is any interest from others? Regards, Steven From agoretoy at gmail.com Mon Mar 22 06:15:29 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Mar 2010 04:15:29 -0600 Subject: execute bash builtins in python In-Reply-To: References: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> Message-ID: actually using the -i param in the command to subprocess doesn't seem to work as well as setting PS1 to some garbage, it starts a new interactive shell therein kicking me out of python. :/ Thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Mar 22 06:35:21 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Mar 2010 11:35:21 +0100 Subject: Tuples vs. variable-length argument lists In-Reply-To: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> References: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> Message-ID: <4BA747E9.5020009@sequans.com> Spencer Pearson wrote: > Hi! > > This might be more of a personal-preference question than anything, > but here goes: when is it appropriate for a function to take a list or > tuple as input, and when should it allow a varying number of > arguments? It seems as though the two are always interchangeable. For > a simple example... > > def subtract( x, nums ): > return x - sum( nums ) > > ... works equally well if you define it as "subtract( x, *nums )" and > put an asterisk in front of any lists/tuples you pass it. I can't > think of any situation where you couldn't convert from one form to the > other with just a star or a pair of parentheses. > > Is there a generally accepted convention for which method to use? Is > there ever actually a big difference between the two that I'm not > seeing? > FYI some linters report the usage of * as bad practice, I don't know the reason though. Pylint reports it as using 'magic'. Anyway the form without * is commonly used. JM From ldo at geek-central.gen.new_zealand Mon Mar 22 07:00:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Mar 2010 00:00:30 +1300 Subject: What is pkg-config for ? References: Message-ID: In message , Gabriel Genellina wrote: > I fail to see how is this relevant to Python... Well, so many of the questions in this noisegroup seem to be about Windows problems, not Python ones... :) From jeanmichel at sequans.com Mon Mar 22 07:01:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Mar 2010 12:01:00 +0100 Subject: accessing variable of the __main__ module In-Reply-To: <4ba4bc88$0$29961$426a74cc@news.free.fr> References: <4ba4bc88$0$29961$426a74cc@news.free.fr> Message-ID: <4BA74DEC.90006@sequans.com> News123 wrote: > Hi, > > > I wondered about the best way, that a module's function could determine > the existance and value of variables in the __main__ module. > > > What I came up with is: > ########### main.py ########## > import mod > A = 4 > if __name__ == "__main__": mod.f() > ########### mod.py ########## > def f(): > try: > from __main__ import A > except ImportError as e: > A = "does not exist" > print "__main__.A" ,A > > Is there anything better / more pythonic? > > Thanks in advance and bye > > > N > The 'was I imported from that module' is usually some sign of bad design. I can't detail more wihtout further detail of what you're trying to achieve. Bud since what you have is working, I would'nt bother more than that cause no matter what you try, it will be ugly :o). JM From newton10471 at gmail.com Mon Mar 22 09:26:45 2010 From: newton10471 at gmail.com (newton10471) Date: Mon, 22 Mar 2010 06:26:45 -0700 (PDT) Subject: chroot fails with mount point passed to subprocess.Popen? Message-ID: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Hi, I'm trying to use subprocess.Popen() to do a Linux chroot to a mount point passed in as a parameter to the following function: def getInstalledKernelVersion(mountPoint): linuxFsRoot = mountPoint + "/root" print "type of linuxFsRoot is %s" % type(linuxFsRoot) installedKernelVersionResult = subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) return installedKernelVersionResult and it dies with the following: type of linuxFsRoot is chroot: cannot change root directory to /storage/mounts/ mnt_3786314034939740895.mnt/root: No such file or directory When I explicitly set linuxFsRoot = "/storage/mounts/ mnt_3786314034939740895.mnt/root", it works fine. I also tried this to concatenate the mountpoint + /root, and it failed in the same way: linuxFsRoot = ("%s/root") % mountPoint Anyone know what might be happening here? Thanks in advance, Matt Newton From alfps at start.no Mon Mar 22 09:33:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 22 Mar 2010 14:33:31 +0100 Subject: chroot fails with mount point passed to subprocess.Popen? In-Reply-To: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> References: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Message-ID: * newton10471: > Hi, > > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount > point passed in as a parameter to the following function: > > def getInstalledKernelVersion(mountPoint): > linuxFsRoot = mountPoint + "/root" > print "type of linuxFsRoot is %s" % type(linuxFsRoot) > installedKernelVersionResult = > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) > return installedKernelVersionResult > > and it dies with the following: > > type of linuxFsRoot is > chroot: cannot change root directory to /storage/mounts/ > mnt_3786314034939740895.mnt/root: No such file or directory > > When I explicitly set linuxFsRoot = "/storage/mounts/ > mnt_3786314034939740895.mnt/root", it works fine. > > I also tried this to concatenate the mountpoint + /root, and it failed > in the same way: > > linuxFsRoot = ("%s/root") % mountPoint Use the os.path functions. > Anyone know what might be happening here? Since the computed and literal paths /look/ identical and same type, the only thing I can imagine is that there is some invisible character. Try comparing the computed and literal path character by character. Print the difference or if they're identical, that they are. Possibly you have GIGO problem. Cheers & hth., - Alf From no.email at please.post Mon Mar 22 09:54:27 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 13:54:27 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: In Dennis Lee Bieber writes: >On Sun, 21 Mar 2010 16:57:40 +0000 (UTC), kj >declaimed the following in gmane.comp.python.general: >> Regarding properties, is there a built-in way to memoize them? For >> example, suppose that the value of a property is obtained by parsing >> the contents of a file (specified in another instance attribute). >> It would make no sense to do this parsing more than once. Is there >> a standard idiom for memoizing the value once it is determined for >> the first time? >> > Pickle, Shelve? Maybe in conjunction with SQLite3... I was thinking of something less persistent; in-memory, that is. Maybe something in the spirit of: @property def foo(self): # up for some "adaptive auto-redefinition"? self.foo = self._some_time_consuming_operation() return self.foo ...except that that assignment won't work! It bombs with "AttributeError: can't set attribute". ~K PS: BTW, this is not the first time that attempting to set an attribute (in a class written by me even) blows up on me. It's situations like these that rattle my grasp of attributes, hence my original question about boring, plodding, verbose Java-oid accessors. For me these Python attributes are still waaay too mysterious and unpredictable to rely on. Sometimes one can set them, sometimes not, and I can't quite tell the two situations apart. It's all very confusing to the Noob. (I'm sure this is all documented *somewhere*, but this does not make using attributes any more intuitive or straightforward. I'm also sure that *eventually*, with enough Python experience under one's belt, this all becomes second nature. My point is that Python attributes are not as transparent and natural to the uninitiated as some of you folks seem to think.) From alfps at start.no Mon Mar 22 10:22:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 22 Mar 2010 15:22:02 +0100 Subject: How to automate accessor definition? In-Reply-To: References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: * kj: > In Dennis Lee Bieber writes: > >> On Sun, 21 Mar 2010 16:57:40 +0000 (UTC), kj >> declaimed the following in gmane.comp.python.general: > >>> Regarding properties, is there a built-in way to memoize them? For >>> example, suppose that the value of a property is obtained by parsing >>> the contents of a file (specified in another instance attribute). >>> It would make no sense to do this parsing more than once. Is there >>> a standard idiom for memoizing the value once it is determined for >>> the first time? >>> >> Pickle, Shelve? Maybe in conjunction with SQLite3... > > I was thinking of something less persistent; in-memory, that is. > Maybe something in the spirit of: > > @property > def foo(self): > # up for some "adaptive auto-redefinition"? > self.foo = self._some_time_consuming_operation() > return self.foo > > ...except that that assignment won't work! It bombs with "AttributeError: > can't set attribute". Since foo is a read only property you can assign to it. But it doesn't matter: if it worked technically it wouldn't give you what you're after, the once-only evaluation. A simple way to do that, in the sense of copying code and having it work, is to use a generator that, after evaluating the expensive op, loops forever yielding the resulting value. A probably more efficient way, and anyway one perhaps more easy to understand, is as follows: from __future__ import print_function class LazyEval: def __init__( self, f ): self._f = f self._computed = False @property def value( self ): if not self._computed: self._value = self._f() self._computed = True return self._value class HiHo: def _expensive_op( self ): print( "Expensive op!" ) return 42 def __init__( self ): self._foo = LazyEval( self._expensive_op ) @property def foo( self ): return self._foo.value o = HiHo() for i in range( 5 ): print( o.foo ) Cheers & hth., - Alf From albert at spenarnc.xs4all.nl Mon Mar 22 10:26:10 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Mar 2010 14:26:10 GMT Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: In article <56597268-3472-4fd9-a829-6d9cf51cf093 at e7g2000yqf.googlegroups.com>, Joel Pendery wrote: >So I am trying to write a bit of code and a simple numerical >subtraction > >y_diff = y_diff-H > >is giving me the error > >Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no >encoding declared. > >Even though I have deleted some lines before it and this line is no >longer line 70, I am still getting the error every time. I have tried >to change the encoding of the file to utf-8 but to no avail, I still >am having this issue. Any ideas? Make a hex-dump of your file. How does line 70 look? If you see 0900 66 66 96 48 0A -- ff.H. you know you are doing something illegal. > >Thanks in advance Groetjes Albert P.S. With all due respect, error messages come not any clearer than that! -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From no.email at please.post Mon Mar 22 10:45:22 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 14:45:22 +0000 (UTC) Subject: short-circuiting any/all ? Message-ID: I have a list of items L, and a test function is_invalid that checks the validity of each item. To check that there are no invalid items in L, I could check the value of any(map(is_invalid, L)). But this approach is suboptimal in the sense that, no matter what L is, is_invalid will be executed for all elements of L, even though the value returned by any() is fully determined by the first True in its argument. In other words, all calls to is_invalid after the first one to return True are superfluous. Is there a short-circuiting counterpart to any(map(is_invalid, L)) that avoids these superfluous calls? OK, there's this one, of course: def _any_invalid(L): for i in L: if is_invalid(i): return True return False But is there anything built-in? (I imagine that a lazy version of map *may* do the trick, *if* any() will let it be lazy.) TIA! ~K From john at castleamber.com Mon Mar 22 10:47:09 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Mar 2010 08:47:09 -0600 Subject: add an entry to twentyquestions.org (please) References: <73490ec3-5d3f-417a-b0fc-c697cd0fb08a@30g2000yqi.googlegroups.com> <8739ztt9gg.fsf@benfinney.id.au> Message-ID: <87bpeg8lci.fsf@castleamber.com> Ben Finney writes: > twenty questions writes: > >> add an entry to http:// > > Don't spam groups with your off-topic begging for a closed database silo > (please) Don't repeat spam -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mail at timgolden.me.uk Mon Mar 22 10:57:38 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Mar 2010 14:57:38 +0000 Subject: short-circuiting any/all ? In-Reply-To: References: Message-ID: <4BA78562.3070802@timgolden.me.uk> On 22/03/2010 14:45, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. In other words, all calls to is_invalid after > the first one to return True are superfluous. Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > for i in L: > if is_invalid(i): > return True > return False > > But is there anything built-in? (I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) Have I missed the point of your question, perhaps? This seems to work as lazily as you'd like... def less_than_five (x): print "testing", x return x < 5 L = range (10) print any (less_than_five (i) for i in L) print all (less_than_five (i) for i in L) # for symmetry TJG From jeanmichel at sequans.com Mon Mar 22 11:08:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 22 Mar 2010 16:08:49 +0100 Subject: short-circuiting any/all ? In-Reply-To: References: Message-ID: <4BA78801.3040605@sequans.com> kj wrote: > > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. In other words, all calls to is_invalid after > the first one to return True are superfluous. Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > for i in L: > if is_invalid(i): > return True > return False > > But is there anything built-in? (I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) > > TIA! > > ~K > Sounds like unnecessary optimization. Just write def _any_valid(L): return bool([i for i in L if is_valid(i)]) If you really care about speed, meaning if the user experiences some execution duration increase, then the solution you proposed is fine. JM From tim.wintle at teamrubber.com Mon Mar 22 11:12:52 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Mon, 22 Mar 2010 15:12:52 +0000 Subject: short-circuiting any/all ? In-Reply-To: References: Message-ID: <1269270772.2407.1.camel@localhost> On Mon, 2010-03-22 at 14:45 +0000, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, any( is_invalid(a) for a in L ) ... generator expression will be lazily computed. Tim From pruebauno at latinmail.com Mon Mar 22 11:17:03 2010 From: pruebauno at latinmail.com (nn) Date: Mon, 22 Mar 2010 08:17:03 -0700 (PDT) Subject: short-circuiting any/all ? References: Message-ID: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. In other words, all calls to is_invalid after > the first one to return True are superfluous. Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > for i in L: > if is_invalid(i): > return True > return False > > But is there anything built-in? (I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) > > TIA! > > ~K If you are in Python 3 "any(map(is_invalid, L))" should short circuit. If you are in Python 2 use "from itertools import imap; any(imap(is_invalid, L))" From robert.kern at gmail.com Mon Mar 22 11:22:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 22 Mar 2010 10:22:29 -0500 Subject: nonuniform sampling with replacement In-Reply-To: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> References: <0c333952-2150-4207-90e8-7bb3f2bc7c4c@b9g2000pri.googlegroups.com> Message-ID: On 2010-03-21 05:11 AM, Jah_Alarm wrote: > I've got a vector length n of integers (some of them are repeating), I recommend reducing it down to unique integers first. > and I got a selection probability vector of the same length. How will > I sample with replacement k (<=n) values with the probabilty vector. > In Matlab this function is randsample. I couldn't find anything to > this extent in Scipy or Numpy. In [19]: from scipy.stats import rv_discrete In [20]: p = rv_discrete(name='adhoc', values=([0, 1, 2], [0.5, 0.25, 0.25])) In [21]: p.rvs(size=100) Out[21]: array([0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 2, 2, 2, 1, 0, 0, 2, 0, 0, 1, 0, 0, 2, 2, 0, 1, 2, 1, 0, 0, 2, 1, 1, 1, 1, 1, 2, 1, 2, 0, 2, 0, 2, 0, 0, 2, 0, 1, 0, 2, 2, 1, 0, 0, 1, 0, 2, 1, 0, 0, 1, 0, 2, 1, 2, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 2, 0, 1, 2, 1, 1, 0, 0, 0, 1, 0]) -- 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 From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 22 11:44:01 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 22 Mar 2010 16:44:01 +0100 Subject: How to automate accessor definition? In-Reply-To: References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> Message-ID: <4ba79040$0$22397$426a74cc@news.free.fr> kj a ?crit : > In Dennis Lee Bieber writes: > >> On Sun, 21 Mar 2010 16:57:40 +0000 (UTC), kj >> declaimed the following in gmane.comp.python.general: > >>> Regarding properties, is there a built-in way to memoize them? For >>> example, suppose that the value of a property is obtained by parsing >>> the contents of a file (specified in another instance attribute). >>> It would make no sense to do this parsing more than once. Is there >>> a standard idiom for memoizing the value once it is determined for >>> the first time? >>> >> Pickle, Shelve? Maybe in conjunction with SQLite3... > > I was thinking of something less persistent; in-memory, that is. > Maybe something in the spirit of: > > @property > def foo(self): > # up for some "adaptive auto-redefinition"? > self.foo = self._some_time_consuming_operation() > return self.foo > > ...except that that assignment won't work! It bombs with "AttributeError: > can't set attribute". > > ~K > > PS: BTW, this is not the first time that attempting to set an > attribute (in a class written by me even) blows up on me. It's > situations like these that rattle my grasp of attributes, hence my > original question about boring, plodding, verbose Java-oid accessors. > For me these Python attributes are still waaay too mysterious and > unpredictable to rely on. Somehow simplified, here's what you have to know: 1/ there are instance attributes and class attributes. Instance attributes lives in the instance's __dict__, class attributes lives in the class's __dict__ or in a parent's class __dict__. 2/ when looking up an attribute on an instance, the rules are * first, check if there's a key by that name in the instance's __dict__. If yes, return the associated value * else, check if there's a class or parent class attribute by that name. * if yes ** if the attribute has a '__get__' method, call the __get__ method with class and instance as arguments, and return the result (this is known as the "descriptor protocol" and provides support for computed attributes (including methods and properties) ** else return the attribute itself * else (if nothing has been found yet), look for a __getattr__ method in the class and it's parents. If found, call this __getattr__ method with the attribute name and return the result * else, give up and raise an AttributeError 3/ When binding an attribute on an instance, the rules are: * first, check if there's a class (or parent class) attribute by that name that has a '__set__' method. If yes, call this class attribute's __set__ method with instance and value as arguments. This is the second part part of the "descriptor protocol", as used by the property type. * else, add the attribute's name and value in the instance's __dict__ As I said, this is a somehow simplified description of the process - I skipped the parts about __slots__, __getattribute__ and __setattr__, as well as the part about how function class attributes become methods. But this should be enough to get an idea of what's going on. In your above case, you defined a "foo" property class attribute. The property type implements both __get__ and __set__, but you only defined a callback for the __get__ method (the function you decorated with 'property'), so when you try to rebind "foo", the default property type's __set__ implementation is invoked, which behaviour is to forbid setting the attribute. If you want a settable property, you have to provide a setter too. Now if you want a "replaceable" property-like attribute, you could define your own computed attribute (aka "descriptor") type _without_ a __set__ method: class replaceableprop(object): def __init__(self, fget): self._fget = fget def __get__(self, instance, cls): if instance is None: return self return self._fget(instance) @replaceableprop def foo(self): # will add 'foo' into self.__dict__, s self.foo = self._some_time_consuming_operation() return self.foo Another (better IMHO) solution is to use a plain property, and store the computed value as an implementation attribute : @property def foo(self): cached = self.__dict__.get('_foo_cache') if cached is None: self._foo_cache = cached = self._some_time_consuming_operation() return cached > Sometimes one can set them, sometimes > not, and I can't quite tell the two situations apart. It's all > very confusing to the Noob. (I'm sure this is all documented > *somewhere*, but this does not make using attributes any more > intuitive or straightforward. I'm also sure that *eventually*, > with enough Python experience under one's belt, this all becomes > second nature. My point is that Python attributes are not as > transparent and natural to the uninitiated as some of you folks > seem to think.) I agree that the introduction of the descriptor protocol added some more complexity to an already somehow unusual model object. HTH. From jjposner at optimum.net Mon Mar 22 13:36:34 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 22 Mar 2010 13:36:34 -0400 Subject: How to automate accessor definition? In-Reply-To: <4ba79040$0$22397$426a74cc@news.free.fr> References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba79040$0$22397$426a74cc@news.free.fr> Message-ID: <4ba7aa87$0$4974$607ed4bc@cv.net> On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote: > Another (better IMHO) solution is to use a plain property, and store the > computed value as an implementation attribute : > > @property > def foo(self): > cached = self.__dict__.get('_foo_cache') > if cached is None: > self._foo_cache = cached = self._some_time_consuming_operation() > return cached > There's no need to access __dict__ directly. I believe this is equivalent (and clearer): @property def foo(self): try: cached = self._foo_cache except AttributeError: self._foo_cache = cached = self._time_consuming_op() return cached -John From luismgz at gmail.com Mon Mar 22 13:59:07 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Mon, 22 Mar 2010 10:59:07 -0700 (PDT) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <15025fc0-c697-4085-81a0-160882767540@15g2000yqi.googlegroups.com> On Feb 21, 6:40?pm, Mensanator wrote: > On Feb 21, 12:14?pm, Paul Boddie wrote: > > > > > > > On 21 Feb, 17:32, Mensanator wrote: > > > > On Feb 21, 10:30 am, Mensanator wrote: > > > > > What versions of Python does it suuport? > > > > What OS are supported? > > > From the Web site referenced in the announcement (http:// > > dreampie.sourceforge.net/): > > > """ > > # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and > > Python 3.1. > > # Works on Windows and Linux. > > """ > > Yeah, I saw that. Funny that something important like that wasn't part > of the > announcement. I notice no mention of Mac OS, so visiting the website > was a complete > waste of time on my part, wasn't it? > > > > > Paul Geez... someone spends many hours (or days or even months) writing a program to be offered for free to the world, and you get annoyed by losing two seconds while checking it out? From chambon.pascal at wanadoo.fr Mon Mar 22 14:20:39 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Mon, 22 Mar 2010 19:20:39 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> Message-ID: <4BA7B4F7.6080404@wanadoo.fr> Gabriel Genellina a ?crit : > > En Wed, 17 Mar 2010 09:42:06 -0300, Pascal Chambon > escribi?: > >> traceback functions indeed allow the manipulation of exception >> tracebacks, >> but the root problem is that anyway, since that traceback is incomplete, >> your "traceback.format_exc().splitlines()" will only provide frames for >> callee (downward) functions, not caller (upward) ones, starting from the >> exception catching frame. > > Either I don't understand what you mean, or I can't reproduce it: > > Allright, here is more concretely the problem : import logging def a(): return b() def b(): return c() def c(): try: return d() except: logging.exception("An error") def d(): raise ValueError def main(): logging.basicConfig(level=logging.DEBUG) a() main() OUTPUT: >>> ERROR:root:An error Traceback (most recent call last): File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c return d() File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d def d(): raise ValueError ValueError >>> As you see, the traceback only starts from function c, which handles the exception. It doesn't show main(), a() and b(), which might however be (and are, in my case) critical to diagnose the severity of the problem (since many different paths would lead to calling c()). So the question is : is that possible to enforce, by a way or another, the retrieval of the FULL traceback at exception raising point, instead of that incomplete one ? Thank you for your help, regards, Pascal From python at rcn.com Mon Mar 22 14:27:57 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 22 Mar 2010 11:27:57 -0700 (PDT) Subject: short-circuiting any/all ? References: Message-ID: On Mar 22, 7:45?am, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. ?To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invalid will be executed for all elements of L, even though > the value returned by any() is fully determined by the first True > in its argument. ?In other words, all calls to is_invalid after > the first one to return True are superfluous. ?Is there a > short-circuiting counterpart to any(map(is_invalid, L)) that avoids > these superfluous calls? > > OK, there's this one, of course: > > def _any_invalid(L): > ? ? for i in L: > ? ? ? ? if is_invalid(i): > ? ? ? ? ? ? return True > ? ? return False ? > > But is there anything built-in? ?(I imagine that a lazy version of > map *may* do the trick, *if* any() will let it be lazy.) Yes, that will work: from itertools import imap # lazy version of map any(imap(is_invalid, L) # short-circuits on first True Yet another approach (slightly faster): from itertools import ifilter any(ifilter(is_invalid, L)) Raymond From no.email at please.post Mon Mar 22 14:30:34 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 18:30:34 +0000 (UTC) Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: In <291d82b7-b13b-4f49-901c-8194f3e07598 at e7g2000yqf.googlegroups.com> nn writes: >If you are in Python 3 "any(map(is_invalid, L))" should short circuit. >If you are in Python 2 use "from itertools import imap; >any(imap(is_invalid, L))" Thanks! I'm glad to know that one can get the short circuiting using a map-type idiom. (I prefer map over comprehensions when I don't need to define a function just for the purpose of passing it to it.) And thanks also to the other repliers for pointing out that the comprehension version does what I was asking for. ~K From mail at timgolden.me.uk Mon Mar 22 14:43:07 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 22 Mar 2010 18:43:07 +0000 Subject: short-circuiting any/all ? In-Reply-To: References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: <4BA7BA3B.2000006@timgolden.me.uk> On 22/03/2010 18:30, kj wrote: > Thanks! I'm glad to know that one can get the short circuiting > using a map-type idiom. (I prefer map over comprehensions when I > don't need to define a function just for the purpose of passing it > to it.) In what way does "map" over "comprehensions" save you defining a function? any (map (is_invalid, L)) any (is_invalid (i) for i in L) TJG From krister.svanlund at gmail.com Mon Mar 22 17:19:49 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 22 Mar 2010 22:19:49 +0100 Subject: Problem with sys.path when embedding Python3 in C Message-ID: <2cf430a61003221419t2192c9aajd3c2d2922b1d7f12@mail.gmail.com> Hi, I've recently begun experimenting with embedding python and i got a small problem. This is my current testing code (basically all from python docs): > int main(int argc, char *argv[]) > > { > > PyObject *pModuleName, *pTestModule, *pTestFunc, *pTestResult, *pTestArgs; > > PyImport_AppendInittab("node", &PyInit_node); > > Py_Initialize(); The following line here is the ugly-hack I had to do to make it work, nothing else I know of makes it possible to import modules from startup directory. So my question is: Is there a prettier way to do this? > PyRun_SimpleString("import sys\nsys.path.append(\"\")"); > > PyRun_SimpleString("import sys\nprint(sys.path)"); > > pModuleName = PyUnicode_FromString("stuff"); > > pTestModule = PyImport_Import(pModuleName); > > Py_DECREF(pModuleName); > > if (pTestModule != NULL) > > { ... The whole code is here: http://pastebin.com/805BSY8f You only need a file in the same directory called stuff.py containing a function def for a function called do_stuff From zookog at gmail.com Mon Mar 22 17:19:49 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Mon, 22 Mar 2010 15:19:49 -0600 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: My apologies; I left out the heading on the last of the four structures in the benchmark results. Here are those results again with the missing heading (Stringy) inserted: Regards, Zooko - Hide quoted text - On Sun, Mar 21, 2010 at 11:09 PM, Zooko O'Whielacronx wrote: > > impl: StringChain > task: _accumulate_then_one_gulp > 10000 best: 2.694e+00 > 50000 best: 2.742e+00 > 100000 best: 2.310e+00 > 500000 best: 2.040e+00 > 1000000 best: 1.988e+00 > 5000000 best: 2.193e+00 > > task: _alternate_str > 10000 best: 6.509e+00 > 50000 best: 4.559e+00 > 100000 best: 4.308e+00 > 500000 best: 4.070e+00 > 1000000 best: 3.991e+00 > 5000000 best: 4.000e+00 > > impl: SimplerStringChain > task: _accumulate_then_one_gulp > 10000 best: 1.407e+00 > 50000 best: 2.317e+00 > 100000 best: 2.012e+00 > 500000 best: 1.902e+00 > 1000000 best: 1.897e+00 > 5000000 best: 2.104e+00 > > task: _alternate_str > 10000 best: 4.888e+00 > 50000 best: 5.198e+00 > 100000 best: 1.750e+01 > 500000 best: 6.233e+01 > 1000000 best: 1.134e+02 > 5000000 best: 7.599e+02 > > impl: StringIOy > task: _accumulate_then_one_gulp > 10000 best: 4.196e+00 > 50000 best: 5.522e+00 > 100000 best: 4.499e+00 > 500000 best: 3.756e+00 > 1000000 best: 4.176e+00 > 5000000 best: 5.414e+00 > > task: _alternate_str > 10000 best: 5.484e+00 > 50000 best: 7.863e+00 > 100000 best: 2.126e+01 > 500000 best: 6.972e+01 > 1000000 best: 1.219e+02 > 5000000 best: 9.463e+02 > impl: Stringy - Hide quoted text - > task: _accumulate_then_one_gulp > 10000 best: 1.502e+00 > 50000 best: 1.420e+01 > 100000 best: 2.245e+01 > 500000 best: 8.577e+01 > 1000000 best: 2.295e+02 > 5000000 best: 1.326e+03 > > task: _alternate_str > 10000 best: 3.290e+00 > 50000 best: 4.220e+00 > 100000 best: 1.665e+01 > 500000 best: 6.281e+01 > 1000000 best: 1.127e+02 > 5000000 best: 7.626e+02 > From zookog at gmail.com Mon Mar 22 17:21:53 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Mon, 22 Mar 2010 15:21:53 -0600 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Mon, Mar 22, 2010 at 2:07 AM, Steven D'Aprano wrote: > > Perhaps you should have said that it was a wrapper around deque giving > richer functionality, rather than giving the impression that it was a > brand new data structure invented by you. People are naturally going to > be more skeptical about a newly invented data structure than one based on > a reliable, component like deque. The fact that StringChain uses deque to hold the queue of strings isn't that important. I just benchmarked it by swapping in the deque for a list and using the list costs about one third of a nanosecond per byte at the scales that the benchmark exercises (namely 10,000,000 bytes in about 10,000 strings). A third of a nanosecond per byte is about 4% of the runtime. I also implemented and benchmarked a simpler deque-based scheme which puts all the actual bytes from the strings into a deque with self.d.extend(newstr). As you would expect, this shows good asymptotic performance but the constants are relatively bad so that at all of the actual loads measured it was three orders of magnitude worse than StringChain and than String-Chain-with-a-list-instead-of-a-deque. Moral: the constants matter! Those benchmarks are appended. You can run the benchmarks yourself per the README.txt. But anyway, I take your point and I updated the StringChain README to explain that it is a pretty simple data structure that holds a list (actually a deque) of strings and isn't anything too clever or novel. By the way, we could further micro-optimize this kind of thing if ''.join() would accept either strings or buffers instead of requiring strings: >>> ''.join([buffer("abc"), "def"]) Traceback (most recent call last): File "", line 1, in TypeError: sequence item 0: expected string, buffer found Then whenever StringChain needs to slice a string into leading and trailing parts, it could construct a buffer() viewing each part instead of making a copy of each part. > it. Maybe you should consider linking to it on PyPI and seeing if there > is any interest from others? http://pypi.python.org/pypi/stringchain Regards, Zooko impl: StringChain task: _accumulate_then_one_gulp 10000 best: 5.698e+00, 3th-best: 7.486e+00, mean: 7.758e+00, 100000 best: 4.640e+00, 3th-best: 4.690e+00, mean: 7.674e+00, 1000000 best: 3.789e+00, 3th-best: 3.806e+00, mean: 3.995e+00, 10000000 best: 4.095e+00, 1th-best: 4.095e+00, mean: 4.095e+00, task: _alternate_str 10000 best: 1.378e+01, 3th-best: 1.390e+01, mean: 1.500e+01, 100000 best: 9.198e+00, 3th-best: 9.248e+00, mean: 9.385e+00, 1000000 best: 8.715e+00, 3th-best: 8.755e+00, mean: 8.808e+00, 10000000 best: 8.738e+00, 1th-best: 8.738e+00, mean: 8.738e+00, impl: StringChainWithList task: _accumulate_then_one_gulp 10000 best: 3.600e+00, 3th-best: 3.695e+00, mean: 4.129e+00, 100000 best: 4.070e+00, 3th-best: 4.079e+00, mean: 4.162e+00, 1000000 best: 3.662e+00, 3th-best: 3.688e+00, mean: 3.721e+00, 10000000 best: 3.902e+00, 1th-best: 3.902e+00, mean: 3.902e+00, 1th-worst: 3.902e+00, worst: 3.902e+00 (of 1) task: _alternate_str 10000 best: 1.369e+01, 3th-best: 1.380e+01, mean: 1.442e+01, 100000 best: 9.251e+00, 3th-best: 9.289e+00, mean: 9.416e+00, 1000000 best: 8.809e+00, 3th-best: 8.876e+00, mean: 8.943e+00, 10000000 best: 9.095e+00, 1th-best: 9.095e+00, mean: 9.095e+00, impl: Dequey task: _accumulate_then_one_gulp 10000 best: 2.772e+02, 3th-best: 2.785e+02, mean: 2.911e+02, 100000 best: 2.314e+02, 3th-best: 2.334e+02, mean: 2.422e+02, 1000000 best: 2.282e+02, 3th-best: 2.288e+02, mean: 2.370e+02, 10000000 best: 2.587e+02, 1th-best: 2.587e+02, mean: 2.587e+02, task: _alternate_str 10000 best: 1.576e+03, 3th-best: 1.580e+03, mean: 1.608e+03, 100000 best: 1.301e+03, 3th-best: 1.303e+03, mean: 1.306e+03, 1000000 best: 1.275e+03, 3th-best: 1.276e+03, mean: 1.278e+03, 10000000 best: 1.280e+03, 1th-best: 1.280e+03, mean: 1.280e+03, From no.email at please.post Mon Mar 22 18:16:09 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 22:16:09 +0000 (UTC) Subject: How to automate accessor definition? References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba79040$0$22397$426a74cc@news.free.fr> Message-ID: In <4ba79040$0$22397$426a74cc at news.free.fr> Bruno Desthuilliers writes: >kj a ?crit : >> PS: BTW, this is not the first time that attempting to set an >> attribute (in a class written by me even) blows up on me. It's >> situations like these that rattle my grasp of attributes, hence my >> original question about boring, plodding, verbose Java-oid accessors. >> For me these Python attributes are still waaay too mysterious and >> unpredictable to rely on. >Somehow simplified, here's what you have to know: ... >As I said, this is a somehow simplified description of the process - I >skipped the parts about __slots__, __getattribute__ and __setattr__, as >well as the part about how function class attributes become methods. >this should be enough to get an idea of what's going on. Thank you, sir! That was quite the education. (Someday I really should read carefully the official documentation for the stuff you described, assuming it exists.) Thanks also for your code suggestions. ~K From no.email at please.post Mon Mar 22 18:19:57 2010 From: no.email at please.post (kj) Date: Mon, 22 Mar 2010 22:19:57 +0000 (UTC) Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: In Tim Golden writes: >On 22/03/2010 18:30, kj wrote: >> Thanks! I'm glad to know that one can get the short circuiting >> using a map-type idiom. (I prefer map over comprehensions when I >> don't need to define a function just for the purpose of passing it >> to it.) >In what way does "map" over "comprehensions" save you defining a function? >any (map (is_invalid, L)) >any (is_invalid (i) for i in L) I was talking in the *general* case. map at the very least requires a lambda expression, which is a one-time function defintion. ~K From steve at holdenweb.com Mon Mar 22 19:17:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 22 Mar 2010 19:17:00 -0400 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <15025fc0-c697-4085-81a0-160882767540@15g2000yqi.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <15025fc0-c697-4085-81a0-160882767540@15g2000yqi.googlegroups.com> Message-ID: Luis M. Gonz?lez wrote: > On Feb 21, 6:40 pm, Mensanator wrote: >> On Feb 21, 12:14 pm, Paul Boddie wrote: >> >> >> >> >> >>> On 21 Feb, 17:32, Mensanator wrote: >>>> On Feb 21, 10:30 am, Mensanator wrote: >>>>> What versions of Python does it suuport? >>>> What OS are supported? >>> From the Web site referenced in the announcement (http:// >>> dreampie.sourceforge.net/): >>> """ >>> # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and >>> Python 3.1. >>> # Works on Windows and Linux. >>> """ >> Yeah, I saw that. Funny that something important like that wasn't part >> of the >> announcement. I notice no mention of Mac OS, so visiting the website >> was a complete >> waste of time on my part, wasn't it? >> >> >> >>> Paul > > Geez... someone spends many hours (or days or even months) writing a > program to be offered for free to the world, and you get annoyed by > losing two seconds while checking it out? And if it's open source there's always the possibility of doing a Mac port and contributing the code back. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tan at nowhere.land Mon Mar 22 19:40:16 2010 From: tan at nowhere.land (tan) Date: Mon, 22 Mar 2010 23:40:16 GMT Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: In article , Stefan Behnel wrote: >Lawrence D'Oliveiro, 22.03.2010 00:36: >> Terry Reedy wrote: >>> No one has discovered a setting >>> of the internal tuning parameters for which there are no bad patterns >>> and I suspect there are not any such. This does not negate Xavier's >>> suggestion that a code change might also solve your problem. >> >> Could it be that for implementing a structure like a trie as the OP is, >> where a lot of CPU cycles can be spent manipulating the structure, a high- >> level language like Python, Perl or Ruby just gets in the way? > >I would rather say that the specific problem of the trie data structure is >that it has extremely little benefit over other available data structures. Not true. >There may still be a couple of niches where it makes sense to consider it >as an alternative, but given that dicts are so heavily optimised in Python, >it'll be hard for tries to compete even when written in a low-level language. It depends. If your data is not in nearly sorted order, trees are some of the best mechanisms available. >Remember that the original use case was to load a dictionary from a text >file. For this use case, a trie can be very wasteful in terms of memory and >rather CPU cache unfriendly on traversal, whereas hash values are a) rather >fast to calculate for a string, and b) often just calculated once and then >kept alive in the string object for later reuse. You still have to walk the bucket in a hash map/table. Performance may be orders of magnitude worse than for trees. >> My feeling would be, try to get the language to do as much of the work for >> you as possible. If you can???t do that, then you might be better off with a >> lower-level language. > >I agree with the first sentence, but I'd like to underline the word 'might' >in the second. As this newsgroup shows, very often it's enough to look for >a better algorithmic approach first. > >Stefan > -- You want to know who you are? http://oshosearch.net/Convert/search.php Most Osho books on line: http://oshosearch.net From vlastimil.brom at gmail.com Mon Mar 22 20:19:04 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 23 Mar 2010 01:19:04 +0100 Subject: individually updating unicodedata db? Message-ID: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Hi all, I just tried to find some information about the unicodedata database and the possibilities of updating it to the latest version of the unicode standards (currently 5.2, while python supports 5.1 in the latest versions). An option to update this database individually might be useful as the unicode standard updates seem to be more frequent than the official python releases (and not every release is updated to the latest available unicode db version either). Am I right, that this is not possible without recompiling python from source? I eventually found the promissing file ...Python-src--2.6.5\Python-2.6.5\Tools\unicode\makeunicodedata.py which required the following files from the unicode database to be in the same folder: EastAsianWidth-3.2.0.txt UnicodeData-3.2.0.txt CompositionExclusions-3.2.0.txt UnicodeData.txt EastAsianWidth.txt CompositionExclusions.txt and also Modules/unicodedata_db.h Modules/unicodename_db.h, Objects/unicodetype_db.h After a minor correction - addig the missing "import re" - the script was able to run and recreate the above h files. I guess, I am stuck here, as I use the precompiled version supplied in the windows installer and can't compile python from source to obtain the needed unicodedata.pyd. Or are there any possibilities I missed to individually upgrade the unicodedata databese? (Using Python 2.6.5, Win XPh SP3) Thanks in advance for any hints, vbr From hawat.thufir at gmail.com Mon Mar 22 20:23:27 2010 From: hawat.thufir at gmail.com (Thufir) Date: Mon, 22 Mar 2010 17:23:27 -0700 (PDT) Subject: google token References: <4ba49f98$0$27838$c3e8da3@news.astraweb.com> Message-ID: <4f5d2017-8d64-4d4c-b013-b49b4c199005@v20g2000prc.googlegroups.com> On Mar 20, 3:12 am, Steven D'Aprano wrote: > On Sat, 20 Mar 2010 09:17:14 +0000, Thufir wrote: > > I'd like to acquire a token, as below, but from Java: > > Perhaps you should be asking a Java discussion group? This group is for > discussing Python. > > -- > Steven What I meant to ask is, how is that token being acquired? Is that just a GET? thanks, Thufir From python at mrabarnett.plus.com Mon Mar 22 21:27:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Mar 2010 01:27:28 +0000 Subject: individually updating unicodedata db? In-Reply-To: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> References: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Message-ID: <4BA81900.6000505@mrabarnett.plus.com> Vlastimil Brom wrote: > Hi all, > I just tried to find some information about the unicodedata database > and the possibilities of updating it to the latest version of the > unicode standards (currently 5.2, while python supports 5.1 in the > latest versions). > An option to update this database individually might be useful as the > unicode standard updates seem to be more frequent than the official > python releases (and not every release is updated to the latest > available unicode db version either). > Am I right, that this is not possible without recompiling python from source? > I eventually found the promissing file > ...Python-src--2.6.5\Python-2.6.5\Tools\unicode\makeunicodedata.py > which required the following files from the unicode database to be in > the same folder: > EastAsianWidth-3.2.0.txt > UnicodeData-3.2.0.txt > CompositionExclusions-3.2.0.txt > UnicodeData.txt > EastAsianWidth.txt > CompositionExclusions.txt > > and also > Modules/unicodedata_db.h > Modules/unicodename_db.h, > Objects/unicodetype_db.h > > After a minor correction - addig the missing "import re" - the script > was able to run and recreate the above h files. > I guess, I am stuck here, as I use the precompiled version supplied in > the windows installer and can't compile python from source to obtain > the needed unicodedata.pyd. > Or are there any possibilities I missed to individually upgrade the > unicodedata databese? (Using Python 2.6.5, Win XPh SP3) > > Thanks in advance for any hints, > vbr From the look of it the Unicode data is compiled into the DLL, but I don't see any reason, other than speed, why preprocessed data couldn't be read from a file at startup by the DLL, provided that the format hasn't changed, eg new fields added, without affecting the DLL's interface to the rest of Python. From steven at REMOVE.THIS.cybersource.com.au Mon Mar 22 21:30:37 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Mar 2010 01:30:37 GMT Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: On Mon, 22 Mar 2010 22:19:57 +0000, kj wrote: > In Tim Golden > writes: > >>On 22/03/2010 18:30, kj wrote: >>> Thanks! I'm glad to know that one can get the short circuiting using >>> a map-type idiom. (I prefer map over comprehensions when I don't need >>> to define a function just for the purpose of passing it to it.) > >>In what way does "map" over "comprehensions" save you defining a >>function? > >>any (map (is_invalid, L)) >>any (is_invalid (i) for i in L) > > I was talking in the *general* case. map at the very least requires a > lambda expression, which is a one-time function defintion. But keep in mind that instead of this: map(lambda x,y: x+y, somelist) you can do this: import operator map(operator.add, somelist) In any case, the once-off cost of creating or importing a function is usually quite cheap. As usual, the best advise is not to worry about optimization until you have profiled the code and learned where the actual bottlenecks are. Write what reads best, not what you guess might be faster, until you really know you need the speed and that it is an optimization and not a pessimation. -- Steven From solipsis at pitrou.net Mon Mar 22 22:11:57 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 23 Mar 2010 02:11:57 +0000 (UTC) Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: Le Mon, 22 Mar 2010 23:40:16 +0000, tan a ?crit?: > >>Remember that the original use case was to load a dictionary from a text >>file. For this use case, a trie can be very wasteful in terms of memory >>and rather CPU cache unfriendly on traversal, whereas hash values are a) >>rather fast to calculate for a string, and b) often just calculated once >>and then kept alive in the string object for later reuse. > > You still have to walk the bucket in a hash map/table. Performance may > be orders of magnitude worse than for trees. "walk the bucket" shouldn't be a significant cost factor here, especially if you are doing meaningful work with the traversed items. In the CPython implementation the total hash table size is less than a constant times the number of actual items. Moreover, it's a linear scan over an array rather than having to dereference pointers as in tree. "Orders of magnitude worse", in any case, sounds very exaggerated. (and, of course, as the OP said, there's the major difference that the dict type is implemented in C, which makes constant factors an order of magnitude smaller than for a Python trie implementation) From no.email at please.post Mon Mar 22 22:26:20 2010 From: no.email at please.post (kj) Date: Tue, 23 Mar 2010 02:26:20 +0000 (UTC) Subject: short-circuiting any/all ? References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: In Steven D'Aprano writes: >On Mon, 22 Mar 2010 22:19:57 +0000, kj wrote: >In any case, the once-off cost of creating or importing a function is >usually quite cheap. As usual, the best advise is not to worry about >optimization until you have profiled the code and learned where the >actual bottlenecks are. Write what reads best, not what you guess might >be faster, until you really know you need the speed and that it is an >optimization and not a pessimation. My preference for map in this case is not due to performance considerations, but to avoid unnecessary code-clutter. I just find, e.g., x = map(int, y) slightly easier on the eyes than x = [int(z) for z in y] This tiny improvement in readability gets negated if one needs to define a function in order to use map. Hence, e.g., I prefer x = [_[0] for _ in y] over x = map(lambda _: _[0], y) and certainly over def _first(seq): return seq[0] x = map(_first, y) Arguably, Knuth's "premature optimization is the root of all evil" applies even to readability (e.g. "what's the point of making code optimally readable if one is going to change it completely next day?") If there were the equivalent of a profiler for code clutter, I guess I could relax my readability standards a bit... ~K From rami.chowdhury at gmail.com Mon Mar 22 22:59:18 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 22 Mar 2010 19:59:18 -0700 Subject: google token In-Reply-To: <4f5d2017-8d64-4d4c-b013-b49b4c199005@v20g2000prc.googlegroups.com> References: <4ba49f98$0$27838$c3e8da3@news.astraweb.com> <4f5d2017-8d64-4d4c-b013-b49b4c199005@v20g2000prc.googlegroups.com> Message-ID: <201003221959.19307.rami.chowdhury@gmail.com> On Monday 22 March 2010 17:23:27 Thufir wrote: > On Mar 20, 3:12 am, Steven D'Aprano > cybersource.com.au> wrote: > > On Sat, 20 Mar 2010 09:17:14 +0000, Thufir wrote: > > > I'd like to acquire a token, as below, but from Java: > > Perhaps you should be asking a Java discussion group? This group is for > > discussing Python. > > > > -- > > Steven > > What I meant to ask is, how is that token being acquired? Is that > just a GET? > Looks like it -- a urllib2 request, anyway -- the self._web object is defined here: http://pyrfeed.googlecode.com/svn/trunk/lib/web/web.py > > > thanks, > > Thufir ---- Rami Chowdhury "Any sufficiently advanced incompetence is indistinguishable from malice." -- Grey's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From timr at probo.com Tue Mar 23 00:22:28 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Mar 2010 21:22:28 -0700 Subject: device identification References: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> Message-ID: <46ggq59e49qpna7f9ae6q8ftobhot351un@4ax.com> Omer Ihsan wrote: > >i have installed pyusb now and run the sample usbenum.py....i have 3 >usb ports on my PC but the results show 6 outputs to >dev.filename..they are numbers like 001 or 005 etc.... and they >changed when i plugged in devices...(i am no good with the usb >standards)....i just want to identify each device/port... what >parameter in the example would help me.... You can't identify the ports.[1] What good would it do you? The ports on your PC are not numbered. You certainly CAN identify the devices, by their VID and PID (or idVendor and idProduct). You identify by function, not by location. When you plug in a USB drive, you don't want to worry about where it's plugged in. === [1]: OK, technically, it is not impossible to identify the port numbers, but it is quite tedious. You need to chase through the sysfs expansion of your buses hub/port tree and find a match for your device. It's not worth the trouble. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From no.email at nospam.invalid Tue Mar 23 01:05:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Mar 2010 22:05:40 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Antoine Pitrou writes: > "Orders of magnitude worse", in any case, sounds very exaggerated. The worst case can lose orders of magnitude if a lot of values hash to the same bucket. From gagsl-py2 at yahoo.com.ar Tue Mar 23 02:12:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Mar 2010 03:12:54 -0300 Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> Message-ID: En Mon, 22 Mar 2010 15:20:39 -0300, Pascal Chambon escribi?: > > Allright, here is more concretely the problem : > > ERROR:root:An error > Traceback (most recent call last): > File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c > return d() > File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d > def d(): raise ValueError > ValueError > >>> > > As you see, the traceback only starts from function c, which handles the > exception. > It doesn't show main(), a() and b(), which might however be (and are, in > my case) critical to diagnose the severity of the problem (since many > different paths would lead to calling c()). > > So the question is : is that possible to enforce, by a way or another, > the retrieval of the FULL traceback at exception raising point, instead > of that incomplete one ? Thanks for bringing this topic! I learned a lot trying to understand what happens. The exception traceback (what sys.exc_info()[2] returns) is *not* a complete stack trace. The sys module documentation is wrong [1] when it says "...encapsulates the call stack at the point where the exception originally occurred." The Language Reference is more clear [2]: "Traceback objects represent a stack trace of an exception. A traceback object is created when an exception occurs. When the search for an exception handler unwinds the execution stack, at each unwound level a traceback object is inserted in front of the current traceback. When an exception handler is entered, the stack trace is made available to the program." That is, a traceback holds only the *forward* part of the stack: the frames already exited when looking for an exception handler. Frames going from the program starting point up to the current execution point are *not* included. Conceptually, it's like having two lists: stack and traceback. The complete stack trace is always stack+traceback. At each step (when unwinding the stack, looking for a frame able to handle the current exception) an item is popped from the top of the stack (last item) and inserted at the head of the traceback. The traceback holds the "forward" path (from the current execution point, to the frame where the exception was actually raised). It's a linked list, its tb_next attribute holds a reference to the next item; None marks the last one. The "back" path (going from the current execution point to its caller and all the way to the program entry point) is a linked list of frames; the f_back attribute points to the previous one, or None. In order to show a complete stack trace, one should combine both. The traceback module contains several useful functions: extract_stack() + extract_tb() are a starting point. The simplest way I could find to make the logging module report a complete stack is to monkey patch logging.Formatter.formatException so it uses format_exception() and format_stack() combined (in fact it is simpler than the current implementation using a StringIO object): import logging import traceback def formatException(self, ei): """ Format and return the specified exception information as a string. This implementation builds the complete stack trace, combining traceback.format_exception and traceback.format_stack. """ lines = traceback.format_exception(*ei) if ei[2]: lines[1:1] = traceback.format_stack(ei[2].tb_frame.f_back) return ''.join(lines) # monkey patch the logging module logging.Formatter.formatException = formatException def a(): return b() def b(): return c() def c(): try: return d() except: logging.exception("An error") raise def d(): raise ValueError def main(): a() main() Output: ERROR:root:An error Traceback (most recent call last): File "test_logging.py", line 32, in main() File "test_logging.py", line 30, in main a() File "test_logging.py", line 19, in a def a(): return b() File "test_logging.py", line 20, in b def b(): return c() File "test_logging.py", line 23, in c return d() File "test_logging.py", line 27, in d def d(): raise ValueError ValueError Traceback (most recent call last): File "test_logging.py", line 32, in main() File "test_logging.py", line 30, in main a() File "test_logging.py", line 19, in a def a(): return b() File "test_logging.py", line 20, in b def b(): return c() File "test_logging.py", line 23, in c return d() File "test_logging.py", line 27, in d def d(): raise ValueError ValueError Note that both tracebacks are identical: the first comes from the patched logging module, the second is the standard Python one. [1] http://docs.python.org/library/sys.html#sys.exc_info [2] http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Tue Mar 23 02:32:13 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Mar 2010 06:32:13 GMT Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 22 Mar 2010 22:05:40 -0700, Paul Rubin wrote: > Antoine Pitrou writes: >> "Orders of magnitude worse", in any case, sounds very exaggerated. > > The worst case can lose orders of magnitude if a lot of values hash to > the same bucket. Well, perhaps one order of magnitude. >>> for i in xrange(100): ... n = 32*i+1 ... assert hash(2**n) == hash(2) ... >>> d1 = dict.fromkeys(xrange(100)) >>> d2 = dict.fromkeys([2**(32*i+1) for i in xrange(100)]) >>> >>> from timeit import Timer >>> setup = "from __main__ import d1, d2" >>> t1 = Timer("for k in d1.keys(): x = d1[k]", setup) >>> t2 = Timer("for k in d2.keys(): x = d2[k]", setup) >>> >>> min(t1.repeat(number=1000, repeat=5)) 0.026707887649536133 >>> min(t2.repeat(number=1000, repeat=5)) 0.33103203773498535 -- Steven From gagsl-py2 at yahoo.com.ar Tue Mar 23 03:07:47 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Mar 2010 04:07:47 -0300 Subject: Problem with sys.path when embedding Python3 in C References: <2cf430a61003221419t2192c9aajd3c2d2922b1d7f12@mail.gmail.com> Message-ID: En Mon, 22 Mar 2010 18:19:49 -0300, Krister Svanlund escribi?: > Hi, I've recently begun experimenting with embedding python and i got > a small problem. > > The following line here is the ugly-hack I had to do to make it work, > nothing else I know of makes it possible to import modules from > startup directory. So my question is: Is there a prettier way to do > this? The startup directory is not included in the module search path - neither in your embedded version, nor in the standard interpreter (it's only included when running in interactive mode). >> PyRun_SimpleString("import sys\nsys.path.append(\"\")"); If you really want the current directory in sys.path, use the getcwd function to obtain it. But make sure this is what you want - the directory containing the executable might be a better choice (at least more predictable). Note that Python already provides lots of ways to add directories to sys.path (the default search path (see site.py), per-user site directories (see PEP370), .pth files, the PYTHONPATH and PYTHONHOME environment variables, the Windows registry, other ways I forgot...) So I'd ask why do you want to add a non-standard one. In C code, you can alter the initial search path by setting Py_SetProgramName and Py_SetPythonHome. And you may even completely replace getpathp.c source file with your own. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 23 03:22:59 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 23 Mar 2010 04:22:59 -0300 Subject: individually updating unicodedata db? References: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Message-ID: En Mon, 22 Mar 2010 21:19:04 -0300, Vlastimil Brom escribi?: > I guess, I am stuck here, as I use the precompiled version supplied in > the windows installer and can't compile python from source to obtain > the needed unicodedata.pyd. You can recompile Python from source, on Windows, using the free Microsoft? Visual C++? 2008 Express Edition. http://www.microsoft.com/express/Windows/ Fetch the required dependencies using Tools\buildbot\external.bat, and then execute PCbuild\env.bat and build.bat. See readme.txt in that directory for details. It should build cleanly. -- Gabriel Genellina From vinay_sajip at yahoo.co.uk Tue Mar 23 04:10:36 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 23 Mar 2010 01:10:36 -0700 (PDT) Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: On Mar 20, 8:36?am, Peter Otten <__pete... at web.de> wrote: > Jean-Michel Pichavant wrote: > > You are still accessing the private attribute of the ?modulelogging. > > Just reading it is a significantly more conservative approach than setting > it to an object with an unusual notion of equality ;) > > > My previous remark was misleading, in fact there's nothing you can do > > about it. > > How about replacinglogging._srcfile with fixname(logging.__file__)? > > > _srcfile is not meant to be used elsewhere than in theloggingmodule > > itself. > > However, I don't wanna sound like I'm rejecting this solution, 1st the > > OP is satisified with it and since this solution is working, it is still > > more helpful than anyone noticing that you've accessed a private > > attribute (some will successfully argue that python allows to do so). > > Yeah, I had hoped that I could get away without drawing the "consenting > adults" wildcard... > > > At the very begining of this thread I've provided a complete different > > approach, instead of using the builtin 'filename' and 'lineno' field of > > thelogging, use custom fileds with the extra parameter. > > > It has also some drawbacks but could be a possible alternative. > > Having two filename/lineno sets ist likely to confuse. > > Peter Guys, Sorry I'm a little late to this discussion. I could add a _findCaller function to the module (not part of the public API, but replaceable by someone who really needs to) which does the heavy lifting, and Logger.findCaller just calls it. Then those who need to can implement their own strategy, without needing to jump through hoops. Does that approach sound helpful? Regards, Vinay Sajip From no.email at nospam.invalid Tue Mar 23 04:17:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Mar 2010 01:17:32 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: <7xr5nbwixv.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Well, perhaps one order of magnitude. >>>> for i in xrange(100): > ... n = 32*i+1 > ... assert hash(2**n) == hash(2) Try with much more than 100 items (you might want to construct the entries a little more intricately to avoid such big numbers). The point is that access becomes O(N) instead of O(1). See: http://www.cs.rice.edu/~scrosby/hash/ for the consequences. http://cr.yp.to/critbit.html discusses the issue a little more. From __peter__ at web.de Tue Mar 23 04:43:54 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Mar 2010 09:43:54 +0100 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: Steven D'Aprano wrote: > On Mon, 22 Mar 2010 22:05:40 -0700, Paul Rubin wrote: > >> Antoine Pitrou writes: >>> "Orders of magnitude worse", in any case, sounds very exaggerated. >> >> The worst case can lose orders of magnitude if a lot of values hash to >> the same bucket. > > > Well, perhaps one order of magnitude. > > >>>> for i in xrange(100): > ... n = 32*i+1 > ... assert hash(2**n) == hash(2) > ... >>>> d1 = dict.fromkeys(xrange(100)) >>>> d2 = dict.fromkeys([2**(32*i+1) for i in xrange(100)]) >>>> >>>> from timeit import Timer >>>> setup = "from __main__ import d1, d2" >>>> t1 = Timer("for k in d1.keys(): x = d1[k]", setup) >>>> t2 = Timer("for k in d2.keys(): x = d2[k]", setup) >>>> >>>> min(t1.repeat(number=1000, repeat=5)) > 0.026707887649536133 >>>> min(t2.repeat(number=1000, repeat=5)) > 0.33103203773498535 But the ratio grows with the number of collisions: $ python extrapolate.py 10 0.00120401382446 0.00753307342529 ratio: 6.25663366337 100 0.00542402267456 0.316139936447 ratio: 58.2851428571 1000 0.00553417205811 3.36690688133 ratio: 608.384930209 $ cat extrapolate.py from timeit import Timer class Item(object): def __init__(self, value, hash=None): self.value = value self.hash = value if hash is None else hash def __eq__(self, other): return self.value == other.value def __hash__(self): return self.hash setup = "from __main__ import d" bench = "for k in d: x = d[k]" for n, number in (10,100), (100,100), (1000,10): print n d1 = dict.fromkeys(Item(i) for i in xrange(n)) d2 = dict.fromkeys(Item(i, 0) for i in xrange(n)) ab = [] for d in d1, d2: t = Timer(bench, setup) ab.append(min(t.repeat(number=number, repeat=3))) print ab[-1] print "ratio:", ab[1]/ab[0] print See also http://xkcd.com/605/ Peter From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 23 05:13:05 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 23 Mar 2010 10:13:05 +0100 Subject: How to automate accessor definition? In-Reply-To: <4ba7aa87$0$4974$607ed4bc@cv.net> References: <639908184290880449.447600deets-nospam.web.de@news.hansenet.de> <4ba79040$0$22397$426a74cc@news.free.fr> <4ba7aa87$0$4974$607ed4bc@cv.net> Message-ID: <4ba8861b$0$17824$426a74cc@news.free.fr> John Posner a ?crit : > On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote: > > > >> Another (better IMHO) solution is to use a plain property, and store the >> computed value as an implementation attribute : >> >> @property >> def foo(self): >> cached = self.__dict__.get('_foo_cache') >> if cached is None: >> self._foo_cache = cached = self._some_time_consuming_operation() >> return cached >> > > There's no need to access __dict__ directly. Nope, inded. I guess I wrote it that way to make clear that we were looking for an instance attribute (as a sequel of my previous writing on attribute lookup rules). > I believe this is > equivalent (and clearer): > > @property > def foo(self): > try: > cached = self._foo_cache > except AttributeError: > self._foo_cache = cached = self._time_consuming_op() > return cached > This is functionally _almost_ equivalent - won't work the same if there's a class attribute "_foo_cache", which might or not be a good thing !-) Will possibly be a bit faster after the first access - IIRC setting up an error handler is by itself cheaper than doing a couple attribute access and a method call - but I'd timeit before worrying about it. From krister.svanlund at gmail.com Tue Mar 23 05:23:53 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 23 Mar 2010 10:23:53 +0100 Subject: Problem with sys.path when embedding Python3 in C In-Reply-To: References: <2cf430a61003221419t2192c9aajd3c2d2922b1d7f12@mail.gmail.com> Message-ID: <2cf430a61003230223i32c06f01je20e698c119b1bb1@mail.gmail.com> On Tue, Mar 23, 2010 at 8:07 AM, Gabriel Genellina wrote: > En Mon, 22 Mar 2010 18:19:49 -0300, Krister Svanlund > escribi?: > >> Hi, I've recently begun experimenting with embedding python and i got >> a small problem. >> >> The following line here is the ugly-hack I had to do to make it work, >> nothing else I know of makes it possible to import modules from >> startup directory. So my question is: Is there a prettier way to do >> this? > > The startup directory is not included in the module search path - neither in > your embedded version, nor in the standard interpreter (it's only included > when running in interactive mode). > >>> PyRun_SimpleString("import sys\nsys.path.append(\"\")"); > > If you really want the current directory in sys.path, use the getcwd > function to obtain it. But make sure this is what you want - the directory > containing the executable might be a better choice (at least more > predictable). > Note that Python already provides lots of ways to add directories to > sys.path (the default search path (see site.py), per-user site directories > (see PEP370), .pth files, the PYTHONPATH and PYTHONHOME environment > variables, the Windows registry, other ways I forgot...) So I'd ask why do > you want to add a non-standard one. > > In C code, you can alter the initial search path by setting > ?Py_SetProgramName and Py_SetPythonHome. And you may even completely replace > getpathp.c source file with your own. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > The thing is that I want the application to be able to import modules I've written, but yeah, the applications directory is what I want rather than the cwd. I have tried Py_SetProgramName but haven't gotten it to work or cause any change at all to the import behaviour. Could you possibly provide som sort of example? From no.email at nospam.invalid Tue Mar 23 05:57:56 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Mar 2010 02:57:56 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: <7xpr2v2wd7.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > While this is theoretically true, and it's good to be aware of this > possibility, common string hash functions make it so rare in practice > that a hash table will almost always outperform a trie for exact > lookups. If it happens, it will either show up clearly enough in > benchmarks or not be worth bothering. It is unlikely to happen by accident. You might care that it can happen on purpose. See: http://www.cs.rice.edu/~scrosby/hash/ that I cited in another post. The article shows some sample attacks on Python cgi's. From stefan_ml at behnel.de Tue Mar 23 06:05:36 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Mar 2010 11:05:36 +0100 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: <7xwrx3mxuj.fsf@ruckus.brouhaha.com> References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin, 23.03.2010 06:05: > Antoine Pitrou writes: >> "Orders of magnitude worse", in any case, sounds very exaggerated. > > The worst case can lose orders of magnitude if a lot of values hash > to the same bucket. While this is theoretically true, and it's good to be aware of this possibility, common string hash functions make it so rare in practice that a hash table will almost always outperform a trie for exact lookups. If it happens, it will either show up clearly enough in benchmarks or not be worth bothering. Stefan From python at hope.cz Tue Mar 23 06:48:38 2010 From: python at hope.cz (Johny) Date: Tue, 23 Mar 2010 03:48:38 -0700 (PDT) Subject: How to find the best solution ? Message-ID: I have a text and would like to split the text into smaller parts, say into 100 characters each. But if the 100th character is not a blank ( but word) this must be less than 100 character.That means the word itself can not be split. These smaller parts must contains only whole( not split) words. I was thinking about RegEx but do not know how to find the correct Regular Expression. Can anyone help? Thanks L. From mail at timgolden.me.uk Tue Mar 23 06:54:33 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 10:54:33 +0000 Subject: How to find the best solution ? In-Reply-To: References: Message-ID: <4BA89DE9.5080001@timgolden.me.uk> On 23/03/2010 10:48, Johny wrote: > I have a text and would like to split the text into smaller parts, > say into 100 characters each. But if the 100th character is not a > blank ( but word) this must be less than 100 character.That means the > word itself can not be split. > These smaller parts must contains only whole( not split) words. > I was thinking about RegEx but do not know how to find the correct > Regular Expression. > Can anyone help? > Thanks > L. Have a look at the textwrap module TJG From alfps at start.no Tue Mar 23 06:54:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Mar 2010 11:54:45 +0100 Subject: Some silly code for Easter holiday Message-ID: This program simulates some colored balls moving around, changing color according to certain rules. I think the most interesting is perhaps to not look at this code but just try to run it and figure out the color changing rules from observing the effect (extra mystery: why I wrote this). Sort of like an Easter holiday mystery. # Py3 # Copyright 2010 Alf P. Steinbach import tkinter as tk from collections import namedtuple import random Point = namedtuple( "Point", "x, y" ) Size = namedtuple( "Size", "x, y" ) RGB = namedtuple( "RGB", "r, g, b" ) def generator( g ): assert isinstance( g, type( (i for i in ()) ) ) return g def tk_internal_bbox_from( bbox: tuple ): return ((bbox[0], bbox[1], bbox[2]+2, bbox[3]+2)) def tk_new_ellipse( canvas, bbox: tuple, **kwargs ): return canvas.create_oval( tk_internal_bbox_from( bbox ), **kwargs ) class TkTimer: def __init__( self, widget, msecs: int, action, start_running: bool = True ): self._widget = widget self._msecs = msecs self._action = action self._id = None if start_running: self.start() def start( self ): self._id = self._widget.after( self._msecs, self._on_timer ) def stop( self ): id = self._id; self._id = None self._widget.after_cancel( id ) # Try to cancel last event. def _on_timer( self ): if self._id is not None: self._action() self.start() class TkEllipse: def __init__( self, canvas, bbox: tuple, **kwargs ): self._canvas = canvas self._id = tk_new_ellipse( canvas, bbox, **kwargs ) @property # id def id( self ): return self._id @property # fill def fill( self ): return self._canvas.itemcget( self._id, "fill" ) @fill.setter def fill( self, color_representation: str ): self._canvas.itemconfigure( self._id, fill = color_representation ) @property # internal_bbox def internal_bbox( self ): return tuple( self._canvas.coords( self._id ) ) @property # position def position( self ): bbox = self.internal_bbox return Point( bbox[0], bbox[1] ) @position.setter def position( self, new_pos: Point ): bbox = self.internal_bbox (dx, dy) = (new_pos.x - bbox[0], new_pos.y - bbox[1]) self._canvas.move( self._id, dx, dy ) #assert self.position == new_pos class Color: def __init__( self, rgb_or_name ): if isinstance( rgb_or_name, RGB ): name = None rgb = rgb_or_name else: assert isinstance( rgb_or_name, str ) name = rgb_or_name rgb = None self._name = name self._rgb = rgb @property def representation( self ): if self._name is not None: return self._name else: rgb = self._rgb return "#{:02X}{:02X}{:02X}".format( rgb.r, rgb.g, rgb.b ) def __str__( self ): return self.representation def __hash__( self ): return hash( self.representation ) class Rectangle: def __init__( self, width : int, height : int, upper_left : Point = Point( 0, 0 ) ): self._left = upper_left.x self._right = upper_left.x + width self._top = upper_left.y self._bottom = upper_left.y + height @property # left def left( self ): return self._left @property # top def top( self ): return self._top @property # right def right( self ): return self._right @property # bottom def bottom( self ): return self._bottom @property # width def width( self ): return self._right - self._left @property # height def height( self ): return self._bottom - self._top @property # size def size( self ): return Size( self.width, self.height ) class Ball: def __init__( self, color : Color, position : Point = Point( 0, 0 ), velocity : Point = Point( 0, 0 ) ): self.color = color self.position = position self.velocity = velocity def squared_distance_to( self, other ): p1 = self.position p2 = other.position return (p2.x - p1.x)**2 + (p2.y - p1.y)**2 class BallSim: def __init__( self, rect : Rectangle, n_balls : int = 1 ): def random_pos(): return Point( random.randrange( rect.left, rect.right ), random.randrange( rect.top, rect.bottom ) ) def random_velocity(): return Point( random.randint( -10, 10 ), random.randint( -10, 10 ) ) def balls( color ): return generator( Ball( color, random_pos(), random_velocity() ) for i in range( n_balls ) ) self._rect = rect self._kind_1_color = Color( "blue" ) self._kind_2_color = Color( "orange" ) self._balls = tuple( balls( self._kind_1_color ) ) self._is_close_distance = 20; @property # rect def rect( self ): return self._rect @property # interaction_radius def interaction_radius( self ): return self._is_close_distance @property # n_balls def n_balls( self ): return len( self._balls ) def ball( self, i ): return self._balls[i] def balls( self ): return self._balls def _update_positions_and_velocities( self ): rect = self._rect for ball in self._balls: pos = ball.position; v = ball.velocity; pos = Point( pos.x + v.x, pos.y + v.y ) if pos.x < 0: pos = Point( -pos.x, pos.y ) v = Point( -v.x, v.y ) if pos.x >= rect.width: pos = Point( 2*rect.width - pos.x, pos.y ) v = Point( -v.x, v.y ) if pos.y < 0: pos = Point( pos.x, -pos.y ) v = Point( v.x, -v.y ) if pos.y >= rect.height: pos = Point( pos.x, 2*rect.height - pos.y ) v = Point( v.x, -v.y ) ball.position = pos ball.velocity = v def _balls_possibly_close_to( self, ball ): max_d_squared = self._is_close_distance**2 result = [] for other in self._balls: if other is ball: continue if ball.squared_distance_to( other ) <= max_d_squared: result.append( other ) return result def _update_kinds( self ): max_d_squared = self._is_close_distance**2 for ball in self._balls: if ball.color == self._kind_1_color: for other_ball in self._balls_possibly_close_to( ball ): if ball.squared_distance_to( other_ball ) <= max_d_squared: if other_ball.color == self._kind_1_color: ball.color = self._kind_2_color other_ball.color = self._kind_2_color break else: if random.random() < 0.01: ball.color = self._kind_1_color def evolve( self ): self._update_positions_and_velocities() self._update_kinds() class View: def _create_widgets( self, parent_widget, sim: BallSim ): self.widget = tk.Frame( parent_widget ) if True: canvas = tk.Canvas( self.widget, bg = "white", width = sim.rect.width, height = sim.rect.height ) canvas.pack() self._canvas = canvas self._circles = [] radius = sim.interaction_radius // 2 self._ball_radius = radius for ball in sim.balls(): (x, y) = (ball.position.x, ball.position.y) bbox = (x - radius, y - radius, x + radius, y + radius) ellipse = TkEllipse( canvas, bbox, fill = ball.color.representation ) self._circles.append( ellipse ) pass def __init__( self, parent_widget, sim: BallSim ): self._create_widgets( parent_widget, sim ) self._sim = sim def update( self ): sim = self._sim r = self._ball_radius for (i, ball) in enumerate( sim.balls() ): center_pos = ball.position self._circles[i].position = Point( center_pos.x - r, center_pos.y - r ) self._circles[i].fill = ball.color class Controller: def __init__( self, main_window ): self._window = main_window self._model = BallSim( Rectangle( 600, 500 ), n_balls = 20 ) self._view = view = View( main_window, self._model ) view.widget.place( relx = 0.5, rely = 0.5, anchor="center" ) self._timer = TkTimer( main_window, msecs = 42, action = self._on_timer ) def _on_timer( self ): self._model.evolve() self._view.update() def main(): window = tk.Tk() window.title( "Sim 1 -- Chameleon Balls" ) window.geometry( "640x510" ) controller = Controller( window ) window.mainloop() main() Cheers, - Alf From jeanmichel at sequans.com Tue Mar 23 06:55:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 23 Mar 2010 11:55:16 +0100 Subject: short-circuiting any/all ? In-Reply-To: References: <291d82b7-b13b-4f49-901c-8194f3e07598@e7g2000yqf.googlegroups.com> Message-ID: <4BA89E14.3050507@sequans.com> kj wrote: > Arguably, Knuth's "premature optimization is the root of all evil" > applies even to readability (e.g. "what's the point of making code > optimally readable if one is going to change it completely next > day?") The guy who will change it will have to read it. The only waste would be if the code would never be read again. > If there were the equivalent of a profiler for code clutter, > I guess I could relax my readability standards a bit... > > ~K > Don't relax, just keep up :o) JM From alexandre.fayolle at logilab.fr Tue Mar 23 07:48:44 2010 From: alexandre.fayolle at logilab.fr (Alexandre Fayolle) Date: Tue, 23 Mar 2010 12:48:44 +0100 Subject: ANN: Pylint bug day, 2nd edition In-Reply-To: <201003221838.07672.alexandre.fayolle@logilab.fr> References: <201003221838.07672.alexandre.fayolle@logilab.fr> Message-ID: <201003231248.44408.alexandre.fayolle@logilab.fr> On Monday 22 March 2010 18:38:07 Alexandre Fayolle wrote: > .. _pylint bugs day: https://www.logilab.net/elo/blogentry/18781 Correct link is : http://www.logilab.org/blogentry/18781 Sorry for the inconvenience. -- Alexandre Fayolle LOGILAB, Paris (France) Formations Python, CubicWeb, Debian : http://www.logilab.fr/formations D?veloppement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique: http://www.logilab.fr/science From phil at freehackers.org Tue Mar 23 08:38:37 2010 From: phil at freehackers.org (BlueBird) Date: Tue, 23 Mar 2010 05:38:37 -0700 (PDT) Subject: SOAP 1.2 Python client ? References: <5a36bd30-6cbd-48ca-9ca3-dc34c97e03c0@o30g2000yqb.googlegroups.com> <13753751-d0af-48df-b78d-5b371109e05c@t41g2000yqt.googlegroups.com> Message-ID: On 5 mar, 13:19, lbolla wrote: > On Mar 5, 10:01?am, BlueBird wrote: > > > > > > > On 3 mar, 20:35, Stefan Behnel wrote: > > > > BlueBird, 03.03.2010 17:32: > > > > > I am looking for aSOAP1.2 python client. To my surprise, it seems > > > > that this does not exist. Does anybody know about this ? > > > >SOAPmay be an overly bloated protocol, but it's certainly not black magic. > > > It's not hard to do manually if you really need to: > > > >http://effbot.org/zone/element-soap.htm > > > But this requires a goog knowloedge ofSOAP, in order to parse > > everything correctly. The reason I want to use a ready-made client is > > that I have about zero knowledge aboutSOAP, and even more in the > > differences betweenSOAP1.1 and 1.2 . > > > cheers, > > > Philippe > > I use a thin custom-made python wrapper around gSoap[1], which is tens > of times faster than ZSI. I looked at gSoap and the solution seemed really nice. They can generate C that I can call with ctypes. The only problem is that I am working on a closed source software and their licensing cost for close source were too expensive for my company. After much much digging, we found out the problem and managed to solve it with SUDS. When calling a .NET service, you should not reference the soap envelope spec with 'http://schemas.xmlsoap.org/soap/ envelope/' but with 'http://schemas.xmlsoap.org/soap/envelope' . The .NET server implementation seems to be very picky about the last / . Yeah for SUDS and oooooh for .NET cheers, Philippe From saimapk81 at gmail.com Tue Mar 23 08:54:01 2010 From: saimapk81 at gmail.com (saima81) Date: Tue, 23 Mar 2010 05:54:01 -0700 (PDT) Subject: "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ Message-ID: <3214acd7-f057-4444-9ff8-d6402d7a4b30@u5g2000prd.googlegroups.com> "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ From vlastimil.brom at gmail.com Tue Mar 23 10:18:17 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 23 Mar 2010 15:18:17 +0100 Subject: individually updating unicodedata db? In-Reply-To: References: <9fdb569a1003221719k50345867vfc4a47683e877aae@mail.gmail.com> Message-ID: <9fdb569a1003230718u37d2e2dem944e4141def631b0@mail.gmail.com> 2010/3/23 Gabriel Genellina : > En Mon, 22 Mar 2010 21:19:04 -0300, Vlastimil Brom > escribi?: > >> I guess, I am stuck here, as I use the precompiled version supplied in >> the windows installer and can't compile python from source to obtain >> the needed unicodedata.pyd. > > You can recompile Python from source, on Windows, using the free Microsoft? > Visual C++? 2008 Express Edition. > http://www.microsoft.com/express/Windows/ > > Fetch the required dependencies using Tools\buildbot\external.bat, and then > execute PCbuild\env.bat and build.bat. See readme.txt in that directory for > details. It should build cleanly. > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > Thanks for the hints; i probably screwed some steps up in some way, but the result seem to be working for the most part; I'll try to summarise it just for the record (also hoping to get further suggestions): I used the official source tarball for python 2.6.5 from: http://www.python.org/download/ In the unpacked sources, I edited the file: ...\Python-2.6.5-src\Tools\unicode\makeunicodedata.py import re # added ... # UNIDATA_VERSION = "5.1.0" # changed to: UNIDATA_VERSION = "5.2.0" Furthermore the following text files were copied to the same directory like makeunicodedata.py CompositionExclusions-3.2.0.txt EastAsianWidth-3.2.0.txt UnicodeData-3.2.0.txt UnicodeData.txt EastAsianWidth.txt CompositionExclusions.txt from http://unicode.org/Public/3.2-Update/ and http://unicode.org/Public/5.2.0/ucd/ furthermore there are some files in the subdirectories needed: ...\Python-2.6.5-src\Tools\unicode\Objects\unicodetype_db.h ...\Python-2.6.5-src\Tools\unicode\Modules\unicodedata_db.h ...\Python-2.6.5-src\Tools\unicode\Modules\unicodename_db.h After running makeunicodedata.py, the above headers are recreated from the new unicode database and can be copied to the original locations in the source ...\Python-2.6.5-src\Objects\unicodetype_db.h ...\Python-2.6.5-src\Modules\unicodedata_db.h ...\Python-2.6.5-src\Modules\unicodename_db.h (while keeping the backups) Trying to run ...\Python-2.6.5-src\Tools\buildbot\external.bat and other bat files, I got quite a few path mismatches resulting in file ... not found errors; However, I was able to just open the solution file in Visual C++ 2008 Express: C:\install\Python-2.6.5-src\PCbuild\pcbuild.sln set the build configuration to "release" and try to build the sources. There were some errors in particular modules (which might be due to my mistakes or ommissions, as this maybe shouldn't happen normally), but the wanted ...\Python-2.6.5-src\PCbuild\unicodedata.pyd was generated and can be used in the original python installation: C:\Python26\DLLs\unicodedata.pyd the newly added characters, cf.: http://www.unicode.org/Public/UNIDATA/DerivedAge.txt seem to be available ? (dec.: 8528) (hex.: 0x2150) # ? VULGAR FRACTION ONE SEVENTH (Number, Other) ? (dec.: 68352) (hex.: 0x10b00) # ? AVESTAN LETTER A (Letter, Other) but some are not present; I noticed this for the new CJK block - CJK Unified Ideographs Extension C (U+2A700..U+2B73F). Probably this new range isn't taken into account for some reason. All in all, I am happy to have the current version of the unicode database available; I somehow expected this to be more complicated, but on the other hand I can't believe this is the standard way of preparing the built versions (with all the copying,checking and and replacing the files); it might be possible, that the actual distribution is built using some different tools (the trivial missing import in makeunicodedata.py would be found immediately, I guess). I also wanted to ask, whether the missing characters might be a result of my error in updating the unicode database, or could it be a problem with the makeunicodedata.py itself? Thanks in advance and sorry for this long post. vbr From peter at psantoro.net Tue Mar 23 10:38:20 2010 From: peter at psantoro.net (peter at psantoro.net) Date: 23 Mar 2010 07:38:20 -0700 Subject: RELEASED Python 2.6.5 References: Message-ID: Thank you everyone for all the work that went into this update, but there may be a small problem with the Windows x86 installer. I've built and used python 2.6.5 on linux without any apparent problems, but the Windows x86 binary installer stops after compiling a few python source files. I've tried the Windows x86 installer on two differently configured Windows XP PCs (SP3 with patches), but I get the following errors during the advanced compiling of python source files: "There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor." "Python 2.6.5 Installer ended prematurely ..." The md5sum of the Windows x86 installer matched the published value. I did not try not using the advanced option. I reinstalled python 2.6.4 on both of the PCs without any problems and used the advanced compile option. Is anyone else having trouble with the 2.6.5 Windows x86 installer? Peter From omrihsan at gmail.com Tue Mar 23 10:49:08 2010 From: omrihsan at gmail.com (Omer Ihsan) Date: Tue, 23 Mar 2010 07:49:08 -0700 (PDT) Subject: device identification References: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> <46ggq59e49qpna7f9ae6q8ftobhot351un@4ax.com> Message-ID: <57c86289-85e7-4c9f-b7ed-787687d9a5b6@x23g2000prd.googlegroups.com> On Mar 23, 9:22?am, Tim Roberts wrote: > Omer Ihsan wrote: > > >i have installed pyusb now and run the sample usbenum.py....i have 3 > >usb ports on my PC but the results show 6 outputs to > >dev.filename..they are numbers like 001 or 005 etc.... and they > >changed when i plugged in devices...(i am no good with the usb > >standards)....i just want to identify each device/port... what > >parameter in the example would help me.... > > You can't identify the ports.[1] ?What good would it do you? ?The ports on > your PC are not numbered. > > You certainly CAN identify the devices, by their VID and PID (or idVendor > and idProduct). ?You identify by function, not by location. ?When you plug > in a USB drive, you don't want to worry about where it's plugged in. > === > [1]: OK, technically, it is not impossible to identify the port numbers, > but it is quite tedious. ?You need to chase through the sysfs expansion of > your buses hub/port tree and find a match for your device. ?It's not worth > the trouble. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. VID and PID is fair enough. now what i want is that i have a threaded code that threads two functions to run at the same time. i want each function to run seperate devices. the problem is if it doesnt identify the attached devices it might run the code on a single device which isnt what is required. how will i be able to run a code on a device of my choice???....you can leave away the threading part for now. From alley at dragoncreativeworks.net Tue Mar 23 12:04:21 2010 From: alley at dragoncreativeworks.net (Allan Davis) Date: Tue, 23 Mar 2010 11:04:21 -0500 Subject: RELEASED Python 2.6.5 In-Reply-To: References: Message-ID: <61c507641003230904w41a028dbl21e83fc4399dc6cf@mail.gmail.com> I just downloaded the installer and tested it on my win xp machine. The installer worked fine. -------------------------------------------------------------- Allan Davis Member of NetBeans Dream Team http://wiki.netbeans.org/NetBeansDreamTeam Lead Developer, nbPython http://wiki.netbeans.org/Python http://codesnakes.blogspot.com (my blog) Co-Chair, CajunJUG http://www.cajunjug.org On Tue, Mar 23, 2010 at 9:38 AM, wrote: > Thank you everyone for all the work that went into this update, but there > may be > a small problem with the Windows x86 installer. > > I've built and used python 2.6.5 on linux without any apparent problems, > but the > Windows x86 binary installer stops after compiling a few python source > files. > > I've tried the Windows x86 installer on two differently configured Windows > XP > PCs (SP3 with patches), but I get the following errors during the advanced > compiling of python source files: > > "There is a problem with this Windows Installer package. A program run as > part > of the setup did not finish as expected. Contact your support personnel or > package vendor." > > "Python 2.6.5 Installer ended prematurely ..." > > The md5sum of the Windows x86 installer matched the published value. I did > not > try not using the advanced option. I reinstalled python 2.6.4 on both of > the > PCs without any problems and used the advanced compile option. > > Is anyone else having trouble with the 2.6.5 Windows x86 installer? > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosymonijasmine at gmail.com Tue Mar 23 12:05:42 2010 From: rosymonijasmine at gmail.com (Jasmine Rose) Date: Tue, 23 Mar 2010 09:05:42 -0700 (PDT) Subject: Stop the Heat from Sun Rays! Message-ID: <37e5dd24-c8a4-494f-8cf1-1577cf247401@u15g2000prd.googlegroups.com> Stop the Heat! Stop UV Damage! Save Money! - More Details : http://www.suntechglasstinting.com/welcome.php From solipsis at pitrou.net Tue Mar 23 12:53:34 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 23 Mar 2010 16:53:34 +0000 (UTC) Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> <7xpr2v2wd7.fsf@ruckus.brouhaha.com> Message-ID: Le Tue, 23 Mar 2010 02:57:56 -0700, Paul Rubin a ?crit?: > > It is unlikely to happen by accident. You might care that it can happen > on purpose. See: http://www.cs.rice.edu/~scrosby/hash/ that I cited in > another post. The article shows some sample attacks on Python cgi's. Certainly interesting in a purely academic point of view, but in real life if you want to cause a denial of service by overwhelming a server, there are far more obvious options than trying to guess the server's use of hash tables and trying to cause lots of collisions in them. From jfernand57 at gmail.com Tue Mar 23 12:55:30 2010 From: jfernand57 at gmail.com (Jose Manuel) Date: Tue, 23 Mar 2010 09:55:30 -0700 (PDT) Subject: Python is cool!! Message-ID: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> I have been learning Python, and it is amazing .... I am using the tutorial that comes with the official distribution. At the end my goal is to develop applied mathematic in engineering applications to be published on the Web, specially on app. oriented to simulations and control systems, I was about to start learning Java but I found Python which seems easier to learn that Java. Would it be easy to integrate Python in Web pages with HTML? I have read many info on Internet saying it is, and I hope so .... Any opinion From mehgcap at gmail.com Tue Mar 23 13:01:21 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 23 Mar 2010 13:01:21 -0400 Subject: using message loop for hotkey capturing Message-ID: Hi all, but mainly Tim Golden: Tim, I am using your wonderful message loop for keyboard input, the one on your site that you pointed me to a few months ago. It has been working perfectly as long as I had only one dictionary of keys mapping to one dictionary of functions, but now I want two of each. My program has different modes, which may have varying keystrokes, and I also have some global keystrokes which are the same across all modes, like exiting or switching modes. I cannot figure out how to make the message loop look in two dictionaries at onc. I tried using an if, saying that if action_to_take was not set in the mode-specific dictionary then look at the global dictionary, but it is like it is never looking in the global dictionary at all. I get no syntax errors or problems when running the program, so it has to be something in my logic. Go to http://www.gateway2somewhere.com/sw/main.pyw to see what I mean; the problem code is near the very bottom of the file. Thanks for any suggestions. Oh, please note that I indent one space per indentation level. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From vinay_sajip at yahoo.co.uk Tue Mar 23 13:06:43 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 23 Mar 2010 10:06:43 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() References: mailman.1078.1269324766.23598.python-list@python.org Message-ID: <54e357f4-705f-40a8-ac6c-e5ae84f814f7@t23g2000yqt.googlegroups.com> On Mar 23, 6:12?am, "Gabriel Genellina" wrote: > En Mon, 22 Mar 2010 15:20:39 -0300, Pascal Chambon ? > escribi???: > > > > > > > Allright, here is more concretely the problem : > > > ERROR:root:An error > > Traceback (most recent call last): > > ? File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c > > ? ? return d() > > ? File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d > > ? ? def d(): raise ValueError > > ValueError > > > As you see, the traceback only starts from function c, which handles the ? > > exception. > > It doesn't show main(), a() and b(), which might however be (and are, in ? > > my case) critical to diagnose the severity of the problem (since many ? > > different paths would lead to calling c()). > > > So the question is : is that possible to enforce, by a way or another, ? > > the retrieval of the FULL traceback at exception raising point, instead ? > > of that incomplete one ? > > Thanks for bringing this topic! I learned a lot trying to understand what ? > happens. > > The exception traceback (what sys.exc_info()[2] returns) is *not* a ? > complete stack trace. The sys module documentation is wrong [1] when it ? > says "...encapsulates the call stack at the point where the exception ? > originally occurred." > > The Language Reference is more clear [2]: "Traceback objects represent a ? > stack trace of an exception. A traceback object is created when an ? > exception occurs. When the search for an exception handler unwinds the ? > execution stack, at each unwound level a traceback object is inserted in ? > front of the current traceback. When an exception handler is entered, the ? > stack trace is made available to the program." > > That is, a traceback holds only the *forward* part of the stack: the ? > frames already exited when looking for an exception handler. Frames going ? > ?from the program starting point up to the current execution point are ? > *not* included. > > Conceptually, it's like having two lists: stack and traceback. The ? > complete stack trace is always stack+traceback. At each step (when ? > unwinding the stack, looking for a frame able to handle the current ? > exception) an item is popped from the top of the stack (last item) and ? > inserted at the head of the traceback. > > The traceback holds the "forward" path (from the current execution point, ? > to the frame where the exception was actually raised). It's a linked list, ? > its tb_next attribute holds a reference to the next item; None marks the ? > last one. > > The "back" path (going from the current execution point to its caller and ? > all the way to the program entry point) is a linked list of frames; the ? > f_back attribute points to the previous one, or None. > > In order to show a complete stack trace, one should combine both. The ? > traceback module contains several useful functions: extract_stack() + ? > extract_tb() are a starting point. The simplest way I could find to make ? > theloggingmodule report a complete stack is to monkey patch ?logging.Formatter.formatException so it uses format_exception() and ? > format_stack() combined (in fact it is simpler than the current ? > implementation using a StringIO object): > > > importlogging > import traceback > > def formatException(self, ei): > ? ? ?""" > ? ? ?Format and return the specified exception information as a string. > > ? ? ?This implementation builds the complete stack trace, combining > ? ? ?traceback.format_exception and traceback.format_stack. > ? ? ?""" > ? ? ?lines = traceback.format_exception(*ei) > ? ? ?if ei[2]: > ? ? ? ? ?lines[1:1] = traceback.format_stack(ei[2].tb_frame.f_back) > ? ? ?return ''.join(lines) > > # monkey patch theloggingmodulelogging.Formatter.formatException = formatException > > def a(): return b() > def b(): return c() > def c(): > ? ? ?try: > ? ? ? ?return d() > ? ? ?except: > ? ? ? ?logging.exception("An error") > ? ? ? ?raise > def d(): raise ValueError > > def main(): > ? ?a() > > main() > > > Output: > > ERROR:root:An error > Traceback (most recent call last): > ? ?File "test_logging.py", line 32, in > ? ? ?main() > ? ?File "test_logging.py", line 30, in main > ? ? ?a() > ? ?File "test_logging.py", line 19, in a > ? ? ?def a(): return b() > ? ?File "test_logging.py", line 20, in b > ? ? ?def b(): return c() > ? ?File "test_logging.py", line 23, in c > ? ? ?return d() > ? ?File "test_logging.py", line 27, in d > ? ? ?def d(): raise ValueError > ValueError > > Traceback (most recent call last): > ? ?File "test_logging.py", line 32, in > ? ? ?main() > ? ?File "test_logging.py", line 30, in main > ? ? ?a() > ? ?File "test_logging.py", line 19, in a > ? ? ?def a(): return b() > ? ?File "test_logging.py", line 20, in b > ? ? ?def b(): return c() > ? ?File "test_logging.py", line 23, in c > ? ? ?return d() > ? ?File "test_logging.py", line 27, in d > ? ? ?def d(): raise ValueError > ValueError > > Note that both tracebacks are identical: the first comes from the patched ?loggingmodule, the second is the standard Python one. > > [1]http://docs.python.org/library/sys.html#sys.exc_info > [2] ?http://docs.python.org/reference/datamodel.html#the-standard-type-hie... > > -- > Gabriel Genellina Good catch, Gabriel. There should be no need to monkey-patch the logging module - it's better if I include the change in the module itself. The only remaining question is that of backward compatibility, but I can do this for Python 2.7/3.2 only so that won't be an issue. It's probably a good idea to log an issue on the bug tracker, though, so we have some history for the change - do you want to do that, or shall I? Regards, Vinay Sajip From mail at timgolden.me.uk Tue Mar 23 13:07:57 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 17:07:57 +0000 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4BA8F56D.6060305@timgolden.me.uk> On 23/03/2010 16:55, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... You probably want to be looking at IronPython and Silverlight. In fact, the prolific Michael Foord has already produced an example of this, which gives you the Python tutorial online! http://trypython.org TJG From mail at timgolden.me.uk Tue Mar 23 13:09:36 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 17:09:36 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: Message-ID: <4BA8F5D0.7080502@timgolden.me.uk> On 23/03/2010 17:01, Alex Hall wrote: > Hi all, but mainly Tim Golden: > Tim, I am using your wonderful message loop for keyboard input, the > one on your site that you pointed me to a few months ago. It has been > working perfectly as long as I had only one dictionary of keys mapping > to one dictionary of functions, but now I want two of each. My program > has different modes, which may have varying keystrokes, and I also > have some global keystrokes which are the same across all modes, like > exiting or switching modes. I cannot figure out how to make the > message loop look in two dictionaries at onc. I tried using an if, > saying that if action_to_take was not set in the mode-specific > dictionary then look at the global dictionary, but it is like it is > never looking in the global dictionary at all. I get no syntax errors > or problems when running the program, so it has to be something in my > logic. Go to > http://www.gateway2somewhere.com/sw/main.pyw Happy to look, Alex, but that link's giving me a 404 at the moment TJG From mehgcap at gmail.com Tue Mar 23 13:29:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 23 Mar 2010 13:29:05 -0400 Subject: using message loop for hotkey capturing In-Reply-To: <4BA8F5D0.7080502@timgolden.me.uk> References: <4BA8F5D0.7080502@timgolden.me.uk> Message-ID: Sorry about that, it is fixed now. On 3/23/10, Tim Golden wrote: > On 23/03/2010 17:01, Alex Hall wrote: >> Hi all, but mainly Tim Golden: >> Tim, I am using your wonderful message loop for keyboard input, the >> one on your site that you pointed me to a few months ago. It has been >> working perfectly as long as I had only one dictionary of keys mapping >> to one dictionary of functions, but now I want two of each. My program >> has different modes, which may have varying keystrokes, and I also >> have some global keystrokes which are the same across all modes, like >> exiting or switching modes. I cannot figure out how to make the >> message loop look in two dictionaries at onc. I tried using an if, >> saying that if action_to_take was not set in the mode-specific >> dictionary then look at the global dictionary, but it is like it is >> never looking in the global dictionary at all. I get no syntax errors >> or problems when running the program, so it has to be something in my >> logic. Go to >> http://www.gateway2somewhere.com/sw/main.pyw > > > Happy to look, Alex, but that link's giving me a 404 at the moment > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From python.list at tim.thechases.com Tue Mar 23 13:31:09 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Mar 2010 12:31:09 -0500 Subject: How to find the best solution ? In-Reply-To: References: Message-ID: <4BA8FADD.5070709@tim.thechases.com> Johny wrote: > I have a text and would like to split the text into smaller parts, > say into 100 characters each. But if the 100th character is not a > blank ( but word) this must be less than 100 character.That means the > word itself can not be split. > These smaller parts must contains only whole( not split) words. > I was thinking about RegEx but do not know how to find the correct > Regular Expression. While I suspect you can come close with a regular expression: import re, random size = 100 r = re.compile(r'.{1,%i}\b' % size) # generate a random text string with a mix of word-lengths words = ['a', 'an', 'the', 'four', 'fives', 'sixsix'] data = ' '.join(random.choice(words) for _ in range(200)) # for each chunk of 100 characters (or fewer # if on a word-boundary), do something for bit in r.finditer(data): chunk = bit.group(0) print "%i: [%s]" % (len(chunk), chunk) it may have an EOF fencepost error, so you might have to clean up the last item. My simple test seemed to show it worked without cleanup though. -tkc From pruebauno at latinmail.com Tue Mar 23 13:33:33 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 10:33:33 -0700 (PDT) Subject: Unicode blues in Python3 Message-ID: I know that unicode is the way to go in Python 3.1, but it is getting in my way right now in my Unix scripts. How do I write a chr(253) to a file? #nntst2.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) print(mychar) > ./nntst2.py ISO8859-1 ? > ./nntst2.py >nnout2 Traceback (most recent call last): File "./nntst2.py", line 5, in print(mychar) UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 0: ordinal not in range(128) > cat nnout2 ascii ..Oh great! ok lets try this: #nntst3.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) print(mychar.encode('latin1')) > ./nntst3.py ISO8859-1 b'\xfd' > ./nntst3.py >nnout3 > cat nnout3 ascii b'\xfd' ..Eh... not what I want really. #nntst4.py import sys,codecs mychar=chr(253) print(sys.stdout.encoding) sys.stdout=codecs.getwriter("latin1")(sys.stdout) print(mychar) > ./nntst4.py ISO8859-1 Traceback (most recent call last): File "./nntst4.py", line 6, in print(mychar) File "Python-3.1.2/Lib/codecs.py", line 356, in write self.stream.write(data) TypeError: must be str, not bytes ..OK, this is not working either. Is there any way to write a value 253 to standard output? From python at mrabarnett.plus.com Tue Mar 23 13:54:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Mar 2010 17:54:58 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: Message-ID: <4BA90072.9060305@mrabarnett.plus.com> Alex Hall wrote: > Hi all, but mainly Tim Golden: > Tim, I am using your wonderful message loop for keyboard input, the > one on your site that you pointed me to a few months ago. It has been > working perfectly as long as I had only one dictionary of keys mapping > to one dictionary of functions, but now I want two of each. My program > has different modes, which may have varying keystrokes, and I also > have some global keystrokes which are the same across all modes, like > exiting or switching modes. I cannot figure out how to make the > message loop look in two dictionaries at onc. I tried using an if, > saying that if action_to_take was not set in the mode-specific > dictionary then look at the global dictionary, but it is like it is > never looking in the global dictionary at all. I get no syntax errors > or problems when running the program, so it has to be something in my > logic. Go to > http://www.gateway2somewhere.com/sw/main.pyw > to see what I mean; the problem code is near the very bottom of the > file. Thanks for any suggestions. Oh, please note that I indent one > space per indentation level. > "msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc, not ints. Incidentally, you might want to change: if(not action_to_take): to: if action_to_take is None: in case any of the values happen to be 0 (if not now, then possibly at some time in the future). From rami.chowdhury at gmail.com Tue Mar 23 14:00:09 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 23 Mar 2010 11:00:09 -0700 Subject: Unicode blues in Python3 In-Reply-To: References: Message-ID: <201003231100.10103.rami.chowdhury@gmail.com> On Tuesday 23 March 2010 10:33:33 nn wrote: > I know that unicode is the way to go in Python 3.1, but it is getting > in my way right now in my Unix scripts. How do I write a chr(253) to a > file? > > #nntst2.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar) The following code works for me: $ cat nnout5.py #!/usr/bin/python3.1 import sys mychar = chr(253) sys.stdout.write(mychar) $ echo $(cat nnout) ? Can I ask why you're using print() in the first place, rather than writing directly to a file? Python 3.x, AFAIK, distinguishes between text and binary files and will let you specify the encoding you want for strings you write. Hope that helps, Rami > > > ./nntst2.py > > ISO8859-1 > ? > > > ./nntst2.py >nnout2 > > Traceback (most recent call last): > File "./nntst2.py", line 5, in > print(mychar) > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > position 0: ordinal not in range(128) > > > cat nnout2 > > ascii > > ..Oh great! > > ok lets try this: > #nntst3.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar.encode('latin1')) > > > ./nntst3.py > > ISO8859-1 > b'\xfd' > > > ./nntst3.py >nnout3 > > > > cat nnout3 > > ascii > b'\xfd' > > ..Eh... not what I want really. > > #nntst4.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > print(mychar) > > > ./nntst4.py > > ISO8859-1 > Traceback (most recent call last): > File "./nntst4.py", line 6, in > print(mychar) > File "Python-3.1.2/Lib/codecs.py", line 356, in write > self.stream.write(data) > TypeError: must be str, not bytes > > ..OK, this is not working either. > > Is there any way to write a value 253 to standard output? ---- Rami Chowdhury "Ninety percent of everything is crap." -- Sturgeon's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From mehgcap at gmail.com Tue Mar 23 14:04:15 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 23 Mar 2010 14:04:15 -0400 Subject: using message loop for hotkey capturing In-Reply-To: <4BA90072.9060305@mrabarnett.plus.com> References: <4BA90072.9060305@mrabarnett.plus.com> Message-ID: On 3/23/10, MRAB wrote: > Alex Hall wrote: >> Hi all, but mainly Tim Golden: >> Tim, I am using your wonderful message loop for keyboard input, the >> one on your site that you pointed me to a few months ago. It has been >> working perfectly as long as I had only one dictionary of keys mapping >> to one dictionary of functions, but now I want two of each. My program >> has different modes, which may have varying keystrokes, and I also >> have some global keystrokes which are the same across all modes, like >> exiting or switching modes. I cannot figure out how to make the >> message loop look in two dictionaries at onc. I tried using an if, >> saying that if action_to_take was not set in the mode-specific >> dictionary then look at the global dictionary, but it is like it is >> never looking in the global dictionary at all. I get no syntax errors >> or problems when running the program, so it has to be something in my >> logic. Go to >> http://www.gateway2somewhere.com/sw/main.pyw >> to see what I mean; the problem code is near the very bottom of the >> file. Thanks for any suggestions. Oh, please note that I indent one >> space per indentation level. >> > "msg.wParam" gives an int, but the keys of globalFuncs are 'g1', etc, > not ints. That did it. I originally used 1-4 like I did for the mode dictionaries, not realizing that the ints were so important; I figured they were just keys in the dictionary and that they could be anything, it was just easier to use ints. Now, I have changed my globals to 20-23 and everything seems to be going well. Thanks!! > Incidentally, you might want to change: > > if(not action_to_take): > > to: > > if action_to_take is None: > > in case any of the values happen to be 0 (if not now, then possibly at > some time in the future). Sorry, could you explain why you suggested this? I do not follow. Because of the if statement "if action_to_take:", I figured it was saying "if action_to_take was successfully set" or something else having a boolean value. Guess not? > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From pruebauno at latinmail.com Tue Mar 23 14:09:45 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 11:09:45 -0700 (PDT) Subject: Unicode blues in Python3 References: Message-ID: Rami Chowdhury wrote: > On Tuesday 23 March 2010 10:33:33 nn wrote: > > I know that unicode is the way to go in Python 3.1, but it is getting > > in my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > #nntst2.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar) > > The following code works for me: > > $ cat nnout5.py > #!/usr/bin/python3.1 > > import sys > mychar = chr(253) > sys.stdout.write(mychar) > $ echo $(cat nnout) > ? > > Can I ask why you're using print() in the first place, rather than writing > directly to a file? Python 3.x, AFAIK, distinguishes between text and binary > files and will let you specify the encoding you want for strings you write. > > Hope that helps, > Rami > > > > > ./nntst2.py > > > > ISO8859-1 > > ? > > > > > ./nntst2.py >nnout2 > > > > Traceback (most recent call last): > > File "./nntst2.py", line 5, in > > print(mychar) > > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > > position 0: ordinal not in range(128) > > > > > cat nnout2 > > > > ascii > > > > ..Oh great! > > > > ok lets try this: > > #nntst3.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar.encode('latin1')) > > > > > ./nntst3.py > > > > ISO8859-1 > > b'\xfd' > > > > > ./nntst3.py >nnout3 > > > > > > cat nnout3 > > > > ascii > > b'\xfd' > > > > ..Eh... not what I want really. > > > > #nntst4.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > > print(mychar) > > > > > ./nntst4.py > > > > ISO8859-1 > > Traceback (most recent call last): > > File "./nntst4.py", line 6, in > > print(mychar) > > File "Python-3.1.2/Lib/codecs.py", line 356, in write > > self.stream.write(data) > > TypeError: must be str, not bytes > > > > ..OK, this is not working either. > > > > Is there any way to write a value 253 to standard output? > #nntst5.py import sys mychar=chr(253) sys.stdout.write(mychar) > ./nntst5.py >nnout5 Traceback (most recent call last): File "./nntst5.py", line 4, in sys.stdout.write(mychar) UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in position 0: ordinal not in range(128) equivalent to print. I use print so I can do tests and debug runs to the screen or pipe it to some other tool and then configure the production bash script to write the final output to a file of my choosing. From gherron at islandtraining.com Tue Mar 23 14:11:15 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 23 Mar 2010 11:11:15 -0700 Subject: Unicode blues in Python3 In-Reply-To: References: Message-ID: <4BA90443.6060307@islandtraining.com> nn wrote: > I know that unicode is the way to go in Python 3.1, but it is getting > in my way right now in my Unix scripts. How do I write a chr(253) to a > file? > Python3 make a distinction between bytes and string(i.e., unicode) types, and you are still thinking in the Python2 mode that does *NOT* make such a distinction. What you appear to want is to write a particular byte to a file -- so use the bytes type and a file open in binary mode: >>> b=bytes([253]) >>> f = open("abc", 'wb') >>> f.write(b) 1 >>> f.close() On unix (at least), the "od" program can verify the contents is correct: > od abc -d 0000000 253 0000001 Hope that helps. Gary Herron > #nntst2.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar) > > > ./nntst2.py > ISO8859-1 > ? > > > ./nntst2.py >nnout2 > Traceback (most recent call last): > File "./nntst2.py", line 5, in > print(mychar) > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > position 0: ordinal not in range(128) > > >> cat nnout2 >> > ascii > > ..Oh great! > > ok lets try this: > #nntst3.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar.encode('latin1')) > > >> ./nntst3.py >> > ISO8859-1 > b'\xfd' > > >> ./nntst3.py >nnout3 >> > > >> cat nnout3 >> > ascii > b'\xfd' > > ..Eh... not what I want really. > > #nntst4.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > print(mychar) > > > ./nntst4.py > ISO8859-1 > Traceback (most recent call last): > File "./nntst4.py", line 6, in > print(mychar) > File "Python-3.1.2/Lib/codecs.py", line 356, in write > self.stream.write(data) > TypeError: must be str, not bytes > > ..OK, this is not working either. > > Is there any way to write a value 253 to standard output? > From pruebauno at latinmail.com Tue Mar 23 14:46:33 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 11:46:33 -0700 (PDT) Subject: Unicode blues in Python3 References: Message-ID: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Gary Herron wrote: > nn wrote: > > I know that unicode is the way to go in Python 3.1, but it is getting > > in my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > Python3 make a distinction between bytes and string(i.e., unicode) > types, and you are still thinking in the Python2 mode that does *NOT* > make such a distinction. What you appear to want is to write a > particular byte to a file -- so use the bytes type and a file open in > binary mode: > > >>> b=bytes([253]) > >>> f = open("abc", 'wb') > >>> f.write(b) > 1 > >>> f.close() > > On unix (at least), the "od" program can verify the contents is correct: > > od abc -d > 0000000 253 > 0000001 > > > Hope that helps. > > Gary Herron > > > > > #nntst2.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar) > > > > > ./nntst2.py > > ISO8859-1 > > ? > > > > > ./nntst2.py >nnout2 > > Traceback (most recent call last): > > File "./nntst2.py", line 5, in > > print(mychar) > > UnicodeEncodeError: 'ascii' codec can't encode character '\xfd' in > > position 0: ordinal not in range(128) > > > > > >> cat nnout2 > >> > > ascii > > > > ..Oh great! > > > > ok lets try this: > > #nntst3.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar.encode('latin1')) > > > > > >> ./nntst3.py > >> > > ISO8859-1 > > b'\xfd' > > > > > >> ./nntst3.py >nnout3 > >> > > > > > >> cat nnout3 > >> > > ascii > > b'\xfd' > > > > ..Eh... not what I want really. > > > > #nntst4.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > sys.stdout=codecs.getwriter("latin1")(sys.stdout) > > print(mychar) > > > > > ./nntst4.py > > ISO8859-1 > > Traceback (most recent call last): > > File "./nntst4.py", line 6, in > > print(mychar) > > File "Python-3.1.2/Lib/codecs.py", line 356, in write > > self.stream.write(data) > > TypeError: must be str, not bytes > > > > ..OK, this is not working either. > > > > Is there any way to write a value 253 to standard output? > > Actually what I want is to write a particular byte to standard output, and I want this to work regardless of where that output gets sent to. I am aware that I could do open('nnout','w',encoding='latin1').write(mychar) but I am porting a python2 program and don't want to rewrite everything that uses that script. From iamforufriends at gmail.com Tue Mar 23 15:21:50 2010 From: iamforufriends at gmail.com (MARRY) Date: Tue, 23 Mar 2010 12:21:50 -0700 (PDT) Subject: DRUNK MOM AND BOY... HOT CLIP..... Message-ID: <1ff5a046-d2c3-40d2-a1f7-7e3b20d30dd2@a37g2000prd.googlegroups.com> DRUNK MOM AND BOY... HOT CLIP..... http://123sex4u.blogspot.com/ http://123sex4u.blogspot.com/ http://123sex4u.blogspot.com/ http://123sex4u.blogspot.com/ From python at mrabarnett.plus.com Tue Mar 23 15:37:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Mar 2010 19:37:51 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: <4BA90072.9060305@mrabarnett.plus.com> Message-ID: <4BA9188F.407@mrabarnett.plus.com> Alex Hall wrote: > On 3/23/10, MRAB wrote: [snip] >> Incidentally, you might want to change: >> >> if(not action_to_take): >> >> to: >> >> if action_to_take is None: >> >> in case any of the values happen to be 0 (if not now, then possibly at >> some time in the future). > Sorry, could you explain why you suggested this? I do not follow. > Because of the if statement "if action_to_take:", I figured it was > saying "if action_to_take was successfully set" or something else > having a boolean value. Guess not? > The code: globalFuncs.get (msg.wParam) returns None if the key isn't in the dict. 'if' and 'while' statements treat other objects than just True as True, in fact anything for which bool() returns True. For example: bool(100) returns True bool([1, 2, 3]) returns True bool('some text') returns True but: bool(0) returns False bool([]) returns False bool('') returns False bool(None) returns False I also just noticed that you don't give action_to_take a default value before checking whether it's a hotkey. Suppose that "msg.message == win32con.WM_HOTKEY" was False: if msg.message == win32con.WM_HOTKEY: action_to_take=globalFuncs.get (msg.wParam) if(not action_to_take): It would get to "if(not action_to_take):" and either find that action_to_take wasn't defined, or use the value from the previous pass through the loop. From bahesanhak at gmail.com Tue Mar 23 15:48:19 2010 From: bahesanhak at gmail.com (=?UTF-8?B?2YXYpNmF2YYg2YXYtdmE2K0=?=) Date: Tue, 23 Mar 2010 12:48:19 -0700 (PDT) Subject: Miracles of the devil and beat of the revolution of religious reform Message-ID: <16ec4cd6-a68d-4ba4-a55f-8d75d93358ca@b7g2000yqd.googlegroups.com> Follow what god revealed to the Almighty Peace be upon you Those who wish to familiarized themselves after you click on the link please wait a little until it opens the link Miracles of the devil and beat of the revolution of religious reform http://www.ushaaqallah.com/forum/viewtopic.php?f=22&t=19225&sid=49b706e316461bcd768accfb7ccf031c Peace be upon you From stefan_ml at behnel.de Tue Mar 23 15:57:32 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Mar 2010 20:57:32 +0100 Subject: Unicode blues in Python3 In-Reply-To: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: nn, 23.03.2010 19:46: > Actually what I want is to write a particular byte to standard output, > and I want this to work regardless of where that output gets sent to. > I am aware that I could do > open('nnout','w',encoding='latin1').write(mychar) but I am porting a > python2 program and don't want to rewrite everything that uses that > script. Are you writing text or binary data to stdout? Stefan From debatem1 at gmail.com Tue Mar 23 16:04:55 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 23 Mar 2010 16:04:55 -0400 Subject: Python is cool!! In-Reply-To: <4BA8F56D.6060305@timgolden.me.uk> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> Message-ID: On Tue, Mar 23, 2010 at 1:07 PM, Tim Golden wrote: > On 23/03/2010 16:55, Jose Manuel wrote: >> >> I have been learning Python, and it is amazing .... I am using the >> tutorial that comes with the official distribution. >> >> At the end my goal is to develop applied mathematic in engineering >> applications to be published on the Web, specially on app. oriented to >> simulations and control systems, I was about to start learning Java >> but I found Python which seems easier to learn that Java. >> >> Would it be easy to integrate Python in Web pages with HTML? I have >> read many info on Internet saying it is, and I hope so .... > > You probably want to be looking at IronPython and Silverlight. > In fact, the prolific Michael Foord has already produced an > example of this, which gives you the Python tutorial online! > > ?http://trypython.org > > TJG Granted that I know next to nothing about webwork, but is there a reason why you recommended a competing, nonstandard technology rather than simply pointing him towards more standards compliant tools that exist to do exactly what he asked for? Seems a bit dodgy to advocate a closed solution when the alternative has 100% market share. Geremy Condra From mail at timgolden.me.uk Tue Mar 23 16:12:27 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 23 Mar 2010 20:12:27 +0000 Subject: Python is cool!! In-Reply-To: References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> Message-ID: <4BA920AB.2070206@timgolden.me.uk> On 23/03/2010 20:04, geremy condra wrote: > On Tue, Mar 23, 2010 at 1:07 PM, Tim Golden wrote: >> On 23/03/2010 16:55, Jose Manuel wrote: >>> Would it be easy to integrate Python in Web pages with HTML? I have >>> read many info on Internet saying it is, and I hope so .... >> >> You probably want to be looking at IronPython and Silverlight. >> In fact, the prolific Michael Foord has already produced an >> example of this, which gives you the Python tutorial online! >> >> http://trypython.org >> >> TJG > > Granted that I know next to nothing about webwork, but > is there a reason why you recommended a competing, > nonstandard technology rather than simply pointing him > towards more standards compliant tools that exist to do > exactly what he asked for? Seems a bit dodgy to > advocate a closed solution when the alternative has 100% > market share. I can't say I thought *very* hard before sending that but... The OP asked for "integrate Python in Web Pages with HTML" which I understood -- perhaps wrongly -- to mean: run Python in the browser. The only two ways I'm aware of doing that in Python are the undersupported Python-as-IE-scripting-language and IronPython/Silverlight. Now I look again, I realise that he may have meant simply: Python as a server-side toolset with possible support for Javascript. In which case, of course, my answer was not so applicable. TJG From pruebauno at latinmail.com Tue Mar 23 16:36:20 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 23 Mar 2010 13:36:20 -0700 (PDT) Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: Stefan Behnel wrote: > nn, 23.03.2010 19:46: > > Actually what I want is to write a particular byte to standard output, > > and I want this to work regardless of where that output gets sent to. > > I am aware that I could do > > open('nnout','w',encoding='latin1').write(mychar) but I am porting a > > python2 program and don't want to rewrite everything that uses that > > script. > > Are you writing text or binary data to stdout? > > Stefan latin1 charset text. From torriem at gmail.com Tue Mar 23 16:47:20 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 23 Mar 2010 14:47:20 -0600 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4BA928D8.4050903@gmail.com> Jose Manuel wrote: > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... Django is, among several other similar projects and frameworks, very popular for generating web apps in Python. I have only used Django and it works very well. From chambon.pascal at wanadoo.fr Tue Mar 23 16:49:14 2010 From: chambon.pascal at wanadoo.fr (Pascal Chambon) Date: Tue, 23 Mar 2010 21:49:14 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> Message-ID: <4BA9294A.9090703@wanadoo.fr> Gabriel Genellina a ?crit : > > En Mon, 22 Mar 2010 15:20:39 -0300, Pascal Chambon > escribi?: >> >> Allright, here is more concretely the problem : >> >> ERROR:root:An error >> Traceback (most recent call last): >> File "C:/Users/Pakal/Desktop/aaa.py", line 7, in c >> return d() >> File "C:/Users/Pakal/Desktop/aaa.py", line 11, in d >> def d(): raise ValueError >> ValueError >> >>> >> >> As you see, the traceback only starts from function c, which handles >> the exception. >> It doesn't show main(), a() and b(), which might however be (and are, >> in my case) critical to diagnose the severity of the problem (since >> many different paths would lead to calling c()). >> >> So the question is : is that possible to enforce, by a way or >> another, the retrieval of the FULL traceback at exception raising >> point, instead of that incomplete one ? > > Thanks for bringing this topic! I learned a lot trying to understand > what happens. > > The exception traceback (what sys.exc_info()[2] returns) is *not* a > complete stack trace. The sys module documentation is wrong [1] when > it says "...encapsulates the call stack at the point where the > exception originally occurred." > > The Language Reference is more clear [2]: "Traceback objects represent > a stack trace of an exception. A traceback object is created when an > exception occurs. When the search for an exception handler unwinds the > execution stack, at each unwound level a traceback object is inserted > in front of the current traceback. When an exception handler is > entered, the stack trace is made available to the program." > > That is, a traceback holds only the *forward* part of the stack: the > frames already exited when looking for an exception handler. Frames > going from the program starting point up to the current execution > point are *not* included. > > Conceptually, it's like having two lists: stack and traceback. The > complete stack trace is always stack+traceback. At each step (when > unwinding the stack, looking for a frame able to handle the current > exception) an item is popped from the top of the stack (last item) and > inserted at the head of the traceback. > > The traceback holds the "forward" path (from the current execution > point, to the frame where the exception was actually raised). It's a > linked list, its tb_next attribute holds a reference to the next item; > None marks the last one. > > The "back" path (going from the current execution point to its caller > and all the way to the program entry point) is a linked list of > frames; the f_back attribute points to the previous one, or None. > > In order to show a complete stack trace, one should combine both. The > traceback module contains several useful functions: extract_stack() + > extract_tb() are a starting point. The simplest way I could find to > make the logging module report a complete stack is to monkey patch > logging.Formatter.formatException so it uses format_exception() and > format_stack() combined (in fact it is simpler than the current > implementation using a StringIO object): Good point, there is clearly a distinction between "stack trace" and "exception traceback" that I didn't know (actually, it seems no one makes it in computer literature). > Good catch, Gabriel. > > There should be no need to monkey-patch the logging module - it's > better if I include the change in the module itself. The only > remaining question is that of backward compatibility, but I can do > this for Python 2.7/3.2 only so that won't be an issue. It's probably > a good idea to log an issue on the bug tracker, though, so we have > some history for the change - do you want to do that, or shall I? > > Regards, > > Vinay Sajip > Well having it fixed in logging would be great, but that kind of information is good to have in other circumstances, so shouldn't we rather advocate the availability of this "stack trace part" in exc_info too ? This way, people like me who consider frames as black magic wouldn't need to meet complex stuffs as "traceback.format_stack(ei[2].tb_frame.f_back" :p Should I open an issue for this evolution of exceptiuon handling, or should we content ourselves of this "hacking" of frame stck ? Regards, Pascal From pmaupin at gmail.com Tue Mar 23 17:24:30 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 23 Mar 2010 14:24:30 -0700 (PDT) Subject: Python is cool!! References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> Message-ID: <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> On Mar 23, 3:12?pm, Tim Golden wrote: > I can't say I thought *very* hard before sending that but... > The OP asked for "integrate Python in Web Pages with HTML" > which I understood -- perhaps wrongly -- to mean: run Python > in the browser. The only two ways I'm aware of doing that > in Python are the undersupported Python-as-IE-scripting-language > and IronPython/Silverlight. If I had to run Python in a browser, the first thing I would do is turn to Pyjamas: http://pyjs.org/ Regards, Pat From anand.shashwat at gmail.com Tue Mar 23 17:50:16 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 03:20:16 +0530 Subject: Python is cool!! In-Reply-To: <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> Message-ID: There is a project PyWhip (renamed as PyKata) which aims for the same purpose. Google AppEmgine + Django does the trick for that. May be you can take an inspiration or two from there especially because all code is open to/for you. ~l0nwlf On Wed, Mar 24, 2010 at 2:54 AM, Patrick Maupin wrote: > On Mar 23, 3:12 pm, Tim Golden wrote: > > I can't say I thought *very* hard before sending that but... > > The OP asked for "integrate Python in Web Pages with HTML" > > which I understood -- perhaps wrongly -- to mean: run Python > > in the browser. The only two ways I'm aware of doing that > > in Python are the undersupported Python-as-IE-scripting-language > > and IronPython/Silverlight. > > If I had to run Python in a browser, the first thing I would do is > turn to Pyjamas: http://pyjs.org/ > > Regards, > Pat > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Tue Mar 23 18:09:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 23 Mar 2010 18:09:36 -0400 Subject: Pythonic way to trim and keep leading and trailing whitespace Message-ID: <1269382176.23636.1366365237@webmail.messagingengine.com> I'm looking for a pythonic way to trim and keep leading whitespace in a string. Use case: I have a bunch of text strings with various amounts of leading and trailing whitespace (spaces and tabs). I want to grab the leading and trailing whitespace, save it, surround the remaining text with html tags, and then add back the leading and trailing whitespace. The only solution I can think of is regex, and that makes me think of the 2 proverbial problems that come with that :) Is there a 'better' solution than regex for this scenario? (Seems like this would be a common type of string processing). Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From dpawlows at umich.edu Tue Mar 23 18:13:36 2010 From: dpawlows at umich.edu (dpawlows) Date: Tue, 23 Mar 2010 18:13:36 -0400 Subject: Posting to https Message-ID: <0BAF76CC-8D91-4872-A5F2-EEC9F15C97AF@umich.edu> I am trying to obtain data on a https site, but everytime I try to access the data that is behind the logon screen, I get the logon page instead. I was able to successfully do a test problem: import sys, urllib2, urllib zipcode = "48103" url = 'http://www.wunderground.com/cgi-bin/findweather/getForecast' data = urllib.urlencode([('query', zipcode)]) req = urllib2.Request(url) fd = urllib2.urlopen(req, data) while 1: data = fd.read(1024) if not len(data): break sys.stdout.write(data) which performed as I expected. However, for the url 'https://secure.umcu.org/cgi-bin/mcw000.cgi?MCWSTART' with data = ... {'HBUSERNAME':username,'PASSWORD':password} I was sent just the logon screen. Am I missing something important that has to do with interaction with javascript, https, or cgi, or something completely different? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Tue Mar 23 18:16:45 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 23 Mar 2010 17:16:45 -0500 Subject: Python is cool!! In-Reply-To: References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> <4BA8F56D.6060305@timgolden.me.uk> <62d1f435-e473-4ba5-a7a6-334f5c69e4e3@d37g2000yqn.googlegroups.com> Message-ID: On Tue, Mar 23, 2010 at 4:50 PM, Shashwat Anand wrote: > There is a project PyWhip (renamed as PyKata) which aims for the same > purpose. Google AppEmgine + Django does the trick for that. May be you can > take an inspiration or two from there especially because all code is open > to/for you. But, if I understand PyWhip/PyKata after glancing at the project page, it doesn't actually run code in the browser... Regards, Pat From emile at fenx.com Tue Mar 23 18:34:48 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 23 Mar 2010 15:34:48 -0700 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <1269382176.23636.1366365237@webmail.messagingengine.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: On 3/23/2010 3:09 PM python at bdurham.com said... > I'm looking for a pythonic way to trim and keep leading > whitespace in a string. > > Use case: I have a bunch of text strings with various amounts of > leading and trailing whitespace (spaces and tabs). I want to grab > the leading and trailing whitespace, save it, surround the > remaining text with html tags, and then add back the leading and > trailing whitespace. I'd do it this way: target = ' spam and eggs ' stripped = target.strip() replaced = target.replace(stripped,"%s" % stripped) HTH, Emile > > The only solution I can think of is regex, and that makes me > think of the 2 proverbial problems that come with that :) > > Is there a 'better' solution than regex for this scenario? (Seems > like this would be a common type of string processing). > > Thanks, > Malcolm > > From daniel.chiquito at gmail.com Tue Mar 23 18:39:15 2010 From: daniel.chiquito at gmail.com (Daniel Chiquito) Date: Tue, 23 Mar 2010 18:39:15 -0400 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <1269382176.23636.1366365237@webmail.messagingengine.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: <9deff17c1003231539kfdef1cfn5fd45e06e330d613@mail.gmail.com> As far as I know, I don't think there is anything that strips it and returns the material that was stripped. Regex's would be your best bet. Daniel On Tue, Mar 23, 2010 at 6:09 PM, wrote: > I'm looking for a pythonic way to trim and keep leading whitespace in a > string. > > Use case: I have a bunch of text strings with various amounts of leading > and trailing whitespace (spaces and tabs). I want to grab the leading and > trailing whitespace, save it, surround the remaining text with html tags, > and then add back the leading and trailing whitespace. > > The only solution I can think of is regex, and that makes me think of the 2 > proverbial problems that come with that :) > > Is there a 'better' solution than regex for this scenario? (Seems like this > would be a common type of string processing). > > Thanks, > Malcolm > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- ~ -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Tue Mar 23 18:42:47 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 23 Mar 2010 23:42:47 +0100 Subject: Unicode blues in Python3 In-Reply-To: References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: <4BA943E7.5000202@v.loewis.de> nn wrote: > > Stefan Behnel wrote: >> nn, 23.03.2010 19:46: >>> Actually what I want is to write a particular byte to standard output, >>> and I want this to work regardless of where that output gets sent to. >>> I am aware that I could do >>> open('nnout','w',encoding='latin1').write(mychar) but I am porting a >>> python2 program and don't want to rewrite everything that uses that >>> script. >> Are you writing text or binary data to stdout? >> >> Stefan > > latin1 charset text. Are you sure about that? If you carefully reconsider, could you come to the conclusion that you are not writing text at all, but binary data? If it really was text that you write, why do you need to use U+00FD (LATIN SMALL LETTER Y WITH ACUTE). To my knowledge, that character is really infrequently used in practice. So that you try to write it strongly suggests that it is not actually text what you are writing. Also, your formulation suggests the same: "Is there any way to write a value 253 to standard output?" If you would really be writing text, you'd ask "Is there any way to write '?' to standard output?" Regards, Martin From vinay_sajip at yahoo.co.uk Tue Mar 23 18:43:40 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 23 Mar 2010 15:43:40 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> Message-ID: <0301d0b5-5d5d-436f-a342-16fe81b340d7@t41g2000yqt.googlegroups.com> On Mar 23, 8:49?pm, Pascal Chambon wrote: > > Should I open an issue for this evolution of exceptiuon handling, or > should we content ourselves of this "hacking" of frame stck ? > Possibly worth raising an issue (not logging-related), but perhaps it's worth seeing if this has come up before creating the issue. Regards, Vinay Sajip From python at bdurham.com Tue Mar 23 18:45:36 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 23 Mar 2010 18:45:36 -0400 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: <1269384336.29264.1366374513@webmail.messagingengine.com> Emile, > target = ' spam and eggs ' > stripped = target.strip() > replaced = target.replace(stripped,"%s" % stripped) Brilliant! That's just the type of clever solution I was looking for. Thank you! Malcolm ----- Original message ----- From: "Emile van Sebille" To: python-list at python.org Date: Tue, 23 Mar 2010 15:34:48 -0700 Subject: Re: Pythonic way to trim and keep leading and trailing whitespace On 3/23/2010 3:09 PM python at bdurham.com said... > I'm looking for a pythonic way to trim and keep leading > whitespace in a string. > > Use case: I have a bunch of text strings with various amounts of > leading and trailing whitespace (spaces and tabs). I want to grab > the leading and trailing whitespace, save it, surround the > remaining text with html tags, and then add back the leading and > trailing whitespace. I'd do it this way: target = ' spam and eggs ' stripped = target.strip() replaced = target.replace(stripped,"%s" % stripped) HTH, Emile > > The only solution I can think of is regex, and that makes me > think of the 2 proverbial problems that come with that :) > > Is there a 'better' solution than regex for this scenario? (Seems > like this would be a common type of string processing). > > Thanks, > Malcolm > > -- http://mail.python.org/mailman/listinfo/python-list From anand.shashwat at gmail.com Tue Mar 23 18:50:25 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 04:20:25 +0530 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <9deff17c1003231539kfdef1cfn5fd45e06e330d613@mail.gmail.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> <9deff17c1003231539kfdef1cfn5fd45e06e330d613@mail.gmail.com> Message-ID: regex is not goto that you should always avoid using it. It have its own use-case, here regex solution is intuitive although @emile have done this for you via string manpulation. On Wed, Mar 24, 2010 at 4:09 AM, Daniel Chiquito wrote: > As far as I know, I don't think there is anything that strips it and > returns the material that was stripped. Regex's would be your best bet. > > Daniel > > On Tue, Mar 23, 2010 at 6:09 PM, wrote: > >> I'm looking for a pythonic way to trim and keep leading whitespace in a >> string. >> >> Use case: I have a bunch of text strings with various amounts of leading >> and trailing whitespace (spaces and tabs). I want to grab the leading and >> trailing whitespace, save it, surround the remaining text with html tags, >> and then add back the leading and trailing whitespace. >> >> The only solution I can think of is regex, and that makes me think of the >> 2 proverbial problems that come with that :) >> >> Is there a 'better' solution than regex for this scenario? (Seems like >> this would be a common type of string processing). >> >> Thanks, >> Malcolm >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > ~ > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue Mar 23 19:38:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Mar 2010 18:38:10 -0500 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: <1269382176.23636.1366365237@webmail.messagingengine.com> References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: <4BA950E2.4020708@tim.thechases.com> python at bdurham.com wrote: > I'm looking for a pythonic way to trim and keep leading > whitespace in a string. > > Use case: I have a bunch of text strings with various amounts of > leading and trailing whitespace (spaces and tabs). I want to grab > the leading and trailing whitespace, save it, surround the > remaining text with html tags, and then add back the leading and > trailing whitespace. > > The only solution I can think of is regex, and that makes me > think of the 2 proverbial problems that come with that :) Just in case you're okay with a regexp solution, you can use >>> s = "\t\tabc def " >>> import re >>> r = re.compile(r'^(\s*)(.*?)(\s*)$') >>> m = re.match(s) >>> m.groups() ('\t\t', 'abc def', ' ') >>> leading, text, trailing = m.groups() While Emile's solution works nicely for your particular use-case, in the event you need to discern between leading/trailing whitespace, the above makes it pretty easy. -tkc From martin.hellwig at dcuktec.org Tue Mar 23 19:57:23 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 23 Mar 2010 23:57:23 +0000 Subject: Pythonic way to trim and keep leading and trailing whitespace In-Reply-To: References: <1269382176.23636.1366365237@webmail.messagingengine.com> Message-ID: On 03/23/10 23:38, Tim Chase wrote: > Just in case you're okay with a regexp solution, you can use > > >>> s = "\t\tabc def " > >>> import re > >>> r = re.compile(r'^(\s*)(.*?)(\s*)$') > >>> m = re.match(s) > >>> m.groups() > ('\t\t', 'abc def', ' ') > >>> leading, text, trailing = m.groups() Ahhh regex, the hammer, Swiss Army Knife, cable tie, duct tape, superglue and soldering iron, all wrapped in one*. Mastery of it will enable you to drive the nails in your coffin at an incomparable speed. :-) *Yes I was a sysadmin, why do you ask? -- mph From nilly16 at yahoo.com Tue Mar 23 20:05:09 2010 From: nilly16 at yahoo.com (Jimbo) Date: Tue, 23 Mar 2010 17:05:09 -0700 (PDT) Subject: Advice Criticism on Python App Message-ID: I have made a Python App(really script) that will check a stocks current values from a website & save that data to a SQLite 3 database. I am looking for any suggestions & criticisms on what I should do better or anything at all but mainly in these areas: [QUOTE] - Correct Python Layout of code - Correct error checking: Am I catching all my errors or are my exceptions not specific enough? Should I be using more try excepts inside my functions? - Are there any areas where huge errors, bugs etc could occur that I have not compensated for? - I am also looking for suggestions on how to write a function better, so if you think that function is really bad & should be rewritten completely or something I would really like to hear it. - Anything else that you see - Is python meant to be used in the way I have used it? To make a 'semi detailed' app?[/QUOTE] Any advice criticism would be really helpful. App: [CODE]""" *Stock Data Builder* Algorithm: - Search website for stock - Get website HTML source code - Search code for target stock data(price,dividends,etc..) - Add data to text file """ import sys import os import sqlite3 import datetime import time import urllib2 ### Global Variables ### menu = "***Stock Program*** \n\n1. Add a Stock to track \n2. Get Todays Tracking Data \n3. Exit \nEnter decision: " target = '

",sourceCode) getStockData(targetData,Stock) Stock.printStats() #writeStockToDatabase(conn,Stock) else: print "You must first identify a stock to follow. \nPlease select option 1." elif (decision==3): print "Thank you for using Stock Program. Goodbye.\n" programEnd = True; # Exit program conn.close() return 0 # End program main()[/CODE] From clp2 at rebertia.com Tue Mar 23 21:32:11 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Mar 2010 18:32:11 -0700 Subject: Advice Criticism on Python App In-Reply-To: References: Message-ID: <50697b2c1003231832i280655adu9c52ee45f9c1de15@mail.gmail.com> On Tue, Mar 23, 2010 at 5:05 PM, Jimbo wrote: > I have made a Python App(really script) that will check a stocks > current values from a website & save that data to a SQLite 3 database. > > I am looking for any suggestions & criticisms on what I should do > better or anything at all but mainly in these areas: > Any advice criticism would be really helpful. Complying with Python naming conventions would be one place to start: * Class names should be in StudlyCaps (so class "Stock", not class "stock"). * Constants should be in UPPERCASE_WITH_UNDERSCORES. * Most other names should be words_separated_by_underscores, not camelCaseLikeThis; FWIW, I'm not a fan of this part of the guideline personally. Also, conditions don't need parentheses around them. So: if (decision == 1): #WRONG! harder to read, extra syntactic noise if decision == 1: #RIGHT For many more style details, see PEP 8 -- Style Guide for Python Code: http://www.python.org/dev/peps/pep-0008/ Additionally, the "return 0" in main() serves no purpose; the return value isn't used as the exit code for the program. You can either eliminate the line entirely or use plain "return" if you want the extra clarity. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Tue Mar 23 21:36:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Mar 2010 01:36:31 +0000 Subject: Advice Criticism on Python App In-Reply-To: References: Message-ID: <4BA96C9F.9080301@mrabarnett.plus.com> Jimbo wrote: > I have made a Python App(really script) that will check a stocks > current values from a website & save that data to a SQLite 3 database. > > I am looking for any suggestions & criticisms on what I should do > better or anything at all but mainly in these areas: > [QUOTE] > - Correct Python Layout of code > - Correct error checking: Am I catching all my errors or are my > exceptions not specific enough? Should I be using more try excepts > inside my functions? > - Are there any areas where huge errors, bugs etc could occur that I > have not compensated for? > - I am also looking for suggestions on how to write a function better, > so if you think that function is really bad & should be rewritten > completely or something I would really like to hear it. > - Anything else that you see > - Is python meant to be used in the way I have used it? To make a > 'semi detailed' app?[/QUOTE] > > Any advice criticism would be really helpful. > > App: > [CODE]""" > *Stock Data Builder* > Algorithm: > - Search website for stock > - Get website HTML source code > - Search code for target stock data(price,dividends,etc..) > - Add data to text file > """ > > import sys > import os > import sqlite3 > import datetime > import time > import urllib2 > > ### Global Variables ### > menu = "***Stock Program*** \n\n1. Add a Stock to track \n2. Get > Todays Tracking Data \n3. Exit \nEnter decision: " > target = '",sourceCode) > getStockData(targetData,Stock) > Stock.printStats() > #writeStockToDatabase(conn,Stock) > else: > print "You must first identify a stock to follow. > \nPlease select option 1." > elif (decision==3): > print "Thank you for using Stock Program. Goodbye.\n" > programEnd = True; # Exit program > > conn.close() > return 0 # End program > 'main' is called by the main program and its return value is never used, so just omit this return statement. > main()[/CODE] The recommended standard in Python is for names of classes to be CamelCase, names of constants to be UPPERCASE_WITH_UNDERSCORES, and names of everything else to be lowercase_with_underscores. From no.email at nospam.invalid Tue Mar 23 21:39:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Mar 2010 18:39:49 -0700 Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> <7xwrx3mxuj.fsf@ruckus.brouhaha.com> <7xpr2v2wd7.fsf@ruckus.brouhaha.com> Message-ID: <7xaaty4hwa.fsf@ruckus.brouhaha.com> Antoine Pitrou writes: >> See: http://www.cs.rice.edu/~scrosby/hash/ ... > Certainly interesting in a purely academic point of view, but in real > life if you want to cause a denial of service by overwhelming a server, > there are far more obvious options than trying to guess the server's use > of hash tables and trying to cause lots of collisions in them. If you look at the very low bandwidth used in some of those hashtable attacks, it's hard to see any other somewhat-generic attack that's comparably effective. Usually we think of "DOS" as involving massive botnets and the like, not a dribble of a few hundred characters per second. From vipshopper.us at hotmail.com Tue Mar 23 21:53:31 2010 From: vipshopper.us at hotmail.com (marrylin) Date: Tue, 23 Mar 2010 18:53:31 -0700 (PDT) Subject: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Message-ID: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Air jordan(1-24)shoes $33 UGG BOOT $50 Nike shox(R4,NZ,OZ,TL1,TL2,TL3) $35 Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 FREE SHIPPING From eire1130 at gmail.com Tue Mar 23 22:51:48 2010 From: eire1130 at gmail.com (JR) Date: Tue, 23 Mar 2010 19:51:48 -0700 (PDT) Subject: 'gcc' failed with exit status 1 Message-ID: <8e68f9ea-7c99-4d52-90f3-0ea90b8f5c57@z3g2000yqz.googlegroups.com> Hello All, I was hoping I could get some help with this issue with getting Cython to work. Earlier I had an issue that said "unable to find vcvarsall.bat" and it turns out there is an active bug report that covers that issue (I have a 64 bit windows system). I still hadn't installed 3.1.2, so I did that tonight and now I have the issue below. Any thoughts on what I am doing wrong? Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\James>cd C:\Python31 C:\Python31>python setup.py build_ext --inplace running build_ext cythoning hello.pyx to hello.c Error converting Pyrex file to C: ------------------------------------------------------------ ... def say_hello_to(name): ^ ------------------------------------------------------------ C:\Python31\hello.pyx:1:23: Unrecognized character building 'hello' extension C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python31\include - IC:\Pytho n31\PC -c hello.c -o build\temp.win-amd64-3.1\Release\hello.o hello.c:1:2: #error Do not use this file, it is the result of a failed Cython co mpilation. error: command 'gcc' failed with exit status 1 C:\Python31> From steven at REMOVE.THIS.cybersource.com.au Wed Mar 24 00:41:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Mar 2010 04:41:01 GMT Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: On Tue, 23 Mar 2010 11:46:33 -0700, nn wrote: > Actually what I want is to write a particular byte to standard output, > and I want this to work regardless of where that output gets sent to. What do you mean "work"? Do you mean "display a particular glyph" or something else? In bash: $ echo -e "\0101" # octal 101 = decimal 65 A $ echo -e "\0375" # decimal 253 ? but if I change the terminal encoding, I get this: $ echo -e "\0375" ? Or this: $ echo -e "\0375" ? depending on which encoding I use. I think your question is malformed. You need to work out what behaviour you actually want, before you can ask for help on how to get it. -- Steven From stefan_ml at behnel.de Wed Mar 24 02:48:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 24 Mar 2010 07:48:58 +0100 Subject: 'gcc' failed with exit status 1 In-Reply-To: <8e68f9ea-7c99-4d52-90f3-0ea90b8f5c57@z3g2000yqz.googlegroups.com> References: <8e68f9ea-7c99-4d52-90f3-0ea90b8f5c57@z3g2000yqz.googlegroups.com> Message-ID: JR, 24.03.2010 03:51: > I was hoping I could get some help with this issue with getting Cython > to work. Earlier I had an issue that said "unable to find > vcvarsall.bat" and it turns out there is an active bug report that > covers that issue (I have a 64 bit windows system). I still hadn't > installed 3.1.2, so I did that tonight and now I have the issue below. > Any thoughts on what I am doing wrong? > > > Microsoft Windows [Version 6.1.7600] > Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > C:\Users\James>cd C:\Python31 > > C:\Python31>python setup.py build_ext --inplace > running build_ext > cythoning hello.pyx to hello.c > > Error converting Pyrex file to C: > ------------------------------------------------------------ > ... > def say_hello_to(name): > ^ > ------------------------------------------------------------ > > C:\Python31\hello.pyx:1:23: Unrecognized character Given that you're on Windows, this looks like a known bug in Cython: http://trac.cython.org/cython_trac/ticket/520 This is due to the lack of universal newline support in the codecs module, which has been fixed in the new Py2.6+ 'io' module. A patch for Cython that switches to the new 'io' module and works around this issue in older Python versions is available: http://hg.cython.org/cython-devel/raw-rev/751bdd38b55c That being said, the simplest way to work around this issue is to switch to Unix line endings in your source file. Most editors support this without problems. Stefan From xenoszh at gmail.com Wed Mar 24 03:23:39 2010 From: xenoszh at gmail.com (Parker) Date: Wed, 24 Mar 2010 00:23:39 -0700 (PDT) Subject: Python is cool!! References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: On Mar 23, 4:55?pm, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... > > Any opinion this must be the one you want http://web2py.com/ From stef.mientki at gmail.com Wed Mar 24 03:52:02 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 24 Mar 2010 08:52:02 +0100 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4BA9C4A2.40100@gmail.com> On 23-03-2010 17:55, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... > > Any opinion > you might take a look at http://www.sagemath.org/ cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Mar 24 04:03:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 05:03:46 -0300 Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> <4BA7B4F7.6080404@wanadoo.fr> <0301d0b5-5d5d-436f-a342-16fe81b340d7@t41g2000yqt.googlegroups.com> Message-ID: En Tue, 23 Mar 2010 19:43:40 -0300, Vinay Sajip escribi?: > On Mar 23, 8:49 pm, Pascal Chambon wrote: >> >> Should I open an issue for this evolution of exceptiuon handling, or >> should we content ourselves of this "hacking" of frame stck ? > > Possibly worth raising an issue (not logging-related), but perhaps > it's worth seeing if this has come up before creating the issue. There is, from 2006: http://bugs.python.org/issue1553375 I'll add a patch+tests to this issue. -- Gabriel Genellina From joho.smithury at gmail.com Wed Mar 24 05:07:26 2010 From: joho.smithury at gmail.com (John Smithury) Date: Wed, 24 Mar 2010 17:07:26 +0800 Subject: Where can i reference the "regular expressions" Message-ID: Dear pythoners, I'm a new member to studay the python, i wan't to studay the "regular expressions" handle like below: ==============source============ the is name ==============source end========= after convert, the result like below: -------------------------result------------------------ {'t','t','e'}, {'i','s'}, {'n','a','m','e'} -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Wed Mar 24 05:18:14 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 24 Mar 2010 10:18:14 +0100 Subject: Where can i reference the "regular expressions" In-Reply-To: References: Message-ID: <6faf39c91003240218x770290c3l8c70ea5c3e70f6ac@mail.gmail.com> On Wed, Mar 24, 2010 at 10:07 AM, John Smithury wrote: > Dear pythoners, > > I'm a new member to studay the python, i wan't to studay the "regular > expressions" handle like below: > > ==============source============ > the > is > name > ==============source end========= > > > after convert, the result like below: > > -------------------------result------------------------ > {'t','t','e'}, > {'i','s'}, > {'n','a','m','e'} What did you think of yourself, and where did you get into the "I don't know what to do now" place? Why do you think your problem would have to do with regular expressions? -- Andr? Engels, andreengels at gmail.com From __peter__ at web.de Wed Mar 24 05:34:31 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Mar 2010 10:34:31 +0100 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Vinay Sajip wrote: > Sorry I'm a little late to this discussion. I could add a _findCaller > function to the module (not part of the public API, but replaceable by > someone who really needs to) which does the heavy lifting, and > Logger.findCaller just calls it. Then those who need to can implement > their own strategy, without needing to jump through hoops. Does that > approach sound helpful? You mean you'd have to monkey-patch logging._findCaller() instead of overriding logging.Logger.findCaller()? I don't see a big advantage in that. Here's an alternative proposal: simplify findCaller() by moving part of the code into a generator: def callers(self): """ Walk up the call stack. Helper for findCaller(). """ f = currentframe() #On some versions of IronPython, currentframe() returns None if #IronPython isn't run with -X:Frames. if f is not None: f = f.f_back while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) yield filename, f.f_lineno, co.co_name f = f.f_back def findCaller(self): """ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ for filename, lineno, funcname in self.callers(): if filename != _srcfile: return filename, lineno, funcname return UNKNOWN_CALLER Another simplification might be to have setLoggerClass() implicitly set the root logger and to drop the distinct RootLogger class completely. Note that I have no strong opinion on all this. If you leave things as is I'm fine with that. Peter From mail at timgolden.me.uk Wed Mar 24 05:41:00 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Mar 2010 09:41:00 +0000 Subject: using message loop for hotkey capturing In-Reply-To: References: Message-ID: <4BA9DE2C.6060307@timgolden.me.uk> On 23/03/2010 17:01, Alex Hall wrote: > Hi all, but mainly Tim Golden: > Tim, I am using your wonderful message loop for keyboard input, the > one on your site that you pointed me to a few months ago. It has been > working perfectly as long as I had only one dictionary of keys mapping > to one dictionary of functions, but now I want two of each. My program > has different modes, which may have varying keystrokes, and I also > have some global keystrokes which are the same across all modes, like > exiting or switching modes. I cannot figure out how to make the > message loop look in two dictionaries at onc. I tried using an if, > saying that if action_to_take was not set in the mode-specific > dictionary then look at the global dictionary, but it is like it is > never looking in the global dictionary at all. I get no syntax errors > or problems when running the program, so it has to be something in my > logic. There's definitely some confusion, as MRAB picked up, with the globalkeys / globalfuncs thing. I can see no problem with simply defining an additional pair of dictionaries parallel with each of the keys/funcs dictionaries (note that the numbers are different from those of othe other dictionaries as these are the registration ids of the hotkeys): global_keys = { 100: (68, win32com.MOD_ALT | win32con.MOD_CONTROL ...), ... } global_funcs = { 100 : dict.ShowLookupDialog, ... } Then your central action code could be something like: action_to_take = global_funcs.get (msg.wParam) or HOTKEY_ACTIONS.get (msg.wParam) if action_to_take: action_to_take () This assumes that the funcs dictionaries will only ever contain a valid function, so the only possible Falsish value will arise from the get returning None. TJG BTW, you're shadowing a couple of builtins: global & dict which might give you problems later if you needed them. There are other issues with the structure of your code but nothing a little refactoring couldn't sort out if you felt so inclined. From andreengels at gmail.com Wed Mar 24 05:50:37 2010 From: andreengels at gmail.com (Andre Engels) Date: Wed, 24 Mar 2010 10:50:37 +0100 Subject: Where can i reference the "regular expressions" In-Reply-To: References: <6faf39c91003240218x770290c3l8c70ea5c3e70f6ac@mail.gmail.com> Message-ID: <6faf39c91003240250p3327c795k6544ad089a96c464@mail.gmail.com> On Wed, Mar 24, 2010 at 10:34 AM, John Smithury wrote: > ==============source============ > the > is > name > ==============source end========= > > First, get the word only(discard the "" and ""), it can use > regular expression, right? > > the > is > name > Second, get a charactor in each word and compose like format {'t','h','e'} >>>>for a in line > > > Most import is learning the "regular expressions" var this example. Okay, then I'll go into that part. regex = re.compile("([^<>]*)") [^<>] here means "any character but < or >" * means that we have any number (zero or more) of such characters The brackets mean that this is the part of the expression we are interested in (the group) The expression as a whole thus means: First , then the part we are interested in, which is a random string of things that are not < or >, then To use this expression (assuming 'text' is the string you want to check: result = regex.findall(text) will find all occurences of the regular expression, and provide you with the content of the group. -- Andr? Engels, andreengels at gmail.com From jeanmichel at sequans.com Wed Mar 24 06:37:17 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Mar 2010 11:37:17 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BA9EB5D.5050003@sequans.com> Peter Otten wrote: > Vinay Sajip wrote: > > >> Sorry I'm a little late to this discussion. I could add a _findCaller >> function to the module (not part of the public API, but replaceable by >> someone who really needs to) which does the heavy lifting, and >> Logger.findCaller just calls it. Then those who need to can implement >> their own strategy, without needing to jump through hoops. Does that >> approach sound helpful? >> > > [snip] > > Note that I have no strong opinion on all this. If you leave things as is > I'm fine with that. > > Peter > Agreed, I'm not sure it's worth the effort Vinay. JM From mehgcap at gmail.com Wed Mar 24 06:43:24 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 06:43:24 -0400 Subject: exiting threaded program? Message-ID: Hi all, I have a program with a timer in it, therefore I have multiple threads. My method of exiting by using "user32.PostQuitMessage (0)" no longer seems to be doing the job since I added the timer. What else do I have to do to close my program? I say it is not closing because, before, I would be returned to a prompt in the cmd line, but now I cannot type in the cmd line window even after the program supposedly closes, whereas before I could have. Thanks. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From vinay_sajip at yahoo.co.uk Wed Mar 24 06:45:32 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 24 Mar 2010 03:45:32 -0700 (PDT) Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: On Mar 24, 9:34?am, Peter Otten <__pete... at web.de> wrote: > > You mean you'd have to monkey-patchlogging._findCaller() instead of > overridinglogging.Logger.findCaller()? > > I don't see a big advantage in that. > Only that you just have to replace a function, and not have to subclass Logger + override findCaller. And it's not especially monkey- patching if the function is put there specifically to be replaced when needed :-) > Another simplification might be to have setLoggerClass() implicitly set the > root logger and to drop the distinct RootLogger class completely. I can't remember now why I created a separate class for the root - I thought it might have some specialization which never happened. Of course, I'm not sure if anyone is using it, so I can't just get rid of it. Anyway, the root logger is in some sense special so it might be more useful in the future. > Note that I have no strong opinion on all this. If you leave things as is > I'm fine with that. Yes, it's hardly a common case that the OP is mentioning. AFAIK this is the first time it's come up. I just thought from your and Jean- Michel's solutions that there might be a need felt by more people to have this functionality be more flexible. Regards, Vinay Sajip From mehgcap at gmail.com Wed Mar 24 06:48:21 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 06:48:21 -0400 Subject: using message loop for hotkey capturing In-Reply-To: <4BA9DE2C.6060307@timgolden.me.uk> References: <4BA9DE2C.6060307@timgolden.me.uk> Message-ID: Thanks, it seems to be working for now... Hopefully that trend continues! On 3/24/10, Tim Golden wrote: > On 23/03/2010 17:01, Alex Hall wrote: >> Hi all, but mainly Tim Golden: >> Tim, I am using your wonderful message loop for keyboard input, the >> one on your site that you pointed me to a few months ago. It has been >> working perfectly as long as I had only one dictionary of keys mapping >> to one dictionary of functions, but now I want two of each. My program >> has different modes, which may have varying keystrokes, and I also >> have some global keystrokes which are the same across all modes, like >> exiting or switching modes. I cannot figure out how to make the >> message loop look in two dictionaries at onc. I tried using an if, >> saying that if action_to_take was not set in the mode-specific >> dictionary then look at the global dictionary, but it is like it is >> never looking in the global dictionary at all. I get no syntax errors >> or problems when running the program, so it has to be something in my >> logic. > > There's definitely some confusion, as MRAB picked up, with the > globalkeys / globalfuncs thing. I can see no problem with simply > defining an additional pair of dictionaries parallel with each of > the keys/funcs dictionaries (note that the numbers are different > from those of othe other dictionaries as these are the registration > ids of the hotkeys): > > global_keys = { > 100: (68, win32com.MOD_ALT | win32con.MOD_CONTROL ...), > ... > } > > global_funcs = { > 100 : dict.ShowLookupDialog, > ... > } > > Then your central action code could be something like: > > action_to_take = global_funcs.get (msg.wParam) or HOTKEY_ACTIONS.get > (msg.wParam) > if action_to_take: > action_to_take () > > This assumes that the funcs dictionaries will only ever contain a > valid function, so the only possible Falsish value will arise from > the get returning None. > > TJG > > BTW, you're shadowing a couple of builtins: global & dict which > might give you problems later if you needed them. There are other > issues with the structure of your code but nothing a little > refactoring couldn't sort out if you felt so inclined. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From mail at timgolden.me.uk Wed Mar 24 06:48:55 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Mar 2010 10:48:55 +0000 Subject: exiting threaded program? In-Reply-To: References: Message-ID: <4BA9EE17.4050606@timgolden.me.uk> On 24/03/2010 10:43, Alex Hall wrote: > Hi all, > I have a program with a timer in it, therefore I have multiple > threads. My method of exiting by using "user32.PostQuitMessage (0)" no > longer seems to be doing the job since I added the timer. What else do > I have to do to close my program? I say it is not closing because, > before, I would be returned to a prompt in the cmd line, but now I > cannot type in the cmd line window even after the program supposedly > closes, whereas before I could have. Thanks. > Make the timer thread a daemon? TJG From alfps at start.no Wed Mar 24 06:55:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 24 Mar 2010 11:55:34 +0100 Subject: exiting threaded program? In-Reply-To: References: Message-ID: * Alex Hall: > Hi all, > I have a program with a timer in it, therefore I have multiple > threads. Is the "therefore..." an inference or independendent information? If it is an inference then it may not be correct. For example, timers in a GUI program need not involve additional threads. > My method of exiting by using "user32.PostQuitMessage (0)" This sounds like the Windows API level accessed from Python, not Python level? At the Windows API level, as I recall PostQuitMessage results in a WM_QUIT posted to the current thread's message queue, where it'll be processed by this thread's message loop, if it has one, which will then ideally finish. Possibly, if you indeed have more than one thread, you're posting the WM_QUIT to the wrong thread -- to quit the app it needs to be posted to the main thread. > no > longer seems to be doing the job since I added the timer. What else do > I have to do to close my program? I say it is not closing because, > before, I would be returned to a prompt in the cmd line, but now I > cannot type in the cmd line window even after the program supposedly > closes, whereas before I could have. Thanks. Try to reduce the problem to a minimal complete program, and post that? Unless the above comments help? Cheers, - Alf From mehgcap at gmail.com Wed Mar 24 07:04:40 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 07:04:40 -0400 Subject: exiting threaded program? In-Reply-To: <4BA9EE17.4050606@timgolden.me.uk> References: <4BA9EE17.4050606@timgolden.me.uk> Message-ID: A daemon... Good idea, and that makes more sense for what the thread does anyway; it is just a timer, updating a variable by contacting a server every hour. By the way, just what is the difference between user32.PostQuitMessage (0) and sys.exit()? On 3/24/10, Tim Golden wrote: > On 24/03/2010 10:43, Alex Hall wrote: >> Hi all, >> I have a program with a timer in it, therefore I have multiple >> threads. My method of exiting by using "user32.PostQuitMessage (0)" no >> longer seems to be doing the job since I added the timer. What else do >> I have to do to close my program? I say it is not closing because, >> before, I would be returned to a prompt in the cmd line, but now I >> cannot type in the cmd line window even after the program supposedly >> closes, whereas before I could have. Thanks. >> > > Make the timer thread a daemon? > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From mail at timgolden.me.uk Wed Mar 24 07:08:06 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 24 Mar 2010 11:08:06 +0000 Subject: exiting threaded program? In-Reply-To: References: <4BA9EE17.4050606@timgolden.me.uk> Message-ID: <4BA9F296.4010504@timgolden.me.uk> On 24/03/2010 11:04, Alex Hall wrote: > A daemon... Good idea, and that makes more sense for what the thread > does anyway; it is just a timer, updating a variable by contacting a > server every hour. By the way, just what is the difference between > user32.PostQuitMessage (0) and sys.exit()? The former is a notification to a Windows message loop (something most Python programs don't have) that it should exit; the latter is a system call to exit the running program -- after any message loops have completed if applicable. BTW if you're running a Windows message loop anyway, you could just use Windows timers, catch the WM_TIMER message and avoid the complication of threads. Just an idea. TJG From info at egenix.com Wed Mar 24 08:36:39 2010 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 24 Mar 2010 13:36:39 +0100 Subject: ANN: eGenix mxODBC Zope Database Adapter 2.0.0 Message-ID: <4BAA0757.5050701@egenix.com> ________________________________________________________________________ ANNOUNCEMENT mxODBC Zope Database Adapter Version 2.0.0 for Zope and the Plone CMS Available for Zope 2.12 and later on Windows, Linux, Mac OS X, FreeBSD and other platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.0.0-GA.html ________________________________________________________________________ INTRODUCTION The eGenix mxODBC Zope Database Adapter allows you to easily connect your Zope or Plone installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, FreeBSD and other platforms. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. ________________________________________________________________________ NEWS We are pleased to announce a new version 2.0 of our mxODBC Zope DA product. The new version was changes to conform with the new Zope 2.12 layout and installation system and includes many enhancements over our previous 1.0 version: * Includes mxODBC 3.1 with updated support for many current ODBC drivers, giving you more portability and features for a wider range of database backends. * Mac OS X 10.6 (Snow Leopard) support. * Python 2.5 and 2.6 support. * Zero maintenance support to automatically reconnect the Zope connection after a network or database problem. * More flexible Unicode support with options to work with pure Unicode, plain strings or mixed setups - even for databases that don't support Unicode * Automatic and transparent text encoding and decoding * More flexible date/time support including options to work with Python datetime objects, mxDateTime, strings or tuples * New decimal support to have the Zope DA return decimal column values using Python's decimal objects. * Fully eggified to simplify easy_install and buildout based installation ________________________________________________________________________ UPGRADING If you have already bought mxODBC Zope DA 1.0.x licenses, we offer you a time limited upgrade option: * If you have purchased the licenses between 2009-06-01 and 2009-12-31 you can get a 20% discount on the full price of version 2.0. * If you have purchased the licenses after 2010-01-01 you can get a 40% discount on the full price of version 2.0. This offer is time limited until 2010-09-30. Please write to sales at egenix.com for details on how to get the needed discount coupons. ________________________________________________________________________ MORE INFORMATION For more information on the mxODBC Zope Database Adapter, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/zope/mxODBCZopeDA/ You can buy mxODBC Zope DA licenses online from the eGenix.com shop at: http://shop.egenix.com/ ________________________________________________________________________ Thank you, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Mar 24 2010) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From pruebauno at latinmail.com Wed Mar 24 09:03:31 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 24 Mar 2010 06:03:31 -0700 (PDT) Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> <4BA943E7.5000202@v.loewis.de> Message-ID: <0250ffe0-0bb0-4cb2-8c3e-6446fb51b0b8@r27g2000yqn.googlegroups.com> Martin v. Loewis wrote: > nn wrote: > > > > Stefan Behnel wrote: > >> nn, 23.03.2010 19:46: > >>> Actually what I want is to write a particular byte to standard output, > >>> and I want this to work regardless of where that output gets sent to. > >>> I am aware that I could do > >>> open('nnout','w',encoding='latin1').write(mychar) but I am porting a > >>> python2 program and don't want to rewrite everything that uses that > >>> script. > >> Are you writing text or binary data to stdout? > >> > >> Stefan > > > > latin1 charset text. > > Are you sure about that? If you carefully reconsider, could you come to > the conclusion that you are not writing text at all, but binary data? > > If it really was text that you write, why do you need to use > U+00FD (LATIN SMALL LETTER Y WITH ACUTE). To my knowledge, that > character is really infrequently used in practice. So that you try to > write it strongly suggests that it is not actually text what you are > writing. > > Also, your formulation suggests the same: > > "Is there any way to write a value 253 to standard output?" > > If you would really be writing text, you'd ask > > > "Is there any way to write '?' to standard output?" > > Regards, > Martin To be more informative I am both writing text and binary data together. That is I am embedding text from another source into stream that uses non-ascii characters as "control" characters. In Python2 I was processing it mostly as text containing a few "funny" characters. From pruebauno at latinmail.com Wed Mar 24 09:08:26 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 24 Mar 2010 06:08:26 -0700 (PDT) Subject: Unicode blues in Python3 References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: <5db21794-371b-42eb-8c08-06395149faea@y17g2000yqd.googlegroups.com> Steven D'Aprano wrote: > On Tue, 23 Mar 2010 11:46:33 -0700, nn wrote: > > > Actually what I want is to write a particular byte to standard output, > > and I want this to work regardless of where that output gets sent to. > > What do you mean "work"? > > Do you mean "display a particular glyph" or something else? > > In bash: > > $ echo -e "\0101" # octal 101 = decimal 65 > A > $ echo -e "\0375" # decimal 253 > ? > > but if I change the terminal encoding, I get this: > > $ echo -e "\0375" > ? > > Or this: > > $ echo -e "\0375" > ? > > depending on which encoding I use. > > I think your question is malformed. You need to work out what behaviour > you actually want, before you can ask for help on how to get it. > > > > -- > Steven Yes sorry it is a bit ambiguous. I don't really care what glyph is, the program reading my output reads 8 bit values expects the binary value 0xFD as control character and lets everything else through as is. From melanienicoleo at gmail.com Wed Mar 24 09:32:27 2010 From: melanienicoleo at gmail.com (melanienicoleo) Date: Wed, 24 Mar 2010 06:32:27 -0700 (PDT) Subject: UNDERAGE DAUGHTERS FUCK - FATHER-YOUNG DAUGHTER INCEST - SEXY YOUNG LEGS Message-ID: http://dizzyporn.com/2010-Mar/Preteen_Pantyhose_03.avi http://dizzyporn.com/2010-Mar/Young_Brazil_Teen_Model.avi http://dizzyporn.com/2010-Mar/Naked_Underage_Lolita.avi http://dizzyporn.com/2010-Mar/Underage_Hardcore_Fucking_720x480.avi http://dizzyporn.com/2010-Mar/Preteen_Cameltoe.mpeg http://dizzyporn.com/2010-Mar/Underage_Lesbian_Porn_07.avi http://dizzyporn.com/2010-Mar/Lolita_Pussy_Insertions_XviD.AC3.avi http://dizzyporn.com/2010-Mar/Black_Young_Baby_640x480.wmv http://dizzyporn.com/2010-Mar/3d_Underage_Hentai.avi http://dizzyporn.com/2010-Mar/Horny_Preteen_Pussy.avi http://dizzyporn.com/2010-Mar/Young_Girls_Squirting_Trailer.wmv http://dizzyporn.com/2010-Mar/Underage_Uncensored_XxX.avi http://dizzyporn.com/2010-Mar/Underage_Lolitas_Fucking.mpeg http://dizzyporn.com/2010-Mar/Japan_Underground_Lolita_Bondage_2008.JP.avi underage nudism preteen black girl lesbian sex mature and young russian lolita thumbs sweet young pussy free galleries underage japanese porn free lolita porn young girls poop preteen erected young russian model preteen lolitas tgp young chubby models underage illegal girls young male celebrities nude asian underage girls well hung young boys underage nude photos free young teen pussy nude underage teen art very young russian virgin sex very young gay studs petite underage nonude preteen cam photos bald preteen pussy young girls and boys nude lolita ls news lolita girls in pantyhose free young lolita ass selector bbs lolitas lolita sluts hands on science for young kids preteen nudists galleries preteen lolita ls magazine young black lolita cute young virgins preteen bbs loli bbs preteen young hairless girls impact of underage drinking hey young girl lolita underage bbs rompl lolita modeling pics young puffy nipple teen lolita dog sex fake underage amateur underage sex among young teens preteen underware young hot latin lesbians free young hardcore video porn sexy young models preteen underage models young black gays fucking lolitas preteen young adult nudists lolita cp preteen pre teen xxx lolita russian teens lolitas machine teen cute young art young models really younge anal free nude ls girl preteen pictures young male underwear models young girl thong very young teen redheads preteens lolitas very young voyeur real young porn live fast die young lolita twink porn pics preteen naturalist underaged schoolgirl young incest lollita clip young son & mom incest sites young asian gay dvd ukraine angels lolita birthday parties for preteens young japanese sluts sweet preteen pussy girls lolita bs little lolita bbs, little lolita lolita guestbook preteen girl pussy little lolitas top free underage preteen lolita sites lolitas slaves 10- russian teens young cute boys youngest schoolgirl uniform sex underage studio From solipsis at pitrou.net Wed Mar 24 09:41:11 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 24 Mar 2010 13:41:11 +0000 (UTC) Subject: Unicode blues in Python3 References: Message-ID: Le Tue, 23 Mar 2010 10:33:33 -0700, nn a ?crit?: > I know that unicode is the way to go in Python 3.1, but it is getting in > my way right now in my Unix scripts. How do I write a chr(253) to a > file? > > #nntst2.py > import sys,codecs > mychar=chr(253) > print(sys.stdout.encoding) > print(mychar) print() writes to the text (unicode) layer of sys.stdout. If you want to access the binary (bytes) layer, you must use sys.stdout.buffer. So: sys.stdout.buffer.write(chr(253).encode('latin1')) or: sys.stdout.buffer.write(bytes([253])) See http://docs.python.org/py3k/library/io.html#io.TextIOBase.buffer From lawandawil at gmail.com Wed Mar 24 10:14:48 2010 From: lawandawil at gmail.com (anthoony) Date: Wed, 24 Mar 2010 07:14:48 -0700 (PDT) Subject: PRETEEN ASIAN NUDES - UNCENSORED UNDERAGE SEX - YOUNG FUCK ASIAN Message-ID: <95203262-9476-4a0a-b5c8-d2061fb348c1@z4g2000yqa.googlegroups.com> http://dizzyporn.com/2010-Mar/Christine_Young_Masturbation_BDRip.XviD.AC.avi http://dizzyporn.com/2010-Mar/Young_Sisters__Mobile.Spycam.3gp http://dizzyporn.com/2010-Mar/Underage_Asian_Teens_Fucking.mpeg http://dizzyporn.com/2010-Mar/Hot_Lolita_Stripping.mpeg http://dizzyporn.com/2010-Mar/Lolitas_Fingering_Pussy_800x600.wmv http://dizzyporn.com/2010-Mar/Preteen_Forced_Fucking.mp4 http://dizzyporn.com/2010-Mar/Brutal_Lolita_Fucking_EDTV_720x576.avi http://dizzyporn.com/2010-Mar/Christine_Young_Hardcore_HDRip.XviD.DVDRip.avi http://dizzyporn.com/2010-Mar/Yong_Lolita_Sex.avi http://dizzyporn.com/2010-Mar/Young_Pissing_Scene.mpeg http://dizzyporn.com/2010-Mar/Lolita_Pussy_Licking_EDTV_720x576.avi http://dizzyporn.com/2010-Mar/Young_Lolita_Bondage_EDTV_640x480.avi http://dizzyporn.com/2010-Mar/Bizzare_Underage_Sex_HDRip.XviD.DVDRip.avi lolita girls young cute young butts nude preteen angels underage lolita models russian young lolita sex free underage porn webcams hot young chick blowjobs for free schoolgirls preteen sex fucking very young girls preteen nipples preteens with big breast youngest first ladies lesbian lolita girl underage nude boy real young tits underage school girls naked czech underage girl iligal underage young african girl hidden preteen lolitas preteen nude softcore amateur young blonde underage pedolove naked lolita underage underage youth lolitas young naked bbw underage lolita top sites preteen bbs pedo underage lolitas mature women young males russian preteen photos lolita model top nude sites rape lolita russian lolita monthly underage toons young teens giving blowjobs tiny young girls young blowjob facials bikini teen lolita young and pregnant young girl bikini beach young hardcore free thumbnails civil war underage enlistees young girls strip lolita boys naked young anal gapes underage italian models kinder lolitas ukraine lolita young girls cock preteen panty wetting nude young model little girl lolitas maxi young preteen gallery links preteen girls slumber partys ohio welfare office youngstown swimsuit preteen incest granny young dick petite young preteen asian girl boy boy gay teen young hot young blonde cheerleader teen petite young young up skirts young asian cumshots lolita teen girls kelli young forum young incest and rape pedo preteen pussy, pedo pussy amateur young blowjob little russian preteen adults and young boys preteenteen tits tiny preteen model bbs alcoholism and underage drinking youngest penis young blondes fucking young super models nn preteen girls black preteen models free gallery mature young preteen girls bbs youngest twink girls pics young deep throat fucking young virgins nude young indian little tiny girl preteen model junior high girls young From hv at tbz-pariv.de Wed Mar 24 10:29:03 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 24 Mar 2010 15:29:03 +0100 Subject: crypto: verify external pkcs7 signature Message-ID: <80ulu3Fg0jU1@mid.individual.net> Hi, some black box system gives me secKey.pkcs7 signature and a data file. The signature should be correct, but it fails. On newer system I get this: M2Crypto.SMIME.PKCS7_Error: digest failure on older systems (openssl-0.9.8h-28.10.1) I get PKCS7 routines:PKCS7_verify:signature failure:pk7_smime.c:312 On a system with openssl-0.9.8e-45.13 the script creates a core dump. Any hints? {{{ def verify(file): s = SMIME.SMIME() cert_file='CN=NW4.cert' x509=X509.load_cert(cert_file) sk=X509.X509_Stack() sk.push(x509) s.set_x509_stack(sk) # Load the signer's CA cert. In this case, because the signer's # cert is self-signed, it is the signer's cert itself. st = X509.X509_Store() st.load_info(cert_file) # CA Cert s.set_x509_store(st) from M2Crypto.BIO import File # Load the data, verify it. p7=SMIME.load_pkcs7('secKey.pkcs7') try: print s.verify(p7, File(open(file))) except (M2Crypto.SMIME.PKCS7_Error, M2Crypto.SMIME.SMIME_Error), exc: print '%s failed: %s' % (file, str(exc).strip()) return False return True }}} -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From python at bdurham.com Wed Mar 24 10:52:40 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 10:52:40 -0400 Subject: Sniffing encoding type by looking at file BOM header Message-ID: <1269442360.3213.1366489361@webmail.messagingengine.com> I assume there's no standard library function that wraps codecs.open() to sniff a file's BOM header and open the file with the appropriate encoding? My reading of the docs leads me to believe that there are 5 types of possible BOM headers with multiple names (synoymns?) for the same BOM encoding type. BOM = '\xff\xfe' BOM_LE = '\xff\xfe' BOM_UTF16 = '\xff\xfe' BOM_UTF16_LE = '\xff\xfe' BOM_BE = '\xfe\xff' BOM32_BE = '\xfe\xff' BOM_UTF16_BE = '\xfe\xff' BOM64_BE = '\x00\x00\xfe\xff' BOM_UTF32_BE = '\x00\x00\xfe\xff' BOM64_LE = '\xff\xfe\x00\x00' BOM_UTF32 = '\xff\xfe\x00\x00' BOM_UTF32_LE = '\xff\xfe\x00\x00' BOM_UTF8 = '\xef\xbb\xbf' Is the process of writing a BOM sniffer readlly as simple as detecting one of these 5 header types and then calling codecs.open() with the appropriate encoding= parameter? Note: I'm only interested in Unicode encodings. I am not interested in any of the non-Unicode encodings supported by the codecs module. Thank you, Malcolm From googler.1.webmaster at spamgourmet.com Wed Mar 24 11:09:27 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Wed, 24 Mar 2010 08:09:27 -0700 (PDT) Subject: C-API: Extract information from function object Message-ID: Hi, I have a reference to a function and would like to know how to extract information from a function object. Information I am looking for: line and file where this function is from. PyObject_Call can do this to when I call a function object and something failed so these information are written to the traceback. So any suggestions how to do that? Thx!! moerchendiser2k3 From anand.shashwat at gmail.com Wed Mar 24 11:17:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 20:47:12 +0530 Subject: spams Message-ID: Lately this list have been spammed a lot. Any workarounds by moderators? ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From yoavglazner at gmail.com Wed Mar 24 11:27:38 2010 From: yoavglazner at gmail.com (Glazner) Date: Wed, 24 Mar 2010 08:27:38 -0700 (PDT) Subject: Advice needed on parallel processing in python Message-ID: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Hi! I need to replace an app that does number crunching over a local network. it have about 50 computers as slaves each computer needs to run COM that will do the "job" right now the system uses MFC threads and DCOM to distribute the load. as i said, Now i'm trying to replace this system with python. I already use win32all and read about Pareller Python and Pyro. a requirement is that messages can be sent to the remote worker. If anyone can share experience I'll love to hear Many Thanks, Yoav Glazner From no.email at please.post Wed Mar 24 11:29:07 2010 From: no.email at please.post (kj) Date: Wed, 24 Mar 2010 15:29:07 +0000 (UTC) Subject: sum for sequences? Message-ID: Is there a sequence-oriented equivalent to the sum built-in? E.g.: seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) ? (By "sequence" I'm referring primarily to lists and tuples, and excluding strings, since for these there is ''.join()). TIA! ~K From yoavglazner at gmail.com Wed Mar 24 11:39:10 2010 From: yoavglazner at gmail.com (Glazner) Date: Wed, 24 Mar 2010 08:39:10 -0700 (PDT) Subject: sum for sequences? References: Message-ID: On Mar 24, 5:29?pm, kj wrote: > Is there a sequence-oriented equivalent to the sum built-in? ?E.g.: > > ? seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > > (By "sequence" I'm referring primarily to lists and tuples, and > excluding strings, since for these there is ''.join()). > > TIA! > > ~K try itertools.chain From neilc at norwich.edu Wed Mar 24 11:42:02 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Mar 2010 15:42:02 GMT Subject: sum for sequences? References: Message-ID: <80uq6aF6i4U1@mid.individual.net> On 2010-03-24, kj wrote: > > > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > > (By "sequence" I'm referring primarily to lists and tuples, and > excluding strings, since for these there is ''.join()). reduce, or functools.reduce in Python 3.1. >>> functools.reduce(operator.add, ((1, 2), (5, 6))) (1, 2, 5, 6) -- Neil Cerutti "It's not fun to build walls. But it's even less fun to live without walls in a world full of zombies." --Greedy Goblin From insomnia.iit.roorkee at gmail.com Wed Mar 24 11:42:44 2010 From: insomnia.iit.roorkee at gmail.com (insomnia iit roookee) Date: Wed, 24 Mar 2010 08:42:44 -0700 (PDT) Subject: coding contest Message-ID: IIT ROORKEE COGNIZANCE presents INSOMNIA :THE MIDNIGHT PROGRAMMING CONTEST... www.insomnia.cognizance.org.in Starts on : 27th March, 9:00 PM Cash prizes worth Rs.30,000 on stake for this round. (PS: Problems of previous rounds are available for practice.) From darcy at druid.net Wed Mar 24 11:42:51 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 24 Mar 2010 11:42:51 -0400 Subject: spams In-Reply-To: References: Message-ID: <20100324114251.ac0714c8.darcy@druid.net> On Wed, 24 Mar 2010 20:47:12 +0530 Shashwat Anand wrote: > Lately this list have been spammed a lot. Any workarounds by moderators? Not as long as it is gatewayed to Usenet. You can kill most of the spam by blocking anything from gmail.com with a Newsgroups line. Unfortunately you will also block a lot of legitimate postings. If they would turn off the gateway then legitimate posters can choose to join the list but as long as the gateway is there then there is no reason to switch. With the gateway off there are all sorts of tools to reduce spam. I think the best one is to set the flag to only allow subscribers to post and to start all new users as moderated and remove the moderation on the first posting as long as it is not spam. If the first posting is not spam then chances are none of the rest from that user will be spam. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Wed Mar 24 11:42:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 11:42:52 -0400 Subject: sum for sequences? In-Reply-To: References: Message-ID: kj wrote: > > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > > (By "sequence" I'm referring primarily to lists and tuples, and > excluding strings, since for these there is ''.join()). > Do you mean you want to flatten a list structure? There have been several discussions about this, which Google will find for you quite easily. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at please.post Wed Mar 24 12:05:10 2010 From: no.email at please.post (kj) Date: Wed, 24 Mar 2010 16:05:10 +0000 (UTC) Subject: What's the matter with docs.python.org? Message-ID: In the last couple of weeks, docs.python.org has been down repeatedly (like right now). Has anyone else noticed this? ~K From python at bdurham.com Wed Mar 24 12:17:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 12:17:16 -0400 Subject: Programmatically discovering encoding types supported by codecs module Message-ID: <1269447436.19612.1366507993@webmail.messagingengine.com> Is there a way to programmatically discover the encoding types supported by the codecs module? For example, the following link shows a table with Codec, Aliases, and Language columns. http://docs.python.org/library/codecs.html#standard-encodings I'm looking for a way to programmatically generate this table through some form of module introspection. Ideas? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Mar 24 12:19:09 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 12:19:09 -0400 Subject: What's the matter with docs.python.org? In-Reply-To: References: Message-ID: <1269447549.19932.1366508801@webmail.messagingengine.com> KJ, > In the last couple of weeks, docs.python.org has been down repeatedly > (like right now). Has anyone else noticed this? I've been surfing docs.python.org all morning and haven't had any problems. I'm connecting from Bethlehem, PA (USA). Malcolm From philip at semanchuk.com Wed Mar 24 12:19:19 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 24 Mar 2010 12:19:19 -0400 Subject: What's the matter with docs.python.org? In-Reply-To: References: Message-ID: <2329E820-C060-43F2-AE3C-0FBF53221AA9@semanchuk.com> On Mar 24, 2010, at 12:05 PM, kj wrote: > In the last couple of weeks, docs.python.org has been down repeatedly > (like right now). Has anyone else noticed this? http://downforeveryoneorjustme.com/docs.python.org Works for me... HTH Philip From duncan.booth at invalid.invalid Wed Mar 24 12:20:17 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 Mar 2010 16:20:17 GMT Subject: sum for sequences? References: Message-ID: kj wrote: > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? > Apart from the suggestions for Google for general list flattening, for this specific example you could just use the 'sum' built-in: >>> sum(((1, 2), (5, 6)), ()) (1, 2, 5, 6) Just give it an empty tuple as the starting value. From steve at holdenweb.com Wed Mar 24 12:24:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 12:24:55 -0400 Subject: What's the matter with docs.python.org? In-Reply-To: References: Message-ID: kj wrote: > > > In the last couple of weeks, docs.python.org has been down repeatedly > (like right now). Has anyone else noticed this? http://downforeveryoneorjustme.com/docs.python.org regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at please.post Wed Mar 24 12:25:45 2010 From: no.email at please.post (kj) Date: Wed, 24 Mar 2010 16:25:45 +0000 (UTC) Subject: What's the matter with docs.python.org? References: Message-ID: In Philip Semanchuk writes: >On Mar 24, 2010, at 12:05 PM, kj wrote: >> In the last couple of weeks, docs.python.org has been down repeatedly >> (like right now). Has anyone else noticed this? >http://downforeveryoneorjustme.com/docs.python.org Very handy. Thanks! ~K From gagsl-py2 at yahoo.com.ar Wed Mar 24 12:49:30 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 13:49:30 -0300 Subject: C-API: Extract information from function object References: Message-ID: En Wed, 24 Mar 2010 12:09:27 -0300, moerchendiser2k3 escribi?: > I have a reference to a function and would like to know how to extract > information from a function object. > > Information I am looking for: line and file where this function is > from. > > PyObject_Call can do this to when I call a function object and > something failed so these information are written to the traceback. So > any suggestions how to do that? See the Language Reference; the associated code object holds the file and starting line the function comes from. The traceback object contains better information (like the line being executed instead of the first one). Why don't you use it instead? -- Gabriel Genellina From anand.shashwat at gmail.com Wed Mar 24 13:12:09 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 22:42:09 +0530 Subject: spams In-Reply-To: <20100324114251.ac0714c8.darcy@druid.net> References: <20100324114251.ac0714c8.darcy@druid.net> Message-ID: seems good :) On Wed, Mar 24, 2010 at 9:12 PM, D'Arcy J.M. Cain wrote: > On Wed, 24 Mar 2010 20:47:12 +0530 > Shashwat Anand wrote: > > Lately this list have been spammed a lot. Any workarounds by moderators? > > Not as long as it is gatewayed to Usenet. You can kill most of the > spam by blocking anything from gmail.com with a Newsgroups line. > Unfortunately you will also block a lot of legitimate postings. > > If they would turn off the gateway then legitimate posters can choose > to join the list but as long as the gateway is there then there is no > reason to switch. > > With the gateway off there are all sorts of tools to reduce spam. I > think the best one is to set the flag to only allow subscribers to post > and to start all new users as moderated and remove the moderation on > the first posting as long as it is not spam. If the first posting is > not spam then chances are none of the rest from that user will be spam. > > -- > D'Arcy J.M. Cain | Democracy is three wolves > http://www.druid.net/darcy/ | and a sheep voting on > +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Mar 24 13:18:32 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 24 Mar 2010 13:18:32 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: <1269447436.19612.1366507993@webmail.messagingengine.com> References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: On Wed, Mar 24, 2010 at 12:17 PM, wrote: > Is there a way to programmatically discover the encoding types supported by > the codecs module? > > For example, the following link shows a table with Codec, Aliases, and > Language columns. > http://docs.python.org/library/codecs.html#standard-encodings > > I'm looking for a way to programmatically generate this table through some > form of module introspection. > > Ideas? > > Malcolm > -- According to my brief messing around with the REPL, encodings.aliases.aliases is a good place to start. I don't know of any way to get the Language column, but at the very least that will give you most of the supported encodings and any aliases they have. From torriem at gmail.com Wed Mar 24 13:33:46 2010 From: torriem at gmail.com (Michael Torrie) Date: Wed, 24 Mar 2010 11:33:46 -0600 Subject: Unicode blues in Python3 In-Reply-To: References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> Message-ID: <4BAA4CFA.7000907@gmail.com> Steven D'Aprano wrote: > I think your question is malformed. You need to work out what behaviour > you actually want, before you can ask for help on how to get it. It may or may not be malformed, but I understand the question. So let eme translate for you. How can he write arbitrary bytes ( 0x0 through 0xff) to stdout without having them mangled by encodings. It's a very simple question, really. Looks like Antoine Pitrou has answered this question quite nicely as well. From pruebauno at latinmail.com Wed Mar 24 13:34:20 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 24 Mar 2010 10:34:20 -0700 (PDT) Subject: Unicode blues in Python3 References: Message-ID: <408cc5cf-28ac-440e-9536-e557347c6c1f@i25g2000yqm.googlegroups.com> Antoine Pitrou wrote: > Le Tue, 23 Mar 2010 10:33:33 -0700, nn a ?crit?: > > > I know that unicode is the way to go in Python 3.1, but it is getting in > > my way right now in my Unix scripts. How do I write a chr(253) to a > > file? > > > > #nntst2.py > > import sys,codecs > > mychar=chr(253) > > print(sys.stdout.encoding) > > print(mychar) > > print() writes to the text (unicode) layer of sys.stdout. > If you want to access the binary (bytes) layer, you must use > sys.stdout.buffer. So: > > sys.stdout.buffer.write(chr(253).encode('latin1')) > > or: > > sys.stdout.buffer.write(bytes([253])) > > See http://docs.python.org/py3k/library/io.html#io.TextIOBase.buffer Just what I needed! Now I full control of the output. Thanks Antoine. The new io stack is still a bit of a mystery to me. Thanks everybody else, and sorry for confusing the issue. Latin1 just happens to be very convenient to manipulate bytes and is what I thought of initially to handle my mix of textual and non-textual data. From gagsl-py2 at yahoo.com.ar Wed Mar 24 13:39:20 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 14:39:20 -0300 Subject: Programmatically discovering encoding types supported by codecs module References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: En Wed, 24 Mar 2010 13:17:16 -0300, escribi?: > Is there a way to programmatically discover the encoding types > supported by the codecs module? > > For example, the following link shows a table with Codec, > Aliases, and Language columns. > http://docs.python.org/library/codecs.html#standard-encodings > > I'm looking for a way to programmatically generate this table > through some form of module introspection. After looking at how things are done in codecs.c and encodings/__init__.py I think you should enumerate all modules in the encodings package that define a getregentry function. Aliases come from encodings.aliases.aliases. -- Gabriel Genellina From wolfgang.lipp at gmail.com Wed Mar 24 13:44:13 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Wed, 24 Mar 2010 10:44:13 -0700 (PDT) Subject: Is it possible to use re2 from Python? References: Message-ID: yes we can! http://github.com/facebook/pyre2 as pointed out by http://stackoverflow.com/users/219162/daniel-stutzbach now gotta go and try it out. From wolfgang.lipp at gmail.com Wed Mar 24 13:47:22 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Wed, 24 Mar 2010 10:47:22 -0700 (PDT) Subject: how to do asynchronous http requests with epoll and python 3.1 Message-ID: <031f3a5b-28ac-42f0-a6a8-2cb7998cad6d@q16g2000yqq.googlegroups.com> i asked this question before on http://stackoverflow.com/questions/2489780/how-to-do-asynchronous-http-requests-with-epoll-and-python-3-1 but without a definitive answer as yet. can someone help me out? i want to do several simple http GET and POST requests in the same process using Python 3.1 without using threading. the original post: there is an interesting page [http://scotdoyle.com/python-epoll- howto.html][1] about how to do asnchronous / non-blocking / AIO http serving in python 3. there is the [tornado web server][2] which does include a non-blocking http client. i have managed to port parts of the server to python 3.1, but the implementation of the client requires [pyCurl][3] and [seems to have problems][4] (with one participant stating how ?Libcurl is such a pain in the neck?, and looking at the incredibly ugly pyCurl page i doubt pyCurl will arrive in py3+ any time soon). now that epoll is available in the standard library, it should be possible to do asynchronous http requests out of the box with python. i really do not want to use asyncore or whatnot; epoll has a reputation for being the ideal tool for the task, and it is part of the python distribution, so using anything but epoll for non-blocking http is highly counterintuitive (prove me wrong if you feel like it). oh, and i feel threading is horrible. no threading. i use [stackless] [5]. *people further interested in the topic of asynchronous http should not miss out on this [talk by peter portante at PyCon2010][6]; also of interest is [the keynote][7], where speaker antonio rodriguez at one point emphasizes the importance of having up-to-date web technology libraries right in the standard library.* [1]: http://scotdoyle.com/python-epoll-howto.html [2]: http://www.tornadoweb.org/ [3]: http://pycurl.sourceforge.net/ [4]: http://groups.google.com/group/python-tornado/browse_thread/thread/276059a076593266/c49e8f834497271e?lnk=gst&q=httpclient+trouble+with+epoll#c49e8f834497271e [5]: http://stackless.com/ [6]: http://python.mirocommunity.org/video/1501/pycon-2010-demystifying-non-bl [7]: http://python.mirocommunity.org/video/1605/pycon-2010-keynote-relentlessl From python at bdurham.com Wed Mar 24 13:55:32 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 13:55:32 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: <1269453332.6801.1366527617@webmail.messagingengine.com> Benjamin, > According to my brief messing around with the REPL, encodings.aliases.aliases is a good place to start. I don't know of any way to get the Language column, but at the very least that will give you most of the supported encodings and any aliases they have. Thank you - that's exactly the type of information I was looking for. I'm including the following for anyone browsing the mailing list archives in the future. Here's the snippet we're using to dynamically generate the codec documentation posted on the docs.python website. import encodings encodingDict = encodings.aliases.aliases encodingType = dict() for key, value in encodingDict.items(): if value not in encodingType: encodingType[ value ] = list() encodingType[ value ].append( key ) for key in sorted( encodingType.keys() ): aliases = sorted( encodingType[ key ] ) aliases = ', '.join( aliases ) print '%-20s%s' % ( key, aliases ) Regards, Malcolm From python at bdurham.com Wed Mar 24 13:58:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 13:58:47 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: References: <1269447436.19612.1366507993@webmail.messagingengine.com> Message-ID: <1269453527.7192.1366528303@webmail.messagingengine.com> Gabriel, > After looking at how things are done in codecs.c and encodings/__init__.py I think you should enumerate all modules in the encodings package that define a getregentry function. Aliases come from encodings.aliases.aliases. Thanks for looking into this for me. Benjamin Kaplan made a similar observation. My reply to him included the snippet of code we're using to generate the actual list of encodings that our software will support (thanks to Python's codecs and encodings modules). Your help is always appreciated :) Regards, Malcolm ----- Original message ----- From: "Gabriel Genellina" To: python-list at python.org Date: Wed, 24 Mar 2010 14:39:20 -0300 Subject: Re: Programmatically discovering encoding types supported by codecs module En Wed, 24 Mar 2010 13:17:16 -0300, escribi?: > Is there a way to programmatically discover the encoding types > supported by the codecs module? > > For example, the following link shows a table with Codec, > Aliases, and Language columns. > http://docs.python.org/library/codecs.html#standard-encodings > > I'm looking for a way to programmatically generate this table > through some form of module introspection. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From joncle at googlemail.com Wed Mar 24 14:13:11 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Mar 2010 11:13:11 -0700 (PDT) Subject: Advice needed on parallel processing in python References: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Message-ID: On 24 Mar, 15:27, Glazner wrote: > Hi! > > I need to replace an app that does number crunching over a local > network. > it have about 50 computers as slaves > each computer needs to run COM that will do the "job" > right now the system uses MFC threads and DCOM to distribute the load. > > as i said, Now i'm trying to replace this system with python. > I already use win32all and read about Pareller Python and Pyro. > > a requirement is that messages can be sent to the remote worker. > > If anyone can share experience I'll love to hear > > Many Thanks, > Yoav Glazner Would Celery suit? http://celeryproject.org/ hth Jon. From anand.shashwat at gmail.com Wed Mar 24 14:17:55 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Mar 2010 23:47:55 +0530 Subject: Advice needed on parallel processing in python In-Reply-To: References: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Message-ID: have you checked hadoop ? On Wed, Mar 24, 2010 at 11:43 PM, Jon Clements wrote: > On 24 Mar, 15:27, Glazner wrote: > > Hi! > > > > I need to replace an app that does number crunching over a local > > network. > > it have about 50 computers as slaves > > each computer needs to run COM that will do the "job" > > right now the system uses MFC threads and DCOM to distribute the load. > > > > as i said, Now i'm trying to replace this system with python. > > I already use win32all and read about Pareller Python and Pyro. > > > > a requirement is that messages can be sent to the remote worker. > > > > If anyone can share experience I'll love to hear > > > > Many Thanks, > > Yoav Glazner > > Would Celery suit? http://celeryproject.org/ > > hth > > Jon. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Wed Mar 24 15:35:27 2010 From: nagle at animats.com (John Nagle) Date: Wed, 24 Mar 2010 12:35:27 -0700 Subject: Unicode blues in Python3 In-Reply-To: <0250ffe0-0bb0-4cb2-8c3e-6446fb51b0b8@r27g2000yqn.googlegroups.com> References: <3a428b39-bab1-48f2-b7df-560a849b8883@d27g2000yqf.googlegroups.com> <4BA943E7.5000202@v.loewis.de> <0250ffe0-0bb0-4cb2-8c3e-6446fb51b0b8@r27g2000yqn.googlegroups.com> Message-ID: <4baa64e1$0$1632$742ec2ed@news.sonic.net> nn wrote: > To be more informative I am both writing text and binary data > together. That is I am embedding text from another source into stream > that uses non-ascii characters as "control" characters. In Python2 I > was processing it mostly as text containing a few "funny" characters. OK. Then you need to be writing arrays of bytes, not strings. Encoding is your problem. This has nothing to do with Unicode. John Nagle From leahy_rich at hotmail.com Wed Mar 24 16:26:51 2010 From: leahy_rich at hotmail.com (Richard Leahy) Date: Wed, 24 Mar 2010 22:26:51 +0200 Subject: help sending text to windows edit control Message-ID: I am trying to write text into a windows edit control using python. it seems to write to every control i try except the edit box not sure if this is a security measure or not. here is my code any help please. import os,sys,subprocess,time from subprocess import * from os import * from ctypes import * from ctypes.wintypes import * PROCESS_ALL_ACCESS = ( 0x000F0000 | 0x00100000 | 0xFFF ) kernel32 = windll.kernel32 pid = sys.argv[1] h_process = kernel32.OpenProcess( PROCESS_ALL_ACCESS, False, int(pid) ) if not h_process: print "[*] Couldn't acquire a handle to PID: %s" % pid sys.exit(0) user32 = windll.user32 # parent window window_handle = windll.user32.FindWindowA(None, "Windows App") if not window_handle: print "[*] cant find window" # 1 is the control id of the edit box child window #below line has no effect on the control for some reason?? windll.user32.SetDlgItemTextA(window_handle, 1, "test") # 2 is the control id of a button # this line works and changes the button text? not sure whats going on windll.user32.SetDlgItemTextA(window_handle, 2, "test") _________________________________________________________________ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969 -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Wed Mar 24 16:34:59 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 24 Mar 2010 16:34:59 -0400 Subject: Is there a way to detect an environment's "default" encoding type (Windows)? Message-ID: <1269462899.32722.1366552387@webmail.messagingengine.com> Is there a way to detect an environment's "default" encoding type under Windows? I'm not sure if code page and encoding mean the same thing here. For example: When I use Word on my US based version of Windows and decide to save a file as text, I am prompted with an encoding dialog that defaults to 'Windows (default)' which appears maps to their 'Western European (Windows)' code page which I assume maps to code page 1252. (That's a lot of assumptions!). I would like to be able to make the same assumption about text files produced on a user's system. (Of course our software will offer a way to explictly specify an encoding format as well). Here's what I've been able to dig up so far but I'm not sure how reliable this is or if its the same information Word is looking at when it offers a default encoding value. >>> import locale >>> locale.getdefaultlocale()[1] 'cp1252' Any ideas? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.mtarver at ukonline.co.uk Wed Mar 24 16:50:57 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Wed, 24 Mar 2010 13:50:57 -0700 (PDT) Subject: the Python Foundation Message-ID: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> >From the website The Python Software Foundation (PSF) is a 501(c)(3) non-profit corporation that holds the intellectual property rights behind the Python programming language. We manage the open source licensing for Python version 2.1 and later and own and protect the trademarks associated with Python. Could somebody explain 'what holding the intellectual property rights' means in this context and in what sense PSF manages the licensing and protects the trademarks associated with Python? This is for my education. thanks Mark From steven at REMOVE.THIS.cybersource.com.au Wed Mar 24 17:07:24 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Mar 2010 21:07:24 GMT Subject: sum for sequences? References: Message-ID: On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote: > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > ? Yes, sum. help(sum) is your friend. >>> a = range(2) >>> b = range(3) >>> c = range(4) >>> sum((a, b, c), []) [0, 1, 0, 1, 2, 0, 1, 2, 3] Beware though that sum on lists and tuples will be fairly inefficient if you have lots of them. You may find that this will be much more efficient: result = [] for seq in sequences: result.extend(seq) -- Steven From robert.kern at gmail.com Wed Mar 24 17:09:09 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Mar 2010 16:09:09 -0500 Subject: the Python Foundation In-Reply-To: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: On 2010-03-24 15:50 PM, Mark Tarver wrote: >> From the website > > The Python Software Foundation (PSF) is a 501(c)(3) non-profit > corporation that > holds the intellectual property rights behind the Python programming > language. We manage the open source licensing for Python version 2.1 > and later and own and protect the trademarks associated with Python. > > Could somebody explain 'what holding the intellectual property rights' > means in this context and in what sense PSF manages the licensing and > protects the trademarks associated with Python? This is for my > education. The PSF owns the Python language trademark: http://tess2.uspto.gov/bin/showfield?f=doc&state=4007:oc64of.5.1 Its trademark policy is given in detail here: http://www.python.org/psf/trademarks/ It also controls the license of the Python interpreter and its surrounding code. Contributors license their code to the PSF. Contributors keep the copyright to their code, but they agree to give the PSF the right to distribute it under a different license if the PSF decides to change licenses. See the Contributor Agreement: http://www.python.org/psf/contrib/contrib-form/ I believe they also outright own the copyright to most of the code that was in the Python 2.1 release and up until this Contributor Agreement was set up. I could be wrong about that, though. -- 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 From mehgcap at gmail.com Wed Mar 24 17:12:45 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 17:12:45 -0400 Subject: timers not canceling! Message-ID: Hi all, I am having trouble with a timer I am trying to use. It is the same timer, but I need to cancel it when a certain event happens, then start it again when a second event happens. The below is from a shell session, not a file, but it shows my problem: I call cancel on a timer, then call start on it, and it thinks it is already running? What am I missing? >>> from threading import Timer >>> def func(): ... print("Time up!") ... >>> t=Timer(10.0, func) >>> t.start() >>> t.cancel() >>> t.start() Traceback (most recent call last): File "", line 1, in File "C:\python26\lib\threading.py", line 465, in start raise RuntimeError("thread already started") RuntimeError: thread already started >>> I typed start, then typed cancel within ten seconds (probably four or five), then called start again a couple seconds later. I figured canceling the timer would kill the thread so I could start it again. I am not looking for a reset, since I do not want it counting always. Thanks. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From chairman at python.org Wed Mar 24 17:18:39 2010 From: chairman at python.org (Steve Holden, Chairman, PSF) Date: Wed, 24 Mar 2010 17:18:39 -0400 Subject: the Python Foundation In-Reply-To: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: <4BAA81AF.1010308@python.org> Mark Tarver wrote: >>From the website > > The Python Software Foundation (PSF) is a 501(c)(3) non-profit > corporation that > holds the intellectual property rights behind the Python programming > language. We manage the open source licensing for Python version 2.1 > and later and own and protect the trademarks associated with Python. > > Could somebody explain 'what holding the intellectual property rights' > means in this context and in what sense PSF manages the licensing and > protects the trademarks associated with Python? This is for my > education. > The PSF requires that contributors sign an agreement licensing their code to us, and allowing us to distribute it under the license of our choosing (this does not in any way preclude the contributor licensing the same code to any other party under different terms). In this way people who use Python can be relatively sure that the code is untrammeled by claims of copyright or patent by anyone other than the PSF, and can therefore use it without fear of losing their rights to do so because of legal action by third parties. We have also registered the trademark "Python" for use in reference to computer programming languages, thereby ensuring that we can take action should some ill-advised individual or organization decide to produce another language with "Python" in its name which we did not feel conformed sufficiently strictly to the language definition, for instance. The PSF has an established policy with regard to the use of its trademarks, which you can read at http://www.python.org/psf/trademarks/ regards Steve -- Steve Holden Chairman, Python Software Foundation See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Mar 24 17:36:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 17:36:20 -0400 Subject: timers not canceling! In-Reply-To: References: Message-ID: <4BAA85D4.8050405@holdenweb.com> Alex Hall wrote: > Hi all, > I am having trouble with a timer I am trying to use. It is the same > timer, but I need to cancel it when a certain event happens, then > start it again when a second event happens. The below is from a shell > session, not a file, but it shows my problem: I call cancel on a > timer, then call start on it, and it thinks it is already running? > What am I missing? > >>>> from threading import Timer >>>> def func(): > ... print("Time up!") > ... >>>> t=Timer(10.0, func) >>>> t.start() >>>> t.cancel() >>>> t.start() > Traceback (most recent call last): > File "", line 1, in > File "C:\python26\lib\threading.py", line 465, in start > raise RuntimeError("thread already started") > RuntimeError: thread already started > > I typed start, then typed cancel within ten seconds (probably four or > five), then called start again a couple seconds later. I figured > canceling the timer would kill the thread so I could start it again. I > am not looking for a reset, since I do not want it counting always. > Thanks. I believe you'll need to create a new Timer each time you need one - a Timer is a threading.thread, and these can only be started once. "thread already started" implies that the thread is running, but you actually get the same message if you try to start any terminated thread (including a canceled one), so "threads cannot be restarted" might be a better message. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Mar 24 17:36:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 17:36:20 -0400 Subject: timers not canceling! In-Reply-To: References: Message-ID: <4BAA85D4.8050405@holdenweb.com> Alex Hall wrote: > Hi all, > I am having trouble with a timer I am trying to use. It is the same > timer, but I need to cancel it when a certain event happens, then > start it again when a second event happens. The below is from a shell > session, not a file, but it shows my problem: I call cancel on a > timer, then call start on it, and it thinks it is already running? > What am I missing? > >>>> from threading import Timer >>>> def func(): > ... print("Time up!") > ... >>>> t=Timer(10.0, func) >>>> t.start() >>>> t.cancel() >>>> t.start() > Traceback (most recent call last): > File "", line 1, in > File "C:\python26\lib\threading.py", line 465, in start > raise RuntimeError("thread already started") > RuntimeError: thread already started > > I typed start, then typed cancel within ten seconds (probably four or > five), then called start again a couple seconds later. I figured > canceling the timer would kill the thread so I could start it again. I > am not looking for a reset, since I do not want it counting always. > Thanks. I believe you'll need to create a new Timer each time you need one - a Timer is a threading.thread, and these can only be started once. "thread already started" implies that the thread is running, but you actually get the same message if you try to start any terminated thread (including a canceled one), so "threads cannot be restarted" might be a better message. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steven at REMOVE.THIS.cybersource.com.au Wed Mar 24 17:38:08 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Mar 2010 21:38:08 GMT Subject: timers not canceling! References: Message-ID: On Wed, 24 Mar 2010 17:12:45 -0400, Alex Hall wrote: > Hi all, > I am having trouble with a timer I am trying to use. It is the same > timer, but I need to cancel it when a certain event happens, then start > it again when a second event happens. The below is from a shell session, > not a file, but it shows my problem: I call cancel on a timer, then call > start on it, and it thinks it is already running? What am I missing? > >>>> from threading import Timer >>>> def func(): > ... print("Time up!") > ... >>>> t=Timer(10.0, func) >>>> t.start() >>>> t.cancel() >>>> t.start() > Traceback (most recent call last): > File "", line 1, in > File "C:\python26\lib\threading.py", line 465, in start > raise RuntimeError("thread already started") > RuntimeError: thread already started The start method is to start generic threads, not just timers, and threads don't support being restarted. Timers are fairly simple objects: after you start the thread, they just wait until the time expires, then run a function. You can cancel them, but not pause and restart them. To do what you are trying to do, you will need to subclass either Timer or thread and implement your own logic for pausing or restarting the count down. > I typed start, then typed cancel within ten seconds (probably four or > five), then called start again a couple seconds later. I figured > canceling the timer would kill the thread so I could start it again. That's not how they work. "start" means "start the thread", not "start the timer", and threads cannot be restarted. The documentation is very clear: "start() Start the thread?s activity. It must be called at most once per thread object. It arranges for the object?s run() method to be invoked in a separate thread of control." http://docs.python.org/library/threading.html#thread-objects -- Steven From martin at v.loewis.de Wed Mar 24 18:22:01 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 24 Mar 2010 23:22:01 +0100 Subject: RELEASED Python 2.6.5 In-Reply-To: References: Message-ID: > Is anyone else having trouble with the 2.6.5 Windows x86 installer? Not me. Run msiexec /i py...msi /l*v py.log and inspect py.log for errors (post it to bugs.python.org if you can't determine the cause of the problems). Are you using SUBST by any chance? Regards, Martin From gagsl-py2 at yahoo.com.ar Wed Mar 24 18:50:11 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Mar 2010 19:50:11 -0300 Subject: Programmatically discovering encoding types supported by codecs module References: <1269447436.19612.1366507993@webmail.messagingengine.com> <1269453527.7192.1366528303@webmail.messagingengine.com> Message-ID: En Wed, 24 Mar 2010 14:58:47 -0300, escribi?: >> After looking at how things are done in codecs.c and >> encodings/__init__.py I think you should enumerate all modules in the >> encodings package that define a getregentry function. Aliases come from >> encodings.aliases.aliases. > > Thanks for looking into this for me. Benjamin Kaplan made a similar > observation. My reply to him included the snippet of code we're using to > generate the actual list of encodings that our software will support > (thanks to Python's codecs and encodings modules). I was curious as whether both methods would give the same results: py> modules=set() py> for name in glob.glob(os.path.join(encodings.__path__[0], "*.py")): ... name = os.path.basename(name)[:-3] ... try: mod = __import__("encodings."+name, fromlist=['ilovepythonbutsometimesihateit']) ... except ImportError: continue ... if hasattr(mod, 'getregentry'): ... modules.add(name) ... py> fromalias = set(encodings.aliases.aliases.values()) py> fromalias - modules set(['tactis']) py> modules - fromalias set(['charmap', 'cp1006', 'cp737', 'cp856', 'cp874', 'cp875', 'idna', 'iso8859_1', 'koi8_u', 'mac_arabic', 'mac_centeuro', 'mac_croatian', 'mac_farsi', 'mac_romanian', 'palmos', 'punycode', 'raw_unicode_escape', 'string_escape', 'undefined', 'unicode_escape', 'unicode_internal', 'utf_8_sig']) There is a missing 'tactis' encoding (?) and about twenty without alias. -- Gabriel Genellina From no.email at nospam.invalid Wed Mar 24 19:19:19 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Mar 2010 16:19:19 -0700 Subject: sum for sequences? References: Message-ID: <7x1vf91f60.fsf@ruckus.brouhaha.com> kj writes: > Is there a sequence-oriented equivalent to the sum built-in? E.g.: > seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) use itertools.chain for this. A few people have mentioned that sum will also work, but I think for that purpose it could have O(n**2) complexity. From no.email at nospam.invalid Wed Mar 24 19:22:17 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Mar 2010 16:22:17 -0700 Subject: the Python Foundation References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: <7xwrx1z4nq.fsf@ruckus.brouhaha.com> "Steve Holden, Chairman, PSF" writes: > We have also registered the trademark "Python" for use in reference to > computer programming languages, thereby ensuring that we can take action > should some ill-advised individual or organization decide to produce > another language with "Python" in its name There has been a Lisp compiler called "Python" for many years: http://portal.acm.org/citation.cfm?id=141471.141558 From steve at holdenweb.com Wed Mar 24 20:26:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 20:26:20 -0400 Subject: timers not canceling! In-Reply-To: <4BAA85D4.8050405@holdenweb.com> References: <4BAA85D4.8050405@holdenweb.com> Message-ID: <4BAAADAC.4030603@holdenweb.com> Steve Holden wrote: > Alex Hall wrote: [...] > "thread already started" implies that the thread is running, but you > actually get the same message if you try to start any terminated thread > (including a canceled one), so "threads cannot be restarted" might be a > better message. > Or, better still, "Threads can only be started once". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Mar 24 20:26:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Mar 2010 20:26:20 -0400 Subject: timers not canceling! In-Reply-To: <4BAA85D4.8050405@holdenweb.com> References: <4BAA85D4.8050405@holdenweb.com> Message-ID: <4BAAADAC.4030603@holdenweb.com> Steve Holden wrote: > Alex Hall wrote: [...] > "thread already started" implies that the thread is running, but you > actually get the same message if you try to start any terminated thread > (including a canceled one), so "threads cannot be restarted" might be a > better message. > Or, better still, "Threads can only be started once". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From patrickwasp at gmail.com Wed Mar 24 20:33:35 2010 From: patrickwasp at gmail.com (Waspinator) Date: Wed, 24 Mar 2010 17:33:35 -0700 (PDT) Subject: cxfreeze on ubuntu 9.10 Message-ID: <84719a38-3d00-4d46-aa11-f0dca7ace71c@q15g2000yqj.googlegroups.com> Hi, I'm trying to compile a python script on Ubuntu 9.10. It uses the gtk toolkit. I tried to run GUI2EXE for a cxfreeze gui, but even after installing wxPython in synaptic it still complains about not having it. I also tried to use cxfreeze by itself but the file it produces does not run. I tried to follow the information at http://cx-freeze.sourceforge.net/cx_Freeze.html I created a setup.py file that looks like this (from the page) from cx_Freeze import setup, Executable setup( name = "gtk_test", version = "0.1", description = "gtk_test", executables = [Executable("gtk_test.py")]) and ran: python setup.py build When I try to run the executable I get the following error: ../build/exe.linux-i686-2.6/library.zip/gtk/_gtk.py:12: RuntimeWarning: tp_compare didn't return -1 or -2 for exception ImportError: could not import gio ImportError: could not import gio Traceback (most recent call last): File "/usr/lib/pymodules/python2.6/cx_Freeze/initscripts/ Console.py", line 29, in exec code in m.__dict__ File "gtk_test.py", line 274, in File "gtk_test.py", line 228, in main AttributeError: 'module' object has no attribute 'Window' I was thinking of using the 'copy-dependent-files' option but I'm not sure how. Any ideas? Thanks From mehgcap at gmail.com Wed Mar 24 22:31:03 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 24 Mar 2010 22:31:03 -0400 Subject: threads (specifically timers) and releasing resources Message-ID: Okay, I have my program and it has three different modes (there will be more than that). Each mode will have a timer attached to it. If the mode remains active and the timer runs out, a function specific to that mode is called. If that mode is switched away from, however, the timer is canceled and a new timer is created for the mode to which the user just switched. My question is: what happens with resources taken up by previous timers, whether they cancel or execute? I would hate for my program to run for a long time and slowly build up a massive list of old threads (timers), taking up resources which should have been released. Will Python perform GC and completely erase a thread once it is done, or will it keep hanging around? If the latter, is there a way to completely destroy a thread? Thanks; Google was not too helpful on this one! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From kurianmthayil at gmail.com Wed Mar 24 22:59:38 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Thu, 25 Mar 2010 08:29:38 +0530 Subject: MySQLdb compiled -- Import issue Message-ID: <1269485978.14968.17.camel@localhost> Hi All, I am just a month old with Python and trying to learn CGI with Python. I was trying to install MySQLdb module in my new CentOS 5.3 box with Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb module (MySQL-python-1.2.3c1). Did build as normal user and install as root. MySQL server version that I'm using is 5.1.41, if that has anything to do with the error. I then copied, libmysqlclient_r.so.16 library to /usr/lib/ folder and then I am able to import the module as root user. But cannot do this as normal user. Now, while doing import MySQLdb as normal user, I get the following error message. The scripts will be run as apache and hence cannot have this error. Please check the following output. Also I have attached the output while doing build and install process. [kurianmt at server MySQL-python-1.2.3c1]$ python Python 2.4.3 (#1, Jan 21 2009, 01:10:13) [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path It would be a great help if I understand what's going on!!! Thanks in advance. Regards, Kurian Mathew Thayil. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- [kurianmt at server MySQL-python-1.2.3c1]$ python setup.py build running build running build_py creating build creating build/lib.linux-i686-2.4 copying _mysql_exceptions.py -> build/lib.linux-i686-2.4 creating build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/release.py -> build/lib.linux-i686-2.4/MySQLdb copying MySQLdb/times.py -> build/lib.linux-i686-2.4/MySQLdb creating build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.linux-i686-2.4/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-i686-2.4/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.linux-i686-2.4 gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fPIC -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/local/include/mysql -I/usr/include/python2.4 -c _mysql.c -o build/temp.linux-i686-2.4/_mysql.o -DUNIV_LINUX -DUNIV_LINUX In file included from _mysql.c:36: /usr/local/include/mysql/my_config.h:1050:1: warning: "HAVE_WCSCOLL" redefined In file included from /usr/include/python2.4/pyconfig.h:4, from /usr/include/python2.4/Python.h:8, from pymemcompat.h:10, from _mysql.c:29: /usr/include/python2.4/pyconfig-32.h:648:1: warning: this is the location of the previous definition gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -L/usr/local/lib/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -o build/lib.linux-i686-2.4/_mysql.so -------------- next part -------------- [root at server MySQL-python-1.2.3c1]# python setup.py install running install running bdist_egg running egg_info writing MySQL_python.egg-info/PKG-INFO writing top-level names to MySQL_python.egg-info/top_level.txt writing dependency_links to MySQL_python.egg-info/dependency_links.txt reading manifest file 'MySQL_python.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'MySQL_python.egg-info/SOURCES.txt' installing library code to build/bdist.linux-i686/egg running install_lib running build_py copying MySQLdb/release.py -> build/lib.linux-i686-2.4/MySQLdb running build_ext creating build/bdist.linux-i686 creating build/bdist.linux-i686/egg copying build/lib.linux-i686-2.4/_mysql.so -> build/bdist.linux-i686/egg copying build/lib.linux-i686-2.4/_mysql_exceptions.py -> build/bdist.linux-i686/egg creating build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/connections.py -> build/bdist.linux-i686/egg/MySQLdb creating build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/CR.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/__init__.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/REFRESH.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/FLAG.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/ER.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/constants/CLIENT.py -> build/bdist.linux-i686/egg/MySQLdb/constants copying build/lib.linux-i686-2.4/MySQLdb/__init__.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/times.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/release.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/cursors.py -> build/bdist.linux-i686/egg/MySQLdb copying build/lib.linux-i686-2.4/MySQLdb/converters.py -> build/bdist.linux-i686/egg/MySQLdb byte-compiling build/bdist.linux-i686/egg/_mysql_exceptions.py to _mysql_exceptions.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/connections.py to connections.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/CR.py to CR.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/__init__.py to __init__.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/FLAG.py to FLAG.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/ER.py to ER.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/__init__.py to __init__.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/times.py to times.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/release.py to release.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/cursors.py to cursors.pyc byte-compiling build/bdist.linux-i686/egg/MySQLdb/converters.py to converters.pyc creating stub loader for _mysql.so byte-compiling build/bdist.linux-i686/egg/_mysql.py to _mysql.pyc creating build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-i686/egg/EGG-INFO copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-i686/egg/EGG-INFO writing build/bdist.linux-i686/egg/EGG-INFO/native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist/MySQL_python-1.2.3c1-py2.4-linux-i686.egg' and adding 'build/bdist.linux-i686/egg' to it removing 'build/bdist.linux-i686/egg' (and everything under it) Processing MySQL_python-1.2.3c1-py2.4-linux-i686.egg Removing /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg Copying MySQL_python-1.2.3c1-py2.4-linux-i686.egg to /usr/lib/python2.4/site-packages MySQL-python 1.2.3c1 is already the active version in easy-install.pth Installed /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg Processing dependencies for MySQL-python==1.2.3c1 Finished processing dependencies for MySQL-python==1.2.3c1 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From half.italian at gmail.com Wed Mar 24 23:15:00 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Wed, 24 Mar 2010 20:15:00 -0700 (PDT) Subject: MySQLdb compiled -- Import issue References: Message-ID: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> On Mar 24, 7:59?pm, Kurian Thayil wrote: > Hi All, > > I am just a month old with Python and trying to learn CGI with Python. I > was trying to install MySQLdb module in my new CentOS 5.3 box with > Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb > module (MySQL-python-1.2.3c1). Did build as normal user and install as > root. MySQL server version that I'm using is 5.1.41, if that has > anything to do with the error. I then copied, libmysqlclient_r.so.16 > library to /usr/lib/ folder and then I am able to import the module as > root user. But cannot do this as normal user. > > Now, while doing import MySQLdb as normal user, I get the following > error message. The scripts will be run as apache and hence cannot have > this error. Please check the following output. Also I have attached the > output while doing build and install process. > > [kurianmt at server MySQL-python-1.2.3c1]$ python > Python 2.4.3 (#1, Jan 21 2009, 01:10:13) > [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb > > /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path > > It would be a great help if I understand what's going on!!! Thanks in > advance. > > Regards, > > Kurian Mathew Thayil. > > ?MySQLdb-build.txt > 3KViewDownload > > ?MySQLdb-Install.txt > 6KViewDownload > > ?signature.asc > < 1KViewDownload The warning looks familiar. Are you running python from the MySQLdb source directory? ie. /opt/downloads/py-modules/MySQL-python-1.2.3c1 I think you just need to change directories and the warning will go away. Check what's happening on line 3 of _mysql.py I don't have the source in front of me. ~Sean From aharrisreid at googlemail.com Wed Mar 24 23:17:52 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Thu, 25 Mar 2010 03:17:52 +0000 Subject: Super() function Message-ID: <4BAAD5E0.9050604@googlemail.com> Hi, Using Python 3.1, I sometimes use the super() function to call the equivalent method from a parent class, for example def mymethod(self): super().mymethod() some more code... Is there any way of writing the code so that the super() call is generic and automatically recognises the name of the current method (ie. something like super().thismethod()) or do I always have to repeat the method name after super()? TIA, Alan From littlesweetmelon at gmail.com Wed Mar 24 23:28:58 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 11:28:58 +0800 Subject: Is there any library for indexing binary data? Message-ID: Howdy, Recently, I am finding a good library for build index on binary data. Xapian & Lucene for python binding focus on text digestion rather than binary data. Could anyone give me some recommendation? Is there any library for indexing binary data no matter whether it is written in python? In my case, there is a very big datatable which stores structured binary data, eg: struct Item { long id; // used as key double value; }; I want to build the index on "id" field to speed on searching. Since this datatable is not constant, the library should support incremental indexing. If there is no suitable library, I have to do the index by myself... Thank you in advance. -- ShenLei From timr at probo.com Wed Mar 24 23:41:25 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Mar 2010 20:41:25 -0700 Subject: device identification References: <9c7ed2c8-f04b-4302-a4be-bde1628ef966@y11g2000prf.googlegroups.com> <46ggq59e49qpna7f9ae6q8ftobhot351un@4ax.com> <57c86289-85e7-4c9f-b7ed-787687d9a5b6@x23g2000prd.googlegroups.com> Message-ID: Omer Ihsan wrote: > >VID and PID is fair enough. now what i want is that i have a threaded >code that threads two functions to run at the same time. i want each >function to run seperate devices. the problem is if it doesnt identify >the attached devices it might run the code on a single device which >isnt what is required. Some of the libraries that pyusb uses are not thread-safe, like libusb 0.1. >how will i be able to run a code on a device of my choice???....you >can leave away the threading part for now. You can return all of the devices with a particular VID and PID: collection = usb.core.find( find_all=True, idVendor=0x1234, idProduct=0x5678 ) Then you can dish those out to threads using something like the queue module. Or, usb.core.find accepts a predicate function that allows you to use any criteria you wish. What kind of device are you trying to manipulate? I have a lot of USB experience -- perhaps I can offer advice. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kurianmthayil at gmail.com Wed Mar 24 23:41:26 2010 From: kurianmthayil at gmail.com (Kurian Thayil) Date: Thu, 25 Mar 2010 09:11:26 +0530 Subject: MySQLdb compiled -- Import issue In-Reply-To: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> References: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> Message-ID: <1269488486.14968.22.camel@localhost> On Wed, 2010-03-24 at 20:15 -0700, Sean DiZazzo wrote: > On Mar 24, 7:59 pm, Kurian Thayil wrote: > > Hi All, > > > > I am just a month old with Python and trying to learn CGI with Python. I > > was trying to install MySQLdb module in my new CentOS 5.3 box with > > Python 2.4.3 default install. I downloaded the tar-ball of MySQLdb > > module (MySQL-python-1.2.3c1). Did build as normal user and install as > > root. MySQL server version that I'm using is 5.1.41, if that has > > anything to do with the error. I then copied, libmysqlclient_r.so.16 > > library to /usr/lib/ folder and then I am able to import the module as > > root user. But cannot do this as normal user. > > > > Now, while doing import MySQLdb as normal user, I get the following > > error message. The scripts will be run as apache and hence cannot have > > this error. Please check the following output. Also I have attached the > > output while doing build and install process. > > > > [kurianmt at server MySQL-python-1.2.3c1]$ python > > Python 2.4.3 (#1, Jan 21 2009, 01:10:13) > > [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb > > > > /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg/_mysql.pyc, but /opt/downloads/py-modules/MySQL-python-1.2.3c1 is being added to sys.path > > > > It would be a great help if I understand what's going on!!! Thanks in > > advance. > > > > Regards, > > > > Kurian Mathew Thayil. > > > > MySQLdb-build.txt > > 3KViewDownload > > > > MySQLdb-Install.txt > > 6KViewDownload > > > > signature.asc > > < 1KViewDownload > > The warning looks familiar. Are you running python from the MySQLdb > source directory? ie. /opt/downloads/py-modules/MySQL-python-1.2.3c1 > > I think you just need to change directories and the warning will go > away. Check what's happening on line 3 of _mysql.py I don't have the > source in front of me. > > ~Sean Hi Sean, You are right. I was trying to import the module sitting on the source folder :"-). Thanks for your quick response and let me try further. Regards, Kurian Mathew Thayil. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: face-embarrassed.png Type: image/png Size: 876 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ysj.ray at gmail.com Wed Mar 24 23:42:41 2010 From: ysj.ray at gmail.com (=?UTF-8?B?5bKz5biF5p2w?=) Date: Thu, 25 Mar 2010 11:42:41 +0800 Subject: Super() function In-Reply-To: <4BAAD5E0.9050604@googlemail.com> References: <4BAAD5E0.9050604@googlemail.com> Message-ID: <797c8cbd1003242042s32ee16bbxe6d937a16ab35a50@mail.gmail.com> Hi: On 25 March 2010 11:17, Alan Harris-Reid wrote: > Hi, > > Using Python 3.1, I sometimes use the super() function to call the > equivalent method from a parent class, for example > > def mymethod(self): > super().mymethod() > some more code... > > Is there any way of writing the code so that the super() call is generic > and automatically recognises the name of the current method (ie. something > like super().thismethod()) or do I always have to repeat the method name > after super()? > > TIA, > Alan > -- > http://mail.python.org/mailman/listinfo/python-list > I think, the super() method is designed to delegate any method call to one of the class in its mro list, and the super() function its self return a 'super' object, so it is better to write what method you want to delegate, maybe it's not the current method. -- Best wishes from Ray ... -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Mar 24 23:47:19 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 24 Mar 2010 20:47:19 -0700 (PDT) Subject: Super() function References: Message-ID: <4cb1beeb-a663-46e0-bedb-63e076b7f32c@h35g2000pri.googlegroups.com> Alan Harris-Reid wrote: > Is there any way of writing the code so that the super() call is generic > and automatically recognises the name of the current method (ie. > something like super().thismethod()) or do I always have to repeat the > method name after super()? To the best of my knowledge, you always need to repeat the method name. super() returns a proxy object that has no awareness of its context, so it's unaware of the method it's being called within (in fact, there's nothing that restricts super() to only being used in methods...). You could probably write a wrapper function that uses inspect to determine in which context super() is being called, but unless you're regularly finding this to be a problem with refactoring I wouldn't worry about it. From half.italian at gmail.com Wed Mar 24 23:54:49 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Wed, 24 Mar 2010 20:54:49 -0700 (PDT) Subject: MySQLdb compiled -- Import issue References: <85161d90-2db8-4bbe-ab13-02f27abab82a@y11g2000prf.googlegroups.com> Message-ID: > You are right. I was trying to import the module sitting on the source > folder :"-). Thanks for your quick response and let me try further. Sweet! I remember it because it confused the hell out of me on at least one past occasion. :) From gagsl-py2 at yahoo.com.ar Thu Mar 25 00:00:27 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Mar 2010 01:00:27 -0300 Subject: Super() function References: <4BAAD5E0.9050604@googlemail.com> Message-ID: En Thu, 25 Mar 2010 00:17:52 -0300, Alan Harris-Reid escribi?: > Using Python 3.1, I sometimes use the super() function to call the > equivalent method from a parent class, for example > > def mymethod(self): > super().mymethod() > some more code... > > Is there any way of writing the code so that the super() call is generic > and automatically recognises the name of the current method (ie. > something like super().thismethod()) or do I always have to repeat the > method name after super()? This recipe does what you want: http://code.activestate.com/recipes/286195-selfsuper/ (but requires a bit of black magic...) -- Gabriel Genellina From timr at probo.com Thu Mar 25 00:14:23 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Mar 2010 21:14:23 -0700 Subject: Advice Criticism on Python App References: Message-ID: Jimbo wrote: > >class stock: > code = "" > purchasePrice = 0 > purchaseQuantity = 0 > price = [] # list of recent prices > recentBid = [] # list of recent bids for stock > recentOffer = [] # list of recent offers for stock > stockVol = [] # list of stock quantity available on >market Using lists as class variables is a very good way to create very surprising bugs. Consider the following: C:\Dev>type x.py class test: check = [] def __init__(self): self.check.append(1) x = test() y = test() z = test() print x.check print y.check print z.check C:\Dev>x.py [1, 1, 1] [1, 1, 1] [1, 1, 1] C:\Dev> > def __init__(self): > """ Default Constructor """ > self.code = "" > self.purchasePrice = 0 > self.purchaseQuantity = 0 > > def constructor(self, stockCode, purPrice, purQuant): > """ Constructor """ > self.code = stockCode > self.purchasePrice = purPrice > self.purchaseQuantity = purQuant The "constructor" concept here is not very Pythonic. Why not replace those both with: def __init__(self, stockCode="", purPrice=0, purQuant=0): self.code = stockCode self.purchasePrice = purPrice self.purchaseQuantity = purQuant -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gagsl-py2 at yahoo.com.ar Thu Mar 25 00:29:07 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 25 Mar 2010 01:29:07 -0300 Subject: Is there any library for indexing binary data? References: Message-ID: En Thu, 25 Mar 2010 00:28:58 -0300, ?? escribi?: > Recently, I am finding a good library for build index on binary data. > Xapian & Lucene for python binding focus on text digestion rather than > binary data. Could anyone give me some recommendation? Is there any > library for indexing binary data no matter whether it is written in > python? > > In my case, there is a very big datatable which stores structured > binary data, eg: > struct Item > { > long id; // used as key > double value; > }; > > I want to build the index on "id" field to speed on searching. Since > this datatable is not constant, the library should support incremental > indexing. If there is no suitable library, I have to do the index by > myself... What about a database? -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Thu Mar 25 01:10:06 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Mar 2010 05:10:06 GMT Subject: Advice Criticism on Python App References: Message-ID: On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote: > Jimbo wrote: >> >>class stock: >> code = "" >> purchasePrice = 0 >> purchaseQuantity = 0 >> price = [] # list of recent prices >> recentBid = [] # list of recent bids for stock >> recentOffer = [] # list of recent offers for stock >> stockVol = [] # list of stock quantity available on market > > Using lists as class variables is a very good way to create very > surprising bugs. Consider the following: [snip] Don't you think that the class attributes are *supposed* to be shared by all instances? In that case the behaviour you show is not a bug at all. -- Steven From littlesweetmelon at gmail.com Thu Mar 25 01:53:45 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 13:53:45 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: References: Message-ID: Well, Database is not proper because 1. the table is very big (~10^9 rows) 2. we should support very fast *simple* query that is to get value corresponding to single key (~10^7 queries / second). Currently, I have implemented a specific algorithm to deal with my problem. However, I want to employ some library to simplify codings, otherwise I have to write my own code for each big table. It is possible that, after using indexing library, the program cannot run as fast as homemade code. But if it can greatly simplify my job and can provide satisfied speed (eg 10^5~10^6 queries / second), the indexing library is still a good choice for me. -- ShenLei 2010/3/25 Gabriel Genellina : > En Thu, 25 Mar 2010 00:28:58 -0300, ?? > escribi?: > >> Recently, I am finding a good library for build index on binary data. >> Xapian & Lucene for python binding focus on text digestion rather than >> binary data. Could anyone give me some recommendation? Is there any >> library for indexing binary data no matter whether it is written in >> python? >> >> In my case, there is a very big datatable which stores structured >> binary data, eg: >> struct Item >> { >> long id; // used as key >> double value; >> }; >> >> I want to build the index on "id" field to speed on searching. Since >> this datatable is not constant, the library should support incremental >> indexing. If there is no suitable library, I have to do the index by >> myself... > > What about a database? > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > From tomf.sessile at gmail.com Thu Mar 25 02:50:23 2010 From: tomf.sessile at gmail.com (TomF) Date: Wed, 24 Mar 2010 23:50:23 -0700 Subject: sum for sequences? References: Message-ID: <2010032423502316807-tomfsessile@gmailcom> On 2010-03-24 14:07:24 -0700, Steven D'Aprano said: > On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote: > >> Is there a sequence-oriented equivalent to the sum built-in? E.g.: >> >> seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) >> >> ? > > Yes, sum. > > help(sum) is your friend. You might not want to be so glib. The sum doc sure doesn't sound like it should work on lists. Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start' (which defaults to 0). -Tom From stefan_ml at behnel.de Thu Mar 25 03:22:30 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Mar 2010 08:22:30 +0100 Subject: C-API: Extract information from function object In-Reply-To: References: Message-ID: Gabriel Genellina, 24.03.2010 17:49: > En Wed, 24 Mar 2010 12:09:27 -0300, moerchendiser2k3 escribi?: > >> I have a reference to a function and would like to know how to extract >> information from a function object. >> >> Information I am looking for: line and file where this function is >> from. >> >> PyObject_Call can do this to when I call a function object and >> something failed so these information are written to the traceback. So >> any suggestions how to do that? > > See the Language Reference; the associated code object holds the file > and starting line the function comes from. > The traceback object contains better information (like the line being > executed instead of the first one). Why don't you use it instead? Note that this was a follow-up to another recent thread where I managed to extract the details from the OP by stoically asking back, especially the information that this is not about exception handling but rather about reporting incorrect return values. This is a good example when you need a reason why not to split threads on the same subject... Stefan From steven at REMOVE.THIS.cybersource.com.au Thu Mar 25 03:34:51 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Mar 2010 07:34:51 GMT Subject: sum for sequences? References: <2010032423502316807-tomfsessile@gmailcom> Message-ID: On Wed, 24 Mar 2010 23:50:23 -0700, TomF wrote: > On 2010-03-24 14:07:24 -0700, Steven D'Aprano > said: >> On Wed, 24 Mar 2010 15:29:07 +0000, kj wrote: >> >>> Is there a sequence-oriented equivalent to the sum built-in? E.g.: >>> >>> seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) >>> >>> ? >> >> Yes, sum. >> >> help(sum) is your friend. > > You might not want to be so glib. The sum doc sure doesn't sound like > it should work on lists. > > Returns the sum of a sequence of numbers (NOT strings) plus the > value of parameter 'start' (which defaults to 0). What part of that suggested to you that sum might not be polymorphic? Sure, it says numbers (which should be changed, in my opinion), but it doesn't specify what sort of numbers -- ints, floats, or custom types that have an __add__ method. It also singles out strings as excluded. Why would you need to explicitly exclude strings, since they're not numbers, if sum *only* works with numbers? E.g. help(math.sin) could have said this, but doesn't: Return the sine of x (NOT a dictionary) It doesn't need to, because dicts aren't exceptional: sin doesn't work on anything *but* numbers. There's no __sin__ method to call on arbitrary types. The fact that sum does single out strings is a clear sign that strings are treated as exceptional and suggests strongly that summing arbitrary types should work. I'm not saying that help(sum) explicitly states that it works with lists (it clearly doesn't), but it does suggest the possibility and makes the experiment worth trying. I'll also note that the Fine Manual makes it even more clear that sum is polymorphic: http://docs.python.org/library/functions.html#sum -- Steven From moekaveli at gmail.com Thu Mar 25 03:41:06 2010 From: moekaveli at gmail.com (Dr. Benjamin David Clarke) Date: Thu, 25 Mar 2010 00:41:06 -0700 (PDT) Subject: Saving a page loaded using the webbrowser library? Message-ID: <3b268d9b-0e37-4e19-9f28-9f560edff76b@b30g2000yqd.googlegroups.com> Does anyone know of a way to save the a loaded web page to file after opening it with a webbrowser.open() call? Specifically, what I want to do is get the raw HTML from a web page. This web page uses Javascript. I need the resulting HTML after the Javascript has been run. I've seen a lot about trying to get Python to run Javascript but there doesn't seem to be any promising solution. I can get the raw HTML that I want by saving the page after it has been loaded via the webbrowser.open() call. Is there any way to automate this? Does anyone have any ideas for better approaches to this problem? I don't need ti to be pretty or anything. From irmen at -NOSPAM-xs4all.nl Thu Mar 25 03:58:28 2010 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Thu, 25 Mar 2010 08:58:28 +0100 Subject: Is there any library for indexing binary data? In-Reply-To: References: Message-ID: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> On 3/25/10 4:28 AM, ?? wrote: > Howdy, > > Recently, I am finding a good library for build index on binary data. > Xapian& Lucene for python binding focus on text digestion rather than > binary data. Could anyone give me some recommendation? Is there any > library for indexing binary data no matter whether it is written in > python? > > In my case, there is a very big datatable which stores structured > binary data, eg: > struct Item > { > long id; // used as key > double value; > }; > > I want to build the index on "id" field to speed on searching. Since > this datatable is not constant, the library should support incremental > indexing. If there is no suitable library, I have to do the index by > myself... > > Thank you in advance. > > -- > ShenLei Put it into an Sqlite database? Or something else from http://docs.python.org/library/persistence.html. Or maybe http://www.pytables.org/ is more suitable to your needs (never used that one myself though). Or install a bank or 2 of memory in your box and read everything into memory in one big hashtable. Btw if you already have a big datatable in which the data is stored, I'm guessing that already is in some form of database format. Can't you write something that understands that database format. But I think you need to provide some more details about your data set. -irmen From no.email at nospam.invalid Thu Mar 25 04:04:23 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Mar 2010 01:04:23 -0700 Subject: Is there any library for indexing binary data? References: Message-ID: <7xaatwsu7s.fsf@ruckus.brouhaha.com> ?? writes: > Well, Database is not proper because 1. the table is very big (~10^9 > rows) 2. we should support very fast *simple* query that is to get > value corresponding to single key (~10^7 queries / second). Just one numeric key/value pair in each row? What's wrong with universal hashing? PyJudy might also be of interest: http://www.dalkescientific.com/Python/PyJudy.html From irmen at -NOSPAM-xs4all.nl Thu Mar 25 04:13:27 2010 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Thu, 25 Mar 2010 09:13:27 +0100 Subject: Saving a page loaded using the webbrowser library? In-Reply-To: <3b268d9b-0e37-4e19-9f28-9f560edff76b@b30g2000yqd.googlegroups.com> References: <3b268d9b-0e37-4e19-9f28-9f560edff76b@b30g2000yqd.googlegroups.com> Message-ID: <4bab1bad$0$22941$e4fe514c@news.xs4all.nl> On 3/25/10 8:41 AM, Dr. Benjamin David Clarke wrote: > Does anyone know of a way to save the a loaded web page to file after > opening it with a webbrowser.open() call? > > Specifically, what I want to do is get the raw HTML from a web page. > This web page uses Javascript. I need the resulting HTML after the > Javascript has been run. I've seen a lot about trying to get Python to > run Javascript but there doesn't seem to be any promising solution. I > can get the raw HTML that I want by saving the page after it has been > loaded via the webbrowser.open() call. Is there any way to automate > this? Does anyone have any ideas for better approaches to this > problem? I don't need ti to be pretty or anything. I think I would use an appropriate GUI automation library to simulate user interaction with the web browser that you just started, and e.g. select the File > Save page as > HTML only menu option from the browser... If the javascript heavily modifies the DOM, that might not work however. You might need additional tooling such as Web Developer Toolbar for Firefox where you then can View Source > View Generated Source. irmen From news1234 at free.fr Thu Mar 25 04:25:06 2010 From: news1234 at free.fr (News123) Date: Thu, 25 Mar 2010 09:25:06 +0100 Subject: how to display variables down a stackdump when an exception occurred Message-ID: <4bab1de2$0$19315$426a34cc@news.free.fr> Hi, I captured a piece of code with a try except statement: In the except part I display a stackdump try: domyxmlrpcstuff() except Exception as e: import traceback ex_type,ex_value,e_b = sys.exc_info() tbstring = traceback.format_exc() print '%s%s:%s:%s' % \ (msg,ex_type,ex_value,tbstring) The output, that I receive is: File "C:\mycode\myrpcclient.py", line 63, in upload_chunk rslt = myrpcclient.call() File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ return self.__send(self.__name, args) File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request verbose=self.__verbose File "C:\Python26\lib\xmlrpclib.py", line 1253, in request return self._parse_response(h.getfile(), sock) File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response p.feed(response) File "C:\Python26\lib\xmlrpclib.py", line 601, in feed self._parser.Parse(data, 0) ExpatError: syntax error: line 1, column 0 In order to understand more I would like to display the value of data in C:\Python26\lib\xmlrpclib.py", line 601 Is this possible in a non interactive fashion? This is a generic question about inspecting variables down the stack, whenever an exception occurs. I started another thread specifically about displaying the invalid xmlrpc data. N From news1234 at free.fr Thu Mar 25 04:31:05 2010 From: news1234 at free.fr (News123) Date: Thu, 25 Mar 2010 09:31:05 +0100 Subject: xpat error in xmlrp client. How to inspect data. Message-ID: <4bab1f4a$0$25677$426a74cc@news.free.fr> Hi, I'm havign a small xmlrpc client, which works normally fine. (xmlrpc via https) Sometimes however I receive an Exception about an expat error. The output, that I receive is: File "C:\mycode\myrpcclient.py", line 63, in upload_chunk rslt = myrpcclient.call() File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ return self.__send(self.__name, args) File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request verbose=self.__verbose File "C:\Python26\lib\xmlrpclib.py", line 1253, in request return self._parse_response(h.getfile(), sock) File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response p.feed(response) File "C:\Python26\lib\xmlrpclib.py", line 601, in feed self._parser.Parse(data, 0) ExpatError: syntax error: line 1, column 0 In order to continue debugging I'd like to dump the received http data, which "C:\Python26\lib\xmlrpclib.py", line 601 tried to parse without succes. How can I do this? thanks for any suggestions N From littlesweetmelon at gmail.com Thu Mar 25 05:28:25 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 17:28:25 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: <7xaatwsu7s.fsf@ruckus.brouhaha.com> References: <7xaatwsu7s.fsf@ruckus.brouhaha.com> Message-ID: Thank you Rubin! Let me have a look at Judy. It seems good at first glance. -- ShenLei 2010/3/25 Paul Rubin : > ?? writes: >> Well, Database is not proper because 1. the table is very big (~10^9 >> rows) 2. we should support very fast *simple* query that is to get >> value corresponding to single key (~10^7 queries / second). > > Just one numeric key/value pair in each row? What's wrong with > universal hashing? > > PyJudy might also be of interest: > http://www.dalkescientific.com/Python/PyJudy.html > -- > http://mail.python.org/mailman/listinfo/python-list > From tim.wintle at teamrubber.com Thu Mar 25 05:34:17 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 25 Mar 2010 09:34:17 +0000 Subject: Is it possible to use re2 from Python? In-Reply-To: References: Message-ID: <1269509657.7610.13.camel@localhost> On Wed, 2010-03-24 at 10:44 -0700, _wolf wrote: > yes we can! http://github.com/facebook/pyre2 I had made a thin wrapper experiment with here - looks like the version he's shipped is relatively complete and compatible with the re module though. I'll be interested in seeing how well it performs - The wrapper I had been experimenting with ended up far slower than the re module for simple expressions - and the fastest codepaths in RE2 seem to be ones that are incompatible with the API we're used to using in the re module. Tim From littlesweetmelon at gmail.com Thu Mar 25 05:55:27 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Thu, 25 Mar 2010 17:55:27 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> References: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> Message-ID: Thank you irmen. I will take a look at pytable. FYI, let me explain the case clearly. Originally, my big data table is simply array of Item: struct Item { long id; // used as key BYTE payload[LEN]; // corresponding value with fixed length }; All items are stored in one file by using "stdio.h" function: fwrite(itemarray, sizeof(Item), num_of_items, fp); Note that "id" is randomly unique without any order. To speed up searching I regrouped / sorted them into two-level hash tables (in the form of files). I want to employ certain library to help me index this table. Since the table contains about 10^9 items and LEN is about 2KB, it is impossible to hold all data in memory. Furthermore, some new item may be inserted into the array. Therefore incremental indexing feature is needed. Hope this help you to understand my case. -- ShenLei 2010/3/25 Irmen de Jong : > On 3/25/10 4:28 AM, ?? wrote: >> >> Howdy, >> >> Recently, I am finding a good library for build index on binary data. >> Xapian& Lucene for python binding focus on text digestion rather than >> binary data. Could anyone give me some recommendation? Is there any >> library for indexing binary data no matter whether it is written in >> python? >> >> In my case, there is a very big datatable which stores structured >> binary data, eg: >> struct Item >> { >> long id; // used as key >> double value; >> }; >> >> I want to build the index on "id" field to speed on searching. Since >> this datatable is not constant, the library should support incremental >> indexing. If there is no suitable library, I have to do the index by >> myself... >> >> Thank you in advance. >> >> -- >> ShenLei > > Put it into an Sqlite database? Or something else from > http://docs.python.org/library/persistence.html. > Or maybe http://www.pytables.org/ is more suitable to your needs (never used > that one myself though). > Or install a bank or 2 of memory in your box and read everything into memory > in one big hashtable. > > Btw if you already have a big datatable in which the data is stored, I'm > guessing that already is in some form of database format. Can't you write > something that understands that database format. > > But I think you need to provide some more details about your data set. > > -irmen > -- > http://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Thu Mar 25 05:57:23 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 25 Mar 2010 09:57:23 +0000 Subject: threads (specifically timers) and releasing resources In-Reply-To: References: Message-ID: <4BAB3383.7080003@timgolden.me.uk> On 25/03/2010 02:31, Alex Hall wrote: > Okay, I have my program and it has three different modes (there will > be more than that). Each mode will have a timer attached to it. If the > mode remains active and the timer runs out, a function specific to > that mode is called. If that mode is switched away from, however, the > timer is canceled and a new timer is created for the mode to which the > user just switched. I assume you're using Python's threading.Timer objects as you'd discussed those before. If so, that's basically a threading.Thread in disguise. In which case, you're going to have to make sure it cleans up after itself, releasing whatever resources it holds. Python's reference-count semantics and cyclic gc will take care of things in the normal way once the timer-thread has completed. But you'll have to make sure it completes. > If the latter, is there a way to completely destroy a thread? No: in Python, a thread has to self-destruct. This is a relatively FAQ and there are quite a few recipes around. Here's an example of something which seems to be close to your current needs: http://code.activestate.com/recipes/464959-resettable-timer-class/ TJG From egbertum at xs4all.nl Thu Mar 25 06:16:32 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 25 Mar 2010 11:16:32 +0100 Subject: from import and __init__.py Message-ID: <20100325101632.GA4727@xs4all.nl> When I do 'from some_package import some_module' the __init__.py of some_package will be run. However, there will not be anything like a package-module, and the effects of __init__.py seem all to be lost. Is that true ? Or can I still do something useful with __init__.py ? e -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From rami.chowdhury at gmail.com Thu Mar 25 07:10:33 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Thu, 25 Mar 2010 04:10:33 -0700 Subject: the Python Foundation In-Reply-To: <7xwrx1z4nq.fsf@ruckus.brouhaha.com> References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> <7xwrx1z4nq.fsf@ruckus.brouhaha.com> Message-ID: <20100325111033.GB18576@tigris> On 2010-03-24 16:22, Paul Rubin wrote: > "Steve Holden, Chairman, PSF" writes: > > We have also registered the trademark "Python" for use in reference to > > computer programming languages, thereby ensuring that we can take action > > should some ill-advised individual or organization decide to produce > > another language with "Python" in its name > > There has been a Lisp compiler called "Python" for many years: > > http://portal.acm.org/citation.cfm?id=141471.141558 The FAQ disclaims any connection and claims that Python the Lisp compiler has been around longer than Python the language... http://www.cons.org/cmucl/FAQ.html I was awfully confused the first time I came across SBCL giving me warnings about Python, though -- proves how well the PSF has safeguarded the name! > -- > http://mail.python.org/mailman/listinfo/python-list From newton10471 at gmail.com Thu Mar 25 07:42:08 2010 From: newton10471 at gmail.com (newton10471) Date: Thu, 25 Mar 2010 04:42:08 -0700 (PDT) Subject: chroot fails with mount point passed to subprocess.Popen? References: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Message-ID: <0bbff19b-1cb1-40bb-950c-7594d0eba6cc@r1g2000yqj.googlegroups.com> Hi Alf, After doing some more research, including the character-by-character comparison you suggested (thank you!), I was able to get things working the way I wanted using the following: def getInstalledKernelVersion(mountPoint): linuxFsRoot = mountPoint + "/root" installedKernelVersionResult = subprocess.Popen(['/usr/sbin/ chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'], stdout=subprocess.PIPE).communicate()[0] return installedKernelVersionResult Thanks very much for you help, -Matt On Mar 22, 9:33?am, "Alf P. Steinbach" wrote: > * newton10471: > > > > > Hi, > > > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount > > point passed in as a parameter to the following function: > > > def getInstalledKernelVersion(mountPoint): > > ? ? linuxFsRoot = mountPoint + "/root" > > ? ? print "type of linuxFsRoot is %s" % type(linuxFsRoot) > > ? ? installedKernelVersionResult = > > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) > > ? ? return installedKernelVersionResult > > > and it dies with the following: > > > type of linuxFsRoot is > > chroot: cannot change root directory to /storage/mounts/ > > mnt_3786314034939740895.mnt/root: No such file or directory > > > When I explicitly set linuxFsRoot = "/storage/mounts/ > > mnt_3786314034939740895.mnt/root", it works fine. > > > I also tried this to concatenate the mountpoint + /root, and it failed > > in the same way: > > > linuxFsRoot = ("%s/root") % mountPoint > > Use the os.path functions. > > > Anyone know what might be happening here? > > Since the computed and literal paths /look/ identical and same type, the only > thing I can imagine is that there is some invisible character. Try comparing the > computed and literal path character by character. Print the difference or if > they're identical, that they are. > > Possibly you have GIGO problem. > > Cheers & hth., > > - Alf From steve at holdenweb.com Thu Mar 25 07:42:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Mar 2010 07:42:20 -0400 Subject: from import and __init__.py In-Reply-To: <20100325101632.GA4727@xs4all.nl> References: <20100325101632.GA4727@xs4all.nl> Message-ID: egbert wrote: > When I do 'from some_package import some_module' > the __init__.py of some_package will be run. > However, there will not be anything like a package-module, > and the effects of __init__.py seem all to be lost. Is that true ? > Or can I still do something useful with __init__.py ? > e If I understand correctly what you mean byt a "package-module" then __init__.py is exactly what you are looking for. Many packages are built with an empty __init__.py because they are intended mostly to build a tree-like set of namespaces, but __init__.py *is* run when the package is imported, and its namespace is bound to the name of the package within the importing program. So if you have code you want to run when the package is imported, put it there. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From newton10471 at gmail.com Thu Mar 25 07:42:22 2010 From: newton10471 at gmail.com (newton10471) Date: Thu, 25 Mar 2010 04:42:22 -0700 (PDT) Subject: chroot fails with mount point passed to subprocess.Popen? References: <6a601e7c-7a89-4747-a25c-a78743fe47ab@g4g2000yqa.googlegroups.com> Message-ID: <73728874-ff0a-4360-a328-50fc19236bf6@d27g2000yqf.googlegroups.com> Hi Alf, After doing some more research, including the character-by-character comparison you suggested (thank you!), I was able to get things working the way I wanted using the following: def getInstalledKernelVersion(mountPoint): linuxFsRoot = mountPoint + "/root" installedKernelVersionResult = subprocess.Popen(['/usr/sbin/ chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'], stdout=subprocess.PIPE).communicate()[0] return installedKernelVersionResult Thanks very much for you help, -Matt On Mar 22, 9:33?am, "Alf P. Steinbach" wrote: > * newton10471: > > > > > Hi, > > > I'm trying to use subprocess.Popen() to do a Linux chroot to a mount > > point passed in as a parameter to the following function: > > > def getInstalledKernelVersion(mountPoint): > > ? ? linuxFsRoot = mountPoint + "/root" > > ? ? print "type of linuxFsRoot is %s" % type(linuxFsRoot) > > ? ? installedKernelVersionResult = > > subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen']) > > ? ? return installedKernelVersionResult > > > and it dies with the following: > > > type of linuxFsRoot is > > chroot: cannot change root directory to /storage/mounts/ > > mnt_3786314034939740895.mnt/root: No such file or directory > > > When I explicitly set linuxFsRoot = "/storage/mounts/ > > mnt_3786314034939740895.mnt/root", it works fine. > > > I also tried this to concatenate the mountpoint + /root, and it failed > > in the same way: > > > linuxFsRoot = ("%s/root") % mountPoint > > Use the os.path functions. > > > Anyone know what might be happening here? > > Since the computed and literal paths /look/ identical and same type, the only > thing I can imagine is that there is some invisible character. Try comparing the > computed and literal path character by character. Print the difference or if > they're identical, that they are. > > Possibly you have GIGO problem. > > Cheers & hth., > > - Alf From dksreddy at gmail.com Thu Mar 25 08:15:54 2010 From: dksreddy at gmail.com (Sandy) Date: Thu, 25 Mar 2010 05:15:54 -0700 (PDT) Subject: cxfreeze on ubuntu 9.10 References: <84719a38-3d00-4d46-aa11-f0dca7ace71c@q15g2000yqj.googlegroups.com> Message-ID: <0a385e57-7564-47e1-ab4b-0c75de8ce0d2@r27g2000yqn.googlegroups.com> I used cxFreeze without any problem on Ubuntu 9.10 32 bit version. I tried it on a wxPython gui script and it works fine though I did'n use any setup file. Just try cxFreeze executable (should be in /usr/bin/) instead of setup file. $/usr/bin/cxFreeze my_script.py --target-dir=/what_ever_dir/ what_ever_dir will have the executable file and other libraries needed to run the executable. - dksr On Mar 25, 12:33?am, Waspinator wrote: > Hi, > > I'm trying to compile a python script on Ubuntu 9.10. It uses the gtk > toolkit. I tried to run GUI2EXE for a cxfreeze gui, but even after > installing wxPython in synaptic it still complains about not having > it. > > I also tried to use cxfreeze by itself but the file it produces does > not run. > > I tried to follow the information athttp://cx-freeze.sourceforge.net/cx_Freeze.html > > I created a setup.py file that looks like this (from the page) > > from cx_Freeze import setup, Executable > > setup( > ? ? ? ? name = "gtk_test", > ? ? ? ? version = "0.1", > ? ? ? ? description = "gtk_test", > ? ? ? ? executables = [Executable("gtk_test.py")]) > > and ran: > > python setup.py build > > When I try to run the executable I get the following error: > > ../build/exe.linux-i686-2.6/library.zip/gtk/_gtk.py:12: > RuntimeWarning: tp_compare didn't return -1 or -2 for exception > ImportError: could not import gio > ImportError: could not import gio > Traceback (most recent call last): > ? File "/usr/lib/pymodules/python2.6/cx_Freeze/initscripts/ > Console.py", line 29, in > ? ? exec code in m.__dict__ > ? File "gtk_test.py", line 274, in > ? File "gtk_test.py", line 228, in main > AttributeError: 'module' object has no attribute 'Window' > > I was thinking of using the 'copy-dependent-files' option but I'm not > sure how. > > Any ideas? > > Thanks From ethan at stoneleaf.us Thu Mar 25 08:28:22 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 25 Mar 2010 05:28:22 -0700 Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] In-Reply-To: References: Message-ID: <4BAB56E6.2070201@stoneleaf.us> Michele Simionato wrote: > On Jan 16, 9:27 pm, mk wrote: > >>Hello everyone, >> >>I looked for it I swear, but just can't find it. >> >>Most Python books seem to focus on examples of how to call functions >>from standard library. I don't need that, I have online Python >>documentation for that. >> >>I mean really advanced mental gymnastics, like gory details of how >>Python objects operate, how to exploit its dynamic capabilities, dos and >>donts with particular Python objects, advanced tricks, everything from >>chained decorators to metaprogramming. Dive Into Python comes closest to >>this ideal from what I have found, but still not far enough. >> >>Anybody found such holy grail? > > "Expert Python Programming" by Tarek Ziad? is quite good and I wrote > a review for it: > > http://www.artima.com/weblogs/viewpost.jsp?thread=240415 > > There is plenty of info about Advanced Python on the net, much more > than in book form. Come to think of it, there are my Oxford lectures > (the title was exactly "Advanced Python Programming") and I could > republish it on my blog, since I cannot find them on the net anymore. > > Michele Simionato Michele, Was wondering if you'd had a chance to re-post your lectures -- just did a search for them and came up empty, and I would love to read them! Many thanks in advance! ~Ethan~ From neilc at norwich.edu Thu Mar 25 08:37:14 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Mar 2010 12:37:14 GMT Subject: sum for sequences? References: <2010032423502316807-tomfsessile@gmailcom> Message-ID: <8113nqFsggU3@mid.individual.net> On 2010-03-25, Steven D'Aprano wrote: >> You might not want to be so glib. The sum doc sure doesn't >> sound like it should work on lists. >> >> Returns the sum of a sequence of numbers (NOT strings) plus the >> value of parameter 'start' (which defaults to 0). > > What part of that suggested to you that sum might not be polymorphic? > Sure, it says numbers (which should be changed, in my opinion), but it > doesn't specify what sort of numbers -- ints, floats, or custom types > that have an __add__ method. WTF. -- Neil Cerutti "It's not fun to build walls. But it's even less fun to live without walls in a world full of zombies." --Greedy Goblin From stefan_ml at behnel.de Thu Mar 25 08:44:35 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Mar 2010 13:44:35 +0100 Subject: sum for sequences? In-Reply-To: <8113nqFsggU3@mid.individual.net> References: <2010032423502316807-tomfsessile@gmailcom> <8113nqFsggU3@mid.individual.net> Message-ID: Neil Cerutti, 25.03.2010 13:37: > On 2010-03-25, Steven D'Aprano wrote: >>> You might not want to be so glib. The sum doc sure doesn't >>> sound like it should work on lists. >>> >>> Returns the sum of a sequence of numbers (NOT strings) plus the >>> value of parameter 'start' (which defaults to 0). >> >> What part of that suggested to you that sum might not be polymorphic? >> Sure, it says numbers (which should be changed, in my opinion), but it >> doesn't specify what sort of numbers -- ints, floats, or custom types >> that have an __add__ method. > > WTF. Warning: truth found! Stefan From python at hope.cz Thu Mar 25 08:45:21 2010 From: python at hope.cz (Johny) Date: Thu, 25 Mar 2010 05:45:21 -0700 (PDT) Subject: Does a tiny Python distribution exist? Message-ID: <29c82125-10ce-4302-9423-c8b92a7911f9@q23g2000yqd.googlegroups.com> Does anyone know if there is a tiny Python distribution available running in a Linux environment? From alfps at start.no Thu Mar 25 09:02:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 25 Mar 2010 14:02:05 +0100 Subject: sum for sequences? In-Reply-To: <8113nqFsggU3@mid.individual.net> References: <2010032423502316807-tomfsessile@gmailcom> <8113nqFsggU3@mid.individual.net> Message-ID: * Neil Cerutti: > On 2010-03-25, Steven D'Aprano wrote: >>> You might not want to be so glib. The sum doc sure doesn't >>> sound like it should work on lists. >>> >>> Returns the sum of a sequence of numbers (NOT strings) plus the >>> value of parameter 'start' (which defaults to 0). >> What part of that suggested to you that sum might not be polymorphic? >> Sure, it says numbers (which should be changed, in my opinion), but it >> doesn't specify what sort of numbers -- ints, floats, or custom types >> that have an __add__ method. > > WTF. I think Steven's argument is that it would be pointless for 'sum' to distinguish between user-defined numerical types and other types that happen to support '+'. It could make such a distinction since there's a type hierarchy for numbers, but then that should IMHO be more clearly documented. However, given that it isn't restricted to numbers, the restriction wrt. strings is a bit perplexing in the context of modern CPython. But for Python implementations that don't offer the '+=' optimization it might help to avoid gross inefficiencies, namely quadratic time string concatenation. E.g., here's a natural implementation of sum -- with unoptimized '+=' yielding quadratic time for the string concatenation (with modern CPython it's linear time, though): >>> def sum_all( values, start = 0 ): ... s = start ... for v in values: s += v ... return s ... >>> sum_all( (1, 2, 3, 4) ) 10 >>> sum_all( ("a", "b", "c", "d"), "" ) 'abcd' >>> sum_all( ((1, 2), (3, 4), (5, 6)), () ) (1, 2, 3, 4, 5, 6) >>> _ However, if that hypothesis about the rationale is correct, then 'sum' should also be restricted to not handle tuples or lists, so forth, but at least the CPython implementation does. So perhaps the documentation needs to be more clear? Cheers, - Alf From icanbob at gmail.com Thu Mar 25 09:17:34 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 25 Mar 2010 06:17:34 -0700 (PDT) Subject: Advice needed on parallel processing in python References: <0a050a71-8ff1-4393-aba9-9115eb38cbec@q21g2000yqm.googlegroups.com> Message-ID: On Mar 24, 1:13 pm, Jon Clements wrote: > On 24 Mar, 15:27, Glazner wrote: > > > > > Hi! > > > I need to replace an app that does number crunching over a local > > network. > > it have about 50 computers as slaves > > each computer needs to run COM that will do the "job" > > right now the system uses MFC threads and DCOM to distribute the load. > > > as i said, Now i'm trying to replace this system with python. > > I already use win32all and read about Pareller Python and Pyro. > > > a requirement is that messages can be sent to the remote worker. > > > If anyone can share experience I'll love to hear > > > Many Thanks, > > Yoav Glazner > > Would Celery suit?http://celeryproject.org/ > > hth > > Jon. If you can add just one Linux server onto that network you could use SIMPL-Python to do what you want. http://www.icanprogram.com/06py/lesson1/lesson1.html ie. SIMPL messages going seamlessly from Python (Windows) to Python (Windows) with the SIMPL sandbox being hosted on the Linux node. Of course if you wanted to add Linux nodes as processing nodes. Python (Windows) modules could seamlessly exchange messages with those as well. Same would be true if you wanted to distribute part of your app into the cloud. All your Python code would look virtually identical in each of these cases. As an example of an inexpensive Linux node the SIMPL toolkit has been ported to the ~$100 Sheeva Plug computer (http://www.icanprogram.com/ simpl/plugsimplbin.self.html) (http://www.plugcomputer.org). bob From icanbob at gmail.com Thu Mar 25 09:22:14 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 25 Mar 2010 06:22:14 -0700 (PDT) Subject: Python is cool!! References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <05932144-af1d-4369-8999-50ca5575ae20@z4g2000yqa.googlegroups.com> On Mar 23, 11:55 am, Jose Manuel wrote: > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. > > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... > > Any opinion You probably want to take a look at this tutorial as well: http://www.icanprogram.com/06py/lesson1/lesson1.html The SIMPL toolkit will give you added flexibility to choose the language for some of your more computationally intensive simulations and still present a unified Python interface to the whole thing. bob From michele.simionato at gmail.com Thu Mar 25 09:24:04 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 25 Mar 2010 06:24:04 -0700 (PDT) Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] References: mailman.1182.1269520510.23598.python-list@python.org Message-ID: <54e41616-df9f-42dd-9c91-9e530650bd99@j21g2000yqh.googlegroups.com> On Mar 25, 1:28?pm, Ethan Furman wrote: > > Michele, > > Was wondering if you'd had a chance to re-post your lectures -- just did > a search for them and came up empty, and I would love to read them! > > Many thanks in advance! Oops, I forgot! I will try to make them available soon. From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 25 10:02:18 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Mar 2010 15:02:18 +0100 Subject: Advice Criticism on Python App In-Reply-To: References: Message-ID: <4bab6cd6$0$9118$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote: > >> Jimbo wrote: >>> class stock: >>> code = "" >>> purchasePrice = 0 >>> purchaseQuantity = 0 >>> price = [] # list of recent prices >>> recentBid = [] # list of recent bids for stock >>> recentOffer = [] # list of recent offers for stock >>> stockVol = [] # list of stock quantity available on market >> Using lists as class variables is a very good way to create very >> surprising bugs. Consider the following: > [snip] > > > Don't you think that the class attributes are *supposed* to be shared by > all instances? In that case the behaviour you show is not a bug at all. Python's class attributes are indeed supposed to be shared - that's even the whole point of having class attributes. But this feature has proven to be confusing for newcomers that more often than not have previous exposure to OOPLs where you do "declare" your class "schema" at the class level (where Python defines class attributes). Now reread the OP's code, and you'll find out he's indeed yet another victim of this gotcha: """ for row in cur.fetchall(): newStock = stock() newStock.code = row[0] newStock.purchasePrice = row[1] newStock.purchaseQuantity = row[2] cur.execute(stockQuery,[newStock.code]) for rw in cur.fetchall(): newStock.price.append(rw[0]) newStock.recentOffer.append(rw[1]) newStock.recentBid.append(rw[2]) newStock.stockVol.append(rw[3]) stockList.append(newStock) """ From mehgcap at gmail.com Thu Mar 25 10:38:36 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 25 Mar 2010 10:38:36 -0400 Subject: threads (specifically timers) and releasing resources In-Reply-To: <4BAB3383.7080003@timgolden.me.uk> References: <4BAB3383.7080003@timgolden.me.uk> Message-ID: Thanks, this should work. On 3/25/10, Tim Golden wrote: > On 25/03/2010 02:31, Alex Hall wrote: >> Okay, I have my program and it has three different modes (there will >> be more than that). Each mode will have a timer attached to it. If the >> mode remains active and the timer runs out, a function specific to >> that mode is called. If that mode is switched away from, however, the >> timer is canceled and a new timer is created for the mode to which the >> user just switched. > > I assume you're using Python's threading.Timer objects as you'd discussed > those before. If so, that's basically a threading.Thread in disguise. > In which case, you're going to have to make sure it cleans up after itself, > releasing whatever resources it holds. > > Python's reference-count semantics and cyclic gc will take care of > things in the normal way once the timer-thread has completed. But > you'll have to make sure it completes. > >> If the latter, is there a way to completely destroy a thread? > > No: in Python, a thread has to self-destruct. This is a relatively > FAQ and there are quite a few recipes around. Here's an example of > something which seems to be close to your current needs: > > http://code.activestate.com/recipes/464959-resettable-timer-class/ > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 25 11:01:51 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Mar 2010 16:01:51 +0100 Subject: Python is cool!! In-Reply-To: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> References: <09813819-e3d3-4998-85e0-71fce5992227@u9g2000yqb.googlegroups.com> Message-ID: <4bab7acb$0$2873$426a74cc@news.free.fr> Jose Manuel a ?crit : > I have been learning Python, and it is amazing .... I am using the > tutorial that comes with the official distribution. > > At the end my goal is to develop applied mathematic in engineering > applications to be published on the Web, specially on app. oriented to > simulations and control systems, I was about to start learning Java > but I found Python which seems easier to learn that Java. Python is indeed quite lightweight when compared to Java. But it has it's share of non-obvious features, dark corners, gotchas, and plain warts too. > Would it be easy to integrate Python in Web pages with HTML? I have > read many info on Internet saying it is, and I hope so .... If you think of some server-page PHP-like solution, you won't find much usable stuff. There are quite a few Python web development toolkits / frameworks, but Django is becoming the de facto standard. Arguably not the "best" framework (depending on your definition of "best"), but certainly one of the most pythonic and well documented around. From fpm at u.washington.edu Thu Mar 25 11:10:59 2010 From: fpm at u.washington.edu (cassiope) Date: Thu, 25 Mar 2010 08:10:59 -0700 (PDT) Subject: Does a tiny Python distribution exist? References: <29c82125-10ce-4302-9423-c8b92a7911f9@q23g2000yqd.googlegroups.com> Message-ID: <25d0272d-1a49-40e0-96ac-6c8d431b0c18@c20g2000prb.googlegroups.com> On Mar 25, 5:45?am, Johny wrote: > Does anyone know if there is a tiny Python distribution available > running in a Linux environment? Debian has a package: "python-minimal". HTH... From omrihsan at gmail.com Thu Mar 25 11:23:46 2010 From: omrihsan at gmail.com (Omer Ihsan) Date: Thu, 25 Mar 2010 08:23:46 -0700 (PDT) Subject: nested threading Message-ID: <4566e767-768f-4399-8a6b-5530ec90b03c@a37g2000prd.googlegroups.com> is there anything as "nested threading"....that is, call a thread from within a thread. in this case how will thread locking take place. for example initially there were two functions that were called using threading.Thread. these wont get unlocked unless both of them are done with whatever they need to do. if say function 2 calls another thread. then what?? inquisitive....:-| From mail at timgolden.me.uk Thu Mar 25 11:25:46 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 25 Mar 2010 15:25:46 +0000 Subject: Does a tiny Python distribution exist? In-Reply-To: <25d0272d-1a49-40e0-96ac-6c8d431b0c18@c20g2000prb.googlegroups.com> References: <29c82125-10ce-4302-9423-c8b92a7911f9@q23g2000yqd.googlegroups.com> <25d0272d-1a49-40e0-96ac-6c8d431b0c18@c20g2000prb.googlegroups.com> Message-ID: <4BAB807A.7040104@timgolden.me.uk> On 25/03/2010 15:10, cassiope wrote: > On Mar 25, 5:45 am, Johny wrote: >> Does anyone know if there is a tiny Python distribution available >> running in a Linux environment? > > Debian has a package: "python-minimal". > > HTH... tinypy? http://www.tinypy.org/ TJG From jason.heeris at gmail.com Thu Mar 25 11:39:01 2010 From: jason.heeris at gmail.com (Jason) Date: Thu, 25 Mar 2010 08:39:01 -0700 (PDT) Subject: Represent object type as Message-ID: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> Hi, I want to send objects (new style) over DBUS. DBUS can only send fairly primitive types[1] so I turn my objects into dicts and send that. I'm reusing the __getstate__ function I wrote for pickling like so: def __getstate__(self): attrs = self.__dict__.copy() return attrs ...which is perfectly adequate to dict-ify and reconstitute this simple class. That works just fine over DBUS. The trouble is, the object could actually be of some slightly different types, so I'd like to include that information as well. I tried something like: def __getstate__(self): attrs = self.__dict__.copy() attrs.update({'type': type(self)}) return attrs ...but then realised that "type" is not primitive enough for DBUS to pickle. So, (a) can I get the type name from the type object, or (b) is there a better way to do this? (This pertains to Python 2.5.4.) Cheers, ? Jason [1] http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#data-types From bruno.42.desthuilliers at websiteburo.invalid Thu Mar 25 12:00:34 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Mar 2010 17:00:34 +0100 Subject: Represent object type as In-Reply-To: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> References: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> Message-ID: <4bab888e$0$26553$426a74cc@news.free.fr> Jason a ?crit : > Hi, > > I want to send objects (new style) over DBUS. DBUS can only send > fairly primitive types[1] so I turn my objects into dicts and send > that. I'm reusing the __getstate__ function I wrote for pickling like > so: > > def __getstate__(self): > attrs = self.__dict__.copy() > return attrs > > ...which is perfectly adequate to dict-ify and reconstitute this > simple class. That works just fine over DBUS. > > The trouble is, the object could actually be of some slightly > different types, so I'd like to include that information as well. I > tried something like: > > def __getstate__(self): > attrs = self.__dict__.copy() > attrs.update({'type': type(self)}) attrs['type'] = type(self) Do the same thing with less work !-) Also and while we're at it, using a __magicname__ convention here (ie : '__type__' instead of 'type') might avoid possible collisions. > return attrs > > ...but then realised that "type" is not primitive enough for DBUS to > pickle. > > So, (a) can I get the type name from the type object, attrs['__typename__'] = type(self).__name__ Warning: won't be very useful if your code still uses old-style classes. > or (b) is there > a better way to do this? Depends on what you do with this dict, DBUS etc. And of your definition of "better", of course. HTH From sccolbert at gmail.com Thu Mar 25 12:23:47 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 25 Mar 2010 12:23:47 -0400 Subject: ANN: Pymazon 0.1.1 Released Message-ID: <7f014ea61003250923k50d1fc60h108f83c01c15478b@mail.gmail.com> I'm happy to announce the release of Pymazon 0.1.1! This release brings a big enhancement in the form of PyGtk support in addition to the PyQt4 and Command line interfaces already available. A special thanks to Ray Meyers for his gtk commits! Pymazon Changelog 0.1.1 ----- - Added support for command line options and configuration file - Added support for save name templates - Added a threaded downloader which runs a user-specified simultaneous threads when in gui mode - Added a PyGtk Gui (Submitted by Raymond Myers) - Rewrote the QT Gui with Qt Designer and pyuic4 - this simplified and cleaned up a bunch of stuff - Added graphical progress bars to the Gui's - Removed a check that asserted the downloaded file size was the same as specified in the amz file as Amazon was misreporting file size and it was causing Pymazon to erroneously fail - Cleaned up code all over the place: logging, settings, etc... Pymazon is available in the cheeseshop and google code. Pymazon is a Python implemented downloader for the amazon mp3 store. You can read more about Pymazon at http://code.google.com/p/pymazon/. I always appreciate comments and bug reports. Cheers! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Mar 25 12:43:13 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Mar 2010 12:43:13 -0400 Subject: from import and __init__.py In-Reply-To: <20100325101632.GA4727@xs4all.nl> References: <20100325101632.GA4727@xs4all.nl> Message-ID: On 3/25/2010 6:16 AM, egbert wrote: > When I do 'from some_package import some_module' > the __init__.py of some_package will be run. > However, there will not be anything like a package-module, > and the effects of __init__.py seem all to be lost. Is that true ? No. If you do from sys import modules print(modules.keys()) you will see both some_package and some_package.some_module among the entries. The first is the result of executing some_package/__init__.py. As usual, that code will *not* be re-exectured on subsequent imports involving some_package. > Or can I still do something useful with __init__.py ? > e Some packages put something like 'from _default_stuff import *' in __init__.py with the intention that the package by used as import package perhaps [optionally] followed by import package.specialized_stuff Terry Jan Reedy From sridharr at activestate.com Thu Mar 25 12:59:30 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 25 Mar 2010 09:59:30 -0700 Subject: ANN: ActivePython 2.6.5.12 and 3.1.2.3 are now available Message-ID: <5BD6EC71-9F23-4DF8-9DCE-9A03E6FFFAEC@activestate.com> We are pleased to announce the availability of both ActivePython 2.6.5.12 and ActivePython 3.1.2.3. http://www.activestate.com/activepython/ Here is what you should know about these two releases: PyWin32: PyWin32 is now included in the 64-bit & Python3 builds! Since we recently updated our PyWin32 source tree, this release comes with several bug fixes. PyPM: There is now an ?upgrade? feature in PyPM, our beloved Python Package Manager distributed with ActivePython free of charge. What this means is that if you type ?pypm upgrade? it will update all your installed Python Packages to the latest version to save you time and keep you up-to-date. Switch between Python versions: Also new in this 2.6 release is a new tool called "pythonselect" that can be used to switch between multiple ActivePython versions. This is currently only supported on MacOSX although support for other platforms and, perhaps, other Python installations, is in the roadmap (patches are welcome too!). Dive Into Python 3: ActivePython 3.1.2.3 now includes Mark Pilgrim?s Dive Into Python 3, the popular advanced tutorial for learning Python3. You can find it in the documentation section. Miscellaneous: We also updated the base Tcl/Tk version to 8.5.8; added OpenSSL and ctypes support in the 64-bit build; upgraded to openssl-0.9.8l; included Tcl/Tk development headers ? among several other bug fixes with IDLE and Tkinter installation. And of course, they use the latest Python version: 2.6.5 and 3.1.2. See the release notes for full details: http://docs.activestate.com/activepython/2.6/relnotes.html#changes http://docs.activestate.com/activepython/2.6/relnotes.html#changes And our blog post on this release: http://blogs.activestate.com/2010/03/activestate-releases-activepython-2-6-5-12-and-activepython-3-1-2-3/ What is ActivePython? --------------------- ActivePython is ActiveState's binary distribution of Python. Builds for Windows, Mac OS X, Linux are made freely available. Builds for Solaris, HP-UX and AIX, and access to older versions are available with ActivePython Business Edition: http://www.activestate.com/business_edition/ ActivePython includes the Python core and the many core extensions: zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite (sqlite3) database libraries, OpenSSL bindings for HTTPS support, the Tix GUI widgets for Tkinter, ElementTree for XML processing, ctypes (on supported platforms) for low-level library access, and others. The Windows distribution ships with PyWin32 -- a suite of Windows tools developed by Mark Hammond, including bindings to the Win32 API and Windows COM. Beginning with the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: pypm install pylons See this page for full details: http://docs.activestate.com/activepython/2.6/whatsincluded.html As well, ActivePython ships with a wealth of documentation for both new and experienced Python programmers. In addition to the core Python docs, ActivePython includes the "What's New in Python" series, "Dive into Python", the Python FAQs & HOWTOs, and the Python Enhancement Proposals (PEPs). An online version of the docs can be found here: http://docs.activestate.com/activepython/2.6/ We would welcome any and all feedback to: ActivePython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_product=ActivePython On what platforms does ActivePython run? ---------------------------------------- ActivePython includes installers for the following platforms: - Windows/x86 - Windows/x64 (aka "AMD64") - Mac OS X - Linux/x86 - Linux/x86_64 (aka "AMD64") - Solaris/SPARC (Business Edition only) - Solaris/x86 (Business Edition only) - HP-UX/PA-RISC (Business Edition only) - AIX/PowerPC (Business Edition only) - AIX/PowerPC 64-bit (Business Edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/activepython/enterprise/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From andreas.loescher at s2005.tu-chemnitz.de Thu Mar 25 13:41:23 2010 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Thu, 25 Mar 2010 18:41:23 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: Message-ID: <1269538883.9315.6.camel@laptop> > As you see, the traceback only starts from function c, which handles the > exception. > It doesn't show main(), a() and b(), which might however be (and are, in > my case) critical to diagnose the severity of the problem (since many > different paths would lead to calling c()). This results in the way the tb is created. If an exception occours, and there is no one who handles it in the current function, a traceback object is created. Because the the calling function could have a try-except clause, the function returns with NULL and an set exception. Now if there is no one to handle the exception, a traceback object is created and linked with the existing one. In your case does the traceback start from the function c, because no exception occoured in main() etc. You catched it. If you want to determine the calling path, you can take a look at the encapsuled frame in the tb. Best From anfedorov at gmail.com Thu Mar 25 13:41:57 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 25 Mar 2010 13:41:57 -0400 Subject: Repetition of work in Jython Message-ID: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> Hi all, So from what I understand, Jython translates Python code into JVM byte code. Does anyone know why this was chosen instead of translating Python bytecode to JVM bytecode directly? It seems that it would be a lot easier to get Jython up-to-speed if there could be some "shared components" between them and CPython, no? - Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Mar 25 14:10:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Mar 2010 14:10:00 -0400 Subject: Repetition of work in Jython In-Reply-To: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> References: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> Message-ID: <4BABA6F8.8070609@holdenweb.com> Andrey Fedorov wrote: > Hi all, > > So from what I understand, Jython translates Python code into JVM byte > code. Does anyone know why this was chosen instead of translating Python > bytecode to JVM bytecode directly? It seems that it would be a lot > easier to get Jython up-to-speed if there could be some "shared > components" between them and CPython, no? > I don't *know* why Jim Hugunin chose not to take that approach, but I can easily imagine it would be because a mapping of the Python byte code to the Java byte code would be much less efficient. There are various approaches that one could take. The least efficient would be to write a Python virtual machine in Java, thereby putting two levels of interpretation into the execution paths. I doubt it would be possible to get maximal JVM efficiency from code cast into Python byte codes just because of the disparity between the two VMs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Mar 25 14:10:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Mar 2010 14:10:00 -0400 Subject: Repetition of work in Jython In-Reply-To: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> References: <7659cab31003251041if13b73fmf17e759ea52b1015@mail.gmail.com> Message-ID: <4BABA6F8.8070609@holdenweb.com> Andrey Fedorov wrote: > Hi all, > > So from what I understand, Jython translates Python code into JVM byte > code. Does anyone know why this was chosen instead of translating Python > bytecode to JVM bytecode directly? It seems that it would be a lot > easier to get Jython up-to-speed if there could be some "shared > components" between them and CPython, no? > I don't *know* why Jim Hugunin chose not to take that approach, but I can easily imagine it would be because a mapping of the Python byte code to the Java byte code would be much less efficient. There are various approaches that one could take. The least efficient would be to write a Python virtual machine in Java, thereby putting two levels of interpretation into the execution paths. I doubt it would be possible to get maximal JVM efficiency from code cast into Python byte codes just because of the disparity between the two VMs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From sridharr at activestate.com Thu Mar 25 14:47:27 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 25 Mar 2010 11:47:27 -0700 Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 In-Reply-To: References: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> Message-ID: On 2010-02-09, at 2:49 PM, Sridhar Ratnakumar wrote: > > On 2010-02-07, at 5:02 PM, escalation746 wrote: > >> Andrej Mitrovic wrote: >> >>> Perhaps you've accidentally downloaded the wrong version of PythonWin? >> >> Erk, yes, my bad. >> >> Thanks for the quick help! Though I still wonder why the ActiveState >> build does not include this. > > I just added support for PyWin32 in ActivePython 2.6 64-bit. > > http://twitter.com/sridhr/status/8874549314 > > I should be part of next release (2.6.4.11). PyWin32, and thus PythonWin, is now available in all of the recent ActivePython releases: 2.5.5.7, 2.6.5.12 and 3.1.2.3. See also http://blogs.activestate.com/2010/03/activestate-releases-activepython-2-6-5-12-and-activepython-3-1-2-3/ -srid -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen-NOSPAM- at xs4all.nl Thu Mar 25 14:55:45 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Thu, 25 Mar 2010 19:55:45 +0100 Subject: Is there any library for indexing binary data? In-Reply-To: References: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> Message-ID: <4babb132$0$22945$e4fe514c@news.xs4all.nl> On 25-3-2010 10:55, ?? wrote: > Thank you irmen. I will take a look at pytable. > FYI, let me explain the case clearly. > > Originally, my big data table is simply array of Item: > struct Item > { > long id; // used as key > BYTE payload[LEN]; // corresponding value with fixed length > }; > > All items are stored in one file by using "stdio.h" function: > fwrite(itemarray, sizeof(Item), num_of_items, fp); > > Note that "id" is randomly unique without any order. To speed up > searching I regrouped / sorted them into two-level hash tables (in > the form of files). I want to employ certain library to help me index > this table. > > Since the table contains about 10^9 items and LEN is about 2KB, it is > impossible to hold all data in memory. Furthermore, some new item may > be inserted into the array. Therefore incremental indexing feature is > needed. I see, I thought the payload data was small as well. What about this idea: Build a hash table where the keys are the id from your Item structs and the value is the file seek offset of the Item 'record' in your original datafile. (although that might generate values of type long, which take more memory than int, so maybe we should use file_offset/sizeof(Item). This way you can just keep your original data file (you only have to scan it to build the hash table) and you will avoid a lengthy conversion process. If this hashtable still doesn't fit in memory use a sparse array implementation of some sort that is more efficient at storing simple integers, or just put it into a database solution mentioned in earlier responses. Another thing: I think that your requirement of 1e7 lookups per second is a bit steep for any solution where the dataset is not in core memory at once though. Irmen. From st.chris at gmail.com Thu Mar 25 15:51:48 2010 From: st.chris at gmail.com (=?UTF-8?Q?Christian_=C5=9Etef=C4=83nescu?=) Date: Thu, 25 Mar 2010 20:51:48 +0100 Subject: Improved timedelta attributes/methods Message-ID: Hello dear Python-wielding developers! I generally like date/time handling in Python very much, especially how date operations result in Timedelta objects. But I find it somewhat impractical, that you can only get days, seconds and microseconds out of a time delta. I think it would be much more comfortable to have fields for minutes, hours, maybe also years, months. Is there a specific reasoning why this is not available? I would gladly do my best to implement such a solution, if it would make sense to the devs. Regards, Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at psantoro.net Thu Mar 25 16:07:42 2010 From: peter at psantoro.net (Peter) Date: 25 Mar 2010 20:07:42 GMT Subject: RELEASED Python 2.6.5 References: Message-ID: On Wed, 24 Mar 2010 23:22:01 +0100, Martin v. Loewis wrote: >> Is anyone else having trouble with the 2.6.5 Windows x86 installer? > > Not me. Run > > msiexec /i py...msi /l*v py.log > > and inspect py.log for errors (post it to bugs.python.org if you can't > determine the cause of the problems). Martin, Thanks for the tip about the msiexec command line usage. If I run the installer without selecting the Advanced compiling option, it works fine. The relevent part of the log when it fails using the Advanced compiling option is as follows: -------------------- MSI (s) (4C:B4) [14:41:27:205]: Doing action: CompilePyc Action 14:41:27: CompilePyc. Action start 14:41:27: CompilePyc. MSI (s) (4C:B4) [14:45:45:528]: Note: 1: 1722 2: CompilePyc 3: C:\bin \Python26\python.exe 4: -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" MSI (s) (4C:B4) [14:45:45:528]: Note: 1: 2262 2: Error 3: -2147287038 Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action CompilePyc, location: C:\bin \Python26\python.exe, command: -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" MSI (s) (4C:B4) [14:47:41:133]: Note: 1: 2262 2: Error 3: -2147287038 MSI (s) (4C:B4) [14:47:41:133]: Product: Python 2.6.5 -- Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action CompilePyc, location: C:\bin\Python26 \python.exe, command: -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" Action ended 14:47:41: CompilePyc. Return value 3. Action ended 14:47:41: INSTALL. Return value 3. -------------------- I believe the cause of the installation failure message is with the syntax of the following command: C:\bin\Python26\python.exe -Wi "C:\bin\Python26\Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py3_ "C:\bin\Python26\Lib" If you run this command in the Windows XP shell, it yields an error. If you wrap the -x option's args in double quotes, it runs ok (except for a syntax error when compiling one of the python source files - I don't remember which one): C:\bin\Python26\python.exe -Wi "C:\bin\Python26\Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py3_" "C:\bin\Python26\Lib" So it appears that the Windows XP shell is interpreting the "|" characters within the -x option's args as pipe characters and trys to pipe the "multiple commands" together. The simple work around is to not use the Advanced compiling option. Peter From steve at REMOVE-THIS-cybersource.com.au Thu Mar 25 17:11:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Mar 2010 21:11:50 GMT Subject: sum for sequences? References: <2010032423502316807-tomfsessile@gmailcom> <8113nqFsggU3@mid.individual.net> Message-ID: <4babd196$0$8766$c3e8da3@news.astraweb.com> On Thu, 25 Mar 2010 14:02:05 +0100, Alf P. Steinbach wrote: > * Neil Cerutti: >> On 2010-03-25, Steven D'Aprano >> wrote: >>>> You might not want to be so glib. The sum doc sure doesn't sound >>>> like it should work on lists. >>>> >>>> Returns the sum of a sequence of numbers (NOT strings) plus the >>>> value of parameter 'start' (which defaults to 0). >>> What part of that suggested to you that sum might not be polymorphic? >>> Sure, it says numbers (which should be changed, in my opinion), but it >>> doesn't specify what sort of numbers -- ints, floats, or custom types >>> that have an __add__ method. >> >> WTF. > > I think Steven's argument is that it would be pointless for 'sum' to > distinguish between user-defined numerical types and other types that > happen to support '+'. Before Python2.6, which introduced a numeric tower, Python *couldn't* reliably distinguish between numeric types and other types that overloaded +. Since Python discourages type-checking in favour of duck- typing and try...except, this is seen as a good thing. My argument is that sum isn't hard-coded to only work on the built-ins ints or floats, but it supports any object that you can use the + operator on. The *sole* exceptions are str and unicode (not even UserString), and even there it is very simple to overcome the restriction: >>> sum(['a', 'b'], '') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] >>> class S: ... def __add__(self, other): ... return other ... >>> sum(['a', 'b'], S()) 'ab' [...] > However, given that it isn't restricted to numbers, the restriction wrt. > strings is a bit perplexing in the context of modern CPython. But for > Python implementations that don't offer the '+=' optimization it might > help to avoid gross inefficiencies, namely quadratic time string > concatenation. I agree -- the Python philosophy is to allow the user to shoot themselves in the foot if they wish to. You're responsible for the Big Oh behaviour of your code, not the compiler. [...] > However, if that hypothesis about the rationale is correct, then 'sum' > should also be restricted to not handle tuples or lists, so forth, but > at least the CPython implementation does. The reasoning is that naive users are far, far more likely to try summing a large list of strings than to try summing a large list of lists, and therefore in practical terms the consequences of allowing sum on lists is slight enough and rare enough to not be worth the check. I suspect that this is just an after the fact rationalisation, and that the real reason is that those responsible for the hand-holding in sum merely forgot, or didn't know, that repeated addition of lists and tuples is also O(N**2). But I've never cared enough to dig through the archives to find out. -- Steven From winstonw at stratolab.com Thu Mar 25 17:16:12 2010 From: winstonw at stratolab.com (Winston) Date: Thu, 25 Mar 2010 14:16:12 -0700 (PDT) Subject: Revisiting Generators and Subgenerators Message-ID: I have been reading PEP 380 because I am writing a video game/ simulation in Jython and I need cooperative multitasking. PEP 380 hits on my problem, but does not quite solve it for me. I have the following proposal as an alternative to PEP380. I don't know if this is the right way for me to introduce my idea, but below is my writeup. Any thoughts? ------------------------ Proposal for a new Generator Syntax in Python 3K-- A Baton object for generators to allow subfunction to yield, and to make them symetric. Abstract -------- Generators can be used to make coroutines. But they require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value. We propose a modification to generators in Python 3 where a "Baton" object is given to both sides of a generator. Both sides use the baton object to pass execution to the other side, and also to pass values to the other side. The advantages of a baton object over the current scheme are: (1) the generator function can pass the baton to a subfunction, solving the needs of PEP 380, (2) after creation both sides of the generator function are symetric--they both can call yield(), send(), next(). They do the same thing. This means programming with generators is the same as programming with normal functions. No special contortions are needed to pass values back up to a yield command at the top. Motivation ---------- Generators make certain programming tasks easier, such as (a) an iterator which is of infinite length, (b) using a "trampoline function" they can emulate coroutines and cooperative multitasking, (c) they can be used to make both sides of a producer-consumer pattern easy to write-- both sides can appear to be the caller. On the down side, generators as they currently are implemented in Python 3.1 require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value--subfunctions called by the generator function may not yield a value. Here are two use-cases in which generators are commonly used, but where the current limitation causes less readable code: 1) a long generator function which the programmer wants to split into several functions. The subfunctions should be able to yield a result. Currently the subfunctions have to pass values up to the main generator and have it yield the results back. Similarly subfunctions cannot receive values that the caller sends with generator.send() 2) generators are great for cooperative multitasking. A common use- case is agent simulators where many small "tasklets" need to run and then pass execution over to other tasklets. Video games are a common scenario, as is SimPy. Without cooperative multitasking, each tasklet must be contorted to run in a small piece and then return. Generators help this, but a more complicated algorithm which is best decomposed into several functions must be contorted because the subfuctions cannot yield or recive data from the generator.send(). Here is also a nice description of how coroutines make programs easier to read and write: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html Proposal -------- If there is a way to make a sub-function of a generator yield and receive data from generator.send(), then the two problems above are solved. For example, this declares a generator. The first parameter of the generator is the "context" which represents the other side of the execution frame. a Baton object represents a passing of the execution from one line of code to another. A program creates a Baton like so: generator f( baton ): # compute something baton.yield( result ) # compute something baton.yield( result ) baton = f() while True: print( baton.yield() ) A generator function, denoted with they keyword "generator" instead of "def" will return a "baton". Generators have the following methods: __call__( args... ) -- This creates a Baton object which is passed back to the caller, i.e. the code that executed the Baton() command. Once the baton starts working, the two sides are symetric. So we will call the first frame, frame A and the code inside 'function' frame B. Frame is is returned a baton object. As soon as frame A calls baton.yield(), frame B begins, i.e. 'function' starts to run. function is passed the baton as its first argument, and any additional arguments are also passed in. When frame B yields, any value that it yields will be returned to frame A as the result of it's yield(). Batons have the following methods: yield( arg=None ) -- This method will save the current execution state, restore the other execution state, and start running the other function from where it last left off, or from the beginning if this is the first time. If the optional 'arg' is given, then the other side will be "returned" this value from it's last yield(). Note that like generators, the first call to yield may not pass an argument. next() -- This method is the same as yield(None). next() allows the baton to be an iterator. __iter__() -- A baton is an iterator so this just returns the baton back. But it is needed to allow use of batons in "for" statements. start() -- This starts the frame B function running. It may only be called on a new baton. It starts the baton running in frame B, and returns the Baton object to the caller in frame A. Any value from the first yield is lost. baton = Baton( f ).start() It is equivalent to: baton = Baton( f ) # Create the baton baton.yield() # Begin executing in frame B Examples -------- Simple Generator: generator doubler( baton, sequence ): for a in sequence: print( a ) baton.yield( a+a ) baton = doubler( [3,8,2] ) for j in baton: # For statement calls baton.__iter__, and then baton.next() print j Complicated Generator broken into parts: generator Complicated( baton, sequence ): '''A generator function, but there are no yield statements in this function--they are in subfunctions.''' a = sequence.next() if is_special(a): parse_special( baton, a, sequence) else: parse_regular( baton, a, sequence ) def parse_special( baton, first, rest ): # process first baton.yield() b = rest.next() parse_special( baton, b, rest ) def parse_regular( baton, first, rest ): # more stuff baton.yield() baton = Complicated( iter('some data here') ) baton.yield() Cooperative Multitasker: class Creature( object ): def __init__(self, world): self.world = world generator start( self, baton ): '''Designated entry point for tasklets''' # Baton saved for later. Used in other methods like escape() self.baton = baton self.run() def run(self): pass # override me in your subclass def escape(self): # set direction and velocity away from baton creatures self.baton.yield() def chase(self): while True: # set direction and velocity TOWARDS nearest creature self.baton.yield() # if near enough, try to pounce self.baton.yield() class Vegetarian( Tasklet ): def run(self): if self.world.is_creature_visible(): self.escape() else: # do nothing self.baton.yield() class Carnivore( Tasklet ): def run(self): if self.world.is_creature_visible(): self.chase() else: # do nothing self.baton.yield() w = SimulationWorld() v = Vegetarian( w ).start() c = Carnivore( w ).start() while True: v.yield() c.yield() Benefits -------- This new syntax for a generator provides all the benefits of the old generator, including use like a coroutine. Additionally, it makes both sides of the generator almost symetric, i.e. they both "yield" or "send" to the other. And since the baton objects are passed around, subfunctions can yield back to the other execution frame. This fixes problems such as PEP 380. My ideas for syntax above are not fixed, the important concept here is that the two sides of the generator functions will have a "baton" to represent the other side. The baton can be passed to sub- functions, and values can be sent, via the baton, to the other side. This new syntax for a generator will break all existing programs. But we happen to be at the start of Python 3K where new paradaigms are being examined. Alternative Syntax ------------------ With old style generators, g.next() and g.send( 1 ) are conceptually the same as "yield" and "yield 1" inside the generator. They both pass execution to the other side, and the second form passes a value. Yet they currently have different syntax. Once we have a baton object, we can get rid of one of these forms. g.next() is needed to support iterators. How about we keep baton.next() and baton.send( 1 ). We get rid of yield completely. Perhaps instead of a "generator" keyword to denote the generator function, a "fork" keyword should be used to begin the second execution frame. For example: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = fork f() while True: print( baton.next() ) or maybe the "yield" keyword can be used here: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = yield f while True: print( baton.next() ) From winstonw at stratolab.com Thu Mar 25 17:39:51 2010 From: winstonw at stratolab.com (Winston) Date: Thu, 25 Mar 2010 14:39:51 -0700 (PDT) Subject: Revisiting Generators and Subgenerators Message-ID: Here's my proposal again, but hopefully with better formatting so you can read it easier. -Winston ----------------- Proposal for a new Generator Syntax in Python 3K-- A Baton object for generators to allow subfunction to yield, and to make them symetric. Abstract -------- Generators can be used to make coroutines. But they require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value. We propose a modification to generators in Python 3 where a "Baton" object is given to both sides of a generator. Both sides use the baton object to pass execution to the other side, and also to pass values to the other side. The advantages of a baton object over the current scheme are: (1) the generator function can pass the baton to a subfunction, solving the needs of PEP 380, (2) after creation both sides of the generator function are symetric--they both can call yield(), send(), next(). They do the same thing. This means programming with generators is the same as programming with normal functions. No special contortions are needed to pass values back up to a yield command at the top. Motivation ---------- Generators make certain programming tasks easier, such as (a) an iterator which is of infinite length, (b) using a "trampoline function" they can emulate coroutines and cooperative multitasking, (c) they can be used to make both sides of a producer-consumer pattern easy to write--both sides can appear to be the caller. On the down side, generators as they currently are implemented in Python 3.1 require the programmer to take special care in how he writes his generator. In particular, only the generator function may yield a value--subfunctions called by the generator function may not yield a value. Here are two use-cases in which generators are commonly used, but where the current limitation causes less readable code: 1) a long generator function which the programmer wants to split into several functions. The subfunctions should be able to yield a result. Currently the subfunctions have to pass values up to the main generator and have it yield the results back. Similarly subfunctions cannot receive values that the caller sends with generator.send() 2) generators are great for cooperative multitasking. A common use-case is agent simulators where many small "tasklets" need to run and then pass execution over to other tasklets. Video games are a common scenario, as is SimPy. Without cooperative multitasking, each tasklet must be contorted to run in a small piece and then return. Generators help this, but a more complicated algorithm which is best decomposed into several functions must be contorted because the subfuctions cannot yield or recive data from the generator.send(). Here is also a nice description of how coroutines make programs easier to read and write: http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html Proposal -------- If there is a way to make a sub-function of a generator yield and receive data from generator.send(), then the two problems above are solved. For example, this declares a generator. The first parameter of the generator is the "context" which represents the other side of the execution frame. a Baton object represents a passing of the execution from one line of code to another. A program creates a Baton like so: generator f( baton ): # compute something baton.yield( result ) # compute something baton.yield( result ) baton = f() while True: print( baton.yield() ) A generator function, denoted with they keyword "generator" instead of "def" will return a "baton". Generators have the following methods: __call__( args... ) -- This creates a Baton object which is passed back to the caller, i.e. the code that executed the Baton() command. Once the baton starts working, the two sides are symetric. So we will call the first frame, frame A and the code inside 'function' frame B. Frame is is returned a baton object. As soon as frame A calls baton.yield(), frame B begins, i.e. 'function' starts to run. function is passed the baton as its first argument, and any additional arguments are also passed in. When frame B yields, any value that it yields will be returned to frame A as the result of it's yield(). Batons have the following methods: yield( arg=None ) -- This method will save the current execution state, restore the other execution state, and start running the other function from where it last left off, or from the beginning if this is the first time. If the optional 'arg' is given, then the other side will be "returned" this value from it's last yield(). Note that like generators, the first call to yield may not pass an argument. next() -- This method is the same as yield(None). next() allows the baton to be an iterator. __iter__() -- A baton is an iterator so this just returns the baton back. But it is needed to allow use of batons in "for" statements. start() -- This starts the frame B function running. It may only be called on a new baton. It starts the baton running in frame B, and returns the Baton object to the caller in frame A. Any value from the first yield is lost. baton = Baton( f ).start() It is equivalent to: baton = Baton( f ) # Create the baton baton.yield() # Begin executing in frame B Examples -------- Simple Generator: generator doubler( baton, sequence ): for a in sequence: print( a ) baton.yield( a+a ) baton = doubler( [3,8,2] ) # For statement calls baton.__iter__, and then baton.next() for j in baton: print j Complicated Generator broken into parts: generator Complicated( baton, sequence ): '''A generator function, but there are no yield statements in this function--they are in subfunctions.''' a = sequence.next() if is_special(a): parse_special( baton, a, sequence) else: parse_regular( baton, a, sequence ) def parse_special( baton, first, rest ): # process first baton.yield() b = rest.next() parse_special( baton, b, rest ) def parse_regular( baton, first, rest ): # more stuff baton.yield() baton = Complicated( iter('some data here') ) baton.yield() Cooperative Multitasker: class Creature( object ): def __init__(self, world): self.world = world generator start( self, baton ): '''Designated entry point for tasklets''' # Baton saved for later. Used in other # methods like escape() self.baton = baton self.run() def run(self): pass # override me in your subclass def escape(self): # set direction and velocity away # from baton creatures self.baton.yield() def chase(self): while True: # set direction and velocity TOWARDS # nearest creature self.baton.yield() # if near enough, try to pounce self.baton.yield() class Vegetarian( Tasklet ): def run(self): if self.world.is_creature_visible(): self.escape() else: # do nothing self.baton.yield() class Carnivore( Tasklet ): def run(self): if self.world.is_creature_visible(): self.chase() else: # do nothing self.baton.yield() w = SimulationWorld() v = Vegetarian( w ).start() c = Carnivore( w ).start() while True: v.yield() c.yield() Benefits -------- This new syntax for a generator provides all the benefits of the old generator, including use like a coroutine. Additionally, it makes both sides of the generator almost symetric, i.e. they both "yield" or "send" to the other. And since the baton objects are passed around, subfunctions can yield back to the other execution frame. This fixes problems such as PEP 380. My ideas for syntax above are not fixed, the important concept here is that the two sides of the generator functions will have a "baton" to represent the other side. The baton can be passed to sub-functions, and values can be sent, via the baton, to the other side. This new syntax for a generator will break all existing programs. But we happen to be at the start of Python 3K where new paradaigms are being examined. Alternative Syntax ------------------ yield, next, and send are redundant ------------------------------------ With old style generators, g.next() and g.send( 1 ) are conceptually the same as "yield" and "yield 1" inside the generator. They both pass execution to the other side, and the second form passes a value. Yet they currently have different syntax. Once we have a baton object, we can get rid of one of these forms. g.next() is needed to support iterators. How about we keep baton.next() and baton.send( 1 ). We get rid of yield completely. Use keyword to invoke a generator rather than declare ------------------------------------------------------------ Perhaps instead of a "generator" keyword to denote the generator function, a "fork" keyword should be used to begin the second execution frame. For example: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = fork f() while True: print( baton.next() ) or maybe the "yield" keyword can be used here: def f( baton ): # compute something baton.send( result ) # compute something baton.send( result ) baton = yield f while True: print( baton.next() ) From michel.metzger at gmail.com Thu Mar 25 18:00:35 2010 From: michel.metzger at gmail.com (Michel) Date: Thu, 25 Mar 2010 15:00:35 -0700 (PDT) Subject: Create a class at run-time Message-ID: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Hi everyone, I'm trying to dynamically create a class. What I need is to define a class, add methods to it and later instantiate this class. Methods need to be bound to the instance though, and that's my problem. Here is what I have so far: method_template = "def test_foo(self):\ #actual test_foo\ pass" exec method_template TestClass = types.ClassType("MyTestClass", (unittest.TestCase, ), {}) TestClass.__module__ = "test" now what to do next? I looked at types.MethodType but it needs an instance to bind the method and a function object. Should I define __new__ to bind the method during instantiation? Hope this makes sense, Michel. From john at castleamber.com Thu Mar 25 18:13:49 2010 From: john at castleamber.com (John Bokma) Date: Thu, 25 Mar 2010 16:13:49 -0600 Subject: XPCOM/hulahop: waiting for JavaScript finished? Message-ID: <87sk7ohwwy.fsf@castleamber.com> I am playing a bit with hulahop/xpcom using the code found at http://www.advogato.org/article/1014.html but have no idea how to check if some JavaScript has finised running. The _loaded method of Browser is called after the document has finished loading, but as far as I can tell this doesn't mean that the JavaScript has finised setting things up. Is there a way to either wait a few seconds in _loaded (fragile, of course). time.sleep() (as expected) blocks. Or better, is there a way to check if JavaScript has stopped running? (Hmmm... thinking of it, this can also run on events, so maybe there is no good way to do this?) Thanks, -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From motoom at xs4all.nl Thu Mar 25 18:18:17 2010 From: motoom at xs4all.nl (Michiel Overtoom) Date: Thu, 25 Mar 2010 23:18:17 +0100 Subject: Create a class at run-time In-Reply-To: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <4BABE129.8010205@xs4all.nl> On 2010-03-25 23:00, Michel wrote: > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Maybe this snippet is of any help? import functools class Template(object): pass def printmyname(self): print self.name t=Template() t.name="Pete" t.printmyname=functools.partial(printmyname,t) u=Template() u.name="Mary" u.printmyname=functools.partial(printmyname,u) t.printmyname() u.printmyname() Greetings, -- "The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing." - Vinod Valloppillil http://www.catb.org/~esr/halloween/halloween4.html From egbertum at xs4all.nl Thu Mar 25 18:28:48 2010 From: egbertum at xs4all.nl (egbert) Date: Thu, 25 Mar 2010 23:28:48 +0100 Subject: from import and __init__.py In-Reply-To: References: <20100325101632.GA4727@xs4all.nl> Message-ID: <20100325222848.GB13846@xs4all.nl> On Thu, Mar 25, 2010 at 12:43:13PM -0400, Terry Reedy wrote: > On 3/25/2010 6:16 AM, egbert wrote: > >When I do 'from some_package import some_module' > >the __init__.py of some_package will be run. > >However, there will not be anything like a package-module, > >and the effects of __init__.py seem all to be lost. Is that true ? > > No. If you do > > from sys import modules > print(modules.keys()) > > you will see both some_package and some_package.some_module among > the entries. Yes, you are right. And I can reach everything with modules['some_package'] or variants thereof. Thanks, egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From pmaupin at gmail.com Thu Mar 25 18:34:32 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 25 Mar 2010 15:34:32 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <239b30ba-5465-4466-b2a6-6a5cf62e1028@35g2000yqm.googlegroups.com> On Mar 25, 5:00?pm, Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: Well, you should just fill your empty dict with function definitions, BEFORE you build the class. That's easiest. Also, you can just use type: def foo(*whatever): print foo bar = type('MyDynamicClass', (object,), dict(foo=foo)) HTH, Pat From james.harris.1 at googlemail.com Thu Mar 25 18:40:33 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Thu, 25 Mar 2010 15:40:33 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi Message-ID: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> I am looking to store named pieces of text in a form that can be edited by a standard editor such as notepad (under Windows) or vi (under Unix) and then pulled into Python as needed. The usual record locking and transactions of databases are not required. Another way to look at it is to treat the separate files as entries in a dictionary. The file name would be the key and the lines of the file the value. Anyone know of a database (with a Python interface) which will allow text files to be treated as database fields? If not I can just write it but I thought it best to ask if there was an existing solution first. James From jkn_gg at nicorp.f9.co.uk Thu Mar 25 18:55:20 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Thu, 25 Mar 2010 15:55:20 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> Message-ID: Kirbybase is one possibility. http://pypi.python.org/pypi/KirbyBase/1.9 J^n From joncle at googlemail.com Thu Mar 25 18:56:22 2010 From: joncle at googlemail.com (Jon Clements) Date: Thu, 25 Mar 2010 15:56:22 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> Message-ID: <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> On 25 Mar, 22:40, James Harris wrote: > I am looking to store named pieces of text in a form that can be > edited by a standard editor such as notepad (under Windows) or vi > (under Unix) and then pulled into Python as needed. The usual record > locking and transactions of databases are not required. > > Another way to look at it is to treat the separate files as entries in > a dictionary. The file name would be the key and the lines of the file > the value. > > Anyone know of a database (with a Python interface) which will allow > text files to be treated as database fields? If not I can just write > it but I thought it best to ask if there was an existing solution > first. > > James I could be missing something here, but aren't you basically just talking about an OS's filesystem? glob or listdir somewhere, then create a dict using the file contents would meet your criteria, with very little lines of code -- but I would be interested to know what the use-case was for this... Is it read completely at start up time, or if each file contains a large amount of lines and aren't fixed width (or has no other indexing support without maintenance), then is a complete sequential-scan required each time, or do you just tell the user to not update when running (unless I s'pose something along the lines of a SIGHUP for config files is applicable). Sorry, just don't understand why you'd want this. Jon. From sccolbert at gmail.com Thu Mar 25 19:07:56 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 25 Mar 2010 19:07:56 -0400 Subject: nested threading In-Reply-To: <4566e767-768f-4399-8a6b-5530ec90b03c@a37g2000prd.googlegroups.com> References: <4566e767-768f-4399-8a6b-5530ec90b03c@a37g2000prd.googlegroups.com> Message-ID: <7f014ea61003251607q7a3086adx90eb04a1a2861bce@mail.gmail.com> Spawning a thread from within a thread works just fine. Calling thread.start() is a non-blocking function and returns immediately. On Thu, Mar 25, 2010 at 11:23 AM, Omer Ihsan wrote: > is there anything as "nested threading"....that is, call a thread from > within a thread. > in this case how will thread locking take place. > > for example initially there were two functions that were called using > threading.Thread. these wont get unlocked unless both of them are done > with whatever they need to do. if say function 2 calls another thread. > then what?? > > inquisitive....:-| > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Thu Mar 25 19:16:39 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 26 Mar 2010 12:16:39 +1300 Subject: Sniffing encoding type by looking at file BOM header References: Message-ID: In message , python at bdurham.com wrote: > BOM_UTF8 = '\xef\xbb\xbf' Since when does UTF-8 need a BOM? From irmen-NOSPAM- at xs4all.nl Thu Mar 25 19:21:34 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Fri, 26 Mar 2010 00:21:34 +0100 Subject: Sniffing encoding type by looking at file BOM header In-Reply-To: References: Message-ID: <4babef80$0$22918$e4fe514c@news.xs4all.nl> On 26-3-2010 0:16, Lawrence D'Oliveiro wrote: > In message, > python at bdurham.com wrote: > >> BOM_UTF8 = '\xef\xbb\xbf' > > Since when does UTF-8 need a BOM? It doesn't, but it is allowed. Not recommended though. Unfortunately several tools, such as notepad.exe, have a tendency of silently adding it when saving files. -irmen From martin.hellwig at dcuktec.org Thu Mar 25 19:29:09 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Mar 2010 23:29:09 +0000 Subject: Don't understand behavior; instance form a class in another class' instance Message-ID: Hi all, When I run the following snippet (drastically simplified, to just show what I mean): >> import platform, sys class One(object): def __init__(self): self.one = True def change(self): self.one = False class Two(object): def __init__(self): self._instance_one = One() self.one = self._instance_one.one self.change = self._instance_one.change if __name__ == '__main__': print(sys.version) print(platform.machine()) print(80*'#') TEST1 = One() print(TEST1.one) TEST1.change() print(TEST1.one) TEST1 = None print(80*'#') TEST2 = Two() print(TEST2.one) TEST2.change() print(TEST2.one >> I get the following result: << [GCC 4.2.1 20070719 [FreeBSD]] amd64 ################################################################################ True False ################################################################################ True True ################################################################################ << What I don't understand why in the second test, the last boolean is True instead of (what I expect) False. Could somebody enlighten me please as this has bitten me before and I am confused by this behavior. Thanks in advance -- mph From lists at cheimes.de Thu Mar 25 19:41:57 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 26 Mar 2010 00:41:57 +0100 Subject: Don't understand behavior; instance form a class in another class' instance In-Reply-To: References: Message-ID: Martin P. Hellwig schrieb: > What I don't understand why in the second test, the last boolean is True > instead of (what I expect) False. > Could somebody enlighten me please as this has bitten me before and I am > confused by this behavior. Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you alter TEST2.__instance_one.one you don't magically change TEST2.one, too. Python doesn't have variables like C pointers. Python's copy by object (or share by object) behavior can be understand as labels. The label TEST2.one references the same object as TEST2.__instance_one.one until you change where the label TEST2.__instance_one.one points to. Christian From martin.hellwig at dcuktec.org Thu Mar 25 20:06:06 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 26 Mar 2010 00:06:06 +0000 Subject: Don't understand behavior; instance form a class in another class' instance In-Reply-To: References: Message-ID: On 03/25/10 23:41, Christian Heimes wrote: > Martin P. Hellwig schrieb: >> What I don't understand why in the second test, the last boolean is True >> instead of (what I expect) False. >> Could somebody enlighten me please as this has bitten me before and I am >> confused by this behavior. > > Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you > alter TEST2.__instance_one.one you don't magically change TEST2.one, > too. Python doesn't have variables like C pointers. Python's copy by > object (or share by object) behavior can be understand as labels. The > label TEST2.one references the same object as TEST2.__instance_one.one > until you change where the label TEST2.__instance_one.one points to. > > Christian > Ah okay thanks for the explanation, Am I correct in thinking (please correct me if I mangle up the terminology and/or totally are in the wrong ballpark) that this is more or less because the label of the first class is to an object (boolean with value False) and the label of the second class does not cascade to the first label for looking something up but instead during assignment sees that it is a label to an object instead of the object itself thus copies the label content instead? I probably expected classes namespaces to behave in about the same way as lists and dictionaries do, don't know where I picked that up. Thanks again, -- mph From ovidiudeac at gmail.com Thu Mar 25 20:11:39 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 02:11:39 +0200 Subject: python logging writes an empty file Message-ID: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> Hi, I have the following situation: My application uses nosetests to discover&run the unittests. I pass the log configuration file as --logging-config=logging.conf Everything works just fine, the logs are printed as required by the configuration file which makes me happy. I take this as a sign that my logging.conf is correct Then in my main script, which starts the production application, I have this line: logging.config.fileConfig("logging.conf") The logging module is configured without errors BUT my output.log is EMPTY. It's like all the messages are filtered. If I configure logging like this: logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)s: %(message)s', datefmt='%m-%d %H:%M:%S', filename=file, filemode='w') Then the logs are printed ok. Then I tried this: file = logging.FileHandler(logFileBasename, 'w') file.setLevel(logging.INFO) # set a format which is simpler for console use formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s',) # tell the handler to use this format file.setFormatter(formatter) # add the handler to the root logger logging.getLogger('').addHandler(file) logging.getLogger('') ...which also leaves my output file EMPTY. I'm out of ideas. Can anybody help me with this? Thanks in advance! ovidiu Here is my logging.conf: [formatters] keys: detailed,simple [handlers] keys: console,file [loggers] keys: root [formatter_simple] format: %(name)s:%(levelname)s: %(message)s [formatter_detailed] format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s [handler_console] class: StreamHandler args: [] formatter: detailed [handler_file] class=FileHandler level=DEBUG formatter=detailed args=('output.log', 'w') filename=output.log mode=w [logger_root] level: INFO handlers: file propagate: 1 From cs at zip.com.au Thu Mar 25 20:23:39 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 26 Mar 2010 11:23:39 +1100 Subject: Revisiting Generators and Subgenerators In-Reply-To: References: Message-ID: <20100326002339.GA18453@cskk.homeip.net> On 25Mar2010 14:39, Winston wrote: | Here's my proposal again, but hopefully with better formatting so you | can read it easier. Having quickly read the Abstract and Motivation, why is this any better than a pair of threads and a pair of Queue objects? (Aside from co-routines being more lightweight in terms of machine resources?) On the flipside, given that generators were recently augumented to support coroutines I can see your motivation within that framework. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ C makes it easy for you to shoot yourself in the foot. C++ makes that harder, but when you do, it blows away your whole leg. - Bjarne Stroustrup From andrej.mitrovich at gmail.com Thu Mar 25 20:25:58 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Thu, 25 Mar 2010 17:25:58 -0700 (PDT) Subject: Traversing through Dir() Message-ID: I would like to traverse through the entire structure of dir(), and write it to a file. Now, if I try to write the contents of dir() to a file (via pickle), I only get the top layer. So even if there are lists within the returned list from dir(), they get written as a list of strings to the file. Basically, I have an embedded and somewhat stripped version of Python. I would like to find out just how much functionality it has (I have no documentation for it), so I thought the best way to do that is traverse thru the dir() call. Any clues as to how I could write the whole structure to a file? I guess I'll need some kind of recursion here. :) From winstonw at stratolab.com Thu Mar 25 20:31:24 2010 From: winstonw at stratolab.com (Winston Wolff) Date: Thu, 25 Mar 2010 17:31:24 -0700 Subject: Revisiting Generators and Subgenerators In-Reply-To: <20100326002339.GA18453@cskk.homeip.net> References: <20100326002339.GA18453@cskk.homeip.net> Message-ID: <21283BA1-DFA5-4DD9-9478-89D0622F447C@stratolab.com> Coroutines achieve very similar things to threads, but avoid problems resulting from the pre-emptive nature of threads. Specifically, a coroutine indicates where it will yield to the other coroutine. This avoids lots of problems related to synchronization. Also the lightweight aspect is apparently important for some simulations when they have many thousands of agents to simulate--this number of threads becomes a problem. -Winston Winston Wolff Stratolab - Games for Learning tel: (646) 827-2242 web: www.stratolab.com On Mar 25, 2010, at 5:23 PM, Cameron Simpson wrote: > > Having quickly read the Abstract and Motivation, why is this any better > than a pair of threads and a pair of Queue objects? (Aside from > co-routines being more lightweight in terms of machine resources?) > > On the flipside, given that generators were recently augumented to > support coroutines I can see your motivation within that framework. > > Cheers, > -- > Cameron Simpson DoD#743 > http://www.cskk.ezoshosting.com/cs/ > > C makes it easy for you to shoot yourself in the foot. C++ makes that > harder, but when you do, it blows away your whole leg. > - Bjarne Stroustrup From jason.heeris at gmail.com Thu Mar 25 20:49:30 2010 From: jason.heeris at gmail.com (Jason) Date: Thu, 25 Mar 2010 17:49:30 -0700 (PDT) Subject: Represent object type as References: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> <4bab888e$0$26553$426a74cc@news.free.fr> Message-ID: On Mar 26, 12:00?am, Bruno Desthuilliers wrote: > ? ? ? ? ? ?attrs['type'] = type(self) > > Do the same thing with less work !-) Ah, silly me :P > ? ? ?attrs['__typename__'] = type(self).__name__ That's exactly what I needed ? I was not aware of the "__name__" attribute. > Warning: won't be very useful if your code still uses old-style classes. No, all the objects are new-style classes so that's fine. > Depends on what you do with this dict, DBUS etc. And of your definition > of "better", of course. Simplest possible :P But this looks like it, so thanks very much :) Cheers, Jason From anand.shashwat at gmail.com Thu Mar 25 20:59:33 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 06:29:33 +0530 Subject: Traversing through Dir() In-Reply-To: References: Message-ID: have you tried os.walk() ? On Fri, Mar 26, 2010 at 5:55 AM, Andrej Mitrovic wrote: > I would like to traverse through the entire structure of dir(), and > write it to a file. > > Now, if I try to write the contents of dir() to a file (via pickle), I > only get the top layer. So even if there are lists within the returned > list from dir(), they get written as a list of strings to the file. > > Basically, I have an embedded and somewhat stripped version of Python. > I would like to find out just how much functionality it has (I have no > documentation for it), so I thought the best way to do that is > traverse thru the dir() call. Any clues as to how I could write the > whole structure to a file? I guess I'll need some kind of recursion > here. :) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nocbos at gmail.com Thu Mar 25 21:03:58 2010 From: nocbos at gmail.com (C. B.) Date: Thu, 25 Mar 2010 18:03:58 -0700 (PDT) Subject: Automatic import ? Message-ID: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Hi everyone, I'm currently coding a C library which provides several modules and objects. Let's say that some of these objects are classes called AAA and BBB. The constructor of AAA needs to get BBB as argument. So I can run the following code : from mymodule import AAA from mymodule import BBB a = AAA(BBB())) But, as there is no case where AAA can be used without BBB, I would like to avoid importing BBB in my Python scripts when I already import AAA. For now, I think that reproducing the behavior of the __init__.py file could be a good way to do this, but how can I code that using only the C API ? Are there any other solutions ? Is this kind of importation a good idea ? Greetings, Cyrille Bagard From rhodri at wildebst.demon.co.uk Thu Mar 25 21:10:36 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 26 Mar 2010 01:10:36 -0000 Subject: Don't understand behavior; instance form a class in another class' instance References: Message-ID: On Fri, 26 Mar 2010 00:06:06 -0000, Martin P. Hellwig wrote: > On 03/25/10 23:41, Christian Heimes wrote: >> Martin P. Hellwig schrieb: >>> What I don't understand why in the second test, the last boolean is >>> True >>> instead of (what I expect) False. >>> Could somebody enlighten me please as this has bitten me before and I >>> am >>> confused by this behavior. >> >> Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you >> alter TEST2.__instance_one.one you don't magically change TEST2.one, >> too. Python doesn't have variables like C pointers. Python's copy by >> object (or share by object) behavior can be understand as labels. The >> label TEST2.one references the same object as TEST2.__instance_one.one >> until you change where the label TEST2.__instance_one.one points to. >> >> Christian >> > > Ah okay thanks for the explanation, Am I correct in thinking (please > correct me if I mangle up the terminology and/or totally are in the > wrong ballpark) that this is more or less because the label of the first > class is to an object (boolean with value False) > and the label of the second class does not cascade to the first label > for looking something up but instead during assignment sees that it is a > label to an object instead of the object itself thus copies the label > content instead? Pretty much. In the sense that you're thinking of, every assignment works that way, even the initial "TEST1 = One()". Assignment binds names to objects, though you have to be aware that names can be such exotic things as "t", "a[15]" or "TEST2.__instance_one.one" > I probably expected classes namespaces to behave in about the same way > as lists and dictionaries do, don't know where I picked that up. They do, in fact, which isn't terribly surprising considering that class namespaces are implemented with dictionaries. The distinction you're missing is that lists and dictionaries are mutable, while booleans aren't; you can change the contents of a dictionary, but you can't change the 'contents' of a boolean. -- Rhodri James *-* Wildebeeste Herder to the Masses From littlesweetmelon at gmail.com Thu Mar 25 21:45:44 2010 From: littlesweetmelon at gmail.com (=?GB2312?B?zPC5zw==?=) Date: Fri, 26 Mar 2010 09:45:44 +0800 Subject: Is there any library for indexing binary data? In-Reply-To: <4babb132$0$22945$e4fe514c@news.xs4all.nl> References: <4bab182a$0$22933$e4fe514c@news.xs4all.nl> <4babb132$0$22945$e4fe514c@news.xs4all.nl> Message-ID: Many thanks for your kind reply. As you mentioned, a sparse array may be the best choice. Storing offset rather than payload itself can greatly save memory space. 1e7 queries per second is my ideal aim. But 1e6 must be achieved. Currently I have implemented 5e6 on one PC (without incremental indexing and all incoming queries coming from local data stream). Since the table is very big and responding is time critical, the finally system will be definitely distributed computing. I hope that Judy algorithm can simplify indexing, so I can focus on implementing data persistence and distributed computing affairs. -- ShenLei ? 2010?3?26? ??2:55?Irmen de Jong ??? > On 25-3-2010 10:55, ?? wrote: >> Thank you irmen. I will take a look at pytable. >> FYI, let me explain the case clearly. >> >> Originally, my big data table is simply array of Item: >> struct Item >> { >> long id; // used as key >> BYTE payload[LEN]; // corresponding value with fixed length >> }; >> >> All items are stored in one file by using "stdio.h" function: >> fwrite(itemarray, sizeof(Item), num_of_items, fp); >> >> Note that "id" is randomly unique without any order. To speed up >> searching I regrouped / sorted them into two-level hash tables (in >> the form of files). I want to employ certain library to help me index >> this table. >> >> Since the table contains about 10^9 items and LEN is about 2KB, it is >> impossible to hold all data in memory. Furthermore, some new item may >> be inserted into the array. Therefore incremental indexing feature is >> needed. > > I see, I thought the payload data was small as well. What about this idea: > Build a hash table where the keys are the id from your Item structs and > the value is the file seek offset of the Item 'record' in your original > datafile. (although that might generate values of type long, which take > more memory than int, so maybe we should use file_offset/sizeof(Item). > This way you can just keep your original data file (you only have to > scan it to build the hash table) and you will avoid a lengthy conversion > process. > > If this hashtable still doesn't fit in memory use a sparse array > implementation of some sort that is more efficient at storing simple > integers, or just put it into a database solution mentioned in earlier > responses. > > Another thing: I think that your requirement of 1e7 lookups per second > is a bit steep for any solution where the dataset is not in core memory > at once though. > > Irmen. > -- > http://mail.python.org/mailman/listinfo/python-list > From ivlenin at gmail.com Thu Mar 25 21:53:04 2010 From: ivlenin at gmail.com (I V) Date: 26 Mar 2010 02:53:04 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <4bac1380$1@news.x-privat.org> On Thu, 25 Mar 2010 15:00:35 -0700, Michel wrote: > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods need > to be bound to the instance though, and that's my problem. Here is what > I have so far: I'm not entirely sure what you mean by binding methods to the instance. Do you mean you need to dynamically add methods to a specific instance? Or that you need to add methods to a class, such that they can be invoked on specific instances? For the latter, just do: TestClass.test_foo = test_foo For the former, try: tc = TestClass() tc.test_foo = types.MethodType(test_foo, tc) From martin.hellwig at dcuktec.org Thu Mar 25 21:56:38 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 26 Mar 2010 01:56:38 +0000 Subject: Don't understand behavior; instance form a class in another class' instance In-Reply-To: References: Message-ID: On 03/26/10 01:10, Rhodri James wrote: > > Pretty much. In the sense that you're thinking of, every assignment > works that way, even the initial "TEST1 = One()". Assignment binds names > to objects, though you have to be aware that names can be such exotic > things as "t", "a[15]" or "TEST2.__instance_one.one" > >> I probably expected classes namespaces to behave in about the same way >> as lists and dictionaries do, don't know where I picked that up. > > They do, in fact, which isn't terribly surprising considering that class > namespaces are implemented with dictionaries. The distinction you're > missing is that lists and dictionaries are mutable, while booleans > aren't; you can change the contents of a dictionary, but you can't > change the 'contents' of a boolean. > All makes sense now, thanks Rhodri & Christian. -- mph From nagle at animats.com Thu Mar 25 23:28:19 2010 From: nagle at animats.com (John Nagle) Date: Thu, 25 Mar 2010 20:28:19 -0700 Subject: Is there any library for indexing binary data? In-Reply-To: References: Message-ID: <4BAC29D3.6020503@animats.com> ?? wrote: > Well, Database is not proper because 1. the table is very big (~10^9 > rows) 2. we should support very fast *simple* query that is to get > value corresponding to single key (~10^7 queries / second). Ah, crypto rainbow tables. John Nagle From pmaupin at gmail.com Thu Mar 25 23:30:32 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 25 Mar 2010 20:30:32 -0700 (PDT) Subject: Revisiting Generators and Subgenerators References: <20100326002339.GA18453@cskk.homeip.net> Message-ID: <04e65930-889e-4eea-b12c-6bd21a11630a@z3g2000yqz.googlegroups.com> On Mar 25, 7:31?pm, Winston Wolff wrote: (a bunch of stuff about coroutines) There have been proposals in the past for more full-featured generators, that would work as general purpose coroutines. Among other things, there were issues with exception propagation, and the design was deliberately simplified to what we have today. Before proposing anything in this area you should carefully read PEPs 288, 325, and 342, and all the discussion about those PEPs in the python- dev archives. After reading all that, and still being convinced that you have the greatest thing since sliced bread (and that you REALLY understand all the concerns about exceptions and other things), you need to update your document to address all the concerns raised in the discussions on those PEPs, put on your asbestos suit (modern asbestos-free replacements never work as advertised), and then re-post your document. Personally, I am very interested in co-routines, but I have very little time right now, and am not at all interested in reading a proposal from somebody who doesn't know the full history of how generators got to be the way they are (the lack of coroutines is not an accidental oversight). I suspect I am not alone in this opinion, so there is probably some interest in a realistic proposal, but perhaps also some skepticism about whether a realistic proposal can actually be engineered... Best regards and good luck! Pat From steve at REMOVE-THIS-cybersource.com.au Fri Mar 26 00:20:45 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Mar 2010 04:20:45 GMT Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4bac361d$0$8840$c3e8da3@news.astraweb.com> On Thu, 25 Mar 2010 18:03:58 -0700, C. B. wrote: > Hi everyone, > > I'm currently coding a C library which provides several modules and > objects. > > Let's say that some of these objects are classes called AAA and BBB. The > constructor of AAA needs to get BBB as argument. > > So I can run the following code : > > from mymodule import AAA > from mymodule import BBB > > a = AAA(BBB())) > > But, as there is no case where AAA can be used without BBB, I would like > to avoid importing BBB in my Python scripts when I already import AAA. Since AAA must take an argument of BBB, then give it a default: # in mymodule def AAA(arg=BBB()): ... # in another module from mymodule import AAA a = AAA() Or do this: from mymodule import AAA, BBB a = AAA(BBB()) > For now, I think that reproducing the behavior of the __init__.py file > could be a good way to do this, but how can I code that using only the C > API ? What is the behaviour of the __init__.py file? -- Steven From stefan_ml at behnel.de Fri Mar 26 00:51:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Mar 2010 05:51:22 +0100 Subject: Revisiting Generators and Subgenerators In-Reply-To: <04e65930-889e-4eea-b12c-6bd21a11630a@z3g2000yqz.googlegroups.com> References: <20100326002339.GA18453@cskk.homeip.net> <04e65930-889e-4eea-b12c-6bd21a11630a@z3g2000yqz.googlegroups.com> Message-ID: Patrick Maupin, 26.03.2010 04:30: > ... and then re-post your document. ... preferably to the python-ideas mailing list. Although it seems to me that this is something that could be explored as a library first - which usually means that people will tell you exactly that on python-ideas and ask you to come back with an implementation that has proven to be useful in practice. Stefan From v.harishankar at gmail.com Fri Mar 26 02:37:24 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 12:07:24 +0530 Subject: Question regarding curses and text-input methods Message-ID: <20100326120724.33e8c2a6@gmail.com> I am trying to use Python curses.textpad to get (preferably UTF-8 but not needed) input from the user in a python curses application, but I realize that it is extremely limited and doesn't allow me to specify an existing text to edit. Also it doesn't seem to provide scrolling abilities on the window. Is this at all possible to get a large chunk of text using curses module like a GUI textbox or should I look at alternatives like newt? I prefer curses because it's simple and very flexible, but I am lost for ideas on this. Any ideas which doesn't involve throwing away the whole curses interface would be appreciated. -- V.Harishankar http://literaryforums.org http://harishankar.org From kushal.kumaran+python at gmail.com Fri Mar 26 03:40:26 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 26 Mar 2010 13:10:26 +0530 Subject: Improved timedelta attributes/methods In-Reply-To: References: Message-ID: <1e364c4e1003260040k1fe336d0lcf33577986f64075@mail.gmail.com> 2010/3/26 Christian ?tef?nescu : > Hello dear Python-wielding developers! > > I generally like date/time handling in Python very much, especially how date > operations result in Timedelta objects. But I find it somewhat impractical, > that you can only get days, seconds and microseconds out of a time delta. I > think it would be much more comfortable to have fields for minutes, hours, > maybe also years, months. Is there a specific reasoning why this is not > available? > > I would gladly do my best to implement such a solution, if it would make > sense to the devs. > You might want to check out mxDateTime[1]. It has a RelativeDateTime that seems to do what you like. [1] http://www.egenix.com/products/python/mxBase/mxDateTime/doc/ -- regards, kushal From nocbos at gmail.com Fri Mar 26 04:15:44 2010 From: nocbos at gmail.com (C. B.) Date: Fri, 26 Mar 2010 01:15:44 -0700 (PDT) Subject: Automatic import ? References: 4bac361d$0$8840$c3e8da3@news.astraweb.com Message-ID: > > What is the behaviour of the __init__.py file? > Not yet used, but I read this file is run by Python when a module of a package is imported. So you can insert default importations in it. From alfps at start.no Fri Mar 26 04:18:17 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Mar 2010 09:18:17 +0100 Subject: Traversing through Dir() In-Reply-To: References: Message-ID: * Andrej Mitrovic: > I would like to traverse through the entire structure of dir(), and > write it to a file. > > Now, if I try to write the contents of dir() to a file (via pickle), I > only get the top layer. So even if there are lists within the returned > list from dir(), they get written as a list of strings to the file. > > Basically, I have an embedded and somewhat stripped version of Python. > I would like to find out just how much functionality it has (I have no > documentation for it), so I thought the best way to do that is > traverse thru the dir() call. Any clues as to how I could write the > whole structure to a file? I guess I'll need some kind of recursion > here. :) The built-in dir() function just produces a sequence of strings. You can inspect the attributes via the getattr() function. The getattr() function produces a reference to an object (as does every expression). Problem: if you start with the number 42 and apply dir(), do getattr() on the first string, apply dir() on that object, and so on, with CPython you then get into an infinite recursion because those objects are produced on demand... obj = 42 obj_name = "42" for n in range( 12 ): where = id( obj ) t = type( obj ).__name__ print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) attribute_names = dir( obj ) obj_name = attribute_names[0] obj = getattr( obj, obj_name ) Similarly, if you do this with the Turtle module as starting point, with CPython you get into a different kind of infinite recursion because the chain of attributes so obtained is circular. import turtle obj = turtle obj_name = 'turtle' for n in range( 12 ): where = id( obj ) t = type( obj ).__name__ print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) attribute_names = dir( obj ) obj_name = attribute_names[0] obj = getattr( obj, obj_name ) It's not a clean, strict hierarchy of objects. However, the basic idea is sound when you only want to obtain some limited, known information, such as e.g. short descriptions of all string methods, or a listing of the standard exception hierarchy. for attribute_name in dir( str ): if attribute_name.startswith( "_" ): pass else: attribute = getattr( str, attribute_name ) doc_string = attribute.__doc__ doc_lines = doc_string.splitlines() if len( doc_lines ) > 2: essential_doc = doc_lines[2] else: essential_doc = doc_lines[0] print( attribute_name.ljust( 15 ) + essential_doc ) "Lists the standard exception class hierarchy with short descriptions." import builtins import inspect indentation = "." + 2*" " def is_type( o ): # Could use inspect.isclass for this, but in the DIY spirit: return isinstance( o, type ) def beginning_of( s, max_chars ): return s[:max_chars] # Not yet discussed, but doesn't matter. def print_hierarchy( h, level ): for o in h: if isinstance( o, tuple ): # o is a tuple describing a class cls = o[0] doc_lines = cls.__doc__.splitlines() short_doc = beginning_of( doc_lines[0], 55 ) print( "{:<34} {}".format( level*indentation + cls.__name__, short_doc ) ) else: # o is a list array of subclasses print_hierarchy( o, level + 1 ) classes = [] for name in dir( builtins ): o = getattr( builtins, name ) if is_type( o ): if issubclass( o, BaseException ): classes.append( o ) hierarchy = inspect.getclasstree( classes ) # 'hierarchy' is a list array of tuples and nested list arrays of the same form. # The top level is an array of two items, the first item a tuple describing the 'object' # class, and the second item a list array representing the BaseException hierarchy. print_hierarchy( hierarchy[1], level = 0 ) Cheers & hth., - Alf From michele.simionato at gmail.com Fri Mar 26 04:22:54 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Fri, 26 Mar 2010 01:22:54 -0700 (PDT) Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] References: mailman.1182.1269520510.23598.python-list@python.org <54e41616-df9f-42dd-9c91-9e530650bd99@j21g2000yqh.googlegroups.com> Message-ID: <9dd0d6b0-7249-4a6f-8d03-b0c3a44eace2@l25g2000yqd.googlegroups.com> On Mar 25, 2:24?pm, Michele Simionato wrote: > On Mar 25, 1:28?pm, Ethan Furman wrote: > > > > > Michele, > > > Was wondering if you'd had a chance to re-post your lectures -- just did > > a search for them and came up empty, and I would love to read them! > > > Many thanks in advance! > > Oops, I forgot! I will try to make them available soon. Here they are: http://www.phyast.pitt.edu/~micheles/oxford-lectures.zip From james.harris.1 at googlemail.com Fri Mar 26 05:49:53 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Fri, 26 Mar 2010 02:49:53 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> Message-ID: <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> On 25 Mar, 22:56, Jon Clements wrote: > On 25 Mar, 22:40, James Harris wrote: > > > I am looking to store named pieces of text in a form that can be > > edited by a standard editor such as notepad (under Windows) or vi > > (under Unix) and then pulled into Python as needed. The usual record > > locking and transactions of databases are not required. > > > Another way to look at it is to treat the separate files as entries in > > a dictionary. The file name would be the key and the lines of the file > > the value. > > > Anyone know of a database (with a Python interface) which will allow > > text files to be treated as database fields? If not I can just write > > it but I thought it best to ask if there was an existing solution > > first. ... > I could be missing something here, but aren't you basically just > talking about an OS's filesystem? For storage, yes. The files would be marked-up text stored in the filesystem. The "dbms" (I use the term loosely!) would provide access to them by some full or partial key mechanism yet to be determined. Read-only access would do - at least for now. > glob or listdir somewhere, then create a dict using the file contents > would meet your criteria, with very little lines of code -- but I > would be interested to know what the use-case was for this... Is it > read completely at start up time, or if each file contains a large > amount of lines and aren't fixed width (or has no other indexing > support without maintenance), then is a complete sequential-scan > required each time, or do you just tell the user to not update when > running (unless I s'pose something along the lines of a SIGHUP for > config files is applicable). All good questions. For now, at least, the files can be read-only and I'd want those on disk to be the master copies at all times. If I was writing it myself I'd probably 'cache' some files in memory and stat them before use. If newer I would reread the file. > > Sorry, just don't understand why you'd want this. I tried to avoid boring folks with the details. I'm toying with some ideas for a way to help generate source code (in various languages, not just Python). If it goes ahead the text files would be mainly marked-up code snippets - with or without symbols that need to be replaced. Rather than write one single monolithic app I thought to split it into reusable components. One part being data access could perhaps be an existing database (and I'll take a look at jkn's suggestion). Think of the database as similar to an associative array stored on disk. The only difference is I may want to play fast and loose with the keys in some ways - e.g. check for partial key matches or return a list of part-matched keys. The language name could be part of the key but I'd also need to store variants for specific language versions. I'm not sure yet how it will all pan out. As I say, just throwing around some ideas. James From almar.klein at gmail.com Fri Mar 26 05:52:51 2010 From: almar.klein at gmail.com (Almar Klein) Date: Fri, 26 Mar 2010 10:52:51 +0100 Subject: Python database of plain text editable by notepad or vi In-Reply-To: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> Message-ID: Hi, On 25 March 2010 23:40, James Harris wrote: > I am looking to store named pieces of text in a form that can be > edited by a standard editor such as notepad (under Windows) or vi > (under Unix) and then pulled into Python as needed. The usual record > locking and transactions of databases are not required. > I wrote a file format and parser for Python and Matlab that enables saving structured data in a human readable file. I use it to store all kinds of scientific data, but also for ini-like files for certain applications. Implementations and more information can be obtained here: http://code.google.com/p/ssdf/ It's not a database in the sense that you can query it, but it might be enough for your needs; it can store named pieces of (unicode) text. Cheers, Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Fri Mar 26 05:57:53 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 26 Mar 2010 10:57:53 +0100 Subject: sqlite version on windows Message-ID: <4BAC8521.2@shopzeus.com> Hi All, On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: 3.6.10 On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: 3.5.9 Why is that? I wrote a program that uses SAVEPOINT/ROLLBACK to. It is only available in SQLite 3.6.8 and above. Can I install it on Windows somehow? Thanks, Laszlo From v.harishankar at gmail.com Fri Mar 26 06:04:51 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 15:34:51 +0530 Subject: Python database of plain text editable by notepad or vi In-Reply-To: <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: <20100326153451.1fae9524@gmail.com> On Fri, 26 Mar 2010 02:49:53 -0700 (PDT) James Harris wrote: > On 25 Mar, 22:56, Jon Clements wrote: > > On 25 Mar, 22:40, James Harris > > wrote: > > > > > I am looking to store named pieces of text in a form that can be > > > edited by a standard editor such as notepad (under Windows) or vi > > > (under Unix) and then pulled into Python as needed. The usual > > > record locking and transactions of databases are not required. > > > > > Another way to look at it is to treat the separate files as > > > entries in a dictionary. The file name would be the key and the > > > lines of the file the value. > > > > > Anyone know of a database (with a Python interface) which will > > > allow text files to be treated as database fields? If not I can > > > just write it but I thought it best to ask if there was an > > > existing solution first. > ... > > I could be missing something here, but aren't you basically just > > talking about an OS's filesystem? > > For storage, yes. The files would be marked-up text stored in the > filesystem. The "dbms" (I use the term loosely!) would provide access > to them by some full or partial key mechanism yet to be determined. > Read-only access would do - at least for now. > > > glob or listdir somewhere, then create a dict using the file > > contents would meet your criteria, with very little lines of code > > -- but I would be interested to know what the use-case was for > > this... Is it read completely at start up time, or if each file > > contains a large amount of lines and aren't fixed width (or has no > > other indexing support without maintenance), then is a complete > > sequential-scan required each time, or do you just tell the user to > > not update when running (unless I s'pose something along the lines > > of a SIGHUP for config files is applicable). > > All good questions. For now, at least, the files can be read-only and > I'd want those on disk to be the master copies at all times. If I was > writing it myself I'd probably 'cache' some files in memory and stat > them before use. If newer I would reread the file. > > > > > Sorry, just don't understand why you'd want this. > > I tried to avoid boring folks with the details. I'm toying with some > ideas for a way to help generate source code (in various languages, > not just Python). If it goes ahead the text files would be mainly > marked-up code snippets - with or without symbols that need to be > replaced. > > Rather than write one single monolithic app I thought to split it into > reusable components. One part being data access could perhaps be an > existing database (and I'll take a look at jkn's suggestion). > > Think of the database as similar to an associative array stored on > disk. The only difference is I may want to play fast and loose with > the keys in some ways - e.g. check for partial key matches or return a > list of part-matched keys. The language name could be part of the key > but I'd also need to store variants for specific language versions. > I'm not sure yet how it will all pan out. As I say, just throwing > around some ideas. > > James I am not sure exactly what you need, but would you consider using something like ConfigParser module provided by Python? It appears to be something similar to what you need. -- V.Harishankar http://literaryforums.org http://harishankar.org From james.harris.1 at googlemail.com Fri Mar 26 06:12:57 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Fri, 26 Mar 2010 03:12:57 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: mailman.1210.1269597926.23598.python-list@python.org Message-ID: On 26 Mar, 10:04, Harishankar wrote: ... > > Think of the database as similar to an associative array stored on > > disk. The only difference is I may want to play fast and loose with > > the keys in some ways - e.g. check for partial key matches or return a > > list of part-matched keys. The language name could be part of the key > > but I'd also need to store variants for specific language versions. > > I'm not sure yet how it will all pan out. As I say, just throwing > > around some ideas. ... > I am not sure exactly what you need, but would you consider using > something like ConfigParser module provided by Python? It appears to be > something similar to what you need. Thanks, I'll take a look at it. James From gandalf at shopzeus.com Fri Mar 26 07:11:26 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 26 Mar 2010 12:11:26 +0100 Subject: sqlite version on windows In-Reply-To: <4BAC8521.2@shopzeus.com> References: <4BAC8521.2@shopzeus.com> Message-ID: <4BAC965E.70302@shopzeus.com> 2010.03.26. 10:57 keltez?ssel, Laszlo Nagy ?rta: > > Hi All, > > On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: 3.6.10 > On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: 3.5.9 > > Why is that? I wrote a program that uses SAVEPOINT/ROLLBACK to. It is > only available in SQLite 3.6.8 and above. Can I install it on Windows > somehow? Hmm. Looks like I only needed to download a new sqlite3.dll file and put it into Python26\DLLs Why it is not included in the standard distribution? The default installed version 3.5.9 is quite old. Is there a special reason for that? Or do you think that I can post a patch? Thanks, Laszlo From ovidiudeac at gmail.com Fri Mar 26 07:14:01 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 13:14:01 +0200 Subject: Automatic import ? In-Reply-To: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <804cd4021003260414t5c5b7482vf315a2e596d3916c@mail.gmail.com> > But, as there is no case where AAA can be used without BBB, I would > like to avoid importing BBB in my Python scripts when I already import > AAA. Then why do you need to explicitely pass BBB() to AAA constructor? You could leave AAA constructor with no parameters or with a parameter with a default BBB() value From steve at holdenweb.com Fri Mar 26 07:49:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Mar 2010 07:49:25 -0400 Subject: Revisiting Generators and Subgenerators In-Reply-To: References: Message-ID: Winston wrote: [...] > This new syntax for a generator will break all existing > programs. But we happen to be at the start of Python 3K where > new paradaigms are > being examined. However good your idea may be, I suspect this one sentence will kill it. We are no longer "at the start of Py3k", we are moving towards the third release, and there is already a substantial body of code and literature embodying the current syntax. So you would need to reformulate your proposals to incorporate backward compatibility. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Fri Mar 26 08:35:58 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 13:35:58 +0100 Subject: Automatic import ? In-Reply-To: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4BACAA2E.6010402@sequans.com> C. B. wrote: > Hi everyone, > > I'm currently coding a C library which provides several modules and > objects. > > Let's say that some of these objects are classes called AAA and BBB. > The constructor of AAA needs to get BBB as argument. > > So I can run the following code : > > from mymodule import AAA > from mymodule import BBB > > a = AAA(BBB())) > > But, as there is no case where AAA can be used without BBB, I would > like to avoid importing BBB in my Python scripts when I already import > AAA. > > For now, I think that reproducing the behavior of the __init__.py file > could be a good way to do this, but how can I code that using only the > C API ? > > Are there any other solutions ? Is this kind of importation a good > idea ? > > Greetings, > Cyrille Bagard > Make AAA do the call to BBB: def AAA(*args, **kwargs): param = BBB(*args, **kwargs) # more code from mymodule import AAA AAA(1,2,3) # list of parameters you would have used with BBB. Saying that, is there any strong reason (meaning design issue) why you don't want to import explicitly BBB ? Because if the reason is 'It takes too much time', then it's a bad reason. Cheers, JM From philip at semanchuk.com Fri Mar 26 08:57:47 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 26 Mar 2010 08:57:47 -0400 Subject: sqlite version on windows In-Reply-To: <4BAC8521.2@shopzeus.com> References: <4BAC8521.2@shopzeus.com> Message-ID: On Mar 26, 2010, at 5:57 AM, Laszlo Nagy wrote: > > Hi All, > > On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: > 3.6.10 > On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: > 3.5.9 > > Why is that? I wrote a program that uses SAVEPOINT/ROLLBACK to. It > is only available in SQLite 3.6.8 and above. Can I install it on > Windows somehow? I did a little research on this for Python 2.5. What I found is that The Python distributions for Windows from python.org are conservative with their SQLite version. For instance, Python 2.5.0 and 2.5.4 ship with the exact same SQLite version (3.3.4, from February 2006). Our application dependencies state a minimum Python of 2.5. We have to work with the lowest common denominator (2.5.0), so we can't use any SQLite features that showed up after 3.3.4. The few Linux distros that I checked are much more aggressive about bundling newer versions of SQLite. For instance, Ubuntu 8.04 has Python 2.5.2 with SQLite 3.4.2, while Ubuntu 8.10 has the same version of Python but offers SQLite 3.5.9. You asked "why" and I don't know. I imagine it comes down to philosophical differences or maybe just a lack of time to test when building new WIndows distros for Python.org. bye Philip From luismgz at gmail.com Fri Mar 26 09:14:49 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 26 Mar 2010 06:14:49 -0700 (PDT) Subject: OT: Meaning of "monkey" Message-ID: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... Monkeys everywhere. Sorry for the off topic question, but what does "monkey" mean in a nerdy-geek context?? Luis From v.harishankar at gmail.com Fri Mar 26 09:23:25 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 13:23:25 +0000 (UTC) Subject: Have you embraced Python 3.x yet? Message-ID: Have you people embraced Python 3.x or still with 2.5 or 2.6? I personally want to switch over but not too sure how many people are using 3.x as opposed to 2 so I want to keep my programs compatible for the majority. -- Hari From kushal.kumaran+python at gmail.com Fri Mar 26 09:25:41 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 26 Mar 2010 18:55:41 +0530 Subject: OT: Meaning of "monkey" In-Reply-To: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <1e364c4e1003260625u4e747b23g566b0082cb24b6b6@mail.gmail.com> 2010/3/26 Luis M. Gonz?lez : > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? > These might help you get the gist: http://www.catb.org/~esr/jargon/html/C/code-monkey.html http://www.catb.org/~esr/jargon/html/T/tape-monkey.html -- regards, kushal From mehgcap at gmail.com Fri Mar 26 09:29:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Fri, 26 Mar 2010 09:29:05 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: Because of compatibility, and many modules being built for 2.6 only, I am still on 2.6.4 (updating to .5 soon). On 3/26/10, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many people are > using 3.x as opposed to 2 so I want to keep my programs compatible for > the majority. > > -- Hari > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From neilc at norwich.edu Fri Mar 26 09:34:35 2010 From: neilc at norwich.edu (Neil Cerutti) Date: 26 Mar 2010 13:34:35 GMT Subject: Have you embraced Python 3.x yet? References: Message-ID: <813rfbFi0kU1@mid.individual.net> On 2010-03-26, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many > people are using 3.x as opposed to 2 so I want to keep my > programs compatible for the majority. I switched 6 months ago, or so. My library needs are met by what's in CPython, so I couldn't see, at the time, a good reason to sit still. My programs didn't take much effort to convert. They are nearly all data conversion programs. Microsoft rendering the one outside module I did use, an Excel reader, obsolete caused me a lot more trouble than switching from 2.5 to 3.1. Past advice in this forum has been that as long as you don't depend on libraries that don't yet support Python 3, you can probably switch over and not need to look back. -- Neil Cerutti From anand.shashwat at gmail.com Fri Mar 26 09:35:54 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 19:05:54 +0530 Subject: OT: Meaning of "monkey" In-Reply-To: <1e364c4e1003260625u4e747b23g566b0082cb24b6b6@mail.gmail.com> References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <1e364c4e1003260625u4e747b23g566b0082cb24b6b6@mail.gmail.com> Message-ID: evolved monkey = human (can relate codemonkey to it) 2010/3/26 Kushal Kumaran > > 2010/3/26 Luis M. Gonz?lez : > > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > > > Monkeys everywhere. > > Sorry for the off topic question, but what does "monkey" mean in a > > nerdy-geek context?? > > > > These might help you get the gist: > > http://www.catb.org/~esr/jargon/html/C/code-monkey.html > http://www.catb.org/~esr/jargon/html/T/tape-monkey.html > > -- > regards, > kushal > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Fri Mar 26 09:37:13 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 19:07:13 +0530 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: 2.6.x is what most applications rely on. It is still too early for python 3 On Fri, Mar 26, 2010 at 6:59 PM, Alex Hall wrote: > Because of compatibility, and many modules being built for 2.6 only, I > am still on 2.6.4 (updating to .5 soon). > > On 3/26/10, Harishankar wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > > > I personally want to switch over but not too sure how many people are > > using 3.x as opposed to 2 so I want to keep my programs compatible for > > the majority. > > > > -- Hari > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Have a great day, > Alex (msg sent from GMail website) > mehgcap at gmail.com; http://www.facebook.com/mehgcap > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Fri Mar 26 09:37:13 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 26 Mar 2010 19:07:13 +0530 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: 2.6.x is what most applications rely on. It is still too early for python 3 On Fri, Mar 26, 2010 at 6:59 PM, Alex Hall wrote: > Because of compatibility, and many modules being built for 2.6 only, I > am still on 2.6.4 (updating to .5 soon). > > On 3/26/10, Harishankar wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > > > I personally want to switch over but not too sure how many people are > > using 3.x as opposed to 2 so I want to keep my programs compatible for > > the majority. > > > > -- Hari > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Have a great day, > Alex (msg sent from GMail website) > mehgcap at gmail.com; http://www.facebook.com/mehgcap > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Mar 26 09:53:26 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 14:53:26 +0100 Subject: python logging writes an empty file In-Reply-To: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> Message-ID: <4BACBC56.1020105@sequans.com> Ovidiu Deac wrote: > Then I tried this: > file = logging.FileHandler(logFileBasename, 'w') > file.setLevel(logging.INFO) > # set a format which is simpler for console use > formatter = logging.Formatter('%(asctime)s %(name)-12s > %(levelname)-8s %(message)s',) > # tell the handler to use this format > file.setFormatter(formatter) > # add the handler to the root logger > logging.getLogger('').addHandler(file) > logging.getLogger('') > > ...which also leaves my output file EMPTY. > > I'm out of ideas. Can anybody help me with this? > > Thanks in advance! > ovidiu > You set le level of your handler, but did not set the level of the logger itself. Replace file.setLevel(logging.INFO) by logging.getLogger().setLevel(logging.INFO) Log events are matched versus the logger level 1st, then the handler level (if applicable). Most of the time you don't need to tune your handler levels. JM From incensedprey at gmail.com Fri Mar 26 10:05:52 2010 From: incensedprey at gmail.com (Kevin Adams) Date: Fri, 26 Mar 2010 07:05:52 -0700 (PDT) Subject: [python3] References: Message-ID: On Mar 19, 3:02?pm, Terry Reedy wrote: > On 3/19/2010 2:17 PM, Steve Holden wrote: > > > > > Kevin Adams wrote: > >> Greetings! > > >> Please forgive me if im posting this to the wrong group. > > >> I'm new to Python, learning Python3 from the O'rielly "Learning > >> Python" book. ?Reading > >> about operator overloading, specifically __getitem__. ? I put together > >> a small bit of code to > >> do some experimenting and threw in a timer so i can see it do its > >> thing. ?For some reason > >> the time.sleep(x) function doesnt work when my print function includes > >> "end=''". > > >> Thanks in advance for any help. > > > Try the following changes: > > >> ---code--- > > >> class TestClass(): > >> ? ? ?def __init__(self): > >> ? ? ? ? ?self.data = "I was far from home and the spell of the eastern > >> sea was upon me." > > >> ? ? ?def __getitem__(self,i): > >> ? ? ? ? ?return self.data[i] > > >> import time > > > import sys > > >> if __name__ == "__main__": > > >> ? ? ?me = TestClass() > >> ? ? ?for x in me: > >> ? ? ? ? ?print(x,end='') ?#if i remove the 'end=''' ?it performs as i'd > >> expect > > ? ? ? ? ? ?sys.stdout.flush() > > >> ? ? ? ? ?time.sleep(int(2)) > > > It may just be that the output is being held in buffers until the > > program terminates. the fluch() methof pushes it straight out. > > The IDLE Shell window must get print output back from the pythonw > process without buffering. When I cut and pasted from IDLE editor to > standard interpreter window, output was bunched after several seconds. > OP should have started with short string and minimal delay so output > would not take a whole minute. Flushing fixed problem in standard > interpreter. I will have to remember that testing partial line output in > IDLE does not show how it will act elsewhere. > > Kevin: when reporting a problem, be more specific as to what 'does not > work' means. > > Terry Jan Reedy Terry: Will definately try to be more informative next time. Thanks again. K From andrej.mitrovich at gmail.com Fri Mar 26 10:16:47 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Fri, 26 Mar 2010 07:16:47 -0700 (PDT) Subject: Traversing through Dir() References: Message-ID: On Mar 26, 9:18?am, "Alf P. Steinbach" wrote: > * Andrej Mitrovic: > > > I would like to traverse through the entire structure of dir(), and > > write it to a file. > > > Now, if I try to write the contents of dir() to a file (via pickle), I > > only get the top layer. So even if there are lists within the returned > > list from dir(), they get written as a list of strings to the file. > > > Basically, I have an embedded and somewhat stripped version of Python. > > I would like to find out just how much functionality it has (I have no > > documentation for it), so I thought the best way to do that is > > traverse thru the dir() call. Any clues as to how I could write the > > whole structure to a file? I guess I'll need some kind of recursion > > here. :) > > The built-in dir() function just produces a sequence of strings. > > You can inspect the attributes via the getattr() function. The getattr() > function produces a reference to an object (as does every expression). Problem: > if you start with the number 42 and apply dir(), do getattr() on the first > string, apply dir() on that object, and so on, with CPython you then get into an > infinite recursion because those objects are produced on demand... > > > obj = 42 > obj_name = "42" > for n in range( 12 ): > ? ? ?where = id( obj ) > ? ? ?t = type( obj ).__name__ > ? ? ?print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) > ? ? ?attribute_names = dir( obj ) > ? ? ?obj_name = attribute_names[0] > ? ? ?obj = getattr( obj, obj_name ) > > > Similarly, if you do this with the Turtle module as starting point, with CPython > you get into a different kind of infinite recursion because the chain of > attributes so obtained is circular. > > > import turtle > > obj = turtle > obj_name = 'turtle' > for n in range( 12 ): > ? ? ?where = id( obj ) > ? ? ?t = type( obj ).__name__ > ? ? ?print( "{:>2} {:>10} {:20} of type '{}'".format( n, where, obj_name, t ) ) > ? ? ?attribute_names = dir( obj ) > ? ? ?obj_name = attribute_names[0] > ? ? ?obj = getattr( obj, obj_name ) > > > It's not a clean, strict hierarchy of objects. > > However, the basic idea is sound when you only want to obtain some limited, > known information, such as e.g. short descriptions of all string methods, or a > listing of the standard exception hierarchy. > > > for attribute_name in dir( str ): > ? ? ?if attribute_name.startswith( "_" ): > ? ? ? ? ?pass > ? ? ?else: > ? ? ? ? ?attribute = getattr( str, attribute_name ) > ? ? ? ? ?doc_string = attribute.__doc__ > ? ? ? ? ?doc_lines = doc_string.splitlines() > ? ? ? ? ?if len( doc_lines ) > 2: > ? ? ? ? ? ? ?essential_doc = doc_lines[2] > ? ? ? ? ?else: > ? ? ? ? ? ? ?essential_doc = doc_lines[0] > ? ? ? ? ?print( attribute_name.ljust( 15 ) + essential_doc ) > > > > "Lists the standard exception class hierarchy with short descriptions." > import builtins > import inspect > > indentation ? ? = "." + 2*" " > > def is_type( o ): > ? ? ?# Could use inspect.isclass for this, but in the DIY spirit: > ? ? ?return isinstance( o, type ) > > def beginning_of( s, max_chars ): > ? ? ?return s[:max_chars] ? ?# Not yet discussed, but doesn't matter. > > def print_hierarchy( h, level ): > ? ? ?for o in h: > ? ? ? ? ?if isinstance( o, tuple ): > ? ? ? ? ? ? ?# o is a tuple describing a class > ? ? ? ? ? ? ?cls = o[0] > ? ? ? ? ? ? ?doc_lines = cls.__doc__.splitlines() > ? ? ? ? ? ? ?short_doc = beginning_of( doc_lines[0], 55 ) > ? ? ? ? ? ? ?print( "{:<34} {}".format( > ? ? ? ? ? ? ? ? ?level*indentation + cls.__name__, short_doc > ? ? ? ? ? ? ? ? ?) ) > ? ? ? ? ?else: > ? ? ? ? ? ? ?# o is a list array of subclasses > ? ? ? ? ? ? ?print_hierarchy( o, level + 1 ) > > classes = [] > for name in dir( builtins ): > ? ? ?o = getattr( builtins, name ) > ? ? ?if is_type( o ): > ? ? ? ? ?if issubclass( o, BaseException ): > ? ? ? ? ? ? ?classes.append( o ) > > hierarchy = inspect.getclasstree( classes ) > # 'hierarchy' is a list array of tuples and nested list arrays of the same form. > # The top level is an array of two items, the first item a tuple describing the > 'object' > # class, and the second item a list array representing the BaseException hierarchy. > print_hierarchy( hierarchy[1], level = 0 ) > > > Cheers & hth., > > - Alf Thanks for all of that. And yes, I've noticed I get into infinite recursions all the time, which is why I was asking if there was a simple way to do this. I'll have a look at these later. Kind regards, Andrej Mitrovic From andrej.mitrovich at gmail.com Fri Mar 26 10:22:40 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Fri, 26 Mar 2010 07:22:40 -0700 (PDT) Subject: Have you embraced Python 3.x yet? References: Message-ID: I use both, really. I started by learning and using Python 3, but I ended up using Python 2 much more often compared to Py3. Not because of the functionality of the language, but because most software that embeds Python or is extendable in some way is usually using Python 2. + There's the whole libraries issue (or the lack of them). But I have to say, Python 3 is a sexy language, I can't wait for more libraries to appear so I could focus more of my attention there. From kw at codebykevin.com Fri Mar 26 10:28:12 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Fri, 26 Mar 2010 10:28:12 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: <5dda4$4bacc47c$4275d90a$1703@FUSE.NET> On 3/26/10 9:23 AM, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many people are > using 3.x as opposed to 2 so I want to keep my programs compatible for > the majority. > > -- Hari Not yet. Some key libraries I am using for apps under development haven't been ported to support 3.x yet (feedparser, pycrypto). -- Kevin Walzer Code by Kevin http://www.codebykevin.com From ovidiudeac at gmail.com Fri Mar 26 10:29:43 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 16:29:43 +0200 Subject: python logging writes an empty file In-Reply-To: <4BACBC56.1020105@sequans.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> Message-ID: <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> > You set le level of your handler, but did not set the level of the logger > itself. > Replace file.setLevel(logging.INFO) by > logging.getLogger().setLevel(logging.INFO) > > Log events are matched versus the logger level 1st, then the handler level > (if applicable). Most of the time you don't need to tune your handler > levels. Right. Thanks a lot!!! Now for the second part, any idea why logging.config.fileConfig doesn't work? Now the logging.conf looks like this: [formatters] keys: detailed [handlers] keys: console,file [loggers] keys: root [formatter_detailed] format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s [handler_console] class: StreamHandler args: [] formatter: detailed [handler_file] class=FileHandler formatter=detailed args=('output.log', 'w') filename=output.log mode=w [logger_root] level: INFO handlers: file From seb.binet at gmail.com Fri Mar 26 10:29:57 2010 From: seb.binet at gmail.com (Sebastien Binet) Date: Fri, 26 Mar 2010 07:29:57 -0700 (PDT) Subject: Revisiting Generators and Subgenerators References: Message-ID: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> On Mar 25, 10:39?pm, Winston wrote: > Here's my proposal again, but hopefully with better formatting so you > can read it easier. > > -Winston > ----------------- > > Proposal for a new Generator Syntax in Python 3K-- > A Baton object for generators to allow subfunction to yield, and to > make > them symetric. isn't a Baton what CSP calls a channel ? there is this interesting PyCSP library (which implements channels over greenlets, os-processes (via multiprocessing) or python threads) http://code.google.com/p/pycsp cheers, sebastien. From gnarlodious at gmail.com Fri Mar 26 10:30:47 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Fri, 26 Mar 2010 07:30:47 -0700 (PDT) Subject: Have you embraced Python 3.x yet? References: Message-ID: I have been using Py3 since October, I switched over for the OrderedDict feature. Some parts are a little hard to get used to, but others are easier. I am doing web programming, so the UTF 8 default is a big improvement. -- Gnarlie From showell30 at yahoo.com Fri Mar 26 10:31:17 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 26 Mar 2010 07:31:17 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> Message-ID: <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> On Mar 24, 4:19?pm, Paul Rubin wrote: > kj writes: > > Is there a sequence-oriented equivalent to the sum built-in? ?E.g.: > > ? seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > use itertools.chain for this. ?A few people have mentioned that sum will > also work, but I think for that purpose it could have O(n**2) > complexity. I agree on the practical matter that itertools.chain and other solutions are usually the way to go for most tasks that involve iterating through several lists. >From a purely academic standpoint, I'm not convinced that sum() is inefficient in terms of big-O complexity, though. showell at showell-laptop:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 >>> class StupidList: ... def __init__(self, lst): ... print 'creating', lst ... self.lst = lst ... def __add__(self, other): ... self.lst += '|' ... self.lst.extend(other.lst) ... return self ... >>> result = sum([StupidList([1, 2]), StupidList([3,4]), StupidList([5,6])], StupidList([0])) creating [1, 2] creating [3, 4] creating [5, 6] creating [0] >>> result.lst [0, '|', 1, 2, '|', 3, 4, '|', 5, 6] If I'm interpreting the above program correctly, then sum() is doing the most efficient thing under the hood--it appears to do the equivalent of += without creating unnecessary objects for intermediate sums. I think the special-case error message might be a case where practicality simply beats out purity. It would be nice if sum() were completely duck-typed-let-you-shoot-yourself-in-foot-if-you-know-what- you-are-doing, but maybe this was such a pitfall at one time, that extra safeguards were put into sum(). I wonder how severely sum(), without the restriction, would underperform join() on modern versions of Python, though. >>> sum('1', '2') Traceback (most recent call last): File "", line 1, in TypeError: sum() can't sum strings [use ''.join(seq) instead] Note that you can easily fake out sum() to get duck typing. >>> class EmptyStringStarter: ... def __add__(self, other): return other ... >>> empty = EmptyStringStarter() >>> sum(['hello ', 'world'], empty) 'hello world' From no.email at please.post Fri Mar 26 10:49:02 2010 From: no.email at please.post (kj) Date: Fri, 26 Mar 2010 14:49:02 +0000 (UTC) Subject: Classes as namespaces? Message-ID: What's the word on using "classes as namespaces"? E.g. class _cfg(object): spam = 1 jambon = 3 huevos = 2 breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Granted, this is not the "intended use" for classes, and therefore could be viewed as a misuse ("that's what dictionaries are for", etc.). But other than this somewhat academic objection[*], I really can see no problem with using classes in this way. And yet, I've come across online murky warnings against using classes as "pseudo-namespaces". Is there some problem that I'm not seeing with this technique? ~K [*] My own subjective dislike for the widespread practice of using triple quotes to comment out code is formally similar to this one ("the 'intended use' for triple-quoting is not to comment out code", etc.). Here I find myself on the opposite side of the purist/pragmatic divide. Hmmm. From showell30 at yahoo.com Fri Mar 26 10:56:48 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 26 Mar 2010 07:56:48 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> Message-ID: On Mar 26, 7:31?am, Steve Howell wrote: > On Mar 24, 4:19?pm, Paul Rubin wrote: > > > kj writes: > > > Is there a sequence-oriented equivalent to the sum built-in? ?E.g.: > > > ? seq_sum(((1, 2), (5, 6))) --> (1, 2) + (5, 6) --> (1, 2, 5, 6) > > > use itertools.chain for this. ?A few people have mentioned that sum will > > also work, but I think for that purpose it could have O(n**2) > > complexity. > > I agree on the practical matter that itertools.chain and other > solutions are usually the way to go for most tasks that involve > iterating through several lists. > > From a purely academic standpoint, I'm not convinced that sum() is > inefficient in terms of big-O complexity, though. > > ?showell at showell-laptop:~$ python > ?Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > ?[GCC 4.3.3] on linux2 > ?>>> class StupidList: > ?... ? def __init__(self, lst): > ?... ? ? print 'creating', lst > ?... ? ? self.lst = lst > ?... ? def __add__(self, other): > ?... ? ? self.lst += '|' > ?... ? ? self.lst.extend(other.lst) > ?... ? ? return self > ?... > ?>>> result = sum([StupidList([1, 2]), StupidList([3,4]), > StupidList([5,6])], StupidList([0])) > ?creating [1, 2] > ?creating [3, 4] > ?creating [5, 6] > ?creating [0] > ?>>> result.lst > ?[0, '|', 1, 2, '|', 3, 4, '|', 5, 6] > > If I'm interpreting the above program correctly, then sum() is doing > the most efficient thing under the hood--it appears to do the > equivalent of += without creating unnecessary objects for intermediate > sums. > > I think the special-case error message might be a case where > practicality simply beats out purity. ?It would be nice if sum() were > completely duck-typed-let-you-shoot-yourself-in-foot-if-you-know-what- > you-are-doing, but maybe this was such a pitfall at one time, that > extra safeguards were put into sum(). ?I wonder how severely sum(), > without the restriction, would underperform join() on modern versions > of Python, though. > > ?>>> sum('1', '2') > ?Traceback (most recent call last): > ? ?File "", line 1, in > ?TypeError: sum() can't sum strings [use ''.join(seq) instead] > > Note that you can easily fake out sum() to get duck typing. > > ?>>> class EmptyStringStarter: > ?... ? def __add__(self, other): return other > ?... > ?>>> empty = EmptyStringStarter() > ?>>> sum(['hello ', 'world'], empty) > ?'hello world' Looking at the code answers my own questions: http://svn.python.org/view/python/trunk/Python/bltinmodule.c?view=markup Look for builtin_sum(). First you see the guard against strings: /* reject string values for 'start' parameter */ if (PyObject_TypeCheck(result, &PyBaseString_Type)) { PyErr_SetString(PyExc_TypeError, "sum() can't sum strings [use ''.join(seq) instead]"); Py_DECREF(iter); return NULL; } Py_INCREF(result); Also, Paul's suspicion that sum() works in O(N squared) for lists is confirmed by this comment: /* It's tempting to use PyNumber_InPlaceAdd instead of PyNumber_Add here, to avoid quadratic running time when doing 'sum(list_of_lists, [])'. However, this would produce a change in behaviour: a snippet like empty = [] sum([[x] for x in range(10)], empty) would change the value of empty. */ It's interesting, though, that you can construct classes pretty easily, as I did above, that avoid the quadratic behavior, as long as you do not mind mutating the start value, which I think is usually fine, since the original start value usually is not useful afterward anyway. From robert.kern at gmail.com Fri Mar 26 10:56:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Mar 2010 09:56:52 -0500 Subject: OT: Meaning of "monkey" In-Reply-To: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 2010-03-26 08:14 AM, Luis M. Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? Partly because "monkey" is just a funny word. As for monkey-patching, it came from the Zope community: http://en.wikipedia.org/wiki/Monkey_patching -- 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 From joncle at googlemail.com Fri Mar 26 10:58:52 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Mar 2010 07:58:52 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: On 26 Mar, 09:49, James Harris wrote: > On 25 Mar, 22:56, Jon Clements wrote: > > > > > On 25 Mar, 22:40, James Harris wrote: > > > > I am looking to store named pieces of text in a form that can be > > > edited by a standard editor such as notepad (under Windows) or vi > > > (under Unix) and then pulled into Python as needed. The usual record > > > locking and transactions of databases are not required. > > > > Another way to look at it is to treat the separate files as entries in > > > a dictionary. The file name would be the key and the lines of the file > > > the value. > > > > Anyone know of a database (with a Python interface) which will allow > > > text files to be treated as database fields? If not I can just write > > > it but I thought it best to ask if there was an existing solution > > > first. > ... > > I could be missing something here, but aren't you basically just > > talking about an OS's filesystem? > > For storage, yes. The files would be marked-up text stored in the > filesystem. The "dbms" (I use the term loosely!) would provide access > to them by some full or partial key mechanism yet to be determined. > Read-only access would do - at least for now. > > > glob or listdir somewhere, then create a dict using the file contents > > would meet your criteria, with very little lines of code -- but I > > would be interested to know what the use-case was for this... Is it > > read completely at start up time, or if each file contains a large > > amount of lines and aren't fixed width (or has no other indexing > > support without maintenance), then is a complete sequential-scan > > required each time, or do you just tell the user to not update when > > running (unless I s'pose something along the lines of a SIGHUP for > > config files is applicable). > > All good questions. For now, at least, the files can be read-only and > I'd want those on disk to be the master copies at all times. If I was > writing it myself I'd probably 'cache' some files in memory and stat > them before use. If newer I would reread the file. > It's hard to bore this group :) > > > > Sorry, just don't understand why you'd want this. > > I tried to avoid boring folks with the details. I'm toying with some > ideas for a way to help generate source code (in various languages, > not just Python). If it goes ahead the text files would be mainly > marked-up code snippets - with or without symbols that need to be > replaced. > > Rather than write one single monolithic app I thought to split it into > reusable components. One part being data access could perhaps be an > existing database (and I'll take a look at jkn's suggestion). > > Think of the database as similar to an associative array stored on > disk. The only difference is I may want to play fast and loose with > the keys in some ways - e.g. check for partial key matches or return a > list of part-matched keys. The language name could be part of the key > but I'd also need to store variants for specific language versions. > I'm not sure yet how it will all pan out. As I say, just throwing > around some ideas. > > James Thanks for the explanation. Who admins and, who's editing this data? I couldn't 100% guarantee that I could modify a text file and always put the right delimiter in the right place and remember to escape the relevant chars (and I'm probably not the 'average' user). Any opposition to just putting it in a 'proper' DB, then 'blobbing' the values? (or just integrate a procedure/script/function whatever your chosen RDBMS calls to choose it). Or in some systems, 'externally referencing'... loads of DB's have free front-ends, and there are lots of Python libraries. I think perhaps, all I'm saying is, I'd choose a different approach. I'd provide a front-end, rather than choose to re-write the wheel over DB's. Be nice to know how you get on, if you'd be so kind? Cheers, Jon. From michel.metzger at gmail.com Fri Mar 26 11:00:57 2010 From: michel.metzger at gmail.com (Michel) Date: Fri, 26 Mar 2010 08:00:57 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <3479ec6a-fe04-4088-83e9-e3ef60a8152e@k4g2000prh.googlegroups.com> Well, I don't have the reference to the instance. The class is actually instantiated later by a the unittest library. On Mar 25, 6:18?pm, Michiel Overtoom wrote: > On 2010-03-25 23:00, Michel wrote: > > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods to it and later instantiate this class. Methods > > need to be bound to the instance though, and that's my problem. > > Maybe this snippet is of any help? > > import functools > > class Template(object): > ? ? ?pass > > def printmyname(self): > ? ? ?print self.name > > t=Template() > t.name="Pete" > t.printmyname=functools.partial(printmyname,t) > > u=Template() > u.name="Mary" > u.printmyname=functools.partial(printmyname,u) > > t.printmyname() > u.printmyname() > > Greetings, > > -- > "The ability of the OSS process to collect and harness > the collective IQ of thousands of individuals across > the Internet is simply amazing." - Vinod Valloppillilhttp://www.catb.org/~esr/halloween/halloween4.html From v.harishankar at gmail.com Fri Mar 26 11:04:13 2010 From: v.harishankar at gmail.com (Harishankar) Date: Fri, 26 Mar 2010 15:04:13 +0000 (UTC) Subject: Classes as namespaces? References: Message-ID: On Fri, 26 Mar 2010 14:49:02 +0000, kj wrote: > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore could > be viewed as a misuse ("that's what dictionaries are for", etc.). But > other than this somewhat academic objection[*], I really can see no > problem with using classes in this way. > > And yet, I've come across online murky warnings against using classes as > "pseudo-namespaces". Is there some problem that I'm not seeing with > this technique? > > ~K > > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one ("the > 'intended use' for triple-quoting is not to comment out code", etc.). > Here I find myself on the opposite side of the purist/pragmatic divide. > Hmmm. I myself am a humble beginner in many ways, but generally isn't that (namespacing) achieved by using modules? I don't find the need generally to assign namespace to local variables and when there is a need for it, module level objects do the job. From philip at semanchuk.com Fri Mar 26 11:08:35 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 26 Mar 2010 11:08:35 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <8651EEFD-64CC-4488-B981-F247C4F75BA6@semanchuk.com> On Mar 26, 2010, at 10:49 AM, kj wrote: > > > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". Is there some problem that I'm > not seeing with this technique? I hope it's not problematic; I use it all the time. A few differences about the way I do it: - I respect PEP 8 for the class name (CamelCaps) - If the attributes are supposed to be constants, I capitalize the attributes - I often add NONE with a value of zero so that bool(MyClass.NONE) will evaluate to False and everything else will be True Here's an example from my code: class Apodization(object): """ Apodization constants """ # These constants are arbitrary and may change. # However bool(NONE) is guaranteed to be False NONE = 0 GAUSSIAN = 1 LORENTZIAN = 2 Cheers Philip From jeanmichel at sequans.com Fri Mar 26 11:44:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 16:44:39 +0100 Subject: python logging writes an empty file In-Reply-To: <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> Message-ID: <4BACD667.7020803@sequans.com> Ovidiu Deac wrote: >> You set le level of your handler, but did not set the level of the logger >> itself. >> Replace file.setLevel(logging.INFO) by >> logging.getLogger().setLevel(logging.INFO) >> >> Log events are matched versus the logger level 1st, then the handler level >> (if applicable). Most of the time you don't need to tune your handler >> levels. >> > > Right. Thanks a lot!!! > > Now for the second part, any idea why logging.config.fileConfig doesn't work? > > Now the logging.conf looks like this: > > [formatters] > keys: detailed > > [handlers] > keys: console,file > > [loggers] > keys: root > > [formatter_detailed] > format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s > > [handler_console] > class: StreamHandler > args: [] > formatter: detailed > > [handler_file] > class=FileHandler > formatter=detailed > args=('output.log', 'w') > filename=output.log > mode=w > > [logger_root] > level: INFO > handlers: file > I'm not sure, I don't use configuration file my loggers. I don't think the handler_file should have a filename or mode field though. Try removing them. JM From invalid at invalid.invalid Fri Mar 26 11:45:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 26 Mar 2010 15:45:18 +0000 (UTC) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 2010-03-26, Luis M Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? In colloquial English, "-monkey" is a slang term for a person who does a particular job for a living. For example "grease monkey" is a slang term for an auto mechanic. A "code monkey" is somebody who writes code for a living. It can be slightly derogitory in some situations since it implies that the task is mechanical and repetitive and doesn't require a lot of creative thinking. However, it can be used among peers in an affectionate way. One may refer to one's peer as "code monkey" without offense, but a manager could not refer to one of his employees as a "code monkey" without risking it being seen as an insult. Many people are accustomed to speaking anthopomorphically about computers and programs, so when somebody writes a program that does "foo", the name "foo monkey" seems natural for that program. -- Grant Edwards grant.b.edwards Yow! I don't know WHY I at said that ... I think it gmail.com came from the FILLINGS in my rear molars ... From joncle at googlemail.com Fri Mar 26 11:47:29 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Mar 2010 08:47:29 -0700 (PDT) Subject: Classes as namespaces? References: Message-ID: <809a6515-214f-4460-a847-0e935c7f87b9@t23g2000yqt.googlegroups.com> On 26 Mar, 14:49, kj wrote: > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ? spam = 1 > ? ? jambon = 3 > ? ? huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). ?But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". ?Is there some problem that I'm > not seeing with this technique? > > ~K > > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one > ("the 'intended use' for triple-quoting is not to comment out code", > etc.). ?Here I find myself on the opposite side of the purist/pragmatic > divide. ?Hmmm. Given this example, I would go for the module and CONSTANT_NAMING approach. But yes, even in the docs. you can use a class as a C type-of struct. I stick to the convention of a class knows what it's doing, what it's doing it on, and a module just happens to contain those classes. C++ std::algorithm for instance, makes sense it's called std, ditto algorithm and has shed loads in it, but would I create a class called algorithm (unlikely). I would tend to view modules as "namespace". Rightly or wrongly, just lets you make the right design choice. Jon. From jackdied at gmail.com Fri Mar 26 11:49:14 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 26 Mar 2010 11:49:14 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: On Fri, Mar 26, 2010 at 10:49 AM, kj wrote: > > > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ?spam = 1 > ? ?jambon = 3 > ? ?huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Classes as namespaces are a valid use case (I do it all the time). Python 3 has a small cleanup that makes classes even closer to module namespaces; namely the concept of "unbound methods" goes away. In 3.x when you get a function from a class you get the function itself and not an unbound function. -Jack From jeanmichel at sequans.com Fri Mar 26 11:50:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Mar 2010 16:50:31 +0100 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <4BACD7C7.1060006@sequans.com> kj wrote: > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > You cannot see the problem because there's no problem using classes as namespaces. > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". Is there some problem that I'm > not seeing with this technique? > > ~K > import this [snip] Namespaces are one honking great idea -- let's do more of those! Modules and dictionaries are no more namespaces than classes. So any container is potentially a namespace. JM From michel.metzger at gmail.com Fri Mar 26 11:54:11 2010 From: michel.metzger at gmail.com (Michel) Date: Fri, 26 Mar 2010 08:54:11 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4bac1380$1@news.x-privat.org> Message-ID: I want to add a method to a class such that it can be invoked on specifics instances. You solution works (as well as Patrick's one), thanks ! I still have a question though. If I print the type of the self object I get when my method is called, I get "". I guess this is because the method is defined as a class method. This is ok in my case, but just out of curiosity, what should I do to change this method to an instance method? Thanks for your help, Michel. On Mar 25, 9:53?pm, I V wrote: > On Thu, 25 Mar 2010 15:00:35 -0700, Michel wrote: > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods to it and later instantiate this class. Methods need > > to be bound to the instance though, and that's my problem. Here is what > > I have so far: > > I'm not entirely sure what you mean by binding methods to the instance. > Do you mean you need to dynamically add methods to a specific instance? > Or that you need to add methods to a class, such that they can be invoked > on specific instances? For the latter, just do: > > TestClass.test_foo = test_foo > > For the former, try: > > tc = TestClass() > tc.test_foo = types.MethodType(test_foo, tc) From robert.kern at gmail.com Fri Mar 26 12:06:19 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Mar 2010 11:06:19 -0500 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 2010-03-26 10:45 AM, Grant Edwards wrote: > On 2010-03-26, Luis M Gonz?lez wrote: >> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >> >> Monkeys everywhere. > Many people are accustomed to speaking anthopomorphically about "simiomorphically"? -- 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 From mwilson at the-wire.com Fri Mar 26 12:08:41 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Mar 2010 12:08:41 -0400 Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: Grant Edwards wrote: > However, it can be used among peers in an affectionate way. One may > refer to one's peer as "code monkey" without offense, but a manager > could not refer to one of his employees as a "code monkey" without > risking it being seen as an insult. Somewhere on the Internet there's a particularly brilliant pop song called "Code Monkey". Mel. From joncle at googlemail.com Fri Mar 26 12:14:35 2010 From: joncle at googlemail.com (Jon Clements) Date: Fri, 26 Mar 2010 09:14:35 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On 26 Mar, 15:45, Grant Edwards wrote: > On 2010-03-26, Luis M ?Gonz?lez wrote: > > > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > > Monkeys everywhere. > > Sorry for the off topic question, but what does "monkey" mean in a > > nerdy-geek context?? > > In colloquial English, "-monkey" is a slang term for a > person who does a particular job for a living. ?For example "grease > monkey" is a slang term for an auto mechanic. ?A "code monkey" is > somebody who writes code for a living. > > It can be slightly derogitory in some situations since it implies that > the task is mechanical and repetitive and doesn't require a lot of > creative thinking. > > However, it can be used among peers in an affectionate way. ?One may > refer to one's peer as "code monkey" without offense, but a manager > could not refer to one of his employees as a "code monkey" without > risking it being seen as an insult. > > Many people are accustomed to speaking anthopomorphically about > computers and programs, so when somebody writes a program that does > "foo", the name "foo monkey" seems natural for that program. > > -- > Grant Edwards ? ? ? ? ? ? ? grant.b.edwards ? ? ? ?Yow! I don't know WHY I > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? at ? ? ? ? ? ? ? said that ... I think it > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? gmail.com ? ? ? ? ? ?came from the FILLINGS in > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?my rear molars ... Can I take the slight risk that actually it can also be (as you said 'affectionately') in a very positive sense. The same way "geek" or "nerd" can be applied. I used to be called "Big Geek" from the last company I worked for on PAYE, but that was a compliment. But, I've heard my step-dad call someone a "Geek" which is derogatory. No winning when you have language that can mean "bad" (in meaning "wicked/very good/awesome" (and even 'wicked' means good sometimes - as in enthusiasm for an idea)) or actually "bad/not good [add your own synonyms]". All valid, but which is good/bad :) Anyway, this' a group for Python, not English :) Feel better for my rant :) Jon. From ovidiudeac at gmail.com Fri Mar 26 12:26:20 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 18:26:20 +0200 Subject: python logging writes an empty file In-Reply-To: <4BACD667.7020803@sequans.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> <4BACD667.7020803@sequans.com> Message-ID: <804cd4021003260926y6610e90flb433737dc9a99e4a@mail.gmail.com> Anyway, thanks for the first part. Anybody else has any idea why using the same configuration file works when running the tests with nosetests and doesn't work with logging.config.fileConfig() ? From tim.wintle at teamrubber.com Fri Mar 26 12:54:30 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 26 Mar 2010 16:54:30 +0000 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <1269622470.29388.1.camel@localhost> On Fri, 2010-03-26 at 12:08 -0400, Mel wrote: > Somewhere on the Internet there's a particularly brilliant pop song > called "Code Monkey". http://www.jonathancoulton.com/2006/04/14/thing-a-week-29-code-monkey/ (he's linked to the mp3 from there) From __peter__ at web.de Fri Mar 26 13:29:23 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Mar 2010 18:29:23 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: Michel wrote: > Hi everyone, > > I'm trying to dynamically create a class. What I need is to define a > class, add methods to it and later instantiate this class. Methods > need to be bound to the instance though, and that's my problem. Here > is what I have so far: > > method_template = "def test_foo(self):\ > #actual test_foo\ > pass" > exec method_template > > TestClass = types.ClassType("MyTestClass", (unittest.TestCase, ), {}) > TestClass.__module__ = "test" > > now what to do next? Just assign it: >>> import unittest >>> class MyTestClass(unittest.TestCase): pass ... >>> def test_foo(self): ... self.assertEquals(1, 2) ... >>> MyTestClass.test_foo = test_foo # <---- >>> unittest.main() F ====================================================================== FAIL: test_foo (__main__.MyTestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "", line 2, in test_foo AssertionError: 1 != 2 ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) If you don't know the method name beforehand use setattr(MyTestClass, method_name, method), e. g: >>> import unittest >>> class MyTestClass(unittest.TestCase): pass ... >>> def make_method(n): ... def test(self): self.assertEquals(2, n) ... return test ... >>> for i in range(3): ... setattr(MyTestClass, "test_%d" % i, make_method(i)) ... >>> unittest.main() FF. ====================================================================== FAIL: test_0 (__main__.MyTestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "", line 2, in test AssertionError: 2 != 0 ====================================================================== FAIL: test_1 (__main__.MyTestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "", line 2, in test AssertionError: 2 != 1 ---------------------------------------------------------------------- Ran 3 tests in 0.000s FAILED (failures=2) Peter From sccolbert at gmail.com Fri Mar 26 13:36:55 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 26 Mar 2010 13:36:55 -0400 Subject: Classes as namespaces? In-Reply-To: <4BACD7C7.1060006@sequans.com> References: <4BACD7C7.1060006@sequans.com> Message-ID: <7f014ea61003261036t11f50d89k409b66f854d53ab1@mail.gmail.com> i use them in Pymazon to encapsulate program wide settings and enforce valid values for these settings. http://code.google.com/p/pymazon/source/browse/pymazon/settings.py On Fri, Mar 26, 2010 at 11:50 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > kj wrote: > >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): >> spam = 1 >> jambon = 3 huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> >> >> Granted, this is not the "intended use" for classes, and therefore >> could be viewed as a misuse ("that's what dictionaries are for", >> etc.). But other than this somewhat academic objection[*], I really >> can see no problem with using classes in this way. >> >> > You cannot see the problem because there's no problem using classes as > namespaces. > > And yet, I've come across online murky warnings against using >> classes as "pseudo-namespaces". Is there some problem that I'm >> not seeing with this technique? >> >> ~K >> >> > import this > [snip] > Namespaces are one honking great idea -- let's do more of those! > > Modules and dictionaries are no more namespaces than classes. So any > container is potentially a namespace. > > JM > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Fri Mar 26 13:38:58 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 26 Mar 2010 17:38:58 +0000 Subject: Have you embraced Python 3.x yet? References: Message-ID: On Fri, 26 Mar 2010 13:23:25 +0000, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? Still with 2.6, and probably will be indefinitely. I use Python mostly for Unix scripting: the kind of task which would traditionally have used Bourne shell. For that purpose, life is much simpler when everything is byte strings rather than character strings. If I was doing the same thing on Windows, Python 3.x would probably make more sense, as all of the OS APIs use Unicode (although there's still a hell of a lot of software written using the "ANSI" interfaces; my AppLocale folder has over a hundred entries). From no.email at please.post Fri Mar 26 13:51:36 2010 From: no.email at please.post (kj) Date: Fri, 26 Mar 2010 17:51:36 +0000 (UTC) Subject: Classes as namespaces? References: Message-ID: Thanks for all your comments. I see that modules are arguably Python's standard way for implementing namespaces. I guess I tend to avoid modules primarily because of lingering mental trauma over incidents of insane/bizarro import bugs in the past. (It's not rational, I know; it's like when one develops an aversion for some previously liked food after a bout of food poisoning with it.) Now I postpone creating a new Python module until the pain of not doing so forces me beyond my phobia. (Yes, you got that right, I'm a basket case.) From ownbusiness.ws at gmail.com Fri Mar 26 14:04:18 2010 From: ownbusiness.ws at gmail.com (www.ownbusiness.ws) Date: Fri, 26 Mar 2010 11:04:18 -0700 (PDT) Subject: Income for life ! Message-ID: www.ownbusiness.ws Change your life now. Try, it really works. From pavithra445 at gmail.com Fri Mar 26 14:04:44 2010 From: pavithra445 at gmail.com (PAVITHRA) Date: Fri, 26 Mar 2010 11:04:44 -0700 (PDT) Subject: EARN MONEY IN FREE TIME(DO MORE & EARN MORE) Message-ID: http://cancerresearch-vijay.blogspot.com/ http://nutritionhealthnoni.blogspot.com/ http://vijay-forestenjoy.blogspot.com/ http://information-041.blogspot.com/ http://onlineworktamilnadu.blogspot.com/ http://vijay-onlinejob.blogspot.com/ http://online-trading111.blogspot.com/ http://hot-problem.blogspot.com/ http://vijay681.blogspot.com/ http://nutuernoni.blogspot.com/ http://nonisearch2008.blogspot.com From ownbusiness.ws at gmail.com Fri Mar 26 14:05:12 2010 From: ownbusiness.ws at gmail.com (www.ownbusiness.ws) Date: Fri, 26 Mar 2010 11:05:12 -0700 (PDT) Subject: Income for life ! Message-ID: <5bd2ff92-4327-4699-a839-e280e0aa6225@j21g2000yqh.googlegroups.com> www.ownbusiness.ws Change your life now. Try, it really works. From philip at semanchuk.com Fri Mar 26 14:10:59 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 26 Mar 2010 14:10:59 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <4CA7EC42-05F4-46F2-A8B2-6BD8FE1CE17A@semanchuk.com> On Mar 26, 2010, at 1:51 PM, kj wrote: > Thanks for all your comments. > > I see that modules are arguably Python's standard way for implementing > namespaces. I guess I tend to avoid modules primarily because of > lingering mental trauma over incidents of insane/bizarro import > bugs in the past. There can be good reasons (i.e. unrelated to trauma) not to use a one- namespace-per-module rule. For instance, The app I'm working on now has 43 classes defined in a constants.py file. Each class is just a namespace for constants. That's much more practical than 43 modules called foo_constants.py, bar_constants.py, etc. My Currency(type=CurrencyType.USD, value=decimal.Decimal(".02")), Philip From luismgz at gmail.com Fri Mar 26 14:26:04 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 26 Mar 2010 11:26:04 -0700 (PDT) Subject: Classes as namespaces? References: Message-ID: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> On 26 mar, 11:49, kj wrote: > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ? spam = 1 > ? ? jambon = 3 > ? ? huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) I see no problem. I wouldn't mix English, French and Spanish in the same recipe though... From michel.metzger at gmail.com Fri Mar 26 14:41:21 2010 From: michel.metzger at gmail.com (Michel) Date: Fri, 26 Mar 2010 11:41:21 -0700 (PDT) Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> Message-ID: <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> Thanks Peter. I searched a little bit more and wrote the following example: ------------------------------------ import types class MyClass: def test_toto(self): print type(self) print self.name def test_toto(self): print type(self) print self.name MyDynClass = types.ClassType("MyDynClass", (object, ), {}) MyDynClass.__module__ = "test.complex.hierarchy" MyDynClass.test_toto = test_toto t1 = MyDynClass() t2 = MyDynClass() t1.name = "Marcel" t2.name = "Oscar" t1.test_toto() t2.test_toto() c1 = MyClass() c1.name = "Raoul" c1.test_toto() -------------------------------- the output is: Marcel Oscar Raoul I'm wondering why the type of the self parameter is not 'instance' in the calls t1.test_toto() and t2.test_toto() The rest of the behavior is correct though, so I guess it's just internal Python stuff. Thanks for your help, Michel. On Mar 26, 1:29?pm, Peter Otten <__pete... at web.de> wrote: > Michel wrote: > > Hi everyone, > > > I'm trying to dynamically create a class. What I need is to define a > > class, add methods to it and later instantiate this class. Methods > > need to be bound to the instance though, and that's my problem. Here > > is what I have so far: > > > method_template = "def test_foo(self):\ > > ? ? #actual test_foo\ > > ? ? pass" > > exec method_template > > > TestClass = types.ClassType("MyTestClass", (unittest.TestCase, ), {}) > > TestClass.__module__ = "test" > > > now what to do next? > > Just assign it: > > >>> import unittest > >>> class MyTestClass(unittest.TestCase): pass > ... > >>> def test_foo(self): > > ... ? ? self.assertEquals(1, 2) > ...>>> MyTestClass.test_foo = test_foo # <---- > >>> unittest.main() > > F > ====================================================================== > FAIL: test_foo (__main__.MyTestClass) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ? File "", line 2, in test_foo > AssertionError: 1 != 2 > > ---------------------------------------------------------------------- > Ran 1 test in 0.000s > > FAILED (failures=1) > > If you don't know the method name beforehand use > > setattr(MyTestClass, method_name, method), e. g: > > >>> import unittest > >>> class MyTestClass(unittest.TestCase): pass > > ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?>>> def make_method(n): > > ... ? ? def test(self): self.assertEquals(2, n) > ... ? ? return test ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ...>>> for i in range(3): > > ... ? ? setattr(MyTestClass, "test_%d" % i, make_method(i)) > ...>>> unittest.main() > > FF. > ====================================================================== > FAIL: test_0 (__main__.MyTestClass) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ? File "", line 2, in test > AssertionError: 2 != 0 > > ====================================================================== > FAIL: test_1 (__main__.MyTestClass) > ---------------------------------------------------------------------- > Traceback (most recent call last): > ? File "", line 2, in test > AssertionError: 2 != 1 > > ---------------------------------------------------------------------- > Ran 3 tests in 0.000s > > FAILED (failures=2) > > Peter From vinay_sajip at yahoo.co.uk Fri Mar 26 15:09:10 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 26 Mar 2010 12:09:10 -0700 (PDT) Subject: python logging writes an empty file References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> <4BACD667.7020803@sequans.com> Message-ID: <12364311-5d80-4a14-a19b-f1e29aea9735@g19g2000yqe.googlegroups.com> On Mar 26, 4:26?pm, Ovidiu Deac wrote: > Anyway, thanks for the first part. > > Anybody else has any idea why using the same configuration file works > when running the tests with nosetests and doesn't work withlogging.config.fileConfig() ? It's probably because the fileConfig code is intended to *replace* any existing configuration. This means disabling any existing loggers which are not named explicitly, or not descendants of loggers named explicitly, in the configuration. Make sure you call logging.config.fileConfig() before any loggers have been instantiated in your code, or else ensure that all the top-level parents of those loggers (i.e. just below the root logger) are defined in the configuration. If you have version 2.6 or newer of Python, the fileConfig call has an optional keyword parameter disable_existing_loggers which has a default value of True, but which you can set to False to avoid disabling the existing loggers. Regards, Vinay Sajip From jonas at lophus.org Fri Mar 26 15:10:24 2010 From: jonas at lophus.org (Jonas H.) Date: Fri, 26 Mar 2010 20:10:24 +0100 Subject: [C-API] malloc error in PyDict_New Message-ID: <4BAD06A0.3080206@lophus.org> Hi there, I'm currently diving into Python C programming and I have a problem with `PyDict_New`. My application receives a SIGABRT from malloc every time I execute `PyDict_New`. malloc throws the following error: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) [snip]' failed. gdb gives me the following traceback: Program received signal SIGABRT, Aborted. 0x0012d422 in __kernel_vsyscall () (gdb) bt full #0 0x0012d422 in __kernel_vsyscall () #5 0x003fef8c in malloc () from /lib/tls/i686/cmov/libc.so.6 #6 0x001b129c in new_arena (nbytes=3221223842) at ../Objects/obmalloc.c:534 i = numarenas = 16 arenaobj = 0x0 excess = 16 #7 PyObject_Malloc (nbytes=3221223842) at ../Objects/obmalloc.c:794 bp = pool = next = size = 4983326 #8 0x001baef5 in PyString_FromString (str=0x2964bf "") at ../Objects/stringobject.c:138 op = 0x0 #9 0x001a9d55 in PyDict_New () at ../Objects/dictobject.c:227 mp = #10 0x08048fc0 in Transaction_new () at bjoern.c:32 transaction = 0x80503a0 #11 0x08049309 in on_sock_accept (mainloop=0x13a120, accept_watcher=0xbffff770, revents=1) at bjoern.c:109 [snip] #12 0x00130594 in ev_invoke_pending () from /usr/lib/libev.so.3 #13 0x00135774 in ev_loop () from /usr/lib/libev.so.3 #14 0x080496e0 in main (argcount=1, args=0xbffff864) at bjoern.c:207 [snip] I have walked millions of Google pages but I couldn't find any explanation what causes the allocation error. I tried to put the `PyDict_New` somewhere else to let it be invoked earlier/later. The only effect I got is a "memory corruption" reported by glibc. Could anybody tell me what exactly I'm doing wrong? It is quite possible that I fscked up some pointers or memory ranges as this is my first C project. You can find the whole source at github: http://github.com/jonashaag/bjoern The call to `PyDict_New` is here: http://github.com/jonashaag/bjoern/blob/master/bjoern.c#L32 Thanks for your help! Jonas From __peter__ at web.de Fri Mar 26 15:16:28 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Mar 2010 20:16:28 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> Message-ID: Michel wrote: > Thanks Peter. > > I searched a little bit more and wrote the following example: > > ------------------------------------ > import types > > class MyClass: > > def test_toto(self): > print type(self) > print self.name > > def test_toto(self): > print type(self) > print self.name > > MyDynClass = types.ClassType("MyDynClass", (object, ), {}) > MyDynClass.__module__ = "test.complex.hierarchy" > MyDynClass.test_toto = test_toto > > t1 = MyDynClass() > t2 = MyDynClass() > > t1.name = "Marcel" > t2.name = "Oscar" > > t1.test_toto() > t2.test_toto() > > c1 = MyClass() > c1.name = "Raoul" > c1.test_toto() > -------------------------------- > > the output is: > > > Marcel > > Oscar > > Raoul > > I'm wondering why the type of the self parameter is not 'instance' in > the calls > t1.test_toto() and t2.test_toto() > > The rest of the behavior is correct though, so I guess it's just > internal Python stuff. In Python 2.x there are "classic" and "newstyle" classes. In practice the main differences are that classic classes are more likely to call __getattr__() and that only newstyle classes support properties correctly. By inheriting from object you make MyDynClass a newstyle class: >>> classic = types.ClassType("A", (), {}) >>> newstyle = types.ClassType("A", (object,), {}) >>> type(classic()), type(classic) (, ) >>> type(newstyle()), type(newstyle) (, ) Classic classes exist for backwards compatibility and because most programmers are too lazy to have their classes inherit from object when the difference doesn't matter. When you create a class dynamically I recommend that you use the type() builtin instead of types.ClassType(). This will always create a newstyle class -- even when you don't inherit from object explicitly: >>> type(type("A", (), {})) >>> type("A", (), {}).__bases__ (,) Peter From steve at holdenweb.com Fri Mar 26 15:19:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Mar 2010 15:19:44 -0400 Subject: Create a class at run-time In-Reply-To: <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4767a89e-d6a7-4c77-97f8-54d84e3e5bc8@u19g2000prh.googlegroups.com> Message-ID: Michel wrote: > Thanks Peter. > > I searched a little bit more and wrote the following example: > > ------------------------------------ > import types > > class MyClass: > > def test_toto(self): > print type(self) > print self.name > > def test_toto(self): > print type(self) > print self.name > > MyDynClass = types.ClassType("MyDynClass", (object, ), {}) > MyDynClass.__module__ = "test.complex.hierarchy" > MyDynClass.test_toto = test_toto > > t1 = MyDynClass() > t2 = MyDynClass() > > t1.name = "Marcel" > t2.name = "Oscar" > > t1.test_toto() > t2.test_toto() > > c1 = MyClass() > c1.name = "Raoul" > c1.test_toto() > -------------------------------- > > the output is: > > > Marcel > > Oscar > > Raoul > > I'm wondering why the type of the self parameter is not 'instance' in > the calls > t1.test_toto() and t2.test_toto() > > The rest of the behavior is correct though, so I guess it's just > internal Python stuff. > Yes, it's just that MyClass is an old-style class (its type is ) whereas MyDynClass is a new-style class (its type is , because it inherits from object). It's as though you had written class MyClass: ... class MyDynClass(object): ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From stefan_ml at behnel.de Fri Mar 26 15:41:50 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 26 Mar 2010 20:41:50 +0100 Subject: [C-API] malloc error in PyDict_New In-Reply-To: <4BAD06A0.3080206@lophus.org> References: <4BAD06A0.3080206@lophus.org> Message-ID: Jonas H., 26.03.2010 20:10: > I'm currently diving into Python C programming and I have a problem with > `PyDict_New`. > > My application receives a SIGABRT from malloc every time I execute > `PyDict_New`. malloc throws the following error: > > malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) > &((av)->bins[((1) - 1) * 2])) [snip]' failed. In case this code is not called from within Python but from some kind of network layer callback (maybe in a thread created by C code?), you will have to set up a Python interpreter environment for such a thread first. See the PyInterpreterState and PyThreadState functions here: http://docs.python.org/c-api/init.html Stefan From phlip2005 at gmail.com Fri Mar 26 15:44:04 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 26 Mar 2010 12:44:04 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> On Mar 26, 6:14?am, Luis M. Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? > > Luis Better at typing than thinking. From mensanator at aol.com Fri Mar 26 16:07:34 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 26 Mar 2010 13:07:34 -0700 (PDT) Subject: Have you embraced Python 3.x yet? References: Message-ID: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> On Mar 26, 8:23?am, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? 3.1. The only module I use regularly is gmpy and that's one that has been updated. From ovidiudeac at gmail.com Fri Mar 26 16:08:14 2010 From: ovidiudeac at gmail.com (Ovidiu Deac) Date: Fri, 26 Mar 2010 22:08:14 +0200 Subject: python logging writes an empty file In-Reply-To: <12364311-5d80-4a14-a19b-f1e29aea9735@g19g2000yqe.googlegroups.com> References: <804cd4021003251711p5c1ec832pf2b98da8f19bef1e@mail.gmail.com> <4BACBC56.1020105@sequans.com> <804cd4021003260729t150ffdd3m1f30fc1bdea138ca@mail.gmail.com> <4BACD667.7020803@sequans.com> <12364311-5d80-4a14-a19b-f1e29aea9735@g19g2000yqe.googlegroups.com> Message-ID: <804cd4021003261308m5c5fc88cp35e0d1c43909aeb2@mail.gmail.com> It worked. Setting disable_existing_loggers=False fixed my problem. Thanks to both of you! Ovidiu On Fri, Mar 26, 2010 at 9:09 PM, Vinay Sajip wrote: > On Mar 26, 4:26?pm, Ovidiu Deac wrote: >> Anyway, thanks for the first part. >> >> Anybody else has any idea why using the same configuration file works >> when running the tests with nosetests and doesn't work withlogging.config.fileConfig() ? > > It's probably because the fileConfig code is intended to *replace* any > existing configuration. This means disabling any existing loggers > which are not named explicitly, or not descendants of loggers named > explicitly, in the configuration. > > Make sure you call logging.config.fileConfig() before any loggers have > been instantiated in your code, or else ensure that all the top-level > parents of those loggers (i.e. just below the root logger) are defined > in the configuration. > > If you have version 2.6 or newer of Python, the fileConfig call has an > optional keyword parameter disable_existing_loggers which has a > default value of True, but which you can set to False to avoid > disabling the existing loggers. > > Regards, > > Vinay Sajip > -- > http://mail.python.org/mailman/listinfo/python-list > From mensanator at aol.com Fri Mar 26 16:18:47 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 26 Mar 2010 13:18:47 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: On Mar 26, 2:44?pm, Phlip wrote: > On Mar 26, 6:14?am, Luis M. Gonz?lez wrote: > > > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > > Monkeys everywhere. > > Sorry for the off topic question, but what does "monkey" mean in a > > nerdy-geek context?? > > > Luis > > Better at typing than thinking. Really? I thought it was more of a reference to Eddington, i.e., given enough time even a monkey can type out a program. From sccolbert at gmail.com Fri Mar 26 16:26:44 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 26 Mar 2010 16:26:44 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> Message-ID: <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> On Fri, Mar 26, 2010 at 4:07 PM, Mensanator wrote: > On Mar 26, 8:23 am, Harishankar wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > 3.1. > > The only module I use regularly is gmpy and that's one that has > been updated. > -- > http://mail.python.org/mailman/listinfo/python-list > I won't switch until NumPy and SciPy make the jump. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ivlenin at gmail.com Fri Mar 26 16:46:04 2010 From: ivlenin at gmail.com (I V) Date: 26 Mar 2010 21:46:04 +0100 Subject: Create a class at run-time References: <0b161d98-64b2-488f-b62e-19062bad23c8@f14g2000pre.googlegroups.com> <4bac1380$1@news.x-privat.org> Message-ID: <4bad1d0c$1@news.x-privat.org> On Fri, 26 Mar 2010 08:54:11 -0700, Michel wrote: > I want to add a method to a class such that it can be invoked on > specifics instances. > You solution works (as well as Patrick's one), thanks ! I still have a > question though. If I print the type of the self object I get when my > method is > called, I get "". I guess this is because the > method is defined as a class method. > This is ok in my case, but just out of curiosity, what should I do to > change this method to an instance method? It already is an instance method. When you create a TestClass instance, the type of that instance is TestClass (the type of TestClass itself is "type"). From ricaraoz at gmail.com Fri Mar 26 16:51:23 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 26 Mar 2010 17:51:23 -0300 Subject: Classes as namespaces? In-Reply-To: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> Message-ID: <4BAD1E4B.5000000@gmail.com> Luis M. Gonz?lez wrote: > On 26 mar, 11:49, kj wrote: > >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): >> spam = 1 >> jambon = 3 >> huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> > > I see no problem. > I wouldn't mix English, French and Spanish in the same recipe though... > Why? Do you think it might get over cooked? ;c) -------------- next part -------------- An HTML attachment was scrubbed... URL: From winstonwolff at gmail.com Fri Mar 26 17:34:42 2010 From: winstonwolff at gmail.com (Winston) Date: Fri, 26 Mar 2010 14:34:42 -0700 (PDT) Subject: Revisiting Generators and Subgenerators References: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> Message-ID: On Mar 26, 7:29?am, Sebastien Binet wrote: > > Proposal for a new Generator Syntax in Python 3K-- > > A Baton object for generators to allow subfunction to yield, and to > > make > > them symetric. > > isn't a Baton what CSP calls a channel ? > > there is this interesting PyCSP library (which implements channels > over greenlets, os-processes (via multiprocessing) or python threads)http://code.google.com/p/pycsp > > cheers, > sebastien. Thanks for the link. After reading about Greenlets, it seems my Baton is a Greenlet. It is not passed in to the new greenlet as I wrote above, but both sides use it to pass execution to the other, and to send a value on switching. I'm glad my thinking is matching other people's thinking. Now I have to search for a greenlet written for Jython. And thanks to others for their thoughts on this subject. -Winston From novacompute at gmail.com Fri Mar 26 17:58:08 2010 From: novacompute at gmail.com (wukong) Date: Fri, 26 Mar 2010 14:58:08 -0700 (PDT) Subject: exec .exe Message-ID: newbie question, how do you run a .exe generated by MSVC++ in python in windows? From ldo at geek-central.gen.new_zealand Fri Mar 26 18:05:34 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Mar 2010 11:05:34 +1300 Subject: sqlite version on windows References: <4BAC8521.2@shopzeus.com> Message-ID: In message , Philip Semanchuk wrote: > On Mar 26, 2010, at 5:57 AM, Laszlo Nagy wrote: >> >> On my Linux system: Python version: 2.6.2 sqlite3.sqlite_version: >> 3.6.10 >> On my Windows system: Python version: 2.6.5 sqlite3.sqlite_version: >> 3.5.9 >> >> Why is that? > > The few Linux distros that I checked are much more aggressive about > bundling newer versions of SQLite. For instance, Ubuntu 8.04 has > Python 2.5.2 with SQLite 3.4.2, while Ubuntu 8.10 has the same version > of Python but offers SQLite 3.5.9. > > You asked "why" and I don't know. I imagine it comes down to > philosophical differences or maybe just a lack of time to test when > building new WIndows distros for Python.org. Maybe the issues are more practical than philosophical. Linux distros use an integrated package manager and are maintained by a cohesive community. What that means is that the SQLite package isn?t just used by Python, but by a bunch of other stuff as well. So all the maintainers of those packages have an interest in making sure that SQLite doesn?t break them. Whereas on Windows, the Python download has to include _all_ its dependencies, it cannot rely on a system-integrated package manager to automatically provide them. And the same is true for every other open-source package that anyone tries to pre-build for Windows. So they all have to provide their own installation routines, their own updates, their own testing ... in short, a lot of duplication of effort. This is expensive. From emile at fenx.com Fri Mar 26 18:09:24 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 26 Mar 2010 15:09:24 -0700 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: On 3/26/2010 1:18 PM Mensanator said... > On Mar 26, 2:44 pm, Phlip wrote: >> On Mar 26, 6:14 am, Luis M. Gonz?lez wrote: >> >>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >> >>> Monkeys everywhere. >>> Sorry for the off topic question, but what does "monkey" mean in a >>> nerdy-geek context?? >> >>> Luis >> >> Better at typing than thinking. > > Really? I thought it was more of a reference to Eddington, i.e., given > enough time even a monkey can type out a program. I like the quote that went along the lines of 'here we are, and no we haven't' From irmen-NOSPAM- at xs4all.nl Fri Mar 26 18:10:38 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Fri, 26 Mar 2010 23:10:38 +0100 Subject: exec .exe In-Reply-To: References: Message-ID: <4bad3060$0$22937$e4fe514c@news.xs4all.nl> On 26-3-2010 22:58, wukong wrote: > newbie question, how do you run a .exe generated by MSVC++ in python > in windows? Use the subprocess module, for instance: subprocess.call(["notepad.exe", "d:/file.txt"]) irmen From cs at zip.com.au Fri Mar 26 18:28:28 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 27 Mar 2010 09:28:28 +1100 Subject: Revisiting Generators and Subgenerators In-Reply-To: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> References: <32b967ce-bb76-45ad-8660-c1d96a35fc72@g11g2000yqe.googlegroups.com> Message-ID: <20100326222828.GA15135@cskk.homeip.net> On 26Mar2010 07:29, Sebastien Binet wrote: | On Mar 25, 10:39?pm, Winston wrote: | > A Baton object for generators to allow subfunction to yield, and to | > make them symetric. | | isn't a Baton what CSP calls a channel ? I was thinking about this (roughly) in the shower this morning before seeing this message. One difference is that a Channel or zero-storage Queue lets the putter continue execution after the put (or at least the other side's get). A co-routine won't proceed until later, no? So a co-routine setup will do lazier computation than a similar threaded setup. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Principles have no real force except when one is well fed. - Mark Twain From novacompute at gmail.com Fri Mar 26 18:48:02 2010 From: novacompute at gmail.com (wukong) Date: Fri, 26 Mar 2010 15:48:02 -0700 (PDT) Subject: exec .exe References: <4bad3060$0$22937$e4fe514c@news.xs4all.nl> Message-ID: <8524a2ad-1f16-45b1-9c56-6f8b5b7e1413@l12g2000pra.googlegroups.com> On Mar 26, 3:10?pm, Irmen de Jong wrote: > On 26-3-2010 22:58, wukong wrote: > > > newbie question, how do you run a .exe generated by MSVC++ in python > > in windows? > > Use the subprocess module, for instance: > subprocess.call(["notepad.exe", "d:/file.txt"]) > > irmen worked like a charm, :-) thanks irmen. From tjreedy at udel.edu Fri Mar 26 19:43:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 26 Mar 2010 19:43:18 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: On 3/26/2010 9:23 AM, Harishankar wrote: > Have you people embraced Python 3.x? Yes. My current work only needs the stdlib and I much prefer the streamlined language. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 26 20:03:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Mar 2010 00:03:30 GMT Subject: Classes as namespaces? References: Message-ID: <4bad4b52$0$27866$c3e8da3@news.astraweb.com> On Fri, 26 Mar 2010 14:49:02 +0000, kj wrote: > What's the word on using "classes as namespaces"? >>> import this [...] Namespaces are one honking great idea -- let's do more of those! > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one ("the > 'intended use' for triple-quoting is not to comment out code", etc.). On the contrary. CPython deliberately strips bare strings (whether triple quoted or not) out during compilation. This isn't an accident, it is deliberate. >>> code = """ ... x = 1 ... y = 2 ... # comment ... "a string" ... z = 4 ... """ >>> o = compile(code, '', 'exec') >>> dis.dis(o) 2 0 LOAD_CONST 0 (1) 3 STORE_NAME 0 (x) 3 6 LOAD_CONST 1 (2) 9 STORE_NAME 1 (y) 6 12 LOAD_CONST 2 (4) 15 STORE_NAME 2 (z) 18 LOAD_CONST 3 (None) 21 RETURN_VALUE Why should you not do this? First, it is implementation-specific: other Pythons may not behave the same. Potentially they may compile in the (potentially large) string, push it on the stack, then immediately pop it off again. Older versions of CPython used to do that for non-strings. Secondly, and FAR more importantly, leaving large amounts of commented out code in your source is a TERRIBLE idea. Yes, sure, it's tempting to do, especially for quick and dirty scripts. Resist the temptation. Learn how to use a proper code repository. Don't leave the detritus of ancient unused code in your source files -- it confuses the reader, makes searching harder, slows down parsing, and (trust me) you will never need to read the old code again. It just gets in the way. Of course, like everything, this needs to be considered in context. You might leave commented-out code like this: # DON'T DO THIS: # s = spam(s, s*2) # It doesn't work. See bug #12345 in the tracker. Instead do this: s = spam(s*2, s) -- Steven From debatem1 at gmail.com Fri Mar 26 20:33:12 2010 From: debatem1 at gmail.com (geremy condra) Date: Fri, 26 Mar 2010 20:33:12 -0400 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: On Fri, Mar 26, 2010 at 9:23 AM, Harishankar wrote: > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > I personally want to switch over but not too sure how many people are > using 3.x as opposed to 2 so I want to keep my programs compatible for > the majority. > > -- Hari > -- > http://mail.python.org/mailman/listinfo/python-list > Yes- I write new code in 3.x and backport it PRN. Geremy Condra From ethan at stoneleaf.us Fri Mar 26 20:59:21 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 26 Mar 2010 17:59:21 -0700 Subject: Python database of plain text editable by notepad or vi In-Reply-To: References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: <4BAD5869.1010107@stoneleaf.us> Jon Clements wrote: > On 26 Mar, 09:49, James Harris wrote: > >>On 25 Mar, 22:56, Jon Clements wrote: >> >> >> >> >>>On 25 Mar, 22:40, James Harris wrote: >> >>>>I am looking to store named pieces of text in a form that can be >>>>edited by a standard editor such as notepad (under Windows) or vi >>>>(under Unix) and then pulled into Python as needed. The usual record >>>>locking and transactions of databases are not required. >> >>>>Another way to look at it is to treat the separate files as entries in >>>>a dictionary. The file name would be the key and the lines of the file >>>>the value. >> >>>>Anyone know of a database (with a Python interface) which will allow >>>>text files to be treated as database fields? If not I can just write >>>>it but I thought it best to ask if there was an existing solution >>>>first. >> >>... >> >>>I could be missing something here, but aren't you basically just >>>talking about an OS's filesystem? >> >>For storage, yes. The files would be marked-up text stored in the >>filesystem. The "dbms" (I use the term loosely!) would provide access >>to them by some full or partial key mechanism yet to be determined. >>Read-only access would do - at least for now. >> >> >>>glob or listdir somewhere, then create a dict using the file contents >>>would meet your criteria, with very little lines of code -- but I >>>would be interested to know what the use-case was for this... Is it >>>read completely at start up time, or if each file contains a large >>>amount of lines and aren't fixed width (or has no other indexing >>>support without maintenance), then is a complete sequential-scan >>>required each time, or do you just tell the user to not update when >>>running (unless I s'pose something along the lines of a SIGHUP for >>>config files is applicable). >> >>All good questions. For now, at least, the files can be read-only and >>I'd want those on disk to be the master copies at all times. If I was >>writing it myself I'd probably 'cache' some files in memory and stat >>them before use. If newer I would reread the file. >> > > > It's hard to bore this group :) > > >> >>>Sorry, just don't understand why you'd want this. >> >>I tried to avoid boring folks with the details. I'm toying with some >>ideas for a way to help generate source code (in various languages, >>not just Python). If it goes ahead the text files would be mainly >>marked-up code snippets - with or without symbols that need to be >>replaced. >> >>Rather than write one single monolithic app I thought to split it into >>reusable components. One part being data access could perhaps be an >>existing database (and I'll take a look at jkn's suggestion). >> >>Think of the database as similar to an associative array stored on >>disk. The only difference is I may want to play fast and loose with >>the keys in some ways - e.g. check for partial key matches or return a >>list of part-matched keys. The language name could be part of the key >>but I'd also need to store variants for specific language versions. >>I'm not sure yet how it will all pan out. As I say, just throwing >>around some ideas. >> >>James > > > Thanks for the explanation. > > Who admins and, who's editing this data? > > I couldn't 100% guarantee that I could modify a text file and always > put the right > delimiter in the right place and remember to escape the relevant chars > (and I'm > probably not the 'average' user). > > Any opposition to just putting it in a 'proper' DB, then 'blobbing' > the values? > (or just integrate a procedure/script/function whatever your chosen > RDBMS calls to choose it). > Or in some systems, 'externally referencing'... loads of DB's have > free front-ends, > and there are lots of Python libraries. > > I think perhaps, all I'm saying is, I'd choose a different approach. > I'd provide a front-end, rather than choose to re-write the wheel over > DB's. Just to provide a counter-viewpoint: The (one) system I have worked with that was like that (program source files kept in blobs in a database) I absolutely hated. I was stuck with using the tools provided by the app (which, amazingly enough, I also hated ;), and unable to use my own tools because because *my* source files were _not_ saved as *files*. Okay, venting over. My point is, if what you are storing is plain ol' source files, providing a way to directly access them is a good thing. If what you are storing is a mangled version, the ability to let the user choose any editor to use is a good thing. :) My $0.02. ~Ethan~ From nocbos at gmail.com Fri Mar 26 21:18:07 2010 From: nocbos at gmail.com (C. B.) Date: Fri, 26 Mar 2010 18:18:07 -0700 (PDT) Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: At first, thank you all for your answers. Some more details about what I'm coding and what I need... The classes AAA and BBB are just given as examples. In fact, BBB's constructor accepts several parameters, meaning it can be different for each creation of AAA. So it can't be simply skipped from the AAA's one, even if there can be a default value. Making AAA do the call to BBB is a solution, but, in that case, the end-user loses the reference to the used BBB instance. Concerning the reason why I wish to avoid importing, once again AAA and BBB were just examples. I plan to add more classes, so AAA will also need CCC, DDD, and so on to work. It takes time to write the relative importations, that's ok, but I think it could be more pleasant for the end-user to not have to write a huge list of "from mymodule import xxx" if it is possible to take advantage of automatic importations. Cheers, From apt.shansen at gmail.invalid Fri Mar 26 21:45:54 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Fri, 26 Mar 2010 18:45:54 -0700 Subject: GIF89A and PIL Message-ID: <2010032618455468300-aptshansen@gmailinvalid> Hi, all. Is it possible to get PIL to save GIF's in GIF89A format, instead of GIF87A? If not, are there any decent other image libraries out there that anyone's familiar with? The only one I could find was PythonMagick, which seems completely undocumented. Or I'm blind. Ahem. But the problem is, I have a nice, small little 72 byte GIF89A file, that I want to do some slight tweaking on and then re-save. I noticed that even if I completely skipped the tweaking step and -just- saved, it exploded into a 919 byte GIF87A file. And in this context, bytes really, really matter. I picked GIF over PNG because the same file in PNG was 120 bytes :) I'm not an expert on graphics, so I don't actually know for certain if its the fact that PIL is saving in GIF87A format that's causing the size to explode, it might just be that PIL is doing.. Something Weird when it saves it as a GIF, too. To demonstrate: >>> f = open('../tiles/BaseTemplate.gif', 'rb') >>> d1 = f.read() >>> len(d1) 73 >>> d1 'GIF89a\x10\x00\x10\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00!\xf9\x04\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x10\x00\x10\x00\x00\x02 \x8c\x8fi\xc0\xed\xbe\x9edq\xbej\x1b\xce`go\x81\x93(\x91W\xc0AhJ\xad\xac\xa9*\xb2Q\x00\x00;' >>> im = Image.open('../tiles/BaseTemplate.gif') >>> import cStringIO >>> cfp = cStringIO.StringIO() >>> im.save(cfp, format="gif") >>> cfp.seek(0) >>> d2 = cfp.read() >>> d2 'GIF87a\x10[...snip...]\x00;' >>> len(d2) 919 -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 26 22:00:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Mar 2010 02:00:24 GMT Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4bad66b8$0$27866$c3e8da3@news.astraweb.com> On Fri, 26 Mar 2010 18:18:07 -0700, C. B. wrote: > It takes time to write the relative importations, that's ok, but I think > it could be more pleasant for the end-user to not have to write a huge > list of "from mymodule import xxx" if it is possible to take advantage > of automatic importations. You mean by black magic? Something like this? >>> GGG = "My really important value" >>> from mymodule import AAA >>> print AAA() "something" >>> print GGG >>> print "WTF happened to my important value???" 'magic ate it' As a general rule, Python does not allow magic. One exception is: from mymodule import * however once you have been bitten by it, you will soon learn to avoid it as almost always a bad idea. -- Steven From timr at probo.com Fri Mar 26 23:15:27 2010 From: timr at probo.com (Tim Roberts) Date: Fri, 26 Mar 2010 20:15:27 -0700 Subject: Advice Criticism on Python App References: Message-ID: Steven D'Aprano wrote: >On Wed, 24 Mar 2010 21:14:23 -0700, Tim Roberts wrote: > >> Jimbo wrote: >>> >>>class stock: >>> code = "" >>> purchasePrice = 0 >>> purchaseQuantity = 0 >>> price = [] # list of recent prices >>> recentBid = [] # list of recent bids for stock >>> recentOffer = [] # list of recent offers for stock >>> stockVol = [] # list of stock quantity available on market >> >> Using lists as class variables is a very good way to create very >> surprising bugs. Consider the following: > >Don't you think that the class attributes are *supposed* to be shared by >all instances? In that case the behaviour you show is not a bug at all. Yes, it occurred to me just after I sent that pot that I had answered a different question from the one he asked. I SUSPECT that he is using class variables as a way to initialize members, not as true class variables. Thanks for clarifying this. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at mrabarnett.plus.com Fri Mar 26 23:50:00 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Mar 2010 03:50:00 +0000 Subject: Automatic import ? In-Reply-To: References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4BAD8068.3010309@mrabarnett.plus.com> C. B. wrote: > At first, thank you all for your answers. > > Some more details about what I'm coding and what I need... > > The classes AAA and BBB are just given as examples. In fact, BBB's > constructor accepts several parameters, meaning it can be different > for each creation of AAA. So it can't be simply skipped from the AAA's > one, even if there can be a default value. > > Making AAA do the call to BBB is a solution, but, in that case, the > end-user loses the reference to the used BBB instance. > > Concerning the reason why I wish to avoid importing, once again AAA > and BBB were just examples. I plan to add more classes, so AAA will > also need CCC, DDD, and so on to work. > > It takes time to write the relative importations, that's ok, but I > think it could be more pleasant for the end-user to not have to write > a huge list of "from mymodule import xxx" if it is possible to take > advantage of automatic importations. > Couldn't you just have: import mymodule as m and then use: m.AAA m.BBB and so on? It's not much longer and it avoids 'magic'. From ldo at geek-central.gen.new_zealand Sat Mar 27 00:37:10 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Mar 2010 17:37:10 +1300 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> Message-ID: In message <2010032618455468300-aptshansen at gmailinvalid>, Stephen Hansen wrote: > Is it possible to get PIL to save GIF's in GIF89A format, instead of > GIF87A? Why? What does GIF do for you that PNG doesn?t? From apt.shansen at gmail.invalid Sat Mar 27 00:53:10 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Fri, 26 Mar 2010 21:53:10 -0700 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> Message-ID: <2010032621531095506-aptshansen@gmailinvalid> On 2010-03-26 21:37:10 -0700, Lawrence D'Oliveiro said: > In message <2010032618455468300-aptshansen at gmailinvalid>, Stephen Hansen > wrote: > >> Is it possible to get PIL to save GIF's in GIF89A format, instead of >> GIF87A? > > Why? What does GIF do for you that PNG doesn?t? If I take this PSD and save it as a GIF as fully optimized as possible, its 72 bytes; do the same with PNG, and its 120. In this situation that difference really is very important. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From greg.ewing at canterbury.ac.nz Sat Mar 27 01:18:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 27 Mar 2010 17:18:40 +1200 Subject: from import and __init__.py In-Reply-To: References: <20100325101632.GA4727@xs4all.nl> Message-ID: <815i6bF3lcU1@mid.individual.net> egbert wrote: > Yes, you are right. And I can reach everything with > modules['some_package'] > or variants thereof. Although note that the usual way to get it would be to simply do import some_package -- Greg From greg.ewing at canterbury.ac.nz Sat Mar 27 01:23:19 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 27 Mar 2010 17:23:19 +1200 Subject: Represent object type as In-Reply-To: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> References: <6a6a37e3-f04f-4b63-9134-7ca9fd137297@f14g2000pre.googlegroups.com> Message-ID: <815if2F3lcU2@mid.individual.net> Jason wrote: > I'm reusing the __getstate__ function I wrote for pickling like > so: Instead of reinventing part of pickle, is there some reason you couldn't just use it? -- Greg From anythinginternetseo at gmail.com Sat Mar 27 01:26:02 2010 From: anythinginternetseo at gmail.com (anything internet) Date: Fri, 26 Mar 2010 22:26:02 -0700 (PDT) Subject: Stop the Heat from Sun Rays! Message-ID: Stop the Heat! Stop UV Damage! Save Money! - More Details : http://www.suntechglasstinting.com/welcome.php From matttibbals69 at yahoo.com Sat Mar 27 01:48:45 2010 From: matttibbals69 at yahoo.com (matttibbals) Date: Fri, 26 Mar 2010 22:48:45 -0700 (PDT) Subject: python Message-ID: <65354fef-2e84-4182-bfdb-69dc5468e9b6@f12g2000prn.googlegroups.com> I'm Matt Tibbals, pedophile. http://www.matthewtibbals.com From lacrima.maxim at gmail.com Sat Mar 27 02:10:59 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Fri, 26 Mar 2010 23:10:59 -0700 (PDT) Subject: Advanced Python Programming Oxford Lectures [was: Re: *Advanced* Python book?] References: mailman.1182.1269520510.23598.python-list@python.org <54e41616-df9f-42dd-9c91-9e530650bd99@j21g2000yqh.googlegroups.com> <9dd0d6b0-7249-4a6f-8d03-b0c3a44eace2@l25g2000yqd.googlegroups.com> Message-ID: On Mar 26, 10:22?am, Michele Simionato wrote: > On Mar 25, 2:24?pm, Michele Simionato > wrote: > > > On Mar 25, 1:28?pm, Ethan Furman wrote: > > > > Michele, > > > > Was wondering if you'd had a chance to re-post your lectures -- just did > > > a search for them and came up empty, and I would love to read them! > > > > Many thanks in advance! > > > Oops, I forgot! I will try to make them available soon. > > Here they are:http://www.phyast.pitt.edu/~micheles/oxford-lectures.zip Hello, Michele! Thanks a lot for posting!!! From vipshopper.us at hotmail.com Sat Mar 27 03:53:05 2010 From: vipshopper.us at hotmail.com (marrylin) Date: Sat, 27 Mar 2010 00:53:05 -0700 (PDT) Subject: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Message-ID: <31437927-ccfd-403f-b79e-e349e662b286@33g2000yqj.googlegroups.com> Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://loveshopping.us ==== Air jordan(1-24)shoes $33 UGG BOOT $50 Nike shox(R4,NZ,OZ,TL1,TL2,TL3) $35 Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 FREE SHIPPING From steve at REMOVE-THIS-cybersource.com.au Sat Mar 27 06:18:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Mar 2010 10:18:35 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> Message-ID: <4baddb7b$0$27866$c3e8da3@news.astraweb.com> On Fri, 26 Mar 2010 07:31:17 -0700, Steve Howell wrote: > From a purely academic standpoint, I'm not convinced that sum() is > inefficient in terms of big-O complexity, though. > > showell at showell-laptop:~$ python > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on > linux2 > >>> class StupidList: [...] But it's not *sum* that is inefficient, it is sum *with a particular data structure*. Sure, if you create your own data structure, you can make it as efficient as you like. Obviously the sum algorithm itself has to perform one addition per item, or O(N), which scales tolerably well. But each addition has a cost. If the cost is constant, then sum() as a whole remains O(N). But if the cost of addition varies with N, sum() degrades badly. We can compare the performance of sum with different data structures, starting with plain integers versus long integers: >>> from timeit import Timer >>> setup = 'data = [%d]*%d' >>> for i in range(6): ... t1 = Timer('sum(data, 0)', setup % (1, 10**i)) ... t2 = Timer('sum(data, 0)', setup % (10**50, 10**i)) ... print min(t1.repeat(number=1000)), ... print min(t2.repeat(number=1000)) ... 0.00179290771484 0.00263810157776 0.00340414047241 0.00854396820068 0.0190401077271 0.0502791404724 0.155302047729 0.645124912262 0.794432878494 2.55748295784 7.97877693176 25.3812758923 Both scale about as well, but the cost varies significantly: arithmetic on very large longints is expensive. Strings, with a trick to fool sum into accepting them, versus lists. Note that I changed the number of iterations from 6 down to 5. The reason why will become obvious: >>> class EmptyStringStarter: ... def __add__(self, other): ... return other ... >>> empty = EmptyStringStarter() >>> setup = """from __main__ import empty; data = [%r]*%d""" >>> >>> for i in range(5): ... t1 = Timer('sum(data, empty)', setup % ('a', 10**i)) ... t2 = Timer('sum(data, [])', setup % ([1], 10**i)) ... print min(t1.repeat(number=1000)), ... print min(t2.repeat(number=1000)) ... 0.00849103927612 0.00226998329163 0.0121459960938 0.0082700252533 0.0489149093628 0.186735153198 0.428920030594 5.28623914719 14.6552250385 589.102822065 Strings perform tolerably well, up to a point, but lists perform terribly. And in fact, the relatively good performance of strings is an artifact of recent versions of CPython. In Jython and IronPython, and older versions of CPython, it will behave as poorly as lists. > I wonder how severely sum(), without > the restriction, would underperform join() on modern versions of Python, > though. Take note that, in order to get an answer in reasonable time, I've reduced the number of timing iterations drastically: >>> for i in range(6): ... t1 = Timer('sum(data, empty)', setup % ('a', 10**i)) ... t2 = Timer('"".join(data)', setup % ('a', 10**i)) ... print min(t1.repeat(number=10)), ... print min(t2.repeat(number=10)) ... 8.89301300049e-05 1.09672546387e-05 0.000131845474243 2.19345092773e-05 0.000591993331909 9.29832458496e-05 0.0101289749146 0.00082802772522 0.365957021713 0.00884819030762 24.2072279453 0.0421011447906 Note the performance degradation of sum. It gets worse. Much worse: >>> for i in range(4, 7): ... t1 = Timer('sum(data, empty)', setup % ('a', 10**i)) ... t2 = Timer('"".join(data)', setup % ('a', 10**i)) ... print min(t1.repeat(number=1)), # note fewer iterations ... print min(t2.repeat(number=1)) ... 0.031229019165 0.000817060470581 2.45445990562 0.00365781784058 1024.79705095 0.0398509502411 This is absolutely catastrophic performance degradation. -- Steven From davea at ieee.org Sat Mar 27 06:18:40 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 27 Mar 2010 05:18:40 -0500 Subject: Traversing through Dir() In-Reply-To: References: Message-ID: <4BADDB80.90003@ieee.org> Andrej Mitrovic wrote: > On Mar 26, 9:18 am, "Alf P. Steinbach" wrote: > >> >> hierarchy =nspect.getclasstree( classes ) >> # 'hierarchy' is a list array of tuples and nested list arrays of the same form. >> # The top level is an array of two items, the first item a tuple describing the >> 'object' >> # class, and the second item a list array representing the BaseException hierarchy. >> print_hierarchy( hierarchy[1], level = ) >> >> >> Cheers & hth., >> >> - Alf >> > > Thanks for all of that. And yes, I've noticed I get into infinite > recursions all the time, which is why I was asking if there was a > simple way to do this. I'll have a look at these later. > > Kind regards, > Andrej Mitrovic > > I can't help with the original question, but generally the cure for getting into infinite recursion when traversing a tree with multiple connections is to keep a set() of all visited nodes. Whenever you hit a node a second time, don't visit it or its dependents. It's not hard to add to otherwise working code, and frequently the easiest place is right at the beginning of the recursive function. if new_node in myset: return myset.add(new_node) ...process_this_node... for child in new_node: ...recurse... HTH DaveA From v.harishankar at gmail.com Sat Mar 27 07:06:36 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 27 Mar 2010 11:06:36 +0000 (UTC) Subject: Any examples/documentation for python-newt Message-ID: I am writing a fairly featureful TUI in python and I figured newt is the best lightweight TUI which actually offers widgets. curses is low level and its text editing capabilities are poor while UIs like urwid and stfl too complex for simple programs like the ones I am creating. Could anybody point me to at least a decent example program in newt/snack and I don't mean popcorn.py or peanuts.py. Something that at least shows how to create a basic menu-driven program in the command line with a main menu and implementing several sub menus. Also a bit of explanation of the behaviour of OK and Cancel buttons in standard forms would be of help. So anybody uses newt? Or have people stopped using text based UIs completely? -- -- Harishankar (http://harishankar.org http://literaryforums.org) -- -- Harishankar (http://harishankar.org http://literaryforums.org) From tartley at tartley.com Sat Mar 27 07:28:56 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Sat, 27 Mar 2010 04:28:56 -0700 (PDT) Subject: Classes as namespaces? References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> Message-ID: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> On Mar 26, 6:26?pm, Luis M. Gonz?lez wrote: > On 26 mar, 11:49, kj wrote: > > > What's the word on using "classes as namespaces"? ?E.g. > > > class _cfg(object): > > ? ? spam = 1 > > ? ? jambon = 3 > > ? ? huevos = 2 > > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > I see no problem. > I wouldn't mix English, French and Spanish in the same recipe though... Hey everyone. By coincidence, only yesterday I was wondering about using classes as a way of labeling a block of code, ie. an lightweight alternative to defining a function that would only be called from one location. eg. instead of: x = 1 ((some complex logic)) y = 2 one might like to name the complex block of logic, just to make it readable: x = 1 def account_for_non_square_pixels(x): ((some complex logic)) account_for_non_square_pixels() y = 2 But defining and then calling the function like that is a tad cumbersome. So I was wondering about: x = 1 class account_for_non_square_pixels: ((some complex logic)) y = 2 I don't exactly like this, but I think you can see what I'm getting at. Does this fall down in some way I haven't grasped? Is it as awful an abuse of 'class' as my intuition suggests it is? Is there a way to do it better? From jcd at sdf.lonestar.org Sat Mar 27 07:54:06 2010 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sat, 27 Mar 2010 07:54:06 -0400 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <20100327115406.GA22246@sdf.lonestar.org> On Sat, Mar 27, 2010 at 04:28:56AM -0700, Jonathan Hartley wrote regarding Re: Classes as namespaces?: > > Hey everyone. By coincidence, only yesterday I was wondering about > using classes as a way of labeling a block of code, ie. an lightweight > alternative to defining a function that would only be called from one > location. > > eg. instead of: > > > x = 1 > ((some complex logic)) > y = 2 > > > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? Is it as awful > an abuse of 'class' as my intuition suggests it is? Is there a way to > do it better? > -- > http://mail.python.org/mailman/listinfo/python-list Hmm. I don't like that because it leaves a class polluting your namespace that doesn't behave like a class. Using a function for that purpose doesn't seem as bad, because even if you don't call it again, at least you *could*, and it would behave in an expected fashion. If you're dead-set against calling the chunk of code you just created, and you're using python 2.5 or higher, you might consider creating a no-op context manager: x = 1 with code_block("Account for non square pixels"): ((complex_logic)) y = 2 Though in general, I think refactoring your code to reasonably scoped functions or methods is a better idea. If it's too complex to read in one block, it's probably too complex for one function. From jeanmichel at sequans.com Sat Mar 27 07:54:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sat, 27 Mar 2010 12:54:42 +0100 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <4BADF202.3090704@sequans.com> Jonathan Hartley wrote: > On Mar 26, 6:26 pm, Luis M. Gonz?lez wrote: > >> On 26 mar, 11:49, kj wrote: >> >> >>> What's the word on using "classes as namespaces"? E.g. >>> >>> class _cfg(object): >>> spam = 1 >>> jambon = 3 >>> huevos = 2 >>> >>> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >>> >> I see no problem. >> I wouldn't mix English, French and Spanish in the same recipe though... >> > > > Hey everyone. By coincidence, only yesterday I was wondering about > using classes as a way of labeling a block of code, ie. an lightweight > alternative to defining a function that would only be called from one > location. > > eg. instead of: > > > x = 1 > ((some complex logic)) > y = 2 > > > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? Is it as awful > an abuse of 'class' as my intuition suggests it is? Is there a way to > do it better? > on good way to label part of the code is to simply add comments. You can also find tricks to indent this code block, but I've never seen that before. x=1 # account for non square pixels some complex logic # done y=2 I'm perfectly comfortable using classes for namespaces, 'cause classes implement objects or entities, and a namespaces can easily be designed as a coherent entity. For labelling code that you will not reuse, I'm not sure classes are suitable in the way people may issue a 'WTF' when reading your code. JM From jcd at sdf.lonestar.org Sat Mar 27 08:04:59 2010 From: jcd at sdf.lonestar.org (J. Clifford Dyer) Date: Sat, 27 Mar 2010 08:04:59 -0400 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <20100327120458.GB22246@sdf.lonestar.org> On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes as namespaces?: > > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. > > And yet, I've come across online murky warnings against using > classes as "pseudo-namespaces". Is there some problem that I'm > not seeing with this technique? > > ~K I don't see anything wrong with this, except that I would clean it up in a couple ways. Like other posters, I would give the class a proper class name (Cfg). I also would not assign integers to spam, jambon, or huevos. Instead I would assign each a bare object(). That way you won't get unexpected interactions with other constants outside the class. An object() is equal only to itself. I would also not rule out letting your "pseudo-namespace" grow into a full-fledged class. If you've got a method that makes sense with your class, use it. class Cfg(object): spam = object() jambon = object() huevos = object() def get_animal(self, meat): if meat == self.jambon: return 'pig' elif meat == self.huevos: return 'chicken' elif meat = self.spam: return 'spamalope' Later, perhaps, you might refactor so that each meat type (OK so huevos aren't a meat) gets its own subclass, with a simple, one-line get_animal method. Cheers, Cliff From steve at holdenweb.com Sat Mar 27 08:22:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Mar 2010 08:22:17 -0400 Subject: Classes as namespaces? In-Reply-To: <20100327120458.GB22246@sdf.lonestar.org> References: <20100327120458.GB22246@sdf.lonestar.org> Message-ID: J. Clifford Dyer wrote: > On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes > as namespaces?: >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): spam = 1 jambon = 3 huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> [...] > I also would not assign integers to spam, jambon, or huevos. Instead > I would assign each a bare object(). That way you won't get > unexpected interactions with other constants outside the class. An > object() is equal only to itself. > It also has the advantage (?) that you can use "is" (identity) comparisons rather than testing for equality, though this is only a readability issue, I suspect. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Sat Mar 27 08:42:07 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sat, 27 Mar 2010 13:42:07 +0100 Subject: Automatic import ? In-Reply-To: References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <4BADFD1F.5000405@sequans.com> C. B. wrote: > [snip] > It takes time to write the relative importations, that's ok, but I > think it could be more pleasant for the end-user to not have to write > a huge list of "from mymodule import xxx" if it is possible to take > advantage of automatic importations. > > Cheers, > In that particular case, replace automatic by implicit, and you got the reason why it is not a good idea. Maybe in your case the C habits clashes to the python habits. Talking about python, if the user needs to know about BBB, then it has to import it, perdiod. If the user needs to know about many objects, then it has to import them all, explicitly. However it looks like all your objects belong to the same module, quoting MRAB: " Couldn't you just have: import mymodule as m and then use: m.AAA m.BBB " You don't like prefixing your object with the namespace they belong to ? Well, you should :o) JM PS : I would'n have renamed the module, but that falls into personal preferences. From ethan at stoneleaf.us Sat Mar 27 09:13:01 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 27 Mar 2010 06:13:01 -0700 Subject: Simple Traits Message-ID: <4BAE045D.3080604@stoneleaf.us> Wow. I just stumbled across one of Michele Simionato's offerings, called simple traits (strait for short) which looks *really* cool. You can find it here: http://pypi.python.org/pypi/strait/0.5.1 Extremely quick summary: Instead of multiple inheritance, with it's range of problems, use single inheritance for the basics, and include traits for various extra functionality that you want your class to have. As a side note, one of his blog entries at Artima talks about using composition instead of mixins when constructing a class, e.g. by doing: class foo(object): import baz def __init__(self): self.baz.do_something() which has the benefit (over mixins) of avoiding name-space pollution, as well as being able to tell where your methods are coming from. The cool thing (to me, at least) was the realization of being able to use import statements in class construction. Thanks, Michele!! ~Ethan~ From ethan at stoneleaf.us Sat Mar 27 09:19:02 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 27 Mar 2010 06:19:02 -0700 Subject: Simple Traits Questions Message-ID: <4BAE05C6.4070601@stoneleaf.us> Okay, different post for my actual questions. :) On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) it has the example of choosing which methods to keep in the composed class: class TOSWidget(BaseWidget): __metaclass__ = include(Pack, Place, Grid) info = Pack.info.im_func config = Pack.config.im_func configure = Pack.configure.im_func slaves = Pack.slaves.im_func forget = Pack.forget.im_func propagate = Pack.propagate.im_func My question is: Why use info = Pack.info.im_func instead of info = Pack.info ? Any and all enlightenment appreciated! ~Ethan~ From philip at semanchuk.com Sat Mar 27 09:26:40 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 27 Mar 2010 09:26:40 -0400 Subject: Classes as namespaces? In-Reply-To: <20100327120458.GB22246@sdf.lonestar.org> References: <20100327120458.GB22246@sdf.lonestar.org> Message-ID: On Mar 27, 2010, at 8:04 AM, J. Clifford Dyer wrote: > On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes > as namespaces?: >> >> What's the word on using "classes as namespaces"? E.g. >> >> class _cfg(object): >> spam = 1 >> jambon = 3 >> huevos = 2 >> >> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) >> >> >> Granted, this is not the "intended use" for classes, and therefore >> could be viewed as a misuse ("that's what dictionaries are for", >> etc.). But other than this somewhat academic objection[*], I really >> can see no problem with using classes in this way. >> >> And yet, I've come across online murky warnings against using >> classes as "pseudo-namespaces". Is there some problem that I'm >> not seeing with this technique? >> >> ~K > > I don't see anything wrong with this, except that I would clean it > up in a couple ways. Like other posters, I would give the class a > proper class name (Cfg). > > I also would not assign integers to spam, jambon, or huevos. > Instead I would assign each a bare object(). That way you won't get > unexpected interactions with other constants outside the class. An > object() is equal only to itself. What I like about this method is that it will break the bad habit I see in junior programmers of making assumptions about the value of the constant. For instance, if they see that Cfg.JAMBON = 3 and hardcode 3 in their code somewhere, that will work fine until someone re-orders the constants. Using object() instead forces them to use Cfg.JAMBON since the value will (probably) change with every run of the program. It will also discourage bugs-waiting-to-happen like this: if breakfast > Cfg.SPAM: print "Good news, breakfast is jambon or huevos" bye P From ethan at stoneleaf.us Sat Mar 27 09:34:45 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 27 Mar 2010 06:34:45 -0700 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <4BAE0975.1090004@stoneleaf.us> Jonathan Hartley wrote: > Hey everyone. By coincidence, only yesterday I was wondering about > using classes as a way of labeling a block of code, ie. an lightweight > alternative to defining a function that would only be called from one > location. > > eg. instead of: > > > x = 1 > ((some complex logic)) > y = 2 > > > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? Is it as awful > an abuse of 'class' as my intuition suggests it is? Is there a way to > do it better? Both solutions look horrible to me, as both hurt readability. Make your function somewhere else, then call it in the code. Who cares if you only use it once? x = 1 account_for_non_square_pixels() y = 2 Isn't that easier to read? And when you want to (read/change) the complex code, you have an easy place to go to do it. ~Ethan~ From jmheralds at gmail.com Sat Mar 27 09:37:26 2010 From: jmheralds at gmail.com (James Heralds) Date: Sat, 27 Mar 2010 06:37:26 -0700 (PDT) Subject: Call for papers (Deadline Extended): SETP-10, USA, July 2010 Message-ID: It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Call for papers (Deadline Extended): SETP-10, USA, July 2010 The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org ) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. ? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) ? International Conference on Automation, Robotics and Control Systems (ARCS-10) ? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) ? International Conference on Computer Communications and Networks (CCN-10) ? International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) ? International Conference on High Performance Computing Systems (HPCS-10) ? International Conference on Information Security and Privacy (ISP-10) ? International Conference on Image and Video Processing and Computer Vision (IVPCV-10) ? International Conference on Software Engineering Theory and Practice (SETP-10) ? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World? Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining ? all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. Sincerely James Heralds From invalid at invalid.invalid Sat Mar 27 10:44:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Mar 2010 14:44:23 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On 2010-03-27, Harishankar wrote: > I am writing a fairly featureful TUI in python and I figured newt is the > best lightweight TUI which actually offers widgets. curses is low level > and its text editing capabilities are poor while UIs like urwid and stfl > too complex for simple programs like the ones I am creating. > > Could anybody point me to at least a decent example program in newt/snack > and I don't mean popcorn.py or peanuts.py. Something that at least shows > how to create a basic menu-driven program in the command line with a main > menu and implementing several sub menus. Also a bit of explanation of the > behaviour of OK and Cancel buttons in standard forms would be of help. > > So anybody uses newt? Or have people stopped using text based UIs > completely? I've used it for some trivial stuff, but not for anything very sophisticated. Redhat's text-mode installer program (anaconda) was written in Python using Newt (I believe it is why Newt was invented). That's probably the most "full featured" example I know of. -- Grant From v.harishankar at gmail.com Sat Mar 27 10:49:37 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 27 Mar 2010 14:49:37 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On Sat, 27 Mar 2010 14:44:23 +0000, Grant Edwards wrote: > On 2010-03-27, Harishankar wrote: >> I am writing a fairly featureful TUI in python and I figured newt is >> the best lightweight TUI which actually offers widgets. curses is low >> level and its text editing capabilities are poor while UIs like urwid >> and stfl too complex for simple programs like the ones I am creating. >> >> Could anybody point me to at least a decent example program in >> newt/snack and I don't mean popcorn.py or peanuts.py. Something that at >> least shows how to create a basic menu-driven program in the command >> line with a main menu and implementing several sub menus. Also a bit of >> explanation of the behaviour of OK and Cancel buttons in standard forms >> would be of help. >> >> So anybody uses newt? Or have people stopped using text based UIs >> completely? > > I've used it for some trivial stuff, but not for anything very > sophisticated. Redhat's text-mode installer program (anaconda) was > written in Python using Newt (I believe it is why Newt was invented). > That's probably the most "full featured" example I know of. Does your code use forms in an application loop? I am having a bit of trouble with getting the form to stack up properly when I displaying another. As far as I know the two examples uses a single instance of a form which is discarded immediately on exit. If you have even a small code sample I wouldn't mind reading it! -- -- Harishankar (http://harishankar.org http://literaryforums.org) From invalid at invalid.invalid Sat Mar 27 10:56:30 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Mar 2010 14:56:30 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On 2010-03-27, Harishankar wrote: >> I've used it for some trivial stuff, but not for anything very >> sophisticated. Redhat's text-mode installer program (anaconda) was >> written in Python using Newt (I believe it is why Newt was invented). >> That's probably the most "full featured" example I know of. > > Does your code use forms in an application loop? Not really. It uses a series of forms. I don't think I ever stack forms. > I am having a bit of trouble with getting the form to stack up > properly when I displaying another. As far as I know the two examples > uses a single instance of a form which is discarded immediately on > exit. That's pretty much all my program did. > If you have even a small code sample I wouldn't mind reading it! I'm afraid I'm not at liberty to post it. -- Grant From aharrisreid at googlemail.com Sat Mar 27 11:08:09 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sat, 27 Mar 2010 15:08:09 +0000 Subject: Super() function In-Reply-To: <797c8cbd1003242042s32ee16bbxe6d937a16ab35a50@mail.gmail.com> References: <4BAAD5E0.9050604@googlemail.com> <797c8cbd1003242042s32ee16bbxe6d937a16ab35a50@mail.gmail.com> Message-ID: <4BAE1F59.4070800@googlemail.com> ?p wrote: > Hi: > > On 25 March 2010 11:17, Alan Harris-Reid > wrote: > > Hi, > > Using Python 3.1, I sometimes use the super() function to call the > equivalent method from a parent class, for example > > def mymethod(self): > super().mymethod() > some more code... > > Is there any way of writing the code so that the super() call is > generic and automatically recognises the name of the current > method (ie. something like super().thismethod()) or do I always > have to repeat the method name after super()? > > TIA, > Alan > -- > http://mail.python.org/mailman/listinfo/python-list > > > > > I think, the super() method is designed to delegate any method call > to one of the class in its mro list, and the super() function its self > return a 'super' object, so it is better to write what method you want > to delegate, maybe it's not the current method. > > -- > Best wishes from Ray ... Thanks Ray - I'll stick to repeating the method name. Regards, Alan -------------- next part -------------- An HTML attachment was scrubbed... URL: From v.harishankar at gmail.com Sat Mar 27 11:12:57 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sat, 27 Mar 2010 15:12:57 +0000 (UTC) Subject: Any examples/documentation for python-newt References: Message-ID: On Sat, 27 Mar 2010 14:56:30 +0000, Grant Edwards wrote: > On 2010-03-27, Harishankar wrote: > >>> I've used it for some trivial stuff, but not for anything very >>> sophisticated. Redhat's text-mode installer program (anaconda) was >>> written in Python using Newt (I believe it is why Newt was invented). >>> That's probably the most "full featured" example I know of. >> >> Does your code use forms in an application loop? > > Not really. It uses a series of forms. I don't think I ever stack > forms. > >> I am having a bit of trouble with getting the form to stack up properly >> when I displaying another. As far as I know the two examples uses a >> single instance of a form which is discarded immediately on exit. > > That's pretty much all my program did. > >> If you have even a small code sample I wouldn't mind reading it! > > I'm afraid I'm not at liberty to post it. Thanks anyway. I'm taking a look at text.py in the anaconda source code tree here: http://git.fedorahosted.org/git/anaconda.git? p=anaconda.git;a=blob_plain;f=text.py;hb=HEAD I'm afraid it looks as though newt was primarily built to display a series of forms in order, like an installer does, so it is inherently limited by that interface. However, it might still be what I can use... -- Harishankar (http://harishankar.org http://literaryforums.org) From alain at dpt-info.u-strasbg.fr Sat Mar 27 11:17:46 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 27 Mar 2010 16:17:46 +0100 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> Message-ID: <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> Stephen Hansen writes: > Is it possible to get PIL to save GIF's in GIF89A format, instead of > GIF87A? GIF89 was patented. I guess that is why it isn't used by PIL. (The patent has expired now, IIRC.) Anyway, PNG was supposed to replace GIF. > If not, are there any decent other image libraries out there > that anyone's familiar with? The only one I could find was > PythonMagick, which seems completely undocumented. Or I'm blind. I don't know PythonMagick, but it is based on ImageMagick, which is kind of a swiss-knife in image manipulation and conversion. You could try the standalone tools first, to see if you get what you want/need. > But the problem is, I have a nice, small little 72 byte GIF89A file, > that I want to do some slight tweaking on and then re-save. I noticed > that even if I completely skipped the tweaking step and -just- saved, > it exploded into a 919 byte GIF87A file. And in this context, bytes > really, really matter. I picked GIF over PNG because the same file in > PNG was 120 bytes :) [...] >>>> f = open('../tiles/BaseTemplate.gif', 'rb') >>>> d1 = f.read() >>>> len(d1) > 73 >>>> d1 > 'GIF89a\x10\x00\x10\x00[...]' Hmm, a 16x16 image. Don't expect much from the most sophisticated formats (e.g, PNG), because their overhead (headers etc.) may well be above the size of the data. Compression isn't usually targeted at small files. (BTW: "slight tweaking" may have an effect on file-size if it introduces new colors, because GIF uses a color-table. I guess you know all this.) GIF uses the LZW algorithm, and so does zip and gzip (the latter with an additional layer of Huffmann coding). If your images are of fixed size, you _may_ be better off compressing the raw data with a general purpose compressor (i.e., gzip). Check the packages gzip and zlib. -- Alain. From vicente.soler at gmail.com Sat Mar 27 11:24:26 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 27 Mar 2010 08:24:26 -0700 (PDT) Subject: function decorator-like function Message-ID: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> Hi, Still learning Python, now decorators. Before diving deeply into decorators, I'd like to apply a function to another function. My "extremely simple function" should print number 3, then the sum of its 2 arguments. Say that I call f(5,7) I'd like to get, somehow, 3 then 12. I've tried the following: def d(f): print 3 return f def f(a, b): print a+b f=d(f) However, it does not work. Calling f(5,7) only returns 12, (3 is missing) How should I proceed? From pmaupin at gmail.com Sat Mar 27 12:06:40 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 27 Mar 2010 09:06:40 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> Message-ID: <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> On Mar 27, 10:24?am, vsoler wrote: > Hi, > > Still learning Python, now decorators. > > Before diving deeply into decorators, I'd like to apply a function to > another function. > > My "extremely simple function" should print number 3, then the sum of > its 2 arguments. > > Say that I call ? f(5,7) > I'd like to get, somehow, 3 then 12. > > I've tried the following: > > def d(f): > ? ? print 3 > ? ? return f > > def f(a, b): > ? ? print a+b > > f=d(f) > > However, it does not work. Calling f(5,7) only returns 12, (3 is > missing) > How should I proceed? >>> def d(f): ... def wrapper(*args): ... print 3 ... return f(*args) ... return wrapper ... >>> def f(a, b): ... print a + b ... >>> f = d(f) >>> f(5, 7) 3 12 HTH, Pat From lkizer at cfl.rr.com Sat Mar 27 12:21:02 2010 From: lkizer at cfl.rr.com (Larry Kizer) Date: Sat, 27 Mar 2010 12:21:02 -0400 Subject: Ipython(x,y) Won't Run Message-ID: <4bae3040$0$5117$9a6e19ea@unlimited.newshosting.com> I uninstalled my previous version of Python and installed Python(x,y) ver 2.6.2.0 in Windows XP - Install seemed to work fine but when I try to run Ipython(x,y) I get the following error: python.exe has encountered a problem and needs to close. We are sorry for the inconvenience. Any ideas? Thanks. LK From vicente.soler at gmail.com Sat Mar 27 12:21:06 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 27 Mar 2010 09:21:06 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> Message-ID: On 27 mar, 17:06, Patrick Maupin wrote: > On Mar 27, 10:24?am, vsoler wrote: > > > > > Hi, > > > Still learning Python, now decorators. > > > Before diving deeply into decorators, I'd like to apply a function to > > another function. > > > My "extremely simple function" should print number 3, then the sum of > > its 2 arguments. > > > Say that I call ? f(5,7) > > I'd like to get, somehow, 3 then 12. > > > I've tried the following: > > > def d(f): > > ? ? print 3 > > ? ? return f > > > def f(a, b): > > ? ? print a+b > > > f=d(f) > > > However, it does not work. Calling f(5,7) only returns 12, (3 is > > missing) > > How should I proceed? > >>> def d(f): > > ... ? ? def wrapper(*args): > ... ? ? ? ? print 3 > ... ? ? ? ? return f(*args) > ... ? ? return wrapper > ...>>> def f(a, b): > > ... ? ? print a + b > ...>>> f = d(f) > >>> f(5, 7) > > 3 > 12 > > HTH, > Pat Pat, I think some lines are missing. I don't see "d" function defined. Any lines above def wrapper? Thank you From vicente.soler at gmail.com Sat Mar 27 12:24:51 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 27 Mar 2010 09:24:51 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> Message-ID: On 27 mar, 17:21, vsoler wrote: > On 27 mar, 17:06, Patrick Maupin wrote: > > > > > On Mar 27, 10:24?am, vsoler wrote: > > > > Hi, > > > > Still learning Python, now decorators. > > > > Before diving deeply into decorators, I'd like to apply a function to > > > another function. > > > > My "extremely simple function" should print number 3, then the sum of > > > its 2 arguments. > > > > Say that I call ? f(5,7) > > > I'd like to get, somehow, 3 then 12. > > > > I've tried the following: > > > > def d(f): > > > ? ? print 3 > > > ? ? return f > > > > def f(a, b): > > > ? ? print a+b > > > > f=d(f) > > > > However, it does not work. Calling f(5,7) only returns 12, (3 is > > > missing) > > > How should I proceed? > > >>> def d(f): > > > ... ? ? def wrapper(*args): > > ... ? ? ? ? print 3 > > ... ? ? ? ? return f(*args) > > ... ? ? return wrapper > > ...>>> def f(a, b): > > > ... ? ? print a + b > > ...>>> f = d(f) > > >>> f(5, 7) > > > 3 > > 12 > > > HTH, > > Pat > > Pat, > > I think some lines are missing. I don't see "d" function defined. Any > lines above def wrapper? > > Thank you Patrick, I see what happened. The first line was somehow hidden. Thank you very much. Vicente Soler From aharrisreid at googlemail.com Sat Mar 27 12:43:11 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Sat, 27 Mar 2010 16:43:11 +0000 Subject: Super() function In-Reply-To: References: <4BAAD5E0.9050604@googlemail.com> Message-ID: <4BAE359F.6090200@googlemail.com> Gabriel Genellina wrote: >
En Thu, 25 Mar 2010 00:17:52 -0300, Alan > Harris-Reid escribi?: > >> Using Python 3.1, I sometimes use the super() function to call the >> equivalent method from a parent class, for example >> >> def mymethod(self): >> super().mymethod() >> some more code... >> >> Is there any way of writing the code so that the super() call is >> generic and automatically recognises the name of the current method >> (ie. something like super().thismethod()) or do I always have to >> repeat the method name after super()? > > This recipe does what you want: > http://code.activestate.com/recipes/286195-selfsuper/ > (but requires a bit of black magic...) > Hi Gabriel - thanks for the reply. Goodness me - that's a mighty complicated recipe for what I want to achieve! I think I'll stick with repeating the method name - it's a small price to pay. Regards, Alan From james.harris.1 at googlemail.com Sat Mar 27 13:01:34 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sat, 27 Mar 2010 10:01:34 -0700 (PDT) Subject: Python database of plain text editable by notepad or vi References: <93d7991f-d688-4692-b34f-2fa571cebbdf@q15g2000yqj.googlegroups.com> <46822448-2984-4ef6-85c7-bef834e2e86c@r1g2000yqj.googlegroups.com> <3d897b92-9def-4339-ac19-b06b5fb9705e@e6g2000yqh.googlegroups.com> Message-ID: <929d4c9a-ec2d-4b21-ac10-9ae099c040b0@q21g2000yqm.googlegroups.com> On 26 Mar, 14:58, Jon Clements wrote: > On 26 Mar, 09:49, James Harris wrote: ... > > I'm toying with some > > ideas for a way to help generate source code (in various languages, > > not just Python). If it goes ahead the text files would be mainly > > marked-up code snippets - with or without symbols that need to be > > replaced. > > > Rather than write one single monolithic app I thought to split it into > > reusable components. One part being data access could perhaps be an > > existing database (and I'll take a look at jkn's suggestion). > > > Think of the database as similar to an associative array stored on > > disk. The only difference is I may want to play fast and loose with > > the keys in some ways - e.g. check for partial key matches or return a > > list of part-matched keys. The language name could be part of the key > > but I'd also need to store variants for specific language versions. > > I'm not sure yet how it will all pan out. As I say, just throwing > > around some ideas. ... > Thanks for the explanation. No problem. Thanks for taking an interest! > Who admins and, who's editing this data? For the app I have in mind a programmer would admin and edit the files. > I couldn't 100% guarantee that I could modify a text file and always > put the right > delimiter in the right place and remember to escape the relevant chars > (and I'm > probably not the 'average' user). Apart from any markup each file would be just source code or, maybe, individual fragments of source code so there would be few delimiters to get right. And any that were wrong could be detected either by the code writer or the compiler when used. > Any opposition to just putting it in a 'proper' DB, then 'blobbing' > the values? > (or just integrate a procedure/script/function whatever your chosen > RDBMS calls to choose it). > Or in some systems, 'externally referencing'... loads of DB's have > free front-ends, > and there are lots of Python libraries. I've thought of that. Like Ethan, though, I'd prefer simple text for this. Databases, for good reasons, tend to obscure text. For one thing it makes them more secure but it also makes them less transparent and harder to examine and edit. For this app simple text files seem to be the best option at the moment. > > I think perhaps, all I'm saying is, I'd choose a different approach. > I'd provide a front-end, rather than choose to re-write the wheel over > DB's. Agreed. That was my reason for asking the question initially. > Be nice to know how you get on, if you'd be so kind? I don't know yet if it will be feasible but if I do eventually write something I'll report back. James From tjreedy at udel.edu Sat Mar 27 13:10:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Mar 2010 13:10:22 -0400 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: On 3/27/2010 7:28 AM, Jonathan Hartley wrote: > On Mar 26, 6:26 pm, Luis M. Gonz?lez wrote: > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > > > > x = 1 > class account_for_non_square_pixels: > ((some complex logic)) > y = 2 > > > I don't exactly like this, but I think you can see what I'm getting > at. Does this fall down in some way I haven't grasped? The assignments within the class are performed within a new local namespace. So moving non-toy code within a class block will typically fail. From pmaupin at gmail.com Sat Mar 27 14:07:47 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 27 Mar 2010 11:07:47 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> Message-ID: <40ba11d3-5a18-4da4-a48a-0dd815f3b459@35g2000yqm.googlegroups.com> On Mar 27, 11:24?am, vsoler wrote: > I see what happened. The first line was somehow hidden. > Thank you very much. You're welcome. Sorry about the formatting. Also, note that if your decorator is complicated, you might want to use a class instead of a nested function. Here's the same thing, using a class (and using the actual decorator syntax): class d(object): def __init__(self, func): self.func = func def __call__(self, *args): print 3 return self.func(*args) @d def f(a, b): print a + b f(5, 7) Pat From pmaupin at gmail.com Sat Mar 27 14:22:09 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 27 Mar 2010 11:22:09 -0700 (PDT) Subject: Classes as namespaces? References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <8db24743-f293-4f87-b2fa-d86291de2f86@j21g2000yqh.googlegroups.com> On Mar 27, 12:10?pm, Terry Reedy wrote: > On 3/27/2010 7:28 AM, Jonathan Hartley wrote: > > > On Mar 26, 6:26 pm, Luis M. Gonz?lez ?wrote: > > But defining and then calling the function like that is a tad > > cumbersome. So I was wondering about: > > > x = 1 > > class account_for_non_square_pixels: > > ? ?((some complex logic)) > > y = 2 > The assignments within the class are performed within > a new local namespace. I could be misunderstanding, but I think that may be the point. When you have what is basically a bunch of linear logic in Python, sometimes it makes sense to break the logic up into separate namespaces, such that you don't pollute the global namespace too badly (which could cause obscure failures due to inadvertently reusing a variable name which is not properly initialized on the second use). As the OP mentioned, functions are typically used for this, but then you have to decide if you are going to put all your functions above all the rest of the code, or in-line, which is where they belong according to the flow. Either decision has drawbacks -- it is jarring to see functions defined in the middle of a code flow, but it requires extra work to page up and down to see code that is logically in the middle of a code flow, but has been moved out to a sub-function somewhere. > So moving non-toy code within a class block > will typically fail. I think, as with moving non-toy code into a function, the point may be to *force* (more obvious) failures when something is screwed up, rather than allowing the silent failures that can easily occur with a large number of only marginally related variables in one big namespace. I have done what (I think) the OP is suggesting in the distant past. I don't know why I don't do it any more -- perhaps it is more of a comfort thing, or maybe I have gotten better at choosing the right abstraction points for the function boundaries so that I don't always need to read the function code when I am reading the code that invokes it. But in any case, I don't personally think that: a = 27 b = 30 class DoMoreComputation: c = a + b d = DoMoreComputation.c is a terrible, ugly thing, although it is not my current preference. Regards, Pat From andrej.mitrovich at gmail.com Sat Mar 27 15:29:39 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sat, 27 Mar 2010 12:29:39 -0700 (PDT) Subject: Vertical line in function arguments Message-ID: <3d96ca83-7741-483d-8449-d88dc0f445b7@y17g2000yqd.googlegroups.com> There is this peace of code in a 3rd party module: MidiIn.SetFilter(pypm.FILT_ACTIVE | pypm.FILT_CLOCK | pypm.FILT_PITCHBEND | pypm.FILT_NOTE) What are the vertical lines in a function call such as this? This actually calls a function from a Pyrex module that was compiled into a .pyd. Those filters are hex constants, but I've no idea what these vertical lines mean. Is this some form of binary "or" operation? From andrej.mitrovich at gmail.com Sat Mar 27 15:30:53 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sat, 27 Mar 2010 12:30:53 -0700 (PDT) Subject: Vertical line in function arguments References: <3d96ca83-7741-483d-8449-d88dc0f445b7@y17g2000yqd.googlegroups.com> Message-ID: <150eb50d-6117-426b-a014-e6b1662a867e@19g2000yqu.googlegroups.com> Well I hate it when this happens. I ask a question, and literally 2 seconds later I bump into the answer. This explains it a bit: http://docs.python.org/library/stdtypes.html#bit-string-operations-on-integer-types From lie.1296 at gmail.com Sat Mar 27 15:48:21 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 28 Mar 2010 06:48:21 +1100 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4bae6130$1@dnews.tpgi.com.au> On 03/22/2010 07:07 PM, Steven D'Aprano wrote: > Perhaps you should have said that it was a wrapper around deque giving > richer functionality, rather than giving the impression that it was a > brand new data structure invented by you. People are naturally going to > be more skeptical about a newly invented data structure than one based on > a reliable, component like deque. Well, technically StringChain is not a data structure in the first place. StringChain is a string; a string that is implemented using deque data structure to make appending algorithmically efficient. It is not a data structure, in the sense that I can't put arbitrary "thing" into the data structure. In the same sense, "string" is also not a data structure as "string" is an implementation of stream using "array" data structure; "StringChain" is an implementation of stream using "deque" data structure. From jenjenmu at gmail.com Sat Mar 27 17:14:31 2010 From: jenjenmu at gmail.com (knobbyknees) Date: Sat, 27 Mar 2010 14:14:31 -0700 (PDT) Subject: Python Psycopg2 - Interface Error : Connection already closed Message-ID: I'm not sure if this is the right group, but I'm hoping it is... Basically, I'm trying to use pgloader, which depends on python and psycopg2. After banging my head against a wall, I found this: Found this: http://www.mail-archive.com/sqlalchemy at googlegroups.com/msg13209.html Although, the suggestion didn't work for me at all... Running this command: /usr/bin/pgloader -c /var/mybin/pgconfs/fr.conf Yields this in the pgloader.log (with the process just hanging) more /tmp/pgloader.log 27-03-2010 12:22:53 pgloader INFO Logger initialized 27-03-2010 12:22:53 pgloader INFO Reformat path is ['/usr/ share/python-support/pgloader/reformat'] 27-03-2010 12:22:53 pgloader INFO Will consider following sections: 27-03-2010 12:22:53 pgloader INFO fixed 27-03-2010 12:22:54 fixed INFO fixed processing 27-03-2010 12:22:54 pgloader INFO All threads are started, wait for them to terminate 27-03-2010 12:22:57 fixed ERROR connection already closed 27-03-2010 12:22:57 fixed INFO closing current database connection [pgsql] host = localhost port = 5432 base = frdb user = username pass = password [fixed] table = fr format = fixed filename = /var/www/fr.txt ... This is what I see for the traceback: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 847, in run self.terminate() File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 874, in terminate self.db.close() File "/usr/lib/pymodules/python2.6/pgloader/db.py", line 103, in close self.dbconn.close() I'm at a total loss here.... Can anyone please help me out? From nocbos at gmail.com Sat Mar 27 18:39:23 2010 From: nocbos at gmail.com (C. B.) Date: Sat, 27 Mar 2010 15:39:23 -0700 (PDT) Subject: Automatic import ? References: <4d167b6b-04fb-42bb-9c21-ab66d0fb4367@k17g2000yqb.googlegroups.com> Message-ID: <23f6145e-c44d-4d37-8e5e-a98636d4d452@i25g2000yqm.googlegroups.com> > In that particular case, replace automatic by implicit, and you got the > reason why it is not a good idea. > Maybe in your case the C habits clashes to the python habits. > You're right ! As a C developer, I appreciate to only include to deal with strings, without wondering which other header provides size_t definition. > Talking about python, if the user needs to know about BBB, then it has > to import it, perdiod. If the user needs to know about many objects, > then it has to import them all, explicitly. Ok. If this is the Python way of coding, that's ok for me. I will stop now my quest for an automatic import and work like that. The most interesting solution I have found until now is using PyImport_AppendInittab() and PyEval_GetGlobals() functions. But this also brings lots of problems (mainly namespaces and unloading). Anyway, the time spent to look for a solution was a nice way to learn Python internals :) Cheers, From saimapk81 at gmail.com Sat Mar 27 18:51:43 2010 From: saimapk81 at gmail.com (saima81) Date: Sat, 27 Mar 2010 15:51:43 -0700 (PDT) Subject: "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ Message-ID: <7fce4205-a64f-46dd-8066-cdfd45400183@a16g2000pre.googlegroups.com> "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ "jobs in usa for foreigners" "jobs in usa hotels" "jobs in usa for uk citizens" "usa jobs" "usa jobs in afghanistan" "usa jobs application manager" "usa jobs for non us citizens" on http://jobsinusa-net.blogspot.com/ From greg.ewing at canterbury.ac.nz Sat Mar 27 18:56:21 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Mar 2010 10:56:21 +1200 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <817g5kFb3mU1@mid.individual.net> Jonathan Hartley wrote: > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > class account_for_non_square_pixels: > ((some complex logic)) I don't see much advantage -- you're still leaving behind an object that won't be used again. If you're concerned about namespace pollution, there are a couple of ways to clean it up: 1) Delete the function after using it: def account_for_non_square_pixels(x): ... account_for_non_square_pixels() del account_for_non_square_pixels 2) Use __all__ to specify which names you intend to export (doesn't prevent anyone from importing something explicitly, but at least it makes your intention clear, stops irrelevant things appearing in dir() or help(), etc). -- Greg From greg.ewing at canterbury.ac.nz Sat Mar 27 19:40:07 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Mar 2010 11:40:07 +1200 Subject: Classes as namespaces? In-Reply-To: References: Message-ID: <817inlFoj9U1@mid.individual.net> kj wrote: > What's the word on using "classes as namespaces"? My only concern would be that classes do magical things with certain types when you retrieve them as attributes (e.g. functions, property descriptors), so you can't use one as a completely general purpose transparent container. But for enum constants and the like this isn't a problem. If you're up for a bit of hackery, the following code tricks the class statement into producing a module instead of a class: from types import ModuleType class MetaNamespace(ModuleType): def __init__(self, name, bases, dict): ModuleType.__init__(self, name) self.__file__ = __file__ self.__dict__.update(dict) Namespace = MetaNamespace.__new__(MetaNamespace) class Foo(Namespace): ford = 42 arthur = 88 print Foo print Foo.__dict__ -- Greg From robert.kern at gmail.com Sat Mar 27 20:23:51 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Mar 2010 19:23:51 -0500 Subject: Simple Traits Questions In-Reply-To: <4BAE05C6.4070601@stoneleaf.us> References: <4BAE05C6.4070601@stoneleaf.us> Message-ID: On 2010-03-27 08:19 , Ethan Furman wrote: > Okay, different post for my actual questions. :) > > On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) > it has the example of choosing which methods to keep in the composed class: > > class TOSWidget(BaseWidget): > __metaclass__ = include(Pack, Place, Grid) > info = Pack.info.im_func > config = Pack.config.im_func > configure = Pack.configure.im_func > slaves = Pack.slaves.im_func > forget = Pack.forget.im_func > propagate = Pack.propagate.im_func > > My question is: > > Why use > > info = Pack.info.im_func > > instead of > > info = Pack.info > > ? Pack.info is an unbound method object attached to the Pack class, not a function object. It has some extra semantics on top of functions and is tied to the Pack class. The .im_func attribute gets the actual function object underneath. When defining the TOSWidget class, the objects defined in the suite under the class: statement need to be actual functions in order to be turned into unbound methods attached to the TOSWidget class. -- 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 From robert.kern at gmail.com Sat Mar 27 20:25:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Mar 2010 19:25:23 -0500 Subject: Ipython(x,y) Won't Run In-Reply-To: <4bae3040$0$5117$9a6e19ea@unlimited.newshosting.com> References: <4bae3040$0$5117$9a6e19ea@unlimited.newshosting.com> Message-ID: On 2010-03-27 11:21 , Larry Kizer wrote: > I uninstalled my previous version of Python and installed Python(x,y) > ver 2.6.2.0 in Windows XP - Install seemed to work fine but when I try to > run > Ipython(x,y) I get the following error: python.exe has encountered a > problem and needs to close. We are sorry for the inconvenience. > Any ideas? Thanks. You will want to report Python(x,y) bugs here: http://www.pythonxy.com/ -- 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 From apt.shansen at gmail.invalid Sat Mar 27 22:44:54 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Sat, 27 Mar 2010 19:44:54 -0700 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> Message-ID: <2010032719445464825-aptshansen@gmailinvalid> On 2010-03-27 08:17:46 -0700, Alain Ketterlin said: > Stephen Hansen writes: >> If not, are there any decent other image libraries out there >> that anyone's familiar with? The only one I could find was >> PythonMagick, which seems completely undocumented. Or I'm blind. > > I don't know PythonMagick, but it is based on ImageMagick, which is kind > of a swiss-knife in image manipulation and conversion. You could try the > standalone tools first, to see if you get what you want/need. Well, I know it -can- do what I need, except the subprocess business isn't something I want to deal with. And the library seems utterly undocumented. :( > Hmm, a 16x16 image. Don't expect much from the most sophisticated > formats (e.g, PNG), because their overhead (headers etc.) may well be > above the size of the data. Compression isn't usually targeted at small > files. Yeah, I don't expect much from PNG. The images are very small but I might be sending a LOT of them over a pipe which is fairly tight, so 50-60 bytes matters. That's why I selected GIF. > (BTW: "slight tweaking" may have an effect on file-size if it introduces > new colors, because GIF uses a color-table. I guess you know all this.) Yeah, I know this is possible, which is why the tweaking was to be very careful: these images all have only a couple indexed colors each, and I should be able to do the tweaks and not increase the size excessively. However, the problem is: I left out all the tweaks and it still exploded in size. Just opening, and then saving the same file with no changes at all, resulted in a 72 byte file growing to 920. I thought it was GIF87a vs GIF89a... but have since come to determine it doesn't appear to be. I decided to give PNG a try again, since those extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better then 900. Unfortunately, I hit the same wall there. If I convert these itty-bitty images into PNG, they're about 120 bytes or so. Opening one in PNG, making no changes, and saving, results in the new file being 900 bytes too :( So I wonder if there's just some hyper-optimization Photoshop does that PIL can't round-trip. > GIF uses the LZW algorithm, and so does zip and gzip (the latter with an > additional layer of Huffmann coding). If your images are of fixed size, > you _may_ be better off compressing the raw data with a general purpose > compressor (i.e., gzip). Check the packages gzip and zlib. Hm. I hadn't thought of compressing the saved version. I could do that, I suppose: it just seems there is so much extra stuff which shouldn't be needed that's being saved out. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From v.harishankar at gmail.com Sat Mar 27 23:32:16 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 28 Mar 2010 03:32:16 +0000 (UTC) Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: On Sat, 27 Mar 2010 19:44:54 -0700, Stephen Hansen wrote: > On 2010-03-27 08:17:46 -0700, Alain Ketterlin said: > >> Stephen Hansen writes: > >>> If not, are there any decent other image libraries out there that >>> anyone's familiar with? The only one I could find was PythonMagick, >>> which seems completely undocumented. Or I'm blind. >> >> I don't know PythonMagick, but it is based on ImageMagick, which is >> kind of a swiss-knife in image manipulation and conversion. You could >> try the standalone tools first, to see if you get what you want/need. > > Well, I know it -can- do what I need, except the subprocess business > isn't something I want to deal with. And the library seems utterly > undocumented. :( > >> Hmm, a 16x16 image. Don't expect much from the most sophisticated >> formats (e.g, PNG), because their overhead (headers etc.) may well be >> above the size of the data. Compression isn't usually targeted at small >> files. > > Yeah, I don't expect much from PNG. The images are very small but I > might be sending a LOT of them over a pipe which is fairly tight, so > 50-60 bytes matters. That's why I selected GIF. > >> (BTW: "slight tweaking" may have an effect on file-size if it >> introduces new colors, because GIF uses a color-table. I guess you know >> all this.) > > Yeah, I know this is possible, which is why the tweaking was to be very > careful: these images all have only a couple indexed colors each, and I > should be able to do the tweaks and not increase the size excessively. > > However, the problem is: I left out all the tweaks and it still exploded > in size. > > Just opening, and then saving the same file with no changes at all, > resulted in a 72 byte file growing to 920. > > I thought it was GIF87a vs GIF89a... but have since come to determine it > doesn't appear to be. I decided to give PNG a try again, since those > extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better > then 900. Unfortunately, I hit the same wall there. > > If I convert these itty-bitty images into PNG, they're about 120 bytes > or so. Opening one in PNG, making no changes, and saving, results in the > new file being 900 bytes too :( > > So I wonder if there's just some hyper-optimization Photoshop does that > PIL can't round-trip. > >> GIF uses the LZW algorithm, and so does zip and gzip (the latter with >> an additional layer of Huffmann coding). If your images are of fixed >> size, you _may_ be better off compressing the raw data with a general >> purpose compressor (i.e., gzip). Check the packages gzip and zlib. > > Hm. I hadn't thought of compressing the saved version. I could do that, > I suppose: it just seems there is so much extra stuff which shouldn't be > needed that's being saved out. This might not be of much use to you, but I've found by experience that PNGs are almost always bigger or equal to GIFs of the same resolution, colour depth and so on. I've never yet seen a PNG file that is smaller than a GIF for the same set of pixels. As mentioned above, compressing raw data stream might be more beneficial in this situation. Also try the pngcrush utility and see what size it gives you. http://pmt.sourceforge.net/pngcrush/ -- Harishankar (http://harishankar.org http://literaryforums.org) From apt.shansen at gmail.invalid Sun Mar 28 00:31:16 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Sat, 27 Mar 2010 21:31:16 -0700 Subject: Classes as namespaces? References: Message-ID: <2010032721311671584-aptshansen@gmailinvalid> On 2010-03-26 07:49:02 -0700, kj said: > What's the word on using "classes as namespaces"? E.g. > > class _cfg(object): > spam = 1 > jambon = 3 > huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) > > > Granted, this is not the "intended use" for classes, and therefore > could be viewed as a misuse ("that's what dictionaries are for", > etc.). But other than this somewhat academic objection[*], I really > can see no problem with using classes in this way. On the contrary, this is the intended use of classes. Or at least, one of them. A class *is* a namespace, albeit one that you must address explicitly unlike the local and global namespaces which are usually implicit. That said... > [*] My own subjective dislike for the widespread practice of using > triple quotes to comment out code is formally similar to this one > ("the 'intended use' for triple-quoting is not to comment out code", > etc.). Here I find myself on the opposite side of the purist/pragmatic > divide. Hmmm. What?! Where do you get this "widespread practice"? You mentioned that before when you last posted about that and I forgot to comment. I've never seen it. In the 110k lines of in-house code I maintain, we don't use it once; we have somewhere around 300k lines of third-party code from a wide range of sources, and although I haven't reviewed it all by any means, I regularly have to peek over it and I never seen triple quoted "comments". Hell, I almost never see commented -code-. Code should only be commented while fiddling or debugging. Once fiddlng is done, dead code should be removed. I'm sure it -happens- every once in awhile, but.. why? Who uses editors that can't block comment/uncomment anymore? :( -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From sccolbert at gmail.com Sun Mar 28 01:21:18 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 28 Mar 2010 01:21:18 -0400 Subject: GIF89A and PIL In-Reply-To: References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: <7f014ea61003272221t15e84931hf56411ecd00a1cb5@mail.gmail.com> since the images only use a couple colors each, just run length encode it. Depending on the image, you may be able to get a super small size that way, and avoid the whole mess. On Sat, Mar 27, 2010 at 11:32 PM, Harishankar wrote: > On Sat, 27 Mar 2010 19:44:54 -0700, Stephen Hansen wrote: > > > On 2010-03-27 08:17:46 -0700, Alain Ketterlin said: > > > >> Stephen Hansen writes: > > > >>> If not, are there any decent other image libraries out there that > >>> anyone's familiar with? The only one I could find was PythonMagick, > >>> which seems completely undocumented. Or I'm blind. > >> > >> I don't know PythonMagick, but it is based on ImageMagick, which is > >> kind of a swiss-knife in image manipulation and conversion. You could > >> try the standalone tools first, to see if you get what you want/need. > > > > Well, I know it -can- do what I need, except the subprocess business > > isn't something I want to deal with. And the library seems utterly > > undocumented. :( > > > >> Hmm, a 16x16 image. Don't expect much from the most sophisticated > >> formats (e.g, PNG), because their overhead (headers etc.) may well be > >> above the size of the data. Compression isn't usually targeted at small > >> files. > > > > Yeah, I don't expect much from PNG. The images are very small but I > > might be sending a LOT of them over a pipe which is fairly tight, so > > 50-60 bytes matters. That's why I selected GIF. > > > >> (BTW: "slight tweaking" may have an effect on file-size if it > >> introduces new colors, because GIF uses a color-table. I guess you know > >> all this.) > > > > Yeah, I know this is possible, which is why the tweaking was to be very > > careful: these images all have only a couple indexed colors each, and I > > should be able to do the tweaks and not increase the size excessively. > > > > However, the problem is: I left out all the tweaks and it still exploded > > in size. > > > > Just opening, and then saving the same file with no changes at all, > > resulted in a 72 byte file growing to 920. > > > > I thought it was GIF87a vs GIF89a... but have since come to determine it > > doesn't appear to be. I decided to give PNG a try again, since those > > extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better > > then 900. Unfortunately, I hit the same wall there. > > > > If I convert these itty-bitty images into PNG, they're about 120 bytes > > or so. Opening one in PNG, making no changes, and saving, results in the > > new file being 900 bytes too :( > > > > So I wonder if there's just some hyper-optimization Photoshop does that > > PIL can't round-trip. > > > >> GIF uses the LZW algorithm, and so does zip and gzip (the latter with > >> an additional layer of Huffmann coding). If your images are of fixed > >> size, you _may_ be better off compressing the raw data with a general > >> purpose compressor (i.e., gzip). Check the packages gzip and zlib. > > > > Hm. I hadn't thought of compressing the saved version. I could do that, > > I suppose: it just seems there is so much extra stuff which shouldn't be > > needed that's being saved out. > > This might not be of much use to you, but I've found by experience that > PNGs are almost always bigger or equal to GIFs of the same resolution, > colour depth and so on. I've never yet seen a PNG file that is smaller > than a GIF for the same set of pixels. > > As mentioned above, compressing raw data stream might be more beneficial > in this situation. > > Also try the pngcrush utility and see what size it gives you. > http://pmt.sourceforge.net/pngcrush/ > > -- > Harishankar (http://harishankar.org http://literaryforums.org) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at rcn.com Sun Mar 28 02:36:40 2010 From: python at rcn.com (Raymond Hettinger) Date: Sat, 27 Mar 2010 23:36:40 -0700 (PDT) Subject: Classes as namespaces? References: Message-ID: <03b4f91e-39aa-4b97-a510-fa784ad906f6@u5g2000prd.googlegroups.com> On Mar 26, 7:49?am, kj wrote: > What's the word on using "classes as namespaces"? ?E.g. > > class _cfg(object): > ? ? spam = 1 > ? ? jambon = 3 > ? ? huevos = 2 > > breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos) Works for me. Raymond From catalinfest at gmail.com Sun Mar 28 02:59:05 2010 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Sat, 27 Mar 2010 23:59:05 -0700 (PDT) Subject: Encryption source code with md5 Message-ID: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Dear friends . I have two simple questions: It is possible to encrypt with md5 python source code? What option do I have to protect my python source code? Thank you . From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Mar 28 03:22:11 2010 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 28 Mar 2010 07:22:11 +0000 (UTC) Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: Harishankar wrote: > >> Just opening, and then saving the same file with no changes at all, >> resulted in a 72 byte file growing to 920. >> >> I thought it was GIF87a vs GIF89a... but have since come to determine it >> doesn't appear to be. I decided to give PNG a try again, since those >> extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better >> then 900. Unfortunately, I hit the same wall there. >> > Also try the pngcrush utility and see what size it gives you. > http://pmt.sourceforge.net/pngcrush/ > optipng gives slightly better results. Anyway, depending on your pictures, you might find out that using *.ppm.gz, *.pgm.gz or *.pbm.gz outperforms both optimised gif ad png... and if sending more pictures down the line, tar-ing them (*.p?m) and compressing the result will give even better sizes. -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From agoretoy at gmail.com Sun Mar 28 04:15:22 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 28 Mar 2010 02:15:22 -0600 Subject: Encryption source code with md5 In-Reply-To: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: There's not many options when it comes to obfuscating python source. If you even do find a way to obfuscate it. It won't take much to reverse it. That's just how python works. Really I wouldn't even worry about looking for a way to do this, reason behind that is that it's not difficult to reverse it. This is not c,c++, php or java man/woman. Good luck. Thank you, -Alex Goretoy http://launchpad.net/~a1g On Sun, Mar 28, 2010 at 12:59 AM, catalinfest at gmail.com < catalinfest at gmail.com> wrote: > Dear friends . > > I have two simple questions: > It is possible to encrypt with md5 python source code? > What option do I have to protect my python source code? > > Thank you . > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From starglider.dev at gmail.com Sun Mar 28 06:02:03 2010 From: starglider.dev at gmail.com (starglider develop) Date: Sun, 28 Mar 2010 11:02:03 +0100 Subject: Encryption source code with md5 In-Reply-To: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: py2exe On 28 March 2010 07:59, catalinfest at gmail.com wrote: > Dear friends . > > I have two simple questions: > It is possible to encrypt with md5 python source code? > What option do I have to protect my python source code? > > Thank you . > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Sun Mar 28 06:08:22 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sun, 28 Mar 2010 23:08:22 +1300 Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: In message <91541c26-6f18-40c7- a0df-252a52bb7cd5 at l25g2000yqd.googlegroups.com>, catalinfest at gmail.com wrote: > It is possible to encrypt with md5 python source code? Don?t use MD5. > What option do I have to protect my python source code? Copyright. From news1234 at free.fr Sun Mar 28 06:25:36 2010 From: news1234 at free.fr (News123) Date: Sun, 28 Mar 2010 12:25:36 +0200 Subject: Classes as namespaces? In-Reply-To: <2010032721311671584-aptshansen@gmailinvalid> References: <2010032721311671584-aptshansen@gmailinvalid> Message-ID: <4baf2ea0$0$4595$426a74cc@news.free.fr> Hi STephen, Stephen Hansen wrote: > That said... > >> [*] My own subjective dislike for the widespread practice of using >> triple quotes to comment out code is formally similar to this one >> ("the 'intended use' for triple-quoting is not to comment out code", >> etc.). Here I find myself on the opposite side of the purist/pragmatic >> divide. Hmmm. > > What?! > > Where do you get this "widespread practice"? You mentioned that before > when you last posted about that and I forgot to comment. I've never seen > it. I wouldn't say it's wide spread, but definitely something one encounters. Especially with python rather new to python > > In the 110k lines of in-house code I maintain, we don't use it once; we > have somewhere around 300k lines of third-party code from a wide range > of sources, and although I haven't reviewed it all by any means, I > regularly have to peek over it and I never seen triple quoted "comments". > > Hell, I almost never see commented -code-. Code should only be commented > while fiddling or debugging. Once fiddlng is done, dead code should be > removed. > > I'm sure it -happens- every once in awhile, but.. why? Who uses editors > that can't block comment/uncomment anymore? :( I had to explain block comment / uncomment to some collegues before the triple quote commenting disappeared from our code. Unfortunaltely everybody uses a different type of editor, so I googled for them to show them what their editors can do. You'd be surprised how many people do neither master their editors nor care for it. bye N From python at bdurham.com Sun Mar 28 06:48:52 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 28 Mar 2010 06:48:52 -0400 Subject: Programmatically discovering encoding types supported by codecs module In-Reply-To: References: <1269447436.19612.1366507993@webmail.messagingengine.com><1269453527.7192.1366528303@webmail.messagingengine.com> Message-ID: <1269773332.19498.1367099243@webmail.messagingengine.com> Gabriel, Thank you for your analysis - very interesting. Enjoyed your fromlist choice of names. I'm still in my honeymoon phase with Python so I only know the first part :) Regards, Malcolm ----- Original message ----- From: "Gabriel Genellina" To: python-list at python.org Date: Wed, 24 Mar 2010 19:50:11 -0300 Subject: Re: Programmatically discovering encoding types supported by codecs module En Wed, 24 Mar 2010 14:58:47 -0300, escribi?: >> After looking at how things are done in codecs.c and >> encodings/__init__.py I think you should enumerate all modules in the >> encodings package that define a getregentry function. Aliases come from >> encodings.aliases.aliases. > > Thanks for looking into this for me. Benjamin Kaplan made a similar > observation. My reply to him included the snippet of code we're using to > generate the actual list of encodings that our software will support > (thanks to Python's codecs and encodings modules). I was curious as whether both methods would give the same results: py> modules=set() py> for name in glob.glob(os.path.join(encodings.__path__[0], "*.py")): ... name = os.path.basename(name)[:-3] ... try: mod = __import__("encodings."+name, fromlist=['ilovepythonbutsometimesihateit']) ... except ImportError: continue ... if hasattr(mod, 'getregentry'): ... modules.add(name) ... py> fromalias = set(encodings.aliases.aliases.values()) py> fromalias - modules set(['tactis']) py> modules - fromalias set(['charmap', 'cp1006', 'cp737', 'cp856', 'cp874', 'cp875', 'idna', 'iso8859_1', 'koi8_u', 'mac_arabic', 'mac_centeuro', 'mac_croatian', 'mac_farsi', 'mac_romanian', 'palmos', 'punycode', 'raw_unicode_escape', 'string_escape', 'undefined', 'unicode_escape', 'unicode_internal', 'utf_8_sig']) There is a missing 'tactis' encoding (?) and about twenty without alias. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list From arunbgg at gmail.com Sun Mar 28 07:09:05 2010 From: arunbgg at gmail.com (Arun Balagopal) Date: Sun, 28 Mar 2010 16:39:05 +0530 Subject: Need help with using SOAP based web service Message-ID: <29c2bde91003280409y7460ca50oabacec7f1271d0ca@mail.gmail.com> Hi, I am working on a project in text mining using Python. As part of the project I need to use a technical term extractor, and I found the Terminesystem from NACTEM very useful. I have used the web demo (it's pretty nifty) and now want to integrate it in my project. The service provides a SOAP interface, which I am trying to use in Python with the ZSI 2.0 module (I have never used it before). The sample client scripts and instructions for Python are provided here Here's what I did. I installed ZSI 2.0 and its dependency PyXml. Then as given in the instructions, I generated wrappers for the service (2 python files). However when I try to run the sample script, I get errors (something about no attribute 'typecode'). I have tried tweaking in the source, but still no luck. If anybody knows how exactly to get this thing working, please help. I am new to the mailing list, and I apologize if this is the wrong place to post such questions. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From irmen.NOSPAM at xs4all.nl Sun Mar 28 07:17:24 2010 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 28 Mar 2010 13:17:24 +0200 Subject: Encryption source code with md5 In-Reply-To: References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> Message-ID: <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> On 28-3-2010 12:08, Lawrence D'Oliveiro wrote: > In message<91541c26-6f18-40c7- > a0df-252a52bb7cd5 at l25g2000yqd.googlegroups.com>, catalinfest at gmail.com > wrote: > >> It is possible to encrypt with md5 python source code? > > Don?t use MD5. Also, md5 is not an encryption algorithm at all, it is a secure hashing function. (well, not so secure anymore nowadays, which probably is why Lawrence already wrote to avoid using it). irmen From kelithaem at gmail.com Sun Mar 28 07:30:51 2010 From: kelithaem at gmail.com (Rolla) Date: Sun, 28 Mar 2010 04:30:51 -0700 (PDT) Subject: AUTHENTIC DESIGNER HANDBAGS ACCESSORIES GREAT DISCOUNTS! WWW.VOGUELANDE.COM Message-ID: <5820a042-2e7d-4f3a-a672-cd4a4315a72f@g28g2000prb.googlegroups.com> Dear Customer, We now have NEW ARRIVAL accessories coming. Please check the site as follows, http://www.voguelande.com/ChanelAcce.html http://www.voguelande.com/Accessories.html CONTACT INFO: INFO at VOGUELANDE.COM From zaq2442 at gmail.com Sun Mar 28 08:12:49 2010 From: zaq2442 at gmail.com (=?UTF-8?B?2KfYp9in2KfZhNmI2KfZgdmK?=) Date: Sun, 28 Mar 2010 05:12:49 -0700 (PDT) Subject: =?windows-1256?B?0czhIM3H4+Eg3e0gx+Hf5u3KICEhISDV5tE=?= Message-ID: <0a44111d-e4f8-4822-a4cd-828bb3fa54a8@q15g2000yqj.googlegroups.com> http://www.nb11.net/vb/forumdisplay.php?f=25 From catalinfest at gmail.com Sun Mar 28 09:00:58 2010 From: catalinfest at gmail.com (catalinfest at gmail.com) Date: Sun, 28 Mar 2010 06:00:58 -0700 (PDT) Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: I had a talk about Python and distribution of commercial products created with python. This made me think of a way to protect my source code to be distributed. I thought a live CD version and then to an encryption method of a portion of source code. These thoughts are the source of two questions. From l.quesada at 4c.ucc.ie Sun Mar 28 09:26:43 2010 From: l.quesada at 4c.ucc.ie (Luis Quesada) Date: Sun, 28 Mar 2010 14:26:43 +0100 Subject: map, index Message-ID: Dear all, I am new to Python, so I apologize in advance if you find my questions naive (or if they have been already answered in this forum). 1. What is the most pythonic way of mapping a list where the value each element is mapped to depends on the index of the element. Is there a way of writing the following without using zip: map(lambda (id,v):id*v,zip(range(len(L)),L)) I wonder whether there is something like mapInd in Oz (http://www.mozart-oz.org/documentation/base/list.html) so that you can pass a binary function to map and refer to the index of the element in the body of the given function. It would be cool to be able to simply write: mapInd(lambda id,v:id*v,L) 2. Is there a higher order index function that lets you specify the condition to be met by the returned element. I mean something like: def my_index(f,L,default): for x in L: if f(x):return x return default Thanks in advance for your answer! Cheers, Luis From ethan at stoneleaf.us Sun Mar 28 09:46:36 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 28 Mar 2010 06:46:36 -0700 Subject: Simple Traits Questions In-Reply-To: References: <4BAE05C6.4070601@stoneleaf.us> Message-ID: <4BAF5DBC.7050909@stoneleaf.us> Robert Kern wrote: > On 2010-03-27 08:19 , Ethan Furman wrote: > >> Okay, different post for my actual questions. :) >> >> On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) >> it has the example of choosing which methods to keep in the composed >> class: >> >> class TOSWidget(BaseWidget): >> __metaclass__ = include(Pack, Place, Grid) >> info = Pack.info.im_func >> config = Pack.config.im_func >> configure = Pack.configure.im_func >> slaves = Pack.slaves.im_func >> forget = Pack.forget.im_func >> propagate = Pack.propagate.im_func >> >> My question is: >> >> Why use >> >> info = Pack.info.im_func >> >> instead of >> >> info = Pack.info >> >> ? > > > Pack.info is an unbound method object attached to the Pack class, not a > function object. It has some extra semantics on top of functions and is > tied to the Pack class. The .im_func attribute gets the actual function > object underneath. When defining the TOSWidget class, the objects > defined in the suite under the class: statement need to be actual > functions in order to be turned into unbound methods attached to the > TOSWidget class. Ah, thank you. In Python 3, though, would the Pack.info form be correct? ~Ethan~ From duncan.booth at invalid.invalid Sun Mar 28 09:53:36 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Mar 2010 13:53:36 GMT Subject: map, index References: Message-ID: Luis Quesada wrote: > Is there a way > of writing the following without using zip: > map(lambda (id,v):id*v,zip(range(len(L)),L)) [ id*v for id,v in enumerate(L) ] From steve at holdenweb.com Sun Mar 28 10:08:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 28 Mar 2010 10:08:20 -0400 Subject: Encryption source code with md5 In-Reply-To: References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: catalinfest at gmail.com wrote: > I had a talk about Python and distribution of commercial products > created with python. This made me think of a way to protect my source > code to be distributed. I thought a live CD version and then to an > encryption method of a portion of source code. These thoughts are the > source of two questions. I'd suggest that you don't think about encrypting your source code until you have a rather better handle on encryption technology. Your mention of MD5, a hashing rather than an encryption algorithm, makes it clear that you aren't familiar with the technologies at present. There's nothing wrong with ignorance (I have a more than adequate supply of my own), but in encryption it's *very* easy to make mistakes that render whole systems vulnerable to trivial attack. So you do really need to know what you are doing. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From showell30 at yahoo.com Sun Mar 28 10:16:10 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 07:16:10 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: On Mar 27, 3:18?am, Steven D'Aprano wrote: > On Fri, 26 Mar 2010 07:31:17 -0700, Steve Howell wrote: > > From a purely academic standpoint, I'm not convinced that sum() is > > inefficient in terms of big-O complexity, though. > > > ?showell at showell-laptop:~$ python > > ?Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on > > ?linux2 > > ?>>> class StupidList: > > [...] > > But it's not *sum* that is inefficient, it is sum *with a particular data > structure*. > Yep, the implied context was with particular data structures. > Sure, if you create your own data structure, you can make it as efficient > as you like. Obviously the sum algorithm itself has to perform one > addition per item, or O(N), which scales tolerably well. But each > addition has a cost. If the cost is constant, then sum() as a whole > remains O(N). But if the cost of addition varies with N, sum() degrades > ba > The surprising part of sum() is not that the outer loop to do the sums is O(N). It is hard to imagine any other implementation (without parallelizing it). The mildly surprising part of sum() is that is does add vs. add-in- place, which leads to O(N) vs. O(1) for the inner loop calls, for certain data structures, notably lists, even though none of the intermediate results get used by the caller. For lists, you could make a more efficient variant of sum() that clones the start value and does add-in-place. I could guess pretty confidently that the reason this optimization was never tried is that sum() has always been intended to be used on numerics, since other alternatives exist for strings (join), lists (chain), and hand-coded data classes that support add-in-place (roll- your-own loop). The documentation is pretty clear on the intention that sum() is intended for numbers: http://docs.python.org/library/functions.html#sum Except for strings, the docs are not explicit about efficiency concerns for other data structures, or the fact that the reference implementation does add vs. add-in-place under the hood. http://docs.python.org/library/functions.html#sum From michele.simionato at gmail.com Sun Mar 28 10:17:24 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Sun, 28 Mar 2010 07:17:24 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> <40ba11d3-5a18-4da4-a48a-0dd815f3b459@35g2000yqm.googlegroups.com> Message-ID: <1ea8ca8b-b556-44f1-9af8-75e1f60c5fb1@i25g2000yqm.googlegroups.com> Another option is to use my own decorator module (http:// pypi.python.org/pypi/decorator): from decorator import decorator @decorator def d(func, *args): print 3 return func(*args) @d def f(a, b): print a + b f(5, 7) From l.quesada at 4c.ucc.ie Sun Mar 28 10:34:12 2010 From: l.quesada at 4c.ucc.ie (Luis Quesada) Date: Sun, 28 Mar 2010 15:34:12 +0100 Subject: map, index In-Reply-To: References: Message-ID: Duncan Booth wrote: > Luis Quesada wrote: > >> Is there a way >> of writing the following without using zip: >> map(lambda (id,v):id*v,zip(range(len(L)),L)) > > [ id*v for id,v in enumerate(L) ] Cool! Thanks! Cheers, Luis From v.harishankar at gmail.com Sun Mar 28 10:39:12 2010 From: v.harishankar at gmail.com (Harishankar) Date: Sun, 28 Mar 2010 14:39:12 +0000 (UTC) Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: On Sun, 28 Mar 2010 10:08:20 -0400, Steve Holden wrote: > catalinfest at gmail.com wrote: >> I had a talk about Python and distribution of commercial products >> created with python. This made me think of a way to protect my source >> code to be distributed. I thought a live CD version and then to an >> encryption method of a portion of source code. These thoughts are the >> source of two questions. > > I'd suggest that you don't think about encrypting your source code until > you have a rather better handle on encryption technology. Your mention > of MD5, a hashing rather than an encryption algorithm, makes it clear > that you aren't familiar with the technologies at present. > > There's nothing wrong with ignorance (I have a more than adequate supply > of my own), but in encryption it's *very* easy to make mistakes that > render whole systems vulnerable to trivial attack. So you do really need > to know what you are doing. > > regards > Steve This article offers some good ideas and also sums up some good points *against* code obfuscation. http://stackoverflow.com/questions/261638/how-do-i-protect-python-code Read it and judge whether the benefits of not obfuscating code outweighs the advantages of obfuscating it. -- Harishankar (http://harishankar.org http://literaryforums.org) From steve at REMOVE-THIS-cybersource.com.au Sun Mar 28 10:57:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Mar 2010 14:57:08 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <4baf6e43$0$8756$c3e8da3@news.astraweb.com> On Sun, 28 Mar 2010 07:16:10 -0700, Steve Howell wrote: > The mildly surprising part of sum() is that is does add vs. add-in- > place, which leads to O(N) vs. O(1) for the inner loop calls, for > certain data structures, notably lists, even though none of the > intermediate results get used by the caller. For lists, you could make > a more efficient variant of sum() that clones the start value and does > add-in-place. I have no doubt that you could make a version of sum for lists which is more efficient than the existing one. After all, join more or less does the same sort of thing, and it's very efficient. But don't think that add- in-place is necessarily cheap. List appends are amortized O(1) each; if you are adding M lists of N items each, that gives you O(M*N). It's possible to improve the performance a tad if you can make multiple appends in roughly constant time, which is what list.extend (probably?) does, but only up to a point. Lists are over-allocated, but if you try to add more items than there is room for, you need to make the list bigger, and that means reallocating memory, which could easily be O(N**2) or worse, depending on how good your OS's memory management is. Under Linux, at least by default, malloc will never fail, but there's no guarantee how long it will take to return. If the OOM killer has to start shutting down other applications, and paging more and more memory to disk, eventually malloc will return (or the system will core dump), but it could take a while... -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 28 10:58:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Mar 2010 14:58:18 GMT Subject: Encryption source code with md5 References: <91541c26-6f18-40c7-a0df-252a52bb7cd5@l25g2000yqd.googlegroups.com> <4baf3ac4$0$22903$e4fe514c@news.xs4all.nl> Message-ID: <4baf6e8a$0$8756$c3e8da3@news.astraweb.com> On Sun, 28 Mar 2010 10:08:20 -0400, Steve Holden wrote: > catalinfest at gmail.com wrote: >> I had a talk about Python and distribution of commercial products >> created with python. This made me think of a way to protect my source >> code to be distributed. I thought a live CD version and then to an >> encryption method of a portion of source code. These thoughts are the >> source of two questions. > > I'd suggest that you don't think about encrypting your source code until > you have a rather better handle on encryption technology. Your mention > of MD5, a hashing rather than an encryption algorithm, makes it clear > that you aren't familiar with the technologies at present. Furthermore, you should forget about encrypting your program until you are sure that it is something that needs encrypting. In my experience, most times newbies start waffling on about encrypting their precious code (usually displaying total confusion about encryption technology), it turns out their critical application is something like Notepad only with fewer features. Not that I'm jaded at all. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Mar 28 10:59:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Mar 2010 14:59:18 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> <4bae6130$1@dnews.tpgi.com.au> Message-ID: <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote: > On 03/22/2010 07:07 PM, Steven D'Aprano wrote: >> Perhaps you should have said that it was a wrapper around deque giving >> richer functionality, rather than giving the impression that it was a >> brand new data structure invented by you. People are naturally going to >> be more skeptical about a newly invented data structure than one based >> on a reliable, component like deque. > > Well, technically StringChain is not a data structure in the first > place. StringChain is a string; And strings are data structures, as are arrays and structs. Just because they're simple data structures made directly from primitives rather than rich, complex structures, doesn't mean they're not data structures. > a string that is implemented using deque > data structure to make appending algorithmically efficient. It is not a > data structure, in the sense that I can't put arbitrary "thing" into the > data structure. Any "thing" that can be pickled or serialised can be put into a string. -- Steven From duncan.booth at invalid.invalid Sun Mar 28 11:17:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 28 Mar 2010 15:17:46 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: Steve Howell wrote: > The mildly surprising part of sum() is that is does add vs. add-in- > place, which leads to O(N) vs. O(1) for the inner loop calls, for > certain data structures, notably lists, even though none of the > intermediate results get used by the caller. For lists, you could > make a more efficient variant of sum() that clones the start value and > does add-in-place. Doing add-in-place isn't the only way to make sum more efficient: if you assume that addition is associative (which of course the builtin sum can't) then you can form partial sums. e.g. instead of calculating: (((((((a + b) + c) + d) + e) + f) + g) + h) you calculate: (((a + b) + (c + d)) + ((e + f) + (g + h))) Obviously this requires more space than the naive sum, but not as much as you might at first expect: you only need to hold log(n) intermediates values at any time. > I could guess pretty confidently that the reason this optimization was > never tried is that sum() has always been intended to be used on > numerics, since other alternatives exist for strings (join), lists > (chain), and hand-coded data classes that support add-in-place (roll- > your-own loop). Doing it this way helps summing lists or strings (though not as much as str.join), but it also helps if you need to sum a long list of similarly sized floats as you'll get a more accurate answer. See http://groups.google.com/group/comp.lang.python/browse_thread/thread/9eda29 faf92f532e/027cef7d4429aa3a for an earlier discussion of this, or just Google comp.lang.python for 'pairwise sum'. Here's the code I posted in that thread: def sumpairs(seq): tmp = [] for i,v in enumerate(seq): if i&1: tmp[-1] = tmp[-1] + v i = i + 1 n = i & -i while n > 2: t = tmp.pop(-1) tmp[-1] = tmp[-1] + t n >>= 1 else: tmp.append(v) while len(tmp) > 1: t = tmp.pop(-1) tmp[-1] = tmp[-1] + t return tmp[0] and I claimed that my Python coded sumpairs function was faster than the builtin sum on a list of lists once you had more than about 210 items. I never did get round to rewriting it in C for a more realistic speed comparison: summing integers my Python version is about 60 times slower than the builtin. From showell30 at yahoo.com Sun Mar 28 11:55:05 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 08:55:05 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> On Mar 28, 8:17?am, Duncan Booth wrote: > Steve Howell wrote: > > The mildly surprising part of sum() is that is does add vs. add-in- > > place, which leads to O(N) vs. O(1) for the inner loop calls, for > > certain data structures, notably lists, even though none of the > > intermediate results get used by the caller. ?For lists, you could > > make a more efficient variant of sum() that clones the start value and > > does add-in-place. > > Doing add-in-place isn't the only way to make sum more efficient: if you > assume that addition is associative (which of course the builtin sum can't) > then you can form partial sums. e.g. instead of calculating: > > ? (((((((a + b) + c) + d) + e) + f) + g) + h) > > you calculate: > > ? (((a + b) + (c + d)) + ((e + f) + (g + h))) > > Obviously this requires more space than the naive sum, but not as much as > you might at first expect: you only need to hold log(n) intermediates > values at any time. > Yep, I did mention in my post that the outer loop does not *have* to be O(N), if you can parallelize it. Apart from reducing intermediates, the divide-and-conquer method does not reduce overall computation time unless you have multiple processors, correct? > > I could guess pretty confidently that the reason this optimization was > > never tried is that sum() has always been intended to be used on > > numerics, since other alternatives exist for strings (join), lists > > (chain), and hand-coded data classes that support add-in-place (roll- > > your-own loop). > > Doing it this way helps summing lists or strings (though not as much as > str.join), but it also helps if you need to sum a long list of similarly > sized floats as you'll get a more accurate answer. > Interesting! That makes sense. The docs for math.fsum() suggest that partial sums are used to maintain precision. http://docs.python.org/library/math.html#math.fsum > Seehttp://groups.google.com/group/comp.lang.python/browse_thread/thread/... > faf92f532e/027cef7d4429aa3a > for an earlier discussion of this, or just Google comp.lang.python for > 'pairwise sum'. > > Here's the code I posted in that thread: > > def sumpairs(seq): > ? ? tmp = [] > ? ? for i,v in enumerate(seq): > ? ? ? ? if i&1: > ? ? ? ? ? ? tmp[-1] = tmp[-1] + v > ? ? ? ? ? ? i = i + 1 > ? ? ? ? ? ? n = i & -i > ? ? ? ? ? ? while n > 2: > ? ? ? ? ? ? ? ? t = tmp.pop(-1) > ? ? ? ? ? ? ? ? tmp[-1] = tmp[-1] + t > ? ? ? ? ? ? ? ? n >>= 1 > ? ? ? ? else: > ? ? ? ? ? ? tmp.append(v) > ? ? while len(tmp) > 1: > ? ? ? ? t = tmp.pop(-1) > ? ? ? ? tmp[-1] = tmp[-1] + t > ? ? return tmp[0] > > and I claimed that my Python coded sumpairs function was faster than the > builtin sum on a list of lists once you had more than about 210 items. > I never did get round to rewriting it in C for a more realistic speed > comparison: summing integers my Python version is about 60 times slower > than the builtin. From wolftracks at invalid.com Sun Mar 28 12:20:21 2010 From: wolftracks at invalid.com (W. eWatson) Date: Sun, 28 Mar 2010 09:20:21 -0700 Subject: Why this Difference in Importing NumPy 1.2 vs 1.4? Message-ID: I wrote a program in Python 2.5 under Win7 and it runs fine using Numpy 1.2 , but not on a colleague's machine who has a slightly newer 2.5 and uses NumPy 1.4. We both use IDLE to execute the program. During import he gets this: >>> Traceback (most recent call last): File "C:\Documents and Settings\HP_Administrator.DavesDesktop\My Documents\Astro\Meteors\NC-FireballReport.py", line 38, in from scipy import stats as stats # scoreatpercentile File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in from stats import * File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in import scipy.special as special File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, in from numpy.testing import NumpyTest ImportError: cannot import name NumpyTest >>> Comments? It looks as though the problem is in NumPy 1.4. If it's either in NumPy or SciPy, how does my colleague back out to an earlier version to agree with mine? Does he just pull down 1.3 or better 1.2 (I use it.), and install it? How does he somehow remove 1.4? Is it as easy as going to IDLE's path browser and removing, under site-packages, numpy? (I'm not sure that's even possible. I don't see a right-click menu.) From showell30 at yahoo.com Sun Mar 28 12:21:59 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 09:21:59 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <4baf6e43$0$8756$c3e8da3@news.astraweb.com> Message-ID: <2af1fb7c-5952-484b-af2a-95ea97b47994@x11g2000prb.googlegroups.com> On Mar 28, 7:57?am, Steven D'Aprano wrote: > On Sun, 28 Mar 2010 07:16:10 -0700, Steve Howell wrote: > > The mildly surprising part of sum() is that is does add vs. add-in- > > place, which leads to O(N) vs. O(1) for the inner loop calls, for > > certain data structures, notably lists, even though none of the > > intermediate results get used by the caller. ?For lists, you could make > > a more efficient variant of sum() that clones the start value and does > > add-in-place. > > I have no doubt that you could make a version of sum for lists which is > more efficient than the existing one. After all, join more or less does > the same sort of thing, and it's very efficient. But don't think that add- > in-place is necessarily cheap. List appends are amortized O(1) each; if > you are adding M lists of N items each, that gives you O(M*N). > O(M*N) is still cheaper than O(M*N*N). > It's possible to improve the performance a tad if you can make multiple > appends in roughly constant time, which is what list.extend (probably?) > does, but only up to a point. Lists are over-allocated, but if you try to > add more items than there is room for, you need to make the list bigger, > and that means reallocating memory, which could easily be O(N**2) or > worse, depending on how good your OS's memory management is. Under Linux, > at least by default, malloc will never fail, but there's no guarantee how > long it will take to return. If the OOM killer has to start shutting down > other applications, and paging more and more memory to disk, eventually > malloc will return (or the system will core dump), but it could take a > while... > Even though extend() obviously has to do memory allocations along the way itself, it is still more efficient than the alternative. No need to speculate, you can measure these methods on your platform: M = 10 N = 1000 def in_place( start = [], sublists = ([[None] * M]) * N ): accum = start[:] for sublist in sublists: accum.extend(sublist) return accum def with_intermediates( start = [], sublists = ([[None] * M]) * N ): accum = start for sublist in sublists: accum = accum + sublist return accum From fhernandezn at gmail.com Sun Mar 28 12:22:23 2010 From: fhernandezn at gmail.com (Fabian Hernandez) Date: Sun, 28 Mar 2010 12:22:23 -0400 Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION In-Reply-To: References: Message-ID: <3be2e7f21003280922t1f248ae6pb68e37caf048dded@mail.gmail.com> 2010/3/27 G.Lowell Krane > Here is the ad i am trying to get Python-list to post ASAP--this weekend. > > Also, in case one of your best applications is not public, and you want to > demonstrate it, do you prefer webex or what do you prefer? > --gary > > ---------- Forwarded message ---------- > From: G.Lowell Krane > Date: Fri, Mar 26, 2010 at 4:26 PM > Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup > To: python-list at python.org > > > TECH ADVISOR (1-3 hrs/wk) WANTED FOR UNUSUAL SOCIAL VENTURE STARTUP > > > This position is for an unusual well advanced (though not yet in beta) > Social Venture Internet Startup that has hopefully figured out a way through > an unusually robust web application to help the 95% of unhappy couples in > the Western Hemisphere who cannot afford or will not trust a marriage > therapist, to save, ensure, deepen their relationships (about 60MM > couples!). The monetization model is initially subscriber (very low fee that > mkt research (harris poll) has shown the majority of these in USA, at least > would like to use this for about $20/mo for at least 3 mo or longer as long > as they felt it was helping at least a little.) Our startup, eCoupleCoach > /ParejasContentas, would in fact be the pioneer of this blue ocean market > using a conceptual advance, and employing a social media as well as "tapping > the wisdom of the best experts" model. > > > Our urgent need now is for someone who is a senior level > developer/programmer to be able to vet three or four of the best web > application teams we have finally found, or at least the one python team we > found (in Bogota, where I, the ceo/founder/head research psychologist, will > be working with them daily to ensure maximum efficiency).** > > *BTW, anyone who has gone through a tough divorce (or whose parents > divorced at a tender age, will probably find this enormously fascinating and > gratifying?an opportunity to turn your lemons into lemonade.* > > Besides the python freelance team ( team, we also have a .net freelance > team, and php company . We might identify a 4th soon. But the priority > now is to vet the python team?one lead developer who has been doing python > on and off (part and fulltime )for several years (but collapsed, 3 years), > and the other developer, about 1 year. The third member of their team is > more of a designer, doing css and html. > > After this vetting, we ideally hope, if you are excited about our potential > and yours with us, that you will want to stay on up to two hours a week (of > course the more you can devote the better if you are interested in any other > challenges) to at least QA the code quality and make sure it is being > dumped at least weekly. > > WHAT WE HAVE GOING FOR US: A lot. Once we hear from you, we will send > detailed backgrounders. > > COMPENSATION: would be negotiable and this could also lead to a highly > responsible high up position once we are funded. > > TO APPLY: PLEASE email me at eCoupleCoach at gmail.com to make initial > contact, and send us your resume. After this we will > Send you detailed backgrounders on who we are and what we have going for > us. > > IN YOUR SIGNATURE (so easy to find): Please also indicate your skype > contact info, for follow up phone conversation, unless you prefer chat, in > which case your chat contact info (preferably google), since I am in > Colombia now and will be till the beta is done, though my partner and VP of > Product Development/Project Manager is in NYC. > > > > > > > Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y > eCoupleCoach) > "Tapping the wisdom of the best experts and the wisest couples (TM)," and > "Making Honesty easier than ever before." > Medellin and Bogota: 300 415 5298 > Skype: garykrane > > "The greatness of a human is to be measured exactly by the degree to which > he has helped his/her fellow human."-Gandhi > "The best things in life are not things" (anon) > > > > > -- > Attentamente, > Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y > eCoupleCoach) > "Tapping the wisdom of the best experts and the wisest couples (TM)," and > "Making Honesty easier than ever before." > Medellin: 300 415 5298 > Skype: garykrane > > "Un ser humano se convierte en una gran exactitud en la medida en la que ?l > trabaja para el bienestar de sus compa?eros " - Mahatma Gandhi > "The greatness of a human is to be measured exactly by the degree to which > he has helped his/her fellow human."-Gandhi > "The best things in life are not things" (anon) > > -- Fabian Hernandez Nieto http://www.sidesoftware.net Linux User # 485518 -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Sun Mar 28 12:26:39 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 09:26:39 -0700 (PDT) Subject: function decorator-like function References: <9935ff3e-ff2f-44b8-83f4-60883b1512ac@k17g2000yqb.googlegroups.com> <90fe2ae8-cf1e-4d89-8b6d-2802874e64b5@e7g2000yqf.googlegroups.com> <40ba11d3-5a18-4da4-a48a-0dd815f3b459@35g2000yqm.googlegroups.com> <1ea8ca8b-b556-44f1-9af8-75e1f60c5fb1@i25g2000yqm.googlegroups.com> Message-ID: On Mar 28, 9:17?am, Michele Simionato wrote: > Another option is to use my own decorator module (http:// > pypi.python.org/pypi/decorator): > > from decorator import decorator > > @decorator > def d(func, *args): > ? ? print 3 > ? ? return func(*args) > > @d > def f(a, b): > ? ? print a + b > > f(5, 7) That looks cool (and I'm glad you mentioned it), but it appeared to me the OP was trying to manually construct the equivalent of a decorator without the "@" syntax, in order to gain an understanding of how decorators work, and for this particular purpose, piling additional magic on top of decorators is probably not helpful :-) Regards, Pat From fhernandezn at gmail.com Sun Mar 28 12:44:56 2010 From: fhernandezn at gmail.com (Fabian Hernandez) Date: Sun, 28 Mar 2010 12:44:56 -0400 Subject: OT: Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION Message-ID: <3be2e7f21003280944i49f4e1a2g6dd199be2e1b3018@mail.gmail.com> ---------- Forwarded message ---------- From: G.Lowell Krane Date: 2010/3/27 Subject: Fwd: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION To: Daniel Arbelaez Cc: arpunk , Fabian Hernandez Here is the ad i am trying to get Python-list to post ASAP--this weekend. Also, in case one of your best applications is not public, and you want to demonstrate it, do you prefer webex or what do you prefer? --gary ---------- Forwarded message ---------- From: G.Lowell Krane Date: Fri, Mar 26, 2010 at 4:26 PM Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup To: python-list at python.org TECH ADVISOR (1-3 hrs/wk) WANTED FOR UNUSUAL SOCIAL VENTURE STARTUP This position is for an unusual well advanced (though not yet in beta) Social Venture Internet Startup that has hopefully figured out a way through an unusually robust web application to help the 95% of unhappy couples in the Western Hemisphere who cannot afford or will not trust a marriage therapist, to save, ensure, deepen their relationships (about 60MM couples!). The monetization model is initially subscriber (very low fee that mkt research (harris poll) has shown the majority of these in USA, at least would like to use this for about $20/mo for at least 3 mo or longer as long as they felt it was helping at least a little.) Our startup, eCoupleCoach /ParejasContentas, would in fact be the pioneer of this blue ocean market using a conceptual advance, and employing a social media as well as "tapping the wisdom of the best experts" model. Our urgent need now is for someone who is a senior level developer/programmer to be able to vet three or four of the best web application teams we have finally found, or at least the one python team we found (in Bogota, where I, the ceo/founder/head research psychologist, will be working with them daily to ensure maximum efficiency).** *BTW, anyone who has gone through a tough divorce (or whose parents divorced at a tender age, will probably find this enormously fascinating and gratifying?an opportunity to turn your lemons into lemonade.* Besides the python freelance team ( team, we also have a .net freelance team, and php company . We might identify a 4th soon. But the priority now is to vet the python team?one lead developer who has been doing python on and off (part and fulltime )for several years (but collapsed, 3 years), and the other developer, about 1 year. The third member of their team is more of a designer, doing css and html. After this vetting, we ideally hope, if you are excited about our potential and yours with us, that you will want to stay on up to two hours a week (of course the more you can devote the better if you are interested in any other challenges) to at least QA the code quality and make sure it is being dumped at least weekly. WHAT WE HAVE GOING FOR US: A lot. Once we hear from you, we will send detailed backgrounders. COMPENSATION: would be negotiable and this could also lead to a highly responsible high up position once we are funded. TO APPLY: PLEASE email me at eCoupleCoach at gmail.com to make initial contact, and send us your resume. After this we will Send you detailed backgrounders on who we are and what we have going for us. IN YOUR SIGNATURE (so easy to find): Please also indicate your skype contact info, for follow up phone conversation, unless you prefer chat, in which case your chat contact info (preferably google), since I am in Colombia now and will be till the beta is done, though my partner and VP of Product Development/Project Manager is in NYC. Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y eCoupleCoach) "Tapping the wisdom of the best experts and the wisest couples (TM)," and "Making Honesty easier than ever before." Medellin and Bogota: 300 415 5298 Skype: garykrane "The greatness of a human is to be measured exactly by the degree to which he has helped his/her fellow human."-Gandhi "The best things in life are not things" (anon) -- Attentamente, Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y eCoupleCoach) "Tapping the wisdom of the best experts and the wisest couples (TM)," and "Making Honesty easier than ever before." Medellin: 300 415 5298 Skype: garykrane "Un ser humano se convierte en una gran exactitud en la medida en la que ?l trabaja para el bienestar de sus compa?eros " - Mahatma Gandhi "The greatness of a human is to be measured exactly by the degree to which he has helped his/her fellow human."-Gandhi "The best things in life are not things" (anon) -- Fabian Hernandez Nieto http://www.sidesoftware.net Linux User # 485518 -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Sun Mar 28 12:46:07 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 09:46:07 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <2eb7e099-6ad5-46f0-abe3-4599231f70f5@z4g2000yqa.googlegroups.com> On Mar 28, 10:17?am, Duncan Booth wrote: > Doing add-in-place isn't the only way to make sum more efficient: if you > assume that addition is associative (which of course the builtin sum can't) > then you can form partial sums. e.g. instead of calculating: ... > > Doing it this way helps summing lists or strings (though not as much as > str.join), but it also helps if you need to sum a long list of similarly > sized floats as you'll get a more accurate answer. Also, partial sums would be a clear winner over add-in-place if someone were dumb^H^H^H^Hnaive enough to use sum() on a long list of tuples :-) From alfps at start.no Sun Mar 28 12:56:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Mar 2010 18:56:26 +0200 Subject: sum for sequences? In-Reply-To: <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: * Steve Howell: > On Mar 28, 8:17 am, Duncan Booth wrote: >> Steve Howell wrote: >>> The mildly surprising part of sum() is that is does add vs. add-in- >>> place, which leads to O(N) vs. O(1) for the inner loop calls, for >>> certain data structures, notably lists, even though none of the >>> intermediate results get used by the caller. For lists, you could >>> make a more efficient variant of sum() that clones the start value and >>> does add-in-place. >> Doing add-in-place isn't the only way to make sum more efficient: if you >> assume that addition is associative (which of course the builtin sum can't) >> then you can form partial sums. e.g. instead of calculating: >> >> (((((((a + b) + c) + d) + e) + f) + g) + h) >> >> you calculate: >> >> (((a + b) + (c + d)) + ((e + f) + (g + h))) >> >> Obviously this requires more space than the naive sum, but not as much as >> you might at first expect: you only need to hold log(n) intermediates >> values at any time. >> > > Yep, I did mention in my post that the outer loop does not *have* to > be O(N), if you can parallelize it. Apart from reducing > intermediates, the divide-and-conquer method does not reduce overall > computation time unless you have multiple processors, correct? > With a single thread of execution it can reduce the time for large integers and custom numerical types, with n the number of final bits, from O(n^2) to O(n log n). I don't think the parallelism here is very relevant for Python. From a more practical point of view, the sum efficiency could be improved by doing the first addition using '+' and the rest using '+=', without changing the behavior. Cheers & hth., - Alf From showell30 at yahoo.com Sun Mar 28 13:21:08 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 10:21:08 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> On Mar 28, 9:56?am, "Alf P. Steinbach" wrote: > * Steve Howell: >> (talking about summing a list of lists) > > ?From a more practical point of view, the sum efficiency could be improved by > doing the first addition using '+' and the rest using '+=', without changing the > behavior. I like that approach, because you don't have to assume that the start object is clonable, although perhaps you need to make that assumption anyway for the case where the list is empty. Here is code that might shed light on Alf's suggested approach: import timeit M = 10 N = 8000 def in_place( start = [], sublists = ([[None] * M]) * N ): # only macro-optimized i = 0 for sublist in sublists: if i == 0: accum = start + sublist i += 1 else: accum.extend(sublist) if i == 0: return 'whatever' # semantics here? return accum def with_intermediates( start = [], sublists = ([[None] * M]) * N ): accum = start for sublist in sublists: accum = accum + sublist return accum t1 = timeit.timeit('in_place()', 'from __main__ import in_place', number=10) t2 = timeit.timeit('with_intermediates()', 'from __main__ import with_intermediates', number=10) print M, N, t1, t2, int(t2 / t1) For N=100, you get a significant speedup (x84): 10 1000 0.00102496147156 0.0867249965668 84 More data: 10 1000 0.00102496147156 0.0867249965668 84 10 2000 0.00211381912231 0.172616004944 81 10 4000 0.00491786003113 0.561800956726 114 10 8000 0.0706541538239 19.9019489288 281 10 16000 0.0161759853363 9.64171791077 596 10 32000 0.0351569652557 43.98346591 1251 From pmaupin at gmail.com Sun Mar 28 13:27:38 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 10:27:38 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: On Mar 28, 11:56?am, "Alf P. Steinbach" wrote: > ?From a more practical point of view, the sum efficiency could be improved by > doing the first addition using '+' and the rest using '+=', without changing the > behavior. Mod parent up!!!! :-) From showell30 at yahoo.com Sun Mar 28 13:34:13 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 10:34:13 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> Message-ID: <0c76b611-c54f-4474-8f45-d745c53f72d0@k5g2000prg.googlegroups.com> On Mar 28, 10:21?am, Steve Howell wrote: > ? ? import timeit > ? ? M = 10 > ? ? N = 8000 > > ? ? def in_place( > ? ? ? ? start = [], > ? ? ? ? sublists = ([[None] * M]) * N > ? ? ? ? ): > ? ? ? ? # only macro-optimized > ? ? ? ? i = 0 > ? ? ? ? for sublist in sublists: > ? ? ? ? ? ? if i == 0: > ? ? ? ? ? ? ? ?accum = start + sublist > ? ? ? ? ? ? ? ?i += 1 > ? ? ? ? ? ? else: > ? ? ? ? ? ? ? ? accum.extend(sublist) FYI I later obtained similar results with the more general: accum += sublist > ? ? ? ? if i == 0: > ? ? ? ? ? ? return 'whatever' # semantics here? > ? ? ? ? return accum > > ? ? def with_intermediates( > ? ? ? ? start = [], > ? ? ? ? sublists = ([[None] * M]) * N > ? ? ? ? ): > ? ? ? ? accum = start > ? ? ? ? for sublist in sublists: > ? ? ? ? ? ? accum = accum + sublist > ? ? ? ? return accum > From pmaupin at gmail.com Sun Mar 28 14:16:25 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Mar 2010 11:16:25 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> <0c76b611-c54f-4474-8f45-d745c53f72d0@k5g2000prg.googlegroups.com> Message-ID: <56cb099a-7757-481e-a316-f9655c3ac03c@k13g2000yqe.googlegroups.com> On Mar 28, 12:34?pm, Steve Howell wrote: > FYI I later obtained similar results with the more general: > ? ? ? ? ? ? ? ? ? accum += sublist Yeah, but you still have to create an object of the correct type for accum. And for summing small lists, that will actually increase the runtime. (Worst case, a list of a single item: you have to create the accum object based on the type of the start value, then do two += into it, for the start value and the first item in the list, vs just doing a single + which automatically creates an object.) Personally, I think the most general approach, if sum were open to enhancements, would be to automatically apply Alf's suggestion of "+" on summing the first item to the start value, and "+=" on subsequent items. Also, you *could* add a parameter to sum(), for example, default "partialsums=False" that would allow the use of partial sums in those cases where that might give better behavior (such as floats and tuples). From showell30 at yahoo.com Sun Mar 28 14:50:09 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 28 Mar 2010 11:50:09 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <88a43c1d-6529-41ea-bdea-21d49d6e2616@v34g2000prd.googlegroups.com> <0c76b611-c54f-4474-8f45-d745c53f72d0@k5g2000prg.googlegroups.com> <56cb099a-7757-481e-a316-f9655c3ac03c@k13g2000yqe.googlegroups.com> Message-ID: <975c7b4e-6c30-40b7-a4da-bcbbeb13e1aa@l5g2000pri.googlegroups.com> On Mar 28, 11:16?am, Patrick Maupin wrote: > On Mar 28, 12:34?pm, Steve Howell wrote: > > > FYI I later obtained similar results with the more general: > > ? ? ? ? ? ? ? ? ? accum += sublist > > Yeah, but you still have to create an object of the correct type for > accum. ? I think you overlooked the surrounding code. Here is the code again: def in_place( start = [], sublists = ([[None] * M]) * N ): # only macro-optimized i = 0 for sublist in sublists: if i == 0: accum = start + sublist i += 1 else: accum += sublist if i == 0: return 'whatever' # semantics here? return accum No need to infer the type. > And for summing small lists, that will actually increase the > runtime. ?(Worst case, a list of a single item: you have to create the > accum object based on the type of the start value, then do two += into > it, for the start value and the first item in the list, vs just doing > a single + which automatically creates an object.) > For small lists, the performance of any sane implementation would probably be so fast as to be negligible, unless you are in a really tight loop. If you are in a tight loop, then your use case probably eventually sums large lists. Even if it doesn't, the slowdown is just a constant. For M=5, I get these results on my machine: M N t1 t2 (t2/t1) 5 1 3.50475311279e-05 3.2901763916e-05 0.938775510204 5 2 2.00271606445e-05 1.59740447998e-05 0.797619047619 5 4 6.79492950439e-05 6.31809234619e-05 0.929824561404 5 8 0.000124931335449 0.000126123428345 1.00954198473 5 64 0.000530958175659 0.00226187705994 4.25999101931 5 1024 0.00262904167175 0.27246594429 103.636981953 t1 = time with add only first element t2 = time with add all elements Very small penalty for small lists, very large gain for large lists. > Personally, I think the most general approach, if sum were open to > enhancements, would be to automatically apply Alf's suggestion of "+" > on summing the first item to the start value, and "+=" on subsequent > items. ? See above. That's the approach I would use as well. From robert.kern at gmail.com Sun Mar 28 15:03:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 28 Mar 2010 14:03:49 -0500 Subject: Simple Traits Questions In-Reply-To: <4BAF5DBC.7050909@stoneleaf.us> References: <4BAE05C6.4070601@stoneleaf.us> <4BAF5DBC.7050909@stoneleaf.us> Message-ID: On 2010-03-28 08:46 , Ethan Furman wrote: > Robert Kern wrote: >> On 2010-03-27 08:19 , Ethan Furman wrote: >> >>> Okay, different post for my actual questions. :) >>> >>> On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) >>> it has the example of choosing which methods to keep in the composed >>> class: >>> >>> class TOSWidget(BaseWidget): >>> __metaclass__ = include(Pack, Place, Grid) >>> info = Pack.info.im_func >>> config = Pack.config.im_func >>> configure = Pack.configure.im_func >>> slaves = Pack.slaves.im_func >>> forget = Pack.forget.im_func >>> propagate = Pack.propagate.im_func >>> >>> My question is: >>> >>> Why use >>> >>> info = Pack.info.im_func >>> >>> instead of >>> >>> info = Pack.info >>> >>> ? >> >> >> Pack.info is an unbound method object attached to the Pack class, not >> a function object. It has some extra semantics on top of functions and >> is tied to the Pack class. The .im_func attribute gets the actual >> function object underneath. When defining the TOSWidget class, the >> objects defined in the suite under the class: statement need to be >> actual functions in order to be turned into unbound methods attached >> to the TOSWidget class. > > Ah, thank you. > > In Python 3, though, would the Pack.info form be correct? Seems so: Python 3.1 (r31:73578, Jun 27 2009, 21:49:46) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class Pack(): ... def info(self, x): ... pass ... >>> Pack.info -- 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 From nytrokiss at gmail.com Sun Mar 28 16:01:38 2010 From: nytrokiss at gmail.com (James Matthews) Date: Sun, 28 Mar 2010 13:01:38 -0700 Subject: Have you embraced Python 3.x yet? In-Reply-To: References: Message-ID: <8a6b8e351003281301s121ed942x9847b4fc7d451f0f@mail.gmail.com> I am still on py 2.6 and since my code is heavy model dependent. I am bound to the most critical ones. Although I would really like if someone could backport some new stuff done with the GIL on 3.2 (they had a nice talk about it at PyCon) On Fri, Mar 26, 2010 at 5:33 PM, geremy condra wrote: > On Fri, Mar 26, 2010 at 9:23 AM, Harishankar > wrote: > > Have you people embraced Python 3.x or still with 2.5 or 2.6? > > > > I personally want to switch over but not too sure how many people are > > using 3.x as opposed to 2 so I want to keep my programs compatible for > > the majority. > > > > -- Hari > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Yes- I write new code in 3.x and backport it PRN. > > Geremy Condra > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.goldwatches.com -- -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sun Mar 28 16:46:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Mar 2010 13:46:40 -0700 Subject: map, index References: Message-ID: <7xeij418en.fsf@ruckus.brouhaha.com> Luis Quesada writes: >> [ id*v for id,v in enumerate(L) ] > Cool! Thanks! If you really want to write that in pointfree style (untested): import itertools, operator ... itertools.starmap(operator.mul, enumerate(L)) For your other question, you could probably do something ugly with ifilter, but it's not worth it. For the style of programming you're interested in, you should read the docs for the itertools module. Python culture in general tends to not be that fond of heavy use of HOF's, since it's very easy to make mistakes with its iterator protocol and with its dynamic type system. From kgo at grant-olson.net Sun Mar 28 16:46:50 2010 From: kgo at grant-olson.net (Grant Olson) Date: Sun, 28 Mar 2010 16:46:50 -0400 Subject: ANN: Pyasm version 0.3 Message-ID: <4BAFC03A.8010707@grant-olson.net> Pyasm is a full-featured dynamic assembler written entirely in Python. By dynamic, I mean that it can be used to generate and execute machine code in python at runtime without requiring the generation of object files and linkage. It essentially allow 'inline' assembly in python modules on x86 platforms. In addition, pyasm can generate COFF format object files, which may be of interest to anyone writing a compiler in python. More details and downloads are available at: http://www.grant-olson.net/python/pyasm The 0.3 release is long overdue. It includes: + A binary installer for python 2.6. The previous binary installer was python 2.4. + Automatic mapping of python structure values in the assembler. For Example, assuming EAX is a pointer to a string, MOV [EAX+PyString_ob_sval],0x42424242 will change the first four letters of the string to B's + The assembler now supports implicit string creation: PUSH 'foo\n\0' + The ability to build and test with the mingw toolset on windows. This previously required an MSVC toolset. Thanks to Markus L?ll for sorting this out. -Grant From no.email at nospam.invalid Sun Mar 28 16:49:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Mar 2010 13:49:32 -0700 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> Message-ID: <7xaats189v.fsf@ruckus.brouhaha.com> Steve Howell writes: > The documentation is pretty clear on the intention that sum() is > intended for numbers: ... I've never been big on the idea of duck-typing addition. Who would have thought that (1,2,3)+(4.5.6) was something other than the vector sum? I think itertools.chain more directly expresses what the OP was trying to do, and is preferable for readability, independently of these performance questions. From philip at semanchuk.com Sun Mar 28 17:43:46 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 28 Mar 2010 17:43:46 -0400 Subject: Python Psycopg2 - Interface Error : Connection already closed In-Reply-To: References: Message-ID: <0A52C506-749F-460D-A660-A72BB793A1E2@semanchuk.com> On Mar 27, 2010, at 5:14 PM, knobbyknees wrote: > I'm not sure if this is the right group, but I'm hoping it is... > > Basically, I'm trying to use pgloader, which depends on python and > psycopg2. After banging my head against a wall, I found this: > > Found this: > http://www.mail-archive.com/sqlalchemy at googlegroups.com/msg13209.html > > Although, the suggestion didn't work for me at all... > > Running this command: > /usr/bin/pgloader -c /var/mybin/pgconfs/fr.conf > > Yields this in the pgloader.log (with the process just hanging) > > more /tmp/pgloader.log > 27-03-2010 12:22:53 pgloader INFO Logger initialized > 27-03-2010 12:22:53 pgloader INFO Reformat path is ['/usr/ > share/python-support/pgloader/reformat'] > 27-03-2010 12:22:53 pgloader INFO Will consider following > sections: > 27-03-2010 12:22:53 pgloader INFO fixed > 27-03-2010 12:22:54 fixed INFO fixed processing > 27-03-2010 12:22:54 pgloader INFO All threads are started, > wait for them to terminate > 27-03-2010 12:22:57 fixed ERROR connection already closed > 27-03-2010 12:22:57 fixed INFO closing current database > connection > > [pgsql] > host = localhost > port = 5432 > base = frdb > user = username > pass = password > > > [fixed] > table = fr > format = fixed > filename = /var/www/fr.txt > ... > > > This is what I see for the traceback: > Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 525, in > __bootstrap_inner > self.run() > File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 847, > in run > self.terminate() > File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 874, > in terminate > self.db.close() > File "/usr/lib/pymodules/python2.6/pgloader/db.py", line 103, in > close > self.dbconn.close() > > > I'm at a total loss here.... Can anyone please help me out? Hi knobbyknees, I can't help you with this problem, but the folks on the psycopg2 mailing list are probably a much better crowd to ask: http://lists.initd.org/mailman/listinfo/psycopg Good luck Philip From tjreedy at udel.edu Sun Mar 28 18:06:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 28 Mar 2010 18:06:21 -0400 Subject: Simple Traits Questions In-Reply-To: <4BAF5DBC.7050909@stoneleaf.us> References: <4BAE05C6.4070601@stoneleaf.us> <4BAF5DBC.7050909@stoneleaf.us> Message-ID: On 3/28/2010 9:46 AM, Ethan Furman wrote: > Robert Kern wrote: >> On 2010-03-27 08:19 , Ethan Furman wrote: >> >>> Okay, different post for my actual questions. :) >>> >>> On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1) >>> it has the example of choosing which methods to keep in the composed >>> class: >>> >>> class TOSWidget(BaseWidget): >>> __metaclass__ = include(Pack, Place, Grid) >>> info = Pack.info.im_func >>> config = Pack.config.im_func >>> configure = Pack.configure.im_func >>> slaves = Pack.slaves.im_func >>> forget = Pack.forget.im_func >>> propagate = Pack.propagate.im_func >>> >>> My question is: >>> >>> Why use >>> >>> info = Pack.info.im_func >>> >>> instead of >>> >>> info = Pack.info >>> >>> ? >> >> >> Pack.info is an unbound method object attached to the Pack class, not >> a function object. It has some extra semantics on top of functions and >> is tied to the Pack class. The .im_func attribute gets the actual >> function object underneath. When defining the TOSWidget class, the >> objects defined in the suite under the class: statement need to be >> actual functions in order to be turned into unbound methods attached >> to the TOSWidget class. > > Ah, thank you. > > In Python 3, though, would the Pack.info form be correct? Yes. One of the simplifications of Py3. From l.quesada at 4c.ucc.ie Sun Mar 28 18:14:31 2010 From: l.quesada at 4c.ucc.ie (Luis Quesada) Date: Sun, 28 Mar 2010 23:14:31 +0100 Subject: map, index In-Reply-To: <7xeij418en.fsf@ruckus.brouhaha.com> References: <7xeij418en.fsf@ruckus.brouhaha.com> Message-ID: <9xQrn.826$I8.164@news.indigo.ie> Paul Rubin wrote: > Luis Quesada writes: >>> [ id*v for id,v in enumerate(L) ] >> Cool! Thanks! > > If you really want to write that in pointfree style (untested): > > import itertools, operator > ... > itertools.starmap(operator.mul, enumerate(L)) > > For your other question, you could probably do something ugly > with ifilter, but it's not worth it. > > For the style of programming you're interested in, you should read the > docs for the itertools module. Python culture in general tends to > not be that fond of heavy use of HOF's, since it's very easy to make > mistakes with its iterator protocol and with its dynamic type system. Thanks a lot for the pointer. Python is rather cool indeed. Cheers, Luis From tdelaney at avaya.com Sun Mar 28 20:58:07 2010 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Mon, 29 Mar 2010 08:58:07 +0800 Subject: Super() function In-Reply-To: <4BAE359F.6090200@googlemail.com> References: <4BAAD5E0.9050604@googlemail.com> <4BAE359F.6090200@googlemail.com> Message-ID: > Gabriel Genellina wrote: >> Alan Harris-Reid escribi?: >> >>> Using Python 3.1, I sometimes use the super() function to call the >>> equivalent method from a parent class, for example >>> >>> def mymethod(self): >>> super().mymethod() >>> some more code... >>> >>> Is there any way of writing the code so that the super() call is >>> generic and automatically recognises the name of the current method >>> (ie. something like super().thismethod()) or do I always have to >>> repeat the method name after super()? >> >> This recipe does what you want: >> http://code.activestate.com/recipes/286195-selfsuper/ >> (but requires a bit of black magic...) >> > Hi Gabriel - thanks for the reply. > > Goodness me - that's a mighty complicated recipe for what I want to achieve! > I think I'll stick with repeating the method name - it's a small price to pay. I wrote that recipe back before Python 3.x supported super() without parameters, and near equivalent functionality was part of the new super PEP as an option. However, Guido decided to go with the much simpler super().attr with no shortcutting. If you think the pure-python version of the recipe is complicated, you should have a look at the performance-optimised Pyrex version ;) Tim Delaney From steven at REMOVE.THIS.cybersource.com.au Sun Mar 28 21:34:54 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 01:34:54 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <7xaats189v.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 28 Mar 2010 13:49:32 -0700, Paul Rubin wrote: > Steve Howell writes: >> The documentation is pretty clear on the intention that sum() is >> intended for numbers: ... > > I've never been big on the idea of duck-typing addition. Who would have > thought that (1,2,3)+(4.5.6) was something other than the vector sum? But your arguments are tuples, not vectors. There are languages which do treat arithmetic operations on vectors as vector operations, as do (e.g.) H-P scientific calculators. That's a fine design choice, and it works for languages where the emphasis is on scientific calculations. But Python is a more generalist language, so in my mind it is more appropriate to treat lists as generic lists, and not numeric vectors: [1, 2, 3] + [4, "a"] => [1, 2, 3, 4, "a"] just as "123" + "4a" => "1234a" -- Steven From keith at nekotaku.com Sun Mar 28 22:14:19 2010 From: keith at nekotaku.com (KB) Date: Sun, 28 Mar 2010 19:14:19 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse Message-ID: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Hi there, I have in the past used PythonWin to write python for COM, and switched to Eclipse. I am getting an error from the IDE saying it does not recognise CoInitialize(): **** import pythoncom pythoncom.CoInitialize() pythoncom.CoUninitialize() **** (red X next to the two bottom lines saying: "Undefined variable from import: CoInitialize") If I open a PyDev/Python Console window in Eclipse, I can type the above, no errors, no problem. I tried removing my Python Interpreter and re-adding/re-building but no change. python 2.5.2 eclipse 3.5.1 pydev 1.5.0 Thanks! From ysj.ray at gmail.com Sun Mar 28 22:25:50 2010 From: ysj.ray at gmail.com (Ray Allen) Date: Mon, 29 Mar 2010 10:25:50 +0800 Subject: Have you embraced Python 3.x yet? In-Reply-To: <8a6b8e351003281301s121ed942x9847b4fc7d451f0f@mail.gmail.com> References: <8a6b8e351003281301s121ed942x9847b4fc7d451f0f@mail.gmail.com> Message-ID: <797c8cbd1003281925q31217cb9q8436a8fe20388ac0@mail.gmail.com> In our company, we still use python-2.5.4, and will be updated to python-2.5.5. I hope we can go to 2.6.x or 3.x, but I'm not sure when. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Sun Mar 28 22:45:32 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 02:45:32 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: On Sun, 28 Mar 2010 18:56:26 +0200, Alf P. Steinbach wrote: > From a more practical point of view, the sum efficiency could be > improved by doing the first addition using '+' and the rest using '+=', > without changing the behavior. But that would change the behaviour. The __iadd__ method is not the same as the __add__ method, and you can't guarantee that they will behave the same -- or even similarly. And what about tuples? And subclasses of list/tuples? How many different types need to be optimized? In practical terms, does anyone actually ever use sum on more than a handful of lists? I don't believe this is more than a hypothetical problem. The primary use case for sum is adding numbers when floating point accuracy is not critical. If you need float accuracy, use math.fsum. If you need to add more than a handful of small lists, don't use sum: just calling extend in a loop is probably fast enough, or use itertools.chain. Trying to turn sum into an all-singing all-dancing function optimised for an ever-increasing number of objects is a fool's errand. The implementation of sum in C is already complex enough: 95 lines, excluding comments, blanks and braces, for something which is a lightweight function with very simple semantics. But if anyone wants to submit a patch to the bug tracker, go right ahead. Without a patch though, I'd say that Python-Dev will consider this a non- issue. -- Steven From jason.scheirer at gmail.com Sun Mar 28 23:16:43 2010 From: jason.scheirer at gmail.com (Jason Scheirer) Date: Sun, 28 Mar 2010 20:16:43 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Message-ID: <03f8158f-cc4e-4e98-a45a-d0749030e877@w29g2000prg.googlegroups.com> On Mar 28, 7:14?pm, KB wrote: > Hi there, > > I have in the past used PythonWin to write python for COM, and > switched to Eclipse. > > I am getting an error from the IDE saying it does not recognise > CoInitialize(): > > **** > import pythoncom > > pythoncom.CoInitialize() > pythoncom.CoUninitialize() > **** > > (red X next to the two bottom lines saying: "Undefined variable from > import: CoInitialize") > > If I open a PyDev/Python Console window in Eclipse, I can type the > above, no errors, no problem. > > I tried removing my Python Interpreter and re-adding/re-building but > no change. > > python 2.5.2 > eclipse 3.5.1 > pydev 1.5.0 > > Thanks! PyDev is probably only looking at functions/classes defined in Python source files and not ones defined in C extensions. To confirm, try typing this in the window: import _ctypes _ctypes._Pointer() If it says that _ctypes._Pointer doesn't exist, then that's obviously the problem. From dieterv at optionexplicit.be Mon Mar 29 01:59:24 2010 From: dieterv at optionexplicit.be (Dieter Verfaillie) Date: Mon, 29 Mar 2010 07:59:24 +0200 Subject: pythoncom.CoInitialize() not recognised in Eclipse In-Reply-To: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Message-ID: <20100329075924.64164i05fobzkdrw@webmail.linuxsystems.be> Quoting KB : > I am getting an error from the IDE saying it does not recognise > CoInitialize(): > > **** > import pythoncom > > pythoncom.CoInitialize() > pythoncom.CoUninitialize() > **** It works out of the box with PyDev 1.5.5.2010030420 on Eclipse 3.5.2 on Windows XP. If nothing seems to work for you, you could try adding pythoncom to the "Forced Builtins" tab of your Python interpreter configuration to see if it helps (restart eclipse after you've done that, sometimes changes to the symbols database don't get picked up without restarting eclipse...) mvg, Dieter ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From gaoxtwarrior at gmail.com Mon Mar 29 02:42:41 2010 From: gaoxtwarrior at gmail.com (Gao) Date: Mon, 29 Mar 2010 14:42:41 +0800 Subject: How to verify a signature using SHA1WithRSA with python Message-ID: I have a public key, and I want to write a method that verify a string which is a signature signed by this public key's private key. And is M2Crypto I can't find algorithm named "SHA1WithRSA" or so . Could anyone help me? From alfps at start.no Mon Mar 29 03:34:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 29 Mar 2010 09:34:07 +0200 Subject: sum for sequences? In-Reply-To: References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: * Steven D'Aprano: > On Sun, 28 Mar 2010 18:56:26 +0200, Alf P. Steinbach wrote: > >> From a more practical point of view, the sum efficiency could be >> improved by doing the first addition using '+' and the rest using '+=', >> without changing the behavior. > > But that would change the behaviour. The __iadd__ method is not the same > as the __add__ method, and you can't guarantee that they will behave the > same -- or even similarly. Hm, I don't think it's documented (except if the reference implementation serves as documentation) which one is currently used. > And what about tuples? And subclasses of list/tuples? How many different > types need to be optimized? Point. One would need to check for availability of '+='. > In practical terms, does anyone actually ever use sum on more than a > handful of lists? I don't believe this is more than a hypothetical > problem. Agreed. Cheers, - Alf From vamsi2123.vgn at gmail.com Mon Mar 29 03:37:44 2010 From: vamsi2123.vgn at gmail.com (vamsi.v) Date: Mon, 29 Mar 2010 13:07:44 +0530 Subject: header intact Message-ID: > > confirm bec6a35eaf702fee07b1542f90784d939bbbebff > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Mon Mar 29 03:41:23 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 29 Mar 2010 19:41:23 +1200 Subject: GIF89A and PIL In-Reply-To: <2010032719445464825-aptshansen@gmailinvalid> References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> Message-ID: <81b39uFggeU1@mid.individual.net> Stephen Hansen wrote: > So I wonder if there's just some hyper-optimization Photoshop does that > PIL can't round-trip. You may find that PIL isn't bothering to compress at all, or only doing it in a very simpleminded way. -- Greg From stephane at harobed.org Mon Mar 29 04:12:09 2010 From: stephane at harobed.org (=?windows-1252?Q?St=E9phane_Klein?=) Date: Mon, 29 Mar 2010 10:12:09 +0200 Subject: =?windows-1252?Q?I=27m_looking_for_html_cleaner=2E_Exa?= =?windows-1252?Q?mple_=3A_convert_=3Ch1=3E=3Cspan=3E=3Cfont=3Emy_?= =?windows-1252?Q?title=3C/font=3E=3C/span=3E=3C/h1=3E_=3D=3E_=3Ch1=3E?= =?windows-1252?Q?my_title=3C/h1=3E=85?= Message-ID: Hi, I work on HTML cleaner. I export OpenOffice.org documents to HTML. Next, I would like clean this HTML export files : * remove comment * remove style * remove dispensable tag * ... some difficulty : * convert

my text foo bar

=>

my text foo par

* convert

my title

=>

my title

to do this process, I use lxml and pyquery. Question : * are there some xml helper tools in Python to do this process ? I've looked for in pypi, I found nothing about it If you confirm than this tools don't exists, I'll maybe publish a helper package to do this "clean" processing. Thanks for your help, Stephane From v.harishankar at gmail.com Mon Mar 29 05:09:42 2010 From: v.harishankar at gmail.com (Harishankar) Date: Mon, 29 Mar 2010 09:09:42 +0000 (UTC) Subject: I'm looking for html cleaner. Example : convert

my title

=>

my =?windows-1251?q?title=3C=2Fh1=3E=85?= References: Message-ID: On Mon, 29 Mar 2010 10:12:09 +0200, St?phane Klein wrote: > Hi, > > I work on HTML cleaner. > > I export OpenOffice.org documents to HTML. Next, I would like clean this > HTML export files : > > * remove comment > * remove style > * remove dispensable tag > * ... > > some difficulty : > > * convert

my text foo bar

=>

my text foo par

> * convert

my title

=>

my > title

> > to do this process, I use lxml and pyquery. > > Question : > > * are there some xml helper tools in Python to do this process ? I've > looked for in pypi, I found nothing about it > > If you confirm than this tools don't exists, I'll maybe publish a helper > package to do this "clean" processing. > > Thanks for your help, > Stephane Take a look at htmllib and HTMLParser (two different modules) in the Python built-in library. In Python 3.x there is one called html.parser You can use this to parse out specific tags from HTML documents. If you want something more advanced, consider using XML. -- Harishankar (http://harishankar.org http://literaryforums.org) From pieter.cogghe at gmail.com Mon Mar 29 05:39:05 2010 From: pieter.cogghe at gmail.com (Yuccaplant) Date: Mon, 29 Mar 2010 02:39:05 -0700 (PDT) Subject: refer to self in a decorator on a class method Message-ID: Hi all, I would like to do something like this: ******************** class HelloWorld (object): def __init__(self,clk): self.clk = clk @always(self.clk.posedge) def sayHello(self): print "%s Hello World!" % now() ******************** Problem is however I can't refer to self in the decorator call. Is there any workarround? thanks a lot, pieter From __peter__ at web.de Mon Mar 29 05:53:51 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Mar 2010 11:53:51 +0200 Subject: refer to self in a decorator on a class method References: Message-ID: Yuccaplant wrote: > Hi all, > > I would like to do something like this: > > ******************** > class HelloWorld (object): > > def __init__(self,clk): > self.clk = clk > > @always(self.clk.posedge) > def sayHello(self): > print "%s Hello World!" % now() > ******************** > > Problem is however I can't refer to self in the decorator call. Is > there any workarround? Pass attribute names: >>> def always(name): ... def always(f): ... def wrapper(self, *args, **kw): ... print attrgetter(name)(self) ... return f(self, *args, **kw) ... return wrapper ... return always ... >>> from operator import attrgetter >>> class A(object): ... def __init__(self, clk): ... self.clk = clk ... @always("clk.posedge") ... def hello(self): ... print "hello world" ... >>> class clk: ... posedge = 42 ... >>> A(clk).hello() 42 hello world There may be better ways depending on your usecase. Peter From cournape at gmail.com Mon Mar 29 06:06:53 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 29 Mar 2010 19:06:53 +0900 Subject: Have you embraced Python 3.x yet? In-Reply-To: <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> Message-ID: <5b8d13221003290306n7580c5dey8111071fbb4c073c@mail.gmail.com> On Sat, Mar 27, 2010 at 5:26 AM, Chris Colbert wrote: > > I won't switch until NumPy and SciPy make the jump. We're almost there, though (mostly thanks to other people's work on Numpy): http://github.com/cournape/scipy3/branches/py3k David From dr.mtarver at ukonline.co.uk Mon Mar 29 06:46:10 2010 From: dr.mtarver at ukonline.co.uk (Mark Tarver) Date: Mon, 29 Mar 2010 03:46:10 -0700 (PDT) Subject: the Python Foundation References: <70db60af-cad4-4385-b199-e181f1e39898@b7g2000yqd.googlegroups.com> Message-ID: <63099700-c0a0-4d9c-b1f1-e872fe52f0cf@y17g2000yqd.googlegroups.com> On 24 Mar, 22:18, "Steve Holden, Chairman, PSF" wrote: > MarkTarver wrote: > >>From the website > > > The Python Software Foundation (PSF) is a 501(c)(3) non-profit > > corporation that > > holds the intellectual property rights behind the Python programming > > language. We manage the open source licensing for Python version 2.1 > > and later and own and protect the trademarks associated with Python. > > > Could somebody explain 'what holding the intellectual property rights' > > means in this context and in what sense PSF manages the licensing and > > protects the trademarks associated with Python? ? This is for my > > education. > > The PSF requires that contributors sign an agreement licensing their > code to us, and allowing us to distribute it under the license of our > choosing (this does not in any way preclude the contributor licensing > the same code to any other party under different terms). > > In this way people who use Python can be relatively sure that the code > is untrammeled by claims of copyright or patent by anyone other than the > PSF, and can therefore use it without fear of losing their rights to do > so because of legal action by third parties. > > We have also registered the trademark "Python" for use in reference to > computer programming languages, thereby ensuring that we can take action > should some ill-advised individual or organization decide to produce > another language with "Python" in its name which we did not feel > conformed sufficiently strictly to the language definition, for instance. > > The PSF has an established policy with regard to the use of its > trademarks, which you can read at > > ?http://www.python.org/psf/trademarks/ > > regards > ?Steve > -- > Steve Holden ? ? ? ?Chairman, Python Software Foundation > See PyCon Talks from Atlanta 2010 ?http://pycon.blip.tv/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ Thankyou to all on this thread for this clarification. I may return and ask some questions if I need further clarification. Mark From pon at iki.fi Mon Mar 29 07:13:49 2010 From: pon at iki.fi (Pasi Oja-Nisula) Date: 29 Mar 2010 11:13:49 GMT Subject: Python magazine Message-ID: Python magazine web site says this: "So, sit back and relax - enjoy your holidays, and come see us again on January 26th, when the new PyMag will launch." Anyone heard any rumours or anything? I quite liked the magazine. Pasi From 1234567890 at vanwingerde.net Mon Mar 29 08:11:57 2010 From: 1234567890 at vanwingerde.net (Jaap van Wingerde) Date: Mon, 29 Mar 2010 05:11:57 -0700 (PDT) Subject: Python magazine References: Message-ID: <88f34d4c-b620-4d8e-9e02-4c42384735b6@35g2000yqm.googlegroups.com> On 29 mrt, 13:13, Pasi Oja-Nisula wrote: > Python magazine web site says this: > "So, sit back and relax - enjoy your holidays, and come see us again on > January 26th, when the new ?PyMag will launch." From ben+python at benfinney.id.au Mon Mar 29 08:43:29 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 29 Mar 2010 23:43:29 +1100 Subject: Have you embraced Python 3.x yet? References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> Message-ID: <878w9bnvri.fsf@benfinney.id.au> David Cournapeau writes: > On Sat, Mar 27, 2010 at 5:26 AM, Chris Colbert wrote: > > I won't switch until NumPy and SciPy make the jump. > > We're almost there, though (mostly thanks to other people's work on > Numpy): > > http://github.com/cournape/scipy3/branches/py3k Are you maintaining separate parallel Python 3 versus Python 2 code bases? If not, what are you doing in that regard? -- \ ?The most common way people give up their power is by thinking | `\ they don't have any.? ?Alice Walker | _o__) | Ben Finney From cournape at gmail.com Mon Mar 29 08:58:17 2010 From: cournape at gmail.com (David Cournapeau) Date: Mon, 29 Mar 2010 21:58:17 +0900 Subject: Have you embraced Python 3.x yet? In-Reply-To: <878w9bnvri.fsf@benfinney.id.au> References: <195c7315-85cc-412d-8ef5-f13314aecaae@33g2000yqj.googlegroups.com> <7f014ea61003261326g3be655d8oefc1f710a6f7ae91@mail.gmail.com> <878w9bnvri.fsf@benfinney.id.au> Message-ID: <5b8d13221003290558w18fa6c94s4605189382148366@mail.gmail.com> On Mon, Mar 29, 2010 at 9:43 PM, Ben Finney wrote: > David Cournapeau writes: > >> On Sat, Mar 27, 2010 at 5:26 AM, Chris Colbert wrote: >> > I won't switch until NumPy and SciPy make the jump. >> >> We're almost there, though (mostly thanks to other people's work on >> Numpy): >> >> http://github.com/cournape/scipy3/branches/py3k > > Are you maintaining separate parallel Python 3 versus Python 2 code > bases? No, we don't have the manpower to have two code bases - the C code handles both versions, and the python 2 code is converted to python 3 "on the fly". We are lucky not to have too much IO / string handling, which are the hard things to handle with 2to3. The hard part was NumPy, because it used the python C api so much. Porting scipy to something somewhat usable was an half-day job, cheers, David From wolftracks at invalid.com Mon Mar 29 09:04:17 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 29 Mar 2010 06:04:17 -0700 Subject: Why this Difference in Importing NumPy 1.2 vs 1.4? In-Reply-To: References: Message-ID: Add/Remove under Control Panel. It's a numpy problem. On 3/28/2010 9:20 AM, W. eWatson wrote: > I wrote a program in Python 2.5 under Win7 and it runs fine using Numpy > 1.2 , but not on a colleague's machine who has a slightly newer 2.5 and > uses NumPy 1.4. We both use IDLE to execute the program. During import > he gets this: > > >>> > Traceback (most recent call last): > File "C:\Documents and Settings\HP_Administrator.DavesDesktop\My > Documents\Astro\Meteors\NC-FireballReport.py", line 38, in > from scipy import stats as stats # scoreatpercentile > File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in > > from stats import * > File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in > > import scipy.special as special > File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22, > in > from numpy.testing import NumpyTest > ImportError: cannot import name NumpyTest > >>> > > Comments? > > It looks as though the problem is in NumPy 1.4. If it's either in NumPy > or SciPy, how does my colleague back out to an earlier version to agree > with mine? Does he just pull down 1.3 or better 1.2 (I use it.), and > install it? How does he somehow remove 1.4? Is it as easy as going to > IDLE's path browser and removing, under site-packages, numpy? (I'm not > sure that's even possible. I don't see a right-click menu.) From slais-www at ucl.ac.uk Mon Mar 29 09:09:48 2010 From: slais-www at ucl.ac.uk (djc) Date: Mon, 29 Mar 2010 14:09:48 +0100 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: Mensanator wrote: > On Mar 26, 2:44 pm, Phlip wrote: >> On Mar 26, 6:14 am, Luis M. Gonz?lez wrote: >> >>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >>> Monkeys everywhere. >>> Sorry for the off topic question, but what does "monkey" mean in a >>> nerdy-geek context?? >>> Luis >> Better at typing than thinking. > > Really? I thought it was more of a reference to Eddington, i.e., given > enough time even a monkey can type out a program. Precisely, given infinite typing and zero thinking... Note also the expression 'talk to the organ grinder not the monkey' and 'a trained monkey could do it' and then there are monkey wrenches, and monkey bikes... and never call the Librarian a monkey -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 29 09:22:06 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 29 Mar 2010 15:22:06 +0200 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: <4bb0a951$0$11311$426a34cc@news.free.fr> djc a ?crit : > > and never call the Librarian a monkey ook ?!? From krister.svanlund at gmail.com Mon Mar 29 09:32:08 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 29 Mar 2010 15:32:08 +0200 Subject: OT: Meaning of "monkey" In-Reply-To: References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> <6eca52f7-0a55-4c96-8144-9face3c88124@15g2000yqi.googlegroups.com> Message-ID: <2cf430a61003290632k1e40eb81r38e8b0a67d6eb3a8@mail.gmail.com> On Mon, Mar 29, 2010 at 3:09 PM, djc wrote: > Mensanator wrote: >> On Mar 26, 2:44 pm, Phlip wrote: >>> On Mar 26, 6:14 am, Luis M. Gonz?lez wrote: >>> >>>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, >>>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >>>> Monkeys everywhere. >>>> Sorry for the off topic question, but what does "monkey" mean in a >>>> nerdy-geek context?? >>>> Luis >>> Better at typing than thinking. >> >> Really? I thought it was more of a reference to Eddington, i.e., given >> enough time even a monkey can type out a program. > > > Precisely, given infinite typing and zero thinking... > > Note also the expression 'talk to the organ ?grinder not the monkey' > > and 'a trained monkey could do it' > > and then there are monkey wrenches, and monkey bikes... > > and never call the Librarian a monkey > The monkeys comes from different places... for example: "The term monkey patch was first used as guerrilla patch, [...], which was referred to as the patches engaging in battle with each other. Since the word guerrilla and gorilla are near-homophones, people started using the incorrect term gorilla patch instead of guerrilla patch. When a developer then created a guerrilla patch they tried very hard to avoid any battles that may ensue due to the patch and the term monkey patch was coined to make the patch sound less forceful." And then there is, as said, monkey wrenches which is utility tools. Codemonkeys, i believe, comes from the infinite monkeys theory. From pierre.gaillard at gmail.com Mon Mar 29 09:44:51 2010 From: pierre.gaillard at gmail.com (Pierre) Date: Mon, 29 Mar 2010 06:44:51 -0700 (PDT) Subject: Matplotlib patches collection + alpha face Message-ID: <7727f7e7-6337-4107-92c3-f5cfb2e90772@q15g2000yqj.googlegroups.com> Hello, I would like to draw on the same axes several patches (rectangle) with different alpha-face (transparency)... Anyone has an idea ? In particular, I would like to use the class PatchCollection but it seems that the alpha property is common to all the patches... Thanks for your help. From debatem1 at gmail.com Mon Mar 29 10:01:28 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 29 Mar 2010 10:01:28 -0400 Subject: How to verify a signature using SHA1WithRSA with python In-Reply-To: References: Message-ID: On Mon, Mar 29, 2010 at 2:42 AM, Gao wrote: > I have a public key, and I want to write a method that verify a string which > is a signature signed by this public key's private key. And is M2Crypto I > can't find algorithm named "SHA1WithRSA" or so . Could anyone help me? > -- > http://mail.python.org/mailman/listinfo/python-list > In OpenSSL you would simply use the EVP_Verify* functions, I don't see that in M2Crypto's documentation though. You may have to use RSA_Verify. If you're not forced to use M2Crypto, you *may* want to check out evpy, which is a set of ctypes bindings for openssl's evp interface and a very easy to use wrapper. It's available at http://gitorious.org/evpy, and will be up for a first release in a few weeks. Geremy Condra From pmaupin at gmail.com Mon Mar 29 10:40:54 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 07:40:54 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> Message-ID: <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> On Mar 28, 9:45?pm, Steven D'Aprano wrote: > And what about tuples? And subclasses of list/tuples? How many different > types need to be optimized? One of the beautiful things about Python is that, for most things, there are few surprises for even new users. "There should be one obvious way to do it" for the user means that, sometimes, under the hood, there are a lot of special cases for the implementers. > In practical terms, does anyone actually ever use sum on more than a > handful of lists? I don't believe this is more than a hypothetical > problem. Right now, it's probably not, because when somebody sums a large list and gets thwacked on the head by the lack of efficiency, they then come here and get thwacked because "everybody knows" they should user itertools or something else; not sum(). > > The primary use case for sum is adding numbers when floating point > accuracy is not critical. If you need float accuracy, use math.fsum. See, I think the very existence of math.fsum() already violates "there should be one obvious way to do it." > But if anyone wants to submit a patch to the bug tracker, go right ahead. > Without a patch though, I'd say that Python-Dev will consider this a non- > issue. Agreed. Wish I had the time to do this sort of cleanup. Regards, Pat From showell30 at yahoo.com Mon Mar 29 11:12:00 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 08:12:00 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> Message-ID: <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> On Mar 29, 7:40?am, Patrick Maupin wrote: > On Mar 28, 9:45?pm, Steven D'Aprano > > wrote: > > And what about tuples? And subclasses of list/tuples? How many different > > types need to be optimized? > > One of the beautiful things about Python is that, for most things, > there are few surprises for even new users. ?"There should be one > obvious way to do it" for the user means that, sometimes, under the > hood, there are a lot of special cases for the implementers. > If nothing else, I think it's reasonably for users to expect symmetry. If you can use "+" to concatentate lists, then it seems reasonable that something spelled "sum" would concatenate lists as well, and in reasonable time. > > In practical terms, does anyone actually ever use sum on more than a > > handful of lists? I don't believe this is more than a hypothetical > > problem. > > Right now, it's probably not, because when somebody sums a large list > and gets thwacked on the head by the lack of efficiency, they then > come here and get thwacked because "everybody knows" they should user > itertools or something else; not sum(). > Indeed. It would be nice if the docs for sum() at least pointed to list(itertools.chain(list_of_lists)), or whatever the most kosher alternative is supposed to be. It only takes a handful of sublists, about ten on my box, to expose the limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's under the hood. It only takes 200 sublists to start getting a 10x degradation in performance. > > The primary use case for sum is adding numbers when floating point > > accuracy is not critical. If you need float accuracy, use math.fsum. > > See, I think the very existence of math.fsum() already violates "there > should be one obvious way to do it." > The nice thing about math.fsum() is that it is at least documented from sum(), although I suspect some users try sum() without even consulting the docs. You could appease all users with an API where the most obvious choice, sum(), never behaves badly, and where users can still call more specialized versions (math.fsum() and friends) directly if they know what they are doing. This goes back to the statement that Patrick makes--under the hood, this means more special cases for implementers, but fewer pitfalls for users. From gareth.sims at googlemail.com Mon Mar 29 11:31:46 2010 From: gareth.sims at googlemail.com (Gryff) Date: Mon, 29 Mar 2010 08:31:46 -0700 (PDT) Subject: Newbie question: Tuples and reading csv files Message-ID: Hi Its been 20 years since I programmed, so I'm stepping back in via Python. However I'm beating my brains on tuples/lists (what I used to know as arrays). I've fooled around with small code snippets and tried a few things, but I can't figure out how to grab elements of tuples ... For example, I'm reading in a small csv file like this: import csv csvfile = open("example.csv") #sniff the dialect dialect = csv.Sniffer().sniff(csvfile.read(1024)) csvfile.seek(0) # get file in using reader method mylist=[] reader = csv.reader(csvfile, dialect) # grab the lines into a reader and pass to mylist for row in reader: mylist.append(row) # now print something out to prove this worked print mylist[:3] and the output I get is: ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'] ['2010-03-05', '224.20', '230.70', '223.80', '228.30', '5051500', '228.30'] ['2010-03-04', '223.00', '228.50', '220.50', '224.50', '4040500', '224.50'] So far so good but not useful. My "mylist" has all the data in there, but I can only figure out how to get each line out!?! -> I want to get access to the individual items in each line. In my bad old days I'd have used an array and grabbed "mylist [row,item]" ...job done. Try as I like and after *lots* of reading around, I can't figure out whether: a) I'm missing something...really...simple b) "You can't do that" (and I should just use numpy and arrays?) c) errrr.... Like I said, basic/newbie question from a programmer who spent 20 years away from it. Cheers Gareth From showell30 at yahoo.com Mon Mar 29 11:34:32 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 08:34:32 -0700 (PDT) Subject: Newbie question: Tuples and reading csv files References: Message-ID: <029f4a90-fbe5-4739-9c1d-f048046e4d9f@k5g2000prg.googlegroups.com> On Mar 29, 8:31?am, Gryff wrote: > Hi > > Its been 20 years since I programmed, so I'm stepping back in via > Python. However I'm beating my brains on tuples/lists (what I used to > know as arrays). I've fooled around with small code snippets and tried > a few things, but I can't figure out how to grab elements of > tuples ... > > For example, I'm reading in a small csv file like this: > > import csv > > csvfile = open("example.csv") > > #sniff the dialect > dialect = csv.Sniffer().sniff(csvfile.read(1024)) > csvfile.seek(0) > > # get file in using reader method > > mylist=[] > reader = csv.reader(csvfile, dialect) > > # grab the lines into a reader and pass to mylist > > for row in reader: > > ? ? mylist.append(row) > > # now print something out to prove this worked > > print mylist[:3] > > and the output I get is: > > ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'] > ['2010-03-05', '224.20', '230.70', '223.80', '228.30', '5051500', > '228.30'] > ['2010-03-04', '223.00', '228.50', '220.50', '224.50', '4040500', > '224.50'] > > So far so good but not useful. My "mylist" has all the data in there, > but I can only figure out how to get each line out!?! > -> I want to get access to the individual items in each line. In my > bad old days I'd have used an array and grabbed "mylist > [row,item]" ...job done. You are not too far: mylist[row][item] If you try that and still get an error (unlikely), be sure to post the exact code you tried and any error messages. From kushal.kumaran+python at gmail.com Mon Mar 29 11:42:37 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Mon, 29 Mar 2010 21:12:37 +0530 Subject: Newbie question: Tuples and reading csv files In-Reply-To: References: Message-ID: <1e364c4e1003290842q1b0f65a4kc09faae19a40f097@mail.gmail.com> On Mon, Mar 29, 2010 at 9:01 PM, Gryff wrote: > Hi > > Its been 20 years since I programmed, so I'm stepping back in via > Python. However I'm beating my brains on tuples/lists (what I used to > know as arrays). I've fooled around with small code snippets and tried > a few things, but I can't figure out how to grab elements of > tuples ... > > For example, I'm reading in a small csv file like this: > > import csv > > csvfile = open("example.csv") > > #sniff the dialect > dialect = csv.Sniffer().sniff(csvfile.read(1024)) > csvfile.seek(0) > > # get file in using reader method > > mylist=[] > reader = csv.reader(csvfile, dialect) > > # grab the lines into a reader and pass to mylist > > for row in reader: > > ? ?mylist.append(row) > > # now print something out to prove this worked > > print mylist[:3] > > and the output I get is: > > ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'] > ['2010-03-05', '224.20', '230.70', '223.80', '228.30', '5051500', > '228.30'] > ['2010-03-04', '223.00', '228.50', '220.50', '224.50', '4040500', > '224.50'] > > So far so good but not useful. My "mylist" has all the data in there, > but I can only figure out how to get each line out!?! > -> I want to get access to the individual items in each line. In my > bad old days I'd have used an array and grabbed "mylist > [row,item]" ...job done. Try as I like and after *lots* of reading > around, I can't figure out whether: > mylist is a list of lists. mylist[0] gives you the first list (the row with the column headings, in your case). You can get the first item in that list by mylist[0][0]. > a) I'm missing something...really...simple > b) "You can't do that" ?(and I should just use numpy and arrays?) > c) errrr.... > > Like I said, basic/newbie question from a programmer who spent 20 > years away from it. > -- regards, kushal From patentsvnc at gmail.com Mon Mar 29 11:50:20 2010 From: patentsvnc at gmail.com (Den) Date: Mon, 29 Mar 2010 08:50:20 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: <5ad930bd-131a-4b7d-99ea-e3258f75449e@a16g2000pre.googlegroups.com> On Mar 26, 6:14?am, Luis M. Gonz?lez wrote: > Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, J?germonkey, > Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... > > Monkeys everywhere. > Sorry for the off topic question, but what does "monkey" mean in a > nerdy-geek context?? > > Luis To go even more off topic, I remember Trunk Monkey commercials. Also, I remember a web site whose intentions was to simulate monkeys typing Shakespeare. They had set up a distributed system where you could contribute your computer to providing random characters, which they compared to a selected set of Shakespeare's plays. Just before the site disappeared (or I lost track of it), they had received strings representing the first maybe 15 or 20 characters of several plays. Den From gareth.sims at googlemail.com Mon Mar 29 11:51:25 2010 From: gareth.sims at googlemail.com (Gryff) Date: Mon, 29 Mar 2010 08:51:25 -0700 (PDT) Subject: Newbie question: Tuples and reading csv files References: <029f4a90-fbe5-4739-9c1d-f048046e4d9f@k5g2000prg.googlegroups.com> Message-ID: *tada!* *enlightenment* Thanks - I figured it was something simple.... :-) From tim at johnsons-web.com Mon Mar 29 12:40:23 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 29 Mar 2010 11:40:23 -0500 Subject: Jython as an alternative to Python Message-ID: FYI: I've used python for years primarily on *nix platforms and primarily for web programming. I'm considering studying a scripting language that uses and accesses java. My first obvious choice would by jython. The following questions could probably be answered by pointers to previous discussions, docs or blogs. 1)What can jython *do* that cannot be done by python. 2)What is the current state of jython as a development community? I.E. is it being upgraded, updated etc. 3)Is the jython community "bound to" the python community? I.E. I don't think python is going to "go away", what happens if jython development "stalls". 4)If someone in this community would consider a java scripting language other than jython, what would it be? And why? 5)Are there issues installing and deploying jython on shared webservers? I.E. Assuming that a dedicated server is one that I have full access to and can install what I please, and a shared server would not afford me such access; is there any trend for "server farms" to install jython? Thanks -- Tim tim at johnsons-web.com http://www.akwebsoft.com From keith at nekotaku.com Mon Mar 29 13:16:40 2010 From: keith at nekotaku.com (KB) Date: Mon, 29 Mar 2010 10:16:40 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> <03f8158f-cc4e-4e98-a45a-d0749030e877@w29g2000prg.googlegroups.com> Message-ID: <9e8fc13f-f8f2-4efa-8900-d19e228f0c99@t9g2000prh.googlegroups.com> On Mar 28, 8:16?pm, Jason Scheirer wrote: > On Mar 28, 7:14?pm, KB wrote: > > > > > Hi there, > > > I have in the past used PythonWin to write python for COM, and > > switched to Eclipse. > > > I am getting an error from the IDE saying it does not recognise > > CoInitialize(): > > > **** > > import pythoncom > > > pythoncom.CoInitialize() > > pythoncom.CoUninitialize() > > **** > > > (red X next to the two bottom lines saying: "Undefined variable from > > import: CoInitialize") > > > If I open a PyDev/Python Console window in Eclipse, I can type the > > above, no errors, no problem. > > > I tried removing my Python Interpreter and re-adding/re-building but > > no change. > > > python 2.5.2 > > eclipse 3.5.1 > > pydev 1.5.0 > > > Thanks! > > PyDev is probably only looking at functions/classes defined in Python > source files and not ones defined in C extensions. > > To confirm, try typing this in the window: > > import _ctypes > _ctypes._Pointer() > > If it says that _ctypes._Pointer doesn't exist, then that's obviously > the problem. No problems at all with the editor recognising the above. Also note that I tried the pythoncom snippet in my OP from the IDE's python console without issue... weird. From keith at nekotaku.com Mon Mar 29 13:50:18 2010 From: keith at nekotaku.com (KB) Date: Mon, 29 Mar 2010 10:50:18 -0700 (PDT) Subject: pythoncom.CoInitialize() not recognised in Eclipse References: <4558b9a2-9d1c-4ec2-b564-9219be6443f2@w39g2000prd.googlegroups.com> Message-ID: On Mar 28, 10:59?pm, "Dieter Verfaillie" wrote: > Quoting KB : > > > I am getting an error from the IDE saying it does not recognise > > CoInitialize(): > > > **** > > import pythoncom > > > pythoncom.CoInitialize() > > pythoncom.CoUninitialize() > > **** > > It works out of the box with PyDev 1.5.5.2010030420 on Eclipse 3.5.2 ? > on Windows XP. If nothing seems to work for you, you could try adding ? > pythoncom to the > "Forced Builtins" tab of your Python interpreter configuration to see if it > helps (restart eclipse after you've done that, sometimes changes to ? > the symbols > database don't get picked up without restarting eclipse...) Dieter, Thanks, I tried updating my PyDev and Eclipse to your versions. Still same issue. How exactly would I add pythoncom to the Forced Builtins ? I tried simply adding "pythoncom" to the Forced Builtin's tab but no change. Any suggestions? From steve at holdenweb.com Mon Mar 29 14:02:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 29 Mar 2010 14:02:04 -0400 Subject: Jython as an alternative to Python In-Reply-To: References: Message-ID: Tim Johnson wrote: > FYI: I've used python for years primarily on *nix platforms and > primarily for web programming. I'm considering studying a scripting > language that uses and accesses java. My first obvious choice would by > jython. The following questions could probably be answered by pointers > to previous discussions, docs or blogs. > > 1)What can jython *do* that cannot be done by python. > Import Java classes and instantiate them, calling their methods from Python. > 2)What is the current state of jython as a development community? > I.E. is it being upgraded, updated etc. > It's currently just about at 2.6, and the developers are committed to a port to 3.x (probably 3.2, I suspect) but haven't yet committed to a timescale. Two of the main developers have just started work at Sauce Labs, and this may affect their availability. > 3)Is the jython community "bound to" the python community? > I.E. I don't think python is going to "go away", what happens if > jython development "stalls". > The PSF has already once provided a grant to keep Jython moving forward when it looked like it might stall. I don't know whether this is inevitable in the future, but *I* think Jython should be kept in the mainstream. > 4)If someone in this community would consider a java scripting language > other than jython, what would it be? And why? > Pass. > 5)Are there issues installing and deploying jython on shared webservers? > I.E. Assuming that a dedicated server is one that I have full access to and > can install what I please, and a shared server would not afford me > such access; is there any trend for "server farms" to install jython? I don't know. A survey of Python-friendly hosting companies would be useful. You could use http://wiki.python.org/moin/PythonHosting as a starting point, and publish the data you discover. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From gagsl-py2 at yahoo.com.ar Mon Mar 29 15:19:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 29 Mar 2010 16:19:18 -0300 Subject: Super() function References: <4BAAD5E0.9050604@googlemail.com> <4BAE359F.6090200@googlemail.com> Message-ID: En Sun, 28 Mar 2010 21:58:07 -0300, Delaney, Timothy (Tim) escribi?: >> Gabriel Genellina wrote: >>> Alan Harris-Reid escribi?: >>> >>>> Using Python 3.1, I sometimes use the super() function to call the >>>> equivalent method from a parent class, for example >>>> >>>> def mymethod(self): >>>> super().mymethod() >>>> some more code... >>> >>> This recipe does what you want: >>> http://code.activestate.com/recipes/286195-selfsuper/ > If you think the pure-python version of the recipe is complicated, you > should have > a look at the performance-optimised Pyrex version ;) Where can we look at it? The link in the activestate recipe does not work anymore :( -- Gabriel Genellina From tim at johnsons-web.com Mon Mar 29 15:40:22 2010 From: tim at johnsons-web.com (Tim Johnson) Date: Mon, 29 Mar 2010 14:40:22 -0500 Subject: Jython as an alternative to Python References: Message-ID: On 2010-03-29, Steve Holden wrote: > Tim Johnson wrote: <<.>> 1)What can jython *do* that cannot be done by python. >> > Import Java classes and instantiate them, calling their methods from Python. Of course >> 2)What is the current state of jython as a development community? >> I.E. is it being upgraded, updated etc. >> > It's currently just about at 2.6, and the developers are committed to a > port to 3.x (probably 3.2, I suspect) but haven't yet committed to a > timescale. Two of the main developers have just started work at Sauce > Labs, and this may affect their availability. That is the news I was looking for. >> 3)Is the jython community "bound to" the python community? >> I.E. I don't think python is going to "go away", what happens if >> jython development "stalls". >> > The PSF has already once provided a grant to keep Jython moving forward > when it looked like it might stall. I don't know whether this is > inevitable in the future, but *I* think Jython should be kept in the > mainstream. Ditto. >> 4)If someone in this community would consider a java scripting language >> other than jython, what would it be? And why? >> > Pass. . I've looked at clojure and kawa since I have a comfort level with lisp dialects, but clojure seems pretty proprietory (and thus exotic). kawa advertises that it complies with the general scheme specification. And I'm a little leery about the 'exotic' since I already use two 'exotic' server - side languages. >> 5)Are there issues installing and deploying jython on shared webservers? >> I.E. Assuming that a dedicated server is one that I have full access to and >> can install what I please, and a shared server would not afford me >> such access; is there any trend for "server farms" to install jython? > > I don't know. A survey of Python-friendly hosting companies would be > useful. You could use Not really a big deal with me, as I work primarily with dedicated servers, but .... > http://wiki.python.org/moin/PythonHosting Not much there. I will look further, given time, I note the googling "jython friendly hostings" shows this thread at the top :) I appreciate the reply. thanks -- Tim tim at johnsons-web.com http://www.akwebsoft.com From christos.jonathan.hayward at gmail.com Mon Mar 29 15:41:15 2010 From: christos.jonathan.hayward at gmail.com (Jonathan Hayward) Date: Mon, 29 Mar 2010 12:41:15 -0700 (PDT) Subject: "Usability, the Soul of Python" Message-ID: I've posted "Usability, the Soul of Python: An Introduction to the Python Programming Language Through the Eyes of Usability", at: http://JonathansCorner.com/python/ The basic suggestion is that much of what works well in Python has something to do with the usability it offers programmers. Enjoy. -- Jonathan Hayward, christos.jonathan.hayward at gmail.com An Orthodox Christian author: theology, literature, et cetera. My award-winning collection is available for free reading online: I invite you to visit my main site at http://JonathansCorner.com/ From phlip2005 at gmail.com Mon Mar 29 15:45:39 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 29 Mar 2010 12:45:39 -0700 (PDT) Subject: "Usability, the Soul of Python" References: Message-ID: Jonathan Hayward wrote: > I've posted "Usability, the Soul of Python: An Introduction to the > Python Programming Language Through the Eyes of Usability", at: > > ? ?http://JonathansCorner.com/python/ > > The basic suggestion is that much of what works well in Python has > something to do with the usability it offers programmers. You mean like... Order.has_many :line_items ? Oops, sorry, wrong language. My bad! -- Phlip http://zeekland.zeroplayer.com/ From saimapk81 at gmail.com Mon Mar 29 16:07:59 2010 From: saimapk81 at gmail.com (saima81) Date: Mon, 29 Mar 2010 13:07:59 -0700 (PDT) Subject: "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ Message-ID: <26910518-73d6-4fd8-8cdb-9bc862d58beb@a4g2000prb.googlegroups.com> "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia" "jobs in saudi arabia for pakistanis" "jobs in saudi arabia banks" "jobs in saudi" "jobs in saudi airline" "jobs in saudi telecom" "saudi arabia jobs "on http://jobsinsaudiarabia-net.blogspot.com/ From stefan_ml at behnel.de Mon Mar 29 16:14:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 29 Mar 2010 22:14:22 +0200 Subject: =?windows-1252?Q?Re=3A_I=27m_looking_for_html_cleaner=2E?= =?windows-1252?Q?_Example_=3A_convert_=3Ch1=3E=3Cspan=3E=3Cfont=3E?= =?windows-1252?Q?my_title=3C/font=3E=3C/span=3E=3C/h1=3E_=3D=3E_=3C?= =?windows-1252?Q?h1=3Emy_title=3C/h1=3E=85?= In-Reply-To: References: Message-ID: St?phane Klein, 29.03.2010 10:12: > I work on HTML cleaner. > > I export OpenOffice.org documents to HTML. > Next, I would like clean this HTML export files : > > * remove comment > * remove style > * remove dispensable tag > * ... > > some difficulty : > > * convert

my text foo bar

=>

my text foo par

> * convert

my title

=>

my title

> > to do this process, I use lxml and pyquery. lxml.html has tools for that in the 'clean' module. Just specify the list of tags that you want to discard. > * are there some xml helper tools in Python to do this process ? I've > looked for in pypi, I found nothing about it The HTML tools in the standard library are close to non-existant. You can achieve some things with the builtin tools, but if they fail for a particular input document, there's little you can do. > If you confirm than this tools don't exists, I'll maybe publish a helper > package to do this "clean" processing. Take a look at lxml.html.clean first. Stefan From g.bogle at auckland.no.spam.ac.nz Mon Mar 29 18:31:14 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 30 Mar 2010 11:31:14 +1300 Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: I prefer to think of myself as a code-ape - I look down on code-monkeys. From steve at REMOVE-THIS-cybersource.com.au Mon Mar 29 19:19:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 23:19:28 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> Message-ID: <4bb13580$0$8827$c3e8da3@news.astraweb.com> On Mon, 29 Mar 2010 07:40:54 -0700, Patrick Maupin wrote: > On Mar 28, 9:45?pm, Steven D'Aprano > wrote: >> And what about tuples? And subclasses of list/tuples? How many >> different types need to be optimized? > > One of the beautiful things about Python is that, for most things, there > are few surprises for even new users. "There should be one obvious way > to do it" for the user means that, sometimes, under the hood, there are > a lot of special cases for the implementers. It never ceases to amaze me how often people simply don't understand this. "There should be one obvious way to do it" is the opposite of "NO obvious way", not of "many ways which may or may not be obvious". The complete quote from the Zen makes that clear: There should be one-- and preferably ONLY one --obvious way to do it. [Emphasis added] And don't forget the next line: Although that way may not be obvious at first unless you're Dutch. Python is under no compulsion to make "the obvious way" obvious to anyone except Guido. It's a bonus if it happens to be obvious to newbies, not a requirement. And besides, what is "it" you're talking about? * Adding integers, decimals or fractions, or floats with a low requirement for precision and accuracy? Use sum. * Adding floats with a high requirement for precision and accuracy? Use math.fsum. * Concatenating strings? Use ''.join. * Joining lists? Use [].extend. * Iterating over an arbitrary sequence of arbitrary sequences? Use itertools.chain. That's five different "its", and five obvious ways to do them. >> In practical terms, does anyone actually ever use sum on more than a >> handful of lists? I don't believe this is more than a hypothetical >> problem. > > Right now, it's probably not, because when somebody sums a large list > and gets thwacked on the head by the lack of efficiency, they then come > here and get thwacked because "everybody knows" they should user > itertools or something else; not sum(). Exactly. If you're adding a large number of large lists, you're already doing it wrong. Making sum more efficient is just a band aid. >> The primary use case for sum is adding numbers when floating point >> accuracy is not critical. If you need float accuracy, use math.fsum. > > See, I think the very existence of math.fsum() already violates "there > should be one obvious way to do it." How does the existence of math.fsum contradict the existence of sum? -- Steven From tdelaney at avaya.com Mon Mar 29 19:35:43 2010 From: tdelaney at avaya.com (Delaney, Timothy (Tim)) Date: Tue, 30 Mar 2010 07:35:43 +0800 Subject: Super() function In-Reply-To: References: <4BAAD5E0.9050604@googlemail.com><4BAE359F.6090200@googlemail.com> Message-ID: Gabriel Genellina write: > En Sun, 28 Mar 2010 21:58:07 -0300, Delaney, Timothy (Tim) escribi?: >>> Gabriel Genellina wrote: >>>> Alan Harris-Reid escribi?: >>>> >>>>> Using Python 3.1, I sometimes use the super() function to call the >>>>> equivalent method from a parent class, for example >>>>> >>>>> def mymethod(self): >>>>> super().mymethod() >>>>> some more code... >>>> >>>> This recipe does what you want: >>>> http://code.activestate.com/recipes/286195-selfsuper/ >> If you think the pure-python version of the recipe is complicated, you >> should have a look at the performance-optimised Pyrex version ;) > > Where can we look at it? The link in the activestate recipe does not work anymore :( You're right - I've changed ISPs. I'll have to find somewhere else to upload it and change the link. Can't do it today unfortunately. Tim Delaney From no.email at nospam.invalid Mon Mar 29 19:36:17 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 29 Mar 2010 16:36:17 -0700 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: <7xtyryitu6.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > * Iterating over an arbitrary sequence of arbitrary sequences? > Use itertools.chain. chain is only for finite sequences. For arbitrary sequences, use chain.from_iterable. From steve at REMOVE-THIS-cybersource.com.au Mon Mar 29 19:38:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 29 Mar 2010 23:38:53 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> Message-ID: <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> On Mon, 29 Mar 2010 08:12:00 -0700, Steve Howell wrote: > On Mar 29, 7:40?am, Patrick Maupin wrote: >> On Mar 28, 9:45?pm, Steven D'Aprano >> >> wrote: >> > And what about tuples? And subclasses of list/tuples? How many >> > different types need to be optimized? >> >> One of the beautiful things about Python is that, for most things, >> there are few surprises for even new users. ?"There should be one >> obvious way to do it" for the user means that, sometimes, under the >> hood, there are a lot of special cases for the implementers. >> >> > If nothing else, I think it's reasonably for users to expect symmetry. Why? What is symmetry in programming? Since the + operator takes both numbers and lists, and the - operator doesn't, does "symmetry" require that we make up some list operation so that integers and lists are symmetrical? > If you can use "+" to concatentate lists, then it seems reasonable that > something spelled "sum" would concatenate lists as well, and in > reasonable time. Where do you get the "reasonable time" from? A *single* + on lists can be slooooow. Try this: L = [None]*10**9 result = L+L (assuming you've even got enough memory to do so) With a very few exceptions (e.g. dict lookup being "usually" O(1), list append being amortized O(1)), Python makes no promises about performance. It's not part of the language. If you, the programmer, are making any assumptions about performance that aren't clearly and explicitly documented in the official docs, then YOU are at fault, not Python. >> > In practical terms, does anyone actually ever use sum on more than a >> > handful of lists? I don't believe this is more than a hypothetical >> > problem. >> >> Right now, it's probably not, because when somebody sums a large list >> and gets thwacked on the head by the lack of efficiency, they then come >> here and get thwacked because "everybody knows" they should user >> itertools or something else; not sum(). >> >> > Indeed. It would be nice if the docs for sum() at least pointed to > list(itertools.chain(list_of_lists)), or whatever the most kosher > alternative is supposed to be. > > It only takes a handful of sublists, about ten on my box, to expose the > limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's under > the hood. It only takes 200 sublists to start getting a 10x degradation > in performance. And how many times have you needed to add 200 sublists? How many times have you needed to add 10 sublists? Nobody has demonstrated that this is anything more than a hypothetical problem. >> > The primary use case for sum is adding numbers when floating point >> > accuracy is not critical. If you need float accuracy, use math.fsum. >> >> See, I think the very existence of math.fsum() already violates "there >> should be one obvious way to do it." >> >> > The nice thing about math.fsum() is that it is at least documented from > sum(), although I suspect some users try sum() without even consulting > the docs. > > You could appease all users with an API where the most obvious choice, > sum(), never behaves badly, and where users can still call more > specialized versions (math.fsum() and friends) directly if they know > what they are doing. This goes back to the statement that Patrick > makes--under the hood, this means more special cases for implementers, > but fewer pitfalls for users. More special cases for implementers means more bugs in the language, which means I end up writing my own code and ignoring the built-in version anyway. More special cases means I have to pay the cost of high accuracy float summation even when I don't need, or want, it. More special cases means I'm fooled into paying the cost of summing lists when I don't need to, because it's easier than importing itertools: for item in sum(lots_of_lists): pass needlessly creates a large list out of the smaller ones. Even if I don't fall for the temptation, and write bad code, I still pay the cost in the libraries and applications written by others. More special cases isn't free. It's MORE costly than teaching users to use list.extend or itertools.chain. -- Steven From mensanator at aol.com Mon Mar 29 19:59:58 2010 From: mensanator at aol.com (Mensanator) Date: Mon, 29 Mar 2010 16:59:58 -0700 (PDT) Subject: OT: Meaning of "monkey" References: <0b0c8a0c-f62a-4cb4-9403-2af8ce5de9fb@35g2000yqm.googlegroups.com> Message-ID: On Mar 29, 5:31?pm, Gib Bogle wrote: > I prefer to think of myself as a code-ape - I look down on code-monkeys. Why? They have prehensile tails. From nagle at animats.com Mon Mar 29 20:30:05 2010 From: nagle at animats.com (John Nagle) Date: Mon, 29 Mar 2010 17:30:05 -0700 Subject: "Usability, the Soul of Python" In-Reply-To: References: Message-ID: <4bb14173$0$1640$742ec2ed@news.sonic.net> Jonathan Hayward wrote: > I've posted "Usability, the Soul of Python: An Introduction to the > Python Programming Language Through the Eyes of Usability", at: > > http://JonathansCorner.com/python/ No, it's just a rather verbose introduction to Python, in dark brown type on a light brown background. One could write a good paper on this topic, but this isn't it. By the same author: "The Case For Uncreative Web Design", which has no examples. John Nagle From nagle at animats.com Mon Mar 29 20:35:09 2010 From: nagle at animats.com (John Nagle) Date: Mon, 29 Mar 2010 17:35:09 -0700 Subject: =?windows-1252?Q?Re=3A_I=27m_looking_for_html_cleaner=2E?= =?windows-1252?Q?_Example_=3A_convert_=3Ch1=3E=3Cspan=3E=3Cfont=3E?= =?windows-1252?Q?my_title=3C/font=3E=3C/span=3E=3C/h1=3E_=3D=3E_=3C?= =?windows-1252?Q?h1=3Emy_title=3C/h1=3E=85?= In-Reply-To: References: Message-ID: <4bb142a4$0$1669$742ec2ed@news.sonic.net> St?phane Klein wrote: > Hi, > > I work on HTML cleaner. > > I export OpenOffice.org documents to HTML. > Next, I would like clean this HTML export files : > > * remove comment > * remove style > * remove dispensable tag > * ... Try parsing with HTML5 Parser ("http://code.google.com/p/html5lib/") which is the closest thing to a good parser available for Python. It's basically a reference implementation of HTML5, including all the handling of bad HTML. Once you have a tree, write something to go through the tree and remove empty tags from a list of tags which do nothing when empty. Then regenerate HTML from the tree. Or just use HTML Tidy: "http://www.w3.org/People/Raggett/tidy/" John Nagle From lxkain at gmail.com Mon Mar 29 20:54:26 2010 From: lxkain at gmail.com (LX) Date: Mon, 29 Mar 2010 17:54:26 -0700 (PDT) Subject: decorators only when __debug__ == True Message-ID: Hi all, I have a question about decorators. I would like to use them for argument checking, and pre/post conditions. However, I don't want the additional overhead when I run in non-debug mode. I could do something like this, using a simple trace example. @decorator def pass_decorator(f, *args, **kw): # what about the slow-down that incurs when using pass_decorator? return f(*args, **kw) @decorator def trace_decorator(f, *args, **kw): print "calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) trace_enable_flag = False #__debug__ trace = trace_decorator if trace_enable_flag else pass_decorator Trouble is, there is still an additional encapsulating function call. Is there any way to eliminate the extra function call altogether? Thanks in advance! From brian at sweetapp.com Mon Mar 29 21:23:12 2010 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 29 Mar 2010 18:23:12 -0700 Subject: xml-rpc In-Reply-To: <4B9C9AF9.80609@gmail.com> References: <4B9C9AF9.80609@gmail.com> Message-ID: <0590084D-BB4A-4D4E-B331-B7F486597A1A@sweetapp.com> On Mar 14, 2010, at 12:14 AM, ahmet erdinc yilmaz wrote: > Hello, > > Recenetly we are developing a senior project and decide to use > xmlrpclib. > However I have some questions. In the documentation I could not find > any clue about > handling requests? Does the server handles each request in a > separate thread? Or is > there some queuing mechanism for client calls? Thanks in advance. By default calls are processed serially. Look for ThreadingMixIn in: http://docs.python.org/library/socketserver.html And maybe read this too: http://code.activestate.com/recipes/81549-a-simple-xml-rpc-server/ Cheers, Brian > > > --erdinc > -- > http://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Mon Mar 29 21:34:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 02:34:27 +0100 Subject: decorators only when __debug__ == True In-Reply-To: References: Message-ID: <4BB15523.4040901@mrabarnett.plus.com> LX wrote: > Hi all, I have a question about decorators. I would like to use them > for argument checking, and pre/post conditions. However, I don't want > the additional overhead when I run in non-debug mode. I could do > something like this, using a simple trace example. > > > @decorator > def pass_decorator(f, *args, **kw): # what about the slow-down that > incurs when using pass_decorator? > return f(*args, **kw) > > @decorator > def trace_decorator(f, *args, **kw): > print "calling %s with args %s, %s" % (f.func_name, args, kw) > return f(*args, **kw) > > trace_enable_flag = False #__debug__ > trace = trace_decorator if trace_enable_flag else pass_decorator > > > Trouble is, there is still an additional encapsulating function call. > Is there any way to eliminate the extra function call altogether? > Thanks in advance! I think you have misunderstood certain details about decorators. This code with a decorator: @decorator def hello(): print "hello world" basically does this: def hello(): print "hello world" hello = decorator(hello) so your non-decorator just needs to return the function it was passed: def pass_decorator(func): return func and your trace decorator would be something like this: def trace_decorator(func): def show(*args, **kwargs): print "calling %s with args %s, %s" % (func.func_name, args, kwargs) result = func(*args, **kwargs) print "returning %s from %s" % (result, func.func_name) return result return show From showell30 at yahoo.com Mon Mar 29 22:05:30 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 19:05:30 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mar 29, 4:38?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 08:12:00 -0700, Steve Howell wrote: > > On Mar 29, 7:40?am, Patrick Maupin wrote: > >> On Mar 28, 9:45?pm, Steven D'Aprano > > >> wrote: > >> > And what about tuples? And subclasses of list/tuples? How many > >> > different types need to be optimized? > > >> One of the beautiful things about Python is that, for most things, > >> there are few surprises for even new users. ?"There should be one > >> obvious way to do it" for the user means that, sometimes, under the > >> hood, there are a lot of special cases for the implementers. > > > If nothing else, I think it's reasonably for users to expect symmetry. > > Why? What is symmetry in programming? "Symmetry" is best shown by example. >>> 3 - 2 1 >>> set([1,2,3]) - set([2,3]) set([1]) >>> 5 * 3 15 >>> [1, 2, 3, 4, 5] * 3 [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5] >>> 1 + 2 + 3 + 4 10 >>> sum([1,2,3,4]) 10 >>> [1,2] + [3,4] [1, 2, 3, 4] >>> sum([[1,2], [3,4]], []) [1, 2, 3, 4] > Since the + operator takes both numbers and lists, and the - operator > doesn't, does "symmetry" require that we make up some list operation so > that integers and lists are symmetrical? > No. Nobody is advocating for list subtraction. > > If you can use "+" to concatentate lists, then it seems reasonable that > > something spelled "sum" would concatenate lists as well, and in > > reasonable time. > > Where do you get the "reasonable time" from? > >From common sense. Concatenation of lists should be in O(M*N) time, not O(M*N*N), because there is no need to build intermediate lists. > > With a very few exceptions (e.g. dict lookup being "usually" O(1), list > append being amortized O(1)), Python makes no promises about performance. > It's not part of the language. If you, the programmer, are making any > assumptions about performance that aren't clearly and explicitly > documented in the official docs, then YOU are at fault, not Python. I'm not making any assumptions here. I know that sum() is needlessly slow for lists, even though it is not explicitly documented. > > > It only takes a handful of sublists, about ten on my box, to expose the > > limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's under > > the hood. ?It only takes 200 sublists to start getting a 10x degradation > > in performance. > > And how many times have you needed to add 200 sublists? > > How many times have you needed to add 10 sublists? > Aggregating lists is a very common task in programming. An example of a list of lists would be a list of departments, where each department is a list of employees. If you want to sort the employees, you will want to aggregate to a list. > More special cases for implementers means more bugs in the language, > which means I end up writing my own code and ignoring the built-in > version anyway. > Special cases do not have to introduce bugs in the language. > More special cases means I have to pay the cost of high accuracy float > summation even when I don't need, or want, it. > Nothing about making sum() work for the general cases precludes more specific, optimized functions. > More special cases means I'm fooled into paying the cost of summing lists > when I don't need to, because it's easier than importing itertools: You don't have to be fooled. > for item in sum(lots_of_lists): > ? ? pass > > needlessly creates a large list out of the smaller ones. Although this is a mostly harmless example, developers with common sense would not sum lots of lists unless they expected to keep the resulting list around for multiple operations, or for one operation, like sort(), where you need to create a list for the subsequent operation. > Even if I don't > fall for the temptation, and write bad code, I still pay the cost in the > libraries and applications written by others. You already pay the small price for polymorphism when you use Python. > More special cases isn't free. Nobody said they were. > It's MORE costly than teaching users to > use list.extend or itertools.chain. > Which the docs for sum() don't do. From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 22:11:09 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 02:11:09 GMT Subject: decorators only when __debug__ == True References: Message-ID: On Mon, 29 Mar 2010 17:54:26 -0700, LX wrote: > Hi all, I have a question about decorators. I would like to use them for > argument checking, and pre/post conditions. However, I don't want the > additional overhead when I run in non-debug mode. I could do something > like this, using a simple trace example. def decorator(func): if __debug__: @functools.wraps(func) def inner(*args, **kwargs): preprocess() result = func(*args, **kwargs) postprocess() return result return inner else: return func -- Steven From pmaupin at gmail.com Mon Mar 29 22:24:42 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 19:24:42 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> On Mar 29, 6:19?pm, Steven D'Aprano wrote: > How does the existence of math.fsum contradict the existence of sum? You're exceptionally good at (probably deliberately) mis-interpreting what people write. Regards, Pat From pmaupin at gmail.com Mon Mar 29 22:31:44 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 19:31:44 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: <8dac78c8-124a-4b02-9944-6d577bfac84f@15g2000yqi.googlegroups.com> On Mar 29, 6:38?pm, Steven D'Aprano wrote: > With a very few exceptions (e.g. dict lookup being "usually" O(1), list > append being amortized O(1)), Python makes no promises about performance. > It's not part of the language. If you, the programmer, are making any > assumptions about performance that aren't clearly and explicitly > documented in the official docs, then YOU are at fault, not Python. It's not about promises, guarantees, quid-pro-quo, etc. It's about a lack of surprises. Which, 99% of the time, Python excels at. This is why many of us program in Python. This is why some of us who would never use sum() on lists, EVEN IF IT WERE FIXED TO NOT BE SO OBNOXIOUSLY SLOW, advocate that it, in fact, be fixed to not be so obnoxiously slow. BTW, it's also not about "fault". There is no shame in writing a Python program, seeing that it doesn't go fast enough, and then hammering on it until it does. There is also no shame in not reading the docs before you write the program, although arguably (and you obviously work very hard to help see to this) a great deal of shame attaches to posting to the newsgroup before reading the docs. Regards, Pat From showell30 at yahoo.com Mon Mar 29 22:53:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 19:53:04 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mar 29, 4:19?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 07:40:54 -0700, Patrick Maupin wrote: > > On Mar 28, 9:45?pm, Steven D'Aprano > > wrote: > >> And what about tuples? And subclasses of list/tuples? How many > >> different types need to be optimized? > > > One of the beautiful things about Python is that, for most things, there > > are few surprises for even new users. ?"There should be one obvious way > > to do it" for the user means that, sometimes, under the hood, there are > > a lot of special cases for the implementers. > > It never ceases to amaze me how often people simply don't understand this. > > "There should be one obvious way to do it" is the opposite of "NO obvious > way", not of "many ways which may or may not be obvious". The complete > quote from the Zen makes that clear: > > There should be one-- and preferably ONLY one --obvious way to do it. > [Emphasis added] > > And don't forget the next line: > > Although that way may not be obvious at first unless you're Dutch. > > Python is under no compulsion to make "the obvious way" obvious to anyone > except Guido. It's a bonus if it happens to be obvious to newbies, not a > requirement. > > And besides, what is "it" you're talking about? > > * Adding integers, decimals or fractions, or floats with a low > ? requirement for precision and accuracy? Use sum. > > * Adding floats with a high requirement for precision and accuracy? > ? Use math.fsum. > > * Concatenating strings? Use ''.join. > > * Joining lists? Use [].extend. > > * Iterating over an arbitrary sequence of arbitrary sequences? > ? Use itertools.chain. > > That's five different "its", and five obvious ways to do them. > Let's go through them... > * Adding integers, decimals or fractions, or floats with a low > requirement for precision and accuracy? Use sum. > Pretty obvious. >>> sum([1, 2, 3]) 6 > * Adding floats with a high requirement for precision and accuracy? > Use math.fsum. > Mostly obvious. >>> fsum([1.234534665989, 2.987, 3]) Traceback (most recent call last): File "", line 1, in NameError: name 'fsum' is not defined >>> import math >>> math.fsum([1.234534665989, 2.987, 3]) 7.2215346659890001 > * Concatenating strings? Use ''.join. Common pitfall: >>> ['abc', 'def', 'ghi'].join() Traceback (most recent call last): File "", line 1, in AttributeError: 'list' object has no attribute 'join' >>> ''.join(['abc', 'def', 'ghi']) 'abcdefghi' > * Joining lists? Use [].extend. Obvious, yes. Convenient? Not really. >>> start = [] >>> for list in [[1, 2], [3, 4]]: ... start.extend(list) ... >>> start [1, 2, 3, 4] > * Iterating over an arbitrary sequence of arbitrary sequences? > Use itertools.chain. >>> group1 = ['al', 'bob'] >>> group2 = ['cal'] >>> groups = [group1, group2] Obvious if you are Dutch... >>> itertools.chain(groups) Traceback (most recent call last): File "", line 1, in NameError: name 'itertools' is not defined >>> import itertools >>> itertools.chain(groups) >>> len(itertools.chain(groups)) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'itertools.chain' has no len() >>> len(list(itertools.chain(groups))) 2 >>> len(list(itertools.chain(*groups))) 3 So you have sum, fsum, join, extend, and chain. Sum is builtin, but you have to import fsum from math and chain from itertools. Join is actually a method on strings, not sequences. Chain can take multiple lists, or you can use the splat operator on a list of lists. Extend is actually a method on lists, and it only takes one list, not multiple ones. >>> [].extend(*groups) Traceback (most recent call last): File "", line 1, in TypeError: extend() takes exactly one argument (2 given) Just commit all that to memory, and enjoy the productivity of using a high level language! ;) From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:01:03 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:01:03 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Mar 2010 19:05:30 -0700, Steve Howell wrote: >> > If nothing else, I think it's reasonably for users to expect >> > symmetry. >> >> Why? What is symmetry in programming? > > "Symmetry" is best shown by example. > > >>> 3 - 2 > 1 > >>> set([1,2,3]) - set([2,3]) > set([1]) That's a useless example. >>> 42 - 10 32 >>> set([42]) - set([10]) set([42]) You don't define symmetry. You don't even give a sensible example of symmetry. Consequently I reject your argument that because sum is the obvious way to sum a lot of integers, "symmetry" implies that it should be the obvious way to concatenate a lot of lists. >>> 1+2 3 >>> [1] + [2] [1, 2] >>> set([1]) + set([2]) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'set' and 'set' >> > If you can use "+" to concatentate lists, then it seems reasonable >> > that something spelled "sum" would concatenate lists as well, and in >> > reasonable time. >> >> Where do you get the "reasonable time" from? >> >> > From common sense. Concatenation of lists should be in O(M*N) time, not > O(M*N*N), because there is no need to build intermediate lists. You are correct that building intermediate lists isn't *compulsory*, there are alternatives, but the alternatives themselves have costs. Complexity itself is a cost. sum currently has nice simple semantics, which means you can reason about it: sum(sequence, start) is the same as total = start for item in sequence: total = total + start return total You don't have to care what the items in sequence are, you don't have to make assumptions about what methods sequence and start have (beyond supporting iteration and addition). Adding special cases to sum means it becomes more complex and harder to reason about. If you pass some other sequence type in the middle of a bunch of lists, what will happen? Will sum suddenly break, or perhaps continue to work but inefficiently? You still need to ask these questions with existing sum, but it is comparatively easy to answer them: you only need to consider how the alternative behaves when added to a list. You don't have to think about the technicalities of the sum algorithm itself -- sometimes it calls +, sometimes extend, sometimes +=, sometimes something else... which of the various different optimized branches will I fall into this time? Who knows? sum already has two branches. In my opinion, three branches is one too many. [...] >> > It only takes a handful of sublists, about ten on my box, to expose >> > the limitation of the Shlemeil-the-Painter O(M*N*N) algorithm that's >> > under the hood. ?It only takes 200 sublists to start getting a 10x >> > degradation in performance. >> >> And how many times have you needed to add 200 sublists? >> >> How many times have you needed to add 10 sublists? >> >> > Aggregating lists is a very common task in programming. "Aggregating" lists? Not summing them? I think you've just undercut your argument that sum is the "obvious" way of concatenating lists. In natural language, we don't talk about "summing" lists, we talk about joining, concatenating or aggregating them. You have just done it yourself, and made my point for me. And this very thread started because somebody wanted to know what the equivalent to sum for sequences. If sum was the obvious way to concatenate sequences, this thread wouldn't even exist. > An example of a > list of lists would be a list of departments, where each department is a > list of employees. If you want to sort the employees, you will want to > aggregate to a list. I grant you that 10 departments is likely to be a borderline case, but if you have 200 departments, then you will most likely be querying a database and getting back a single list of employees. And if you're not, you probably should be. >> More special cases for implementers means more bugs in the language, >> which means I end up writing my own code and ignoring the built-in >> version anyway. >> >> > Special cases do not have to introduce bugs in the language. They don't *have* to, but since even Donald Knuth has written code with bugs in it, it is a safe bet that the number of bugs in code written by mere mortals will be roughly proportional to the complexity: more complex means more bugs. You can go to the bank with that. >> More special cases means I have to pay the cost of high accuracy float >> summation even when I don't need, or want, it. >> >> > Nothing about making sum() work for the general cases precludes more > specific, optimized functions. You have missed my point. If I call your version of sum which all the special cases, I pay the overhead of the complexity regardless of whether I need it or not. The existence of other functions which duplicate the special cases in sum is irrelevant. [...] >> It's MORE costly than teaching users to use list.extend or >> itertools.chain. >> >> > Which the docs for sum() don't do. Patches are always welcome. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:02:25 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:02:25 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xtyryitu6.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 29 Mar 2010 16:36:17 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> * Iterating over an arbitrary sequence of arbitrary sequences? >> Use itertools.chain. > > chain is only for finite sequences. For arbitrary sequences, use > chain.from_iterable. Correction noted. Obviously I'm not Dutch. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:29:11 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:29:11 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> Message-ID: On Mon, 29 Mar 2010 19:24:42 -0700, Patrick Maupin wrote: > On Mar 29, 6:19?pm, Steven D'Aprano cybersource.com.au> wrote: >> How does the existence of math.fsum contradict the existence of sum? > > You're exceptionally good at (probably deliberately) mis-interpreting > what people write. I cannot read your mind, I can only interpret the words you choose to write. You said [quote] See, I think the very existence of math.fsum() already violates "there should be one obvious way to do it." [end quote] If sum satisfies the existence of one obvious way, how does math.fsum violate it? sum exists, and is obvious, regardless of whatever other solutions exist as well. -- Steven From pmaupin at gmail.com Mon Mar 29 23:33:14 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Mon, 29 Mar 2010 20:33:14 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> Message-ID: <559a2ee3-fb2c-477f-a444-7edbb6da8676@r1g2000yqj.googlegroups.com> On Mar 29, 10:29?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 19:24:42 -0700, Patrick Maupin wrote: > > On Mar 29, 6:19?pm, Steven D'Aprano > cybersource.com.au> wrote: > >> How does the existence of math.fsum contradict the existence of sum? > > > You're exceptionally good at (probably deliberately) mis-interpreting > > what people write. > > I cannot read your mind, I can only interpret the words you choose to > write. You said > > [quote] > See, I think the very existence of math.fsum() already violates "there > should be one obvious way to do it." > [end quote] > > If sum satisfies the existence of one obvious way, how does math.fsum > violate it? sum exists, and is obvious, regardless of whatever other > solutions exist as well. Because sum() is the obvious way to sum floats; now the existence of math.fsum() means there are TWO obvious ways to sum floats. Is that really that hard to understand? How can you misconstrue this so badly that you write something that can be (easily) interpreted to mean that you think that I think that once math.fsum() exists, sum() doesn't even exist any more???? From showell30 at yahoo.com Mon Mar 29 23:34:17 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 29 Mar 2010 20:34:17 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> Message-ID: <3c7ed32c-201f-41c8-bd46-4bf3092a3d6f@x12g2000yqx.googlegroups.com> On Mar 29, 8:01?pm, Steven D'Aprano wrote: > You don't define symmetry. You don't even give a sensible example of > symmetry. Consequently I reject your argument that because sum is the > obvious way to sum a lot of integers, "symmetry" implies that it should > be the obvious way to concatenate a lot of lists. > You are not rejecting my argument; you are rejecting an improper paraphrase of my argument. My argument was that repeated use of "+" is spelled "sum" for integers, so it's natural to expect the same name for repeated use of "+" on lists. Python already allows for this symmetry, just SLOWLY. > > You are correct that building intermediate lists isn't *compulsory*, > there are alternatives, but the alternatives themselves have costs. > Complexity itself is a cost. sum currently has nice simple semantics, > which means you can reason about it: sum(sequence, start) is the same as > > total = start > for item in sequence: > ? ? total = total + start > return total > I could just as reasonably expect these semantics: total = start for item in sequence: total += start return total Python does not contradict my expectations here: >>> start = [] >>> x = sum([], start) >>> x.append(1) >>> start [1] > You don't have to care what the items in sequence are, you don't have to > make assumptions about what methods sequence and start have (beyond > supporting iteration and addition). The only additional assumption I'm making is that Python can take advantage of in-place addition, which is easy to introspect. > Adding special cases to sum means it > becomes more complex and harder to reason about. If you pass some other > sequence type in the middle of a bunch of lists, what will happen? Will > sum suddenly break, or perhaps continue to work but inefficiently? This is mostly a red herring, as I would tend to use sum() on sequences of homogenous types. Python already gives me the power to shoot myself in the foot for strings. >>> list = [1, 2] >>> list += "foo" >>> list [1, 2, 'f', 'o', 'o'] >>> lst = [1,2] >>> lst.extend('foo') >>> lst [1, 2, 'f', 'o', 'o'] I'd prefer to get an exception for cases where += would do the same. >>> start = [] >>> bogus_example = [[1, 2], None, [3]] >>> for item in bogus_example: start += item ... Traceback (most recent call last): File "", line 1, in TypeError: 'NoneType' object is not iterable > You still need to ask these questions with existing sum, but it is > comparatively easy to answer them: you only need to consider how the > alternative behaves when added to a list. You don't have to think about > the technicalities of the sum algorithm itself -- sometimes it calls +, > sometimes extend, sometimes +=, sometimes something else I would expect sum() to support the same contract as +=, which already works for numerics (so no backward incompatibility), and which already works for lists. For custom-designed classes, I would rely on the promise that augmented assignment falls back to normal methods. > ... which of the > various different optimized branches will I fall into this time? Who > knows? sum already has two branches. In my opinion, three branches is one > too many. As long as it falls into the branch that works, I'm happy. :) > > "Aggregating" lists? Not summing them? I think you've just undercut your > argument that sum is the "obvious" way of concatenating lists. > > In natural language, we don't talk about "summing" lists, we talk about > joining, concatenating or aggregating them. You have just done it > yourself, and made my point for me. Nor do you use "chain" or "extend." > And this very thread started because > somebody wanted to know what the equivalent to sum for sequences. > > If sum was the obvious way to concatenate sequences, this thread wouldn't > even exist. This thread is entitled "sum for sequences." I think you just made my point. From steven at REMOVE.THIS.cybersource.com.au Mon Mar 29 23:49:46 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 03:49:46 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <069f41e7-6a4a-4a40-b570-2559ca5ce69d@x11g2000prb.googlegroups.com> <4bb13a0c$0$8827$c3e8da3@news.astraweb.com> <8dac78c8-124a-4b02-9944-6d577bfac84f@15g2000yqi.googlegroups.com> Message-ID: On Mon, 29 Mar 2010 19:31:44 -0700, Patrick Maupin wrote: > It's about a lack of surprises. Which, 99% of the time, Python excels > at. This is why many of us program in Python. This is why some of us > who would never use sum() on lists, EVEN IF IT WERE FIXED TO NOT BE SO > OBNOXIOUSLY SLOW, advocate that it, in fact, be fixed to not be so > obnoxiously slow. As I said, patches are welcome. Personally, I expect that it would be rejected, but that's not my decision to make, and who knows, perhaps I'm wrong and you'll have some of the Python-Dev people support your idea. sum is not designed to work with lists. It happens to work because lists happen to use + for concatenation, and because it is too much trouble for too little benefit to explicitly exclude lists in the same way sum explicitly excludes strings. In the Python philosophy, simplicity of implementation is a virtue: the code that is not there contributes exactly no bugs and has precisely no overhead. sum has existed as a Python built-in for many years -- by memory, since Python 2.2, which was nearly nine years ago. Unlike the serious gotcha of repeated string concatenation: # DO NOT DO THIS result = "" for s in items: result += s which *does* cause real problems in real code, I don't believe that there have been any significant problems caused by summing lists of lists. As problems go, it is such a minor one that it isn't worth this discussion, let alone fixing it. But if anyone disagrees, this is open source, go ahead and fix it. You don't need my permission. -- Steven From gagsl-py2 at yahoo.com.ar Tue Mar 30 00:00:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Mar 2010 01:00:16 -0300 Subject: GIF89A and PIL References: <2010032618455468300-aptshansen@gmailinvalid> <87oci9hjz9.fsf@dpt-info.u-strasbg.fr> <2010032719445464825-aptshansen@gmailinvalid> <81b39uFggeU1@mid.individual.net> Message-ID: En Mon, 29 Mar 2010 04:41:23 -0300, Gregory Ewing escribi?: > Stephen Hansen wrote: > >> So I wonder if there's just some hyper-optimization Photoshop does that >> PIL can't round-trip. > > You may find that PIL isn't bothering to compress at all, > or only doing it in a very simpleminded way. Indeed. Fredrik Lundh, in http://mail.python.org/pipermail/image-sig/1998-July/000506.html "When writing GIF files, PIL uses a simpleminded encoding that, by some odd reason, LZW decoders have no trouble reading. To write compressed GIF files, there are a number of options: -- install NETPBM, and hack GifImagePlugin so it uses _save_ppm instead of _save (just remove "_ppm" from the latter). -- write an _imaging_gif module that takes a PIL image and writes a GIF version of it. how you implement that is up to you..." After twelve years the above comments are still applicable. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 30 00:36:52 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 30 Mar 2010 01:36:52 -0300 Subject: xpat error in xmlrp client. How to inspect data. References: <4bab1f4a$0$25677$426a74cc@news.free.fr> Message-ID: En Thu, 25 Mar 2010 05:31:05 -0300, News123 escribi?: > I'm havign a small xmlrpc client, which works normally fine. > (xmlrpc via https) > > Sometimes however I receive an Exception about an expat error. > > > The output, that I receive is: > File "C:\mycode\myrpcclient.py", line 63, in upload_chunk > rslt = myrpcclient.call() > File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ > return self.__send(self.__name, args) > File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request > verbose=self.__verbose > File "C:\Python26\lib\xmlrpclib.py", line 1253, in request > return self._parse_response(h.getfile(), sock) > File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response > p.feed(response) > File "C:\Python26\lib\xmlrpclib.py", line 601, in feed > self._parser.Parse(data, 0) > ExpatError: syntax error: line 1, column 0 > > > In order to continue debugging I'd like to dump the received http data, > which "C:\Python26\lib\xmlrpclib.py", line 601 tried to parse without > succes. > > How can I do this? a) Use the standard cgitb module (despite its name, it is useful outside CGI scripts) b) Use the tb module available from http://pypi.python.org/pypi/tb Both provide a more verbose traceback, including local variables at each execution frame. c) Replace ("monkey-patch") the feed() method with a more debug-friendly version: def feed(self, data): try: self._parser.Parse(data, 0) except xmlrpclib.expat.ExpatError, e: e.args += (data,) raise xmlrpclib.ExpatParser.feed = feed (Or perhaps set e.data = data) d) In your exception handler, walk the traceback object until you reach the feed() call, and inspect the corresponding tb_frame.f_locals dictionary. -- Gabriel Genellina From cs at zip.com.au Tue Mar 30 00:41:11 2010 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 30 Mar 2010 15:41:11 +1100 Subject: GIF89A and PIL In-Reply-To: <2010032719445464825-aptshansen@gmailinvalid> References: <2010032719445464825-aptshansen@gmailinvalid> Message-ID: <20100330044111.GA684@cskk.homeip.net> On 27Mar2010 19:44, Stephen Hansen wrote: | Yeah, I don't expect much from PNG. The images are very small but I | might be sending a LOT of them over a pipe which is fairly tight, so | 50-60 bytes matters. That's why I selected GIF. How well does a stream of XPM files compress? Probably not enough, I would guess. Just wondering. Do you need to move a "standard" image format around? If everything's 16x16 8 bit colour (and if, with luck, they share a colour map) maybe you can ship raw bytes expressing what you want. How colourful are these GIFs? -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ What I want is Facts. Teach these boys and girls nothing but Facts. Facts alone are wanted in life. Plant nothing else, and root out everything else. - Charles Dickens John Huffam 1812-1870 Hard Times [1854] From kse.listed.co1 at gmail.com Tue Mar 30 00:41:38 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Mon, 29 Mar 2010 21:41:38 -0700 (PDT) Subject: "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ Message-ID: "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ "jobs in saudi arabia universities" "jobs in saudi arabia for pakistanis" "jobs in saudi" "saudi jobs" "saudi job vacancies" "saudi job visa" "saudi job consultants" "saudi jobs site" "jobs site" on http://jobsinsaudiarabia-net.blogspot.com/ From vinni at altern.org Tue Mar 30 01:47:40 2010 From: vinni at altern.org (Vincent MAILLE) Date: Mon, 29 Mar 2010 22:47:40 -0700 (PDT) Subject: PyScripter Logo Message-ID: <9483843a-e855-4648-ae69-fef9e7006ffd@z3g2000yqz.googlegroups.com> Hi, Where can I find a image of the snake PyScipter in high quality ? Thnaks, Vincent From steven at REMOVE.THIS.cybersource.com.au Tue Mar 30 02:41:51 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 06:41:51 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mon, 29 Mar 2010 19:53:04 -0700, Steve Howell wrote: > On Mar 29, 4:19?pm, Steven D'Aprano cybersource.com.au> wrote: [...] >> Python is under no compulsion to make "the obvious way" obvious to >> anyone except Guido. It's a bonus if it happens to be obvious to >> newbies, not a requirement. >> >> And besides, what is "it" you're talking about? >> >> * Adding integers, decimals or fractions, or floats with a low >> ? requirement for precision and accuracy? Use sum. >> >> * Adding floats with a high requirement for precision and accuracy? >> ? Use math.fsum. >> >> * Concatenating strings? Use ''.join. >> >> * Joining lists? Use [].extend. >> >> * Iterating over an arbitrary sequence of arbitrary sequences? >> ? Use itertools.chain. >> >> That's five different "its", and five obvious ways to do them. >> >> > Let's go through them... "Obvious" doesn't mean you don't have to learn the tools you use. It doesn't mean that there's no need to think about the requirements of your problem. It doesn't even mean that the way to do it has to be a built-in or pre-built solution in the standard library, or that somebody with no Python experience could intuit the correct function to use based on nothing more than a good grasp of English. It certainly doesn't mean that users shouldn't be expected to know how to import a module: > >>> fsum([1.234534665989, 2.987, 3]) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'fsum' is not defined I called it math.fsum every time I referred to it. Did I need to specify that you have to import the math module first? >> * Concatenating strings? Use ''.join. > > > Common pitfall: > > >>> ['abc', 'def', 'ghi'].join() > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'list' object has no attribute 'join' Is it really common? I've been hanging around this newsgroup for many years now, and I don't believe I've ever seen anyone confused by this. I've seen plenty of newbies use repeated string concatenation, but never anyone trying to do a string join and getting it wrong. If you have any links to threads showing such confusion, I'd be grateful to see them. >> * Joining lists? Use [].extend. > > Obvious, yes. Convenient? Not really. > > >>> start = [] > >>> for list in [[1, 2], [3, 4]]: > ... start.extend(list) > ... > >>> start > [1, 2, 3, 4] Why isn't that convenient? It is an obvious algorithm written in three short lines. If you need a one-liner, write a function and call it: concatenate_lists(sequence_of_lists) >> * Iterating over an arbitrary sequence of arbitrary sequences? >> Use itertools.chain. > > >>> group1 = ['al', 'bob'] > >>> group2 = ['cal'] > >>> groups = [group1, group2] > > Obvious if you are Dutch... Or are familiar with the itertools module and the Pythonic practice of iterating over lazy sequences. Iterators and itertools are fundamental to the Pythonic way of doing things. > >>> itertools.chain(groups) > Traceback (most recent call last): > File "", line 1, in > NameError: name 'itertools' is not defined That's the second time you've either mistakenly neglected to import a module, or deliberately not imported it to make the rhetorical point that you have to import a module before using it. Yes, you *do* have to import modules before using them. What's your point? Not everything has to be a built-in. [...] > Sum is builtin, but you have to import fsum from math and chain from > itertools. > > Join is actually a method on strings, not sequences. Is that supposed to be an argument against them? [...] > Just commit all that to memory, and enjoy the productivity of using a > high level language! ;) If you don't know your tools, you will spend your life hammering screws in with the butt of your saw. It will work, for some definition of work. Giving saws heavier, stronger handles to make it faster to hammer screws is not what I consider good design. -- Steven From no.email at nospam.invalid Tue Mar 30 02:55:55 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 29 Mar 2010 23:55:55 -0700 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> Message-ID: <7xr5n2i9hg.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >>>> ... >>> ... >> ... > "Obvious" doesn't mean you don't have to learn the tools you use.... Geez you guys, get a room ;-). You're all good programmers with too much experience for this arguing over stuff this silly. From loveguruworld7 at gmail.com Tue Mar 30 03:05:01 2010 From: loveguruworld7 at gmail.com (love guru 4 world) Date: Tue, 30 Mar 2010 00:05:01 -0700 (PDT) Subject: Watch Angelina Jolie's sex scandal videos at her house Message-ID: <67a85379-1f60-4028-b812-4650fb3fc719@a16g2000pre.googlegroups.com> Watch Angelina Jolie's sex scandal videos at her house for more details register here to start watching video now http://moourl.com/82x99 From keeloh at rocketmail.com Tue Mar 30 03:33:01 2010 From: keeloh at rocketmail.com (POOJA) Date: Tue, 30 Mar 2010 00:33:01 -0700 (PDT) Subject: Help Desk Software by PerlDesk Message-ID: Help Desk Software by PerlDesk ------------------------ http://sites.google.com/site/freehelpdesksoftware From chris at simplistix.co.uk Tue Mar 30 04:03:00 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 30 Mar 2010 09:03:00 +0100 Subject: PyDispatcher on sourceforge doesn't play nice with easy_install Message-ID: <4BB1B034.9020905@simplistix.co.uk> Hi All, Using easy_install to get PyDispatcher results in: Searching for PyDispatcher Reading http://pypi.python.org/simple/PyDispatcher/ Reading http://pydispatcher.sourceforge.net Reading https://sourceforge.net/project/showfiles.php?group_id=79755 Reading http://sourceforge.net/projects/pydispatcher/files/pydispatcher/ Best match: PyDispatcher 2.0.1 Downloading http://sourceforge.net/projects/pydispatcher/files/pydispatcher/2.0.1/PyDispatcher-2.0.1-py2.5.egg/download Processing download error: Couldn't find a setup script in /tmp/easy_install-ioAdEo/download Who's the maintainer of PyDispatcher nowadays? Would be handy if they removed the sourceforge link from pypi. In the meantime, the following works around the problem: easy_install PyDispatcher -H *.python.org cheers, Chris From steven at REMOVE.THIS.cybersource.com.au Tue Mar 30 04:06:09 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 08:06:09 GMT Subject: PyScripter Logo References: <9483843a-e855-4648-ae69-fef9e7006ffd@z3g2000yqz.googlegroups.com> Message-ID: On Mon, 29 Mar 2010 22:47:40 -0700, Vincent MAILLE wrote: > Where can I find a image of the snake PyScipter in high quality ? Did you mean PyScripter (note spelling)? If so, then googling for PyScripter brings me to the PyScripter project, which has contact details. You should ask the project author. -- Steven From jeanmichel at sequans.com Tue Mar 30 05:03:06 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 30 Mar 2010 11:03:06 +0200 Subject: "Usability, the Soul of Python" In-Reply-To: <4bb14173$0$1640$742ec2ed@news.sonic.net> References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <4BB1BE4A.50407@sequans.com> John Nagle wrote: > Jonathan Hayward wrote: >> I've posted "Usability, the Soul of Python: An Introduction to the >> Python Programming Language Through the Eyes of Usability", at: >> >> http://JonathansCorner.com/python/ > > No, it's just a rather verbose introduction to Python, in dark brown > type on a light brown background. One could write a good paper on this > topic, but this isn't it. > > > John Nagle Why is it bad ? JM From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 06:10:55 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 10:10:55 GMT Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xr5n2i9hg.fsf@ruckus.brouhaha.com> Message-ID: <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >>>>> ... >>>> ... >>> ... >> "Obvious" doesn't mean you don't have to learn the tools you use.... > > Geez you guys, get a room ;-). You're all good programmers with too > much experience for this arguing over stuff this silly. Yes Mum ;) You're right of course. I spend too much time being this guy: http://xkcd.com/386/ and not enough this one: http://xkcd.com/167/ -- Steven From am8734200 at gmail.com Tue Mar 30 06:19:33 2010 From: am8734200 at gmail.com (a m) Date: Tue, 30 Mar 2010 03:19:33 -0700 (PDT) Subject: It's a fact not lost on the opportunity to see yourself Message-ID: <49471fea-67f2-476a-93cf-1e9f9eabfcb7@i25g2000yqm.googlegroups.com> http://www.google.com/url?sa=D&q=http://www.google.com/url%3Fsa%3DD%26q%3Dhttp://osamah2000.jeeran.com/daauageralmuslmeen1.htm%26usg%3DAFQjCNGQhhGz-1TGv9Y7gE8zKwHHustJCg&usg=AFQjCNH5ZzXRqkh5EGL1dsjQxcjNQCmAEQ From malte.usenet at web.de Tue Mar 30 07:17:21 2010 From: malte.usenet at web.de (Malte Dik) Date: Tue, 30 Mar 2010 13:17:21 +0200 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <81e4u2F7ubU1@mid.dfncis.de> > Why is it bad ? > Not working code, examples, that are weird to read, and a lot of text :) From lie.1296 at gmail.com Tue Mar 30 07:23:32 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 30 Mar 2010 22:23:32 +1100 Subject: StringChain -- a data structure for managing large sequences ofchunks of bytes In-Reply-To: <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> <4bae6130$1@dnews.tpgi.com.au> <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> Message-ID: <4bb1df60$1@dnews.tpgi.com.au> On 03/29/2010 01:59 AM, Steven D'Aprano wrote: > On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote: > >> On 03/22/2010 07:07 PM, Steven D'Aprano wrote: >>> Perhaps you should have said that it was a wrapper around deque giving >>> richer functionality, rather than giving the impression that it was a >>> brand new data structure invented by you. People are naturally going to >>> be more skeptical about a newly invented data structure than one based >>> on a reliable, component like deque. >> >> Well, technically StringChain is not a data structure in the first >> place. StringChain is a string; > > And strings are data structures, as are arrays and structs. Just because > they're simple data structures made directly from primitives rather than > rich, complex structures, doesn't mean they're not data structures. Array is a way to structure data and thus a data structure; array is the concept of structuring data using contiguous memory with elements addressed by an index. string is just a contiguous memory reserved to store data, or in other words: string is an array. This is what I meant when I said string is not itself a data structure. >> a string that is implemented using deque >> data structure to make appending algorithmically efficient. It is not a >> data structure, in the sense that I can't put arbitrary "thing" into the >> data structure. > > Any "thing" that can be pickled or serialised can be put into a string. Fair enough, you're right to think so but IMHO I disagree. Streams (or perhaps 'blob' to avoid the connotation of FIFO) are the data structure which you can put anything pickleable/serialisable into, but string (the implementation of stream/blob using array) are just a special case of array data structure and not a different, separate data structure than array. Perhaps I should not make such a bold claim as saying string is not data structure; what I have in mind is that string is just a special case of array and not distinctly separate data structure than array. From steve at holdenweb.com Tue Mar 30 07:33:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 07:33:37 -0400 Subject: sum for sequences? In-Reply-To: <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xr5n2i9hg.fsf@ruckus.brouhaha.com> <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> Message-ID: <4BB1E191.9040909@holdenweb.com> Steven D'Aprano wrote: > On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote: > >> Steven D'Aprano writes: >>>>>> ... >>>>> ... >>>> ... >>> "Obvious" doesn't mean you don't have to learn the tools you use.... >> Geez you guys, get a room ;-). You're all good programmers with too >> much experience for this arguing over stuff this silly. > > Yes Mum ;) > > > You're right of course. I spend too much time being this guy: > > http://xkcd.com/386/ > > and not enough this one: > > http://xkcd.com/167/ > > Yeah, it can happen to all of us. I've certainly been "that guy" too. But Steven, surely now it's time to *show us the squirrels* regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 30 07:33:37 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 07:33:37 -0400 Subject: sum for sequences? In-Reply-To: <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <7xr5n2i9hg.fsf@ruckus.brouhaha.com> <4bb1ce2e$0$8827$c3e8da3@news.astraweb.com> Message-ID: <4BB1E191.9040909@holdenweb.com> Steven D'Aprano wrote: > On Mon, 29 Mar 2010 23:55:55 -0700, Paul Rubin wrote: > >> Steven D'Aprano writes: >>>>>> ... >>>>> ... >>>> ... >>> "Obvious" doesn't mean you don't have to learn the tools you use.... >> Geez you guys, get a room ;-). You're all good programmers with too >> much experience for this arguing over stuff this silly. > > Yes Mum ;) > > > You're right of course. I spend too much time being this guy: > > http://xkcd.com/386/ > > and not enough this one: > > http://xkcd.com/167/ > > Yeah, it can happen to all of us. I've certainly been "that guy" too. But Steven, surely now it's time to *show us the squirrels* regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From lie.1296 at gmail.com Tue Mar 30 07:39:41 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 30 Mar 2010 22:39:41 +1100 Subject: Classes as namespaces? In-Reply-To: <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> References: <69463be0-d839-43cf-a8a7-1cc9081f672d@r27g2000yqn.googlegroups.com> <52ae180e-b959-41c9-b5a5-f09944364367@b33g2000yqc.googlegroups.com> Message-ID: <4bb1e329$1@dnews.tpgi.com.au> On 03/27/2010 10:28 PM, Jonathan Hartley wrote: > one might like to name the complex block of logic, just to make it > readable: > > > x = 1 > def account_for_non_square_pixels(x): > ((some complex logic)) > account_for_non_square_pixels() > y = 2 > > > But defining and then calling the function like that is a tad > cumbersome. So I was wondering about: > I never liked the narrow definition of function as "reusable piece of code". This narrow definition implies that a piece of code used only once do not need to be made a function. I would rather define function as "a logically independent piece of code" and encourage refactorizing code into functions even if they are only used once as long as they are conceptually a "step" and being able to reuse code as a nice side-effect of it. Under this definition, the "some complex logic" conceptually is an independent piece of code that can (and probably should) be factorized. From alfps at start.no Tue Mar 30 07:40:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 30 Mar 2010 13:40:22 +0200 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: * Jean-Michel Pichavant: > John Nagle wrote: >> Jonathan Hayward wrote: >>> I've posted "Usability, the Soul of Python: An Introduction to the >>> Python Programming Language Through the Eyes of Usability", at: >>> >>> http://JonathansCorner.com/python/ >> >> No, it's just a rather verbose introduction to Python, in dark brown >> type on a light brown background. One could write a good paper on this >> topic, but this isn't it. >> >> >> John Nagle > Why is it bad ? Consider From a usability standpoint, the braces go with the lines to print out the stanza rather than the for statement or the code after, so the following is best: for(i = 99; i > 0; ++i) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i + 1); } This is just unsubstantiated opinion, but worse, it makes a tacit assumption that there is "best" way to do indentation. However, most programmers fall into that trap, and I've done it myself. In fact, when I worked as a consultant (then in Andersen Consulting, now Accenture) I used the style above. Petter Hesselberg, author of "Industrial Strength Windows Programming" (heh, I'm mentioned) asked my why on Earth I did that, like, nobody does that? It was a habit I'd picked up in Pascal, from very na?ve considerations of parse nesting levels, a kind of misguided idealism instead of more practical pragmatism, but since I realized that that was an incredibly weak argument I instead answered by pointing towards Charles Petzold's code in his "Programming Windows" books. And amazingly I was allowed to continue using this awkward and impractical style. I may or may not have been responsible for the similarly impractical compromise convention of using three spaces per indentation level. At least, in one big meeting the question about number of spaces was raised by the speaker, and I replied from the benches, just in jest, "three!". And that was it (perhaps). Cheers, - Alf (admitting to earlier mistakes) From contact at xavierho.com Tue Mar 30 08:11:05 2010 From: contact at xavierho.com (Xavier Ho) Date: Tue, 30 Mar 2010 22:11:05 +1000 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <2d56febf1003300511h617d7487t1bee6f69c6722a17@mail.gmail.com> Did no one notice that for(i = 99; i > 0; ++i) Gives you an infinite loop (sort of) because i starts a 99, and increases every loop? Cheers, Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: contact at xavierho.com Website: http://xavierho.com/ On Tue, Mar 30, 2010 at 9:40 PM, Alf P. Steinbach wrote: > * Jean-Michel Pichavant: > >> John Nagle wrote: >> >>> Jonathan Hayward wrote: >>> >>>> I've posted "Usability, the Soul of Python: An Introduction to the >>>> Python Programming Language Through the Eyes of Usability", at: >>>> >>>> http://JonathansCorner.com/python/ >>>> >>> >>> No, it's just a rather verbose introduction to Python, in dark brown >>> type on a light brown background. One could write a good paper on this >>> topic, but this isn't it. >>> >>> >>> John Nagle >>> >> Why is it bad ? >> > > Consider > > > > From a usability standpoint, the braces go with the lines to print out the > stanza rather than the for statement or the code after, so the following is > best: > > for(i = 99; i > 0; ++i) > { > printf("%d slabs of spam in my mail!\n", i); > printf("%d slabs of spam,\n", i); > printf("Send one to abuse and Just Hit Delete,\n"); > printf("%d slabs of spam in my mail!\n\n", i + 1); > } > > > > This is just unsubstantiated opinion, but worse, it makes a tacit > assumption that there is "best" way to do indentation. However, most > programmers fall into that trap, and I've done it myself. In fact, when I > worked as a consultant (then in Andersen Consulting, now Accenture) I used > the style above. Petter Hesselberg, author of "Industrial Strength Windows > Programming" (heh, I'm mentioned) asked my why on Earth I did that, like, > nobody does that? It was a habit I'd picked up in Pascal, from very na?ve > considerations of parse nesting levels, a kind of misguided idealism instead > of more practical pragmatism, but since I realized that that was an > incredibly weak argument I instead answered by pointing towards Charles > Petzold's code in his "Programming Windows" books. And amazingly I was > allowed to continue using this awkward and impractical style. > > I may or may not have been responsible for the similarly impractical > compromise convention of using three spaces per indentation level. At least, > in one big meeting the question about number of spaces was raised by the > speaker, and I replied from the benches, just in jest, "three!". And that > was it (perhaps). > > > Cheers, > > - Alf (admitting to earlier mistakes) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 30 09:46:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 09:46:20 -0400 Subject: StringChain -- a data structure for managing large sequences ofchunks of bytes In-Reply-To: <4bb1df60$1@dnews.tpgi.com.au> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> <4bae6130$1@dnews.tpgi.com.au> <4baf6ec6$0$8756$c3e8da3@news.astraweb.com> <4bb1df60$1@dnews.tpgi.com.au> Message-ID: Lie Ryan wrote: > On 03/29/2010 01:59 AM, Steven D'Aprano wrote: >> On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote: >> >>> On 03/22/2010 07:07 PM, Steven D'Aprano wrote: >>>> Perhaps you should have said that it was a wrapper around deque giving >>>> richer functionality, rather than giving the impression that it was a >>>> brand new data structure invented by you. People are naturally going to >>>> be more skeptical about a newly invented data structure than one based >>>> on a reliable, component like deque. >>> Well, technically StringChain is not a data structure in the first >>> place. StringChain is a string; >> And strings are data structures, as are arrays and structs. Just because >> they're simple data structures made directly from primitives rather than >> rich, complex structures, doesn't mean they're not data structures. > > Array is a way to structure data and thus a data structure; array is the > concept of structuring data using contiguous memory with elements > addressed by an index. string is just a contiguous memory reserved to > store data, or in other words: string is an array. This is what I meant > when I said string is not itself a data structure. > >>> a string that is implemented using deque >>> data structure to make appending algorithmically efficient. It is not a >>> data structure, in the sense that I can't put arbitrary "thing" into the >>> data structure. >> Any "thing" that can be pickled or serialised can be put into a string. > > Fair enough, you're right to think so but IMHO I disagree. Streams (or > perhaps 'blob' to avoid the connotation of FIFO) are the data structure > which you can put anything pickleable/serialisable into, but string (the > implementation of stream/blob using array) are just a special case of > array data structure and not a different, separate data structure than > array. > > Perhaps I should not make such a bold claim as saying string is not data > structure; what I have in mind is that string is just a special case of > array and not distinctly separate data structure than array. While this may be true conceptually it's certainly not true in Python (and in Python you need to be careful to distinguish between lists and arrays, since it does have both types). >From the point of view of the language, strings are primitives. But every Python implementation uses a data structure to store them, and the structure is definitely not the same as is used to store lists, or arrays (which in Python are container types, whereas the string isn't because the individual indexable elements are immutable). As always, it's better to seek common ground than pick the nits: I don't think that there's really that much difference between your approach and Steven's, but he's a well-known nit-picker (and we are *sometimes* grateful for it). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mwilson at the-wire.com Tue Mar 30 09:53:52 2010 From: mwilson at the-wire.com (Mel) Date: Tue, 30 Mar 2010 09:53:52 -0400 Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> <559a2ee3-fb2c-477f-a444-7edbb6da8676@r1g2000yqj.googlegroups.com> Message-ID: Patrick Maupin wrote: > Because sum() is the obvious way to sum floats; now the existence of > math.fsum() means there are TWO obvious ways to sum floats. Is that > really that hard to understand? How can you misconstrue this so badly > that you write something that can be (easily) interpreted to mean that > you think that I think that once math.fsum() exists, sum() doesn't > even exist any more???? floats are nasty -- as evidence the recent thread on comparing floats for equality. People use floats when they have to. fsum exists because of this: mwilson at tecumseth:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from math import fsum >>> a=(1.0e200, 156.0, -1.0e200) >>> sum(a) 0.0 >>> fsum(a) 156.0 You could generalize sum, but after that, there's a case that even fsum can't handle: >>> ni=1.0e200+1.0j >>> nj=1.0+1.0e200j >>> ai=(ni, nj, 156.0+651.0j, -ni, -nj) >>> sum(ai) (-1+0j) >>> fsum(ai) Traceback (most recent call last): File "", line 1, in TypeError: can't convert complex to float; use abs(z) >>> Mel. From sccolbert at gmail.com Tue Mar 30 10:25:54 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 10:25:54 -0400 Subject: "Usability, the Soul of Python" In-Reply-To: <2d56febf1003300511h617d7487t1bee6f69c6722a17@mail.gmail.com> References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <2d56febf1003300511h617d7487t1bee6f69c6722a17@mail.gmail.com> Message-ID: <7f014ea61003300725yf3dfcbdw2976160ca37f60f3@mail.gmail.com> not really, the int will eventually overflow and cycle around ;) On Tue, Mar 30, 2010 at 8:11 AM, Xavier Ho wrote: > Did no one notice that > > > for(i = 99; i > 0; ++i) > > Gives you an infinite loop (sort of) because i starts a 99, and increases > every loop? > > Cheers, > > Ching-Yun Xavier Ho, Technical Artist > > Contact Information > Mobile: (+61) 04 3335 4748 > Skype ID: SpaXe85 > Email: contact at xavierho.com > Website: http://xavierho.com/ > > > > On Tue, Mar 30, 2010 at 9:40 PM, Alf P. Steinbach wrote: > >> * Jean-Michel Pichavant: >> >>> John Nagle wrote: >>> >>>> Jonathan Hayward wrote: >>>> >>>>> I've posted "Usability, the Soul of Python: An Introduction to the >>>>> Python Programming Language Through the Eyes of Usability", at: >>>>> >>>>> http://JonathansCorner.com/python/ >>>>> >>>> >>>> No, it's just a rather verbose introduction to Python, in dark brown >>>> type on a light brown background. One could write a good paper on this >>>> topic, but this isn't it. >>>> >>>> >>>> John Nagle >>>> >>> Why is it bad ? >>> >> >> Consider >> >> >> >> >From a usability standpoint, the braces go with the lines to print out >> the stanza rather than the for statement or the code after, so the following >> is best: >> >> for(i = 99; i > 0; ++i) >> { >> printf("%d slabs of spam in my mail!\n", i); >> printf("%d slabs of spam,\n", i); >> printf("Send one to abuse and Just Hit Delete,\n"); >> printf("%d slabs of spam in my mail!\n\n", i + 1); >> } >> >> >> >> This is just unsubstantiated opinion, but worse, it makes a tacit >> assumption that there is "best" way to do indentation. However, most >> programmers fall into that trap, and I've done it myself. In fact, when I >> worked as a consultant (then in Andersen Consulting, now Accenture) I used >> the style above. Petter Hesselberg, author of "Industrial Strength Windows >> Programming" (heh, I'm mentioned) asked my why on Earth I did that, like, >> nobody does that? It was a habit I'd picked up in Pascal, from very na?ve >> considerations of parse nesting levels, a kind of misguided idealism instead >> of more practical pragmatism, but since I realized that that was an >> incredibly weak argument I instead answered by pointing towards Charles >> Petzold's code in his "Programming Windows" books. And amazingly I was >> allowed to continue using this awkward and impractical style. >> >> I may or may not have been responsible for the similarly impractical >> compromise convention of using three spaces per indentation level. At least, >> in one big meeting the question about number of spaces was raised by the >> speaker, and I replied from the benches, just in jest, "three!". And that >> was it (perhaps). >> >> >> Cheers, >> >> - Alf (admitting to earlier mistakes) >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bluemangroupie at gmail.com Tue Mar 30 11:13:02 2010 From: bluemangroupie at gmail.com (aditya) Date: Tue, 30 Mar 2010 08:13:02 -0700 (PDT) Subject: Binary Decimals in Python Message-ID: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. - Aditya From anand.shashwat at gmail.com Tue Mar 30 11:19:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 30 Mar 2010 20:49:52 +0530 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: decimal binary number is not included AFAIK On Tue, Mar 30, 2010 at 8:43 PM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > > - Aditya > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Tue Mar 30 11:28:50 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 30 Mar 2010 08:28:50 -0700 (PDT) Subject: Binary Decimals in Python References: Message-ID: <4e7acb50-797f-4e19-a915-90724cf157fc@u22g2000yqf.googlegroups.com> On Mar 30, 10:13?am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > > - Aditya So, why should int('1.1', 2) throw an error when int('1.1') doesn't? Regards, Pat From pmaupin at gmail.com Tue Mar 30 11:31:25 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 30 Mar 2010 08:31:25 -0700 (PDT) Subject: sum for sequences? References: <7x1vf91f60.fsf@ruckus.brouhaha.com> <1a715cad-6c6a-43d4-b708-a15538b2f27c@k36g2000prb.googlegroups.com> <4baddb7b$0$27866$c3e8da3@news.astraweb.com> <94640659-fbf6-436c-83e6-3fee9fcddb27@j16g2000prn.googlegroups.com> <35e10f7d-d7dc-4e4f-aa5a-8ba3ec5c0664@g10g2000yqh.googlegroups.com> <4bb13580$0$8827$c3e8da3@news.astraweb.com> <31c7977e-9c8d-4be0-ae21-3c490e6364fe@z35g2000yqd.googlegroups.com> <559a2ee3-fb2c-477f-a444-7edbb6da8676@r1g2000yqj.googlegroups.com> Message-ID: <9437e04d-b7ba-489e-9737-89cd1af41b40@k19g2000yqn.googlegroups.com> On Mar 30, 8:53?am, Mel wrote: > floats are nasty -- as evidence the recent thread on comparing floats for > equality. ?People use floats when they have to. ?fsum exists because of > this: ... I understand there are technical reasons for why math.fsum() exists. I still think that whatever math.fsum() does should probably be a part of sum(). Regards, Pat From kgo at grant-olson.net Tue Mar 30 11:35:21 2010 From: kgo at grant-olson.net (Grant Olson) Date: Tue, 30 Mar 2010 11:35:21 -0400 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: <4BB21A39.1070102@grant-olson.net> On 3/30/2010 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > Well technically that would be a 'radix point', not a decimal point. But I think the problem is that computers don't store fractional values that way internally. They either use floating or fixed point math. You would never look at raw binary data on a computer and see something like '1010.1010', and no one would write it that way, and no language (that I know of) would accept that as a valid value if you did something like "x = 0b1010.1010" So in that sense, it might not be an intentional oversight, but it's not a very practical or useful feature. From benjamin.kaplan at case.edu Tue Mar 30 11:37:36 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 30 Mar 2010 11:37:36 -0400 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > > - Aditya > -- Because int stands for integer and 1.1 is not an integer. You get the same error if you try doing int('1.1') > http://mail.python.org/mailman/listinfo/python-list > From tibor.beck at hotmail.com Tue Mar 30 11:40:56 2010 From: tibor.beck at hotmail.com (gentlestone) Date: Tue, 30 Mar 2010 08:40:56 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' Message-ID: Hi, how can I write the popular C/JAVA syntax in Python? Java example: return (a==b) ? 'Yes' : 'No' My first idea is: return ('No','Yes')[bool(a==b)] Is there a more elegant/common python expression for this? From anand.shashwat at gmail.com Tue Mar 30 11:43:39 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 30 Mar 2010 21:13:39 +0530 Subject: Binary Decimals in Python In-Reply-To: <4BB21A39.1070102@grant-olson.net> References: <4BB21A39.1070102@grant-olson.net> Message-ID: The conversion is not supported for decimal integers AFAIK, however '0b123.456' is always valid. I guess you can always get a decimal number convertor onto Python-recipes On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson wrote: > On 3/30/2010 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > > int('11',2) # returns 3 > > > > But decimal binary numbers throw a ValueError: > > > > int('1.1',2) # should return 1.5, throws error instead. > > > > Is this by design? It seems to me that this is not the correct > > behavior. > > > > Well technically that would be a 'radix point', not a decimal point. > > But I think the problem is that computers don't store fractional values > that way internally. They either use floating or fixed point math. You > would never look at raw binary data on a computer and see something like > '1010.1010', and no one would write it that way, and no language (that I > know of) would accept that as a valid value if you did something like "x > = 0b1010.1010" > > So in that sense, it might not be an intentional oversight, but it's not > a very practical or useful feature. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrmakent at cox.net Tue Mar 30 11:44:23 2010 From: mrmakent at cox.net (Mike Kent) Date: Tue, 30 Mar 2010 08:44:23 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: Message-ID: <034130b2-295b-4564-ac32-44de15d3f1c1@33g2000yqj.googlegroups.com> On Mar 30, 11:40?am, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > ? ? return (a==b) ? 'Yes' : 'No' > > My first idea is: > ? ? return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? return ('Yes' if a == b else 'No') From python at rcn.com Tue Mar 30 11:49:04 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 30 Mar 2010 08:49:04 -0700 (PDT) Subject: Binary Decimals in Python References: Message-ID: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> On Mar 30, 8:13?am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. The int() constructor returns integers. So, look to float() for non-integral values. Binary representation isn't supported yet, but we do have hex: >>> float.fromhex('1.8') 1.5 Raymond From kgo at grant-olson.net Tue Mar 30 11:51:49 2010 From: kgo at grant-olson.net (Grant Olson) Date: Tue, 30 Mar 2010 11:51:49 -0400 Subject: Binary Decimals in Python In-Reply-To: References: <4BB21A39.1070102@grant-olson.net> Message-ID: <4BB21E15.60507@grant-olson.net> Doh! Well the problem is that int's are integers. So yeah, you can't even do that with normal value "int ('2.1')" will also throw an error. And floats don't support radix conversion, because no-one really writes numbers that way. (At least computer programmers...) On 3/30/2010 11:43 AM, Shashwat Anand wrote: > The conversion is not supported for decimal integers AFAIK, however > '0b123.456' is always valid. I guess you can always get a decimal number > convertor onto Python-recipes > > > > On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson > wrote: > > On 3/30/2010 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > > int('11',2) # returns 3 > > > > But decimal binary numbers throw a ValueError: > > > > int('1.1',2) # should return 1.5, throws error instead. > > > > Is this by design? It seems to me that this is not the correct > > behavior. > > > > Well technically that would be a 'radix point', not a decimal point. > > But I think the problem is that computers don't store fractional values > that way internally. They either use floating or fixed point math. You > would never look at raw binary data on a computer and see something like > '1010.1010', and no one would write it that way, and no language (that I > know of) would accept that as a valid value if you did something like "x > = 0b1010.1010" > > So in that sense, it might not be an intentional oversight, but it's not > a very practical or useful feature. > -- > http://mail.python.org/mailman/listinfo/python-list > > From python at mrabarnett.plus.com Tue Mar 30 11:54:08 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 16:54:08 +0100 Subject: Binary Decimals in Python In-Reply-To: References: Message-ID: <4BB21EA0.5060306@mrabarnett.plus.com> aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this is not the correct > behavior. > int() returns an integer (hence the name!), so it should never return a float anyway. What you want is for float() to accept a base, but that is rarely needed. From bluemangroupie at gmail.com Tue Mar 30 11:54:43 2010 From: bluemangroupie at gmail.com (aditya) Date: Tue, 30 Mar 2010 08:54:43 -0700 (PDT) Subject: Binary Decimals in Python References: Message-ID: On Mar 30, 10:37?am, Benjamin Kaplan wrote: > On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws error instead. > > > Is this by design? It seems to me that this is not the correct > > behavior. > > > - Aditya > > -- > > Because int stands for integer and 1.1 is not an integer. You get the > same error if you try doing int('1.1') > > >http://mail.python.org/mailman/listinfo/python-list > > That makes sense. The closest thing I've found is this question on StackOverflow: http://stackoverflow.com/questions/1592158/python-convert-hex-to-float It seems to me that adding a conversion feature to floats would be a lot more intuitive. From mcfletch at vrplumber.com Tue Mar 30 11:56:08 2010 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Tue, 30 Mar 2010 11:56:08 -0400 Subject: PyDispatcher on sourceforge doesn't play nice with easy_install In-Reply-To: <4BB1B034.9020905@simplistix.co.uk> References: <4BB1B034.9020905@simplistix.co.uk> Message-ID: <4BB21F18.2010705@vrplumber.com> Chris Withers wrote: > Hi All, > > Using easy_install to get PyDispatcher results in: > ... > Who's the maintainer of PyDispatcher nowadays? Would be handy if they > removed the sourceforge link from pypi. ... Thanks for the report. I've released a 2.0.2 version on PyPI. That should now work properly with easy_install. HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From bluemangroupie at gmail.com Tue Mar 30 11:56:26 2010 From: bluemangroupie at gmail.com (aditya) Date: Tue, 30 Mar 2010 08:56:26 -0700 (PDT) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> Message-ID: <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> On Mar 30, 10:49?am, Raymond Hettinger wrote: > On Mar 30, 8:13?am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws error instead. > > > Is this by design? It seems to me that this is not the correct > > behavior. > > The int() constructor returns integers. > So, look to float() for non-integral values. > Binary representation isn't supported yet, > but we do have hex: > > ? ? >>> float.fromhex('1.8') > ? ? 1.5 > > Raymond That looks very elegant, thanks! From clp2 at rebertia.com Tue Mar 30 12:01:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 09:01:54 -0700 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: References: Message-ID: <50697b2c1003300901k157d10b0u7308b96a1f8be984@mail.gmail.com> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > ? ?return (a==b) ? 'Yes' : 'No' > > My first idea is: > ? ?return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? Yes, Python has ternary operator-like syntax: return ('Yes' if a==b else 'No') Note that this requires a recent version of Python. Cheers, Chris -- http://blog.rebertia.com From fetchinson at googlemail.com Tue Mar 30 12:17:04 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 30 Mar 2010 18:17:04 +0200 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <034130b2-295b-4564-ac32-44de15d3f1c1@33g2000yqj.googlegroups.com> References: <034130b2-295b-4564-ac32-44de15d3f1c1@33g2000yqj.googlegroups.com> Message-ID: >> Hi, how can I write the popular C/JAVA syntax in Python? >> >> Java example: >> return (a==b) ? 'Yes' : 'No' >> >> My first idea is: >> return ('No','Yes')[bool(a==b)] >> >> Is there a more elegant/common python expression for this? > > return ('Yes' if a == b else 'No') And for less clutter you can even leave the parenthesis: return 'Yes' if a == b else 'No' -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fordhaivat at gmail.com Tue Mar 30 12:23:28 2010 From: fordhaivat at gmail.com (Someone Something) Date: Tue, 30 Mar 2010 12:23:28 -0400 Subject: CPAN for python? Message-ID: Hi, I've learned python a few months ago but I still use Perl because of CPAN and the tremendous amount of stuff that's already been done for you. is there something like CPAN for python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Tue Mar 30 12:34:18 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Tue, 30 Mar 2010 09:34:18 -0700 (PDT) Subject: Python Script Creator/Generator (function factory) Message-ID: Hello, I have the following situation: I've got a 3rd party application that has a Python API. The applicaiton has integrated support for MIDI Hardware Controllers, which can be used to manipulate various parameters of the application. The app can also load Python User Scripts, which can define the mapping between the Controllers and Parameters, but they can also be used to define the behavior of those mappings as well. I want to provide my users a GUI App that allows them to map their MIDI Controllers to the application's Parameters, but with a specific behavior. Once they've defined the mappings and behavior, my application would generate a custom Python User Script, which then gets loaded by the 3rd party app. I've already got MIDI covered, and the GUI. Deployment via Pyinstaller has been taken care of as well. My application can currently map Controllers to Parameters in a 1:1 fashion, and can generate a simple python User Script with all the mappings. What I'm left with implementing is the behavior part. Let me give you a simple example of a possible behavior that the user could select: - The user has a button on their MIDI Hardware (a simple type of MIDI controller) - The first time the button is hit, a specific parameter is selected in the 3rd party application. - The second time the button is hit, a different parameter is selected. - And so on, depending on the behavior of the function that's mapped to that MIDI button So, in essence, a simple User Script would look something like this (pseudocode-ish): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ swap_parameters() if button1 was_hit_the_first_time: select parameter1 else: select parameter2 buttons = ( button1 = swap_parameters() button3 = parameter3 button4 = parameter4 ... ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ What I had in mind, was to have a collection of behaviors stored in a file (basically functions such as "swap_parameters") which the user could select via my application, map them to a specific MIDI Controller (such as a Button), and generate the User Script. In essence, I'm trying to build a function factory that's specific to the 3rd party application's provided API. But the user would have the ability to change the way the function works. In the above example, the user might want their MIDI Button to select parameter2 first, and parameter1 the second time. Has anyone had any experience with generating functionality this way, and could you give me some pointers in the right direction? Any tips, advice, book recommendations are more than welcome. Kind regards, Andrej Mitrovic From andrej.mitrovich at gmail.com Tue Mar 30 12:35:42 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Tue, 30 Mar 2010 09:35:42 -0700 (PDT) Subject: Python Script Creator/Generator (function factory) References: Message-ID: I forgot to mention, I'm using Python 2.5.x. I can't use Python 3 unfortunately, the 3rd party application uses Py2.5.x internally, so I have to limit the functionality to that version. From kushal.kumaran+python at gmail.com Tue Mar 30 12:51:40 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Tue, 30 Mar 2010 22:21:40 +0530 Subject: CPAN for python? In-Reply-To: References: Message-ID: <1e364c4e1003300951w58515844n222e79df61b60779@mail.gmail.com> On Tue, Mar 30, 2010 at 9:53 PM, Someone Something wrote: > Hi, > I've learned python a few months ago but I still use Perl because of CPAN > and the tremendous amount of stuff that's already been done for you. is > there something like CPAN for python? > Try PyPI. http://pypi.python.org/pypi -- regards, kushal From gatoygata2 at gmail.com Tue Mar 30 12:57:34 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 30 Mar 2010 09:57:34 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: Message-ID: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> On Mar 30, 5:40?pm, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > ? ? return (a==b) ? 'Yes' : 'No' > > My first idea is: > ? ? return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? (a==b) and 'YES' or 'NO' Yes, ugly Joaquin From robert.kern at gmail.com Tue Mar 30 12:58:39 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 11:58:39 -0500 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb22b39$0$1638$742ec2ed@news.sonic.net> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: On 2010-03-30 12:08 PM, John Nagle wrote: > Chris Rebert wrote: >> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >> wrote: >>> Hi, how can I write the popular C/JAVA syntax in Python? >>> >>> Java example: >>> return (a==b) ? 'Yes' : 'No' >>> >>> My first idea is: >>> return ('No','Yes')[bool(a==b)] >>> >>> Is there a more elegant/common python expression for this? >> >> Yes, Python has ternary operator-like syntax: >> return ('Yes' if a==b else 'No') >> >> Note that this requires a recent version of Python. > > Who let the dogs in? That's awful syntax. http://www.python.org/dev/peps/pep-0308/ -- 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 From anand.shashwat at gmail.com Tue Mar 30 13:03:51 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Tue, 30 Mar 2010 22:33:51 +0530 Subject: CPAN for python? In-Reply-To: <1e364c4e1003300951w58515844n222e79df61b60779@mail.gmail.com> References: <1e364c4e1003300951w58515844n222e79df61b60779@mail.gmail.com> Message-ID: This has been discussed tons of times. You should have atleast googled it. Python have nothing like CPAN and Cheese Shop (pypi) comes closest to it. On Tue, Mar 30, 2010 at 10:21 PM, Kushal Kumaran < kushal.kumaran+python at gmail.com > wrote: > On Tue, Mar 30, 2010 at 9:53 PM, Someone Something > wrote: > > Hi, > > I've learned python a few months ago but I still use Perl because of CPAN > > and the tremendous amount of stuff that's already been done for you. is > > there something like CPAN for python? > > > > Try PyPI. http://pypi.python.org/pypi > > -- > regards, > kushal > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 13:05:14 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 17:05:14 GMT Subject: Binary Decimals in Python References: <4e7acb50-797f-4e19-a915-90724cf157fc@u22g2000yqf.googlegroups.com> Message-ID: <4bb22f4a$0$8827$c3e8da3@news.astraweb.com> On Tue, 30 Mar 2010 08:28:50 -0700, Patrick Maupin wrote: > On Mar 30, 10:13?am, aditya wrote: >> To get the decimal representation of a binary number, I can just do >> this: >> >> int('11',2) # returns 3 >> >> But decimal binary numbers throw a ValueError: >> >> int('1.1',2) # should return 1.5, throws error instead. >> >> Is this by design? It seems to me that this is not the correct >> behavior. >> >> - Aditya > > So, why should int('1.1', 2) throw an error when int('1.1') doesn't? >>> int('1.1') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '1.1' int('1.1', 2) shouldn't return 1.5 because 1.5 isn't an integer. The obvious question is, why doesn't float('1.1', 2) work? The answer is that Python doesn't support floats in any base except 10. It's not something needed very often, and it's harder to get right than it might seem. -- Steven From philip at semanchuk.com Tue Mar 30 13:07:28 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 30 Mar 2010 13:07:28 -0400 Subject: CPAN for python? In-Reply-To: References: Message-ID: <37A3074F-2980-4241-AC59-19E3252D9C6A@semanchuk.com> On Mar 30, 2010, at 12:23 PM, Someone Something wrote: > Hi, > I've learned python a few months ago but I still use Perl because of > CPAN and the tremendous amount of stuff that's already been done for > you. is there something like CPAN for python? Yes and no, depending on what CPAN means to you. This question come up often; have a look in the archives. Here's one thread on the topic from last month: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ecd51ced8d24593e/f773e080024862cb?lnk=gst&q=cpan#f773e080024862cb From nagle at animats.com Tue Mar 30 13:08:31 2010 From: nagle at animats.com (John Nagle) Date: Tue, 30 Mar 2010 10:08:31 -0700 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: References: Message-ID: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Chris Rebert wrote: > On Tue, Mar 30, 2010 at 8:40 AM, gentlestone wrote: >> Hi, how can I write the popular C/JAVA syntax in Python? >> >> Java example: >> return (a==b) ? 'Yes' : 'No' >> >> My first idea is: >> return ('No','Yes')[bool(a==b)] >> >> Is there a more elegant/common python expression for this? > > Yes, Python has ternary operator-like syntax: > return ('Yes' if a==b else 'No') > > Note that this requires a recent version of Python. Who let the dogs in? That's awful syntax. John Nagle From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 13:09:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 17:09:18 GMT Subject: (a==b) ? 'Yes' : 'No' References: Message-ID: <4bb2303e$0$8827$c3e8da3@news.astraweb.com> On Tue, 30 Mar 2010 08:40:56 -0700, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: > return (a==b) ? 'Yes' : 'No' > > My first idea is: > return ('No','Yes')[bool(a==b)] You don't need the call to bool. ('No','Yes')[a==b] > Is there a more elegant/common python expression for this? The above is pretty elegant to my eyes, but you can also do: return 'Yes' if a==b else 'No' -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Mar 30 13:11:29 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 30 Mar 2010 17:11:29 GMT Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <4bb230c1$0$8827$c3e8da3@news.astraweb.com> On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote: >> Yes, Python has ternary operator-like syntax: return ('Yes' if a==b >> else 'No') >> >> Note that this requires a recent version of Python. > > Who let the dogs in? That's awful syntax. I used to think so to, but now I like it. It matches common English syntax like: "I'm going to the movies tonight, if I leave the office early, otherwise I'll stay home and nitpick on Usenet." -- Steven From sccolbert at gmail.com Tue Mar 30 13:12:04 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 13:12:04 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb22b39$0$1638$742ec2ed@news.sonic.net> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <7f014ea61003301012u2b52cf7bi75298750989c46a7@mail.gmail.com> On Tue, Mar 30, 2010 at 1:08 PM, John Nagle wrote: > Chris Rebert wrote: > >> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >> wrote: >> >>> Hi, how can I write the popular C/JAVA syntax in Python? >>> >>> Java example: >>> return (a==b) ? 'Yes' : 'No' >>> >>> My first idea is: >>> return ('No','Yes')[bool(a==b)] >>> >>> Is there a more elegant/common python expression for this? >>> >> >> Yes, Python has ternary operator-like syntax: >> return ('Yes' if a==b else 'No') >> >> Note that this requires a recent version of Python. >> > > Who let the dogs in? That's awful syntax. > > John Nagle > > -- > http://mail.python.org/mailman/listinfo/python-list > I wouldn't say that. It reads exactly how one would say it. I prefer this over the ? semantics. Whenever I see that, my mind goes "Does a equal b? If so, return this, otherwise return that". "Return this if a equals b, otherwise return that" is much more direct and declaritive IMHO. -------------- next part -------------- An HTML attachment was scrubbed... URL: From howe.steven at gmail.com Tue Mar 30 13:19:26 2010 From: howe.steven at gmail.com (Steven Howe) Date: Tue, 30 Mar 2010 10:19:26 -0700 Subject: CPAN for python? In-Reply-To: References: Message-ID: <4BB2329E.9050304@gmail.com> This question comes up at least once a month, eliciting a thread that goes on for day. Wouldn't it be wise to put a link on the bottom of the mail list? Something like CPAN for Python == PyPi << make that an href or Python( CPAN ) = PyPi Not too many characters. sph On 03/30/2010 09:23 AM, Someone Something wrote: > Hi, > I've learned python a few months ago but I still use Perl because of > CPAN and the tremendous amount of stuff that's already been done for > you. is there something like CPAN for python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From gatoygata2 at gmail.com Tue Mar 30 13:50:15 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 30 Mar 2010 10:50:15 -0700 (PDT) Subject: How many packages there are in PyPI Message-ID: <084b6a4e-27e6-45e0-bebf-256b41598f20@z3g2000yqz.googlegroups.com> Hi, PyPI is reaching the 10000 package figure (In the case of 3.x only about 140 packages and increasing very very slowly). Looking at available packages for 3.x I observed that some packages are listed several times. For example, lxml is listed 5 times. Are these repetitions included in the package count? If yes, just out of curiosity, somebody knows what the actual number of different packages in the PyPI reservoir is? Joaquin. From steve at holdenweb.com Tue Mar 30 13:56:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 13:56:04 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb22b39$0$1638$742ec2ed@news.sonic.net> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Chris Rebert wrote: >> On Tue, Mar 30, 2010 at 8:40 AM, gentlestone >> wrote: >>> Hi, how can I write the popular C/JAVA syntax in Python? >>> >>> Java example: >>> return (a==b) ? 'Yes' : 'No' >>> >>> My first idea is: >>> return ('No','Yes')[bool(a==b)] >>> >>> Is there a more elegant/common python expression for this? >> >> Yes, Python has ternary operator-like syntax: >> return ('Yes' if a==b else 'No') >> >> Note that this requires a recent version of Python. > > Who let the dogs in? That's awful syntax. > Yes, that's deliberately awful syntax. Guido designed it that way to ensure that people didn't aver-use it, thereby reducing the readability of Python applications. Speaking purely personally I hardly ever use it, but don't dislike it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mensanator at aol.com Tue Mar 30 14:03:27 2010 From: mensanator at aol.com (Mensanator) Date: Tue, 30 Mar 2010 11:03:27 -0700 (PDT) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> Message-ID: <4eea3f36-10da-498a-890b-d879aac1fb86@y14g2000yqm.googlegroups.com> On Mar 30, 10:49?am, Raymond Hettinger wrote: > On Mar 30, 8:13?am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws error instead. > > > Is this by design? It seems to me that this is not the correct > > behavior. > > The int() constructor returns integers. > So, look to float() for non-integral values. > Binary representation isn't supported yet, It is supported in the gmpy module. >>> import gmpy >>> help(gmpy.mpf) Help on built-in function mpf in module gmpy: mpf(...) mpf(n): builds an mpf object with a numeric value n (n may be any Python number, or an mpz, mpq, or mpf object) and a default precision (in bits) depending on the nature of n mpf(n,bits=0): as above, but with the specified number of bits (0 means to use default precision, as above) mpf(s,bits=0,base=10): builds an mpf object from a string s made up of digits in the given base, possibly with fraction-part (with period as a separator) and/or exponent-part (with exponent marker 'e' for base<=10, else '@'). If base=256, s must be a gmpy.mpf portable binary representation as built by the function gmpy.fbinary (and the .binary method of mpf objects). The resulting mpf object is built with a default precision (in bits) if bits is 0 or absent, else with the specified number of bits. >>> gmpy.mpf('1.1',0,2) mpf('1.5e0') > but we do have hex: > > ? ? >>> float.fromhex('1.8') > ? ? 1.5 > > Raymond From robert.kern at gmail.com Tue Mar 30 14:05:13 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 13:05:13 -0500 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <4bb230c1$0$8827$c3e8da3@news.astraweb.com> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <4bb230c1$0$8827$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-30 12:11 PM, Steven D'Aprano wrote: > On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote: > >>> Yes, Python has ternary operator-like syntax: return ('Yes' if a==b >>> else 'No') >>> >>> Note that this requires a recent version of Python. >> >> Who let the dogs in? That's awful syntax. > > I used to think so to, but now I like it. It matches common English > syntax like: > > "I'm going to the movies tonight, if I leave the office early, otherwise > I'll stay home and nitpick on Usenet." I would suggest that this is much more common and less awkward English usage: "If I leave the office early, I'm going to the movies tonight; otherwise, I'll stay home and nitpick on Usenet." I don't have a problem with the current syntax, and while its English analogue is grammatical, I don't think you can rightly call it idiomatic. -- 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 From invalid at invalid.invalid Tue Mar 30 14:08:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Mar 2010 18:08:14 +0000 (UTC) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: On 2010-03-30, John Nagle wrote: > Hex floats are useful because you can get a string representation of > the exact value of a binary floating point number. It should always > be the case that > > float.fromhex(float.hex(x)) == x Until you try running your program on a machine that represents floats using a radix other than 2,4, or 16. ;) And it works for NaN and Inf too! It would have been nice to have had that 5-6 years ago when I had to write my own pickle/unpickle methods for floating point values so that inf and nan were portable between Windows and Linux. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From nagle at animats.com Tue Mar 30 14:14:07 2010 From: nagle at animats.com (John Nagle) Date: Tue, 30 Mar 2010 11:14:07 -0700 Subject: Binary Decimals in Python In-Reply-To: <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> Message-ID: <4bb23a99$0$1582$742ec2ed@news.sonic.net> aditya wrote: > On Mar 30, 10:49 am, Raymond Hettinger wrote: >> On Mar 30, 8:13 am, aditya wrote: >> >>> To get the decimal representation of a binary number, I can just do >>> this: >>> int('11',2) # returns 3 >>> But decimal binary numbers throw a ValueError: >>> int('1.1',2) # should return 1.5, throws error instead. >>> Is this by design? It seems to me that this is not the correct >>> behavior. >> The int() constructor returns integers. >> So, look to float() for non-integral values. >> Binary representation isn't supported yet, >> but we do have hex: >> >> >>> float.fromhex('1.8') >> 1.5 >> >> Raymond > > That looks very elegant, thanks! Hex floats are useful because you can get a string representation of the exact value of a binary floating point number. It should always be the case that float.fromhex(float.hex(x)) == x That's not always true of decimal representations, due to rounding problems. Long discussion of this here: "http://bugs.python.org/issue1580" John Nagle From no.spam at local.local Tue Mar 30 14:16:09 2010 From: no.spam at local.local (Robert Fendt) Date: Tue, 30 Mar 2010 20:16:09 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <20100330201609.6ef12ee1@vulcan.local> And thus spake Steve Holden Tue, 30 Mar 2010 13:56:04 -0400: > >> Yes, Python has ternary operator-like syntax: > >> return ('Yes' if a==b else 'No') > >> > >> Note that this requires a recent version of Python. > > > > Who let the dogs in? That's awful syntax. > > Yes, that's deliberately awful syntax. Guido designed it that way to > ensure that people didn't aver-use it, thereby reducing the readability > of Python applications. Speaking purely personally I hardly ever use it, > but don't dislike it. In fact, the syntax just shouts 'do [...] unless' to me. And that's so strong a Perl-ism I cannot quite express how ugly I actually find it... Regards, Robert From nagle at animats.com Tue Mar 30 14:24:05 2010 From: nagle at animats.com (John Nagle) Date: Tue, 30 Mar 2010 11:24:05 -0700 Subject: How many packages there are in PyPI In-Reply-To: <084b6a4e-27e6-45e0-bebf-256b41598f20@z3g2000yqz.googlegroups.com> References: <084b6a4e-27e6-45e0-bebf-256b41598f20@z3g2000yqz.googlegroups.com> Message-ID: <4BB241C5.60501@animats.com> Joaquin Abian wrote: > Hi, > PyPI is reaching the 10000 package figure (In the case of 3.x only > about 140 packages and increasing very very slowly). > > Looking at available packages for 3.x I observed that some packages > are listed several times. For example, lxml is listed 5 times. > Are these repetitions included in the package count? If yes, just out > of curiosity, somebody knows what the actual number of different > packages in the PyPI reservoir is? > > Joaquin. There aren't that many packages "in" PyPI. It's more of a directory than a repository. And some of the links are dead. I just tried "Dejavu", which only has a link to "projects.amor.org". That subdomain is dead. "amor.org" is some kind of religious organization. John Nagle From python at mrabarnett.plus.com Tue Mar 30 14:52:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 19:52:36 +0100 Subject: Binary Decimals in Python In-Reply-To: <4bb23a99$0$1582$742ec2ed@news.sonic.net> References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: <4BB24874.6020309@mrabarnett.plus.com> John Nagle wrote: > aditya wrote: >> On Mar 30, 10:49 am, Raymond Hettinger wrote: >>> On Mar 30, 8:13 am, aditya wrote: >>> >>>> To get the decimal representation of a binary number, I can just do >>>> this: >>>> int('11',2) # returns 3 >>>> But decimal binary numbers throw a ValueError: >>>> int('1.1',2) # should return 1.5, throws error instead. >>>> Is this by design? It seems to me that this is not the correct >>>> behavior. >>> The int() constructor returns integers. >>> So, look to float() for non-integral values. >>> Binary representation isn't supported yet, >>> but we do have hex: >>> >>> >>> float.fromhex('1.8') >>> 1.5 >>> >>> Raymond >> >> That looks very elegant, thanks! > > Hex floats are useful because you can get a string representation > of the exact value of a binary floating point number. It should > always be the case that > > float.fromhex(float.hex(x)) == x > > That's not always true of decimal representations, due to rounding > problems. > Floats have a limited length, unlike ints which are virtually unlimited. > Long discussion of this here: "http://bugs.python.org/issue1580" > From john at castleamber.com Tue Mar 30 15:19:19 2010 From: john at castleamber.com (John Bokma) Date: Tue, 30 Mar 2010 13:19:19 -0600 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> Message-ID: <87sk7h8vns.fsf@castleamber.com> Robert Fendt writes: > In fact, the syntax just shouts 'do [...] unless' to me. And > that's so strong a Perl-ism I cannot quite express how ugly I > actually find it... And a == b and 'Yes' or 'No' isn't a Perl-ism? Sheesh, this group would be so much nicer without the constant dragging in of Perl to make a point. On top of that, do { } unless blocks are not idomatic in Perl. Perl Best Practices even clearly states to *never* use unless. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From quentel.pierre at wanadoo.fr Tue Mar 30 15:38:08 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Tue, 30 Mar 2010 12:38:08 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> Message-ID: <5ef544bb-95a0-4329-80ef-f679d62b8ead@z11g2000yqz.googlegroups.com> On 30 mar, 21:19, John Bokma wrote: > Robert Fendt writes: > > In fact, the syntax just shouts 'do [...] unless' to me. And > > that's so strong a Perl-ism I cannot quite express how ugly I > > actually find it... > > And > > ?a == b and 'Yes' or 'No' > > isn't a Perl-ism? > > Sheesh, this group would be so much nicer without the constant dragging > in of Perl to make a point. On top of that, do { ?} unless blocks are > not idomatic in Perl. Perl Best Practices even clearly states to *never* > use unless. > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development I'm surprised nobody proposed a solution with itertools ;-) - Pierre From russ.paielli at gmail.com Tue Mar 30 16:03:37 2010 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 30 Mar 2010 13:03:37 -0700 (PDT) Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: According to Wikipedia, this is called the Whitesmith style: for(i = 99; i > 0; ++i) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i + 1); } I agree with the Mr. Hayward that it is preferable to the more common K&R style, because the braces do not violate and visually clutter the logical indentation structure. It looks more like Python. The deeper the level of nesting, the more this style reduces visual clutter compared to the conventional style. A slightly better style, in my opinion, is the Banner style: for(i = 99; i > 0; ++i) { // a blank line here is optional printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i + 1); } On Mar 30, 4:40?am, "Alf P. Steinbach" wrote: > * Jean-Michel Pichavant: > > > John Nagle wrote: > >> Jonathan Hayward wrote: > >>> I've posted "Usability, the Soul of Python: An Introduction to the > >>> Python Programming Language Through the Eyes of Usability", at: > > >>> ? ?http://JonathansCorner.com/python/ > > >> ? ?No, it's just a rather verbose introduction to Python, in dark brown > >> type on a light brown background. ?One could write a good paper on this > >> topic, but this isn't it. > > >> ? ? ? ? ? ? ? ? John Nagle > > Why is it bad ? > > Consider > > > ?From a usability standpoint, the braces go with the lines to print out the > stanza rather than the for statement or the code after, so the following is best: > > for(i = 99; i > 0; ++i) > ? ? ?{ > ? ? ?printf("%d slabs of spam in my mail!\n", i); > ? ? ?printf("%d slabs of spam,\n", i); > ? ? ?printf("Send one to abuse and Just Hit Delete,\n"); > ? ? ?printf("%d slabs of spam in my mail!\n\n", i + 1); > ? ? ?} > > > This is just unsubstantiated opinion, but worse, it makes a tacit assumption > that there is "best" way to do indentation. However, most programmers fall into > that trap, and I've done it myself. In fact, when I worked as a consultant (then > in Andersen Consulting, now Accenture) I used the style above. Petter > Hesselberg, author of "Industrial Strength Windows Programming" (heh, I'm > mentioned) asked my why on Earth I did that, like, nobody does that? It was a > habit I'd picked up in Pascal, from very na?ve considerations of parse nesting > levels, a kind of misguided idealism instead of more practical pragmatism, but > since I realized that that was an incredibly weak argument I instead answered by > pointing towards Charles Petzold's code in his "Programming Windows" books. And > amazingly I was allowed to continue using this awkward and impractical style. > > I may or may not have been responsible for the similarly impractical compromise > convention of using three spaces per indentation level. At least, in one big > meeting the question about number of spaces was raised by the speaker, and I > replied from the benches, just in jest, "three!". And that was it (perhaps). > > Cheers, > > - Alf ?(admitting to earlier mistakes) From no.spam at local.local Tue Mar 30 16:16:00 2010 From: no.spam at local.local (Robert Fendt) Date: Tue, 30 Mar 2010 22:16:00 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> Message-ID: <20100330221600.42cd3536@vulcan.local> And thus spake John Bokma Tue, 30 Mar 2010 13:19:19 -0600: > And > > a == b and 'Yes' or 'No' > > isn't a Perl-ism? I never said that this would be better. I don't even get the point of what the advantage is supposed to be of inverting the order of the return statement and the conditional check what should actually _be_ returned. What's wrong with just writing if a==b: return 'Yes' else: return 'No' apart from it being a few more line breaks and an additional return statement? The inverted form is not more readable per se (in fact, quite the opposite), and I would even suggest to minimise its use even in languages like C++ and Java. The Python syntax is even worse since it not only inverts the order of return statement and conditional check, but it also puts the conditional between the two results. I find such a convoluted construct especially ugly in a language which I previously regarded as having a rather striking beauty of syntactical simplicity. The construct is superfluous, illogical, unelegant, and thus very un-pythonesque, IMHO. But of course that's just my $0.02. > Sheesh, this group would be so much nicer without the constant dragging > in of Perl to make a point. On top of that, do { } unless blocks are > not idomatic in Perl. Perl Best Practices even clearly states to *never* > use unless. Sorry, but you have just underlined my point, in fact. If it's discouraged by experts, then of course the question must be valid why such a feature even exists (okay, apart from 'it seemed like a good idea at the time'). And more importantly (and more on-topic here), why we have to have an analogon in Python. Regards, Robert From ckaynor at zindagigames.com Tue Mar 30 16:19:33 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 30 Mar 2010 13:19:33 -0700 Subject: Binary Decimals in Python In-Reply-To: <4bb23a99$0$1582$742ec2ed@news.sonic.net> References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: Chris On Tue, Mar 30, 2010 at 11:14 AM, John Nagle wrote: > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: >> >>> On Mar 30, 8:13 am, aditya wrote: >>> >>> To get the decimal representation of a binary number, I can just do >>>> this: >>>> int('11',2) # returns 3 >>>> But decimal binary numbers throw a ValueError: >>>> int('1.1',2) # should return 1.5, throws error instead. >>>> Is this by design? It seems to me that this is not the correct >>>> behavior. >>>> >>> The int() constructor returns integers. >>> So, look to float() for non-integral values. >>> Binary representation isn't supported yet, >>> but we do have hex: >>> >>> >>> float.fromhex('1.8') >>> 1.5 >>> >>> Raymond >>> >> >> That looks very elegant, thanks! >> > > Hex floats are useful because you can get a string representation > of the exact value of a binary floating point number. It should > always be the case that > > float.fromhex(float.hex(x)) == x > > That's not always true of decimal representations, due to rounding > problems. > Actually, any number you can represent exactly in base 2 (or any power there of) you can also represent exactly in decimal - its the other way around thats a problem. > > Long discussion of this here: "http://bugs.python.org/issue1580" > > > John Nagle > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 30 16:32:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 16:32:51 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <20100330221600.42cd3536@vulcan.local> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: Robert Fendt wrote: > And thus spake John Bokma > Tue, 30 Mar 2010 13:19:19 -0600: > >> And >> >> a == b and 'Yes' or 'No' >> >> isn't a Perl-ism? > > I never said that this would be better. I don't even get the > point of what the advantage is supposed to be of inverting the > order of the return statement and the conditional check what > should actually _be_ returned. What's wrong with just writing > > if a==b: > return 'Yes' > else: > return 'No' > > apart from it being a few more line breaks and an additional > return statement? The inverted form is not more readable per > se (in fact, quite the opposite), and I would even suggest to > minimise its use even in languages like C++ and Java. The Python > syntax is even worse since it not only inverts the order of > return statement and conditional check, but it also puts the > conditional between the two results. > > I find such a convoluted construct especially ugly in a language > which I previously regarded as having a rather striking beauty > of syntactical simplicity. The construct is superfluous, > illogical, unelegant, and thus very un-pythonesque, IMHO. But of > course that's just my $0.02. > >> Sheesh, this group would be so much nicer without the constant dragging >> in of Perl to make a point. On top of that, do { } unless blocks are >> not idomatic in Perl. Perl Best Practices even clearly states to *never* >> use unless. > > Sorry, but you have just underlined my point, in fact. If it's > discouraged by experts, then of course the question must be > valid why such a feature even exists (okay, apart from 'it > seemed like a good idea at the time'). And more importantly (and > more on-topic here), why we have to have an analogon in Python. It exists because people nagged Guido mercilessly until, against his better judgment, he capitulated. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From saimapk81 at gmail.com Tue Mar 30 16:33:15 2010 From: saimapk81 at gmail.com (saima81) Date: Tue, 30 Mar 2010 13:33:15 -0700 (PDT) Subject: "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ Message-ID: <57003757-f992-4c10-82d5-1d91fe247d35@z35g2000yqd.googlegroups.com> "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ "jobs in kuwait" "jobs in kuwait for pakistanis" "jobs in kuwait 2010" "jobs in kuwait airways" "jobs in kuwait banks" "jobs in kuwait telecom" "kuwait jobs" "kuwait airways" "kuwait jobs online" on http://jobsinkuwait-net.blogspot.com/ From lxkain at gmail.com Tue Mar 30 16:43:42 2010 From: lxkain at gmail.com (LX) Date: Tue, 30 Mar 2010 13:43:42 -0700 (PDT) Subject: decorators only when __debug__ == True References: Message-ID: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> On Mar 29, 6:34?pm, MRAB wrote: > LX wrote: > > Hi all, I have a question about decorators. I would like to use them > > for argument checking, and pre/post conditions. However, I don't want > > the additional overhead when I run in non-debug mode. I could do > > something like this, using a simple trace example. > > > @decorator > > def pass_decorator(f, *args, **kw): # what about the slow-down that > > incurs when using pass_decorator? > > ? ? return f(*args, **kw) > > > @decorator > > def trace_decorator(f, *args, **kw): > > ? ? print "calling %s with args %s, %s" % (f.func_name, args, kw) > > ? ? return f(*args, **kw) > > > trace_enable_flag = False #__debug__ > > trace = trace_decorator if trace_enable_flag else pass_decorator > > > Trouble is, there is still an additional encapsulating function call. > > Is there any way to eliminate the extra function call altogether? > > Thanks in advance! > > I think you have misunderstood certain details about decorators. > > This code with a decorator: > > ? ? ?@decorator > ? ? ?def hello(): > ? ? ? ? ?print "hello world" > > basically does this: > > ? ? ?def hello(): > ? ? ? ? ?print "hello world" > ? ? ?hello = decorator(hello) > > so your non-decorator just needs to return the function it was passed: > > ? ? ?def pass_decorator(func): > ? ? ? ? ?return func > > and your trace decorator would be something like this: > > ? ? ?def trace_decorator(func): > ? ? ? ? ?def show(*args, **kwargs): > ? ? ? ? ? ? ?print "calling %s with args %s, %s" % (func.func_name, > args, kwargs) > ? ? ? ? ? ? ?result = func(*args, **kwargs) > ? ? ? ? ? ? ?print "returning %s from %s" % (result, func.func_name) > ? ? ? ? ? ? ?return result > ? ? ? ? ?return show Sure, but during runtime, pass_decorator will still be called, even though it doesn't do anything. I am wondering if I can disable this additional function call at non-debug runtime. In other words, I want the calling stack to contain no decorator at all, not even pass_decorator. I should mention that, in my code, the symbol "decorator" is imported from Michele Simionato's decorator.py file. From lxkain at gmail.com Tue Mar 30 16:44:40 2010 From: lxkain at gmail.com (LX) Date: Tue, 30 Mar 2010 13:44:40 -0700 (PDT) Subject: decorators only when __debug__ == True References: Message-ID: On Mar 29, 7:11?pm, Steven D'Aprano wrote: > On Mon, 29 Mar 2010 17:54:26 -0700, LX wrote: > > Hi all, I have a question about decorators. I would like to use them for > > argument checking, and pre/post conditions. However, I don't want the > > additional overhead when I run in non-debug mode. I could do something > > like this, using a simple trace example. > > def decorator(func): > ? ? if __debug__: > ? ? ? ? @functools.wraps(func) > ? ? ? ? def inner(*args, **kwargs): > ? ? ? ? ? ? preprocess() > ? ? ? ? ? ? result = func(*args, **kwargs) > ? ? ? ? ? ? postprocess() > ? ? ? ? ? ? return result > ? ? ? ? return inner > ? ? else: > ? ? ? ? return func > > -- > Steven Actually, I am using "decorator" from Michele Simionato's decorator.py file, at http://pypi.python.org/pypi/decorator. From anton.shishkov at gmail.com Tue Mar 30 16:47:42 2010 From: anton.shishkov at gmail.com (ASh) Date: Tue, 30 Mar 2010 13:47:42 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: Message-ID: Hi, please help me understand why am I getting error with this query new_start_date = "NOW() - '29 days'::INTERVAL" self.dyndb.orderdb.query('''update xxxx set creation_date = %s where id_order = %s''', (new_start_date, "123")) ... psycopg2.DataError: invalid input syntax for type timestamp with time zone: "NOW() - '29 days'::INTERVAL" From news1234 at free.fr Tue Mar 30 17:01:40 2010 From: news1234 at free.fr (News123) Date: Tue, 30 Mar 2010 23:01:40 +0200 Subject: xpat error in xmlrp client. How to inspect data. In-Reply-To: References: <4bab1f4a$0$25677$426a74cc@news.free.fr> Message-ID: <4bb266b5$0$21786$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Thu, 25 Mar 2010 05:31:05 -0300, News123 escribi?: > >> I'm havign a small xmlrpc client, which works normally fine. >> (xmlrpc via https) >> >> Sometimes however I receive an Exception about an expat error. >> >> >> The output, that I receive is: >> File "C:\mycode\myrpcclient.py", line 63, in upload_chunk >> rslt = myrpcclient.call() >> File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ >> return self.__send(self.__name, args) >> File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request >> verbose=self.__verbose >> File "C:\Python26\lib\xmlrpclib.py", line 1253, in request >> return self._parse_response(h.getfile(), sock) >> File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response >> p.feed(response) >> File "C:\Python26\lib\xmlrpclib.py", line 601, in feed >> self._parser.Parse(data, 0) >> ExpatError: syntax error: line 1, column 0 >> > > a) Use the standard cgitb module (despite its name, it is useful outside > CGI scripts) > > b) Use the tb module available from http://pypi.python.org/pypi/tb > I'm currently using the default module traceback and code, which looks roughly like: try: xmlrpccall() except Exception as e: ex_type,ex_value,e_b = sys.exc_info() tbstring = traceback.format_exc() logging.error('%s:%s:%s' % (ex_type,ex_value,tbstring) do cgitb or tb really provide much more info? > Both provide a more verbose traceback, including local variables at each > execution frame. > > c) Replace ("monkey-patch") the feed() method with a more debug-friendly > version: > > def feed(self, data): > try: > self._parser.Parse(data, 0) > except xmlrpclib.expat.ExpatError, e: > e.args += (data,) > raise > > xmlrpclib.ExpatParser.feed = feed Well, the monkey patch seems to be THE solution for my problem. Thanks a lot. Now I'll just have to wait till the problem shows up again. Probably I'll just display the backtrace in the except section. > > (Or perhaps set e.data = data) > > d) In your exception handler, walk the traceback object until you reach > the feed() call, and inspect the corresponding tb_frame.f_locals > dictionary. How can I walk a traceback? For the current problem the the monkeypatch should be good enough, but for other cases it might be good to know. bye N From mensanator at aol.com Tue Mar 30 17:05:44 2010 From: mensanator at aol.com (Mensanator) Date: Tue, 30 Mar 2010 14:05:44 -0700 (PDT) Subject: Binary Decimals in Python References: <24939652-22cb-47f1-97d5-3941463dd7b3@h27g2000yqm.googlegroups.com> <1c1313db-16ac-4c40-bc89-2950cd9f5592@g10g2000yqh.googlegroups.com> <4bb23a99$0$1582$742ec2ed@news.sonic.net> Message-ID: <951faaf2-affd-474c-811b-157579b2897c@g10g2000yqh.googlegroups.com> On Mar 30, 1:52?pm, MRAB wrote: > John Nagle wrote: > > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: > >>> On Mar 30, 8:13 am, aditya wrote: > > >>>> To get the decimal representation of a binary number, I can just do > >>>> this: > >>>> int('11',2) # returns 3 > >>>> But decimal binary numbers throw a ValueError: > >>>> int('1.1',2) # should return 1.5, throws error instead. > >>>> Is this by design? It seems to me that this is not the correct > >>>> behavior. > >>> The int() constructor returns integers. > >>> So, look to float() for non-integral values. > >>> Binary representation isn't supported yet, > >>> but we do have hex: > > >>> ? ? >>> float.fromhex('1.8') > >>> ? ? 1.5 > > >>> Raymond > > >> That looks very elegant, thanks! > > > ? ?Hex floats are useful because you can get a string representation > > of the exact value of a binary floating point number. ?It should > > always be the case that > > > ? ? ?float.fromhex(float.hex(x)) == x > > > That's not always true of decimal representations, due to rounding > > problems. > > Floats have a limited length, unlike ints which are virtually unlimited. gmpy gives you arbitrary precision floats, also. > > > > > Long discussion of this here: "http://bugs.python.org/issue1580"- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - From philip at semanchuk.com Tue Mar 30 17:26:51 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 30 Mar 2010 17:26:51 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: References: Message-ID: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> On Mar 30, 2010, at 4:47 PM, ASh wrote: > Hi, please help me understand why am I getting error with this query > > > new_start_date = "NOW() - '29 days'::INTERVAL" > self.dyndb.orderdb.query('''update xxxx set creation_date > = %s > where id_order = %s''', (new_start_date, "123")) > > > > ... > psycopg2.DataError: invalid input syntax for type timestamp with time > zone: "NOW() - '29 days'::INTERVAL" Hi Anton, It sounds to me like the problem is with your SQL rather than with psycopg2 or Python. Try the query directly in Postgres -- does it work there? If so, then your next step should be to ask on the psycopg2 mailing list that Google can find for you. Good luck Philip From hp6 at rice.edu Tue Mar 30 17:31:58 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 16:31:58 -0500 Subject: A question about making a sort-of-counter. Message-ID: <4BB26DCE.7070307@rice.edu> Suppose I have a list. a = list() And suppose allowed digits as the element are 1,2,3,4,5. What can I do in order to iterate over all possible values for each element? For instance, the sequence of the list I want to have would be [1,1,1,1,1] [1,1,1,1,2] [1,1,1,1,3] .... [5,5,5,5,4] [5,5,5,5,5] How can I make it happen? Thanks, Justin. From python at mrabarnett.plus.com Tue Mar 30 17:41:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 22:41:31 +0100 Subject: decorators only when __debug__ == True In-Reply-To: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <4BB2700B.90200@mrabarnett.plus.com> LX wrote: > On Mar 29, 6:34 pm, MRAB wrote: >> LX wrote: >>> Hi all, I have a question about decorators. I would like to use them >>> for argument checking, and pre/post conditions. However, I don't want >>> the additional overhead when I run in non-debug mode. I could do >>> something like this, using a simple trace example. >>> @decorator >>> def pass_decorator(f, *args, **kw): # what about the slow-down that >>> incurs when using pass_decorator? >>> return f(*args, **kw) >>> @decorator >>> def trace_decorator(f, *args, **kw): >>> print "calling %s with args %s, %s" % (f.func_name, args, kw) >>> return f(*args, **kw) >>> trace_enable_flag = False #__debug__ >>> trace = trace_decorator if trace_enable_flag else pass_decorator >>> Trouble is, there is still an additional encapsulating function call. >>> Is there any way to eliminate the extra function call altogether? >>> Thanks in advance! >> I think you have misunderstood certain details about decorators. >> >> This code with a decorator: >> >> @decorator >> def hello(): >> print "hello world" >> >> basically does this: >> >> def hello(): >> print "hello world" >> hello = decorator(hello) >> >> so your non-decorator just needs to return the function it was passed: >> >> def pass_decorator(func): >> return func >> >> and your trace decorator would be something like this: >> >> def trace_decorator(func): >> def show(*args, **kwargs): >> print "calling %s with args %s, %s" % (func.func_name, >> args, kwargs) >> result = func(*args, **kwargs) >> print "returning %s from %s" % (result, func.func_name) >> return result >> return show > > Sure, but during runtime, pass_decorator will still be called, even > though it doesn't do anything. I am wondering if I can disable this > additional function call at non-debug runtime. In other words, I want > the calling stack to contain no decorator at all, not even > pass_decorator. > > I should mention that, in my code, the symbol "decorator" is imported > from Michele Simionato's decorator.py file. pass_decorator will be called when the decorated function is _defined_, but not when the decorated function is _called_. From python at mrabarnett.plus.com Tue Mar 30 17:43:04 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Mar 2010 22:43:04 +0100 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <20100330221600.42cd3536@vulcan.local> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <4BB27068.9020009@mrabarnett.plus.com> Robert Fendt wrote: > And thus spake John Bokma > Tue, 30 Mar 2010 13:19:19 -0600: > >> And >> >> a == b and 'Yes' or 'No' >> >> isn't a Perl-ism? > > I never said that this would be better. I don't even get the > point of what the advantage is supposed to be of inverting the > order of the return statement and the conditional check what > should actually _be_ returned. What's wrong with just writing > > if a==b: > return 'Yes' > else: > return 'No' > > apart from it being a few more line breaks and an additional > return statement? The inverted form is not more readable per > se (in fact, quite the opposite), and I would even suggest to > minimise its use even in languages like C++ and Java. The Python > syntax is even worse since it not only inverts the order of > return statement and conditional check, but it also puts the > conditional between the two results. > > I find such a convoluted construct especially ugly in a language > which I previously regarded as having a rather striking beauty > of syntactical simplicity. The construct is superfluous, > illogical, unelegant, and thus very un-pythonesque, IMHO. But of > course that's just my $0.02. > I think you mean that it's very _un-Pythonic_ (perhaps because it's very very Pythonesque)! :-) >> Sheesh, this group would be so much nicer without the constant dragging >> in of Perl to make a point. On top of that, do { } unless blocks are >> not idomatic in Perl. Perl Best Practices even clearly states to *never* >> use unless. > > Sorry, but you have just underlined my point, in fact. If it's > discouraged by experts, then of course the question must be > valid why such a feature even exists (okay, apart from 'it > seemed like a good idea at the time'). And more importantly (and > more on-topic here), why we have to have an analogon in Python. > From no.spam at local.local Tue Mar 30 17:47:27 2010 From: no.spam at local.local (Robert Fendt) Date: Tue, 30 Mar 2010 23:47:27 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <20100330234727.25bcbda8@vulcan.local> And thus spake MRAB Tue, 30 Mar 2010 22:43:04 +0100: > I think you mean that it's very _un-Pythonic_ (perhaps because it's very > very Pythonesque)! :-) Yes. Of course. What was I thinking. ;-) Regards, Robert From mail at hellmutweber.de Tue Mar 30 17:49:24 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Tue, 30 Mar 2010 23:49:24 +0200 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BB271E4.4000505@hellmutweber.de> Hi Peter and Jean-Michel, thanks for all your hints and pieces of code. It took me a while to play around with what I got from you (and some study of Vinay's module documentation. Now I have come up with a more complete solution I'm quite satisfied with. And I would be very glad to receive your comments on my code indicating what I could do better, given that I'm still at the very beginning with python. Cheers + TIA Hellmut Here is my module and a corresponding test program: leo at sylvester hw_logg $ cat loc_logg.py #!/bin/env python # -*- coding: utf-8 -*- """Hw's local logging module To be done: Factorize 'trace' decorator to own module (to permit dependency on debug level) ??? """ import sys # Basic system functions import logging # Logging base import logging.handlers import inspect # monkey patch caller filename # --- color change strings for terminal output --- # pc_yell = '\033[01;93m' pc_purp = '\033[01;33m' pc_gren = '\033[01;92m' pc_blue = '\033[01;94m' # pc_bold = '\033[01;1m' pc_norm = '\033[0m' # pc_reed = '\033[01;91m' pc_cyan = '\033[01;96m' level_color = { 'fatal': pc_yell, 'error': pc_yell, 'warning': pc_purp, 'info': pc_gren, 'debug': pc_blue, 'bold': pc_bold, 'normal': pc_norm } # --- define string building help function --- # def argskw_2_string(*args, **kwargs): """Generate String from *args and **kwargs Return string with *args list (comma separated) in first line **kwargs key=val list (comma separated) in second line """ _str_lines = [] if args: _args_strings = '' for a in args: _args_strings += str(a) + ', ' _str_lines.append(_args_strings) if kwargs: _kwargs_strings = '' for k in kwargs: _kwargs_strings += str(k)+' = '+str(kwargs[k]) + ', ' _str_lines.append(_kwargs_strings) return ''.join(_str_lines) # --- Class for all logging functionality --- # class locLogg(): _logger = None def __init__(self, newlogg=None): if not locLogg._logger: locLogg._logger = newlogg def init_logging(self, loclogg_output='line', # stream or/and file loclogg_fname='loggfile.txt', loclogg_dblevel='DEBUG' ): """Initiate logging with locLogg._logger Defines the logging handler to be used and initiates it. Possible values for loclogg_output: line ==> output to console file ==> log_file must be given both ==> log_file must be given null ==> no logging (NullHandler) """ locLogg._logger.handlers=[] if loclogg_output in ('null'): class NullHandler(logging.Handler): def emit(self, record): pass locLogg._logger.addHandler(NullHandler()) if loclogg_output in ('line', 'both'): locLogg._logger.addHandler(logging.StreamHandler()) if loclogg_output in ('file', 'both'): locLogg._logger.addHandler( logging.handlers.RotatingFileHandler(loclogg_fname, maxBytes=200000, backupCount=5) ) for _loc_logger in locLogg._logger.handlers: _loc_logger.setFormatter(logging.Formatter( '%(asctime)s ' + \ '%(custom_filename)s <%(custom_lineno)d>:' + \ '%(levelname)s %(message)s')) # Can this be done better ? _loc_levels = {'NOTSET': 0, 'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'ERROR': 40, 'CRITICAL': 50} locLogg._logger.setLevel(_loc_levels[loclogg_dblevel]) def info_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.info(str(level_color['info'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno': previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def debug_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.debug(str(level_color['debug'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def warn_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.debug(str(level_color['warning'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def error_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.error(str(level_color['error'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def fatal_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.fatal(str(level_color['fatal'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) # --- Permit definition of a tracing decorator --- from decorator import decorator @decorator def trace(f, *args, **kw): print "@trace: calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) # cf. doc of Michele Simoniato's decorator module if __name__ == '__main__': _logger = logging.getLogger('jmp_logg__main__') foo = locLogg(_logger) foo.init_logging() foo.info_log('a foo info') foo.info_log('another bar info', 1,2,3, a=11, b=22, c=44) foo.debug_log('a debug bar info', 'a', '1aA', qwe=2, asd=99) foo.warn_log('a test info', 'ggg', '2U2', yxcv=2, asdf=99) try: b = 123 c = 0 a = b / c except: foo.fatal_log('Division by zero', b=123, c=0) leo at sylvester hw_logg $ cat test_loclogg.py #!/bin/env python # -*- coding: utf-8 -*- import logging _logger = logging.getLogger() import sys pyDevelDir = '/home/leo/leo/brbeit/py-devel/Modules' sys.path.append(pyDevelDir) from hw_logg.loc_logg import locLogg foo = locLogg(_logger) foo.init_logging( loclogg_output='both', loclogg_dblevel='DEBUG') import loc_module as jm foo.info_log('First info with args in string: %d %d %d' % (1,2,3)) foo.warn_log('First warning') foo.debug_log('First debug message TestTestTest', '----------', 4,5,6, 12*25, d=34, e='qwe') foo.debug_log('Before calling jm.doIt()') jm.doIt(True) foo.info_log('Second info with kwargs separate:', a=11,b=22,c=33) x = jm.MyClass(1, 2, 'abc') x.mymethod() x.mymethod(123, 234, a=1, b=2, c=3) try: jm.doIt(0) except Exception, e: foo.error_log(str(e), 1,5,8) foo.fatal_log('Fatal message') leo at sylvester hw_logg $ cat loc_module.py # -*- coding: utf-8 -*- import logging _logger = logging.getLogger('jmp_logger') import sys pyDevelDir = '/home/leo/leo/brbeit/py-devel/Modules' sys.path.append(pyDevelDir) from hw_logg.loc_logg import locLogg, trace foo = locLogg(_logger) foo.info_log("Start importing "+__name__) def doIt(yn=None): foo.debug_log("doin' stuff, yn =", str(yn)) # logLevel at calling point ! print '=====> Output from doIt:', yn #do stuff...but suppose an error occurs? if yn: foo.info_log('yn: good value') else: raise TypeError, "bogus type error for testing" class MyClass(object): @trace def __init__(self, *args, **kwargs): print 'MyClass.__init__' @trace def mymethod(self, *args, **kwargs): print 'MyClass.mymethod' foo.info_log("End importing "+__name__) -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From darcy at druid.net Tue Mar 30 17:50:56 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 30 Mar 2010 17:50:56 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: References: Message-ID: <20100330175056.ca69563c.darcy@druid.net> On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) ASh wrote: > Hi, please help me understand why am I getting error with this query > > > new_start_date = "NOW() - '29 days'::INTERVAL" > self.dyndb.orderdb.query('''update xxxx set creation_date > = %s > where id_order = %s''', (new_start_date, "123")) Put single quotes around the first %s in the query. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From robert.kern at gmail.com Tue Mar 30 17:58:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 16:58:34 -0500 Subject: A question about making a sort-of-counter. In-Reply-To: <4BB26DCE.7070307@rice.edu> References: <4BB26DCE.7070307@rice.edu> Message-ID: On 2010-03-30 16:31 PM, Justin Park wrote: > Suppose I have a list. > a = list() > And suppose allowed digits as the element are 1,2,3,4,5. > > What can I do in order to iterate over all possible values for each element? > For instance, the sequence of the list I want to have would be > [1,1,1,1,1] > [1,1,1,1,2] > [1,1,1,1,3] > > .... > > [5,5,5,5,4] > [5,5,5,5,5] > > How can I make it happen? def counter(n=5, length=5): for i in xrange(n ** length): x = [] for j in range(length): i, r = divmod(i, n) x.append(r) yield [k+1 for k in x[::-1]] -- 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 From anon at blank.com Tue Mar 30 18:00:13 2010 From: anon at blank.com (anon) Date: Tue, 30 Mar 2010 23:00:13 +0100 Subject: A question about making a sort-of-counter. In-Reply-To: References: Message-ID: Justin Park wrote: > Suppose I have a list. > a = list() > And suppose allowed digits as the element are 1,2,3,4,5. > > What can I do in order to iterate over all possible values for each element? > For instance, the sequence of the list I want to have would be > [1,1,1,1,1] > [1,1,1,1,2] > [1,1,1,1,3] > > .... > > [5,5,5,5,4] > [5,5,5,5,5] > > How can I make it happen? > > Thanks, > Justin. http://docs.python.org/library/itertools.html#itertools.product from itertools import product for item in product([1, 2], repeat=2): print item From invalid at invalid.invalid Tue Mar 30 18:01:14 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Mar 2010 22:01:14 +0000 (UTC) Subject: Can't get odtwriter to work Message-ID: I just installed odtwriter 1.3d on a Gentoo system running Python 2.6.4. I used the normal "python setup.py build" then "python setup.py install" method. But, odtwriter doesn't seem to work: rst2odt.py --help Traceback (most recent call last): File "/usr/bin/rst2odt.py", line 5, in pkg_resources.run_script('odtwriter==1.3d', 'rst2odt.py') File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 461, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1194, in run_script execfile(script_filename, namespace, namespace) File "/usr/lib/python2.6/site-packages/odtwriter-1.3d-py2.6.egg/EGG-INFO/scripts/rst2odt.py", line 21, in from docutils.writers.odtwriter import Writer, Reader ImportError: No module named odtwriter I verified that I have docutils installed: Python 2.6.4 (r264:75706, Mar 1 2010, 10:33:43) [GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import docutils >>> docutils What am I doing wrong? -- Grant Edwards grant.b.edwards Yow! LOOK!! Sullen at American teens wearing gmail.com MADRAS shorts and "Flock of Seagulls" HAIRCUTS! From crebert at ucsd.edu Tue Mar 30 18:08:17 2010 From: crebert at ucsd.edu (Chris Rebert) Date: Tue, 30 Mar 2010 15:08:17 -0700 Subject: A question about making a sort-of-counter. In-Reply-To: <4BB26DCE.7070307@rice.edu> References: <4BB26DCE.7070307@rice.edu> Message-ID: <50697b2c1003301508w7dca3ab0pb9468a7a90afdd45@mail.gmail.com> On Tue, Mar 30, 2010 at 2:31 PM, Justin Park wrote: > Suppose I have a list. > a = list() > And suppose allowed digits as the element are 1,2,3,4,5. > > What can I do in order to iterate over all possible values for each element? > For instance, the sequence of the list I want to have would be > [1,1,1,1,1] > [1,1,1,1,2] > [1,1,1,1,3] > > .... > > [5,5,5,5,4] > [5,5,5,5,5] > > How can I make it happen? allowed = range(1,6) length = 5 for counter_tuple in product(allowed, repeat=length): counter_list = list(counter_tuple) # if you really need a list #do whatever with the counter value See the docs for itertools.product(); an example virtually identical to your situation is given: http://docs.python.org/library/itertools.html#itertools.product Cheers, Chris -- http://blog.rebertia.com From hp6 at rice.edu Tue Mar 30 18:12:28 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 17:12:28 -0500 Subject: A question about making a sort-of-counter. In-Reply-To: <50697b2c1003301508w7dca3ab0pb9468a7a90afdd45@mail.gmail.com> References: <4BB26DCE.7070307@rice.edu> <50697b2c1003301508w7dca3ab0pb9468a7a90afdd45@mail.gmail.com> Message-ID: <4BB2774C.7040906@rice.edu> Thanks! It works! Justin. Chris Rebert wrote: > On Tue, Mar 30, 2010 at 2:31 PM, Justin Park wrote: > >> Suppose I have a list. >> a = list() >> And suppose allowed digits as the element are 1,2,3,4,5. >> >> What can I do in order to iterate over all possible values for each element? >> For instance, the sequence of the list I want to have would be >> [1,1,1,1,1] >> [1,1,1,1,2] >> [1,1,1,1,3] >> >> .... >> >> [5,5,5,5,4] >> [5,5,5,5,5] >> >> How can I make it happen? >> > > allowed = range(1,6) > length = 5 > for counter_tuple in product(allowed, repeat=length): > counter_list = list(counter_tuple) # if you really need a list > #do whatever with the counter value > > See the docs for itertools.product(); an example virtually identical > to your situation is given: > http://docs.python.org/library/itertools.html#itertools.product > > Cheers, > Chris > -- > http://blog.rebertia.com > > From apt.shansen at gmail.invalid Tue Mar 30 18:17:28 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Tue, 30 Mar 2010 15:17:28 -0700 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <2010033015172862741-aptshansen@gmailinvalid> On 2010-03-30 13:16:00 -0700, Robert Fendt said: > > I find such a convoluted construct especially ugly in a language > which I previously regarded as having a rather striking beauty > of syntactical simplicity. The construct is superfluous, > illogical, unelegant, and thus very un-pythonesque, IMHO. But of > course that's just my $0.02. In Python before list-comprehensions, I might have agreed with you. Initially, I was quite resistant to list comprehensions as well. They seemed ugly, and backwards, and why not just write a for loop? Then I got used to them, and I find they are very elegant when used properly. Sometimes you can do something ugly with them, but its actually quite possible to write positively hideous Python even without any of these new fancy shmancy features. But, in the post-comprehension world, where one can do: my_odds = [x for x in range(100) if x % 2 == 1] Things have changed. I've now grown used to reading expressions like that which seem a bit backwards, with the value being returned by an expression is the left-most element. Its not an exact correlation because they're answering different problems. But having gotten used to list comprehensions, and actually quite appreciating their elegance now, I find this reads very well: is_odd = "odd" if x % 2 == 1 else "even" In fact, it reads better then any of the other conditional expression syntaxes people proposed back in the day, and a LOT better then what was done before: is_odd = x % 2 == 1 and "odd" or "even" Even if the above falls a bit more in line with what other languages usually do order-wise, this isn't other languages. Now, none of this addresses your original argument of why not just use a regular if statement. I dunno, I often used "and/or" for simple expressions or defaults and found it very convienent and made code more readable then the line and whitespace inducing true if-statement. And so I'm glad to have something even more readable and without the bug-prone and/or error. Why not just use a for loop anytime you use a list comprehension? :) Same question really applies. -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From invalid at invalid.invalid Tue Mar 30 18:20:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 30 Mar 2010 22:20:29 +0000 (UTC) Subject: Can't get odtwriter to work References: Message-ID: On 2010-03-30, Grant Edwards wrote: > I just installed odtwriter 1.3d on a Gentoo system running Python > 2.6.4. I used the normal "python setup.py build" then "python > setup.py install" method. But, odtwriter doesn't seem to work: > > rst2odt.py --help > > Traceback (most recent call last): > File "/usr/bin/rst2odt.py", line 5, in > pkg_resources.run_script('odtwriter==1.3d', 'rst2odt.py') > File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 461, in run_script > self.require(requires)[0].run_script(script_name, ns) > File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1194, in run_script > execfile(script_filename, namespace, namespace) > File "/usr/lib/python2.6/site-packages/odtwriter-1.3d-py2.6.egg/EGG-INFO/scripts/rst2odt.py", line 21, in > from docutils.writers.odtwriter import Writer, Reader > ImportError: No module named odtwriter > > I verified that I have docutils installed: > > Python 2.6.4 (r264:75706, Mar 1 2010, 10:33:43) > [GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import docutils > >>> docutils > > > What am I doing wrong? I'm not sure what/if I did wrong when installing docutils/odtwriter, but I managed to make it work by manually copying everything from /usr/lib/python2.6/site-packages/odtwriter-1.3d-py2.6.egg/docutils/writers to /usr/lib/python2.6/site-packages/docutils/writers I think that means that odtwriter's setup.py is old/broken, but I don't know enough to fix it... -- Grant Edwards grant.b.edwards Yow! I'm having a MID-WEEK at CRISIS! gmail.com From no.spam at local.local Tue Mar 30 18:32:41 2010 From: no.spam at local.local (Robert Fendt) Date: Wed, 31 Mar 2010 00:32:41 +0200 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <20100331003241.47fa91f6@vulcan.local> And thus spake "Alf P. Steinbach" Tue, 30 Mar 2010 13:40:22 +0200: > > From a usability standpoint, the braces go with the lines to print out the > stanza rather than the for statement or the code after, so the following is best: > > for(i = 99; i > 0; ++i) > { > printf("%d slabs of spam in my mail!\n", i); > printf("%d slabs of spam,\n", i); > printf("Send one to abuse and Just Hit Delete,\n"); > printf("%d slabs of spam in my mail!\n\n", i + 1); > } > I liked this one even more: One way of writing the same code in Python would be: count = 99 while count > 0: print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' The braces are gone, and with them the holy wars. Whatever brace styles Python programmers may happen to use in languages with braces, all the Python code looks the same, and while the major brace styles illustrated above are a few of many ways the C code could be laid out, there's only one real way to do it. Has the fact changed that Python does not care about (1) how many characaters you use for indentation, (1a) you can use tabs OR spaces, (2) indentation does not have to be consistent across a module, (3) not even across a file, (4) even in nested blocks and (5) you can even switch from spaces to tabs and back in the same file? So much for 'all the Python code looks the same'. In general I do not really see what qualifies the author for an article on Python's usability. On the same site one can also find a lot of things e.g. on intelligent design and creationism, and the 'The Case For Uncreative Web Design' in which the author advocates 'uncreative' (in the sense of non-distracting) web design while at the same time showcasing quite the opposite: suffice it to say I found most essays rather difficult to read from a technical point of view, to say nothing about the content. Regards, Robert From anton.shishkov at gmail.com Tue Mar 30 18:45:03 2010 From: anton.shishkov at gmail.com (ASh) Date: Tue, 30 Mar 2010 15:45:03 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: Message-ID: On Mar 31, 12:26?am, Philip Semanchuk wrote: > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > Hi, please help me understand why am I getting error with this query > > > ? ? ? ? ? ?new_start_date = "NOW() - '29 days'::INTERVAL" > > ? ? ? ? ? ?self.dyndb.orderdb.query('''update xxxx set creation_date > > = %s > > ? ? ? ? ? ?where id_order = %s''', (new_start_date, "123")) > > > ... > > psycopg2.DataError: invalid input syntax for type timestamp with time > > zone: "NOW() - '29 days'::INTERVAL" > > Hi Anton, > It sounds to me like the problem is with your SQL rather than with ? > psycopg2 or Python. Try the query directly in Postgres -- does it work ? > there? If so, then your next step should be to ask on the psycopg2 ? > mailing list that Google can find for you. > > Good luck > Philip sql itself is correct From anton.shishkov at gmail.com Tue Mar 30 18:46:12 2010 From: anton.shishkov at gmail.com (ASh) Date: Tue, 30 Mar 2010 15:46:12 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: Message-ID: On Mar 31, 12:50?am, "D'Arcy J.M. Cain" wrote: > On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) > > ASh wrote: > > Hi, please help me understand why am I getting error with this query > > > ? ? ? ? ? ? new_start_date = "NOW() - '29 days'::INTERVAL" > > ? ? ? ? ? ? self.dyndb.orderdb.query('''update xxxx set creation_date > > = %s > > ? ? ? ? ? ? where id_order = %s''', (new_start_date, "123")) > > Put single quotes around the first %s in the query. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. Tried like you said, got this error: psycopg2.ProgrammingError: syntax error at or near "NOW" LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 da... ^ From hp6 at rice.edu Tue Mar 30 18:50:18 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 17:50:18 -0500 Subject: Sometimes the python shell cannot recognize the presence of an attribute. Message-ID: <4BB2802A.7050500@rice.edu> Sometimes when I am working on an already generated package, the python shell cannot perceive the presence of an attribute that I implemented on top of what was there. Is there a way to have it perceive newly created attributes? Thanks, Justin. From hp6 at rice.edu Tue Mar 30 18:57:37 2010 From: hp6 at rice.edu (Justin Park) Date: Tue, 30 Mar 2010 17:57:37 -0500 Subject: Sometimes the python shell cannot recognize the presence of an attribute. In-Reply-To: <4BB2802A.7050500@rice.edu> References: <4BB2802A.7050500@rice.edu> Message-ID: <4BB281E1.2030101@rice.edu> Sorry, my mistake. The real problem is this. When I started working on the package, somehow all of indentations were made by space-bars instead of using tabs. But when I am implementing my own on top of it, I still use tabs to make indentations. This is causing a problem. I have to either conform to their style and change all my tabs to the space-bars making up those spaces, or change all indentations in the previous implementations by tabs. But both the previous implementations and what I am going to do are also so large that either way is not going to be efficient. What can I do in order to resolve this issue? Thanks, Justin. Justin Park wrote: > Sometimes when I am working on an already generated package, > the python shell cannot perceive the presence of an attribute that I > implemented on top of what was there. > > Is there a way to have it perceive newly created attributes? > > Thanks, > Justin. > > From ldo at geek-central.gen.new_zealand Tue Mar 30 19:18:21 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 31 Mar 2010 12:18:21 +1300 Subject: (a==b) ? 'Yes' : 'No' References: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> Message-ID: In message <7316f3d2-bcc9-4a1a-8598- cdd5d41fd74b at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > (a==b) and 'YES' or 'NO' > > Yes, ugly Why would you say that?s ugly? By the way, you don?t need the parentheses. From clp2 at rebertia.com Tue Mar 30 19:20:32 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 16:20:32 -0700 Subject: "Usability, the Soul of Python" In-Reply-To: <20100331003241.47fa91f6@vulcan.local> References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <20100331003241.47fa91f6@vulcan.local> Message-ID: <50697b2c1003301620j376e4787xa8763cb0d21bd2f1@mail.gmail.com> On Tue, Mar 30, 2010 at 3:32 PM, Robert Fendt wrote: > And thus spake "Alf P. Steinbach" > Tue, 30 Mar 2010 13:40:22 +0200: >> >> ?From a usability standpoint, the braces go with the lines to print out the >> stanza rather than the for statement or the code after, so the following is best: >> >> for(i = 99; i > 0; ++i) >> ? ? ?{ >> ? ? ?printf("%d slabs of spam in my mail!\n", i); >> ? ? ?printf("%d slabs of spam,\n", i); >> ? ? ?printf("Send one to abuse and Just Hit Delete,\n"); >> ? ? ?printf("%d slabs of spam in my mail!\n\n", i + 1); >> ? ? ?} >> > > I liked this one even more: > > > One way of writing the same code in Python would be: > > count = 99 > while count > 0: > ? ?print u'%d slabs of spam in my mail!' % count > ? ?print u'%d slabs of spam,' % count > ? ?print u'Send one to abuse and Just Hit Delete,' > ? ?count += 1 > ? ?print u'%d slabs of spam in my mail!' % count > ? ?print u'' > > The braces are gone, and with them the holy wars. Whatever brace > styles Python programmers may happen to use in languages with > braces, all the Python code looks the same, and while the major > brace styles illustrated above are a few of many ways the C code > could be laid out, there's only one real way to do it. > > > Has the fact changed that Python does not care about (1) how > many characaters you use for indentation, (1a) you can use tabs > OR spaces, (2) indentation does not have to be consistent across > a module, (3) not even across a file, (4) even in nested blocks > and (5) you can even switch from spaces to tabs and back in the > same file? So much for 'all the Python code looks the same'. Since we're harping on block delimitation, I'll plug a post I did on the subject a little while ago: http://blog.rebertia.com/2010/01/24/of-braces-and-semicolons/ Hopefully it's more thorough than the OP's. Cheers, Chris From ldo at geek-central.gen.new_zealand Tue Mar 30 19:23:46 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 31 Mar 2010 12:23:46 +1300 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <20100331003241.47fa91f6@vulcan.local> Message-ID: In message <20100331003241.47fa91f6 at vulcan.local>, Robert Fendt wrote: > The braces are gone, and with them the holy wars. Let me start a new one. I would still put in some kind of explicit indicator of the end of the grouping construct: count = 99 while count > 0: print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' #end while From see at sig.for.address Tue Mar 30 19:25:38 2010 From: see at sig.for.address (Victor Eijkhout) Date: Tue, 30 Mar 2010 18:25:38 -0500 Subject: sort array, apply rearrangement to second Message-ID: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> I have two arrays, made with numpy. The first one has values that I want to use as sorting keys; the second one needs to be sorted by those keys. Obviously I could turn them into a dictionary of pairs and sort by the first member, but I think that's not very efficient, at least in space, and this needs to be done as efficiently as possible. I could use a hand. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From ldo at geek-central.gen.new_zealand Tue Mar 30 19:32:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 31 Mar 2010 12:32:42 +1300 Subject: "Usability, the Soul of Python" References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: In message , Alf P. Steinbach wrote: > This is just unsubstantiated opinion, but worse, it makes a tacit > assumption that there is "best" way to do indentation. However, most > programmers fall into that trap, and I've done it myself. Having used so many different languages over the years, I have settled on a reasonably common set of indentation conventions that work across most of them. The only one that currently annoys me is JavaScript, because its semicolons- are-optional rule means that certain ways I write statements continued across multiple lines are interpreted as prematurely completing the statement. In revenge for that, I refuse to put optional semicolons in my JavaScript code altogether. > I may or may not have been responsible for the similarly impractical > compromise convention of using three spaces per indentation level. At > least, in one big meeting the question about number of spaces was raised > by the speaker, and I replied from the benches, just in jest, "three!". > And that was it (perhaps). I use four. Why four? Because it?s divisible by two. Because I use the half- step (two columns) for lines containing nothing but bracketing symbols: for (i = 99; i > 0; --i) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); printf("%d slabs of spam in my mail!\n\n", i - 1); } /*for*/ for i := 99 downto 1 do begin writeln(i, " slabs of spam in my mail!"); writeln(i, " slabs of spam,"); writeln("Send one to abuse and Just Hit Delete,"); writeln(i - 1, " slabs of spam in my mail!\n\n") end {for} Actually this looks like another opportunity for a loop-with-exit-in-the- middle: for (i = 99;;) { printf("%d slabs of spam in my mail!\n", i); printf("%d slabs of spam,\n", i); printf("Send one to abuse and Just Hit Delete,\n"); --i; if (i == 0) break; printf("%d slabs of spam in my mail!\n\n", i); } /*for*/ From hidura at gmail.com Tue Mar 30 19:33:25 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Tue, 30 Mar 2010 23:33:25 +0000 Subject: Fetch files from mail in python Message-ID: <0016e6470e5c57735f04830d0e5a@google.com> Hello list, i want to know how could i fetch a file from an email, what kind of library i have to use for that, actually i am working in the support of IMAP and POP3. Thanks. Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Mar 30 19:39:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 16:39:08 -0700 Subject: Fetch files from mail in python In-Reply-To: <0016e6470e5c57735f04830d0e5a@google.com> References: <0016e6470e5c57735f04830d0e5a@google.com> Message-ID: <50697b2c1003301639l4fa75583mc4b290b4c83664cf@mail.gmail.com> On Tue, Mar 30, 2010 at 4:33 PM, wrote: > Hello list, i want to know how could i fetch a file from an email, what kind > of library i have to use for that, actually i am working in the support of > IMAP and POP3. Next time, consult the Global Module Index (http://docs.python.org/modindex.html) before posting. IMAP: http://docs.python.org/library/imaplib.html POP: http://docs.python.org/library/poplib.html Cheers, Chris -- http://blog.rebertia.com From steve at holdenweb.com Tue Mar 30 19:43:41 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:43:41 -0400 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: References: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> Message-ID: Lawrence D'Oliveiro wrote: > In message <7316f3d2-bcc9-4a1a-8598- > cdd5d41fd74b at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > >> (a==b) and 'YES' or 'NO' >> >> Yes, ugly > > Why would you say that?s ugly? > > By the way, you don?t need the parentheses. But at the same time, if you don't *absolutely know* you don't need the parentheses then the parentheses are a very good idea, so I applaud the example as Pythonic while agreeing that it's ugly. A conditional expression seems more natural. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 30 19:44:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:44:53 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: <20100330175056.ca69563c.darcy@druid.net> References: <20100330175056.ca69563c.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) > ASh wrote: >> Hi, please help me understand why am I getting error with this query >> >> >> new_start_date = "NOW() - '29 days'::INTERVAL" >> self.dyndb.orderdb.query('''update xxxx set creation_date >> = %s >> where id_order = %s''', (new_start_date, "123")) > > Put single quotes around the first %s in the query. > And in future please tell us exactly what error you are trying to explain by quoting the traceback exactly. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Tue Mar 30 19:45:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 31 Mar 2010 01:45:35 +0200 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: * Victor Eijkhout: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. Just do the pairing, but in a 'list', not a dictionary (a dictionary is unordered and can't be sorted). You need to keep track of which keys belong to which values anyway. And anything in Python is a reference: you're not copying the data by creating the pairs. That is, the space overhead is proportional to the number of items but is independent of the data size of each item. Cheers & hth., - Alf From steve at holdenweb.com Tue Mar 30 19:52:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:52:25 -0400 Subject: Sometimes the python shell cannot recognize the presence of an attribute. In-Reply-To: <4BB281E1.2030101@rice.edu> References: <4BB2802A.7050500@rice.edu> <4BB281E1.2030101@rice.edu> Message-ID: Justin Park wrote: > Sorry, my mistake. > > The real problem is this. > When I started working on the package, somehow all of indentations were > made by space-bars instead of using tabs. > But when I am implementing my own on top of it, I still use tabs to make > indentations. > > This is causing a problem. > I have to either conform to their style and change all my tabs to the > space-bars making up those spaces, > or change all indentations in the previous implementations by tabs. > But both the previous implementations and what I am going to do are also > so large that either way is not going to be efficient. > > What can I do in order to resolve this issue? > You might try Googling for "expandtabs". This isn't a new problem, though I agree it can be very vexing when it's new to you ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Mar 30 19:56:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 19:56:25 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. > Well, my first approach would be to do it as inefficiently as I can ( or at least no more efficiently than I can with a simple-minded approach) and then take it from there. If I believe this is not a premature optimization (a question about which I am currently skeptical) I'd suggest conversion to a list of pairs rather than a dict. Can you use zip() on numpy arrays? That would be the easiest way to create the list of pairs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From darcy at druid.net Tue Mar 30 20:10:34 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 30 Mar 2010 20:10:34 -0400 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: References: Message-ID: <20100330201034.020c3bf6.darcy@druid.net> On Tue, 30 Mar 2010 15:46:12 -0700 (PDT) ASh wrote: > > > ? ? ? ? ? ? new_start_date = "NOW() - '29 days'::INTERVAL" > > > ? ? ? ? ? ? self.dyndb.orderdb.query('''update xxxx set creation_date > > > = %s > > > ? ? ? ? ? ? where id_order = %s''', (new_start_date, "123")) > > > > Put single quotes around the first %s in the query. > > Tried like you said, got this error: > > psycopg2.ProgrammingError: syntax error at or near "NOW" > LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 > da... Right. I misread it. Please show us the exact error that you get with the original code. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From steve at holdenweb.com Tue Mar 30 20:12:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 30 Mar 2010 20:12:54 -0400 Subject: "Usability, the Soul of Python" In-Reply-To: References: Message-ID: Jonathan Hayward wrote: > I've posted "Usability, the Soul of Python: An Introduction to the > Python Programming Language Through the Eyes of Usability", at: > > http://JonathansCorner.com/python/ > > The basic suggestion is that much of what works well in Python has > something to do with the usability it offers programmers. > > Enjoy. > Now try another one called "Brevity, the Soul of Technical Writing: An Introduction to Making Yourself Understood Through the Eyes of Readability". What I managed to read seemed to be making worthwhile points, but I felt a bit like I was wading through a steaming pile of irrelevant verbiage that actually made it more difficult to extract the useful nuggets. Bravo for undertaking this task, but I do feel the treatment needs work from a good copy editor. Of course you have to take into account my allergy to folksy metaphors and meandering discourse. Had I chosen your style I might instead have written the criticism above as: """ I would like to begin my critique of this paper with a feature that many competent technical writers completely fail to appreciate: why brevity is desirable in technical writing. Technical writing is not, of course, the only form of writing that there is. People have been writing ever since the first caveman decided he could leave marks on the wall of a cave to indicate that food could be had in the vicinity. The basic concept of brevity is that you should not, as a writer, use superfluous words because if you do then the reader will always be in doubt about which parts of your discourse are meaningful and which are merely decoration. ... """ And so on. As I say, this may be criticism dictated by my personal taste, but I feel you could condense the presentation considerably to good effect. Sorry if this offends. It's meant to help. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at mrabarnett.plus.com Tue Mar 30 20:13:16 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 31 Mar 2010 01:13:16 +0100 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: <4BB2939C.2040706@mrabarnett.plus.com> Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. > You could sort a list of the indices, using the first array to provide the keys. From hidura at gmail.com Tue Mar 30 20:47:47 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Wed, 31 Mar 2010 00:47:47 +0000 Subject: Fetch files from mail in python In-Reply-To: <50697b2c1003301639l4fa75583mc4b290b4c83664cf@mail.gmail.com> Message-ID: <0016e68ded464e17c304830e18f9@google.com> I did that but i want to know if i have a file inside the mail how could i download that file from my mail. On Mar 30, 2010 7:39pm, Chris Rebert wrote: > On Tue, Mar 30, 2010 at 4:33 PM, hidura at gmail.com> wrote: > > Hello list, i want to know how could i fetch a file from an email, what > kind > > of library i have to use for that, actually i am working in the support > of > > IMAP and POP3. > Next time, consult the Global Module Index > (http://docs.python.org/modindex.html) before posting. > IMAP: http://docs.python.org/library/imaplib.html > POP: http://docs.python.org/library/poplib.html > Cheers, > Chris > -- > http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Mar 30 20:56:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 30 Mar 2010 17:56:27 -0700 Subject: Fetch files from mail in python In-Reply-To: <0016e68ded464e17c304830e18f9@google.com> References: <50697b2c1003301639l4fa75583mc4b290b4c83664cf@mail.gmail.com> <0016e68ded464e17c304830e18f9@google.com> Message-ID: <50697b2c1003301756u3c169616o3dc2a7bebbe70219@mail.gmail.com> > On Mar 30, 2010 7:39pm, Chris Rebert wrote: >> On Tue, Mar 30, 2010 at 4:33 PM, ?hidura at gmail.com> wrote: >> > Hello list, i want to know how could i fetch a file from an email, what >> > kind >> > of library i have to use for that, actually i am working in the support >> > of >> > IMAP and POP3. >> >> IMAP: http://docs.python.org/library/imaplib.html >> POP: http://docs.python.org/library/poplib.html On Tue, Mar 30, 2010 at 5:47 PM, wrote: > I did that but i want to know if i have a file inside the mail how could i > download that file from my mail. I believe you'd use the email.parser module: http://docs.python.org/library/email.parser.html Cheers, Chris From cs at zip.com.au Tue Mar 30 21:04:43 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 31 Mar 2010 12:04:43 +1100 Subject: "Usability, the Soul of Python" In-Reply-To: <7f014ea61003300725yf3dfcbdw2976160ca37f60f3@mail.gmail.com> References: <7f014ea61003300725yf3dfcbdw2976160ca37f60f3@mail.gmail.com> Message-ID: <20100331010443.GA12592@cskk.homeip.net> On 30Mar2010 10:25, Chris Colbert wrote: | not really, the int will eventually overflow and cycle around ;) | | On Tue, Mar 30, 2010 at 8:11 AM, Xavier Ho wrote: | | > Did no one notice that | > for(i = 99; i > 0; ++i) | > Gives you an infinite loop (sort of) because i starts a 99, and increases | > every loop? And here we see the strength of the Usability example; in Python it won't overflow, rather seguing seamlessly into an increasing expensive arbitrary sized int. Though most machines will eventually run out of memory to hold it... -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Surely it was of this place, now Cambridge but formerly known by the name of Babylon, that the prophet spoke when he said, 'the wild beasts of the desert shall dwell there, and their houses shall be full of doleful creatures, and owls shall build there, and satyrs shall dance there.' - Thomas Gray (1716-1771) From john at castleamber.com Tue Mar 30 21:22:42 2010 From: john at castleamber.com (John Bokma) Date: Tue, 30 Mar 2010 19:22:42 -0600 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> Message-ID: <87hbnxz3ml.fsf@castleamber.com> Robert Fendt writes: > And thus spake John Bokma > Tue, 30 Mar 2010 13:19:19 -0600: > >> And >> >> a == b and 'Yes' or 'No' >> >> isn't a Perl-ism? > > I never said that this would be better. It was not my intention to imply you did. But yet I do see books on Python mention the and or usage, and personally I think the ... if ... else is preferable. > point of what the advantage is supposed to be of inverting the > order of the return statement and the conditional check what > should actually _be_ returned. What's wrong with just writing > > if a==b: > return 'Yes' > else: > return 'No' To me the else is adding unneeded noise, I would just write: if a==b: return 'Yes' return 'No' > apart from it being a few more line breaks and an additional > return statement? The inverted form is not more readable per > se (in fact, quite the opposite), and I would even suggest to > minimise its use even in languages like C++ and Java. The Python > syntax is even worse since it not only inverts the order of > return statement and conditional check, but it also puts the > conditional between the two results. I use(d) the if ... else as follows (per Programming in Python 3): list = [] if list is None else list in Perl I would've written: defined $list or $list = []; Which I prefer over: $list = [] unless defined $list; and more over: $list = [] if not defined $list; To me the first Perl form reads as a pre-condition: the list must be defined *or* make it so. And maybe you're right, the Python one could've been written: if list is None: list = [] which looks, now, also more readable to me as well. >> Sheesh, this group would be so much nicer without the constant dragging >> in of Perl to make a point. On top of that, do { } unless blocks are >> not idomatic in Perl. Perl Best Practices even clearly states to *never* >> use unless. > > Sorry, but you have just underlined my point, in fact. If it's > discouraged by experts, then of course the question must be > valid why such a feature even exists (okay, apart from 'it > seemed like a good idea at the time'). I guess the latter. Perl has quite some things that in retrospect could've been done better. On the other hand, Perl developers are very fanatic about backwards compatibility, which makes it hard to remove stuff like unless. On top of that Perl can't be statically analyzed, meaning you can't just write a perl4to5 or perl510to512 converter. > And more importantly (and > more on-topic here), why we have to have an analogon in Python. My point. You can sufficiently argue what's wrong with if..else in Python 3 without dragging Perl into it and staying in Python context. I am both a Perl and (learning) Python programmer, and to be honest I get very tired of the somewhat weekly omg Perl suxxxorsss!!11111 Each language has its own suckage. There are several reasons why while I am learning Python I also keep updating my Perl skills ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From sccolbert at gmail.com Tue Mar 30 21:59:32 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 21:59:32 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: On Tue, Mar 30, 2010 at 7:25 PM, Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. > > I could use a hand. > > Victor. > -- > Victor Eijkhout -- eijkhout at tacc utexas edu > -- > http://mail.python.org/mailman/listinfo/python-list > I'm not quite sure what you are asking, but there is probably an efficient way to do it in pure numpy. You can either post an example of what you want here, or better, take it to the NumPy mailing list and I will help you there. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sccolbert at gmail.com Tue Mar 30 22:11:41 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 30 Mar 2010 22:11:41 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: On Tue, Mar 30, 2010 at 9:59 PM, Chris Colbert wrote: > > > On Tue, Mar 30, 2010 at 7:25 PM, Victor Eijkhout wrote: > >> I have two arrays, made with numpy. The first one has values that I want >> to use as sorting keys; the second one needs to be sorted by those keys. >> Obviously I could turn them into a dictionary of pairs and sort by the >> first member, but I think that's not very efficient, at least in space, >> and this needs to be done as efficiently as possible. >> >> I could use a hand. >> >> Victor. >> -- >> Victor Eijkhout -- eijkhout at tacc utexas edu >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > I'm not quite sure what you are asking, but there is probably an efficient > way to do it in pure numpy. You can either post an example of what you want > here, or better, take it to the NumPy mailing list and I will help you > there. > > This seems to be what you want: http://stackoverflow.com/questions/1903462/how-can-i-zip-sort-parallel-numpy-arrays -------------- next part -------------- An HTML attachment was scrubbed... URL: From russ.paielli at gmail.com Tue Mar 30 22:18:50 2010 From: russ.paielli at gmail.com (Russ P.) Date: Tue, 30 Mar 2010 19:18:50 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> Message-ID: <60a3bde8-c503-4d14-89f0-a68f683afd32@x3g2000yqd.googlegroups.com> On Mar 30, 10:08?am, John Nagle wrote: > Chris Rebert wrote: > > On Tue, Mar 30, 2010 at 8:40 AM, gentlestone wrote: > >> Hi, how can I write the popular C/JAVA syntax in Python? > > >> Java example: > >> ? ?return (a==b) ? 'Yes' : 'No' > > >> My first idea is: > >> ? ?return ('No','Yes')[bool(a==b)] > > >> Is there a more elegant/common python expression for this? > > > Yes, Python has ternary operator-like syntax: > > return ('Yes' if a==b else 'No') > > > Note that this requires a recent version of Python. > > ? ? ?Who let the dogs in? ?That's awful syntax. > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle Baloney. The Python ternary syntax is perfectly fine. The "if" could have been put in front, as in Scala: return if a == b "yes" else "no" but either way is fine and perfectly readable as far as I am concerned. From python.list at tim.thechases.com Tue Mar 30 22:25:13 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Mar 2010 21:25:13 -0500 Subject: (a==b) ? 'Yes' : 'No' In-Reply-To: <87hbnxz3ml.fsf@castleamber.com> References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <20100330221600.42cd3536@vulcan.local> <87hbnxz3ml.fsf@castleamber.com> Message-ID: <4BB2B289.9050301@tim.thechases.com> John Bokma wrote: > And maybe you're right, the Python one could've been written: > > if list is None: > list = [] > > which looks, now, also more readable to me as well. Though there's a slight difference[1], I'd usually use lst = lst or [] for your particular initialization use case. -tkc [1] Difference being >>> lst = [] >>> other = lst >>> if lst is None: # your code ... lst = [] ... >>> other.append(42) >>> lst, other ([42], [42]) >>> lst = [] >>> other = lst >>> lst = lst or [] # my proposal >>> other.append(42) >>> lst, other ([], [42]) From robert.kern at gmail.com Tue Mar 30 23:00:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Mar 2010 22:00:38 -0500 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: On 2010-03-30 18:25 , Victor Eijkhout wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. second[first.argsort()] Ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists -- 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 From keeloh at rocketmail.com Tue Mar 30 23:39:53 2010 From: keeloh at rocketmail.com (POOJA) Date: Tue, 30 Mar 2010 20:39:53 -0700 (PDT) Subject: Consolidate Credit Card Debt Message-ID: <5270502a-1fc4-41cf-8427-30c5dee865fd@k5g2000prg.googlegroups.com> Consolidate Credit Card Debt ------------------------------ http://sites.google.com/site/creditcarddebtconsolidation33 From gagsl-py2 at yahoo.com.ar Wed Mar 31 02:22:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 31 Mar 2010 03:22:54 -0300 Subject: xpat error in xmlrp client. How to inspect data. References: <4bab1f4a$0$25677$426a74cc@news.free.fr> <4bb266b5$0$21786$426a74cc@news.free.fr> Message-ID: En Tue, 30 Mar 2010 18:01:40 -0300, News123 escribi?: > Gabriel Genellina wrote: >> En Thu, 25 Mar 2010 05:31:05 -0300, News123 escribi?: >> >>> I'm havign a small xmlrpc client, which works normally fine. >>> (xmlrpc via https) >>> >>> Sometimes however I receive an Exception about an expat error. >>> >>> >>> The output, that I receive is: >>> File "C:\mycode\myrpcclient.py", line 63, in upload_chunk >>> rslt = myrpcclient.call() >>> File "C:\Python26\lib\xmlrpclib.py", line 1199, in __call__ >>> return self.__send(self.__name, args) >>> File "C:\Python26\lib\xmlrpclib.py", line 1489, in __request >>> verbose=self.__verbose >>> File "C:\Python26\lib\xmlrpclib.py", line 1253, in request >>> return self._parse_response(h.getfile(), sock) >>> File "C:\Python26\lib\xmlrpclib.py", line 1387, in _parse_response >>> p.feed(response) >>> File "C:\Python26\lib\xmlrpclib.py", line 601, in feed >>> self._parser.Parse(data, 0) >>> ExpatError: syntax error: line 1, column 0 >>> >> >> a) Use the standard cgitb module (despite its name, it is useful outside >> CGI scripts) >> >> b) Use the tb module available from http://pypi.python.org/pypi/tb >> > I'm currently using the default module traceback and code, which looks > roughly like: > > try: > xmlrpccall() > except Exception as e: > ex_type,ex_value,e_b = sys.exc_info() > tbstring = traceback.format_exc() > logging.error('%s:%s:%s' % (ex_type,ex_value,tbstring) > > > do cgitb or tb really provide much more info? Well, for each frame along the stack, cgitb shows the value of all function arguments, the value of each name referenced, and a few more lines of code around the current one. It's rather verbose, but doesn't include all local variables. The tb module shows -also for each frame along the stack- the value of all its local names (but doesn't include any global one). Just try both of them and see which one you like most. >> d) In your exception handler, walk the traceback object until you reach >> the feed() call, and inspect the corresponding tb_frame.f_locals >> dictionary. > > How can I walk a traceback? For the current problem the the monkeypatch > should be good enough, but for other cases it might be good to know. Each traceback object is linked to the next one via its tb_next attribute. But inspect.trace() builds a list of traceback records that may be easier to handle; see the inspect module documentation. You can identify the desired frame with its filename and function name, and then access its local variables with f_locals. I did something like that to gather context information for errors happening in a third party library that were hard to diagnose otherwise. -- Gabriel Genellina From frank at chagford.com Wed Mar 31 02:49:04 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 31 Mar 2010 08:49:04 +0200 Subject: Sublassing tuple works, subclassing list does not Message-ID: Hi all I needed something similar to, but not quite the same as, collections.namedtuple. The differences are that namedtuple requires the 'names' to be provided at creation time, and then lends itself to creating multiple instances of itself. I wanted a more generic class where I could supply the 'names' and 'values' at instantiation time. I came up with a simple solution that seems to work - >>> class MyTuple(tuple): ... def __new__(cls, names, values): ... for name, value in zip(names, values): ... setattr(cls, name, value) ... return tuple.__new__(cls, values) ... >>> names = ['A', 'B', 'C'] >>> values = ['a', 'b', 'c'] >>> >>> tup = MyTuple(names, values) >>> >>> print tup ('a', 'b', 'c') >>> >>> print tup[0] a >>> >>> print tup.B b >>> Then I had a need to add elements after the tuple had been created. As tuples are immutable, I thought it would be easy to change it to a list. However, it does not work - >>> class MyList(list): ... def __new__(cls, names, values): ... for name, value in zip(names, values): ... setattr(cls, name, value) ... return list.__new__(cls, values) ... >>> names = ['A', 'B', 'C'] >>> values = ['a', 'b', 'c'] >>> >>> lst = MyList(names, values) Traceback (most recent call last): File "", line 1, in TypeError: list() takes at most 1 argument (2 given) >>> I can find a workaround, but I would be interested to know the reason why it does not work. Version is 2.6.2. Thanks Frank Millman From affdfsdfdsfsd at b.com Wed Mar 31 03:47:32 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 31 Mar 2010 07:47:32 GMT Subject: Python + OpenOffice Calc Message-ID: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Hi all! i'm giving away to a friend of mine that have a garage (he repair car) my old computer. He will use it essentialy to create estimates of the work via an ods file (i've made a simple ods file to be filled with the cost of materials and a description of the work). He's totally new with computer and have difficult to fill the ods file, so i'ld like to create a simple python program that help him to introduce the data in to the ods file via a simple gui. So what i'm looking for is a way in python to insert data in a particular cell of the ods file and possibly to save it and print it when it's full filled with data. the guy is similar to this: 3 fields: quantity - description of the piece bought - price a way to add a new "line" if needed (for a new piece entry) similar to the "add rule" in evolution 1 text field for the description of the work + 1 field for the price of the work and off course a way to insert this data in to the ods file via python Any hints/tutorial/info? thanks Nico From __peter__ at web.de Wed Mar 31 03:52:09 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Mar 2010 09:52:09 +0200 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Hellmut Weber wrote: > Hi Peter and Jean-Michel, > thanks for all your hints and pieces of code. > > It took me a while to play around with what I got from you (and some > study of Vinay's module documentation. > > Now I have come up with a more complete solution I'm quite satisfied > with. And I would be very glad to receive your comments on my code > indicating what I could do better, given that I'm still at the very > beginning with python. > Here is my module and a corresponding test program: > # --- color change strings for terminal output --- > # > pc_yell = '\033[01;93m' > pc_purp = '\033[01;33m' > pc_gren = '\033[01;92m' Hw lng wld psts + prgrms b wr it nt 4 z art of clvr + ez 2 mmrz abbreviations ;) > # --- Class for all logging functionality --- > # > class locLogg(): > _logger = None > > def debug_log(self, msg, *args, **kwargs): > def warn_log(self, msg, *args, **kwargs): > def error_log(self, msg, *args, **kwargs): It should be easy to factor out most the code in your xxx_log() methods into a common helper. > def fatal_log(self, msg, *args, **kwargs): > previousFrame = inspect.currentframe().f_back > locLogg._logger.fatal(str(level_color['fatal'])+msg+pc_norm + \ > ' ' + argskw_2_string(*args, **kwargs), > extra={'custom_lineno':previousFrame.f_lineno, > 'custom_filename': previousFrame.f_code.co_filename }) I think the formatting belongs into another layer. That's the purpose of the logging.Formatter class. You could enhance it along those lines: class Formatter(logging.Formatter): markers = { logging.INFO: ("", ""), logging.WARN: ("", ""), } def format(self, record): message = logging.Formatter.format(self, record) try: prefix, suffix = self.markers[record.levelno] except KeyError: pass else: message = prefix + message + suffix return message My general impression is that you are fighting the logging library's structure rather than trying to use it as effectively as possible. > foo.info_log('another bar info', 1,2,3, a=11, b=22, c=44) You could achieve something similar with a standard logger by passing your extra information through the extra parameter, e. g: def extra(*args, **kw): return dict(argskw=(args, kw)) foo.info("another...", extra=extra(1, 2, 3, a=11, b=22)) Peter From kse.listed.co1 at gmail.com Wed Mar 31 03:56:41 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Wed, 31 Mar 2010 00:56:41 -0700 (PDT) Subject: "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ Message-ID: <1c64f0d6-e34a-4997-b919-ba9b49b5e466@y11g2000prf.googlegroups.com> "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ "Jobs in Kuwait" "Kuwait jobs" "accounts jobs in kuwait" "MEDICAL JOBS IN KUWAIT" "FINANCE JOBS IN KUWAIT" "ENGINEERING JOBS IN KUWAIT" "ADVERTISED JOBS ION KUWAIT" ON http://jobsinkuwait-net.blogspot.com/ VV From __peter__ at web.de Wed Mar 31 03:57:51 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Mar 2010 09:57:51 +0200 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <5ef544bb-95a0-4329-80ef-f679d62b8ead@z11g2000yqz.googlegroups.com> Message-ID: Pierre Quentel wrote: > I'm surprised nobody proposed a solution with itertools ;-) next(itertools.takewhile(lambda _: a == b, ["yes"]), "no") You spoke to soon :) Peter From clp2 at rebertia.com Wed Mar 31 03:58:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Mar 2010 00:58:46 -0700 Subject: Python + OpenOffice Calc In-Reply-To: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Message-ID: On Wed, Mar 31, 2010 at 12:47 AM, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price > > a way to add a new "line" if needed (for a new piece entry) similar to the > "add rule" in evolution > > 1 text field for the description of the work + 1 field for the price of > the work > > and off course a way to insert this data in to the ods file via python > > Any hints/tutorial/info? PyUNO: http://wiki.services.openoffice.org/wiki/PyUNO_bridge Cheers, Chris -- http://blog.rebertia.com From v.harishankar at gmail.com Wed Mar 31 04:16:58 2010 From: v.harishankar at gmail.com (Harishankar) Date: Wed, 31 Mar 2010 08:16:58 +0000 (UTC) Subject: No editbox () functionality in python-dialog module? Message-ID: Strange issue, I find that the dialog utility has an editbox function but the python-dialog module doesn't provide this and there's no mention of the reason for the omission of this important functionality. Is there no easy and simple way to create a multi-line input dialog in ANY of the text mode console libraries? :-( -- Harishankar (http://harishankar.org http://literaryforums.org) From lbolla at gmail.com Wed Mar 31 04:18:39 2010 From: lbolla at gmail.com (lbolla) Date: Wed, 31 Mar 2010 01:18:39 -0700 (PDT) Subject: Sublassing tuple works, subclassing list does not References: Message-ID: On Mar 31, 7:49?am, "Frank Millman" wrote: > Hi all > > I needed something similar to, but not quite the same as, > collections.namedtuple. > > The differences are that namedtuple requires the 'names' to be provided at > creation time, and then lends itself to creating multiple instances of > itself. I wanted a more generic class where I could supply the 'names' and > 'values' at instantiation time. > > I came up with a simple solution that seems to work - > > >>> class MyTuple(tuple): > > ... ? def __new__(cls, names, values): > ... ? ? for name, value in zip(names, values): > ... ? ? ? setattr(cls, name, value) > ... ? ? return tuple.__new__(cls, values) > ... > > >>> names = ['A', 'B', 'C'] > >>> values = ['a', 'b', 'c'] > > >>> tup = MyTuple(names, values) > > >>> print tup > ('a', 'b', 'c') > > >>> print tup[0] > a > > >>> print tup.B > b > > Then I had a need to add elements after the tuple had been created. As > tuples are immutable, I thought it would be easy to change it to a list. > However, it does not work - > > >>> class MyList(list): > > ... ? def __new__(cls, names, values): > ... ? ? for name, value in zip(names, values): > ... ? ? ? setattr(cls, name, value) > ... ? ? return list.__new__(cls, values) > ...>>> names = ['A', 'B', 'C'] > >>> values = ['a', 'b', 'c'] > > >>> lst = MyList(names, values) > > Traceback (most recent call last): > ? File "", line 1, in > TypeError: list() takes at most 1 argument (2 given) > > > > I can find a workaround, but I would be interested to know the reason why it > does not work. > > Version is 2.6.2. > > Thanks > > Frank Millman When subclassing immutable types, you need to override __new__; otherwise you need to override __init__. Here is an in-depth explanation: http://www.python.org/download/releases/2.2/descrintro/#metaclasses Here is some code: class MyTuple(tuple): def __new__(cls, names, values): for name, value in zip(names, values): setattr(cls, name, value) return tuple.__new__(cls, values) class MyList(list): def __init__(self, names, values): list.__init__(self, values) for name, value in zip(names, values): setattr(self, name, value) names = ['A', 'B', 'C'] values = ['a', 'b', 'c'] tup = MyTuple(names, values) print tup print tup[0] print tup.B lst = MyList(names, values) print lst print lst[0] print lst.B L. From frank at chagford.com Wed Mar 31 04:29:17 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 31 Mar 2010 10:29:17 +0200 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: "lbolla" wrote in message news:f8011c0b-0b1b-4a4f-94ff-304c16ef9a5b at q16g2000yqq.googlegroups.com... On Mar 31, 7:49 am, "Frank Millman" wrote: >> Hi all >> > When subclassing immutable types, you need to override __new__; > otherwise you need to override __init__. Perfect. Thanks very much. Frank From michael.ricordeau at gmail.com Wed Mar 31 04:29:43 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 31 Mar 2010 10:29:43 +0200 Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: In-Reply-To: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> References: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> Message-ID: <20100331102943.7f542d17@moriz.interne> Hi You cannot add 'NOW() - '29 days'::INTERVAL' as a query because cursor.execute() will try to mogrify it. You can do : import datetime idays = psycopg2.extensions.adapt(datetime.timedelta(days=29)) self.dyndb.orderdb.query('update xxxx set creation_date=(NOW() - %s) where id_order=%s', idays, "123")) Or: import datetime interval = datetime.datetime.now() - datetime.timedelta(days=29) self.dyndb.orderdb.query('update xxxx set creation_date=%s where id_order=%s', (interval, "123")) # But in this case current date/time is not evaluated from postgresql server but only from python env ... this may cause some bugs You may also try to add an interval type with psycopg2.extensions.INTERVAL (I never played with it) Le Tue, 30 Mar 2010 17:26:51 -0400, Philip Semanchuk a ?crit : > > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > Hi, please help me understand why am I getting error with this query > > > > > > new_start_date = "NOW() - '29 days'::INTERVAL" > > self.dyndb.orderdb.query('''update xxxx set creation_date > > = %s > > where id_order = %s''', (new_start_date, "123")) > > > > > > > > ... > > psycopg2.DataError: invalid input syntax for type timestamp with time > > zone: "NOW() - '29 days'::INTERVAL" > > Hi Anton, > It sounds to me like the problem is with your SQL rather than with > psycopg2 or Python. Try the query directly in Postgres -- does it work > there? If so, then your next step should be to ask on the psycopg2 > mailing list that Google can find for you. > > Good luck > Philip > From richard.lamboj at bilcom.at Wed Mar 31 04:36:32 2010 From: richard.lamboj at bilcom.at (Richard Lamboj) Date: Wed, 31 Mar 2010 10:36:32 +0200 Subject: libpst - python bindings Message-ID: <201003311036.32554.richard.lamboj@bilcom.at> Hello, are there any python bindings for libpst? http://www.five-ten-sg.com/libpst/ https://alioth.debian.org/projects/libpst/ Kind Regards Richi From anton.shishkov at gmail.com Wed Mar 31 04:42:41 2010 From: anton.shishkov at gmail.com (Anton Shishkov) Date: Wed, 31 Mar 2010 01:42:41 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: Message-ID: On Mar 31, 3:10?am, "D'Arcy J.M. Cain" wrote: > On Tue, 30 Mar 2010 15:46:12 -0700 (PDT) > > ASh wrote: > > > > ? ? ? ? ? ? new_start_date = "NOW() - '29 days'::INTERVAL" > > > > ? ? ? ? ? ? self.dyndb.orderdb.query('''update xxxx set creation_date > > > > = %s > > > > ? ? ? ? ? ? where id_order = %s''', (new_start_date, "123")) > > > > Put single quotes around the first %s in the query. > > > Tried like you said, got this error: > > > psycopg2.ProgrammingError: syntax error at or near "NOW" > > LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 > > da... > > Right. ?I misread it. ?Please show us the exact error that you get with > the original code. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. Error: cursor.execute(sql, params) File "/opt/local/lib/python2.5/site-packages/psycopg2/extras.py", line 118, in execute return _cursor.execute(self, query, vars, async) psycopg2.ProgrammingError: syntax error at or near "NOW" LINE 1: update orderdb.orders set creation_date = 'E'NOW() - ''29 da... ^ From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 31 04:58:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 31 Mar 2010 10:58:53 +0200 Subject: Sublassing tuple works, subclassing list does not In-Reply-To: References: Message-ID: <4bb30e95$0$17814$426a74cc@news.free.fr> lbolla a ?crit : > > class MyList(list): > def __init__(self, names, values): > list.__init__(self, values) > for name, value in zip(names, values): > setattr(self, name, value) > > names = ['A', 'B', 'C'] > values = ['a', 'b', 'c'] > > lst = MyList(names, values) > print lst > print lst[0] > print lst.B > >>> lst[0] = "foobar" >>> lst.A 'a'>>> lst.B = 42 >>> lst[1] 'b' >>> lst.D="duh" >>> lst[3] Traceback (most recent call last): File "", line 1, in IndexError: list index out of range From rtw at rtw.me.uk Wed Mar 31 05:02:27 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Wed, 31 Mar 2010 04:02:27 -0500 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: Frank Millman wrote in news:mailman.1360.1270018159.23598.python- list at python.org in comp.lang.python: > I came up with a simple solution that seems to work - > >>>> class MyTuple(tuple): > ... def __new__(cls, names, values): > ... for name, value in zip(names, values): > ... setattr(cls, name, value) > ... return tuple.__new__(cls, values) > ... >>>> names = ['A', 'B', 'C'] >>>> values = ['a', 'b', 'c'] >>>> >>>> tup = MyTuple(names, values) >>>> Are you aware you are adding attributes to the class here, IOW: MyTuple.C == 'c' If you want to add attibutes to the instance: class MyTuple(tuple): def __new__(cls, names, values): r = tuple.__new__(cls, values) for name, value in zip(names, values): setattr(r, name, value) return r names = ['A', 'B', 'C'] values = ['a', 'b', 'c'] tup = MyTuple(names, values) assert tup[0] == 'a' assert tup.B == 'b' try: MyTuple.C except AttributeError: pass else: assert False From pavlovevidence at gmail.com Wed Mar 31 05:38:33 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 31 Mar 2010 02:38:33 -0700 (PDT) Subject: Sublassing tuple works, subclassing list does not References: Message-ID: <2baf58a8-b5f1-4db0-9dff-260c62f1641f@h4g2000pre.googlegroups.com> On Mar 31, 2:02?am, Rob Williscroft wrote: > Frank Millman wrote in news:mailman.1360.1270018159.23598.python- > l... at python.org in comp.lang.python: > > > I came up with a simple solution that seems to work - > > >>>> class MyTuple(tuple): > > ... ? def __new__(cls, names, values): > > ... ? ? for name, value in zip(names, values): > > ... ? ? ? setattr(cls, name, value) > > ... ? ? return tuple.__new__(cls, values) > > ... > >>>> names = ['A', 'B', 'C'] > >>>> values = ['a', 'b', 'c'] > > >>>> tup = MyTuple(names, values) > > Are you aware you are adding attributes to the class here, IOW: > > ? ? ? ? MyTuple.C == 'c' > If you want to add attibutes to the instance: > > class MyTuple(tuple): > ? def __new__(cls, names, values): > ? ? r = ?tuple.__new__(cls, values) > ? ? for name, value in zip(names, values): > ? ? ? setattr(r, name, value) > ? ? return r > > names = ['A', 'B', 'C'] > values = ['a', 'b', 'c'] > > tup = MyTuple(names, values) > > assert tup[0] == 'a' > assert tup.B == 'b' > > try: > ? MyTuple.C > except AttributeError: > ? pass > else: > ? assert False Careful, this adds the new attributes as to the object's __dict__, not to the tuple item slots. Which works ok if you don't care if that someone can mutate the attributes, and if they do the attributes no longer match the items. Personally I do mind. tup = MyTuple(names,values) assert tup.A == 'a' assert tup[0] == 'a' tup.A = 'd' # doesn't fail but should assert tup.A == 'd' assert tup[0] == 'd' # fails but, granted you allow mutabilty, shouldn't The best way to do what the OP wanted (originally) is this, no subclassing necessary: def my_named_tuple(names,values): return namedtuple('ad_hoc_named_tuple',names)(*values) As for the OP's second problem, to append named items, I'd first consider whether I'm thinking about the problem correctly, and if so, go with a subclass of list and overriding __getattr__. Probably one of the rare cases I would override __getattr__ other than a proxy class. Carl Banks From mark.dufour at gmail.com Wed Mar 31 05:50:42 2010 From: mark.dufour at gmail.com (Mark Dufour) Date: Wed, 31 Mar 2010 11:50:42 +0200 Subject: ANN: Shed Skin 0.4 Message-ID: Hi all, I have just released Shed Skin 0.4, an experimental (restricted) Python-to-C++ compiler. Please see my blog for more details about the release: http://shed-skin.blogspot.com/ Thanks, Mark Dufour. -- "Overdesigning is a SIN. It's the archetypal example of what I call 'bad taste'" - Linus Torvalds -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Wed Mar 31 06:39:30 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 31 Mar 2010 11:39:30 +0100 Subject: PyDispatcher on sourceforge doesn't play nice with easy_install In-Reply-To: <4BB21F18.2010705@vrplumber.com> References: <4BB1B034.9020905@simplistix.co.uk> <4BB21F18.2010705@vrplumber.com> Message-ID: <4BB32662.9080702@simplistix.co.uk> Mike C. Fletcher wrote: > Chris Withers wrote: >> Hi All, >> >> Using easy_install to get PyDispatcher results in: >> > ... >> Who's the maintainer of PyDispatcher nowadays? Would be handy if they >> removed the sourceforge link from pypi. > ... > > Thanks for the report. I've released a 2.0.2 version on PyPI. That > should now work properly with easy_install. Great! Thanks Mike! Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From iwanttobeabadger at googlemail.com Wed Mar 31 06:49:14 2010 From: iwanttobeabadger at googlemail.com (Nathan Harmston) Date: Wed, 31 Mar 2010 11:49:14 +0100 Subject: Generating text from a regular expression Message-ID: Hi everyone, I have a slightly complicated/medium sized regular expression and I want to generate all possible words that it can match (to compare performance of regex against an acora based matcher). Using the regular expression as a grammar to generate all words in its language. I was wondering if this possible in Python or possible using anything. Google doesnt seem to give any obvious answers. Many thanks in advance, Nathan From anton.shishkov at gmail.com Wed Mar 31 06:50:39 2010 From: anton.shishkov at gmail.com (Anton Shishkov) Date: Wed, 31 Mar 2010 03:50:39 -0700 (PDT) Subject: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone: References: <5171EFC3-09A0-4937-BDAD-C179CF1E1DFE@semanchuk.com> Message-ID: On Mar 31, 11:29?am, Michael Ricordeau wrote: > Hi > > You cannot add 'NOW() - '29 days'::INTERVAL' as a query because cursor.execute() will try to mogrify it. > > You can do : > ? import datetime > ? idays = psycopg2.extensions.adapt(datetime.timedelta(days=29)) > ? self.dyndb.orderdb.query('update xxxx set creation_date=(NOW() - %s) where id_order=%s', idays, "123")) > > Or: > ? import datetime > ? interval = datetime.datetime.now() - datetime.timedelta(days=29) > ? self.dyndb.orderdb.query('update xxxx set creation_date=%s where id_order=%s', (interval, "123")) > ? # But in this case current date/time is not evaluated from postgresql server but only from python env ... this may cause some bugs ? ? > > You may also try to add an interval type with psycopg2.extensions.INTERVAL (I never played with it) > > Le Tue, 30 Mar 2010 17:26:51 -0400, > Philip Semanchuk a ?crit : > > > > > > > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > > Hi, please help me understand why am I getting error with this query > > > > ? ? ? ? ? ?new_start_date = "NOW() - '29 days'::INTERVAL" > > > ? ? ? ? ? ?self.dyndb.orderdb.query('''update xxxx set creation_date > > > = %s > > > ? ? ? ? ? ?where id_order = %s''', (new_start_date, "123")) > > > > ... > > > psycopg2.DataError: invalid input syntax for type timestamp with time > > > zone: "NOW() - '29 days'::INTERVAL" > > > Hi Anton, > > It sounds to me like the problem is with your SQL rather than with ? > > psycopg2 or Python. Try the query directly in Postgres -- does it work ? > > there? If so, then your next step should be to ask on the psycopg2 ? > > mailing list that Google can find for you. > > > Good luck > > Philip thank you for good examples (bow) From hniksic at xemacs.org Wed Mar 31 07:07:55 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 31 Mar 2010 13:07:55 +0200 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: <87iq8czr3o.fsf@busola.homelinux.net> "Frank Millman" writes: >>>> class MyList(list): > ... def __new__(cls, names, values): > ... for name, value in zip(names, values): > ... setattr(cls, name, value) > ... return list.__new__(cls, values) Did you really mean to setattr the class here? If I'm guessing your intentions correctly, it should be: def __new__(cls, names, values): self = list.__new__(cls, values) for name, value in zip(names, values): setattr(self, name, value) return self > Traceback (most recent call last): > File "", line 1, in > TypeError: list() takes at most 1 argument (2 given) >>>> > > I can find a workaround, but I would be interested to know the reason > why it does not work. Because you didn't define __init__, so MyList inherited the one from list, and it has a different signature to what you're calling it with. Simply add an __init__ with the proper signature, and the proper upcall to list.__init__: def __init__(self, names, values): list.__init__(self, values) But if you're doing that, you don't need __new__ at all. Simply override __init__ and place your setattr loop there: >>> class MyList(list): ... def __init__(self, names, values): ... for name, value in zip(names, values): ... setattr(self, name, value) ... list.__init__(self, values) ... >>> MyList(['a'], [1]) [1] >>> _.a 1 From frank at chagford.com Wed Mar 31 07:51:05 2010 From: frank at chagford.com (Frank Millman) Date: Wed, 31 Mar 2010 13:51:05 +0200 Subject: Sublassing tuple works, subclassing list does not References: Message-ID: On Mar 31, 8:49 am, "Frank Millman" wrote: > Hi all Thanks to all for the helpful replies. Rob, you are correct, I had not realised I was adding attributes to the class instead of the instance. Your alternative does work correctly. Thanks. Carl, I understand your concern about modifying attributes. In my particular case, this is not a problem, as the class is under my control, and an instance will not be modified once it is set up, but I agree one must be careful not to mis-use it. My use-case is that I want to create a number of objects, I want to store them in a tuple/list so that I can retrieve them sequentially, and I also want to retrieve them individually by name. Normally I would create a tuple and a dictionary to serve the two purposes, but I thought this might be a convenient way to get both behaviours from the same structure. Regarding adding elements after instantiation, I would subclass 'list', as suggested by others, and then add an 'add' method, like this - def add(self, name, value): setattr(self, name, value) self.append(value) I tested this and it behaves as I want. Having said all of this, I have realised that what I probably want is an ordered dict. I will play with the one in PyPi, hopefully it will render this entire discussion redundant. It was interesting, though, and I have learned a lot. Thanks again Frank From gagsl-py2 at yahoo.com.ar Wed Mar 31 07:58:03 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 31 Mar 2010 08:58:03 -0300 Subject: Generating text from a regular expression References: Message-ID: En Wed, 31 Mar 2010 07:49:14 -0300, Nathan Harmston escribi?: > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match (to compare > performance of regex against an acora based matcher). Using the > regular expression as a grammar to generate all words in its language. > I was wondering if this possible in Python or possible using anything. > Google doesnt seem to give any obvious answers. I've done this some time ago. This recipe http://code.activestate.com/recipes/577041-merge-multiple-potentially-infinite-sorted-inputs-/ provides an infinite merge operation, required for effectively enumerating a regular language (with shorter strings first, else 'a*b' would get stuck repeating "a"s and never yielding any "b"). The example at the end shows the basics of how to use it (by hand) in a very simple case. To enumerate all strings matching '(a|bc)*' one should invoke closure(product(['a'],['b','c'])), which gives: '', 'a', 'aa', 'bc', 'aaa', 'abc', 'bca', 'aaaa', 'aabc', 'abca', 'bcaa', 'bcbc', 'aaaaa', 'aaabc', 'aabca', 'abcaa', 'abcbc', 'bcaaa', 'bcabc', 'bcbca', ... Converting the former expression into the later function calls requires a parser (not shown -- and I won't be able to find it until Friday) -- Gabriel Genellina From python.list at tim.thechases.com Wed Mar 31 08:01:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 31 Mar 2010 07:01:57 -0500 Subject: Generating text from a regular expression In-Reply-To: References: Message-ID: <4BB339B5.3050505@tim.thechases.com> Nathan Harmston wrote: > I have a slightly complicated/medium sized regular expression > and I want to generate all possible words that it can match > (to compare performance of regex against an acora based > matcher). Using the regular expression as a grammar to > generate all words in its language. I was wondering if this > possible in Python or possible using anything. Google doesnt > seem to give any obvious answers. Unless you limit your regexp to bounded regular expressions (you don't use the "*", "+" and unbounded-top-end "{...}" tokens), it has an infinite number of possible words that can match. As a simple example, the regexp "a*" matches "" (the empty string), "a", "aa", "aaa", "aaaa"...and so on up to the limit of a string length. There was a discussion on this a while back: http://mail.python.org/pipermail/python-list/2010-February/1235120.html so you might chat with the person who started that thread. You basically have to write a regexp parser that generates code to generate the expressions, and even simple expressions such as "[a-z]{1,30}" can create an astronomical number of possible inputs. -tkc From piet at vanoostrum.org Wed Mar 31 08:50:51 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 31 Mar 2010 14:50:51 +0200 Subject: os.walk restart References: Message-ID: You have no guarantee that on the next run the directories will be visited in the same order as in the first run (this could depend on the filesystem). So then remembering a last directory won't do it. You could write each completed directory name to a file, and then on the second run check whether a directory is in that list and skip the program run for these. Something like this (symbolically): lastrun = map(string.strip, logfile.readlines()) newlog = ... open logfile in append mode ... for root, dirs, files in os.walk(basedir): if root not in lastrun: run program newlog.write(root) newlog.flush() -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonwaar op http://www.zylja.com From jura.grozni at gmail.com Wed Mar 31 09:01:34 2010 From: jura.grozni at gmail.com (azrael) Date: Wed, 31 Mar 2010 06:01:34 -0700 (PDT) Subject: wrapping data from groups Message-ID: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> Hi Could anyone give me a hint about a problem I have. I want to wrap data from newsgroups like comp.lang.python. Is there anywhere out some module for this or does google has something for this. From jeanmichel at sequans.com Wed Mar 31 09:02:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 31 Mar 2010 15:02:16 +0200 Subject: libpst - python bindings In-Reply-To: <201003311036.32554.richard.lamboj@bilcom.at> References: <201003311036.32554.richard.lamboj@bilcom.at> Message-ID: <4BB347D8.7050202@sequans.com> Richard Lamboj wrote: > Hello, > > are there any python bindings for libpst? > > http://www.five-ten-sg.com/libpst/ > https://alioth.debian.org/projects/libpst/ > > Kind Regards > > Richi > http://www.lmgtfy.com/?q=libpst+python 3rd hit Cheers, JM From steve at holdenweb.com Wed Mar 31 09:28:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 09:28:32 -0400 Subject: wrapping data from groups In-Reply-To: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> References: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> Message-ID: azrael wrote: > Hi > > Could anyone give me a hint about a problem I have. I want to wrap > data from newsgroups like comp.lang.python. Is there anywhere out > some module for this or does google has something for this. nntplib would be the normal starting point. I've used it, and it works reasonably well. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From invalid at invalid.invalid Wed Mar 31 10:13:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 31 Mar 2010 14:13:32 +0000 (UTC) Subject: Generating text from a regular expression References: Message-ID: On 2010-03-31, Nathan Harmston wrote: > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match > > I was wondering if this possible in Python or possible using > anything. Google doesnt seem to give any obvious answers. We did this one a couple weeks ago. It's not possible in the general case (there are an infinite number of matching words for many/most regular expressions). -- Grant Edwards grant.b.edwards Yow! ... the MYSTERIANS are at in here with my CORDUROY gmail.com SOAP DISH!! From ptmcg at austin.rr.com Wed Mar 31 11:23:48 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 31 Mar 2010 08:23:48 -0700 (PDT) Subject: Generating text from a regular expression References: Message-ID: <829a8515-0c35-449e-abb9-2321092f2598@l25g2000yqd.googlegroups.com> On Mar 31, 5:49?am, Nathan Harmston wrote: > Hi everyone, > > I have a slightly complicated/medium sized regular expression and I > want to generate all possible words that it can match (to compare > performance of regex against an acora based matcher). The pyparsing wiki Examples page includes this regex inverter: http://pyparsing.wikispaces.com/file/view/invRegex.py >From the module header: # Supports: # - {n} and {m,n} repetition, but not unbounded + or * repetition # - ? optional elements # - [] character ranges # - () grouping # - | alternation -- Paul From jmontoyaz at gmail.com Wed Mar 31 12:40:30 2010 From: jmontoyaz at gmail.com (Javier Montoya) Date: Wed, 31 Mar 2010 09:40:30 -0700 (PDT) Subject: associative array Message-ID: Dear all, I'm a newbie in python and would be acknowledge if somebody could shed some light on associative arrays. More precisely, I would like to create a multi-dimensional associative array. I have for example a list of students which are identified uniquely by their student IDs. Additionally, for each student I have some information: FirstName, LastName, etc. The array would have then the following form: [StudentID] => [FirstName][LastName][Telephone]...[ ... ] I would like to be able to access a field directly by using a StudentID [StudentID][FirstName] [StudentID][LastName] How could I manipulate such an array (create the array, add elements, access data)? Best wishes From kushal.kumaran+python at gmail.com Wed Mar 31 12:52:14 2010 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Wed, 31 Mar 2010 22:22:14 +0530 Subject: associative array In-Reply-To: References: Message-ID: On Wed, Mar 31, 2010 at 10:10 PM, Javier Montoya wrote: > Dear all, > > I'm a newbie in python and would be acknowledge if somebody could shed > some light on associative arrays. > More precisely, I would like to create a multi-dimensional associative > array. I have for example a list of students which are identified > uniquely by their student IDs. Additionally, for each student I have > some information: FirstName, LastName, etc. > > The array would have then the following form: > [StudentID] => [FirstName][LastName][Telephone]...[ ... ] > > I would like to be able to access a field directly by using a > StudentID > [StudentID][FirstName] > [StudentID][LastName] > > How could I manipulate such an array (create the array, add elements, > access data)? > Did you try the python tutorial? Dictionaries might be what you are looking for. http://docs.python.org/tutorial/datastructures.html#dictionaries -- regards, kushal From jura.grozni at gmail.com Wed Mar 31 12:58:40 2010 From: jura.grozni at gmail.com (azrael) Date: Wed, 31 Mar 2010 09:58:40 -0700 (PDT) Subject: wrapping data from groups References: <2c51a367-73b3-4639-b8bf-fa6b6db90be2@b30g2000yqd.googlegroups.com> Message-ID: I tried to use some servers I know but they have a limited amount of stored threads. not like google that has every thread ever opened. so I tried to wrap google's html but I get a 403 error. any sugesstions? On Mar 31, 3:28?pm, Steve Holden wrote: > azrael wrote: > > Hi > > > Could anyone give me a hint about a problem I have. I want to wrap > > data from ?newsgroups like comp.lang.python. Is there anywhere out > > some module for this or does google has something for this. > > nntplib would be the normal starting point. I've used it, and it works > reasonably well. > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > See PyCon Talks from Atlanta 2010 ?http://pycon.blip.tv/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ From ccurvey at gmail.com Wed Mar 31 13:08:50 2010 From: ccurvey at gmail.com (Chris Curvey) Date: Wed, 31 Mar 2010 10:08:50 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter Message-ID: I must be having a brain cramp. Given a list of objects, how can I sort the list on one attribute in descending order, then sort within each group in ascending order on another attribute. For example: class Foo: def __init__(self, a, b, c): self.a = a self.b = b self.c = c I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort ascending on both attributes, but how could i sort by "a, descending, then b, ascending)?" From tomf.sessile at gmail.com Wed Mar 31 13:21:36 2010 From: tomf.sessile at gmail.com (TomF) Date: Wed, 31 Mar 2010 10:21:36 -0700 Subject: (a==b) ? 'Yes' : 'No' References: <4bb22b39$0$1638$742ec2ed@news.sonic.net> <20100330201609.6ef12ee1@vulcan.local> <87sk7h8vns.fsf@castleamber.com> <5ef544bb-95a0-4329-80ef-f679d62b8ead@z11g2000yqz.googlegroups.com> Message-ID: <2010033110213616807-tomfsessile@gmailcom> On 2010-03-31 00:57:51 -0700, Peter Otten <__peter__ at web.de> said: > Pierre Quentel wrote: > >> I'm surprised nobody proposed a solution with itertools ;-) > > next(itertools.takewhile(lambda _: a == b, ["yes"]), "no") > > You spoke to soon :) I salute you, sir, for upholding the standards of this group. -Tom From safoo.alahmadi at gmail.com Wed Mar 31 13:30:39 2010 From: safoo.alahmadi at gmail.com (safwan alahmadi) Date: Wed, 31 Mar 2010 10:30:39 -0700 (PDT) Subject: Video is very funny..hhhhhhhhhhhh Message-ID: <9ba61e22-bcca-4684-a5d6-1fd587641525@8g2000yqz.googlegroups.com> hhhhhhhhhhhh Video is very funny http://www.youtube.com/watch?v=-cKvPp71QFY From mail at timgolden.me.uk Wed Mar 31 13:35:00 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 31 Mar 2010 18:35:00 +0100 Subject: sorting ascending/descending with operator.attrgetter In-Reply-To: References: Message-ID: <4BB387C4.5010002@timgolden.me.uk> On 31/03/2010 18:08, Chris Curvey wrote: > I must be having a brain cramp. Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > def __init__(self, a, b, c): > self.a = a > self.b = b > self.c = c I think this is the kind of thing you're after... http://ramblings.timgolden.me.uk/2009/10/15/reverse-sorting-on-arbitrary-key-segments/ ... at least the link to the Wiki should help: http://wiki.python.org/moin/HowTo/Sorting TJG From gherron at digipen.edu Wed Mar 31 13:36:22 2010 From: gherron at digipen.edu (Gary Herron) Date: Wed, 31 Mar 2010 10:36:22 -0700 Subject: associative array In-Reply-To: References: Message-ID: <4BB38816.4030305@digipen.edu> Javier Montoya wrote: > Dear all, > > I'm a newbie in python and would be acknowledge if somebody could shed > some light on associative arrays. > More precisely, I would like to create a multi-dimensional associative > array. I have for example a list of students which are identified > uniquely by their student IDs. Additionally, for each student I have > some information: FirstName, LastName, etc. > > The array would have then the following form: > [StudentID] => [FirstName][LastName][Telephone]...[ ... ] > > I would like to be able to access a field directly by using a > StudentID > [StudentID][FirstName] > [StudentID][LastName] > > How could I manipulate such an array (create the array, add elements, > access data)? > > Best wishes > > > Create a class for student with attributes for ID, FirstName, LastName, etc. class Student: def __init__(self, id, FirstName, ...): self.id = id self.FirstName = FirstName ... then whenever you create a student object, use a dictionary to associate the object with its is AA = {} # An empty dictionary s = Student(...) AA[s.id] = s ... and repeat for many students... Then to access a student's object given an id: s = AA[id] print s.id, s.FirstName, s.LastName, ... I'd *not* call this a multi-dimension association, but rather just an association between student objects and their ids. Hope that helps, Gary Herron -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From __peter__ at web.de Wed Mar 31 13:49:08 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 31 Mar 2010 19:49:08 +0200 Subject: sorting ascending/descending with operator.attrgetter References: Message-ID: Chris Curvey wrote: > I must be having a brain cramp. Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > def __init__(self, a, b, c): > self.a = a > self.b = b > self.c = c > > > I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort > ascending on both attributes, but how could i sort by "a, descending, > then b, ascending)?" In the general case you have to sort twice: >>> from collections import namedtuple >>> Foo = namedtuple("Foo", "a b") >>> items = [Foo(x, y) for x in range(3) for y in range(3)] >>> def show(items): ... for item in items: print item ... >>> show(items) Foo(a=0, b=0) Foo(a=0, b=1) Foo(a=0, b=2) Foo(a=1, b=0) Foo(a=1, b=1) Foo(a=1, b=2) Foo(a=2, b=0) Foo(a=2, b=1) Foo(a=2, b=2) >>> from operator import attrgetter >>> items.sort(key=attrgetter("b")) >>> items.sort(key=attrgetter("a"), reverse=True) >>> show(items) Foo(a=2, b=0) Foo(a=2, b=1) Foo(a=2, b=2) Foo(a=1, b=0) Foo(a=1, b=1) Foo(a=1, b=2) Foo(a=0, b=0) Foo(a=0, b=1) Foo(a=0, b=2) This is guaranteed to work because list.sort() is "stable", i. e. it doesn't alter the order of items with equal keys. Peter From nathan.alexander.rice at gmail.com Wed Mar 31 13:58:58 2010 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Wed, 31 Mar 2010 13:58:58 -0400 Subject: Question about list comprehension/standard "for" disparities Message-ID: I was just wondering, why the list/generator and standard "for" have disparities? It would be really nice to be able to do: for x in y if foo: ... rather than: for x in (x for x in y if foo): ... Also, from a style standpoint, I prefer to extract the loop logic into a function if it's more than a few lines long. As a result, most of my loops are of the form: for x in y: bar(x) So I frequently end up using map. As I understand it, there is some discussion of removing map() in favor of comprehensions. Is there any reason why the for syntax could not be expanded to accommodate statements of the form: bar(x) for x in y ? This inconsistency really bothered me when I started playing with python, and it seems kind of at-odds with the "one right way to do things" mentality. -Nathan -------------- next part -------------- An HTML attachment was scrubbed... URL: From wescpy at gmail.com Wed Mar 31 14:01:58 2010 From: wescpy at gmail.com (wesley chun) Date: Wed, 31 Mar 2010 11:01:58 -0700 Subject: ANN: Intro+Intermediate Python course, SF, May 10-12 Message-ID: Need to get up-to-speed with Python as quickly as possible? Come join me, Wesley Chun, author of Prentice-Hall's bestseller "Core Python Programming," for a comprehensive intro course coming up this May in beautiful Northern California! Please pass on this note to whomever you think may be interested. I look forward to meeting you and your colleagues! feel free to pass around the PDF flyer linked down below. (Comprehensive) Introduction to Python Mon-Wed, 2010 May 10-12, 9am-5pm - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (COMPREHENSIVE) INTRO+INTERMEDIATE PYTHON Although this course may appear to those new to Python, it is also perfect for those who have tinkered with it and want to "fill in the gaps" and/or want to get more in-depth formal training. It combines the best of both an introduction to the language as well as a "Python Internals" training course. We will immerse you in the world of Python in only a few days, showing you more than just its syntax (which you don't really need a book to learn, right?). Knowing more about how Python works under the covers, including the relationship between data objects and memory management, will make you a much more effective Python programmer coming out of the gate. 3 hands-on labs each day will help hammer the concepts home. Come find out why Google, Yahoo!, Disney, ILM/LucasFilm, VMware, NASA, Ubuntu, YouTube, and Red Hat all use Python. Users supporting or jumping to Plone, Zope, TurboGears, Pylons, Django, Google App Engine, Jython, IronPython, and Mailman will also benefit! PREVIEW 1: you will find (and can download) a video clip of a class session recorded live to get an idea of my lecture style and the interactive classroom environment at: http://cyberwebconsulting.com PREVIEW 2: Partnering with O'Reilly and Pearson, Safari Books Online has asked me to deliver a 1-hour webcast last Spring called "What is Python?". This was an online seminar based on a session that I've delivered at numerous conferences in the past. It will give you an idea of lecture style as well as an overview of the material covered in the course. info:http://www.safaribooksonline.com/events/WhatIsPython.html download (reg req'd): http://www.safaribooksonline.com/Corporate/DownloadAndResources/webcastInfo.php?page=WhatIsPython - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WHERE: near the San Francisco Airport (SFO/San Bruno), CA, USA WEB: http://cyberwebconsulting.com FLYER: http://starship.python.net/crew/wesc/flyerPP1may10.pdf LOCALS: easy freeway (101/280/380) with lots of parking plus public transit (BART and CalTrain) access via the San Bruno stations, easily accessible from all parts of the Bay Area VISITORS: free shuttle to/from the airport, free high-speed internet, free breakfast and regular evening receptions; fully-equipped suites See website for costs, venue info, and registration. There is a significant discounts available for full-time students, secondary teachers, and others. Hope to see you there! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com From nagle at animats.com Wed Mar 31 14:05:58 2010 From: nagle at animats.com (John Nagle) Date: Wed, 31 Mar 2010 11:05:58 -0700 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> Message-ID: <4bb38a31$0$1595$742ec2ed@news.sonic.net> Alf P. Steinbach wrote: > * Jean-Michel Pichavant: >> John Nagle wrote: >>> Jonathan Hayward wrote: >>>> I've posted "Usability, the Soul of Python: An Introduction to the >>>> Python Programming Language Through the Eyes of Usability", at: >>>> >>>> http://JonathansCorner.com/python/ >>> >>> No, it's just a rather verbose introduction to Python, in dark brown >>> type on a light brown background. One could write a good paper on this >>> topic, but this isn't it. >>> >>> >>> John Nagle >> Why is it bad ? > > Consider > > > > From a usability standpoint, the braces go with the lines to print out > the stanza rather than the for statement or the code after, so the > following is best: The last time I ran a C++ project, I just had everyone run their code through Artistic Style ("http://astyle.sourceforge.net") with "--style=ansi". No more inconsistencies. John Nagle From see at sig.for.address Wed Mar 31 14:58:03 2010 From: see at sig.for.address (Victor Eijkhout) Date: Wed, 31 Mar 2010 13:58:03 -0500 Subject: sort array, apply rearrangement to second References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: <1jg81f7.5ub3191oci9fkN%see@sig.for.address> Robert Kern wrote: > second[first.argsort()] Really cool. Thanks. > Ask numpy questions on the numpy mailing list. I will. I thought that this question would have an answer in a generic python idiom. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From pmaupin at gmail.com Wed Mar 31 15:05:24 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 31 Mar 2010 12:05:24 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter References: Message-ID: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> On Mar 31, 12:08?pm, Chris Curvey wrote: > I must be having a brain cramp. ?Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > ? ? def __init__(self, a, b, c): > ? ? ? ? self.a = a > ? ? ? ? self.b = b > ? ? ? ? self.c = c > > I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort > ascending on both attributes, but how could i sort by "a, descending, > then b, ascending)?" You can provide a cmp function to the string sort method, e.g. cmp = lambda x,y: -cmp(x.a, y.a) or cmp(x.b, y.b) You can also possibly gain some efficiency by using key instead of cmp. For example, if one of the objects is numeric, you can call sort() with something like key = lambda x:(-x.a, x.b) Or if b is numeric but a is a string, you could use lambda x:(x.a, - x.b) and then use list.reverse() afterward. HTH, Pat From gatoygata2 at gmail.com Wed Mar 31 15:11:18 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Wed, 31 Mar 2010 12:11:18 -0700 (PDT) Subject: (a==b) ? 'Yes' : 'No' References: <7316f3d2-bcc9-4a1a-8598-cdd5d41fd74b@k17g2000yqb.googlegroups.com> Message-ID: On Mar 31, 1:18?am, Lawrence D'Oliveiro wrote: > In message <7316f3d2-bcc9-4a1a-8598- > > cdd5d41fd... at k17g2000yqb.googlegroups.com>, Joaquin Abian wrote: > > (a==b) and 'YES' or 'NO' > > > Yes, ugly > > Why would you say that?s ugly? > > By the way, you don?t need the parentheses. Lawrence, maybe it was not the perfect adjective. I meant 'not beautiful' because for me it is not an expression I can easily read. It is not internalized in my brain. I know how to use it because I learnt how to do it time ago(in Learning Python) but always I have to think how it works (like a mental translation). For me the other alternative expresion is more readable: take_it if you_have_it else search_for_it this was already in my brain before I started writing python code. Thus, I prefer this option for my code. On the other hand, in my post, I proposed the and/or style because I found interesting how symmetrical it was with the one the OP was refering: (a==b) ? 'Yes' : 'No' (a==b) and 'Yes' or 'No' I know, I could write it without parenthesis but it seems more naturally organized with it and I read it faster and clearly. I dont know exactly why but it seems also safer to me. Joaquin From robert.kern at gmail.com Wed Mar 31 15:13:52 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 31 Mar 2010 14:13:52 -0500 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg81f7.5ub3191oci9fkN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> <1jg81f7.5ub3191oci9fkN%see@sig.for.address> Message-ID: On 2010-03-31 13:58 PM, Victor Eijkhout wrote: > Robert Kern wrote: > >> second[first.argsort()] > > Really cool. Thanks. > >> Ask numpy questions on the numpy mailing list. > > I will. I thought that this question would have an answer in a generic > python idiom. When dealing with numpy arrays, the generic Python idiom is often much slower. -- 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 From ricaraoz at gmail.com Wed Mar 31 15:21:48 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Wed, 31 Mar 2010 16:21:48 -0300 Subject: "Usability, the Soul of Python" In-Reply-To: References: <4bb14173$0$1640$742ec2ed@news.sonic.net> <20100331003241.47fa91f6@vulcan.local> Message-ID: <4BB3A0CC.2090409@gmail.com> Lawrence D'Oliveiro wrote: > In message <20100331003241.47fa91f6 at vulcan.local>, Robert Fendt wrote: > > >> The braces are gone, and with them the holy wars. >> > > Let me start a new one. I would still put in some kind of explicit indicator > of the end of the grouping construct: > > count = 99 > while count > 0: > print u'%d slabs of spam in my mail!' % count > print u'%d slabs of spam,' % count > print u'Send one to abuse and Just Hit Delete,' > count += 1 > print u'%d slabs of spam in my mail!' % count > print u'' > #end while > I'd much prefer the following : ## Beginning of a program block count = 99 # Set the variable count as a name for the integer object 99 while count > 0: # if count is the name of 0 or less then exit the loop (this will NEVER happen) ## Beginning of a while loop print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' ## End of a while loop ## End of a program block Which is reeeaaally easier to understand than : count = 99 while True print u'%d slabs of spam in my mail!' % count print u'%d slabs of spam,' % count print u'Send one to abuse and Just Hit Delete,' count += 1 print u'%d slabs of spam in my mail!' % count print u'' -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Mar 31 15:22:26 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 15:22:26 -0400 Subject: sort array, apply rearrangement to second In-Reply-To: <1jg81f7.5ub3191oci9fkN%see@sig.for.address> References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> <1jg81f7.5ub3191oci9fkN%see@sig.for.address> Message-ID: Victor Eijkhout wrote: > Robert Kern wrote: > >> second[first.argsort()] > > Really cool. Thanks. > >> Ask numpy questions on the numpy mailing list. > > I will. I thought that this question would have an answer in a generic > python idiom. > > Victor. Not an unreasonable assumption, but it turns out that for most Python users (estimate PFTA: 97%) numpy/scipt is esoteric knowledge. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at rcn.com Wed Mar 31 16:09:54 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 31 Mar 2010 13:09:54 -0700 (PDT) Subject: sort array, apply rearrangement to second References: <1jg6j1v.oxpx651vbq67mN%see@sig.for.address> Message-ID: <8d8415a5-ba77-4dc3-b870-f159886e76b5@i25g2000yqm.googlegroups.com> On Mar 30, 4:25?pm, s... at sig.for.address (Victor Eijkhout) wrote: > I have two arrays, made with numpy. The first one has values that I want > to use as sorting keys; the second one needs to be sorted by those keys. > Obviously I could turn them into a dictionary ?of pairs and sort by the > first member, but I think that's not very efficient, at least in space, > and this needs to be done as efficiently as possible. Alf's recommendation is clean and correct. Just make a list of tuples. FWIW, here's a little hack that does the work for you: >>> values = ['A', 'B', 'C', 'D', 'E'] >>> keys = [50, 20, 40, 10, 30] >>> keyiter = iter(keys) >>> sorted(values, key=lambda k: next(keyiter)) ['D', 'B', 'E', 'C', 'A'] Raymond From pulikesimahesh at gmail.com Wed Mar 31 16:18:44 2010 From: pulikesimahesh at gmail.com (SWETHA) Date: Wed, 31 Mar 2010 13:18:44 -0700 (PDT) Subject: Want / Need Genuine Google Adsense Account for Rs.300/- Message-ID: Genuine Google Adsense Account for Rs.300/- We will approve your google adsense approval. We will help you till you get the first adsense check. Please send your mobile number to pramesh0538 at gmail.com , i will call you with in 15 minutes and give you the google adsense account. High Price Reduction for multiple adsense accounts. From icanbob at gmail.com Wed Mar 31 16:21:16 2010 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 31 Mar 2010 13:21:16 -0700 (PDT) Subject: Python + OpenOffice Calc References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Message-ID: <1233c19f-3268-4e57-bec7-e72c17941981@z9g2000vbm.googlegroups.com> On Mar 31, 2:47 am, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price > > a way to add a new "line" if needed (for a new piece entry) similar to the > "add rule" in evolution > > 1 text field for the description of the work + 1 field for the price of > the work > > and off course a way to insert this data in to the ods file via python > > Any hints/tutorial/info? > > thanks > Nico OOcalc supports a little known feature whereby data can be automatically sync'd between the spreadsheet and an HTML table. A few years ago I did up a demo of this in action using Tcl/Tk (http:// www.icanprogram.com/hosug). It should not be too hard to port this idea to Python. bob From steve at holdenweb.com Wed Mar 31 16:21:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 16:21:17 -0400 Subject: Question about list comprehension/standard "for" disparities In-Reply-To: References: Message-ID: Nathan Rice wrote: > I was just wondering, why the list/generator and standard "for" have > disparities? > > It would be really nice to be able to do: > > for x in y if foo: > ... > > rather than: > > for x in (x for x in y if foo): > ... > But it's not much of an issue when you can easily write for x in y: if foo: ... is it? What's the advantage of your preferred format that overrides its reduced readability? > Also, from a style standpoint, I prefer to extract the loop logic into a > function if it's more than a few lines long. As a result, most of my > loops are of the form: > > for x in y: > bar(x) > > So I frequently end up using map. As I understand it, there is some > discussion of removing map() in favor of comprehensions. Is there any > reason why the for syntax could not be expanded to accommodate > statements of the form: > > bar(x) for x in y > > ? > Put parentheses around it and you have a generator expression, which sounds like it's exactly what you want: a lazy way of producing a sequence of values: >>> y = ["this", "that", "and", "the", "other"] >>> def bar(x): ... return 2*x ... >>> ge = (bar(x) for x in y) >>> ge >>> for x in ge: ... print x ... thisthis thatthat andand thethe otherother >>> If you need to use the sequence repeatedly then a list comprehension is clearly better, since you don't exhaust it by iterating over it. I doubt map's going to disappear, but neither are comprehensions or generator expressions. > This inconsistency really bothered me when I started playing with > python, and it seems kind of at-odds with the "one right way to do > things" mentality. > That's the Platonic ideal, but the real world is a dirty place and Python lives firmly in the real world! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From sccolbert at gmail.com Wed Mar 31 16:38:04 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 31 Mar 2010 16:38:04 -0400 Subject: Python + OpenOffice Calc In-Reply-To: <1233c19f-3268-4e57-bec7-e72c17941981@z9g2000vbm.googlegroups.com> References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> <1233c19f-3268-4e57-bec7-e72c17941981@z9g2000vbm.googlegroups.com> Message-ID: On Wed, Mar 31, 2010 at 4:21 PM, bobicanprogram wrote: > On Mar 31, 2:47 am, Tracubik wrote: > > Hi all! > > i'm giving away to a friend of mine that have a garage (he repair car) my > > old computer. He will use it essentialy to create estimates of the work > > via an ods file (i've made a simple ods file to be filled with the cost > of > > materials and a description of the work). > > He's totally new with computer and have difficult to fill the ods file, > so > > i'ld like to create a simple python program that help him to introduce > the > > data in to the ods file via a simple gui. > > So what i'm looking for is a way in python to insert data in a particular > > cell of the ods file and possibly to save it and print it when it's full > > filled with data. > > > > the guy is similar to this: > > > > 3 fields: quantity - description of the piece bought - price > > > > a way to add a new "line" if needed (for a new piece entry) similar to > the > > "add rule" in evolution > > > > 1 text field for the description of the work + 1 field for the price of > > the work > > > > and off course a way to insert this data in to the ods file via python > > > > Any hints/tutorial/info? > > > > thanks > > Nico > > > OOcalc supports a little known feature whereby data can be > automatically sync'd between the spreadsheet and an HTML table. A > few years ago I did up a demo of this in action using Tcl/Tk (http:// > www.icanprogram.com/hosug). It should not be too hard to port this > idea to Python. > > bob > -- > http://mail.python.org/mailman/listinfo/python-list > if he cant click on a cell in oocalc, what makes you think he'll be able to use your program? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lxkain at gmail.com Wed Mar 31 16:59:01 2010 From: lxkain at gmail.com (LX) Date: Wed, 31 Mar 2010 13:59:01 -0700 (PDT) Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: On Mar 30, 2:41?pm, MRAB wrote: > LX wrote: > > On Mar 29, 6:34 pm, MRAB wrote: > >> LX wrote: > >>> Hi all, I have a question about decorators. I would like to use them > >>> for argument checking, and pre/post conditions. However, I don't want > >>> the additional overhead when I run in non-debug mode. I could do > >>> something like this, using a simple trace example. > >>> @decorator > >>> def pass_decorator(f, *args, **kw): # what about the slow-down that > >>> incurs when using pass_decorator? > >>> ? ? return f(*args, **kw) > >>> @decorator > >>> def trace_decorator(f, *args, **kw): > >>> ? ? print "calling %s with args %s, %s" % (f.func_name, args, kw) > >>> ? ? return f(*args, **kw) > >>> trace_enable_flag = False #__debug__ > >>> trace = trace_decorator if trace_enable_flag else pass_decorator > >>> Trouble is, there is still an additional encapsulating function call. > >>> Is there any way to eliminate the extra function call altogether? > >>> Thanks in advance! > >> I think you have misunderstood certain details about decorators. > > >> This code with adecorator: > > >> ? ? ?@decorator > >> ? ? ?def hello(): > >> ? ? ? ? ?print "hello world" > > >> basically does this: > > >> ? ? ?def hello(): > >> ? ? ? ? ?print "hello world" > >> ? ? ?hello =decorator(hello) > > >> so your non-decoratorjust needs to return the function it was passed: > > >> ? ? ?def pass_decorator(func): > >> ? ? ? ? ?return func > > >> and your tracedecoratorwould be something like this: > > >> ? ? ?def trace_decorator(func): > >> ? ? ? ? ?def show(*args, **kwargs): > >> ? ? ? ? ? ? ?print "calling %s with args %s, %s" % (func.func_name, > >> args, kwargs) > >> ? ? ? ? ? ? ?result = func(*args, **kwargs) > >> ? ? ? ? ? ? ?print "returning %s from %s" % (result, func.func_name) > >> ? ? ? ? ? ? ?return result > >> ? ? ? ? ?return show > > > Sure, but during runtime, pass_decorator will still be called, even > > though it doesn't do anything. I am wondering if I can disable this > > additional function call at non-debug runtime. In other words, I want > > the calling stack to contain nodecoratorat all, not even > > pass_decorator. > > > I should mention that, in my code, the symbol "decorator" is imported > > from Michele Simionato'sdecorator.py file. > > pass_decorator will be called when the decorated function is _defined_, > but not when the decorated function is _called_. Why is it then that during runtime, with a breakpoint in some arbitrary main() in main.py, I get something similar to the following call stack: main.py, line xxx, in main() , line 2, in main decorator.py, line 261, in pass_decorator return f(*args, **kw) main.py, line yyy, in main() * breakpoint line here * It looks to me the call stack still includes the additional level of the decorator... what am I missing? Thank you for your time. From novacompute at gmail.com Wed Mar 31 17:26:24 2010 From: novacompute at gmail.com (wukong) Date: Wed, 31 Mar 2010 14:26:24 -0700 (PDT) Subject: subprocess only good for win32? Message-ID: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> subprocess works fine on my win pro 32-bit, but not on vista 64-bit. am i doing some wrong, or it just won't work for win64? If that's true, will it be extended to win64 in teh future? thanks in advance wk From python at mrabarnett.plus.com Wed Mar 31 17:27:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 31 Mar 2010 22:27:05 +0100 Subject: decorators only when __debug__ == True In-Reply-To: References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <4BB3BE29.70504@mrabarnett.plus.com> LX wrote: > On Mar 30, 2:41 pm, MRAB wrote: >> LX wrote: >>> On Mar 29, 6:34 pm, MRAB wrote: >>>> LX wrote: >>>>> Hi all, I have a question about decorators. I would like to use them >>>>> for argument checking, and pre/post conditions. However, I don't want >>>>> the additional overhead when I run in non-debug mode. I could do >>>>> something like this, using a simple trace example. >>>>> @decorator >>>>> def pass_decorator(f, *args, **kw): # what about the slow-down that >>>>> incurs when using pass_decorator? >>>>> return f(*args, **kw) >>>>> @decorator >>>>> def trace_decorator(f, *args, **kw): >>>>> print "calling %s with args %s, %s" % (f.func_name, args, kw) >>>>> return f(*args, **kw) >>>>> trace_enable_flag = False #__debug__ >>>>> trace = trace_decorator if trace_enable_flag else pass_decorator >>>>> Trouble is, there is still an additional encapsulating function call. >>>>> Is there any way to eliminate the extra function call altogether? >>>>> Thanks in advance! >>>> I think you have misunderstood certain details about decorators. >>>> This code with adecorator: >>>> @decorator >>>> def hello(): >>>> print "hello world" >>>> basically does this: >>>> def hello(): >>>> print "hello world" >>>> hello =decorator(hello) >>>> so your non-decoratorjust needs to return the function it was passed: >>>> def pass_decorator(func): >>>> return func >>>> and your tracedecoratorwould be something like this: >>>> def trace_decorator(func): >>>> def show(*args, **kwargs): >>>> print "calling %s with args %s, %s" % (func.func_name, >>>> args, kwargs) >>>> result = func(*args, **kwargs) >>>> print "returning %s from %s" % (result, func.func_name) >>>> return result >>>> return show >>> Sure, but during runtime, pass_decorator will still be called, even >>> though it doesn't do anything. I am wondering if I can disable this >>> additional function call at non-debug runtime. In other words, I want >>> the calling stack to contain nodecoratorat all, not even >>> pass_decorator. >>> I should mention that, in my code, the symbol "decorator" is imported >>> from Michele Simionato'sdecorator.py file. >> pass_decorator will be called when the decorated function is _defined_, >> but not when the decorated function is _called_. > > Why is it then that during runtime, with a breakpoint in some > arbitrary main() in main.py, I get something similar to the following > call stack: > > main.py, line xxx, in > main() > > , line 2, in main > > decorator.py, line 261, in pass_decorator > return f(*args, **kw) > > main.py, line yyy, in main() > * breakpoint line here * > > It looks to me the call stack still includes the additional level of > the decorator... what am I missing? Thank you for your time. Are you still defining your decorators in the same way as in your original post? A decorator shouldn't call the function it's decorating. My version of pass_decorator just returns the function it's decorating, not call it, and my version of trace_decorator returns a locally-defined function which will call the decorated function. From apt.shansen at gmail.invalid Wed Mar 31 17:28:27 2010 From: apt.shansen at gmail.invalid (Stephen Hansen) Date: Wed, 31 Mar 2010 14:28:27 -0700 Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <2010033114282721695-aptshansen@gmailinvalid> On 2010-03-31 13:59:01 -0700, LX said: >> pass_decorator will be called when the decorated function is _defined_, >> but not when the decorated function is _called_. > > Why is it then that during runtime, with a breakpoint in some > arbitrary main() in main.py, I get something similar to the following > call stack: > > main.py, line xxx, in > main() > > , line 2, in main > > decorator.py, line 261, in pass_decorator > return f(*args, **kw) > > main.py, line yyy, in main() > * breakpoint line here * > > It looks to me the call stack still includes the additional level of > the decorator... what am I missing? Thank you for your time. You're not defining pass_decorator correctly. Always show us the actual code when you're showing results. Your pass_decorator should just return the original function, undecorated, unmodified if you're not in debug. It should only return a decorated function otherwise. Consider: ----- from decorator import decorator def debug_decorator(fn): if __debug__: def wrapper(fn, *args, **kwargs): # insert pre-condition testing here if len(args) != 1: raise ValueError("Incorrect number of arguments") result = fn(*args, **kwargs) # insert post-condition testing here if result not in (True, False): raise ValueError("Incorrect return value!") return result return decorator(wrapper, fn) else: return fn @debug_decorator def my_test(arg): if not arg: raise RuntimeError return True my_test(0) ----- And the output depending on if you're in debug mode or not: Top:test ixokai$ python deco.py Traceback (most recent call last): File "deco.py", line 27, in my_test(0) File "", line 2, in my_test File "deco.py", line 10, in wrapper result = fn(*args, **kwargs) File "deco.py", line 24, in my_test raise RuntimeError RuntimeError Top:test ixokai$ python -O deco.py Traceback (most recent call last): File "deco.py", line 27, in my_test(0) File "deco.py", line 24, in my_test raise RuntimeError RuntimeError -- --S ... p.s: change the ".invalid" to ".com" in email address to reply privately. From clp2 at rebertia.com Wed Mar 31 17:33:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 31 Mar 2010 14:33:13 -0700 Subject: subprocess only good for win32? In-Reply-To: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: On Wed, Mar 31, 2010 at 2:26 PM, wukong wrote: > subprocess works fine on my win pro 32-bit, but not on vista 64-bit. > am i doing some wrong, or it just won't work for win64? ?If that's > true, will it be extended to win64 in teh future? Please characterize exactly how it is not working for you. Include any error message and/or exception traceback. Cheers, Chris -- http://blog.rebertia.com From dreadpiratejeff at gmail.com Wed Mar 31 17:37:10 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 31 Mar 2010 17:37:10 -0400 Subject: Get Eclipse/PyDev to run scripts that don't end in .py Message-ID: Is there any way to tell PyDev in Eclipse to run a script that doesn't end in .py? Even if I have to go and manually set something for each file... I've inherited (in a manner of speaking) a dev project that is done in python2.6... I pulled the latest dev branch and have it opened as a project in Eclipse, however, none of the python files end in .py, so PyDev only sees them as text files. And because of that, I can't run them in Eclipse to try my changes, debug, etc. So, is there a way to make them show up as python code without the .py extension? Because of this, I also don't get any of the fancy indenting and highlighting that I'd normally get... Cheers, Jeff From novacompute at gmail.com Wed Mar 31 17:43:26 2010 From: novacompute at gmail.com (wukong) Date: Wed, 31 Mar 2010 14:43:26 -0700 (PDT) Subject: subprocess only good for win32? References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: On Mar 31, 2:33?pm, Chris Rebert wrote: > On Wed, Mar 31, 2010 at 2:26 PM, wukong wrote: > > subprocess works fine on my win pro 32-bit, but not on vista 64-bit. > > am i doing some wrong, or it just won't work for win64? ?If that's > > true, will it be extended to win64 in teh future? > > Please characterize exactly how it is not working for you. > Include any error message and/or exception traceback. > > Cheers, > Chris > --http://blog.rebertia.com thanks for checking in, here's the error msg. """ Traceback (most recent call last): File "C:/GUI/mainFunc.py", line 230, in OnSolve subprocess.call([filename]) File "C:\Program Files (x86)\python26\lib\subprocess.py", line 470, in call return Popen(*popenargs, **kwargs).wait() File "C:\Program Files (x86)\python26\lib\subprocess.py", line 621, in __init__ errread, errwrite) File "C:\Program Files (x86)\python26\lib\subprocess.py", line 830, in _execute_child startupinfo) WindowsError: [Error 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail """ also subprocess.py clearly says """ import sys mswindows = (sys.platform == "win32") """ thanks wk From tjreedy at udel.edu Wed Mar 31 17:54:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 31 Mar 2010 17:54:56 -0400 Subject: subprocess only good for win32? In-Reply-To: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: On 3/31/2010 5:26 PM, wukong wrote: > subprocess works fine on my win pro 32-bit, but not on vista 64-bit. You are more likely to get a helpful answer if you give a minimal example and explain exactly what 'not [works fine]' means. What did happen? Include full error traceback if there was one. From python at rcn.com Wed Mar 31 18:42:34 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 31 Mar 2010 15:42:34 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter References: Message-ID: On Mar 31, 10:08?am, Chris Curvey wrote: > I must be having a brain cramp. ?Given a list of objects, how can I > sort the list on one attribute in descending order, then sort within > each group in ascending order on another attribute. > > For example: > > class Foo: > ? ? def __init__(self, a, b, c): > ? ? ? ? self.a = a > ? ? ? ? self.b = b > ? ? ? ? self.c = c > > I can do "allmyfoos.sort(operator.attrgetter('a','b'))" to sort > ascending on both attributes, but how could i sort by "a, descending, > then b, ascending)?" Rely on sort stability and do two passes: allmyfoos.sort(operator.attrgetter('b')) allmyfoos.sort(operator.attrgetter('a'), reverse=True) Raymond From martin at v.loewis.de Wed Mar 31 18:47:18 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 01 Apr 2010 00:47:18 +0200 Subject: subprocess only good for win32? In-Reply-To: References: <353133a8-ff39-4b36-b96d-4836cea621bf@j41g2000vbe.googlegroups.com> Message-ID: <4BB3D0F6.2010906@v.loewis.de> > WindowsError: [Error 14001] The application has failed to start > because its side-by-side configuration is incorrect. Please see the > application event log for more detail This is a configuration error on your system. The application you are trying to start is incorrectly installed - it's not only that Python can't start it, but nobody can. Regards, Martin From abrahamalrajhi at gmail.com Wed Mar 31 18:48:07 2010 From: abrahamalrajhi at gmail.com (Abethebabe) Date: Wed, 31 Mar 2010 15:48:07 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? Message-ID: I wanted to know if there was a way I could get a Python program to run off of my flash drive as soon as the computer (Windows) detected the device? For example I could have a a simple program that would create a text document on the computers desktop when my flash drive is detected. From steve at REMOVE-THIS-cybersource.com.au Wed Mar 31 18:53:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Mar 2010 22:53:51 GMT Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> Message-ID: <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> On Wed, 31 Mar 2010 22:27:05 +0100, MRAB wrote: > LX wrote: [...] >> It looks to me the call stack still includes the additional level of >> the decorator... what am I missing? Thank you for your time. > > Are you still defining your decorators in the same way as in your > original post? > > A decorator shouldn't call the function it's decorating. *raises eyebrow* Surely, in the general case, a decorator SHOULD call the function it is decorating? I'm sure you know that, but your wording is funny and could confuse the OP. In this specific case, where the OP wants a "do nothing pass-decorator", he should do this: def decorator(func): if __debug__: ... else: return func rather than this: def decorator(func): if __debug__: ... else: def inner(*args): return func(*args) return inner -- Steven From steve at REMOVE-THIS-cybersource.com.au Wed Mar 31 18:57:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 31 Mar 2010 22:57:10 GMT Subject: sorting ascending/descending with operator.attrgetter References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> Message-ID: <4bb3d346$0$8827$c3e8da3@news.astraweb.com> On Wed, 31 Mar 2010 12:05:24 -0700, Patrick Maupin wrote: > You can provide a cmp function to the string sort method, e.g. cmp = > lambda x,y: -cmp(x.a, y.a) or cmp(x.b, y.b) String sort method? >>> ''.sort Traceback (most recent call last): File "", line 1, in AttributeError: 'str' object has no attribute 'sort' >>> import string >>> string.sort Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'sort' Did you mean list sort method? > You can also possibly gain some efficiency by using key instead of cmp. That is an impressive understatement. key is called once for every item, cmp is called once for every comparison. cmp has been dropped from Python 3.x because its performance is poor. -- Steven From rantingrick at gmail.com Wed Mar 31 19:00:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 31 Mar 2010 16:00:46 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? References: Message-ID: <19123497-50f6-4234-bf99-6550f35324a4@o30g2000yqb.googlegroups.com> On Mar 31, 5:48?pm, Abethebabe wrote: > I wanted to know if there was a way I could get a Python program to > run off of my flash drive as soon as the computer (Windows) detected > the device? > > For example I could have a a simple program that would create a text > document on the computers desktop when my flash drive is detected. Well i sure hope your intentions are for the forces of good and NOT the forces of evil. Anyway the beauty of USB is the fact you can read and write to it just like any other file on your harddisc, unlike with CD media where you need a CS degree and MS's blessing. So now the question really is """ How do i run a python script when i plug in my flash drive"""? And thats a good question. Well it's going to involve "something" watching and waiting for this (big hint) "event" to happen. Maybe something like a "Flash Drive plug in watcher sevice" Do you have any experience with win32 programming? From alfps at start.no Wed Mar 31 19:04:39 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 01 Apr 2010 01:04:39 +0200 Subject: Getting a Python program to run of off a flash drive? In-Reply-To: References: Message-ID: * Abethebabe: > I wanted to know if there was a way I could get a Python program to > run off of my flash drive as soon as the computer (Windows) detected > the device? > > For example I could have a a simple program that would create a text > document on the computers desktop when my flash drive is detected. As long as its your own computer, no problem. However, in the war between the corporate "we own your computer" and the individual's "I think the computer's mine" (so eloquently expressed as the main goal of the 70's Smalltalk project, to bring effective computing to the masses) the arms race is currently stuck at a point where any computer-literate person running Windows turns off the various run-automatically features as soon as they're sneak-introduced by Windows service packs and IE updates and whatever. I don't know, but I think there are six or seven such schemes. Happily, as far as I know they can all be turned off. If not for this then the recording industry could have sued a lot of people in Norway. But our laws require copy protection schemes to be effective, and a scheme based on a feature that most intelligent persons have turned off isn't effective, so wrt. law it's like it's not there. I think it was EMI who once distributed a nasty rootkit (and yes, it was theirs, it was not an accident) as a copy protection scheme on a music CD. Getting a lot of bad publicity for that they and other record companies didn't back off but continued with just less malware-like auto run protection. I was perplexed when I learned that one CD with Madrugada, that I'd copied to my hard disk, was supposedly protected this way. Sure enough, there was this sticker on it. However, since the idiot scheme they used was based on auto-run I never noticed. Cheers, - Alf From python at mrabarnett.plus.com Wed Mar 31 19:27:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 01 Apr 2010 00:27:51 +0100 Subject: decorators only when __debug__ == True In-Reply-To: <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> Message-ID: <4BB3DA77.1040302@mrabarnett.plus.com> Steven D'Aprano wrote: > On Wed, 31 Mar 2010 22:27:05 +0100, MRAB wrote: > >> LX wrote: > [...] >>> It looks to me the call stack still includes the additional level of >>> the decorator... what am I missing? Thank you for your time. >> Are you still defining your decorators in the same way as in your >> original post? >> >> A decorator shouldn't call the function it's decorating. > > *raises eyebrow* > > Surely, in the general case, a decorator SHOULD call the function it is > decorating? I'm sure you know that, but your wording is funny and could > confuse the OP. > What I mean is that the function that's doing the decorating shouldn't call the function; it's the locally-defined wrapper function that calls the decorated function. For example, in my version of trace_decorator() it's show() that calls the decorated function, not trace_decorator() itself. Unless the word 'decorator' refers to the locally-defined function, in which case, what do you call the function that does the wrapping, the one whose name follows the '@'? > In this specific case, where the OP wants a "do nothing pass-decorator", > he should do this: > > def decorator(func): > if __debug__: > ... > else: > return func > > rather than this: > > def decorator(func): > if __debug__: > ... > else: > def inner(*args): > return func(*args) > return inner > > > From lxkain at gmail.com Wed Mar 31 20:01:05 2010 From: lxkain at gmail.com (LX) Date: Wed, 31 Mar 2010 17:01:05 -0700 (PDT) Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> <2010033114282721695-aptshansen@gmailinvalid> Message-ID: <241036ac-23c9-4f2c-8619-69fbba5f300e@30g2000yqi.googlegroups.com> On Mar 31, 2:28?pm, Stephen Hansen wrote: > On 2010-03-31 13:59:01 -0700, LX said: > > > > > > >> pass_decorator will be called when the decorated function is _defined_, > >> but not when the decorated function is _called_. > > > Why is it then that during runtime, with a breakpoint in some > > arbitrary main() in main.py, I get something similar to the following > > call stack: > > > main.py, line xxx, in > > ?main() > > > , line 2, in main > > >decorator.py, line 261, in pass_decorator > > ?return f(*args, **kw) > > > main.py, line yyy, in main() > > ?* breakpoint line here * > > > It looks to me the call stack still includes the additional level of > > thedecorator... what am I missing? Thank you for your time. > > You're not defining pass_decorator correctly. Always show us the actual > code when you're showing results. > > Your pass_decorator should just return the original function, > undecorated, unmodified if you're not in debug. It should only return a > decorated function otherwise. > > Consider: > > ----- > fromdecoratorimportdecorator > > def debug_decorator(fn): > ? ? if __debug__: > ? ? ? ? def wrapper(fn, *args, **kwargs): > ? ? ? ? ? ? # insert pre-condition testing here > ? ? ? ? ? ? if len(args) != 1: > ? ? ? ? ? ? ? ? raise ValueError("Incorrect number of arguments") > > ? ? ? ? ? ? result = fn(*args, **kwargs) > > ? ? ? ? ? ? # insert post-condition testing here > ? ? ? ? ? ? if result not in (True, False): > ? ? ? ? ? ? ? ? raise ValueError("Incorrect return value!") > > ? ? ? ? ? ? return result > ? ? ? ? returndecorator(wrapper, fn) > ? ? else: > ? ? ? ? return fn > > @debug_decorator > def my_test(arg): > ? ? if not arg: > ? ? ? ? raise RuntimeError > ? ? return True > > my_test(0) > ----- > > And the output depending on if you're in debug mode or not: > Top:test ixokai$ python deco.py > Traceback (most recent call last): > ? File "deco.py", line 27, in > ? ? my_test(0) > ? File "", line 2, in my_test > ? File "deco.py", line 10, in wrapper > ? ? result = fn(*args, **kwargs) > ? File "deco.py", line 24, in my_test > ? ? raise RuntimeError > RuntimeError > > Top:test ixokai$ python -O deco.py > Traceback (most recent call last): > ? File "deco.py", line 27, in > ? ? my_test(0) > ? File "deco.py", line 24, in my_test > ? ? raise RuntimeError > RuntimeError > > -- > --S > > ... p.s: change the ".invalid" to ".com" in email address to reply privately. Thank you all a lot! The last 3 posts helped me figure it out. Indeed, my pass_decorator function used "@decorator", using the decoratory.py library. This prevented return of the original function. The code that I have now is: #NOT THIS: #@decorator #def pass_decorator(f, *args, **kw): # what about the slow-down that incurs when using pass_decorator #return f(*args, **kw) def pass_decorator(f): return f @decorator def trace_decorator(f, *args, **kw): print "calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) trace_enable_flag = False #__debug__ trace = trace_decorator if trace_enable_flag else pass_decorator From pmaupin at gmail.com Wed Mar 31 20:21:18 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 31 Mar 2010 17:21:18 -0700 (PDT) Subject: sorting ascending/descending with operator.attrgetter References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> <4bb3d346$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Mar 31, 5:57?pm, Steven D'Aprano wrote: > Did you mean list sort method? Why, yes. Yes, I did. Yes, I'm an old forgetful man who sometimes misspeaks or mistypes, and you're the smartest, sharpest guy in the world. Most helpful, too. It's much more useful to show how I'm wrong than to provide useful info to the OP. Teaches people not to quickly post on CLP to try to help out people with immediate problems. No, it would have been much more useful for me to self-edit my post for a couple of days before posting. Doesn't matter though. The OP was sorting lists, not strings, so he knew what I meant. > > You can also possibly gain some efficiency by using key instead of cmp. > > That is an impressive understatement. key is called once for every item, > cmp is called once for every comparison. cmp has been dropped from Python > 3.x because its performance is poor. Yes, well, I did have the "Use a key" statement before "use cmp" (before I did the tiny bit of editing I did before posting) and then it occurred to me that he might be sorting with strings, so I thought I would give him something that worked, and then something that might work better under some circumstances. And, BTW, if he is only occasionally sorting a few short strings^H^H^H^H^H^H^Hlists, he'll never notice a performance difference. But at least you can take comfort that he now knows how superior your intellect is to mine. Of course, he might accidentally underestimate Peter and Raymond's intellect. They published dual sort solutions that are, for most cases, probably better than the single sort solution I published, but neglected to call attention to just how bad my suggestion was. From abrahamalrajhi at gmail.com Wed Mar 31 20:32:33 2010 From: abrahamalrajhi at gmail.com (Abethebabe) Date: Wed, 31 Mar 2010 17:32:33 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? References: <19123497-50f6-4234-bf99-6550f35324a4@o30g2000yqb.googlegroups.com> Message-ID: <11ac4094-655e-4474-98c8-fa8829d4f56f@z3g2000yqz.googlegroups.com> On Mar 31, 7:00?pm, rantingrick wrote: > On Mar 31, 5:48?pm, Abethebabe wrote: > > > I wanted to know if there was a way I could get a Python program to > > run off of my flash drive as soon as the computer (Windows) detected > > the device? > > > For example I could have a a simple program that would create a text > > document on the computers desktop when my flash drive is detected. > > Well i sure hope your intentions are for the forces of good and NOT > the forces of evil. Anyway the beauty of USB is the fact you can read > and write to it just like any other file on your harddisc, unlike with > CD media where you need a CS degree and MS's blessing. So now the > question really is > > """ How do i run a python script when i plug in my flash drive"""? > > And thats a good question. Well it's going to involve "something" > watching and waiting for this (big hint) "event" to happen. Maybe > something like a "Flash Drive plug in watcher sevice" Do you have any > experience with win32 programming? I'm a web programmer and python is my first delve into desktop programming. I had a rough guesstimation that I'd need to maybe use wxpython with an API for the flash drive (wasn't sure if hardware had this, I guess it would be the drivers?) So do you think wxPython would have the answer I'm looking for? Thanks for your reply btw From abrahamalrajhi at gmail.com Wed Mar 31 20:33:49 2010 From: abrahamalrajhi at gmail.com (Abethebabe) Date: Wed, 31 Mar 2010 17:33:49 -0700 (PDT) Subject: Getting a Python program to run of off a flash drive? References: Message-ID: On Mar 31, 7:04?pm, "Alf P. Steinbach" wrote: > * Abethebabe: > > > I wanted to know if there was a way I could get a Python program to > > run off of my flash drive as soon as the computer (Windows) detected > > the device? > > > For example I could have a a simple program that would create a text > > document on the computers desktop when my flash drive is detected. > > As long as its your own computer, no problem. > > However, in the war between the corporate "we own your computer" and the > individual's "I think the computer's mine" (so eloquently expressed as the main > goal of the 70's Smalltalk project, to bring effective computing to the masses) > the arms race is currently stuck at a point where any computer-literate person > running Windows turns off the various run-automatically features as soon as > they're sneak-introduced by Windows service packs and IE updates and whatever. I > don't know, but I think there are six or seven such schemes. Happily, as far as > I know they can all be turned off. If not for this then the recording industry > could have sued a lot of people in Norway. But our laws require copy protection > schemes to be effective, and a scheme based on a feature that most intelligent > persons have turned off isn't effective, so wrt. law it's like it's not there. > > I think it was EMI who once distributed a nasty rootkit (and yes, it was theirs, > it was not an accident) as a copy protection scheme on a music CD. Getting a lot > of bad publicity for that they and other record companies didn't back off but > continued with just less malware-like auto run protection. I was perplexed when > I learned that one CD with Madrugada, that I'd copied to my hard disk, was > supposedly protected this way. Sure enough, there was this sticker on it. > However, since the idiot scheme they used was based on auto-run I never noticed. > > Cheers, > > - Alf Interesting, so every new computer I'd use it on I would need to disable these filters? If I could just disable them on my computer though I'd be happy enough. From keith at nekotaku.com Wed Mar 31 20:38:46 2010 From: keith at nekotaku.com (KB) Date: Wed, 31 Mar 2010 17:38:46 -0700 (PDT) Subject: CGI templating with python Message-ID: Hi there, Years ago I wrote a LAMP app using python. I find I need a simple web data entry tool to store records (stock research) and when I enter a stock ticker, to pull up all the past research I have done. I am imagining fields like ticker, date, pulldown menus for various options, long text for comments etc.. It's a very light weight application, so I was wondering if using something like Cheetah is the best way to do this? Or should I research Zope further or are there any other suggestions? Environment: - Python 2.5 (w/ MySQLdb) - MySQL 5.1 - Windows Vista Many thanks in advance! From martin.hellwig at dcuktec.org Wed Mar 31 21:13:57 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 01 Apr 2010 02:13:57 +0100 Subject: Get Eclipse/PyDev to run scripts that don't end in .py In-Reply-To: References: Message-ID: On 03/31/10 22:37, J wrote: > Is there any way to tell PyDev in Eclipse to run a script that doesn't > end in .py? Even if I have to go and manually set something for each > file... > > I've inherited (in a manner of speaking) a dev project that is done in > python2.6... I pulled the latest dev branch and have it opened as a > project in Eclipse, however, none of the python files end in .py, so > PyDev only sees them as text files. And because of that, I can't run > them in Eclipse to try my changes, debug, etc. > > So, is there a way to make them show up as python code without the .py > extension? Because of this, I also don't get any of the fancy > indenting and highlighting that I'd normally get... > > Cheers, > > Jeff You probably need to do that one level higher, i.e. in Eclipse (hint: Preferences>General>Editors>File Associations ). I do have a couple of remarks though. It sounds to me like you inherited something of more or less a 'shipped' product. Perhaps it would be wise to invest some time to restructure the project so that it works nicely with all the tools you have (unit testing, coverage, refactoring, etc.) and build a script that from your source builds the actually release (resembling that what you have inherited). This question would probably have been more suitable in http://sourceforge.net/projects/pydev/forums/forum/293649 (that is the PyDev forum), and it is likely that they would have sent you through to http://www.eclipse.org/forums/ . -- mph From fabiofz at gmail.com Wed Mar 31 21:17:09 2010 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Wed, 31 Mar 2010 22:17:09 -0300 Subject: Get Eclipse/PyDev to run scripts that don't end in .py In-Reply-To: References: Message-ID: On Wed, Mar 31, 2010 at 6:37 PM, J wrote: > Is there any way to tell PyDev in Eclipse to run a script that doesn't > end in .py? ?Even if I have to go and manually set something for each > file... > > I've inherited (in a manner of speaking) a dev project that is done in > python2.6... I pulled the latest dev branch and have it opened as a > project in Eclipse, however, none of the python files end in .py, so > PyDev only sees them as text files. ?And because of that, I can't run > them in Eclipse to try my changes, debug, etc. > > So, is there a way to make them show up as python code without the .py > extension? ?Because of this, I also don't get any of the fancy > indenting and highlighting that I'd normally get... You have to change it in 2 places: 1. window > preferences > general > editors > file associations: add the *.extension and bind it to the Python Editor (see how the *.py association is done). 2. window > preferences > Pydev > editor > code style > file types: add your custom extension there (and you may want to change the default python extension if you'll keep creating modules with that different extension). Cheers, Fabio From steven at REMOVE.THIS.cybersource.com.au Wed Mar 31 21:30:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Apr 2010 01:30:21 GMT Subject: decorators only when __debug__ == True References: <7778821c-84f3-4829-8e05-85134c5d6c5b@y17g2000yqd.googlegroups.com> <4bb3d27f$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Thu, 01 Apr 2010 00:27:51 +0100, MRAB wrote: >>> A decorator shouldn't call the function it's decorating. >> >> *raises eyebrow* >> >> Surely, in the general case, a decorator SHOULD call the function it is >> decorating? I'm sure you know that, but your wording is funny and could >> confuse the OP. >> > What I mean is that the function that's doing the decorating shouldn't > call the function; it's the locally-defined wrapper function that calls > the decorated function. Ah, gotcha, that makes sense. Now I understand the distinction you were making. Thank you for the clarification. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Mar 31 21:34:36 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Apr 2010 01:34:36 GMT Subject: sorting ascending/descending with operator.attrgetter References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> <4bb3d346$0$8827$c3e8da3@news.astraweb.com> Message-ID: On Wed, 31 Mar 2010 17:21:18 -0700, Patrick Maupin wrote: > Doesn't matter though. The OP was sorting lists, not strings, so he > knew what I meant. I have found that when people ask basic questions about fundamental Python operations like sorting, it is risky to assume that they will know what I meant if I say something different. Since I've been on both the giving and receiving end of carelessly inaccurate answers, I know how frustrating it is to spend significant time trying to work out what I was doing wrong, only to be told much later "Oh, I meant you should do Y, not X. I thought you would understand what I meant." -- Steven From steve at holdenweb.com Wed Mar 31 22:19:27 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 31 Mar 2010 22:19:27 -0400 Subject: sorting ascending/descending with operator.attrgetter In-Reply-To: References: <96712ef1-5c10-455b-904c-c2436736c9d2@35g2000yqm.googlegroups.com> <4bb3d346$0$8827$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 31 Mar 2010 17:21:18 -0700, Patrick Maupin wrote: > >> Doesn't matter though. The OP was sorting lists, not strings, so he >> knew what I meant. > > I have found that when people ask basic questions about fundamental > Python operations like sorting, it is risky to assume that they will know > what I meant if I say something different. > > Since I've been on both the giving and receiving end of carelessly > inaccurate answers, I know how frustrating it is to spend significant > time trying to work out what I was doing wrong, only to be told much > later "Oh, I meant you should do Y, not X. I thought you would understand > what I meant." > But you surely will admit that you could be held to, well rather than "be pedantic" perhaps we should say "tend towards the literal"? I'm the same myself, and I know from personal experience that while I am (simply?) seeking accuracy and truth it sometimes bugs the hell out of people ... It's a geek thing. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From robert.kern at gmail.com Wed Mar 31 22:46:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 31 Mar 2010 21:46:54 -0500 Subject: CGI templating with python In-Reply-To: References: Message-ID: On 2010-03-31 19:38 , KB wrote: > Hi there, > > Years ago I wrote a LAMP app using python. I find I need a simple web > data entry tool to store records (stock research) and when I enter a > stock ticker, to pull up all the past research I have done. I am > imagining fields like ticker, date, pulldown menus for various > options, long text for comments etc.. > > It's a very light weight application, so I was wondering if using > something like Cheetah is the best way to do this? > > Or should I research Zope further or are there any other suggestions? Django will probably get you where you want to go the fastest: http://www.djangoproject.com/ In particular, its admin interface will probably automatically generate a usable UI for you without your having to write many templates at all. -- 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 From aahz at pythoncraft.com Wed Mar 31 23:33:35 2010 From: aahz at pythoncraft.com (Aahz) Date: 31 Mar 2010 20:33:35 -0700 Subject: Getting a Python program to run of off a flash drive? References: Message-ID: In article , Alf P. Steinbach wrote: > >I think it was EMI who once distributed a nasty rootkit (and yes, it >was theirs, it was not an accident) as a copy protection scheme on a >music CD. Sony, and I still (mostly) boycott Sony. (I buy no Sony hardware, but because Sony owns a movie studio, it's a little more difficult to boycott Sony DVDs.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? From ded.utility at gmail.com Wed Mar 31 23:36:56 2010 From: ded.utility at gmail.com (d d) Date: Wed, 31 Mar 2010 23:36:56 -0400 Subject: how to build with --enable-shared so that binary knows where libraries are. Message-ID: The following is on Linux. I'd like to build python with ./configure --enable-shared. And install in a non-standard place (an nfs-mounted directory). However, the binary is then not usable, since it can't find the library. I can fix this by defining LD_LIBRARY_PATH, but I don't want to do that. Doing anything system-specific is impractical, since many systems will point to this directory (LD_LIBRARY_PATH is feasible, though undesired, because it can be set in a common script that users call from their .cshrc files.) Is there a way to configure the build such that the binary will know where the shared library is? I found this: http://koansys.com/tech/building-python-with-enable-shared-in-non-standard-location It recommends LDFLAGS="-rpath ", and mentions that you get a "compiler cannot create executables" error unless you first create the empty directory. But I get that error even when I do create the empty directory. Any help would be appreciated. --Dan From rantingrick at gmail.com Wed Mar 31 23:53:08 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 31 Mar 2010 20:53:08 -0700 (PDT) Subject: Python + OpenOffice Calc References: <4bb2fe14$0$1120$4fafbaef@reader3.news.tin.it> Message-ID: On Mar 31, 2:47?am, Tracubik wrote: > Hi all! > i'm giving away to a friend of mine that have a garage (he repair car) my > old computer. He will use it essentialy to create estimates of the work > via an ods file (i've made a simple ods file to be filled with the cost of > materials and a description of the work). > He's totally new with computer and have difficult to fill the ods file, so > i'ld like to create a simple python program that help him to introduce the > data in to the ods file via a simple gui. > So what i'm looking for is a way in python to insert data in a particular > cell of the ods file and possibly to save it and print it when it's full > filled with data. > > the guy is similar to this: > > 3 fields: quantity - description of the piece bought - price So what is your plan...? * Pop up a dialog with three entrys, * have him fill out the three entrys, * then have python insert the data into the spreadsheet? ...Why bother messing with OO, too much trouble for me? If the guy is that scared of spreadsheets I would skip the spreadsheet all together and just use a Tk.Listbox to display the data. Create a big button at the bottom (preferably in Times 20 red font) that says "NEW INPUT" and let him edit lines by double clicking on them. You need a good Scrolled Listbox with a nice interface, an entry dialog, and some file IO with backup protection. Thats about it. I would probably create a new file every day, week, or month depending on the amount of data he enters daily, you don't want to load enormous files into a Tk.Listbox. Then just save all the data as csv and you can always load it into a spreadsheet later if the IRS comes knocking, or you need to print a professional looking spreadsheet ;-). Simple, 100% python solution! If you want to do this and need help i would be happy to offer my assistance. This would be a "fairly" simple script and great learning experience for you.

... > > Is there any way to do this in ElementTree? I think the easiest is to iterate not over the elements themselves, but over their parents, and then to remove all children of the specified tag in each step. Stefan From robert.kern at gmail.com Tue Mar 9 11:01:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Mar 2010 10:01:07 -0600 Subject: scipy sparse matrix question In-Reply-To: <1jf28jr.7abra61nwu04pN%see@sig.for.address> References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> Message-ID: On 2010-03-09 00:14 AM, Victor Eijkhout wrote: > I can't find any detailed information about scipy.sparse. The place to ask would be on scipy-user: http://www.scipy.org/Mailing_Lists > My specific question: what does "for x in A" give me when A is a sparse > matrix? It seems to yield all nonzero locations, No, it gives you rows, just like a dense 2D array. -- 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 From __peter__ at web.de Tue Mar 9 11:10:26 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Mar 2010 17:10:26 +0100 Subject: related lists mean value (golfed) References: Message-ID: Michael Rudolf wrote: > Am 09.03.2010 13:02, schrieb Peter Otten: >>>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] >> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] >> Peter > > ... pwned. > Should be the fastest and shortest way to do it. It may be short, but it is not particularly efficient. A dict-based approach is probably the fastest. If y is guaranteed to be sorted itertools.groupby() may also be worth a try. $ cat tmp_average_compare.py from __future__ import division from collections import defaultdict try: from itertools import izip as zip except ImportError: pass x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] def f(x=x, y=y): p = defaultdict(int) q = defaultdict(int) for a, b in zip(x, y): p[b] += a q[b] += 1 return [p[b]/q[b] for b in y] def g(x=x, y=y): return [sum(a for a,b in zip(x,y)if b==c)/y.count(c)for c in y] if __name__ == "__main__": print(f()) print(g()) assert f() == g() $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'f()' 100000 loops, best of 3: 11.4 usec per loop $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'g()' 10000 loops, best of 3: 22.8 usec per loop Peter From mehgcap at gmail.com Tue Mar 9 11:18:05 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 9 Mar 2010 11:18:05 -0500 Subject: odd error In-Reply-To: References: Message-ID: I know ctrl-c kills a process in the shell, but these are global hotkeys and all others work fine. You made me discover something, though: the error only happens if ctrl-shift-c is pressed when in the shell from where the program was run; when pressed anywhere else, the keystroke does nothing at all. Is there something I am missing about these keystroke dictionaries? It seems like they do not work unless the keycodes are in numerical order and are not separated by more than one number. Currently, my dictionary consists of the numbers 1-0 on the top of the keyboard, but adding any other keycode, like the 99 in my original message, will cause that keystroke to do absolutely nothing. Thanks to your response, I suspect the problem is something to do with the keypress being captured by the shell. Still, not being able to use anything except numbers is very annoying!! Why would this be happening? On 3/9/10, Ulrich Eckhardt wrote: > Alex Hall wrote: >> Now, though, when I press ctrl-shift-c (keystroke 11), nothing >> happens. > > Control-C sends a special signal to the console, like Control-Break. > >> Pressing any other keystroke after that will crash the program >> with some sort of Python internal com server exception that I >> have never seen before. > > Neither do I, in particular since you don't share that rare gem with us. ;) > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From showell30 at yahoo.com Tue Mar 9 11:29:44 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 08:29:44 -0800 (PST) Subject: related lists mean value References: Message-ID: <253e4e31-21f7-42cc-8276-72afe8702946@q2g2000pre.googlegroups.com> On Mar 8, 2:34?pm, dimitri pater - serpia wrote: > Hi, > > I have two related lists: > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > what I need is a list representing the mean value of 'a', 'b' and 'c' > while maintaining the number of items (len): > w = [1.5, 1.5, 8, 4, 4, 4] > What results are you expecting if you have multiple runs of 'a' in a longer list? From rrpsteps at gmail.com Tue Mar 9 11:33:40 2010 From: rrpsteps at gmail.com (Rikal) Date: Tue, 9 Mar 2010 08:33:40 -0800 (PST) Subject: 1794 - Best, Cheapest Web-Hosting, Domain at $1.99! Message-ID: <6cb49bce-7913-4e60-a458-5650f95ddc03@15g2000yqi.googlegroups.com> World's Cheapest Rate Hosting, 99.9% Uptime US Based Dedicated Server, Fast Customer Service Register Domain only at $1.99 per Year 3 Month Hosting Free with 1 year Package From mail at timgolden.me.uk Tue Mar 9 11:34:03 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Mar 2010 16:34:03 +0000 Subject: odd error In-Reply-To: References: Message-ID: <4B96787B.3030907@timgolden.me.uk> On 09/03/2010 13:55, Alex Hall wrote: > Hi all, > In the same program I wrote about yesterday, I have a dictionary of > keystrokes which are captured. I just tried adding a new one, bringing > the total to 11. Here are entries 10 and 11; 10 has been working fine > for months. > > 10 : (57, win32con.MOD_CONTROL), > 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) > > Now, though, when I press ctrl-shift-c (keystroke 11) Ctrl-C (with or without any other modifier) has a special meaning which overrides any hotkeys. You may be able to do something by adding a break handler through SetConsoleCtrlHandler (exposed in win32api). But it would obviously be a special case outside your normal control flow. TJG From gherron at islandtraining.com Tue Mar 9 11:34:38 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 09 Mar 2010 08:34:38 -0800 Subject: imported var not being updated In-Reply-To: <4B9658C2.1040707@optimum.net> References: <4B9658C2.1040707@optimum.net> Message-ID: <4B96789E.8040402@islandtraining.com> John Posner wrote: > On 3/8/2010 11:55 PM, Gary Herron wrote: > >> >> The form of import you are using >> from helpers import mostRecent >> makes a *new* binding to the value in the module that's doing the >> import. > > > >> What you can do, is not make a separate binding, but reach into the >> helpers module to get the value there. Like this: >> >> import helpers >> print helpers.mostRecent >> > > Gary, are you asserting that in these separate situations: > > one.py: > > from helpers import mostRecent > x = mostRecent > > two.py: > > import helpers > x = helpers.mostRecent > > > ... the name "x" will be bound to different objects? > > Tx, > John Hi John, No they are bound to the same object ... to start with. But if, as the OP indicated, something in the helpers module changes that module's binding of 'mostRecent', then the only helpers.mostRecent in your two.py will notice that change. The variable 'x' in both samples and the 'mostRecent' value in one.py will remain unchanged. That's true for mutable *and* immutable values -- however, mutable values admit a further consideration: Since all 'x's and 'mostRecent's refer to the same value, any mutation is noticed in all cases. But, *any* assignment ( with = or of the form *from helpers import mostRecent* ) breaks the reference to the shared value. Gary Herron -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Mar 9 11:36:32 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Mar 2010 16:36:32 +0000 Subject: odd error In-Reply-To: <4B96787B.3030907@timgolden.me.uk> References: <4B96787B.3030907@timgolden.me.uk> Message-ID: <4B967910.1090108@timgolden.me.uk> On 09/03/2010 16:34, Tim Golden wrote: > On 09/03/2010 13:55, Alex Hall wrote: >> Hi all, >> In the same program I wrote about yesterday, I have a dictionary of >> keystrokes which are captured. I just tried adding a new one, bringing >> the total to 11. Here are entries 10 and 11; 10 has been working fine >> for months. >> >> 10 : (57, win32con.MOD_CONTROL), >> 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) >> >> Now, though, when I press ctrl-shift-c (keystroke 11) > > Ctrl-C (with or without any other modifier) has a special meaning > which overrides any hotkeys. You may be able to do something by > adding a break handler through SetConsoleCtrlHandler (exposed in > win32api). But it would obviously be a special case outside your > normal control flow. ... or you could use SetConsoleMode to disable input processing. But that would only work (I think) in one console, not at a global level. TJG From showell30 at yahoo.com Tue Mar 9 11:38:35 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 08:38:35 -0800 (PST) Subject: related lists mean value References: <4B95B4FF.1070407@optimum.net> <5574554b-1d62-4faf-bb89-34cb431741cd@q2g2000pre.googlegroups.com> Message-ID: <08f0cc42-1d5b-4e45-be51-b68c617bd554@m27g2000prl.googlegroups.com> On Mar 9, 7:21?am, Steve Howell wrote: > > def num_dups_at_head(lst): > ? ? assert len(lst) > 0 > ? ? val = lst[0] > ? ? i = 1 > ? ? while i < len(lst) and lst[i] == val: > ? ? ? ? i += 1 > ? ? return i > > def smooth(x, y): > ? ? result = [] > ? ? while x: > ? ? ? ? cnt = num_dups_at_head(y) > ? ? ? ? avg = sum(x[:cnt]) * 1.0 / cnt > ? ? ? ? result += [avg] * cnt > ? ? ? ? x = x[cnt:] # expensive? > ? ? ? ? y = y[cnt:] # expensive? > ? ? return result > BTW I recognize that my solution would be inefficient for long lists, unless the underlying list implementation had copy-on-write. I'm wondering what the easiest fix would be. I tried a quick shot at islice(), but the lack of len() thwarted me. From theller at ctypes.org Tue Mar 9 11:43:23 2010 From: theller at ctypes.org (Thomas Heller) Date: Tue, 09 Mar 2010 17:43:23 +0100 Subject: libc Sleep api performs a busy waiting In-Reply-To: <27e52ad11003082013h658cf7deu761e7d14198af9f1@mail.gmail.com> References: <27e52ad11003082013h658cf7deu761e7d14198af9f1@mail.gmail.com> Message-ID: Joe Fox schrieb: > Hi, > > actually i have simplified my scenario a lot here , > > In my actual case , i have to call a C-api which blocks on c select , in a > separate thread. > > my thread is getting struck in that api , and thus blocking all the other > threads. > Can you point to something which will help me call this blocking C-api call > without my thread getting struck. > ctypes. Releases the GIL before calling C api functions. From mehgcap at gmail.com Tue Mar 9 11:48:10 2010 From: mehgcap at gmail.com (Alex Hall) Date: Tue, 9 Mar 2010 11:48:10 -0500 Subject: odd error In-Reply-To: <4B96787B.3030907@timgolden.me.uk> References: <4B96787B.3030907@timgolden.me.uk> Message-ID: Okay, I changed the keycode from 99 (c) to 107 (k), and the errors have disappeared. However, now the function that should be called is not. As I said in a previous message, I have always had trouble with this sort of keystroke dictionary. It seems like, if a keycode is out of order or not one more than the number before it, the function to which it is tied will not get called. I am using the message looping mode from Tim Golden's website, and it works beautifully until I try to put an out-of-sequence keycode into the keystrokes dictionary. The dictionary contains numbers 0-9 (48-57) and all is well, but when I put in this 107 code then the function tied to 107 is not called, yet the ones tied to 48-57 still work normally. Why would the sequence matter, or does it not and I am doing something else wrong? Here is a sample of my dictionary: keys.append({ 1 : (48, win32con.MOD_CONTROL), 2 : (49, win32con.MOD_CONTROL), 3 : (50, win32con.MOD_CONTROL), 4 : (51, win32con.MOD_CONTROL), 5 : (52, win32con.MOD_CONTROL), 6 : (53, win32con.MOD_CONTROL), 7 : (54, win32con.MOD_CONTROL), 8 : (55, win32con.MOD_CONTROL), 9 : (56, win32con.MOD_CONTROL), 10 : (57, win32con.MOD_CONTROL), 11 : (107, win32con.MOD_CONTROL | win32con.MOD_SHIFT) #never calls its #function, and note that it is not in the sequence of the other ten }) and here is a list of functions tied to it: funcs.append({ 1 : exitProgram, 2 : arm.sayLoad1, 3 : arm.sayLoad2, 4 : arm.sayLoad3, 5 : arm.sayLoad4, 6 : arm.sayProcAvg, 7 : arm.sayUsedRam, 8 : arm.sayDisk1Info, 9 : arm.sayDisk2Info, 10 : nextMode, 11: clipboard.toClipboard }) If I were to tie clipboard.toClipboard to any of keys 1-10 (0-9, or 48-57) then it would work fine; it is when the 107 shows up that the function is not called, and this is a huge limitation for the rest of the program since I am stuck with just the ten numbers available on the keyboard. Any suggestions would be great! On 3/9/10, Tim Golden wrote: > On 09/03/2010 13:55, Alex Hall wrote: >> Hi all, >> In the same program I wrote about yesterday, I have a dictionary of >> keystrokes which are captured. I just tried adding a new one, bringing >> the total to 11. Here are entries 10 and 11; 10 has been working fine >> for months. >> >> 10 : (57, win32con.MOD_CONTROL), >> 11 : (99, win32con.MOD_CONTROL | win32con.MOD_SHIFT) >> >> Now, though, when I press ctrl-shift-c (keystroke 11) > > Ctrl-C (with or without any other modifier) has a special meaning > which overrides any hotkeys. You may be able to do something by > adding a break handler through SetConsoleCtrlHandler (exposed in > win32api). But it would obviously be a special case outside your > normal control flow. > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From jjposner at optimum.net Tue Mar 9 11:49:37 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 09 Mar 2010 11:49:37 -0500 Subject: imported var not being updated In-Reply-To: <4b965fde$0$14410$426a74cc@news.free.fr> References: <4B9658C2.1040707@optimum.net> <4b965fde$0$14410$426a74cc@news.free.fr> Message-ID: <4b967bfa$0$31260$607ed4bc@cv.net> On 3/9/2010 9:48 AM, Bruno Desthuilliers wrote: > John Posner a ?crit : >> On 3/8/2010 11:55 PM, Gary Herron wrote: >> >>> >>> The form of import you are using >>> from helpers import mostRecent >>> makes a *new* binding to the value in the module that's doing the >>> import. >> >> >> >>> What you can do, is not make a separate binding, but reach into the >>> helpers module to get the value there. Like this: >>> >>> import helpers >>> print helpers.mostRecent >>> >> >> Gary, are you asserting that in these separate situations: >> >> one.py: >> >> from helpers import mostRecent >> x = mostRecent >> >> two.py: >> >> import helpers >> x = helpers.mostRecent >> >> >> ... the name "x" will be bound to different objects? > > Nope. What he's saying is that one.x and two.x are two different names - > each living in it's own namespace - that happen to be bound to the same > object. Now rebiding one.x to a different object will _of course_ have > no impact on the object two.x is bound to. Sure -- my bad, Python 101. In this case, the module *helpers* is the equivalent of a container object, one of whose attributes *mostRecent* gets bound to a series of immutable string objects. > > That's exactly the same as: > > one = dict() > two = dict() > > # one['x'] and two['x'] refer to the same object > one['x'] = two['x'] = ["foo", "bar"] > print one['x'], two['x'], one['x'] is two['x'] > > # mutating one['x'], visible in two['x'] > # (of course since it's the same object) > one['x'].append("baaz") > print one['x'], two['x'], one['x'] is two['x'] > > # now rebind one['x'] > one['x'] = 42 > > # obvious result: one['x'] and two['x'] now refer to 2 different objects > print one['x'], two['x'], one['x'] is two['x'] > > > If in doubt about namespaces, think dicts. Namespaces are like dicts - > and are often nothing else that a plain old dict FWIW. No doubts here, I hope. I even tend to see namespaces where, strictly speaking, they don't exist. As I said at the end of a recent (and flame-ridden) thread [1]: ----------- * A dict is a collection of user-devised names, each of which is assigned to an object. * A list/tuple is an interpreter-maintained collection of integer names (0, 1, 2, ...), each of which is assigned to an object. ----------- So in my world, in mylist[cnt+1], the expression *cnt+1* is equivalent to the integer "name" 4 (if cnt==3, that is), so that mylist[cnt+1] = obj.subobj.attr ... is just a NAME2 = NAME1 kind of assignment statement, binding an additional name to an object that already has a name. Tx, John [1] http://mail.python.org/pipermail/python-list/2010-February/1236318.html From cbmanica at gmail.com Tue Mar 9 11:54:55 2010 From: cbmanica at gmail.com (C. Benson Manica) Date: Tue, 9 Mar 2010 08:54:55 -0800 (PST) Subject: String is ASCII or UTF-8? Message-ID: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Hours of Googling has not helped me resolve a seemingly simple question - Given a string s, how can I tell whether it's ascii (and thus 1 byte per character) or UTF-8 (and two bytes per character)? This is python 2.4.3, so I don't have getsizeof available to me. From alfps at start.no Tue Mar 9 12:02:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Mar 2010 18:02:29 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: * C. Benson Manica: > Hours of Googling has not helped me resolve a seemingly simple > question - Given a string s, how can I tell whether it's ascii (and > thus 1 byte per character) or UTF-8 (and two bytes per character)? > This is python 2.4.3, so I don't have getsizeof available to me. Generally, if you need 100% certainty then you can't tell the encoding from a sequence of byte values. However, if you know that it's EITHER ascii or utf-8 then the presence of any value above 127 (or, for signed byte values, any negative values), tells you that it can't be ascii, hence, must be utf-8. And since utf-8 is an extension of ascii nothing is lost by assuming ascii in the other case. So, problem solved. If the string represents the contents of a file then you may also look for an UTF-8 represention of the Unicode BOM (Byte Order Mark) at the beginning. If found then it indicates utf-8 for almost-sure and more expensive searching can be avoided. It's just three bytes to check. Cheers & hth., - Alf From mail at timgolden.me.uk Tue Mar 9 12:07:44 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Mar 2010 17:07:44 +0000 Subject: String is ASCII or UTF-8? In-Reply-To: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <4B968060.7080606@timgolden.me.uk> On 09/03/2010 16:54, C. Benson Manica wrote: > Hours of Googling has not helped me resolve a seemingly simple > question - Given a string s, how can I tell whether it's ascii (and > thus 1 byte per character) or UTF-8 (and two bytes per character)? > This is python 2.4.3, so I don't have getsizeof available to me. You can't. You can apply one or more heuristics, depending on exactly what your requirement is. But any valid ASCII text is also valid UTF8-encoded text since UTF-8 isn't "two bytes per char" but a variable number of bytes per char. Obviously, you can test whether all the bytes are less than 128 which suggests that the text is legal ASCII. But then it's also legal UTF8. Or you can just attempt to decode and catch the exception: try: unicode (text, "ascii") except UnicodeDecodeError: print "Not ASCII" TJG From stef.mientki at gmail.com Tue Mar 9 12:12:48 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 09 Mar 2010 18:12:48 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <4B968190.6010208@gmail.com> On 09-03-2010 18:02, Alf P. Steinbach wrote: > * C. Benson Manica: >> Hours of Googling has not helped me resolve a seemingly simple >> question - Given a string s, how can I tell whether it's ascii (and >> thus 1 byte per character) or UTF-8 (and two bytes per character)? >> This is python 2.4.3, so I don't have getsizeof available to me. > > Generally, if you need 100% certainty then you can't tell the encoding > from a sequence of byte values. > > However, if you know that it's EITHER ascii or utf-8 then the presence > of any value above 127 (or, for signed byte values, any negative > values), tells you that it can't be ascii, AFAIK it's completely impossible. UTF-8 characters have 1 to 4 bytes / byte. I can create ASCII strings containing byte values between 127 and 255. cheers, Stef > hence, must be utf-8. And since utf-8 is an extension of ascii nothing > is lost by assuming ascii in the other case. So, problem solved. > > If the string represents the contents of a file then you may also look > for an UTF-8 represention of the Unicode BOM (Byte Order Mark) at the > beginning. If found then it indicates utf-8 for almost-sure and more > expensive searching can be avoided. It's just three bytes to check. > > > Cheers & hth., > > - Alf From tjreedy at udel.edu Tue Mar 9 12:13:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Mar 2010 12:13:33 -0500 Subject: scipy sparse matrix question In-Reply-To: <1jf28jr.7abra61nwu04pN%see@sig.for.address> References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> Message-ID: On 3/9/2010 1:14 AM, Victor Eijkhout wrote: > I can't find any detailed information about scipy.sparse. Scipy questions are best asked on the scipy list, which I suspect you can also access via news.gmane.org. > > My specific question: what does "for x in A" give me when A is a sparse > matrix? Try it and see what you get. From MLMDev at Comcast.net Tue Mar 9 12:15:59 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Tue, 9 Mar 2010 12:15:59 -0500 Subject: sys.stdout vs. sys.stderr In-Reply-To: References: Message-ID: On Jan 11, 2010, at 1:47 PM Nobody wrote: > >> On Mon, 11 Jan 2010 10:09:36 +0100, Martin v. Loewis wrote: >> >>> In Python 3.1 is there any difference in the buffering behavior of >>> the >>> initial sys.stdout and sys.stderr streams? >> >> No. >> >>> Were they different at some earlier point in Python's evolution? >> >> That depends on the operating system. These used to be whatever the >> C library set up as stdout and stderr. Typically, they were buffered >> in the same way. > > On Unix, stdout will be line buffered if it is associated with a tty > and fully buffered otherwise, while stderr is always unbuffered. > > On Windows, stdout and stderr are unbuffered if they refer to a > character > device, fully buffered otherwise (Windows doesn't have line buffering; > setvbuf(_IOLBF) is equivalent to setvbuf(_IOFBF)). > > ANSI C says: > > As initially opened, the standard error stream is not fully > buffered; the > standard input and standard output streams are fully buffered if and > only > if the stream can be determined not to refer to an interactive > device. > I don't want to get into a quibble fight here, but I need to reraise this issue. [I teach and write and want to make sure I get this right. I already have an incorrect paragraph about this in my Bioinformatics Programming Using Python book.] The key question here is line buffering vs full buffering. In Unix (at least in an OS X Terminal), the following code prints a number every two seconds in Python 2: >>> for n in range(5): . . . print >> sys.stderr, n, # final , to not send newline . . . time.sleep(2) However, in Python 3, similar code does not print the numbers until the whole thing finishes (again, running from the terminal). >>> for n in range(5): . . . print(n, file=sys.stderr, end='') . . . time.sleep(2) So it appears that in a Unix terminal window, Python 2 does not line- buffer stderr whereas Python 3 does. That's what tripped me up. While developing and debugging code, I often print periods on a line as some loop progresses (sometimes every Nth time around, for some reasonable N) just to know the pace of execution and that the program is still doing something. In doing that recently in Python 3 I discovered that I either had to leave out the end='' or do sys.stderr.flush() after every print, which amounts to the same thing. This was a big surprise, after many, many years of C, C++, Java, and Python programming -- I have always thought of stderr as completely unbuffered in languages that have it. Doesn't mean some languages line- buffer stderr on some platforms, just pointing out an assumption I've lived with for a very long time that tripped me up writing a note about using stderr in Python 3 without actually demonstrating the code and therefore not catching my error. -------------- next part -------------- An HTML attachment was scrubbed... URL: From cbmanica at gmail.com Tue Mar 9 12:17:58 2010 From: cbmanica at gmail.com (C. Benson Manica) Date: Tue, 9 Mar 2010 09:17:58 -0800 (PST) Subject: String is ASCII or UTF-8? References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> On Mar 9, 12:07?pm, Tim Golden wrote: > You can't. You can apply one or more heuristics, depending on exactly > what your requirement is. But any valid ASCII text is also valid > UTF8-encoded text since UTF-8 isn't "two bytes per char" but a variable > number of bytes per char. Hm, well that's very unfortunate. I'm using a database library which seems to assume that all strings passed to it are ASCII, and I'm attempting to use it on two different systems - one where all strings are ASCII, and one where they seem to be UTF-8. The strings come from the same place, i.e. they're exclusively normal ASCII characters. What I would want is to check once for whether the strings passed to function foo() are ASCII or UTF-8, and if they are to assume that all strings need to be decoded. So that's not possible? From R.Brodie at rl.ac.uk Tue Mar 9 12:24:49 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Tue, 9 Mar 2010 17:24:49 -0000 Subject: String is ASCII or UTF-8? References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> Message-ID: "C. Benson Manica" wrote in message news:98375575-1071-46af-8ebc-f3c817b47e1d at q23g2000yqd.googlegroups.com... >The strings come from the same place, i.e. they're exclusively > normal ASCII characters. In this case then converting them to/from UTF-8 is a no-op, so it makes no difference at all. From cbmanica at gmail.com Tue Mar 9 12:31:59 2010 From: cbmanica at gmail.com (C. Benson Manica) Date: Tue, 9 Mar 2010 09:31:59 -0800 (PST) Subject: String is ASCII or UTF-8? References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> Message-ID: <1c9b34ab-d949-4d2d-afbd-9a1c41462f0a@g4g2000yqa.googlegroups.com> On Mar 9, 12:24?pm, "Richard Brodie" wrote: > "C. Benson Manica" wrote in messagenews:98375575-1071-46af-8ebc-f3c817b47e1d at q23g2000yqd.googlegroups.com... > > >The strings come from the same place, i.e. they're exclusively > > normal ASCII characters. > > In this case then converting them to/from UTF-8 is a no-op, so > it makes no difference at all. Except to the database library, which seems perfectly happy to send an 8-character UTF-8 string to the database as 16 raw characters... From robert.kern at gmail.com Tue Mar 9 12:36:48 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Mar 2010 11:36:48 -0600 Subject: String is ASCII or UTF-8? In-Reply-To: <4B968190.6010208@gmail.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <4B968190.6010208@gmail.com> Message-ID: On 2010-03-09 11:12 AM, Stef Mientki wrote: > On 09-03-2010 18:02, Alf P. Steinbach wrote: >> * C. Benson Manica: >>> Hours of Googling has not helped me resolve a seemingly simple >>> question - Given a string s, how can I tell whether it's ascii (and >>> thus 1 byte per character) or UTF-8 (and two bytes per character)? >>> This is python 2.4.3, so I don't have getsizeof available to me. >> >> Generally, if you need 100% certainty then you can't tell the encoding >> from a sequence of byte values. >> >> However, if you know that it's EITHER ascii or utf-8 then the presence >> of any value above 127 (or, for signed byte values, any negative >> values), tells you that it can't be ascii, > AFAIK it's completely impossible. > UTF-8 characters have 1 to 4 bytes / byte. > I can create ASCII strings containing byte values between 127 and 255. No, you can't. ASCII strings only have characters in the range 0..127. You could create Latin-1 (or any number of the 8-bit encodings out there) strings with characters 0..255, yes, but not ASCII. -- 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 From askedrelic at gmail.com Tue Mar 9 12:37:12 2010 From: askedrelic at gmail.com (Matthew Behrens) Date: Tue, 9 Mar 2010 12:37:12 -0500 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: References: Message-ID: <75d625cc1003090937t24c2dbe7u9a61e5a9a2107d19@mail.gmail.com> > I like this tools, I'm wonder if there are similar tools in Python ? Blogofile is a static file blog engine/compiler, inspired by Jekyll. http://blogofile.com/ http://github.com/EnigmaCurry/blogofile From tjreedy at udel.edu Tue Mar 9 12:59:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Mar 2010 12:59:16 -0500 Subject: String is ASCII or UTF-8? In-Reply-To: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: On 3/9/2010 11:54 AM, C. Benson Manica wrote: > Hours of Googling has not helped me resolve a seemingly simple > question - Given a string s, how can I tell whether it's ascii (and > thus 1 byte per character) or UTF-8 (and two bytes per character)? Utf-8 is an encoding that uses 1 to 4 bytes per character. So it is not clear what you are asking. Alf answered one of the possible questions. > This is python 2.4.3, so I don't have getsizeof available to me. From rschroev_nospam_ml at fastmail.fm Tue Mar 9 13:13:07 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 09 Mar 2010 19:13:07 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: <1c9b34ab-d949-4d2d-afbd-9a1c41462f0a@g4g2000yqa.googlegroups.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <98375575-1071-46af-8ebc-f3c817b47e1d@q23g2000yqd.googlegroups.com> <1c9b34ab-d949-4d2d-afbd-9a1c41462f0a@g4g2000yqa.googlegroups.com> Message-ID: Op 2010-03-09 18:31, C. Benson Manica schreef: > On Mar 9, 12:24 pm, "Richard Brodie" wrote: >> "C. Benson Manica" wrote in messagenews:98375575-1071-46af-8ebc-f3c817b47e1d at q23g2000yqd.googlegroups.com... >> >>> The strings come from the same place, i.e. they're exclusively >>> normal ASCII characters. >> >> In this case then converting them to/from UTF-8 is a no-op, so >> it makes no difference at all. > > Except to the database library, which seems perfectly happy to send an > 8-character UTF-8 string to the database as 16 raw characters... In that case I think you mean UTF-16 or UCS-2 instead of UTF-8. UTF-16 uses 2 or more bytes per character, UCS-2 always uses 2 bytes per character. UTF-8 uses 1 or more bytes per character. If your texts are in a Western language, the second byte will be zero in most characters; you could check for that (but note that the second byte might be the first one in the byte stream, depending on the byte ordering). HTH, Roel -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From pruebauno at latinmail.com Tue Mar 9 13:24:27 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 9 Mar 2010 10:24:27 -0800 (PST) Subject: related lists mean value (golfed) References: Message-ID: <62af4b09-77f6-47ab-bce0-2cfcbafecfed@c16g2000yqd.googlegroups.com> Peter Otten wrote: > Michael Rudolf wrote: > > > Am 09.03.2010 13:02, schrieb Peter Otten: > >>>>> [sum(a for a,b in zip(x,y) if b==c)/y.count(c)for c in y] > >> [1.5, 1.5, 8.0, 4.0, 4.0, 4.0] > >> Peter > > > > ... pwned. > > Should be the fastest and shortest way to do it. > > It may be short, but it is not particularly efficient. A dict-based approach > is probably the fastest. If y is guaranteed to be sorted itertools.groupby() > may also be worth a try. > > $ cat tmp_average_compare.py > from __future__ import division > from collections import defaultdict > try: > from itertools import izip as zip > except ImportError: > pass > > x = [1 ,2, 8, 5, 0, 7] > y = ['a', 'a', 'b', 'c', 'c', 'c' ] > > def f(x=x, y=y): > p = defaultdict(int) > q = defaultdict(int) > for a, b in zip(x, y): > p[b] += a > q[b] += 1 > return [p[b]/q[b] for b in y] > > def g(x=x, y=y): > return [sum(a for a,b in zip(x,y)if b==c)/y.count(c)for c in y] > > if __name__ == "__main__": > print(f()) > print(g()) > assert f() == g() > $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'f()' > 100000 loops, best of 3: 11.4 usec per loop > $ python3 -m timeit -s 'from tmp_average_compare import f, g' 'g()' > 10000 loops, best of 3: 22.8 usec per loop > > Peter I converged to the same solution but had an extra reduction step in case there were a lot of repeats in the input. I think it is a good compromise between efficiency, readability and succinctness. x = [1 ,2, 8, 5, 0, 7] y = ['a', 'a', 'b', 'c', 'c', 'c' ] from collections import defaultdict totdct = defaultdict(int) cntdct = defaultdict(int) for name, num in zip(y,x): totdct[name] += num cntdct[name] += 1 avgdct = {name : totdct[name]/cnts for name, cnts in cntdct.items()} w = [avgdct[name] for name in y] From stefan_ml at behnel.de Tue Mar 9 14:19:44 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Mar 2010 20:19:44 +0100 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: References: Message-ID: KLEIN St?phane, 09.03.2010 09:30: > Today, I've show this static web site generating tools writed in ruby : > > * http://webgen.rubyforge.org/index.html > * http://nanoc.stoneship.org/about/ > * http://webby.rubyforge.org/tutorial/ > > I like this tools, I'm wonder if there are similar tools in Python ? Here's a still incomplete but not so short list of web frameworks in Python: http://wiki.python.org/moin/WebFrameworks You might be interested in the templating frameworks if all you want is generate static pages. Stefan From tavares at fe.up.pt Tue Mar 9 14:25:57 2010 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Tue, 9 Mar 2010 11:25:57 -0800 (PST) Subject: ICNAAM 2010 Mini-Symposium on Computational Bioimaging and Visualization Message-ID: Dear Colleague, Within the ICNAAM 2010 - 8th International Conference of Numerical Analysis and Applied Mathematics (http://www.icnaam.org), to be held in Rhodes, Greece, on 19-25 September 2010, we are organizing the Mini- Symposium on ?Computational Bioimaging and Visualization?. Due to your research activities in the related fields, we would like to invite you to submit an invited extended abstract to our mini- symposium. Your contribution is mostly welcomed, and we would be honoured if you could accept this invitation. TOPICS OF INTEREST (not restricted to): - Image Processing and Analysis for Computational Bioimaging and Visualization; - Biomedical Signal and Image Acquisition and Processing; - Data Processing, Modeling and Analysis; - Scientific Visualization; - Enhanced Visualization; - Human Computer Interaction; - Simulation and Animation; - Virtual Reality; - Computer Aided Diagnosis, Surgery, Therapy, Treatment and Telemedicine Systems; - Software Development for Computational Bioimaging and Visualization; - Grid Computing in Computational Bioimaging and Visualization; - Applications of Computational Bioimaging and Visualization. IMPORTANT DATES: Deadline for Submission of Extended Abstract: July 22, 2010; Notification of acceptance: July 29, 2010; Deadline for Submission of the source files of the camera ready extended abstracts to American Institute of Physics (AIP Conference Proceedings): August 1, 2010. SUBMISSION INSTRUCTIONS: Extended abstracts will be published in a Special Volume of the AIP Conference Proceedings. Please, see the Instructions for Authors at: http://www.icnaam.org/abstract.htm, and select the Mini-Symposium on ?Computational Bioimaging and Visualization? when submitting your contribution. With kind regards, Jo?o Manuel R. S. Tavares, University of Porto, Portugal, tavares at fe.up.pt Renato Natal Jorge, University of Porto, Portugal, rnatal at fe.up.pt (Organizers of the Mini-Symposium on ?Computational Bioimaging and Visualization?) From tarekamr at gmail.com Tue Mar 9 15:31:15 2010 From: tarekamr at gmail.com (tarekamr at gmail.com) Date: Tue, 9 Mar 2010 12:31:15 -0800 (PST) Subject: Pyrhon2.5 to 2.4 conversion References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <8676dc2a-2246-4fcb-8736-e6effeddbcad@b7g2000yqd.googlegroups.com> Thanks a lot everybody for your help, it worked now :) On Feb 28, 4:12?am, MRAB wrote: > tarek... at gmail.com wrote: > > Hi, > > > I am currently using oauth2.py library, and it works fine on one of my > > PC's (python2.5), but later on when I tried to use it with python2.4 > > the following line (line 332 inhttp://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > > showed a syntax error > > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > > sorted(self.items()) if k != 'oauth_signature'] > > > So it there a way to convert this line to a python2.4 compliant > > syntax. > > I think the clearest is: > > items = [] > for k, v in sorted(self.items()): > ? ? ?if k != 'oauth_signature': > ? ? ? ? ?if type(v) == ListType: > ? ? ? ? ? ? ?v = sorted(v) > ? ? ? ? ?items.append((k, v)) From martin at v.loewis.de Tue Mar 9 15:44:54 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 09 Mar 2010 21:44:54 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> Message-ID: <4B96B346.2050700@v.loewis.de> > I can create ASCII strings containing byte values between 127 and 255. No, you can't - or what you create wouldn't be an ASCII string, by definition of ASCII. Regards, Martin From see at sig.for.address Tue Mar 9 15:52:03 2010 From: see at sig.for.address (Victor Eijkhout) Date: Tue, 9 Mar 2010 14:52:03 -0600 Subject: scipy sparse matrix question References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> Message-ID: <1jf3d8v.crydq1be5um2N%see@sig.for.address> Terry Reedy wrote: > > My specific question: what does "for x in A" give me when A is a sparse > > matrix? > > Try it and see what you get. Ah, how do I see what I get? If I print it it looks plausible, but I don't know how to pull it apart. It doesn't seem to be an array. Victor. -- Victor Eijkhout -- eijkhout at tacc utexas edu From gagsl-py2 at yahoo.com.ar Tue Mar 9 15:56:24 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Mar 2010 17:56:24 -0300 Subject: How to detect C Function block using python References: <769249.71022.qm@web62401.mail.re1.yahoo.com> Message-ID: En Tue, 09 Mar 2010 04:51:57 -0300, Faheem escribi?: > I'm new in this community. I am writing a static analyzer for validating > C Code using python and for that I'm looking for a python module/API > that will detect Function block of a given C-File. I know simple > function can be detected using push "{" and poping it if character "}" > is found. This solution is actually done already, I want a robust API > that can do more then that like detecting Function name parameters its > return types etc. Take a look at ctypeslib [1]; it uses gccxml [2] to parse .h header files and generate equivalent Python declarations. [1] http://svn.python.org/view/ctypes/trunk/ctypeslib/ [2] http://www.gccxml.org/ -- Gabriel Genellina From robert.kern at gmail.com Tue Mar 9 16:13:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Mar 2010 15:13:23 -0600 Subject: scipy sparse matrix question In-Reply-To: <1jf3d8v.crydq1be5um2N%see@sig.for.address> References: <1jf28jr.7abra61nwu04pN%see@sig.for.address> <1jf3d8v.crydq1be5um2N%see@sig.for.address> Message-ID: On 2010-03-09 14:52 PM, Victor Eijkhout wrote: > Terry Reedy wrote: > >>> My specific question: what does "for x in A" give me when A is a sparse >>> matrix? >> >> Try it and see what you get. > > Ah, how do I see what I get? If I print it it looks plausible, but I > don't know how to pull it apart. It doesn't seem to be an array. In [5]: I = sparse.csr_matrix(np.eye(4)) In [6]: list(I) Out[6]: [<1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>, <1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>, <1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>, <1x4 sparse matrix of type '' with 1 stored elements in Compressed Sparse Row format>] What is unclear about that? They are obviously 1x4 sparse matrices, i.e. the rows of the matrix. Use the .indices and .data attributes to get the indices of the nonzero values and the corresponding values. Details may differ depending on the format of sparse matrix. Some aren't even iterable. -- 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 From anfedorov at gmail.com Tue Mar 9 16:26:52 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Tue, 9 Mar 2010 16:26:52 -0500 Subject: Down casting Python objects Message-ID: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to "down cast" x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect things to work OK in all major versions of CPython? -------------- next part -------------- An HTML attachment was scrubbed... URL: From art at hens-teeth.net Tue Mar 9 16:28:54 2010 From: art at hens-teeth.net (Art Zemon) Date: Tue, 09 Mar 2010 15:28:54 -0600 Subject: CSV DictReader loops when used with MySQLdb Message-ID: <4B96BD96.5010605@hens-teeth.net> I'm going crazy. Using python 2.5.2 on 64 bit Linux. I have a class which reads CSV files using the CSV DictReader. If I print the rows, everything works perfectly. If I insert the rows into a MySQL table using MySQLdb, the DictReader loops back and begins re-reading from the beginning of the file when it reaches EOF. Here's the code: class CsvLoader: """load data from a CSV file into a corresponding MySQL table""" def __init__(self, fname, schema, db, useCleanReader = False): self.schema = schema self.db = db if useCleanReader: self.reader = csv.DictReader(CleanReader(fname), delimiter=',', quotechar='"') else: self.reader = csv.DictReader(open(fname), delimiter=',', quotechar='"') def loadMysql(self): for row in self.reader: self.db.insertGeneric(self.schema.tableName(), row) def printRows(self): for row in self.reader: print "\n", row and here is the insertGeneric method: def insertGeneric(self, table, record): """execute a generic INSERT, given a dict as input""" fieldList = [] valueList = [] for k in record.keys(): fieldList.append(k) valueList.append(record[k]) fields = ", ".join(fieldList) m = ['%s'] valueMarkers = ", ".join(m * len(valueList)) # create a string like: %s, %s, %s... sql = 'insert into %s (%s) values (%s)' % (table, fields, valueMarkers) cursor = self.conn.cursor() print "+++ insert: %s <= %s" % (sql, valueList) cursor.execute(sql, valueList) cursor.close() useCleanReader is False CsvLoader.printRows() works fine. CsvLoader.loadMySql() keeps looping through the CSV file. Ideas? -- Art Z. -- Art Zemon, President Hen's Teeth Network Phone: (866)HENS-NET or (636)447-3030 ext. 200 Twitter: AZemon -------------- next part -------------- An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Tue Mar 9 16:36:08 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 09 Mar 2010 22:36:08 +0100 Subject: String is ASCII or UTF-8? In-Reply-To: References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <4B968190.6010208@gmail.com> Message-ID: <4B96BF48.7080201@gmail.com> On 09-03-2010 18:36, Robert Kern wrote: > On 2010-03-09 11:12 AM, Stef Mientki wrote: >> On 09-03-2010 18:02, Alf P. Steinbach wrote: >>> * C. Benson Manica: >>>> Hours of Googling has not helped me resolve a seemingly simple >>>> question - Given a string s, how can I tell whether it's ascii (and >>>> thus 1 byte per character) or UTF-8 (and two bytes per character)? >>>> This is python 2.4.3, so I don't have getsizeof available to me. >>> >>> Generally, if you need 100% certainty then you can't tell the encoding >>> from a sequence of byte values. >>> >>> However, if you know that it's EITHER ascii or utf-8 then the presence >>> of any value above 127 (or, for signed byte values, any negative >>> values), tells you that it can't be ascii, >> AFAIK it's completely impossible. >> UTF-8 characters have 1 to 4 bytes / byte. >> I can create ASCII strings containing byte values between 127 and 255. > > No, you can't. ASCII strings only have characters in the range 0..127. > You could create Latin-1 (or any number of the 8-bit encodings out > there) strings with characters 0..255, yes, but not ASCII. > Probably, and according to wikipedia you're right. I think I've to get rid of my old books, Borland turbo Pascal 4 (1987) has an ASCII table of 256 characters, while the small letters say 7-bit ;-) cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From bringa at gmail.com Tue Mar 9 16:41:10 2010 From: bringa at gmail.com (Daniel Klein) Date: Tue, 9 Mar 2010 13:41:10 -0800 (PST) Subject: Named loops for breaking Message-ID: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Hey, I did a little searching and couldn't really find much recent on this. The only thing I found was this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a696624c92b91181/5b7479fdc3362b83?lnk=gst&q=break+named+loop#5b7479fdc3362b83 Basically I'm wondering if there are any plans to implemented named loops in Python, so I can tell a break command to break out of a specific loop in the case of nested loops. Currently I'm using boolean flag variables, but I find that very clumsy. I know this idea of breaking out of specific loops from javascript; I guess java does it too. It just seems a very Pythonian idea to me: clear, promotes code legibility, seems obvious. From shengcer at gmail.com Tue Mar 9 16:48:42 2010 From: shengcer at gmail.com (Shane) Date: Tue, 9 Mar 2010 13:48:42 -0800 (PST) Subject: How to dynamic insert more conditional statements into a function Message-ID: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> Hi I am a newbie for Python Here is a question, say I have a list L, function foo is: def foo(L): if L[0] > 0: return True if later I want another function goo which returns "True" when L[0] and L[1] are both > 0, i.e., def goo(L): if L[0] > 0 and L[1] > 0: return True Can anybody tell me how can I write the function "goo" based upon the function "foo"? Thanks! I know if it is implementable, I should use "decorator". But I just cannot figure out how. From no.email at nospam.invalid Tue Mar 9 16:58:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 09 Mar 2010 13:58:01 -0800 Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <7xocixximu.fsf@ruckus.brouhaha.com> Daniel Klein writes: > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. Currently I'm using boolean > flag variables, but I find that very clumsy. The usual way to do this in Python is with an exception, perhaps a specially named one if that makes your code clearer: class Whatever(Exception): pass ... try: for x in thingie: for y in x.whatsis(): if lose(y): raise Whatever ... except Whatever: pass This situation doesn't come up all that often and you should probably ask yourself if you really need those nested loops. You might also be able to put the nested loop structure into a function that you can then exit with a return statement. From ccurvey at gmail.com Tue Mar 9 17:05:15 2010 From: ccurvey at gmail.com (Chris Curvey) Date: Tue, 9 Mar 2010 14:05:15 -0800 (PST) Subject: find text location (in pixels) using python (pyPdf) Message-ID: Has anyone ever tried to find the pixel (or point) location of text in a PDF using Python? I've been using the pyPdf libraries for other things, and it seems to me that if I can find the bounding box for text, I should be able to calculate the location. What I want to do is take a PDF of one of our vendor invoices and blur everything in it except the block that's related to a single customer. So if I have an invoice that looks like: Alfred Annoying 123 Elm St Somewhere, NJ $100 Barbie Bonehead 456 Pine St Elsewhere, NJ $125 Charlie Clueless 789 Beech St. Everywhere, NJ $150 I want to show Barbie just her section of the invoice (with the header intact, so that she can tell it's a real invoice) but with Alfred and Charlie's information blurred out. I was going to convert the PDF to a JPG or PNG and do the blurring with ImageMagick/PythonMagick. But that requires me to know the pixel location of the regions that I want blurred and left alone. I'm also open to other ideas if I'm going about this the hard way.... From donal.k.fellows at man.ac.uk Tue Mar 9 17:06:39 2010 From: donal.k.fellows at man.ac.uk (Donal K. Fellows) Date: Tue, 9 Mar 2010 14:06:39 -0800 (PST) Subject: Updates about Tk References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> <6adc$4b895233$4275d90a$6509@FUSE.NET> Message-ID: <6aa37d52-13a0-4c1b-9304-d301ed8f8c63@q23g2000yqd.googlegroups.com> On Feb 27, 5:29?pm, rantingrick wrote: > Great post Kevin! The only thing i would like to add are my two > favorite references for learning Tkinter. They are not geared around > the new ttk stuff, but still 95% relevant to any Tkinter-ing > > http://effbot.org/tkinterbook/ > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ You might also want to check out: http://www.tkdocs.com/ Which covers the ttk widgets too (and, for multi-language people, it also handles how to do it from four languages). Donal. From emile at fenx.com Tue Mar 9 17:15:18 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Mar 2010 14:15:18 -0800 Subject: String is ASCII or UTF-8? In-Reply-To: <4B96BF48.7080201@gmail.com> References: <25591dae-3b98-4039-b022-ad549785dd65@g4g2000yqa.googlegroups.com> <4B968190.6010208@gmail.com> <4B96BF48.7080201@gmail.com> Message-ID: On 3/9/2010 1:36 PM Stef Mientki said... > On 09-03-2010 18:36, Robert Kern wrote: >> No, you can't. ASCII strings only have characters in the range 0..127. >> You could create Latin-1 (or any number of the 8-bit encodings out >> there) strings with characters 0..255, yes, but not ASCII. >> > Probably, and according to wikipedia you're right. I too looked at wikipedia, and it seems historically incomplete to me. In particular, I looked for 'high order ascii', which, when I was working with Basic Four in the '70's, is what they used. Essentially, the high order bit was set for all characters to make 8A a line feed, etc. Still the same 0..127 characters, but not really an extended ascii which is where wikipedia forwards you to. I remember having to strap the eighth bit high when I reused the older line printers to get them to work. Emile From emile at fenx.com Tue Mar 9 17:21:37 2010 From: emile at fenx.com (Emile van Sebille) Date: Tue, 09 Mar 2010 14:21:37 -0800 Subject: How to dynamic insert more conditional statements into a function In-Reply-To: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> References: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> Message-ID: On 3/9/2010 1:48 PM Shane said... > Hi I am a newbie for Python > > Here is a question, say I have a list L, > > function foo is: > > def foo(L): > if L[0]> 0: return True > > if later I want another function goo which returns "True" when L[0] > and L[1] are both> 0, i.e., > > def goo(L): > if L[0]> 0 and L[1]> 0: return True Here's one way... def foo(L,deep=0): return L[0] and not deep or foo(L[1:],deep-1) Subject to clean up. Emile From gramos at yahoo.com Tue Mar 9 17:53:50 2010 From: gramos at yahoo.com (brown wrap) Date: Tue, 9 Mar 2010 14:53:50 -0800 (PST) Subject: Can't build hashlib In-Reply-To: Message-ID: <865538.86264.qm@web111703.mail.gq1.yahoo.com> The md5 module is used in build xulrunner and Firefox from source. When I do run the install its says md5 no such module. I compiled Python 2.6.4 after installing openssl and BerkleyDB, yet I get this error when compilying Python: Failed to find the necessary bits to build these modules: _tkinter bsddb185 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: _hashlib _ssl From sluggoster at gmail.com Tue Mar 9 18:18:11 2010 From: sluggoster at gmail.com (Mike Orr) Date: Tue, 9 Mar 2010 15:18:11 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <8fc356e0-f3ed-4a67-9b37-f21561cef4a5@p13g2000pre.googlegroups.com> Message-ID: <73dcf2e2-a391-4c7a-9ded-b1ab156ad59f@u19g2000prh.googlegroups.com> I just saw this thread on the Python-URL. On Feb 14, 12:39?pm, a... at pythoncraft.com (Aahz) wrote: > >> Sean DiZazzo =A0 wrote: > > >>>Why did Path() get rejected? Is it the idea itself, or just the > >>>approach that was used? What are the complaints? > > >> You should search for the discussiona around it. > > >I read the discussion, and there was definitely some going back and > >forth on whether it should be sub-classed from string, but the > >conversation just seemed to stop abruptly with no decision one way of > >the other. ?Maybe I missed a thread. It has a habit of being discussed and dropped repeatedly. The main issue is that Guido doesn't see an OO approach as necessarily better than the existing functions, so it has a high bar for acceptance. One issue is that some people see a need to separate filesystem- independent functionality (joining paths and extracting components) from filesystem-dependent functionality (listing directories, removing files, etc). ``path.py`` and PEP 355 were rejected mainly because of this. There was support for a small filesystem-independent class that could be put into the stdlib, and some modest moving/renaming of the filesystem functions (which are scattered across os, os.path, shutil, glob, etc). We were hoping to get this done for Python 3 but didn't make it. I wrote a ``Unipath`` package that tried to be a compromise between what everybody wanted, with a FS-independent class and a FS- dependent subclass, but could not get any feedback on it. Somebody else was going to write a PEP for the renamings, but I never saw it. Since then, path.py has been included in a couple packages and seems to have the most widespread use. I gave up on the stdlib and reconfigured Unipath as a pure 3rd-party library. (The FS-independent AbstractPath class is still there if anybody wants to use it for a PEP.) The other people who made their own implementations seemed to be happy with theirs, and that was that. The string vs non-string argument has pretty much been decided in favor of strings (i.e., a string subclass). Not ``"a.txt".open()`` but ``open(Path("a.txt"))``. Too many standard and 3rd-party modules expect string paths: you'd have to convert your path to a string every time you pass it as an argument. The main problem with string paths is that .join() means something else, but that's usually solved by using a different method name: "joinpath", "child", "/", etc. Other proposals have been a tuple subclass, so that ``Path("a/b/c.txt") [-1] == Path("c.txt")``, and a library that can do non-native paths (Windows style on Unix systems and vice-versa). These don't seem to be in vogue anymore. What has become more common is virtual paths; i.e., the same interface for filesystems, FTP, zip files, etc. That was discussed during the last go-around but there were no implementations. Now there are a few projects active on this, such as http://groups.google.com/group/stdpyfs . This is probably the future of any path object, so it would make sense to define a path now that can work with all these backends. --Mike From jcb at iteris.com Tue Mar 9 18:56:47 2010 From: jcb at iteris.com (Metalone) Date: Tue, 9 Mar 2010 15:56:47 -0800 (PST) Subject: file seek is slow Message-ID: I ran a comparison that timed 1e6 file seeks. The tests were run with Python 2.6.4 and Microsoft Visual C 6.0 on Windows XP with an Intel 3GHz single processor with hyperthreading. Results: C : 0.812 seconds Python: 1.458 seconds. difference = 0.646 seconds. If the file.seek is removed the Python loop takes 2ms so the loop overhead is minimal. Without pysco the loop overhead is 4.6ms and Python takes 1.866. Any ideas what is causing the slow down over the 'C' version. In general I have been trying to take a video application written in C+ + and make it work in Python. There seem to be delays in the handoff to Windows System code that make the Python version just a touch slower in some areas, but these slowdowns are critically effecting the work. File seek is not a deal breaker here, it is just the latest thing I have noticed and the simplest to demonstrate. Python version: import time def main(): # write temp file SIZE = 1000 f1 = file('video.txt', 'wb') f1.write('+' * SIZE) f1.close() f1 = file('video.txt', 'rb') t0 = time.clock() for i in xrange(1000000): f1.seek(0) delta = time.clock() - t0 print "%.3f" % delta f1.close() if __name__ == '__main__': import psyco psyco.full() main() // 'C' version #include #include #define SIZE 1000 static void main(int argc, char *argv[]) { FILE *f1; int i; int t0; float delta; char buffer[SIZE]; // write temp file memset(buffer, (int)'+', SIZE); f1 = fopen("video.txt", "wb"); fwrite(buffer, SIZE, 1, f1); fclose(f1); f1 = fopen("video.txt", "rb"); t0 = clock(); for (i=0; i < 1000000; i++) { fseek(f1, 0, SEEK_SET); } delta = (float)(clock() - t0) / CLOCKS_PER_SEC; printf("%.3f\n", delta); fclose(f1); } From martin.hellwig at dcuktec.org Tue Mar 9 18:58:01 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 09 Mar 2010 23:58:01 +0000 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: On 02/09/10 14:00, Phlip wrote: > Ah, now we get down to the root of the problem. Because Python is so > stuck on the "one best way to do it" mentality, language bigotry > prevented the Committee from picking from among several equally valid > but non-best options. And after 20 years of growth, Python still has > no Pathname class. What a mature community! C-: > Well even if this statement would be true, I personally think that not proclaiming something a 'standard' if you are sure that you are not sure about it, is a virtue. -- mph From ptmcg at austin.rr.com Tue Mar 9 19:11:35 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 9 Mar 2010 16:11:35 -0800 (PST) Subject: file seek is slow References: Message-ID: This is a pretty tight loop: for i in xrange(1000000): f1.seek(0) But there is still a lot going on, some of which you can lift out of the loop. The easiest I can think of is the lookup of the 'seek' attribute on the f1 object. Try this: f1_seek = f1.seek for i in xrange(1000000): f1_seek(0) How does that help your timing? -- Paul From greg.ewing at canterbury.ac.nz Tue Mar 9 19:17:48 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 10 Mar 2010 13:17:48 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: <7vo661F7s7U1@mid.individual.net> Dave Angel wrote: > If you assume it's done in a single pass, and you know which byte is the > end of the buffer, I'd think you could learn a lot by just tweaking that > last byte. I'm sure I would, but unfortunately I can't control the last byte. The bytes that I can influence are some distance back from the end of the data. -- Greg From robin.rytich at gmail.com Tue Mar 9 20:57:47 2010 From: robin.rytich at gmail.com (Robin Rytich) Date: Wed, 10 Mar 2010 04:57:47 +0300 Subject: Knight's tour Warndorff's algorithm problem Message-ID: <1268186267.11433.47.camel@rytich-laptop> Hi all I'm having some troubles with writing Knight's tour (http://en.wikipedia.org/wiki/Knight%27s_tour) solution in Python 3. I'm using Warnsdorff's algorithm (http://en.wikipedia.org/wiki/Knight% 27s_tour#Algorithm) and I'm wondering why it doesn't work with boards of certain sizes. I've written a solution and I like it but it does not work correctly for 15x15, 26x26, 27x27 and 32x32 boards (don't know why; checked from 5x5 to 40x40). So I'd be really glad if you tell me whether I am too stupid for Python or for Discrete Math? In other words, did I implemented Warnsdorff's algorithm in Python 3 correctly or maybe all my troubles are because I haven't read tutorial with enough patience? P.S. Warnsdorff's algorithm says that it's not really important which square to choose between those which have equal amount of ways out. In spite of that I tried to changed my program and added '=' to condition at line 78. Results were quite surprising: now it works for 5x5, 6x6, ... 34x34 but not for 35x35! -------------- next part -------------- A non-text attachment was scrubbed... Name: knights_tour.py Type: text/x-python Size: 3210 bytes Desc: not available URL: From wuwei23 at gmail.com Tue Mar 9 21:10:20 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Mar 2010 18:10:20 -0800 (PST) Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <41d99d1f-7499-4c3e-8c25-8d58a6c16bd3@c37g2000prb.googlegroups.com> Daniel Klein wrote: > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. You should be able to do this with the goto module: http://entrian.com/goto/ But please note that I'm not seriously advocating its use :) From dr.cg at 126.com Tue Mar 9 22:36:10 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 10 Mar 2010 11:36:10 +0800 (CST) Subject: Six Minutes and fourty two seconds Message-ID: <5fa8d25e.47df.1274624d257.Coremail.dr.cg@126.com> >Tobiah wrote: >> Now that I use python, this is the amount of time >> per day that I spend adding forgotten semicolons while >> debugging other languages. >> >What compels you to write Python code without semicolons? >Frederic Try the C language without semicolons and braces http://pythoidc.googlecode.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Mar 9 23:01:01 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 9 Mar 2010 20:01:01 -0800 (PST) Subject: odd error References: <4B96787B.3030907@timgolden.me.uk> Message-ID: <5bfe3bef-3e27-4e46-a3ae-3f029630d80a@c37g2000prb.googlegroups.com> Alex Hall wrote: > Why would the sequence > matter, or does it not and I am doing something else wrong? Here is a > sample of my dictionary: Showing us the code that handles the dictionary lookup + function calling would probably help us a lot more here. From fukazawa at gmail.com Wed Mar 10 00:01:48 2010 From: fukazawa at gmail.com (Andy) Date: Tue, 9 Mar 2010 21:01:48 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> <6596caf4-8d36-40b4-8e8d-a5ed2a18f245@z1g2000prc.googlegroups.com> Message-ID: <9a15f63e-c486-40fd-bd6f-9c328328f0a1@a16g2000pre.googlegroups.com> Hi Kishore, Have you tried "ser=serial.Serial(port='COM2', baudrate=9600)" instead of "port='\\.\COM2'"? Also, I'd suggest you temporarily define some other parameters that now you're leaving to default values. From the documentation of pyserial: readline(size=None, eol='\n') You're sure that your Arduino device is sending a '\n' right after the '1', aren't you? Or is it two consecutive '1'? And another idea: If this is your first experience with PySerial, I suggest you first use some free software as counterpart to your Arduino device in order to confirm the microcontroller is sending exactly what you think it is sending. In other words, is it sending to your Python program '11' or '1\n1\n'? Also to confirm other details such as parity bits, baud, etc. Cheers, Andy From showell30 at yahoo.com Wed Mar 10 00:23:08 2010 From: showell30 at yahoo.com (Steve Howell) Date: Tue, 9 Mar 2010 21:23:08 -0800 (PST) Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <3b1dce65-99ed-471a-8494-9eaf0e6d44ad@e19g2000prn.googlegroups.com> On Mar 7, 7:09?pm, Gregory Ewing wrote: > Given some known data/crc pairs, how feasible is it to > figure out the polynomial being used to generate the crc? > > In the case I'm looking at, it appears that the crc > size may be at least 24 bits, so just trying all possible > polynomials probably isn't doable. > > An article I found hints at the possibility of using > GCDs to make the search more efficient, but doesn't go > into any details. Anyone know of any literature about > this? > > If it helps, I have the ability to generate test cases > with known message contents to some extent, although > I don't have complete control over the contents. Also > it's a manual process, so generating large numbers of > them automatically isn't an option. > Hi Greg. I would at least flip one bit at a time on the first byte of your data to see if the transformation is bitwise. From rami.chowdhury at gmail.com Wed Mar 10 00:24:00 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Tue, 9 Mar 2010 21:24:00 -0800 Subject: Down casting Python objects In-Reply-To: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> Message-ID: <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> On Mar 9, 2010, at 13:26 , Andrey Fedorov wrote: > So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to "down cast" x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect things to work OK in all major versions of CPython? Could you tell us *why* you need to down-cast x? Explicit type-casting is usually unnecessary in Python... ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -------------- next part -------------- An HTML attachment was scrubbed... URL: From stava at telcotec.se Wed Mar 10 00:31:19 2010 From: stava at telcotec.se (Lars Stavholm) Date: Wed, 10 Mar 2010 11:01:19 +0530 Subject: pexpect and logging integration Message-ID: <4B972EA7.50807@telcotec.se> Hi all, has anyone managed to integrate pexpect and logging? I.e., I'd like to be able to pick up the dialog, commands sent and responses received, in my logging. I know about the pexpect logfile, and I can log things to stdout or stderr, but I really need to log using the python logging library. Any thoughts appreciated /Lars From gagsl-py2 at yahoo.com.ar Wed Mar 10 00:37:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 02:37:14 -0300 Subject: Knight's tour Warndorff's algorithm problem Message-ID: El 9 mar, 22:57, Robin Rytich escribi?: > I'm having some troubles with writing Knight's tour > (http://en.wikipedia.org/wiki/Knight%27s_tour) solution in Python 3. I'm > using Warnsdorff's algorithm (http://en.wikipedia.org/wiki/Knight% > 27s_tour#Algorithm) and I'm wondering why it doesn't work with boards of > certain sizes. I've written a solution and I like it but it does not > work correctly for 15x15, 26x26, 27x27 and 32x32 boards (don't know why; > checked from 5x5 to 40x40). Warnsdorff's algorithm is heuristic; it works most of the time, but in some cases leads to a dead end and you have to backtrack and try another alternative. The starting square is important; if you start at 1,1 (instead of 0,0) your program finds a solution for all those problematic board sizes. > So I'd be really glad if you tell me whether > I am too stupid for Python or for Discrete Math? In other words, did I > implemented Warnsdorff's algorithm in Python 3 correctly or maybe all my > troubles are because I haven't read tutorial with enough patience? Your implementation looks fine to me. Some comments on the code itself: > class ChessBoard: > > size = 8 # Board square width and height. > cell = [] # Embedded list of board cells. This sets a class attribute (as opposed to normal, instance attributes) which is shared by all ChessBoard instances (this really should be covered in the FAQ!). You really want an instance attribute here: do `self.cell = []` in __init__ > def __init__(self): > > import sys > > # Reading board size. > > if len(sys.argv) >= 2: > self.size = int(sys.argv[1]) I would process command line arguments when the script starts, and supply size/x/y as parameters to the ChessBoard constructor. In other words, the caller must provide those parameters, it's not ChessBoard responsability to hunt for them. > if (next != 0): > (self.y, self.x) = (next.y, next.x) All those six () are unnecessary. Also, `next` might refer to integer 0 or a ChessBoardSquare instance. That's perfectly legal in Python, but *I* prefer to assign objects of the same type when using the same variable name. In this case, 0 is used only as a marker, any other non-ChessBoardSquare instance would do, and I'd substitute None instead. (This is more than a stylistic whim: some JIT compiler may benefit from knowing the object type won't change) > def printField(self): > """ This function prints field to standart output. for i in > range(self.size): > for j in range(self.size): > print(self.cell[i][j].status, end = '') > print() Instead of artificially iterate over the *indices* to finally reach the objects, you may directly iterate over the board squares: for row in self.cell: for square in row: print(square.status, end = '') print() Later: > applicants = [[y - 1, x - 2], [y - 1, x + 2], > [y + 1, x - 2], [y + 1, x + 2], > [y - 2, x - 1], [y - 2, x + 1], > [y + 2, x - 1], [y + 2, x + 1]] > result = [] > for applicant in applicants: > if applicant[0] < 0 or applicant[0] >= self.size: > continue > if applicant[1] < 0 or applicant[1] >= self.size: > continue > if self.cell[applicant[0]][applicant[1]].status == 0: > result.append(self.cell[applicant[0]][applicant[1]]) It would be better to use meaningful names instead of applicant[0], applicant[1] -- let me re-use y,x. We can write a more concise condition: result = [] for y,x in applicants: if not 0 <= y < self.size: continue if not 0 <= x < self.size: continue if self.cell[y][x].status == 0: result.append(self.cell[y][x]) Now, lets combine all those conditions into a single one: result = [] for y,x in applicants: if 0 <= y < self.size and 0 <= x < self.size and self.cell[y][x].status == 0: result.append(self.cell[y][x]) Finally, a code pattern like the above can always be rewritten as a list comprehension: result = [self.cell[y][x] for y,x in applicants if 0 <= y < self.size and 0 <= x < self.size and self.cell[y][x].status == 0 ] Apart from these points, your program looks fine to me. You even added function docstrings! (ok, they might be more informative, but at least they exist!) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 01:29:02 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 03:29:02 -0300 Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein escribi?: > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. See PEP3136 [1] and its rejection note [2] I think you may find some more discussion in the python-ideas list. > Currently I'm using boolean > flag variables, but I find that very clumsy. I know this idea of > breaking out of specific loops from javascript; I guess java does it > too. It just seems a very Pythonian idea to me: clear, promotes code > legibility, seems obvious. Although I've occasionally missed the feature myself, I agree with Guido's arguments against it. You have several alternatives: refactor the loop into an auxiliary function, use a specific exception, add boolean flags, or repeat the test at the outer levels. (I usually choose the first). [1] http://www.python.org/dev/peps/pep-3136/ [2] http://mail.python.org/pipermail/python-3000/2007-July/008663.html -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 01:35:12 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 03:35:12 -0300 Subject: How to dynamic insert more conditional statements into a function References: <93ea751a-9d23-4186-897c-c2b079cc5c6c@e1g2000yqh.googlegroups.com> Message-ID: En Tue, 09 Mar 2010 18:48:42 -0300, Shane escribi?: > Hi I am a newbie for Python > > Here is a question, say I have a list L, > > function foo is: > > def foo(L): > if L[0] > 0: return True > > if later I want another function goo which returns "True" when L[0] > and L[1] are both > 0, i.e., > > def goo(L): > if L[0] > 0 and L[1] > 0: return True > > Can anybody tell me how can I write the function "goo" based upon the > function "foo"? Thanks! > I know if it is implementable, I should use "decorator". But I just > cannot figure out how. To implement goo based on foo: def goo(L): if foo(L) and L[1]>0: return True I don't see how to use a decorator here - maybe your example became too simple to be useful. A more realistic use case? -- Gabriel Genellina From agoretoy at gmail.com Wed Mar 10 01:58:13 2010 From: agoretoy at gmail.com (alex goretoy) Date: Wed, 10 Mar 2010 00:58:13 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: > > DATE_TYPE = type(date.today()) def dates_diff(self, *targs): nargs = len(targs) if nargs == 0: return self.enddate - self.startdate if nargs == 1: arg = targs[0] if not isinstance(arg, (list, tuple)) or len(arg) != 2: raise Exception( "single arg must be list or tuple of length 2") start, end = arg elif nargs == 2: start, end = targs else: raise Exception("expected 0,1, or 2 args; found %d" % nargs) if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE): return end - start raise Exception("both values must be of type DATE_TYPE") > HTH, > John This is awesome. Thank you for your contribution. I wasn't sure anyone was gonna reply; just saw your reply, pardon my delay. I will make the changes you suggested to other functions that apply in the lib as well(mimic that style of coding). Make it so it raises exceptions instead of failing over quietly(fallback to the __init__ passed args in other words). Is There any other functions or methods that you would recommend be added to the lib? Any and all other suggestions are welcome. I love python and you guys are practically helping me expand on my knowledge in this realm :) I haven't touched it in a little bit so after I mess with it again I'll be able to add more this thread/lib or whatever. Thanks Again, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Mar 10 02:04:04 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 04:04:04 -0300 Subject: Down casting Python objects References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> Message-ID: En Tue, 09 Mar 2010 18:26:52 -0300, Andrey Fedorov escribi?: > So I have `x', a instance of class `Foo'. I also have class `Bar', a > class > extending `Foo' with a couple of methods. I'd like to "down cast" x as > efficiently as possible. Is it OK to just set `x.__class__ = Bar' and > expect > things to work OK in all major versions of CPython? If the assignment x.__class__ = Bar succeeds, yes, that's enough. But you may not be able to reassign __class__ in some cases (e.g. Foo defines __slots__ but Bar doesn't, so you have a layout conflict). Of course, you always have to make sure Bar invariants hold on this particular instance... I must ask, why you didn't create a Bar instance in the first place? -- Gabriel Genellina From timr at probo.com Wed Mar 10 02:08:48 2010 From: timr at probo.com (Tim Roberts) Date: Tue, 09 Mar 2010 23:08:48 -0800 Subject: file seek is slow References: Message-ID: Metalone wrote: > >static void main(int argc, char *argv[]) As a side note, do you realize that this definition is invalid, in two ways? "main" cannot be declared "static". The whole reason we use the special name "main" is so that the startup code in the C run-time can link to it. If "main" is static, it won't be exposed in the object file, and the linker couldn't find it. It happens to work here because your C compiler knows about "main" and discards the "static", but that's not a good practice. Further, it's not valid to have "main" return "void". The standards require that it be declared as returning "int". Again, "void" happens to work in VC++, but there are architectures where it does not. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From agoretoy at gmail.com Wed Mar 10 02:14:45 2010 From: agoretoy at gmail.com (alex goretoy) Date: Wed, 10 Mar 2010 01:14:45 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: I have another quick question. What would be the best way to implement dates length function? or should i just leave that up to the user using the lib? -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From agoretoy at gmail.com Wed Mar 10 02:23:31 2010 From: agoretoy at gmail.com (alex goretoy) Date: Wed, 10 Mar 2010 01:23:31 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: >>> import datelib >>> datelib.datelib().dates_list() [datetime.date(2009, 3, 10), datetime.date(2009, 4, 10), datetime.date(2009, 5, 10), datetime.date(2009, 6, 10), datetime.date(2009, 7, 10), datetime.date(2009, 8, 10), datetime.date(2009, 9, 10), datetime.date(2009, 10, 10), datetime.date(2009, 11, 10), datetime.date(2009, 12, 10), datetime.date(2010, 1, 10), datetime.date(2010, 2, 10), datetime.date(2010, 3, 10)] >>> len(datelib.datelib().dates_list()) 13 >>> I know i can do this and untested below: function dates_len(*targs, **dargs) return len(self.dates_list(*targs, **dargs)) Is this bloating the lib with unnecessary functions/methods? -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Wed Mar 10 03:07:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 05:07:18 -0300 Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: En Tue, 09 Mar 2010 12:01:22 -0300, kishore escribi?: >> >> > Iam using python 2.5.4 >> > pyserial 2.4 >> > pywin32-214 >> > on windows 7 >> >> > i hav a small test script written to query a serial device (arduino) >> > and get back reply appropriately >> > > Thanks for your response > i tried closing idle and the following code prints > port opened > Write failed > > code: > > import serial > import time > ser=serial.Serial(port='\\.\COM2', baudrate=9600) If you want a string containing these 8 characters \\.\COM2 you have to write it either as r'\\.\COM2' or '\\\\.\\COM2' > if ser: > print 'port opened' Either the Serial object is constructed and returned, or an exception is raised. 'if ser:' has no sense; Python is not C... > ser.open() > if ser.write('1'): > print 'Write success' > else: > print 'write failed' The write method, when successful, implicitly returns None. None has a false boolean value, so your code will always print 'write failed'. Usually, in Python, error conditions are marked by raising an exception. Using return values to indicate success/failure is uncommon. Also, are you sure the device doesn't expect a newline character? '1\n'? You may need to call ser.flushOutput() to ensure the output buffer is actually emptied. > time.sleep(1) > a=ser.readline() print repr(a) > time.sleep(1) > b=ser.readline() print repr(b) > ser.close() > I believe this might be a serial port access error. > how to solve this? > Any suggestions? I don't think so. If you could not access the serial port, you'd have seen an IOError exception or similar. -- Gabriel Genellina From kishoreinme at gmail.com Wed Mar 10 03:39:36 2010 From: kishoreinme at gmail.com (kishore) Date: Wed, 10 Mar 2010 00:39:36 -0800 (PST) Subject: pyserial script doesnt execute properly References: <4b9612bc$0$6059$426a74cc@news.free.fr> Message-ID: <85262eff-ac2d-4fe1-bca3-2840c13ef06d@b36g2000pri.googlegroups.com> On Mar 10, 1:07?pm, "Gabriel Genellina" wrote: > En Tue, 09 Mar 2010 12:01:22 -0300, kishore > escribi?: > > > > > > >> > Iam using python 2.5.4 > >> > pyserial ?2.4 > >> > pywin32-214 > >> > on windows 7 > > >> > i hav a small test script written to query a serial device (arduino) > >> > and get back reply appropriately > > > Thanks for your response > > i tried closing idle and the following code prints > > port opened > > Write failed > > > code: > > > import serial > > import time > > ser=serial.Serial(port='\\.\COM2', baudrate=9600) > > If you want a string containing these 8 characters \\.\COM2 you have to > write it either as r'\\.\COM2' or '\\\\.\\COM2' > > > if ser: > > ? ?print 'port opened' > > Either the Serial object is constructed and returned, or an exception is > raised. 'if ser:' has no sense; Python is not C... > > > ser.open() > > if ser.write('1'): > > ? ?print 'Write success' > > else: > > ? ?print 'write failed' > > The write method, when successful, implicitly returns None. None has a > false boolean value, so your code will always print 'write failed'. > > Usually, in Python, error conditions are marked by raising an exception. > Using return values to indicate success/failure is uncommon. > > Also, are you sure the device doesn't expect a newline character? '1\n'? > > You may need to call ser.flushOutput() to ensure the output buffer is > actually emptied. > > > time.sleep(1) > > a=ser.readline() > > print repr(a) > > > time.sleep(1) > > b=ser.readline() > > print repr(b) > > > ser.close() > > I believe this might be a serial port access error. > > how to solve this? > > Any suggestions? > > I don't think so. If you could not access the serial port, you'd have seen > an IOError exception or similar. > > -- > Gabriel Genellina thanks Gabriel & Andy..ll get back soon here after trying ur suggestions From jeherul at gmail.com Wed Mar 10 04:06:28 2010 From: jeherul at gmail.com (JEHERUL) Date: Wed, 10 Mar 2010 14:36:28 +0530 Subject: about Telnetlib problem Message-ID: <46c1bcc21003100106s1db37a95ke928306c5e79d088@mail.gmail.com> Dear All I am trying to telnet to a Cisco router . Following is my code . #code router.py import getpass import sys import telnetlib HOST = "router address" # router address is ommitted for security reason user = raw_input("Username : ") password = getpass.getpass() tn = telnetlib.Telnet(HOST) tn.read_until("Username: ") tn.write(user + "\n") tn.read_until("Password: ") tn.write(password + "\n") tn.read_until("I>") tn.write("sh int f0/0") print "Just to check" print tn.read_all() print "after read" tn.write("exit\n") But when I execute the program I got the following error . Traceback (most recent call last): File "router.py", line 23, in ? print tn.read_all() File "/usr/lib/python2.4/telnetlib.py", line 330, in read_all self.fill_rawq() File "/usr/lib/python2.4/telnetlib.py", line 521, in fill_rawq buf = self.sock.recv(50) Please help me . Regards -- Jeherul Islam Indian Institute of Information Technology and Management . Gwalior (MP) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Mar 10 04:16:27 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Mar 2010 09:16:27 GMT Subject: odd error References: <4B96787B.3030907@timgolden.me.uk> Message-ID: On Tue, 09 Mar 2010 11:48:10 -0500, Alex Hall wrote: > Okay, I changed the keycode from 99 (c) to 107 (k), and the errors have > disappeared. However, now the function that should be called is not. As > I said in a previous message, I have always had trouble with this sort > of keystroke dictionary. It seems like, if a keycode is out of order or > not one more than the number before it, the function to which it is tied > will not get called. Dictionaries aren't ordered, that can't be the problem. > keys.append({ > 1 : (48, win32con.MOD_CONTROL), > 2 : (49, win32con.MOD_CONTROL), [...] Dicts don't have an append message. Why are you building a list and adding a dictionary to it? The question is, how many such dicts are in the list, and which one are you searching for the function? Is it possible that the problem is that you have multiple dicts in the keys list, and then perform your look-ups on the wrong one? Likewise for your list of functions: > funcs.append({ > 1 : exitProgram, > 2 : arm.sayLoad1, [...] Perhaps all you need is a single dict, mapping characters to functions: funcs = { # Just a dict # keycode: function 'q': exitProgram, 'a': arm.sayLoad1 # etc. } Then whenever you get a keyboard event, convert it to the character: keycode = 113 c = chr(keycode) funcs(c)() -- Steven From mail at timgolden.me.uk Wed Mar 10 04:25:53 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Mar 2010 09:25:53 +0000 Subject: odd error In-Reply-To: References: <4B96787B.3030907@timgolden.me.uk> Message-ID: <4B9765A1.1030509@timgolden.me.uk> On 10/03/2010 09:16, Steven D'Aprano wrote: > Perhaps all you need is a single dict, mapping characters to functions: > > funcs = { # Just a dict > # keycode: function > 'q': exitProgram, > 'a': arm.sayLoad1 > # etc. > } > > > Then whenever you get a keyboard event, convert it to the character: > > keycode = 113 > c = chr(keycode) > funcs(c)() FWIW (altho' it's not clear from the OP's code) he's basically doing this: http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html which uses the dictionary keys as an id in the call to RegisterHotKey. Obviously, that doesn't explain why he's building lists of dictionaries. TJG From robin.rytich at gmail.com Wed Mar 10 04:32:05 2010 From: robin.rytich at gmail.com (Robin Rytich) Date: Wed, 10 Mar 2010 12:32:05 +0300 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: <1268213525.12869.188.camel@rytich-laptop> On Wed, 2010-03-10 at 02:37 -0300, Gabriel Genellina wrote: > Warnsdorff's algorithm is heuristic; it works most of the time, but in > some cases leads to a dead end and you have to backtrack and try another > alternative. > The starting square is important; if you start at 1,1 (instead of 0,0) > your program finds a solution for all those problematic board sizes. Wow, didn't know about that. It seems to be a good idea for me to make a little research around this question. > Some comments on the code itself: > This sets a class attribute (as opposed to normal, instance attributes) > which is shared by all ChessBoard instances (this really should be covered > in the FAQ!). Damn, I'm ashamed. About other points, I actually totally agree with you (and corrected almost everything before received your letter). Thank you for your remarks, I'll review public code more careful next time. Robin Rytich From mehgcap at gmail.com Wed Mar 10 07:09:13 2010 From: mehgcap at gmail.com (Alex Hall) Date: Wed, 10 Mar 2010 07:09:13 -0500 Subject: odd error In-Reply-To: <4B9765A1.1030509@timgolden.me.uk> References: <4B96787B.3030907@timgolden.me.uk> <4B9765A1.1030509@timgolden.me.uk> Message-ID: I am honestly a bit lost as to why keys.append() is not a good choice here, but I have it working. I apparently have to use the ascii for capital letters if I am capturing the shift modifier, not the lowercase ascii. Using 67 instead of 99 works as expected. I use append because the program has three different modes. Eventually, each mode may have its own keystrokes. When the user switches modes, the previous mode's keystrokes are unregistered and the new keystrokes, keys[currentModeNumber], are registered. The same with the functions; when a function is called from the dictionary, it is called using funcs[currentModeNumber]. Again, this lets me put all my functions into one big list, where each member of the list is a dictionary. I probably have the terminology wrong, but hopefully that makes sense. Sorry for not explaining that earlier, but I was just looking for problems in the key codes. Thanks for your help! On 3/10/10, Tim Golden wrote: > On 10/03/2010 09:16, Steven D'Aprano wrote: >> Perhaps all you need is a single dict, mapping characters to functions: >> >> funcs = { # Just a dict >> # keycode: function >> 'q': exitProgram, >> 'a': arm.sayLoad1 >> # etc. >> } >> >> >> Then whenever you get a keyboard event, convert it to the character: >> >> keycode = 113 >> c = chr(keycode) >> funcs(c)() > > FWIW (altho' it's not clear from the OP's code) he's basically > doing this: > > http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html > > which uses the dictionary keys as an id in the call to RegisterHotKey. > > Obviously, that doesn't explain why he's building lists of dictionaries. > > > TJG > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From mail at timgolden.me.uk Wed Mar 10 07:15:06 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Mar 2010 12:15:06 +0000 Subject: odd error In-Reply-To: References: <4B96787B.3030907@timgolden.me.uk> <4B9765A1.1030509@timgolden.me.uk> Message-ID: <4B978D4A.5060204@timgolden.me.uk> On 10/03/2010 12:09, Alex Hall wrote: > I am honestly a bit lost as to why keys.append() is not a good choice > here, but I have it working. That's ok; it's just not clear from the context why you have a list of dicts but your comment about different modes explains that. > I apparently have to use the ascii for > capital letters if I am capturing the shift modifier, not the > lowercase ascii. Using 67 instead of 99 works as expected. That's probably because the os is "preprocessing" the keystroke so that shift-a returns "A" and not "a". You might find that you don't even *need* the shift modifier in those circs. If I get the time this pm, I'll try to put together some example code which runs to more than 10 items in a dict just in case there is some bizarre cornercase which is causing a problem but I honestly doubt it. TJG From paskari007 at yahoo.ca Wed Mar 10 07:19:29 2010 From: paskari007 at yahoo.ca (PEYMAN ASKARI) Date: Wed, 10 Mar 2010 04:19:29 -0800 (PST) Subject: Importing Modules Message-ID: <676034.43316.qm@web30001.mail.mud.yahoo.com> Hello I frequent the PyGtk mailing list all the time, but this is the first time I am posting here =) I wanted to know if imported classes are treated differently than internal classes. I have attached a minimal example which points out what I mean. Essentially, if I create a class: class A(): ?__init__(self): ? pass and call A, or A() I get something to the effect of? <__main__.A instance at 0xb7f088ac> but if I call from module_name import A and then call A or A() I get something to the effect of? I was wondering if this would be a problem. I have included the test_import.py file as well as 4 module files which it loads. Save the tes_import.py file to a folder, create another folder there, and save ONLY the 4 modules files to that new folder. In the code, update line 26 to reflect to path of the newly created directory Thanks in advanced Peyman -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test_import.py Type: text/x-python Size: 2218 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_1.py Type: text/x-python Size: 67 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_2.py Type: text/x-python Size: 67 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_3.py Type: text/x-python Size: 67 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: module_4.py Type: text/x-python Size: 67 bytes Desc: not available URL: From jeanmichel at sequans.com Wed Mar 10 07:27:33 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 13:27:33 +0100 Subject: Import problem In-Reply-To: <4b957866$0$17135$426a34cc@news.free.fr> References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b957866$0$17135$426a34cc@news.free.fr> Message-ID: <4B979035.60505@sequans.com> News123 wrote: > Jean-Michel Pichavant wrote: > >> Johny wrote: >> >>> I have this directory structure >>> >>> C: >>> \A >>> __init__.py >>> amodule.py >>> >>> \B >>> __init__.py >>> bmodule.py >>> >>> \D >>> __init__.py >>> dmodule.py >>> >>> and I want to import bmodule.py >>> C:\>cd \ >>> >>> C:\>python >>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>> (Intel)] on win >>> 32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>>>>> from A.B import bmodule >>>>>> >>>>>> >>> I am bmodule >>> C:\> >>> >>> so far so good. Now I would like to import bmodule but if the current >>> directory is \D subdirectory. >>> >>> C:> cd \A\B\D >>> C:\A\B\D> >>> C:\A\B\D>python >>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>> (Intel)] on win >>> 32 >>> Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>>>>> import sys >>>>>> sys.path.append('C:\\A') >>>>>> from A.B import bmodule >>>>>> >>>>>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named A.B >>> >>> C:\> >>> >>> so I can not import a module from the parent directory? Or where did I >>> make an error? >>> Thanks for help >>> >>> L. >>> >>> >> try >> >> import sys >> sys.path.append('C:\\') >> from A.B import bmodule >> >> > is there any 'automatic' way of finding the top level > directory?basically the 'top level directory is the first directory > going upwards, that doesn't contain a __init__.py file. > what if some user has an __init__.py file the top level directory of your package ? > of course you could do this 'manually' by > doing: > > # assume, that this module is A.amodule > import sys > import os > > # I'd love to have a similiar automatic construct > if __name__ == "__main__": > level = 1 # or function locating how far to go up before > # finding a dir, whcih does not contain a __init__.py > mydir = os.path.split(__file__)[0] > topdir = os.path.join( mydir,*(("..",)*level)) > abstop = os.path.abspath(topdir) > sys.path.append(abstop) > > ## now you can import with the normal module paths > > import A.blo > print "and I found blo",dir(A.blo) > > > bye N > > > > You don't want to do that and you don't need it neither. That's what the env variable PYTHONPATH is for. set it correctly, install your package inside and everything works just fine (+standard). With a linux OS it easy to create smb links to point to any working directory. It should be possible on windows as well. If your package is meant to be destributed, you may use setup.py JM From victorsubervi at gmail.com Wed Mar 10 07:32:15 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 10 Mar 2010 08:32:15 -0400 Subject: Interacting With Another Script Message-ID: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Hi; There's a program (vpopmail) that has commands which, when called, request input ("email address", "password", etc.) from the command line. I would like to build a TTW interface for my clients to use that interacts with these commands. It's easy enough for me to get the information from a script, but how do I input it when these functions keep requesting information? I hope I've made myself clear :-} TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From ndbecker2 at gmail.com Wed Mar 10 08:12:14 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 08:12:14 -0500 Subject: Can't define __call__ within __init__? Message-ID: Want to switch __call__ behavior. Why doesn't this work? What is the correct way to write this? class X (object): def __init__(self, i): if i == 0: def __call__ (self): return 0 else: def __call_ (self): return 1 x = X(0) x() TypeError: 'X' object is not callable From jeanmichel at sequans.com Wed Mar 10 08:22:36 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 14:22:36 +0100 Subject: Named loops for breaking In-Reply-To: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <4B979D1C.6090706@sequans.com> Daniel Klein wrote: > Hey, > > I did a little searching and couldn't really find much recent on this. > The only thing I found was this: > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/a696624c92b91181/5b7479fdc3362b83?lnk=gst&q=break+named+loop#5b7479fdc3362b83 > > Basically I'm wondering if there are any plans to implemented named > loops in Python, so I can tell a break command to break out of a > specific loop in the case of nested loops. Currently I'm using boolean > flag variables, but I find that very clumsy. I know this idea of > breaking out of specific loops from javascript; I guess java does it > too. It just seems a very Pythonian idea to me: clear, promotes code > legibility, seems obvious. > Strange that I've rarely been in need of such feature. Continues & breaks are mess-prone, adding an 'outter block' break feature would just increase the messing potential of such controls. Just my opinion though. Still there's a control that is able to break outter scopes : return. So embed your loop in a function and you'll be able to break whenever you want. JM From simon at brunningonline.net Wed Mar 10 08:27:31 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Mar 2010 13:27:31 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> On 10 March 2010 13:12, Neal Becker wrote: > Want to switch __call__ behavior. ?Why doesn't this work? ?What is the > correct way to write this? > > class X (object): > ? ?def __init__(self, i): > ? ? ? ?if i == 0: > ? ? ? ? ? ?def __call__ (self): > ? ? ? ? ? ? ? ?return 0 > ? ? ? ?else: > ? ? ? ? ? ?def __call_ (self): > ? ? ? ? ? ? ? ?return 1 > > > x = X(0) > > x() > TypeError: 'X' object is not callable __call__ is in the __init__ method's local namespace - you need to bind it to the class's namespace instead: X.__call__ = __call__ But this probably isn't what you want either, since all instances of X will share the same method. What are you trying to do? In your simple example, you'd be much better off with a single __call__ method. But you knew that. -- Cheers, Simon B. From anfedorov at gmail.com Wed Mar 10 08:31:14 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Wed, 10 Mar 2010 08:31:14 -0500 Subject: Down casting Python objects In-Reply-To: <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> Message-ID: <7659cab31003100531i51749f7er6f23ca0ef59cdddf@mail.gmail.com> On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury wrote: > Could you tell us *why* you need to down-cast x? Explicit type-casting is > usually unnecessary in Python... Sure! It's related to the longer question I unwisely asked during PyCon [1] (when no one had time to read it, I suppose). I have a couple of different flavors of request objects which I'd like to make conform to a single interface. So Request `x' come in, I determine which kind of request I'm dealing with, and would like to "down-cast" it to ARequest or BRequest, classes which will provide appropriate accessor properties for the rest of the code to use. An option clearly in line with Python's docs might be for `x' to be an attribute of an ARequest instance, but that would complicate the code of ARequest. What I'm looking for is a way of adding mix-in's at runtime, if that makes sense. Cheers, Andrey 1. http://mail.python.org/pipermail/python-list/2010-February/1236681.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Mar 10 08:40:19 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 10 Mar 2010 13:40:19 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: Neal Becker wrote: > Want to switch __call__ behavior. Why doesn't this work? What is the > correct way to write this? > > class X (object): > def __init__(self, i): > if i == 0: > def __call__ (self): > return 0 > else: > def __call_ (self): > return 1 > > > x = X(0) > > x() > TypeError: 'X' object is not callable > > I think it's because X has already been constructed when __init__ is called, so __new__ is the place for your conditional code. From ndbecker2 at gmail.com Wed Mar 10 08:41:28 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 08:41:28 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Simon Brunning wrote: > On 10 March 2010 13:12, Neal Becker wrote: >> Want to switch __call__ behavior. Why doesn't this work? What is the >> correct way to write this? >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> def __call__ (self): >> return 0 >> else: >> def __call_ (self): >> return 1 >> >> >> x = X(0) >> >> x() >> TypeError: 'X' object is not callable > > __call__ is in the __init__ method's local namespace - you need to > bind it to the class's namespace instead: > > X.__call__ = __call__ > > But this probably isn't what you want either, since all instances of X > will share the same method. > > What are you trying to do? In your simple example, you'd be much > better off with a single __call__ method. But you knew that. > Sorry, a bit early in the morning. This works: class X (object): def __init__(self, i): if i == 0: def F (self): return 0 else: def F (self): return 1 self.F = F def __call__ (self): return self.F (self) Not sure if there is a more elegant (or compact) way to write this. Could __call__ be defined directly within __init__? What I'm trying to do is make a callable whose behavior is switched based on some criteria that will be fixed for all calls. In my example, this will ultimately be determined by the setting of a command line switch. From martin.hellwig at dcuktec.org Wed Mar 10 08:54:27 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Mar 2010 13:54:27 +0000 Subject: Does this already exists?: A module that checks if the used platform is supported Message-ID: Hi all, Before I start reinventing a squared wheel, I have the following question: Is there already a (standard) module that wraps around the various os/sys information which checks if the platform + version is supported for what I want to do with it. For example I am currently looking at making a wrapper around sysctl, for Freebsd only (2.2 onwards perhaps later I add Linux if I feel up to it. So yes of course I can do a os.uname() but it struck me that there must be a better way. * If you think I made a thought error along the line and there is a better solution, please do tell me too :-) Thanks, -- mph * Something like: test = RequirePlatform(do_not_raise=True) test.require(platform='freebsd', version_min='2.2') # If the platform is anything else but FreeBSD 2.2+ # raise an EnvironmentError. Otherwise, store the # result of the test (True/False). # Result of the require (and any additional tests # can be accessed using the index operators if test[0]: print('supported') From mnordhoff at mattnordhoff.com Wed Mar 10 08:58:07 2010 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Wed, 10 Mar 2010 13:58:07 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: <4B97A56F.5060903@mattnordhoff.com> Neal Becker wrote: > Simon Brunning wrote: > >> On 10 March 2010 13:12, Neal Becker wrote: >>> Want to switch __call__ behavior. Why doesn't this work? What is the >>> correct way to write this? >>> >>> class X (object): >>> def __init__(self, i): >>> if i == 0: >>> def __call__ (self): >>> return 0 >>> else: >>> def __call_ (self): >>> return 1 >>> >>> >>> x = X(0) >>> >>> x() >>> TypeError: 'X' object is not callable >> __call__ is in the __init__ method's local namespace - you need to >> bind it to the class's namespace instead: >> >> X.__call__ = __call__ >> >> But this probably isn't what you want either, since all instances of X >> will share the same method. >> >> What are you trying to do? In your simple example, you'd be much >> better off with a single __call__ method. But you knew that. >> > > Sorry, a bit early in the morning. This works: > class X (object): > def __init__(self, i): > if i == 0: > def F (self): > return 0 > else: > def F (self): > return 1 > self.F = F > > def __call__ (self): > return self.F (self) > > > Not sure if there is a more elegant (or compact) way to write this. > Could __call__ be defined directly within __init__? > > What I'm trying to do is make a callable whose behavior is switched based on > some criteria that will be fixed for all calls. In my example, this will > ultimately be determined by the setting of a command line switch. ISTM it would be prettiest to do: class X(object): def __init__(self, i): self.flag = i == 0 def __call__(self): if self.flag: return 0 else: return 1 Or, if the comparison isn't particularly expensive, it would look nicer to just use self.i and do "self.i == 0" in __call__. Not that it matters, but this is probably faster than your version, too, since it saves a method call. By the way, IIRC Python only looks up double-underscore methods on the class, not the instance. That's why you had to indirect through self.F. -- Matt Nordhoff From jeanmichel at sequans.com Wed Mar 10 09:07:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 15:07:57 +0100 Subject: pexpect and logging integration In-Reply-To: <4B972EA7.50807@telcotec.se> References: <4B972EA7.50807@telcotec.se> Message-ID: <4B97A7BD.6050003@sequans.com> Lars Stavholm wrote: > Hi all, > > has anyone managed to integrate pexpect and logging? > > I.e., I'd like to be able to pick up the dialog, > commands sent and responses received, in my logging. > I know about the pexpect logfile, and I can log things > to stdout or stderr, but I really need to log using the > python logging library. > > Any thoughts appreciated > /Lars > > I had to implement this. It's a bit of a hack, but it does the job. The following code is tested with python 2.5, I remember pexpect behaves slightly differently in python 2.3. import logging import pexpect import re # this will be the method called by the pexpect object to log def _write(*args, **kwargs): content = args[0] # let's ignore other params, pexpect only use one arg AFAIK if content in [' ', '', '\n', '\r', '\r\n']: return # don't log empty lines for eol in ['\r\n', '\r', '\n']: # remove ending EOL, the logger will add it anyway content = re.sub('\%s$' % eol, '', content) return logger.info(content) # call the logger info method with the reworked content # our flush method def _doNothing(): pass # get the logger logger = logging.getLogger('foo') # configure the logger logger.handlers=[] logger.addHandler(logging.StreamHandler()) logger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) logger.setLevel(logging.INFO) # give the logger the methods required by pexpect logger.write = _write logger.flush = _doNothing p = pexpect.spawn('echo "hello world !!"', logfile=logger) p.expect('!!') ... 2010-03-10 15:01:31,234 - foo - INFO - hello world !! Hope it helps. JM From jeanmichel at sequans.com Wed Mar 10 09:10:10 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Mar 2010 15:10:10 +0100 Subject: about Telnetlib problem In-Reply-To: <46c1bcc21003100106s1db37a95ke928306c5e79d088@mail.gmail.com> References: <46c1bcc21003100106s1db37a95ke928306c5e79d088@mail.gmail.com> Message-ID: <4B97A842.4030709@sequans.com> JEHERUL wrote: > Dear All > > I am trying to telnet to a Cisco router . Following is my code . > > #code router.py > > import getpass > import sys > import telnetlib > > HOST = "router address" # router address is ommitted for > security reason > user = raw_input("Username : ") > password = getpass.getpass() > > tn = telnetlib.Telnet(HOST) > > tn.read_until("Username: ") > tn.write(user + "\n") > tn.read_until("Password: ") > tn.write(password + "\n") > > > tn.read_until("I>") > tn.write("sh int f0/0") > > print "Just to check" > > > print tn.read_all() > > print "after read" > tn.write("exit\n") > > > > But when I execute the program I got the following error . > > > Traceback (most recent call last): > File "router.py", line 23, in ? > print tn.read_all() > File "/usr/lib/python2.4/telnetlib.py", line 330, in read_all > self.fill_rawq() > File "/usr/lib/python2.4/telnetlib.py", line 521, in fill_rawq > buf = self.sock.recv(50) > > Please help me . > > Regards > -- > Jeherul Islam > Indian Institute of Information Technology and Management . > Gwalior (MP) > > Hi, Your error trace is incomplete it's missing the exception. It would be better if you provide it. JM From tjreedy at udel.edu Wed Mar 10 09:21:12 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 09:21:12 -0500 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: On 3/10/2010 12:37 AM, Gabriel Genellina wrote: >> if (next != 0): >> (self.y, self.x) = (next.y, next.x) In Python3, next is a builtin function. Choose a different name, at least in public code ;=). From richardbp at gmail.com Wed Mar 10 09:29:03 2010 From: richardbp at gmail.com (Richard) Date: Wed, 10 Mar 2010 06:29:03 -0800 (PST) Subject: os.rename [Errno 31] Too many links Message-ID: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> I want to atomically write to a file so have been using temporary files and renaming: temp = tempfile.NamedTemporaryFile(delete=False) temp.file.write(data) temp.file.close() os.rename(temp.name, output_file) This worked but after 39567 files os.rename raises an OSError: [Errno 31] Too many links I can still create files in this directory so I doubt it is a platform limitation. Can you tell what is wrong? Am I not freeing the temporary file resources properly? thanks, Richard From tjreedy at udel.edu Wed Mar 10 09:32:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 09:32:03 -0500 Subject: Importing Modules In-Reply-To: <676034.43316.qm@web30001.mail.mud.yahoo.com> References: <676034.43316.qm@web30001.mail.mud.yahoo.com> Message-ID: On 3/10/2010 7:19 AM, PEYMAN ASKARI wrote: > Hello > > I frequent the PyGtk mailing list all the time, but this is the first > time I am posting here =) > > I wanted to know if imported classes are treated differently than > internal classes. > > I have attached a minimal example which points out what I mean. > Essentially, if I create a class: > > class A(): > __init__(self): > pass > > and call A, or A() I get something to the effect of <__main__.A instance > at 0xb7f088ac> > > but if I call from module_name import A and then call A or A() I get > something to the effect of > > I was wondering if this would be a problem. Only if you code cares about A.__module__ (3.x, not sure of 2.x) and the string returned by str or repr, which nearly always, it should not. tjr From jjposner at optimum.net Wed Mar 10 09:45:38 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Mar 2010 09:45:38 -0500 Subject: Method / Functions - What are the differences? In-Reply-To: <4b911ee0$0$4988$607ed4bc@cv.net> References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> Message-ID: <4B97B092.4060901@optimum.net> [ cross-posting to edu-sig ] Bruno (and anyone else interested) -- As I promised/threatened, here's the *start* of a write-up on properties, aimed at non-advanced Python programmers: http://www.jjposner.net/media/python-properties-0310.pdf I'm interested in corrections, of course. But I'm also interested in opinions as to whether this somewhat lengthy treatment is worth the effort -- does it improve on existing write-ups? Tx, John From bringa at gmail.com Wed Mar 10 10:15:47 2010 From: bringa at gmail.com (Daniel Klein) Date: Wed, 10 Mar 2010 07:15:47 -0800 (PST) Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: <43248058-f388-4127-904a-e0c2e80a36e4@33g2000yqj.googlegroups.com> Thanks for the link to the PEP. I should search through PEPs first next time :) Okay, I understand Guido's reasoning and yield the point. I typed up the specific example in which I came across this problem and, while doing so, realized there's a much better way of approaching the problem, so thank you for that as well :) From jpeck at fedex.com Wed Mar 10 10:17:12 2010 From: jpeck at fedex.com (Jeff Peck) Date: Wed, 10 Mar 2010 09:17:12 -0600 Subject: Bluetooth In-Reply-To: References: Message-ID: <4B97B7F8.2030303@fedex.com> On 3/7/2010 1:26 PM, PythonAB wrote: > Hello, > > > I'm writing a script that has to connect a bluetooth device > with a 3D application. > On my search for a bluetooth module i ran into this: > http://www.python.org/download/releases/2.4/notes/ > where it says: > "The socket module now supports Bluetooth sockets, > if the system has " > > Yet I can't find anything at all in the socket manuals > nor anywhere else on the site... > > Does the socket module really support Bluetooth out of the box? > I've used socket before but never read anything about bluetooth... > > Maybe I need to get the bluetooth.h file, but i have no idea what I > am supposed to do with it... > > Can anyone shed some light on this for me please? > > thanks in advance, > > gr > Arno Have you come across the PyBluez library yet? I recently used it in a project and it worked very well. Hth, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at please.post Wed Mar 10 10:19:04 2010 From: no.email at please.post (kj) Date: Wed, 10 Mar 2010 15:19:04 +0000 (UTC) Subject: Anything like "Effective Java" for Python? Message-ID: Subject line pretty much says it all: is there a book like "Effective Java" for Python. I.e. a book that assumes that readers are experienced programmers that already know the basics of the language, and want to focus on more advanced programming issues? ~K From simon at brunningonline.net Wed Mar 10 10:29:44 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Mar 2010 15:29:44 +0000 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <8c7f10c61003100729j2afba0c9rf00760e48f535249@mail.gmail.com> On 10 March 2010 15:19, kj wrote: > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. ?I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? is good. -- Cheers, Simon B. From echerlin at gmail.com Wed Mar 10 10:31:35 2010 From: echerlin at gmail.com (Edward Cherlin) Date: Wed, 10 Mar 2010 10:31:35 -0500 Subject: [Edu-sig] Method / Functions - What are the differences? In-Reply-To: <4B97B092.4060901@optimum.net> References: <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> <4B97B092.4060901@optimum.net> Message-ID: On Wed, Mar 10, 2010 at 09:45, John Posner wrote: > [ cross-posting to edu-sig ] > > Bruno (and anyone else interested) -- > > As I promised/threatened, here's the *start* of a write-up on properties, > aimed at non-advanced Python programmers: > > ?http://www.jjposner.net/media/python-properties-0310.pdf > > I'm interested in corrections, of course. But I'm also interested in > opinions as to whether this somewhat lengthy treatment is worth the effort > -- does it improve on existing write-ups? I find that it will explain things to those who already understand most of the concepts. However, I felt as though I were being led through a maze without knowing where we were headed. This suggests that the concepts can be re-ordered in a manner that will help your readers more, and then we can refactor further. (Yes, you can apply Extreme Programming concepts to create Extreme Documentation, including consultations with users, pair or group writing, frequent refactoring, and more, as at FLOSSManuals.net.) Who is your expected audience? > Tx, > John > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig > -- Edward Mokurai (??/???????????????/????????????? ?) Cherlin Silent Thunder is my name, and Children are my nation. The Cosmos is my dwelling place, the Truth my destination. http://www.earthtreasury.org/ From bsagert at gmail.com Wed Mar 10 10:55:27 2010 From: bsagert at gmail.com (Bill) Date: Wed, 10 Mar 2010 07:55:27 -0800 (PST) Subject: I passed a fizzbuzz test but failed at recursion. Message-ID: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Look at this recursive fizzbuzz function from http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html def fizzbuzz(num): if num: if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' else : return fizzbuzz(num-1) + ('%d \n' % num) return '' print fizzbuzz(100) This returns "1 2 fizz 4 ...etc... 97 98 fizz buzz" which is correct. However, when I try to decipher the logic of the function I imagine the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". After all, the first num is 100 which decrements by one until a zero stops the recursive loop. My (faulty) reasoning is that fizzbuzz(100) would firstly print a "fizz" and the last fizzbuzz(1) would finally print a "1". My logic is wrong, but I don't know why. From hv at tbz-pariv.de Wed Mar 10 11:08:44 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Wed, 10 Mar 2010 17:08:44 +0100 Subject: os.rename [Errno 31] Too many links In-Reply-To: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> References: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> Message-ID: <7vpugdF5bqU1@mid.individual.net> Richard wrote: > I want to atomically write to a file so have been using temporary > files and renaming: > > temp = tempfile.NamedTemporaryFile(delete=False) > temp.file.write(data) > temp.file.close() > os.rename(temp.name, output_file) > > This worked but after 39567 files os.rename raises an OSError: [Errno > 31] Too many links > > I can still create files in this directory so I doubt it is a platform > limitation. > Can you tell what is wrong? Am I not freeing the temporary file > resources properly? If you are on linux you can have a look at the open file descriptors of a running process like this: ls -l /proc/PID/fd/ But I guess it is a limitation of your filesystem. What do you use? I once had this problem with ext2. It has a low limit for subdirectories. With xfs the limits are much greater. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From chris.hulan at gmail.com Wed Mar 10 11:24:00 2010 From: chris.hulan at gmail.com (Chris Hulan) Date: Wed, 10 Mar 2010 08:24:00 -0800 (PST) Subject: I passed a fizzbuzz test but failed at recursion. References: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Message-ID: <749d9c6e-f41f-4859-9c57-459caeddf6e4@j27g2000yqn.googlegroups.com> On Mar 10, 10:55?am, Bill wrote: > Look at this recursive fizzbuzz function fromhttp://www.codinghorror.com/blog/2007/02/why-cant-programmers-program... > > def fizzbuzz(num): > ? ? if num: > ? ? ? ? if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' > ? ? ? ? elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' > ? ? ? ? elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' > ? ? ? ? else : return fizzbuzz(num-1) + ('%d \n' % num) > ? ? return '' > print fizzbuzz(100) > > This returns "1 2 fizz 4 ...etc... 97 98 fizz buzz" which is correct. > > However, when I try to decipher the logic of the function I imagine > the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". > > After all, the first num is 100 which decrements by one until a zero > stops the recursive loop. > > My (faulty) reasoning is that fizzbuzz(100) would firstly print a > "fizz" and ?the last fizzbuzz(1) would finally print a "1". > > My logic is wrong, but I don't know why. There's only one print, it prints the string returned by fizzbuzz(100) The string is constructed via recursion ie: fizzbuzz(6) fizzbuzz(5) fizzbuzz(4) fizzbuzz(3) fizzbuzz(2) fizzbuzz(1) fizzbuzz(0) ''+'1 \n' '1 \n'+'2 \n' '1 \n2 \n'+'fizz \n' '1 \n2 \n fizz \n'+'4 \n' '1 \n2 \n fizz \n4 \n'+'buzz \n' '1 \n2 \n fizz \n4 \nbuzz \n'+'fizz \n' print '1 \n2 \n fizz \n4 \nbuzz \nfizz \n' clear as mud ;) From clp2 at rebertia.com Wed Mar 10 11:31:06 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Mar 2010 08:31:06 -0800 Subject: Interacting With Another Script In-Reply-To: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Message-ID: <50697b2c1003100831l302a84e2j1aeaf351dd4e1fe6@mail.gmail.com> On Wed, Mar 10, 2010 at 4:32 AM, Victor Subervi wrote: > Hi; > There's a program (vpopmail) that has commands which, when called, request > input ("email address", "password", etc.) from the command line. I would > like to build a TTW interface for my clients to use that interacts with > these commands. It's easy enough for me to get the information from a > script, but how do I input it when these functions keep requesting > information? I hope I've made myself clear :-} (assuming TTW = Thru The Web; been a while since I've come across an unknown, non-new acronym) [Disclaimer: I know zilch about vpopmail's specifics] Option A. Check for when the latest output looks prompt-like (e.g. colon followed by a space; this will be program-specific and possibly different for vpopmail) and then ask for input. For example: 1. Get new session request from client 2. Run new vpopmail process 3. Wait until prompt detected in process' output 4. Send back webpage with the output and a
to answer the prompt 5. Write user's response from form as input to process. 6. If read EOF, send final output back as webpage to client and close session. Else, GOTO 3 (See also: expect) Option B. Web pseudo-shell using AJAX. Client polls server for new output. Client pushes new input to server at any time. 1. Get new session request from client 2. Run new vpopmail process 3. Send back webpage w/ JavaScript code 4.1. Client periodically polls server for new output via AJAX and displays it when there is some. 4.2. Client has omnipresent that on submission sends an AJAX request to the server with the given input. 5. If get input message from client, write input to process' stdin. If get polling message from client, do non-blocking read on the process' output and respond with the result. If get EOF, inform client on next poll and then close session. Option C. The most user-friendly, and in some sense simplest, one. Figure out the "conversation tree" vpopmail follows. Create a matching form tree workflow, presenting multiple input fields at once. Run vpopmail and write the appropriate input to its stdin based on the form data. Send the output back as a webpage. [Session management & timeouts in the preceding are left as exercises for the implementor] Option D. The Zen option: It seems quite probable that someone's already written a web frontend for vpopmail administration/configuration. Just use that. The best software is that which you don't have to write. Cheers, Chris -- Ironically, I have yet to code a webapp. http://blog.rebertia.com From clp2 at rebertia.com Wed Mar 10 11:39:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Mar 2010 08:39:57 -0800 Subject: Interacting With Another Script In-Reply-To: <4dc0cfea1003100834g5d611cdcg63842d385f350fe7@mail.gmail.com> References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> <50697b2c1003100831l302a84e2j1aeaf351dd4e1fe6@mail.gmail.com> <4dc0cfea1003100834g5d611cdcg63842d385f350fe7@mail.gmail.com> Message-ID: <50697b2c1003100839w5dc9a63fo5702ef1e842f40da@mail.gmail.com> On Wed, Mar 10, 2010 at 8:34 AM, Victor Subervi wrote: > On Wed, Mar 10, 2010 at 12:31 PM, Chris Rebert wrote: >> Option C. The most user-friendly, and in some sense simplest, one. >> Figure out the "conversation tree" vpopmail follows. Create a matching >> form tree workflow, presenting multiple input fields at once. Run >> vpopmail and write the appropriate input to its stdin based on the >> form data. Send the output back as a webpage. > > Yeah, that was my idea. But how does the program know when it's being > prompted to enter data? That's my question ;) There's no magical "prompt time". The process's stdin's openness to writing is not conditional. Just send it all the input at once with the proper newlines in place and it should work just fine assuming the user input was valid (barring vpopmail using some fancy terminal input malarkey like curses). Cheers, Chris -- http://blog.rebertia.com From invalid at invalid.invalid Wed Mar 10 11:44:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Mar 2010 16:44:29 +0000 (UTC) Subject: Interacting With Another Script References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> <50697b2c1003100831l302a84e2j1aeaf351dd4e1fe6@mail.gmail.com> <4dc0cfea1003100834g5d611cdcg63842d385f350fe7@mail.gmail.com> Message-ID: On 2010-03-10, Chris Rebert wrote: > On Wed, Mar 10, 2010 at 8:34 AM, Victor Subervi wrote: > >> Yeah, that was my idea. But how does the program know when it's being >> prompted to enter data? That's my question ;) > > There's no magical "prompt time". That depends on the program. Some programs that prompt for input (particulary username/password) flush stdin before displaying each prompt. I'm not saying the program in question does that... > The process's stdin's openness to writing is not conditional. That doesn't mean that data written prior to the prompt won't be ignore. > Just send it all the input at once with the proper newlines in place > and it should work just fine assuming the user input was valid > (barring vpopmail using some fancy terminal input malarkey like > curses). It's worth trying, but there's a slight chance it won't work. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From chris at simplistix.co.uk Wed Mar 10 11:46:23 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 10 Mar 2010 16:46:23 +0000 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <4B97CCDF.7070802@simplistix.co.uk> kj wrote: > > > Subject line pretty much says it all: is there a book like "Effective > Java" oxymoronic, no? Sorry, couldn't resist ;-) Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From krishna.k.0001 at gmail.com Wed Mar 10 11:47:44 2010 From: krishna.k.0001 at gmail.com (Krishna K) Date: Wed, 10 Mar 2010 08:47:44 -0800 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} In-Reply-To: <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> Message-ID: On Fri, Feb 19, 2010 at 11:27 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Fri, Feb 19, 2010 at 10:36 PM, krishna > wrote: > > I have to manage a couple of dicts with huge dataset (larger than > > feasible with the memory on my system), it basically has a key which > > is a string (actually a tuple converted to a string) and a two item > > list as value, with one element in the list being a count related to > > the key. I have to at the end sort this dictionary by the count. > > > > The platform is linux. I am planning to implement it by setting a > > threshold beyond which I write the data into files (3 columns: 'key > > count some_val' ) and later merge those files (I plan to sort the > > individual files by the key column and walk through the files with one > > pointer per file and merge them; I would add up the counts when > > entries from two files match by key) and sorting using the 'sort' > > command. Thus the bottleneck is the 'sort' command. > > > > Any suggestions, comments? > > > > You should be using BDBs or even something like PostgreSQL. The > indexes there will give you the scalability you need. I doubt you will > be able to write anything that will select, update, insert or delete > data better than what BDBs and PostgreSQL can give you. > > -- > Jonathan Gardner > jgardner at jonathangardner.net Thank you. I tried BDB, it seems to get very very slow as you scale. Thank you, Krishna -------------- next part -------------- An HTML attachment was scrubbed... URL: From phlip2005 at gmail.com Wed Mar 10 11:54:51 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 10 Mar 2010 08:54:51 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: Martin P. Hellwig wrote: > Well even if this statement would be true, I personally think that not > proclaiming something a 'standard' if you are sure that you are not sure > about it, is a virtue. In terms of trying too hard to achieve perfection, am I missing a Python repository similar to the C++ Boost project? All the nice-to- have classes that extend the core of C++ get to live in Boost before the C++ Committee pulls the best ideas off the top and add them to the Standard Library... -- Phlip http://penbird.tumblr.com/ From clp2 at rebertia.com Wed Mar 10 12:15:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Mar 2010 09:15:07 -0800 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <50697b2c1003100915u206aaef9n314503b3cb9d6187@mail.gmail.com> On Wed, Mar 10, 2010 at 8:54 AM, Phlip wrote: > Martin P. Hellwig wrote: >> Well even if this statement would be true, I personally think that not >> proclaiming something a 'standard' if you are sure that you are not sure >> about it, is a virtue. > > In terms of trying too hard to achieve perfection, am I missing a > Python repository similar to the C++ Boost project? All the nice-to- > have classes that extend the core of C++ get to live in Boost before > the C++ Committee pulls the best ideas off the top and add them to the > Standard Library... The next closest thing would probably be the Python Cookbook: http://code.activestate.com/recipes/langs/python/ However, such stuff can also be found as third-party modules. Cheers, Chris -- http://blog.rebertia.com From duncan.booth at invalid.invalid Wed Mar 10 12:26:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Mar 2010 17:26:46 GMT Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> <13c167f4-5e37-48a0-a480-3494c212035c@k5g2000pra.googlegroups.com> Message-ID: Xah Lee wrote: > On Mar 8, 11:14??am, Duncan Booth > wrote: >> Xah Lee wrote: >> > For example, consider, if you are within world's top 100th user of >> > database in terms of database size, such as Google, then it may be >> > that the off-the-shelf tools may be limiting. But how many users >> > really have such massive size of data? >> >> You've totally missed the point. It isn't the size of the data you >> have today that matters, it's the size of data you could have in >> several years > ' >> time. > > so, you saying, in several years, we'd all become the world's top 100 > database users in terms of size, like Google? > No, I'm saying that if you plan to build a business that could grow you should be clear up front how you plan to handle the growth. It's too late if you suddenly discover your platform isn't scalable just when you need to scale it. From duncan.booth at invalid.invalid Wed Mar 10 12:39:27 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Mar 2010 17:39:27 GMT Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Neal Becker wrote: > What I'm trying to do is make a callable whose behavior is switched > based on some criteria that will be fixed for all calls. In my > example, this will ultimately be determined by the setting of a > command line switch. > If you want different behaviour its usually best to use different classes. You can keep all the common behaviour in a base class and just override the __call__ method for the different behaviour. Then use a factory function to decide which class to instantiate or else override __new__ and make the decision there. e.g. >>> class X(object): def __call__(self): return 0 def __new__(cls, i): if i!=0: cls = Y return object.__new__(cls) >>> class Y(X): def __call__(self): return 1 >>> x = X(0) >>> x() 0 >>> y = X(1) >>> y() 1 >>> isinstance(x, X) True >>> isinstance(y, X) True P.S. I don't know what you did in your post but your Followup-To header is pointing to a group on gmane which makes extra work for me replying. Please don't do that. From dickinsm at gmail.com Wed Mar 10 12:47:19 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Mar 2010 09:47:19 -0800 (PST) Subject: Calculating very large exponents in python References: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> Message-ID: On Mar 9, 6:39?am, casevh wrote: > [also replying to Geremy since the OP's message doesn't appear...] > > On Mar 8, 11:05?am, geremy condra wrote: > > > > > > > On Mon, Mar 8, 2010 at 2:15 AM, Fahad Ahmad wrote: > > > Thanks Geremy, > > > > That has been an absolute bump........... GOD i cant sit on my chair, it has > > > worked even on 512 bit number and with no time.......... > > > superb i would say. > > > > lastly, i am using the code below to calculate Largest Prime factor of a > > > number: > > > > print > > > ('''======================================================================= ?========''' > > > ?????? '''????????????? CALCULATE? HIGHEST PRIME > > > FACTOR????????????????????????????????? ''' > > > > '''======================================================================== ?=======''') > > > > #!/usr/bin/env python > > > def highest_prime_factor(n): > > > ?? if isprime(n): > > > ????? return n > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return highest_prime_factor(n/x) > > > def isprime(n): > > > ?? for x in xrange(2,n ** 0.5 + 1): > > > ????? if not n % x: > > > ???????? return False > > > ?? return True > > > if? __name__ == "__main__": > > > ?? import time > > > ?? start = time.time() > > > ?? print highest_prime_factor(1238162376372637826) > > > ?? print time.time() - start > > > > the code works with a bit of delay on the number : "1238162376372637826" but > > > extending it to > > > (10902610991329142436630551158108608965062811746392577675456004845499113044 ?30471090261099132914243663055115810860896506281174639257767545600484549911 3?0443047) > > > ?makes python go crazy. Is there any way just like above, i can have it > > > calculated it in no time. > > > > thanks for the support. > > > If you're just looking for the largest prime factor I would suggest using > > a fermat factorization attack. In the example you gave, it returns > > nearly immediately. > > > Geremy Condra- Hide quoted text - > > > - Show quoted text - > > For a Python-based solution, you might want to look at pyecm (http:// > sourceforge.net/projects/pyecm/) > > On a system with gmpy installed also, pyecm found the following > factors: > > 101, 521, 3121, 9901, 36479, 300623, 53397071018461, > 1900381976777332243781 > > There still is a 98 digit unfactored composite: > > 602525071745682437589111511878284384468144476539868422797968232621651594065 00174226172705680274911 > > Factoring this remaining composite using ECM may not be practical. > > casevh The complete factorization is: 101 x 521 x 3121 x 9901 x 36479 x 300623 x 53397071018461 x 1900381976777332243781 x 6060517860310398033985611921721 x 9941808367425935774306988776021629111399536914790551022447994642391 It helps if you notice that the digits of the original 156-digit number come from concatenating a 78-digit string to itself, giving an immediate factor of 10**78 + 1. (Oops. Perhaps this was supposed to be a secret back door to the OP's crypto scheme. I've given it away now. :)) -- Mark From barry at python.org Wed Mar 10 12:50:10 2010 From: barry at python.org (Barry Warsaw) Date: Wed, 10 Mar 2010 12:50:10 -0500 Subject: Python 2.6.5 release candidate 2 now available Message-ID: <20100310125010.415f838e@heresy.wooz.org> Hi everyone, The source tarballs and Windows installer for Python 2.6.5 release candidate 2 are now available: http://www.python.org/download/releases/2.6.5/ As usual, please download, install, and test them with your favorite projects and environments. A number of regressions and build problems on OS X have been fixed since rc1, and I'm really hoping we will not have to do an rc3. I'm currently planning on releasing 2.6.5 final on March 19, 2010. Enjoy, -Barry P.S. The Mac installer will hopefully be available soon. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From dickinsm at gmail.com Wed Mar 10 12:51:23 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Mar 2010 09:51:23 -0800 (PST) Subject: Calculating very large exponents in python References: <90e5f42d-b0d0-4578-82ea-9d0e5770048b@k2g2000pro.googlegroups.com> Message-ID: <9a244983-53ab-4ee5-a176-c67332337c96@15g2000yqi.googlegroups.com> On Mar 9, 1:54?pm, casevh wrote: > After a few hours, the remaining factors are > > 6060517860310398033985611921721 > > and > > 9941808367425935774306988776021629111399536914790551022447994642391 > > casevh Whoops---I missed this. I'm too slow! But at least my answers agree with yours. (Factoring 10**78+1 took around 7 seconds using GP/Pari on a 2.5 GHz MacBook; factoring the remaining quotient n / (10**78+1) was much quicker.) -- Mark From tjreedy at udel.edu Wed Mar 10 12:52:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 12:52:47 -0500 Subject: I passed a fizzbuzz test but failed at recursion. In-Reply-To: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> References: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Message-ID: On 3/10/2010 10:55 AM, Bill wrote: > Look at this recursive fizzbuzz function from > http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html > > def fizzbuzz(num): > if num: > if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' > elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' > elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' In all 3 branches, 'is' should be '=='. As written, this code depends on the implementation treating 0 as a singleton, which CPython does as an optimization, but which the language def does not require. > else : return fizzbuzz(num-1) + ('%d \n' % num) > return '' > print fizzbuzz(100) > > This returns "1 2 fizz 4 ...etc... 97 98 fizz buzz" which is correct. > > However, when I try to decipher the logic of the function I imagine > the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". > > After all, the first num is 100 which decrements by one until a zero > stops the recursive loop. > > My (faulty) reasoning is that fizzbuzz(100) would firstly print a > "fizz" and the last fizzbuzz(1) would finally print a "1". If one reversed the string addition in each branch, it would. As written, the 'word' for n is tacked on at the end. > My logic is wrong, but I don't know why. Is this slightly revised version any clearer? def fizzbuzz_rb(n): if n: previous = fizzbuzz_rb(n-1) word = (not n % 15 and 'fizzbuzz \n' or not n % 5 and 'buzz \n' or not n % 3 and 'fizz \n' or '%d \n' % n) return previous + word else: return '' or this equivalent tail-recursive version? def fizzbuzz_rt(i,n,s): if i <= n: word = (not i % 15 and 'fizzbuzz \n' or not i % 5 and 'buzz \n' or not i % 3 and 'fizz \n' or '%d \n' % i) return fizzbuzz_rt(i+1, n, s+word) else: return s or this equivalent iterative version? def fizzbuzz_it(n): s = '' for i in range(1,n+1): s += (not i % 15 and 'fizzbuzz \n' or not i % 5 and 'buzz \n' or not i % 3 and 'fizz \n' or '%d \n' % i) return s print (fizzbuzz_rb(100) == fizzbuzz_rt(1,100,'') == fizzbuzz_it(100)) # prints True Terry Jan Reedy From ndbecker2 at gmail.com Wed Mar 10 13:23:02 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 13:23:02 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Duncan Booth wrote: ... > > P.S. I don't know what you did in your post but your Followup-To header is > pointing to a group on gmane which makes extra work for me replying. > Please don't do that. I'm sorry about that, there is some bad interaction between gmane's nntp- smtp gateway and python's mail list. I don't know what to do about it. I think the problem only happens on python's mail list (I've never seen it reported on any of the MANY other lists I use via gmane). From duncan.booth at invalid.invalid Wed Mar 10 13:37:59 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Mar 2010 18:37:59 GMT Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Neal Becker wrote: > Duncan Booth wrote: > ... >> >> P.S. I don't know what you did in your post but your Followup-To >> header is pointing to a group on gmane which makes extra work for me >> replying. Please don't do that. > > I'm sorry about that, there is some bad interaction between gmane's > nntp- smtp gateway and python's mail list. I don't know what to do > about it. I think the problem only happens on python's mail list > (I've never seen it reported on any of the MANY other lists I use via > gmane). > Are the other mailing lists gatewayed from Usenet? It may not matter if there's a followup-to header on a mailing list, it probably just gets ignored, but it does matter on Usenet (which after all is what Gmane is emulating). From debatem1 at gmail.com Wed Mar 10 13:49:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 10 Mar 2010 13:49:59 -0500 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} In-Reply-To: References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> Message-ID: On Wed, Mar 10, 2010 at 11:47 AM, Krishna K wrote: > > > On Fri, Feb 19, 2010 at 11:27 PM, Jonathan Gardner > wrote: >> >> On Fri, Feb 19, 2010 at 10:36 PM, krishna >> wrote: >> > I have to manage a couple of dicts with huge dataset (larger than >> > feasible with the memory on my system), it basically has a key which >> > is a string (actually a tuple converted to a string) and a two item >> > list as value, with one element in the list being a count related to >> > the key. I have to at the end sort this dictionary by the count. >> > >> > The platform is linux. I am planning to implement it by setting a >> > threshold beyond which I write the data into files (3 columns: 'key >> > count some_val' ) and later merge those files (I plan to sort the >> > individual files by the key column and walk through the files with one >> > pointer per file and merge them; I would add up the counts when >> > entries from two files match by key) and sorting using the 'sort' >> > command. Thus the bottleneck is the 'sort' command. >> > >> > Any suggestions, comments? >> > >> >> You should be using BDBs or even something like PostgreSQL. The >> indexes there will give you the scalability you need. I doubt you will >> be able to write anything that will select, update, insert or delete >> data better than what BDBs and PostgreSQL can give you. >> >> -- >> Jonathan Gardner >> jgardner at jonathangardner.net > > Thank you. I tried BDB, it seems to get very very slow as you scale. > > Thank you, > Krishna Have you tried any of the big key-value store systems, like couchdb etc? Geremy Condra From mrkafk at gmail.com Wed Mar 10 13:58:07 2010 From: mrkafk at gmail.com (mk) Date: Wed, 10 Mar 2010 19:58:07 +0100 Subject: Text mining in Python Message-ID: Hello everyone, I need to do the following: (0. transform words in a document into word roots) 1. analyze a set of documents to see which words are highly frequent 2. detect clusters of those highly frequent words 3. map the clusters to some "special" keywords 4. rank the documents on clusters and "top n" most frequent words 5. provide search that would rank documents according to whether search words were "special" cluster keywords or frequent words Is there some good open source engine out there that would be suitable to the task at hand? Anybody has experience with them? Now, I do now about NLTK and Python bindings to UIMA. The thing is, I do not know if those are good for the above task. If somebody has experience with those or other and would be able to say if they're good for this, please post. Regards, mk From robert.kern at gmail.com Wed Mar 10 14:05:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 13:05:38 -0600 Subject: Text mining in Python In-Reply-To: References: Message-ID: On 2010-03-10 12:58 PM, mk wrote: > Hello everyone, > > I need to do the following: > > (0. transform words in a document into word roots) > > 1. analyze a set of documents to see which words are highly frequent > > 2. detect clusters of those highly frequent words > > 3. map the clusters to some "special" keywords > > 4. rank the documents on clusters and "top n" most frequent words > > 5. provide search that would rank documents according to whether search > words were "special" cluster keywords or frequent words > > Is there some good open source engine out there that would be suitable > to the task at hand? Anybody has experience with them? You can probably do most of this with Whoosh: http://whoosh.ca/ -- 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 From steve at holdenweb.com Wed Mar 10 14:06:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Mar 2010 14:06:05 -0500 Subject: Down casting Python objects In-Reply-To: <7659cab31003100531i51749f7er6f23ca0ef59cdddf@mail.gmail.com> References: <7659cab31003091326i6f3ab6bta3b8f5948ab7b0ff@mail.gmail.com> <41B1429F-57E8-4F58-883E-03F20FA9A635@gmail.com> <7659cab31003100531i51749f7er6f23ca0ef59cdddf@mail.gmail.com> Message-ID: Andrey Fedorov wrote: > On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury > > wrote: > > Could you tell us *why* you need to down-cast x? Explicit > type-casting is usually unnecessary in Python... > > > Sure! It's related to the longer question I unwisely asked during PyCon > [1] (when no one had time to read it, I suppose). > > I have a couple of different flavors of request objects which I'd like > to make conform to a single interface. So Request `x' come in, I > determine which kind of request I'm dealing with, and would like to > "down-cast" it to ARequest or BRequest, classes which will provide > appropriate accessor properties for the rest of the code to use. > > An option clearly in line with Python's docs might be for `x' to be an > attribute of an ARequest instance, but that would complicate the code of > ARequest. What I'm looking for is a way of adding mix-in's at runtime, > if that makes sense. > The technique you need is not inheritance (which you are really trying to abuse here, IMHO) but delegation. Since all requests start out as of the same type, why not just give each request a handler attribute and set it to a BarHandler or FooHandler instance as appropriate. Then your generic code can call the handler's methods, obtaining Foo- or Bar-style behavior as appropriate. If the handler needs to manipulate the request object then the request object can pass itself in as a method argument. Technically your requests are delegating the handling to a subsidiary object which implements the correct behavior for the request type. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tack at urandom.ca Wed Mar 10 14:31:56 2010 From: tack at urandom.ca (Jason Tackaberry) Date: Wed, 10 Mar 2010 14:31:56 -0500 Subject: Text mining in Python In-Reply-To: References: Message-ID: <1268249516.5238.779.camel@arrakis> On Wed, 2010-03-10 at 19:58 +0100, mk wrote: > I need to do the following: [...] > Is there some good open source engine out there that would be suitable > to the task at hand? Anybody has experience with them? It sounds like a full text search engine might do a bit more than you need, but based on what you described, should also be sufficient. I highly recommend Xapian (xapian.org). It has feature-complete Python bindings, it's very well designed, and its performance is fantastic. Xapian supports stemmers for most major languages (except for Asian languages, unfortunately). Cheers, Jason. From ndbecker2 at gmail.com Wed Mar 10 14:42:39 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 14:42:39 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Duncan Booth wrote: > Neal Becker wrote: > >> Duncan Booth wrote: >> ... >>> >>> P.S. I don't know what you did in your post but your Followup-To >>> header is pointing to a group on gmane which makes extra work for me >>> replying. Please don't do that. >> >> I'm sorry about that, there is some bad interaction between gmane's >> nntp- smtp gateway and python's mail list. I don't know what to do >> about it. I think the problem only happens on python's mail list >> (I've never seen it reported on any of the MANY other lists I use via >> gmane). >> > Are the other mailing lists gatewayed from Usenet? It may not matter if > there's a followup-to header on a mailing list, it probably just gets > ignored, but it does matter on Usenet (which after all is what Gmane is > emulating). For the record, it isn't really gatewayed to usenet - it's just allowing you to read your favorite ML via nntp - which is MUCH more sensible than actually having all that mail delivered personally to you, if you read a lot of lists. From jcb at iteris.com Wed Mar 10 15:03:35 2010 From: jcb at iteris.com (Metalone) Date: Wed, 10 Mar 2010 12:03:35 -0800 (PST) Subject: file seek is slow References: Message-ID: f1_seek = f1.seek did not change the performance at all. As it turns out each call is only 646 nanoseconds slower than 'C'. However, that is still 80% of the time to perform a file seek, which I would think is a relatively slow operation compared to just making a system call. From jcb at iteris.com Wed Mar 10 15:04:28 2010 From: jcb at iteris.com (Metalone) Date: Wed, 10 Mar 2010 12:04:28 -0800 (PST) Subject: file seek is slow References: Message-ID: Thanks, Tim. Good to know. From robert.kern at gmail.com Wed Mar 10 15:06:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 14:06:34 -0600 Subject: Can't define __call__ within __init__? In-Reply-To: References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: On 2010-03-10 13:42 PM, Neal Becker wrote: > Duncan Booth wrote: > >> Neal Becker wrote: >> >>> Duncan Booth wrote: >>> ... >>>> >>>> P.S. I don't know what you did in your post but your Followup-To >>>> header is pointing to a group on gmane which makes extra work for me >>>> replying. Please don't do that. >>> >>> I'm sorry about that, there is some bad interaction between gmane's >>> nntp- smtp gateway and python's mail list. I don't know what to do >>> about it. I think the problem only happens on python's mail list >>> (I've never seen it reported on any of the MANY other lists I use via >>> gmane). >>> >> Are the other mailing lists gatewayed from Usenet? It may not matter if >> there's a followup-to header on a mailing list, it probably just gets >> ignored, but it does matter on Usenet (which after all is what Gmane is >> emulating). > > For the record, it isn't really gatewayed to usenet - it's just allowing you > to read your favorite ML via nntp - which is MUCH more sensible than > actually having all that mail delivered personally to you, if you read a lot > of lists. python-list is also gatewayed to the real USENET group comp.lang.python in addition to its GMane gateway. Duncan is reading comp.lang.python from a real USENET server, not via python-list through his email client. Most of the other lists you read via GMane aren't gatewayed to the real USENET, so your Followup-To header never caused a problem for anyone else. -- 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 From robert.kern at gmail.com Wed Mar 10 15:08:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 14:08:38 -0600 Subject: Can't define __call__ within __init__? In-Reply-To: References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: On 2010-03-10 12:23 PM, Neal Becker wrote: > Duncan Booth wrote: > ... >> >> P.S. I don't know what you did in your post but your Followup-To header is >> pointing to a group on gmane which makes extra work for me replying. >> Please don't do that. > > I'm sorry about that, there is some bad interaction between gmane's nntp- > smtp gateway and python's mail list. I don't know what to do about it. I > think the problem only happens on python's mail list (I've never seen it > reported on any of the MANY other lists I use via gmane). I think it may be your news reader adding the Original-Followup-To header. I use Thunderbird 3 to read this list via GMane, too, but my posts do not contain the header. What newsreader are you using? -- 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 From lacrima.maxim at gmail.com Wed Mar 10 15:16:25 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 10 Mar 2010 12:16:25 -0800 (PST) Subject: Can't install ssl for Python2.5 Message-ID: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> Hello! I use Ubuntu 9.10 Karmic Koala. It has Python 2.6 as default installation. And I installed Python 2.5 alongside (for the need of Google AppEngine). But it seems like my Python 2.5 installation lacks ssl support. I can't import ssl and starting appengine server fails with "'module' object has no attribute 'HTTPSHandler'". So I tried to install this: http://pypi.python.org/pypi/ssl/1.15 But it failed with a very strange error: sudo easy_install-2.5 ssl ------------- Searching for ssl Reading http://pypi.python.org/simple/ssl/ Reading http://docs.python.org/dev/library/ssl.html Best match: ssl 1.15 Downloading http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz#md5=81ea8a1175e437b4c769ae65b3290e0c Processing ssl-1.15.tar.gz Running ssl-1.15/setup.py -q bdist_egg --dist-dir /tmp/easy_install- Kd839q/ssl-1.15/egg-dist-tmp-QCIl6J looking for /usr/include/openssl/ssl.h looking for /usr/local/ssl/include/openssl/ssl.h looking for /usr/include/krb5.h looking for /usr/kerberos/include/krb5.h error: Setup script exited with error: SandboxViolation: open('/usr/ local/lib/python2.5/test/test_ssl.py', 'wb') {} The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted. This package cannot be safely installed by EasyInstall, and may not support alternate installation locations even if you run its setup script by hand. Please inform the package's author and the EasyInstall maintainers to find out if a fix or workaround is available. ------------- I don't know how to solve this problem and I am looking forward for help. Thanks in advance. with regards, Maxim. From mail at hellmutweber.de Wed Mar 10 16:23:18 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Wed, 10 Mar 2010 22:23:18 +0100 Subject: logging: local functions ==> loss of lineno Message-ID: <4B980DC6.4050807@hellmutweber.de> Hi Vinay Sajip, I'm very glad discoverd your logging module ;-) (That's what I would have liked 25 years ago when I was working as a technical software developper!) Now I'm writing just some personal tools, I like python and want to use logging on a regular basis. Logging works very well giving the filename and line number of the point where it is called. As long as I use the loggers directly. BUT when I have to wrap the logger call in some other function, I always get file name and line number of the call of the logger inside the wrapping function. Is there a possibility to get this information in this situation too? TIA Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From martin at v.loewis.de Wed Mar 10 16:23:38 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Wed, 10 Mar 2010 22:23:38 +0100 Subject: Can't install ssl for Python2.5 In-Reply-To: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> References: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> Message-ID: > I don't know how to solve this problem and I am looking forward for > help. Try running "python setup.py install" directly, after downloading and unpacking the package. Regards, Martin From ldo at geek-central.gen.new_zealand Wed Mar 10 16:49:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:49:51 +1300 Subject: Knight's tour Warndorff's algorithm problem References: Message-ID: In message , Gabriel Genellina wrote: > Warnsdorff's algorithm is heuristic ... Then it shouldn?t be called an ?algorithm?. From dreadpiratejeff at gmail.com Wed Mar 10 16:52:28 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 10 Mar 2010 16:52:28 -0500 Subject: Ideas for creating processes Message-ID: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> I'm working on a project and thought I'd ask for a suggestion on how to proceed (I've got my own ideas, but I wanted to see if I was on the right track) For now, I've got this: def main(): ## get our list of directories to refresh releases=sys.argv[1:] if len(releases) < 1: print "You need to provide at least one dir to update" sys.exit() ## Lets figure out what there is to update updateDirs = [] for rel in releases: currentDir = os.path.join(homedir, rel) for item in os.listdir(currentDir): updateDirs += [os.path.join(homedir, rel, item)] which returns a list of full pathnames to directories that need to be updated (updates will be carried out by calling rsync or zsync eventually) The directory hierarchy looks like this: /home/user/files /home/user/files/version1 /home/user/files/version1/type1 /home/user/files/version1/type2 /home/user/files/version2 /home/user/files/version2/type1 and the list ends up looking like this: ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] the next thing I need to do is figure out how to update those. the quick and dirty would be (as I'm imagining it at the moment): for path in pathlist: chdir into path execute rsync or zsync but that gets me moving into one dir, updating, then moving into another. What I was wondering about though, is spawning off separate rsync processes to run concurrently (each rsync will hit a different remote dir for each local dir) so I'm trying to figure out a good way to do this: for path in pathlist: kick off an individual rsync|zsync process to update path wait for all child processes to end exit program. I've been looking at subprocess because at the moment, that's all I really know... But is there a better way of kicking off multiple simultaneous processes so I can update all dirs at once instead of one at a time? No, this isn't homework, it's something I'm working on to sync a couple directories of ISO images to grab nightly builds Yes, there are plenty of pre-made scripts out there, but I don't want to even look at those because I figured this would be a good learning experience, and I want to try to solve this as much on my own as I can without just cut and pasting from someone elses program. So, with that said, any ideas on the best way to proceed? I'm going to start looking at ways to use subprocess to do this, or would there be a better way (multi-threading maybe?) Or am I even in the right ballpark? Cheers Jeff From james.harris.1 at googlemail.com Wed Mar 10 16:53:34 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Wed, 10 Mar 2010 13:53:34 -0800 (PST) Subject: Named loops for breaking References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: On 10 Mar, 06:29, "Gabriel Genellina" wrote: > En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein ? > escribi : > > > Basically I'm wondering if there are any plans to implemented named > > loops in Python, so I can tell a break command to break out of a > > specific loop in the case of nested loops. > > See PEP3136 [1] and its rejection note [2] > I think you may find some more discussion in the python-ideas list. > > > Currently I'm using boolean > > flag variables, but I find that very clumsy. I know this idea of > > breaking out of specific loops from javascript; I guess java does it > > too. It just seems a very Pythonian idea to me: clear, promotes code > > legibility, seems obvious. > > Although I've occasionally missed the feature myself, I agree with Guido's ? > arguments against it. I don't agree with Guido's second reason in particular. He writes in the link Gabriel provided > [2]http://mail.python.org/pipermail/python-3000/2007-July/ 008663.html G> However, I'm rejecting it on the basis that code so complicated to G> require this feature is very rare. In most cases there are existing G> work-arounds that produce clean code, for example using 'return'. G> While I'm sure there are some (rare) real cases where clarity of the G> code would suffer from a refactoring that makes it possible to use G> return, this is offset by two issues: G> 1. The complexity added to the language, permanently. This affects not G> only all Python implementations, but also every source analysis tool, G> plus of course all documentation for the language. Guido may have a point here about source tools but I don't think the language becomes more complex. If anything it would become more orthogonal - i.e. fewer arbitrary restrictions. And documentation is needed for any change so saying that documentation would need to be updated is an odd reason to reject a change. G> 2. My expectation that the feature will be abused more than it will be G> used right, leading to a net decrease in code clarity (measured across G> all Python code written henceforth). Lazy programmers are everywhere, G> and before you know it you have an incredible mess on your hands of G> unintelligible code. Breaking out of an inner loop is just as natural as breaking out of the immediately enclosing loop. ISTM that if one is allowed the other should be also. > You have several alternatives: refactor the loop ? > into an auxiliary function, use a specific exception, add boolean flags, ? > or repeat the test at the outer levels. (I usually choose the first). The auxiliary function idea (Guido's preference as well as Gabriel's) works but it may require accessing of variables which don't appear in the function interface, and the "return" in that function is no different from the break dropping through multiple levels. Return does exactly that (as well as setting a result value). There are often times when it *is* better to factor out the code to a different function but adding a function just to enable a break from an inner loop doesn't seem to me a good reason. James From ldo at geek-central.gen.new_zealand Wed Mar 10 16:56:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:56:19 +1300 Subject: Draft PEP on RSON configuration file format References: <4b8b5cef$0$1625$742ec2ed@news.sonic.net> Message-ID: In message <4b8b5cef$0$1625$742ec2ed at news.sonic.net>, John Nagle wrote: > Patrick Maupin wrote: >> >> Finding .ini configuration files too limiting, JSON and XML to hard to >> manually edit, and YAML too complex to parse quickly, I have started >> work on a new configuration file parser. > > You're not supposed to edit those formats manually. Strange. A previous client of mine was a totally non-IT-technical guy, yet I was able to set him up with editing XML files (needed to drive some software I wrote for him) just fine. Of course he was using a purpose-built editor, namely KXMLEditor. From ldo at geek-central.gen.new_zealand Wed Mar 10 16:57:15 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:57:15 +1300 Subject: Passing FILE * types using ctypes References: <7vbrveFegeU1@mid.individual.net> Message-ID: In message <7vbrveFegeU1 at mid.individual.net>, Gregory Ewing wrote: > If you need the same FILE * that Python is using, you > may need to use ctypes to extract it out of the file > object. Why would Python be using a FILE *? From ldo at geek-central.gen.new_zealand Wed Mar 10 16:58:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Mar 2010 10:58:30 +1300 Subject: Passing FILE * types using ctypes References: Message-ID: In message , Zeeshan Quireshi wrote: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer ... Another option is to fix your library not to use stdio directly. From isso.moh at gmail.com Wed Mar 10 17:03:50 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Wed, 10 Mar 2010 23:03:50 +0100 Subject: show image in python Message-ID: Hey, This is my program 1 #!/usr/bin/python 2 import PIL 3 import numpy 4 import Image 5 import ImageOps 6 import sys 7 8 def Matimg(path): 9 """transforme image en matrice""" 10 Img = Image.open(str(path)) 11 Img1 = ImageOps.grayscale(Img) 12 largeur,hauteur = Img1.size 13 imdata = Img1.getdata() 14 tab = numpy.array(imdata) 15 matrix = numpy.reshape(tab,(hauteur,largeur)) 16 return matrix 17 18 def Creeimg(): 19 """transforme matrice en image""" 20 img = Image.new ("L",(8,8)) 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 22 img.putdata(matrix) 23 img.show() 24 img.save(fp="./ana.bmp") 25 26 if __name__== '__main__': 27 if len(sys.argv) < 2 : 28 print "Usage: img.py " 29 sys.exit(0) 30 path = sys.argv[1] 31 matrix = Matimg(path) 32 print matrix 33 Creeimg() My probeleme : In line 23 "img.show()" Don't work, normally I show the image but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" it's work WHERE IS THE PROBLEME. I have this error in shell : "(eog:3176): GLib-WARNING **: GError set over the top of a previous GError or uninitialized memory. This indicates a bug in someone's code. You must ensure an error is NULL before it's set. The overwriting error message was: Error in getting image file info " os: ubuntu 9.10 sorry for my english. ;-) -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreadpiratejeff at gmail.com Wed Mar 10 17:04:47 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 10 Mar 2010 17:04:47 -0500 Subject: Ideas for creating processes In-Reply-To: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> Message-ID: <36dec4ff1003101404v402f0b59lf0ac67e4a9c8cc3c@mail.gmail.com> On Wed, Mar 10, 2010 at 16:52, J wrote: > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > ? ?chdir into path > ? ?execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > ? ?kick off an individual rsync|zsync process to update path And now I'm looking at subprocess and I can set shell=True and it will intrepret special characters like & So could I do something like this: for item in pathlist: subprocess.Popen('rsync command &', shell=True) and simply wait unti they are all done? From robert.kern at gmail.com Wed Mar 10 17:05:45 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 16:05:45 -0600 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: On 2010-03-10 15:49 PM, Lawrence D'Oliveiro wrote: > In message, Gabriel > Genellina wrote: > >> Warnsdorff's algorithm is heuristic ... > > Then it shouldn?t be called an ?algorithm?. There are lots of algorithms that use heuristics or are heuristics. The two are orthogonal concepts. -- 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 From robert.kern at gmail.com Wed Mar 10 17:09:26 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Mar 2010 16:09:26 -0600 Subject: Passing FILE * types using ctypes In-Reply-To: References: <7vbrveFegeU1@mid.individual.net> Message-ID: On 2010-03-10 15:57 PM, Lawrence D'Oliveiro wrote: > In message<7vbrveFegeU1 at mid.individual.net>, Gregory Ewing wrote: > >> If you need the same FILE * that Python is using, you >> may need to use ctypes to extract it out of the file >> object. > > Why would Python be using a FILE *? In Python 2.x, Python's file objects use a stdio FILE* pointer underneath. The I/O subsystem was rewritten in Python 3.x to use only file descriptors. -- 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 From invalid at invalid.invalid Wed Mar 10 17:09:58 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Mar 2010 22:09:58 +0000 (UTC) Subject: Knight's tour Warndorff's algorithm problem References: Message-ID: On 2010-03-10, Lawrence D'Oliveiro wrote: > In message , Gabriel > Genellina wrote: > >> Warnsdorff's algorithm is heuristic ... > > Then it shouldn???t be called an ???algorithm???. Why? An algorithm is just a well-defined series of steps. Just because it uses heuristics doesn't mean it's not an algorithm. In my book it's still an algorithm even if it never produces a correct result. It's just not a very _good_ algorithm. :) -- Grant Edwards grant.b.edwards Yow! YOU PICKED KARL at MALDEN'S NOSE!! gmail.com From xahlee at gmail.com Wed Mar 10 17:36:58 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 10 Mar 2010 14:36:58 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> <13c167f4-5e37-48a0-a480-3494c212035c@k5g2000pra.googlegroups.com> Message-ID: <06323935-e1a0-4447-b4d8-f62bf94dfb40@e19g2000prn.googlegroups.com> On Mar 10, 9:26?am, Duncan Booth wrote: > No, I'm saying that if you plan to build a business that could grow you > should be clear up front how you plan to handle the growth. It's too late > if you suddenly discover your platform isn't scalable just when you need to > scale it. Right, but that doesn't seems to have any relevance about my point. Many says that scalability is key to NoSQL, i pointed out that unless you are like google, or ranked top 1000 in the world in terms data size, the scalability reason isn't that strong. Xah Lee wrote: > many people mentioned scalibility... though i think it is fruitful to > talk about at what size is the NoSQL databases offer better > scalability than SQL databases. > > For example, consider, if you are within world's top 100th user of > database in terms of database size, such as Google, then it may be > that the off-the-shelf tools may be limiting. But how many users > really have such massive size of data? note that google's need for > database today isn't just a seach engine. > > It's db size for google search is probably larger than all the rest of > search engine company's sizes combined. Plus, there's youtube (vid > hosting), gmail, google code (source code hosting), google blog, orkut > (social networking), picasa (photo hosting), etc, each are all ranked > within top 5 or so with respective competitors in terms of number of > accounts... so, google's datasize is probably number one among the > world's user of databases, probably double or triple than the second > user with the most large datasize. At that point, it seems logical > that they need their own db, relational or not. Xah ? http://xahlee.org/ ? From alfps at start.no Wed Mar 10 17:53:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Mar 2010 23:53:09 +0100 Subject: Named loops for breaking In-Reply-To: References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: * James Harris: > On 10 Mar, 06:29, "Gabriel Genellina" wrote: >> En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein >> escribi : >> >>> Basically I'm wondering if there are any plans to implemented named >>> loops in Python, so I can tell a break command to break out of a >>> specific loop in the case of nested loops. >> See PEP3136 [1] and its rejection note [2] >> I think you may find some more discussion in the python-ideas list. >> >>> Currently I'm using boolean >>> flag variables, but I find that very clumsy. I know this idea of >>> breaking out of specific loops from javascript; I guess java does it >>> too. It just seems a very Pythonian idea to me: clear, promotes code >>> legibility, seems obvious. >> Although I've occasionally missed the feature myself, I agree with Guido's >> arguments against it. > > I don't agree with Guido's second reason in particular. He writes in > the link Gabriel provided > > > [2]http://mail.python.org/pipermail/python-3000/2007-July/ > 008663.html > > G> However, I'm rejecting it on the basis that code so complicated to > G> require this feature is very rare. In most cases there are existing > G> work-arounds that produce clean code, for example using 'return'. > G> While I'm sure there are some (rare) real cases where clarity of > the > G> code would suffer from a refactoring that makes it possible to use > G> return, this is offset by two issues: > > G> 1. The complexity added to the language, permanently. This affects > not > G> only all Python implementations, but also every source analysis > tool, > G> plus of course all documentation for the language. > > Guido may have a point here about source tools but I don't think the > language becomes more complex. If anything it would become more > orthogonal - i.e. fewer arbitrary restrictions. And documentation is > needed for any change so saying that documentation would need to be > updated is an odd reason to reject a change. > > G> 2. My expectation that the feature will be abused more than it will > be > G> used right, leading to a net decrease in code clarity (measured > across > G> all Python code written henceforth). Lazy programmers are > everywhere, > G> and before you know it you have an incredible mess on your hands of > G> unintelligible code. > > Breaking out of an inner loop is just as natural as breaking out of > the immediately enclosing loop. ISTM that if one is allowed the other > should be also. > >> You have several alternatives: refactor the loop >> into an auxiliary function, use a specific exception, add boolean flags, >> or repeat the test at the outer levels. (I usually choose the first). > > The auxiliary function idea (Guido's preference as well as Gabriel's) > works but it may require accessing of variables which don't appear in > the function interface, and the "return" in that function is no > different from the break dropping through multiple levels. Return does > exactly that (as well as setting a result value). > > There are often times when it *is* better to factor out the code to a > different function but adding a function just to enable a break from > an inner loop doesn't seem to me a good reason. Gabriel Genellina mentioned these alternatives: "refactor the loop into an auxiliary function, use a specific exception, add boolean flags, or repeat the test at the outer levels. (I usually choose the first)" And I agree, but in Python there is at least one more very practical alternative, namely /flatting/ the nested loops, representing them as a single loop. It can go like this -- very artifical construed example: from __future__ import print_function try: range = xrange except: pass def inclusive_range( first, last ): return range( first, last + 1 ) def xy_range( x_range, y_range ): for x in x_range: for y in y_range: yield (x, y) def main(): needle = 42 x_range = inclusive_range( 1, 10 ) y_range = inclusive_range( 1, 10 ) pos = None for (x, y) in xy_range( x_range, y_range ): if x*y == needle: pos = (x, y) break if pos is None: print( "Sorry, {0} not found.".format( needle ) ) else: print( "{0} found at {1}.".format( needle, pos ) ) main() Cheers & hth., - Alf PS: Gabriel, if you read this and don't understand it (as you mentioned in another thread that you never understand my postings), please just ask! From martin.hellwig at dcuktec.org Wed Mar 10 17:55:25 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Mar 2010 22:55:25 +0000 Subject: Ideas for creating processes In-Reply-To: References: Message-ID: On 03/10/10 21:52, J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) Well I can't speak with authority but I would go into similar lines, especially since you want to call an external program in the end anyway. Otherwise threading might have been an option. Just make sure that all subprocesses are exited nicely before you are on the end of your script ;-) -- mph From nyamatongwe+thunder at gmail.com Wed Mar 10 18:01:05 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 10 Mar 2010 23:01:05 GMT Subject: file seek is slow In-Reply-To: References: Message-ID: Metalone: > As it turns out each call is only > 646 nanoseconds slower than 'C'. > However, that is still 80% of the time to perform a file seek, > which I would think is a relatively slow operation compared to just > making a system call. A seek may not be doing much beyond setting a current offset value. It is likely that fseek(f1, 0, SEEK_SET) isn't even doing a system call. An implementation of fseek will often return relatively quickly when the position is within the current buffer -- from line 192 in http://www.google.com/codesearch/p?hl=en#XAzRy8oK4zA/libc/stdio/fseek.c&q=fseek&sa=N&cd=1&ct=rc Neil From python at mrabarnett.plus.com Wed Mar 10 18:03:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Mar 2010 23:03:17 +0000 Subject: Ideas for creating processes In-Reply-To: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> Message-ID: <4B982535.4080000@mrabarnett.plus.com> J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) > > For now, I've got this: > > def main(): > ## get our list of directories to refresh > releases=sys.argv[1:] > if len(releases) < 1: > print "You need to provide at least one dir to update" > sys.exit() > > ## Lets figure out what there is to update > updateDirs = [] > for rel in releases: > currentDir = os.path.join(homedir, rel) > for item in os.listdir(currentDir): > updateDirs += [os.path.join(homedir, rel, item)] > > which returns a list of full pathnames to directories that need to be > updated (updates will be carried out by calling rsync or zsync > eventually) > > The directory hierarchy looks like this: > > /home/user/files > /home/user/files/version1 > /home/user/files/version1/type1 > /home/user/files/version1/type2 > /home/user/files/version2 > /home/user/files/version2/type1 > > and the list ends up looking like this: > > ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] > > the next thing I need to do is figure out how to update those. > > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > chdir into path > execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > kick off an individual rsync|zsync process to update path > > wait for all child processes to end > exit program. > > I've been looking at subprocess because at the moment, that's all I > really know... > But is there a better way of kicking off multiple simultaneous > processes so I can update all dirs at once instead of one at a time? > > No, this isn't homework, it's something I'm working on to sync a > couple directories of ISO images to grab nightly builds > Yes, there are plenty of pre-made scripts out there, but I don't want > to even look at those because I figured this would be a good learning > experience, and I want to try to solve this as much on my own as I can > without just cut and pasting from someone elses program. > > So, with that said, any ideas on the best way to proceed? I'm going > to start looking at ways to use subprocess to do this, or would there > be a better way (multi-threading maybe?) > > Or am I even in the right ballpark? > Are you sure that you would gain from doing more than one at a time? The bottleneck will probably be the speed of your network connection, and if that's working at its maximum speed with one sync then doing several concurrently won't save any time. (The syncs will also be completing for disk I/O.) It might, however, save time if the remote server takes time to respond to a sync and/or doesn't use your network connection at its maximum speed (the server's connection will have its own limits, of course, and might be talking to other computers at the same time). You could increase the number of concurrent syncs until you find the number that gives the best results. From nilly16 at yahoo.com Wed Mar 10 18:06:41 2010 From: nilly16 at yahoo.com (Jimbo) Date: Wed, 10 Mar 2010 15:06:41 -0800 (PST) Subject: Python Script to get Info from Site not working Message-ID: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> Hello I am asking what is probably a very easy thing to do but I cannot find a tutorial on how to do it anywhere. [b]I want to use a Python script to get information from a webpage. [/b] I found a semi Python & internet tutorial here if anyone else would like it http://www.upriss.org.uk/python/session6.html I would like to create a python script that gets a value from a set of radio buttons on a HTML page & tell me which one is selected. I have 3 radio buttons: Tea, Coffee, Hot Chocolate & a Submit button My script is meant to find which radio button is selected & tell me that. But it just keeps saying "No Drink Selected!" Can you help me figure out how to fix this. FYI: My Python script & my HTML page are both saved in the same directory. And I made the webpage using Notepad++, I open the webpage in Interent Explorer & I made the Python Script in Idle. Python Script: [code]# Practice 9 CGI ######### don't change the following three lines: ########### import cgi print("Content-Type: text/html\n") form = cgi.FieldStorage() ## add a form.getvalue for each of the names in your form: ## drink = form.getvalue("drink") ########## start of HTML code ########### print(""" What would you like to drink

Your drink:

""") ############ end of HTML code ############# if drink == "tea": print("You requested tea.") elif drink == "coffee": print("You requested coffee.") elif drink == "hot chocolate": print ("You requested hot chocolate.") else: print ("You need to select a drink!") ########### start of HTML code ########### print ("""

Thank you for your visit. Please come again.

""") ############# end of HTML code ############## [/code] HTML Code: [code] Tea
Coffee
Hot Chocolate

[/code] From news1234 at free.fr Wed Mar 10 18:17:19 2010 From: news1234 at free.fr (News123) Date: Thu, 11 Mar 2010 00:17:19 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b957866$0$17135$426a34cc@news.free.fr> Message-ID: <4B98287F.2010101@free.fr> Hi JM, Jean-Michel Pichavant wrote: > News123 wrote: >> Jean-Michel Pichavant wrote: >> >>> Johny wrote: >>> >>>> I have this directory structure >>>> >>>> C: >>>> \A >>>> __init__.py >>>> amodule.py >>>> >>>> \B >>>> __init__.py >>>> bmodule.py >>>> >>>> \D >>>> __init__.py >>>> dmodule.py >>>> >>>> and I want to import bmodule.py >>>> C:\>cd \ >>>> >>>> C:\>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> from A.B import bmodule >>>>>>> >>>> I am bmodule >>>> C:\> >>>> >>>> so far so good. Now I would like to import bmodule but if the current >>>> directory is \D subdirectory. >>>> >>>> C:> cd \A\B\D >>>> C:\A\B\D> >>>> C:\A\B\D>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> import sys >>>>>>> sys.path.append('C:\\A') >>>>>>> from A.B import bmodule >>>>>>> >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> ImportError: No module named A.B >>>> >>>> C:\> >>>> >>>> so I can not import a module from the parent directory? Or where did I >>>> make an error? >>>> Thanks for help >>>> >>>> L. >>>> >>> try >>> >>> import sys >>> sys.path.append('C:\\') >>> from A.B import bmodule >>> >>> >> is there any 'automatic' way of finding the top level >> directory?basically the 'top level directory is the first directory >> going upwards, that doesn't contain a __init__.py file. >> > what if some user has an __init__.py file the top level directory of > your package ? Is there any other usage of __init.py__ than indicating a module directory? I wasn't aware of it, but you're right I did not investigte in depth and users can of course do whatever they like. >> of course you could do this 'manually' by >> doing: >> >> # assume, that this module is A.amodule >> import sys >> import os >> >> # I'd love to have a similiar automatic construct >> if __name__ == "__main__": >> level = 1 # or function locating how far to go up before >> # finding a dir, whcih does not contain a __init__.py >> mydir = os.path.split(__file__)[0] >> topdir = os.path.join( mydir,*(("..",)*level)) >> abstop = os.path.abspath(topdir) >> sys.path.append(abstop) >> >> ## now you can import with the normal module paths >> >> import A.blo >> print "and I found blo",dir(A.blo) >> >> > You don't want to do that and you don't need it neither. That's what the > env variable PYTHONPATH is for. set it correctly, install your package > inside and everything works just fine (+standard). With a linux OS it > easy to create smb links to point to any working directory. It should be > possible on windows as well. I like your idea with the symlinks. However not sure how to do it with windows. I assume default shortcuts won't do. > > If your package is meant to be destributed, you may use setup.py > > Well, It's nice if a user just unpacks a zip file and can click on any script with the .py suffix in the tree. (Its nice for example for tutorials / demos ) It's also nice if he can later on just delete the unpacked directory and there will be no trace left in the registry or in the python base dir. This is why I'm interested in solutions without setup.py or changing environment variables. bye N From news1234 at free.fr Wed Mar 10 18:18:05 2010 From: news1234 at free.fr (News123) Date: Thu, 11 Mar 2010 00:18:05 +0100 Subject: Import problem In-Reply-To: References: <6630f859-b85d-4841-b1d5-2a563dca9cbb@q15g2000yqj.googlegroups.com> <4b957866$0$17135$426a34cc@news.free.fr> Message-ID: <4b9828ad$0$698$426a74cc@news.free.fr> Hi JM, Jean-Michel Pichavant wrote: > News123 wrote: >> Jean-Michel Pichavant wrote: >> >>> Johny wrote: >>> >>>> I have this directory structure >>>> >>>> C: >>>> \A >>>> __init__.py >>>> amodule.py >>>> >>>> \B >>>> __init__.py >>>> bmodule.py >>>> >>>> \D >>>> __init__.py >>>> dmodule.py >>>> >>>> and I want to import bmodule.py >>>> C:\>cd \ >>>> >>>> C:\>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> from A.B import bmodule >>>>>>> >>>> I am bmodule >>>> C:\> >>>> >>>> so far so good. Now I would like to import bmodule but if the current >>>> directory is \D subdirectory. >>>> >>>> C:> cd \A\B\D >>>> C:\A\B\D> >>>> C:\A\B\D>python >>>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit >>>> (Intel)] on win >>>> 32 >>>> Type "help", "copyright", "credits" or "license" for more information. >>>> >>>> >>>>>>> import sys >>>>>>> sys.path.append('C:\\A') >>>>>>> from A.B import bmodule >>>>>>> >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> ImportError: No module named A.B >>>> >>>> C:\> >>>> >>>> so I can not import a module from the parent directory? Or where did I >>>> make an error? >>>> Thanks for help >>>> >>>> L. >>>> >>> try >>> >>> import sys >>> sys.path.append('C:\\') >>> from A.B import bmodule >>> >>> >> is there any 'automatic' way of finding the top level >> directory?basically the 'top level directory is the first directory >> going upwards, that doesn't contain a __init__.py file. >> > what if some user has an __init__.py file the top level directory of > your package ? Is there any other usage of __init.py__ than indicating a module directory? I wasn't aware of it, but you're right I did not investigte in depth and users can of course do whatever they like. >> of course you could do this 'manually' by >> doing: >> >> # assume, that this module is A.amodule >> import sys >> import os >> >> # I'd love to have a similiar automatic construct >> if __name__ == "__main__": >> level = 1 # or function locating how far to go up before >> # finding a dir, whcih does not contain a __init__.py >> mydir = os.path.split(__file__)[0] >> topdir = os.path.join( mydir,*(("..",)*level)) >> abstop = os.path.abspath(topdir) >> sys.path.append(abstop) >> >> ## now you can import with the normal module paths >> >> import A.blo >> print "and I found blo",dir(A.blo) >> >> > You don't want to do that and you don't need it neither. That's what the > env variable PYTHONPATH is for. set it correctly, install your package > inside and everything works just fine (+standard). With a linux OS it > easy to create smb links to point to any working directory. It should be > possible on windows as well. I like your idea with the symlinks. However not sure how to do it with windows. I assume default shortcuts won't do. > > If your package is meant to be destributed, you may use setup.py > > Well, It's nice if a user just unpacks a zip file and can click on any script with the .py suffix in the tree. (Its nice for example for tutorials / demos ) It's also nice if he can later on just delete the unpacked directory and there will be no trace left in the registry or in the python base dir. This is why I'm interested in solutions without setup.py or changing environment variables. bye N From ndbecker2 at gmail.com Wed Mar 10 18:38:10 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 10 Mar 2010 18:38:10 -0500 Subject: Can't define __call__ within __init__? References: <8c7f10c61003100527o7c7f9375ie662ce67ab78f1de@mail.gmail.com> Message-ID: Robert Kern wrote: > On 2010-03-10 12:23 PM, Neal Becker wrote: >> Duncan Booth wrote: >> ... >>> >>> P.S. I don't know what you did in your post but your Followup-To header >>> is pointing to a group on gmane which makes extra work for me replying. >>> Please don't do that. >> >> I'm sorry about that, there is some bad interaction between gmane's nntp- >> smtp gateway and python's mail list. I don't know what to do about it. >> I think the problem only happens on python's mail list (I've never seen >> it reported on any of the MANY other lists I use via gmane). > > I think it may be your news reader adding the Original-Followup-To header. > I use Thunderbird 3 to read this list via GMane, too, but my posts do not > contain the header. What newsreader are you using? > knode. From sjdevnull at yahoo.com Wed Mar 10 18:38:28 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Wed, 10 Mar 2010 15:38:28 -0800 (PST) Subject: file seek is slow References: Message-ID: On Mar 10, 6:01?pm, Neil Hodgson wrote: > Metalone: > > > As it turns out each call is only > > 646 nanoseconds slower than 'C'. > > However, that is still 80% of the time to perform a file seek, > > which I would think is a relatively slow operation compared to just > > making a system call. > > ? ?A seek may not be doing much beyond setting a current offset value. > It is likely that fseek(f1, 0, SEEK_SET) isn't even doing a system call. Exactly. If I replace both calls to fseek with gettimeofday (aka time.time() on my platform in python) I get fairly close results: $ ./testseek 4.120 $ python2.5 testseek.py 4.170 $ ./testseek 4.080 $ python2.5 testseek.py 4.130 FWIW, my results with fseek aren't as bad as those of the OP. This is python2.5 on a 2.6.9 Linux OS, with psyco: $ ./testseek 0.560 $ python2.5 testseek.py 0.750 $ ./testseek 0.570 $ python2.5 testseek.py 0.760 From rbrt.somerville at gmail.com Wed Mar 10 18:48:14 2010 From: rbrt.somerville at gmail.com (robert somerville) Date: Wed, 10 Mar 2010 15:48:14 -0800 Subject: Elementtree install problem in Ubuntu (a newbie ..) Message-ID: <2fb4a5011003101548x862eef2w4f46473bae4bf9f4@mail.gmail.com> Hi ; I installed the elementtree and celementree packages throught the synaptic package manager, all seems to go fine through the install ... when i startup python and try to import them (as per the EFFBOTT.org suggestions) .. PROBLEMS ... (see below ..) What am i doing wrong ??? this is a new window after installation of packages ... Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import elementtree.ElementTree as ET Traceback (most recent call last): File "", line 1, in ImportError: No module named elementtree.ElementTree >>> import elementtree Traceback (most recent call last): File "", line 1, in ImportError: No module named elementtree thanks; Robert somerville -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Wed Mar 10 18:56:08 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 10 Mar 2010 18:56:08 -0500 Subject: Elementtree install problem in Ubuntu (a newbie ..) In-Reply-To: <2fb4a5011003101548x862eef2w4f46473bae4bf9f4@mail.gmail.com> References: <2fb4a5011003101548x862eef2w4f46473bae4bf9f4@mail.gmail.com> Message-ID: On Mar 10, 2010, at 6:48 PM, robert somerville wrote: > Hi ; > I installed the elementtree and celementree packages throught the > synaptic > package manager, all seems to go fine through the install ... > > when i startup python and try to import them (as per the EFFBOTT.org > suggestions) .. PROBLEMS ... (see below ..) What am i doing > wrong ??? this > is a new window after installation of packages ... > > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import elementtree.ElementTree as ET > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named elementtree.ElementTree >>>> import elementtree > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named elementtree Hi Robert, In Python >= 2.5, ElementTree is part the standard library so it doesn't need to be installed separately. Here's the documentation for it: http://www.python.org/doc/2.6.4/library/xml.etree.elementtree.html HTH Philip From genetiq at gmail.com Wed Mar 10 19:05:13 2010 From: genetiq at gmail.com (phantasm) Date: Wed, 10 Mar 2010 16:05:13 -0800 (PST) Subject: Can't install PIL on MacOS X Leopard Message-ID: <94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com> Hello! I'm trying to install PIL module on MacOS X Leopard with python 2.6. Everything seemed to be fine - now I have PIL egg package in "site- packages" directory, but when I'm trying "import PIL", I get an error "ImportError: No module named PIL". All other modules such as SQL Alchemy work fine. Their EGGs reside in a same directory as a resulting PIL package. I've tried to install either via easy_install and manually, results are the same. PYTHONPATH environment variable is set to a correct directory. python command "import _imaging" returns no error. What I'm doing wrong? From rbrt.somerville at gmail.com Wed Mar 10 19:17:29 2010 From: rbrt.somerville at gmail.com (robert somerville) Date: Wed, 10 Mar 2010 16:17:29 -0800 Subject: Python 2.6 and modules dbi AND odbc Message-ID: <2fb4a5011003101617r5518b322y6ccc091046b0ccc4@mail.gmail.com> hi; i am trying to get some legacy python code (which i no nothing about) working with tries to import dbi and odbc (the import fails ...) it looks like these modules are deprecated ?? if so is there a work around , if not deprecated, what am i doing wrong ?? i see no Ubuntu packages that look promising .. Robert Somerville -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Wed Mar 10 19:34:51 2010 From: nad at acm.org (Ned Deily) Date: Wed, 10 Mar 2010 16:34:51 -0800 Subject: Can't install PIL on MacOS X Leopard References: <94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com> Message-ID: In article <94070db2-91f0-47a8-a259-36378aab95ea at o3g2000yqb.googlegroups.com>, phantasm wrote: > I'm trying to install PIL module on MacOS X Leopard with python 2.6. > Everything seemed to be fine - now I have PIL egg package in "site- > packages" directory, but when I'm trying "import PIL", I get an error > "ImportError: No module named PIL". > > All other modules such as SQL Alchemy work fine. Their EGGs reside in > a same directory as a resulting PIL package. > > I've tried to install either via easy_install and manually, results > are the same. PYTHONPATH environment variable is set to a correct > directory. python command "import _imaging" returns no error. > > What I'm doing wrong? Hard to say without more information but it does seem odd that _imaging can be imported. One thing to try: $ python2.6 Python 2.6.4 (r264:75706, Oct 28 2009, 20:34:51) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import _imaging >>> _imaging.__file__ '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-pac kages/PIL/_imaging.so' # or something like that Make sure the file is located within the expected PIL directory. Also make sure there aren't any file permission problems on any of the PIL directories and files. I'm assuming PIL was installed as an unzipped egg. And double-check the contents of any .pth files. -- Ned Deily, nad at acm.org From genetiq at gmail.com Wed Mar 10 19:43:26 2010 From: genetiq at gmail.com (phantasm) Date: Wed, 10 Mar 2010 16:43:26 -0800 (PST) Subject: Can't install PIL on MacOS X Leopard References: <94070db2-91f0-47a8-a259-36378aab95ea@o3g2000yqb.googlegroups.com> Message-ID: Thank you for your reply, Ned, but I just tried to install it again and found out that I didn't finally run "python setup.py install" after building PIL manually. It solved the problem. From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:01 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:01 -0300 Subject: Does this already exists?: A module that checks if the used platform is supported References: Message-ID: En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig escribi?: > Before I start reinventing a squared wheel, I have the following > question: > Is there already a (standard) module that wraps around the various > os/sys information which checks if the platform + version is supported > for what I want to do with it. In case you were not aware of it: see the platform module. But you'll have to do the checks yourself (based on the info it returns). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:08 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:08 -0300 Subject: Importing Modules References: <676034.43316.qm@web30001.mail.mud.yahoo.com> Message-ID: En Wed, 10 Mar 2010 09:19:29 -0300, PEYMAN ASKARI escribi?: > I wanted to know if imported classes are treated differently than > internal classes. If by 'internal classes' you mean 'classes defined in the main module', no, they're absolutely the same. > class A(): > __init__(self): > pass > > and call A, or A() I get something to the effect of <__main__.A > instance at 0xb7f088ac> > > but if I call from module_name import A and then call A or A() I get > something to the effect of Note that both reprs have the same structure. Both say When you execute `python test_import.py`, the code is executed into a newly created module called __main__ (not test_import). So __main__ is the name of the main module, and __main__.A is the full name of the A class defined in the __main__ module. In the other case, module_4.module_4 is the full name of the module_4 class defined in the module_4 module. > I was wondering if this would be a problem. In general, no, you shouldn't care. There is a problem, though, if some other module imports the main one (using `import test_import`). Python knows the main one as "__main__", not as "test_import", so it will load it *again*, and you'll end with two separate copies of the same module. Solution: don't do that :) -- redesign your application so subordinate modules don't have to import the main one (move the required parts into a third module). -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:14 -0300 Subject: Interacting With Another Script References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Message-ID: En Wed, 10 Mar 2010 09:32:15 -0300, Victor Subervi escribi?: > There's a program (vpopmail) that has commands which, when called, > request > input ("email address", "password", etc.) from the command line. I would > like to build a TTW interface for my clients to use that interacts with > these commands. I know nothing about vpopmail, but can't you provide all the required information by some other means? Command line arguments, a configuration file, perhaps there is an API to call some internal functions? Faking an interactive session would be my last option. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:37:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:37:18 -0300 Subject: Method / Functions - What are the differences? References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> <4B97B092.4060901@optimum.net> Message-ID: En Wed, 10 Mar 2010 11:45:38 -0300, John Posner escribi?: > As I promised/threatened, here's the *start* of a write-up on > properties, aimed at non-advanced Python programmers: > > http://www.jjposner.net/media/python-properties-0310.pdf I'd use 'function' instead of 'procedure', as this last word is very uncommon in Python literature (also, "the procedure's return value..." may look very strange to some people). I'm unsure if one should make a distinction 'storage attribute' vs. 'method attribute', or even if it makes things actually more clear. I think you could present the motivating idea first ("I want to execute some code when accessing an attribute") and only later talk about properties and descriptors (as written, the reader still doesn't know how to define a simple property and you've already talked about deleting attributes...) -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Wed Mar 10 20:38:09 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Mar 2010 22:38:09 -0300 Subject: Python Script to get Info from Site not working References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> Message-ID: En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: > I found a semi Python & internet tutorial here if anyone else would > like it http://www.upriss.org.uk/python/session6.html > > My script is meant to find which radio button is selected & tell me > that. But it just keeps saying "No Drink Selected!" Are you sure? From the code you posted, the message should read "You need to select a drink!", not that one. > if drink == "tea": > print("You requested tea.") > elif drink == "coffee": > print("You requested coffee.") > elif drink == "hot chocolate": > print ("You requested hot chocolate.") > else: > print ("You need to select a drink!") Replace the last line with something like this, to see what you are getting exactly: print("Sorry, no %r (%r) available." % ( drink, cgi.escape(repr(type(drink))))) BTW, which Python version are you using? The tutorial you linked to is aimed at Python 2.x, but your print syntax suggests you're using Python 3.x -- Gabriel Genellina From wuwei23 at gmail.com Wed Mar 10 21:16:04 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Mar 2010 18:16:04 -0800 (PST) Subject: Interacting With Another Script References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> Message-ID: <2db4409d-d8d7-4af9-a9a7-e8071bc30b0f@o16g2000prh.googlegroups.com> Victor Subervi wrote: > > There's a program (vpopmail) that has commands which, when called, request > > input ("email address", "password", etc.) from the command line. I would > > like to build a TTW interface for my clients to use that interacts with > > these commands. The Pexpect[1] module is pretty much aimed at doing exactly this. 1: http://www.noah.org/wiki/Pexpect From nilly16 at yahoo.com Wed Mar 10 21:26:05 2010 From: nilly16 at yahoo.com (Jimbo) Date: Wed, 10 Mar 2010 18:26:05 -0800 (PST) Subject: Python Script to get Info from Site not working References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> Message-ID: <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> On Mar 11, 12:38?pm, "Gabriel Genellina" wrote: > En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: > > > I found a semi Python & internet tutorial here if anyone else would > > like ithttp://www.upriss.org.uk/python/session6.html > > > My script is meant to find which radio button is selected & tell me > > that. But it just keeps saying "No Drink Selected!" > > Are you sure? From the code you posted, the message should read "You need ? > to select a drink!", not that one. > Replace the last line with something like this, to see what you are ? > getting exactly: > > ? ? ? ? print("Sorry, no %r (%r) available." % ( > ? ? ? ? ? ?drink, > ? ? ? ? ? ?cgi.escape(repr(type(drink))))) > > BTW, which Python version are you using? The tutorial you linked to is ? > aimed at Python 2.x, but your print syntax suggests you're using Python 3.x > > -- > Gabriel Genellina Yeah that("You need to select a drink!") was the string I was getting but I should be getting hot chocolate or something else(which ever one I have selected) I am using 3.x, do you think I should be using something else? Also the your code I put in does the some thing, just now it says "Sorry no none drink available" all the time. From dreadpiratejeff at gmail.com Wed Mar 10 21:52:19 2010 From: dreadpiratejeff at gmail.com (J) Date: Wed, 10 Mar 2010 21:52:19 -0500 Subject: Ideas for creating processes In-Reply-To: <4B982535.4080000@mrabarnett.plus.com> References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> <4B982535.4080000@mrabarnett.plus.com> Message-ID: <36dec4ff1003101852x1b997d5bg68be4168ce01ce34@mail.gmail.com> On Wed, Mar 10, 2010 at 18:03, MRAB wrote: > Are you sure that you would gain from doing more than one at a time? > > The bottleneck will probably be the speed of your network connection, > and if that's working at its maximum speed with one sync then doing > several concurrently won't save any time. (The syncs will also be > completing for disk I/O.) Good point MRAB... thanks for making it. I started to wonder the same thing, but it took me a couple hours away from working on it and a good dinner before I saw that... Yeah, looking at it freshly now, I agree, I think I probably would be better off running them one at a time. The goal is to update several directories of ISO images with nightly builds. I can use rsync and only download images that are changed, or I can use zsync and only download diffs (I believe that's how it works) which is faster anyway. The only reason I was considering doing them all simultaneously, or in batches at least, is that I have to update 10 - 12 ISOs daily... BUT, now that I look at it from your perspective, yeah, it would probably be faster overall to do them one at a time instead because of the bottleneck. Thanks! That helped a lot (and probably saved me a lot of headache later on) :-) Cheers Jeff From steven at REMOVE.THIS.cybersource.com.au Wed Mar 10 22:18:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Mar 2010 03:18:47 GMT Subject: Can't define __call__ within __init__? References: Message-ID: On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > Want to switch __call__ behavior. Why doesn't this work? What is the > correct way to write this? > > class X (object): > def __init__(self, i): > if i == 0: > def __call__ (self): > return 0 > else: > def __call_ (self): > return 1 Others have already pointed out that there are two reasons that won't work: (1) you define __call__ as a local variable of the __init__ method which then disappears as soon as the __init__ method completes; and (2) special methods like __call__ are only called on the class, not the instance, so you can't give each instance its own method. Perhaps the best way to solve this is to use delegation: def zero_returner(): return 0 def one_returner(): return 1 class X (object): def __init__(self, i): if i == 0: self.func = zero_returner else: self.func = one_returner def __call__(self, *args, **kwargs): return self.func(*args, **kwargs) zero_returner and one_returner can be any callable object, not necessarily a function. Of course, all this assumes that your solution isn't even simpler: class X (object): def __init__(self, i): self.i = i def __call__(self): return self.i but I assume if it was that simple, you would have done that already. -- Steven From tjreedy at udel.edu Wed Mar 10 23:44:49 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Mar 2010 23:44:49 -0500 Subject: Knight's tour Warndorff's algorithm problem In-Reply-To: References: Message-ID: On 3/10/2010 4:49 PM, Lawrence D'Oliveiro wrote: > In message, Gabriel > Genellina wrote: > >> Warnsdorff's algorithm is heuristic ... > > Then it shouldn?t be called an ?algorithm?. Heuristic algorithms correctly compute some function, just not the one you want ;-). From radhakrishna12 at gmail.com Wed Mar 10 23:47:30 2010 From: radhakrishna12 at gmail.com (Radhakrishna Bhat) Date: Thu, 11 Mar 2010 10:17:30 +0530 Subject: Get a method instance through 'getattr' but not superclass's method Message-ID: I am using getattr to get a method instance from a class. But it also returns methods from the superclass. How to detect if an attribute is from superclass? -Radhakrishna -------------- next part -------------- An HTML attachment was scrubbed... URL: From efiish at gmail.com Wed Mar 10 23:56:48 2010 From: efiish at gmail.com (Lan Qing) Date: Thu, 11 Mar 2010 12:56:48 +0800 Subject: a newbie's question In-Reply-To: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> References: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> Message-ID: hi Cheers, Think you, that helps me a lot. On Tue, Mar 9, 2010 at 10:00 PM, Simon Brunning wrote: > On 9 March 2010 13:51, Lan Qing wrote: > > Hi all, > > I'm a newbie of python programming language. > > Welcome! > > > I have used c/c++ for 5 > > years, and one year experience in Lua programming language. Can any one > give > > me some advice on learning python. Think you for any help!! > > You'll find some useful starting points here - > . > > -- > Cheers, > Simon B. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Thu Mar 11 00:28:01 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 11 Mar 2010 10:58:01 +0530 Subject: a newbie's question In-Reply-To: References: <8c7f10c61003090600u692bfd8sdc287a73425ed47e@mail.gmail.com> Message-ID: Python is one language which is quite easy to get grasp of. one week and you'll start doing productive stuff. Best of luck on your quest. On Thu, Mar 11, 2010 at 10:26 AM, Lan Qing wrote: > hi Cheers, > Think you, that helps me a lot. > > > On Tue, Mar 9, 2010 at 10:00 PM, Simon Brunning wrote: > >> On 9 March 2010 13:51, Lan Qing wrote: >> > Hi all, >> > I'm a newbie of python programming language. >> >> Welcome! >> >> > I have used c/c++ for 5 >> > years, and one year experience in Lua programming language. Can any one >> give >> > me some advice on learning python. Think you for any help!! >> >> You'll find some useful starting points here - >> . >> >> -- >> Cheers, >> Simon B. >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sivaits4u at gmail.com Thu Mar 11 00:40:14 2010 From: sivaits4u at gmail.com (Bujji) Date: Thu, 11 Mar 2010 11:10:14 +0530 Subject: use of multiple versions of python Message-ID: <581ce2791003102140t7fd470e5obcad20ec714f60f3@mail.gmail.com> hi all, I have installed python 2.6 in addition to python 2.5 in my system Now for some modules(while installing ) it needs to use python 2.6 how can i do that in case of easy_install what should i do to it to use python 2.6 from my understanding /usr/bin/python is the one which will be taking care of version. but with this only one version of python can run even though we have tow versions. please post some solution for my problem. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lacrima.maxim at gmail.com Thu Mar 11 00:48:45 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 10 Mar 2010 21:48:45 -0800 (PST) Subject: Can't install ssl for Python2.5 References: <3c0d84fc-1975-4937-9b65-88535e699999@u9g2000yqb.googlegroups.com> Message-ID: On Mar 10, 11:23?pm, "Martin v. Loewis" wrote: > > I don't know how to solve this problem and I am looking forward for > > help. > > Try running "python setup.py install" directly, after downloading and > unpacking the package. > > Regards, > Martin Thanks a lot! It helped! From richardbp at gmail.com Thu Mar 11 01:22:56 2010 From: richardbp at gmail.com (Richard) Date: Wed, 10 Mar 2010 22:22:56 -0800 (PST) Subject: os.rename [Errno 31] Too many links References: <253f4908-1cb9-4165-bf01-1d89b39d3b35@k6g2000prg.googlegroups.com> <7vpugdF5bqU1@mid.individual.net> Message-ID: <1082952b-5dc0-4efa-b47f-9ada9aa7980f@x23g2000prd.googlegroups.com> On Mar 11, 3:08?am, Thomas Guettler wrote: > Richard wrote: > > I want to atomically write to a file so have been using temporary > > files and renaming: > > > temp = tempfile.NamedTemporaryFile(delete=False) > > temp.file.write(data) > > temp.file.close() > > os.rename(temp.name, output_file) > > > This worked but after 39567 files os.rename raises an OSError: [Errno > > 31] Too many links > > > I can still create files in this directory so I doubt it is a platform > > limitation. > > Can you tell what is wrong? Am I not freeing the temporary file > > resources properly? > > If you are on linux you can have a look at the open file descriptors of > a running process like this: > > ls -l /proc/PID/fd/ > > But I guess it is a limitation of your filesystem. What do you use? > > I once had this problem with ext2. It has a low limit for > subdirectories. > > With xfs the limits are much greater. > > ? Thomas > > -- > Thomas Guettler,http://www.thomas-guettler.de/ > E-Mail: guettli (*) thomas-guettler + de I am using Ubuntu 9.10 with ext3, which I believe has a limit for the number of subdirectories but not files. Thanks for the open file descriptor tip - I will check that out. Richard From stefan_ml at behnel.de Thu Mar 11 02:53:51 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Mar 2010 08:53:51 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: <4B97CCDF.7070802@simplistix.co.uk> References: <4B97CCDF.7070802@simplistix.co.uk> Message-ID: Chris Withers, 10.03.2010 17:46: > kj wrote: >> Subject line pretty much says it all: is there a book like "Effective >> Java" > > oxymoronic, no? > > Sorry, couldn't resist ;-) Nothing to excuse for. I thought exactly the same thing. Stefan From james.harris.1 at googlemail.com Thu Mar 11 03:30:02 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Thu, 11 Mar 2010 00:30:02 -0800 (PST) Subject: Anything like "Effective Java" for Python? References: Message-ID: <62192fd8-2350-49c5-aeea-c8fe14878a61@d2g2000yqa.googlegroups.com> On 10 Mar, 15:19, kj wrote: > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. ?I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? I don't know about the Java book you mention but I find Python in a Nutshell published by O'Reilly to be a good reference. James From stava at telcotec.se Thu Mar 11 03:43:50 2010 From: stava at telcotec.se (Lars Stavholm) Date: Thu, 11 Mar 2010 14:13:50 +0530 Subject: pexpect and logging integration In-Reply-To: <4B97A7BD.6050003@sequans.com> References: <4B972EA7.50807@telcotec.se> <4B97A7BD.6050003@sequans.com> Message-ID: <4B98AD46.6090702@telcotec.se> It works like a charm, thank you! /Lars Jean-Michel Pichavant wrote: > Lars Stavholm wrote: >> Hi all, >> >> has anyone managed to integrate pexpect and logging? >> >> I.e., I'd like to be able to pick up the dialog, >> commands sent and responses received, in my logging. >> I know about the pexpect logfile, and I can log things >> to stdout or stderr, but I really need to log using the >> python logging library. >> >> Any thoughts appreciated >> /Lars >> >> > I had to implement this. > It's a bit of a hack, but it does the job. > > The following code is tested with python 2.5, I remember pexpect behaves > slightly differently in python 2.3. > > import logging > import pexpect > import re > > # this will be the method called by the pexpect object to log > def _write(*args, **kwargs): > content = args[0] > # let's ignore other params, pexpect only use one arg AFAIK > if content in [' ', '', '\n', '\r', '\r\n']: > return # don't log empty lines > for eol in ['\r\n', '\r', '\n']: > # remove ending EOL, the logger will add it anyway > content = re.sub('\%s$' % eol, '', content) > return logger.info(content) # call the logger info method with the > reworked content > > > # our flush method > def _doNothing(): > pass > > # get the logger > logger = logging.getLogger('foo') > > # configure the logger > logger.handlers=[] > logger.addHandler(logging.StreamHandler()) > logger.handlers[-1].setFormatter(logging.Formatter("%(asctime)s - > %(name)s - %(levelname)s - %(message)s")) > logger.setLevel(logging.INFO) > > # give the logger the methods required by pexpect > logger.write = _write > logger.flush = _doNothing > > p = pexpect.spawn('echo "hello world !!"', logfile=logger) > p.expect('!!') > > ... 2010-03-10 15:01:31,234 - foo - INFO - hello world !! > > Hope it helps. > > JM > > From mihir3445 at gmail.com Thu Mar 11 04:12:02 2010 From: mihir3445 at gmail.com (Mihir Patel) Date: Thu, 11 Mar 2010 01:12:02 -0800 (PST) Subject: EOFError: EOF when reading a line Message-ID: I am trying to use the subprocess to send the data to child process. I am not sure why i keep getting "EOFError: EOF when reading a line" i am using Python 2.4.3, GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on 64bit linux ,centos Thanks output : ===== Traceback (most recent call last): File "test_input.py", line 3, in ? x = raw_input() EOFError: EOF when reading a line output: hello Main Program: =========== command_line = 'python test_input.py' p =subprocess.Popen(command_line, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) print 'output:', p.communicate()[0] o,e = p.communicate('test') print "out:",o print "error:",e p.stdout.close() print "Exit Success" test_input.py ========== print 'hello\n' x = raw_input() print x From jitu.icfai at gmail.com Thu Mar 11 04:32:18 2010 From: jitu.icfai at gmail.com (jitendra gupta) Date: Thu, 11 Mar 2010 15:02:18 +0530 Subject: Behavior of default parameter in a function Message-ID: def foo(x = [0]): x[0] = x[0] + 1 return x[0] def soo(x = None): if x is None: x = [0] x[0] = x[0] + 1 return x[0] >>> foo() 1 >>>foo() #See the behavior incremented by one 2 >>>foo([1]) # but here based on given number 2 >>>foo() 3 >>>foo([1]) 2 >>>foo() 4 >>>soo() 1 >>>soo() 1 >>>soo([1]) 2 >>>soo() 1 Why foo() is incremented by 1 always when we are not passing any argument, but this is not happening in soo() case, In which scenario we will use these type of function.' Thanks Jitendra Kumar -------------- next part -------------- An HTML attachment was scrubbed... URL: From shashank.sunny.singh at gmail.com Thu Mar 11 04:40:43 2010 From: shashank.sunny.singh at gmail.com (Shashank Singh) Date: Thu, 11 Mar 2010 15:10:43 +0530 Subject: Behavior of default parameter in a function In-Reply-To: References: Message-ID: <332972a21003110140h4f83acbp55a0c75ced584ace@mail.gmail.com> quoting from docs:http://docs.python.org/reference/compound_stmts.html *Default parameter values are evaluated when the function definition is executed.* This means that the expression is evaluated once, when the function is defined, and that that same ?pre-computed? value is used for each call. This is especially important to understand when a default parameter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified so default object for x in foo is precomputed once and is modified with each call. hth --shashank On Thu, Mar 11, 2010 at 3:02 PM, jitendra gupta wrote: > > def foo(x = [0]): > x[0] = x[0] + 1 > return x[0] > > def soo(x = None): > if x is None: > x = [0] > x[0] = x[0] + 1 > return x[0] > > >>> foo() > 1 > >>>foo() #See the behavior incremented by one > 2 > >>>foo([1]) # but here based on given number > 2 > >>>foo() > 3 > >>>foo([1]) > 2 > >>>foo() > 4 > > >>>soo() > 1 > >>>soo() > 1 > >>>soo([1]) > 2 > >>>soo() > 1 > > Why foo() is incremented by 1 always when we are not passing any argument, > but this is not happening in soo() case, In which scenario we will use > these type of function.' > > Thanks > Jitendra Kumar > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Regards Shashank Singh Senior Undergraduate, Department of Computer Science and Engineering Indian Institute of Technology Bombay shashank.sunny.singh at gmail.com http://www.cse.iitb.ac.in/~shashanksingh -------------- next part -------------- An HTML attachment was scrubbed... URL: From george.sakkis at gmail.com Thu Mar 11 05:21:51 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Thu, 11 Mar 2010 11:21:51 +0100 Subject: Multiple import of the same module under different names Message-ID: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> The import mechanism is not very smart in identifying whether two modules imported under different name are actually the same module, at least when dealing with implicit relative imports and sys.path manipulation. However, at least in cases of plain file modules, the module's __file__ would be adequate (or at least better than __name__) in determining this. Below is an illustration of the different situations (absolute imports, explicit relative imports, implicit relative import, sys.path tweaking). So why does not import consult __file__ before deciding to create a new module instance ? George === File structure ============= ~/pkg/ __init__.py # empty mod1.py mod2.py mod3.py mod4.py main.py subpkg/ __init__.py # empty foo.py # empty === Run ============= ~$ PYTHONPATH=. python pkg/main.py === Output ============= Imported foo from pkg.subpkg: Imported foo from subpkg: Imported foo from pkg.mod1: Imported foo from mod1: Imported foo from pkg.mod2: Failed to import foo from mod2: Attempted relative import in non-package Imported foo from pkg.mod3: Imported foo from mod3: Imported foo from pkg.mod4: Imported foo from mod4: * 9 total module(s) * 3 distinct module(s) * 1 distinct file(s) /home/george/pkg/subpkg/foo.py === Code ============= ### mod1.py ### # implicit relative import from subpkg import foo ### mod2.py ### # explicit relative import from .subpkg import foo ### mod3.py ### # absolute import from pkg.subpkg import foo ### mod4.py ### # absolute import after tweaking sys.path import sys from os.path import dirname,join sys.path.append(join(dirname(__file__), 'subpkg')) import foo ### main.py ### #!/usr/bin/env python from os.path import abspath, normpath def test(*modules): module_set = set(modules) file_set = set(module_file(m) for m in modules) print '* %d total module(s)' % len(modules) print '* %d distinct module(s)' % len(module_set) for m in module_set: print '\t', m print '* %d distinct file(s)' % len(file_set) for f in file_set: print '\t', f def module_file(mod): f = abspath(normpath(mod.__file__)) if f.endswith('.pyc'): f = f[:-1] return f if __name__ == '__main__': from pkg.subpkg import foo print 'Imported foo from pkg.subpkg:\t', foo from subpkg import foo as rel_foo print 'Imported foo from subpkg:\t\t', rel_foo from pkg.mod1 import foo as foo1 print 'Imported foo from pkg.mod1:\t', foo1 from mod1 import foo as rel_foo1 print 'Imported foo from mod1:\t\t', rel_foo1 from pkg.mod2 import foo as foo2 print 'Imported foo from pkg.mod2:\t', foo2 try: from mod2 import foo as rel_foo2 except ValueError, ex: print 'Failed to import foo from mod2:', ex from pkg.mod3 import foo as foo3 print 'Imported foo from pkg.mod3:\t', foo3 from mod3 import foo as rel_foo3 print 'Imported foo from mod3:\t\t', rel_foo3 from pkg.mod4 import foo as foo4 print 'Imported foo from pkg.mod4:\t', foo4 from mod4 import foo as rel_foo4 print 'Imported foo from mod4:\t\t', rel_foo4 print test(foo, rel_foo, foo1, rel_foo1, foo2, # rel_foo2, foo3, rel_foo3, foo4, rel_foo4) From Neil.Blue at biowisdom.com Thu Mar 11 05:30:24 2010 From: Neil.Blue at biowisdom.com (Neil Blue) Date: Thu, 11 Mar 2010 10:30:24 -0000 Subject: How to handle file uploads with http.server In-Reply-To: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> References: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> Message-ID: <4728DC0EADB2654E8BA2A487F0CF2785AD6D2E@ws-ukexchange.internal.biowisdom.com> Hello, I have a basic http.server instance running (class HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I would like to upload files with multipart forms. def do_POST(self): ctype, pdict = cgi.parse_header(self.headers['Content-Type']) if ctype=='multipart/form-data': print('parsing...') query=cgi.parse_multipart(self.rfile, pdict) print(query) However the file never seems to finish being parsed. There are no errors, but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict) Please can anyone offer some insight into this or somewhere else I may find some more information. Thanks Neil ********************************************* The information contained in this message is likely to be confidential. It is intended only for the person named above. Any dissemination, distribution, copying, disclosure or use of this message or its contents unless authorised by BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of BioWisdom Ltd. If you have received this message in error, please immediately notify us and delete it. Thank you. Registered Office: BioWisdom Ltd, Harston Mill, Harston, Cambridge, CB22 7GG. Registered in England: (GB) 3861669. VAT registered: (GB) 750899881. Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, Internet:www.biowisdom.com ********************************************* From jeanmichel at sequans.com Thu Mar 11 05:44:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Mar 2010 11:44:22 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: <4B980DC6.4050807@hellmutweber.de> References: <4B980DC6.4050807@hellmutweber.de> Message-ID: <4B98C986.10707@sequans.com> Hellmut Weber wrote: > Hi Vinay Sajip, > I'm very glad discoverd your logging module ;-) > (That's what I would have liked 25 years ago when I was working as a > technical software developper!) > > Now I'm writing just some personal tools, I like python and want to > use logging on a regular basis. > > Logging works very well giving the filename and line number of the > point where it is called. As long as I use the loggers directly. > BUT when I have to wrap the logger call in some other function, I > always get file name and line number of the call of the logger inside > the wrapping function. > > Is there a possibility to get this information in this situation too? > > TIA > > Hellmut > You have to specify the file and line number by yourself, the logging feature can only assume that you want the line number of the logger call. i.e. in test.py: import logging import inspect _logger = logging.getLogger(__name__) class Foo: def __init__(self): self._logger = _logger def info(self, msg): previousFrame = inspect.currentframe().f_back self._logger.info(msg, extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename}) if __name__ == '__main__': _logger.handlers=[] _logger.addHandler(logging.StreamHandler()) _logger.handlers[-1].setFormatter(logging.Formatter('file %(custom_filename)s line %(custom_lineno)d : %(message)s')) _logger.setLevel(logging.DEBUG) foo = Foo() foo.info('a foo info') In [3]: run test.py file test.py line 20 : a foo info note that you cannot override the logging builtin 'lineno' key with the extra dictionary, that is why I'm using the 'custom_lineno' key. I don't know why the logger forbids it though, would have been nice to override lineno without the need of adding a new key. JM From __peter__ at web.de Thu Mar 11 06:14:08 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Mar 2010 12:14:08 +0100 Subject: logging: local functions ==> loss of lineno References: Message-ID: Hellmut Weber wrote: > Logging works very well giving the filename and line number of the point > where it is called. As long as I use the loggers directly. > BUT when I have to wrap the logger call in some other function, I always > get file name and line number of the call of the logger inside the > wrapping function. > > Is there a possibility to get this information in this situation too? The official way is probably to write a custom Logger class that overrides the findCaller() method. Below is a hack that monkey-patches the logging._srcfile attribute to ignore user-specified modules in the call stack: $ cat wrapper.py import logging import os import sys logger = logging.getLogger() class SrcFile(object): def __init__(self, exclude_files): self.files = set(exclude_files) def __eq__(self, other): return other in self.files def fixname(filename): if filename.lower().endswith((".pyc", ".pyo")): filename = filename[:-4] + ".py" return os.path.normcase(filename) if "--monkey" in sys.argv: print "patching" logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) def warn(*args, **kw): logger.warn(*args, **kw) $ cat main.py import logging logging.basicConfig(format="%(filename)s <%(lineno)s>: %(message)s") import wrapper wrapper.warn("foo") wrapper.warn("bar") wrapper.warn("baz") $ python main.py wrapper.py <23>: foo wrapper.py <23>: bar wrapper.py <23>: baz $ python main.py --monkey patching main.py <4>: foo main.py <5>: bar main.py <6>: baz $ python -V Python 2.6.4 Peter From steve at holdenweb.com Thu Mar 11 07:37:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 07:37:20 -0500 Subject: Python Script to get Info from Site not working In-Reply-To: <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> Message-ID: Jimbo wrote: > On Mar 11, 12:38 pm, "Gabriel Genellina" > wrote: >> En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: >> >>> I found a semi Python & internet tutorial here if anyone else would >>> like ithttp://www.upriss.org.uk/python/session6.html >>> My script is meant to find which radio button is selected & tell me >>> that. But it just keeps saying "No Drink Selected!" >> Are you sure? From the code you posted, the message should read "You need >> to select a drink!", not that one. > >> Replace the last line with something like this, to see what you are >> getting exactly: >> >> print("Sorry, no %r (%r) available." % ( >> drink, >> cgi.escape(repr(type(drink))))) >> >> BTW, which Python version are you using? The tutorial you linked to is >> aimed at Python 2.x, but your print syntax suggests you're using Python 3.x >> >> -- >> Gabriel Genellina > > Yeah that("You need to select a drink!") was the string I was getting > but I should be getting hot chocolate or something else(which ever one > I have selected) > > I am using 3.x, do you think I should be using something else? Also > the your code I put in does the some thing, just now it says "Sorry no > none drink available" all the time. It may not seem like it, but you *are* making progress here (of a sort). >From the information you have given us so far it appears that your call to form.getvalue() is returning None (which is of type - your browser is probably not displaying this because it sees it as a bogus HTML tag. Perhaps you haven't yet realised the importance of exact copy-and-paste here. What I'd like you to do is change the line drink = form.getvalue("drink") to drink = form.getfirst("drink", "No drink selected") then have you browser display the HTML source of the response page your program is returning and paste that into a reply to this mail. You might also want to take a look at http://docs.python.org/3.1/library/cgi.html for further information about the Python library your are trying to use. In particular I'd recommend heeding its advice about use of the cgitb module. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Mar 11 07:42:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 07:42:29 -0500 Subject: Get a method instance through 'getattr' but not superclass's method In-Reply-To: References: Message-ID: Radhakrishna Bhat wrote: > I am using getattr to get a method instance from a class. But it also > returns methods from the superclass. How to detect if an attribute is > from superclass? > You could try, if x is in instance, looking to see whether the name is defined in x.__class__.__dict__. >>> class A: ... def method1(self): ... print "A1" ... def method2(self): ... print "A2" ... >>> class B(A): ... def method2(self): ... print"B2" ... def method3(self): ... print "B3" ... >>> a = A() >>> b = B() >>> b.method2() B2 >>> b.method1() A1 >>> b.method3() B3 >>> b.__class__.__dict__ {'__module__': '__main__', 'method2': , 'method3': , '__doc__': None} >>> a.__class__.__dict__ {'__module__': '__main__', 'method2': , '__doc__': None, 'method1': } >>> I'd be interested to know why this is so important. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ndbecker2 at gmail.com Thu Mar 11 07:56:59 2010 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 11 Mar 2010 07:56:59 -0500 Subject: Can't define __call__ within __init__? References: Message-ID: Steven D'Aprano wrote: > On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > >> Want to switch __call__ behavior. Why doesn't this work? What is the >> correct way to write this? >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> def __call__ (self): >> return 0 >> else: >> def __call_ (self): >> return 1 > > > Others have already pointed out that there are two reasons that won't > work: > > (1) you define __call__ as a local variable of the __init__ method which > then disappears as soon as the __init__ method completes; and > > (2) special methods like __call__ are only called on the class, not the > instance, so you can't give each instance its own method. > > > Perhaps the best way to solve this is to use delegation: > > > def zero_returner(): > return 0 > > def one_returner(): > return 1 > > > class X (object): > def __init__(self, i): > if i == 0: > self.func = zero_returner > else: > self.func = one_returner > def __call__(self, *args, **kwargs): > return self.func(*args, **kwargs) > > > zero_returner and one_returner can be any callable object, not > necessarily a function. > > Of course, all this assumes that your solution isn't even simpler: > > class X (object): > def __init__(self, i): > self.i = i > def __call__(self): > return self.i > > but I assume if it was that simple, you would have done that already. > > > The example I showed was just a toy problem. The real problem is I expect to call a function many times, and I want to avoid the overhead of the 'if blah' everytime. From paskari007 at yahoo.ca Thu Mar 11 07:58:35 2010 From: paskari007 at yahoo.ca (PEYMAN ASKARI) Date: Thu, 11 Mar 2010 04:58:35 -0800 (PST) Subject: a newbie's question In-Reply-To: Message-ID: <493846.1798.qm@web30003.mail.mud.yahoo.com> Hello I need some help dynamically reloading modules. As it turns out, it is not as simple as calling reload, as outlined here http://pyunit.sourceforge.net/notes/reloading.html Is there builtin support for this? The example they gave does not seem to work for me, and I am unclear as to what PyUnit is. Thanks Peyman --- On Thu, 3/11/10, Lan Qing wrote: From: Lan Qing Subject: Re: a newbie's question To: "Python List" Received: Thursday, March 11, 2010, 4:56 AM hi Cheers,?? ? Think you, that helps me a lot. On Tue, Mar 9, 2010 at 10:00 PM, Simon Brunning wrote: On 9 March 2010 13:51, Lan Qing wrote: > Hi all, > ?? ? ?I'm a newbie of python programming language. Welcome! > I have used c/c++ for 5 > years, and one year experience in Lua programming language. Can any one give > me some advice on learning python. Think you for any help!! You'll find some useful starting points here - . -- Cheers, Simon B. -----Inline Attachment Follows----- -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Mar 11 08:10:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Mar 2010 14:10:40 +0100 Subject: a newbie's question In-Reply-To: <493846.1798.qm@web30003.mail.mud.yahoo.com> References: <493846.1798.qm@web30003.mail.mud.yahoo.com> Message-ID: <4B98EBD0.8020902@sequans.com> PEYMAN ASKARI wrote: > Hello > > I need some help dynamically reloading modules. As it turns out, it is > not as simple as calling reload, as outlined here > http://pyunit.sourceforge.net/notes/reloading.html > > Is there builtin support for this? The example they gave does not seem > to work for me, and I am unclear as to what PyUnit is. > > Thanks > > > Peyman > Please don't top post. As for your question, there's no built-in method to reload a module because it is not possible (in a generic manner). However if you *really* want to do it you can do it for your particular module (and only for this one). It is tough to explain though. You have to know perfectly the python object model and I'm not familiar enough with it to do the explanation. So: 1/ try to live without dynamic reload 2/ if you *really* require dynamic reload, you can try to execute the module in a subprocess. That way, every time you start a new subprocess, the last up to date version of the module is used 3/ reload the module and all it's related objects currently in memory, this is painfull and there are many traps to fall into. I'll let someone else answer this point. JM From radhakrishna12 at gmail.com Thu Mar 11 08:15:19 2010 From: radhakrishna12 at gmail.com (Radhakrishna Bhat) Date: Thu, 11 Mar 2010 18:45:19 +0530 Subject: Get a method instance through 'getattr' but not superclass's method In-Reply-To: References: Message-ID: Thanks. I just have to check in that string if method1 is from present in subclass's __dict__ or not. This is important for me because in my code, I am dynamically calling methods of 2 classes where one is superclass of the other. And I was getting duplicate results because of this problem. -Radhakrishna On Thu, Mar 11, 2010 at 6:12 PM, Steve Holden wrote: > Radhakrishna Bhat wrote: > > I am using getattr to get a method instance from a class. But it also > > returns methods from the superclass. How to detect if an attribute is > > from superclass? > > > You could try, if x is in instance, looking to see whether the name is > defined in x.__class__.__dict__. > > >>> class A: > ... def method1(self): > ... print "A1" > ... def method2(self): > ... print "A2" > ... > >>> class B(A): > ... def method2(self): > ... print"B2" > ... def method3(self): > ... print "B3" > ... > >>> a = A() > >>> b = B() > >>> b.method2() > B2 > >>> b.method1() > A1 > >>> b.method3() > B3 > >>> b.__class__.__dict__ > {'__module__': '__main__', 'method2': , > 'method3': , '__doc__': None} > >>> a.__class__.__dict__ > {'__module__': '__main__', 'method2': , > '__doc__': None, 'method1': } > >>> > > I'd be interested to know why this is so important. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Mar 11 08:30:12 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 08:30:12 -0500 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: Neal Becker wrote: > Steven D'Aprano wrote: > >> On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: >> >>> Want to switch __call__ behavior. Why doesn't this work? What is the >>> correct way to write this? >>> >>> class X (object): >>> def __init__(self, i): >>> if i == 0: >>> def __call__ (self): >>> return 0 >>> else: >>> def __call_ (self): >>> return 1 >> >> Others have already pointed out that there are two reasons that won't >> work: >> >> (1) you define __call__ as a local variable of the __init__ method which >> then disappears as soon as the __init__ method completes; and >> >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. >> >> >> Perhaps the best way to solve this is to use delegation: >> >> >> def zero_returner(): >> return 0 >> >> def one_returner(): >> return 1 >> >> >> class X (object): >> def __init__(self, i): >> if i == 0: >> self.func = zero_returner >> else: >> self.func = one_returner >> def __call__(self, *args, **kwargs): >> return self.func(*args, **kwargs) >> >> >> zero_returner and one_returner can be any callable object, not >> necessarily a function. >> >> Of course, all this assumes that your solution isn't even simpler: >> >> class X (object): >> def __init__(self, i): >> self.i = i >> def __call__(self): >> return self.i >> >> but I assume if it was that simple, you would have done that already. >> >> >> > The example I showed was just a toy problem. The real problem is > I expect to call a function many times, and I want to avoid the overhead of > the 'if blah' everytime. > This is a premature optimization. First, make it work. Then (if it doesn't work fast enough) make it work faster. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From astley.lejasper at gmail.com Thu Mar 11 08:55:56 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 11 Mar 2010 05:55:56 -0800 (PST) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) Message-ID: I have a Windows 7 (64bit AMD) machine and am having quite a lot of problems installing Reportlabs and Pil. I wondered if anyone else has had the same issues and what the best way of dealing with it. So far I've tried: 1. Reportlabs / Pil 32 installers - I've tried using these but they can't find python. I also tried registering Python (http://effbot.org/ zone/python-register.htm) but this also fails. 2. Reportlabs / Pil Source - I downloaded each of these and tried to do a "python setup.py install". However, both complain that they can't find "vcvarsall.bat". I've done some checking and it's because the compiler isn't present. Everyone is suggesting downloading Visual Studio Express C++, but this only comes with the 32bit compiler. There seems to be quite a lot of work to get 64bit VSE working on a 64bit machine (http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008- express-edition-and-64-bit-targets/). But before I start down that path, I wondered if anyone had any advice (.... and no I don't mean suggesting I swap to Linux). ALJ From victorsubervi at gmail.com Thu Mar 11 08:57:03 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 11 Mar 2010 09:57:03 -0400 Subject: Interacting With Another Script In-Reply-To: <2db4409d-d8d7-4af9-a9a7-e8071bc30b0f@o16g2000prh.googlegroups.com> References: <4dc0cfea1003100432h2495ede1vf5e5bd75172ab5ea@mail.gmail.com> <2db4409d-d8d7-4af9-a9a7-e8071bc30b0f@o16g2000prh.googlegroups.com> Message-ID: <4dc0cfea1003110557y16ad8e65i81a136d841b7c07e@mail.gmail.com> On Wed, Mar 10, 2010 at 10:16 PM, alex23 wrote: > Victor Subervi wrote: > > > There's a program (vpopmail) that has commands which, when called, > request > > > input ("email address", "password", etc.) from the command line. I > would > > > like to build a TTW interface for my clients to use that interacts with > > > these commands. > > The Pexpect[1] module is pretty much aimed at doing exactly this. > > 1: http://www.noah.org/wiki/Pexpect THIS looks PERFECT! Thanks! beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreengels at gmail.com Thu Mar 11 09:14:45 2010 From: andreengels at gmail.com (Andre Engels) Date: Thu, 11 Mar 2010 15:14:45 +0100 Subject: Can't define __call__ within __init__? In-Reply-To: References: Message-ID: <6faf39c91003110614v2b2aec8dg5c0c62f01fb56503@mail.gmail.com> On Thu, Mar 11, 2010 at 2:30 PM, Steve Holden wrote: >> The example I showed was just a toy problem. ?The real problem is >> I expect to call a function many times, and I want to avoid the overhead of >> the 'if blah' everytime. >> > This is a premature optimization. First, make it work. Then (if it > doesn't work fast enough) make it work faster. Corrolary: When you do make it faster, make it faster where it is slow. Second corrolary: If making it fast is so important that these two rules do not apply, Python is not your language of choice. -- Andr? Engels, andreengels at gmail.com From stefan_ml at behnel.de Thu Mar 11 09:24:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 11 Mar 2010 15:24:13 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: <62192fd8-2350-49c5-aeea-c8fe14878a61@d2g2000yqa.googlegroups.com> References: <62192fd8-2350-49c5-aeea-c8fe14878a61@d2g2000yqa.googlegroups.com> Message-ID: James Harris, 11.03.2010 09:30: > On 10 Mar, 15:19, kj wrote: >> Subject line pretty much says it all: is there a book like "Effective >> Java" for Python. I.e. a book that assumes that readers are >> experienced programmers that already know the basics of the language, >> and want to focus on more advanced programming issues? > > I don't know about the Java book you mention but I find Python in a > Nutshell published by O'Reilly to be a good reference. There's also the Python Cookbook that has a couple of useful recipes that can become handy at times. http://code.activestate.com/recipes/langs/python/ Stefan From gb345 at invalid.com Thu Mar 11 09:57:37 2010 From: gb345 at invalid.com (gb345) Date: Thu, 11 Mar 2010 14:57:37 +0000 (UTC) Subject: Need advice on starting a Python group Message-ID: I'm hoping to get advice from anyone with prior experience setting up a Python group. A friend of mine and I have been trying to start a scientific-programming-oriented Python group in our school (of medecine and bio research), with not much success. The main problem is attendance. Even though a *ton* of people have told us that it's a great idea, that they're *very* interested, and have asked to be added to our mailing list, the attendance to our first few meeting has never been more than 5, including my friend and I. Last time just he and I showed up. The second problem is getting content. The format we'd envisioned for this group was centered around code review (though not limited to it). The idea was that at every meeting a different member would show some code. This could be for any of a number of reasons, such as, for example, 1) illustrate a cool module or technique; 2) present a scientific research problem and how they used Python to solve it, or get help solving it; 3) get general feedback (e.g. on code clarity, software usability, module architecture, etc.). But in principle just about anything is OK: e.g. a talk on favorite Python resources, or a comparison of Python with some other language, or an overview of Python gotchas would all be fair game. Also, we stressed that the talks were not expected to be polished: no need for PowerPoint slides, etc. Just project any old code onto the screen, and talk about it, or scribble stuff on the chalkboard. Still, we have a hard time finding volunteers. And even when we've had volunteers, hardly anyone shows up! Any suggestions would be appreciated. GB P.S. There's a Python Meetup we could go to, but it does not fit the bill for us: it doesn't meet often enough, it's sort of out of the way, and has practically no one doing scientific programming. From no.email at please.post Thu Mar 11 10:05:30 2010 From: no.email at please.post (kj) Date: Thu, 11 Mar 2010 15:05:30 +0000 (UTC) Subject: Anything like "Effective Java" for Python? References: Message-ID: In Chris Withers writes: >kj wrote: >> >> >> Subject line pretty much says it all: is there a book like "Effective >> Java" >oxymoronic, no? >Sorry, couldn't resist ;-) I hear you, but still: read "Effective Java" some day; it will make you a better programmer, whatever your language preference. I'm certainly no fan of Java, but I still rank Effective Java as one of my best reads on programming ever. I felt that my maturity as a programmer went up a notch or two after digesting this book. Cheers, ~K From philip at semanchuk.com Thu Mar 11 10:09:08 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 11 Mar 2010 10:09:08 -0500 Subject: show image in python In-Reply-To: References: Message-ID: On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote: > Hey, This is my program > > 1 #!/usr/bin/python > 2 import PIL > 3 import numpy > 4 import Image > 5 import ImageOps > 6 import sys > 7 > 8 def Matimg(path): > 9 """transforme image en matrice""" > 10 Img = Image.open(str(path)) > 11 Img1 = ImageOps.grayscale(Img) > 12 largeur,hauteur = Img1.size > 13 imdata = Img1.getdata() > 14 tab = numpy.array(imdata) > 15 matrix = numpy.reshape(tab,(hauteur,largeur)) > 16 return matrix > 17 > 18 def Creeimg(): > 19 """transforme matrice en image""" > 20 img = Image.new ("L",(8,8)) > 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] > 22 img.putdata(matrix) > 23 img.show() > 24 img.save(fp="./ana.bmp") > 25 > 26 if __name__== '__main__': > 27 if len(sys.argv) < 2 : > 28 print "Usage: img.py " > 29 sys.exit(0) > 30 path = sys.argv[1] > 31 matrix = Matimg(path) > 32 print matrix > 33 Creeimg() > > My probeleme : In line 23 "img.show()" Don't work, normally I show > the image > but it's not work, but strangely in line 24 "img.save(fp="./ > ana.bmp")" it's > work > WHERE IS THE PROBLEME. > > I have this error in shell : "(eog:3176): GLib-WARNING **: GError > set over > the top of a previous GError or uninitialized memory. > This indicates a bug in someone's code. You must ensure an error is > NULL > before it's set. > The overwriting error message was: Error in getting image file info " > > > os: ubuntu 9.10 Hi issolah, I don't know what your problem is but I have a few suggestions -- 1) You say that img.show() doesn't work. How does it fail? Is that where you get the GLib warning? 2) I'm glad you posted your code, but because it has line numbers, it's awkward to copy & paste into a local example. Please show your code without line numbers. I'm unfamiliar with PIL, so this is just a wild guess, but based on the GLib error it seems like you haven't initialized something properly. Sorry I couldn't be more helpful. Maybe someone who knows more will answer. Good luck Philip From showell30 at yahoo.com Thu Mar 11 10:16:25 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 11 Mar 2010 07:16:25 -0800 (PST) Subject: Anything like "Effective Java" for Python? References: Message-ID: <498a6d4c-3f8b-44fd-b2e0-23793031fee2@a16g2000pre.googlegroups.com> On Mar 11, 7:05?am, kj wrote: > In Chris Withers writes: > > >kj wrote: > > >> Subject line pretty much says it all: is there a book like "Effective > >> Java" > >oxymoronic, no? > >Sorry, couldn't resist ;-) > > I hear you, but still: read "Effective Java" some day; it will make > you a better programmer, whatever your language preference. ?I'm > certainly no fan of Java, but I still rank Effective Java as one > of my best reads on programming ever. ?I felt that my maturity as > a programmer went up a notch or two after digesting this book. > I'll second that. I much prefer Python to Java, but Effective Java is an excellent book. Many of its topics would be applicable to Python, although the solutions in Python would obviously be different. Eliminate obsolete object references (use None to break reference counts) Avoid finalizers (use the "with" statement) Favor immutability Design method signatures carefully (including the x=[] gotcha) Optimize judiciously Don't ignore exceptions Avoid excessive synchronization There are also some topics in Effective Java where the advice is almost the opposite of Python tradition. From CalWhoNOSPAM at roadrunner.com Thu Mar 11 10:43:35 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 10:43:35 -0500 Subject: I get the error: ImportError: No module named ffnet Message-ID: I have the .py file in Eclipse #@PydevCodeAnalysisIgnore from ffnet import ffnet, mlgraph topology = mlgraph( (2, 3, 1) ) nn = ffnet(topology) I select RunAs / Python Run I get the error from ffnet import ffnet, mlgraph ImportError: No module named ffnet In the folder Python26\lib\site-packages I see ffnet-0.6.2-py2.6.egg-info also a folder ffnet in that folder there is a folder Examples If I click one of the examples pyrhon.exe opens and runs it OK. Is there enough in the above for you to tell me how to procede? Thanks in advance for any help at all From kw at codebykevin.com Thu Mar 11 10:44:12 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 11 Mar 2010 10:44:12 -0500 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <94360$4b990fcc$4275d90a$23785@FUSE.NET> On 3/10/10 10:19 AM, kj wrote: > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K I haven't read "Effective Java," but I have found Lutz's "Programming Python" to be a very useful guide to solving various programming issues with the language. It's a big, big book, so there's lots to look at. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From icanbob at gmail.com Thu Mar 11 10:54:44 2010 From: icanbob at gmail.com (bobicanprogram) Date: Thu, 11 Mar 2010 07:54:44 -0800 (PST) Subject: Ideas for creating processes References: Message-ID: <0878d070-2c7a-4bdc-82eb-278432aa6695@b7g2000yqd.googlegroups.com> On Mar 10, 4:52 pm, J wrote: > I'm working on a project and thought I'd ask for a suggestion on how > to proceed (I've got my own ideas, but I wanted to see if I was on the > right track) > > For now, I've got this: > > def main(): > ## get our list of directories to refresh > releases=sys.argv[1:] > if len(releases) < 1: > print "You need to provide at least one dir to update" > sys.exit() > > ## Lets figure out what there is to update > updateDirs = [] > for rel in releases: > currentDir = os.path.join(homedir, rel) > for item in os.listdir(currentDir): > updateDirs += [os.path.join(homedir, rel, item)] > > which returns a list of full pathnames to directories that need to be > updated (updates will be carried out by calling rsync or zsync > eventually) > > The directory hierarchy looks like this: > > /home/user/files > /home/user/files/version1 > /home/user/files/version1/type1 > /home/user/files/version1/type2 > /home/user/files/version2 > /home/user/files/version2/type1 > > and the list ends up looking like this: > > ['/home/user/files/version1/type1','/home/user/files/version1/type2','/home/user/files/version2/type1','/home/user/files/version2/type2'] > > the next thing I need to do is figure out how to update those. > > the quick and dirty would be (as I'm imagining it at the moment): > for path in pathlist: > chdir into path > execute rsync or zsync > > but that gets me moving into one dir, updating, then moving into another. > > What I was wondering about though, is spawning off separate rsync > processes to run concurrently (each rsync will hit a different remote > dir for each local dir) > > so I'm trying to figure out a good way to do this: > > for path in pathlist: > kick off an individual rsync|zsync process to update path > > wait for all child processes to end > exit program. > > I've been looking at subprocess because at the moment, that's all I > really know... > But is there a better way of kicking off multiple simultaneous > processes so I can update all dirs at once instead of one at a time? > > No, this isn't homework, it's something I'm working on to sync a > couple directories of ISO images to grab nightly builds > Yes, there are plenty of pre-made scripts out there, but I don't want > to even look at those because I figured this would be a good learning > experience, and I want to try to solve this as much on my own as I can > without just cut and pasting from someone elses program. > > So, with that said, any ideas on the best way to proceed? I'm going > to start looking at ways to use subprocess to do this, or would there > be a better way (multi-threading maybe?) > > Or am I even in the right ballpark? > > Cheers > Jeff You might be able to use the SIMPL toolkit for this one. (http://www.icanprogram.com/06py/lesson1/lesson1.html) You could wrap the rsync executable as a SIMPL receiver module and then message to that from inside your Python script to kick it off and synchronize actions. bob From dvkeeney at gmail.com Thu Mar 11 11:00:29 2010 From: dvkeeney at gmail.com (dkeeney) Date: Thu, 11 Mar 2010 08:00:29 -0800 (PST) Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: <3707bdd1-7371-445e-b303-96c2b636102d@e19g2000prn.googlegroups.com> On Mar 8, 12:14?pm, Duncan Booth wrote: > You've totally missed the point. It isn't the size of the data you have > today that matters, it's the size of data you could have in several years' > time. > > Maybe today you've got 10 users each with 10 megabytes of data, but you're > aspiring to become the next twitter/facebook or whatever. It's a bit late > as you approach 100 million users (and a petabyte of data) to discover that > your system isn't scalable: scalability needs to be built in from day one. Do you have examples of sites that got big by planning their site architecture from day 0 to be big? Judging from published accounts, even Facebook and Twitter did not plan to be 'the next twitter/facebook'; each started with routine LAMP stack architecture and successfully re-engineered the architecture multiple times on the way up. Is there compelling reason to think the 'next twitter/facebook' can't and won't climb a very similar path? I see good reasons to think that they *will* follow the same path, in that there are motivations at both ends of the path for re-engineering as you go. When the site is small, resources commited to the backend are not spent on making the frontend useful, so business-wise the best backend is the cheapest one. When the site becomes super-large, the backend gets re-engineered based on what that organization learned while the site was just large; Facebook, Twitter, and Craigslist all have architectures custom designed to support their specific needs. Had they tried to design for large size while they were small, they would have failed; they couldn't have known enough then about what they would eventually need. The only example I can find of a large site that architected large very early is Google, and they were aiming for a market (search) that was already known to be huge. Its reasonable to assume that the 'next twitter/facebook' will *not* be in web search, social-networking, broadcast instant messaging, or classified ads, just because those niches are taken already. So whichever 'high-scalability' model the aspiring site uses will be the wrong one. They might as well start with a quick and cheap LAMP stack, and re-engineer as they go. Just one internet watcher's biased opinion... David www.rdbhost.com -> SQL databases via a web-service From python at mrabarnett.plus.com Thu Mar 11 11:01:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 16:01:41 +0000 Subject: Can't define __call__ within __init__? In-Reply-To: <6faf39c91003110614v2b2aec8dg5c0c62f01fb56503@mail.gmail.com> References: <6faf39c91003110614v2b2aec8dg5c0c62f01fb56503@mail.gmail.com> Message-ID: <4B9913E5.7060404@mrabarnett.plus.com> Andre Engels wrote: > On Thu, Mar 11, 2010 at 2:30 PM, Steve Holden wrote: > >>> The example I showed was just a toy problem. The real problem is >>> I expect to call a function many times, and I want to avoid the overhead of >>> the 'if blah' everytime. >>> >> This is a premature optimization. First, make it work. Then (if it >> doesn't work fast enough) make it work faster. > > Corrolary: When you do make it faster, make it faster where it is slow. > Second corrolary: If making it fast is so important that these two > rules do not apply, Python is not your language of choice. > Addendum: a bad algorithm is bad, whatever language it's written in. From gnarlodious at gmail.com Thu Mar 11 11:02:59 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Thu, 11 Mar 2010 08:02:59 -0800 (PST) Subject: Insert missing keys using defaultdict Message-ID: <55e00342-a83e-4e45-8448-d04e71251631@c16g2000yqd.googlegroups.com> I am trying to grok this documentation but need help: http://docs.python.org/library/collections.html#defaultdict-examples In a perfect world the dict looks like this: plistDict={'Style':'ExternalURL', 'Ref':'http://Gnarlodious.com/', 'Tip':'Opens in a new window', 'Text':'Gnarlodious.com'} Let's say I want to prep a dict from a plist to insert the values into an HTML link string: "%(Text)s" % plistDict However, in this imperfect world the dict might look like this: plistDict={'Ref':'http://Gnarlodious.com/', 'Text':'Gnarlodious.com'} which would error: KeyError: 'Style' So using defaultdict: from collections import defaultdict How do create a dict assigning every missing key with a default string? -- Gnarlie From isso.moh at gmail.com Thu Mar 11 11:07:39 2010 From: isso.moh at gmail.com (mohamed issolah) Date: Thu, 11 Mar 2010 17:07:39 +0100 Subject: show image in python In-Reply-To: References: Message-ID: hey #!/usr/bin/python 2 import PIL 3 import numpy 4 import Image import ImageOps import sys def Matimg(path): """transforme image en matrice""" Img = Image.open(str(path)) Img1 = ImageOps.grayscale(Img) largeur,hauteur = Img1.size imdata = Img1.getdata() tab = numpy.array(imdata) matrix = numpy.reshape(tab,(hauteur,largeur)) return matrix def Creeimg(): """transforme matrice en image""" img = Image.new ("L",(8,8)) matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] img.putdata(matrix) img.show() img.save(fp="./ana.bmp") if __name__== '__main__': if len(sys.argv) < 2 : print "Usage: img.py " sys.exit(0) path = sys.argv[1] matrix = Matimg(path) print matrix Creeimg() 2010/3/11 Philip Semanchuk > > On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote: > > Hey, This is my program >> >> 1 #!/usr/bin/python >> 2 import PIL >> 3 import numpy >> 4 import Image >> 5 import ImageOps >> 6 import sys >> 7 >> 8 def Matimg(path): >> 9 """transforme image en matrice""" >> 10 Img = Image.open(str(path)) >> 11 Img1 = ImageOps.grayscale(Img) >> 12 largeur,hauteur = Img1.size >> 13 imdata = Img1.getdata() >> 14 tab = numpy.array(imdata) >> 15 matrix = numpy.reshape(tab,(hauteur,largeur)) >> 16 return matrix >> 17 >> 18 def Creeimg(): >> 19 """transforme matrice en image""" >> 20 img = Image.new ("L",(8,8)) >> 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] >> 22 img.putdata(matrix) >> 23 img.show() >> 24 img.save(fp="./ana.bmp") >> 25 >> 26 if __name__== '__main__': >> 27 if len(sys.argv) < 2 : >> 28 print "Usage: img.py " >> 29 sys.exit(0) >> 30 path = sys.argv[1] >> 31 matrix = Matimg(path) >> 32 print matrix >> 33 Creeimg() >> >> My probeleme : In line 23 "img.show()" Don't work, normally I show the >> image >> but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" >> it's >> work >> WHERE IS THE PROBLEME. >> >> I have this error in shell : "(eog:3176): GLib-WARNING **: GError set over >> the top of a previous GError or uninitialized memory. >> This indicates a bug in someone's code. You must ensure an error is NULL >> before it's set. >> The overwriting error message was: Error in getting image file info " >> >> >> os: ubuntu 9.10 >> > > Hi issolah, > I don't know what your problem is but I have a few suggestions -- > 1) You say that img.show() doesn't work. How does it fail? Is that where > you get the GLib warning? > 2) I'm glad you posted your code, but because it has line numbers, it's > awkward to copy & paste into a local example. Please show your code without > line numbers. > > I'm unfamiliar with PIL, so this is just a wild guess, but based on the > GLib error it seems like you haven't initialized something properly. Sorry I > couldn't be more helpful. Maybe someone who knows more will answer. > > Good luck > Philip > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- issolah mohamed -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Mar 11 11:20:14 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 11 Mar 2010 08:20:14 -0800 (PST) Subject: Can't define __call__ within __init__? References: Message-ID: On Mar 10, 7:18?pm, Steven D'Aprano wrote: > On Wed, 10 Mar 2010 08:12:14 -0500, Neal Becker wrote: > > Want to switch __call__ behavior. ?Why doesn't this work? ?What is the > > correct way to write this? > > > class X (object): > > ? ? def __init__(self, i): > > ? ? ? ? if i == 0: > > ? ? ? ? ? ? def __call__ (self): > > ? ? ? ? ? ? ? ? return 0 > > ? ? ? ? else: > > ? ? ? ? ? ? def __call_ (self): > > ? ? ? ? ? ? ? ? return 1 > > Others have already pointed out that there are two reasons that won't > work: > > (1) you define __call__ as a local variable of the __init__ method which > then disappears as soon as the __init__ method completes; and > > (2) special methods like __call__ are only called on the class, not the > instance, so you can't give each instance its own method. > Are you sure about that? This program prints 1, 2, 1, 2. class Foo: def __init__(self, a): if a == 1: self.__call__ = lambda: 1 else: self.__call__ = lambda: 2 foo1 = Foo(1) print foo1() foo2 = Foo(2) print foo2() print foo1() print foo2() See here: http://docs.python.org/reference/datamodel.html Class instances Class instances are described below. Class instances are callable only when the class has a __call__() method; x(arguments) is a shorthand for x.__call__(arguments). From george.sakkis at gmail.com Thu Mar 11 11:20:47 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Thu, 11 Mar 2010 08:20:47 -0800 (PST) Subject: Insert missing keys using defaultdict References: <55e00342-a83e-4e45-8448-d04e71251631@c16g2000yqd.googlegroups.com> Message-ID: <350e66eb-5c5b-4abe-826b-44a73a90053c@33g2000yqj.googlegroups.com> On Mar 11, 5:02?pm, Gnarlodious wrote: > I am trying to grok this documentation but need help:http://docs.python.org/library/collections.html#defaultdict-examples > > In a perfect world the dict looks like this: > plistDict={'Style':'ExternalURL', 'Ref':'http://Gnarlodious.com/', > 'Tip':'Opens in a new window', 'Text':'Gnarlodious.com'} > > Let's say I want to prep a dict from a plist to insert the values into > an HTML link string: > "%(Text)s" % > plistDict > > However, in this imperfect world the dict might look like this: > plistDict={'Ref':'http://Gnarlodious.com/', 'Text':'Gnarlodious.com'} > > which would error: > KeyError: 'Style' > > So using defaultdict: > from collections import defaultdict > > How do create a dict assigning every missing key with a default > string? "%(Text)s" % defaultdict(lambda:'_MISSING_', plistDict) HTH, George From gnarlodious at gmail.com Thu Mar 11 11:27:24 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Thu, 11 Mar 2010 08:27:24 -0800 (PST) Subject: Insert missing keys using defaultdict References: <55e00342-a83e-4e45-8448-d04e71251631@c16g2000yqd.googlegroups.com> <350e66eb-5c5b-4abe-826b-44a73a90053c@33g2000yqj.googlegroups.com> Message-ID: <2b32f4ae-a61d-4a5b-a085-1df16a6cea58@c16g2000yqd.googlegroups.com> On Mar 11, 9:20?am, George Sakkis wrote: > > How do create a dict assigning every missing key with a default > > string? > > "%(Text)s" % > defaultdict(lambda:'_MISSING_', plistDict) Brilliant, I love Python. -- Gnarlie From rizwanahmed24 at gmail.com Thu Mar 11 11:28:38 2010 From: rizwanahmed24 at gmail.com (rizwanahmed24 at gmail.com) Date: Thu, 11 Mar 2010 08:28:38 -0800 (PST) Subject: bypass UAC control through python script (to be run from batchfile) Message-ID: <26028cd0-8ead-47d0-95d8-09e2214dddd3@e7g2000yqf.googlegroups.com> Hi here is my problem. i want to install a program through python script. The python scripts is called from a batch file. The UAC control is not allowing the python script to install a msi (installer). I need to somehow by pass the UAC control. i dont want to turn it off permanently. Once i have run the batch file, i do not interact with the system manually, therefore Clicking allow on UAC dialog is not the solution for me. i just want to achieve the goal, whether i run batch file in Admin mode, or do it form python, doesnt matter. any ideas? //Rizwan From robin at reportlab.com Thu Mar 11 11:29:26 2010 From: robin at reportlab.com (Robin Becker) Date: Thu, 11 Mar 2010 16:29:26 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: References: Message-ID: <4B991A66.4020203@chamonix.reportlab.co.uk> On 11/03/2010 13:55, Astley Le Jasper wrote: > I have a Windows 7 (64bit AMD) machine and am having quite a lot of > problems installing Reportlabs and Pil. I wondered if anyone else has > had the same issues and what the best way of dealing with it. > > So far I've tried: > > 1. Reportlabs / Pil 32 installers - I've tried using these but they > can't find python. I also tried registering Python (http://effbot.org/ > zone/python-register.htm) but this also fails. > 2. Reportlabs / Pil Source - I downloaded each of these and tried to > do a "python setup.py install". However, both complain that they can't > find "vcvarsall.bat". I've done some checking and it's because the > compiler isn't present. Everyone is suggesting downloading Visual > Studio Express C++, but this only comes with the 32bit compiler. There > seems to be quite a lot of work to get 64bit VSE working on a 64bit > machine (http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008- > express-edition-and-64-bit-targets/). > > But before I start down that path, I wondered if anyone had any advice > (.... and no I don't mean suggesting I swap to Linux). > > ALJ Hi, you might get more assistance on the reportlab users mailing list at http://two.pairlist.net/mailman/listinfo/reportlab-users We do have users that run both reportlab & pil on 64 bit linux architectures, but I don't think I have ever compiled any of the extensions for 64bit windows. The vcvarsall.bat reference is the distutils package desperately looking for a suitable compiler (and not finding it). Perhaps some expert on the python list knows which versions of VS support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set up a 64bit machine to see if they will install on a 64bit architecture. -- Robin Becker From __peter__ at web.de Thu Mar 11 11:36:03 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Mar 2010 17:36:03 +0100 Subject: Can't define __call__ within __init__? References: Message-ID: Steve Howell wrote: > On Mar 10, 7:18 pm, Steven D'Aprano > wrote: >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. > Are you sure about that? This program prints 1, 2, 1, 2. You are using a classic class while the behaviour described above applies to newstyle classes: >>> class Foo: ... def __init__(self): ... self.__call__ = lambda: 42 ... >>> Foo()() 42 >>> class Bar(object): ... def __init__(self): ... self.__call__ = lambda: 42 ... >>> Bar()() Traceback (most recent call last): File "", line 1, in TypeError: 'Bar' object is not callable I don't think it's a good idea to write new code that requires a classic class. Peter From gherron at islandtraining.com Thu Mar 11 11:48:20 2010 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 11 Mar 2010 08:48:20 -0800 Subject: Behavior of default parameter in a function In-Reply-To: References: Message-ID: <4B991ED4.1030203@islandtraining.com> This is addressed in the FAQ. http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects jitendra gupta wrote: > > def foo(x = [0]): > x[0] = x[0] + 1 > return x[0] > > def soo(x = None): > if x is None: > x = [0] > x[0] = x[0] + 1 > return x[0] > > >>> foo() > 1 > >>>foo() #See the behavior incremented by one > 2 > >>>foo([1]) # but here based on given number > 2 > >>>foo() > 3 > >>>foo([1]) > 2 > >>>foo() > 4 > > >>>soo() > 1 > >>>soo() > 1 > >>>soo([1]) > 2 > >>>soo() > 1 > > Why foo() is incremented by 1 always when we are not passing any argument, > but this is not happening in soo() case, In which scenario > we will use these type of function.' > > Thanks > Jitendra Kumar > From CalWhoNOSPAM at roadrunner.com Thu Mar 11 12:04:20 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 12:04:20 -0500 Subject: I get the error: ImportError: No module named ffnet References: Message-ID: I ran this: import sys from pprint import pprint as pp pp(sys.path) The output included: 'E:\\Program Files\\Python26', 'E:\\Program Files\\Python26\\DLLs', 'E:\\Program Files\\Python26\\lib', 'E:\\Program Files\\Python26\\lib\\lib-tk', 'E:\\Program Files\\Python26\\lib\\plat-win', 'E:\\Program Files\\Python26\\lib\\site-packages', Python is at E:\Python26 but other things like java are at E:\Program Files Showhow it is looking in the wrong place and I don't know how to fix it. I checked the registry. The entries all look good there. Thanks " Cal Who" wrote in message news:hnb339$g2g$1 at news.eternal-september.org... > > > I have the .py file in Eclipse > #@PydevCodeAnalysisIgnore > from ffnet import ffnet, mlgraph > topology = mlgraph( (2, 3, 1) ) > nn = ffnet(topology) > > I select RunAs / Python Run > > I get the error > from ffnet import ffnet, mlgraph > ImportError: No module named ffnet > > In the folder Python26\lib\site-packages I see > ffnet-0.6.2-py2.6.egg-info > > also a folder ffnet > in that folder there is a folder Examples > If I click one of the examples pyrhon.exe opens and runs it OK. > > Is there enough in the above for you to tell me how to procede? > > Thanks in advance for any help at all > > > From bartc at freeuk.com Thu Mar 11 12:22:49 2010 From: bartc at freeuk.com (bartc) Date: Thu, 11 Mar 2010 17:22:49 GMT Subject: Named loops for breaking In-Reply-To: References: <6d6a35e8-f09c-4792-8abe-5a0dc24d214e@g28g2000yqh.googlegroups.com> Message-ID: James Harris wrote: > On 10 Mar, 06:29, "Gabriel Genellina" wrote: >> En Tue, 09 Mar 2010 18:41:10 -0300, Daniel Klein >> escribi : >> >>> Basically I'm wondering if there are any plans to implemented named >>> loops in Python, so I can tell a break command to break out of a >>> specific loop in the case of nested loops. >> >> See PEP3136 [1] and its rejection note [2] >> I think you may find some more discussion in the python-ideas list. > Breaking out of an inner loop is just as natural as breaking out of > the immediately enclosing loop. ISTM that if one is allowed the other > should be also. Exactly. Python already has single-level break (probably some baggage carried over from C), and some of the same arguments can be applied to that too. Given that break does exist, it's annoying that in the followed contrived example: def f(n): return n==2 for i in range(10): print i if f(0): break if f(1): break if f(2): break if f(3): break I can't turn the list of ifs into a loop. I can use break embedded inside a statement inside a loop, provided it's not another loop! That's discrimination... > There are often times when it *is* better to factor out the code to a > different function but adding a function just to enable a break from > an inner loop doesn't seem to me a good reason. Multi-level breaks should just have been part of the language, so they are available to those who want them, and ignored by everyone else. (And in languages where I've implemented them -- all generally faster than Python -- they have no impact on performance. I also had 4 loop controls rather than just 2, all multi-level, and the world hasn't ended yet.) My experience of these break statements is that they are used infrequently in final code. But they are handy when developing code too: you don't want to waste time refactoring, and generally turning code upside-down, when the code has to be rewritten a dozen times anyway. -- Bartc From mrkafk at gmail.com Thu Mar 11 12:28:04 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Mar 2010 18:28:04 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: kj wrote: > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? I'm surprised nobody mentioned Dive Into Python: http://diveintopython.org/ Available for free online. Most Python books contain a lot of 'hello world' material which for someone who knows at least one programming language is boring, this one doesn't, it cuts straight to the point. I found it very readable. Regards, mk From mehgcap at gmail.com Thu Mar 11 12:51:57 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 11 Mar 2010 12:51:57 -0500 Subject: importing modules from subdirs Message-ID: Hi all, The manual says, for modules in a project stored in subdirectories, you can do: import folderName.module I have a couple questions, though: 1. Do I then have to call functions from module like folder.module.function, or can I still use the normal module.function? 2. When I try to do this, it fails. I have an sw folder. Inside that I have a modes folder, holding weather.pyw. Main.pyw, back in the sw folder, is trying to import modes.weather, but nothing happens. I have tried putting weather.pyw in its own weather folder under the modes folder, but that also fails. I have placed an empty __init__.py file in both the modes folder and the weather subfolder, but I cannot get main.pyw to import weather! 3. How does weather import from a folder above or beside it? For example, if a config directory is at the same level as the modes directory, how can weather import something from config? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gherron at islandtraining.com Thu Mar 11 13:00:10 2010 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 11 Mar 2010 10:00:10 -0800 Subject: importing modules from subdirs In-Reply-To: References: Message-ID: <4B992FAA.2020102@islandtraining.com> Alex Hall wrote: > Hi all, > The manual says, for modules in a project stored in subdirectories, you can do: > import folderName.module > > I have a couple questions, though: > 1. Do I then have to call functions from module like > folder.module.function, or can I still use the normal module.function? > Either, depending on how you do the import: import folder.module folder.module.function() or from folder.module import function function() or from folder import module module.function() > 2. When I try to do this, it fails. I have an sw folder. Inside that I > have a modes folder, holding weather.pyw. Main.pyw, back in the sw > folder, is trying to import modes.weather, but nothing happens. I have > tried putting weather.pyw in its own weather folder under the modes > folder, but that also fails. I have placed an empty __init__.py file > in both the modes folder and the weather subfolder, but I cannot get > main.pyw to import weather! > Show us some code and a diagram of your forcer hierarchy, and we'll look at it. > 3. How does weather import from a folder above or beside it? For > example, if a config directory is at the same level as the modes > directory, how can weather import something from config? > You don't import from up the hierarchy. You can put a higher folder on sys.path, and get to it that way. Gary Herron > Thanks! > > From martin at v.loewis.de Thu Mar 11 13:00:21 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Thu, 11 Mar 2010 19:00:21 +0100 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: References: Message-ID: <4B992FB5.8090207@v.loewis.de> >> I have a Windows 7 (64bit AMD) machine This is somewhat imprecise: is it a) that your CPU is AMD64, and thus supports 64-bit mode, or b) that *in addition*, your Windows 7 installation is a 64-bit installation, or c) that *in addition*, your Python installation is also a 64-bit installation. Unless you have a specific need for 64-bit mode, I recommend that you use the 32-bit version of Windows (unless you have more than 4GB of main memory), and (even if you have a 64-bit Windows) you install the 32-bit version of Python on it (unless you have the need to access more than 2GB of objects in your Python applications. >> 1. Reportlabs / Pil 32 installers - I've tried using these but they >> can't find python. I also tried registering Python (http://effbot.org/ >> zone/python-register.htm) but this also fails. Install the 32-bit version of Python, and these installers should work fine. > Perhaps some expert on the python list knows which versions of VS > support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set > up a 64bit machine to see if they will install on a 64bit architecture. For Python 2.6 and later, use VS 2008. This comes with an AMD64 compiler. You technically don't need a 64-bit Windows, as it supports cross-compilation (but you would need a 64-bit Windows to test it). I personally build Python on a 32-bit machine, and move the MSI to a 64-bit machine for testing. Regards, Martin From steve at holdenweb.com Thu Mar 11 13:10:48 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 13:10:48 -0500 Subject: importing modules from subdirs In-Reply-To: References: Message-ID: Alex Hall wrote: > Hi all, > The manual says, for modules in a project stored in subdirectories, you can do: > import folderName.module > > I have a couple questions, though: > 1. Do I then have to call functions from module like > folder.module.function, or can I still use the normal module.function? > > 2. When I try to do this, it fails. I have an sw folder. Inside that I > have a modes folder, holding weather.pyw. Main.pyw, back in the sw > folder, is trying to import modes.weather, but nothing happens. I have > tried putting weather.pyw in its own weather folder under the modes > folder, but that also fails. I have placed an empty __init__.py file > in both the modes folder and the weather subfolder, but I cannot get > main.pyw to import weather! > > 3. How does weather import from a folder above or beside it? For > example, if a config directory is at the same level as the modes > directory, how can weather import something from config? > > Thanks! > I haven't checked this, but I believe .pyw names are only for main programs. Try renaming weather.pyw as weather.py and see if it makes any difference. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From drobinow at gmail.com Thu Mar 11 13:14:01 2010 From: drobinow at gmail.com (David Robinow) Date: Thu, 11 Mar 2010 13:14:01 -0500 Subject: use of multiple versions of python In-Reply-To: <581ce2791003102140t7fd470e5obcad20ec714f60f3@mail.gmail.com> References: <581ce2791003102140t7fd470e5obcad20ec714f60f3@mail.gmail.com> Message-ID: <4eb0089f1003111014w4f7bffack1ea409aa7a17ac2c@mail.gmail.com> On Thu, Mar 11, 2010 at 12:40 AM, Bujji wrote: > hi all, > I have installed python 2.6 in addition to python 2.5 in my system > Now for some modules(while installing ) it needs to use python 2.6 > how can i do that > in case of easy_install what should i do to it to use python 2.6 You should have an easy_install-2.5 and easy_install-2.6. One of them will be linked to easy_install, depending on how you did the install. Just use the one you need. From mehgcap at gmail.com Thu Mar 11 13:15:38 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 11 Mar 2010 13:15:38 -0500 Subject: unable to run wxPython script: dll errors Message-ID: Hi all, I am trying to run a file that should pop up a dialog. The dialog is fine (I used XRCed to create it and running it from within that editor brings up the dialog I want). When I run my file, though, I get this traceback: C:\Users\Alex>c:\python26\python.exe i:\arm\dictionary.py Traceback (most recent call last): File "i:\arm\dictionary.py", line 2, in import wx File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 4 5, in from wx._core import * File "c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, i n import _core_ ImportError: DLL load failed: The specified procedure could not be found. I am running win7x64, wxPython2.8, python2.6. Any ideas why this would be happening? I found a forum post that talked about a manifest file and some dll files being needed, but it did not make a lot of sense. Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From gagsl-py2 at yahoo.com.ar Thu Mar 11 13:28:15 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Mar 2010 15:28:15 -0300 Subject: Python Script to get Info from Site not working References: <993c3089-0f96-4f37-b42a-111731045b2d@k24g2000pro.googlegroups.com> <396ffb5b-8548-4e4d-8245-a53ecb3cff23@k24g2000pro.googlegroups.com> Message-ID: En Wed, 10 Mar 2010 23:26:05 -0300, Jimbo escribi?: > On Mar 11, 12:38 pm, "Gabriel Genellina" > wrote: >> En Wed, 10 Mar 2010 20:06:41 -0300, Jimbo escribi?: >> >> > I found a semi Python & internet tutorial here if anyone else would >> > like ithttp://www.upriss.org.uk/python/session6.html >> >> Replace the last line with something like this, to see what you are >> getting exactly: >> >> print("Sorry, no %r (%r) available." % ( >> drink, >> cgi.escape(repr(type(drink))))) >> >> BTW, which Python version are you using? The tutorial you linked to is >> aimed at Python 2.x, but your print syntax suggests you're using Python >> 3.x > I am using 3.x, do you think I should be using something else? Yes, you should use the same version as the tutorial you're following. Learning how to program, CGI, HTML and Python at the same time is hard enough to complicate it with incompatible version differences. I suggest Python 2.6.4 > Also > the your code I put in does the some thing, just now it says "Sorry no > none drink available" all the time. As a general rule, always directly copy and paste the error messages you get and the source code you execute. Do not retype or paraphrase them. That's important for the rest of us to be able to help you - now and in the future. In this case, the message should read "Sorry, no None () available." (None, not none, is a built-in special object in Python). So we know that drink is None instead of one of the expected values, and we could start investigating why. But there is no point in digging further - instead, downgrade to Python 2.6.4 and try again. This might be a server issue, unrelated to your script. BTW, you didn't mention the server software. -- Gabriel Genellina From ludolph at openhazel.co.za Thu Mar 11 13:38:56 2010 From: ludolph at openhazel.co.za (Ludolph) Date: Thu, 11 Mar 2010 20:38:56 +0200 Subject: Visual Python programming and decompilers? Message-ID: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Hi Guys At work I have been exposed to a Agile Platform called OutSystems. It allows you to visually program your web applications http://i.imgur.com/r2F0i.png and I find the idea very intriguing. So I have started to play around with the idea on how will I be able to visually represent Python code as in the above image and then allow the programmer to change some of the flow/code/logic visually and then get it back as python source code. I don't know if this have been tried before and after some googling I can't find anything like this, so maybe I'm just lacking basic googling skills or a python solution like the above does not exist yet. If anybody knows of such solution please let me know, so that I don't spend a lot of time recreating the wheel. Otherwise help me out on the following problem: I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to disassemble the code to workable objects, It even allows me to rebuild the objects to bytecode. So if I define patterns on how python interrupts the source code to bytecode I can visually represent this and also so convert my visual representations back to bytecode. The only problem I have at the moment is how will I get this bytecode back to python source code. I have googled for python decompiler but only found old projects like unpyc, decompyle and some online services. I would like to know if anybody know of a well maintained or at least recent module that can help me accomplish the above mentioned, because I'm hoping I can implement this in Python 3.1. So any input or suggestion would be greatly appreciated. Kind Regards, -- Ludolph Neethling From gagsl-py2 at yahoo.com.ar Thu Mar 11 13:45:03 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Mar 2010 15:45:03 -0300 Subject: Get a method instance through 'getattr' but not superclass's method References: Message-ID: En Thu, 11 Mar 2010 01:47:30 -0300, Radhakrishna Bhat escribi?: > I am using getattr to get a method instance from a class. But it also > returns methods from the superclass. How to detect if an attribute is > from > superclass? You may look it up directly in the class dictionary (__dict__) -- Gabriel Genellina From kevin.p.dwyer at gmail.com Thu Mar 11 13:54:41 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Thu, 11 Mar 2010 18:54:41 +0000 (UTC) Subject: Python 2.6 and modules dbi AND odbc References: <2fb4a5011003101617r5518b322y6ccc091046b0ccc4@mail.gmail.com> Message-ID: On Wed, 10 Mar 2010 16:17:29 -0800, robert somerville wrote: > hi; > i am trying to get some legacy python code (which i no nothing about) > working with tries to import dbi and odbc (the import fails ...) it > looks like these modules are deprecated ?? if so is there a work around > , if not deprecated, what am i doing wrong ?? i see no Ubuntu packages > that look promising .. Hello Robert, These modules are distributed as part of the PyWin32 Python for Windows extensions, so they need to run on a Windows box. They'll run fine there regardless of the deprecation of dbi (though "import dbi" will provide a useful warning message). Pyodbc is a possible alternative. Cheers, Kev From CalWhoNOSPAM at roadrunner.com Thu Mar 11 13:56:08 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 13:56:08 -0500 Subject: I get the error: ImportError: No module named ffnet References: Message-ID: I found out I had something installed wrong. " Cal Who" wrote in message news:hnb339$g2g$1 at news.eternal-september.org... > > > I have the .py file in Eclipse > #@PydevCodeAnalysisIgnore > from ffnet import ffnet, mlgraph > topology = mlgraph( (2, 3, 1) ) > nn = ffnet(topology) > > I select RunAs / Python Run > > I get the error > from ffnet import ffnet, mlgraph > ImportError: No module named ffnet > > In the folder Python26\lib\site-packages I see > ffnet-0.6.2-py2.6.egg-info > > also a folder ffnet > in that folder there is a folder Examples > If I click one of the examples pyrhon.exe opens and runs it OK. > > Is there enough in the above for you to tell me how to procede? > > Thanks in advance for any help at all > > > From jcb at iteris.com Thu Mar 11 14:01:39 2010 From: jcb at iteris.com (Metalone) Date: Thu, 11 Mar 2010 11:01:39 -0800 (PST) Subject: file seek is slow References: Message-ID: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> I am assuming that Python delegates the f.seek call to the seek call in the MS C runtime library msvcrt.dll. Does anybody know a nice link to the Python source like was posted above for the BSD 'C' library? Ok, I ran some more tests. C, seek : 0.812 seconds // test from original post Python, f.seek : 1.458 seconds. // test from original post C, time(&tm) : 0.671 seconds Python, time.time(): 0.513 seconds. Python, ctypes.msvcrt.time(ctypes.byref(tm)): 0.971 seconds. # factored the overhead to be outside the loop, so really this was func_ptr(ptr). Perhaps I am just comparing apples to oranges. I never tested the overhead of ctypes like this before. Most of my problem timings involve calls through ctypes. From CalWhoNOSPAM at roadrunner.com Thu Mar 11 14:01:39 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 14:01:39 -0500 Subject: Where can I find documentation for data[:,9] Message-ID: data = readdata( 'data/input.dat', delimiter = ',' ) input = data[:, :9]#nine data columns Where can I find documentation for the data[:,9] in the code above. Been looking and found many examples but would like to know the definition. I need to skip the first column and then read 9 I would also like to print the data in ihe variable "input" Thanks From robert.kern at gmail.com Thu Mar 11 14:22:21 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Mar 2010 13:22:21 -0600 Subject: Where can I find documentation for data[:,9] In-Reply-To: References: Message-ID: On 2010-03-11 13:01 PM, Cal Who wrote: > data = readdata( 'data/input.dat', delimiter = ',' ) > > input = data[:, :9]#nine data columns > > > > Where can I find documentation for the > > data[:,9] > > in the code above. > > Been looking and found many examples but would like to know the definition. When asking questions like this, it helps *a lot* to provide a complete example, not just a snippet. If I weren't already intimately familiar with the library you are using, I would have no idea how to help you. However, I do know that input object is a numpy array, and the syntax you are asking about is multidimensional slicing. http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html > I need to skip the first column and then read 9 data[:, 1:10] > I would also like to print the data in ihe variable "input" print input -- 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 From misceverything at gmail.com Thu Mar 11 14:29:53 2010 From: misceverything at gmail.com (T) Date: Thu, 11 Mar 2010 11:29:53 -0800 (PST) Subject: Parsing Email Headers Message-ID: All I'm looking to do is to download messages from a POP account and retrieve the sender and subject from their headers. Right now I'm 95% of the way there, except I can't seem to figure out how to *just* get the headers. Problem is, certain email clients also include headers in the message body (i.e. if you're replying to a message), and these are all picked up as additional senders/subjects. So, I want to avoid processing anything from the message body. Here's a sample of what I have: # For each line in message for j in M.retr(i+1)[1]: # Create email message object from returned string emailMessage = email.message_from_string(j) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From") I also tried using the following, but got the same results: emailMessage = email.Parser.HeaderParser().parsestr(j, headersonly=True) Any help would be appreciated! From mehgcap at gmail.com Thu Mar 11 14:56:12 2010 From: mehgcap at gmail.com (Alex Hall) Date: Thu, 11 Mar 2010 14:56:12 -0500 Subject: importing modules from subdirs In-Reply-To: References: Message-ID: Halfway there. It imports now, but it says that the module does not have functions which I know it does have. I will just leave it all in one folder for now and play with organization after I get the project working better. On 3/11/10, Steve Holden wrote: > Alex Hall wrote: >> Hi all, >> The manual says, for modules in a project stored in subdirectories, you >> can do: >> import folderName.module >> >> I have a couple questions, though: >> 1. Do I then have to call functions from module like >> folder.module.function, or can I still use the normal module.function? >> >> 2. When I try to do this, it fails. I have an sw folder. Inside that I >> have a modes folder, holding weather.pyw. Main.pyw, back in the sw >> folder, is trying to import modes.weather, but nothing happens. I have >> tried putting weather.pyw in its own weather folder under the modes >> folder, but that also fails. I have placed an empty __init__.py file >> in both the modes folder and the weather subfolder, but I cannot get >> main.pyw to import weather! >> >> 3. How does weather import from a folder above or beside it? For >> example, if a config directory is at the same level as the modes >> directory, how can weather import something from config? >> >> Thanks! >> > I haven't checked this, but I believe .pyw names are only for main > programs. Try renaming weather.pyw as weather.py and see if it makes any > difference. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From python at mrabarnett.plus.com Thu Mar 11 15:13:48 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 20:13:48 +0000 Subject: Parsing Email Headers In-Reply-To: References: Message-ID: <4B994EFC.4060400@mrabarnett.plus.com> T wrote: > All I'm looking to do is to download messages from a POP account and > retrieve the sender and subject from their headers. Right now I'm 95% > of the way there, except I can't seem to figure out how to *just* get > the headers. Problem is, certain email clients also include headers > in the message body (i.e. if you're replying to a message), and these > are all picked up as additional senders/subjects. So, I want to avoid > processing anything from the message body. > > Here's a sample of what I have: > > # For each line in message > for j in M.retr(i+1)[1]: > # Create email message object from returned string > emailMessage = email.message_from_string(j) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") > > I also tried using the following, but got the same results: > emailMessage = > email.Parser.HeaderParser().parsestr(j, headersonly=True) > > Any help would be appreciated! If you're using poplib then use ".top" instead of ".retr". From debatem1 at gmail.com Thu Mar 11 15:16:26 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 11 Mar 2010 15:16:26 -0500 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: On Thu, Mar 11, 2010 at 1:38 PM, Ludolph wrote: > Hi Guys > > At work I have been exposed to a Agile Platform called OutSystems. It > allows you to visually program your web applications > http://i.imgur.com/r2F0i.png and I find the idea very intriguing. > > So I have started to play around with the idea on how will I be able > to visually represent Python code as in the above image and then allow > the programmer to change some of the flow/code/logic visually and then > get it back as python source code. I don't know if this have been > tried before and after some googling I can't find anything like this, > so maybe I'm just lacking basic googling skills or a python solution > like the above does not exist yet. > > If anybody knows of such solution please let me know, so that I don't > spend a lot of time recreating the wheel. Otherwise help me out on the > following problem: > > I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to > disassemble the code to workable objects, It even allows me to rebuild > the objects to bytecode. So if I define patterns on how python > interrupts the source code to bytecode I can visually represent this > and also so convert my visual representations back to bytecode. > > The only problem I have at the moment is how will I get this bytecode > back to python source code. I have googled for python decompiler but > only found old projects like unpyc, decompyle and some online > services. I would like to know if anybody know of a well maintained or > at least recent module that can help me accomplish the above > mentioned, because I'm hoping I can implement this in Python 3.1. > > So any input or suggestion would be greatly appreciated. > > Kind Regards, > > -- > Ludolph Neethling > -- > http://mail.python.org/mailman/listinfo/python-list > Maybe something like http://www.pypes.org/? They were at pycon and sounded pretty into what they were talking about- I'd send them an email. Geremy Condra From stef.mientki at gmail.com Thu Mar 11 15:17:09 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Thu, 11 Mar 2010 21:17:09 +0100 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: <4B994FC5.1030106@gmail.com> On 11-03-2010 19:38, Ludolph wrote: > Hi Guys > > At work I have been exposed to a Agile Platform called OutSystems. It > allows you to visually program your web applications > http://i.imgur.com/r2F0i.png and I find the idea very intriguing. > > Although not as low level as you want, http://mientki.ruhosting.nl/data_www/pylab_works/pw_animations_screenshots.html http://code.google.com/p/pylab-works/ and here an overview of similar packages cheers, Stef From invalid at invalid.invalid Thu Mar 11 15:20:56 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 11 Mar 2010 20:20:56 +0000 (UTC) Subject: Parsing Email Headers References: Message-ID: On 2010-03-11, T wrote: > All I'm looking to do is to download messages from a POP account and > retrieve the sender and subject from their headers. Right now I'm 95% > of the way there, except I can't seem to figure out how to *just* get > the headers. The headers are saparated from the body by a blank line. > Problem is, certain email clients also include headers in the message > body (i.e. if you're replying to a message), and these are all picked > up as additional senders/subjects. So, I want to avoid processing > anything from the message body. Then stop when you see a blank line. Or retreive just the headers. -- Grant Edwards grant.b.edwards Yow! My life is a patio at of fun! gmail.com From astley.lejasper at gmail.com Thu Mar 11 15:57:07 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Thu, 11 Mar 2010 12:57:07 -0800 (PST) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) References: <4B992FB5.8090207@v.loewis.de> Message-ID: <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> @Robin Thanks. I thought that this seemed to be a general python thing because it was effecting both installs. However, after also reading Martin's comments ... @Martin > This is somewhat imprecise: is it > a) that your CPU is AMD64, and thus supports 64-bit mode, or > b) that *in addition*, your Windows 7 installation is a 64-bit > installation, or > c) that *in addition*, your Python installation is also a 64-bit > installation. > > Unless you have a specific need for 64-bit mode, I recommend that you > use the 32-bit version of Windows (unless you have more than 4GB of > main memory), and (even if you have a 64-bit Windows) you install the > 32-bit version of Python on it (unless you have the need to access more > than 2GB of objects in your Python applications. Sorry. I have Windows 7 (64-bit) installed on a machine with an AMD cpu (which supports 64-bit mode), with a 64-bit version of (Activestate) python 2.6 .... although I didn't realise the later until I looked just now. > Install the 32-bit version of Python, and these installers should work fine. Well, I uninstalled the 64-bit version and the installers did indeed work. I?m sorry everyone. I didn?t realise I had installed the 64-bit version of Python. Well, at least someone else might find have the same problem. But I think that there is going to be a bit of a rough patch as everyone moves over to 64-bit. ALJ From greg.ewing at canterbury.ac.nz Thu Mar 11 16:40:33 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 12 Mar 2010 10:40:33 +1300 Subject: Reverse engineering CRC? In-Reply-To: <3b1dce65-99ed-471a-8494-9eaf0e6d44ad@e19g2000prn.googlegroups.com> References: <7vj7fdFnnjU1@mid.individual.net> <3b1dce65-99ed-471a-8494-9eaf0e6d44ad@e19g2000prn.googlegroups.com> Message-ID: <7vt5n8FetlU1@mid.individual.net> Steve Howell wrote: > Hi Greg. I would at least flip one bit at a time on the first byte of > your data to see if the transformation is bitwise. I'm actually making good progress on this -- it turns out there *is* a way of deducing the polynomial by looking at the effect of single-bit flips. It's actually quite simple, with no brute-force searching needed at all. Things get a bit tricky when you don't quite know all of the data that goes into the CRC, though, which seems to be the case here... I'm writing up an essay on my experiences. I'll post a link when it's finished. -- Greg From CalWhoNOSPAM at roadrunner.com Thu Mar 11 17:08:36 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 17:08:36 -0500 Subject: Where can I find documentation for data[:,9] References: Message-ID: "Robert Kern" wrote in message news:mailman.631.1268335358.23598.python-list at python.org... > On 2010-03-11 13:01 PM, Cal Who wrote: >> data = readdata( 'data/input.dat', delimiter = ',' ) >> >> input = data[:, :9]#nine data columns >> >> >> >> Where can I find documentation for the >> >> data[:,9] >> >> in the code above. >> >> Been looking and found many examples but would like to know the >> definition. > > When asking questions like this, it helps *a lot* to provide a complete > example, not just a snippet. If I weren't already intimately familiar with > the library you are using, I would have no idea how to help you. > > However, I do know that input object is a numpy array, and the syntax you > are asking about is multidimensional slicing. > > http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html > >> I need to skip the first column and then read 9 > > data[:, 1:10] > >> I would also like to print the data in ihe variable "input" > > print input > > -- > 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 > Thanks, that helped a lot. I'm having trouble knowing what to search for to find documenatation. For example, is print a Python command, a numpy command or a java command? I like to read the documentation even if the command is working for me. Thanks again From martin.hellwig at dcuktec.org Thu Mar 11 17:19:09 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Mar 2010 22:19:09 +0000 Subject: Where can I find documentation for data[:,9] In-Reply-To: References: Message-ID: On 03/11/10 22:08, Cal Who wrote: > Thanks, that helped a lot. > > I'm having trouble knowing what to search for to find documenatation. For > example, is print a Python command, a numpy command or a java command? > > I like to read the documentation even if the command is working for me. > > > Thanks again > > Probably for you the right way would be to familiarize yourself with the namespace concept of Python, this makes it easier to identify whether something is built-in, a standard module or an external module. Which makes it much easier to feed google the right clues. -- mph From misceverything at gmail.com Thu Mar 11 17:44:09 2010 From: misceverything at gmail.com (T) Date: Thu, 11 Mar 2010 14:44:09 -0800 (PST) Subject: Parsing Email Headers References: Message-ID: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> On Mar 11, 3:13?pm, MRAB wrote: > T wrote: > > All I'm looking to do is to download messages from a POP account and > > retrieve the sender and subject from their headers. ?Right now I'm 95% > > of the way there, except I can't seem to figure out how to *just* get > > the headers. ?Problem is, certain email clients also include headers > > in the message body (i.e. if you're replying to a message), and these > > are all picked up as additional senders/subjects. ?So, I want to avoid > > processing anything from the message body. > > > Here's a sample of what I have: > > > ? ? ? ? ? ? ? ? # For each line in message > > ? ? ? ? ? ? ? ? for j in M.retr(i+1)[1]: > > ? ? ? ? ? ? ? ? ? ? # Create email message object from returned string > > ? ? ? ? ? ? ? ? ? ? emailMessage = email.message_from_string(j) > > ? ? ? ? ? ? ? ? ? ? # Get fields > > ? ? ? ? ? ? ? ? ? ? fields = emailMessage.keys() > > ? ? ? ? ? ? ? ? ? ? # If email contains "From" field > > ? ? ? ? ? ? ? ? ? ? if emailMessage.has_key("From"): > > ? ? ? ? ? ? ? ? ? ? ? ? # Get contents of From field > > ? ? ? ? ? ? ? ? ? ? ? ? from_field = emailMessage.__getitem__("From") > > > I also tried using the following, but got the same results: > > ? ? ? ? ? ? ? ? ?emailMessage = > > email.Parser.HeaderParser().parsestr(j, headersonly=True) > > > Any help would be appreciated! > > If you're using poplib then use ".top" instead of ".retr". I'm still having the same issue, even with .top. Am I missing something? for j in M.top(i+1, 0)[1]: emailMessage = email.message_from_string(j) #emailMessage = email.Parser.HeaderParser().parsestr(j, headersonly=True) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From") Is there another way I should be using to retrieve only the headers (not those in the body)? From martin.hellwig at dcuktec.org Thu Mar 11 17:46:57 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Mar 2010 22:46:57 +0000 Subject: Platform Requirement Checker (was Does this already exists?: A module that checks if the used platform is supported) In-Reply-To: References: Message-ID: On 03/11/10 01:37, Gabriel Genellina wrote: > En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig > escribi?: > >> Before I start reinventing a squared wheel, I have the following >> question: >> Is there already a (standard) module that wraps around the various >> os/sys information which checks if the platform + version is supported >> for what I want to do with it. > > In case you were not aware of it: see the platform module. But you'll have > to do the checks yourself (based on the info it returns). > Thanks for the reminder, it indeed slipped my mind. As Python features are luckily mostly platform independent, I am not sure if a convenient 'platform requirement check' module would be worth the energy creating it, any thoughts on that? For clarity purpose I re'added (and adapted) in what lines I was thinking: - test = RequirePlatform(do_not_raise=True) # If do_not_raise is not set or False, an error will be raised # after a failed require line, otherwise just continue. test.require(key='test1', platform='freebsd', version_min='2.2') # If the platform is anything else but FreeBSD 2.2 onwards return False # and store the result of the test. # Result of the require (and any additional tests # can be accessed using the index operators; if test['test1']: print('supported') - Other requirements like architecture, python vm type/version, cpu features, etc. Might also be nice to have. -- mph From CalWhoNOSPAM at roadrunner.com Thu Mar 11 17:52:21 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Thu, 11 Mar 2010 17:52:21 -0500 Subject: Where can I find documentation for data[:,9] References: Message-ID: "Martin P. Hellwig" wrote in message news:hnbq8q$vgm$1 at news.eternal-september.org... > On 03/11/10 22:08, Cal Who wrote: > >> Thanks, that helped a lot. >> >> I'm having trouble knowing what to search for to find documenatation. For >> example, is print a Python command, a numpy command or a java command? >> >> I like to read the documentation even if the command is working for me. >> >> >> Thanks again >> >> > Probably for you the right way would be to familiarize yourself with the > namespace concept of Python, this makes it easier to identify whether > something is built-in, a standard module or an external module. > Which makes it much easier to feed google the right clues. > > -- > mph Thanks a lot, I'll look that up now. From jcb at iteris.com Thu Mar 11 17:57:28 2010 From: jcb at iteris.com (Metalone) Date: Thu, 11 Mar 2010 14:57:28 -0800 (PST) Subject: file seek is slow References: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> Message-ID: <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> I just tried the seek test with Cython. Cython fseek() : 1.059 seconds. 30% slower than 'C' Python f.seek : 1.458 secondds. 80% slower than 'C'. It is amazing to me that Cython generates a 'C' file that is 1478 lines. #Cython code import time cdef int SEEK_SET = 0 cdef extern from "stdio.h": void* fopen(char* filename, char* mode) int fseek(void*, long, int) def main(): cdef void* f1 = fopen('video.txt', 'rb') cdef int i=1000000 t0 = time.clock() while i > 0: fseek(f1, 0, SEEK_SET) i -= 1 delta = time.clock() - t0 print "%.3f" % delta if __name__ == '__main__': main() From felix.antoine.fortin at gmail.com Thu Mar 11 18:05:00 2010 From: felix.antoine.fortin at gmail.com (=?ISO-8859-1?Q?F=E9lix=2DAntoine_Fortin?=) Date: Thu, 11 Mar 2010 15:05:00 -0800 (PST) Subject: inspect.stack() and frame Message-ID: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> Given this code : # Experience with frame import sys import inspect def foo(): stack = inspect.stack() print "foo frame : " + str(hex(id(sys._getframe()))) def foo2(): inspect.stack() print "foo2 frame : " + str(hex(id(sys._getframe()))) def bar(): print "bar frame : " + str(hex(id(sys._getframe()))) foo() foo() foo2() foo2() bar() bar() Output example : foo frame : 0x84d2c0 foo frame : 0x844bf0 foo2 frame : 0x898c90 foo2 frame : 0x898c90 bar frame : 0x898f70 bar frame : 0x898f70 Why are the ids (address) of the frame for each foo call not the same? Or why the call to "stack = inspect.stack()" change the address of the frame? From python at mrabarnett.plus.com Thu Mar 11 18:06:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 23:06:40 +0000 Subject: Parsing Email Headers In-Reply-To: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> References: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> Message-ID: <4B997780.4000009@mrabarnett.plus.com> T wrote: > On Mar 11, 3:13 pm, MRAB wrote: >> T wrote: >>> All I'm looking to do is to download messages from a POP account and >>> retrieve the sender and subject from their headers. Right now I'm 95% >>> of the way there, except I can't seem to figure out how to *just* get >>> the headers. Problem is, certain email clients also include headers >>> in the message body (i.e. if you're replying to a message), and these >>> are all picked up as additional senders/subjects. So, I want to avoid >>> processing anything from the message body. >>> Here's a sample of what I have: >>> # For each line in message >>> for j in M.retr(i+1)[1]: >>> # Create email message object from returned string >>> emailMessage = email.message_from_string(j) >>> # Get fields >>> fields = emailMessage.keys() >>> # If email contains "From" field >>> if emailMessage.has_key("From"): >>> # Get contents of From field >>> from_field = emailMessage.__getitem__("From") >>> I also tried using the following, but got the same results: >>> emailMessage = >>> email.Parser.HeaderParser().parsestr(j, headersonly=True) >>> Any help would be appreciated! >> If you're using poplib then use ".top" instead of ".retr". > > I'm still having the same issue, even with .top. Am I missing > something? > > for j in M.top(i+1, 0)[1]: > emailMessage = email.message_from_string(j) > #emailMessage = > email.Parser.HeaderParser().parsestr(j, headersonly=True) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") > > Is there another way I should be using to retrieve only the headers > (not those in the body)? The documentation does say: """unfortunately, TOP is poorly specified in the RFCs and is frequently broken in off-brand servers.""" All I can say is that it works for me with my ISP! :-) From python at mrabarnett.plus.com Thu Mar 11 18:09:05 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 23:09:05 +0000 Subject: Platform Requirement Checker (was Does this already exists?: A module that checks if the used platform is supported) In-Reply-To: References: Message-ID: <4B997811.3000607@mrabarnett.plus.com> Martin P. Hellwig wrote: > On 03/11/10 01:37, Gabriel Genellina wrote: >> En Wed, 10 Mar 2010 10:54:27 -0300, Martin P. Hellwig >> escribi?: >> >>> Before I start reinventing a squared wheel, I have the following >>> question: >>> Is there already a (standard) module that wraps around the various >>> os/sys information which checks if the platform + version is supported >>> for what I want to do with it. >> >> In case you were not aware of it: see the platform module. But you'll >> have >> to do the checks yourself (based on the info it returns). >> > Thanks for the reminder, it indeed slipped my mind. > > As Python features are luckily mostly platform independent, I am not > sure if a convenient 'platform requirement check' module would be worth > the energy creating it, any thoughts on that? > > For clarity purpose I re'added (and adapted) in what lines I was thinking: > - > test = RequirePlatform(do_not_raise=True) > # If do_not_raise is not set or False, an error will be raised > # after a failed require line, otherwise just continue. > > test.require(key='test1', platform='freebsd', version_min='2.2') > # If the platform is anything else but FreeBSD 2.2 onwards return False > # and store the result of the test. > # Result of the require (and any additional tests > # can be accessed using the index operators; > > if test['test1']: > print('supported') > - > Other requirements like architecture, python vm type/version, cpu > features, etc. Might also be nice to have. > It might be useful for up-front checking in those platform-specific scripts, although the platform module might already be fulfilling that need. From gundlach at gmail.com Thu Mar 11 18:16:36 2010 From: gundlach at gmail.com (gundlach) Date: Thu, 11 Mar 2010 15:16:36 -0800 (PST) Subject: pivot() equivalent Message-ID: I *know* this already exists, but I can't remember where: def pivot(func, seq): # I know, a good implementation shouldn't call func() twice per item return ( (x for x in seq if func(x)), (x for x in seq if not func(x)) ) I feel like I read a thread in which this was argued to death, and I can't find that either. The scenario: I have a sequence of lines from a file. I want to split it into those lines that contain a substring, and those that don't. I want it to be more efficient and prettier than with = [x for x in lines if substring in x] without = [x for x in lines if substring not in x] Does this exist? TIA, Michael From misceverything at gmail.com Thu Mar 11 18:19:36 2010 From: misceverything at gmail.com (T) Date: Thu, 11 Mar 2010 15:19:36 -0800 (PST) Subject: Parsing Email Headers References: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> Message-ID: <6e0f6857-bedd-4b23-81af-69dd06a53764@q15g2000yqj.googlegroups.com> Thanks for your suggestions! Here's what seems to be working - it's basically the same thing I originally had, but first checks to see if the line is blank response, lines, bytes = M.retr(i+1) # For each line in message for line in lines: if not line.strip(): M.dele(i+1) break emailMessage = email.message_from_string(line) # Get fields fields = emailMessage.keys() # If email contains "From" field if emailMessage.has_key("From"): # Get contents of From field from_field = emailMessage.__getitem__("From") From alfps at start.no Thu Mar 11 18:22:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Mar 2010 00:22:02 +0100 Subject: inspect.stack() and frame In-Reply-To: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> Message-ID: * F?lix-Antoine Fortin: > Given this code : > # Experience with frame > import sys > import inspect > > def foo(): > stack = inspect.stack() > print "foo frame : " + str(hex(id(sys._getframe()))) hex returns a string. applying str is therefore redundant. > def foo2(): > inspect.stack() > print "foo2 frame : " + str(hex(id(sys._getframe()))) > > def bar(): > print "bar frame : " + str(hex(id(sys._getframe()))) > > foo() > foo() > > foo2() > foo2() > > bar() > bar() > > Output example : > foo frame : 0x84d2c0 > foo frame : 0x844bf0 > foo2 frame : 0x898c90 > foo2 frame : 0x898c90 > bar frame : 0x898f70 > bar frame : 0x898f70 > > Why are the ids (address) of the frame for each foo call not the same? You're dealing with Python objects. You're not dealing with the computer's machine stack. Whether you get the same id for two objects whose lifetimes don't overlap depends on the implementation's memory and id allocation strategy. > Or why the call to "stack = inspect.stack()" change the address of the > frame? Does it? Cheers, - Alf From python at rgbaz.eu Thu Mar 11 18:29:12 2010 From: python at rgbaz.eu (PythonAB) Date: Fri, 12 Mar 2010 00:29:12 +0100 Subject: Bluetooth In-Reply-To: <4B97B7F8.2030303@fedex.com> References: <4B97B7F8.2030303@fedex.com> Message-ID: <1ED82F61-E3E8-4A3A-8028-0F8D4B82E580@rgbaz.eu> On 10 mrt 2010, at 16:17, Jeff Peck wrote: > On 3/7/2010 1:26 PM, PythonAB wrote: >> >> Hello, >> >> >> I'm writing a script that has to connect a bluetooth device >> with a 3D application. >> On my search for a bluetooth module i ran into this: >> http://www.python.org/download/releases/2.4/notes/ >> where it says: >> "The socket module now supports Bluetooth sockets, >> if the system has " >> >> Yet I can't find anything at all in the socket manuals >> nor anywhere else on the site... >> >> Does the socket module really support Bluetooth out of the box? >> I've used socket before but never read anything about bluetooth... >> >> Maybe I need to get the bluetooth.h file, but i have no idea what I >> am supposed to do with it... >> >> Can anyone shed some light on this for me please? >> >> thanks in advance, >> >> gr >> Arno > > Have you come across the PyBluez library yet? I recently used it in a project and it worked very well. > > Hth, > Jeff Hi Jeff, Yes I ran into it, but couldn't find an OSX version... I'm using the lightblue module now but would have preferred to use the socket module without compiling python myself. Sorry for not mentioning the platform. gr Arno -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Thu Mar 11 18:39:12 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 11 Mar 2010 18:39:12 -0500 Subject: pivot() equivalent In-Reply-To: References: Message-ID: <4b997f06$0$5013$607ed4bc@cv.net> On 3/11/2010 6:16 PM, gundlach wrote: > I *know* this already exists, but I can't remember where: > > def pivot(func, seq): > # I know, a good implementation shouldn't call func() twice per item > return ( (x for x in seq if func(x)), (x for x in seq if not > func(x)) ) > > I feel like I read a thread in which this was argued to death, and I > can't find that either. > > The scenario: I have a sequence of lines from a file. I want to split > it into those lines that contain a substring, and those that don't. I > want it to be more efficient and prettier than > > with = [x for x in lines if substring in x] > without = [x for x in lines if substring not in x] > > Does this exist? > > TIA, > Michael Try this: > type lines.txt the quick brown fox jumps over the lazy dog > type pivot.py def pivot(pivot_function, filename): a_list = [] b_list = [] for line in open(filename): target_list = a_list if pivot_function(line) else b_list target_list.append(line[:-1]) return (a_list, b_list) print pivot(lambda line: 'e' in line, "lines.txt") > python pivot.py (['the', 'over', 'the'], ['quick', 'brown', 'fox', 'jumps', 'lazy', 'dog']) -John From python at mrabarnett.plus.com Thu Mar 11 18:50:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Mar 2010 23:50:13 +0000 Subject: pivot() equivalent In-Reply-To: References: Message-ID: <4B9981B5.4020005@mrabarnett.plus.com> gundlach wrote: > I *know* this already exists, but I can't remember where: > > def pivot(func, seq): > # I know, a good implementation shouldn't call func() twice per item > return ( (x for x in seq if func(x)), (x for x in seq if not > func(x)) ) > > I feel like I read a thread in which this was argued to death, and I > can't find that either. > > The scenario: I have a sequence of lines from a file. I want to split > it into those lines that contain a substring, and those that don't. I > want it to be more efficient and prettier than > > with = [x for x in lines if substring in x] > without = [x for x in lines if substring not in x] > > Does this exist? > The clearest way is just: def pivot(func, seq): with, without = [], [] for x in seq: if func(x): with.append(x) else: without.append(x) return with, without From felix.antoine.fortin at gmail.com Thu Mar 11 19:03:07 2010 From: felix.antoine.fortin at gmail.com (=?ISO-8859-1?Q?F=E9lix=2DAntoine_Fortin?=) Date: Thu, 11 Mar 2010 16:03:07 -0800 (PST) Subject: inspect.stack() and frame References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> Message-ID: <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> On Mar 11, 6:22?pm, "Alf P. Steinbach" wrote: > * F lix-Antoine Fortin: > > > Given this code : > > # Experience with frame > > import sys > > import inspect > > > def foo(): > > ? ? stack = inspect.stack() > > ? ? print "foo frame : " + str(hex(id(sys._getframe()))) > > hex returns a string. applying str is therefore redundant. > My bad. > > > > > > def foo2(): > > ? ? inspect.stack() > > ? ? print "foo2 frame : " + str(hex(id(sys._getframe()))) > > > def bar(): > > ? ? print "bar frame : " + str(hex(id(sys._getframe()))) > > > foo() > > foo() > > > foo2() > > foo2() > > > bar() > > bar() > > > Output example : > > foo frame : 0x84d2c0 > > foo frame : 0x844bf0 > > foo2 frame : 0x898c90 > > foo2 frame : 0x898c90 > > bar frame : 0x898f70 > > bar frame : 0x898f70 > > > Why are the ids (address) of the frame for each foo call not the same? > > You're dealing with Python objects. You're not dealing with the computer's > machine stack. Whether you get the same id for two objects whose lifetimes don't > overlap depends on the implementation's memory and id allocation strategy. > Okay, I thought I got that when I read the id documentation, but now I get it. So the only to compare two ids, is by making sure their lifetimes overlap. In this case, instead of keeping the ids, I have to keep a reference on the frame to make sure it is still alive when I will compare it with a second one. Thanks! > > Or why the call to "stack = inspect.stack()" change the address of the > > frame? > > Does it? > Yeah it does... I always get N different id when I run foo() N times in a row. Actually, what you said about lifetime applies here too. Here is another quick snippet : import sys import inspect def foo(): stack = inspect.stack() return sys._getframe() def foo2(): stack = inspect.stack() del stack return sys._getframe() def bar(): inspect.stack() return sys._getframe() frame_foo = foo() frame_foo2 = foo2() frame_bar = bar() print sys.getrefcount(frame_foo) print sys.getrefcount(frame_foo2) print sys.getrefcount(frame_bar) Output : 3 2 2 So it seems that there is one more reference to the foo frame because only because of "stack = inspect.stack()", so its lifetime isn't done contrary to foo2 and bar frame, and the frame id of a foo frame is different for each call. Now, what is keeping a reference on foo frame? Thanks Alf, Felix From gagsl-py2 at yahoo.com.ar Thu Mar 11 20:22:51 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Mar 2010 22:22:51 -0300 Subject: EOFError: EOF when reading a line References: Message-ID: En Thu, 11 Mar 2010 06:12:02 -0300, Mihir Patel escribi?: > I am trying to use the subprocess to send the data to child process. I > am not sure why i keep getting "EOFError: EOF when reading a line" > > command_line = 'python test_input.py' > p =subprocess.Popen(command_line, shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE) > print 'output:', p.communicate()[0] > > o,e = p.communicate('test') You may call communicate at most once. -- Gabriel Genellina From albert at spenarnc.xs4all.nl Thu Mar 11 20:33:12 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2010 01:33:12 GMT Subject: My four-yorkshireprogrammers contribution References: <20100224212303.242222c6@geekmail.INVALID> <7v9e3rFl7mU1@mid.individual.net> Message-ID: In article <7vdo8sFrelU1 at mid.individual.net>, Gregory Ewing wrote: >MRAB wrote: > >> By the standards of just a few years later, that's not so much a >> microcomputer as a nanocomputer! > >Although not quite as nano as another design published >in EA a couple of years earlier, the EDUC-8: > > http://www.sworld.com.au/steven/educ-8/ > >It had a *maximum* of 256 bytes -- due to the architecture, >there was no way of addressing any more. Also it was >divided into 16-byte pages, with indirect addressing >required to access anything in a different page from >the instruction. Programming for it must have been >rather challenging. > >As far as I know, the EDUC-8 is unique in being the >only computer design ever published in a hobby magazine >that *wasn't* based on a microprocessor -- it was all >built out of 9000 and 7400 series TTL logic chips! There was the 74 computer in Elektuur (now Elektor). That was a quite respectable computer, built (you guessed) from 74-series chips. How many were built, I don't know. > >-- >Greg Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From steve at holdenweb.com Thu Mar 11 20:43:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Mar 2010 20:43:44 -0500 Subject: file seek is slow In-Reply-To: <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> References: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> Message-ID: Metalone wrote: > I just tried the seek test with Cython. > Cython fseek() : 1.059 seconds. 30% slower than 'C' > Python f.seek : 1.458 secondds. 80% slower than 'C'. > > It is amazing to me that Cython generates a 'C' file that is 1478 > lines. > And what response are you seeking to your amazement? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From albert at spenarnc.xs4all.nl Thu Mar 11 20:49:47 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2010 01:49:47 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <7v69rcFcmeU1@mid.individual.net> Message-ID: In article , Grant Edwards wrote: >On 2010-03-03, Grant Edwards wrote: >> On 2010-03-03, Gregory Ewing wrote: >>> Grant Edwards wrote: >>> >>>> Just a mediocre copy of the CP/M filesystem, which was in turn >>>> copied from DEC's RSTS or RSX. >>> >>> It was actually an improvement over CP/M's file system. CP/M >>> didn't have hierarchical directories >> >> Neither did the original MS-DOS filesystem. >> >>> or timestamps and recorded file sizes in 128-byte blocks >>> rather than bytes. >> >> I thought that was true of the original MS-DOS filesystem as >> well, but I wouldn't bet money on it. > >I definitely remember that old MS-DOS programs would treat >Ctrl-Z as an EOF marker when it was read from a text file and >would terminate a text file with a Ctrl-Z when writing one. > >I don't know if that was because the underlying filesystem was >still did everything in blocks or if it was because those >MS-DOS programs were direct ports of CP/M programs. I would >have sworn that the orignal MS-DOS file API was FCB based and >worked almost exactly like CP/M. IIRC, the "byte stream" API >showed up (in the OS) sever versions later. The byte stream >API was implemented by many compiler vendor's C libraries on >top of the block-oriented FCB API. My programming reference manual for MSDOS 6.0 (1993) states the FCB stuff as "superseded" (not obsolete or obsolescent). It states: "A programmer should not use a superseded function except to maintain compatibility with versions of MS-DOS earlier than version 2.0." FCB did *not* support paths, but you could access the current directory. >-- >Grant Edwards grant.b.edwards Yow! I had a lease on an Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From ldo at geek-central.gen.new_zealand Thu Mar 11 22:15:23 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Mar 2010 16:15:23 +1300 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4b947298$0$8836$c3e8da3@news.astraweb.com> Message-ID: In message , Dave Angel wrote: > However, if there's anything in there about how to derive the polynomial > algorithm from (a few) samples I missed it entirely. Given that CRC is all just a sequence of xor operations, what happens if you xor various pairs of CRCs together, wouldn?t that cancel out at least parts of the operations? From ldo at geek-central.gen.new_zealand Thu Mar 11 22:16:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 12 Mar 2010 16:16:56 +1300 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: In message <7vlameF7goU1 at mid.individual.net>, Gregory Ewing wrote: > I'm going by the fact that the application reports a > "CRC mismatch" when it's wrong. I can't be sure that what > it calls a "CRC" is really a true CRC, but it's more than > a simple sum, because changing one bit in the file results > in a completely different value. They could be using a strong cryptographic hash and truncating it to 16 bits or something. In which case you?ve got your work cut out for you... From steve at REMOVE-THIS-cybersource.com.au Thu Mar 11 22:24:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 03:24:39 GMT Subject: Can't define __call__ within __init__? References: Message-ID: <4b99b3f7$0$27822$c3e8da3@news.astraweb.com> On Thu, 11 Mar 2010 08:20:14 -0800, Steve Howell wrote: >> (2) special methods like __call__ are only called on the class, not the >> instance, so you can't give each instance its own method. >> >> > Are you sure about that? This program prints 1, 2, 1, 2. The rules for classic classes are different. Since classic classes have gone away in 3.0, and are becoming rarer in 2.x, I didn't bother to mention the complication. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Mar 11 22:30:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 03:30:02 GMT Subject: Can't define __call__ within __init__? References: Message-ID: <4b99b53a$0$27822$c3e8da3@news.astraweb.com> On Thu, 11 Mar 2010 07:56:59 -0500, Neal Becker wrote: > The example I showed was just a toy problem. The real problem is I > expect to call a function many times, and I want to avoid the overhead > of the 'if blah' everytime. Unless the __call__ methods are very small, the overhead of one extra if and one extra attribute lookup will be insignificant. -- Steven From lin.jianying at hotmail.com Thu Mar 11 22:55:13 2010 From: lin.jianying at hotmail.com (marrylin) Date: Thu, 11 Mar 2010 19:55:13 -0800 (PST) Subject: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! Message-ID: Hello,everybody,the good shoping place,the new year approaching, click in. Let's facelift bar! ===== HTTP://steezeclothing.com ==== Air jordan(1-24)shoes $33 UGG BOOT $50 Nike shox(R4,NZ,OZ,TL1,TL2,TL3) $35 Handbags(Coach lv fendi d&g) $35 Tshirts (Polo ,ed hardy,lacoste) $16 Jean(True Religion,ed hardy,coogi) $30 Sunglasses(Oakey,coach,gucci,Armaini) $16 New era cap $15 Bikini (Ed hardy,polo) $25 FREE SHIPPING From python at bdurham.com Fri Mar 12 00:41:16 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 12 Mar 2010 00:41:16 -0500 Subject: Any downsides to UPX-ing my 32-bit Python 2.6.4 EXE/PYD/DLL files? Message-ID: <1268372476.27561.1364429171@webmail.messagingengine.com> Are there any downsides to UPX-ing my 32-bit Python 2.6.4 development environment EXE/PYD/DLL files? The reason I'm asking is that I frequently use a custom PY2EXE script that UPX's copies of these files on every build. Yes, I could get fancy and try to cache UPXed files, but I think a simpler, safer, and higher performance solution would be for me to just UPX my Python 2.6.4 directory once and be done with it. What are your thoughts? Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Fri Mar 12 00:48:52 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 06:48:52 +0100 Subject: sqlite3 is sqlite 2? Message-ID: <4B99D5C4.8070100@shopzeus.com> gandalf at ubuntu:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3.version '2.4.1' Is it possible to install a real sqlite version 3 somehow? I really need it because I have to use savepoint/rollback to. That is only supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know that is not a question about Python itself. But still, it is interesting that a module named "sqlite3" can actually be used for something called "sqlite 2". Thanks Laszlo From pmaupin at gmail.com Fri Mar 12 01:02:54 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Fri, 12 Mar 2010 00:02:54 -0600 Subject: ANNOUNCE: RSON v 0.02 available Message-ID: RSON (Readable Serial Object Notation) is a superset of JSON that is suitable for files that humans have to edit and diff. The current release is decoder-only, but the decoder will read files encoded by JSON encoders such as json or simplejson. The current release consists of a single Python module and a short manual. The manual admittedly needs some work, but has a few syntax examples. http://code.google.com/p/rson/ From gagsl-py2 at yahoo.com.ar Fri Mar 12 01:11:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Mar 2010 03:11:44 -0300 Subject: inspect.stack() and frame References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> Message-ID: En Thu, 11 Mar 2010 21:03:07 -0300, F?lix-Antoine Fortin escribi?: > On Mar 11, 6:22 pm, "Alf P. Steinbach" wrote: >> * F lix-Antoine Fortin: >> >> > Given this code : >> > # Experience with frame >> > import sys >> > import inspect >> >> > def foo(): >> > stack = inspect.stack() >> > print "foo frame : " + str(hex(id(sys._getframe()))) >> >> > def foo2(): >> > inspect.stack() >> > print "foo2 frame : " + str(hex(id(sys._getframe()))) >> >> > def bar(): >> > print "bar frame : " + str(hex(id(sys._getframe()))) >> >> > foo() >> > foo() >> >> > foo2() >> > foo2() >> >> > bar() >> > bar() >> >> > Output example : >> > foo frame : 0x84d2c0 >> > foo frame : 0x844bf0 >> > foo2 frame : 0x898c90 >> > foo2 frame : 0x898c90 >> > bar frame : 0x898f70 >> > bar frame : 0x898f70 >> >> > Why are the ids (address) of the frame for each foo call not the same? >> >> You're dealing with Python objects. You're not dealing with the >> computer's >> machine stack. Whether you get the same id for two objects whose >> lifetimes don't >> overlap depends on the implementation's memory and id allocation >> strategy. >> > > Okay, I thought I got that when I read the id documentation, but now I > get it. > So the only to compare two ids, is by making sure their lifetimes > overlap. In > this case, instead of keeping the ids, I have to keep a reference on > the frame > to make sure it is still alive when I will compare it with a second > one. The best way to compare object identities is using the 'is' operator: `a is b` returns true if and only if after evaluating both operands they are the very same object. id() may be misleading if you are not careful: py> id([]) == id([]) True py> [] is [] False >> > Or why the call to "stack = inspect.stack()" change the address of the >> > frame? >> >> Does it? > > Yeah it does... I always get N different id when I run foo() N times > in a row. Think again after reading the response below. > Actually, what you said about lifetime applies here too. Here is > another quick > snippet : > > import sys > import inspect > > def foo(): > stack = inspect.stack() > return sys._getframe() > > def foo2(): > stack = inspect.stack() > del stack > return sys._getframe() > > def bar(): > inspect.stack() > return sys._getframe() > > frame_foo = foo() > frame_foo2 = foo2() > frame_bar = bar() > > print sys.getrefcount(frame_foo) > print sys.getrefcount(frame_foo2) > print sys.getrefcount(frame_bar) > > Output : > 3 > 2 > 2 > > So it seems that there is one more reference to the foo frame because > only because of "stack = inspect.stack()", so its lifetime isn't done > contrary to foo2 and bar frame, and the frame id of a foo frame is > different for each call. > > Now, what is keeping a reference on foo frame? The foo frame keeps a reference to the 'stack' local variable (in its f_locals attribute), and 'stack' keeps a reference to the current frame too. This doesn't happen neither in foo2() nor bar(), where the local array is empty. inspect.stack() isn't special: any other reference to the current frame would have the same effect. Let's examine the simple example above: py> id([]) == id([]) True Python creates an empty list, takes its id, and discards the list. The list object is then ready to be re-used again (the interpreter keeps a list of free objects for many common types), so the right-hand side gets the very same list. The same thing happens with the frame object in your first examples foo2() and bar(): the frame object is discarded after leaving the function, and is ready to be used again in the next call. But foo() creates a circular reference - the frame object is still alive after leaving the first call, so the second call must use a new frame. (The garbage collector will, eventually, break the cycle and free those objects, but not very soon). -- Gabriel Genellina From enleverLesX_XXmcX at XmclavXeauX.com.invalid Fri Mar 12 01:32:13 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Fri, 12 Mar 2010 07:32:13 +0100 Subject: bypass UAC control through python script (to be run from batchfile) References: <26028cd0-8ead-47d0-95d8-09e2214dddd3@e7g2000yqf.googlegroups.com> Message-ID: <4b99dff5$0$17899$ba4acef3@reader.news.orange.fr> Hi ! Install a resident soff (script) by task-planified, in Administrator rights. Then, call this script from current work, for bypass UAC. @-salutations -- Michel Claveau From gandalf at shopzeus.com Fri Mar 12 01:46:48 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 07:46:48 +0100 Subject: sqlite savepoint problem (was: Re: sqlite3 is sqlite 2?) In-Reply-To: <87bpeqzmmv.fsf@castleamber.com> References: <87bpeqzmmv.fsf@castleamber.com> Message-ID: <4B99E358.4020507@shopzeus.com> > > That's the sqlite *bindings* version: > > >>> sqlite3.version > '2.4.1' > >>> sqlite3.sqlite_version > '3.6.16' > >>> Thanks. I tried it and RELEASE command didn't work: >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> with conn: ... conn.execute("BEGIN") ... conn.execute("create table a ( i integer)") ... conn.execute("insert into a values (1)") ... conn.execute("savepoint sp1") ... conn.execute("insert into a values(2)") ... conn.execute("release sp1") ... conn.execute("COMMIT") ... Traceback (most recent call last): File "", line 7, in sqlite3.OperationalError: no such savepoint: sp1 >>> The syntax is correct: http://www.sqlite.org/lang_savepoint.html The savepoint was really created. But I get this error, telling "no such savepoint". What is wrong here? Maybe it has to do something with transaction isolation? :-s Thank you Laszlo From agoretoy at gmail.com Fri Mar 12 01:52:15 2010 From: agoretoy at gmail.com (alex goretoy) Date: Fri, 12 Mar 2010 00:52:15 -0600 Subject: execute bash builtins in python Message-ID: hi, i'm trying to write a section of my program that needs to run bash builtin alias and declare, i've googled and tried every type of example i could find no to avail. this is what I've tried below and it doesn't work, is there a way for me to execute a bah builin from python? what i need is to take alias output and pipe it to another command with python and return the results to a string or list. >>> p1=Popen(["alias"],stdout=PIPE) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/subprocess.py", line 621, in __init__ errread, errwrite) File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory if i add shell=True i get empty string and no thins error message >>> p1=Popen(["alias"],stdout=PIPE,shell=True) >>> p1 >>> p1.stdout.read() '' thank you, -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at riddergarn.dk Fri Mar 12 02:11:20 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 07:11:20 +0000 Subject: Threading, Queue for a function so it only runs once at a time. Message-ID: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> Hi, Im programming a simple webcrawler with threading for the fun of it, which is inserting the data fetch into a mysql database, but after continuously cause my mysql server to produce error during database queries (i assume its cause because of the many execution at the same time.) the scipt produces errors. I figured out i need some kind of queue for the function i use to insert into the database, to make sure its only called once at a time. I have looked at the Queue module but its for more complicated than my current python skills can cope with. :) Would somebody please help me out here? Thanks. -- John P. From zookog at gmail.com Fri Mar 12 02:11:37 2010 From: zookog at gmail.com (Zooko O'Whielacronx) Date: Fri, 12 Mar 2010 00:11:37 -0700 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes Message-ID: Folks: Every couple of years I run into a problem where some Python code that worked well at small scales starts burning up my CPU at larger scales, and the underlying issue turns out to be the idiom of accumulating data by string concatenation. It just happened again (http://foolscap.lothar.com/trac/ticket/149 ), and as usual it is hard to make the data accumulator efficient without introducing a bunch of bugs into the surrounding code. So this time around I decided to try encapsulating my preferred more efficient idiom into a reusable class. So I present to you StringChain, which is an efficient way to accumulate and process data in many chunks: http://tahoe-lafs.org/trac/stringchain Here are some benchmarks generated by running python -OOu -c 'from stringchain.bench import bench; bench.quick_bench()' as instructed by the README.txt file. The N: in the left-hand column is how many bytes were in the test dataset. The ave rate: number in the right-hand column is how many bytes per second were processed. "naive" means the string-based idiom sketched above and "strch" means using the StringChain class. _buildup init_naive N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 890, ave rate: 58350579 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 265, ave rate: 34800398 N: 262144, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 79, ave rate: 20745346 N: 524288, time: best: 0.05, 2th-best: 0.05, ave: 0.05, 2th-worst: 0.05, worst: 0.05 (of 5), reps/s: 20, ave rate: 10823850 _buildup init_strch N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 25543, ave rate: 1674043282 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 14179, ave rate: 1858538925 N: 262144, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 8016, ave rate: 2101513050 N: 524288, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 4108, ave rate: 2154215572 _consume init_naive_loaded N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 931, ave rate: 61037862 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 270, ave rate: 35454393 N: 262144, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 74, ave rate: 19471963 N: 524288, time: best: 0.05, 2th-best: 0.05, ave: 0.05, 2th-worst: 0.05, worst: 0.06 (of 5), reps/s: 19, ave rate: 10146747 _consume init_strch_loaded N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 4309, ave rate: 282447500 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 2313, ave rate: 303263357 N: 262144, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 1186, ave rate: 311159052 N: 524288, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 606, ave rate: 317814669 _randomy init_naive N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 479, ave rate: 31450561 N: 131072, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 140, ave rate: 18461191 N: 262144, time: best: 0.02, 2th-best: 0.02, ave: 0.02, 2th-worst: 0.03, worst: 0.03 (of 5), reps/s: 42, ave rate: 11127714 N: 524288, time: best: 0.06, 2th-best: 0.07, ave: 0.08, 2th-worst: 0.08, worst: 0.09 (of 5), reps/s: 13, ave rate: 6906341 _randomy init_strch N: 65536, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 973, ave rate: 63827127 N: 131072, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 495, ave rate: 64970669 N: 262144, time: best: 0.00, 2th-best: 0.00, ave: 0.00, 2th-worst: 0.00, worst: 0.00 (of 5), reps/s: 239, ave rate: 62913360 N: 524288, time: best: 0.01, 2th-best: 0.01, ave: 0.01, 2th-worst: 0.01, worst: 0.01 (of 5), reps/s: 121, ave rate: 63811569 The naive approach is slower than the StringChain class, and the bigger the dataset the slower it goes. The StringChain class is fast and also it is scalable (with regard to these benchmarks at least...). Thanks! Regards, Zooko From no.email at nospam.invalid Fri Mar 12 02:20:08 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Mar 2010 23:20:08 -0800 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: Message-ID: <7xd3za6m6v.fsf@ruckus.brouhaha.com> "Zooko O'Whielacronx" writes: > Every couple of years I run into a problem where some Python code that > worked well at small scales starts burning up my CPU at larger scales, > and the underlying issue turns out to be the idiom of accumulating > data by string concatenation. I usually use StringIO or cStringIO for that (python 2.x syntax): buf = cStringIO() buf.write("first thing") buf.write("second thing") result = buf.getvalue() Sometimes I like to use a generator instead: def stuff(): yield "first thing" yield "second thing" result = ''.join(stuff()) From martin at v.loewis.de Fri Mar 12 02:31:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 12 Mar 2010 08:31:42 +0100 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> References: <4B992FB5.8090207@v.loewis.de> <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> Message-ID: <4B99EDDE.5070604@v.loewis.de> > I?m sorry everyone. I didn?t realise I had installed the 64-bit > version of Python. Well, at least someone else might find have the > same problem. But I think that there is going to be a bit of a rough > patch as everyone moves over to 64-bit. Expect that move to take a few more years. 64-bit CPUs were introduced more than ten years ago (e.g. Alpha, in 1992), and only slowly reach "the masses". People typically still don't have more than 4GiB of memory in their desktop PCs or laptops, so users who do install 64-bit operating systems on such hardware are still early adaptors. Regards, Martin From gandalf at shopzeus.com Fri Mar 12 02:32:21 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 08:32:21 +0100 Subject: sqlite savepoint problem In-Reply-To: <1268600658.2846.17.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> Message-ID: <4B99EE05.8060505@shopzeus.com> > From memory you can't issue a "CREATE TABLE" statement inside a > transaction, at least not at the default isolation level. Such a > statement will automatically commit the current transaction. Doesn't > help with your current problem but worth pointing out :-) > Thank you. I'll keep in mind. > When debugging strange transaction behaviour, I find it easiest to > create the connection with isolation_level=None so that are no implicit > transactions being created behind your back. Not sure why, but setting > this makes your example work for me. > Yes, same for me. But setting it to None means auto commit mode! See here: http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions But it does not work that way. Look at this example import sqlite3 conn = sqlite3.connect(':memory:') conn.isolation_level = None with conn: conn.execute("create table a ( i integer ) ") with conn: conn.execute("insert into a values (1)") conn.execute("SAVEPOINT sp1") conn.execute("insert into a values (2)") conn.execute("SAVEPOINT sp2") conn.execute("insert into a values (3)") conn.execute("ROLLBACK TO sp2") conn.execute("insert into a values (4)") conn.execute("RELEASE sp1") with conn: for row in conn.execute("select * from a"): print row It prints: (1,) (2,) (4,) So everything is working. Nothing is auto commited. But if I change it to "DEFERRED" or "IMMEDIATE" or "EXCLUSIVE" then it won't work. Why? I'm now confused. Also, I could not find anything about these isolation levels on the sqlite website. The only think I could find is "PRAGMA read_uncommited". If that is the same as setting isolation_level to None, then I don't want it. L From gandalf at shopzeus.com Fri Mar 12 02:48:33 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 08:48:33 +0100 Subject: sqlite savepoint problem In-Reply-To: <4B99EE05.8060505@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> Message-ID: <4B99F1D1.2070202@shopzeus.com> > > I'm now confused. Also, I could not find anything about these > isolation levels on the sqlite website. The only think I could find is > "PRAGMA read_uncommited". If that is the same as setting > isolation_level to None, then I don't want it. Yes, it is. Here is a test: import os import sqlite3 import threading import time FPATH = '/tmp/test.sqlite' if os.path.isfile(FPATH): os.unlink(FPATH) def getconn(): global FPATH conn = sqlite3.connect(FPATH) conn.isolation_level = None return conn class Thr1(threading.Thread): def run(self): conn = getconn() print "Thr1: Inserting 0,1,2,3,4,5" with conn: for i in range(6): conn.execute("insert into a values (?)",[i]) print "Thr1: Commited" with conn: print "Thr1: Selecting all rows:" for row in conn.execute("select * from a"): print row print "Thr1: Wait some..." time.sleep(3) print "Thr1: Selecting again, in the same transaction" for row in conn.execute("select * from a"): print row class Thr2(threading.Thread): def run(self): conn = getconn() with conn: print "Thr2: deleting all rows from a" conn.execute("delete from a") print "Thr2: Now we wait some BEFORE commiting changes." time.sleep(3) print "Thr2: Will roll back!" raise Exception def main(): with getconn() as conn: conn.execute("create table a ( i integer ) ") thr1 = Thr1() thr1.start() time.sleep(1) thr1 = Thr2() thr1.start() main() And the test result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction Thr2: Will roll back! Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner self.run() File "test.py", line 44, in run raise Exception Exception It means that setting isolation_level to None will really allow uncommited changes to be read by other transactions! This is sad, and of course this is something that I do not want. If I change it to DEFERRED then I get a correct result: Thr1: Inserting 0,1,2,3,4,5 Thr1: Commited Thr1: Selecting all rows: (0,) (1,) (2,) (3,) (4,) (5,) Thr1: Wait some... Thr2: deleting all rows from a Thr2: Now we wait some BEFORE commiting changes. Thr1: Selecting again, in the same transaction (0,) (1,) (2,) (3,) (4,) (5,) Thr2: Will roll back! However, then savepoints won't work. Is there any way to use read commited (or higher) isolation level, and have savepoints working at the same time? I don't see how would savepoints be useful without at least read commited isolation level. :-( L From dr.cg at 126.com Fri Mar 12 02:51:11 2010 From: dr.cg at 126.com (CHEN Guang) Date: Fri, 12 Mar 2010 15:51:11 +0800 (CST) Subject: file seek is slow Message-ID: <61ca1c62.17647.127515b0539.Coremail.dr.cg@126.com> Metalone wrote: > I just tried the seek test with Cython. > Cython fseek() : 1.059 seconds. 30% slower than 'C' > Python f.seek : 1.458 secondds. 80% slower than 'C'. > > It is amazing to me that Cython generates a 'C' file that is 1478 > lines. > PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. PythoidC is the C language like the Python, by the Python and for the Python. CHEN Guang -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Fri Mar 12 03:15:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Mar 2010 09:15:09 +0100 Subject: file seek is slow In-Reply-To: <61ca1c62.17647.127515b0539.Coremail.dr.cg@126.com> References: <61ca1c62.17647.127515b0539.Coremail.dr.cg@126.com> Message-ID: CHEN Guang, 12.03.2010 08:51: > Metalone wrote: >> I just tried the seek test with Cython. >> Cython fseek() : 1.059 seconds. 30% slower than 'C' >> Python f.seek : 1.458 secondds. 80% slower than 'C'. >> >> It is amazing to me that Cython generates a 'C' file that is 1478 >> lines. > > PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. > PythoidC is the C language like the Python, by the Python and for the Python. Except that it's not a language but rather a syntax converter, i.e. it doesn't really add any features to the C language but rather restricts Python syntax to C language features (plus a bit of header file introspection, it seems, but C's preprocessor has a bit of that, too). Stefan From gandalf at shopzeus.com Fri Mar 12 03:35:27 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 09:35:27 +0100 Subject: sqlite savepoint problem [solved] In-Reply-To: <1268604831.2846.23.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> <1268604831.2846.23.camel@durian> Message-ID: <4B99FCCF.5080506@shopzeus.com> > No it doesn't. The problem is that using a connection as a context > manager doesn't do what you think. > > It does *not* start a new transaction on __enter__ and commit it on > __exit__. As far as I can tell it does nothing on __enter__ and calls > con.commit() or con.rollback() on exit. With isolation_level=None, > these are no-ops. > Thank you Ryan! You are abolutely right, and thank you for reading the source. Now everything works as I imagined. The way the context manager and isolation_level works looks very very strange to me. Here is a demonstration: import sqlite3 def getconn(): conn = sqlite3.connect(':memory:') conn.isolation_level = None return conn def main(): with getconn() as conn: conn.execute("create table a ( i integer ) ") try: conn.execute("insert into a values (1)") with conn: conn.execute("insert into a values (2)") raise Exception except: print "There was an error" for row in conn.execute("select * from a"): print row main() Output: There was an error (1,) (2,) Looks like the context manager did not roll back anything. If I remove isolation_level=None then I get this: There was an error E.g. the context manager rolled back something that was executed outside the context. I cannot argue with the implementation - it is that way. But this is not what I would expect. I believe I'm not alone with this. Using your connection manager, everything is perfect: There was an error (1,) The only thing I have left is to implement a connection manager that emulates nested transactions, using a stack of savepoints. :-) Suggestions: Just for clarity, we should put a comment at the end of the documentation here: http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions I would add at least these things: #1. By using isolation_level = None, connection objects (used as a context manager) WON'T automatically commit or rollback transactions. #2. Using any isolation level, connection objects WON'T automatically begin a transaction. #3. Possibly, include your connection manager class code, to show how to do it "the expected" way. Also one should clarify in the documentation, what isolation_level does. Looks like setting isolation_level to None is not really an "auto commit mode". It is not even part of sqlite itself. It is part of the python extension. Thank you again. Laszlo From steve at REMOVE-THIS-cybersource.com.au Fri Mar 12 03:52:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 08:52:30 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: Message-ID: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> On Fri, 12 Mar 2010 00:11:37 -0700, Zooko O'Whielacronx wrote: > Folks: > > Every couple of years I run into a problem where some Python code that > worked well at small scales starts burning up my CPU at larger scales, > and the underlying issue turns out to be the idiom of accumulating data > by string concatenation. I don't mean to discourage you, but the simple way to avoid that is not to accumulate data by string concatenation. The usual Python idiom is to append substrings to a list, then once, at the very end, combine into a single string: accumulator = [] for item in sequence: accumulator.append(process(item)) string = ''.join(accumulator) > It just happened again > (http://foolscap.lothar.com/trac/ticket/149 ), and as usual it is hard > to make the data accumulator efficient without introducing a bunch of > bugs into the surrounding code. I'm sorry, I don't agree about that at all. I've never come across a situation where I wanted to use string concatenation and couldn't easily modify it to use the list idiom above. [...] > Here are some benchmarks generated by running python -OOu -c 'from > stringchain.bench import bench; bench.quick_bench()' as instructed by > the README.txt file. To be taken seriously, I think you need to compare stringchain to the list idiom. If your benchmarks favourably compare to that, then it might be worthwhile. -- Steven From stefan_ml at behnel.de Fri Mar 12 03:56:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Mar 2010 09:56:00 +0100 Subject: file seek is slow In-Reply-To: <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> References: <781d69b1-c5e1-4013-9015-4983dbfaa4d7@k6g2000prg.googlegroups.com> <5fab36b5-8f04-4e17-98c0-67aab24bb239@u19g2000prh.googlegroups.com> Message-ID: Metalone, 11.03.2010 23:57: > I just tried the seek test with Cython. > Cython fseek() : 1.059 seconds. 30% slower than 'C' > Python f.seek : 1.458 secondds. 80% slower than 'C'. > > It is amazing to me that Cython generates a 'C' file that is 1478 > lines. Well, it generated an optimised Python interface for your module and made it compilable in CPython 2.3 through 3.2. It doesn't look like your C module features that. ;) > #Cython code > > import time > > cdef int SEEK_SET = 0 > > cdef extern from "stdio.h": > void* fopen(char* filename, char* mode) > int fseek(void*, long, int) Cython ships with a stdio.pxd that you can cimport. It looks like it doesn't currently define fseek(), but it defines at least fopen() and FILE. Patches are always welcome. > def main(): > cdef void* f1 = fopen('video.txt', 'rb') > cdef int i=1000000 > t0 = time.clock() > while i> 0: > fseek(f1, 0, SEEK_SET) > i -= 1 > delta = time.clock() - t0 Note that the call to time.clock() takes some time, too, so it's not surprising that this is slower than hand-written C code. Did you test how it scales? Also, did you look at the generated C code or the annotated Cython code (cython -a)? Did you make sure both were compiled with the same CFLAGS? Also, any reason you're not using a for-in-xrange loop? It shouldn't make a difference in speed, it's just more common. You even used a for loop in your C code. Finally, I'm not sure why you think that these 30% matter at all. In your original post, you even state that seek-time isn't the "deal breaker", so maybe you should concentrate on the real issues? Stefan From neo100110 at gmail.com Fri Mar 12 03:59:19 2010 From: neo100110 at gmail.com (Neo) Date: Fri, 12 Mar 2010 00:59:19 -0800 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: I have learned java for half a year and now I want to learn Python, should I learn python 3k or the traditional version? On Wed, Mar 10, 2010 at 7:19 AM, kj wrote: > > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rizwanahmed24 at gmail.com Fri Mar 12 04:00:48 2010 From: rizwanahmed24 at gmail.com (rizwanahmed24 at gmail.com) Date: Fri, 12 Mar 2010 01:00:48 -0800 (PST) Subject: bypass UAC control through python script (to be run from batchfile) References: <26028cd0-8ead-47d0-95d8-09e2214dddd3@e7g2000yqf.googlegroups.com> <4b99dff5$0$17899$ba4acef3@reader.news.orange.fr> Message-ID: <2351c608-2ad5-4835-a4cb-068f6646ede0@k17g2000yqb.googlegroups.com> Hi Michel. what is this 'resident soff' script, i cannot find it on google. Secondly if i was to install something in admin mode, then i would have installed the application i want to install. The actual problem is that i dont want to manually run something with admin rights and install. still havent got the solution From jgardner at jonathangardner.net Fri Mar 12 04:05:27 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 12 Mar 2010 01:05:27 -0800 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> Message-ID: <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> On Wed, Mar 3, 2010 at 2:41 PM, Avid Fan wrote: > Jonathan Gardner wrote: >> >> I see it as a sign of maturity with sufficiently scaled software that >> they no longer use an SQL database to manage their data. At some point >> in the project's lifetime, the data is understood well enough that the >> general nature of the SQL database is unnecessary. >> > > I am really struggling to understand this concept. > > Is it the normalised table structure that is in question or the query > language? > > Could you give some sort of example of where SQL would not be the way to go. > ? The only things I can think of a simple flat file databases. Sorry for the late reply. Let's say you have an application that does some inserts and updates and such. Eventually, you are going to run into a limitation with the number of inserts and updates you can do at once. The typical solution to this is to shard your database. However, there are other solutions, such as storing the files in a different kind of database, one which is less general but more efficient for your particular data. Let me give you an example. I worked on a system that would load recipients for email campaigns into a database table. The SQL database was nice during the initial design and prototype stage because we could quickly adjust the tables to add or remove columns and try out different designs.. However, once our system got popular, the limitation was how fast we could load recipients into the database. Rather than make our DB bigger or shard the data, we discovered that storing the recipients outside of the database in flat files was the precise solution we needed. Each file represented a different email campaign. The nature of the data was that we didn't need random access, just serial access. Storing the data this way also meant sharding the data was almost trivial. Now, we can load a massive number of recipients in parallel. You are going to discover certain patterns in how your data is used and those patterns may not be best served by a generic relational database. The relational database will definitely help you discover and even experiment with these patterns, but eventually, you will find its limits. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Fri Mar 12 04:14:26 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 12 Mar 2010 01:14:26 -0800 Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: <6cc20cea1003120114s44ed833fmf82c06edc7d47ca0@mail.gmail.com> On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: > > And even when we've had volunteers, hardly anyone shows up! > > Any suggestions would be appreciated. > Two things: One, only you and your friend really care. Let that sink in. No one is going to carry the group but you two, at least initially. Two, there's a lot of people at movie theaters and the county fair. Why? Because it is interesting and fun. Scientists work the same way. Yes, a lot of people are interested in Python. Why don't you do a bit of snooping around and see what people want to know about? Let me give some examples: * Interactive numeric programming with Python * Rapid website development with Pylons (Trust me, everyone wants to make a website.) Show how you are showing off data from one of your experiments of projects and how easy it is to organize and manage data. * How you used Python on your latest and greatest project Don't expect the audience to participate, except to show up and ask questions. If you want to build a Python support group, then form an informal group with your friends. Start a public mailing list and offer Python advice and support for free. Integrate whatever code your org has with Python, and manage and maintain that code so others can use it. Finally, advertise. The more people see "Python", the more they will be interested. Coca-cola and Pepsi are really good at this! -- Jonathan Gardner jgardner at jonathangardner.net From gandalf at shopzeus.com Fri Mar 12 05:12:39 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 12 Mar 2010 11:12:39 +0100 Subject: sqlite savepoint problem [solved] In-Reply-To: <1268639629.2846.48.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> <1268604831.2846.23.camel@durian> <4B99FCCF.5080506@shopzeus.com> <1268639629.2846.48.camel@durian> Message-ID: <4B9A1397.4010409@shopzeus.com> >> #1. By using isolation_level = None, connection objects (used as a >> context manager) WON'T automatically commit or rollback transactions. >> #2. Using any isolation level, connection objects WON'T automatically >> begin a transaction. >> #3. Possibly, include your connection manager class code, to show how to >> do it "the expected" way. >> >> Also one should clarify in the documentation, what isolation_level does. >> Looks like setting isolation_level to None is not really an "auto commit >> mode". It is not even part of sqlite itself. It is part of the python >> extension. >> > > I think of it as almost the opposite - you have to set > isolation_level=None to get the unadulterated behaviour of the > underlying sqlite library. > > I'm sure the devs would appreciate a documentation patch (submission > details at http://python.org/dev/patches/). I'm also pretty confident > that I won't have time to do one up anytime soon :-) > Patch submitted. http://bugs.python.org/issue8145 From robin at reportlab.com Fri Mar 12 05:16:44 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 10:16:44 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> References: <4B992FB5.8090207@v.loewis.de> <72a0d93e-50f8-415b-aa74-5d7abe6d8523@z11g2000yqz.googlegroups.com> Message-ID: <4B9A148C.7050707@chamonix.reportlab.co.uk> Following the information from MvL I will try and get the 2.6 pyds built for amd64, I see that there's a cross platform compile technique for distutils, but am not sure if it applies to bdist_winexe etc etc. I'll have a go at this next week. -- Robin Becker From greg.ewing at canterbury.ac.nz Fri Mar 12 06:24:31 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Mar 2010 00:24:31 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> Message-ID: <7vum06Fj82U1@mid.individual.net> Lawrence D'Oliveiro wrote: > They could be using a strong cryptographic hash and truncating it to 16 bits > or something. > > In which case you?ve got your work cut out for you... Nope, I've determined that it's actually a pretty standard CRC, and it's even using one of the standard polynomials, 0x8005. I'll explain the details of how I figured that out in my essay. What confused me initially is that it seems to be adding a few extra bytes to the checked data that aren't present in the file. Figuring out what they're supposed to contain is proving to be quite a headache... -- Greg From news1234 at free.fr Fri Mar 12 06:39:50 2010 From: news1234 at free.fr (News123) Date: Fri, 12 Mar 2010 12:39:50 +0100 Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: <4b9a2806$0$22047$426a74cc@news.free.fr> Jonathan Gardner wrote: > On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: >> And even when we've had volunteers, hardly anyone shows up! >> >> Any suggestions would be appreciated. >> > > Two things: One, only you and your friend really care. Let that sink > in. No one is going to carry the group but you two, at least > initially. > > Two, there's a lot of people at movie theaters and the county fair. > Why? Because it is interesting and fun. Scientists work the same way. > Yes, a lot of people are interested in Python. Why don't you do a bit > of snooping around and see what people want to know about? > > Let me give some examples: > > * Interactive numeric programming with Python > * Rapid website development with Pylons (Trust me, everyone wants to > make a website.) Show how you are showing off data from one of your > experiments of projects and how easy it is to organize and manage > data. > * How you used Python on your latest and greatest project > > Don't expect the audience to participate, except to show up and ask questions. > > If you want to build a Python support group, then form an informal > group with your friends. Start a public mailing list and offer Python > advice and support for free. Integrate whatever code your org has with > Python, and manage and maintain that code so others can use it. > > Finally, advertise. The more people see "Python", the more they will > be interested. Coca-cola and Pepsi are really good at this! > attendance will be very low and be sure nobody cares to check whether anything happened on this group. My suggestion is: I'd suggest to setup a group, to which one can subscribe with mail notification and for all the old ones perhaps even via nntp ;-) and of course via a web front end (though I personally hate web groups) Afterwards you can 'friendly-fore-subscribe' some collegues. ;-) Just talk about your new cool group during lunch, etc. Be sure, that most will be to lazy to unsuscribe. Start discussing interesting topics on this group and then . . . maybe others start joining. maybo nobody cares and you have just to accept it. bye N From robin at reportlab.com Fri Mar 12 06:40:00 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 11:40:00 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B992FB5.8090207@v.loewis.de> References: <4B992FB5.8090207@v.loewis.de> Message-ID: <4B9A2810.9030602@chamonix.reportlab.co.uk> On 11/03/2010 18:00, Martin v. Loewis wrote: > >>> I have a Windows 7 (64bit AMD) machine ...... > >> Perhaps some expert on the python list knows which versions of VS >> support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set >> up a 64bit machine to see if they will install on a 64bit architecture. > > For Python 2.6 and later, use VS 2008. This comes with an AMD64 > compiler. You technically don't need a 64-bit Windows, as it supports > cross-compilation (but you would need a 64-bit Windows to test it). > > I personally build Python on a 32-bit machine, and move the MSI to a > 64-bit machine for testing. > OK I've got the VC2008 64bit tools installed on my 32bit build platform, but I'm getting build errors because of missing libraries. I assume that's because I don't have the python amd64 runtime libraries/dlls etc etc since the errors are looking like this _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FindMethod referenced in function Box_getattr _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Init referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Malloc referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyList_Type referenced in function BoxList_init _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FatalError referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Ready referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Type referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyModule_AddObject referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyErr_NewException referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_InitModule4_64 referenced in function init_rl_accel build\lib.win-amd64-2.6\_rl_accel.pyd : fatal error LNK1120: 69 unresolved externals I assume I can get those from a working Python amd64 install and stuff on one of the compiler paths somehow. -- Robin Becker From robin at reportlab.com Fri Mar 12 06:40:00 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 11:40:00 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B992FB5.8090207@v.loewis.de> References: <4B992FB5.8090207@v.loewis.de> Message-ID: <4B9A2810.9030602@chamonix.reportlab.co.uk> On 11/03/2010 18:00, Martin v. Loewis wrote: > >>> I have a Windows 7 (64bit AMD) machine ...... > >> Perhaps some expert on the python list knows which versions of VS >> support 64bit; I do have VS 2005/2008 etc, but I'll probably need to set >> up a 64bit machine to see if they will install on a 64bit architecture. > > For Python 2.6 and later, use VS 2008. This comes with an AMD64 > compiler. You technically don't need a 64-bit Windows, as it supports > cross-compilation (but you would need a 64-bit Windows to test it). > > I personally build Python on a 32-bit machine, and move the MSI to a > 64-bit machine for testing. > OK I've got the VC2008 64bit tools installed on my 32bit build platform, but I'm getting build errors because of missing libraries. I assume that's because I don't have the python amd64 runtime libraries/dlls etc etc since the errors are looking like this _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FindMethod referenced in function Box_getattr _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Init referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyObject_Malloc referenced in function Box _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyList_Type referenced in function BoxList_init _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_FatalError referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Ready referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyType_Type referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyModule_AddObject referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyErr_NewException referenced in function init_rl_accel _rl_accel.obj : error LNK2019: unresolved external symbol __imp_Py_InitModule4_64 referenced in function init_rl_accel build\lib.win-amd64-2.6\_rl_accel.pyd : fatal error LNK1120: 69 unresolved externals I assume I can get those from a working Python amd64 install and stuff on one of the compiler paths somehow. -- Robin Becker From news1234 at free.fr Fri Mar 12 06:44:27 2010 From: news1234 at free.fr (News123) Date: Fri, 12 Mar 2010 12:44:27 +0100 Subject: show image in python In-Reply-To: References: Message-ID: <4b9a291b$0$21425$426a74cc@news.free.fr> Philip Semanchuk wrote: > > On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote: > >> Hey, This is my program >> >> 18 def Creeimg(): >> 19 """transforme matrice en image""" >> 20 img = Image.new ("L",(8,8)) >> 21 matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] >> 22 img.putdata(matrix) >> 23 img.show() >> 24 img.save(fp="./ana.bmp") >> 25 >> >> My probeleme : In line 23 "img.show()" Don't work, normally I show the >> image Image show is implemented rather half heartedly (at least on linux) a potential reasons is: - you didn not install the correct image viewer tool (You should see an error message though". Then you could try to install the tool, that python did not find. depending on the platform, you might have bugs, that don't allow to view more than one image at a time / etc. potentially you might be better of by just using a hand rolled os.system() or subprocess.Popen call bye N >> but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" >> it's >> work >> WHERE IS THE PROBLEME. >> >> I have this error in shell : "(eog:3176): GLib-WARNING **: GError set >> over >> the top of a previous GError or uninitialized memory. >> This indicates a bug in someone's code. You must ensure an error is NULL >> before it's set. >> The overwriting error message was: Error in getting image file info " >> >> >> os: ubuntu 9.10 > > Hi issolah, > I don't know what your problem is but I have a few suggestions -- > 1) You say that img.show() doesn't work. How does it fail? Is that where > you get the GLib warning? > 2) I'm glad you posted your code, but because it has line numbers, it's > awkward to copy & paste into a local example. Please show your code > without line numbers. > > I'm unfamiliar with PIL, so this is just a wild guess, but based on the > GLib error it seems like you haven't initialized something properly. > Sorry I couldn't be more helpful. Maybe someone who knows more will answer. > > Good luck > Philip > > > > > From steve at REMOVE-THIS-cybersource.com.au Fri Mar 12 07:35:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Mar 2010 12:35:57 GMT Subject: Unicode characters in btye-strings Message-ID: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> I know this is wrong, but I'm not sure just how wrong it is, or why. Using Python 2.x: >>> s = "???" >>> print s ??? >>> len(s) 6 >>> list(s) ['\xc3', '\xa9', '\xc3', '\xa2', '\xc3', '\x84'] Can somebody explain what happens when I put non-ASCII characters into a non-unicode string? My guess is that the result will depend on the current encoding of my terminal. In this case, my terminal is set to UTF-8. If I change it to ISO 8859-1, and repeat the above, I get this: >>> list("???") ['\xe9', '\xe2', '\xc4'] If I do this: >>> s = u"???" >>> s.encode('utf-8') '\xc3\xa9\xc3\xa2\xc3\x84' >>> s.encode('iso8859-1') '\xe9\xe2\xc4' which at least explains why the bytes have the values which they do. Thank you, -- Steven From jeanmichel at sequans.com Fri Mar 12 07:51:43 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Mar 2010 13:51:43 +0100 Subject: Need advice on starting a Python group In-Reply-To: <4b9a2806$0$22047$426a74cc@news.free.fr> References: <4b9a2806$0$22047$426a74cc@news.free.fr> Message-ID: <4B9A38DF.1020208@sequans.com> News123 wrote: > Jonathan Gardner wrote: > >> On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: >> >>> And even when we've had volunteers, hardly anyone shows up! >>> >>> Any suggestions would be appreciated. >>> >>> >> Two things: One, only you and your friend really care. Let that sink >> in. No one is going to carry the group but you two, at least >> initially. >> >> Two, there's a lot of people at movie theaters and the county fair. >> Why? Because it is interesting and fun. Scientists work the same way. >> Yes, a lot of people are interested in Python. Why don't you do a bit >> of snooping around and see what people want to know about? >> >> Let me give some examples: >> >> * Interactive numeric programming with Python >> * Rapid website development with Pylons (Trust me, everyone wants to >> make a website.) Show how you are showing off data from one of your >> experiments of projects and how easy it is to organize and manage >> data. >> * How you used Python on your latest and greatest project >> >> Don't expect the audience to participate, except to show up and ask questions. >> >> If you want to build a Python support group, then form an informal >> group with your friends. Start a public mailing list and offer Python >> advice and support for free. Integrate whatever code your org has with >> Python, and manage and maintain that code so others can use it. >> >> Finally, advertise. The more people see "Python", the more they will >> be interested. Coca-cola and Pepsi are really good at this! >> >> > > > attendance will be very low and be sure nobody cares to check whether > anything happened on this group. > > My suggestion is: > > > I'd suggest to setup a group, to which one can subscribe with mail > notification and for all the old ones perhaps even via nntp ;-) and of > course via a web front end (though I personally hate web groups) > > Afterwards you can 'friendly-fore-subscribe' some collegues. ;-) > Just talk about your new cool group during lunch, etc. > > Be sure, that most will be to lazy to unsuscribe. > > Start discussing interesting topics on this group and then . . . > maybe others start joining. maybo nobody cares and you have just to > accept it. > > bye > > > N > Python is not interesting enough by itself to grab students attention. It's just a tool to solve some technical problems. So, either python has a direct benefit on the study itself (meaning it can help getting better results), or you'll have to make it intereseting as a hobbit. But python is not music, video, dance nor it is related to sport, sex or whatever things that usually interest people. So I really don't know how to make it interesting, I'm not sure it's even possible nor desirable. Good luck anyway. JM From hv at tbz-pariv.de Fri Mar 12 07:59:54 2010 From: hv at tbz-pariv.de (Thomas Guettler) Date: Fri, 12 Mar 2010 13:59:54 +0100 Subject: Parsing Email Headers In-Reply-To: <6e0f6857-bedd-4b23-81af-69dd06a53764@q15g2000yqj.googlegroups.com> References: <91153e11-2980-4218-bc88-c92bda7d517e@z11g2000yqz.googlegroups.com> <6e0f6857-bedd-4b23-81af-69dd06a53764@q15g2000yqj.googlegroups.com> Message-ID: <7vus6aFm6qU1@mid.individual.net> T wrote: > Thanks for your suggestions! Here's what seems to be working - it's > basically the same thing I originally had, but first checks to see if > the line is blank > > response, lines, bytes = M.retr(i+1) > # For each line in message > for line in lines: > if not line.strip(): > M.dele(i+1) > break > > emailMessage = email.message_from_string(line) > # Get fields > fields = emailMessage.keys() > # If email contains "From" field > if emailMessage.has_key("From"): > # Get contents of From field > from_field = emailMessage.__getitem__("From") Hi T, wait, this code looks strange. You delete the email if it contains an empty line? I use something like this: message='\n'.join(connection.retr(msg_num)[1]) Your code: emailMessage = email.message_from_string(line) create an email object from only *one* line! You retrieve the whole message (you don't save bandwith), but maybe that's what you want. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de From steve at holdenweb.com Fri Mar 12 08:04:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Mar 2010 08:04:19 -0500 Subject: Need advice on starting a Python group In-Reply-To: <4B9A38DF.1020208@sequans.com> References: <4b9a2806$0$22047$426a74cc@news.free.fr> <4B9A38DF.1020208@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > News123 wrote: >> Jonathan Gardner wrote: >> >>> On Thu, Mar 11, 2010 at 6:57 AM, gb345 wrote: >>> >>>> And even when we've had volunteers, hardly anyone shows up! >>>> >>>> Any suggestions would be appreciated. >>>> >>>> >>> Two things: One, only you and your friend really care. Let that sink >>> in. No one is going to carry the group but you two, at least >>> initially. >>> >>> Two, there's a lot of people at movie theaters and the county fair. >>> Why? Because it is interesting and fun. Scientists work the same way. >>> Yes, a lot of people are interested in Python. Why don't you do a bit >>> of snooping around and see what people want to know about? >>> >>> Let me give some examples: >>> >>> * Interactive numeric programming with Python >>> * Rapid website development with Pylons (Trust me, everyone wants to >>> make a website.) Show how you are showing off data from one of your >>> experiments of projects and how easy it is to organize and manage >>> data. >>> * How you used Python on your latest and greatest project >>> >>> Don't expect the audience to participate, except to show up and ask >>> questions. >>> >>> If you want to build a Python support group, then form an informal >>> group with your friends. Start a public mailing list and offer Python >>> advice and support for free. Integrate whatever code your org has with >>> Python, and manage and maintain that code so others can use it. >>> >>> Finally, advertise. The more people see "Python", the more they will >>> be interested. Coca-cola and Pepsi are really good at this! >>> >>> >> >> >> attendance will be very low and be sure nobody cares to check whether >> anything happened on this group. >> >> My suggestion is: >> >> >> I'd suggest to setup a group, to which one can subscribe with mail >> notification and for all the old ones perhaps even via nntp ;-) and of >> course via a web front end (though I personally hate web groups) >> >> Afterwards you can 'friendly-fore-subscribe' some collegues. ;-) >> Just talk about your new cool group during lunch, etc. >> >> Be sure, that most will be to lazy to unsuscribe. >> >> Start discussing interesting topics on this group and then . . . >> maybe others start joining. maybo nobody cares and you have just to >> accept it. >> >> bye >> >> >> N >> > Python is not interesting enough by itself to grab students attention. > It's just a tool to solve some technical problems. > > So, either python has a direct benefit on the study itself (meaning it > can help getting better results), or you'll have to make it intereseting > as a hobbit. But python is not music, video, dance nor it is related to > sport, sex or whatever things that usually interest people. So I really > don't know how to make it interesting, I'm not sure it's even possible > nor desirable. > > Good luck anyway. > > JM > > All the advice you have had is good. You need to turn around your enthusiasm and look at it from the potential visitor's point of view - what's in it for them? You don't say where you are (and your invalid domain doesn't really help identify that), but if you have any of the superstars from the scientific Python world around you, invite one of them as a guest speaker. Take a look on the web - e.g. in pycon.blip.tv, where all the PyCon talks for the last two years are available. Maybe you could start each meeting by showing one of those videos? Also take a look to see what SciPy conferences have made available (though I don't think they do videos yet). The PSF has invested hugely in making that information available, and the more they get used the happier we will be. But mostly it's a matter of focusing on what your community needs from the group, and providing that. Good luck! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Mar 12 08:07:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Mar 2010 08:07:00 -0500 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: Neo wrote: > I have learned java for half a year and now I want to learn Python, > should I learn python 3k or the traditional version? > That depends on whether you need to use specific libraries that haven't yet been ported to Python 3. If so then start with Python 2. If not, start with 3 - the differences are small enough that you can relatively easily fall back to 2 if you need to get access to non-ported libraries. regards Steve > On Wed, Mar 10, 2010 at 7:19 AM, kj wrote: > > > > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Mar 12 08:15:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Mar 2010 08:15:49 -0500 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: alex goretoy wrote: > hi, > i'm trying to write a section of my program that needs to run bash > builtin alias and declare, i've googled and tried every type of example > i could find no to avail. this is what I've tried below and it doesn't > work, is there a way for me to execute a bah builin from python? what i > need is to take alias output and pipe it to another command with python > and return the results to a string or list. > >>>> p1=Popen(["alias"],stdout=PIPE) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/subprocess.py", line 621, in __init__ > errread, errwrite) > File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > if i add shell=True i get empty string and no thins error message > >>>> p1=Popen(["alias"],stdout=PIPE,shell=True) >>>> p1 > >>>> p1.stdout.read() > '' > > thank you, > -Alex Goretoy > For shell=True I believe you should provide the command as a single string, not a list of arguments. >>> p1 = Popen("alias", stdout=PIPE, shell=True) >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bartc at freeuk.com Fri Mar 12 08:38:07 2010 From: bartc at freeuk.com (bartc) Date: Fri, 12 Mar 2010 13:38:07 GMT Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: <3trmn.49663$Ym4.35065@text.news.virginmedia.com> "gb345" wrote in message news:hnb0d1$2el$1 at reader1.panix.com... > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. Last time just he and I showed up. ... > Still, we have a hard time finding volunteers. > > And even when we've had volunteers, hardly anyone shows up! > > Any suggestions would be appreciated. Try and get a girl or two interested in coming to the meetings... -- Bartc From python at mrabarnett.plus.com Fri Mar 12 08:40:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Mar 2010 13:40:23 +0000 Subject: StringChain -- a data structure for managing large sequences of chunks of bytes In-Reply-To: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4B9A4447.8010500@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 12 Mar 2010 00:11:37 -0700, Zooko O'Whielacronx wrote: > >> Folks: >> >> Every couple of years I run into a problem where some Python code that >> worked well at small scales starts burning up my CPU at larger scales, >> and the underlying issue turns out to be the idiom of accumulating data >> by string concatenation. > > I don't mean to discourage you, but the simple way to avoid that is not > to accumulate data by string concatenation. > > The usual Python idiom is to append substrings to a list, then once, at > the very end, combine into a single string: > > > accumulator = [] > for item in sequence: > accumulator.append(process(item)) > string = ''.join(accumulator) > > >> It just happened again >> (http://foolscap.lothar.com/trac/ticket/149 ), and as usual it is hard >> to make the data accumulator efficient without introducing a bunch of >> bugs into the surrounding code. > > I'm sorry, I don't agree about that at all. I've never come across a > situation where I wanted to use string concatenation and couldn't easily > modify it to use the list idiom above. > > [...] >> Here are some benchmarks generated by running python -OOu -c 'from >> stringchain.bench import bench; bench.quick_bench()' as instructed by >> the README.txt file. > > To be taken seriously, I think you need to compare stringchain to the > list idiom. If your benchmarks favourably compare to that, then it might > be worthwhile. > IIRC, someone did some work on making concatenation faster by delaying it until a certain threshold had been reached (in the string class implementation). From hiralsmaillist at gmail.com Fri Mar 12 08:49:04 2010 From: hiralsmaillist at gmail.com (hiral) Date: Fri, 12 Mar 2010 05:49:04 -0800 (PST) Subject: result of os.times() is different with 'time' command Options Message-ID: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> Hi, Python version: 2.6 Script: def pt(start_time, end_time): def ptime(time, time_str): min, sec = divmod(time, 60) hr, min = divmod(min, 60) stmt = time_str + '\t' if hr: stmt += str(hr) + 'h' stmt += str(min) + 'm' + str(sec) + 's' print stmt if start_time and end_time: real_time = end_time[4] - start_time[4] ptime(real_time, "real") user_time = end_time[0] - start_time[0] ptime(user_time, "user") sys_time = end_time[1] - start_time[1] ptime(sys_time, "sys") import os, subprocess cmd = ['ls'] print cmd t1 = os.times() subprocess.call(cmd) t2 = os.times() pt(t1, t2) print ".end" Output: real 0.0m0.0100000002421s user 0.0m0.0s sys 0.0m0.0s Command: $ time ls Output: real 0m0.007s user 0m0.000s sys 0m0.000s Is this the intended behaviour? As per the link it was fixed in python 2.5. Can anybody help. Thank you. From hiralsmaillist at gmail.com Fri Mar 12 08:56:34 2010 From: hiralsmaillist at gmail.com (hiral) Date: Fri, 12 Mar 2010 05:56:34 -0800 (PST) Subject: python module/utility equivalent to 'time' (linux) and/or 'ntimer'(Windows) Message-ID: <01b0d61b-eb5f-44dc-862e-e31d64b3b0e9@k24g2000pro.googlegroups.com> Hi, Is there any python module/utility available which would report the time same as 'time' command in linux and/or report time same as 'ntimer' utility in Windows. Thank you. From hiralsmaillist at gmail.com Fri Mar 12 08:59:18 2010 From: hiralsmaillist at gmail.com (hiral) Date: Fri, 12 Mar 2010 05:59:18 -0800 (PST) Subject: to create variable from dict Message-ID: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Hi, Is there any way to create variables which name matches with dict key? For example: dict1 = {"abc":'1", "def":"2"} Now I am looking to have variable name abc and it's value be '1' etc. Pl. suggest. Thank you. From felix.antoine.fortin at gmail.com Fri Mar 12 09:08:09 2010 From: felix.antoine.fortin at gmail.com (=?ISO-8859-1?Q?F=E9lix=2DAntoine_Fortin?=) Date: Fri, 12 Mar 2010 06:08:09 -0800 (PST) Subject: inspect.stack() and frame References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> Message-ID: Thanks Gabriel, you resumed quite well what I did discovered after my second post by playing with the garbage collector module. > (The garbage collector will, ? > eventually, break the cycle and free those objects, but not very soon). I'm not very familiar with the Python garbage collector, so you may excuse my simple question, but how can it break the cycle? I guess the object will be freed at least when the program ends, but could it be before that? Is there a mechanisme in the garbage collector to detect circular references? Felix From albert at spenarnc.xs4all.nl Fri Mar 12 09:13:55 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 12 Mar 2010 14:13:55 GMT Subject: Python dos2unix one liner References: <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: In article , Martin P. Hellwig wrote: >On 02/28/10 11:05, Stefan Behnel wrote: >> Steven D'Aprano, 28.02.2010 09:48: >>> There ought to be some kind of competition for the least efficient >>> solution to programming problems >> >> That wouldn't be very interesting. You could just write a code generator >> that spits out tons of garbage code including a line that solves the >> problem, and then let it execute the code afterwards. That beast would >> always win. >> >> Stefan >> >Well that would be an obvious rule that garbage code that does not >contribute to the end result (ie can be taken out without affecting the >end result) would not be allowed. Enforcing the rule is another beast >though, but I would leave that to the competition. Thinking of the international obfuscated c contest (iocc). It is easy to make a mess of a program using the preprocessor. It is also easy to preprocess then prettyprint the program. If the result is not obfuscated, it impresses nobody. Likewise the judges would think nothing of a program with garbage, and would rate it low, so such rule is unnecessary. > >Though the idea of a code generator is solid, but instead of generating >garbage, produces a virtual machine that implements a generator that >produces a virtual machine, etc. etc. That was actually done by Lennart Benschop. He made a Forth program run by an interpreter written in C. Although Forthers thought it was straightforward comprehensible code, it was a winner in the iocc. > >-- >mph Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From emile at fenx.com Fri Mar 12 09:22:23 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Mar 2010 06:22:23 -0800 Subject: Reverse engineering CRC? In-Reply-To: <7vum06Fj82U1@mid.individual.net> References: <7vj7fdFnnjU1@mid.individual.net> <4b9471ee$0$8836$c3e8da3@news.astraweb.com> <7vk3eiFtivU1@mid.individual.net> <7vlameF7goU1@mid.individual.net> <7vum06Fj82U1@mid.individual.net> Message-ID: On 3/12/2010 3:24 AM Gregory Ewing said... > What confused me initially is that it seems to be adding > a few extra bytes to the checked data that aren't present > in the file. Figuring out what they're supposed to contain > is proving to be quite a headache... Length? Emile From darcy at druid.net Fri Mar 12 09:30:51 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 12 Mar 2010 09:30:51 -0500 Subject: NoSQL Movement? In-Reply-To: <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> Message-ID: <20100312093051.75022620.darcy@druid.net> On Fri, 12 Mar 2010 01:05:27 -0800 Jonathan Gardner wrote: > Let me give you an example. I worked on a system that would load > recipients for email campaigns into a database table. The SQL database > was nice during the initial design and prototype stage because we > could quickly adjust the tables to add or remove columns and try out > different designs.. However, once our system got popular, the > limitation was how fast we could load recipients into the database. Just curious, what database were you using that wouldn't keep up with you? I use PostgreSQL and would never consider going back to flat files. The only thing I can think of that might make flat files faster is that flat files are buffered whereas PG guarantees that your information is written to disk before returning but if speed is more important than 100% reliability you can turn that off and let PG use the file system buffering just like flat files. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From python.list at tim.thechases.com Fri Mar 12 09:40:52 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Mar 2010 08:40:52 -0600 Subject: to create variable from dict In-Reply-To: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: <4B9A5274.7080301@tim.thechases.com> hiral wrote: > Is there any way to create variables which name matches with dict key? > > For example: > dict1 = {"abc":'1", "def":"2"} > > Now I am looking to have variable name abc and it's value be '1' etc. 1) you can't because "def" is a reserved word in Python. 2) why do you want to? This seems to come up about every week or so and people STILL want to do it. Search the archives...you won't have to go back too far. 3) once you have it, how do you plan to use the variables? If you don't know what they'll be named ahead of time, how can you use them in your code The usual answer is "don't do that -- just use them as a dict", or if you're trying to set up some constants, you can use abc, def_, ghi = 1, 2, 3 -tkc From luismgz at gmail.com Fri Mar 12 09:50:18 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 12 Mar 2010 06:50:18 -0800 (PST) Subject: to create variable from dict References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: On Mar 12, 10:59?am, hiral wrote: > Hi, > > Is there any way to create variables which name matches with dict key? > > For example: > dict1 = {"abc":'1", "def":"2"} > > Now I am looking to have variable name abc and it's value be '1' etc. > > Pl. suggest. > > Thank you. Check out this thread (very recent): http://groups.google.com/group/comp.lang.python/browse_thread/thread/bb1797ffb6fc3bd7/25fe94103c7a231f?lnk=gst&q=luis+variables#25fe94103c7a231f Short answer: you can update globals() with a dictionary, as follows: globals().update( dict1 ) Then you'll have each key-value pair as variables in the global namespace. The question is: should you do it? Luis From jeanmichel at sequans.com Fri Mar 12 10:02:24 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Mar 2010 16:02:24 +0100 Subject: to create variable from dict In-Reply-To: References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: <4B9A5780.90005@sequans.com> Luis M. Gonz?lez wrote: > On Mar 12, 10:59 am, hiral wrote: > >> Hi, >> >> Is there any way to create variables which name matches with dict key? >> >> For example: >> dict1 = {"abc":'1", "def":"2"} >> >> Now I am looking to have variable name abc and it's value be '1' etc. >> >> Pl. suggest. >> >> Thank you. >> > > Check out this thread (very recent): > http://groups.google.com/group/comp.lang.python/browse_thread/thread/bb1797ffb6fc3bd7/25fe94103c7a231f?lnk=gst&q=luis+variables#25fe94103c7a231f > > Short answer: you can update globals() with a dictionary, as follows: > > globals().update( dict1 ) > > Then you'll have each key-value pair as variables in the global > namespace. > The question is: should you do it? > > Luis > The answer is known: no, he should not do it :o) JM From pemerson at gmail.com Fri Mar 12 10:15:16 2010 From: pemerson at gmail.com (Pete Emerson) Date: Fri, 12 Mar 2010 07:15:16 -0800 (PST) Subject: Exiting gracefully from ThreadingTCPServer Message-ID: <1f31cddf-1104-4579-bd61-5fad3b2c4677@t17g2000prg.googlegroups.com> I'm trying to get threading going for the first time in python, and I'm trying to modify code I found so that I can have the server close the TCP connections and exit gracefully. Two problems: 1) While the KeyboardInterrupt works, if I make more than 0 curls to the server and then quit, I can't run it again right away and get this: socket.error: [Errno 48] Address already in use Not all of my connections are closing properly. How do I fix this? 2) curling localhost:8080/quit does show the "Quitting" output that I expect, but doesn't quit the server until I manually control-c it. I think that I need *all* threads to close and not just the current one, so I'm not quite sure how to proceed. Pointers in the right direction are appreciated. And if there's a "better" way to do this threading httpd server (subjective, I realize), please let me know! Thanks. Pete ############################################# #!/usr/bin/env python import SocketServer import SimpleHTTPServer PORT = 8080 done = False class CustomHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): global done if self.path=='/quit': self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.wfile.write('Quitting') done = True return self else: self.send_response(200) self.send_header('Content-type','text/html') self.end_headers() self.wfile.write('Unknown') return self if __name__ == "__main__": httpd = SocketServer.ThreadingTCPServer(('localhost', PORT),CustomHandler) try: while not done: print "done: ", done httpd.handle_request() except KeyboardInterrupt: print "Server is done." httpd.server_close() From robert.kern at gmail.com Fri Mar 12 10:37:36 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Mar 2010 09:37:36 -0600 Subject: Unicode characters in btye-strings In-Reply-To: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-12 06:35 AM, Steven D'Aprano wrote: > I know this is wrong, but I'm not sure just how wrong it is, or why. > Using Python 2.x: > >>>> s = "???" >>>> print s > ??? >>>> len(s) > 6 >>>> list(s) > ['\xc3', '\xa9', '\xc3', '\xa2', '\xc3', '\x84'] > > Can somebody explain what happens when I put non-ASCII characters into a > non-unicode string? My guess is that the result will depend on the > current encoding of my terminal. Exactly right. -- 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 From robin at reportlab.com Fri Mar 12 10:44:12 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 15:44:12 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A2810.9030602@chamonix.reportlab.co.uk> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> Message-ID: <4B9A614C.1080105@chamonix.reportlab.co.uk> On 12/03/2010 11:40, Robin Becker wrote: ........ > > I assume I can get those from a working Python amd64 install and stuff > on one of the compiler paths somehow. Not sure if this is a bug; I dug around a bit and find that because of the cross compilation distutils is supposed to add an extra library path with the name PCbuild\AMD64 when doing x86-->amd64 cross builds. I tried copying the 2.6.4 amd64 libs/dlls etc etc into c:\python26\PCbuild\AMD64 and reran my cross build c:\python26\python setup.py build --plat-name=win-amd64 however, that still gives linker import errors. Looked in the output I see this > C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\python26 > \libs /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.obj /OUT:build > \lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\temp.win-amd > 64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyNumber_Int referenced in function _parseSequenceInt > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PySequence_GetItem referenced in function _parseSequence that looks wrong because I'm using 32 bit python to do the build and /LIBPATH:C:\python26\libs /LIBPATH:C:\python26\PCbuild\amd64 means that the 32 bit libraries are first. Running the linker command by itself (without the 32bit libs in the command) works fine ie > C:\ux\PydBuilder\rl_addons\rl_accel>"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe" /DLL /nolog > o /INCREMENTAL:NO /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.ob > j /OUT:build\lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\ > temp.win-amd64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp seems to work fine and produce a pyd in build\lib.win-amd64-2.6 -- Robin Becker From robin at reportlab.com Fri Mar 12 10:44:12 2010 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Mar 2010 15:44:12 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A2810.9030602@chamonix.reportlab.co.uk> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> Message-ID: <4B9A614C.1080105@chamonix.reportlab.co.uk> On 12/03/2010 11:40, Robin Becker wrote: ........ > > I assume I can get those from a working Python amd64 install and stuff > on one of the compiler paths somehow. Not sure if this is a bug; I dug around a bit and find that because of the cross compilation distutils is supposed to add an extra library path with the name PCbuild\AMD64 when doing x86-->amd64 cross builds. I tried copying the 2.6.4 amd64 libs/dlls etc etc into c:\python26\PCbuild\AMD64 and reran my cross build c:\python26\python setup.py build --plat-name=win-amd64 however, that still gives linker import errors. Looked in the output I see this > C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\python26 > \libs /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.obj /OUT:build > \lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\temp.win-amd > 64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PyNumber_Int referenced in function _parseSequenceInt > _rl_accel.obj : error LNK2019: unresolved external symbol __imp_PySequence_GetItem referenced in function _parseSequence that looks wrong because I'm using 32 bit python to do the build and /LIBPATH:C:\python26\libs /LIBPATH:C:\python26\PCbuild\amd64 means that the 32 bit libraries are first. Running the linker command by itself (without the 32bit libs in the command) works fine ie > C:\ux\PydBuilder\rl_addons\rl_accel>"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\x86_amd64\link.exe" /DLL /nolog > o /INCREMENTAL:NO /LIBPATH:C:\python26\PCbuild\amd64 /EXPORT:init_rl_accel build\temp.win-amd64-2.6\Release\_rl_accel.ob > j /OUT:build\lib.win-amd64-2.6\_rl_accel.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\_rl_accel.lib /MANIFESTFILE:build\ > temp.win-amd64-2.6\Release\_rl_accel.pyd.manifest > Creating library build\temp.win-amd64-2.6\Release\_rl_accel.lib and object build\temp.win-amd64-2.6\Release\_rl_accel > .exp seems to work fine and produce a pyd in build\lib.win-amd64-2.6 -- Robin Becker From python at mrabarnett.plus.com Fri Mar 12 10:47:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Mar 2010 15:47:10 +0000 Subject: inspect.stack() and frame In-Reply-To: References: <6f3a93d6-5608-467f-a7db-d360a34fe856@i25g2000yqm.googlegroups.com> <4988c974-c8d2-46c9-8c57-681ad22fc1bc@upsg2000gro.googlegroups.com> Message-ID: <4B9A61FE.1080407@mrabarnett.plus.com> F?lix-Antoine Fortin wrote: > Thanks Gabriel, you resumed quite well what I did discovered after my > second post > by playing with the garbage collector module. > >> (The garbage collector will, >> eventually, break the cycle and free those objects, but not very soon). > > I'm not very familiar with the Python garbage collector, so you may > excuse my > simple question, but how can it break the cycle? I guess the object > will be > freed at least when the program ends, but could it be before that? Is > there a > mechanisme in the garbage collector to detect circular references? > In CPython objects are reference-counted, which allows an object to be collected as soon as there are no references to it. However, this won't take care of circular references, so a secondary garbage collector was introduced which occasionally looks for inaccessible objects (garbage) using (probably) mark-and-sweep. From gabriel.rossetti at arimaz.com Fri Mar 12 10:50:21 2010 From: gabriel.rossetti at arimaz.com (Gabriel Rossetti) Date: Fri, 12 Mar 2010 16:50:21 +0100 Subject: Anything like "Effective Java" for Python? In-Reply-To: References: Message-ID: <4B9A62BD.7080805@arimaz.com> kj wrote: > > Subject line pretty much says it all: is there a book like "Effective > Java" for Python. I.e. a book that assumes that readers are > experienced programmers that already know the basics of the language, > and want to focus on more advanced programming issues? > > ~K > Effective Java is a good book, it is not like most people responding to this topic a "how to program in Java" book but a "I know how to program in Python, but I want it to run fast and use a minimal amount of memory". I would have liked to have such a book for Python when I was past the language learning stage. Gabriel From mailinglists at riddergarn.dk Fri Mar 12 10:56:12 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 15:56:12 +0000 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> Message-ID: Sorry but its not really an option for me with PostgreSQL. Thanks anyway. I wonder if there is a simple way of just queueing the run of a function make it only run once at a time but by multiply threads? :) On Fri, 12 Mar 2010 00:54:57 -0800, Jonathan Gardner wrote: > For lots of transactions running at once, MySQL is a terrible choice. > Give PostgreSQL a try. It does a much better job with that kind of > load. > > On Thu, Mar 11, 2010 at 11:11 PM, John P. > wrote: >> Hi, >> >> Im programming a simple webcrawler with threading for the fun of it, >> which >> is inserting the data fetch into a mysql database, but after continuously >> cause my mysql server to produce error during database queries (i assume >> its cause because of the many execution at the same time.) the scipt >> produces errors. >> >> I figured out i need some kind of queue for the function i use to insert >> into the database, to make sure its only called once at a time. >> >> I have looked at the Queue module but its for more complicated than my >> current python skills can cope with. :) >> >> Would somebody please help me out here? >> From godson.g at gmail.com Fri Mar 12 11:13:06 2010 From: godson.g at gmail.com (Godson Gera) Date: Fri, 12 Mar 2010 21:43:06 +0530 Subject: python module/utility equivalent to 'time' (linux) and/or 'ntimer'(Windows) In-Reply-To: <01b0d61b-eb5f-44dc-862e-e31d64b3b0e9@k24g2000pro.googlegroups.com> References: <01b0d61b-eb5f-44dc-862e-e31d64b3b0e9@k24g2000pro.googlegroups.com> Message-ID: Take a look at hotshot module of python http://docs.python.org/library/hotshot.html On Fri, Mar 12, 2010 at 7:26 PM, hiral wrote: > Hi, > > Is there any python module/utility available which would report the > time same as 'time' command in linux and/or report time same as > 'ntimer' utility in Windows. > > Thank you. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Thanks & Regards, Godson Gera http://godson.in http://www.clickindia.com/detail.php?id=493636 -------------- next part -------------- An HTML attachment was scrubbed... URL: From billy.earney at gmail.com Fri Mar 12 11:18:59 2010 From: billy.earney at gmail.com (Billy Earney) Date: Fri, 12 Mar 2010 10:18:59 -0600 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: <4b9a6976.9713f30a.5a73.69a4@mx.google.com> Ludolph, This reminds me of the orange project which is developed in python. http://www.ailab.si/orange/ It is actually for data mining, but many of the concepts could be used for a more general programming structure. Billy -----Original Message----- From: python-list-bounces+billy.earney=gmail.com at python.org [mailto:python-list-bounces+billy.earney=gmail.com at python.org] On Behalf Of Ludolph Sent: Thursday, March 11, 2010 12:39 PM To: python-list at python.org Subject: Visual Python programming and decompilers? Hi Guys At work I have been exposed to a Agile Platform called OutSystems. It allows you to visually program your web applications http://i.imgur.com/r2F0i.png and I find the idea very intriguing. So I have started to play around with the idea on how will I be able to visually represent Python code as in the above image and then allow the programmer to change some of the flow/code/logic visually and then get it back as python source code. I don't know if this have been tried before and after some googling I can't find anything like this, so maybe I'm just lacking basic googling skills or a python solution like the above does not exist yet. If anybody knows of such solution please let me know, so that I don't spend a lot of time recreating the wheel. Otherwise help me out on the following problem: I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to disassemble the code to workable objects, It even allows me to rebuild the objects to bytecode. So if I define patterns on how python interrupts the source code to bytecode I can visually represent this and also so convert my visual representations back to bytecode. The only problem I have at the moment is how will I get this bytecode back to python source code. I have googled for python decompiler but only found old projects like unpyc, decompyle and some online services. I would like to know if anybody know of a well maintained or at least recent module that can help me accomplish the above mentioned, because I'm hoping I can implement this in Python 3.1. So any input or suggestion would be greatly appreciated. Kind Regards, -- Ludolph Neethling -- http://mail.python.org/mailman/listinfo/python-list From darcy at druid.net Fri Mar 12 11:22:04 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 12 Mar 2010 11:22:04 -0500 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> Message-ID: <20100312112204.5513eebb.darcy@druid.net> On Fri, 12 Mar 2010 15:56:12 +0000 "John P." wrote: > Sorry but its not really an option for me with PostgreSQL. Thanks anyway. Why? It's your best option. Any other solutions that you can't use before people give you more suggestions? -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From victorsubervi at gmail.com Fri Mar 12 11:22:19 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Fri, 12 Mar 2010 12:22:19 -0400 Subject: Help Troubleshooting Message-ID: <4dc0cfea1003120822sb08f494nb56c6f9a438204ff@mail.gmail.com> Hi; I'm running Pexpect (no discussion list) with the following code: #! /usr/bin/python import pexpect def runVpopmail(whatdo, acct, domain, newpw, oldpw=''): if whatdo == 'vadduser': child = pexpect.spawn('/home/vpopmail/bin/%s %s@%s %s' % (whatdo, acct, domain, newpw)) elif whatdo == 'vchangepw': child = pexpect.spawn('/home/vpopmail/bin/%s' % (whatdo)) child.expect('Please enter the email address: ') child.sendline('%s@%s' % (acct, domain)) child.expect('Enter old password: ') child.sendline(oldpw) child.expect('Please enter password for %s@%s: ' % (acct, domain)) child.sendline(newpw) child.expect('enter password again: ') child.sendline(newpw) return child No matter whether I try to add a user or edit a password, the fn seems to return that everything is good, but nothing ever happens. When I place a return of the child value and run it with whatdo==vadduser I get the following output: version: 2.3 ($Revision: 399 $) command: /home/vpopmail/bin/vadduser args: ['/home/vpopmail/bin/vadduser', 'test2 at globalsolutionsgroup.vi', 'qqq'] searcher: None buffer (last 100 chars): before (last 100 chars): None after: None match: None match_index: None exitstatus: None flag_eof: False pid: 1518 child_fd: 3 closed: False timeout: 30 delimiter: pexpect.EOF logfile: None logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0. I don't know what this means. Any ideas on how to troubleshoot this? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.wintle at teamrubber.com Fri Mar 12 11:36:32 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 12 Mar 2010 16:36:32 +0000 Subject: Visual Python programming and decompilers? In-Reply-To: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> References: <95cccfc91003111038y6f07efb2m623122a3b8a60127@mail.gmail.com> Message-ID: <1268411792.6354.2.camel@localhost> On Thu, 2010-03-11 at 20:38 +0200, Ludolph wrote: > > I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to > disassemble the code to workable objects, It even allows me to rebuild > the objects to bytecode. So if I define patterns on how python > interrupts the source code to bytecode I can visually represent this > and also so convert my visual representations back to bytecode. Assuming you're on 2.6 or later, I'd suggest working with the ast module instead: http://docs.python.org/library/ast.html From solipsis at pitrou.net Fri Mar 12 11:48:33 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Mar 2010 16:48:33 +0000 (UTC) Subject: Asynchronous HTTP client References: <20100307131604.2792.1008062813.divmod.xquotient.1336@localhost.localdomain> <30c3a3701003070640y19772987s50b583aa54e535d5@mail.gmail.com> Message-ID: Le Sun, 07 Mar 2010 22:40:36 +0800, pingooo a ?crit?: > I'm writing an open source python client for a web service. The client > may be used in all kinds of environments - Linux, Mac OS X, Windows, web > hosting, etc by others. It is not impossible to have twisted as a > dependency, but that makes deployment a larger job than simply uploading > a Python file. If it can be used by non-Python users, you will have to package it using py2exe or py2app anyway, in which case Twisted will be bundled automatically and the size overhead won't be very large. From mailinglists at riddergarn.dk Fri Mar 12 11:49:04 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 16:49:04 +0000 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: <20100312112204.5513eebb.darcy@druid.net> References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> <20100312112204.5513eebb.darcy@druid.net> Message-ID: <1a57cdb3bd2bdf55176e96369d25d1b7@incoming.servage.net> On Fri, 12 Mar 2010 11:22:04 -0500, "D'Arcy J.M. Cain" wrote: > On Fri, 12 Mar 2010 15:56:12 +0000 > "John P." wrote: >> Sorry but its not really an option for me with PostgreSQL. Thanks anyway. > > Why? It's your best option. Any other solutions that you can't use > before people give you more suggestions? Chill. I didn't ask for an alternative to my database, it could be writing in a file as well. What I need is some kind of queue to my function so it doesnt crack up running 20 times at the same time. I'm working on a remote server which I share with some friends, meaning I can't install whatever I want to. The problem seems to be that my threads are making MySQL queries at the same time before it can fetch the data just requested. Also I said thanks for his effort trying to help and kept a nice tone, shouldn't that be enough? /John From solipsis at pitrou.net Fri Mar 12 11:57:37 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Mar 2010 16:57:37 +0000 (UTC) Subject: file seek is slow References: Message-ID: Le Tue, 09 Mar 2010 15:56:47 -0800, Metalone a ?crit?: > for i in xrange(1000000): > f1.seek(0) This is quite a stupid benchmark to write, since repeatedly seeking to 0 is a no-op. I haven't re-read the file object code recently, but chances are that the Python file object has its own bookkeeping which adds a bit of execution time. But I would suggest measuring the performance of *actual* seeks to different file offsets, before handwaving about the supposed "slowness" of file seeks in Python. Regards Antoine. From mailinglists at riddergarn.dk Fri Mar 12 12:25:13 2010 From: mailinglists at riddergarn.dk (John P.) Date: Fri, 12 Mar 2010 17:25:13 +0000 Subject: Threading, Queue for a function so it only runs once at a time. In-Reply-To: <1a57cdb3bd2bdf55176e96369d25d1b7@incoming.servage.net> References: <84d41f095f0958519ea44d749793efeb@incoming.servage.net> <6cc20cea1003120054jec2241atc2b85920a64d869c@mail.gmail.com> <20100312112204.5513eebb.darcy@druid.net> <1a57cdb3bd2bdf55176e96369d25d1b7@incoming.servage.net> Message-ID: <7242f69346c1ddb6803a50449fe36973@incoming.servage.net> On Fri, 12 Mar 2010 16:49:04 +0000, "John P." wrote: > On Fri, 12 Mar 2010 11:22:04 -0500, "D'Arcy J.M. Cain" > wrote: >> On Fri, 12 Mar 2010 15:56:12 +0000 >> "John P." wrote: >>> Sorry but its not really an option for me with PostgreSQL. Thanks > anyway. >> >> Why? It's your best option. Any other solutions that you can't use >> before people give you more suggestions? > > Chill. I didn't ask for an alternative to my database, it could be writing > in a file as well. What I need is some kind of queue to my function so it > doesnt crack up running 20 times at the same time. I'm working on a remote > server which I share with some friends, meaning I can't install whatever I > want to. > The problem seems to be that my threads are making MySQL queries at the > same time before it can fetch the data just requested. Also I said thanks > for his effort trying to help and kept a nice tone, shouldn't that be > enough? > > /John Don't worry guys, I found a solution. My problem was caused because I used the same mysql connection for all the treads, now its working perfectly, with mysql. /John. From cmpython at gmail.com Fri Mar 12 13:31:50 2010 From: cmpython at gmail.com (CM) Date: Fri, 12 Mar 2010 10:31:50 -0800 (PST) Subject: Need advice on starting a Python group References: Message-ID: On Mar 11, 9:57?am, gb345 wrote: > I'm hoping to get advice from anyone with prior experience setting > up a Python group. > > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. ?Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. ?Last time just he and I showed up. > > The second problem is getting content. ?The format we'd envisioned > for this group was centered around code review (though not limited > to it). ?The idea was that at every meeting a different member > would show some code. ?This could be for any of a number of reasons, > such as, for example, 1) illustrate a cool module or technique; 2) > present a scientific research problem and how they used Python to > solve it, or get help solving it; 3) get general feedback (e.g. on > code clarity, software usability, module architecture, etc.). ?But > in principle just about anything is OK: e.g. a talk on favorite > Python resources, or a comparison of Python with some other language, > or an overview of Python gotchas would all be fair game. > > Also, we stressed that the talks were not expected to be polished: > no need for PowerPoint slides, etc. ?Just project any old code onto > the screen, and talk about it, or scribble stuff on the chalkboard. > > Still, we have a hard time finding volunteers. > > And even when we've had volunteers, hardly anyone shows up! Do you advertise each time and describe what the topic will be for that meeting and why the attendees should care? That might make a difference. I.e., there's a big difference between: a) The Thursday afternoon Python for scientific applications is meeting, and I should remember that this week amidst all the other stuff I have going on. and b) Wow, this Thursday there will be an hour workshop on how to create publication quality graphs (somewhat) easily in Python using ready- made tools...and there will be pizza! Also, giving it a cool acronymic name doesn't hurt. :D Che From ugocupcic at gmail.com Fri Mar 12 13:56:00 2010 From: ugocupcic at gmail.com (Ugo Cupcic) Date: Fri, 12 Mar 2010 18:56:00 +0000 Subject: question regarding wxSlider Message-ID: Hi all, I have a question regarding wxSlider. I'm developing a wxwidget python interface for a robotic hand. The sliders send the target values to the joints. I'd like to display the current position of the joint on the slider. I wanted to use wxSlider.SetTick(myposition) but I couldn't get SetTick to display anything. Anyone has an idea ? I attached a dummy code to the message to illustrate. Cheers, Ugo -- Ugo Cupcic http://www.genugo.com/ugocupcic _ ' v ' / \ m m -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: joint_sliders.py Type: text/x-python Size: 3559 bytes Desc: not available URL: From agoretoy at gmail.com Fri Mar 12 13:57:47 2010 From: agoretoy at gmail.com (alex goretoy) Date: Fri, 12 Mar 2010 12:57:47 -0600 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: Steve thank you. The problem is that you can only run commands from Popen or os.system and stuff. You cant run bash shell builtin commands for some reason. I was able to get this to work. What I did is call this: Popen(["bash -c 'source $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read() and make sure you don't have a line like this in your .bashrc: [ -z "$PS1" ] && return Another approach I came up with was to set aliases and functions as a environment variable and access them with os.environ. this is how I'm doing it. export ALIASES=`alias|awk '{print $2}'|cut -d = -f 1|xargs` export FUNCTIONS=`declare -F|awk '{print $3}'|xargs` use this at the end or the .bashrc and then you can access defined aliases and functions inside python with environ -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Fri Mar 12 14:08:19 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Fri, 12 Mar 2010 14:08:19 -0500 Subject: question regarding wxSlider In-Reply-To: References: Message-ID: <8EA74011-1EA0-42CB-BAF5-F9A9F1FF2D16@semanchuk.com> On Mar 12, 2010, at 1:56 PM, Ugo Cupcic wrote: > Hi all, > > I have a question regarding wxSlider. I'm developing a wxwidget python > interface for a robotic hand. The sliders send the target values to > the > joints. > > I'd like to display the current position of the joint on the slider. I > wanted to use wxSlider.SetTick(myposition) but I couldn't get > SetTick to > display anything. > > Anyone has an idea ? I attached a dummy code to the message to > illustrate. Hi Ugo, I don't mean to chase you away, but there is a dedicated wxPython mailing list where you obviously have a much better chance of getting an answer. http://www.wxpython.org/maillist.php Developing a robotic hand sounds like fun! Cheers Philip From kwmsmith at gmail.com Fri Mar 12 14:16:14 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Fri, 12 Mar 2010 13:16:14 -0600 Subject: Need advice on starting a Python group In-Reply-To: References: Message-ID: On Thu, Mar 11, 2010 at 8:57 AM, gb345 wrote: > > > > I'm hoping to get advice from anyone with prior experience setting > up a Python group. > > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. ?Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. ?Last time just he and I showed up. > > The second problem is getting content. ?The format we'd envisioned > for this group was centered around code review (though not limited > to it). ?The idea was that at every meeting a different member > would show some code. ?This could be for any of a number of reasons, > such as, for example, 1) illustrate a cool module or technique; 2) > present a scientific research problem and how they used Python to > solve it, or get help solving it; 3) get general feedback (e.g. on > code clarity, software usability, module architecture, etc.). ?But > in principle just about anything is OK: e.g. a talk on favorite > Python resources, or a comparison of Python with some other language, > or an overview of Python gotchas would all be fair game. > > Also, we stressed that the talks were not expected to be polished: > no need for PowerPoint slides, etc. ?Just project any old code onto > the screen, and talk about it, or scribble stuff on the chalkboard. > > Still, we have a hard time finding volunteers. > > And even when we've had volunteers, hardly anyone shows up! > > Any suggestions would be appreciated. > > GB > > P.S. ?There's a Python Meetup we could go to, but it does not fit > the bill for us: it doesn't meet often enough, it's sort of out of > the way, and has practically no one doing scientific programming. > -- > http://mail.python.org/mailman/listinfo/python-list > There's a general Scientific Computing interest group that gets together here at the University of Wisconsin-Madison, and it has a significant Python component & focus. They put on a Python bootcamp this January that was a huge success. http://hackerwithin.org/cgi-bin/hackerwithin.fcgi/wiki They have bi-weekly meetings, sometimes it's of the 'come and share on X topic,' although many times its 'local guest speaker is coming to speak about Y'. My impression is that the latter meetings grabbed a number of people around campus -- 'hey, I need to do Y, I'll see what the speaker has to say,' and then they started coming for the show-and-tell meetings. My recommendation would be to provide something of value every meeting, the more specific the better. 'Python' in this regard is a bit open ended. You'd likely get more involvement if you had meetings that focused on, e.g., parallel computing (and have examples in python (mpi4py), and have someone come and talk about MPI or something), or scientific data formats (with examples of pyhdf5 or pytables...), or you could advertise a tutorial on some scipy & numpy features and their advantages over using matlab/octave/idl. It's more work than show-and-tell meetings, but look at it as priming the pump. There is much interest around here re: Python in science, but many have only heard about it, some have dabbled but put it on the shelf, others couldn't get it to work (they're scientists and used to prepackaged software that works out of the box -- if it doesn't, it's somebody else's problem), many others can't justify the time it would take to learn it when they already have something else working. Until something with value comes along (like your meeting with specific topics) to change their minds, an open-ended meeting won't appeal much to them. Just some thoughts, and an example of what's worked here. Personally I tend to make it to the meetings with a specific topic, and end up skipping the ones that are more open-ended. Kurt From gdamjan at gmail.com Fri Mar 12 14:20:48 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Fri, 12 Mar 2010 20:20:48 +0100 Subject: Python for newbies (Pythno users group in Macedonia) Message-ID: Hi all, we are starting with bi-monthly Python User Group meetings in Skopje, Macedonia. The meetings are targeted for both beginners and more experienced users. The basic idea is to have an 1 hour presentation at the start for the beginners and an 1 hour ad-hoc discussion about projects, applications, interesting stuff etc. I'd like to gather some guidance/experince/thoughts about some beginner oriented python lectures we could use? My first idea was to do something like the "Python module of the Week", but maybe there's a better approach? thanks -- damjan From no.email at nospam.invalid Fri Mar 12 14:23:10 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 12 Mar 2010 11:23:10 -0800 Subject: NoSQL Movement? References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> Message-ID: <7xljdx73a9.fsf@ruckus.brouhaha.com> "D'Arcy J.M. Cain" writes: > Just curious, what database were you using that wouldn't keep up with > you? I use PostgreSQL and would never consider going back to flat > files. Try making a file with a billion or so names and addresses, then compare the speed of inserting that many rows into a postgres table against the speed of copying the file. > The only thing I can think of that might make flat files faster is > that flat files are buffered whereas PG guarantees that your > information is written to disk before returning Don't forget all the shadow page operations and the index operations, and that a lot of these operations require reading as well as writing remote parts of the disk, so buffering doesn't help avoid every disk seek. Generally when faced with this sort of problem I find it worthwhile to ask myself whether the mainframe programmers of the 1960's-70's had to deal with the same thing, e.g. when sending out millions of phone bills, or processing credit card transactions (TPF), then ask myself how they did it. Their computers had very little memory or disk space by today's standards, so their main bulk storage medium was mag tape. A heck of a lot of these data processing problems can be recast in terms of sorting large files on tape, rather than updating database one record at a time on disk or in memory. And that is still what (e.g.) large search clusters spend a lot of their time doing (look up the term "pennysort" for more info). From martin at v.loewis.de Fri Mar 12 14:29:40 2010 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 12 Mar 2010 20:29:40 +0100 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A614C.1080105@chamonix.reportlab.co.uk> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> Message-ID: <4B9A9624.7040200@v.loewis.de> > Not sure if this is a bug I think it is. It seems that the cross-build support in msvc9compiler has been tested only in a build tree of Python (where there is no Libs directory). For released copies of Python, I could change that to distribute the AMD64 pythonXY.lib in libs/amd64. [FWIW, I'm still puzzled why I ship the import libraries of all the pyd files as well - I can't see a reason other than tradition]. Then, distutils should change to look it up there. Regards, Martin From jcb at iteris.com Fri Mar 12 14:53:28 2010 From: jcb at iteris.com (Metalone) Date: Fri, 12 Mar 2010 11:53:28 -0800 (PST) Subject: file seek is slow References: Message-ID: I almost wrote a long reply to all this. In the end it boils down to being concerned about how much overhead there is to calling a 'C' function. I assumed that file.seek() simply delegated to fseek() and thus was one way to test this overhead. However, I now think that it must be doing more and may not be a reasonable comparison. I have used the profiler about as much as I can to find where my program is slow, and it appears to me that the overhead to calling 'C' functions is now my biggest problem. I have been using Ctypes, which has been a great tool so far. I just discovered Cython and this looks like it may help me. I had not heard of pythoid, so I will check it out. I did not mean to offend anybody in Cython community. It just seemed funny to me that 21 lines of Python became 1478 lines of 'C'. I wasn't really expecting any response to this. I don't know enough about this to really assume anything. Stephan, I just tested 1e7 loops. 'C': 8.133 seconds Cython: 10.812 seconds I can't figure out what Cython is using for CFLAGS, so this could be important. I used While instead of xrange, because I thought it would be faster in Cython. They had roughly the same execution speed. Thanks all for the suggestions. I think I will just consider this thread closed. From john at castleamber.com Fri Mar 12 15:36:35 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 14:36:35 -0600 Subject: Anything like "Effective Java" for Python? References: Message-ID: <87k4thp99o.fsf@castleamber.com> Gabriel Rossetti writes: > kj wrote: >> >> Subject line pretty much says it all: is there a book like "Effective >> Java" for Python. I.e. a book that assumes that readers are >> experienced programmers that already know the basics of the language, >> and want to focus on more advanced programming issues? > > Effective Java is a good book, it is not like most people responding > to this topic a "how to program in Java" I had more the feeling that these responses were more of the "Look, you actually need a book to learn how to program effectively in Java *snigger*" fanboism. > book but a "I know how to program in Python, but I want it to run fast > and use a minimal amount of memory". > I would have liked to have such a book for Python when I was past the > language learning stage. High Performance Python by Anthony Lewis (Author), et al. (*snigger*!) might be such a book but we have to wait a few more months: Publisher: O'Reilly Media; 1 edition (September 15, 2010) (It has been on my wish list for several months) To the OP: right now, Dive into Python is clearly written with people who have experience with programming in mind. I've both the Python 2 and Python 3 version (books). You can download a version of each for free: http://www.google.com/search?q=dive%20into%20python -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From martin at v.loewis.de Fri Mar 12 15:56:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Fri, 12 Mar 2010 21:56:42 +0100 Subject: Unicode characters in btye-strings In-Reply-To: References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: >> Can somebody explain what happens when I put non-ASCII characters into a >> non-unicode string? My guess is that the result will depend on the >> current encoding of my terminal. > > Exactly right. To elaborate on the "what happens" part: the string that gets entered is typically passed as a byte sequence, from the terminal (application) to the OS kernel, from the OS kernel to Python's stdin, and from there to the parser. Python recognizes the string delimiters, but (practically) leaves the bytes between the delimiters as-is (*), creating a byte string object with the very same bytes. The more interesting question is what happens when you do py> s = u"???" Here, Python needs to decode the bytes, according to some encoding. Usually, it would want to use the source encoding (as given through -*- Emacs -*- markers), but there are none. Various Python versions then try different things; what they should do is to determine the terminal encoding, and decode the bytes according to that one. Regards, Martin (*) If a source encoding was given, the source is actually recoded to UTF-8, parsed, and then re-encoded back into the original encoding. From spamfresser at ch3ka.de Fri Mar 12 17:55:49 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Fri, 12 Mar 2010 23:55:49 +0100 Subject: Unicode characters in btye-strings In-Reply-To: References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: Am 12.03.2010 21:56, schrieb Martin v. Loewis: > (*) If a source encoding was given, the source is actually recoded to > UTF-8, parsed, and then re-encoded back into the original encoding. Why is that? So "unicode"-strings (as in u"string") are not really unicode-, but utf8-strings? Need citation plz. Thx, Michael From torriem at gmail.com Fri Mar 12 18:15:55 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 12 Mar 2010 16:15:55 -0700 Subject: converting datetime with tzinfo to unix timestamp Message-ID: <4B9ACB2B.3090203@gmail.com> On Python 2.5 here. I've searched and searched but I can't find any way to convert a datetime object that includes a timezone (tzinfo) to a unix timestamp. Folks on the net say to simply use the timetuple() method of the object and feed that to time.mktime(). But that just doesn't seem to work for me. At least if my understanding that the unix timestamp is always UTC. I'm using the pytz module to create a datetime object of a certain timezone. For example: import pytz import datetime import time mountain = pytz.timezone("US/Mountain") # MST or MDT depending on date eastern = pytz.timezone("US/Eastern") # EST or EDT depending on date date1 = mountain.localize(datetime.datetime(2010, 3, 12, 9, 0)) date2 = eastern.localize(datetime.datetime(2010, 3, 12, 9, 0)) Now if I examine the two objects, I get: >>> print date1 2010-03-12 09:00:00-07:00 >>> print date2 2010-03-12 09:00:00-05:00 However the standard time.mktime(date2.timetuple()) thing gives me a timestamp, but it's in my local timezone and gives me the same answer for both dates! Can anyone point me in the right direction? thanks. From mmanns at gmx.net Fri Mar 12 18:24:49 2010 From: mmanns at gmx.net (Martin Manns) Date: Sat, 13 Mar 2010 00:24:49 +0100 Subject: [ANN] Pyspread 0.0.14b released Message-ID: Pyspread 0.0.14b released ========================= I am pleased to announce the new release 0.0.14b of pyspread. About: ------ Pyspread is a cross-platform Python spreadsheet application. It is based on and written in the programming language Python. Instead of spreadsheet formulas, Python expressions are entered into the spreadsheet cells. Each expression returns a Python object that can be accessed from other cells. These objects can represent anything including lists or matrices. Pyspread runs on Linux and *nix platforms with GTK support as well as on Windows (XP and Vista tested). On Mac OS X, some icons are too small but the application basically works. Homepage -------- http://pyspread.sourceforge.net New features ------------ * Cell border can be changed independently. * Cell access allows negative indices when not slicing. Enjoy Martin From john at castleamber.com Fri Mar 12 18:37:54 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 17:37:54 -0600 Subject: Unicode characters in btye-strings References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: <87r5npnmb1.fsf@castleamber.com> Michael Rudolf writes: > Am 12.03.2010 21:56, schrieb Martin v. Loewis: >> (*) If a source encoding was given, the source is actually recoded to >> UTF-8, parsed, and then re-encoded back into the original encoding. > > Why is that? So "unicode"-strings (as in u"string") are not really > unicode-, but utf8-strings? utf8 is a Unicode *encoding*. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From martin at v.loewis.de Fri Mar 12 18:51:42 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 13 Mar 2010 00:51:42 +0100 Subject: Unicode characters in btye-strings In-Reply-To: References: <4b9a352d$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4B9AD38E.5030402@v.loewis.de> Michael Rudolf wrote: > Am 12.03.2010 21:56, schrieb Martin v. Loewis: >> (*) If a source encoding was given, the source is actually recoded to >> UTF-8, parsed, and then re-encoded back into the original encoding. > > Why is that? Why is what? That string literals get reencoded into the source encoding? > So "unicode"-strings (as in u"string") are not really > unicode-, but utf8-strings? No. String literals, in 2.x, are not written with u"", and are stored in the source encoding. Above procedure applies to regular strings (see where the "*" goes in my original article). > Need citation plz. You really want a link to the source code implementing that? Regards, Martin From morecrown at gmail.com Fri Mar 12 19:29:33 2010 From: morecrown at gmail.com (Hephzibah) Date: Fri, 12 Mar 2010 16:29:33 -0800 (PST) Subject: POS Tagging Message-ID: <1610f59e-b49f-4c5b-ade7-915c92c32b79@q21g2000yqm.googlegroups.com> I just started working on POS tagging with these codes: import nltk text = nltk.word_tokenize("And now for something completely different") #print text print nltk.pos_tag(text) Python prompted me to download a resource with these codes: Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not found. Please use the NLTK Downloader to obtain the resource: I download the resources available using nltk.download(). But I couldn't run POS tagger. Python gave my the following message: Traceback (most recent call last): File "C:/Python25/tag practices.py", line 5, in print nltk.pos_tag(text) File "C:\Python25\lib\site-packages\nltk\tag\__init__.py", line 62, in pos_tag tagger = nltk.data.load(_POS_TAGGER) File "C:\Python25\lib\site-packages\nltk\data.py", line 492, in load resource_val = pickle.load(_open(resource_url)) File "C:\Python25\lib\site-packages\nltk\classify\maxent.py", line 57, in import numpy ImportError: No module named numpy Can someone pls. tell me what I'm supposed to do next? Thanks, Hephzibah From john at castleamber.com Fri Mar 12 19:33:55 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 18:33:55 -0600 Subject: POS Tagging References: <1610f59e-b49f-4c5b-ade7-915c92c32b79@q21g2000yqm.googlegroups.com> Message-ID: <87aaudnjpo.fsf@castleamber.com> Hephzibah writes: > ImportError: No module named numpy > > Can someone pls. tell me what I'm supposed to do next? Install numpy would be my first guess. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alex.kapps at web.de Fri Mar 12 19:44:49 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 13 Mar 2010 01:44:49 +0100 Subject: Python eCommerce, small webshop Message-ID: <4B9AE001.3050406@web.de> Hello everybody! I have to set up a small webshop for used books, CDs, DVD, and stuff and did't find anything realy usefull on google. I'm pretty skilled with Python and would strongly prefer a Python based Shop but all I've found are in early stage, unmaintained or too limited. I've looked around and found many PHP based shops (currently I'm playing with OpenCart but their code is so messy, I don't think this is going to work) and some Ruby based ones (I don't know Ruby at all) I there really no decent, up-to-date, activily maintained and post beta stage Python webshop? What I need is: - full german support (ie. translation, shipping models, payment models, etc) - secure (code, SQL, full SSL, etc) - themable without getting into all gory details of modern HTML/CSS (a bit is OK) - customizable by people with good Python and basic SQL knowledge - finally (after being setup) usable by people without any programming skills at all. Thanks for any tips. Regards Alex From alex.kapps at web.de Fri Mar 12 20:02:36 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 13 Mar 2010 02:02:36 +0100 Subject: Python eCommerce, small webshop Message-ID: <4B9AE42C.1060905@web.de> Hello everybody! I have to set up a small webshop for used books, CDs, DVD, and stuff and did't find anything realy usefull on google. I'm pretty skilled with Python and would strongly prefer a Python based Shop but all I've found are in early stage, unmaintained or too limited. I've looked around and found many PHP based shops (currently I'm playing with OpenCart but their code is so messy, I don't think this is going to work) and some Ruby based ones (I don't know Ruby at all) I there really no decent, up-to-date, activily maintained and post beta stage Python webshop? What I need is: - full german support (ie. translation, shipping models, payment models, etc) - secure (code, SQL, full SSL, etc) - themable without getting into all gory details of modern HTML/CSS (a bit is OK) - customizable by people with good Python and basic SQL knowledge - finally (after being setup) usable by people without any programming skills at all. Thanks for any tips. Regards Alex From emile at fenx.com Fri Mar 12 20:11:04 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 12 Mar 2010 17:11:04 -0800 Subject: Python eCommerce, small webshop In-Reply-To: <4B9AE42C.1060905@web.de> References: <4B9AE42C.1060905@web.de> Message-ID: On 3/12/2010 5:02 PM Alexander Kapps said... > Hello everybody! > > I have to set up a small webshop for used books, CDs, DVD, and stuff and > did't find anything realy usefull on google. Have you checked the current status of Satchmo? Emile > > I'm pretty skilled with Python and would strongly prefer a Python based > Shop but all I've found are in early stage, unmaintained or too limited. > > I've looked around and found many PHP based shops (currently I'm playing > with OpenCart but their code is so messy, I don't think this is going to > work) and some Ruby based ones (I don't know Ruby at all) > > I there really no decent, up-to-date, activily maintained and post beta > stage Python webshop? > > What I need is: > > - full german support (ie. translation, shipping models, payment models, > etc) > - secure (code, SQL, full SSL, etc) > - themable without getting into all gory details of modern HTML/CSS (a > bit is OK) > - customizable by people with good Python and basic SQL knowledge > - finally (after being setup) usable by people without any programming > skills at all. > > > > Thanks for any tips. > > Regards > Alex From alex.kapps at web.de Fri Mar 12 20:38:55 2010 From: alex.kapps at web.de (Alexander Kapps) Date: Sat, 13 Mar 2010 02:38:55 +0100 Subject: Python eCommerce, small webshop In-Reply-To: <4B9AEB04.3010403@web.de> References: <4B9AE42C.1060905@web.de> <4B9AEB04.3010403@web.de> Message-ID: <4B9AECAF.10709@web.de> Sorry, Emile for the private post, one beer too much and the wrong button... ;-) Emile van Sebille wrote: > On 3/12/2010 5:02 PM Alexander Kapps said... >> Hello everybody! >> >> I have to set up a small webshop for used books, CDs, DVD, and stuff and >> did't find anything realy usefull on google. > > Have you checked the current status of Satchmo? Sort of. I checked their site and feature list which looks promising. Then I searched for a forum. I have quite some objections against projects who only have a google group with a reaction time measured in days. But since you mentioned it, I'll have a closer look. Thank you. From steve at REMOVE-THIS-cybersource.com.au Fri Mar 12 22:06:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 03:06:52 GMT Subject: StringChain -- a data structure for managing large sequences of chunks of bytes References: <4b9a00ce$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4b9b014c$0$27822$c3e8da3@news.astraweb.com> On Fri, 12 Mar 2010 13:40:23 +0000, MRAB wrote: >> To be taken seriously, I think you need to compare stringchain to the >> list idiom. If your benchmarks favourably compare to that, then it >> might be worthwhile. >> > IIRC, someone did some work on making concatenation faster by delaying > it until a certain threshold had been reached (in the string class > implementation). I believe you're talking about this patch: http://bugs.python.org/issue1569040 It's never been formally rejected, but the chances of it being accepted are pretty low. However, in Python 2.4 another optimization was added that makes string concatenation of the form: a = a + b a += b much faster. This is implementation specific (Jython and IronPython don't have it, and almost certainly won't) and it doesn't work for (e.g.): a = b + a See here: http://mail.python.org/pipermail/python-dev/2004-August/046686.html http://bugs.python.org/issue980695 -- Steven From robin1 at cnsp.com Fri Mar 12 22:26:20 2010 From: robin1 at cnsp.com (Robin) Date: Fri, 12 Mar 2010 19:26:20 -0800 (PST) Subject: python to exe Message-ID: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Does anyone know of a good python to stand alone exe compiler? Thanks, -Robin From gagsl-py2 at yahoo.com.ar Fri Mar 12 23:11:47 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Mar 2010 20:11:47 -0800 (PST) Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Message-ID: On 13 mar, 00:26, Robin wrote: > Does anyone know of a good python to stand alone exe compiler? http://tinyurl.com/yfcfzz4 From clp2 at rebertia.com Fri Mar 12 23:12:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Mar 2010 20:12:19 -0800 Subject: python to exe In-Reply-To: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Message-ID: <50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com> On Fri, Mar 12, 2010 at 7:26 PM, Robin wrote: > Does anyone know of a good python to stand alone exe compiler? py2exe: http://www.py2exe.org/ Cheers, Chris -- http://blog.rebertia.com From dr.cg at 126.com Fri Mar 12 23:13:42 2010 From: dr.cg at 126.com (CHEN Guang) Date: Sat, 13 Mar 2010 12:13:42 +0800 (CST) Subject: file seek is slow Message-ID: <3c99dc54.26bd.12755ba44ca.Coremail.dr.cg@126.com> >> Metalone wrote: >>> I just tried the seek test with Cython. >>> Cython fseek() : 1.059 seconds. 30% slower than 'C' >>> Python f.seek : 1.458 secondds. 80% slower than 'C'. >>> >>> It is amazing to me that Cython generates a 'C' file that is 1478 >>> lines. >> >> PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. >> PythoidC is the C language like the Python, by the Python and for the Python. >Except that it's not a language but rather a syntax converter, i.e. it >doesn't really add any features to the C language but rather restricts >Python syntax to C language features (plus a bit of header file >introspection, it seems, but C's preprocessor has a bit of that, too). >Stefan PythoidC is a familar language to Python and C programmers, I do not like waste my time to create unfamilar things to waste users' time studying. In fact PythoidC removed some boring features from C language: 1. no semicolon ; at line ends 2. no braces {} , take Pythonic indent region to express code block PythoidC restricts C syntax to Python language feature, so that C language bacomes friendly to Python programmers and Python IDE. PythoidC realized introspection not only on header files but also any C files. The PythoidC introspection will be as good as Python introspection, if only the C header file wirters adds more detailed annotation. PythoidC is a familar and convenient C language tool for Python programmers and mixed programming. plus, PythoidC is realizable only with Python, it's too far beyond C's preprocessor, believe it, or show us. CHEN Guang Convenient C Python mixed programming --- PythoidC ( http://pythoidc.googlecode.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Fri Mar 12 23:26:34 2010 From: john at castleamber.com (John Bokma) Date: Fri, 12 Mar 2010 22:26:34 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> Message-ID: <87bpes6e4l.fsf@castleamber.com> Gabriel Genellina writes: > On 13 mar, 00:26, Robin wrote: > >> Does anyone know of a good python to stand alone exe compiler? > > http://tinyurl.com/yfcfzz4 Wow, pathetic fuck. You don't have to post you know. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From morecrown at gmail.com Fri Mar 12 23:36:46 2010 From: morecrown at gmail.com (Hephzibah) Date: Fri, 12 Mar 2010 20:36:46 -0800 (PST) Subject: POS Tagging References: <1610f59e-b49f-4c5b-ade7-915c92c32b79@q21g2000yqm.googlegroups.com> <87aaudnjpo.fsf@castleamber.com> Message-ID: <14b223b6-10c2-4ee3-9d18-18677a6769c9@d27g2000yqf.googlegroups.com> On Mar 12, 4:33?pm, John Bokma wrote: > Hephzibah writes: > > ImportError: No module named numpy > > > Can someone pls. tell me what I'm supposed to do next? > > Install numpy would be my first guess. > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development Thanks so much I've been able to resolve the issue. What I did was to run the program after downloading and installing i. a newer version of Python -version 26 ii. pyPAML iii.numpy iv.matplotlib; all from www.nltk.org. regards, Hephzibah From clp2 at rebertia.com Fri Mar 12 23:47:31 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Mar 2010 20:47:31 -0800 Subject: python to exe In-Reply-To: <4B9B17B3.8000307@cnsp.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com> <4B9B17B3.8000307@cnsp.com> Message-ID: <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> On Fri, Mar 12, 2010 at 8:42 PM, robin wrote: > On 3/12/2010 9:12 PM, Chris Rebert wrote: >> On Fri, Mar 12, 2010 at 7:26 PM, Robin ?wrote: >>> Does anyone know of a good python to stand alone exe compiler? >>> >> py2exe: >> http://www.py2exe.org/ > > do you ?of an alternate compilter it doesn't work (py2exe) on my windows 7 > box, I hate windows7 THanks Robin Nope; py2exe is pretty much the go-to tool for this. Try asking on their mailinglist: https://lists.sourceforge.net/lists/listinfo/py2exe-users Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 01:47:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 06:47:47 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> Message-ID: <4b9b3513$0$27822$c3e8da3@news.astraweb.com> On Fri, 12 Mar 2010 22:26:34 -0600, John Bokma wrote: > Gabriel Genellina writes: > >> On 13 mar, 00:26, Robin wrote: >> >>> Does anyone know of a good python to stand alone exe compiler? >> >> http://tinyurl.com/yfcfzz4 > > Wow, pathetic fuck. You don't have to post you know. Gabriel is one of the more helpful and newbie-friendly of the frequent posters on this newsgroup. Even if his actions were worthy of your abuse (and they aren't), he gets at least one Get Out Of Jail Free card for his long-term helpfulness. Speaking as somebody who finds Let Me Google That For You to be tiresome and not at all amusing, nevertheless I support Gabriel's actions. By merely giving Robin the answer, Robin doesn't learn how to find out the answer to simple questions himself, and by rewarding his laziness, we make a rod for our own back. As the old proverb goes: give a man a fish, and you feed him for a day. Teach him how to fish, and he has food forever. I'm an old-fashioned kind of guy, and don't like LMGTFY because it is tiresome and requires Javascript. I prefer: Google is your friend: http://www.google.com/search?q=python+standalone+exe Oh, and Robin, since you have apparently already tried py2exe and found it doesn't work on Windows 7, you should have said so from the start, instead of wasting everyone's time. -- Steven From ugocupcic at gmail.com Sat Mar 13 03:04:31 2010 From: ugocupcic at gmail.com (Ugo Cupcic) Date: Sat, 13 Mar 2010 08:04:31 +0000 Subject: question regarding wxSlider In-Reply-To: <8EA74011-1EA0-42CB-BAF5-F9A9F1FF2D16@semanchuk.com> References: <8EA74011-1EA0-42CB-BAF5-F9A9F1FF2D16@semanchuk.com> Message-ID: Hi Philip, Thanks for your redirection. I'll try with them :) Cheers, Ugo PS : yes developing a robotic hand is really fun :D On Fri, Mar 12, 2010 at 7:08 PM, Philip Semanchuk wrote: > On Mar 12, 2010, at 1:56 PM, Ugo Cupcic wrote: > > Hi all, >> >> I have a question regarding wxSlider. I'm developing a wxwidget python >> interface for a robotic hand. The sliders send the target values to the >> joints. >> >> I'd like to display the current position of the joint on the slider. I >> wanted to use wxSlider.SetTick(myposition) but I couldn't get SetTick to >> display anything. >> >> Anyone has an idea ? I attached a dummy code to the message to illustrate. >> > > > Hi Ugo, > I don't mean to chase you away, but there is a dedicated wxPython mailing > list where you obviously have a much better chance of getting an answer. > > http://www.wxpython.org/maillist.php > > Developing a robotic hand sounds like fun! > > Cheers > Philip > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Ugo Cupcic http://www.genugo.com/ugocupcic _ ' v ' / \ m m -------------- next part -------------- An HTML attachment was scrubbed... URL: From agoretoy at gmail.com Sat Mar 13 03:42:36 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 13 Mar 2010 02:42:36 -0600 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: I found this to be even better; maybe someone will find this useful, who knows. just export PS1, duh Popen(["bash -c 'export PS1='python'; source $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read() -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From g.bogle at auckland.no.spam.ac.nz Sat Mar 13 04:38:29 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 13 Mar 2010 22:38:29 +1300 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > As the old proverb goes: give a man a fish, and you feed him for a day. > Teach him how to fish, and he has food forever. I like this version: Light a man a fire, and you keep him warm for hours. Set a man on fire, and you keep him warm for the rest of his life. ;-) From dr.cg at 126.com Sat Mar 13 05:02:31 2010 From: dr.cg at 126.com (CHEN Guang) Date: Sat, 13 Mar 2010 18:02:31 +0800 (CST) Subject: python to exe Message-ID: <1e3b567.3797.12756f99dda.Coremail.dr.cg@126.com> >Does anyone know of a good python to stand alone exe compiler? >Thanks, >-Robin I tried several such tools and found the easiest one: Pyinstaller ( http://www.pyinstaller.org/ ) but it does not make your script faster, if you want it as fast as C language, please try PythoidC ( http://pythoidc.googlecode.com ) -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Sat Mar 13 05:35:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Mar 2010 11:35:41 +0100 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: * Gib Bogle: > Steven D'Aprano wrote: > >> As the old proverb goes: give a man a fish, and you feed him for a >> day. Teach him how to fish, and he has food forever. > > I like this version: > > Light a man a fire, and you keep him warm for hours. Set a man on fire, > and you keep him warm for the rest of his life. > > ;-) Hey! I was going to post that! And there it was, in the next article... :-) Cheers, - Alf From breamoreboy at yahoo.co.uk Sat Mar 13 05:58:15 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Mar 2010 10:58:15 +0000 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Steven D'Aprano wrote: > >> As the old proverb goes: give a man a fish, and you feed him for a >> day. Teach him how to fish, and he has food forever. > > I like this version: > > Light a man a fire, and you keep him warm for hours. Set a man on fire, > and you keep him warm for the rest of his life. > > ;-) I'm certain that members of the Guinea Pig Club might have something to say on that one, see :- http://en.wikipedia.org/wiki/Guinea_Pig_Club From usenot at geekmail.INVALID Sat Mar 13 06:41:38 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 13 Mar 2010 12:41:38 +0100 Subject: to create variable from dict References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: <20100313124138.6d981759@geekmail.INVALID> On Fri, 12 Mar 2010 06:50:18 -0800 (PST) Luis M. Gonz?lez wrote: > The question is: should you do it? And the answer is: No. And the usual disclaimer is: (Unless you *know* it's the best possible solution to your problem.) /W -- INVALID? DE! From steve at holdenweb.com Sat Mar 13 08:08:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:08:24 -0500 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: alex goretoy wrote: > I found this to be even better; maybe someone will find this useful, who > knows. > just export PS1, duh > Popen(["bash -c 'export PS1='python'; source > $HOME/.bashrc;alias'"],shell=True,stdout=PIPE).stdout.read() > Try using an interactive shell: >>> from subprocess import * >>> p1 = Popen("bash -i -c alias", stdout=PIPE, shell=True) >>> p1.stdout.read() "alias ls='ls --color=auto'\n" >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sat Mar 13 08:09:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:09:34 -0500 Subject: python to exe In-Reply-To: <87bpes6e4l.fsf@castleamber.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> Message-ID: John Bokma wrote: > Gabriel Genellina writes: > >> On 13 mar, 00:26, Robin wrote: >> >>> Does anyone know of a good python to stand alone exe compiler? >> http://tinyurl.com/... > > Wow, pathetic fuck. You don't have to post you know. > And you don't have to give Google a second chance at indexing the URL, but we all make mistakes. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sat Mar 13 08:11:07 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:11:07 -0500 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Steven D'Aprano wrote: > >> As the old proverb goes: give a man a fish, and you feed him for a >> day. Teach him how to fish, and he has food forever. > > I like this version: > > Light a man a fire, and you keep him warm for hours. Set a man on fire, > and you keep him warm for the rest of his life. > > ;-) I like "Give a man a fish, and he eats for a day. Teach a man to fish and he will bore you with stories of the one that got away for the rest of his life". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sat Mar 13 08:15:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:15:49 -0500 Subject: Python for newbies (Pythno users group in Macedonia) In-Reply-To: References: Message-ID: ?????? ??????????? wrote: > Hi all, > we are starting with bi-monthly Python User Group meetings in Skopje, > Macedonia. The meetings are targeted for both beginners and more > experienced users. > > The basic idea is to have an 1 hour presentation at the start for the > beginners and an 1 hour ad-hoc discussion about projects, applications, > interesting stuff etc. > > I'd like to gather some guidance/experince/thoughts about some beginner > oriented python lectures we could use? > > My first idea was to do something like the "Python module of the Week", > but maybe there's a better approach? > > thanks > If you are all English-speakers then perhaps you could consider showing a PyCon video - see http://pycon.blip.tv Good luck with the group. I hope to see PyCon Macedonia emerging before too long! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From vicente.soler at gmail.com Sat Mar 13 08:16:52 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Mar 2010 05:16:52 -0800 (PST) Subject: print formatting Message-ID: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> Hello, My script contains a print statement: print '%40s %15d' % (k, m) However, 1- the string is right adjusted, and I would like it left adjusted 2- the number is a decimal number, and I would like it with the thousands separator and 2 decimals If possible, the thousands separator and the decimal separator should use my local settings. Is there any way to achieve this? From steve at holdenweb.com Sat Mar 13 08:31:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 08:31:32 -0500 Subject: print formatting In-Reply-To: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> References: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> Message-ID: vsoler wrote: > Hello, > > My script contains a print statement: > > print '%40s %15d' % (k, m) > > However, > > 1- the string is right adjusted, and I would like it left > adjusted > 2- the number is a decimal number, and I would like it with > the thousands separator and 2 decimals > > If possible, the thousands separator and the decimal separator should > use my local settings. > > Is there any way to achieve this? Left-alignment is achieved by using a negative width. You can use the locale module to generate thousands-separated numeric string representations: >>> from locale import * >>> setlocale(LC_ALL, '') # locale is otherwise 'C' 'en_US.UTF-8' >>> locale.format("%12.3f", 123456.789, grouping=False) ' 123456.789' >>> locale.format("%12.3f", 123456.789, grouping=True) ' 123,456.789' regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From __peter__ at web.de Sat Mar 13 08:37:50 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Mar 2010 14:37:50 +0100 Subject: print formatting References: <755bdc36-0fb2-4953-9549-148d0e090a68@o3g2000yqb.googlegroups.com> Message-ID: vsoler wrote: > My script contains a print statement: > > print '%40s %15d' % (k, m) > > However, > > 1- the string is right adjusted, and I would like it left > adjusted > 2- the number is a decimal number, and I would like it with > the thousands separator and 2 decimals > > If possible, the thousands separator and the decimal separator should > use my local settings. > > Is there any way to achieve this? >>> import locale >>> locale.setlocale(locale.LC_ALL, "") 'de_DE.UTF-8' Traditional: >>> print '%-40s|%15s' % (k, locale.format("%d", m, grouping=True)) hello | 1.234.567 New: >>> "{0:<40} {1:15n}".format(k, m) 'hello 1.234.567' See also: http://docs.python.org/dev/py3k/library/string.html#formatstrings Peter From python at bdurham.com Sat Mar 13 08:45:06 2010 From: python at bdurham.com (python at bdurham.com) Date: Sat, 13 Mar 2010 08:45:06 -0500 Subject: python to exe In-Reply-To: <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com><50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com><4B9B17B3.8000307@cnsp.com> <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> Message-ID: <1268487906.15871.1364627963@webmail.messagingengine.com> Robin, > do you of an alternate compilter it doesn't work (py2exe) on my windows 7 box I can assure you that Py2exe does work on Windows 7 (my firm develops commercial Python applications packaged using Py2exe running on Windows 7), but it does take a bit of fiddling and some patience. Join the py2exe newsgroup and post your problems there. https://lists.sourceforge.net/lists/listinfo/py2exe-users You may also want to google 'Gui2exe'. This is a free front-end to Py2exe that you can use to generate your Py2exe setup.py scripts. Note that Gui2exe requires wxPython (free) to run. Finally, make sure you are trying to compile 32-bit Python 2.x code. I don't think py2exe supports Python 3.x or 64-bit versions of Python yet. > Nope; py2exe is pretty much the go-to tool for this. I hear great things about PyInstaller. The project is not dead - make sure you use the latest version in the SVN. Search stackoverflow.com for positive feedback and tips on PyInstaller. Its on our plate to take a good look this product 'one of these days'. Good luck! Malcolm From albert at spenarnc.xs4all.nl Sat Mar 13 09:53:35 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Mar 2010 14:53:35 GMT Subject: Question about typing: ints/floats References: <50475f70-e6bf-4f11-b1ab-b91f4e1260f8@e36g2000yqc.googlegroups.com> Message-ID: In article , MRAB wrote: >Zeeshan Quireshi wrote: >> On Mar 3, 6:45 pm, Wells wrote: >>> This seems sort of odd to me: >>> >>>>>> a = 1 >>>>>> a += 1.202 >>>>>> a >>> 2.202 >>> >>> Indicates that 'a' was an int that was implicitly casted to a float. >>> But: >>> >>>>>> a = 1 >>>>>> b = 3 >>>>>> a / b >>> 0 >>> >>> This does not implicitly do the casting, it treats 'a' and 'b' as >>> integers, and the result as well. Changing 'b' to 3.0 will yield a >>> float as a result (0.33333333333333331) >>> >>> Is there some way to explain the consistency here? Does python >>> implicitly change the casting when you add variables of a different >>> numeric type? >>> >>> Anyway, just curiosity more than anything else. Thanks! >> >> Python, like most other languages performs only integer division when >> both the operands are ints. So only if one of the types is a flot or >> you explicitly cast your expression to be a double, then the value >> will be a fraction. otherwise you will the quotient. > >int + int gives int >float + float gives float >int + float gives float You skip a step here that the OP may have missed. a = 1 a += 1.222 This invokes the calculation 1 + 1.222 which is int + float. Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From karper12345 at yahoo.com Sat Mar 13 09:55:07 2010 From: karper12345 at yahoo.com (Karjer Jdfjdf) Date: Sat, 13 Mar 2010 06:55:07 -0800 (PST) Subject: Use python and Jython together? (newbie) Message-ID: <254688.8813.qm@web44705.mail.sp1.yahoo.com> I'm pretty new at programming and want some advice on mixing Jython and Python. I want to use Jython to access some Java libraries, but I want to keep developing in normal Python. Some modules I use a lot are not available in Jython. The bulk of my programming is in Python but I want to use Java 2D libraries for graphical presentation of data generated in normal Python. Is it possible that I generate data in Python and then pass it through to a Jython program to visualise the data. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sat Mar 13 10:05:06 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Mar 2010 07:05:06 -0800 (PST) Subject: building a dict Message-ID: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Say that "m" is a tuple of 2-tuples m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) and I need to build a "d" dict where each key has an associated list whose first element is the count, and the second is the sum. If a 2- tuple contains a None value, it should be discarded. The expected result is: d={'as':[2, 9], 'ab': [1,5]} How should I proceed? So far I have been unsuccessful. I have tried with a "for" loop. Thank you for your help From lists at cheimes.de Sat Mar 13 10:10:22 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 13 Mar 2010 16:10:22 +0100 Subject: Use python and Jython together? (newbie) In-Reply-To: <254688.8813.qm@web44705.mail.sp1.yahoo.com> References: <254688.8813.qm@web44705.mail.sp1.yahoo.com> Message-ID: <4B9BAADE.7090208@cheimes.de> Karjer Jdfjdf wrote: > I'm pretty new at programming and want some advice on mixing Jython and Python. > > I want to use Jython to access some Java libraries, but I want to keep developing in normal Python. Some modules I use a lot are not available in Jython. > > The bulk of my programming is in Python but I want to use Java 2D libraries for graphical presentation of data generated in normal Python. Is it possible that I generate data in Python and then pass it through to a Jython program to visualise the data. You can't mix Jython and Python in one program. But you can use other means to create bindings for Java code. JCC (http://pypi.python.org/pypi/JCC/2.5.1) is a very powerful code generator for CPython. Christian From joncle at googlemail.com Sat Mar 13 10:25:45 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 07:25:45 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Message-ID: <7f3ae1a0-5de8-4c98-9eec-086b7d927c5c@t41g2000yqt.googlegroups.com> On 13 Mar, 15:05, vsoler wrote: > Say that "m" is a tuple of 2-tuples > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > and I need to build a "d" dict where each key has an associated list > whose first element is the count, and the second is the sum. If a 2- > tuple contains a None value, it should be discarded. > > The expected result is: > d={'as':[2, 9], 'ab': [1,5]} > > How should I proceed? So far I have been unsuccessful. I have tried > with a "for" loop. > > Thank you for your help Something like: d = defaultdict( lambda: [0,0] ) for key, val in filter(lambda L: not any(i is None for i in L), m): d[key][0] += 1 d[key][1] += val hth Jon From pmaupin at gmail.com Sat Mar 13 10:28:19 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 07:28:19 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Message-ID: <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> On Mar 13, 9:05?am, vsoler wrote: > Say that "m" is a tuple of 2-tuples > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > and I need to build a "d" dict where each key has an associated list > whose first element is the count, and the second is the sum. If a 2- > tuple contains a None value, it should be discarded. > > The expected result is: > d={'as':[2, 9], 'ab': [1,5]} > > How should I proceed? So far I have been unsuccessful. I have tried > with a "for" loop. Post your first try at a for loop, and people might be willing to point out problems, but this is such a basic for loop that it is unlikely that anybody is going to write your ENTIRE homework for you. Regards, Pat From albert at spenarnc.xs4all.nl Sat Mar 13 10:29:54 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 13 Mar 2010 15:29:54 GMT Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: In article <7vj7fdFnnjU1 at mid.individual.net>, Gregory Ewing wrote: >Given some known data/crc pairs, how feasible is it to >figure out the polynomial being used to generate the crc? > >In the case I'm looking at, it appears that the crc >size may be at least 24 bits, so just trying all possible >polynomials probably isn't doable. > >An article I found hints at the possibility of using >GCDs to make the search more efficient, but doesn't go >into any details. Anyone know of any literature about >this? > >If it helps, I have the ability to generate test cases >with known message contents to some extent, although >I don't have complete control over the contents. Also >it's a manual process, so generating large numbers of >them automatically isn't an option. If it is really a CRC, it is doable. You can have an indication, if the intention is to detect machine errors (transmission or disk errors) or they want you to prevent tampering with the file. In the latter case it may be a one-way hash. Then it is near impossible, as this is the design criterion for a one-way hash. >-- >Greg Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From steve at holdenweb.com Sat Mar 13 10:36:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Mar 2010 10:36:46 -0500 Subject: building a dict In-Reply-To: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> Message-ID: vsoler wrote: > Say that "m" is a tuple of 2-tuples > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > and I need to build a "d" dict where each key has an associated list > whose first element is the count, and the second is the sum. If a 2- > tuple contains a None value, it should be discarded. > > The expected result is: > d={'as':[2, 9], 'ab': [1,5]} > > How should I proceed? So far I have been unsuccessful. I have tried > with a "for" loop. > > Thank you for your help Here's a fairly simple-minded approach using a defaultdict, which calls the dflt() function to create a value when the key is absent. >>> from collections import defaultdict >>> def dflt(): ... return [0, 0] ... >>> m = (('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) >>> d = defaultdict(dflt) >>> for key, n in m: ... if key is not None and n is not None: ... c, t = d[key] ... d[key] = [c+1, t+n] ... >>> d defaultdict(, {'as': [2, 9], 'ab': [1, 5]}) >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From piet at vanoostrum.org Sat Mar 13 10:41:12 2010 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 13 Mar 2010 16:41:12 +0100 Subject: Ideas for creating processes References: <36dec4ff1003101352g7d159742j2a0c76a6b0cd23fb@mail.gmail.com> Message-ID: >>>>> J (J) wrote: >J> And now I'm looking at subprocess and I can set shell=True and it will >J> intrepret special characters like & >J> So could I do something like this: >J> for item in pathlist: >J> subprocess.Popen('rsync command &', shell=True) >J> and simply wait unti they are all done? Using shell=True is often the wrong thing to do. And certainly just to get a process to run in the background. subprocess will run them in the background by default. Besides if you do it in the way you propose you can't wait for them. You can only wait for the shell that starts the rsync, but that will be finished almost immediately. >>> import subprocess >>> p = subprocess.Popen('sleep 1000 &', shell=True) >>> p.wait() 0 >>> The wait() returns immediately. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] Nu Fair Trade woonaccessoires op http://www.zylja.com From joncle at googlemail.com Sat Mar 13 10:58:02 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 07:58:02 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> Message-ID: <251a5a61-aa10-4050-bc0e-da36aed10697@i25g2000yqm.googlegroups.com> On 13 Mar, 15:28, Patrick Maupin wrote: > On Mar 13, 9:05?am, vsoler wrote: > > > Say that "m" is a tuple of 2-tuples > > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > > and I need to build a "d" dict where each key has an associated list > > whose first element is the count, and the second is the sum. If a 2- > > tuple contains a None value, it should be discarded. > > > The expected result is: > > d={'as':[2, 9], 'ab': [1,5]} > > > How should I proceed? So far I have been unsuccessful. I have tried > > with a "for" loop. > > Post your first try at a for loop, and people might be willing to > point out problems, but this is such a basic for loop that it is > unlikely that anybody is going to write your ENTIRE homework for you. > > Regards, > Pat I was thinking it's possibly homework, but looking at previous posts it's fairly unlikely. (If it is, then mea culpa, but as Steve has replied, I think I'll manage to sleep tonight not worrying about the influx of uneducated, incompetent and otherwise useless developers to the market). However, they're receiving some 'elegant' solutions which no professor (unless they're a star pupil - in which case they wouldn't be asking) would take as having been done by their selves. (Or at least I hope not) But yes, I would certainly be interested in the 'unsuccessful attempt'. (To the OP, do post your attempts, it does give more validity). Cheers, Jon. From dreamscmtr63 at gmail.com Sat Mar 13 11:02:07 2010 From: dreamscmtr63 at gmail.com (earner) Date: Sat, 13 Mar 2010 08:02:07 -0800 (PST) Subject: Work at Home - Earn 50, 000 Weekly Without Investment Its Not A Fake, 100% Earning Guarantee Message-ID: Work at Home - Earn 50,000 Weekly Without Investment Its Not A Fake, 100% Earning Guarantee For Register Click Here To Register Now - Start Earning Instantly! http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com http://www.cash-world.myfortuneincome.com From rurpy at yahoo.com Sat Mar 13 11:13:51 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 08:13:51 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> Message-ID: <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> On Mar 13, 8:28 am, Patrick Maupin wrote: > On Mar 13, 9:05 am, vsoler wrote: > > > Say that "m" is a tuple of 2-tuples > > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > > and I need to build a "d" dict where each key has an associated list > > whose first element is the count, and the second is the sum. If a 2- > > tuple contains a None value, it should be discarded. > > > The expected result is: > > d={'as':[2, 9], 'ab': [1,5]} > > > How should I proceed? So far I have been unsuccessful. I have tried > > with a "for" loop. > > Post your first try at a for loop, and people might be willing to > point out problems, but this is such a basic for loop that it is > unlikely that anybody is going to write your ENTIRE homework for you. This is probably what you (OP) were trying to come up with? [untested] d = {} for item in m: key = m[0]; value = m[1] if key is None or value is None: continue if key not in dict: d[key] = [value] else: d[key].append (value) You can replace the for item in m: key = m[0]; value = m[1] above with for key, value in m: which is a little nicer. However, as other responses point out, when you want to "accumulate" results in a dict, collections.defaultdict should pop into your mind first. From mehgcap at gmail.com Sat Mar 13 11:14:37 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sat, 13 Mar 2010 11:14:37 -0500 Subject: wx error, I suspect my class Message-ID: Hello all, I am trying to make a gui out of xrc and wxpython, but I think my understanding of Python's class/method structure is causing problems. The below code returns an error on the line panel=xrc.XRCCTRL(mf, "dl") The error goes back to wxPython itself and says "attribute error: 'none' type object has no attribute 'FindWindowById'" Here is my complete code: import wx from wx import xrc class myapp(wx.App): def OnInit(self): #load the xrc file res=xrc.XmlResource('dictionary.xrc') #load the frame containing everything else mf=res.LoadFrame(None, "mainframe") #assign all necessary controls to variables (text boxes and buttons) for easier binding #format: varName=xrc.XRCCTRL(parent, IDFromXRCFile) panel=xrc.XRCCTRL(mf, "dl") btn_go=xrc.XRCCTRL(panel, "btn_go") btn_close=xrc.XRCCTRL(panel, "btn_close") #now bind the gui controls to functions mf.Bind(wx.EVT_BUTTON, close, id=xrc.XRCID("btn_close")) mf.Show() #end def OnInit def close(self): mf.Close(True) #end def close #end class myapp win=myapp(False) win.MainLoop() That is all there is to it. I made the xrc file with XRCed, so I know it is properly formatted. I always see Python methods and classes using the "self" keyword, but I never understood why or when to/not to use it. I probably need it in the above code, but I am not sure how to insert it correctly. I have been fighting with this code for the last two days with no progress, so I would greatly appreciate any help you can provide. Thanks. -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From joncle at googlemail.com Sat Mar 13 11:19:09 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 08:19:09 -0800 (PST) Subject: Decorator to inject function into __call__ of a class Message-ID: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> This is semi-experimental and I'd appreciate opinions of whether it's the correct design approach or not. It seems like a good idea, but it doesn't mean it is. I have a class 'A', this provides standard support functions and exception handling. I have 'B' and 'C' which specialise upon 'A' What I'd like to achieve is something similar to: @inject(B): def some_function(a, b): pass # something useful The name 'some_function' is completely redundant -- don't need it, don't actually care about the function afterwards, as long as it becomes a __call__ of a 'B' *instance*. I've basically got a huge list of functions, which need to be the callable method of an object, and possibly at run-time, so I don't want to do: class Something(B): def __call__(self, etc.. etc...): pass # do something I've got as far as type(somename, (B,), {}) -- do I then __init__ or __new__ the object or... In short, the function should be the __call__ method of an object that is already __init__'d with the function arguments -- so that when the object is called, I get the result of the the function (based on the objects values). Hope that makes sense, Cheers, Jon. From missive at hotmail.com Sat Mar 13 11:23:07 2010 From: missive at hotmail.com (Lee Harr) Date: Sat, 13 Mar 2010 20:53:07 +0430 Subject: Some PyCon videos won't play Message-ID: I am having a great time watching videos from PyCon. Thanks to everyone who presented, and to those who did such a great job putting the videos up at: http://pycon.blip.tv/ My trouble is that, although most of the videos play perfectly, there are a few that refuse to play at all. Like: Python 101 http://pycon.blip.tv/file/3322312/ Using Python to Create Robotic Simulations for Planetary Exploration http://pycon.blip.tv/file/3332780/ Saturday Morning Lightning talks http://pycon.blip.tv/file/3264041/ Is anyone else having trouble with these? _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. https://signup.live.com/signup.aspx?id=60969 From pmaupin at gmail.com Sat Mar 13 11:26:15 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 08:26:15 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: <83cfee5e-6b6a-41e1-b259-9fdf104423b8@u9g2000yqb.googlegroups.com> On Mar 13, 10:19?am, Jon Clements wrote: > What I'd like to achieve is something similar to: > > @inject(B): > ?def some_function(a, b): > ? ? ?pass # something useful So, just typing at the keyboard here, you mean something like: class InjectClass(object): def __init__(self, func, *args, **kw): self.func = func self.args = args self.kw = kw def __call__(self): self.func(*self.args, **self.kw) Or exactly what are you looking for? Pat From rurpy at yahoo.com Sat Mar 13 11:26:59 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 08:26:59 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> Message-ID: <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> On Mar 13, 9:13?am, ru... at yahoo.com wrote: > On Mar 13, 8:28 am, Patrick Maupin wrote: > > > > > On Mar 13, 9:05 am, vsoler wrote: > > > > Say that "m" is a tuple of 2-tuples > > > > m=(('as',3), ('ab',5), (None, 1), ('as',None), ('as',6)) > > > > and I need to build a "d" dict where each key has an associated list > > > whose first element is the count, and the second is the sum. If a 2- > > > tuple contains a None value, it should be discarded. > > > > The expected result is: > > > d={'as':[2, 9], 'ab': [1,5]} > > > > How should I proceed? So far I have been unsuccessful. I have tried > > > with a "for" loop. > > > Post your first try at a for loop, and people might be willing to > > point out problems, but this is such a basic for loop that it is > > unlikely that anybody is going to write your ENTIRE homework for you. > > This is probably what you (OP) were trying to come up with? > [untested] > > d = {} > for item in m: > ? ? key = m[0]; ?value = m[1] > ? ? if key is None or value is None: continue > ? ? if key not in dict: > ? ? ? ? d[key] = [value] > ? ? else: > ? ? ? ? d[key].append (value) > > You can replace the > ? for item in m: > ? ? ? key = m[0]; ?value = m[1] > above with > ? for key, value in m: > which is a little nicer. > > However, as other responses point out, when you want > to "accumulate" results in a dict, collections.defaultdict > should pop into your mind first. Oops, didn't read very carefully, did I? That should be: d = {} for item in m: key = m[0]; value = m[1] if key is None or value is None: continue if key not in dict: d[key] = [1, value] else: d[key][0] += 1 d[key][1] += value From joncle at googlemail.com Sat Mar 13 11:38:16 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 08:38:16 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <83cfee5e-6b6a-41e1-b259-9fdf104423b8@u9g2000yqb.googlegroups.com> Message-ID: On 13 Mar, 16:26, Patrick Maupin wrote: > On Mar 13, 10:19?am, Jon Clements wrote: > > > What I'd like to achieve is something similar to: > > > @inject(B): > > ?def some_function(a, b): > > ? ? ?pass # something useful > > So, just typing at the keyboard here, you mean something like: > > class InjectClass(object): > ? ? def __init__(self, func, *args, **kw): > ? ? ? ? self.func = func > ? ? ? ? self.args = args > ? ? ? ? self.kw = kw > ? ? def __call__(self): > ? ? ? ? self.func(*self.args, **self.kw) > > Or exactly what are you looking for? > > Pat Not quite. Let's say I have function 'F': def add(a, b): return a + b And a base class of 'C' which does all the __init__ stuff or whatever's needed, the function 'add' should return a new class __init__'d with a and b, but 'add' should be the __call__ of that instance. Hope that makes sense, and TY for your post, Jon. From jackdied at gmail.com Sat Mar 13 11:42:51 2010 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Mar 2010 11:42:51 -0500 Subject: Decorator to inject function into __call__ of a class In-Reply-To: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > This is semi-experimental and I'd appreciate opinions of whether it's > the correct design approach or not. It seems like a good idea, but it > doesn't mean it is. > > I have a class 'A', this provides standard support functions and > exception handling. > I have 'B' and 'C' which specialise upon 'A' > > What I'd like to achieve is something similar to: > > @inject(B): > ?def some_function(a, b): > ? ? pass # something useful > > The name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > > I've basically got a huge list of functions, which need to be the > callable method of an object, and possibly at run-time, so I don't > want to do: > > class Something(B): > ? ?def __call__(self, etc.. etc...): > ? ? ? ? pass # do something > > I've got as far as type(somename, (B,), {}) -- do I then __init__ or > __new__ the object or... > > In short, the function should be the __call__ method of an object that > is already __init__'d with the function arguments -- so that when the > object is called, I get the result of the the function (based on the > objects values). I'm not sure exactly what you are asking for, but if what you want is a bunch of different objects that vary only by their class's __call__ you could do it with a function that returns a new class based on A but with a new __call__: def make_new_call_class(base_class, call_func): class NewClass(base_class): def __call__(self, *args, **kw): return call_func(self, *args, *kw) return NewClass or the return could even be NewClass() [return an instance] if this is a one off. That said, I'm not really sure what this behavior is good for. -Jack From pmaupin at gmail.com Sat Mar 13 12:03:00 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 09:03:00 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <83cfee5e-6b6a-41e1-b259-9fdf104423b8@u9g2000yqb.googlegroups.com> Message-ID: <7c9e6c13-f388-44b9-8fc3-1faaacd8680a@t23g2000yqt.googlegroups.com> On Mar 13, 10:38?am, Jon Clements wrote: > On 13 Mar, 16:26, Patrick Maupin wrote: > > > > > On Mar 13, 10:19?am, Jon Clements wrote: > > > > What I'd like to achieve is something similar to: > > > > @inject(B): > > > ?def some_function(a, b): > > > ? ? ?pass # something useful > > > So, just typing at the keyboard here, you mean something like: > > > class InjectClass(object): > > ? ? def __init__(self, func, *args, **kw): > > ? ? ? ? self.func = func > > ? ? ? ? self.args = args > > ? ? ? ? self.kw = kw > > ? ? def __call__(self): > > ? ? ? ? self.func(*self.args, **self.kw) > > > Or exactly what are you looking for? > > > Pat > > Not quite. > > Let's say I have function 'F': > > def add(a, b): return a + b > > And a base class of 'C' which does all the __init__ stuff or > whatever's needed, > the function 'add' should return a new class __init__'d with a and b, > but 'add' > should be the __call__ of that instance. > > Hope that makes sense, and TY for your post, > > Jon. Well, you could do it with a class. But if I'm understanding correctly, maybe it's simpler than that: >>> def inject(*args, **kw): ... def wrapper(func): ... def go(): ... return func(*args, **kw) ... return go ... return wrapper ... >>> @inject(20, 22) ... def add(a, b): ... return a + b ... >>> add() 42 From jlundell at pobox.com Sat Mar 13 12:03:36 2010 From: jlundell at pobox.com (JLundell) Date: Sat, 13 Mar 2010 09:03:36 -0800 (PST) Subject: class inheritance Message-ID: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> I've got a subclass of fractions.Fraction called Value; it's a mostly trivial class, except that it overrides __eq__ to mean 'nearly equal'. However, since Fraction's operations result in a Fraction, not a Value, I end up with stuff like this: x = Value(1) + Value(2) where x is now a Fraction, not a Value, and x == y uses Fraction.__eq__ rather than Value.__eq__. This appears to be standard Python behavior (int does the same thing). I've worked around it by overriding __add__, etc, with functions that invoke Fraction but coerce the result. But that's tedious; there are a lot of methods to override. So I'm wondering: is there a more efficient way to accomplish what I'm after? From pmaupin at gmail.com Sat Mar 13 12:09:20 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 09:09:20 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <59af7283-f362-4d1e-92c7-14eab59555dd@g19g2000yqe.googlegroups.com> On Mar 13, 11:03?am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? 7 years ago, I had a similar problem for a different and now obsolete reason. I'm sure my solution could be easily updated though. I wrote code to write a wrapper class. Sort of a meta-module. Original reference here: http://groups.google.com/group/comp.lang.python/browse_frm/thread/1253bbab7dfd4b/59289c16603fb374?hl=en&lnk=gst&q=pmaupin+userint#59289c16603fb374 HTH, Pat From joncle at googlemail.com Sat Mar 13 12:10:02 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 09:10:02 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> On 13 Mar, 16:42, Jack Diederich wrote: > On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > > This is semi-experimental and I'd appreciate opinions of whether it's > > the correct design approach or not. It seems like a good idea, but it > > doesn't mean it is. > > > I have a class 'A', this provides standard support functions and > > exception handling. > > I have 'B' and 'C' which specialise upon 'A' > > > What I'd like to achieve is something similar to: > > > @inject(B): > > ?def some_function(a, b): > > ? ? pass # something useful > > > The name 'some_function' is completely redundant -- don't need it, > > don't actually care about the function afterwards, as long as it > > becomes a __call__ of a 'B' *instance*. > > > I've basically got a huge list of functions, which need to be the > > callable method of an object, and possibly at run-time, so I don't > > want to do: > > > class Something(B): > > ? ?def __call__(self, etc.. etc...): > > ? ? ? ? pass # do something > > > I've got as far as type(somename, (B,), {}) -- do I then __init__ or > > __new__ the object or... > > > In short, the function should be the __call__ method of an object that > > is already __init__'d with the function arguments -- so that when the > > object is called, I get the result of the the function (based on the > > objects values). > > I'm not sure exactly what you are asking for, but if what you want is > a bunch of different objects that vary only by their class's __call__ > you could do it with a function that returns a new class based on A > but with a new __call__: > > def make_new_call_class(base_class, call_func): > ? class NewClass(base_class): > ? ? def __call__(self, *args, **kw): > ? ? ? return call_func(self, *args, *kw) > ? return NewClass > > or the return could even be NewClass() [return an instance] if this is > a one off. > > That said, I'm not really sure what this behavior is good for. > > -Jack Cheers Jack for the response. The behaviour is to not derive from a class, but rather allow the decorators to do so... so I would like to iterate over a list of functions (don't care what they're called) and then inject the function as a method. If needs be at run-time. Say I have 1000 functions (okay, admittedly over quoted), but I don't want every programmer to inherit from 'B' or 'C', but to 'inject'. So the idea is that classes are pre-defined, have predictable behaviour, *except* the __call__ is different. You are correct in this. Why do I want that behaviour? -> - It's easier, no inheriting from a class, when needs not. - Some integrity (anyone can define a function and 'inject' to the Management class) - Easier maintainability - maybe :) for i in function_list: i = inject(function_list) At the end of the day: def blah(x, y, z): pass That should be the callable of the object. Cheers again, Jon. From rurpy at yahoo.com Sat Mar 13 12:16:16 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 09:16:16 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> Message-ID: On Mar 13, 9:26?am, ru... at yahoo.com wrote: > That should be: > d = {} > for item in m: ? ? key = item[0]; ?value = item[1] > ? ? if key is None or value is None: continue > ? ? if key not in dict: > ? ? ? ? d[key] = [1, value] > ? ? else: > ? ? ? ? d[key][0] += 1 > ? ? ? ? d[key][1] += value That's it. Any other mistakes, you find 'em. From jackdied at gmail.com Sat Mar 13 12:37:45 2010 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Mar 2010 12:37:45 -0500 Subject: class inheritance In-Reply-To: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: On Sat, Mar 13, 2010 at 12:03 PM, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? If Fraction.__add__ returns a new object but the subclass Value is compatible (as I would except since it is a sublcass) then just change all references in Franction.__add__ to be more generic, ex/ class Franction(): def __add__(self, other): return self.__classs__(self.denominator + other.denominator) That way if __add__ is called by an instance of a subclass it will return an instance of that subclass. -Jack From jackdied at gmail.com Sat Mar 13 12:42:01 2010 From: jackdied at gmail.com (Jack Diederich) Date: Sat, 13 Mar 2010 12:42:01 -0500 Subject: Decorator to inject function into __call__ of a class In-Reply-To: <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> Message-ID: On Sat, Mar 13, 2010 at 12:10 PM, Jon Clements wrote: > On 13 Mar, 16:42, Jack Diederich wrote: >> On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: >> > This is semi-experimental and I'd appreciate opinions of whether it's >> > the correct design approach or not. It seems like a good idea, but it >> > doesn't mean it is. >> >> > I have a class 'A', this provides standard support functions and >> > exception handling. >> > I have 'B' and 'C' which specialise upon 'A' >> >> > What I'd like to achieve is something similar to: >> >> > @inject(B): >> > ?def some_function(a, b): >> > ? ? pass # something useful >> >> > The name 'some_function' is completely redundant -- don't need it, >> > don't actually care about the function afterwards, as long as it >> > becomes a __call__ of a 'B' *instance*. >> >> > I've basically got a huge list of functions, which need to be the >> > callable method of an object, and possibly at run-time, so I don't >> > want to do: >> >> > class Something(B): >> > ? ?def __call__(self, etc.. etc...): >> > ? ? ? ? pass # do something >> >> > I've got as far as type(somename, (B,), {}) -- do I then __init__ or >> > __new__ the object or... >> >> > In short, the function should be the __call__ method of an object that >> > is already __init__'d with the function arguments -- so that when the >> > object is called, I get the result of the the function (based on the >> > objects values). >> >> I'm not sure exactly what you are asking for, but if what you want is >> a bunch of different objects that vary only by their class's __call__ >> you could do it with a function that returns a new class based on A >> but with a new __call__: >> >> def make_new_call_class(base_class, call_func): >> ? class NewClass(base_class): >> ? ? def __call__(self, *args, **kw): >> ? ? ? return call_func(self, *args, *kw) >> ? return NewClass >> >> or the return could even be NewClass() [return an instance] if this is >> a one off. >> >> That said, I'm not really sure what this behavior is good for. >> >> -Jack > > Cheers Jack for the response. > > The behaviour is to not derive from a class, but rather allow > the decorators to do so... so I would like to iterate over > a list of functions (don't care what they're called) and then > inject the function as a method. If needs be at run-time. > > Say I have 1000 functions (okay, admittedly over quoted), but > I don't want every programmer to inherit from 'B' or 'C', but > to 'inject'. So the idea is that classes are pre-defined, have > predictable behaviour, *except* the __call__ is different. > > You are correct in this. Why do I want that behaviour? -> > > - It's easier, no inheriting from a class, when needs not. > - Some integrity (anyone can define a function and 'inject' to the > Management class) > - Easier maintainability - maybe :) > > for i in function_list: > ? ?i = inject(function_list) > > At the end of the day: > def blah(x, y, z): > ? pass > > That should be the callable of the object. I'm still not sure why you are trying to do this, but you can do it with delegation. Have the parent class's __call__ look for an instance attribute named call_this and then call it, ex/ class A(): def __call__(self, *args, **kw): self.call_this(*args, **kw) # we grab this off the instance ob = A() def my_func(*stuff): pass ob.call_this = my_func -Jack From pmaupin at gmail.com Sat Mar 13 12:44:38 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sat, 13 Mar 2010 09:44:38 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <5e8a6388-7532-4183-a69e-bc4330e34b83@t20g2000yqe.googlegroups.com> On Mar 13, 11:37?am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): > ? def __add__(self, other): > ? ? return self.__classs__(self.denominator + other.denominator) > > That way if __add__ is called by an instance of a subclass it will > return an instance of that subclass. > Yes, I think the OP understands that, and also understands that he would have to do the same thing for __sub__, __div__, __rsub__, __radd__, etc. That's why I suggested that, instead of writing all that tedious code, he could write code that writes the tedious code :-) As Terence Parr of ANTLER fame asks: "Why program by hand in five days what you can spend five years of your life automating?" Pat From martin.schoon at gmail.com Sat Mar 13 13:04:19 2010 From: martin.schoon at gmail.com (Martin =?utf-8?B?U2Now7bDtm4=?=) Date: Sat, 13 Mar 2010 19:04:19 +0100 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: <87aaucxfmk.fsf@crunchbang.Belkin> Mark Lawrence writes: > > I'm certain that members of the Guinea Pig Club might have something > to say on that one, see :- > http://en.wikipedia.org/wiki/Guinea_Pig_Club Interesting. My mum is a retired surgeon and in the mid 1980s she attended a course in plastic surgery and among other things she learnt that plastic surgery got going for real during WWII 'thanks' to all pilots with burns. I have forwarded the link above to her. /Martin From jlundell at pobox.com Sat Mar 13 13:11:15 2010 From: jlundell at pobox.com (JLundell) Date: Sat, 13 Mar 2010 10:11:15 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: On Mar 13, 9:37?am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): > ? def __add__(self, other): > ? ? return self.__classs__(self.denominator + other.denominator) > > That way if __add__ is called by an instance of a subclass it will > return an instance of that subclass. That was my first thought, because I had originally assumed that's the way Fraction worked. However, a) it's easier to do the overriding in my own class than patching Fraction (or at least no harder), and 2) Fraction is only doing the same thing that int does, so it's hard to justify a patch. I think Patrick's solution might be the tidiest one. I'll give it a shot (thanks, Patrick). From python at mrabarnett.plus.com Sat Mar 13 13:13:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Mar 2010 18:13:46 +0000 Subject: Use python and Jython together? (newbie) In-Reply-To: <254688.8813.qm@web44705.mail.sp1.yahoo.com> References: <254688.8813.qm@web44705.mail.sp1.yahoo.com> Message-ID: <4B9BD5DA.1060907@mrabarnett.plus.com> Karjer Jdfjdf wrote: > I'm pretty new at programming and want some advice on mixing Jython and > Python. > > I want to use Jython to access some Java libraries, but I want to keep > developing in normal Python. Some modules I use a lot are not available > in Jython. > > The bulk of my programming is in Python but I want to use Java 2D > libraries for graphical presentation of data generated in normal Python. > Is it possible that I generate data in Python and then pass it through > to a Jython program to visualise the data. > You could have 2 scripts running, one in CPython and the other in Jython, communicating via sockets. You would need to decide on a protocol, perhaps passing the data as strings encoded in UTF-8. From news1234 at free.fr Sat Mar 13 13:45:53 2010 From: news1234 at free.fr (News123) Date: Sat, 13 Mar 2010 19:45:53 +0100 Subject: how to start a python script only once Message-ID: <4b9bdd61$0$22515$426a74cc@news.free.fr> Hi, I'd like to make sure, that a certain python program will only be run once per host. (linux/windows) so if the program is started a second time it should just terminate and let the other one run. This does not have to be the fastest solution, but it should be reliable. I have a few ideas, but wonder, which one is the most common My ideas so far: pid file and file locking -------------------------- create a file like program.pid with the pid of the running program an use file locking to avoid race connditions. However I currently don't know how to do file locking under windows and I don't know how to do file lockng with python and linux. I'll start googling. sqlite and locking -------------------- quite some time ago I used a mysql table and locking as an inter-host mutex. Perhaps sqlite would be good enough for an inter process mutex for processes on the same host, but I don't know it well enough. interprocess mutex -------------------- well I even don't know whether something like this exists on linux / windows Thanks in advanced for any tips N From john at castleamber.com Sat Mar 13 13:52:39 2010 From: john at castleamber.com (John Bokma) Date: Sat, 13 Mar 2010 12:52:39 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: <87fx443vgo.fsf@castleamber.com> Steven D'Aprano writes: > As the old proverb goes: give a man a fish, and you feed him for a day. > Teach him how to fish, and he has food forever. True, but you don't teach someone fishing by poking an eye out with a fishing rod. > I'm an old-fashioned kind of guy, and don't like LMGTFY because it is > tiresome and requires Javascript. I prefer: My reply had little to do with lmgtfy and all to do with hiding it behind tinyurl. But even then, why not do what you just did: give a URL to google directly. For quite some time I thought that comp.lang.perl.misc was quite unfriendly because of a certain attitude. comp.lang.python was quite a refreshment for a while: very newbie friendly, less pissing contests, etc. (but way more fanboism). Yesterday was a sady day: I finally had to conclude that it was only wishful thinking on my part; there is no difference. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Sat Mar 13 14:01:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 13 Mar 2010 14:01:34 -0500 Subject: Some PyCon videos won't play In-Reply-To: References: Message-ID: On 3/13/2010 11:23 AM, Lee Harr wrote: > > I am having a great time watching videos from PyCon. Thanks to > everyone who presented, and to those who did such a great job > putting the videos up at: http://pycon.blip.tv/ > > My trouble is that, although most of the videos play perfectly, > there are a few that refuse to play at all. Like: > > Python 101 > http://pycon.blip.tv/file/3322312/ > > Using Python to Create Robotic Simulations for Planetary Exploration > http://pycon.blip.tv/file/3332780/ > > Saturday Morning Lightning talks > http://pycon.blip.tv/file/3264041/ > > > Is anyone else having trouble with these? Yes, 'spinner' spins indefinitely, while others load and play. From apt.shansen at gmail.com Sat Mar 13 14:02:34 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 13 Mar 2010 11:02:34 -0800 Subject: Decorator to inject function into __call__ of a class In-Reply-To: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> Message-ID: <7a9c25c21003131102x15f7e98agfc1c6ea73962ead1@mail.gmail.com> On Sat, Mar 13, 2010 at 8:19 AM, Jon Clements wrote: > The name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > Special methods are looked up on the class, not the instance, so you can't dot his. However, from reading this thread, I think you're just a bit hung up on naming: you don't need these random / arbitrary functions to be the __call__ on an instance. You need these functions to be called when said instance is called. The easiest way to do that is simply define on the class: def __call__(self, *args, **kwargs): self.func(*args, **kwargs) Then while you are iterating over your list of a thousand functions and making instances, just assign each instance's func attribute. So, for fn in [function_one, function_two, function_three, function_four]: inst = B() inst.func = fn Now, if you really like the decorator syntax, sure: >> def inject(klass): ... def decorator(fn): ... inst = klass() ... inst.func = fn ... return inst ... return decorator ... >>> class A: ... def __init__(self): ... pass ... def __call__(self, *args, **kwargs): ... self.func(*args, **kwargs) ... >>> @inject(A) ... def test(mmm): ... print mmm ... >>> test <__main__.A instance at 0x1004a4fc8> >>> test("Hello") Hello Now, I don't -fully- understand what you're trying to do so this may not be precisely the right thing, but you should be able to adapt the theory. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From joncle at googlemail.com Sat Mar 13 14:02:44 2010 From: joncle at googlemail.com (Jon Clements) Date: Sat, 13 Mar 2010 11:02:44 -0800 (PST) Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> Message-ID: <714d79b0-af65-4ce1-806a-73aa1e9b561d@t20g2000yqe.googlegroups.com> On 13 Mar, 17:42, Jack Diederich wrote: > On Sat, Mar 13, 2010 at 12:10 PM, Jon Clements wrote: > > On 13 Mar, 16:42, Jack Diederich wrote: > >> On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > >> > This is semi-experimental and I'd appreciate opinions of whether it's > >> > the correct design approach or not. It seems like a good idea, but it > >> > doesn't mean it is. > > >> > I have a class 'A', this provides standard support functions and > >> > exception handling. > >> > I have 'B' and 'C' which specialise upon 'A' > > >> > What I'd like to achieve is something similar to: > > >> > @inject(B): > >> > ?def some_function(a, b): > >> > ? ? pass # something useful > > >> > The name 'some_function' is completely redundant -- don't need it, > >> > don't actually care about the function afterwards, as long as it > >> > becomes a __call__ of a 'B' *instance*. > > >> > I've basically got a huge list of functions, which need to be the > >> > callable method of an object, and possibly at run-time, so I don't > >> > want to do: > > >> > class Something(B): > >> > ? ?def __call__(self, etc.. etc...): > >> > ? ? ? ? pass # do something > > >> > I've got as far as type(somename, (B,), {}) -- do I then __init__ or > >> > __new__ the object or... > > >> > In short, the function should be the __call__ method of an object that > >> > is already __init__'d with the function arguments -- so that when the > >> > object is called, I get the result of the the function (based on the > >> > objects values). > > >> I'm not sure exactly what you are asking for, but if what you want is > >> a bunch of different objects that vary only by their class's __call__ > >> you could do it with a function that returns a new class based on A > >> but with a new __call__: > > >> def make_new_call_class(base_class, call_func): > >> ? class NewClass(base_class): > >> ? ? def __call__(self, *args, **kw): > >> ? ? ? return call_func(self, *args, *kw) > >> ? return NewClass > > >> or the return could even be NewClass() [return an instance] if this is > >> a one off. > > >> That said, I'm not really sure what this behavior is good for. > > >> -Jack > > > Cheers Jack for the response. > > > The behaviour is to not derive from a class, but rather allow > > the decorators to do so... so I would like to iterate over > > a list of functions (don't care what they're called) and then > > inject the function as a method. If needs be at run-time. > > > Say I have 1000 functions (okay, admittedly over quoted), but > > I don't want every programmer to inherit from 'B' or 'C', but > > to 'inject'. So the idea is that classes are pre-defined, have > > predictable behaviour, *except* the __call__ is different. > > > You are correct in this. Why do I want that behaviour? -> > > > - It's easier, no inheriting from a class, when needs not. > > - Some integrity (anyone can define a function and 'inject' to the > > Management class) > > - Easier maintainability - maybe :) > > > for i in function_list: > > ? ?i = inject(function_list) > > > At the end of the day: > > def blah(x, y, z): > > ? pass > > > That should be the callable of the object. > > I'm still not sure why you are trying to do this, but you can do it > with delegation. ?Have the parent class's __call__ look for an > instance attribute named call_this and then call it, ex/ > > class A(): > ? def __call__(self, *args, **kw): > ? ? self.call_this(*args, **kw) ?# we grab this off the instance > > ob = A() > def my_func(*stuff): pass > ob.call_this = my_func > > -Jack Jack, thanks very much for your replies -- hugely appreciated. I was delayed by the missus calling me for dinner - I'd forgotten we had a stew going in the slow cooker, and she can't make dumplings to save her life :) If I can re-explain slightly, say I have a class 'compute': class Compute(object): def __init__(self, something): self.something = something # misc other methods here..... then... class ComputeAdd(Compute): pass If I do, @inject def ComputeAdd(fst, snd): return fst + snd The end result should be a new class called ComputeAdd __init__'d with fst and snd, which when called, returns fst + snd. Hope that makes sense. Cheers, Jon. From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 14:23:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 19:23:08 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> Message-ID: <4b9be61c$0$27822$c3e8da3@news.astraweb.com> On Sat, 13 Mar 2010 12:52:39 -0600, John Bokma wrote: > For quite some time I thought that comp.lang.perl.misc was quite > unfriendly because of a certain attitude. comp.lang.python was quite a > refreshment for a while: very newbie friendly, less pissing contests, > etc. (but way more fanboism). > > Yesterday was a sady day: I finally had to conclude that it was only > wishful thinking on my part; there is no difference. You were the first one to inject abuse into this thread. There's a big difference between a mildly sarcastic link and dropping the F-word at one of the more helpful and respected members of the community. Perhaps you are projecting your own hostility and aggro onto others? -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 14:48:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 13 Mar 2010 19:48:28 GMT Subject: Decorator to inject function into __call__ of a class References: <7db4b480-51d7-41c0-b6df-f78cdcb7892e@t20g2000yqe.googlegroups.com> <305a95c3-792e-4949-b1eb-20d794ed3218@g7g2000yqe.googlegroups.com> <714d79b0-af65-4ce1-806a-73aa1e9b561d@t20g2000yqe.googlegroups.com> Message-ID: <4b9bec0b$0$27822$c3e8da3@news.astraweb.com> On Sat, 13 Mar 2010 11:02:44 -0800, Jon Clements wrote: > If I can re-explain slightly, say I have a class 'compute': > > class Compute(object): > def __init__(self, something): > self.something = something > # misc other methods here..... > > then... > > class ComputeAdd(Compute): > pass What's the purpose of the do-nothing subclass? > If I do, > > @inject > def ComputeAdd(fst, snd): > return fst + snd > > The end result should be a new class called ComputeAdd __init__'d with > fst and snd, That will cause a TypeError, because ComputeAdd inherits __init__ from Compute, which only takes a single argument. So you can't initialise it with two. > which when called, returns fst + snd. > > Hope that makes sense. None what so ever, even after reading the entire thread :-) Forget about the *mechanism*, and focus on the *result* you want. Let me see if I can guess what result you want. You want to start with a single base class, say Compute as defined above. Then you want to write a function which interacts with Compute somehow, say: def func(self, x, y): return self.something + x + y and wave some sort of magic wand (a decorator? something else?) to get an object x so that: x("a", "b") returns self.something + "a" + "b". Is that right? If not, I have no idea what you want! But if this is what you want, then this is probably the simplest approach: Start by adding delegation to the Compute class: class Compute(object): def __init__(self, something): self.something = something def __call__(self, *args, **kwargs): return self.function(*args, **kwargs) Then you can initialise an instance of Compute, and add a function to it: def func(self, x, y): return self.something + x + y added = Computer("spam") added.function = func And then say: added("ham", "eggs") -> "spamhameggs" You could possibly even turn this into a decorator: # untested def magic(baseclass, *args): instance = baseclass(*args) def decorator(func): instance.function = func return instance return decorator @magic(Compute, "spam") def func(self, x, y): return self.something + x + y func("ham", "eggs") -> "spamhameggs" Hope this helps. -- Steven From martin.hellwig at dcuktec.org Sat Mar 13 15:16:48 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 13 Mar 2010 20:16:48 +0000 Subject: python to exe In-Reply-To: <4b9be61c$0$27822$c3e8da3@news.astraweb.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <4b9be61c$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 03/13/10 19:23, Steven D'Aprano wrote: > On Sat, 13 Mar 2010 12:52:39 -0600, John Bokma wrote: > >> For quite some time I thought that comp.lang.perl.misc was quite >> unfriendly because of a certain attitude. comp.lang.python was quite a >> refreshment for a while: very newbie friendly, less pissing contests, >> etc. (but way more fanboism). >> >> Yesterday was a sady day: I finally had to conclude that it was only >> wishful thinking on my part; there is no difference. > > > You were the first one to inject abuse into this thread. There's a big > difference between a mildly sarcastic link and dropping the F-word at one > of the more helpful and respected members of the community. Perhaps you > are projecting your own hostility and aggro onto others? > > > John's thought process is a slippery slope and I make the same 'mistake' (notice the quotes please :-)) so often it would seem I won't learn it ever. However on the rare occasion I notice that I am making the mistake I say to myself: The view of a number of individuals do NOT necessarily represent the view of the majority unless proven otherwise by that actual majority. -- mph From almar.klein at gmail.com Sat Mar 13 15:17:43 2010 From: almar.klein at gmail.com (Almar Klein) Date: Sat, 13 Mar 2010 21:17:43 +0100 Subject: python to exe In-Reply-To: <1e3b567.3797.12756f99dda.Coremail.dr.cg@126.com> References: <1e3b567.3797.12756f99dda.Coremail.dr.cg@126.com> Message-ID: >Does anyone know of a good python to stand alone exe compiler? > > >Thanks, > >-Robin > I tried several such tools and found the easiest one: Pyinstaller ( > http://www.pyinstaller.org/ ) > Don't forget cx_freeze! I found it to work pretty easy, and it also works for py3k. Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Sat Mar 13 15:26:45 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 13 Mar 2010 12:26:45 -0800 (PST) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> On Mar 13, 9:03?am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? It's a tad unfortunately Python doesn't make this easier. If I had to do it more than once I'd probably write a mixin to do it: class ArithmeticSelfCastMixin(object): def __add__(self,other): return self.__class__(super(ArithmeticSelfCastMixin,self).__add__(other) # etc. class Value(ArithmeticSelfCastMixin,fraction.Fraction): pass However, I want to warn you about overriding __eq__ to mean "almost equal": it can have unexpected results so I don't recommend it. Two of the main issues with it are: 1. It violates the transitive property ("If A == B and B == C, then A == C") which most programmers expect to be true. 2. It will give unpredictable results when the objects are used in sets or as dictionary keys. Those thow types expect the transitive property to be true. If you are going to redefine __eq__ to mean "almost equal", then at least define __hash__ to raise NotImplementedError so that Python will refuse to use them in sets or as dictionary keys: def __hash__(self): raise NotImplementedError Carl Banks From mcfletch at vrplumber.com Sat Mar 13 16:12:02 2010 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Sat, 13 Mar 2010 16:12:02 -0500 Subject: Python for newbies (Pythno users group in Macedonia) In-Reply-To: References: Message-ID: <4B9BFFA2.7080305@vrplumber.com> ?????? ??????????? wrote: > Hi all, > we are starting with bi-monthly Python User Group meetings in Skopje, > Macedonia. The meetings are targeted for both beginners and more > experienced users. > ... http://us.pycon.org/2010/conference/schedule/event/108/ HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From vicente.soler at gmail.com Sat Mar 13 16:42:12 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Mar 2010 13:42:12 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> Message-ID: <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> On 13 mar, 18:16, ru... at yahoo.com wrote: > On Mar 13, 9:26?am, ru... at yahoo.com wrote:> That should be: > > d = {} > > for item in m: > > ? ? ? key = item[0]; ?value = item[1] > > > ? ? if key is None or value is None: continue > > ? ? if key not in dict: > > ? ? ? ? d[key] = [1, value] > > ? ? else: > > ? ? ? ? d[key][0] += 1 > > ? ? ? ? d[key][1] += value > > That's it. ?Any other mistakes, you find 'em. Thank you all. Your answers are more than valuable to me. I'll study them carefully, but no doubt, my post has been answered. By the way, I suppose I am the OP. Since I am not an native English speaking person, I do not know what it stands for. Perhaps you can tell me. >From what I see from your posts, you would have preferred that I included in my original post my "for loop", so that the post is not so abstract. I have taken note and I'll make it better next time. Thank you for your help. Vicente Soler From rurpy at yahoo.com Sat Mar 13 17:04:54 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 13 Mar 2010 14:04:54 -0800 (PST) Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> Message-ID: <45fd2042-280c-4b7c-ab1f-54a41f6b0cec@o3g2000yqb.googlegroups.com> On Mar 13, 2:42?pm, vsoler wrote: > By the way, I suppose I am the OP. Since I am not an native English > speaking person, I do not know what it stands for. Perhaps you can > tell me. OP means Original Poster (the person who started the discussion) or sometimes Original Post, depending on context. From g.bogle at auckland.no.spam.ac.nz Sat Mar 13 17:20:15 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sun, 14 Mar 2010 11:20:15 +1300 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Mark Lawrence wrote: > > I'm certain that members of the Guinea Pig Club might have something to > say on that one, see :- > http://en.wikipedia.org/wiki/Guinea_Pig_Club > You mean, something like: "That's not funny"? From waldemar.osuch at gmail.com Sat Mar 13 18:12:11 2010 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Sat, 13 Mar 2010 15:12:11 -0800 (PST) Subject: Use python and Jython together? (newbie) References: <254688.8813.qm@web44705.mail.sp1.yahoo.com> Message-ID: <60f0beb3-5ad9-4b60-8aa3-b225f3c6cf6b@f8g2000yqn.googlegroups.com> On Mar 13, 8:10?am, Christian Heimes wrote: > Karjer Jdfjdf wrote: > > I'm pretty new at programming and want some advice on mixing Jython and Python. > > > I want to use Jython to access some Java libraries, but I want to keep developing in normal Python. Some modules I use a lot are not available in Jython. > > > The bulk of my programming is in Python but I want to use Java 2D libraries for graphical presentation of data generated in normal Python. Is it possible that I generate data in Python and then pass it through to a Jython program to visualise the data. > > You can't mix Jython and Python in one program. But you can use other > means to create bindings for Java code. JCC > (http://pypi.python.org/pypi/JCC/2.5.1) is a very powerful code > generator for CPython. > I have not tried it myself but it seems to be possible. http://jpype.sourceforge.net/ From np.mapn at gmail.com Sat Mar 13 18:21:38 2010 From: np.mapn at gmail.com (np map) Date: Sat, 13 Mar 2010 15:21:38 -0800 (PST) Subject: Clustering and automated configuration & deployment toolkit with Python Message-ID: <003064f8-e559-41e9-8110-11fad8373d09@y17g2000yqd.googlegroups.com> I'd like to write an open source clustering (for computation and general use) and automation of configuration/deployment in Python. It's main purpose is to be used in academic environments. It would be something like running numpy/simpy code (and other custom python code) on a set of machines in a distributed fashion (e.g. splitting tasks, doing certain bits on some machines, other sub-tasks on other machines, etc). The cluster could be used in at least two ways: - submit code/files via a web interface, monitor the task via the web interface and download the results from the master node (user<>web interface<>master) - run code directly from another machine on the cluster (as if it were a subprocess or something like this) Requirements (so far): - support the Ubuntu Linux distribution in the initial iteration - be easy to extend to other OS-es and package managers - try to be 3.x compatible where dual compatibility is possible (2.x and 3.x) - it will support Python 2.5-2.6 - document required changes to the 2.x only code to make it work on 3.x - make it easy to submit code directly from python scripts to the cluster (with the right credentials) - support key based authentication for job submission - should talk to at least one type of RDBMS to store various types of data - the cluster should be able to kill a task on nodes automatically if it executes for too long or requires too much memory (configurable) - should be modular (use automation & configuration or just clustering) Therefore, I'd like to know a few things: Is there a clustering toolkit already available for python? What would the recommended architecture be ? How should the "user" code interface with the clustering system's code? How should the results be stored (at the node and master level)? Should threading be supported in the tasks? How should they be returned to the Master node(s)? (polling, submitted by the nodes, etc) What libraries should be used for this? (e.g. fabric as a library, pyro, etc) Any other suggestions and pieces of advice? Should Fabric be used in this clustering system for automation? If not, what else? Would simply using a wrapper written in python for the 'ssh' app be ok? Would the following architecture be ok? Master: splits tasks into sub-tasks, sends them to nodes - provided the node's load isn't greater than a certain percentage, gets results, stores and provides configuration to nodes, stores results, etc Node: runs code, applies configuration, submits the results to the master, etc If this system actually gets python-level code submission inside, how should it work? The reason I posted this set of questions and ideas is that I'd like this to be as flexible and usable as possible. Thanks. From maymunbeyin at gmail.com Sat Mar 13 19:34:55 2010 From: maymunbeyin at gmail.com (kuru) Date: Sat, 13 Mar 2010 16:34:55 -0800 (PST) Subject: Feeding differeent data types to a class instance? Message-ID: Hi I have couple classes in the form of class Vector: def __init__(self,x,y,z): self.x=x self.y=y self.z=z This works fine for me. However I want to be able to provide a list, tuple as well as individual arguments like below myvec=Vector(1,2,3) This works well However I also want to be able to do vect=[1,2,3] myvec=Vec(vect) I want this class to accept multiple data types but process them as they are same when the classs deals with the instances. thanks From rhodri at wildebst.demon.co.uk Sat Mar 13 19:54:40 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sun, 14 Mar 2010 00:54:40 -0000 Subject: Feeding differeent data types to a class instance? References: Message-ID: On Sun, 14 Mar 2010 00:34:55 -0000, kuru wrote: > Hi > > I have couple classes in the form of > > class Vector: > def __init__(self,x,y,z): > self.x=x > self.y=y > self.z=z > > This works fine for me. However I want to be able to provide a list, > tuple as well as individual arguments like below > > myvec=Vector(1,2,3) > > This works well > > > However I also want to be able to do > > vect=[1,2,3] > > myvec=Vec(vect) You can do something like: class Vector(object): def __init__(self, x, y=None, z=None): if isinstance(x, list): self.x = x[0] self.y = x[1] self.z = x[2] else: self.x = x self.y = y self.z = z but this gets messy quite quickly. The usual wisdom these days is to write yourself a separate class method to create your object from a different type: class Vector(object): ... def __init__ as you did before ... @classmethod def from_list(cls, lst): return cls(lst[0], lst[1], lst[2]) vect = [1,2,3] myvec = Vector.from_list(vect) -- Rhodri James *-* Wildebeeste Herder to the Masses From monaghand.david at gmail.com Sat Mar 13 20:00:16 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Sun, 14 Mar 2010 01:00:16 +0000 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> Message-ID: On Sat, 13 Mar 2010 12:52:39 -0600, John Bokma wrote: >Steven D'Aprano writes: > >> As the old proverb goes: give a man a fish, and you feed him for a day. >> Teach him how to fish, and he has food forever. > >True, but you don't teach someone fishing by poking an eye out with a >fishing rod. > >> I'm an old-fashioned kind of guy, and don't like LMGTFY because it is >> tiresome and requires Javascript. I prefer: > >My reply had little to do with lmgtfy and all to do with hiding it behind >tinyurl. But even then, why not do what you just did: give a URL to >google directly. > >For quite some time I thought that comp.lang.perl.misc was quite >unfriendly because of a certain attitude. comp.lang.python was quite a >refreshment for a while: very newbie friendly, less pissing contests, >etc. (but way more fanboism). > >Yesterday was a sady day: I finally had to conclude that it was only >wishful thinking on my part; there is no difference. There was a time, when the internet was young and most newbies couldn't find their own backsides with both hands, that your conclusions would be well placed.That time has long passed: Newsgroups are a long way down the hierarchy since those times and anyone turning up here nowadays _has_ heard of Google. If they haven't used it, I don't really consider the gentle reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle soul to be on the internet at all; someone might say "Boo" to you at any moment. Beware. DaveM From usenot at geekmail.INVALID Sat Mar 13 20:01:37 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 14 Mar 2010 02:01:37 +0100 Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> Message-ID: <20100314020137.2bb95011@geekmail.INVALID> On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler wrote: > By the way, I suppose I am the OP. Since I am not an native English > speaking person, I do not know what it stands for. Perhaps you can > tell me. > Perhaps you can find out yourself: http://www.urbandictionary.com/define.php?term=op /W -- INVALID? DE! From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 20:23:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Mar 2010 01:23:46 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: <4b9c3aa2$0$27822$c3e8da3@news.astraweb.com> On Sun, 14 Mar 2010 11:20:15 +1300, Gib Bogle wrote: > Mark Lawrence wrote: >> >> I'm certain that members of the Guinea Pig Club might have something to >> say on that one, see :- >> http://en.wikipedia.org/wiki/Guinea_Pig_Club >> >> > You mean, something like: "That's not funny"? Or possibly "That's hilarious!!!". Gallows humour is sometimes hard to predict. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Mar 13 20:27:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Mar 2010 01:27:56 GMT Subject: Feeding differeent data types to a class instance? References: Message-ID: <4b9c3b9c$0$27822$c3e8da3@news.astraweb.com> On Sat, 13 Mar 2010 16:34:55 -0800, kuru wrote: > I want this class to accept multiple data types but process them as they > are same when the classs deals with the instances. The usual term for this is "polymorphism". > myvec=Vector(1,2,3) > > vect=[1,2,3] > myvec=Vec(vect) I assume you mean Vector in the last line. I find this the easiest way to handle this situation: class Vector(object, *args): if len(args) == 1: # Assume the caller passed a list argument. args = args[0] x, y, z = args # Unpack the arguments. # then process as normal. -- Steven From jgardner at jonathangardner.net Sun Mar 14 03:42:31 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 13 Mar 2010 23:42:31 -0800 Subject: NoSQL Movement? In-Reply-To: <7xljdx73a9.fsf@ruckus.brouhaha.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> Message-ID: <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: > "D'Arcy J.M. Cain" writes: >> Just curious, what database were you using that wouldn't keep up with >> you? ?I use PostgreSQL and would never consider going back to flat >> files. > > Try making a file with a billion or so names and addresses, then > compare the speed of inserting that many rows into a postgres table > against the speed of copying the file. > Also consider how much work it is to partition data from flat files versus PostgreSQL tables. >> The only thing I can think of that might make flat files faster is >> that flat files are buffered whereas PG guarantees that your >> information is written to disk before returning > > Don't forget all the shadow page operations and the index operations, > and that a lot of these operations require reading as well as writing > remote parts of the disk, so buffering doesn't help avoid every disk > seek. > Plus the fact that your other DB operations slow down under the load. -- Jonathan Gardner jgardner at jonathangardner.net From ahmeterdinc09 at gmail.com Sun Mar 14 04:14:49 2010 From: ahmeterdinc09 at gmail.com (ahmet erdinc yilmaz) Date: Sun, 14 Mar 2010 10:14:49 +0200 Subject: xml-rpc Message-ID: <4B9C9AF9.80609@gmail.com> Hello, Recenetly we are developing a senior project and decide to use xmlrpclib. However I have some questions. In the documentation I could not find any clue about handling requests? Does the server handles each request in a separate thread? Or is there some queuing mechanism for client calls? Thanks in advance. --erdinc From niels.ellegaard at gmail.com Sun Mar 14 04:36:24 2010 From: niels.ellegaard at gmail.com (Niels L. Ellegaard) Date: Sun, 14 Mar 2010 09:36:24 +0100 Subject: Some PyCon videos won't play References: Message-ID: <877hpfwb93.fsf@langager.dbnet.dk> Lee Harr writes: > I am having a great time watching videos from PyCon. Thanks to > everyone who presented, and to those who did such a great job > putting the videos up at: http://pycon.blip.tv/ > > My trouble is that, although most of the videos play perfectly, > there are a few that refuse to play at all. Like: I also had problems playing some of the videos (using gnash), but if you press "files and links", then you can download the talk as an ogv file. Furthermore blip.tv provides an rss-feed with ogv-files for each channel on their site. http://pycon.blip.tv/rss Thanks to the pycon people for putting all their nice videos on the web. Niels From bieffe62 at gmail.com Sun Mar 14 04:51:58 2010 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Sun, 14 Mar 2010 00:51:58 -0800 (PST) Subject: how to start a python script only once References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: On 13 Mar, 19:45, News123 wrote: > Hi, > > I'd like to make sure, that a certain python program will only be run > once per host. (linux/windows) > > so if the program is started a second time it should just terminate and > let the other one run. > > This does not have to be the fastest solution, but it should be reliable. > > I have a few ideas, but wonder, which one is the most common > > My ideas so far: > > pid file and file locking > -------------------------- > create a file like program.pid ?with the pid of the running program an > use file locking to avoid race connditions. > > However I currently don't know how to do file locking under windows > and I don't know how to do file lockng with python and linux. > I'll start googling. > > sqlite and locking > -------------------- > quite some time ago I used a mysql table and locking as an inter-host mutex. > > Perhaps sqlite would be good enough for an inter process mutex for > processes on the same host, but I don't know it well enough. > > interprocess mutex > -------------------- > well I even don't know whether something like this exists on linux / windows > > Thanks in advanced for any tips > > N Apart from file, a portable solution would be to bind to an unused porta and assume that finding the port busy means that your program is already running on the port. On recent python installations there is the multiprocessing module which provides process-level semaphores, but I don't know how portable they are. Ciao ---- FB From breamoreboy at yahoo.co.uk Sun Mar 14 05:14:15 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Mar 2010 09:14:15 +0000 Subject: python to exe In-Reply-To: References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Mark Lawrence wrote: >> >> I'm certain that members of the Guinea Pig Club might have something >> to say on that one, see :- >> http://en.wikipedia.org/wiki/Guinea_Pig_Club >> > > You mean, something like: "That's not funny"? No, simply a statement. From breamoreboy at yahoo.co.uk Sun Mar 14 05:33:17 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Mar 2010 09:33:17 +0000 Subject: python to exe In-Reply-To: <4b9c3aa2$0$27822$c3e8da3@news.astraweb.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <4b9c3aa2$0$27822$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 14 Mar 2010 11:20:15 +1300, Gib Bogle wrote: > >> Mark Lawrence wrote: >>> I'm certain that members of the Guinea Pig Club might have something to >>> say on that one, see :- >>> http://en.wikipedia.org/wiki/Guinea_Pig_Club >>> >>> >> You mean, something like: "That's not funny"? > > Or possibly "That's hilarious!!!". Gallows humour is sometimes hard to > predict. > > > Thinking about it can be that's not funny or hilarious depending on context, which is rather difficult to give on this internet/webby thingy. From martin.hellwig at dcuktec.org Sun Mar 14 06:17:54 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 14 Mar 2010 10:17:54 +0000 Subject: xml-rpc In-Reply-To: References: Message-ID: On 03/14/10 08:14, ahmet erdinc yilmaz wrote: > Hello, > > Recenetly we are developing a senior project and decide to use xmlrpclib. > However I have some questions. In the documentation I could not find any > clue about > handling requests? Does the server handles each request in a separate > thread? Or is > there some queuing mechanism for client calls? Thanks in advance. > > > --erdinc How I usually tackle stuff like this: [martin at aspire8930 /usr/home/martin]$ python Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import SimpleXMLRPCServer >>> help(SimpleXMLRPCServer) CLASSES BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) SimpleXMLRPCRequestHandler SimpleXMLRPCDispatcher CGIXMLRPCRequestHandler SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) SocketServer.TCPServer(SocketServer.BaseServer) SimpleXMLRPCServer(SocketServer.TCPServer, SimpleXMLRPCDispatcher) Aah so it is based on SocketServer, lets have a look at that: >>> import SocketServer >>> help(SocketServer) Help on module SocketServer: There are five classes in an inheritance diagram, four of which represent synchronous servers of four types: +------------+ | BaseServer | +------------+ | v +-----------+ +------------------+ | TCPServer |------->| UnixStreamServer | +-----------+ +------------------+ | v +-----------+ +--------------------+ | UDPServer |------->| UnixDatagramServer | +-----------+ +--------------------+ So the base of all these servers is BaseServer, hmm somebody must have a laugh right now :-) Okay lets have a look at that then: >>> import BaseServer Traceback (most recent call last): File "", line 1, in ImportError: No module named BaseServer Hmmm okay, lets have a look at the SocketServer source itself then, but where is it? >>> SocketServer.__file__ '/usr/local/lib/python2.6/SocketServer.pyc' I bet that the non compiled file is in the same directory, let's have a look at it with less. >>> quit() [martin at aspire8930 /usr/home/martin]$ less /usr/local/lib/python2.6/SocketServer.py And there it says among other interesting stuff: # The distinction between handling, getting, processing and # finishing a request is fairly arbitrary. Remember: # # - handle_request() is the top-level call. It calls # select, get_request(), verify_request() and process_request() # - get_request() is different for stream or datagram sockets # - process_request() is the place that may fork a new process # or create a new thread to finish the request # - finish_request() instantiates the request handler class; # this constructor will handle the request all by itself def handle_request(self): """Handle one request, possibly blocking. Respects self.timeout. """ # Support people who used socket.settimeout() to escape # handle_request before self.timeout was available. timeout = self.socket.gettimeout() if timeout is None: timeout = self.timeout elif self.timeout is not None: timeout = min(timeout, self.timeout) fd_sets = select.select([self], [], [], timeout) if not fd_sets[0]: self.handle_timeout() return self._handle_request_noblock() def _handle_request_noblock(self): """Handle one request, without blocking. I assume that select.select has returned that the socket is readable before this function was called, so there should be no risk of blocking in get_request(). """ try: request, client_address = self.get_request() except socket.error: return if self.verify_request(request, client_address): try: self.process_request(request, client_address) except: self.handle_error(request, client_address) self.close_request(request) I leave the remaining parts of your question as an exercise :-) -- mph From hackingkk at gmail.com Sun Mar 14 06:32:30 2010 From: hackingkk at gmail.com (hackingKK) Date: Sun, 14 Mar 2010 16:02:30 +0530 Subject: xml-rpc In-Reply-To: References: Message-ID: <4B9CBB3E.3090902@gmail.com> Instead of using the library directly, isn't python-twisted a better choice? happy hacking. Krishnakant. On Sunday 14 March 2010 03:47 PM, Martin P. Hellwig wrote: > On 03/14/10 08:14, ahmet erdinc yilmaz wrote: >> Hello, >> >> Recenetly we are developing a senior project and decide to use >> xmlrpclib. >> However I have some questions. In the documentation I could not find any >> clue about >> handling requests? Does the server handles each request in a separate >> thread? Or is >> there some queuing mechanism for client calls? Thanks in advance. >> >> >> --erdinc > > How I usually tackle stuff like this: > [martin at aspire8930 /usr/home/martin]$ python > Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16) > [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. > >>> import SimpleXMLRPCServer > >>> help(SimpleXMLRPCServer) > > CLASSES > > BaseHTTPServer.BaseHTTPRequestHandler(SocketServer.StreamRequestHandler) > SimpleXMLRPCRequestHandler > SimpleXMLRPCDispatcher > CGIXMLRPCRequestHandler > SimpleXMLRPCServer(SocketServer.TCPServer, > SimpleXMLRPCDispatcher) > SocketServer.TCPServer(SocketServer.BaseServer) > SimpleXMLRPCServer(SocketServer.TCPServer, > SimpleXMLRPCDispatcher) > > Aah so it is based on SocketServer, lets have a look at that: > > >>> import SocketServer > >>> help(SocketServer) > Help on module SocketServer: > > > There are five classes in an inheritance diagram, four of which > represent > synchronous servers of four types: > > +------------+ > | BaseServer | > +------------+ > | > v > +-----------+ +------------------+ > | TCPServer |------->| UnixStreamServer | > +-----------+ +------------------+ > | > v > +-----------+ +--------------------+ > | UDPServer |------->| UnixDatagramServer | > +-----------+ +--------------------+ > > So the base of all these servers is BaseServer, hmm somebody must have > a laugh right now :-) > > Okay lets have a look at that then: > > >>> import BaseServer > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named BaseServer > > Hmmm okay, lets have a look at the SocketServer source itself then, > but where is it? > >>> SocketServer.__file__ > '/usr/local/lib/python2.6/SocketServer.pyc' > > I bet that the non compiled file is in the same directory, let's have > a look at it with less. > > >>> quit() > [martin at aspire8930 /usr/home/martin]$ less > /usr/local/lib/python2.6/SocketServer.py > > And there it says among other interesting stuff: > > # The distinction between handling, getting, processing and > # finishing a request is fairly arbitrary. Remember: > # > # - handle_request() is the top-level call. It calls > # select, get_request(), verify_request() and process_request() > # - get_request() is different for stream or datagram sockets > # - process_request() is the place that may fork a new process > # or create a new thread to finish the request > # - finish_request() instantiates the request handler class; > # this constructor will handle the request all by itself > > def handle_request(self): > """Handle one request, possibly blocking. > > Respects self.timeout. > """ > # Support people who used socket.settimeout() to escape > # handle_request before self.timeout was available. > timeout = self.socket.gettimeout() > if timeout is None: > timeout = self.timeout > elif self.timeout is not None: > timeout = min(timeout, self.timeout) > fd_sets = select.select([self], [], [], timeout) > if not fd_sets[0]: > self.handle_timeout() > return > self._handle_request_noblock() > > def _handle_request_noblock(self): > """Handle one request, without blocking. > > I assume that select.select has returned that the socket is > readable before this function was called, so there should be > no risk of blocking in get_request(). > """ > try: > request, client_address = self.get_request() > except socket.error: > return > if self.verify_request(request, client_address): > try: > self.process_request(request, client_address) > except: > self.handle_error(request, client_address) > self.close_request(request) > > > I leave the remaining parts of your question as an exercise :-) > From fetchinson at googlemail.com Sun Mar 14 06:49:08 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 14 Mar 2010 11:49:08 +0100 Subject: how to start a python script only once In-Reply-To: <4b9bdd61$0$22515$426a74cc@news.free.fr> References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: > I'd like to make sure, that a certain python program will only be run > once per host. (linux/windows) > > > so if the program is started a second time it should just terminate and > let the other one run. > > This does not have to be the fastest solution, but it should be reliable. > > > I have a few ideas, but wonder, which one is the most common > > > My ideas so far: > > pid file and file locking > -------------------------- > create a file like program.pid with the pid of the running program an > use file locking to avoid race connditions. > > However I currently don't know how to do file locking under windows > and I don't know how to do file lockng with python and linux. > I'll start googling. This is the variant I'm using frequently too and I'd recommend to you as well. Simple to implement and largely problem-free. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From martin.hellwig at dcuktec.org Sun Mar 14 06:50:21 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 14 Mar 2010 10:50:21 +0000 Subject: xml-rpc In-Reply-To: References: Message-ID: On 03/14/10 10:32, hackingKK wrote: > Instead of using the library directly, > isn't python-twisted a better choice? Why? -- mph From spamfresser at ch3ka.de Sun Mar 14 07:25:35 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 12:25:35 +0100 Subject: I passed a fizzbuzz test but failed at recursion. In-Reply-To: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> References: <2380120f-c273-4179-af80-ecc8954a6bd3@b7g2000yqd.googlegroups.com> Message-ID: Am 10.03.2010 16:55, schrieb Bill: > def fizzbuzz(num): > if num: > if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n' > elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n' > elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n' > else : return fizzbuzz(num-1) + ('%d \n' % num) > return '' > print fizzbuzz(100) While I do understand that this is not a Perl group, and this probably won't help the OP, I just could not resist: for i in range(1,101):print('','fizz')[not i%3]+('','buzz')[not i%5]or i > However, when I try to decipher the logic of the function I imagine > the solution reversed as "buzz fizz 98 97 ...etc... 4 fizz 2 1". No, the function creates the string from right to left. See: fizzbuzz(100) = fizzbuzz(99) + "buzz \n" = fizzbuzz(98) + "fizz \n" + "buzz \n" ... = fizzbuzz(1) + "2 \n" + "fizz \n" + "4 \n" + "buzz\n " + "fizz \n" + .... + "97 \n" + "98 \n" + "fizz \n" + "buzz \n" = fizzbuzz(0) + "1 \n" + "2 \n" + "fizz \n" + "4 \n" + "buzz\n " + "fizz \n" + .... + "97 \n" + "98 \n" + "fizz \n" + "buzz \n" = " " + "1 \n" + "2 \n" + "fizz \n" + "4 \n" + "buzz\n " + "fizz \n" + .... + "97 \n" + "98 \n" + "fizz \n" + "buzz \n" Regards, Michael From vicente.soler at gmail.com Sun Mar 14 07:34:53 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 14 Mar 2010 04:34:53 -0700 (PDT) Subject: "Breaking" the __main__ script Message-ID: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Hello, I am still learning python, thus developnig small scripts. Some of them consist only of the main module. While testing them (debugging) I sometimes want to stop the script at a certain point, with something like stop, break, end or something similar. What statement can I use? Vicente Soler From breamoreboy at yahoo.co.uk Sun Mar 14 07:53:22 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Mar 2010 11:53:22 +0000 Subject: "Breaking" the __main__ script In-Reply-To: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like stop, break, end or something similar. > > What statement can I use? > > Vicente Soler Something like import sys sys.exit()? HTH. Mark Lawrence From h.stenstrom at gmail.com Sun Mar 14 07:58:07 2010 From: h.stenstrom at gmail.com (=?ISO-8859-1?Q?Helge_Stenstr=F6m?=) Date: Sun, 14 Mar 2010 04:58:07 -0700 (PDT) Subject: Function that knows its argument's variable name Message-ID: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> I want to write function that prints a value of a variable, for debugging. Like: with myVariable = "parrot" otherVariable = "dead" probe(myVariable) probe(otherVariable) instead of the longer print "myVariable = ", myVariable print "otherVariable = ", otherVariable Is that even possible? The function would look like def probe(var): nameOfVar = someMagic(var) print nameOfVar, " = ", var but can someMagic(var) find the variable name? Is that possible? From spamfresser at ch3ka.de Sun Mar 14 08:20:03 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 13:20:03 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Am 14.03.2010 12:53, schrieb Mark Lawrence: > vsoler wrote: >> I sometimes want to stop the script at a certain point, >> with something like stop, break, end or something similar. >> What statement can I use? > Something like > import sys > sys.exit()? Or just "raise SystemExit", "raise SyntaxError" or any other Exception. But you won't have to: If you use IDLE, you can just set breakpoints in your code: enable the debugger in debug-debugger and set breakpoints via right click in your source file. Or you could use a real debugger, like pdb http://docs.python.org/library/pdb.html HTH, Michael From steve at holdenweb.com Sun Mar 14 08:36:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 08:36:55 -0400 Subject: building a dict In-Reply-To: <20100314020137.2bb95011@geekmail.INVALID> References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> <20100314020137.2bb95011@geekmail.INVALID> Message-ID: Andreas Waldenburger wrote: > On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler > wrote: > >> By the way, I suppose I am the OP. Since I am not an native English >> speaking person, I do not know what it stands for. Perhaps you can >> tell me. >> > Perhaps you can find out yourself: > > http://www.urbandictionary.com/define.php?term=op > Possibly so, and that's a useful site, but I hope you aren't suggesting that Vicente shouldn't have asked. It seemed like a perfectly acceptable question to me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Mar 14 09:03:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 09:03:53 -0400 Subject: Feeding differeent data types to a class instance? In-Reply-To: References: Message-ID: kuru wrote: > Hi > > I have couple classes in the form of > > class Vector: > def __init__(self,x,y,z): > self.x=x > self.y=y > self.z=z > > This works fine for me. However I want to be able to provide a list, > tuple as well as individual arguments like below > > myvec=Vector(1,2,3) > > This works well > > > However I also want to be able to do > > vect=[1,2,3] > > myvec=Vec(vect) > > I want this class to accept multiple data types but process them as > they are same when the classs deals with the instances. > > thanks > > With your existing class you can use Python's ability to transform a list or tuple into individual arguments using the * notation: >>> class Vector: ... def __init__(self,x,y,z): ... self.x=x ... self.y=y ... self.z=z ... >>> vl = [1, 2, 3] >>> v = Vector(*vl) >>> v.x 1 >>> v.y 2 >>> v.z 3 >>> Will this do? It seems much simpler than rewriting an already satisfactory class. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Mar 14 09:07:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 09:07:21 -0400 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Mark Lawrence wrote: > vsoler wrote: >> Hello, >> >> I am still learning python, thus developnig small scripts. >> >> Some of them consist only of the main module. While testing them >> (debugging) I sometimes want to stop the script at a certain point, >> with something like stop, break, end or something similar. >> >> What statement can I use? >> >> Vicente Soler > > Something like > import sys > sys.exit()? > > HTH. I think it's less than likely that it will help, since once sys.exit() is called the program is no longer available for inspection. The OP is probably looking for the "pdb" module in the standard library. The documentation is good enough to get you started. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From usenot at geekmail.INVALID Sun Mar 14 09:28:09 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sun, 14 Mar 2010 14:28:09 +0100 Subject: building a dict References: <83cdccc5-9f4d-40fe-93e5-49c0edae8385@g19g2000yqe.googlegroups.com> <3f56c242-7bf5-40c6-96d4-881d052db39a@o30g2000yqb.googlegroups.com> <289d7e7f-a068-487e-a918-17a39110d0f7@e1g2000yqh.googlegroups.com> <91def698-98ba-4d63-b647-c13467e2a8c0@k17g2000yqb.googlegroups.com> <0ed22def-8cb9-47ec-8df8-60439810819a@g10g2000yqh.googlegroups.com> <20100314020137.2bb95011@geekmail.INVALID> Message-ID: <20100314142809.5c456262@geekmail.INVALID> On Sun, 14 Mar 2010 08:36:55 -0400 Steve Holden wrote: > Andreas Waldenburger wrote: > > On Sat, 13 Mar 2010 13:42:12 -0800 (PST) vsoler > > wrote: > > > >> By the way, I suppose I am the OP. Since I am not an native English > >> speaking person, I do not know what it stands for. Perhaps you can > >> tell me. > >> > > Perhaps you can find out yourself: > > > > http://www.urbandictionary.com/define.php?term=op > > > Possibly so, and that's a useful site, but I hope you aren't > suggesting that Vicente shouldn't have asked. It seemed like a > perfectly acceptable question to me. > I was a bit trigger happy there, I admit. But with vocabulary questions like these, my first reflex is to ask the web rather than people, because it's usually quicker than Usenet (albeit often only by a minute or so). I somehow felt the need to bestow that bit of "wisdom" on the world. But yeah, the question is fine, of course. /W -- INVALID? DE! From darcy at druid.net Sun Mar 14 09:55:13 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 14 Mar 2010 09:55:13 -0400 Subject: NoSQL Movement? In-Reply-To: <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> Message-ID: <20100314095513.61b0fbaa.darcy@druid.net> On Sat, 13 Mar 2010 23:42:31 -0800 Jonathan Gardner wrote: > On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: > > "D'Arcy J.M. Cain" writes: > >> Just curious, what database were you using that wouldn't keep up with > >> you? ?I use PostgreSQL and would never consider going back to flat > >> files. > > > > Try making a file with a billion or so names and addresses, then > > compare the speed of inserting that many rows into a postgres table > > against the speed of copying the file. That's a straw man argument. Copying an already built database to another copy of the database won't be significantly longer than copying an already built file. In fact, it's the same operation. > Also consider how much work it is to partition data from flat files > versus PostgreSQL tables. Another straw man. I'm sure you can come up with many contrived examples to show one particular operation faster than another. Benchmark writers (bad ones) do it all the time. I'm saying that in normal, real world situations where you are collecting billions of data points and need to actually use the data that a properly designed database running on a good database engine will generally be better than using flat files. > >> The only thing I can think of that might make flat files faster is > >> that flat files are buffered whereas PG guarantees that your > >> information is written to disk before returning > > > > Don't forget all the shadow page operations and the index operations, > > and that a lot of these operations require reading as well as writing > > remote parts of the disk, so buffering doesn't help avoid every disk > > seek. Not sure what a "shadow page operation" is but index operations are only needed if you have to have fast access to read back the data. If it doesn't matter how long it takes to read the data back then don't index it. I have a hard time believing that anyone would want to save billions of data points and not care how fast they can read selected parts back or organize the data though. > Plus the fact that your other DB operations slow down under the load. Not with the database engines that I use. Sure, speed and load are connected whether you use databases or flat files but a proper database will scale up quite well. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From gatoygata2 at gmail.com Sun Mar 14 10:03:29 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 07:03:29 -0700 (PDT) Subject: "Breaking" the __main__ script References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: On 14 mar, 12:34, vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like ? ?stop, break, end ? or something similar. > > What statement can I use? > > Vicente Soler Hola Vicente, You need a debugger. A practical solution to start with is to use an IDE with an integrated debugger. Stani's Python Editor (SPE) is a lightweight IDE with pdb integrated (with style checker also). It is a very good ide for learning (simple and not cluttered) but also for medium size applications (it is very well designed). atb Joaquin From steve at holdenweb.com Sun Mar 14 10:16:43 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 10:16:43 -0400 Subject: NoSQL Movement? In-Reply-To: <20100314095513.61b0fbaa.darcy@druid.net> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> <20100314095513.61b0fbaa.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > On Sat, 13 Mar 2010 23:42:31 -0800 > Jonathan Gardner wrote: >> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: >>> "D'Arcy J.M. Cain" writes: >>>> Just curious, what database were you using that wouldn't keep up with >>>> you? I use PostgreSQL and would never consider going back to flat >>>> files. >>> Try making a file with a billion or so names and addresses, then >>> compare the speed of inserting that many rows into a postgres table >>> against the speed of copying the file. > > That's a straw man argument. Copying an already built database to > another copy of the database won't be significantly longer than copying > an already built file. In fact, it's the same operation. > >> Also consider how much work it is to partition data from flat files >> versus PostgreSQL tables. > > Another straw man. I'm sure you can come up with many contrived > examples to show one particular operation faster than another. > Benchmark writers (bad ones) do it all the time. I'm saying that in > normal, real world situations where you are collecting billions of data > points and need to actually use the data that a properly designed > database running on a good database engine will generally be better than > using flat files. > >>>> The only thing I can think of that might make flat files faster is >>>> that flat files are buffered whereas PG guarantees that your >>>> information is written to disk before returning >>> Don't forget all the shadow page operations and the index operations, >>> and that a lot of these operations require reading as well as writing >>> remote parts of the disk, so buffering doesn't help avoid every disk >>> seek. > > Not sure what a "shadow page operation" is but index operations are > only needed if you have to have fast access to read back the data. If > it doesn't matter how long it takes to read the data back then don't > index it. I have a hard time believing that anyone would want to save > billions of data points and not care how fast they can read selected > parts back or organize the data though. > >> Plus the fact that your other DB operations slow down under the load. > > Not with the database engines that I use. Sure, speed and load are > connected whether you use databases or flat files but a proper database > will scale up quite well. > A common complaint about large database loads taking a long time comes about because of trying to commit the whole change as a single transaction. Such an approach can indeed causes stresses on the database system, but aren't usually necessary. I don't know about PostgreSQL's capabilities in this area but I do know that Oracle (which claims to be all about performance, though in fact I believe PostgreSQL is its equal in many applications) allows you to switch off the various time-consuming features such as transaction logging in order to make bulk updates faster. I also question how many databases would actually find a need to store addresses for a sixth of the world's population, but this objection is made mostly for comic relief: I understand that tables of such a size are necessary sometimes. There was a talk at OSCON two years ago by someone who was using PostgreSQL to process 15 terabytes of medical data. I'm sure he'd have been interested in suggestions that flat files were the answer to his problem ... Another talk a couple of years before that discussed how PostgreSQL was superior to Oracle in handling a three-terabyte data warehouse (though it conceded Oracle's superiority in handling the production OLTP system on which the warehouse was based - but that's four years ago). http://images.omniti.net/omniti.com/~jesus/misc/BBPostgres.pdf Of course if you only need sequential access to the data then the relational approach may be overkill. I would never argue that relational is the best approach for all data and all applications, but it's often better than its less-informed critics realize. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From news1234 at free.fr Sun Mar 14 10:30:13 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 15:30:13 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4b9cf2f5$0$27865$426a34cc@news.free.fr> Hi Francesco, Francesco Bochicchio wrote: > On 13 Mar, 19:45, News123 wrote: >> Hi, >> >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> I have a few ideas, but wonder, which one is the most common >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. >> >> sqlite and locking >> -------------------- >> quite some time ago I used a mysql table and locking as an inter-host mutex. >> >> Perhaps sqlite would be good enough for an inter process mutex for >> processes on the same host, but I don't know it well enough. >> >> interprocess mutex >> -------------------- >> well I even don't know whether something like this exists on linux / windows >> >> Thanks in advanced for any tips >> >> N > > Apart from file, a portable solution would be to bind to an unused > porta and assume that finding the port busy means that your program is > already running on the port. Yes, this should work. I assume in this case the bind() function would handle the race condition. > > On recent python installations there is the multiprocessing module > which provides process-level semaphores, but I don't know how portable > they are. Yes, there are process level semaphores in multiprocesing, but if I understood well, they would either require a common parent process or one process, which were acting as a manager, but then the question would be how to make sure, that the manager process were started only once. ( bind port? ) From news1234 at free.fr Sun Mar 14 10:32:09 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 15:32:09 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4b9cf369$0$27865$426a34cc@news.free.fr> Hi Daniel, Daniel Fetchinson wrote: >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> >> I have a few ideas, but wonder, which one is the most common >> >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. > > This is the variant I'm using frequently too and I'd recommend to you as well. > Simple to implement and largely problem-free. OK, So I'll just have to look in a piece of code, that performs file locking for windows AND for linux and I should be fine. bye N From darcy at druid.net Sun Mar 14 10:48:10 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 14 Mar 2010 10:48:10 -0400 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> <20100314095513.61b0fbaa.darcy@druid.net> Message-ID: <20100314104810.adc0c61a.darcy@druid.net> On Sun, 14 Mar 2010 10:16:43 -0400 Steve Holden wrote: > A common complaint about large database loads taking a long time comes > about because of trying to commit the whole change as a single > transaction. Such an approach can indeed causes stresses on the database > system, but aren't usually necessary. True. > I don't know about PostgreSQL's capabilities in this area but I do know > that Oracle (which claims to be all about performance, though in fact I > believe PostgreSQL is its equal in many applications) allows you to > switch off the various time-consuming features such as transaction > logging in order to make bulk updates faster. Yes, PostgreSQL has a bulk loading option as well. It's usually useful when you are copying data from one database into another and need to do it quickly. > I also question how many databases would actually find a need to store > addresses for a sixth of the world's population, but this objection is > made mostly for comic relief: I understand that tables of such a size > are necessary sometimes. How about Microsoft storing it's user base? Oh wait, they only store registered users with legitimate copies. Never mind. > Of course if you only need sequential access to the data then the > relational approach may be overkill. I would never argue that relational > is the best approach for all data and all applications, but it's often > better than its less-informed critics realize. As a rule I find that in the real world the larger the dataset the more likely you need a proper database. For smaller datasets it doesn't matter so why not use a DB anyway and be prepared when that "throwaway" system suddenly becomes your company's core application. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. From news1234 at free.fr Sun Mar 14 10:52:06 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 15:52:06 +0100 Subject: NoSQL Movement? In-Reply-To: References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <4b90a1f8$0$1629$742ec2ed@news.sonic.net> <0d381135-730a-45e4-9225-9ba2a29b77fe@k2g2000pro.googlegroups.com> Message-ID: <4b9cf816$0$20651$426a74cc@news.free.fr> Hi DUncan, Duncan Booth wrote: > Xah Lee wrote: > >> For example, consider, if you are within world's top 100th user of >> database in terms of database size, such as Google, then it may be >> that the off-the-shelf tools may be limiting. But how many users >> really have such massive size of data? > > You've totally missed the point. It isn't the size of the data you have > today that matters, it's the size of data you could have in several years' > time. > > Maybe today you've got 10 users each with 10 megabytes of data, but you're > aspiring to become the next twitter/facebook or whatever. It's a bit late > as you approach 100 million users (and a petabyte of data) to discover that > your system isn't scalable: scalability needs to be built in from day one. any project/product has to adapt over time. Not using SQL just because your 20 user application with 100 data sets might grow into the worlds biggest database doesn't seem right to me. I strongly believe in not overengineering a product. For anything I do I use the most covnenient python library first. This allows me to have results quicky and to get feedback about the product ASAP. Lateron I switch to the more performant versions. bye N From python at bdurham.com Sun Mar 14 11:03:47 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 14 Mar 2010 11:03:47 -0400 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <1268579027.18252.1364740493@webmail.messagingengine.com> Michael, > Or you could use a real debugger, like pdb > http://docs.python.org/library/pdb.html Any reason you prefer PDB over WinPDB? http://winpdb.org/ Thanks, Malcolm From news1234 at free.fr Sun Mar 14 11:04:25 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 16:04:25 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4B9CFAF9.1070802@free.fr> Hi Daniel, One more question: Daniel Fetchinson wrote: >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> >> I have a few ideas, but wonder, which one is the most common >> >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. > > This is the variant I'm using frequently too and I'd recommend to you as well. > Simple to implement and largely problem-free. > How do you make sure, that pid which is stored in the pid file does really belong to the correct process and not just to any process, that has by coincidence the same pid? bye N From news1234 at free.fr Sun Mar 14 11:04:25 2010 From: news1234 at free.fr (News123) Date: Sun, 14 Mar 2010 16:04:25 +0100 Subject: how to start a python script only once In-Reply-To: References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: <4B9CFAF9.1070802@free.fr> Hi Daniel, One more question: Daniel Fetchinson wrote: >> I'd like to make sure, that a certain python program will only be run >> once per host. (linux/windows) >> >> >> so if the program is started a second time it should just terminate and >> let the other one run. >> >> This does not have to be the fastest solution, but it should be reliable. >> >> >> I have a few ideas, but wonder, which one is the most common >> >> >> My ideas so far: >> >> pid file and file locking >> -------------------------- >> create a file like program.pid with the pid of the running program an >> use file locking to avoid race connditions. >> >> However I currently don't know how to do file locking under windows >> and I don't know how to do file lockng with python and linux. >> I'll start googling. > > This is the variant I'm using frequently too and I'd recommend to you as well. > Simple to implement and largely problem-free. > How do you make sure, that pid which is stored in the pid file does really belong to the correct process and not just to any process, that has by coincidence the same pid? bye N From david at boddie.org.uk Sun Mar 14 11:14:27 2010 From: david at boddie.org.uk (David Boddie) Date: Sun, 14 Mar 2010 16:14:27 +0100 Subject: Some PyCon videos won't play References: Message-ID: On Saturday 13 March 2010 20:01, Terry Reedy wrote: > On 3/13/2010 11:23 AM, Lee Harr wrote: >> >> I am having a great time watching videos from PyCon. Thanks to >> everyone who presented, and to those who did such a great job >> putting the videos up at: http://pycon.blip.tv/ >> >> My trouble is that, although most of the videos play perfectly, >> there are a few that refuse to play at all. Like: [...] >> Is anyone else having trouble with these? > > Yes, 'spinner' spins indefinitely, while others load and play. You should still be able to get at the videos themselves by inspecting the page contents, looking for download links like this one: http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv In this case, it's an Ogg Theora video file, so you may want to use a player like VLC to view it: http://www.videolan.org/ David From wolfgang.lipp at gmail.com Sun Mar 14 11:57:36 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sun, 14 Mar 2010 08:57:36 -0700 (PDT) Subject: Is it possible to use re2 from Python? Message-ID: i just discovered http://code.google.com/p/re2, a promising library that uses a long-neglected way (Thompson NFA) to implement a regular expression engine that can be orders of magnitudes faster than the available engines of awk, Perl, or Python. so i downloaded the code and did the usual sudo make install thing. however, that action had seemingly done little more than adding /usr/ local/include/re2/re2.h to my system. there seemed to be some `*.a file in addition, but then what is it with this *.a extension? i would like to use re2 from Python (preferrably Python 3.1) and was excited to see files like make_unicode_groups.py in the distro (maybe just used during the build process?). those however were not deployed on my machine. how can i use re2 from Python? (this message appeared before under http://stackoverflow.com/questions/2439345/is-it-possible-to-use-re2-from-python and, even earlier, http://groups.google.com/group/re2-dev/t/59b78327ec3cca0a) From gherron at islandtraining.com Sun Mar 14 12:45:51 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 14 Mar 2010 09:45:51 -0700 Subject: Function that knows its argument's variable name In-Reply-To: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <4B9D12BF.70307@islandtraining.com> Helge Stenstr?m wrote: > I want to write function that prints a value of a variable, for > debugging. Like: > > with > > myVariable = "parrot" > otherVariable = "dead" > > probe(myVariable) > probe(otherVariable) > > instead of the longer > > print "myVariable = ", myVariable > print "otherVariable = ", otherVariable > > Is that even possible? > > The function would look like > > def probe(var): > nameOfVar = someMagic(var) > print nameOfVar, " = ", var > > but can someMagic(var) find the variable name? Is that possible? > That question really doesn't quite make sense. Consider all the ways such a function can be called: someMagic(42) someMagic(40+2) someMagic(f(123)) someMagic(*argTuple) someMagic(**kwDict) someMagic(array[42]) None of which have a variable name associated with the argument. Yet, the answer to your question is not quite absolutely "no". Python has lots of introspection capabilities, including, perhaps, getting at and parsing the original code to find the call. But there's nothing direct for what you want. Gary Herron From vicente.soler at gmail.com Sun Mar 14 13:17:48 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 14 Mar 2010 10:17:48 -0700 (PDT) Subject: iterator/generator Message-ID: I am working on a script that reads data from an excel workbook. The data is located in a named range whose first row contains the headers. It works!!! I find it superb that python is able to do such things!!! Now my questions. a. My ranges can in practice be quite big, and although I am happy with the speed I get, because I am learning python, I think I could do it still a bit better. I think that the line for i in matriz[1:]: could be improved with an iterator/generator, but I am not quite certain how I should proceed. b. the following lines could be improved by means of a defaultdict, that I know because of a previous post. However you may come up with some other ideas (this b. question is not my main concern, you may discard it if you find the post too long) if i[a] and not(i[a] in g) and i[b]: g[i[a]] = i[b] elif i[a] and (i[a] in g) and i[b]: g[i[a]] += i[b] Can anybody provide some hints? Thank you for your cooperation. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + import win32com.client as win32 def agrupar(matriz, c1, c2): a, b = matriz[0].index(c1), matriz[0].index(c2) g = {} for i in matriz[1:]: if i[a] and not(i[a] in g) and i[b]: g[i[a]] = i[b] elif i[a] and (i[a] in g) and i[b]: g[i[a]] += i[b] for k in g: print '%-50s %15d' % (k, g[k]) # Abrir fichero excel xl = win32.gencache.EnsureDispatch('Excel.Application') ##xl.Visible = True wb=xl.Workbooks.Open(r'C:\Users\Vicente\Documents\VS\Python \Presupuesto fijos 10YP 2011-2020 V0.xls') # Obtenci?n de datos datos=wb.Names('Datos').RefersToRange() print agrupar(datos, u'NomCC', u'BGT-09') # Cerrar libro de trabajo wb.Close() print From steve at holdenweb.com Sun Mar 14 13:49:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 13:49:47 -0400 Subject: iterator/generator In-Reply-To: References: Message-ID: vsoler wrote: > I am working on a script that reads data from an excel workbook. The > data is located in a named range whose first row contains the headers. > It works!!! I find it superb that python is able to do such things!!! > > Now my questions. > > a. My ranges can in practice be quite big, and although I am happy > with the speed I get, because I am learning python, I think I could do > it still a bit better. I think that the line for i in matriz[1:]: > could be improved with an iterator/generator, but I am not quite > certain how I should proceed. > > b. the following lines could be improved by means of a defaultdict, > that I know because of a previous post. However you may come up with > some other ideas (this b. question is not my main concern, you may > discard it if you find the post too long) > > if i[a] and not(i[a] in g) and i[b]: > g[i[a]] = i[b] > elif i[a] and (i[a] in g) and i[b]: > g[i[a]] += i[b] > > Can anybody provide some hints? Thank you for your cooperation. > > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > + > import win32com.client as win32 > > def agrupar(matriz, c1, c2): > a, b = matriz[0].index(c1), matriz[0].index(c2) > g = {} > for i in matriz[1:]: > if i[a] and not(i[a] in g) and i[b]: > g[i[a]] = i[b] > elif i[a] and (i[a] in g) and i[b]: > g[i[a]] += i[b] > for k in g: > print '%-50s %15d' % (k, g[k]) > > # Abrir fichero excel > xl = win32.gencache.EnsureDispatch('Excel.Application') > ##xl.Visible = True > wb=xl.Workbooks.Open(r'C:\Users\Vicente\Documents\VS\Python > \Presupuesto fijos 10YP 2011-2020 V0.xls') > > # Obtenci?n de datos > datos=wb.Names('Datos').RefersToRange() > print > agrupar(datos, u'NomCC', u'BGT-09') > > # Cerrar libro de trabajo > wb.Close() > print Before you go too far down this road (and congratulations, by the way, on having achieved what you already have!) you might like to consider the xlrd, xlwt and xlutils modules. Not only are they easy to use, they are also (I believe) cross-platform and do not require Excel to be loaded on the machine running the programs. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From maymunbeyin at gmail.com Sun Mar 14 14:16:50 2010 From: maymunbeyin at gmail.com (kuru) Date: Sun, 14 Mar 2010 11:16:50 -0700 (PDT) Subject: Feeding differeent data types to a class instance? References: Message-ID: <3189fde6-bd5e-4ee2-8a8e-41c55cf9f926@q23g2000yqd.googlegroups.com> Hi Thank you so much for all these great suggestions. I will have time today to try all these and see which one works best for me cheers From kevin.p.dwyer at gmail.com Sun Mar 14 14:18:45 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 14 Mar 2010 18:18:45 +0000 (UTC) Subject: Is it possible to use re2 from Python? References: Message-ID: On Sun, 14 Mar 2010 08:57:36 -0700, _wolf wrote: > > how can i use re2 from Python? > Hello Wolf, There's a recent thread about this on the python-dev list, Unfortunately it seems to suggest that there are no Python bindings at present. Cheers, Kev From CalWhoNOSPAM at roadrunner.com Sun Mar 14 14:20:55 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 14:20:55 -0400 Subject: What does Error: 'module' object is not callable Mean? Message-ID: The below code produces the error as indicated. But, in E:\Python26\Lib\site-packages\ffnet\tools I see: drawffnet.py drawffnet.pyc drawffnet.pyo Is that what it is looking for? I'm not sure what "not callable" means. Could it be referencing to "nn" rather than drawffnet? What should I do to investigate this? Thanks from ffnet import ffnet, mlgraph, readdata ...snipped working code here ... output, regression = nn.test(inputs2, targets2, iprint = 2) from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable pylab.show() except ImportError, e: print "Cannot make drawffnet plot." From tartley at tartley.com Sun Mar 14 14:24:07 2010 From: tartley at tartley.com (Jonathan Hartley) Date: Sun, 14 Mar 2010 11:24:07 -0700 (PDT) Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com><50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com><4B9B17B3.8000307@cnsp.com> <50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> Message-ID: <78b76065-5fcc-4d00-801c-bed3c8a3a1d7@x12g2000yqx.googlegroups.com> On Mar 13, 1:45?pm, pyt... at bdurham.com wrote: > Robin, > > > do you of an alternate compilter it doesn't work (py2exe) on my windows 7 box > > I can assure you that Py2exe does work on Windows 7 (my firm develops > commercial Python applications packaged using Py2exe running on Windows > 7), but it does take a bit of fiddling and some patience. Join the > py2exe newsgroup and post your problems there.https://lists.sourceforge.net/lists/listinfo/py2exe-users > > You may also want to google 'Gui2exe'. This is a free front-end to > Py2exe that you can use to generate your Py2exe setup.py scripts. Note > that Gui2exe requires wxPython (free) to run. > > Finally, make sure you are trying to compile 32-bit Python 2.x code. I > don't think py2exe supports Python 3.x or 64-bit versions of Python yet. > > > Nope; py2exe is pretty much the go-to tool for this. > > I hear great things about PyInstaller. The project is not dead - make > sure you use the latest version in the SVN. > > Search stackoverflow.com for positive feedback and tips on PyInstaller. > Its on our plate to take a good look this product 'one of these days'. > > Good luck! > > Malcolm I summarised a all the alternatives to py2exe I could find, here: http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Looking for those with a green 'y' in the 'Windows' row, you want to check out cx_freeze, PyInstaller, bbfreeze. Best of luck. From mehgcap at gmail.com Sun Mar 14 14:26:18 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 14:26:18 -0400 Subject: problem with variable and function Message-ID: Hi all, I have a file with a dictionary and a function. The dictionary holds the name of the function, and the function references the dictionary. If I put the dictionary first, the function is happy but the dictionary says the function is not defined. If I switch the two and put the function first, the function says the dictionary does not exist. Does anyone have an idea as to how I can make both of them happy? Thanks! Example: myVar={ 1:myFunc } def myFunc(): myOtherVar=myVar would result in myVar saying myFunc does not exist. Reverse it, though: def myFunc(): myOtherVar=myVar myVar={ 1:myFunc } and the function myFunc does not see the dictionary. I basically cannot win either way, and I need a way to resolve this. If you are curious, the dictionary holds function names and maps to a second dictionary of keystrokes, allowing me to map a keystroke to call a function. Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From python.list at tim.thechases.com Sun Mar 14 14:30:59 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Mar 2010 13:30:59 -0500 Subject: "Breaking" the __main__ script In-Reply-To: <1268579027.18252.1364740493@webmail.messagingengine.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <1268579027.18252.1364740493@webmail.messagingengine.com> Message-ID: <4B9D2B63.8030202@tim.thechases.com> python at bdurham.com wrote: >> Or you could use a real debugger, like pdb >> http://docs.python.org/library/pdb.html > > Any reason you prefer PDB over WinPDB? > http://winpdb.org/ I always count "in the standard library" as a big plus over any add-ons It's nice to know about alternatives such as WinPDB, but everybody that has python also has pdb already installed. -tkc From apt.shansen at gmail.com Sun Mar 14 14:33:34 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 14 Mar 2010 10:33:34 -0800 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: <7a9c25c21003141133x567949b2pf002904e8e22fdf5@mail.gmail.com> On Sun, Mar 14, 2010 at 10:20 AM, Cal Who wrote: > from ffnet.tools import drawffnet > import pylab > drawffnet(nn) #Error: 'module' object is not callable First and foremost, please please please: don't describe or paraphrase tracebacks when asking for help, show them. The whole thing. It doesn't -really- matter here, but it still applies. > That said, "drawffnet" is a module. You can't call -- put () on the end of -- a module. Its not a function. Its a file containing code. Perhaps you mean drawffnet.drawffnet()? --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Sun Mar 14 14:36:34 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 14 Mar 2010 14:36:34 -0400 Subject: python to exe In-Reply-To: <78b76065-5fcc-4d00-801c-bed3c8a3a1d7@x12g2000yqx.googlegroups.com> References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com><50697b2c1003122012q3c2530bt79666118bc639b87@mail.gmail.com><4B9B17B3.8000307@cnsp.com><50697b2c1003122047l5b8fa440lc6f1389b58d02df@mail.gmail.com> <78b76065-5fcc-4d00-801c-bed3c8a3a1d7@x12g2000yqx.googlegroups.com> Message-ID: <1268591794.10570.1364759429@webmail.messagingengine.com> Jonathan, > I summarised a all the alternatives to py2exe I could find, here: > http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html Really great work - thanks for sharing this with all of us!!! Regards, Malcolm From tack at urandom.ca Sun Mar 14 14:40:55 2010 From: tack at urandom.ca (Jason Tackaberry) Date: Sun, 14 Mar 2010 14:40:55 -0400 Subject: problem with variable and function In-Reply-To: References: Message-ID: <1268592055.14177.499.camel@willow> Hi Alex, On Sun, 2010-03-14 at 14:26 -0400, Alex Hall wrote: > Reverse it, though: > > def myFunc(): > myOtherVar=myVar > > myVar={ > 1:myFunc > } > > and the function myFunc does not see the dictionary. The code you provided works just fine (as one would expect). If you can provide an example doesn't work, we should be able to explain why and provide advice. Cheers, Jason. From tjreedy at udel.edu Sun Mar 14 14:41:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 14:41:22 -0400 Subject: Some PyCon videos won't play In-Reply-To: References: Message-ID: On 3/14/2010 11:14 AM, David Boddie wrote: > On Saturday 13 March 2010 20:01, Terry Reedy wrote: > >> On 3/13/2010 11:23 AM, Lee Harr wrote: >>> >>> I am having a great time watching videos from PyCon. Thanks to >>> everyone who presented, and to those who did such a great job >>> putting the videos up at: http://pycon.blip.tv/ >>> >>> My trouble is that, although most of the videos play perfectly, >>> there are a few that refuse to play at all. Like: > > [...] > >>> Is anyone else having trouble with these? >> >> Yes, 'spinner' spins indefinitely, while others load and play. > > You should still be able to get at the videos themselves by inspecting > the page contents, looking for download links like this one: > > http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv > > In this case, it's an Ogg Theora video file, so you may want to use > a player like VLC to view it: For people using html5 competant browsers, which, I believe, play .ogv 'in tha page', blip.tv just needs to update site to make html5 pages an alternative to using the flash player. From benjamin.kaplan at case.edu Sun Mar 14 14:41:25 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 14 Mar 2010 14:41:25 -0400 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: On Sun, Mar 14, 2010 at 2:20 PM, Cal Who wrote: > > The below code produces the error as indicated. But, in > E:\Python26\Lib\site-packages\ffnet\tools I see: > drawffnet.py > drawffnet.pyc > drawffnet.pyo > Is that what it is looking for? > > I'm not sure what "not callable" means. > Could it be referencing to "nn" rather than drawffnet? > What should I do to investigate this? > > Thanks > from ffnet import ffnet, mlgraph, readdata > > ...snipped working code here ... > > output, regression = nn.test(inputs2, targets2, iprint = 2) > > from ffnet.tools import drawffnet > import pylab > drawffnet(nn) #Error: 'module' object is not callable > pylab.show() > except ImportError, e: > print "Cannot make drawffnet plot." > > In Python, everything is an object. Certain objects, like functions, are callable. Other objects, like modules are not. You have a module mapped to the name "drawffnet". Python tries to call that object, but it isn't callable. If there is a function drawffnet inside the drawffnet module (I'm not familiar with the package, so I don't know), you need to call that specifically. drawffnet.drawffnet(nn) > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Mar 14 14:46:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Mar 2010 18:46:29 +0000 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: <4B9D2F05.1060101@mrabarnett.plus.com> Cal Who wrote: > The below code produces the error as indicated. But, in > E:\Python26\Lib\site-packages\ffnet\tools I see: > drawffnet.py > drawffnet.pyc > drawffnet.pyo > Is that what it is looking for? > > I'm not sure what "not callable" means. > Could it be referencing to "nn" rather than drawffnet? > What should I do to investigate this? > > Thanks > from ffnet import ffnet, mlgraph, readdata > > ...snipped working code here ... > > output, regression = nn.test(inputs2, targets2, iprint = 2) > > from ffnet.tools import drawffnet > import pylab > drawffnet(nn) #Error: 'module' object is not callable > pylab.show() > except ImportError, e: > print "Cannot make drawffnet plot." > You're importing the module 'drawffnet' and then trying to call it in: drawffnet(nn) but, as the traceback says, modules can't be called. I had a quick look at the documentation and it looks like you should be calling a function called 'drawffnet' that's defined in the module called 'drawffnet'. Try doing: from ffnet.tools.drawffnet import drawffnet instead. From tjreedy at udel.edu Sun Mar 14 14:47:45 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 14:47:45 -0400 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: On 3/14/2010 2:20 PM, Cal Who wrote: > > The below code produces the error as indicated. But, in > E:\Python26\Lib\site-packages\ffnet\tools I see: > drawffnet.py drawffnet is a module initialized from drawffnet.py (or either of the below) > drawffnet.pyc > drawffnet.pyo > Is that what it is looking for? > > I'm not sure what "not callable" means. > Could it be referencing to "nn" rather than drawffnet? > What should I do to investigate this? > > Thanks > from ffnet import ffnet, mlgraph, readdata > > ...snipped working code here ... > > output, regression = nn.test(inputs2, targets2, iprint = 2) > > from ffnet.tools import drawffnet here you create drawffnet from one of the files. > import pylab > drawffnet(nn) #Error: 'module' object is not callable This is an attempt to call the module as if it were a functions, which it is not. You probably want to call a function within the module. > pylab.show() > except ImportError, e: > print "Cannot make drawffnet plot." > > From clp2 at rebertia.com Sun Mar 14 14:48:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Mar 2010 10:48:18 -0800 Subject: problem with variable and function In-Reply-To: References: Message-ID: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: > Hi all, > I have a file with a dictionary and a function. The dictionary holds > the name of the function, and the function references the dictionary. > If I put the dictionary first, the function is happy but the > dictionary says the function is not defined. If I switch the two and > put the function first, the function says the dictionary does not > exist. Does anyone have an idea as to how I can make both of them > happy? > Reverse it, though: > > def myFunc(): > ?myOtherVar=myVar > > myVar={ > ?1:myFunc > } > > and the function myFunc does not see the dictionary. Please be more specific in what you mean by it not "seeing" the dictionary, because the "reversed" approach *should* work: $ python Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> def foo(): ... bar = baz ... print bar ... >>> baz = {1:foo} >>> foo() {1: } Cheers, Chris -- http://blog.rebertia.com From CalWho at roadrunner.com Sun Mar 14 14:57:02 2010 From: CalWho at roadrunner.com (Cal Who) Date: Sun, 14 Mar 2010 14:57:02 -0400 Subject: What does Error: 'module' object is not callable Mean? References: <7a9c25c21003141133x567949b2pf002904e8e22fdf5@mail.gmail.com> Message-ID: <379818115B06492999BA94573F720BCB@dad> ----- Original Message ----- From: Stephen Hansen To: Cal Who Cc: python-list at python.org Sent: Sunday, March 14, 2010 2:33 PM Subject: Re: What does Error: 'module' object is not callable Mean? On Sun, Mar 14, 2010 at 10:20 AM, Cal Who wrote: from ffnet.tools import drawffnet import pylab drawffnet(nn) #Error: 'module' object is not callable First and foremost, please please please: don't describe or paraphrase tracebacks when asking for help, show them. The whole thing. It doesn't -really- matter here, but it still applies. I'll keep that in mind but in this instance I simply cut and pasted the message. That said, "drawffnet" is a module. You can't call -- put () on the end of -- a module. Its not a function. Its a file containing code. Perhaps you mean drawffnet.drawffnet()? I copied that code from an example and what you suggested fixed it. Thanks. --S ------------------------------------------------------------------------------ No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2746 - Release Date: 03/14/10 03:33:00 -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sun Mar 14 15:10:32 2010 From: john at castleamber.com (John Bokma) Date: Sun, 14 Mar 2010 13:10:32 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> Message-ID: <87sk82zplj.fsf@castleamber.com> David Monaghan writes: > of Google. If they haven't used it, I don't really consider the gentle > reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle > soul to be on the internet at all; someone might say "Boo" to you at any > moment. Beware. I've no problem with lmgtfy. I *do* have a problem with hiding it behing a tinyurl. Why use 2 levels of obfuscating in a group that's about programming in a language that promotes clear coding? The message would have been the same if the OP had just copy pasted the Google link. But hey, that's way less "funny". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mehgcap at gmail.com Sun Mar 14 15:12:35 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 15:12:35 -0400 Subject: problem with variable and function In-Reply-To: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> References: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> Message-ID: Below is pasted the function which is looking for the "funcs" dictionary, as well as the dictionary. They appear in my py file in this order, yet I get an error in nextMode() that "global name 'funcs' is not defined". Oddly, the keys dictionary works fine; it is defined above the nextMode function. def nextMode(): global HOTKEYS global HOTKEY_ACTIONS global mode global modes global modeNum global modeNames global funcs #mode=mode+1 #check to make sure the newly selected mode is enabled tmp=0 while(tmp wrote: > On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: >> Hi all, >> I have a file with a dictionary and a function. The dictionary holds >> the name of the function, and the function references the dictionary. >> If I put the dictionary first, the function is happy but the >> dictionary says the function is not defined. If I switch the two and >> put the function first, the function says the dictionary does not >> exist. Does anyone have an idea as to how I can make both of them >> happy? > >> Reverse it, though: >> >> def myFunc(): >> ?myOtherVar=myVar >> >> myVar={ >> ?1:myFunc >> } >> >> and the function myFunc does not see the dictionary. > > Please be more specific in what you mean by it not "seeing" the > dictionary, because the "reversed" approach *should* work: > > $ python > Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) > [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> def foo(): > ... bar = baz > ... print bar > ... >>>> baz = {1:foo} >>>> foo() > {1: } > > Cheers, > Chris > -- > http://blog.rebertia.com > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From clp2 at rebertia.com Sun Mar 14 15:24:11 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Mar 2010 11:24:11 -0800 Subject: problem with variable and function In-Reply-To: References: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> Message-ID: <50697b2c1003141224o2b645404u30fbc80140eec6bc@mail.gmail.com> > On 3/14/10, Chris Rebert wrote: >> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: >>> Hi all, >>> I have a file with a dictionary and a function. The dictionary holds >>> the name of the function, and the function references the dictionary. >>> If I put the dictionary first, the function is happy but the >>> dictionary says the function is not defined. If I switch the two and >>> put the function first, the function says the dictionary does not >>> exist. Does anyone have an idea as to how I can make both of them >>> happy? >> >>> Reverse it, though: >>> >>> def myFunc(): >>> myOtherVar=myVar >>> >>> myVar={ >>> 1:myFunc >>> } >>> >>> and the function myFunc does not see the dictionary. >> >> Please be more specific in what you mean by it not "seeing" the >> dictionary, because the "reversed" approach *should* work: >> >> $ python >> Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) >> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> def foo(): >> ... bar = baz >> ... print bar >> ... >>>>> baz = {1:foo} >>>>> foo() >> {1: } On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall wrote: > Below is pasted the function which is looking for the "funcs" > dictionary, as well as the dictionary. They appear in my py file in > this order, yet I get an error in nextMode() that "global name 'funcs' > is not defined". Oddly, the keys dictionary works fine; it is defined > above the nextMode function. Please include the full exception Traceback. Also, please don't top-post in the future. > def nextMode(): > ?global HOTKEYS > ?global HOTKEY_ACTIONS > ?global mode You don't need a `global` declaration unless your function needs to rebind the global variable in question. So you can remove the next 4 global declarations; they're unnecessary. > ?global modes > ?global modeNum > ?global modeNames > ?global funcs > ?#mode=mode+1 > ?#check to make sure the newly selected mode is enabled > ?tmp=0 > ?while(tmp ?mode=(mode+1)%modeNum > ?if(sys.modules[modeNames[mode]].enabled=='True'): > ? break #break on the first enabled mode we find > ?#end if > ?tmp+=1 > ?#end while > ?HOTKEYS=keys[mode] > ?HOTKEY_ACTIONS=funcs[mode] > ?registerHotkeys() > ?speak("Now in "+str(modes[mode])+" mode.") > #end def > > #we now have the default mode to be used, but what if it is disabled? > if(sys.modules[modeNames[mode]].enabled=='False'): > ?nextMode() How is this call supposed to work when `funcs` (which nextMode() uses) hasn't been defined yet?! Cheers, Chris -- http://blog.rebertia.com From yoavglazner at gmail.com Sun Mar 14 15:30:43 2010 From: yoavglazner at gmail.com (Glazner) Date: Sun, 14 Mar 2010 12:30:43 -0700 (PDT) Subject: how to start a python script only once References: <4b9bdd61$0$22515$426a74cc@news.free.fr> Message-ID: On Mar 13, 8:45?pm, News123 wrote: > Hi, > > I'd like to make sure, that a certain python program will only be run > once per host. (linux/windows) > > so if the program is started a second time it should just terminate and > let the other one run. > > This does not have to be the fastest solution, but it should be reliable. > > I have a few ideas, but wonder, which one is the most common > > My ideas so far: > > pid file and file locking > -------------------------- > create a file like program.pid ?with the pid of the running program an > use file locking to avoid race connditions. > > However I currently don't know how to do file locking under windows > and I don't know how to do file lockng with python and linux. > I'll start googling. > > sqlite and locking > -------------------- > quite some time ago I used a mysql table and locking as an inter-host mutex. > > Perhaps sqlite would be good enough for an inter process mutex for > processes on the same host, but I don't know it well enough. > > interprocess mutex > -------------------- > well I even don't know whether something like this exists on linux / windows > > Thanks in advanced for any tips > > N I'll just open a port with a TCP socket, it is cross-platform and free from race conditions. From mehgcap at gmail.com Sun Mar 14 15:34:20 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 15:34:20 -0400 Subject: problem with variable and function In-Reply-To: <50697b2c1003141224o2b645404u30fbc80140eec6bc@mail.gmail.com> References: <50697b2c1003141148i1704ff81j38e052fc0539619f@mail.gmail.com> <50697b2c1003141224o2b645404u30fbc80140eec6bc@mail.gmail.com> Message-ID: >> #we now have the default mode to be used, but what if it is disabled? >> if(sys.modules[modeNames[mode]].enabled=='False'): >> nextMode() > >How is this call supposed to work when `funcs` (which nextMode() uses) >hasn't been defined yet?! That seems to have done it, thanks. Sorry about top-posting; inline posting is much harder to read when using a screen reader, as I do, so I am used to top-posting. On 3/14/10, Chris Rebert wrote: >> On 3/14/10, Chris Rebert wrote: >>> On Sun, Mar 14, 2010 at 10:26 AM, Alex Hall wrote: >>>> Hi all, >>>> I have a file with a dictionary and a function. The dictionary holds >>>> the name of the function, and the function references the dictionary. >>>> If I put the dictionary first, the function is happy but the >>>> dictionary says the function is not defined. If I switch the two and >>>> put the function first, the function says the dictionary does not >>>> exist. Does anyone have an idea as to how I can make both of them >>>> happy? >>> >>>> Reverse it, though: >>>> >>>> def myFunc(): >>>> myOtherVar=myVar >>>> >>>> myVar={ >>>> 1:myFunc >>>> } >>>> >>>> and the function myFunc does not see the dictionary. >>> >>> Please be more specific in what you mean by it not "seeing" the >>> dictionary, because the "reversed" approach *should* work: >>> >>> $ python >>> Python 2.6.4 (r264:75706, Feb 25 2010, 01:21:39) >>> [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> def foo(): >>> ... bar = baz >>> ... print bar >>> ... >>>>>> baz = {1:foo} >>>>>> foo() >>> {1: } > > On Sun, Mar 14, 2010 at 11:12 AM, Alex Hall wrote: >> Below is pasted the function which is looking for the "funcs" >> dictionary, as well as the dictionary. They appear in my py file in >> this order, yet I get an error in nextMode() that "global name 'funcs' >> is not defined". Oddly, the keys dictionary works fine; it is defined >> above the nextMode function. > > Please include the full exception Traceback. > Also, please don't top-post in the future. > >> def nextMode(): >> ?global HOTKEYS >> ?global HOTKEY_ACTIONS >> ?global mode > > You don't need a `global` declaration unless your function needs to > rebind the global variable in question. > So you can remove the next 4 global declarations; they're unnecessary. > >> ?global modes >> ?global modeNum >> ?global modeNames >> ?global funcs >> ?#mode=mode+1 >> ?#check to make sure the newly selected mode is enabled >> ?tmp=0 >> ?while(tmp> ?mode=(mode+1)%modeNum >> ?if(sys.modules[modeNames[mode]].enabled=='True'): >> ? break #break on the first enabled mode we find >> ?#end if >> ?tmp+=1 >> ?#end while >> ?HOTKEYS=keys[mode] >> ?HOTKEY_ACTIONS=funcs[mode] >> ?registerHotkeys() >> ?speak("Now in "+str(modes[mode])+" mode.") >> #end def >> >> #we now have the default mode to be used, but what if it is disabled? >> if(sys.modules[modeNames[mode]].enabled=='False'): >> ?nextMode() > > How is this call supposed to work when `funcs` (which nextMode() uses) > hasn't been defined yet?! > > Cheers, > Chris > -- > http://blog.rebertia.com > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From spamfresser at ch3ka.de Sun Mar 14 15:35:14 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 20:35:14 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Am 14.03.2010 16:03, schrieb python at bdurham.com: > Any reason you prefer PDB over WinPDB? > http://winpdb.org/ Yes. I don't have Windows except one one PC :P From sivamadana at gmail.com Sun Mar 14 16:01:26 2010 From: sivamadana at gmail.com (siva kumar) Date: Sun, 14 Mar 2010 13:01:26 -0700 (PDT) Subject: messages Message-ID: <0273e5a4-2fed-48bb-a7c9-fbd298cd87dd@b36g2000pri.googlegroups.com> For Good messages please visit http://messagezonehere.blogspot.com/2010/03/friendly-messages.html From monaghand.david at gmail.com Sun Mar 14 16:04:01 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Sun, 14 Mar 2010 20:04:01 +0000 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> Message-ID: On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma wrote: >David Monaghan writes: > >> of Google. If they haven't used it, I don't really consider the gentle >> reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle >> soul to be on the internet at all; someone might say "Boo" to you at any >> moment. Beware. Sorry. That last comment of mine was uncalled for. >I've no problem with lmgtfy. I *do* have a problem with hiding it behing >a tinyurl. Why use 2 levels of obfuscating in a group that's about >programming in a language that promotes clear coding? > >The message would have been the same if the OP had just copy pasted the >Google link. But hey, that's way less "funny". Good point, although one could argue the unhidden response is just rude, but the masking does make it genuinely funny. DaveM From python at bdurham.com Sun Mar 14 16:08:21 2010 From: python at bdurham.com (python at bdurham.com) Date: Sun, 14 Mar 2010 16:08:21 -0400 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <1268597301.21932.1364768439@webmail.messagingengine.com> >> Any reason you prefer PDB over WinPDB? >> http://winpdb.org/ > Yes. I don't have Windows except one one PC :P WinPDB runs on non-Windows platforms :) Malcolm From ryan at rfk.id.au Sun Mar 14 16:10:10 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 07:10:10 +1100 Subject: sqlite3 is sqlite 2? In-Reply-To: <4B99D5C4.8070100@shopzeus.com> References: <4B99D5C4.8070100@shopzeus.com> Message-ID: <1268597410.2846.5.camel@durian> On Fri, 2010-03-12 at 06:48 +0100, Laszlo Nagy wrote: > gandalf at ubuntu:~$ python > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > >>> sqlite3.version > '2.4.1' > > Is it possible to install a real sqlite version 3 somehow? I really need > it because I have to use savepoint/rollback to. That is only supported > from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu Karmic? I know > that is not a question about Python itself. That's the sqlite *bindings* version: >>> sqlite3.version '2.4.1' >>> sqlite3.sqlite_version '3.6.16' >>> So this is "pysqlite" version 2.4.1, which wraps sqlite version 3.6.16. Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From john at castleamber.com Sun Mar 14 16:11:18 2010 From: john at castleamber.com (John Bokma) Date: Sun, 14 Mar 2010 14:11:18 -0600 Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> Message-ID: <87fx42zms9.fsf@castleamber.com> David Monaghan writes: > On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma wrote: > >>David Monaghan writes: >> >>> of Google. If they haven't used it, I don't really consider the gentle >>> reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle >>> soul to be on the internet at all; someone might say "Boo" to you at any >>> moment. Beware. > > Sorry. That last comment of mine was uncalled for. Thanks. >>I've no problem with lmgtfy. I *do* have a problem with hiding it behing >>a tinyurl. Why use 2 levels of obfuscating in a group that's about >>programming in a language that promotes clear coding? >> >>The message would have been the same if the OP had just copy pasted the >>Google link. But hey, that's way less "funny". > > Good point, although one could argue the unhidden response is just rude, but > the masking does make it genuinely funny. One could argue, sure. But to me it's just the same as posting GFY (don't want to upset the tender soulds again with "the F-word". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From gatoygata2 at gmail.com Sun Mar 14 16:11:29 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 13:11:29 -0700 (PDT) Subject: "Breaking" the __main__ script References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <7608c2b5-c7e2-4002-aacd-b4a53c487e54@q23g2000yqd.googlegroups.com> On 14 mar, 20:35, Michael Rudolf wrote: > Am 14.03.2010 16:03, schrieb pyt... at bdurham.com: > > > Any reason you prefer PDB over WinPDB? > >http://winpdb.org/ > > Yes. I don't have Windows except one one PC :P WinPdb is crossplatform. Is build with From john at castleamber.com Sun Mar 14 16:14:32 2010 From: john at castleamber.com (John Bokma) Date: Sun, 14 Mar 2010 14:14:32 -0600 Subject: sqlite3 is sqlite 2? References: Message-ID: <87bpeqzmmv.fsf@castleamber.com> Laszlo Nagy writes: > gandalf at ubuntu:~$ python > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sqlite3 >>>> sqlite3.version > '2.4.1' > > Is it possible to install a real sqlite version 3 somehow? I really > need it because I have to use savepoint/rollback to. That is only > supported from sqlite 3.6.8. Is it enough if I upgrade to Ubuntu > Karmic? I know that is not a question about Python itself. > > But still, it is interesting that a module named "sqlite3" can > actually be used for something called "sqlite 2". You're mistaking the *module* version with the version of the database, unless I am mistaken. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From gatoygata2 at gmail.com Sun Mar 14 16:18:19 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 13:18:19 -0700 (PDT) Subject: "Breaking" the __main__ script References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <6e5a7393-1ec5-4b60-894b-8574be2fe010@30g2000yqi.googlegroups.com> On 14 mar, 20:35, Michael Rudolf wrote: > Am 14.03.2010 16:03, schrieb pyt... at bdurham.com: > > > Any reason you prefer PDB over WinPDB? > >http://winpdb.org/ > > Yes. I don't have Windows except one one PC :P Sorry, i hit the wrong key. Again: winpdb is crossplatform. It uses a wxwindows gui. Names are not really fortunate... I have installed the last winpdb 1.4.6 in SPE today. atb joaquin From spamfresser at ch3ka.de Sun Mar 14 16:32:30 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 14 Mar 2010 21:32:30 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: Am 14.03.2010 21:08, schrieb python at bdurham.com: >>> Any reason you prefer PDB over WinPDB? >>> http://winpdb.org/ >> Yes. I don't have Windows except one one PC :P > WinPDB runs on non-Windows platforms :) Uh, OK. Then the name mislead me ;) But yeah, I prefer a console based debugger. From guillermo.listas at googlemail.com Sun Mar 14 16:40:09 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 13:40:09 -0700 (PDT) Subject: Python unicode and Windows cmd.exe Message-ID: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Hi, I would appreciate if someone could point out what am I doing wrong here. Basically, I need to save a string containing non-ascii characters to a file encoded in utf-8. If I stay in python, everything seems to work fine, but the moment I try to read the file with another Windows program, everything goes to hell. So here's the script unicode2file.py: =================================================================== # encoding=utf-8 import codecs f = codecs.open("m.txt",mode="w", encoding="utf8") a = u"ma?ana" print repr(a) f.write(a) f.close() f = codecs.open("m.txt", mode="r", encoding="utf8") a = f.read() print repr(a) f.close() =================================================================== That gives the expected output, both calls to repr() yield the same result. But now, if I do type me.txt in cmd.exe, I get garbled characters instead of "?". I then open the file with my editor (Sublime Text), and I see "ma?ana" normally. I save (nothing to be saved, really), go back to the dos prompt, do type m.txt and I get again the same garbled characters. I then open the file m.txt with notepad, and I see "ma?ana" normally. I save (again, no actual modifications), go back to the dos prompt, do type m.txt and this time it works! I get "ma?ana". When notepad opens the file, the encoding is already UTF-8, so short of a UTF-8 bom being added to the file, I don't know what happens when I save the unmodified file. Also, I would think that the python script should save a valid utf-8 file in the first place... What's going on here? Regards, Guillermo From vlastimil.brom at gmail.com Sun Mar 14 16:49:56 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 14 Mar 2010 21:49:56 +0100 Subject: Is it possible to use re2 from Python? In-Reply-To: References: Message-ID: <9fdb569a1003141349u6f5eee8fk536cb48f139898c7@mail.gmail.com> 2010/3/14 _wolf : >... > i would like to use re2 from Python (preferrably Python 3.1) and was > excited to see files like make_unicode_groups.py in the distro (maybe > just used during the build process?). those however were not deployed > on my machine. >... > If you would need a re engine with features like unicode rangees, script, and character properties classes and many others, you may try the proposed implementation of the re library currently available in python issue tracker: http://bugs.python.org/issue2636 I am personally more than satisfied with this development version sofar, however, as some new feature like unlimited lookarounds etc. suggest, it is a classic backtracking engine (as opposed to re2, if you need this very implementation). hth vbr From steve at holdenweb.com Sun Mar 14 16:55:20 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Mar 2010 16:55:20 -0400 Subject: "Breaking" the __main__ script In-Reply-To: <1268597301.21932.1364768439@webmail.messagingengine.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <1268597301.21932.1364768439@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: >>> Any reason you prefer PDB over WinPDB? >>> http://winpdb.org/ > >> Yes. I don't have Windows except one one PC :P > > WinPDB runs on non-Windows platforms :) > One might reasonably argue that it has a pretty couter-intuitive name, then. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From CalWhoNOSPAM at roadrunner.com Sun Mar 14 16:58:54 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 16:58:54 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: Thanks for the replies. That fixed it but produced another problem. There are two plotting routines below. Either one will work without error. But the combo produces: The exception unknown software exception (0x40000015) occurred in the application at location 0x1e05b62a. in a dialog box and the following in the console Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what isa wrong? Second question: Is it common to group all the "from" statements at the top of the program or to put them by the relavent code as I have here? Thanks a lot try: #Or we can use the two commented statements #from ffnet.tools import drawffnet from ffnet.tools.drawffnet import drawffnet import pylab #drawffnet.drawffnet(nn) drawffnet(nn) pylab.show() except ImportError, e: print "Cannot make drawffnet plot.\n%s" % e ? ? # Plot adapted from # http://ffnet.sourceforge.net/examples/stock.html # Make plot if matplotlib is avialble try: from pylab import * plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() except ImportError, e: print "Cannot make plots. For plotting install matplotlib.\n%s" % e ? ? From CalWhoNOSPAM at roadrunner.com Sun Mar 14 17:00:37 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 17:00:37 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: "MRAB" wrote in message news:mailman.745.1268592389.23598.python-list at python.org... > Cal Who wrote: >> The below code produces the error as indicated. But, in >> E:\Python26\Lib\site-packages\ffnet\tools I see: >> drawffnet.py >> drawffnet.pyc >> drawffnet.pyo >> Is that what it is looking for? >> >> I'm not sure what "not callable" means. >> Could it be referencing to "nn" rather than drawffnet? >> What should I do to investigate this? >> >> Thanks >> from ffnet import ffnet, mlgraph, readdata >> >> ...snipped working code here ... >> >> output, regression = nn.test(inputs2, targets2, iprint = 2) >> >> from ffnet.tools import drawffnet >> import pylab >> drawffnet(nn) #Error: 'module' object is not callable >> pylab.show() >> except ImportError, e: >> print "Cannot make drawffnet plot." > You're importing the module 'drawffnet' and then trying to call it in: > > drawffnet(nn) > > but, as the traceback says, modules can't be called. > > I had a quick look at the documentation and it looks like you should be > calling a function called 'drawffnet' that's defined in the module > called 'drawffnet'. Try doing: > > from ffnet.tools.drawffnet import drawffnet > > instead. Thanks, Works great - please see my other post From CalWhoNOSPAM at roadrunner.com Sun Mar 14 17:01:46 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 17:01:46 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: "Terry Reedy" wrote in message news:mailman.746.1268592481.23598.python-list at python.org... > On 3/14/2010 2:20 PM, Cal Who wrote: >> >> The below code produces the error as indicated. But, in >> E:\Python26\Lib\site-packages\ffnet\tools I see: >> drawffnet.py > > drawffnet is a module initialized from drawffnet.py (or either of the > below) > >> drawffnet.pyc >> drawffnet.pyo >> Is that what it is looking for? >> >> I'm not sure what "not callable" means. >> Could it be referencing to "nn" rather than drawffnet? >> What should I do to investigate this? >> >> Thanks >> from ffnet import ffnet, mlgraph, readdata >> >> ...snipped working code here ... >> >> output, regression = nn.test(inputs2, targets2, iprint = 2) >> >> from ffnet.tools import drawffnet > > here you create drawffnet from one of the files. > >> import pylab >> drawffnet(nn) #Error: 'module' object is not callable > > This is an attempt to call the module as if it were a functions, which it > is not. You probably want to call a function within the module. Exactly. Thanks it works now. Please see my other post. > > >> pylab.show() >> except ImportError, e: >> print "Cannot make drawffnet plot." >> >> > > From ryan at rfk.id.au Sun Mar 14 17:04:18 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 08:04:18 +1100 Subject: sqlite savepoint problem (was: Re: sqlite3 is sqlite 2?) In-Reply-To: <4B99E358.4020507@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> Message-ID: <1268600658.2846.17.camel@durian> On Fri, 2010-03-12 at 07:46 +0100, Laszlo Nagy wrote: > > > >>> import sqlite3 > >>> conn = sqlite3.connect(':memory:') > >>> with conn: > ... conn.execute("BEGIN") > ... conn.execute("create table a ( i integer)") > ... conn.execute("insert into a values (1)") > ... conn.execute("savepoint sp1") > ... conn.execute("insert into a values(2)") > ... conn.execute("release sp1") > ... conn.execute("COMMIT") > ... > > > > > > Traceback (most recent call last): > File "", line 7, in > sqlite3.OperationalError: no such savepoint: sp1 > >>> > > The syntax is correct: http://www.sqlite.org/lang_savepoint.html > The savepoint was really created. > But I get this error, telling "no such savepoint". What is wrong here? > Maybe it has to do something with transaction isolation? :-s From memory you can't issue a "CREATE TABLE" statement inside a transaction, at least not at the default isolation level. Such a statement will automatically commit the current transaction. Doesn't help with your current problem but worth pointing out :-) When debugging strange transaction behaviour, I find it easiest to create the connection with isolation_level=None so that are no implicit transactions being created behind your back. Not sure why, but setting this makes your example work for me. Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nyamatongwe+thunder at gmail.com Sun Mar 14 17:05:59 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 14 Mar 2010 21:05:59 GMT Subject: Python unicode and Windows cmd.exe In-Reply-To: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: Guillermo: > I then open the file m.txt with notepad, and I see "ma?ana" normally. > I save (again, no actual modifications), go back to the dos prompt, do > type m.txt and this time it works! I get "ma?ana". When notepad opens > the file, the encoding is already UTF-8, so short of a UTF-8 bom being > added to the file, That is what happens: the file now starts with a BOM \xEB\xBB\xBF as you can see with a hex editor. > I don't know what happens when I save the > unmodified file. Also, I would think that the python script should > save a valid utf-8 file in the first place... Its just as valid UTF-8 without a BOM. People have different opinions on this but for compatibility, I think it is best to always start UTF-8 files with a BOM. Neil From clp2 at rebertia.com Sun Mar 14 17:17:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Mar 2010 13:17:55 -0800 Subject: What does Error: 'module' object is not callable Mean? In-Reply-To: References: Message-ID: <50697b2c1003141417q37a0c0dfga6ff3955eb0e42f1@mail.gmail.com> On Sun, Mar 14, 2010 at 12:58 PM, Cal Who wrote: > Second question: Is it common to group all the "from" statements at the top > of the program > or to put them by the relavent code as I have here? The former. Cheers, Chris -- http://blog.rebertia.com From tjreedy at udel.edu Sun Mar 14 17:19:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 17:19:33 -0400 Subject: Some PyCon videos won't play In-Reply-To: References: Message-ID: On 3/14/2010 2:41 PM, Terry Reedy wrote: > On 3/14/2010 11:14 AM, David Boddie wrote: >> You should still be able to get at the videos themselves by inspecting >> the page contents, looking for download links like this one: >> >> http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv >> >> >> In this case, it's an Ogg Theora video file, so you may want to use >> a player like VLC to view it: > > For people using html5 competant browsers, which, I believe, play .ogv > 'in tha page', blip.tv just needs to update site to make html5 pages an > alternative to using the flash player. Actually, for FF3.6, at least, the problem is already solved. I just click on the download button and FF recognizes .ogv as something it can play and it does, replacing the flash player. The FF player lacks a full-screen button, but that is rarely needed for the talks. tjr From cmpython at gmail.com Sun Mar 14 17:22:22 2010 From: cmpython at gmail.com (CM) Date: Sun, 14 Mar 2010 14:22:22 -0700 (PDT) Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> Message-ID: <806f8246-3b3e-4468-b0e4-3c3f032a6f49@z4g2000yqa.googlegroups.com> On Mar 14, 4:04?pm, David Monaghan wrote: > On Sun, 14 Mar 2010 13:10:32 -0600, John Bokma wrote: > >David Monaghan writes: > > >> of Google. If they haven't used it, I don't really consider the gentle > >> reminder that LMGTFY gives too harsh. If you do, you're too much of a gentle > >> soul to be on the internet at all; someone might say "Boo" to you at any > >> moment. Beware. > > Sorry. That last comment of mine was uncalled for. > > >I've no problem with lmgtfy. I *do* have a problem with hiding it behing > >a tinyurl. Why use 2 levels of obfuscating in a group that's about > >programming in a language that promotes clear coding? > > >The message would have been the same if the OP had just copy pasted the > >Google link. But hey, that's way less "funny". > > Good point, although one could argue the unhidden response is just rude, but > the masking does make it genuinely funny. > > DaveM I thought the point of LMGTFY was to humorously and innocuously get across the point that a lot of basic questions can be answered instantly, or just a few key terms and a mouse click away (i.e. "Was that so hard?") instead of having to write and post a message to a group and then wait for responses. In this sense, using LMGTFY *is* a memorable transmission of information beyond just the answer to the question. It is the meta-information of how to "teach a man to fish". If someone "LMGTFY'ed" me due to my asking a really Googleable question, I'd feel I deserved this gentle ribbing and would make a note to be more diligent in my searches before asking a forum. From guillermo.listas at googlemail.com Sun Mar 14 17:22:46 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 14:22:46 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> > ? ?That is what happens: the file now starts with a BOM \xEB\xBB\xBF as > you can see with a hex editor. Is this an enforced convention under Windows, then? My head's aching after so much pulling at my hair, but I have the feeling that the problem only arises when text travels through the dos console... Cheers, Guillermo From gatoygata2 at gmail.com Sun Mar 14 17:25:12 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Sun, 14 Mar 2010 14:25:12 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> Message-ID: <3193c95f-29c3-44e5-9ac9-23e00b3a33ff@m37g2000yqf.googlegroups.com> On 14 mar, 22:22, Guillermo wrote: > > ? ?That is what happens: the file now starts with a BOM \xEB\xBB\xBF as > > you can see with a hex editor. > > Is this an enforced convention under Windows, then? My head's aching > after so much pulling at my hair, but I have the feeling that the > problem only arises when text travels through the dos console... > > Cheers, > Guillermo search for BOM in wikipedia. There it talks about notepad behavior. ja From nyamatongwe+thunder at gmail.com Sun Mar 14 17:35:51 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 14 Mar 2010 21:35:51 GMT Subject: Python unicode and Windows cmd.exe In-Reply-To: <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> Message-ID: Guillermo: > Is this an enforced convention under Windows, then? My head's aching > after so much pulling at my hair, but I have the feeling that the > problem only arises when text travels through the dos console... The console is commonly using Code Page 437 which is most compatible with old DOS programs since it can display line drawing characters. You can change the code page to UTF-8 with chcp 65001 Now, "type m.txt" with the original BOM-less file and it should be OK. You may also need to change the console font to one that is Unicode compatible like Lucida Console. Neil From tjreedy at udel.edu Sun Mar 14 17:37:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 17:37:29 -0400 Subject: Python unicode and Windows cmd.exe In-Reply-To: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: On 3/14/2010 4:40 PM, Guillermo wrote: > Hi, > > I would appreciate if someone could point out what am I doing wrong > here. > > Basically, I need to save a string containing non-ascii characters to > a file encoded in utf-8. > > If I stay in python, everything seems to work fine, but the moment I > try to read the file with another Windows program, everything goes to > hell. > > So here's the script unicode2file.py: > =================================================================== > # encoding=utf-8 > import codecs > > f = codecs.open("m.txt",mode="w", encoding="utf8") > a = u"ma?ana" > print repr(a) > f.write(a) > f.close() > > f = codecs.open("m.txt", mode="r", encoding="utf8") > a = f.read() > print repr(a) > f.close() > =================================================================== > > That gives the expected output, both calls to repr() yield the same > result. > > But now, if I do type me.txt in cmd.exe, I get garbled characters > instead of "?". > > I then open the file with my editor (Sublime Text), and I see "ma?ana" > normally. I save (nothing to be saved, really), go back to the dos > prompt, do type m.txt and I get again the same garbled characters. > > I then open the file m.txt with notepad, and I see "ma?ana" normally. > I save (again, no actual modifications), go back to the dos prompt, do > type m.txt and this time it works! I get "ma?ana". When notepad opens > the file, the encoding is already UTF-8, so short of a UTF-8 bom being There is no such thing as a utf-8 'byte order mark'. The concept is an oxymoron. > added to the file, I don't know what happens when I save the > unmodified file. Also, I would think that the python script should > save a valid utf-8 file in the first place... Adding the byte that some call a 'utf-8 bom' makes the file an invalid utf-8 file. However, I suspect that notepad wrote the file in the system encoding, which can encode n with tilde and which cmd.exe does understand. If you started with a file with encoded cyrillic, arabic, hindi, and chinese characters (for instance), I suspect you would get a different result. tjr From wolfgang.lipp at gmail.com Sun Mar 14 17:40:07 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sun, 14 Mar 2010 14:40:07 -0700 (PDT) Subject: Is it possible to use re2 from Python? References: Message-ID: <827b3e77-6f2a-412f-bfc2-4b7c8747ddcb@g11g2000yqe.googlegroups.com> i am afraid that thread goes straight perpendicular to what re2 is supposed to be, or do. my suggestion for these folks would be to create a new, clean interface to stop the violence that comes with the Python ``re`` interface, and open the thing up so one can plug in ``re`` implementations as are needed. when i absolutely need a feature, i can always go to the slower machine; simpler regular expressions could be dealt with more efficiently. From wolfgang.lipp at gmail.com Sun Mar 14 17:40:34 2010 From: wolfgang.lipp at gmail.com (_wolf) Date: Sun, 14 Mar 2010 14:40:34 -0700 (PDT) Subject: Is it possible to use re2 from Python? References: Message-ID: <0540f7d0-95f6-4b38-900d-dc25958ff232@g26g2000yqn.googlegroups.com> > There's a recent thread about this on the python-dev list, pointers? i searched but didn?t find anything. From guillermo.listas at googlemail.com Sun Mar 14 17:53:11 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 14:53:11 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> Message-ID: <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> > ? ?The console is commonly using Code Page 437 which is most compatible > with old DOS programs since it can display line drawing characters. You > can change the code page to UTF-8 with > chcp 65001 That's another issue in my actual script. A twofold problem, actually: 1) For me chcp gives 850 and I'm relying on that to decode the bytes I get back from the console. I suppose this is bound to fail because another Windows installation might have a different default codepage. 2) My script gets output from a Popen call (to execute a Powershell script [new Windows shell language] from Python; it does make sense!). I suppose changing the Windows codepage for a single Popen call isn't straightforward/possible? Right now, I only get the desired result if I decode the output from Popen as "cp850". From ryan at rfk.id.au Sun Mar 14 18:13:51 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 09:13:51 +1100 Subject: sqlite savepoint problem In-Reply-To: <4B99F1D1.2070202@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> Message-ID: <1268604831.2846.23.camel@durian> On Fri, 2010-03-12 at 08:48 +0100, Laszlo Nagy wrote: > > > > I'm now confused. Also, I could not find anything about these > > isolation levels on the sqlite website. The only think I could find is > > "PRAGMA read_uncommited". If that is the same as setting > > isolation_level to None, then I don't want it. > Yes, it is. Here is a test: No it isn't. The "magic" behind isolation_level is a creation of the python sqlite bindings. You can probably tell that I'm not a fan of it. > import os > import sqlite3 > import threading > import time > > FPATH = '/tmp/test.sqlite' > if os.path.isfile(FPATH): > os.unlink(FPATH) > > def getconn(): > global FPATH > conn = sqlite3.connect(FPATH) > conn.isolation_level = None > return conn > > class Thr1(threading.Thread): > def run(self): > conn = getconn() > print "Thr1: Inserting 0,1,2,3,4,5" > with conn: > for i in range(6): > conn.execute("insert into a values (?)",[i]) > print "Thr1: Commited" > with conn: > print "Thr1: Selecting all rows:" > for row in conn.execute("select * from a"): > print row > print "Thr1: Wait some..." > time.sleep(3) > print "Thr1: Selecting again, in the same transaction" > for row in conn.execute("select * from a"): > print row > > > class Thr2(threading.Thread): > def run(self): > conn = getconn() > with conn: > print "Thr2: deleting all rows from a" > conn.execute("delete from a") > print "Thr2: Now we wait some BEFORE commiting changes." > time.sleep(3) > print "Thr2: Will roll back!" > raise Exception > > > def main(): > with getconn() as conn: > conn.execute("create table a ( i integer ) ") > thr1 = Thr1() > thr1.start() > time.sleep(1) > thr1 = Thr2() > thr1.start() > > main() > > > And the test result: > > Thr1: Inserting 0,1,2,3,4,5 > Thr1: Commited > Thr1: Selecting all rows: > (0,) > (1,) > (2,) > (3,) > (4,) > (5,) > Thr1: Wait some... > Thr2: deleting all rows from a > Thr2: Now we wait some BEFORE commiting changes. > Thr1: Selecting again, in the same transaction > Thr2: Will roll back! > Exception in thread Thread-2: > Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner > self.run() > File "test.py", line 44, in run > raise Exception > Exception > > > It means that setting isolation_level to None will really allow > uncommited changes to be read by other transactions! This is sad, and of > course this is something that I do not want. No it doesn't. The problem is that using a connection as a context manager doesn't do what you think. It does *not* start a new transaction on __enter__ and commit it on __exit__. As far as I can tell it does nothing on __enter__ and calls con.commit() or con.rollback() on exit. With isolation_level=None, these are no-ops. If you create your own connection wrapper that explicitly creates and commits transactions, you example will work fine with isolation_level=None. Here's the relevant changes: class MyConn(sqlite3.Connection): def __enter__(self): self.execute("BEGIN") return self def __exit__(self,exc_type,exc_info,traceback): if exc_type is None: self.execute("COMMIT") else: self.execute("ROLLBACK") def getconn(): global FPATH conn = sqlite3.connect(FPATH,factory=MyConn) conn.isolation_level = None return conn Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nyamatongwe+thunder at gmail.com Sun Mar 14 18:15:41 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 14 Mar 2010 22:15:41 GMT Subject: Python unicode and Windows cmd.exe In-Reply-To: <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> Message-ID: Guillermo: > 2) My script gets output from a Popen call (to execute a Powershell > script [new Windows shell language] from Python; it does make sense!). > I suppose changing the Windows codepage for a single Popen call isn't > straightforward/possible? You could try SetConsoleOutputCP and SetConsoleCP. Neil From guillermo.listas at googlemail.com Sun Mar 14 18:21:11 2010 From: guillermo.listas at googlemail.com (Guillermo) Date: Sun, 14 Mar 2010 15:21:11 -0700 (PDT) Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> <4de2d54b-ecaa-44b0-973b-10138d42562c@r1g2000yqj.googlegroups.com> <82aa56e1-8000-40bd-96b0-859391dab2e1@q23g2000yqd.googlegroups.com> Message-ID: <7f81925a-01f3-4d69-b67e-725bd176e440@z4g2000yqa.googlegroups.com> > 2) My script gets output from a Popen call (to execute a Powershell > script [new Windows shell language] from Python; it does make sense!). > I suppose changing the Windows codepage for a single Popen call isn't > straightforward/possible? Nevermind. I'm able to change Windows' codepage to 65001 from within the Powershell script and I get back a string encoded in UTF-8 with BOM, so problem solved! Thanks for the help, Guillermo From CalWhoNOSPAM at roadrunner.com Sun Mar 14 18:49:48 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 18:49:48 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: I cleaned up the code by moving all the imports to the top. There are two plotting routines shown below. Either one will work without error. But when I include both, running produces: The exception unknown software exception (0x40000015) occurred in the application at location 0x1e05b62a. In a dialog box and the following in the console: Fatal Python error: PyEval_RestoreThread: NULL tstate This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Do you see what is wrong? Thanks a lot from pylab import plot, legend, title, grid, show, xlabel, ylabel ...snip.... #FIRST PLOT plot( targets2, 'b--' ) plot( output, 'k-' ) legend(('target', 'output')) xlabel('pattern'); ylabel('benign or malignant') title('Outputs vs. target of trained network.') grid(True) show() #SECOND PLOT drawffnet(nn) show() From missive at hotmail.com Sun Mar 14 19:06:19 2010 From: missive at hotmail.com (Lee Harr) Date: Mon, 15 Mar 2010 03:36:19 +0430 Subject: [ANNC] pynguin-0.4 (python turtle graphics application) Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release continues adding basic functionality and ??? refining the interface. If you are interested, please ??? take a look and let me know what you think. Pynguin is tested with Python 2.6.4 and uses PyQt (4.6) ??? for its GUI elements. Pynguin is released under GPLv3. Changes in pynguin-0.4: ??? - improved document switcher ??? - added easy 'random' color access ??? - added new commands ??????? - onscreen ??????? - onclick ??????? - stamp ??????? - viewcoords ??? - winding fill now default ??????? - added method to switch between winding/oddeven fill ??? - show file name in window header ??? - more examples ??? - added default values for examples that take parameters ??? - fixed star example for even number of sides ??? - fixed crash when changing to alternate view image ??? - fixed problem running code with blank lines ??? - fixed problem with ctrl key getting stuck on ??? - added bug report option in Help menu ??? - allow keypad Enter same as Return ??? - factored in to multiple files Changes in pynguin-0.3: ??? - added new commands ??????? - goto ??????? - turnto ??????? - lineto ??????? - distance ??????? - toward ??????? - write ??? - added more examples ??? - fixed problem when changing speed while code is running ??? - editor auto-indent improvement _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969 From ryan at rfk.id.au Sun Mar 14 19:16:19 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 10:16:19 +1100 Subject: sqlite savepoint problem In-Reply-To: <4B99EE05.8060505@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> Message-ID: <1268608579.2846.34.camel@durian> On Fri, 2010-03-12 at 08:32 +0100, Laszlo Nagy wrote: > > From memory you can't issue a "CREATE TABLE" statement inside a > > transaction, at least not at the default isolation level. Such a > > statement will automatically commit the current transaction. Doesn't > > help with your current problem but worth pointing out :-) > > > Thank you. I'll keep in mind. > > When debugging strange transaction behaviour, I find it easiest to > > create the connection with isolation_level=None so that are no implicit > > transactions being created behind your back. Not sure why, but setting > > this makes your example work for me. > > > Yes, same for me. But setting it to None means auto commit mode! See here: > > http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions > > > But it does not work that way. Look at this example > > import sqlite3 > > conn = sqlite3.connect(':memory:') > conn.isolation_level = None > with conn: > conn.execute("create table a ( i integer ) ") > > with conn: > conn.execute("insert into a values (1)") > conn.execute("SAVEPOINT sp1") > conn.execute("insert into a values (2)") > conn.execute("SAVEPOINT sp2") > conn.execute("insert into a values (3)") > conn.execute("ROLLBACK TO sp2") > conn.execute("insert into a values (4)") > conn.execute("RELEASE sp1") > > with conn: > for row in conn.execute("select * from a"): > print row > > > It prints: > > (1,) > (2,) > (4,) > > So everything is working. Nothing is auto commited. But if I change it > to "DEFERRED" or "IMMEDIATE" or "EXCLUSIVE" then it won't work. Why? I have a theory, based on a quick perusal of the sqlite3 bindings source. The bindings think that "SAVEPOINT sp1" is a "non-DML, non-query" statement. So when isolation_level is something other than None, this statement implicitly commits the current transaction and throws away your savepoints! Annotating your example: # entering this context actually does nothing with conn: # a transaction is magically created before this statement conn.execute("insert into a values (1)") # and is implicitly committed before this statement conn.execute("SAVEPOINT sp1") # a new transaction is magically created conn.execute("insert into a values (2)") # and committed, discarding the first savepoint. conn.execute("SAVEPOINT sp2") # a new transaction is magically created conn.execute("insert into a values (3)") # and committed, discarding the very savepoint we are trying to use. conn.execute("ROLLBACK TO sp2") conn.execute("insert into a values (4)") conn.execute("RELEASE sp1") In your previous multi-threaded example, try adding a "SAVEPOINT sp1" statement after deleting the rows in Thread2. You'll see that the delete is immediately committed and the rows cannot be read back by Thread1. (modified version attached for convenience). Cheers, Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: test_savepoint_commit.py Type: text/x-python Size: 1818 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From steve at REMOVE-THIS-cybersource.com.au Sun Mar 14 19:18:28 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Mar 2010 23:18:28 GMT Subject: python to exe References: <68d965b4-3039-4bd1-a75f-353903e6218b@g28g2000yqh.googlegroups.com> <87bpes6e4l.fsf@castleamber.com> <4b9b3513$0$27822$c3e8da3@news.astraweb.com> <87fx443vgo.fsf@castleamber.com> <87sk82zplj.fsf@castleamber.com> <87fx42zms9.fsf@castleamber.com> Message-ID: <4b9d6ec4$0$27822$c3e8da3@news.astraweb.com> On Sun, 14 Mar 2010 14:11:18 -0600, John Bokma wrote: > One could argue, sure. But to me it's just the same as posting GFY > (don't want to upset the tender soulds again with "the F-word". Are you *still* going on about this thing? Sheesh. You've made your point. You don't think posting links to Let Me Google That For You is friendly; you think that "hiding" those links behind tinyurl is downright hostile; and you think that heaping abuse and obscenities on the person who posted the link is acceptable behaviour. You've made it abundantly clear that your concern about keeping this group friendly only applies to others, not to you. Can we move on now? -- Steven From CalWhoNOSPAM at roadrunner.com Sun Mar 14 19:37:00 2010 From: CalWhoNOSPAM at roadrunner.com ( Cal Who) Date: Sun, 14 Mar 2010 19:37:00 -0400 Subject: What does Error: 'module' object is not callable Mean? References: Message-ID: I found it. Had to use "figure" to create a new figure! " Cal Who" wrote in message news:hnjp6f$l4$1 at news.eternal-september.org... >I cleaned up the code by moving all the imports to the top. > There are two plotting routines shown below. > Either one will work without error. > But when I include both, running produces: > The exception unknown software exception (0x40000015) occurred in the > application at location 0x1e05b62a. > In a dialog box and the following in the console: > Fatal Python error: PyEval_RestoreThread: NULL tstate > This application has requested the Runtime to terminate it in an unusual > way. > Please contact the application's support team for more information. > > Do you see what is wrong? > > Thanks a lot > > from pylab import plot, legend, title, grid, show, xlabel, ylabel > ...snip.... > > #FIRST PLOT > plot( targets2, 'b--' ) > plot( output, 'k-' ) > legend(('target', 'output')) > xlabel('pattern'); ylabel('benign or malignant') > title('Outputs vs. target of trained network.') > grid(True) > show() > > #SECOND PLOT > drawffnet(nn) > show() > From tjreedy at udel.edu Sun Mar 14 19:39:46 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Mar 2010 19:39:46 -0400 Subject: Understanding the CPython dict implementation Message-ID: I found this PyCon2010 presentation to be excellent: The Mighty Dictionary, Branden Craig Rhodes, 30 min. http://pycon.blip.tv/file/3264041/ Even knowing Python for over a decade, I learned a few things. Terry Jan Reedy From metolone+gmane at gmail.com Sun Mar 14 20:02:15 2010 From: metolone+gmane at gmail.com (Mark Tolonen) Date: Sun, 14 Mar 2010 17:02:15 -0700 Subject: Python unicode and Windows cmd.exe References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: "Terry Reedy" wrote in message news:hnjkuo$n16$1 at dough.gmane.org... On 3/14/2010 4:40 PM, Guillermo wrote: > Adding the byte that some call a 'utf-8 bom' makes the file an invalid > utf-8 file. Not true. From http://unicode.org/faq/utf_bom.html: Q: When a BOM is used, is it only in 16-bit Unicode text? A: No, a BOM can be used as a signature no matter how the Unicode text is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising the BOM will be whatever the Unicode character FEFF is converted into by that transformation format. In that form, the BOM serves to indicate both that it is a Unicode file, and which of the formats it is in. Examples: BytesEncoding Form 00 00 FE FF UTF-32, big-endian FF FE 00 00 UTF-32, little-endian FE FF UTF-16, big-endian FF FE UTF-16, little-endian EF BB BF UTF-8 -Mark From alfps at start.no Sun Mar 14 20:37:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 01:37:04 +0100 Subject: Python unicode and Windows cmd.exe In-Reply-To: References: <60eec6cf-b62f-4b7e-b461-9f537d62bff5@m37g2000yqf.googlegroups.com> Message-ID: * Mark Tolonen: > > "Terry Reedy" wrote in message > news:hnjkuo$n16$1 at dough.gmane.org... > On 3/14/2010 4:40 PM, Guillermo wrote: >> Adding the byte that some call a 'utf-8 bom' makes the file an invalid >> utf-8 file. > > Not true. From http://unicode.org/faq/utf_bom.html: > > Q: When a BOM is used, is it only in 16-bit Unicode text? > A: No, a BOM can be used as a signature no matter how the Unicode text > is transformed: UTF-16, UTF-8, UTF-7, etc. The exact bytes comprising > the BOM will be whatever the Unicode character FEFF is converted into by > that transformation format. In that form, the BOM serves to indicate > both that it is a Unicode file, and which of the formats it is in. > Examples: > BytesEncoding Form > 00 00 FE FF UTF-32, big-endian > FF FE 00 00 UTF-32, little-endian > FE FF UTF-16, big-endian > FF FE UTF-16, little-endian > EF BB BF UTF-8 Well, technically true, and Terry was wrong about "There is no such thing as a utf-8 'byte order mark'. The concept is an oxymoron.". It's true that as a descriptive term "byte order mark" is an oxymoron for UTF-8. But in this particular context it's not a descriptive term, and it's not only technically allowed, as you point out, but sometimes required. However, some tools are unable to process UTF-8 files with BOM. The most annoying example is the GCC compiler suite, in particular g++, which in its Windows MinGW manifestation insists on UTF-8 source code without BOM, while Microsoft's compiler needs the BOM to recognize the file as UTF-8 -- the only way I found to satisfy both compilers, apart from a restriction to ASCII or perhaps Windows ANSI with wide character literals restricted to ASCII (exploiting a bug in g++ that lets it handle narrow character literals with non-ASCII chars) is to preprocess the source code. But that's not a general solution since the g++ preprocessor, via another bug, accepts some constructs (which then compile nicely) which the compiler doesn't accept when explicit preprocessing isn't used. So it's a mess. Cheers, - Alf From pmaupin at gmail.com Sun Mar 14 22:07:41 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 14 Mar 2010 19:07:41 -0700 (PDT) Subject: iterator/generator References: Message-ID: First of all, as Steve Holden mentioned, do look at xlrd. It's awesome. Second, for your (a) question, if you want an iterator, that's quite easy: matriz = iter(matriz) matriz.next() # Discard the first one for i in matriz: This technique works really well, especially if you have sub-loops. Then, if you use a defaultdict which uses a list for a constructor for i in matriz: if i[a] and i[b]: g[i[a]].append(i[b]) HTH, Pat From timr at probo.com Sun Mar 14 22:14:56 2010 From: timr at probo.com (Tim Roberts) Date: Sun, 14 Mar 2010 19:14:56 -0700 Subject: result of os.times() is different with 'time' command Options References: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> Message-ID: hiral wrote: >... >Output: >real 0.0m0.0100000002421s >user 0.0m0.0s >sys 0.0m0.0s > > >Command: >$ time ls > >Output: >real 0m0.007s >user 0m0.000s >sys 0m0.000s > > >Is this the intended behaviour? What is it that you are wondering about? The formatting difference is due to your code. The difference between 10 milliseconds and 7 milliseconds could be due to any number of things. First, you have the overhead of Python involved in your measurements. Second, you have the variability of memory caching and disk caching. Your Python code causes /bin/ls to be loaded into memory, and it's probably still in a file cache when you run the second command. You can't really do an analysis like this with a task that only takes a few milliseconds. There are too many variables. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mehgcap at gmail.com Sun Mar 14 23:43:35 2010 From: mehgcap at gmail.com (Alex Hall) Date: Sun, 14 Mar 2010 23:43:35 -0400 Subject: dll in project? Message-ID: Hi all, I have a dll I am trying to use, but I get a Windows error 126, "the specified module could not be found". Here is the code segment: nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") I have the specified dll file in the same directory as the file trying to use said dll, and this is the only reference I make to the dll. Do I need to register it somehow? If so, does this need to be done once, or each time the application runs? If I need to register it, how would I do so? Thanks! -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From nagle at animats.com Mon Mar 15 00:05:36 2010 From: nagle at animats.com (John Nagle) Date: Sun, 14 Mar 2010 21:05:36 -0700 Subject: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ? In-Reply-To: References: Message-ID: <4b9dad7c$0$1639$742ec2ed@news.sonic.net> The HTMLTemplate module is useful for static web page generation. It doesn't do much. It's not a "content management system". If you just need to generate a page with some data items filled in, it's fine. If you need more than that, there are bigger packages, but they have more baggage. John Nagle From nagle at animats.com Mon Mar 15 00:06:48 2010 From: nagle at animats.com (John Nagle) Date: Sun, 14 Mar 2010 21:06:48 -0700 Subject: Understanding the CPython dict implementation In-Reply-To: References: Message-ID: <4b9dadc4$0$1639$742ec2ed@news.sonic.net> Terry Reedy wrote: > I found this PyCon2010 presentation to be excellent: > The Mighty Dictionary, Branden Craig Rhodes, 30 min. > http://pycon.blip.tv/file/3264041/ > > Even knowing Python for over a decade, I learned a few things. > > Terry Jan Reedy Is this available as a paper? John Nagle From alfps at start.no Mon Mar 15 00:19:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 05:19:41 +0100 Subject: dll in project? In-Reply-To: References: Message-ID: * Alex Hall: > Hi all, > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") > > I have the specified dll file in the same directory as the file trying > to use said dll, and this is the only reference I make to the dll. Do > I need to register it somehow? If so, does this need to be done once, > or each time the application runs? If I need to register it, how would > I do so? Thanks! If 'ctypes.windll.LoadLibrary' just calls the Windows API LoadLibrary function without adding any path, then the directories considered will only be those known to the Windows API, like e.g. the process' current directory (I'm not sure if the current directory is considered, but the details aren't important). And most likely your calling script file is not in any of those directories. Probably it will work to specify the full path to the DLL. You can obtain the path to the calling file's directory by using the __file__ variable and the 'os.path' functions. Cheers & hth., - Alf From alfps at start.no Mon Mar 15 00:24:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 05:24:46 +0100 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: * Sang-Ho Yun: > I learned that I can check the existence of a file using > os.path.isfile("filename"). > > What if I need to check if there is a file that contains "HV" in the > filename? What should I do? from __future__ import print_function import os for filename in os.listdir( "." ): if "HV" in filename.upper(): print( filename ) Cheers & hth., - Alf From gherron at islandtraining.com Mon Mar 15 00:29:26 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 14 Mar 2010 21:29:26 -0700 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: <4B9DB7A6.2010802@islandtraining.com> Alf P. Steinbach wrote: > * Sang-Ho Yun: >> I learned that I can check the existence of a file using >> os.path.isfile("filename"). >> >> What if I need to check if there is a file that contains "HV" in the >> filename? What should I do? > > > from __future__ import print_function > import os > > for filename in os.listdir( "." ): > if "HV" in filename.upper(): > print( filename ) > > > > Cheers & hth., > > - Alf Or learn the glob module. It allows you to ask for a list of files matching a pattern that can include wildcard characters -- probably "*HV*" for your case. Gary Herron From Sang-Ho.Yun at jpl.nasa.gov Mon Mar 15 00:57:39 2010 From: Sang-Ho.Yun at jpl.nasa.gov (Sang-Ho Yun) Date: Sun, 14 Mar 2010 20:57:39 -0800 Subject: File existence check with partial filename Message-ID: I learned that I can check the existence of a file using os.path.isfile("filename"). What if I need to check if there is a file that contains "HV" in the filename? What should I do? Thank you, Sang-Ho From jgardner at jonathangardner.net Mon Mar 15 00:57:58 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sun, 14 Mar 2010 21:57:58 -0700 Subject: NoSQL Movement? In-Reply-To: <20100314095513.61b0fbaa.darcy@druid.net> References: <74ea9dd7-a9c0-4b44-842c-61c9c7f630eb@u15g2000prd.googlegroups.com> <6cc20cea1003120105j626cc519o2271106e088b2e90@mail.gmail.com> <7xljdx73a9.fsf@ruckus.brouhaha.com> <6cc20cea1003132342s6daefa43m6839a35bff37e0bb@mail.gmail.com> <20100314095513.61b0fbaa.darcy@druid.net> Message-ID: <6cc20cea1003142157h21a1cf22o58899265cd28964f@mail.gmail.com> On Sun, Mar 14, 2010 at 6:55 AM, D'Arcy J.M. Cain wrote: > On Sat, 13 Mar 2010 23:42:31 -0800 > Jonathan Gardner wrote: >> On Fri, Mar 12, 2010 at 11:23 AM, Paul Rubin wrote: >> > "D'Arcy J.M. Cain" writes: >> >> Just curious, what database were you using that wouldn't keep up with >> >> you? ?I use PostgreSQL and would never consider going back to flat >> >> files. >> > >> > Try making a file with a billion or so names and addresses, then >> > compare the speed of inserting that many rows into a postgres table >> > against the speed of copying the file. > > That's a straw man argument. ?Copying an already built database to > another copy of the database won't be significantly longer than copying > an already built file. ?In fact, it's the same operation. > I don't understand what you're trying to get at. Each bit of data follows a particular path through the system. Each bit of data has its own requirements for availability and consistency. No, relational DBs don't have the same performance characteristic as other data systems because they do different things. If you have data that fits a particular style well, then I suggest using that style to manage that data. Let's say I had data that needs to hang around for a little while then disappear into the archives. Let's say you hardly ever do random access on this data because you always work with it serially or in large batches. This is exactly like the recipient d >> Also consider how much work it is to partition data from flat files >> versus PostgreSQL tables. > > Another straw man. ?I'm sure you can come up with many contrived > examples to show one particular operation faster than another. > Benchmark writers (bad ones) do it all the time. ?I'm saying that in > normal, real world situations where you are collecting billions of data > points and need to actually use the data that a properly designed > database running on a good database engine will generally be better than > using flat files. > You're thinking in the general. Yes, RDBMs do wonderful things in the general cases. However, in very specific circumstances, RDBMS do a whole lot worse. Think of the work involved in sharding an RDBMS instance. You need to properly implement two-phase commit above and beyond the normal work involved. I haven't run into a multi-master replication system that is trivial. When you find one, let me know, because I'm sure there are caveats and corner cases that make things really hard to get right. Compare this to simply distributing flat files to one of many machines. It's a whole lot easier to manage and easier to understand, explain, and implement. You should use the right tool for the job. Sometimes the data doesn't fit the profile of an RDBMs, or the RDBMs overhead makes managing the data more difficult than it needs to be. In those cases, it makes a whole lot of sense to try something else out. >> >> The only thing I can think of that might make flat files faster is >> >> that flat files are buffered whereas PG guarantees that your >> >> information is written to disk before returning >> > >> > Don't forget all the shadow page operations and the index operations, >> > and that a lot of these operations require reading as well as writing >> > remote parts of the disk, so buffering doesn't help avoid every disk >> > seek. > > Not sure what a "shadow page operation" is but index operations are > only needed if you have to have fast access to read back the data. ?If > it doesn't matter how long it takes to read the data back then don't > index it. ?I have a hard time believing that anyone would want to save > billions of data points and not care how fast they can read selected > parts back or organize the data though. > I don't care how the recipients for the email campaign were indexed. I don't need an index because I don't do random accesses. I simply need the list of people I am going to send the email campaign to, properly filtered and de-duped, of course. This doesn't have to happen within the database. There are wonderful tools like "sort" and "uniq" to do this work for me, far faster than an RDBMS can do it. In fact, I don't think you can come up with a faster solution than "sort" and "uniq". >> Plus the fact that your other DB operations slow down under the load. > > Not with the database engines that I use. ?Sure, speed and load are > connected whether you use databases or flat files but a proper database > will scale up quite well. > I know for a fact that "sort" and "uniq" are far faster than any RDBMs. The reason why is obvious. -- Jonathan Gardner jgardner at jonathangardner.net From efiish at gmail.com Mon Mar 15 02:44:38 2010 From: efiish at gmail.com (Lan Qing) Date: Mon, 15 Mar 2010 14:44:38 +0800 Subject: Fwd: Some PyCon videos won't play In-Reply-To: References: Message-ID: In China these video can not watch at all. I must spent 3 days to download it... On Mon, Mar 15, 2010 at 5:19 AM, Terry Reedy wrote: > On 3/14/2010 2:41 PM, Terry Reedy wrote: > >> On 3/14/2010 11:14 AM, David Boddie wrote: >> > > You should still be able to get at the videos themselves by inspecting >>> the page contents, looking for download links like this one: >>> >>> >>> http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv >>> >>> >>> In this case, it's an Ogg Theora video file, so you may want to use >>> a player like VLC to view it: >>> >> >> For people using html5 competant browsers, which, I believe, play .ogv >> 'in tha page', blip.tv just needs to update site to make html5 pages an >> alternative to using the flash player. >> > > Actually, for FF3.6, at least, the problem is already solved. I just click > on the download button and FF recognizes .ogv as something it can play and > it does, replacing the flash player. The FF player lacks a full-screen > button, but that is rarely needed for the talks. > > tjr > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hiralsmaillist at gmail.com Mon Mar 15 02:51:28 2010 From: hiralsmaillist at gmail.com (hiral) Date: Sun, 14 Mar 2010 23:51:28 -0700 (PDT) Subject: result of os.times() is different with 'time' command Options References: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> Message-ID: <61c563ad-f0c3-47ae-b689-36c397f88295@l11g2000pro.googlegroups.com> On Mar 15, 7:14?am, Tim Roberts wrote: > hiral wrote: > >... > >Output: > >real ? ?0.0m0.0100000002421s > >user ? ?0.0m0.0s > >sys ? ? 0.0m0.0s > > >Command: > >$ time ls > > >Output: > >real ? ?0m0.007s > >user ? ?0m0.000s > >sys ? ? 0m0.000s > > >Is this the intended behaviour? > > What is it that you are wondering about? ?The formatting difference is due > to your code. ?The difference between 10 milliseconds and 7 milliseconds > could be due to any number of things. ?First, you have the overhead of > Python involved in your measurements. ?Second, you have the variability of > memory caching and disk caching. ?Your Python code causes /bin/ls to be > loaded into memory, and it's probably still in a file cache when you run > the second command. > > You can't really do an analysis like this with a task that only takes a few > milliseconds. ?There are too many variables. > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc.- Hide quoted text - > > - Show quoted text - Thanks for your explanation. From hiralsmaillist at gmail.com Mon Mar 15 02:51:42 2010 From: hiralsmaillist at gmail.com (hiral) Date: Sun, 14 Mar 2010 23:51:42 -0700 (PDT) Subject: to create variable from dict References: <4859ed52-7276-4617-b25e-902b52cfe7c5@s36g2000prh.googlegroups.com> Message-ID: On Mar 12, 8:02?pm, Jean-Michel Pichavant wrote: > Luis M. Gonz?lez wrote: > > On Mar 12, 10:59 am,hiral wrote: > > >> Hi, > > >> Is there any way to create variables which name matches with dict key? > > >> For example: > >> dict1 = {"abc":'1", "def":"2"} > > >> Now I am looking to have variable name abc and it's value be '1' etc. > > >> Pl. suggest. > > >> Thank you. > > > Check out this thread (very recent): > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > > Short answer: you can update globals() with a dictionary, as follows: > > > globals().update( dict1 ) > > > Then you'll have each key-value pair as variables in the global > > namespace. > > The question is: should you do it? > > > Luis > > The answer is known: no, he should not do it :o) > > JM- Hide quoted text - > > - Show quoted text - Thanks for your explanations. From xahlee at gmail.com Mon Mar 15 03:16:33 2010 From: xahlee at gmail.com (Xah Lee) Date: Mon, 15 Mar 2010 00:16:33 -0700 (PDT) Subject: Hacker News, Xahlee.Org, and What is Politics? Message-ID: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> A essay related to the recent discussion of banning, and lisp associated group at ycombinator.com . --------------------------------------------- Hacker News, Xahlee.Org, and What is Politics? Xah Lee, 2010-03-14 Today, i noticed that someone posted one of my article ?Why Emacs is still so useful today? on my blogger site (xahlee.blogspot.com) to Hacker News site here: Source. Note that my site XahLee.org was unceremoniously banned around 2009-02 by the admin geekers there. (see bottom of: Ban Xah Lee). But, apparantly, someone found my article useful. Now, in order to submit my articles, you'll have to use my article mirror at blogger.blogspot.com instead of xahlee.org. -------------------- Tech Geeker's Ignorance Of Politics The human nature of power struggle never ends. Many of these tech geekers think they are apolitical, that they are peace loving, they ride bikes not driving machines that pollute, they don't have interest in business, they embrace the Free of ?freedom? Software or Open Source of ?openness? software. The problem of human animals is that, we all think that, yet, power struggle or the formation of politics isn't something you consciously decide to do. Rather, it is something that you unconsciously do whenever you have interaction with peers when resources are not infinite. At the basic level, you have quarrels with ya brothers about toys, in high school about seats, girls. Going up a bit, you have all these teens, gamers, tech geekers, shouting, kicking, banning, in all sort of internet forums, irc chat rooms, mailing lists, in-world gaming channels. Going up, you have managers fighting in corporations, politicians pissing at each other, leaders warring among nation states. Note the word PEER here, because, you are out of the game with those who are much more powerful than you, and similarly, you can't be bothered by those far beneath you. Of course, the tech geekers all think they are fair, just, maintaining peace. But you can almost see the smug on their faces whenever any of these ?admins?, ?group owners?, ?sysops?, ?operators?, exercise their power. It is a basic human pleasure to force onto uncooperative others. (See: What Desires Are Politically Important?) Serious fairness and open policies never actually come up unless the community becomes large, larger then the original special interest clique. Before the group becomes large, typically their political structure is academically called oligarchy. i.e. basically whoever started the group, his cronies, rule. We all understand conscious power struggle. However, it is when we think that we are not doing politics when exercising our power, is when it is likely most damaging, with respect to human progress. (the subject of human progress, its ideal direction, goal, is itself is quite not agreed upon among historical figures (big philosophers, politicians, leaders, etc.).) Part of the problem is ignorance. Most tech geekers, those coders, engineers, type of folks, typically don't have much education or interest in social sciences. Few years ago on irc channel, i was ranting on the subject of politics, due to some difference of opinion on tech stuff, and learned, rather not surprisingly, that one of the guy don't understand that politics essentially means power struggle. Most tech geekers think that Politics is what politicians do, that it is something about rulers, about bad ass evil lords, ambitious guys, Napolean, or about controversial subjects, back stabbing, cloak and dagger, and isn't about, say, admins or policies in some online forum. -------------------- What Is Politics? Here's some Wikipedia quotes from Politics: Politics is a process by which groups of people make collective decisions. The term is generally applied to behavior within civil governments, but politics has been observed in other group interactions, including corporate, academic, and religious institutions. It consists of "social relations involving authority or power"[1] and refers to the regulation of a political unit,[2] and to the methods and tactics used to formulate and apply policy.[3] ... Political science, the study of politics, examines the acquisition and application of power and "power corrupts". It quotes this juicy quote: ?Politics: A strife of interests masquerading as a contest of principles. The conduct of public affairs for private advantage.? ? Ambrose Bierce[15] I much prefer older edits of Wikipedia's opening paragraph. Here's few excerpts Politics consists of "social relations involving authority or power"[1] and refers to the regulation of a political unit,[2] and to the methods and tactics used to formulate and apply policy.[3] ... In a broader sense, any situation involving power, or any maneouvring in order to enhance one's power or status within a group, may be described as politics (e.g. office politics).[3] This form of politics "is most associated with a struggle for ascendancy among groups having different priorities and power relations."[4] And here's a point-blank shot: Politics is who gets what, when, and how. ? Harold Lasswell ------------------- the url for this essay can be found on my website or blog. Xah ? http://xahlee.org/ ? From gandalf at shopzeus.com Mon Mar 15 03:38:34 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 15 Mar 2010 08:38:34 +0100 Subject: sqlite savepoint problem [solved] In-Reply-To: <1268608579.2846.34.camel@durian> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <1268608579.2846.34.camel@durian> Message-ID: <4B9DE3FA.2090904@shopzeus.com> > Annotating your example: > > # entering this context actually does nothing > with conn: > # a transaction is magically created before this statement > conn.execute("insert into a values (1)") > # and is implicitly committed before this statement > conn.execute("SAVEPOINT sp1") > # a new transaction is magically created > conn.execute("insert into a values (2)") > # and committed, discarding the first savepoint. > conn.execute("SAVEPOINT sp2") > # a new transaction is magically created > conn.execute("insert into a values (3)") > # and committed, discarding the very savepoint we are trying to use. > conn.execute("ROLLBACK TO sp2") > conn.execute("insert into a values (4)") > conn.execute("RELEASE sp1") > We all know the Zen of Python. Explicit is better than implicit. There is no point in using a savepoint outside a transaction. There is no point in using a savepoint if it commits all previous changes automatically. Conclusion: Sqlite's isolation_level is dark magic. It mixes real isolation levels with behaviour of context managers, and automagical commits in the wrong places. Setting isolation_level=None is a must for anyone who want to do any serious work with sqlite. L From Brian.Mingus at Colorado.EDU Mon Mar 15 03:39:29 2010 From: Brian.Mingus at Colorado.EDU (Brian J Mingus) Date: Mon, 15 Mar 2010 01:39:29 -0600 Subject: Hacker News, Xahlee.Org, and What is Politics? In-Reply-To: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> References: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> Message-ID: <9839a05c1003150039j40cbe2bao16cf51ca431a1a0f@mail.gmail.com> On Mon, Mar 15, 2010 at 1:16 AM, Xah Lee wrote: > A essay related to the recent discussion of banning, and lisp > associated group at ycombinator.com . Is there some Python related issue I might help you out with? Or perhaps you wish to provide Python assistance to someone on this list. Or perhaps you would like to write some Python code, or read the friendly Python manual, or draft a new PEP. Any one of these things would be a much better usage of your time than drafting middle to high school quality essays. -------------- next part -------------- An HTML attachment was scrubbed... URL: From davty216 at student.liu.se Mon Mar 15 03:49:34 2010 From: davty216 at student.liu.se (David Tynnhammar) Date: Mon, 15 Mar 2010 08:49:34 +0100 Subject: "Distributed" database in Python Message-ID: <6da346621003150049h7c8901a2kf7dfb09db3ddf861@mail.gmail.com> Greetings. I'm looking for a "distributed" database. (I'm not sure if distributed is the correct terminology though). My problem is this; I have a client application which once in a while needs to sync with a central database. (And of course the client -databases might be updated locally etc). Are there any other resources you can recommend me? (I have basic RDMS knowledge (MySQL)). From kevin.p.dwyer at gmail.com Mon Mar 15 03:50:09 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 15 Mar 2010 07:50:09 +0000 (UTC) Subject: Is it possible to use re2 from Python? References: <0540f7d0-95f6-4b38-900d-dc25958ff232@g26g2000yqn.googlegroups.com> Message-ID: On Sun, 14 Mar 2010 14:40:34 -0700, _wolf wrote: >> There's a recent thread about this on the python-dev list, > > pointers? i searched but didn?t find anything. http://mail.python.org/pipermail/python-dev/2010-March/098354.html From ryan at rfk.id.au Mon Mar 15 03:53:49 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 15 Mar 2010 18:53:49 +1100 Subject: sqlite savepoint problem [solved] In-Reply-To: <4B99FCCF.5080506@shopzeus.com> References: <87bpeqzmmv.fsf@castleamber.com> <4B99E358.4020507@shopzeus.com> <1268600658.2846.17.camel@durian> <4B99EE05.8060505@shopzeus.com> <4B99F1D1.2070202@shopzeus.com> <1268604831.2846.23.camel@durian> <4B99FCCF.5080506@shopzeus.com> Message-ID: <1268639629.2846.48.camel@durian> On Fri, 2010-03-12 at 09:35 +0100, Laszlo Nagy wrote: > > No it doesn't. The problem is that using a connection as a context > > manager doesn't do what you think. > > > > It does *not* start a new transaction on __enter__ and commit it on > > __exit__. As far as I can tell it does nothing on __enter__ and calls > > con.commit() or con.rollback() on exit. With isolation_level=None, > > these are no-ops. > > > Thank you Ryan! You are abolutely right, and thank you for reading the > source. Now everything works as I imagined. No problemo - isolation_level has given me my fair share of headaches in the past, so I couldn't resist the opportunity to understand it a little better. > The way the context manager and isolation_level works looks very very > strange to me. Here is a demonstration: > > import sqlite3 > def getconn(): > conn = sqlite3.connect(':memory:') > conn.isolation_level = None > return conn > def main(): > with getconn() as conn: > conn.execute("create table a ( i integer ) ") > try: > conn.execute("insert into a values (1)") > with conn: > conn.execute("insert into a values (2)") > raise Exception > except: > print "There was an error" > for row in conn.execute("select * from a"): > print row > main() > > > Output: > > There was an error > (1,) > (2,) > > > Looks like the context manager did not roll back anything. Yes, because there were no transactions created so there was nothing to roll back. > If I remove > isolation_level=None then I get this: > > There was an error > > E.g. the context manager rolled back something that was executed outside > the context. Yes, because the transactions created by the default isolation level do not nest, so the rollback happens at outermost scope. > I cannot argue with the implementation - it is that way. > But this is not what I would expect. I believe I'm not alone with this. That's at least two of us :-) > Just for clarity, we should put a comment at the end of the > documentation here: > > http://docs.python.org/library/sqlite3.html#sqlite3-controlling-transactions > > I would add at least these things: > > #1. By using isolation_level = None, connection objects (used as a > context manager) WON'T automatically commit or rollback transactions. > #2. Using any isolation level, connection objects WON'T automatically > begin a transaction. > #3. Possibly, include your connection manager class code, to show how to > do it "the expected" way. > > Also one should clarify in the documentation, what isolation_level does. > Looks like setting isolation_level to None is not really an "auto commit > mode". It is not even part of sqlite itself. It is part of the python > extension. I think of it as almost the opposite - you have to set isolation_level=None to get the unadulterated behaviour of the underlying sqlite library. I'm sure the devs would appreciate a documentation patch (submission details at http://python.org/dev/patches/). I'm also pretty confident that I won't have time to do one up anytime soon :-) Good luck with your project! Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit ryan at rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From steven at REMOVE.THIS.cybersource.com.au Mon Mar 15 04:01:02 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 15 Mar 2010 08:01:02 GMT Subject: "Distributed" database in Python References: Message-ID: On Mon, 15 Mar 2010 08:49:34 +0100, David Tynnhammar wrote: > Greetings. I'm looking for a "distributed" database. (I'm not sure if > distributed is the correct terminology though). > > My problem is this; I have a client application which once in a while > needs to sync with a central database. (And of course the client > -databases might be updated locally etc). > > Are there any other resources you can recommend me? (I have basic RDMS > knowledge (MySQL)). Google and Wikipedia are your friends. http://en.wikipedia.org/wiki/Distributed_database http://www.google.com/search?q=distributed+database http://www.google.com/search?q=python+distributed+database If you have already tried this, then you should say so, so that we don't waste our time, and yours, going over ground you have already covered. -- Steven From mail at timgolden.me.uk Mon Mar 15 04:41:10 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 15 Mar 2010 08:41:10 +0000 Subject: dll in project? In-Reply-To: References: Message-ID: <4B9DF2A6.70608@timgolden.me.uk> On 15/03/2010 03:43, Alex Hall wrote: > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") > > I have the specified dll file in the same directory as the file trying > to use said dll The DLL search path: http://msdn.microsoft.com/en-us/library/7d83bc18%28VS.80%29.aspx includes the directory which holds the executable for the current prcoess; it include the current directory; and it includes other things which I doubt apply here. But it doesn't include (if I may be permitted a little well-intentioned ridicule) the directory where the current Python module is stored. In other words: what does os.getcwd () return? TJG From mick.lausch at gmail.com Mon Mar 15 04:43:02 2010 From: mick.lausch at gmail.com (Michael.Lausch) Date: Mon, 15 Mar 2010 01:43:02 -0700 (PDT) Subject: staticmethod and setattr Message-ID: Hi, I managed to get confused by Python, which is not such an easy task. The problem i have is rooted in marshalling, JSON and Dojo. I need some static class in function with the name "$ref" i tried: class Foo(object): @staticmethod def _ref(o): pass setattr(Foo, "$ref", Foo._ref) but when i do something like this in code: class B(object): pass b = Bar f = Foo.getattr("$ref") f(b) if get the following error ypeError unbound method _ref() must be called with Foo instance as first argument (got Bar instance instead) I managed to impelemnt it with a unbound, "normal" _ref() function, but i want one _ref function per class, because they are a little bit different for each class. One aproach which i have not tried is: setattr(Foo, "$ref", Foo._ref.im_func). maybe this works, but i think this is not a clean aproach. Any ideas? From breamoreboy at yahoo.co.uk Mon Mar 15 04:46:31 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 15 Mar 2010 08:46:31 +0000 Subject: iterator/generator In-Reply-To: References: Message-ID: vsoler wrote: > I am working on a script that reads data from an excel workbook. The > data is located in a named range whose first row contains the headers. > It works!!! I find it superb that python is able to do such things!!! > > Now my questions. > > a. My ranges can in practice be quite big, and although I am happy > with the speed I get, because I am learning python, I think I could do > it still a bit better. I think that the line for i in matriz[1:]: > could be improved with an iterator/generator, but I am not quite > certain how I should proceed. I write this :- for j, i in enumerate(matriz): if j: etc... If there's a better method for some definition of better I'm certain we'll quickly get told. Please see the python docs for the enumerate built-in. HTH. Mark Lawrence. [snip the rest] From rantingrick at gmail.com Mon Mar 15 04:55:33 2010 From: rantingrick at gmail.com (rantingrick) Date: Mon, 15 Mar 2010 01:55:33 -0700 (PDT) Subject: Hacker News, Xahlee.Org, and What is Politics? References: <5b32bf8e-6adc-42a6-8a98-228b13e8a3f1@w9g2000prb.googlegroups.com> Message-ID: Bravo!, Bravo! A wonderful post xah, thanks for sharing and i hope it sinks in with the people around here who need a lesson in humility. I was just a few days ago feeling quite passionate about this subject and creating my own draft but than i lost interest because i knew nobody would even care and probably just accuse me of trolling. Anyhow thanks for this! From robin at reportlab.com Mon Mar 15 05:58:59 2010 From: robin at reportlab.com (Robin Becker) Date: Mon, 15 Mar 2010 09:58:59 +0000 Subject: Python, Reportlabs, Pil and Windows 7 (64bit) In-Reply-To: <4B9A9624.7040200@v.loewis.de> References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> <4B9A9624.7040200@v.loewis.de> Message-ID: <4B9E04E3.90408@chamonix.reportlab.co.uk> On 12/03/2010 19:29, "Martin v. L?wis" wrote: >> Not sure if this is a bug > > I think it is. It seems that the cross-build support in msvc9compiler > has been tested only in a build tree of Python (where there is no Libs > directory). This minor patch seems to fix the problem for me (using a PCBuild folder parallel to libs) C:\Python\Lib\distutils\command>diff build_ext.py.orig build_ext.py 207c207,209 < self.library_dirs.append(new_lib) --- > self.library_dirs.insert(0,new_lib) > else: > self.library_dirs.append(new_lib) > > For released copies of Python, I could change that to distribute the > AMD64 pythonXY.lib in libs/amd64. [FWIW, I'm still puzzled why I ship > the import libraries of all the pyd files as well - I can't see a reason > other than tradition]. Then, distutils should change to look it up there. ....... Just checked and all the pyd's seem only to export the xxx_init functions (sometimes there are two in the pyd) so the .libs do seem a bit redundant. -- Robin Becker From eckhardt at satorlaser.com Mon Mar 15 06:14:31 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Mar 2010 11:14:31 +0100 Subject: dll in project? References: Message-ID: <7td177-uar.ln1@satorlaser.homedns.org> Alex Hall wrote: > I have a dll I am trying to use, but I get a Windows error 126, "the > specified module could not be found". Here is the code segment: > nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") In addition to Alf's answer, this can also happen when the OS can't find another DLL that this one depends on. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From greg.ewing at canterbury.ac.nz Mon Mar 15 06:29:51 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 15 Mar 2010 23:29:51 +1300 Subject: Reverse engineering CRC? In-Reply-To: References: <7vj7fdFnnjU1@mid.individual.net> Message-ID: <4B9E0C1F.9020003@canterbury.ac.nz> I've solved the problem now. It turned out to be a very standard CRC algorithm, complicated by the presence of a few extra bytes of data being checked that didn't appear explicitly in the file anywhere. In the process I developed some very general techniques for solving this kind of problem, which I've written about here if anyone's interested: http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html Thanks for everyone's help, Greg From steve at REMOVE-THIS-cybersource.com.au Mon Mar 15 06:40:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Mar 2010 10:40:31 GMT Subject: staticmethod and setattr References: Message-ID: <4b9e0e9f$0$27822$c3e8da3@news.astraweb.com> On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: > Hi, > > I managed to get confused by Python, which is not such an easy task. > > The problem i have is rooted in marshalling, JSON and Dojo. I need some > static class in function with the name "$ref" i tried: > class Foo(object): > @staticmethod > def _ref(o): > pass > > setattr(Foo, "$ref", Foo._ref) That doesn't work as expected: >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] False Try this instead: >>> setattr(Foo, "$ref", Foo.__dict__['_ref']) >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] True -- Steven From efiish at gmail.com Mon Mar 15 06:57:38 2010 From: efiish at gmail.com (Lan Qing) Date: Mon, 15 Mar 2010 18:57:38 +0800 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: Or use the regular module: import re import os for filename in os.listdir('.'): if re.match("*HV*", filename): # do something with the file On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach wrote: > * Sang-Ho Yun: > > I learned that I can check the existence of a file using >> os.path.isfile("filename"). >> >> What if I need to check if there is a file that contains "HV" in the >> filename? What should I do? >> > > > from __future__ import print_function > import os for filename in os.listdir( "." ): > if "HV" in filename.upper(): > print( filename ) > > > > Cheers & hth., > > - Alf > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mehgcap at gmail.com Mon Mar 15 07:28:11 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 15 Mar 2010 07:28:11 -0400 Subject: dll in project? In-Reply-To: <7td177-uar.ln1@satorlaser.homedns.org> References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: On 3/15/10, Ulrich Eckhardt wrote: > Alex Hall wrote: >> I have a dll I am trying to use, but I get a Windows error 126, "the >> specified module could not be found". Here is the code segment: >> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") > > In addition to Alf's answer, this can also happen when the OS can't find > another DLL that this one depends on. Well, os.getcwd() returns "c:\python26", not my program's directory. However, I changed the reference to the dll to be helpers.progdir+'\\nvdaControllerClient32.dll' and still no luck! helpers.progdir is a var holding the top-level directory of my project, using os.path. Again, using this more precise reference still fails, triggering my except statement in my try/catch loop. From alfps at start.no Mon Mar 15 07:37:55 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Mar 2010 12:37:55 +0100 Subject: dll in project? In-Reply-To: References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: * Alex Hall: > On 3/15/10, Ulrich Eckhardt wrote: >> Alex Hall wrote: >>> I have a dll I am trying to use, but I get a Windows error 126, "the >>> specified module could not be found". Here is the code segment: >>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") >> In addition to Alf's answer, this can also happen when the OS can't find >> another DLL that this one depends on. > > Well, os.getcwd() returns "c:\python26", not my program's directory. > However, I changed the reference to the dll to be > helpers.progdir+'\\nvdaControllerClient32.dll' > and still no luck! Are you sure you get a single directory separator backslash there? I suggest using the os.path 'join' function, whatever it was called. > helpers.progdir is a var holding the top-level > directory of my project, using os.path. But is that where the DLL resides, or is it in some subdirectory? > Again, using this more precise > reference still fails, triggering my except statement in my try/catch > loop. Try also checking the arguments & documentation of ctypes.windll.LoadLibrary. I know, you probably already done that. But I mention it just in case (I'm not familiar with that function at the Python level, so don't know about the args). Cheers & hth., - Alf From eckhardt at satorlaser.com Mon Mar 15 07:44:18 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Mon, 15 Mar 2010 12:44:18 +0100 Subject: dll in project? References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: Alex Hall wrote: > On 3/15/10, Ulrich Eckhardt wrote: >> Alex Hall wrote: >>> I have a dll I am trying to use, but I get a Windows error 126, "the >>> specified module could not be found". Here is the code segment: >>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") >> >> In addition to Alf's answer, this can also happen when the OS can't find >> another DLL that this one depends on. Did you check if this could be the case? > Well, os.getcwd() returns "c:\python26", not my program's directory. > However, I changed the reference to the dll to be > helpers.progdir+'\\nvdaControllerClient32.dll' > and still no luck! Generally, there is os.path.join() IIRC which does this portably. This probably doesn't matter though. What I would check is firstly if this file could be opened at all, e.g. using os.stat(). > helpers.progdir is a var holding the top-level directory of my > project, using os.path. Huh? In what way using os.path? > Again, using this more precise reference still fails, triggering my > except statement in my try/catch loop. Same error? See my initial guess! As a tool for finding out if there are missing dependencies, take a look at http://dependencywalker.com BTW: No need to CC me, I read your initial request here, I can ready any follow-ups here, too. ;) Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From iwanttobeabadger at googlemail.com Mon Mar 15 08:21:42 2010 From: iwanttobeabadger at googlemail.com (Nathan Harmston) Date: Mon, 15 Mar 2010 12:21:42 +0000 Subject: Large regular expressions Message-ID: Hi, So I m trying to use a very large regular expression, basically I have a list of items I want to find in text, its kind of a conjunction of two regular expressions and a big list......not pretty. However everytime I try to run my code I get this exception: OverflowError: regular expression code size limit exceeded I understand that there is a Python imposed limit on the size of the regular expression. And although its not nice I have a machine with 12Gb of RAM just waiting to be used, is there anyway I can alter Python to allow big regular expressions? Could anyone suggest other methods of these kind of string matching in Python? I m trying to see if my swigged alphabet trie is faster than whats possible in Python! Many thanks, Nathan From mick.lausch at gmail.com Mon Mar 15 08:42:01 2010 From: mick.lausch at gmail.com (Michael.Lausch) Date: Mon, 15 Mar 2010 05:42:01 -0700 (PDT) Subject: staticmethod and setattr References: <4b9e0e9f$0$27822$c3e8da3@news.astraweb.com> Message-ID: <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> On Mar 15, 11:40?am, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: > > Hi, > > > I managed to get confused by Python, which is not such an easy task. > > > The problem i have is rooted in marshalling, JSON and Dojo. I need some > > static class in function with the name "$ref" i tried: > > class Foo(object): > > ? ? @staticmethod > > ? ? def _ref(o): > > ? ? ? ? ?pass > > > setattr(Foo, "$ref", Foo._ref) > > That doesn't work as expected: > > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > False > > Try this instead: > > >>> setattr(Foo, "$ref", Foo.__dict__['_ref']) > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > True Now I'm trying to understand why this is the case. How is Foo.__dict__['_ref'] different from Foo._ref? Shouldn't it return the same attribute? And after further experiments i found out that a making Foo._ref a classmethod does work with my first approach. From stefan_ml at behnel.de Mon Mar 15 08:45:31 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 15 Mar 2010 13:45:31 +0100 Subject: Large regular expressions In-Reply-To: References: Message-ID: Nathan Harmston, 15.03.2010 13:21: > So I m trying to use a very large regular expression, basically I have > a list of items I want to find in text, its kind of a conjunction of > two regular expressions and a big list......not pretty. However > everytime I try to run my code I get this exception: > > OverflowError: regular expression code size limit exceeded > > I understand that there is a Python imposed limit on the size of the > regular expression. And although its not nice I have a machine with > 12Gb of RAM just waiting to be used, is there anyway I can alter > Python to allow big regular expressions? > > Could anyone suggest other methods of these kind of string matching in > Python? If what you are trying to match is in fact a set of strings instead of a set of regular expressions, you might find this useful: http://pypi.python.org/pypi/acora Stefan From alain at dpt-info.u-strasbg.fr Mon Mar 15 08:50:27 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 15 Mar 2010 13:50:27 +0100 Subject: Large regular expressions References: Message-ID: <877hpdycj0.fsf@dpt-info.u-strasbg.fr> Nathan Harmston writes: [...] > Could anyone suggest other methods of these kind of string matching in > Python? I m trying to see if my swigged alphabet trie is faster than > whats possible in Python! Since you mention using a trie, I guess it's just a big alternative of fixed strings. You may want to try using the Aho-Corasick variant. It looks like there are several implementations (google finds at least two). I would be surprised if any pure python solution were faster than tries implemented in C. Don't forget to tell us your findings. -- Alain. From mehgcap at gmail.com Mon Mar 15 09:24:01 2010 From: mehgcap at gmail.com (Alex Hall) Date: Mon, 15 Mar 2010 09:24:01 -0400 Subject: dll in project? In-Reply-To: References: <7td177-uar.ln1@satorlaser.homedns.org> Message-ID: Okay, I got a new copy and all seems well now. The dll is found and loaded. The functions inside the dll are not working, but that is not Python's fault. Thanks to everyone for your help and suggestions! On 3/15/10, Ulrich Eckhardt wrote: > Alex Hall wrote: >> On 3/15/10, Ulrich Eckhardt wrote: >>> Alex Hall wrote: >>>> I have a dll I am trying to use, but I get a Windows error 126, "the >>>> specified module could not be found". Here is the code segment: >>>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll") >>> >>> In addition to Alf's answer, this can also happen when the OS can't find >>> another DLL that this one depends on. > > Did you check if this could be the case? > >> Well, os.getcwd() returns "c:\python26", not my program's directory. >> However, I changed the reference to the dll to be >> helpers.progdir+'\\nvdaControllerClient32.dll' >> and still no luck! > > Generally, there is os.path.join() IIRC which does this portably. This > probably doesn't matter though. What I would check is firstly if this file > could be opened at all, e.g. using os.stat(). > >> helpers.progdir is a var holding the top-level directory of my >> project, using os.path. > > Huh? In what way using os.path? > >> Again, using this more precise reference still fails, triggering my >> except statement in my try/catch loop. > > Same error? See my initial guess! As a tool for finding out if there are > missing dependencies, take a look at http://dependencywalker.com > > BTW: No need to CC me, I read your initial request here, I can ready any > follow-ups here, too. ;) > > Uli > > -- > Sator Laser GmbH > Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Have a great day, Alex (msg sent from GMail website) mehgcap at gmail.com; http://www.facebook.com/mehgcap From catonano at gmail.com Mon Mar 15 09:41:14 2010 From: catonano at gmail.com (catonano) Date: Mon, 15 Mar 2010 06:41:14 -0700 (PDT) Subject: Dreaming of new generation IDE References: <5b51740d-11f1-4f01-b51c-d1b6ea161eb7@l19g2000yqb.googlegroups.com> Message-ID: Hello again, people On Feb 11, 6:30?pm, Francis Carr wrote: > > I can't believe the code editing situation today is in a such sorry > > state. > > I can't believe an old coder is feeling so sorry for himself. Ok, I'm feeling sorry; still, I think I made a point. > > Today, I tried to understand the twisted.web.client code and I found 3 > Maybe the relevant lesson to be taken from Smalltalk is *not* > ? "put it all in one image" > but instead > ? "write code to solve problems, e.g., reading code" > I suggest defining a few shell functions to *automate* the search, for > example in zsh > > function allf () { > Smalltalk's images are cool. ?But they are such a huge hammer, and > they impose so many additional requirements! ?The costs outweigh the > cool. Francis, I disagree on the final balance statement about the Smalltalk images and I thank you for your suggestions on how to use grep and shell scripting. I also have no problem to admit I was feeling sorry for myself. But today I found something I think is relevant to this thread. It's here: http://www.cs.brown.edu/people/acb/codebubbles_site.htm it's about a IDE for Java called Bubbles. It sports a zooming interface and the MAIN idea it proposes, in my opinion, is that the code is NOT thought as files content, rather as fragments, called bubbles. And then you arrange your bubbles in a 2d space a little bit like in a videogame. I think it's very similar to the Smalltalk image thing (as a concept, if not as an implementation), with its live things and direct manipulation. If you open the footage directly in youtube, you can go to some "related" footages about a similar thing made by Microsoft that of course ditches the main idea retaining the concept of files and directories, overlapping the concept of files and classes (sigh). I didn't imagine such a research existed and the discovery confirms to me that the bother I indicated in this thread is somewhat shared by someone, around the world. As for my feelings, I swear I'm taking care of them in a way that doesn't involve bothering anyone on any newsgroup ;-) Steve, does Bubble gets any closer to your vision than the "ugly" Smalltalk thing ? Bye Catonano From alex at moreati.org.uk Mon Mar 15 09:50:32 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 15 Mar 2010 06:50:32 -0700 (PDT) Subject: Understanding the CPython dict implementation References: <4b9dadc4$0$1639$742ec2ed@news.sonic.net> Message-ID: On Mar 15, 4:06?am, John Nagle wrote: > ? ? Is this available as a paper? > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? John Nagle It doesn't wppear to be, slides are here: http://us.pycon.org/2010/conference/schedule/event/12/ Alex From bruno.42.desthuilliers at websiteburo.invalid Mon Mar 15 09:51:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 15 Mar 2010 14:51:30 +0100 Subject: staticmethod and setattr In-Reply-To: <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> References: <4b9e0e9f$0$27822$c3e8da3@news.astraweb.com> <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> Message-ID: <4b9e3b61$0$12084$426a34cc@news.free.fr> Michael.Lausch a ?crit : (snip) > Now I'm trying to understand why this is the case. > How is Foo.__dict__['_ref'] different from Foo._ref? > Shouldn't it return the same attribute? > It's an application of the descriptor protocol: http://wiki.python.org/moin/FromFunctionToMethod From andreas.loescher at s2005.tu-chemnitz.de Mon Mar 15 10:24:55 2010 From: andreas.loescher at s2005.tu-chemnitz.de (Andreas =?ISO-8859-1?Q?L=F6scher?=) Date: Mon, 15 Mar 2010 15:24:55 +0100 Subject: staticmethod and setattr In-Reply-To: <43208240-720b-40ff-9f41-b8a5a0c69246@g10g2000yqh.googlegroups.com> Message-ID: <1268663020.10067.35.camel@laptop> Am Montag, den 15.03.2010, 05:42 -0700 schrieb Michael.Lausch: > On Mar 15, 11:40 am, Steven D'Aprano cybersource.com.au> wrote: > > On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: > > > Hi, > > > > > I managed to get confused by Python, which is not such an easy task. > > > > > The problem i have is rooted in marshalling, JSON and Dojo. I need some > > > static class in function with the name "$ref" i tried: > > > class Foo(object): > > > @staticmethod > > > def _ref(o): > > > pass > > > > > setattr(Foo, "$ref", Foo._ref) > > > > That doesn't work as expected: > > > > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > > > False > > > > Try this instead: > > > > >>> setattr(Foo, "$ref", Foo.__dict__['_ref']) > > >>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] > > > > True > > Now I'm trying to understand why this is the case. > How is Foo.__dict__['_ref'] different from Foo._ref? > Shouldn't it return the same attribute? > > And after further experiments i found out that a making > Foo._ref a classmethod does work with my first approach. > In the class dictionary are the "raw" objects stored. For example: class Spam: @staticmethod def egg1(): pass def egg2(self): pass >>> Spam.__dict__ {'egg1': , '__module__': '__main__', 'egg2': , '__doc__': None} If you try to call egg1 as staticmethod you will get an error: >>> Spam.__dict__['egg1']() Traceback (most recent call last): File "", line 1, in TypeError: 'staticmethod' object is not callable getattr() is not only a shortcut for the line above. It searches all base classes for the specified name in the class dictionaries. If the name is found, and the object has an additional descriptor, it is applied on the object itself. In case of an static method, the descriptor sm_descr_get is located in Objects/funcobjects.c of the sources and it retriefes the encapsuled callable, which in this case is the function egg1. If you now set the function as new attribute, it is no longer a static method, but a normal function. If a function is retrieved via getattr(), it is encapsuled in an method object. (func_descr_get in the same file) If you now try to call the method in you example, you call a method from a class. This results in an unbound method, which requests an instance of the class as first agument. I hope this clears some things up. Best Andreas From gdamjan at gmail.com Mon Mar 15 10:53:21 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 15 Mar 2010 15:53:21 +0100 Subject: Python for newbies (Pythno users group in Macedonia) References: Message-ID: <28u177-m9j.ln1@archaeopteryx.softver.org.mk> > If you are all English-speakers then perhaps you could consider > showing a PyCon video - see > > http://pycon.blip.tv That's certainly something I'm considering for the more advanced users > Good luck with the group. I hope to see PyCon Macedonia emerging > before too long! Thanks :) I guess we'd have to wait a decade or so for a PyCon here -- damjan From gdamjan at gmail.com Mon Mar 15 11:05:31 2010 From: gdamjan at gmail.com (=?UTF-8?B?0JTQsNC80ZjQsNC9INCT0LXQvtGA0LPQuNC10LLRgdC60Lg=?=) Date: Mon, 15 Mar 2010 16:05:31 +0100 Subject: Python for newbies (Pythno users group in Macedonia) References: Message-ID: >> we are starting with bi-monthly Python User Group meetings in Skopje, >> Macedonia. The meetings are targeted for both beginners and more >> experienced users. >> > ... > http://us.pycon.org/2010/conference/schedule/event/108/ Great resource, exactly what I needed. So, they use this book http://www.greenteapress.com/thinkpython/ as a guide, seems like a good choice. I also learned about the tutor mail list: http://mail.python.org/mailman/listinfo/tutor -- damjan From alex at moreati.org.uk Mon Mar 15 11:42:40 2010 From: alex at moreati.org.uk (Alex Willmer) Date: Mon, 15 Mar 2010 08:42:40 -0700 (PDT) Subject: EuroPython 2010 - Open for registration and reminder of participation Message-ID: EuroPython 2010 - 17th to 24th July 2010 ---------------------------------------- EuroPython is a conference for the Python programming language community, including the Django, Zope and Plone communities. It is aimed at everyone in the Python community, of all skill levels, both users and programmers. Last year's conference was the largest open source conference in the UK and one of the largest community organised software conferences in Europe. This year EuroPython will be held from the 17th to 24th July in Birmingham, UK. It will include over 100 talks, tutorials, sprints and social events. Registration ------------ Registration is open now at: http://www.europython.eu/registration/ For the best registration rates, book as soon as you can! Extra Early Bird closes soon, after which normal Early Bird rate will apply until 10th May Talks, Activities and Events ---------------------------- Do you have something you wish to present at EuroPython? You want to give a talk, run a tutorial or sprint? Go to http://www.europython.eu/talks/cfp/ for information and advice! Go to http://wiki.europython.eu/Sprints to plan a sprint! Help Us Out ----------- EuroPython is run by volunteers, like you! We could use a hand, and any contribution is welcome. Go to http://wiki.europython.eu/Helping to join us! Go to http://www.europython.eu/contact/ to contact us directly! Sponsors -------- Sponsoring EuroPython is a unique opportunity to affiliate with this prestigious conference and to reach a large number of Python users from computing professionals to academics, from entrepreneurs to motivated and well-educated job seekers. http://www.europython.eu/sponsors/ Spread the Word --------------- We are a community-run not-for-profit conference. Please help to spread the word by distributing this announcement to colleagues, project mailing lists, friends, your blog, Web site, and through your social networking connections. Take a look at our publicity resources: http://wiki.europython.eu/Publicity General Information ------------------- For more information about the conference, please visit the official site: http://www.europython.eu/ Looking forward to see you! The EuroPython Team From python at mrabarnett.plus.com Mon Mar 15 11:44:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Mar 2010 15:44:43 +0000 Subject: File existence check with partial filename In-Reply-To: References: Message-ID: <4B9E55EB.7080802@mrabarnett.plus.com> Lan Qing wrote: > Or use the regular module: > > import re > import os > > for filename in os.listdir('.'): > if re.match("*HV*", filename): > # do something with the file > The regular expression should be ".*HV.*", although: re.search("HV", filename) would be better and: "HV" in filename.upper() would be even better, as Alf posted. > On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach > wrote: > > * Sang-Ho Yun: > > I learned that I can check the existence of a file using > os.path.isfile("filename"). > > What if I need to check if there is a file that contains "HV" in the > filename? What should I do? > > > > from __future__ import print_function > import os > > for filename in os.listdir( "." ): > if "HV" in filename.upper(): > print( filename ) > > > > Cheers & hth., > > - Alf > > -- > http://mail.python.org/mailman/listinfo/python-list > > From python at mrabarnett.plus.com Mon Mar 15 11:51:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Mar 2010 15:51:25 +0000 Subject: Large regular expressions In-Reply-To: References: Message-ID: <4B9E577D.8040905@mrabarnett.plus.com> Nathan Harmston wrote: > Hi, > > So I m trying to use a very large regular expression, basically I have > a list of items I want to find in text, its kind of a conjunction of > two regular expressions and a big list......not pretty. However > everytime I try to run my code I get this exception: > > OverflowError: regular expression code size limit exceeded > > I understand that there is a Python imposed limit on the size of the > regular expression. And although its not nice I have a machine with > 12Gb of RAM just waiting to be used, is there anyway I can alter > Python to allow big regular expressions? > > Could anyone suggest other methods of these kind of string matching in > Python? I m trying to see if my swigged alphabet trie is faster than > whats possible in Python! > There's the regex module at http://pypi.python.org/pypi/regex. It'll even release the GIL while matching on strings! :-) From elias.bachaalany at gmail.com Mon Mar 15 12:39:50 2010 From: elias.bachaalany at gmail.com (lallous) Date: Mon, 15 Mar 2010 09:39:50 -0700 (PDT) Subject: to pass self or not to pass self Message-ID: Hello, Learning Python from the help file and online resources can leave one with many gaps. Can someone comment on the following: # --------- class X: T = 1 def f1(self, arg): print "f1, arg=%d" % arg def f2(self, arg): print "f2, arg=%d" % arg def f3(self, arg): print "f3, arg=%d" % arg # this: F = f2 # versus this: func_tbl = { 1: f1, 2: f2, 3: f3 } def test1(self, n, arg): # why passing 'self' is needed? return self.func_tbl[n](self, arg) def test2(self): f = self.f1 f(6) f = self.F # why passing self is not needed? f(87) # --------- x = X() x.test1(1, 5) print '----------' x.test2() Why in test1() when it uses the class variable func_tbl we still need to pass self, but in test2() we don't ? What is the difference between the reference in 'F' and 'func_tbl' ? Thanks, Elias From constant.beta at gmail.com Mon Mar 15 12:56:39 2010 From: constant.beta at gmail.com (Michal Kwiatkowski) Date: Mon, 15 Mar 2010 09:56:39 -0700 (PDT) Subject: Arguments and a return value of a C function call when using setprofile Message-ID: Hi, I'm trying to write code that will trace arguments and return values of all function calls. Using sys.settrace with 'call' and 'return' events works great for Python functions, but now I want to extend that to C functions as well. Using sys.setprofile instead in theory gives me what I need ('c_call' and 'c_return'), but I'm stuck on getting actual arguments and return values. A snippet of code is worth a thousand words, so here it is: import inspect import sys def trace(frame, event, arg): if event == 'call': print "CALL", frame.f_code.co_name, "arguments:", inspect.getargvalues(frame) elif event == 'return': print "RETURN", frame.f_code.co_name, "return value:", arg elif event == 'c_call': print "C_CALL", arg.__name__, "???" elif event == 'c_return': print "C_RETURN", arg.__name__, "???" def func(x): return x+1 sys.setprofile(trace) func(1) # Python function repr(2) # C function sys.setprofile(None) For a 'c_call' event the trace function is called *before* the call, so frame is still in the context of the caller. 'c_return' event is invoked *after* the function has returned, so I don't get the return value here either. That's why I can't use inspect.getargvalues in those cases. Is there any other way I could get arguments and a return value of a C function call? Cheers, mk From steve at holdenweb.com Mon Mar 15 13:06:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Mar 2010 13:06:45 -0400 Subject: Python for newbies (Pythno users group in Macedonia) In-Reply-To: <28u177-m9j.ln1@archaeopteryx.softver.org.mk> References: <28u177-m9j.ln1@archaeopteryx.softver.org.mk> Message-ID: ?????? ??????????? wrote: >> If you are all English-speakers then perhaps you could consider >> showing a PyCon video - see >> >> http://pycon.blip.tv > > That's certainly something I'm considering for the more advanced users > >> Good luck with the group. I hope to see PyCon Macedonia emerging >> before too long! > > Thanks :) > I guess we'd have to wait a decade or so for a PyCon here > You might be surprised. Python is really taking off right now. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Mar 15 13:09:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Mar 2010 13:09:46 -0400 Subject: Fwd: Some PyCon videos won't play In-Reply-To: References: Message-ID: <4B9E69DA.7080608@holdenweb.com> Lan Qing wrote: > In China these video can not watch at all. I must spent 3 days to > download it... > That's a great pity. If they would be useful to a large population perhaps we could consider having copies hosted where they would be available with higher bandwidth? Who could we (the Python Software Foundation) discuss such a project with? regards Steve > On Mon, Mar 15, 2010 at 5:19 AM, Terry Reedy > wrote: > > On 3/14/2010 2:41 PM, Terry Reedy wrote: > > On 3/14/2010 11:14 AM, David Boddie wrote: > > > You should still be able to get at the videos themselves by > inspecting > the page contents, looking for download links like this one: > > http://blip.tv/file/get/Pycon-PyCon2010UsingPythonToCreateRoboticSimulationsForPlaneta894.ogv > > > In this case, it's an Ogg Theora video file, so you may want > to use > a player like VLC to view it: > > > For people using html5 competant browsers, which, I believe, > play .ogv > 'in tha page', blip.tv just needs to update > site to make html5 pages an > alternative to using the flash player. > > > Actually, for FF3.6, at least, the problem is already solved. I just > click on the download button and FF recognizes .ogv as something it > can play and it does, replacing the flash player. The FF player > lacks a full-screen button, but that is rarely needed for the talks. > > tjr > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From martin.schmidt1 at gmail.com Mon Mar 15 13:16:01 2010 From: martin.schmidt1 at gmail.com (Martin Schmidt) Date: Mon, 15 Mar 2010 13:16:01 -0400 Subject: extract occurrence of regular expression from elements of XML documents Message-ID: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> Hi, I have just started to use Python a few weeks ago and until last week I had no knowledge of XML. Obviously my programming knowledge is pretty basic. Now I would like to use Python in combination with ca. 2000 XML documents (about 30 kb each) to search for certain regular expression within specific elements of these documents. I would then like to record the number of occurrences of the regular expression within these elements. Moreover I would like to count the total number of words contained within these, and record the attribute of a higher level element that contains them. I was trying to figure out the best way how to do this, but got overwhelmed by the available information (e.g. posts using different approaches based on dom, sax, xpath, elementtree, expat). The outcome should be a file that lists the extracted attribute, the number of occurrences of the regular expression, and the total number of words. I did not find a post that addresses my problem. If someone could help me with this I would really appreciate it. Martin -------------- next part -------------- An HTML attachment was scrubbed... URL: From howe.steven at gmail.com Mon Mar 15 13:20:10 2010 From: howe.steven at gmail.com (Steven Howe) Date: Mon, 15 Mar 2010 10:20:10 -0700 Subject: File existence check with partial filename In-Reply-To: <4B9E55EB.7080802@mrabarnett.plus.com> References: <4B9E55EB.7080802@mrabarnett.plus.com> Message-ID: <4B9E6C4A.20509@gmail.com> What wrong with glob? ----------------------- Help on module glob: NAME glob - Filename globbing utility. FILE /usr/lib64/python2.6/glob.py FUNCTIONS glob(pathname) Return a list of paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la fnmatch. iglob(pathname) Return an iterator which yields the paths matching a pathname pattern. The pattern may contain simple shell-style wildcards a la fnmatch. DATA __all__ = ['glob', 'iglob'] ------------------- solution: import glob for afile in glob.iglob( "/home/buddy/*.HV" ): print afile sph On 03/15/2010 08:44 AM, MRAB wrote: > Lan Qing wrote: >> Or use the regular module: >> >> import re >> import os >> >> for filename in os.listdir('.'): >> if re.match("*HV*", filename): >> # do something with the file >> > The regular expression should be ".*HV.*", although: > > re.search("HV", filename) > > would be better and: > > "HV" in filename.upper() > > would be even better, as Alf posted. > >> On Mon, Mar 15, 2010 at 12:24 PM, Alf P. Steinbach > > wrote: >> >> * Sang-Ho Yun: >> >> I learned that I can check the existence of a file using >> os.path.isfile("filename"). >> >> What if I need to check if there is a file that contains "HV" >> in the >> filename? What should I do? >> >> >> >> from __future__ import print_function >> import os >> >> for filename in os.listdir( "." ): >> if "HV" in filename.upper(): >> print( filename ) >> >> >> >> Cheers & hth., >> >> - Alf >> >> -- http://mail.python.org/mailman/listinfo/python-list >> >> > From steve at holdenweb.com Mon Mar 15 13:29:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Mar 2010 13:29:51 -0400 Subject: extract occurrence of regular expression from elements of XML documents In-Reply-To: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> References: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> Message-ID: Martin Schmidt wrote: > Hi, > > I have just started to use Python a few weeks ago and until last week I > had no knowledge of XML. > Obviously my programming knowledge is pretty basic. > Now I would like to use Python in combination with ca. 2000 XML > documents (about 30 kb each) to search for certain regular expression > within specific elements of these documents. > I would then like to record the number of occurrences of the regular > expression within these elements. > Moreover I would like to count the total number of words contained > within these, and record the attribute of a higher level element that > contains them. > I was trying to figure out the best way how to do this, but got > overwhelmed by the available information (e.g. posts using different > approaches based on dom, sax, xpath, elementtree, expat). > The outcome should be a file that lists the extracted attribute, the > number of occurrences of the regular expression, and the total number of > words. > I did not find a post that addresses my problem. > If someone could help me with this I would really appreciate it. > You would get more specific help if you could post an example of the XML and describe the regex searching you want to do in a little more detail, I suspect. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From joel.pendery at gmail.com Mon Mar 15 13:37:34 2010 From: joel.pendery at gmail.com (Joel Pendery) Date: Mon, 15 Mar 2010 10:37:34 -0700 (PDT) Subject: subtraction is giving me a syntax error Message-ID: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> So I am trying to write a bit of code and a simple numerical subtraction y_diff = y_diff-H is giving me the error Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no encoding declared. Even though I have deleted some lines before it and this line is no longer line 70, I am still getting the error every time. I have tried to change the encoding of the file to utf-8 but to no avail, I still am having this issue. Any ideas? Thanks in advance From tomf.sessile at gmail.com Mon Mar 15 13:42:41 2010 From: tomf.sessile at gmail.com (TomF) Date: Mon, 15 Mar 2010 10:42:41 -0700 Subject: to pass self or not to pass self References: Message-ID: <2010031510424116807-tomfsessile@gmailcom> On 2010-03-15 09:39:50 -0700, lallous said: > Hello, > > Learning Python from the help file and online resources can leave one > with many gaps. Can someone comment on the following: > > # --------- > class X: > T = 1 > > def f1(self, arg): > print "f1, arg=%d" % arg > def f2(self, arg): > print "f2, arg=%d" % arg > def f3(self, arg): > print "f3, arg=%d" % arg > > # this: > F = f2 > # versus this: > func_tbl = { 1: f1, 2: f2, 3: f3 } > > def test1(self, n, arg): > # why passing 'self' is needed? > return self.func_tbl[n](self, arg) > > def test2(self): > f = self.f1 > f(6) > > f = self.F > # why passing self is not needed? > f(87) > > # --------- > x = X() > > x.test1(1, 5) > print '----------' > x.test2() > > Why in test1() when it uses the class variable func_tbl we still need > to pass self, but in test2() we don't ? > > What is the difference between the reference in 'F' and 'func_tbl' ? I recommend putting print statements into your code like this: def test1(self, n, arg): print "In test1, I'm calling a %s" % self.func_tbl[n] return self.func_tbl[n](self, arg) def test2(self): f = self.f1 print "Now in test2, I'm calling a %s" % f f(6) Bottom line: You're calling different things. Your func_tbl is a dict of functions, not methods. -Tom From R.Brodie at rl.ac.uk Mon Mar 15 13:42:50 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 15 Mar 2010 17:42:50 -0000 Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: "Joel Pendery" wrote in message news:56597268-3472-4fd9-a829-6d9cf51cf093 at e7g2000yqf.googlegroups.com... >> y_diff = y_diff-H > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. That's likely an en-dash, not a minus sign. From benjamin.kaplan at case.edu Mon Mar 15 13:48:08 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Mar 2010 13:48:08 -0400 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: On Mon, Mar 15, 2010 at 1:37 PM, Joel Pendery wrote: > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? > > Thanks in advance > It's not UTF-8. My guess would be that you're on Windows and it's a dash character in cp1252. The actual minus sign is 0x2D. Your editor must be putting in the wrong character. -------------- next part -------------- An HTML attachment was scrubbed... URL: From philip at semanchuk.com Mon Mar 15 13:48:54 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Mar 2010 13:48:54 -0400 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <3620300A-6BDB-40DA-98D0-9FB1D4E4B071@semanchuk.com> On Mar 15, 2010, at 1:37 PM, Joel Pendery wrote: > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? 0x96 is the Win1252 minus sign character. Did you copy & paste this code from a Web browser or a word processor? Delete the character between "y_diff" and "H" and replace it with a plain ASCII subtraction sign. From python at mrabarnett.plus.com Mon Mar 15 14:00:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Mar 2010 18:00:42 +0000 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <4B9E75CA.4010203@mrabarnett.plus.com> Joel Pendery wrote: > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? > > Thanks in advance Character '\x96' is an en-dash, which looks like a hyphen/minus sign '-', but isn't. From rami.chowdhury at gmail.com Mon Mar 15 14:01:00 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Mon, 15 Mar 2010 11:01:00 -0700 Subject: to pass self or not to pass self In-Reply-To: <2010031510424116807-tomfsessile@gmailcom> References: <2010031510424116807-tomfsessile@gmailcom> Message-ID: <201003151101.01118.rami.chowdhury@gmail.com> On Monday 15 March 2010 10:42:41 TomF wrote: > On 2010-03-15 09:39:50 -0700, lallous said: > > > > Why in test1() when it uses the class variable func_tbl we still need > > to pass self, but in test2() we don't ? > > > > What is the difference between the reference in 'F' and 'func_tbl' ? > > I recommend putting print statements into your code like this: > > def test1(self, n, arg): > print "In test1, I'm calling a %s" % self.func_tbl[n] > return self.func_tbl[n](self, arg) > > def test2(self): > f = self.f1 > print "Now in test2, I'm calling a %s" % f > f(6) > > > Bottom line: You're calling different things. Your func_tbl is a dict > of functions, not methods. > > -Tom To build on that a bit, note that in test2() you are doing: > > f = self.f1 > > f(6) > > > > f = self.F > > # why passing self is not needed? > > f(87) As I understand it, since you obtained the reference to 'f1' from 'self', you got it as a bound rather than an unbound method. So 'self' is automatically passed in as the first argument. ---- Rami Chowdhury "Given enough eyeballs, all bugs are shallow." -- Linus' Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From invalid at invalid.invalid Mon Mar 15 14:09:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 15 Mar 2010 18:09:29 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: On 2010-03-15, Philip Semanchuk wrote: > On Mar 15, 2010, at 1:37 PM, Joel Pendery wrote: > >> So I am trying to write a bit of code and a simple numerical >> subtraction >> >> y_diff = y_diff-H >> >> is giving me the error >> >> Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no >> encoding declared. [...] > > 0x96 is the Win1252 minus sign character. Did you copy & paste this > code from a Web browser or a word processor? > > Delete the character between "y_diff" and "H" and replace it with a > plain ASCII subtraction sign. I think somebody needs to stop editing his code with MS Word and start using a programming editor. ;) -- Grant Edwards grant.b.edwards Yow! Make me look like at LINDA RONSTADT again!! gmail.com From jeanmichel at sequans.com Mon Mar 15 14:24:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:24:38 +0100 Subject: class inheritance In-Reply-To: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> Message-ID: <4B9E7B66.10702@sequans.com> JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Value(1) + Value(2) > > where x is now a Fraction, not a Value, and x == y uses > Fraction.__eq__ rather than Value.__eq__. > > This appears to be standard Python behavior (int does the same thing). > I've worked around it by overriding __add__, etc, with functions that > invoke Fraction but coerce the result. But that's tedious; there are a > lot of methods to override. > > So I'm wondering: is there a more efficient way to accomplish what I'm > after? > I would change the approach. To the question, "*is* a Value a Fraction", some may tempted to answer "No" (for instance, a fraction has a denominator, a value has not). However "Does a Fraction *have* a Value", you could possibly say "Yes". The value may be then an attribute of the class Fraction, not a subclass. To test fraction equality, use F1 == F2. In order to test 'nearly equality', use F1.val() == F2.val(). JM From jeanmichel at sequans.com Mon Mar 15 14:25:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:25:00 +0100 Subject: staticmethod and setattr In-Reply-To: <1268663020.10067.35.camel@laptop> References: <1268663020.10067.35.camel@laptop> Message-ID: <4B9E7B7C.8050701@sequans.com> Am Montag, den 15.03.2010, 05:42 -0700 schrieb Michael.Lausch: >> On Mar 15, 11:40 am, Steven D'Aprano > cybersource.com.au> wrote: >> >>> On Mon, 15 Mar 2010 01:43:02 -0700, Michael.Lausch wrote: >>> >>>> Hi, >>>> >>>> I managed to get confused by Python, which is not such an easy task. >>>> >>>> The problem i have is rooted in marshalling, JSON and Dojo. I need some >>>> static class in function with the name "$ref" i tried: >>>> class Foo(object): >>>> @staticmethod >>>> def _ref(o): >>>> pass >>>> >>>> setattr(Foo, "$ref", Foo._ref) >>>> >>> That doesn't work as expected: >>> >>> >>>>>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] >>>>>> >>> False >>> >>> Try this instead: >>> >>> >>>>>> setattr(Foo, "$ref", Foo.__dict__['_ref']) >>>>>> Foo.__dict__['_ref'] is Foo.__dict__['$ref'] >>>>>> >>> True >>> >> Now I'm trying to understand why this is the case. >> How is Foo.__dict__['_ref'] different from Foo._ref? >> Shouldn't it return the same attribute? >> >> And after further experiments i found out that a making >> Foo._ref a classmethod does work with my first approach. >> >> When you declared _ref as static, a static object has been stored in Foo. Using Foo.__dict__ you can access this static object, which is *not* the _ref function Using Foo._ref, you trigger the lookup mechanism which do much more than accessing the dict. Especially, if it finds a __get__ method in the object, it will return the __get__ result instead of the object itself. Foo._ref is equivalent in your case to Foo.__dict__['_ref'].__get__(None, Foo) JM From jeanmichel at sequans.com Mon Mar 15 14:39:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:39:31 +0100 Subject: "Breaking" the __main__ script In-Reply-To: References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <1268597301.21932.1364768439@webmail.messagingengine.com> Message-ID: <4B9E7EE3.6000807@sequans.com> Steve Holden wrote: > python at bdurham.com wrote: > >>>> Any reason you prefer PDB over WinPDB? >>>> http://winpdb.org/ >>>> >>> Yes. I don't have Windows except one one PC :P >>> >> WinPDB runs on non-Windows platforms :) >> >> > One might reasonably argue that it has a pretty couter-intuitive name, then. > > regards > Steve > 'Win' may stand for Winner, not Windows :D JM From jeanmichel at sequans.com Mon Mar 15 14:41:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:41:18 +0100 Subject: "Breaking" the __main__ script In-Reply-To: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> Message-ID: <4B9E7F4E.4040900@sequans.com> vsoler wrote: > Hello, > > I am still learning python, thus developnig small scripts. > > Some of them consist only of the main module. While testing them > (debugging) I sometimes want to stop the script at a certain point, > with something like stop, break, end or something similar. > > What statement can I use? > > Vicente Soler > import bdb pdb.set_trace() # put this line anywhere you want a breakpoint in your code. type n for next, c for continue, s for step into and google for 'python pdb' for the details. JM From baptiste13z at free.fr Mon Mar 15 14:43:53 2010 From: baptiste13z at free.fr (Baptiste Carvello) Date: Mon, 15 Mar 2010 19:43:53 +0100 Subject: subtraction is giving me a syntax error In-Reply-To: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: Joel Pendery a ?crit : > So I am trying to write a bit of code and a simple numerical > subtraction > > y_diff = y_diff-H > > is giving me the error > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > encoding declared. > > Even though I have deleted some lines before it and this line is no > longer line 70, I am still getting the error every time. I have tried > to change the encoding of the file to utf-8 but to no avail, I still > am having this issue. Any ideas? > > Thanks in advance Hello, I would say that when you press the minus key, your operating system doesn't encode the standard (ASCII) minus character, but some fancy character, which Python cannot interpret. More precisely, I suspect you are unsing Windows with codepage 1252 (latin 1). With this encoding, you have 2 kinds of minus signs: the standard (45th character, in hex '\x2d') and the non-standard (150th character, in hex '\x96'). cf: http://msdn.microsoft.com/en-us/library/cc195054.aspx Cheers, Baptiste From jeanmichel at sequans.com Mon Mar 15 14:50:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Mar 2010 19:50:18 +0100 Subject: "Breaking" the __main__ script In-Reply-To: <4B9E7F4E.4040900@sequans.com> References: <31fd39a9-fbc6-4d9c-8da3-0939eedaf848@f8g2000yqn.googlegroups.com> <4B9E7F4E.4040900@sequans.com> Message-ID: <4B9E816A.7090608@sequans.com> Jean-Michel Pichavant wrote: > vsoler wrote: >> Hello, >> >> I am still learning python, thus developnig small scripts. >> >> Some of them consist only of the main module. While testing them >> (debugging) I sometimes want to stop the script at a certain point, >> with something like stop, break, end or something similar. >> >> What statement can I use? >> >> Vicente Soler >> > import bdb > > pdb.set_trace() # put this line anywhere you want a breakpoint in your > code. > > type n for next, c for continue, s for step into and google for > 'python pdb' for the details. > > JM erratum import pdb From astley.lejasper at gmail.com Mon Mar 15 15:10:21 2010 From: astley.lejasper at gmail.com (Astley Le Jasper) Date: Mon, 15 Mar 2010 12:10:21 -0700 (PDT) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> <4B9A9624.7040200@v.loewis.de> Message-ID: <8aa22e57-f152-4dc7-88da-cf6879de41f7@q16g2000yqq.googlegroups.com> Hi Robin, It looks like you've been busy. I'm sorry but you are well over my head at the moment! :-) If you need me to test an install then I'd be happy to help. However, I just received an email from Christoph Gohlke saying: " ... There are 64 bit versions of Reportlab and PIL for Python 2.6 for Windows available at http://www.lfd.uci.edu/~gohlke/pythonlibs/ ..." Regards Neil From dmitrey.kroshko at scipy.org Mon Mar 15 15:13:29 2010 From: dmitrey.kroshko at scipy.org (dmitrey) Date: Mon, 15 Mar 2010 12:13:29 -0700 (PDT) Subject: [ANN] OpenOpt 0.28, FuncDesigner 0.18, DerApproximator 0.18 Message-ID: <4e6fa172-6edb-4c1a-bc9d-8ba334008101@d27g2000yqf.googlegroups.com> Hi all, I'm glad to inform you about new release of our free (BSD-licensed) soft OpenOpt 0.28 (numerical optimization), FuncDesigner 0.18 (CAS with automatic differentiation), DerApproximator 0.18 (finite- differeces derivatives approximation). More details here: http://forum.openopt.org/viewtopic.php?id=222 Regards, D. From philip at semanchuk.com Mon Mar 15 15:38:54 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Mar 2010 15:38:54 -0400 Subject: Clustering and automated configuration & deployment toolkit with Python In-Reply-To: <003064f8-e559-41e9-8110-11fad8373d09@y17g2000yqd.googlegroups.com> References: <003064f8-e559-41e9-8110-11fad8373d09@y17g2000yqd.googlegroups.com> Message-ID: <577D1DA0-EAB5-4AC0-8C65-5E22CD56475C@semanchuk.com> On Mar 13, 2010, at 6:21 PM, np map wrote: > I'd like to write an open source clustering (for computation and > general use) and automation of configuration/deployment in Python. > It's main purpose is to be used in academic environments. > It would be something like running numpy/simpy code (and other custom > python code) on a set of machines in a distributed fashion (e.g. > splitting tasks, doing certain bits on some machines, other sub-tasks > on other machines, etc). Hi np map, Are you aware of ipython? My colleagues tell me that it contains some code for executing processes on remote machines. It sounds like code which you could build on or borrow from. HTH Philip > > The cluster could be used in at least two ways: > - submit code/files via a web interface, monitor the task via the web > interface and download the results from the master node (user<>web > interface<>master) > - run code directly from another machine on the cluster (as if it were > a subprocess or something like this) > > > Requirements (so far): > - support the Ubuntu Linux distribution in the initial iteration > - be easy to extend to other OS-es and package managers > - try to be 3.x compatible where dual compatibility is possible (2.x > and 3.x) > - it will support Python 2.5-2.6 > - document required changes to the 2.x only code to make it work on > 3.x > - make it easy to submit code directly from python scripts to the > cluster (with the right credentials) > - support key based authentication for job submission > - should talk to at least one type of RDBMS to store various types of > data > - the cluster should be able to kill a task on nodes automatically if > it executes for too long or requires too much memory (configurable) > - should be modular (use automation & configuration or just > clustering) > > > Therefore, I'd like to know a few things: > > Is there a clustering toolkit already available for python? > > What would the recommended architecture be ? > > How should the "user" code interface with the clustering system's > code? > > How should the results be stored (at the node and master level)? > > Should threading be supported in the tasks? > > How should they be returned to the Master node(s)? (polling, submitted > by the nodes, etc) > > What libraries should be used for this? (e.g. fabric as a library, > pyro, etc) > > Any other suggestions and pieces of advice? > > Should Fabric be used in this clustering system for automation? If > not, what else? Would simply using a wrapper written in python for the > 'ssh' app be ok? > > Would the following architecture be ok? > Master: splits tasks into sub-tasks, sends them to nodes - provided > the node's load isn't greater than a certain percentage, gets results, > stores and provides configuration to nodes, stores results, etc > Node: runs code, applies configuration, submits the results to the > master, etc > > If this system actually gets python-level code submission inside, how > should it work? > > The reason I posted this set of questions and ideas is that I'd like > this to be as flexible and usable as possible. From aahz at pythoncraft.com Mon Mar 15 15:57:23 2010 From: aahz at pythoncraft.com (Aahz) Date: 15 Mar 2010 12:57:23 -0700 Subject: When to lock data items returned by multiprocessing.Manager? References: <4428d674-7fa7-4095-a93d-75ea31a81d9a@15g2000yqi.googlegroups.com> Message-ID: In article <4428d674-7fa7-4095-a93d-75ea31a81d9a at 15g2000yqi.googlegroups.com>, Veloz wrote: > >So I'm using a multiprocessing.Manager instance in my main app and >asking it to create a dictionary, which I am providing to instances of >the application that I'm forking off with Process. > >The Processes and main app will be reading/writing to the dictionary. > >It's not clear to me what I have to "lock" and what I don't have to >lock. Any ideas? The way I deal with it is by making sure each key is only updated by a single process. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From jkn_gg at nicorp.f9.co.uk Mon Mar 15 16:52:16 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Mon, 15 Mar 2010 13:52:16 -0700 (PDT) Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: Hi Greg Just to say thanks for taking the time to write up your work on this interesting topic. Cheers J^n From debatem1 at gmail.com Mon Mar 15 16:57:23 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 15 Mar 2010 16:57:23 -0400 Subject: Reverse engineering CRC? In-Reply-To: <4B9E0C1F.9020003@canterbury.ac.nz> References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: On Mon, Mar 15, 2010 at 6:29 AM, Gregory Ewing wrote: > I've solved the problem now. > > It turned out to be a very standard CRC algorithm, complicated > by the presence of a few extra bytes of data being checked that > didn't appear explicitly in the file anywhere. > > In the process I developed some very general techniques for > solving this kind of problem, which I've written about here > if anyone's interested: > > http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html > > Thanks for everyone's help, > Greg Nice writeup, thanks. Geremy Condra From steve at REMOVE-THIS-cybersource.com.au Mon Mar 15 18:33:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Mar 2010 22:33:33 GMT Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote: >> Delete the character between "y_diff" and "H" and replace it with a >> plain ASCII subtraction sign. > > I think somebody needs to stop editing his code with MS Word and start > using a programming editor. ;) I've had this error myself, and I've never used Word to edit code. It can happen if you copy code from a website that "helpfully" converts hyphens to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z characters into strings, etc. They're a devil to debug. -- Steven From sjmachin at lexicon.net Mon Mar 15 18:48:45 2010 From: sjmachin at lexicon.net (John Machin) Date: Mon, 15 Mar 2010 15:48:45 -0700 (PDT) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> Message-ID: <6e982a4f-ebef-4b91-957d-7b50895c7f5d@k18g2000prf.googlegroups.com> On Mar 16, 5:43?am, Baptiste Carvello wrote: > Joel Pendery a ?crit : > > So I am trying to write a bit of code and a simple numerical > > subtraction > > > y_diff = y_diff-H > > > is giving me the error > > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > > encoding declared. > > > I would say that when you press the minus key, your operating system doesn't > encode the standard (ASCII) minus character, but some fancy character, which > Python cannot interpret. The likelihood that any operating system however brain-damaged and in whatever locale would provide by default a "keyboard" or "input method" that generated EN DASH when the '-' key is struck is somewhere between zero and epsilon. Already advanced theories like "used a word processor instead of a programmer's editor" and "scraped it off the web" are much more plausible. > More precisely, I suspect you are unsing Windows with codepage 1252 (latin 1). Codepage 1252 is not "latin1" in the generally accepted meaning of "latin1" i.e. ISO-8859-1. It is a superset. MS in their wisdom or otherwise chose to use most of the otherwise absolutely wasted slots assigned to "C1 control characters" in latin1. > With this encoding, you have 2 kinds of minus signs: the standard (45th > character, in hex '\x2d') and the non-standard (150th character, in hex '\x96'). > > cf:http://msdn.microsoft.com/en-us/library/cc195054.aspx The above link quite correctly says that '\x96` maps to U+2013 EN DASH. EN DASH is not any kind of minus sign. Aside: the syndrome causing the problem is apparent with cp125x for x in range(9) From invalid at invalid.invalid Mon Mar 15 18:56:19 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 15 Mar 2010 22:56:19 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-15, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote: > >>> Delete the character between "y_diff" and "H" and replace it with a >>> plain ASCII subtraction sign. >> >> I think somebody needs to stop editing his code with MS Word and start >> using a programming editor. ;) > > I've had this error myself, and I've never used Word to edit code. It can > happen if you copy code from a website that "helpfully" converts hyphens > to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z characters > into strings, etc. They're a devil to debug. Though it may not be Microsoft Word, I think I'd still maintain that an editor where you can't see a ctrl-Z or tell the difference between an ASCII minus and a windows-codepage-whatever isn't a very good programmer's editor. -- Grant Edwards grant.b.edwards Yow! HUMAN REPLICAS are at inserted into VATS of gmail.com NUTRITIONAL YEAST ... From jlundell at pobox.com Mon Mar 15 19:34:35 2010 From: jlundell at pobox.com (JLundell) Date: Mon, 15 Mar 2010 16:34:35 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> Message-ID: <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> On Mar 13, 1:26?pm, Carl Banks wrote: > It's a tad unfortunately Python doesn't make this easier. ?If I had to > do it more than once I'd probably write a mixin to do it: > > class ArithmeticSelfCastMixin(object): > ? ? def __add__(self,other): > ? ? ? ? return > self.__class__(super(ArithmeticSelfCastMixin,self).__add__(other) > ? ? # etc. > > class Value(ArithmeticSelfCastMixin,fraction.Fraction): > ? ? pass > > However, I want to warn you about overriding __eq__ to mean "almost > equal": it can have unexpected results so I don't recommend it. ?Two > of the main issues with it are: > > 1. It violates the transitive property ("If A == B and B == C, then A > == C") which most programmers expect to be true. > > 2. It will give unpredictable results when the objects are used in > sets or as dictionary keys. ?Those thow types expect the transitive > property to be true. ?If you are going to redefine __eq__ to mean > "almost equal", then at least define __hash__ to raise > NotImplementedError so that Python will refuse to use them in sets or > as dictionary keys: > > ? ? def __hash__(self): raise NotImplementedError > > Carl Banks It's also unfortunate that Python doesn't have an approximately-equal operator; it'd come in handy for floating-point applications while preserving hash. If only there were a ~= or ? operator I could overload. And ~ is unary, so no joy. My application is in that sense a little like a floating-point app, in that it needs approximately-equal. And it doesn't need Value to be hashable; thanks for the NotImplementedError suggestion; I've done that as a safeguard. From mail at hellmutweber.de Mon Mar 15 19:36:01 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Tue, 16 Mar 2010 00:36:01 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: Message-ID: <4B9EC461.9090009@hellmutweber.de> Am 11.03.2010 12:14, schrieb Peter Otten: > Hellmut Weber wrote: > >> Logging works very well giving the filename and line number of the point >> where it is called. As long as I use the loggers directly. >> BUT when I have to wrap the logger call in some other function, I always >> get file name and line number of the call of the logger inside the >> wrapping function. >> >> Is there a possibility to get this information in this situation too? > > The official way is probably to write a custom Logger class that overrides > the findCaller() method. > > Below is a hack that monkey-patches the logging._srcfile attribute to ignore > user-specified modules in the call stack: > > $ cat wrapper.py > import logging > import os > import sys > > logger = logging.getLogger() > > class SrcFile(object): > def __init__(self, exclude_files): > self.files = set(exclude_files) > def __eq__(self, other): > return other in self.files > > def fixname(filename): > if filename.lower().endswith((".pyc", ".pyo")): > filename = filename[:-4] + ".py" > return os.path.normcase(filename) > > if "--monkey" in sys.argv: > print "patching" > logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) > > def warn(*args, **kw): > logger.warn(*args, **kw) > > $ cat main.py > import logging > logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") > import wrapper > wrapper.warn("foo") > wrapper.warn("bar") > wrapper.warn("baz") > > $ python main.py > wrapper.py<23>: foo > wrapper.py<23>: bar > wrapper.py<23>: baz > > $ python main.py --monkey > patching > main.py<4>: foo > main.py<5>: bar > main.py<6>: baz > > $ python -V > Python 2.6.4 > > Peter Hi Peter, thanks for your help ;-) I've been offline for a few days so I found your message only today. I'll try your proposal tomorrow. Thanks again Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From pavlovevidence at gmail.com Mon Mar 15 21:03:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 15 Mar 2010 18:03:15 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> Message-ID: <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> On Mar 15, 4:34?pm, JLundell wrote: > It's also unfortunate that Python doesn't have an approximately-equal > operator; it'd come in handy for floating-point applications while > preserving hash. If only there were a ~= or ? operator I could > overload. And ~ is unary, so no joy. One problem with it is that there's no way to make it universal; different appiplications have different ideas of close. Conceivably it could be usefully defined for a user type though.. Bacause of this problem almost no languages have an almost equal operator. I'm curious what languages do, of if there are any with a trinary operator that also takes a threshold. Carl Banks From twistedphrame at gmail.com Mon Mar 15 22:07:00 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Mon, 15 Mar 2010 19:07:00 -0700 (PDT) Subject: Binary data transfer issue Message-ID: <40c9fafc-a172-4c9c-ba21-35ac8a4029aa@z35g2000yqd.googlegroups.com> Hi all, I'm trying to transfer a binary file over xmlrpclib. My test file is a .jpeg file. I can transfer all the data over but when I go to open the .jpeg I get "Error interpreting JPEG image file (Invalid JPEG file structure: SOS before SOF)" here's the code: ===========Various Shared Functions======== #EncodeAES takes a Cipher c and encrypts a String s EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) #DecodeAES takes a Cipher C and decrypts the cyphertext e #then removes the padding from the decrypted string DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING) CIPHER = AES.new("KEY") # method to change strings back into tuples def stringToTuple(string): if string[0] + string[-1] == "()": items = string[1:-1] items = items.split(',') return items else: raise ValueError("Badly formatted string (missing brackets).") ======client================= def Download(self, FileName, Data_Size=1024): ErrorCount = 0 Pkt_Num = -1 OldPkt_Num = Pkt_Num localFile = open("files/"+FileName, "wb") print print "Requesting First Packet" packet = self.client.download(EncodeAES(CIPHER, str(Pkt_Num))) if packet[0] == "False": print packet[1] return False packet = stringToTuple(DecodeAES(CIPHER, packet)) if int(packet[0]) == -3: print "Received Error Packet" else: print "Received Packet: ", int(packet[0]) print "packet[1], ", packet[2:-1] Pkt_Num = int(packet[0]) while Pkt_Num >= 0 and ErrorCount <= 10: if (OldPkt_Num +1) == Pkt_Num: OldPkt_Num = OldPkt_Num +1 localFile.write(binascii. a2b_base64(packet[1][2:-1])) #<<<= os.path.getsize("files/"+self.usr_dict[client][FILENAME]): return EncodeAES(CIPHER, str((-2, "File Transfer Complete"))) try: f = open("files/"+self.usr_dict[client][FILENAME], "rb") except IOError: return EncodeAES(CIPHER, str((-3, "File Could Not be opened"))) data = f.read((Pkt_Num+1 * DataRate)) data = None data = binascii.b2a_base64(f.read(DataRate)) #<<<<<<< References: <40c9fafc-a172-4c9c-ba21-35ac8a4029aa@z35g2000yqd.googlegroups.com> Message-ID: <4B9EF5F9.5010005@mrabarnett.plus.com> Jordan Apgar wrote: > Hi all, > > I'm trying to transfer a binary file over xmlrpclib. My test file is > a .jpeg file. I can transfer all the data over but when I go to open > the .jpeg I get "Error interpreting JPEG image file (Invalid JPEG file > structure: SOS before SOF)" > > here's the code: > > ===========Various Shared Functions======== > #EncodeAES takes a Cipher c and encrypts a String s > EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) > > #DecodeAES takes a Cipher C and decrypts the cyphertext e > #then removes the padding from the decrypted string > DecodeAES = lambda c, e: > c.decrypt(base64.b64decode(e)).rstrip(PADDING) > > > CIPHER = AES.new("KEY") > > > # method to change strings back into tuples > def stringToTuple(string): > if string[0] + string[-1] == "()": > items = string[1:-1] > items = items.split(',') > return items > else: > raise ValueError("Badly formatted string (missing brackets).") > > ======client================= > def Download(self, FileName, Data_Size=1024): > ErrorCount = 0 > Pkt_Num = -1 > OldPkt_Num = Pkt_Num > localFile = open("files/"+FileName, "wb") > print > print "Requesting First Packet" > packet = self.client.download(EncodeAES(CIPHER, str(Pkt_Num))) > if packet[0] == "False": > print packet[1] > return False > packet = stringToTuple(DecodeAES(CIPHER, packet)) > if int(packet[0]) == -3: > print "Received Error Packet" > else: > print "Received Packet: ", int(packet[0]) > > print "packet[1], ", packet[2:-1] > > Pkt_Num = int(packet[0]) > > while Pkt_Num >= 0 and ErrorCount <= 10: > if (OldPkt_Num +1) == Pkt_Num: > OldPkt_Num = OldPkt_Num +1 > localFile.write(binascii. > a2b_base64(packet[1][2:-1])) > #<<< ErrorCount == 0 > else: > ErrorCount = ErrorCount +1 > Pkt_Num = OldPkt_Num > > print "Requesting Packet: ", Pkt_Num +1 > packet = self.client.download(EncodeAES(CIPHER, > str(Pkt_Num))) > packet = stringToTuple(DecodeAES(CIPHER, packet)) > Pkt_Num = int(packet[0]) > if int(packet[0]) == -3: > print "Received Error Packet" > elif int(packet[0]) == -2: > print "Received EOF" > else: > print "Received Packet: ", int(packet[0]) > > localFile.close() > > if Pkt_Num == -2: > print packet[1][2:-1] > return True > elif Pkt_Num == -3: > os.remove("files/"+FileName) > print packet[1][2:-1] > return False > else: > os.remove("files/"+FileName) > print "Unexpected Packet: File Transfer Stopped" > return False > > > ==========Server Method============= > def download(self, Pkt_Num): > > Old_Pkt_Num = self.PKT > DataRate = self.DATA > Pkt_Num = int(DecodeAES(CIPHER,Pkt_Num)) > if Pkt_Num == -1 and Old_Pkt_Num == -1: > Pkt_Num = 0 > try: > f = open("files/"+self.usr_dict[client][FILENAME], > "rb") > except IOError: > return EncodeAES(CIPHER, > str((-3, "File Could Not be > opened"))) > data = binascii.b2a_base64(f.read((Pkt_Num+1 * > DataRate))) #<<<<< f.close() > self.usr_dict[client][PKT] = Pkt_Num > return EncodeAES(CIPHER, > str((Pkt_Num, data))) > > elif Pkt_Num == Old_Pkt_Num: > if Pkt_Num * DataRate >= > os.path.getsize("files/"+self.usr_dict[client][FILENAME]): > return EncodeAES(CIPHER, > str((-2, "File Transfer Complete"))) > try: > f = open("files/"+self.usr_dict[client][FILENAME], > "rb") > except IOError: > return EncodeAES(CIPHER, > str((-3, "File Could Not be opened"))) > data = f.read((Pkt_Num+1 * DataRate)) Here you're reading: Pkt_Num + DataRate bytes again, > data = None discarding what you've just read, > data = binascii.b2a_base64(f.read(DataRate)) > #<<<<<<< f.close() > self.usr_dict[client][PKT] = Pkt_Num +1 > > return EncodeAES(CIPHER, > str((Pkt_Num+1, data))) > > else: > > return EncodeAES(CIPHER, > str((-3, "Incorrect Packet Requested"))) > > > > Thank you all for the help, I know there are better ways and transfer > protocol modules to but I'd like to do this without them. > I'm not surprised that the transfer is failing! :-) From googler.1.webmaster at spamgourmet.com Mon Mar 15 23:15:37 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Mon, 15 Mar 2010 20:15:37 -0700 (PDT) Subject: Build Python with XCode Message-ID: Hi, I would like to build Python with Xcode (but without the makefile). Does anyone know a link where I can get a real xcodeproj with the current Py2.x sources? Thanks in advance!! Bye, donnerCobra From gagsl-py2 at yahoo.com.ar Mon Mar 15 23:52:43 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 00:52:43 -0300 Subject: converting datetime with tzinfo to unix timestamp References: <4B9ACB2B.3090203@gmail.com> Message-ID: En Fri, 12 Mar 2010 20:15:55 -0300, Michael Torrie escribi?: > On Python 2.5 here. > > I've searched and searched but I can't find any way to convert a > datetime object that includes a timezone (tzinfo) to a unix timestamp. > Folks on the net say to simply use the timetuple() method of the object > and feed that to time.mktime(). But that just doesn't seem to work for > me. At least if my understanding that the unix timestamp is always UTC. Try time.mktime(datetimeobject.utctimetuple()) instead. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 01:50:29 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 02:50:29 -0300 Subject: result of os.times() is different with 'time' command Options References: <16861cbc-4460-4d67-ab46-ff03517173d4@g8g2000pri.googlegroups.com> <61c563ad-f0c3-47ae-b689-36c397f88295@l11g2000pro.googlegroups.com> Message-ID: En Mon, 15 Mar 2010 03:51:28 -0300, hiral escribi?: > On Mar 15, 7:14 am, Tim Roberts wrote: >> hiral wrote: >> >Output: >> >real 0.0m0.0100000002421s >> >user 0.0m0.0s >> >sys 0.0m0.0s >> >> >Command: >> >$ time ls >> >> >Output: >> >real 0m0.007s >> >user 0m0.000s >> >sys 0m0.000s >> >> You can't really do an analysis like this with a task that only takes a >> few >> milliseconds. There are too many variables. > > Thanks for your explanation. Have you tested with the highly recursive function in that 2007 thread you linked to? This should take time enough to make a problem like this clearly visible. -- Gabriel Genellina From joshua.r.english at gmail.com Tue Mar 16 02:01:07 2010 From: joshua.r.english at gmail.com (Josh English) Date: Mon, 15 Mar 2010 23:01:07 -0700 (PDT) Subject: Dynamic Class Creation Message-ID: I have a large program with lots of data stored in XML. I'm upgrading my GUI to use ObjectListView, but with my data in XML, I don't have regular objects to interact with the OLV. I do have an XML validator that defines the structure of the XML elements, and I'm trying to dynamically create a class to wrap the XML element. So, an element like: Writers of the Future I want to create a class like: class Market(object): def __init__(self, elem): self._elem = elem def get_code(self): return self._elem.get('code') def set_code(self, value): self._elem.set('code', value) def get_title(self): return self._elem.find('title').text def set_title(self, value): node = self._elem.find('title') node.text = value Naturally, I don't want to hand code this for every interface but would like to create them dynamically. (The laziness of programming, I guess.) I have tried several solutions that I found on various forums, but they are all several years old. Questions: What's the best way to create these helper methods? How can I attach them to the class and have it run? I have had a few solutions work where I had a class with three methods (get_code, get_tier, get_mail) but they all return the same value, not the individual values. ---- Josh English From gagsl-py2 at yahoo.com.ar Tue Mar 16 02:16:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 03:16:54 -0300 Subject: Reverse engineering CRC? References: <7vj7fdFnnjU1@mid.individual.net> <4B9E0C1F.9020003@canterbury.ac.nz> Message-ID: En Mon, 15 Mar 2010 07:29:51 -0300, Gregory Ewing escribi?: > I've solved the problem now. > > It turned out to be a very standard CRC algorithm, complicated > by the presence of a few extra bytes of data being checked that > didn't appear explicitly in the file anywhere. > > In the process I developed some very general techniques for > solving this kind of problem, which I've written about here > if anyone's interested: > > http://www.cosc.canterbury.ac.nz/greg.ewing/essays/CRC-Reverse-Engineering.html A good solution to an interesting problem - and very nicely explained too! -- Gabriel Genellina From clp2 at rebertia.com Tue Mar 16 02:18:54 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Mar 2010 23:18:54 -0700 Subject: Dynamic Class Creation In-Reply-To: References: Message-ID: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> On Mon, Mar 15, 2010 at 11:01 PM, Josh English wrote: > I have a large program with lots of data stored in XML. I'm upgrading > my GUI to use ObjectListView, but with my data in XML, I don't have > regular objects to interact with the OLV. I do have an XML validator > that defines the structure of the XML elements, and I'm trying to > dynamically create a class to wrap the XML element. > > So, an element like: > > > Writers of the Future > > > I want to create a class like: > > class Market(object): > ? ?def __init__(self, elem): > ? ? ? ?self._elem = elem > > ? ?def get_code(self): > ? ? ? ?return self._elem.get('code') > > ? ?def set_code(self, value): > ? ? ? ?self._elem.set('code', value) > > ? ?def get_title(self): > ? ? ? ?return self._elem.find('title').text > > ? ?def set_title(self, value): > ? ? ? ?node = self._elem.find('title') > ? ? ? ?node.text = value > > Naturally, I don't want to hand code this for every interface but > would like to create them dynamically. (The laziness of programming, I > guess.) > > I have tried several solutions that I found on various forums, but > they are all several years old. > > Questions: > > What's the best way to create these helper methods? Nested functions: def make_attr_getset(name): def get(self): return self._elem.get(name) def set(self, value): self._elem.set(name, value) return get, set get_code, set_code = make_attr_getset('code') def make_subelement_getset(name): def get(self): return self._elem.find(name).text def set(self, value): node = self._elem.find(name) node.text = value return get, set get_title, set_title = make_subelement_getset('title') > How can I attach them to the class and have it run? Use properties and setattr(): class Market(object): def __init__(... #same as before setattr(Market, 'code', property(get_code, set_code)) setattr(Market, 'title', property(get_title, set_title)) m = Market(the_XML) print m.title #=> Writers of the Future m.title = "Writers of the Past" print m.code #=> WotF m.code = "WofP" Cheers, Chris -- http://blog.rebertia.com From satyamrajuhyd at gmail.com Tue Mar 16 02:44:17 2010 From: satyamrajuhyd at gmail.com (Earn money) Date: Mon, 15 Mar 2010 23:44:17 -0700 (PDT) Subject: Data entry Work available Message-ID: Data entry works Available At No need to pay DEposite http://trading7000.blogspot.com/ Adposting Jobs Availble http://trading7000.blogspot.com/ No need to work Hard Earn Money From Home 7000 in Minutes http://trading7000.blogspot.com/ From gagsl-py2 at yahoo.com.ar Tue Mar 16 02:46:05 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 03:46:05 -0300 Subject: time_struct References: <23dbe409-60ed-4f6f-bd38-4336e4f1b3d0@f8g2000yqn.googlegroups.com> Message-ID: En Sun, 07 Mar 2010 10:50:59 -0300, moerchendiser2k3 escribi?: > can anyone tell me how to return a time_struct from the timemodule in > my own C-Module? > Is that possible? I can just find one function in timefuncs.h, but it > doesnt return any PyObject. The type is available as the struct_time attribute in the time module; you create an instance by calling it with a 9-items sequence. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 03:04:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 04:04:44 -0300 Subject: xml-rpc References: <4B9C9AF9.80609@gmail.com> Message-ID: En Sun, 14 Mar 2010 05:14:49 -0300, ahmet erdinc yilmaz escribi?: > Recenetly we are developing a senior project and decide to use xmlrpclib. > However I have some questions. In the documentation I could not find any > clue about > handling requests? Does the server handles each request in a separate > thread? Or is > there some queuing mechanism for client calls? Thanks in advance. xmlrpclib is a *client* library. Python also provides an XMLRPC *server* in the SimpleXMLRPCServer module. It inherits from SocketServer.TCPServer. The default behavior is to process one request at a time, in a single process. You may alter such behavior by additionally inheriting from ForkingMixIn or ThreadingMixIn. -- Gabriel Genellina From no.email at nospam.invalid Tue Mar 16 03:39:55 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 16 Mar 2010 00:39:55 -0700 Subject: affectation in if statement References: Message-ID: <7x8w9s4svo.fsf@ruckus.brouhaha.com> samb writes: > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > else: > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > else > thing = "" > > Which isn't nice neither because I'm going to have maybe 20 match > tests and I wouldn't like to have 20 indentations. for pat in [r'define\s+(\S+)\s*{$', r'include\s+(\S+)$', ...]: m = re.match(pat, line) ... From ldo at geek-central.gen.new_zealand Tue Mar 16 03:40:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Mar 2010 20:40:36 +1300 Subject: import antigravity Message-ID: Subtle... From sam.bancal at gmail.com Tue Mar 16 03:45:34 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 00:45:34 -0700 (PDT) Subject: affectation in if statement Message-ID: Hi, I'm trying to do something like : if m = re.match(r'define\s+(\S+)\s*{$', line): thing = m.group(1) elif m = re.match(r'include\s+(\S+)$', line): thing = m.group(1) else thing = "" But in fact I'm not allowed to affect a variable in "if" statement. My code should then look like : if re.match(r'define\s+(\S+)\s*{$', line): m = re.match(r'define\s+(\S+)\s*{$', line) thing = m.group(1) elif re.match(r'include\s+(\S+)$', line): m = re.match(r'include\s+(\S+)$', line) thing = m.group(1) else thing = "" Which is not nice because I'm doing twice the same instruction or like : m = re.match(r'define\s+(\S+)\s*{$', line) if m: thing = m.group(1) else: m = re.match(r'include\s+(\S+)$', line) if m: thing = m.group(1) else thing = "" Which isn't nice neither because I'm going to have maybe 20 match tests and I wouldn't like to have 20 indentations. Anyone a recommendation? Thanks! From steven at REMOVE.THIS.cybersource.com.au Tue Mar 16 03:47:45 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 16 Mar 2010 07:47:45 GMT Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Mon, 15 Mar 2010 22:56:19 +0000, Grant Edwards wrote: > On 2010-03-15, Steven D'Aprano > wrote: >> On Mon, 15 Mar 2010 18:09:29 +0000, Grant Edwards wrote: >> >>>> Delete the character between "y_diff" and "H" and replace it with a >>>> plain ASCII subtraction sign. >>> >>> I think somebody needs to stop editing his code with MS Word and start >>> using a programming editor. ;) >> >> I've had this error myself, and I've never used Word to edit code. It >> can happen if you copy code from a website that "helpfully" converts >> hyphens to en-dashes, spaces to non-breaking spaces, or inserts ctrl-Z >> characters into strings, etc. They're a devil to debug. > > Though it may not be Microsoft Word, I think I'd still maintain that an > editor where you can't see a ctrl-Z or tell the difference between an > ASCII minus and a windows-codepage-whatever isn't a very good > programmer's editor. Regarding ctrl-Z (or for that matter other control characters), I agree it's a lack. As for not being able to see the difference between a hyphen and an EN- dash, or minus sign, or whatever it is, yes but they are very similar looking glyphs in virtually ever modern font. It would take a good eye to see the difference between (say) ? ? and -. -- Steven From stefan_ml at behnel.de Tue Mar 16 03:50:30 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 08:50:30 +0100 Subject: extract occurrence of regular expression from elements of XML documents In-Reply-To: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> References: <5444f9711003151016m39af59efg3ed38d2ac90f93c1@mail.gmail.com> Message-ID: Martin Schmidt, 15.03.2010 18:16: > I have just started to use Python a few weeks ago and until last week I had > no knowledge of XML. > Obviously my programming knowledge is pretty basic. > Now I would like to use Python in combination with ca. 2000 XML documents > (about 30 kb each) to search for certain regular expression within specific > elements of these documents. 2000 * 30K isn't a huge problem, that's just 60M in total. If you just have to do it once, drop your performance concerns and just get a solution going. If you have to do it once a day, take care to use a tool that is not too resource consuming. If you have strict requirements to do it once a minute, use a fast machine with a couple of cores and do it in parallel. If you have a huge request workload and want to reverse index the XML to do all sorts of sophisticated queries on it, use a database instead. > I would then like to record the number of occurrences of the regular > expression within these elements. > Moreover I would like to count the total number of words contained within > these, len(text.split()) will give you those. BTW, is it document-style XML (with mixed content as in HTML) or is the text always withing a leaf element? > and record the attribute of a higher level element that contains > them. An example would certainly help here. > I was trying to figure out the best way how to do this, but got overwhelmed > by the available information (e.g. posts using different approaches based on > dom, sax, xpath, elementtree, expat). > The outcome should be a file that lists the extracted attribute, the number > of occurrences of the regular expression, and the total number of words. > I did not find a post that addresses my problem. Funny that you say that after stating that you were overwhelmed by the available information. > If someone could help me with this I would really appreciate it. Most likely, the solution with the best simplicity/performance trade-off would be xml.etree.cElementTree's iterparse(), intercept on each interesting tag name, and search its text/tail using the regexp. That's doable in a couple of lines. But unless you provide more information, it's hard to give better advice. Stefan From stefan_ml at behnel.de Tue Mar 16 03:51:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 08:51:58 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: Lawrence D'Oliveiro, 16.03.2010 08:40: > Subtle... Absolutely. Python 2.4.6 (#2, Jan 21 2010, 23:45:25) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import antigravity Traceback (most recent call last): File "", line 1, in ? ImportError: No module named antigravity Stefan From clp2 at rebertia.com Tue Mar 16 03:52:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 00:52:07 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003160052m6358b020g6a65910c8d7af981@mail.gmail.com> On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro wrote: > Subtle... You're a bit behind the times. If my calculations are right, that comic is over 2 years old. Cheers, Chris From clp2 at rebertia.com Tue Mar 16 03:58:23 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 00:58:23 -0700 Subject: affectation in if statement In-Reply-To: References: Message-ID: <50697b2c1003160058t6ec2627ap42cfc7976f1bd2e4@mail.gmail.com> On Tue, Mar 16, 2010 at 12:45 AM, samb wrote: > Hi, > > I'm trying to do something like : > > if m = re.match(r'define\s+(\S+)\s*{$', line): > ? ?thing = m.group(1) > elif m = re.match(r'include\s+(\S+)$', line): > ? ?thing = m.group(1) > else > ? ?thing = "" > > But in fact I'm not allowed to affect a variable in "if" statement. > My code should then look like : > > if re.match(r'define\s+(\S+)\s*{$', line): > ? ?m = re.match(r'define\s+(\S+)\s*{$', line) > ? ?thing = m.group(1) > elif re.match(r'include\s+(\S+)$', line): > ? ?m = re.match(r'include\s+(\S+)$', line) > ? ?thing = m.group(1) > else > ? ?thing = "" > > Which is not nice because I'm doing twice the same instruction > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > ? ?thing = m.group(1) > else: > ? ?m = re.match(r'include\s+(\S+)$', line) > ? ?if m: > ? ? ? ?thing = m.group(1) > ? ?else > ? ? ? ?thing = "" > > Which isn't nice neither because I'm going to have maybe 20 match > tests and I wouldn't like to have 20 indentations. > > Anyone a recommendation? def extract_thing(line): for regex in (r'define\s+(\S+)\s*{$', r'include\s+(\S+)$'): m = re.match(regex, line) if m: return m.group(1) return "" Or if the real code is more complicated than your example: def extract_thing(line): m = re.match(r'define\s+(\S+)\s*{$', line) if m: return m.group(1) m = re.match(r'include\s+(\S+)$', line) if m: return m.group(1) #etc... return "" Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Tue Mar 16 04:10:39 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Mar 2010 01:10:39 -0700 Subject: affectation in if statement In-Reply-To: References: Message-ID: <4B9F3CFF.8040209@islandtraining.com> samb wrote: > Hi, > > I'm trying to do something like : > > if m = re.match(r'define\s+(\S+)\s*{$', line): > thing = m.group(1) > elif m = re.match(r'include\s+(\S+)$', line): > thing = m.group(1) > else > thing = "" > > But in fact I'm not allowed to affect a variable in "if" statement. > My code should then look like : > > if re.match(r'define\s+(\S+)\s*{$', line): > m = re.match(r'define\s+(\S+)\s*{$', line) > thing = m.group(1) > elif re.match(r'include\s+(\S+)$', line): > m = re.match(r'include\s+(\S+)$', line) > thing = m.group(1) > else > thing = "" > > Which is not nice because I'm doing twice the same instruction > or like : > > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > else: > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > else > thing = "" > > Which isn't nice neither because I'm going to have maybe 20 match > tests and I wouldn't like to have 20 indentations. > > Anyone a recommendation? > Yes: Use an array of regular expressions and a loop (untested): exprs = ["...", "...", ] thing = "" for expr in exps: m = re.match(expr, line) if m: thing = m.group(1) break > Thanks! > Gary Herron From clp2 at rebertia.com Tue Mar 16 04:16:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 01:16:02 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003160116p20e2e59v42996dd60241b47f@mail.gmail.com> On Tue, Mar 16, 2010 at 12:51 AM, Stefan Behnel wrote: > Lawrence D'Oliveiro, 16.03.2010 08:40: >> >> Subtle... > > Absolutely. > > ?Python 2.4.6 (#2, Jan 21 2010, 23:45:25) > ?[GCC 4.4.1] on linux2 > ?Type "help", "copyright", "credits" or "license" for more information. > ?>>> import antigravity > ?Traceback (most recent call last): > ? ?File "", line 1, in ? > ?ImportError: No module named antigravity http://svn.python.org/view/python/trunk/Lib/antigravity.py?view=markup&pathrev=66902 Cheers, Chris -- http://blog.rebertia.com From sam.bancal at gmail.com Tue Mar 16 04:37:13 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 01:37:13 -0700 (PDT) Subject: affectation in if statement References: Message-ID: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Thanks for all those suggestions. They are good! 1) Let's suppose now that instead of just affecting "thing = m.group(1)", I need to do a piece of logic depending on which match I entered... 2) Concerning the suggestion : m = re.match(r'define\s+(\S+)\s*{$', line) if m: thing = m.group(1) m = re.match(r'include\s+(\S+)$', line) if m: thing = m.group(1) #etc... It means that I'll do all the checks, even if the first one did match and I know that the next will not... Thanks again. From rtw at rtw.me.uk Tue Mar 16 04:52:45 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Tue, 16 Mar 2010 03:52:45 -0500 Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Message-ID: samb wrote in news:5c361012-1f7b-487f-915b-0f564b238be3 @e1g2000yqh.googlegroups.com in comp.lang.python: > Thanks for all those suggestions. > They are good! > > 1) Let's suppose now that instead of just affecting "thing = > m.group(1)", I need to do a piece of logic depending on which match I > entered... > > 2) Concerning the suggestion : > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > thing = m.group(1) > > m = re.match(r'include\s+(\S+)$', line) > if m: > thing = m.group(1) > > #etc... > > It means that I'll do all the checks, even if the first one did match > and I know that the next will not... > Ths is how I did it when I had the need: class ReMatch( object ): def __call__( self, pat, string ): import re self.match = re.match( pat, string ) return self.match is not None clip = ... re = ReMatch() if re( r'\s*TM(\d+)', clip ): ... elif re( r'\s*(https?://.*)', clip ): ... elif re( r'\d{12}$', clip ): ... Rob. -- From clp2 at rebertia.com Tue Mar 16 04:53:33 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 01:53:33 -0700 Subject: affectation in if statement In-Reply-To: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Message-ID: <50697b2c1003160153o5ca357eci986d40cadd05a06c@mail.gmail.com> On Tue, Mar 16, 2010 at 1:37 AM, samb wrote: > Thanks for all those suggestions. > They are good! > 2) Concerning the suggestion : > m = re.match(r'define\s+(\S+)\s*{$', line) > if m: > ? ?thing = m.group(1) > > m = re.match(r'include\s+(\S+)$', line) > if m: > ? ?thing = m.group(1) > > #etc... > > It means that I'll do all the checks, even if the first one did match > and I know that the next will not... Note how I split it out into a separate function and used `return m.group(1)` to avoid that exact situation. Cheers, Chris -- http://blog.rebertia.com From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 16 05:04:10 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 16 Mar 2010 10:04:10 +0100 Subject: to pass self or not to pass self In-Reply-To: References: Message-ID: <4b9f4984$0$10229$426a74cc@news.free.fr> lallous a ?crit : > Hello, > > Learning Python from the help file and online resources can leave one > with many gaps. Can someone comment on the following: (snip code) > Why in test1() when it uses the class variable func_tbl we still need > to pass self, but in test2() we don't ? > > What is the difference between the reference in 'F' and 'func_tbl' ? Answer here: http://wiki.python.org/moin/FromFunctionToMethod From sam.bancal at gmail.com Tue Mar 16 05:53:51 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 02:53:51 -0700 (PDT) Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> Message-ID: <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> On Mar 16, 9:53?am, Chris Rebert wrote: > On Tue, Mar 16, 2010 at 1:37 AM, samb wrote: > > Thanks for all those suggestions. > > They are good! > > > 2) Concerning the suggestion : > > m = re.match(r'define\s+(\S+)\s*{$', line) > > if m: > > ? ?thing = m.group(1) > > > m = re.match(r'include\s+(\S+)$', line) > > if m: > > ? ?thing = m.group(1) > > > #etc... > > Note how I split it out into a separate function and used `return > m.group(1)` to avoid that exact situation. Yes, you're right. It's an interresting approach. I'll give it a try. Cheers From sam.bancal at gmail.com Tue Mar 16 06:21:45 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 03:21:45 -0700 (PDT) Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: Hi, I've found a work around, inspired from Rob Williscroft : class ReMatch(object): """ Object to be called : 1st time : do a regexp.match and return the answer (args: regexp, line) 2nd time : return the previous result (args: prev) """ def __call__(self, regexp='', line='', prev=False): if prev: return self.prev_match self.prev_match = re.match(regexp, line) return self.prev_match re_match = ReMatch() if re_match(r'define\s+(\S+)\s*{$', line): m = re_match(prev=True) # do some logic with m elif re_match(r'include\s+(\S+)$', line): m = re_match(prev=True) # do some logic with m else # do some logic Hope this is efficient ... I guess yes. Cheers, Sam From __peter__ at web.de Tue Mar 16 06:45:40 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Mar 2010 11:45:40 +0100 Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: samb wrote: > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ > def __call__(self, regexp='', line='', prev=False): > if prev: > return self.prev_match > self.prev_match = re.match(regexp, line) > return self.prev_match > > re_match = ReMatch() > > if re_match(r'define\s+(\S+)\s*{$', line): > m = re_match(prev=True) > # do some logic with m > elif re_match(r'include\s+(\S+)$', line): > m = re_match(prev=True) > # do some logic with m > else > # do some logic > > Hope this is efficient ... I guess yes. No; just accessing the prev_match attribute instead of passing a flag to the __call__() method is more efficient and easier to read. I think the latter is the relevant point... Peter From bruno.42.desthuilliers at websiteburo.invalid Tue Mar 16 06:53:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 16 Mar 2010 11:53:22 +0100 Subject: affectation in if statement In-Reply-To: References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: <4b9f631c$0$3618$426a74cc@news.free.fr> samb a ?crit : > Hi, > > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ > def __call__(self, regexp='', line='', prev=False): > if prev: > return self.prev_match > self.prev_match = re.match(regexp, line) > return self.prev_match > > re_match = ReMatch() > > if re_match(r'define\s+(\S+)\s*{$', line): > m = re_match(prev=True) > # do some logic with m > elif re_match(r'include\s+(\S+)$', line): > m = re_match(prev=True) > # do some logic with m > else > # do some logic > > Hope this is efficient ... I guess yes. A direct attribute access is cheaper than a method call, and makes for a simpler API too: class ReMatch(object): match = None def __call__(self, regexp, source): self.match = re.match(regexp, source) return self.match re_match = ReMatch() if re_match(r'define\s+(\S+)\s*{$', line): m = re_match.match # do some logic with m elif re_match(r'include\s+(\S+)$', line): m = re_match.match # do some logic with m My 2 cents... From mail at hellmutweber.de Tue Mar 16 06:54:49 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Tue, 16 Mar 2010 11:54:49 +0100 Subject: A tool for find dependencies relationships behind Python projects In-Reply-To: References: Message-ID: <4B9F6379.5040805@hellmutweber.de> Am 24.02.2010 18:49, schrieb Victor Lin: > On 2?23?, ??12?32?, Hellmut Weber wrote: >> Hi Victor, >> I would be intereseted to use your tool ;-) >> >> My system is Sabayon-5.1 on Lenovo T61. >> Trying for the first time easy_install I get the following error: >> >> ==================== >> >> root at sylvester ~ # easy_install gluttony >> Searching for gluttony >> Readinghttp://pypi.python.org/simple/gluttony/ >> Readinghttp://code.google.com/p/python-gluttony/ >> Best match: Gluttony 0.3 >> >> Downloadinghttp://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md... >> >> Processing Gluttony-0.3.zip >> Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir >> /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD >> Traceback (most recent call last): >> File "/usr/bin/easy_install", line 9, in >> load_entry_point('distribute==0.6.8', 'console_scripts', >> 'easy_install')() >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 1708, in main >> with_ei_usage(lambda: >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 1696, in with_ei_usage >> return f() >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 1712, in >> distclass=DistributionWithoutHelpCommands, **kw >> File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup >> dist.run_commands() >> File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands >> self.run_command(cmd) >> File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command >> cmd_obj.run() >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 236, in run >> self.easy_install(spec, not self.no_deps) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 471, in easy_install >> return self.install_item(spec, dist.location, tmpdir, deps) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 501, in install_item >> dists = self.install_eggs(spec, download, tmpdir) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 680, in install_eggs >> return self.build_and_install(setup_script, setup_base) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 957, in build_and_install >> self.run_setup(setup_script, setup_base, args) >> File >> "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", >> line 946, in run_setup >> run_setup(setup_script, args) >> File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line >> 29, in run_setup >> lambda: execfile( >> File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line >> 70, in run >> return func() >> File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line >> 31, in >> {'__file__':setup_script, '__name__':'__main__'} >> File "setup.py", line 9, in >> File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", >> line 1, in >> # >> File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", >> line 13, in >> ImportError: No module named pip.log >> root at sylvester ~ # >> >> ==================== >> >> I emerged app-misc/pip, but that didn't help, the error remains the same >> >> What is missing? >> >> Any help appreciated >> >> Best regards >> >> Hellmut >> >> Am 19.02.2010 17:16, schrieb Victor Lin: >> >> >> >> >> >>> Hi, >> >>> I just wrote a tool for drawing dependencies relationships diagram of >>> Python project on Pypi. Here is the home page of the tool: >> >>> http://code.google.com/p/python-gluttony/ >> >>> Some examples: >>> Sprox: >>> http://static.ez2learn.com/gluttony/sprox_dot.png >> >>> TurboGears2: >>> http://static.ez2learn.com/gluttony/tg2_dot.png >> >>> Hope this could be helpful :P >> >>> Regards. >>> Victor Lin. >> >> -- >> Dr. Hellmut Weber m... at hellmutweber.de >> Degenfeldstra?e 2 tel +49-89-3081172 >> D-80803 M?nchen-Schwabing mobil +49-172-8450321 >> please: No DOCs, no PPTs. why: tinyurl.com/cbgq > > Hi, > > That is a mistake I made in when I am making the distribute. Thanks > your reporting. I have already fixed the problem and released > Gluttony 0.4, and I tried to install that, it works fine. > > Victor Lin. Hi Victor, thanks for your message. Sorry I'm so late to answer, I've been offline for a while and didn't remember not to have answered. ,-( I downloaded Gluttony-0.4 and the installation was done in a few seconds. It works just fine ;-) Thanks for providing this tool Cheers Hellmut -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From jeanmichel at sequans.com Tue Mar 16 06:56:11 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 16 Mar 2010 11:56:11 +0100 Subject: affectation in if statement In-Reply-To: References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: <4B9F63CB.1040708@sequans.com> samb wrote: > Hi, > > I've found a work around, inspired from Rob Williscroft : > > class ReMatch(object): > """ > Object to be called : > 1st time : do a regexp.match and return the answer (args: > regexp, line) > 2nd time : return the previous result (args: prev) > """ > def __call__(self, regexp='', line='', prev=False): > if prev: > return self.prev_match > self.prev_match = re.match(regexp, line) > return self.prev_match > > re_match = ReMatch() > > if re_match(r'define\s+(\S+)\s*{$', line): > m = re_match(prev=True) > # do some logic with m > elif re_match(r'include\s+(\S+)$', line): > m = re_match(prev=True) > # do some logic with m > else > # do some logic > > Hope this is efficient ... I guess yes. > > Cheers, > Sam What do you mean by efficient ? If you're talking about speed, make sure you care about it before doing some optimization. If you talk about readability then it is absolutely *not* efficient (to my humble opinion). define, include = re.match(r'define\s+(\S+)\s*{$', line), re.match(r'include\s+(\S+)$', line) if define: # do some stuff elif include: # do some other stuff else: # hello world If you then have some speed problem with that script, you'll start caring about how to execute if faster by making sure that only necessary calls to re.match are done. match = re.match(r'(define)\s+(\S+)\s*{$', line) or re.match(r'(include)\s+(\S+)$', line) # note that the second operand is executed only if the first is None if match.group(1) == 'define': # do some stuff with match.group(2) elif match.group(1) == 'include': # do some other stuff with match.group(2) else: # hello world JM From hackingkk at gmail.com Tue Mar 16 07:02:09 2010 From: hackingkk at gmail.com (hackingKK) Date: Tue, 16 Mar 2010 16:32:09 +0530 Subject: any python libraries for rendering open office spreadsheet to html Message-ID: <4B9F6531.5010604@gmail.com> Hello, Is there a python library which can render ods to html. (I would even prefer javascript library to do this). The reason I am more interested in a python library is because, I am developing a web application in pylons. It is a financial software and initially on the desktop based client, I used odfpy to create spreadsheets. But now I would want to render those sheets to the web front end. Happy hacking. Krishnakant. From steve at REMOVE-THIS-cybersource.com.au Tue Mar 16 07:46:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Mar 2010 11:46:51 GMT Subject: Understanding the CPython dict implementation References: Message-ID: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: > I found this PyCon2010 presentation to be excellent: The Mighty > Dictionary, Branden Craig Rhodes, 30 min. > http://pycon.blip.tv/file/3264041/ Unfortunately, that clip seems to be unwatchable, at least for me. It crashed the Netscape plugin in Konqueror, and crashed Firefox. When I downloaded the ogv file, it crashed MPlayer and Kaffeine. Before crashing, in all four players, it displayed random blocks of colours and lines while the sound played. Not a good advertisement for either BlipTV or Ogg :( -- Steven From googler.1.webmaster at spamgourmet.com Tue Mar 16 07:52:37 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 04:52:37 -0700 (PDT) Subject: C-API PyObject_Call Message-ID: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Hi, i have a serious problem and I am looking for a solution. I pass an instance of a class from a file to PyObject_Call. When something fails, I get a full traceback. If it succeeds, I get the return value. Is it possible to get information from which line/file the return value of PyObject_Call is? Thanks!! moerchendiser2k3 From Ron.Barak at lsi.com Tue Mar 16 07:54:01 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 11:54:01 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: References: Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Hi, I'm trying to add a library path to my pythonpath, but seems it is not accepted - On Windows DOS window: C:\>echo %PYTHONPATH% c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ C:\>python -c "import sys ; print sys.path" ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] C:\> On Windows cygwin: $ echo $PYTHONPATH .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ $ python -c "import sys ; print sys.path" ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] $ What am I doing wrong ? Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eckhardt at satorlaser.com Tue Mar 16 07:56:36 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Tue, 16 Mar 2010 12:56:36 +0100 Subject: import antigravity References: Message-ID: Chris Rebert wrote: > You're a bit behind the times. > If my calculations are right, that comic is over 2 years old. import timetravel Uli From Ron.Barak at lsi.com Tue Mar 16 07:56:47 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 11:56:47 +0000 Subject: Recall: How to add a library path to pythonpath ? Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C839@enbmail01.lsi.com> Barak, Ron would like to recall the message, "How to add a library path to pythonpath ?". From jan at jandecaluwe.com Tue Mar 16 08:10:09 2010 From: jan at jandecaluwe.com (Jan Decaluwe) Date: Tue, 16 Mar 2010 13:10:09 +0100 Subject: The first ASIC designed with MyHDL Message-ID: <4b9f7414$0$2887$ba620e4c@news.skynet.be> I am proud to report on the first ASIC product designed with MyHDL (afaik). http://www.jandecaluwe.com/hdldesign/digmac.html -- Jan Decaluwe - Resources bvba - http://www.jandecaluwe.com Python as a HDL: http://www.myhdl.org VHDL development, the modern way: http://www.sigasi.com Analog design automation: http://www.mephisto-da.com World-class digital design: http://www.easics.com From clp2 at rebertia.com Tue Mar 16 08:13:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 05:13:20 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003160513y7bf2dd8ew9020ddf76f048121@mail.gmail.com> On Tue, Mar 16, 2010 at 4:56 AM, Ulrich Eckhardt wrote: > Chris Rebert wrote: >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. > > import timetravel > > Uli So that's where Guido's been hiding his infamous time machine! Right in plain sight! It's so obvious in retrospect. Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Tue Mar 16 08:13:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Mar 2010 13:13:26 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Ulrich Eckhardt: > Chris Rebert wrote: >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. > > import timetravel C:\test> python Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.altzone -7200 >>> # hm. ... >>> _ Cheers, - Alf From rikutheronin at gmail.com Tue Mar 16 08:27:22 2010 From: rikutheronin at gmail.com (Pablo Recio Quijano) Date: Tue, 16 Mar 2010 13:27:22 +0100 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Message-ID: <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> You have to add yout path to the list: import sys sys.path.append(your_path) Jus simple to add the element on the list :) 2010/3/16 Barak, Ron > Hi, > > I'm trying to add a library path to my pythonpath, but seems it is not > accepted - > > On Windows DOS window: > > C:\>echo %PYTHONPATH% > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > > C:\>python -c "import sys ; print sys.path" > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\syst > em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', > 'C:\\Python26\\l > ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', > 'C:\\Python26\\lib\\ > site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > C:\> > > On Windows cygwin: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > $ python -c "import sys ; print sys.path" > ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > 'c:\\Python26\\lib\\site-packages', > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > $ > > What am I doing wrong ? > > Thanks, > Ron. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at ieee.org Tue Mar 16 08:35:54 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Mar 2010 07:35:54 -0500 Subject: class inheritance In-Reply-To: <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> Message-ID: <4B9F7B2A.1080906@ieee.org> Carl Banks wrote: > On Mar 15, 4:34 pm, JLundell wrote: > >> It's also unfortunate that Python doesn't have an approximately-equal >> operator; it'd come in handy for floating-point applications while >> preserving hash. If only there were a ~=r ? operator I could >> overload. And ~ is unary, so no joy. >> > > One problem with it is that there's no way to make it universal; > different appiplications have different ideas of close. Conceivably > it could be usefully defined for a user type though.. > > Bacause of this problem almost no languages have an almost equal > operator. I'm curious what languages do, of if there are any with a > trinary operator that also takes a threshold. > > Carl Banks > > If I recall correctly, APL has a *fuzz* value, which is used in all(?) comparisons. But I do not recall anything about how it was defined. I do recall that you could change the threshold, and suspect it was relative to the operands. For symmetry, it would probably have to be relative to the average of the two values, or some such. From basaka.chen at gmail.com Tue Mar 16 08:53:35 2010 From: basaka.chen at gmail.com (freakrobot) Date: Tue, 16 Mar 2010 05:53:35 -0700 (PDT) Subject: what's the diffence between "RECENT" and "UNSEEN" in imaplib? Message-ID: <2583d700-db3c-4291-ae18-46f96b02a92d@s25g2000prd.googlegroups.com> When I work with the imaplib, there is a imap4.status(mailboxname, '(MESSAGES RECENT UNSEEN)') function. So I really wonder what's the difference between RECENT and UNSEEN conditions. And what kind of messages belong to RECENT condition? Thank you~ From dmj.ccc at gmail.com Tue Mar 16 08:57:05 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 05:57:05 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple Message-ID: Hi all, This may be a complete brainfart, but it's been puzzling me for a day or two (!). Sorry for not describing "something" in the subject, but it's hard to describe succinctly: I have a short list of non-zero positive integers (say myList=[2,5,8,3,5]). I need to return five lists of non-negative numbers, such that for five different "share sizes", myList[0] and myList[1] will share twice the smaller amount... def getOutcomes(): outcomes=[] if myList[0]<=myList[1]: amountToShare=2*myList[0] remainder=myList[1]-myList[0] outcome.append((amountToShare, remainder)+myList[2:]) # shares are (100%, 0) outcome.append((amountToShare*0.75, remainder +amountToShare*0.25)+myList[2:]) #shares are (75%, 25%), and exactly the same for (50%,50%), (25%, 75%), and (0,100%) ... ... return outcomes i.e. for the above myList, outcomes=[[4,1,8,3,5], [3,2,8,3,5], [2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] if myList[0]>myList[1], i want exactly the opposite to happen (i.e., just switching what happens to positions 0 and 1) Obviously, i can just write the code again, in an else, switching indices 0 and 1. Or, I could just have a test at the beginning, switch them if they are in the order "big, small", and then switch them again at the end in a list comprehension. Both ideas seem terribly silly, and there must be an obvious way to do it that I'm not seeing. any help? many thanks dmj From motoom at xs4all.nl Tue Mar 16 09:00:41 2010 From: motoom at xs4all.nl (Michiel Overtoom) Date: Tue, 16 Mar 2010 14:00:41 +0100 Subject: Understanding the CPython dict implementation In-Reply-To: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> References: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 16 Mar 2010, at 12:46 , Steven D'Aprano wrote: > On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: > >> I found this PyCon2010 presentation to be excellent: The Mighty >> Dictionary, Branden Craig Rhodes, 30 min. >> http://pycon.blip.tv/file/3264041/ > > > Unfortunately, that clip seems to be unwatchable, at least for me. It > crashed the Netscape plugin in Konqueror, and crashed Firefox. When I > downloaded the ogv file, it crashed MPlayer and Kaffeine. It played in VLC without problems. Greetings, From dmj.ccc at gmail.com Tue Mar 16 09:05:30 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 06:05:30 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: ... and of course i screwed up my outcomes... that should read outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] From kw at codebykevin.com Tue Mar 16 09:22:29 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 16 Mar 2010 09:22:29 -0400 Subject: Build Python with XCode In-Reply-To: References: Message-ID: <2c74f$4b9f8616$4275d90a$4845@FUSE.NET> On 3/15/10 11:15 PM, moerchendiser2k3 wrote: > Hi, > > I would like to build Python with Xcode (but without the makefile). > Does anyone know a link where I can get a real xcodeproj with the > current Py2.x sources? > > > Thanks in advance!! Bye, donnerCobra I don't think one exists--I build my Python on OS Xwith configure, make etc.-- but you could try asking on the MacPython list. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From chris at simplistix.co.uk Tue Mar 16 09:47:12 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 16 Mar 2010 13:47:12 +0000 Subject: converting a timezone-less datetime to seconds since the epoch Message-ID: <4B9F8BE0.2050808@simplistix.co.uk> Hi All, We have a bunch of datetime objects that have tzinfo=None. We want to turn them into float timestamps in seconds since the epoch. Here's the first attempt: import time from datetime import datetime from unittest import TestCase def timestamp(dttm): return time.mktime(dttm.timetuple()) class Test(TestCase): def check(self,*args): epoch = datetime.utcfromtimestamp(0) dt = datetime(*args) actual = timestamp(dt) d = dt - epoch expected = d.seconds + 60*60*24*d.days self.assertEquals(expected,actual, '%s != %s (diff %s)'%(expected,actual,expected-actual)) def test_xmas(self): self.check(2009, 12, 25, 1, 2, 3, 456789) def test_midsummer(self): self.check(2009, 6, 21, 2, 3, 4, 5678) For me, test_midsummer fails. I'd be interested in knowing wheher both tests pass for other people. I'd be *more* interested in knowing either why the timestamp function or the tests are wrong and how to correct them... cheers, Chris From pruebauno at latinmail.com Tue Mar 16 09:48:11 2010 From: pruebauno at latinmail.com (nn) Date: Tue, 16 Mar 2010 06:48:11 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: <53f1fd53-7f83-418d-b3f8-ced6f2e929af@g10g2000yqh.googlegroups.com> david jensen wrote: > ... and of course i screwed up my outcomes... that should read > outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] For starters: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder = myList[not low_id]-myList[low_id] tail=myList[2:] outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)] + tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] return outcomes From clp2 at rebertia.com Tue Mar 16 09:57:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 06:57:14 -0700 Subject: what's the diffence between "RECENT" and "UNSEEN" in imaplib? In-Reply-To: <2583d700-db3c-4291-ae18-46f96b02a92d@s25g2000prd.googlegroups.com> References: <2583d700-db3c-4291-ae18-46f96b02a92d@s25g2000prd.googlegroups.com> Message-ID: <50697b2c1003160657g22596349j5f4fb83382e90266@mail.gmail.com> On Tue, Mar 16, 2010 at 5:53 AM, freakrobot wrote: > When I work with the imaplib, > there is a imap4.status(mailboxname, '(MESSAGES RECENT UNSEEN)') > function. > > So I really wonder what's the difference between RECENT and UNSEEN > conditions. > And what kind of messages belong to RECENT condition? A. Your question is not Python-specific and would better have been asked somewhere more relevant. B. RTFRFC: http://www.faqs.org/rfcs/rfc3501.html """ UNSEEN The number of messages which do not have the \Seen flag set. [...] \Seen Message has been read \Recent Message is "recently" arrived in this mailbox. This session is the first session to have been notified about this message; if the session is read-write, subsequent sessions will not see \Recent set for this message. This flag can not be altered by the client. If it is not possible to determine whether or not this session is the first session to be notified about a message, then that message SHOULD be considered recent. If multiple connections have the same mailbox selected simultaneously, it is undefined which of these connections will see newly-arrived messages with \Recent set and which will see it without \Recent set. """ Regards, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Tue Mar 16 10:13:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 07:13:04 -0700 Subject: converting a timezone-less datetime to seconds since the epoch In-Reply-To: <4B9F8BE0.2050808@simplistix.co.uk> References: <4B9F8BE0.2050808@simplistix.co.uk> Message-ID: <50697b2c1003160713x7641d2cfn52a5e5ca199e26de@mail.gmail.com> On Tue, Mar 16, 2010 at 6:47 AM, Chris Withers wrote: > Hi All, > > We have a bunch of datetime objects that have tzinfo=None. > We want to turn them into float timestamps in seconds since the epoch. > > Here's the first attempt: > > import time > from datetime import datetime > from unittest import TestCase > > def timestamp(dttm): > ? ?return time.mktime(dttm.timetuple()) from calendar import timegm def timestamp(dttm): return timegm(dttm.utctimetuple()) #the *utc*timetuple change is just for extra consistency #it shouldn't actually make a difference here And problem solved. As for what the problem was: Paraphrasing the table I got added to the time module docs: (http://docs.python.org/library/time.html) To convert from struct_time in ***UTC*** to seconds since the epoch use calendar.timegm() To convert struct_time in ***local*** time to seconds since the epoch use time.mktime() > I'd be *more* interested in knowing either why the timestamp function or the > tests are wrong and how to correct them... You used a function intended for local times on UTC time data, and therefore got incorrect results. Cheers, Chris -- Entering the workforce in 2012 http://blog.rebertia.com From invalid at invalid.invalid Tue Mar 16 10:20:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 16 Mar 2010 14:20:26 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-16, Steven D'Aprano wrote: >> Though it may not be Microsoft Word, I think I'd still maintain that >> an editor where you can't see a ctrl-Z or tell the difference between >> an ASCII minus and a windows-codepage-whatever isn't a very good >> programmer's editor. > > Regarding ctrl-Z (or for that matter other control characters), I > agree it's a lack. > > As for not being able to see the difference between a hyphen and an > EN- dash, or minus sign, or whatever it is, yes but they are very > similar looking glyphs in virtually ever modern font. It would take a > good eye to see the difference between (say) ??? ??? and -. My point is that if it's an ASCII file, then rendering \x96 as an em-dash isn't correct. I'd expect it to show up highlighted somehow in hex or octal so that I know it's a non-ASCII character. -- Grant Edwards grant.b.edwards Yow! We are now enjoying at total mutual interaction in gmail.com an imaginary hot tub ... From steve at holdenweb.com Tue Mar 16 10:24:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 10:24:36 -0400 Subject: C-API PyObject_Call In-Reply-To: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: moerchendiser2k3 wrote: > Hi, > > i have a serious problem and I am looking for a solution. I pass an > instance of a class from a file to PyObject_Call. When something > fails, I get a full traceback. If it succeeds, I get the return value. > > Is it possible to get information from which line/file the return > value of PyObject_Call is? > > Thanks!! > > moerchendiser2k3 You'll need to use a debugger like gdb that gives you access to the C stack, I believe. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From Ron.Barak at lsi.com Tue Mar 16 10:26:50 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 14:26:50 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> Thanks for the suggestion Pable. However, I really need the $PYTHONPATH to include this additional library, so all Python scripts could use it. In Windows I have defined PYTHONPATH as c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the Windows registry I have HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk; However, even with all the above, the SVMInspecor modules are not found. Bye, Ron. ________________________________ From: Pablo Recio Quijano [mailto:rikutheronin at gmail.com] Sent: Tuesday, March 16, 2010 2:27 PM To: python-list at python.org Subject: Re: How to add a library path to pythonpath ? You have to add yout path to the list: import sys sys.path.append(your_path) Jus simple to add the element on the list :) 2010/3/16 Barak, Ron > Hi, I'm trying to add a library path to my pythonpath, but seems it is not accepted - On Windows DOS window: C:\>echo %PYTHONPATH% c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ C:\>python -c "import sys ; print sys.path" ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] C:\> On Windows cygwin: $ echo $PYTHONPATH .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ $ python -c "import sys ; print sys.path" ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] $ What am I doing wrong ? Thanks, Ron. -- http://mail.python.org/mailman/listinfo/python-list -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From grflanagan at gmail.com Tue Mar 16 10:28:17 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Tue, 16 Mar 2010 14:28:17 +0000 Subject: Searching for most pythonic/least stupid way to do something simple In-Reply-To: References: Message-ID: david jensen wrote: > ... and of course i screwed up my outcomes... that should read > outcomes=[[4,3,8,3,5],[3,4,8,3,5],[2,5,8,3,5],[1,6,8,3,5],[0,7,8,3,5]] > > > abstracting the given algorithm: def iterweights(N): d = 1.0/(N-1) for i in xrange(N): yield i*d, (N-1-i)*d def iterparts(x0, x1, N): a = min(x0, x1) b = max(x0, x1) s = 2 * a t = b - a for m, n in iterweights(N): if a == x0: yield s*m, s*n+t else: yield s*n+t, s*m for p in iterparts(2, 5, 5): print p print for p in iterparts(5, 2, 5): print p (0.0, 7.0) (1.0, 6.0) (2.0, 5.0) (3.0, 4.0) (4.0, 3.0) (7.0, 0.0) (6.0, 1.0) (5.0, 2.0) (4.0, 3.0) (3.0, 4.0) From Dieter.Faulbaum at bessy.de Tue Mar 16 10:30:51 2010 From: Dieter.Faulbaum at bessy.de (Dieter Faulbaum) Date: Tue, 16 Mar 2010 15:30:51 +0100 Subject: cycling through options Message-ID: Hello, is there a better way for cycling through all options than this: (options, args) = parser.parse_args() for opt in options.__dict__.keys(): print opt, ":", options.__dict__[opt] Thanks for any nicer solution -- Dieter Faulbaum From steve at holdenweb.com Tue Mar 16 10:31:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 10:31:02 -0400 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Message-ID: Barak, Ron wrote: > Hi, > > I'm trying to add a library path to my pythonpath, but seems it is not > accepted - > > On Windows DOS window: > > C:\>echo %PYTHONPATH% > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > That looks like it should work. The only thing I notice is that I don't have a trailing backslash on my Windows PYTHONPATH. Could that be the problem? regards Steve > C:\>python -c "import sys ; print sys.path" > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\syst > em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', > 'C:\\Python26\\l > ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', > 'C:\\Python26\\lib\\ > site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > C:\> > > On Windows cygwin: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > $ python -c "import sys ; print sys.path" > ['', > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > 'c:\\Python26\\lib\\site-packages', > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > $ > > What am I doing wrong ? > > Thanks, > Ron. > > > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From davea at ieee.org Tue Mar 16 11:03:44 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Mar 2010 10:03:44 -0500 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> Message-ID: <4B9F9DD0.2080306@ieee.org> Barak, Ron wrote: > Thanks for the suggestion Pable. > > However, I really need the $PYTHONPATH to include this additional library, so all Python scripts could use it. > > In Windows I have defined PYTHONPATH as c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the Windows registry I have > > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk; > > However, even with all the above, the SVMInspecor modules are not found. > > See my response at the end. Top-posting makes for a very confusing thread. > > > 2010/3/16 Barak, Ron > > > Hi, > > I'm trying to add a library path to my pythonpath, but seems it is not accepted - > > On Windows DOS window: > > C:\>echo %PYTHONPATH% > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > > C:\>python -c "import sys ; print sys.path" > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\syst > em32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\l > ib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ > site-packages', 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > C:\> > > On Windows cygwin: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > $ python -c "import sys ; print sys.path" > ['', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > $ > > What am I doing wrong ? > > Thanks, > Ron. > > > In your original message, what you displayed worked exactly as expected. As you didn't say what made you think something was wrong, I ignored the message. Now, you say that some modules are not found. So how about giving some more specifics so someone can actually debug the problem. Pick a particular module, tell us the complete path to that module, and show us both the sys.path strings (which look correct for the Windows case, and of course bogus for the cygwin case), as well as the offending import statement and its traceback. DaveA From robert.kern at gmail.com Tue Mar 16 11:06:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Mar 2010 10:06:10 -0500 Subject: class inheritance In-Reply-To: <4B9F7B2A.1080906@ieee.org> References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> <4B9F7B2A.1080906@ieee.org> Message-ID: On 2010-03-16 07:35 AM, Dave Angel wrote: > > > Carl Banks wrote: >> On Mar 15, 4:34 pm, JLundell wrote: >>> It's also unfortunate that Python doesn't have an approximately-equal >>> operator; it'd come in handy for floating-point applications while >>> preserving hash. If only there were a ~=r ? operator I could >>> overload. And ~ is unary, so no joy. >> >> One problem with it is that there's no way to make it universal; >> different appiplications have different ideas of close. Conceivably >> it could be usefully defined for a user type though.. >> >> Bacause of this problem almost no languages have an almost equal >> operator. I'm curious what languages do, of if there are any with a >> trinary operator that also takes a threshold. >> >> Carl Banks >> > If I recall correctly, APL has a *fuzz* value, which is used in all(?) > comparisons. But I do not recall anything about how it was defined. I do > recall that you could change the threshold, and suspect it was relative > to the operands. For symmetry, it would probably have to be relative to > the average of the two values, or some such. The problem is that frequently there is no system-wide fuzz value which is appropriate for all comparisons in a given program. You need to choose the right value for each comparison. Consequently, you might as well use a function instead of an operator and a global variable. -- 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 From no.email at nospam.invalid Tue Mar 16 11:09:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 16 Mar 2010 08:09:37 -0700 Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: <7xmxy87172.fsf@ruckus.brouhaha.com> david jensen writes: > Obviously, i can just write the code again, in an else, switching > indices 0 and 1. Or, I could just have a test at the beginning, switch > them if they are in the order "big, small", and then switch them again > at the end in a list comprehension. Both ideas seem terribly silly, > and there must be an obvious way to do it that I'm not seeing. Generally when faced with this kind of question, see if you can use the built-in min and max functions: def getOutcomes(): outcomes=[] smaller = min(myList[0], myList[1]) bigger = max(myList[0], myList[1]) amountToShare=2*smaller remainder = bigger - smaller ... From dmj.ccc at gmail.com Tue Mar 16 11:21:41 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 08:21:41 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: Message-ID: <05fe1942-231f-4674-a55a-77ebca451da6@g4g2000yqa.googlegroups.com> Thank you both very much! Yeah: it was a total brainfart on my part: nn's solution should have been obvious. As the general solution, i like your approach, Gerard, but I think I'll stick to nn's, the one i should have written. Again, thank you both! dmj From Ron.Barak at lsi.com Tue Mar 16 11:25:16 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Tue, 16 Mar 2010 15:25:16 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <4B9F9DD0.2080306@ieee.org> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> > -----Original Message----- > From: Dave Angel [mailto:davea at ieee.org] > Sent: Tuesday, March 16, 2010 5:04 PM > To: Barak, Ron > Cc: Pablo Recio Quijano; python-list at python.org > Subject: RE: How to add a library path to pythonpath ? > > > > Barak, Ron wrote: > > Thanks for the suggestion Pable. > > > > However, I really need the $PYTHONPATH to include this > additional library, so all Python scripts could use it. > > > > In Windows I have defined PYTHONPATH as > > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the > > Windows registry I have > > > > > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as > > > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn > > spector\lib\;C:\Python26\Lib\lib-tk; > > > > However, even with all the above, the SVMInspecor modules > are not found. > > > > > See my response at the end. Top-posting makes for a very > confusing thread. > > > > > > 2010/3/16 Barak, Ron > > > > > Hi, > > > > I'm trying to add a library path to my pythonpath, but > seems it is not > > accepted - > > > > On Windows DOS window: > > > > C:\>echo %PYTHONPATH% > > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > > > > C:\>python -c "import sys ; print sys.path" > > ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > > 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', > > 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', > > 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ > > site-packages', > > 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > > > C:\> > > > > On Windows cygwin: > > > > $ echo $PYTHONPATH > > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > > > $ python -c "import sys ; print sys.path" > > ['', > > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > > 'c:\\Python26\\lib\\site-packages', > > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > > > $ > > > > What am I doing wrong ? > > > > Thanks, > > Ron. > > > > > > > In your original message, what you displayed worked exactly > as expected. As you didn't say what made you think something > was wrong, I ignored the message. > > Now, you say that some modules are not found. So how about > giving some more specifics so someone can actually debug the > problem. Pick a particular module, tell us the complete path > to that module, and show us both the sys.path strings (which > look correct for the Windows case, and of course bogus for > the cygwin case), as well as the offending import statement > and its traceback. > > DaveA Hi Dave, My Python is the Windows Python (I need this for wxPython): $ ls -ls `which python` 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 /usr/bin/python -> /cygdrive/c/Python26/python.exe Here's a demo script: #!/usr/bin/env python import sys print "\n",sys.path,"\n" from ErrorManager.ErrorManager import ErrorManager And it's run produces: $ python -u tmp.py ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] Traceback (most recent call last): File "tmp.py", line 6, in from ErrorManager.ErrorManager import ErrorManager ImportError: No module named ErrorManager.ErrorManager $ ls -ls /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py $ grep ErrorManager /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ ErrorManager/ErrorManager.py class ErrorManager: $ echo $PYTHONPATH .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ Please let me know if the above is enough, or you'd like to see the results from a Windows' DOS window. Thanks, Ron. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sam.bancal at gmail.com Tue Mar 16 11:40:29 2010 From: sam.bancal at gmail.com (samb) Date: Tue, 16 Mar 2010 08:40:29 -0700 (PDT) Subject: affectation in if statement References: <5c361012-1f7b-487f-915b-0f564b238be3@e1g2000yqh.googlegroups.com> <8680128a-70a8-4dae-869b-108203be781c@y17g2000yqd.googlegroups.com> Message-ID: <0e235861-54bc-4e0f-bfa1-7472dae8cbc4@30g2000yqi.googlegroups.com> On Mar 16, 11:56?am, Jean-Michel Pichavant wrote: > samb wrote: > > Hi, > > > I've found a work around, inspired from Rob Williscroft : > > > class ReMatch(object): > > ? ? """ > > ? ? ? ? Object to be called : > > ? ? ? ? 1st time : do a regexp.match and return the answer (args: > > regexp, line) > > ? ? ? ? 2nd time : return the previous result (args: prev) > > ? ? """ > > ? ? def __call__(self, regexp='', line='', prev=False): > > ? ? ? ? if prev: > > ? ? ? ? ? ? return self.prev_match > > ? ? ? ? self.prev_match = re.match(regexp, line) > > ? ? ? ? return self.prev_match > > > re_match = ReMatch() > > > if re_match(r'define\s+(\S+)\s*{$', line): > > ? ? m = re_match(prev=True) > > ? ? # do some logic with m > > elif re_match(r'include\s+(\S+)$', line): > > ? ? m = re_match(prev=True) > > ? ? # do some logic with m > > else > > ? ? # do some logic > > > Hope this is efficient ... I guess yes. > > > Cheers, > > Sam > > What do you mean by efficient ? If you're talking about speed, make sure > you care about it before doing some optimization. > If you talk about readability then it is absolutely *not* efficient (to > my humble opinion). > > define, include = re.match(r'define\s+(\S+)\s*{$', line), > re.match(r'include\s+(\S+)$', line) > if define: > ? ? # do some stuff > elif include: > ? ? # do some other stuff > else: > ? ? # hello world > > If you then have some speed problem with that script, you'll start > caring about how to execute if faster by making sure that only necessary > calls to re.match are done. > > match = re.match(r'(define)\s+(\S+)\s*{$', line) or > re.match(r'(include)\s+(\S+)$', line) # note that the second operand is > executed only if the first is None > > if match.group(1) == 'define': > ? ? # do some stuff with match.group(2) > > elif match.group(1) == 'include': > ? ? # do some other stuff with match.group(2) > > else: > ? ? # hello world > > JM Hi, Thanks Bruno for the simpler API! And thanks Jean-Michel, your second suggestion is clearly the best I see. I meant efficient mainly in the readable aspect (important for future maintenance) and secondary for speed of execution. For sure I didn't want to run a regexp twice. Regards, Sam From lists at cheimes.de Tue Mar 16 11:56:28 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Mar 2010 16:56:28 +0100 Subject: How to add a library path to pythonpath ? In-Reply-To: References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> Message-ID: <4B9FAA2C.3060806@cheimes.de> Steve Holden schrieb: > Barak, Ron wrote: >> Hi, >> >> I'm trying to add a library path to my pythonpath, but seems it is not >> accepted - >> >> On Windows DOS window: >> >> C:\>echo %PYTHONPATH% >> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ >> > That looks like it should work. The only thing I notice is that I don't > have a trailing backslash on my Windows PYTHONPATH. Could that be the > problem? Yes, that's definitely a major issue on Windows. Windows' stat() method returns an error for paths with a trailing (back)slash. For example _stat("C:\\Windows") works but _stat("C:\\Windows\\") sets errno to ENOENT or ENOTDIR. I got bitten by the issue a couple of years ago as I worked on pars of Python's import system. Quoting Tim Peters: [1] The Microsoft stat() function is extremely picky about trailing (back)slashes. For example, if you have a directory c:/python, and pass "c:/python/" to the MS stat (), it claims no such thing exists. This isn't documented by MS, but that's how it works: a trailing (back)slash is required if and only if the path passed in "is a root". So MS stat() doesn't understand "/python/", and doesn't understand "d:" either. The former doesn't tolerate a (back)slash, while the latter requires one. Christian [1] http://mail.python.org/pipermail/python-bugs-list/2002-April/011099.html From googler.1.webmaster at spamgourmet.com Tue Mar 16 12:08:22 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 09:08:22 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: <92d7720e-b8cc-4f41-8191-17c078911909@m37g2000yqf.googlegroups.com> But the stack is empty after PyObject_Call, isnt it? From phlip2005 at gmail.com Tue Mar 16 12:12:08 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Mar 2010 09:12:08 -0700 (PDT) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <7284f1df-100e-4fed-aed2-20b114040d64@v34g2000prm.googlegroups.com> Chris Rebert wrote: > The next closest thing would probably be the Python Cookbook:http://code.activestate.com/recipes/langs/python/ One thing I really like about ... my hacked version of path.py ... is path.cd( lambda: ... ). It works great inside fabfile.py to temporarily switch to a different folder: sample_project = path('sample_project').abspath() def run(): sample_project.cd( lambda: _sh('python manage.py runserver 0.0.0.0:8000 -- settings=test_settings') ) After the lambda runs, we exception-safely return to the home folder. (BTW I'm aware that a fabfile.py command with only one statement will return to its shell and remain in the correct folder. It's just ... the thought!) This be .cd(): class path: def cd(self, block=None): previous = path(os.path.curdir).abspath() self.chdir() if block: try: block() finally: previous.chdir() That's based on Jason Orendoff's work at http://www.jorendorff.com/articles/python/path -- Phlip http://c2.com/cgi/wiki?ZeekLand From stefan_ml at behnel.de Tue Mar 16 12:17:02 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 17:17:02 +0100 Subject: C-API PyObject_Call In-Reply-To: <92d7720e-b8cc-4f41-8191-17c078911909@m37g2000yqf.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <92d7720e-b8cc-4f41-8191-17c078911909@m37g2000yqf.googlegroups.com> Message-ID: moerchendiser2k3, 16.03.2010 17:08: > But the stack is empty after PyObject_Call, isnt it? I think Steve was expecting that you wanted to debug into your program, step into the call, and find the line yourself. Stefan From stefan_ml at behnel.de Tue Mar 16 12:18:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 16 Mar 2010 17:18:01 +0100 Subject: C-API PyObject_Call In-Reply-To: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: moerchendiser2k3, 16.03.2010 12:52: > i have a serious problem and I am looking for a solution. I pass an > instance of a class from a file to PyObject_Call. When something > fails, I get a full traceback. If it succeeds, I get the return value. > > Is it possible to get information from which line/file the return > value of PyObject_Call is? Could you explain what you want to do with this information and in what cases you need it? Do you want to extract the information programmatically at runtime? Stefan From python at hope.cz Tue Mar 16 12:20:40 2010 From: python at hope.cz (Johny) Date: Tue, 16 Mar 2010 09:20:40 -0700 (PDT) Subject: Python bindings tutorial Message-ID: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Is there any tutorial how to write a bindings for a exe ( dos) program? I would like to run it from a Python directly ( using import command and a particular function from the binding) not using os.system command. Thanks L. From davea at ieee.org Tue Mar 16 12:23:54 2010 From: davea at ieee.org (Dave Angel) Date: Tue, 16 Mar 2010 11:23:54 -0500 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> Message-ID: <4B9FB09A.7030609@ieee.org> Barak, Ron wrote: > >> -----Original Message----- >> From: Dave Angel [mailto:davea at ieee.org] >> Sent: Tuesday, March 16, 2010 5:04 PM >> To: Barak, Ron >> Cc: Pablo Recio Quijano; python-list at python.org >> Subject: RE: How to add a library path to pythonpath ? >> >> >> >> Barak, Ron wrote: >> >>> Thanks for the suggestion Pable. >>> >>> However, I really need the $PYTHONPATH to include this >>> >> additional library, so all Python scripts could use it. >> >>> In Windows I have defined PYTHONPATH as >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the >>> Windows registry I have >>> >>> >>> >> HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as >> >> C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn >> >>> spector\lib\;C:\Python26\Lib\lib-tk; >>> >>> However, even with all the above, the SVMInspecor modules >>> >> are not found. >> >>> >> See my response at the end. Top-posting makes for a very >> confusing thread. >> >>> >>> >>> 2010/3/16 Barak, Ron > >>> >>> Hi, >>> >>> I'm trying to add a library path to my pythonpath, but >>> >> seems it is not >> >>> accepted - >>> >>> On Windows DOS window: >>> >>> C:\>echo %PYTHONPATH% >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ >>> >>> C:\>python -c "import sys ; print sys.path" >>> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >>> 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', >>> 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', >>> 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ >>> site-packages', >>> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>> >>> C:\> >>> >>> On Windows cygwin: >>> >>> $ echo $PYTHONPATH >>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >>> >>> $ python -c "import sys ; print sys.path" >>> ['', >>> >>> >> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >> >>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', >>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', >>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', >>> 'c:\\Python26\\lib\\site-packages', >>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>> >>> $ >>> >>> What am I doing wrong ? >>> >>> Thanks, >>> Ron. >>> >>> >>> >>> >> In your original message, what you displayed worked exactly >> as expected. As you didn't say what made you think something >> was wrong, I ignored the message. >> >> Now, you say that some modules are not found. So how about >> giving some more specifics so someone can actually debug the >> problem. Pick a particular module, tell us the complete path >> to that module, and show us both the sys.path strings (which >> look correct for the Windows case, and of course bogus for >> the cygwin case), as well as the offending import statement >> and its traceback. >> >> DaveA >> > > Hi Dave, > > My Python is the Windows Python (I need this for wxPython): > > $ ls -ls `which python` > 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 /usr/bin/python -> /cygdrive/c/Python26/python.exe > > Here's a demo script: > > #!/usr/bin/env python > > import sys > print "\n",sys.path,"\n" > > from ErrorManager.ErrorManager import ErrorManager > > And it's run produces: > > $ python -u tmp.py > > ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > Traceback (most recent call last): > File "tmp.py", line 6, in > from ErrorManager.ErrorManager import ErrorManager > ImportError: No module named ErrorManager.ErrorManager > > $ ls -ls /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py > 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py > > $ grep ErrorManager /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > ErrorManager/ErrorManager.py > class ErrorManager: > > $ echo $PYTHONPATH > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > Please let me know if the above is enough, or you'd like to see the results from a Windows' DOS window. > > Thanks, > Ron. > > Well, I pointed out that your cygwin path is bogus, so of course it won't work. One of those entries is '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib' I use Linux, and I use Windows. But cygwin's glomming together has never made sense; some things are Unix-like, and others are Windows-like. So anything you do in that environment is beyond me. If I had to guess, though I'd say you wanted to drop those first two characters from your PYTHONPATH. If you really wanted two directories there, you should be separating them with semicolon (Windows rules), rather than colon (Linux rules). First thing I'd do to test my theories is to print something like: print sys.path[1] print os.listdir(sys.path[1]) Does Python even see the cygwin view of the world ? You also don't show the location of the module you're trying to import. I'm guessing that it's at ...SVMInspector/lib/ErrorManager/ErrorManager.py Do you have a file ...SVMInspector/lib/ErrorManager/__init__.py ? I would seriously recommend against naming your package, your module, and your class all the same thing. Makes debugging very hard. At least make them have different case combinations. DaveA From s.selvamsiva at gmail.com Tue Mar 16 12:31:25 2010 From: s.selvamsiva at gmail.com (S.Selvam) Date: Tue, 16 Mar 2010 22:01:25 +0530 Subject: web sound recording with python In-Reply-To: <4acee8d1$0$919$ba4acef3@news.orange.fr> References: <7676a0f3-5126-4930-af07-0b3cb737dffc@m33g2000pri.googlegroups.com> <4acee8d1$0$919$ba4acef3@news.orange.fr> Message-ID: On Fri, Oct 9, 2009 at 1:10 PM, Michel Claveau - MVP wrote: > Hi! > > On windows, you can record sound who play on the local sound-card. > It is not really Python scripting, but Python can launch it. > Does python do not have support for voice recording ? -- Regards, S.Selvam " I am because we are " -------------- next part -------------- An HTML attachment was scrubbed... URL: From dmj.ccc at gmail.com Tue Mar 16 12:31:36 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 09:31:36 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> Message-ID: <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> Thanks Paul, but i don't immediately see how that helps (maybe I'm just being dense)... nn's solution, though i initially thought it worked, actually has a similar problem: intended: >>> print getOutcomes([3,4,5,5]) [[6, 1, 5, 5], [4.5, 2.5, 5, 5], [3, 4, 5, 5], [1.5, 5.5, 5, 5], [0, 7, 5, 5]] >>> print getOutcomes([4,3,5,5]) [[7, 0, 5, 5], [5.5, 1.5, 5, 5], [4, 3, 5, 5], [2.5, 4.5, 5, 5], [1, 6, 5, 5]] nn's solution: >>> print getOutcomesNN([4,3,5,5]) [[6.0, 1.0, 5, 5], [4.5, 2.5, 5, 5], [3.0, 4.0, 5, 5], [1.5, 5.5, 5, 5], [0.0, 7.0, 5, 5]] it's obvious why this is happening (the list comprehension assumes that index 0 is, after all, index 0), but not immediately obvious how to fix it, except by going with gerard's solution or doing what i did in the beginning: flip them if they're in the wrong order, remember, and flip them again at the end. dmj From googler.1.webmaster at spamgourmet.com Tue Mar 16 12:41:16 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 09:41:16 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> Message-ID: <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> In one case I have to check the return value of PyObject_Call, and if its not of the correct return value, I throw an exception, but I just get a simple output: TypeError: Expected an instance of XYZ, no int. instead of Traceback (most called...) TypeError: in line 3, file test.py: expected an instance of XYZ, no int... From jackdied at gmail.com Tue Mar 16 12:49:59 2010 From: jackdied at gmail.com (Jack Diederich) Date: Tue, 16 Mar 2010 12:49:59 -0400 Subject: Dynamic Class Creation In-Reply-To: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> References: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> Message-ID: On Tue, Mar 16, 2010 at 2:18 AM, Chris Rebert wrote: > On Mon, Mar 15, 2010 at 11:01 PM, Josh English > wrote: >> I have a large program with lots of data stored in XML. I'm upgrading >> my GUI to use ObjectListView, but with my data in XML, I don't have >> regular objects to interact with the OLV. I do have an XML validator >> that defines the structure of the XML elements, and I'm trying to >> dynamically create a class to wrap the XML element. >> >> So, an element like: >> >> >> Writers of the Future >> >> >> I want to create a class like: >> >> class Market(object): >> ? ?def __init__(self, elem): >> ? ? ? ?self._elem = elem >> >> ? ?def get_code(self): >> ? ? ? ?return self._elem.get('code') >> >> ? ?def set_code(self, value): >> ? ? ? ?self._elem.set('code', value) >> >> ? ?def get_title(self): >> ? ? ? ?return self._elem.find('title').text >> >> ? ?def set_title(self, value): >> ? ? ? ?node = self._elem.find('title') >> ? ? ? ?node.text = value >> >> Naturally, I don't want to hand code this for every interface but >> would like to create them dynamically. (The laziness of programming, I >> guess.) >> >> What's the best way to create these helper methods? You can either define a catch-all __getattr__ method to look them up dynamically, or as Chris kinda-suggested write descriptors for the individual elements. class Market(): def __init__(self, elem): self._elem = elem def __getattr__(self, name): try: # I'm assuming this raises a KeyError when not found return self._elem.get(name) except KeyError: return self._elem.find(name) def __setitem__(self, name, value): # like __getitem__ but for setting Chris' property maker function is almost like a descriptor class (how properties are implemented under the hood), here's a refactoring [untested] class ElemGetProperty(): def __init__(self, name): self.name = name def __get__(self, ob, cls): return ob._elem.get(self.name) def __set__(self, ob, val): ob._elem.set(self.name, val) You could write one property class for each kind of element (get/find) and then put them in your class like this class Market(): code = ElemGetProperty('code') title = ElemFindProeprty('title') The getattr/setattr method is easier to understand and will handle arbitrary elements; for the descriptors version you'll have to define one for each tag that might be used on the class. -Jack From clp2 at rebertia.com Tue Mar 16 12:53:37 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Mar 2010 09:53:37 -0700 Subject: Dynamic Class Creation In-Reply-To: References: <50697b2c1003152318t7b9cd692pcf11ca45bbe1f041@mail.gmail.com> Message-ID: <50697b2c1003160953l209c21ddm5b9c0d960a6f2@mail.gmail.com> On Tue, Mar 16, 2010 at 9:49 AM, Jack Diederich wrote: > On Tue, Mar 16, 2010 at 2:18 AM, Chris Rebert wrote: >> On Mon, Mar 15, 2010 at 11:01 PM, Josh English >> wrote: >>> What's the best way to create these helper methods? > > You can either define a catch-all __getattr__ method to look them up > dynamically, or as Chris kinda-suggested write descriptors for the > individual elements. > > class Market(): > ?def __init__(self, elem): > ? ?self._elem = elem > ?def __getattr__(self, name): > ? ?try: > ? ? ?# I'm assuming this raises a KeyError when not found > ? ? ?return self._elem.get(name) > ? ?except KeyError: > ? ? ?return self._elem.find(name) > ?def __setitem__(self, name, value): did you mean __setattr__ here? > The getattr/setattr method is easier to understand and will handle > arbitrary elements; ?for the descriptors version you'll have to define > one for each tag that might be used on the class. Cheers, Chris -- http://blog.rebertia.com From dmj.ccc at gmail.com Tue Mar 16 12:54:57 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 09:54:57 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> Message-ID: <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> of course, changing nn's to: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) amountToShare = 2*myList[low_id] remainder = myList[not low_id]-myList[low_id] tail=list(myList[2:]) outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] return outcomes works, just hides the ugliness in a more compact form From martin.schmidt1 at gmail.com Tue Mar 16 12:56:15 2010 From: martin.schmidt1 at gmail.com (Martin Schmidt) Date: Tue, 16 Mar 2010 11:56:15 -0500 Subject: Python-list Digest, Vol 78, Issue 161 In-Reply-To: References: Message-ID: <5444f9711003160956l316a07dfs89f4f418e7528f20@mail.gmail.com> Thanks, Stefan. Actually I will have to run the searches I am interested in only a few times and therefore will drop performance concerns. Thanks for len(text.split()) . I will try it later. The text I am interested in is always in leaf elements. I have posted a concrete example incl. a representative XML file a few minutes ago. I hope this clarifies my problem. Rereading what I wrote sounds admittedly funnny. What I meant that I did not find a post that closely matches my problem (I know that the closeness needed in my case will seem excessive to more experienced Python/XML users). Best regards. Martin P.S. Sorry for my late reply, but my Internet connection was down for a day. > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Tue, 16 Mar 2010 08:50:30 +0100 > Subject: Re: extract occurrence of regular expression from elements of XML > documents > Martin Schmidt, 15.03.2010 18:16: > >> I have just started to use Python a few weeks ago and until last week I >> had >> no knowledge of XML. >> Obviously my programming knowledge is pretty basic. >> Now I would like to use Python in combination with ca. 2000 XML documents >> (about 30 kb each) to search for certain regular expression within >> specific >> elements of these documents. >> > > 2000 * 30K isn't a huge problem, that's just 60M in total. If you just have > to do it once, drop your performance concerns and just get a solution going. > If you have to do it once a day, take care to use a tool that is not too > resource consuming. If you have strict requirements to do it once a minute, > use a fast machine with a couple of cores and do it in parallel. If you have > a huge request workload and want to reverse index the XML to do all sorts of > sophisticated queries on it, use a database instead. > > > I would then like to record the number of occurrences of the regular >> expression within these elements. >> Moreover I would like to count the total number of words contained within >> these, >> > > len(text.split()) will give you those. > > BTW, is it document-style XML (with mixed content as in HTML) or is the > text always withing a leaf element? > > > and record the attribute of a higher level element that contains >> them. >> > > An example would certainly help here. > > > I was trying to figure out the best way how to do this, but got >> overwhelmed >> by the available information (e.g. posts using different approaches based >> on >> dom, sax, xpath, elementtree, expat). >> The outcome should be a file that lists the extracted attribute, the >> number >> of occurrences of the regular expression, and the total number of words. >> I did not find a post that addresses my problem. >> > > Funny that you say that after stating that you were overwhelmed by the > available information. > > > If someone could help me with this I would really appreciate it. >> > > Most likely, the solution with the best simplicity/performance trade-off > would be xml.etree.cElementTree's iterparse(), intercept on each interesting > tag name, and search its text/tail using the regexp. That's doable in a > couple of lines. > > But unless you provide more information, it's hard to give better advice. > > Stefan > > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: "Lawrence D'Oliveiro" > Date: Tue, 16 Mar 2010 00:52:07 -0700 > Subject: Re: import antigravity > On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro > wrote: > > Subtle... > > You're a bit behind the times. > If my calculations are right, that comic is over 2 years old. > > Cheers, > Chris > > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Tue, 16 Mar 2010 08:51:58 +0100 > Subject: Re: import antigravity > Lawrence D'Oliveiro, 16.03.2010 08:40: > >> Subtle... >> > > Absolutely. > > Python 2.4.6 (#2, Jan 21 2010, 23:45:25) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import antigravity > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named antigravity > > > Stefan > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 16 12:56:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 12:56:21 -0400 Subject: How to add a library path to pythonpath ? In-Reply-To: <4B9FB09A.7030609@ieee.org> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> <4B9FB09A.7030609@ieee.org> Message-ID: Dave Angel wrote: > Barak, Ron wrote: >> >>> -----Original Message----- >>> From: Dave Angel [mailto:davea at ieee.org] >>> Sent: Tuesday, March 16, 2010 5:04 PM >>> To: Barak, Ron >>> Cc: Pablo Recio Quijano; python-list at python.org >>> Subject: RE: How to add a library path to pythonpath ? >>> >>> >>> >>> Barak, Ron wrote: >>> >>>> Thanks for the suggestion Pable. >>>> >>>> However, I really need the $PYTHONPATH to include this >>>> >>> additional library, so all Python scripts could use it. >>> >>>> In Windows I have defined PYTHONPATH as >>>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the >>>> Windows registry I have >>>> >>>> >>>> >>> HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as >>> >>> C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn >>> >>>> spector\lib\;C:\Python26\Lib\lib-tk; >>>> >>>> However, even with all the above, the SVMInspecor modules >>>> >>> are not found. >>> >>>> >>> See my response at the end. Top-posting makes for a very >>> confusing thread. >>> >>>> >>>> >>>> 2010/3/16 Barak, Ron > >>>> >>>> Hi, >>>> >>>> I'm trying to add a library path to my pythonpath, but >>>> >>> seems it is not >>> >>>> accepted - >>>> >>>> On Windows DOS window: >>>> >>>> C:\>echo %PYTHONPATH% >>>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ >>>> >>>> C:\>python -c "import sys ; print sys.path" >>>> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >>>> 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', >>>> 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', >>>> 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ >>>> site-packages', >>>> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>>> >>>> C:\> >>>> >>>> On Windows cygwin: >>>> >>>> $ echo $PYTHONPATH >>>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >>>> >>>> $ python -c "import sys ; print sys.path" >>>> ['', >>>> >>>> >>> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >>> >>>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', >>>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', >>>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', >>>> 'c:\\Python26\\lib\\site-packages', >>>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >>>> >>>> $ >>>> >>>> What am I doing wrong ? >>>> >>>> Thanks, >>>> Ron. >>>> >>>> >>>> >>>> >>> In your original message, what you displayed worked exactly >>> as expected. As you didn't say what made you think something >>> was wrong, I ignored the message. >>> >>> Now, you say that some modules are not found. So how about >>> giving some more specifics so someone can actually debug the >>> problem. Pick a particular module, tell us the complete path >>> to that module, and show us both the sys.path strings (which >>> look correct for the Windows case, and of course bogus for >>> the cygwin case), as well as the offending import statement >>> and its traceback. >>> >>> DaveA >>> >> >> Hi Dave, >> >> My Python is the Windows Python (I need this for wxPython): >> >> $ ls -ls `which python` >> 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 /usr/bin/python -> >> /cygdrive/c/Python26/python.exe >> >> Here's a demo script: >> >> #!/usr/bin/env python >> >> import sys >> print "\n",sys.path,"\n" >> >> from ErrorManager.ErrorManager import ErrorManager >> >> And it's run produces: >> >> $ python -u tmp.py >> >> ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', >> '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', >> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', >> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', >> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', >> 'c:\\Python26\\lib\\site-packages', >> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] >> >> Traceback (most recent call last): >> File "tmp.py", line 6, in >> from ErrorManager.ErrorManager import ErrorManager >> ImportError: No module named ErrorManager.ErrorManager >> >> $ ls -ls >> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py >> >> 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 >> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager/ErrorManager.py >> >> >> $ grep ErrorManager >> /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >> ErrorManager/ErrorManager.py >> class ErrorManager: >> >> $ echo $PYTHONPATH >> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ >> >> Please let me know if the above is enough, or you'd like to see the >> results from a Windows' DOS window. >> >> Thanks, >> Ron. >> >> > Well, I pointed out that your cygwin path is bogus, so of course it > won't work. One of those entries is > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib' > > I use Linux, and I use Windows. But cygwin's glomming together has > never made sense; some things are Unix-like, and others are > Windows-like. So anything you do in that environment is beyond me. > > If I had to guess, though I'd say you wanted to drop those first two > characters from your PYTHONPATH. If you really wanted two directories > there, you should be separating them with semicolon (Windows rules), > rather than colon (Linux rules). First thing I'd do to test my theories > is to print something like: > print sys.path[1] > print os.listdir(sys.path[1]) > Does Python even see the cygwin view of the world ? > > You also don't show the location of the module you're trying to import. > I'm guessing that it's at ...SVMInspector/lib/ErrorManager/ErrorManager.py > Do you have a file ...SVMInspector/lib/ErrorManager/__init__.py ? > > I would seriously recommend against naming your package, your module, > and your class all the same thing. Makes debugging very hard. At least > make them have different case combinations. > In point of fact the mistake that's happening here is running the Windows Python under Cygwin and expecting it to make sense. Just because you run the Windows Python interpreter under Windows doesn't make it magically capable of understanding a Cygwin path specification. We have yet to hear why the Cygwin Python isn't acceptable (though one reason might be the unavailability of 2.6). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From martin.schmidt1 at gmail.com Tue Mar 16 12:58:00 2010 From: martin.schmidt1 at gmail.com (Martin Schmidt) Date: Tue, 16 Mar 2010 11:58:00 -0500 Subject: extract occurrence of regular expression from elements of XML documents Message-ID: <5444f9711003160958h6514141amcfa12fa4233c4c67@mail.gmail.com> On Tue, Mar 16, 2010 at 11:56 AM, Martin Schmidt wrote: > Thanks, Stefan. > Actually I will have to run the searches I am interested in only a few > times and therefore will drop performance concerns. > > Thanks for len(text.split()) . > I will try it later. > > The text I am interested in is always in leaf elements. > > I have posted a concrete example incl. a representative XML file a few > minutes ago. > I hope this clarifies my problem. > > Rereading what I wrote sounds admittedly funnny. > What I meant that I did not find a post that closely matches my problem (I > know that the closeness needed in my case will seem excessive to more > experienced Python/XML users). > > Best regards. > > Martin > > > P.S. Sorry for my late reply, but my Internet connection was down for a > day. > > > > >> ---------- Forwarded message ---------- >> From: Stefan Behnel >> To: python-list at python.org >> Date: Tue, 16 Mar 2010 08:50:30 +0100 >> Subject: Re: extract occurrence of regular expression from elements of XML >> documents >> Martin Schmidt, 15.03.2010 18:16: >> >>> I have just started to use Python a few weeks ago and until last week I >>> had >>> no knowledge of XML. >>> Obviously my programming knowledge is pretty basic. >>> Now I would like to use Python in combination with ca. 2000 XML documents >>> (about 30 kb each) to search for certain regular expression within >>> specific >>> elements of these documents. >>> >> >> 2000 * 30K isn't a huge problem, that's just 60M in total. If you just >> have to do it once, drop your performance concerns and just get a solution >> going. If you have to do it once a day, take care to use a tool that is not >> too resource consuming. If you have strict requirements to do it once a >> minute, use a fast machine with a couple of cores and do it in parallel. If >> you have a huge request workload and want to reverse index the XML to do all >> sorts of sophisticated queries on it, use a database instead. >> >> >> I would then like to record the number of occurrences of the regular >>> expression within these elements. >>> Moreover I would like to count the total number of words contained within >>> these, >>> >> >> len(text.split()) will give you those. >> >> BTW, is it document-style XML (with mixed content as in HTML) or is the >> text always withing a leaf element? >> >> >> and record the attribute of a higher level element that contains >>> them. >>> >> >> An example would certainly help here. >> >> >> I was trying to figure out the best way how to do this, but got >>> overwhelmed >>> by the available information (e.g. posts using different approaches based >>> on >>> dom, sax, xpath, elementtree, expat). >>> The outcome should be a file that lists the extracted attribute, the >>> number >>> of occurrences of the regular expression, and the total number of words. >>> I did not find a post that addresses my problem. >>> >> >> Funny that you say that after stating that you were overwhelmed by the >> available information. >> >> >> If someone could help me with this I would really appreciate it. >>> >> >> Most likely, the solution with the best simplicity/performance trade-off >> would be xml.etree.cElementTree's iterparse(), intercept on each interesting >> tag name, and search its text/tail using the regexp. That's doable in a >> couple of lines. >> >> But unless you provide more information, it's hard to give better advice. >> >> Stefan >> >> >> >> >> ---------- Forwarded message ---------- >> From: Chris Rebert >> To: "Lawrence D'Oliveiro" >> Date: Tue, 16 Mar 2010 00:52:07 -0700 >> Subject: Re: import antigravity >> On Tue, Mar 16, 2010 at 12:40 AM, Lawrence D'Oliveiro >> wrote: >> > Subtle... >> >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. >> >> Cheers, >> Chris >> >> >> >> ---------- Forwarded message ---------- >> From: Stefan Behnel >> To: python-list at python.org >> Date: Tue, 16 Mar 2010 08:51:58 +0100 >> Subject: Re: import antigravity >> Lawrence D'Oliveiro, 16.03.2010 08:40: >> >>> Subtle... >>> >> >> Absolutely. >> >> Python 2.4.6 (#2, Jan 21 2010, 23:45:25) >> [GCC 4.4.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import antigravity >> Traceback (most recent call last): >> File "", line 1, in ? >> ImportError: No module named antigravity >> >> >> Stefan >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Mar 16 13:00:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 13:00:36 -0400 Subject: equivalent of Ruby's Pathname? In-Reply-To: <7284f1df-100e-4fed-aed2-20b114040d64@v34g2000prm.googlegroups.com> References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> <7284f1df-100e-4fed-aed2-20b114040d64@v34g2000prm.googlegroups.com> Message-ID: Phlip wrote: > Chris Rebert wrote: > >> The next closest thing would probably be the Python Cookbook:http://code.activestate.com/recipes/langs/python/ > > One thing I really like about ... my hacked version of path.py ... is > path.cd( lambda: ... ). It works great inside fabfile.py to > temporarily switch to a different folder: > > sample_project = path('sample_project').abspath() > > def run(): > sample_project.cd( lambda: > _sh('python manage.py runserver 0.0.0.0:8000 -- > settings=test_settings') ) > > After the lambda runs, we exception-safely return to the home folder. > > (BTW I'm aware that a fabfile.py command with only one statement will > return to its shell and remain in the correct folder. It's just ... > the thought!) > > This be .cd(): > > class path: > > def cd(self, block=None): > previous = path(os.path.curdir).abspath() > self.chdir() > > if block: > try: block() > finally: previous.chdir() > > That's based on Jason Orendoff's work at http://www.jorendorff.com/articles/python/path > Wouldn't this be better written as a context manager? Be aware also that this won't work well in a multi-threaded environment (assuming os.path.chdir is ultimately used to change directories) because it effects the process's (globaL current directory. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mail.to.daniel.platz at googlemail.com Tue Mar 16 13:10:16 2010 From: mail.to.daniel.platz at googlemail.com (Daniel Platz) Date: Tue, 16 Mar 2010 10:10:16 -0700 (PDT) Subject: passing a socket to a subprocess in windows Message-ID: Hello! I have a problem with passing a socket to a subprocess in windows. It works in Linux and for windows there is a workaround in the Python doc. However, this workaround does not work. It was already noted by other people and they Python issue tracker http://bugs.python.org/issue5879 *************************************************************************************************************** the example from http://docs.python.org/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing named " # Example where a pool of http servers share a single listening socket # " does not work on windows. Reason: s = socket.fromfd(fd, family, type_, proto) in line 156 of reduction.py fails, because fromfd is not available on windows. Sad thing: reduction.py was put into processing.py exactly to solve that problem (i.e. reduction.py is provided as workaround for socket.fromfd not available on windows, from the documentation: if sys.platform == 'win32': import multiprocessing.reduction # make sockets pickable/inheritable the solution within processing was: try: fromfd = socket.fromfd except AttributeError: def fromfd(fd, family, type, proto=0): s = socket._socket.socket() _processing.changeFd(s, fd, family, type, proto) return s but: _multiprocessing has no longer a method changeFd. Harald *********************************************************************************************************************** Has someone information about this or can help me to solve the problem. Thanks in advance Daniel From steve at holdenweb.com Tue Mar 16 13:14:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Mar 2010 13:14:04 -0400 Subject: C-API PyObject_Call In-Reply-To: <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: moerchendiser2k3 wrote: > In one case I have to check the return value of PyObject_Call, and if > its not of the correct return value, > I throw an exception, but I just get a simple output: > > TypeError: Expected an instance of XYZ, no int. > > instead of > > Traceback (most called...) > TypeError: in line 3, file test.py: expected an instance of XYZ, no > int... Could we perhaps see a little bit more of the code? Are you throwing the exception from within your C code or from the Python calling environment with a raise statement? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at bdurham.com Tue Mar 16 13:18:15 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 16 Mar 2010 13:18:15 -0400 Subject: Converting Python CGI to WSGI scripts Message-ID: <1268759895.28810.1365130739@webmail.messagingengine.com> I have a few dozen simple Python CGI scripts. Are there any advantages or disadvantages to rewriting these CGI scripts as WSGI scripts? Apologies if my terminology is not correct ... when I say WSGI scripts I mean standalone scripts like the following simplified (as an example) template: import sys def application(environ, start_response): output = 'Welcome to your mod_wsgi website! It uses:\n\nPython %s' % sys.version response_headers = [ ('Content-Length', str(len(output))), ('Content-Type', 'text/plain'), ] start_response('200 OK', response_headers) return [output] When I say script I don't mean classic WSGI application in the sense of a .serve_forever() loop coordinating a bunch of related scripts - I mean individual, standalone scripts. Hope this makes sense :) Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From gatoygata2 at gmail.com Tue Mar 16 14:13:40 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 16 Mar 2010 11:13:40 -0700 (PDT) Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: <168167cf-c153-4e2b-8bca-5b9ae7afd67d@t23g2000yqt.googlegroups.com> On Mar 16, 5:20?pm, Johny wrote: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > ?not using os.system command. > Thanks > L. subprocess ? From gatoygata2 at gmail.com Tue Mar 16 14:14:50 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Tue, 16 Mar 2010 11:14:50 -0700 (PDT) Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: <92fa9d1d-d5a3-46b5-947b-12a0f338ee7e@t41g2000yqt.googlegroups.com> On Mar 16, 5:20?pm, Johny wrote: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > ?not using os.system command. > Thanks > L. subprocess ? From googler.1.webmaster at spamgourmet.com Tue Mar 16 14:25:25 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 11:25:25 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: Hi, currently I am not at home, I will post some stuff when I am back. Just the note: I throw an exception with the C API. Looks like that PyObject *result = PyObject_Call(my_isntance, "", NULL); if(result==NULL) { PyErr_Print(); //when this happens, the traceback is correct with information about the file/line return; } if(!PyXYZ_Check(result)) { PyErr_SetString(PyExc_TypeError, "Wrong type, ...."); PyErr_Print(); //missing information of the file/line. return; } Well, I expect, that there are no information about the line/file, so I know something is missing, but what is missing? Bye, moerchendiser2k3 From twistedphrame at gmail.com Tue Mar 16 14:56:30 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 16 Mar 2010 11:56:30 -0700 (PDT) Subject: datetime string conversion error Message-ID: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Hey all, I'm trying to convert a string to a date time object and all my fields convert except for month which seems to default to january. here's what I'm doing: date = "2010-03-16 14:46:38.409137" olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") print date print olddate I get: 2010-03-16 14:46:38.409137 2010-01-16 14:46:38.409137 notice the 01 in the second date from what I could tell everything is formatted correctly. thanks for the help. ~Jordan From tack at urandom.ca Tue Mar 16 14:59:00 2010 From: tack at urandom.ca (Jason Tackaberry) Date: Tue, 16 Mar 2010 14:59:00 -0400 Subject: to pass self or not to pass self In-Reply-To: <4b9f4984$0$10229$426a74cc@news.free.fr> References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <1268765940.6473.13.camel@arrakis> On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: > Answer here: > > http://wiki.python.org/moin/FromFunctionToMethod I have a sense I used to know this once upon a time, but the question came to my mind (possibly again) and I couldn't think of an answer: Why not create the bound methods at instantiation time, rather than using the descriptor protocol which has the overhead of creating a new bound method each time the method attribute is accessed? Cheers, Jason. From lists at cheimes.de Tue Mar 16 15:07:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 16 Mar 2010 20:07:32 +0100 Subject: datetime string conversion error In-Reply-To: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: <4B9FD6F4.3060503@cheimes.de> Jordan Apgar wrote: > Hey all, > I'm trying to convert a string to a date time object and all my fields > convert except for month which seems to default to january. > > here's what I'm doing: > date = "2010-03-16 14:46:38.409137" > olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > > print date > print olddate > > I get: > 2010-03-16 14:46:38.409137 > 2010-01-16 14:46:38.409137 > > notice the 01 in the second date from what I could tell everything is > formatted correctly. %j is documtend as "Day of the year as a decimal number [001,366].". Did you mean %d instead? Christian From torriem at gmail.com Tue Mar 16 15:07:38 2010 From: torriem at gmail.com (Michael Torrie) Date: Tue, 16 Mar 2010 13:07:38 -0600 Subject: Searching for most pythonic/least stupid way to do something simple In-Reply-To: <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> Message-ID: <4B9FD6FA.2010607@gmail.com> david jensen wrote: > of course, changing nn's to: > def getOutcomes(myList=[2,5,8,3,5]): > low_id = int(myList[0]>myList[1]) > amountToShare = 2*myList[low_id] > remainder = myList[not low_id]-myList[low_id] > tail=list(myList[2:]) > outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ > tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else > [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc > in (1.0, 0.75, 0.5, 0.25, 0.0)] > return outcomes > > > works, just hides the ugliness in a more compact form If Gerard's code works, I would consider it far superior to your code here. Pythonic does not necessarily mean short and ugly, nor does it mean that you have to always use list comprehensions. Having a readable algorithm that's easy to follow in the future is a far better way than trying to use python's cool features to compact the code to as small and unreadable section as possible. I used to use list comprehension all the time, but I've found that often an explicit for loop is a much better solution in terms of maintainability. Especially when you start seeing nested comprehensions such as you have here. From twistedphrame at gmail.com Tue Mar 16 15:11:54 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 16 Mar 2010 12:11:54 -0700 (PDT) Subject: datetime string conversion error References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: On Mar 16, 3:07?pm, Christian Heimes wrote: > Jordan Apgar wrote: > > Hey all, > > I'm trying to convert a string to a date time object and all my fields > > convert except for month which seems to default to january. > > > here's what I'm doing: > > date = "2010-03-16 14:46:38.409137" > > ?olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > > > print date > > print olddate > > > I get: > > 2010-03-16 14:46:38.409137 > > 2010-01-16 14:46:38.409137 > > > notice the 01 in the second date from what I could tell everything is > > formatted correctly. > > %j is documtend as "Day of the year as a decimal number [001,366].". Did > you mean %d instead? > > Christian That fixed it, thank you From gagsl-py2 at yahoo.com.ar Tue Mar 16 15:12:21 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 16:12:21 -0300 Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: En Tue, 16 Mar 2010 13:20:40 -0300, Johny escribi?: > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > not using os.system command. Do you mean that you want to execute a particular function in the .exe program? That's not possible (ok, you *could* do that if you work hard enough, but that's not how things are usually done) -- Gabriel Genellina From zak.mc.kraken at libero.it Tue Mar 16 15:17:43 2010 From: zak.mc.kraken at libero.it (Vito 'ZeD' De Tullio) Date: Tue, 16 Mar 2010 20:17:43 +0100 Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: Grant Edwards wrote: >> As for not being able to see the difference between a hyphen and an >> EN- dash, or minus sign, or whatever it is, yes but they are very >> similar looking glyphs in virtually ever modern font. It would take a >> good eye to see the difference between (say) ??? ??? and -. > > My point is that if it's an ASCII file, source files aren't (necessary) ASCII files -- By ZeD From hansmu at xs4all.nl Tue Mar 16 15:30:22 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Tue, 16 Mar 2010 20:30:22 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Ulrich Eckhardt wrote: > Chris Rebert wrote: >> You're a bit behind the times. >> If my calculations are right, that comic is over 2 years old. > > import timetravel I think you mean: from __future__ import timetravel -- HansM From martin.hellwig at dcuktec.org Tue Mar 16 15:44:58 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 16 Mar 2010 19:44:58 +0000 Subject: import antigravity In-Reply-To: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: On 03/16/10 19:30, Hans Mulder wrote: > Ulrich Eckhardt wrote: >> Chris Rebert wrote: >>> You're a bit behind the times. >>> If my calculations are right, that comic is over 2 years old. >> >> import timetravel > > I think you mean: > > from __future__ import timetravel > > > -- HansM Well according to Marty it is: from __back_to_the_future import DeLorean -- mph From python at mrabarnett.plus.com Tue Mar 16 15:53:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Mar 2010 19:53:20 +0000 Subject: datetime string conversion error In-Reply-To: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: <4B9FE1B0.3040700@mrabarnett.plus.com> Jordan Apgar wrote: > Hey all, > I'm trying to convert a string to a date time object and all my fields > convert except for month which seems to default to january. > > here's what I'm doing: > date = "2010-03-16 14:46:38.409137" > olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > > print date > print olddate > > I get: > 2010-03-16 14:46:38.409137 > 2010-01-16 14:46:38.409137 > > notice the 01 in the second date from what I could tell everything is > formatted correctly. > The problem seems to be related to your use of "%j", which parses the day of the year. If I use "%d" instead, which parses the day of the month (I think that's what you intended!), then the month comes out as 3 as expected. From tjreedy at udel.edu Tue Mar 16 16:04:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Mar 2010 16:04:22 -0400 Subject: Understanding the CPython dict implementation In-Reply-To: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> References: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 3/16/2010 7:46 AM, Steven D'Aprano wrote: > On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: > >> I found this PyCon2010 presentation to be excellent: The Mighty >> Dictionary, Branden Craig Rhodes, 30 min. Sorry, http://pycon.blip.tv/file/3332763/ which plays fine in FF3.6 on windows >> http://pycon.blip.tv/file/3264041/ wrong file number > Unfortunately, that clip seems to be unwatchable, at least for me. It > crashed the Netscape plugin in Konqueror, and crashed Firefox. The flash version does not work for me. This is true of about 1/3 of the Pycon 2010 videos that I have tried. The .ogv version of this and all others that I have tried (hit Download under Comments) plays fine within FF3.6 on my windows xp machine. Perhaps there is a linux-specific bug, if that is what you are running under. Terry Jan Reedy From tjreedy at udel.edu Tue Mar 16 16:10:22 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Mar 2010 16:10:22 -0400 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: On 3/16/2010 3:12 PM, Gabriel Genellina wrote: > En Tue, 16 Mar 2010 13:20:40 -0300, Johny escribi?: > >> Is there any tutorial how to write a bindings for a exe ( dos) >> program? >> I would like to run it from a Python directly >> ( using import command and a particular function from the binding) >> not using os.system command. > > Do you mean that you want to execute a particular function in the .exe > program? > That's not possible (ok, you *could* do that if you work hard enough, > but that's not how things are usually done) If running a function within the .exe *is* what you want, then you should compile to .dll instead of .exe and use swig or ctypes to do the binding. From invalid at invalid.invalid Tue Mar 16 16:12:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 16 Mar 2010 20:12:29 +0000 (UTC) Subject: subtraction is giving me a syntax error References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On 2010-03-16, Vito 'ZeD' De Tullio wrote: > Grant Edwards wrote: > >>> As for not being able to see the difference between a hyphen and an >>> EN- dash, or minus sign, or whatever it is, yes but they are very >>> similar looking glyphs in virtually ever modern font. It would take a >>> good eye to see the difference between (say) ??? ??? and -. >> >> My point is that if it's an ASCII file, > > source files aren't (necessary) ASCII files OK, if it's a file with encoding , then characters that aren't part of shouldn't be rendered according so some other arbitrary character set. Illegal characters should be flagged and displayed in a manner that makes it obvious you have illegal characters in in the file. If the OP was using a source file with an encoding that isn't accepted by Python, then he needs to pick a source file encoding that is recognized by Python. Using a source file encoding where there are semantically _different_ characters that render identically is just asking for pain... -- Grant Edwards grant.b.edwards Yow! I guess you guys got at BIG MUSCLES from doing too gmail.com much STUDYING! From jgardner at jonathangardner.net Tue Mar 16 16:15:13 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 16 Mar 2010 13:15:13 -0700 Subject: to pass self or not to pass self In-Reply-To: <4b9f4984$0$10229$426a74cc@news.free.fr> References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <6cc20cea1003161315i377bc9c2l525964b1cb6550e7@mail.gmail.com> On Tue, Mar 16, 2010 at 2:04 AM, Bruno Desthuilliers wrote: > lallous a ?crit : >> >> What is the difference between the reference in 'F' and 'func_tbl' ? > > Answer here: > > http://wiki.python.org/moin/FromFunctionToMethod > Among all the things in the Python language proper, this is probably the most confusing thing for new programmers. Heck, even experienced programmers get tangled up because they project how they think things should work on to the Python model. The second most confusing thing is probably how objects get instantiated. -- Jonathan Gardner jgardner at jonathangardner.net From pavlovevidence at gmail.com Tue Mar 16 16:16:50 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 16 Mar 2010 13:16:50 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: On Mar 16, 11:25?am, moerchendiser2k3 wrote: > Hi, currently I am not at home, I will post some stuff when I am back. > Just the note: I throw an exception with the C API. > > Looks like that > > PyObject *result = PyObject_Call(my_isntance, "", NULL); > if(result==NULL) > { > ? ? PyErr_Print(); //when this happens, the traceback is correct with > information about the file/line > ? ? return; > > } > > if(!PyXYZ_Check(result)) > { > ? ? PyErr_SetString(PyExc_TypeError, "Wrong type, ...."); > ? ? PyErr_Print(); //missing information of the file/line. > ? ? return; > } > > Well, I expect, that there are no information about the line/file, so > I know something is missing, but what is missing? Python tracebacks only contain line/file information about Python files, not C files. Here you raise an exception with a C statement, and catch and print it in the very next line. The exception doesn't exit from Python code so there are no lines to print. What line/file data you do expect to see? If you want to see C line/file informnation you have to use a debugger like gdb, as Steve Holden said. Carl Banks From dmj.ccc at gmail.com Tue Mar 16 16:27:19 2010 From: dmj.ccc at gmail.com (david jensen) Date: Tue, 16 Mar 2010 13:27:19 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> Message-ID: <03631aaf-0cf2-4c15-9e0d-7ac0f33ae01d@c16g2000yqd.googlegroups.com> >If Gerard's code works, I would consider it far superior to your code >here. Pythonic does not necessarily mean short and ugly yes, I agree... and in my script i'm using something very like Gerard's (thanks again, Gerard). I just posted the corrected version of nn's because the original solved only half the problem. thanks, all dmj From aahz at pythoncraft.com Tue Mar 16 16:37:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 13:37:57 -0700 Subject: The first ASIC designed with MyHDL References: <4b9f7414$0$2887$ba620e4c@news.skynet.be> Message-ID: In article <4b9f7414$0$2887$ba620e4c at news.skynet.be>, Jan Decaluwe wrote: > >I am proud to report on the first ASIC product designed with MyHDL >(afaik). > >http://www.jandecaluwe.com/hdldesign/digmac.html Congrats! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From benjamin.kaplan at case.edu Tue Mar 16 16:42:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 16 Mar 2010 16:42:05 -0400 Subject: subtraction is giving me a syntax error In-Reply-To: References: <56597268-3472-4fd9-a829-6d9cf51cf093@e7g2000yqf.googlegroups.com> <4b9eb5bd$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Tue, Mar 16, 2010 at 4:12 PM, Grant Edwards wrote: > On 2010-03-16, Vito 'ZeD' De Tullio wrote: > > Grant Edwards wrote: > > > >>> As for not being able to see the difference between a hyphen and an > >>> EN- dash, or minus sign, or whatever it is, yes but they are very > >>> similar looking glyphs in virtually ever modern font. It would take a > >>> good eye to see the difference between (say) ??? ??? and -. > >> > >> My point is that if it's an ASCII file, > > > > source files aren't (necessary) ASCII files > > OK, if it's a file with encoding , then characters that > aren't part of shouldn't be rendered according so some > other arbitrary character set. Illegal characters should be flagged > and displayed in a manner that makes it obvious you have illegal > characters in in the file. > > If the OP was using a source file with an encoding that isn't accepted > by Python, then he needs to pick a source file encoding that is > recognized by Python. > > Using a source file encoding where there are semantically _different_ > characters that render identically is just asking for pain... > > >>> print u'\N{HYPHEN-MINUS}' - >>> print u'\N{MINUS SIGN}' ? >>> print u'\N{SMALL HYPHEN-MINUS}' ? >>> print u'\N{FIGURE DASH}' ? >>> print u'\N{EN DASH}' ? >>> print u'\N{SMALL EM DASH}' ? >>> print u'\N{EM DASH}' ? >>> print u'\N{HORIZONTAL BAR}' ? Good luck finding a character encoding where you can see the difference between each of those in context. Do you program in a hex editor? > -- > Grant Edwards grant.b.edwards Yow! I guess you guys > got > at BIG MUSCLES from doing > too > gmail.com much STUDYING! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Mar 16 16:44:09 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 16 Mar 2010 20:44:09 +0000 Subject: import antigravity In-Reply-To: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: Hans Mulder wrote: > Ulrich Eckhardt wrote: >> Chris Rebert wrote: >>> You're a bit behind the times. >>> If my calculations are right, that comic is over 2 years old. >> >> import timetravel > > I think you mean: > > from __future__ import timetravel > > > -- HansM Taking 1984 into account surely it should be from __past__ import __future__ as future But the question is, have we yet got to 1984, are we currently there or have we already gone past it? Who actually *IS* running the time machine? Are there any bugs?? Regards. Mark Lawrence. From gagsl-py2 at yahoo.com.ar Tue Mar 16 18:39:04 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 19:39:04 -0300 Subject: passing a socket to a subprocess in windows References: Message-ID: En Tue, 16 Mar 2010 14:10:16 -0300, Daniel Platz escribi?: > I have a problem with passing a socket to a subprocess in windows. It > works in Linux and for windows there is a workaround in the Python > doc. However, this workaround does not work. It was already noted by > other people and they Python issue tracker > > http://bugs.python.org/issue5879 Unfortunately I cannot test it at this moment, but around line 360 in socketmodule.c: #if defined(MS_WINDOWS) || defined(__BEOS__) ... #define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */ #endif you could try removing that #define NO_DUP and recompiling. socket.fromfd should appear, and hopefully socket objects can now be sent thru the multiprocessing connection. (I cannot see how the example could have actually worked on Windows, maybe I'm missing something. Perhaps http://bugs.python.org/issue3125 broke this.) -- Gabriel Genellina From jlundell at pobox.com Tue Mar 16 18:55:17 2010 From: jlundell at pobox.com (JLundell) Date: Tue, 16 Mar 2010 15:55:17 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> <4B9F7B2A.1080906@ieee.org> Message-ID: On Mar 16, 8:06?am, Robert Kern wrote: > On 2010-03-16 07:35 AM, Dave Angel wrote: > > > > > > > > > Carl Banks wrote: > >> On Mar 15, 4:34 pm, JLundell wrote: > >>> It's also unfortunate that Python doesn't have an approximately-equal > >>> operator; it'd come in handy for floating-point applications while > >>> preserving hash. If only there were a ~=r ? operator I could > >>> overload. And ~ is unary, so no joy. > > >> One problem with it is that there's no way to make it universal; > >> different appiplications have different ideas of close. Conceivably > >> it could be usefully defined for a user type though.. > > >> Bacause of this problem almost no languages have an almost equal > >> operator. I'm curious what languages do, of if there are any with a > >> trinary operator that also takes a threshold. > > >> Carl Banks > > > If I recall correctly, APL has a *fuzz* value, which is used in all(?) > > comparisons. But I do not recall anything about how it was defined. I do > > recall that you could change the threshold, and suspect it was relative > > to the operands. For symmetry, it would probably have to be relative to > > the average of the two values, or some such. > > The problem is that frequently there is no system-wide fuzz value which is > appropriate for all comparisons in a given program. You need to choose the right > value for each comparison. Consequently, you might as well use a function > instead of an operator and a global variable. > > -- > Robert Kern > APL scaled their fuzz to the larger of the values being compared. In my case, my domain permits me to use a constant fuzz; all my units are the same (votes, as it happens). I've seen abs(a/b-1) used instead of abs(a-b); obviously you'd need to treat comparison with zero specially. But yeah, it's really a domain-specific problem. From joshua.r.english at gmail.com Tue Mar 16 19:31:11 2010 From: joshua.r.english at gmail.com (Josh English) Date: Tue, 16 Mar 2010 16:31:11 -0700 (PDT) Subject: datetime string conversion error References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: On Mar 16, 11:56?am, Jordan Apgar wrote: > here's what I'm doing: > date = "2010-03-16 14:46:38.409137" > ?olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") > Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on the other). When I have a script as simple as this: import datetime datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") Running this script brings up a calendar, believe it or not. The calendar displays March 2010, and shows the 22nd as a holiday. When I dismiss the dialog box I get: Traceback (most recent call last): File "strptimetest.py", line 3, in datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") File "C:\Python25\lib\_strptime.py", line 272, in _TimeRE_cache = TimeRE() File "C:\Python25\lib\_strptime.py", line 191, in __init__ self.locale_time = LocaleTime() File "C:\Python25\lib\_strptime.py", line 74, in __init__ self.__calc_weekday() File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] AttributeError: 'module' object has no attribute 'day_abbr' err... what? Is this an old weirdness I don't remember from the 2.5 series? I can select dates in the calendar, but nothing dismisses it but the close box. Josh English Incredibly Confused From robert.kern at gmail.com Tue Mar 16 19:32:04 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Mar 2010 18:32:04 -0500 Subject: class inheritance In-Reply-To: References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> <7088c1e1-9a1f-42d8-aac2-5ba19806165a@o30g2000yqb.googlegroups.com> <4B9F7B2A.1080906@ieee.org> Message-ID: On 2010-03-16 17:55 PM, JLundell wrote: > On Mar 16, 8:06 am, Robert Kern wrote: >> On 2010-03-16 07:35 AM, Dave Angel wrote: >> >>> Carl Banks wrote: >>>> On Mar 15, 4:34 pm, JLundell wrote: >>>>> It's also unfortunate that Python doesn't have an approximately-equal >>>>> operator; it'd come in handy for floating-point applications while >>>>> preserving hash. If only there were a ~=r ? operator I could >>>>> overload. And ~ is unary, so no joy. >> >>>> One problem with it is that there's no way to make it universal; >>>> different appiplications have different ideas of close. Conceivably >>>> it could be usefully defined for a user type though.. >> >>>> Bacause of this problem almost no languages have an almost equal >>>> operator. I'm curious what languages do, of if there are any with a >>>> trinary operator that also takes a threshold. >> >>>> Carl Banks >> >>> If I recall correctly, APL has a *fuzz* value, which is used in all(?) >>> comparisons. But I do not recall anything about how it was defined. I do >>> recall that you could change the threshold, and suspect it was relative >>> to the operands. For symmetry, it would probably have to be relative to >>> the average of the two values, or some such. >> >> The problem is that frequently there is no system-wide fuzz value which is >> appropriate for all comparisons in a given program. You need to choose the right >> value for each comparison. Consequently, you might as well use a function >> instead of an operator and a global variable. >> >> -- >> Robert Kern >> > > APL scaled their fuzz to the larger of the values being compared. I know. My statement stands for relative fuzz values as well as it does for absolute fuzz values. :-) > In > my case, my domain permits me to use a constant fuzz; all my units are > the same (votes, as it happens). I've seen abs(a/b-1) used instead of > abs(a-b); obviously you'd need to treat comparison with zero > specially. One usually uses a combination of relative and absolute tolerances to account for the case when the values are close to zero. > But yeah, it's really a domain-specific problem. Right. And a single program might need to deal with multiple domains, so a single global setting to control a language feature is pretty fragile. -- 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 From greg.ewing at canterbury.ac.nz Tue Mar 16 19:32:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 17 Mar 2010 12:32:40 +1300 Subject: Function that knows its argument's variable name In-Reply-To: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <80ai5hFh3uU1@mid.individual.net> Helge Stenstr?m wrote: > I want to write function that prints a value of a variable, for > debugging. Like: > > myVariable = "parrot" > otherVariable = "dead" > > probe(myVariable) > probe(otherVariable) Not exactly, but you can come close with a little hackery. import sys def print_var(name): print name, "=", sys._getframe(1).f_locals[name] def f(): fred = 42 mary = "christmas" print_var("fred") print_var("mary") f() -- Greg From phlip2005 at gmail.com Tue Mar 16 19:40:46 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Mar 2010 16:40:46 -0700 (PDT) Subject: Function that knows its argument's variable name References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <460a8b90-ee92-458c-b09e-abf230d7cdbc@q23g2000yqd.googlegroups.com> > Yet, the answer to your question is not quite absolutely "no". ?Python > has lots of introspection capabilities, including, perhaps, getting at > and parsing the original code to find the call. ? ?But there's nothing > direct for what you want. > > Gary Herron Below my sig is one shot at it; which requires a lambda: for other reasons. It's an assertion used with Django models. You can search for the name of your trace method, instead of lambda, using this brute-force technique. And here's a nice thread on Greg's technique, from a very short time ago: http://groups.google.com/group/comp.lang.python/msg/03dd85ce009044e9 -- Phlip http://penbird.tumblr.com/ def assert_model_changes(self, mod, item, frum, too, lamb): source = open(lamb.func_code.co_filename, 'r').readlines() [lamb.func_code.co_firstlineno - 1] source = source.replace('lambda:', '').strip() model = str(mod.__class__).replace("'>", '').split('.')[-1] should = '%s.%s should equal `%s` before your activation line, `%s`' % \ (model, item, frum, source) self.assertEqual(frum, mod.__dict__[item], should) lamb() mod = mod.__class__.objects.get(pk=mod.pk) should = '%s.%s should equal `%s` after your activation line, ` %s`' % \ (model, item, too, source) self.assertEqual(too, mod.__dict__[item], should) return mod From aahz at pythoncraft.com Tue Mar 16 19:47:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 16:47:41 -0700 Subject: highlight words by regex in pdf files using python References: Message-ID: In article , Peng Yu wrote: > >I don't find a general pdf library in python that can do any >operations on pdfs. > >I want to automatically highlight certain words (using regex) in a >pdf. Could somebody let me know if there is a tool to do so in python? Did you Google at all? "python pdf" finds this as the first link, though I have no clue whether it does what you want: http://pybrary.net/pyPdf/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From spamfresser at ch3ka.de Tue Mar 16 19:48:02 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 17 Mar 2010 00:48:02 +0100 Subject: import antigravity In-Reply-To: References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: Am 16.03.2010 21:44, schrieb Mark Lawrence: > Who actually *IS* running the time machine? Are there any bugs?? My is. And as I'm a lazy hacker: sure. there are bugs. lets just call them features and move on. nothing to see here ;) From aahz at pythoncraft.com Tue Mar 16 19:51:23 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 16:51:23 -0700 Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> Message-ID: In article , Pete Emerson wrote: > >Excellent, this is what I finally discovered, although I was looking >for 'foo' in sys.modules.keys(), which apparently isn't necessary. Actually, `foo in sys.modules.keys()` is double-slow, because first the dict must be scanned to create a list, and then the list must be scanned linearly to test for foo. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Tue Mar 16 19:55:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Mar 2010 16:55:51 -0700 Subject: Conditional based on whether or not a module is being used References: <7efe6ba1-d58f-482c-9b35-dc9c67b02194@q2g2000pre.googlegroups.com> <29c6a957-5028-4c2d-8594-6c4db8243ef2@d2g2000yqa.googlegroups.com> <42062deb-785a-4955-9ce0-d9fb7a26455d@j27g2000yqn.googlegroups.com> Message-ID: In article <42062deb-785a-4955-9ce0-d9fb7a26455d at j27g2000yqn.googlegroups.com>, Vinay Sajip wrote: > >I'm reviewing the documentation at the moment, as it happens, and it >still seems hard to be able to put together a structure which is good >for everyone. A full treatment, it seems to me, would talk a little >about the detail of why things work as they do; but a lot of the time, >people are just interested in getting going with the package, and less >interested in the whys and wherefores. But for people trying to do more >than the basics, that deeper understanding is sometimes necessary. The >hard part is satisfying all audiences in one document! Simple answer: don't The main logging docs should be reference material, but the top of the docs should link to a tutorial (or the other way around, but I think the Python docs have generally preferred to make the primary doc reference). Trying to make one page serve all documentation purposes rarely works. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From gagsl-py2 at yahoo.com.ar Tue Mar 16 20:02:38 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 21:02:38 -0300 Subject: cycling through options References: Message-ID: En Tue, 16 Mar 2010 11:30:51 -0300, Dieter Faulbaum escribi?: > is there a better way for cycling through all options than this: > > > (options, args) = parser.parse_args() > for opt in options.__dict__.keys(): > print opt, ":", options.__dict__[opt] (I assume parser is an optparse.OptionParser instance) You may rewrite it as: for oname, ovalue in vars(options).iteritems(): print oname, ":", ovalue This assumes that the only instance attributes existing in 'options' are, uh, parsed options from the command line. I could not find such guarantee in the documentation. Another way would be to ask the parser about the options it knows of: for oname in (o.dest for o in parser.option_list if o.dest): print oname, ":", getattr(options, oname, None) -- Gabriel Genellina From skippy.hammond at gmail.com Tue Mar 16 20:08:10 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 17 Mar 2010 11:08:10 +1100 Subject: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> Message-ID: <4BA01D6A.60208@gmail.com> On 17/03/2010 1:26 AM, Barak, Ron wrote: > Thanks for the suggestion Pable. > However, I really need the $PYTHONPATH to include this additional > library, so all Python scripts could use it. > In Windows I have defined PYTHONPATH as > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the > Windows registry I have > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\/version/\PythonPath\ as > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\;C:\Python26\Lib\lib-tk; > However, even with all the above, the SVMInspecor modules are not found. You need to create your own sub-key, with any name, under the PythonPath key and add your path there. The reason is that Python only looks for that root key when it can't sniff the location of the library itself based on the location of the executable - and in most cases it can. Python does however enumerate and use the sub-keys in all cases. HTH, Mark From dg.gmane at thesamovar.net Tue Mar 16 21:00:11 2010 From: dg.gmane at thesamovar.net (Dan Goodman) Date: Wed, 17 Mar 2010 02:00:11 +0100 Subject: C++ code generation Message-ID: Hi all, I'm doing some C++ code generation using Python, and would be interested in any comments on the approach I'm taking. Basically, the problem involves doing some nested loops and executing relatively simple arithmetic code snippets, like: for i in xrange(len(X)): X[i] += 5 Actually they're considerably more complicated than this, but this gives the basic idea. One way to get C++ code from this would be to use Cython, but there are two problems with doing that. The first problem is that the arithmetic code snippets are user-specified. What I want to do is generate code, and then compile and run it using Scipy's weave package. The second problem is that I have various different data structures and the C++ code generated needs to be different for the different structures (e.g. sparse or dense matrices). So far what I've been doing is writing Python code that writes the C++ code, but in a very non-transparent way. I like the idea of specifying the C++ code using Python syntax, like in Cython. So the idea I came up with was basically to abuse generators and iterators so that when you write something like: for x in X: ... it actually outputs some C++ code that looks like: for(int i=0; i > Is there any tutorial how to write a bindings for a exe ( dos) > program? > I would like to run it from a Python directly > ( using import command and a particular function from the binding) > not using os.system command. An example: PythoidC ( http://pythoidc.googlecode.com ), look at importTemplate.py -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.cg at 126.com Tue Mar 16 21:54:25 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 17 Mar 2010 09:54:25 +0800 (CST) Subject: C++ code generation Message-ID: <11c0630.1732.12769d42e98.Coremail.dr.cg@126.com> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) ----- Original Message ----- From: "Dan Goodman" To: Sent: Wednesday, March 17, 2010 9:00 AM Subject: C++ code generation > Hi all, > > I'm doing some C++ code generation using Python, and would be interested > in any comments on the approach I'm taking. > > Basically, the problem involves doing some nested loops and executing > relatively simple arithmetic code snippets, like: > > for i in xrange(len(X)): > X[i] += 5 > > Actually they're considerably more complicated than this, but this gives > the basic idea. One way to get C++ code from this would be to use > Cython, but there are two problems with doing that. The first problem is > that the arithmetic code snippets are user-specified. What I want to do > is generate code, and then compile and run it using Scipy's weave > package. The second problem is that I have various different data > structures and the C++ code generated needs to be different for the > different structures (e.g. sparse or dense matrices). > > So far what I've been doing is writing Python code that writes the C++ > code, but in a very non-transparent way. I like the idea of specifying > the C++ code using Python syntax, like in Cython. So the idea I came up > with was basically to abuse generators and iterators so that when you > write something like: > > for x in X: > ... > > it actually outputs some C++ code that looks like: > > for(int i=0; i double &x = X[i]; > ... > } > > The ... in the Python code is only executed once because when X is > iterated over it only returns one value. > > Here's the example I've written so far (complete code given below): > > # initialisation code > code = OutputCode() > evaluate = Evaluator(code) > X = Array(code, 'values') > # specification of the C++ loop > for x in X: > evaluate('x += 5; x *= 2') > # and show the output > print code.code > > It generates the following C++ code: > > for(int values_index=0; values_index double &values = values_array[values_index]; > values += 5; > values *= 2; > } > > OK, so that's an overview of the idea that I have of how to do it. Any > comments or suggestions on either the approach or the implementation? > > Below is the complete code I've written for the example above (linewraps > aren't perfect but there's only a couple of lines to correct). > > Thanks for any feedback, > > Dan > > import re, inspect > > # We just use this class to identify certain variables > class Symbol(str): pass > > # This class is basically just a mutable string > class OutputCode(object): > def __init__(self): > self.code = '' > def __iadd__(self, code): > self.code = self.code+code > return self > > # Iterating over instances of this class generates code > # for iterating over a C++ array, it yields a single > # Symbol object, the variable name of the value in the > # array > class Array(object): > def __init__(self, code, name, dtype='double'): > self.name = name > self.dtype = dtype > self.code = code > def __iter__(self): > def f(): > self.code += 'for(int {name}_index=0; > {name}_index<{name}_len; {name}_index++){{\n'.format(name=self.name) > self.code += '{dtype} &{name} = > {name}_array[{name}_index];\n'.format(dtype=self.dtype, name=self.name) > yield Symbol(self.name) > self.code += '}\n' > return f() > > # Instances of this class generate C++ code from Python syntax > # code snippets, replacing variable names that are a Symbol in the > # namespace with the value of that Symbol. > class Evaluator(object): > def __init__(self, code): > self.code = code > def __call__(self, code): > # The set of variables in the code snippet > vars = re.findall(r'\b(\w+)\b', code) > # Extract any names from the namespace of the calling frame > frame = inspect.stack()[1][0] > globals, locals = frame.f_globals, frame.f_locals > values = {} > for var in vars: > if var in locals: > values[var] = locals[var] > elif var in globals: > values[var] = globals[var] > # Replace any variables whose values are Symbols with their values > for var, value in values.iteritems(): > if isinstance(value, Symbol): > code = re.sub(r'\b{var}\b'.format(var=var), str(value), > code) > # Turn Python snippets into C++ (just a simplified version for now) > code = code.replace(';', '\n') > lines = [line.strip() for line in code.split('\n')] > code = ''.join(line+';\n' for line in lines) > self.code += code > > if __name__=='__main__': > code = OutputCode() > evaluate = Evaluator(code) > X = Array(code, 'values') > for x in X: > evaluate('x += 5; x *= 2') > print code.code > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Tue Mar 16 22:07:42 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 23:07:42 -0300 Subject: How to handle file uploads with http.server References: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com> <4728DC0EADB2654E8BA2A487F0CF2785AD6D2E@ws-ukexchange.internal.biowisdom.com> Message-ID: En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue escribi?: > I have a basic http.server instance running (class > HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I > would like to upload files with multipart forms. > > def do_POST(self): > ctype, pdict = cgi.parse_header(self.headers['Content-Type']) > if ctype=='multipart/form-data': > print('parsing...') > query=cgi.parse_multipart(self.rfile, pdict) > print(query) > > However the file never seems to finish being parsed. There are no errors, > but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict) This may be related to this bug: http://bugs.python.org/issue8077 reported last week by Mitchell L. Model in this thread: http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/ -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 22:21:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 23:21:14 -0300 Subject: Exiting gracefully from ThreadingTCPServer References: <1f31cddf-1104-4579-bd61-5fad3b2c4677@t17g2000prg.googlegroups.com> Message-ID: En Fri, 12 Mar 2010 12:15:16 -0300, Pete Emerson escribi?: > I'm trying to get threading going for the first time in python, and > I'm trying to modify code I found so that I can have the server close > the TCP connections and exit gracefully. Two problems: Which Python version? > 1) While the KeyboardInterrupt works, if I make more than 0 curls to > the server and then quit, I can't run it again right away and get > this: > socket.error: [Errno 48] Address already in use > > Not all of my connections are closing properly. How do I fix this? > > 2) curling localhost:8080/quit does show the "Quitting" output that I > expect, but doesn't quit the server until I manually control-c it. On Python 2.6, you should call the shutdown() method (from another thread!) instead of simply server_close() See this recipe [1] -- just look at the main() function (disregard all the previous details); it runs the server(s) in their own thread, the main thread just sits and waits for KeyboardInterrupt or SystemExit. [1] http://code.activestate.com/recipes/577025 -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Mar 16 22:25:50 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 16 Mar 2010 23:25:50 -0300 Subject: datetime string conversion error References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: En Tue, 16 Mar 2010 20:31:11 -0300, Josh English escribi?: > On Mar 16, 11:56 am, Jordan Apgar wrote: > >> here's what I'm doing: >> date = "2010-03-16 14:46:38.409137" >> olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") >> > > Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on > the other). > > When I have a script as simple as this: > > import datetime > > datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") > > > Running this script brings up a calendar, believe it or not. The > calendar displays March 2010, and shows the 22nd as a holiday. When I > dismiss the dialog box I get: > Traceback (most recent call last): > File "strptimetest.py", line 3, in > datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") > File "C:\Python25\lib\_strptime.py", line 272, in > _TimeRE_cache = TimeRE() > File "C:\Python25\lib\_strptime.py", line 191, in __init__ > self.locale_time = LocaleTime() > File "C:\Python25\lib\_strptime.py", line 74, in __init__ > self.__calc_weekday() > File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday > a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] > AttributeError: 'module' object has no attribute 'day_abbr' I'd say you have a calendar.py script somewhere along your sys.path, that shadows the calendar module in the standard library. -- Gabriel Genellina From googler.1.webmaster at spamgourmet.com Tue Mar 16 22:45:50 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Tue, 16 Mar 2010 19:45:50 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: <6d496959-1397-427d-82d3-9c11ca956e54@33g2000yqj.googlegroups.com> At first thanks for your answers!!! On 16 Mrz., 21:16, Carl Banks wrote: > Here you raise an exception with a C statement, > and catch and print it in the very next line. ?The exception doesn't > exit from Python code so there are no lines to print. Exactly, I dont expect any line/file information. I am just looking forward for a solution how to solve that. I would like to avoid the use of the debugger in this case. My ideas: 1. I thought the return value might contain any information where it is from. 2. Otherwise it would be cool if there are any information available in which line, file the last called function/method exited. Bye, moerchendiser2k3 From hidura at gmail.com Tue Mar 16 23:08:17 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Wed, 17 Mar 2010 03:08:17 +0000 Subject: Web Hosting Python 3 Message-ID: <0016e64642280288940481f66d5e@google.com> Hello list, i am in a project what need hosting, who give hosting to python3? -------------- next part -------------- An HTML attachment was scrubbed... URL: From pmaupin at gmail.com Wed Mar 17 00:12:16 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 16 Mar 2010 21:12:16 -0700 (PDT) Subject: highlight words by regex in pdf files using python References: Message-ID: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> On Mar 4, 6:57?pm, Peng Yu wrote: > I don't find a general pdf library in python that can do any > operations on pdfs. > > I want to automatically highlight certain words (using regex) in a > pdf. Could somebody let me know if there is a tool to do so in python? The problem with PDFs is that they can be quite complicated. There is the outer container structure, which isn't too bad (unless the document author applied encryption or fancy multi-object compression), but then inside the graphics elements, things could be stored as regular ASCII, or as fancy indexes into font-specific tables. Not rocket science, but the only industrial-strength solution for this is probably reportlab's pagecatcher. I have a library which works (primarily with the outer container) for reading and writing, called pdfrw. I also maintain a list of other PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries It may be that pdfminer (link on that page) will do what you want -- it is certainly trying to be complete as a PDF reader. But I've never personally used pdfminer. One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools will read in preexisting PDFs and write them out to a reportlab canvas. This works quite well on a few very simple ASCII PDFs, but the font handling needs a lot of work and probably won't work at all right now on unicode. (But if you wanted to improve it, I certainly would accept patches or give you commit rights!) That pdfrw example does graphics reasonably well. I was actually going down that path for getting better vector graphics into rst2pdf (both uniconvertor and svglib were broken for my purposes), but then I realized that the PDF spec allows you to include a page from another PDF quite easily (the spec calls it a form xObject), so you don't actually need to parse down into the graphics stream for that. So, right now, the best way to do vector graphics with rst2pdf is either to give it a preexisting PDF (which it passes off to pdfrw for conversion into a form xObject), or to give it a .svg file and invoke it with -e inkscape, and then it will use inkscape to convert the svg to a pdf and then go through the same path. HTH, Pat From levi.india at gmail.com Wed Mar 17 00:15:46 2010 From: levi.india at gmail.com (pothuri ramesh) Date: Tue, 16 Mar 2010 21:15:46 -0700 (PDT) Subject: Data entry Work available Message-ID: <09d51eec-68e7-4dac-a5bd-6bc3b0b656d6@l40g2000pro.googlegroups.com> Data entry works Available At No need to pay DEposite http://trading7000.blogspot.com/ Adposting Jobs Availble http://trading7000.blogspot.com/ No need to work Hard Earn Money From Home 7000 in Minutes http://trading7000.blogspot.com/ From lie.1296 at gmail.com Wed Mar 17 00:57:17 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Mar 2010 15:57:17 +1100 Subject: to pass self or not to pass self In-Reply-To: References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <4ba06148$1@dnews.tpgi.com.au> On 03/17/2010 05:59 AM, Jason Tackaberry wrote: > On Tue, 2010-03-16 at 10:04 +0100, Bruno Desthuilliers wrote: >> Answer here: >> >> http://wiki.python.org/moin/FromFunctionToMethod > > I have a sense I used to know this once upon a time, but the question > came to my mind (possibly again) and I couldn't think of an answer: > > Why not create the bound methods at instantiation time, rather than > using the descriptor protocol which has the overhead of creating a new > bound method each time the method attribute is accessed? Because people wanted it like so. There was once, a time when python doesn't have the descriptor protocol (old-style classes) and many people feels that a high-level language like python should provide some additional hooks for customizing attribute access which the existing solutions like __getattr__ and __setattr__ couldn't easily provide. The result is new-style class. Most people probably would never need to use descriptor protocol directly, since the immediate benefit of descriptor protocol are property(), classmethod(), and instancemethod() decorators which, without descriptor protocol, would never become a possibility. From sbassi at clubdelarazon.org Wed Mar 17 01:22:49 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Wed, 17 Mar 2010 02:22:49 -0300 Subject: Converting Python CGI to WSGI scripts In-Reply-To: <1268759895.28810.1365130739@webmail.messagingengine.com> References: <1268759895.28810.1365130739@webmail.messagingengine.com> Message-ID: <9e2f512b1003162222v98772d0u8d3aea8ced1ee7bb@mail.gmail.com> On Tue, Mar 16, 2010 at 2:18 PM, wrote: > I have a few dozen simple Python CGI scripts. > Are there any advantages or disadvantages to rewriting these CGI scripts as > WSGI scripts? It depends of the script. WSGI should be faster since you don't start a Python instance for each call (as in CGI). -- Sebasti?n Bassi. Diplomado en Ciencia y Tecnolog?a. Curso de Python en un d?a: http://bit.ly/cursopython Python for Bioinformatics: http://tinyurl.com/biopython 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. From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 01:32:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 05:32:05 GMT Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4ba06148$1@dnews.tpgi.com.au> Message-ID: On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote: > Most people probably would never need to use > descriptor protocol directly, since the immediate benefit of descriptor > protocol are property(), classmethod(), and instancemethod() decorators > which, without descriptor protocol, would never become a possibility. There's an instancemethod decorator? Where? Are you thinking of staticmethod? "instancemethod", if you mean what I think you mean, doesn't need a decorator because it is the default behaviour for new-style classes. -- Steven From pmaupin at gmail.com Wed Mar 17 01:35:03 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Tue, 16 Mar 2010 22:35:03 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> Message-ID: <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> On Mar 16, 1:59?pm, Jason Tackaberry wrote: > Why not create the bound methods at instantiation time, rather than > using the descriptor protocol which has the overhead of creating a new > bound method each time the method attribute is accessed? Well, for one thing, Python classes are open. They can be added to at any time. For another thing, you might not ever use most of the methods of an instance, so it would be a huge waste to create those. Also, this area has been optimized for normal usage patterns quite heavily, to the point where attempted "optimizations" can lead to results that are, on the surface, quite counterintuitive. For example, if you want to take the length of a lot of different strings, you might think you could save time by binding a local variable to str.__len__ and using that on the strings. Here is an example: >>> def a(s, count, lenfunc): ... for i in xrange(count): ... z = lenfunc(s) ... >>> a('abcdef', 100000000, len) >>> a('abcdef', 100000000, str.__len__) Running cPython 2.6 on my machine, len() runs about 3 times faster than str.__len__(). The overhead of checking that an object is usable with a particular class method far outweighs the cost of creating the bound method! So, one thought for the OP. Whenever I have a dictionary that contains class methods in it, if I'm going to use it heavily, I often recode it to create the dictionary at object creation time with bound methods in it. Regards, Pat From joshua.r.english at gmail.com Wed Mar 17 02:13:47 2010 From: joshua.r.english at gmail.com (Josh English) Date: Tue, 16 Mar 2010 23:13:47 -0700 (PDT) Subject: Dynamic Class Creation References: Message-ID: <8d79f0cb-9c5b-4243-8891-a15fb311f652@z18g2000prh.googlegroups.com> Chris, Thanks. This worked for the attributes, but I think the tactic is still misleading. There are child elements I can't quite determine how to deal with: Analog Science Fiction and Fact Analog Science Fiction First Contact Hard Science Fiction
Stanley Schmidt, Editor 267 Broadway, 4th Floor New York, NY 10007-2352
http://www.analogsf.com
A child element with text and an attribute or two, for example, pose a problem. I can call Market.title but should I try Market.title.field or Market.title_field. Multiple elements, such as keywords, are allowed in xml but harder to map to the object. I don't know if I want to go create a list and methods for accessing those keywords as a list, or redefine the rules of my XML to not allow multiple child elements with the same tag. I can't decide. Then the address is a bit of a bear. In short, I have to figure out the whole object interface to the XML and how I want that to work. Thanks for the suggestion. It is undeniably clever. Josh From tino at wildenhain.de Wed Mar 17 02:30:36 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Wed, 17 Mar 2010 07:30:36 +0100 Subject: Function that knows its argument's variable name In-Reply-To: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> Message-ID: <4BA0770C.2070306@wildenhain.de> Hi, Am 14.03.2010 12:58, schrieb Helge Stenstr?m: > I want to write function that prints a value of a variable, for > debugging. Like: > > with > > myVariable = "parrot" > otherVariable = "dead" > > probe(myVariable) > probe(otherVariable) > > instead of the longer > > print "myVariable = ", myVariable > print "otherVariable = ", otherVariable > > Is that even possible? > > The function would look like > > def probe(var): > nameOfVar = someMagic(var) > print nameOfVar, " = ", var > > but can someMagic(var) find the variable name? Is that possible? apart from very hackery, why don't you just use: def probe(**vars): for varname,value in vars.items(): print "%s = %r" % (varname,value) and call it like that: probe(myvar="foo") probe(othervar="bar") or even probe(myvar=myvar) (if myvar was assigned before) please note introspective approaches have a very narrow field where they can work - as already shown in other posts: you can have values w/o names and also more then one name to a value (or object). Regards Tino Wildenhain -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3254 bytes Desc: S/MIME Cryptographic Signature URL: From nagle at animats.com Wed Mar 17 02:34:21 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Mar 2010 23:34:21 -0700 Subject: Converting Python CGI to WSGI scripts In-Reply-To: References: <1268759895.28810.1365130739@webmail.messagingengine.com> Message-ID: <4ba0735b$0$1594$742ec2ed@news.sonic.net> Sebastian Bassi wrote: > On Tue, Mar 16, 2010 at 2:18 PM, wrote: >> I have a few dozen simple Python CGI scripts. >> Are there any advantages or disadvantages to rewriting these CGI scripts as >> WSGI scripts? > > It depends of the script. WSGI should be faster since you don't start > a Python instance for each call (as in CGI). It's almost always faster. But be careful about global state. Remember that WSGI/FCGI programs are really functions, called over and over with a new transaction on each call. So your function has to be reusable. Things like initializing global variables at program load time, rather than when the main function is called, may give trouble. Also, be careful about leaving files, database connections, and sockets open after the main function returns. John Nagle From kalakal46 at rediffmail.com Wed Mar 17 02:35:18 2010 From: kalakal46 at rediffmail.com (Hot Girls) Date: Tue, 16 Mar 2010 23:35:18 -0700 (PDT) Subject: %%% Funny College Girls Nude Video HERE %%% Message-ID: <77825db8-8873-4092-8db0-84a36f3fd818@w39g2000prd.googlegroups.com> %%% Funny College Girls Nude Video HERE %%% http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ $$$$ Enjoy actress SEX HERE $$$$ http://sites.google.com/site/hifiprofile/ From stefan_ml at behnel.de Wed Mar 17 02:46:20 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 07:46:20 +0100 Subject: C-API PyObject_Call In-Reply-To: References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: moerchendiser2k3, 16.03.2010 19:25: > Hi, currently I am not at home, I will post some stuff when I am back. > Just the note: I throw an exception with the C API. > > Looks like that > > > PyObject *result = PyObject_Call(my_isntance, "", NULL); > if(result==NULL) > { > PyErr_Print(); //when this happens, the traceback is correct with > information about the file/line > return; > } > > if(!PyXYZ_Check(result)) > { > PyErr_SetString(PyExc_TypeError, "Wrong type, ...."); > PyErr_Print(); //missing information of the file/line. > return; > } > > Well, I expect, that there are no information about the line/file, so > I know something is missing, but what is missing? Two solutions here: 1) put the line number information into the message string when you raise the exception 2) use Cython instead of plain C, as Cython will automatically generate readable stack traces for you, also for non-Python functions. Stefan From stefan_ml at behnel.de Wed Mar 17 02:48:31 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 07:48:31 +0100 Subject: import antigravity In-Reply-To: References: <4b9fdc50$0$22943$e4fe514c@news.xs4all.nl> Message-ID: Michael Rudolf, 17.03.2010 00:48: > Am 16.03.2010 21:44, schrieb Mark Lawrence: >> Who actually *IS* running the time machine? Are there any bugs?? > > My is. And as I'm a lazy hacker: sure. there are bugs. lets just call > them features and move on. nothing to see here ;) I'll know it, I'll just know it! Stefan From stefan_ml at behnel.de Wed Mar 17 02:54:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 07:54:04 +0100 Subject: C++ code generation In-Reply-To: <11c0630.1732.12769d42e98.Coremail.dr.cg@126.com> References: <11c0630.1732.12769d42e98.Coremail.dr.cg@126.com> Message-ID: CHEN Guang, 17.03.2010 02:54: > ----- Original Message ----- > From: "Dan Goodman" > >> I'm doing some C++ code generation using Python, and would be interested >> in any comments on the approach I'm taking. > > PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) It would be nice if you could start reading the posts before you answer, and then try to give an answer that fits the question. Stefan From sam at sambull.co.uk Wed Mar 17 04:43:38 2010 From: sam at sambull.co.uk (Sam Bull) Date: Wed, 17 Mar 2010 08:43:38 +0000 Subject: Timer Message-ID: <1268815418.2682.31.camel@s-desktop> I'm writing a pyGTK program, and I need to display the contents of a window for a few seconds before automatically moving on. I have tried using the time.sleep method, but this has problems, such as the program becoming unresponsive. I have now attempted to use a timer, but this does not seem to run the function at the end of the time. The code of my latest attempt: def next(self=None, testnum=10, testspeed=5): self.count += 1 #Sets label, telling the user the next word to memorise self.nobtns.set_markup("Word %s is: %s" % (self.count, self.words[self.count-1])) self.nobtns.show() if self.count == testnum: #When all words are shown self.nobtns.hide() else: self.timer = threading.Timer(testspeed, self.next, [testnum, testspeed]) self.timer.start() Putting a print statement at the beginning of the function, I can see that the function is not being run by the timer. Any help on getting this working would be appreciated. Thanks, Sam Bull -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From anand.shashwat at gmail.com Wed Mar 17 04:46:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 17 Mar 2010 14:16:00 +0530 Subject: using DictionaryServices module to get work with python2.6 #OSXspecific Message-ID: I wanted to use dictionary in my OSX terminal. So I wrote a function dict() in my ~/.bash_profile dict () { python2.5 -c 'import sys, DictionaryServices; word = " ".join(sys.argv[1:]); print DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word)))' $@ } here is the output: Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ dict lone wolf noun a person who prefers to act or be alone. The question is why not : DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) works with python2.6 ? Is DictionaryService module not available for python2.6 ? Here is the stack-trace: Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import DictionaryServices >>> word = "lone wolf" >>> DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) Traceback (most recent call last): File "", line 1, in IndexError: NSRangeException - *** -[OC_PythonString _createSubstringWithRange:]: Range or index out of bounds >>> Ofcourse it doesnt work with python2.7 too. Is this OSX specific issue ? Can I make it work with my compiled version of python ? Is there any workaround ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From grflanagan at gmail.com Wed Mar 17 04:54:14 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Wed, 17 Mar 2010 08:54:14 +0000 Subject: Dynamic Class Creation In-Reply-To: <8d79f0cb-9c5b-4243-8891-a15fb311f652@z18g2000prh.googlegroups.com> References: <8d79f0cb-9c5b-4243-8891-a15fb311f652@z18g2000prh.googlegroups.com> Message-ID: Josh English wrote: > Chris, > > Thanks. This worked for the attributes, but I think the tactic is > still misleading. There are child elements I can't quite determine how > to deal with: > > > Analog Science Fiction and Fact > Analog > Science Fiction > First Contact > Hard Science Fiction >
> Stanley Schmidt, Editor > 267 Broadway, 4th Floor > New York, NY 10007-2352 >
> http://www.analogsf.com >
> > A child element with text and an attribute or two, for example, pose a > problem. I can call Market.title but should I try Market.title.field > or Market.title_field. > > Multiple elements, such as keywords, are allowed in xml but harder to > map to the object. I don't know if I want to go create a list and > methods for accessing those keywords as a list, or redefine the rules > of my XML to not allow multiple child elements with the same tag. I > can't decide. > > Then the address is a bit of a bear. > > In short, I have to figure out the whole object interface to the XML > and how I want that to work. > Have you heard of or considered PyXB (http://pyxb.sourceforge.net/)? Not that I've much experience with it, but you can use it to generate python code from XML Schema files, and, I think, WSDL definitions. It's a bit of a rabbit hole, but then isn't that half the fun! The following might give you the idea. You start with a Schema schema.xsd, generate a python module from it, then read in some XML with the generated classes to get your custom objects. ---------------- schema.xsd ---------------------- ---------------- genbindings.sh --------------------------- #!/bin/sh pyxbgen -u schema.xsd -m market_binding -r ---------------- demo.py ----------------------------------- s = """ Analog Science Fiction and Fact Analog Science Fiction First Contact Hard Science Fiction
Stanley Schmidt, Editor 267 Broadway, 4th Floor New York
http://www.analogsf.com
""" import xml.dom.minidom import market_binding market = market_binding.CreateFromDOM(xml.dom.minidom.parseString(s).documentElement) print market.tier print market.code print market.keyword assert len(market.keyword) == 3 print market.address.name print market.toxml() From breamoreboy at yahoo.co.uk Wed Mar 17 04:56:48 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 17 Mar 2010 08:56:48 +0000 Subject: using DictionaryServices module to get work with python2.6 #OSXspecific In-Reply-To: References: Message-ID: Shashwat Anand wrote: > I wanted to use dictionary in my OSX terminal. > So I wrote a function dict() in my ~/.bash_profile > > dict () { > python2.5 -c 'import sys, DictionaryServices; word = " > ".join(sys.argv[1:]); print DictionaryServices.DCSCopyTextDefinition(None, > word, (0, len(word)))' $@ > } > > here is the output: > > Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ dict lone wolf > noun > a person who prefers to act or be alone. > > The question is why not : > DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) works > with python2.6 ? > Is DictionaryService module not available for python2.6 ? > > Here is the stack-trace: > > Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python > Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import DictionaryServices >>>> word = "lone wolf" >>>> DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) > Traceback (most recent call last): > File "", line 1, in > IndexError: NSRangeException - *** -[OC_PythonString > _createSubstringWithRange:]: Range or index out of bounds > > Ofcourse it doesnt work with python2.7 too. Is this OSX specific issue ? Can > I make it work with my compiled version of python ? Is there any workaround > ? > > Are you thinking of this? http://pypi.python.org/pypi/pyobjc-framework-DictionaryServices/2.2 HTH. Mark Lawrence From Ron.Barak at lsi.com Wed Mar 17 04:58:47 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 17 Mar 2010 08:58:47 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <4B9FB09A.7030609@ieee.org> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4B9F9DD0.2080306@ieee.org> <7F0503CD69378F49BE0DC30661C6CCF684F3C894@enbmail01.lsi.com> <4B9FB09A.7030609@ieee.org> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C8DF@enbmail01.lsi.com> > -----Original Message----- > From: Dave Angel [mailto:davea at ieee.org] > Sent: Tuesday, March 16, 2010 6:24 PM > To: Barak, Ron > Cc: Pablo Recio Quijano; python-list at python.org > Subject: Re: How to add a library path to pythonpath ? > > Barak, Ron wrote: > > > >> -----Original Message----- > >> From: Dave Angel [mailto:davea at ieee.org] > >> Sent: Tuesday, March 16, 2010 5:04 PM > >> To: Barak, Ron > >> Cc: Pablo Recio Quijano; python-list at python.org > >> Subject: RE: How to add a library path to pythonpath ? > >> > >> > >> > >> Barak, Ron wrote: > >> > >>> Thanks for the suggestion Pable. > >>> > >>> However, I really need the $PYTHONPATH to include this > >>> > >> additional library, so all Python scripts could use it. > >> > >>> In Windows I have defined PYTHONPATH as > >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and > also in the > >>> Windows registry I have > >>> > >>> > >>> > >> > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\version\PythonPath\ as > >> > >> > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMI > >> n > >> > >>> spector\lib\;C:\Python26\Lib\lib-tk; > >>> > >>> However, even with all the above, the SVMInspecor modules > >>> > >> are not found. > >> > >>> > >> See my response at the end. Top-posting makes for a very > confusing > >> thread. > >> > >>> > >>> > >>> 2010/3/16 Barak, Ron > > >>> > >>> Hi, > >>> > >>> I'm trying to add a library path to my pythonpath, but > >>> > >> seems it is not > >> > >>> accepted - > >>> > >>> On Windows DOS window: > >>> > >>> C:\>echo %PYTHONPATH% > >>> c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ > >>> > >>> C:\>python -c "import sys ; print sys.path" > >>> ['', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > >>> 'C:\\WINDOWS\\syst em32\\python26.zip', 'C:\\Python26\\DLLs', > >>> 'C:\\Python26\\lib', 'C:\\Python26\\l ib\\plat-win', > >>> 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\ > >>> site-packages', > >>> 'C:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > >>> > >>> C:\> > >>> > >>> On Windows cygwin: > >>> > >>> $ echo $PYTHONPATH > >>> .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > >>> > >>> $ python -c "import sys ; print sys.path" > >>> ['', > >>> > >>> > >> > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > >> > >>> 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > >>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > >>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > >>> 'c:\\Python26\\lib\\site-packages', > >>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > >>> > >>> $ > >>> > >>> What am I doing wrong ? > >>> > >>> Thanks, > >>> Ron. > >>> > >>> > >>> > >>> > >> In your original message, what you displayed worked exactly as > >> expected. As you didn't say what made you think something > was wrong, > >> I ignored the message. > >> > >> Now, you say that some modules are not found. So how about giving > >> some more specifics so someone can actually debug the > problem. Pick > >> a particular module, tell us the complete path to that module, and > >> show us both the sys.path strings (which look correct for > the Windows > >> case, and of course bogus for the cygwin case), as well as the > >> offending import statement and its traceback. > >> > >> DaveA > >> > > > > Hi Dave, > > > > My Python is the Windows Python (I need this for wxPython): > > > > $ ls -ls `which python` > > 1 lrwxrwxrwx 1 rbarak mkgroup-l-d 31 Mar 4 14:02 > /usr/bin/python -> > > /cygdrive/c/Python26/python.exe > > > > Here's a demo script: > > > > #!/usr/bin/env python > > > > import sys > > print "\n",sys.path,"\n" > > > > from ErrorManager.ErrorManager import ErrorManager > > > > And it's run produces: > > > > $ python -u tmp.py > > > > ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', > > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', > > 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', > > 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', > > 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', > > 'c:\\Python26\\lib\\site-packages', > > 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] > > > > Traceback (most recent call last): > > File "tmp.py", line 6, in > > from ErrorManager.ErrorManager import ErrorManager > > ImportError: No module named ErrorManager.ErrorManager > > > > $ ls -ls > > > /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager > > /ErrorManager.py > > 4 -rwxr-xr-x 1 rbarak ???????? 1843 Sep 21 19:16 > > > /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ErrorManager > > /ErrorManager.py > > > > $ grep ErrorManager > > /cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > ErrorManager/ErrorManager.py > > class ErrorManager: > > > > $ echo $PYTHONPATH > > .:/cygdrive/c/views/cc_view/TS_svm_ts_tool/SVMInspector/lib/ > > > > Please let me know if the above is enough, or you'd like to > see the results from a Windows' DOS window. > > > > Thanks, > > Ron. > > > > > Well, I pointed out that your cygwin path is bogus, so of > course it won't work. One of those entries is > > > '.:\\cygdrive\\c\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib' > > I use Linux, and I use Windows. But cygwin's glomming > together has never made sense; some things are Unix-like, > and others are Windows-like. So anything you do in that > environment is beyond me. > > If I had to guess, though I'd say you wanted to drop those > first two characters from your PYTHONPATH. If you really > wanted two directories there, you should be separating them > with semicolon (Windows rules), rather than colon (Linux > rules). First thing I'd do to test my theories is to print > something like: > print sys.path[1] > print os.listdir(sys.path[1]) > Does Python even see the cygwin view of the world ? > > You also don't show the location of the module you're trying > to import. > I'm guessing that it's at > ...SVMInspector/lib/ErrorManager/ErrorManager.py > Do you have a file > ...SVMInspector/lib/ErrorManager/__init__.py ? > > I would seriously recommend against naming your package, your > module, and your class all the same thing. Makes debugging > very hard. At least make them have different case combinations. > > DaveA > > Hi Dave, With the suggestions you made above, I managed to solve the problems I reported, and now my paths work as expected. Thanks a lot, Ron. $ cat tmp.py #!/usr/bin/env python import sys import os print "sys.path:",sys.path print "sys.path[1]:",sys.path[1] print "os.listdir(sys.path[1]):",os.listdir(sys.path[1]) from ErrorManager.ErrorManager import ErrorManager $ python -u tmp.py sys.path: ['c:\\views\\cc_view\\TS_svm_ts_tool\\svm_ts_tool', 'c:\\views\\cc_view\\TS_svm_ts_tool\\SVMInspector\\lib', 'C:\\WINDOWS\\system32\\python26.zip', 'c:\\Python26\\DLLs', 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 'c:\\Python26\\lib\\site-packages', 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode'] sys.path[1]: c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib os.listdir(sys.path[1]): ['ConnectivityManager', 'ErrorManager', 'Utility'] $ echo $PYTHONPATH c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ $ echo $PYTHON_PATH c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikelisanke at gmail.com Wed Mar 17 05:08:18 2010 From: mikelisanke at gmail.com (MikeLisanke@gmail.com) Date: Wed, 17 Mar 2010 02:08:18 -0700 (PDT) Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> Message-ID: <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> On Mar 16, 3:12?pm, "Gabriel Genellina" wrote: > En Tue, 16 Mar 2010 13:20:40 -0300, Johny escribi?: > > > Is there any tutorial how to write a bindings for a exe ( dos) > > program? > > I would like to run it from a Python directly > > ( using import command and a particular function from the binding) > > ?not using os.system command. > > Do you mean that you want to execute a particular function in the .exe ? > program? > That's not possible (ok, you *could* do that if you work hard enough, but ? > that's not how things are usually done) > > -- > Gabriel Genellina Gabriel, Its interesting you've mentioned the hard work involved in this interface (binding to an EXE instead of a DLL). A year or more ago I was looking at interfacing IPMITOOL to python. Do to the problems incurred with swig/python I switched to a running the process through its command-line interface. I always felt the problems in interfacing python to an EXE should be worked on (to minimize them), making the direct use of an EXE API's a routine task. I understand some of the problems using an EXE (not running all of its startup code but enough for its proper operation). Have you found this a recurring question? Thanks. Regards, Mike From Neil.Blue at biowisdom.com Wed Mar 17 05:12:33 2010 From: Neil.Blue at biowisdom.com (Neil Blue) Date: Wed, 17 Mar 2010 09:12:33 -0000 Subject: How to handle file uploads with http.server In-Reply-To: References: <91ad5bf81003110221m5e383f8fkc7959aa2887927eb@mail.gmail.com><4728DC0EADB2654E8BA2A487F0CF2785AD6D2E@ws-ukexchange.internal.biowisdom.com> Message-ID: <4728DC0EADB2654E8BA2A487F0CF2785AD6D3E@ws-ukexchange.internal.biowisdom.com> Thanks Gabriel Yep, that looks like the same one. Cheers Neil -----Original Message----- From: Gabriel Genellina [mailto:gagsl-py2 at yahoo.com.ar] Sent: 17 March 2010 02:08 To: python-list at python.org Subject: Re: How to handle file uploads with http.server En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue escribi?: > I have a basic http.server instance running (class > HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and > I would like to upload files with multipart forms. > > def do_POST(self): > ctype, pdict = cgi.parse_header(self.headers['Content-Type']) > if ctype=='multipart/form-data': > print('parsing...') > query=cgi.parse_multipart(self.rfile, pdict) > print(query) > > However the file never seems to finish being parsed. There are no > errors, but the call hangs at: query=cgi.parse_multipart(self.rfile, > pdict) This may be related to this bug: http://bugs.python.org/issue8077 reported last week by Mitchell L. Model in this thread: http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/ -- Gabriel Genellina ********************************************* The information contained in this message is likely to be confidential. It is intended only for the person named above. Any dissemination, distribution, copying, disclosure or use of this message or its contents unless authorised by BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of BioWisdom Ltd. If you have received this message in error, please immediately notify us and delete it. Thank you. Registered Office: BioWisdom Ltd, Harston Mill, Harston, Cambridge, CB22 7GG. Registered in England: (GB) 3861669. VAT registered: (GB) 750899881. Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, Internet:www.biowisdom.com ********************************************* From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 05:12:54 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 10:12:54 +0100 Subject: to pass self or not to pass self In-Reply-To: <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: <4ba09d09$0$21466$426a74cc@news.free.fr> Patrick Maupin a ?crit : > On Mar 16, 1:59 pm, Jason Tackaberry wrote: >> Why not create the bound methods at instantiation time, rather than >> using the descriptor protocol which has the overhead of creating a new >> bound method each time the method attribute is accessed? > > Well, for one thing, Python classes are open. They can be added to at > any time. For another thing, you might not ever use most of the > methods of an instance, so it would be a huge waste to create those. A possible optimization would be a simple memoization on first access. From __peter__ at web.de Wed Mar 17 05:16:17 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 10:16:17 +0100 Subject: Timer References: Message-ID: Sam Bull wrote: > I'm writing a pyGTK program, and I need to display the contents of a > window for a few seconds before automatically moving on. I have tried > using the time.sleep method, but this has problems, such as the program > becoming unresponsive. > > I have now attempted to use a timer, but this does not seem to run the > function at the end of the time. The code of my latest attempt: > > def next(self=None, testnum=10, testspeed=5): > self.count += 1 > #Sets label, telling the user the next word to memorise > self.nobtns.set_markup("Word %s is: %s" % (self.count, > self.words[self.count-1])) > self.nobtns.show() > if self.count == testnum: #When all words are shown > self.nobtns.hide() > else: > self.timer = threading.Timer(testspeed, self.next, [testnum, > testspeed]) > self.timer.start() > > Putting a print statement at the beginning of the function, I can see > that the function is not being run by the timer. Any help on getting > this working would be appreciated. GUI toolkits usually have their own way of handling timeouts. I don't know pygtk, but the following looks promising: http://www.pygtk.org/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html Peter From anand.shashwat at gmail.com Wed Mar 17 05:18:06 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 17 Mar 2010 14:48:06 +0530 Subject: using DictionaryServices module to get work with python2.6 #OSXspecific In-Reply-To: References: Message-ID: > Are you thinking of this? > http://pypi.python.org/pypi/pyobjc-framework-DictionaryServices/2.2 > I get the same IndexError while working with this wrapper. My guess is python2.6 does not support DictionaryServices on Snow Leopard . -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Wed Mar 17 05:36:29 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 10:36:29 +0100 Subject: Python bindings tutorial In-Reply-To: <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: MikeLisanke at gmail.com, 17.03.2010 10:08: > Its interesting you've mentioned the hard work involved in this > interface (binding to an EXE instead of a DLL). A year or more ago I > was looking at interfacing IPMITOOL to python. Do to the problems > incurred with swig/python I switched to a running the process through > its command-line interface. I always felt the problems in interfacing > python to an EXE should be worked on (to minimize them), making the > direct use of an EXE API's a routine task. I understand some of the > problems using an EXE (not running all of its startup code but > enough for its proper operation). Have you found this a recurring > question? Thanks. I think the point here is that executable binaries are not supposed to be used as libraries. Libraries are. That's the difference between a DLL and an executable in the first place. To run an executable, execute it. The subprocess module is the tool of choice here. To use a DLL, link against it. Stefan From dr.cg at 126.com Wed Mar 17 05:41:55 2010 From: dr.cg at 126.com (CHEN Guang) Date: Wed, 17 Mar 2010 17:41:55 +0800 (CST) Subject: C++ code generation Message-ID: <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> >> ----- Original Message ----- >> From: "Dan Goodman" >> >>> I'm doing some C++ code generation using Python, and would be interested >>> in any comments on the approach I'm taking. >> >> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) > > It would be nice if you could start reading the posts before you answer, > and then try to give an answer that fits the question. > > Stefan I have read the post, may be I lost some words and made you misunderstand. I meant: PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not C++), if you find it useful, welcome to take a look. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Ron.Barak at lsi.com Wed Mar 17 06:25:58 2010 From: Ron.Barak at lsi.com (Barak, Ron) Date: Wed, 17 Mar 2010 10:25:58 +0000 Subject: How to add a library path to pythonpath ? In-Reply-To: <4BA01D6A.60208@gmail.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C838@enbmail01.lsi.com> <1fb1c371003160527q10add6bfk75c09b24bc486329@mail.gmail.com> <7F0503CD69378F49BE0DC30661C6CCF684F3C883@enbmail01.lsi.com> <4BA01D6A.60208@gmail.com> Message-ID: <7F0503CD69378F49BE0DC30661C6CCF684F3C8FE@enbmail01.lsi.com> > -----Original Message----- > From: Mark Hammond [mailto:skippy.hammond at gmail.com] > Sent: Wednesday, March 17, 2010 2:08 AM > To: Barak, Ron > Cc: Pablo Recio Quijano; python-list at python.org > Subject: Re: How to add a library path to pythonpath ? > > On 17/03/2010 1:26 AM, Barak, Ron wrote: > > Thanks for the suggestion Pable. > > However, I really need the $PYTHONPATH to include this additional > > library, so all Python scripts could use it. > > In Windows I have defined PYTHONPATH as > > c:\views\cc_view\TS_svm_ts_tool\SVMInspector\lib\, and also in the > > Windows registry I have > > > HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\/version/\Python > Path\ as > > > C:\Python26\Lib;C:\Python26\DLLs;C:\views\cc_view\TS_svm_ts_tool\SVMIn > > spector\lib\;C:\Python26\Lib\lib-tk; > > However, even with all the above, the SVMInspecor modules > are not found. > > You need to create your own sub-key, with any name, under the > PythonPath key and add your path there. The reason is that > Python only looks for that root key when it can't sniff the > location of the library itself based on the location of the > executable - and in most cases it can. > Python does however enumerate and use the sub-keys in all cases. > > HTH, > > Mark > Hi Mark, Could you give an example ilustrating your suggestion ? Thanks, Ron. From lie.1296 at gmail.com Wed Mar 17 06:41:50 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 17 Mar 2010 21:41:50 +1100 Subject: to pass self or not to pass self In-Reply-To: References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4ba06148$1@dnews.tpgi.com.au> Message-ID: <4ba0b20e$1@dnews.tpgi.com.au> On 03/17/2010 04:32 PM, Steven D'Aprano wrote: > On Wed, 17 Mar 2010 15:57:17 +1100, Lie Ryan wrote: > >> Most people probably would never need to use >> descriptor protocol directly, since the immediate benefit of descriptor >> protocol are property(), classmethod(), and instancemethod() decorators >> which, without descriptor protocol, would never become a possibility. > > > There's an instancemethod decorator? Where? > > Are you thinking of staticmethod? "instancemethod", if you mean what I > think you mean, doesn't need a decorator because it is the default > behaviour for new-style classes. Whoops... yep, sorry about that. Got all it up the mixed head in... From chambon.pascal at gmail.com Wed Mar 17 06:42:44 2010 From: chambon.pascal at gmail.com (Pakal) Date: Wed, 17 Mar 2010 03:42:44 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() Message-ID: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> Hello I've just realized recently that sys.exc_info() didn't return a full traceback for exception concerned : it actually only contains the frame below the point of exception catching. That's very annoying to me, because I planned to log such tracebacks with logging.critical(*****, exc_info=True), and these partial tracebacks, like the one below, are clearly unsufficient to determine where the problem comes from. A whole traceback, from program entry point to exception raising point, would be much better. 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to ensure critical emails are properly sent Traceback (most recent call last): << HERE, lots of frames missing >> File "test_common.py", line 34, in test_email_sending os.open("qsdsdqsdsdqsd", "r") TypeError: an integer is required Is there any workaround for this ? I've thought about a custom logging formatter, which would take both the exc_info traceback AND its own full backtrace, and to connect them together on their relevant part, but it's awkward and error prone... why can't we just have all the precious traceback info under the hand there (an additional attribute might have pointed the precise frame in which the exception was caught). Tanks for the attention, Regards, Pascal From davea at ieee.org Wed Mar 17 06:55:38 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Mar 2010 05:55:38 -0500 Subject: datetime string conversion error In-Reply-To: References: <8cebc349-33d5-4820-a944-2e6869408f0f@c34g2000pri.googlegroups.com> Message-ID: <4BA0B52A.10708@ieee.org> Gabriel Genellina wrote: > En Tue, 16 Mar 2010 20:31:11 -0300, Josh English > escribi?: > >> On Mar 16, 11:56 am, Jordan Apgar wrote: >> >>> here's what I'm doing: >>> date = "2010-03-16 14:46:38.409137" >>> olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f") >>> >> >> Due to circumstances, I'm using Python 2.5.4 on one machine (2.6 on >> the other). >> >> When I have a script as simple as this: >> >> import datetime >> >> datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") >> >> >> Running this script brings up a calendar, believe it or not. The >> calendar displays March 2010, and shows the 22nd as a holiday. When I >> dismiss the dialog box I get: >> Traceback (most recent call last): >> File "strptimetest.py", line 3, in >> datetime.datetime.strptime('2010-09-14', "%Y-%m-%d") >> File "C:\Python25\lib\_strptime.py", line 272, in >> _TimeRE_cache = TimeRE() >> File "C:\Python25\lib\_strptime.py", line 191, in __init__ >> self.locale_time = LocaleTime() >> File "C:\Python25\lib\_strptime.py", line 74, in __init__ >> self.__calc_weekday() >> File "C:\Python25\lib\_strptime.py", line 94, in __calc_weekday >> a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] >> AttributeError: 'module' object has no attribute 'day_abbr' > > I'd say you have a calendar.py script somewhere along your sys.path, > that shadows the calendar module in the standard library. > And to find it, you could try the following: import datetime print calendar.__file__ I suspect you have more problems than just that file, but perhaps finding that one can tell you what extra package you've got installed that shadows parts of the standard library. Try temporarily renaming it to see if the problem goes away. DaveA From davea at ieee.org Wed Mar 17 07:14:13 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Mar 2010 06:14:13 -0500 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: <4BA0B985.3060501@ieee.org> Stefan Behnel wrote: >
MikeLisanke at gmail.com, 17.03.2010 10:08: >> Its interesting you've mentioned the hard work involved in this >> interface (binding to an EXE instead of a DLL). A year or more ago I >> was looking at interfacing IPMITOOL to python. Do to the problems >> incurred with swig/python I switched to a running the process through >> its command-line interface. I always felt the problems in interfacing >> python to an EXE should be worked on (to minimize them), making the >> direct use of an EXE API's a routine task. I understand some of the >> problems using an EXE (not running all of its startup code but >> enough for its proper operation). Have you found this a recurring >> question? Thanks. > > I think the point here is that executable binaries are not supposed to > be used as libraries. Libraries are. That's the difference between a > DLL and an executable in the first place. To run an executable, > execute it. The subprocess module is the tool of choice here. To use a > DLL, link against it. > > Stefan > There's no real reason parts of an exe cannot be exported, same as a dll. They are in fact the same structure. And in fact many other files in the Windows environment are also the same structure, from fonts to ocx's Saying they're "not supposed to be used" is like saying that a python module should not have an if __name__ == "__main__": section. After all, who could want to both run a file, and import the same file?? DaveA From hatem.oraby at gmail.com Wed Mar 17 07:26:33 2010 From: hatem.oraby at gmail.com (Hatem Oraby) Date: Wed, 17 Mar 2010 13:26:33 +0200 Subject: Swapping Content of Two Dictionaries. In-Reply-To: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> Message-ID: <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Hello, I want to swap the content of two dictionaries, the obvious way to do it is: a = {1:"I'am A"} b = {2:"I'm B"} temp = a a = b b = temp However, consider the case in which the dictionary we are referencing lives in another module: #external.py # #a = {1:"I'am A} import external temp = external.a external.a = b b = temp Well, still this would work great and anyone later that would refereence external.a would find the content of b, but consider the case where someone else imported "external.py" before my module run, for example: #external.py # #a = {1:"I'm A} #annoyer.py #from external import a # # #Do other stuff with a import external temp = external.a external.a = b b = temp Now in such case when I overwrite the content of external.a in my module, the change in dictionary is not reflected in annoyer module, that's because annoyer hold a reference to the original a but not the new one. annoyer module still see the old content of a. The workaround that i did to solve this problem is the following (I'm simplifying it right here): tempKeys = a.keys() diffKeys = a.keys() - b.keys() #I do it using set()s #item = a temp = {} for key in a.keys(): item[key] = a[key] for key in diffKeys: del a[key] #delete stuff that exist in a but not b. for key in b.keys(): a[key] = b[key] b = temp This works great as the content referenced by the dictionary is changed rather than changing the reference of dictionary itself so it's reflected by any "scope" that references the dictionary. My problem is that i need to do this operation a LOT, simply I got a problem that my program go through a very long loop and inside this loop this operation is needed to be done twice and the dictionary size ain't very small. If anyone has a suggestion one how to do it faster then please feel free and welcome to contribute. Anyway, I decided to go and implement it in C to gain performance, And since I got no expereince in writing C extension I'm not really sure if what I'm doing right or wrong, long story short here is what i decided to do: In real python (I mean not the C code) an object is mainly a reference to a C PyObject (or an inheritance of the PyObject). Python dictionaries are represented as PyDictObject (PyDictObject inherits PyObject), so every Python Dictionary is a reference to PyDictObject, So what i came up with to swap two Python dictionaries is to swap the content of PyDictObjects of the dictionaries, I know that "illegal" way of doing things in Python but I need the hack to gain performance. I opened up python source files: object.h (extracted the definition of PyObject) dictObject.g (extctracted the definition of PyDictObject) And I've written the following C extension: 1. #include 2. #include //I know that it was already imported 3. 4. static char swap_doc[] = 5. "My try to swap dicts, isa hopefully it will work good."; 6. 7. 8. static PyObject* 9. swap_swapDict(PyObject *self, PyObject *args) 10. { 11. PyObject *a, *b; 12. PyDictObject *x, *y; 13. //Temp PyDictObject attriubutes 14. Py_ssize_t ob_refcnt; 15. PyTypeObject *ob_type; 16. Py_ssize_t ma_fill; 17. Py_ssize_t ma_used; 18. Py_ssize_t ma_mask; 19. PyDictEntry *ma_table; 20. PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash); 21. PyDictEntry *ma_smalltable;//[PyDict_MINSIZE]; 22. 23. 24. if (!PyArg_UnpackTuple(args, "swapDict", 2, 2, &a, &b)) { 25. return NULL; 26. } 27. 28. //Make sure that they are dictionaries 29. if (!PyDict_Check(a) && !PyDict_Check(b)) { 30. PyErr_SetString(PyExc_TypeError, 31. "dictionary required, something else was passed"); 32. return NULL; 33. } 34. 35. x = (PyDictObject*)a; 36. y = (PyDictObject*)b; 37. 38. ob_refcnt = x->ob_refcnt; 39. x->ob_refcnt = y->ob_refcnt; 40. y->ob_refcnt = ob_refcnt; 41. 42. ob_type = x->ob_type; 43. x->ob_type = y->ob_type; 44. y->ob_type = ob_type; 45. 46. ma_fill = x->ma_fill; 47. x->ma_fill = y->ma_fill; 48. y->ma_fill = ma_fill; 49. 50. ma_used = x->ma_used; 51. x->ma_used = y->ma_used; 52. y->ma_used = ma_used; 53. 54. ma_mask = x->ma_mask; 55. x->ma_mask = y->ma_mask; 56. y->ma_mask = ma_mask; 57. 58. ma_table = x->ma_table; 59. x->ma_table = y->ma_table; 60. y->ma_table = ma_table; 61. 62. ma_lookup = x-> ma_lookup; 63. x->ma_lookup = y-> ma_lookup; 64. y->ma_lookup = ma_lookup; 65. 66. ma_smalltable = x->ma_smalltable; 67. *(x->ma_smalltable) = *(y->ma_smalltable); 68. *(y->ma_smalltable) = *(ma_smalltable); 69. 70. return Py_None; 71. } 72. 73. //This is extracted form dictObject.h and object.h 74. //typedef struct _dictobject PyDictObject; 75. //struct _dictobject { 76. // PyObject_HEAD 77. // Py_ssize_t ma_fill; /* # Active + # Dummy */ 78. // Py_ssize_t ma_used; /* # Active */ 79. // 80. // /* The table contains ma_mask + 1 slots, and that's a power of 2. 81. // * We store the mask instead of the size because the mask is more 82. // * frequently needed. 83. // */ 84. // Py_ssize_t ma_mask; 85. // 86. // /* ma_table points to ma_smalltable for small tables, else to 87. // * additional malloc'ed memory. ma_table is never NULL! This rule 88. // * saves repeated runtime null-tests in the workhorse getitem and 89. // * setitem calls. 90. // */ 91. // PyDictEntry *ma_table; 92. // PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash); 93. // PyDictEntry ma_smalltable[PyDict_MINSIZE]; 94. //}; 95. //PyObject_Head is a simple two statements equal to: 96. //Py_ssize_t ob_refcnt; 97. //struct _typeobject *ob_type; 98. 99. static char swap_swapDict_doc[] = 100. "Replaces two dicts with each other."; 101. 102. static PyMethodDef swap_methods[] = { 103. {"swapDict", swap_swapDict, METH_VARARGS, swap_swapDict_doc} , 104. {NULL, NULL} 105. }; 106. 107. PyMODINIT_FUNC 108. initswap(void) 109. { 110. Py_InitModule3("swap", swap_methods, swap_doc); 111. } What the code mainly do is that it swap the content of the PyDict objects. However I got a bug where one of them swaps correctly while the other points to a displaced memory location. -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.ricordeau at gmail.com Wed Mar 17 07:40:19 2010 From: michael.ricordeau at gmail.com (Michael Ricordeau) Date: Wed, 17 Mar 2010 12:40:19 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> Message-ID: <20100317124019.7013dfa3@moriz.interne> Hi, to log tracebacks, you can probably try traceback module. I use it like this : import traceback .... #?your code for line in traceback.format_exc().splitlines(): log.trace(line) Le Wed, 17 Mar 2010 03:42:44 -0700 (PDT), Pakal a ?crit : > Hello > > I've just realized recently that sys.exc_info() didn't return a full > traceback for exception concerned : it actually only contains the > frame below the point of exception catching. > > That's very annoying to me, because I planned to log such tracebacks > with logging.critical(*****, exc_info=True), and these partial > tracebacks, like the one below, are clearly unsufficient to determine > where the problem comes from. A whole traceback, from program entry > point to exception raising point, would be much better. > > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to > ensure critical emails are properly sent > Traceback (most recent call last): > << HERE, lots of frames missing >> > File "test_common.py", line 34, in test_email_sending > os.open("qsdsdqsdsdqsd", "r") > TypeError: an integer is required > > Is there any workaround for this ? I've thought about a custom logging > formatter, which would take both the exc_info traceback AND its own > full backtrace, and to connect them together on their relevant part, > but it's awkward and error prone... why can't we just have all the > precious traceback info under the hand there (an additional attribute > might have pointed the precise frame in which the exception was > caught). > > Tanks for the attention, > Regards, > Pascal From alfps at start.no Wed Mar 17 08:03:06 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 17 Mar 2010 13:03:06 +0100 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: * Dave Angel: > Stefan Behnel wrote: >>
MikeLisanke at gmail.com, 17.03.2010 10:08: >>> Its interesting you've mentioned the hard work involved in this >>> interface (binding to an EXE instead of a DLL). A year or more ago I >>> was looking at interfacing IPMITOOL to python. Do to the problems >>> incurred with swig/python I switched to a running the process through >>> its command-line interface. I always felt the problems in interfacing >>> python to an EXE should be worked on (to minimize them), making the >>> direct use of an EXE API's a routine task. I understand some of the >>> problems using an EXE (not running all of its startup code but >>> enough for its proper operation). Have you found this a recurring >>> question? Thanks. >> >> I think the point here is that executable binaries are not supposed to >> be used as libraries. Libraries are. That's the difference between a >> DLL and an executable in the first place. To run an executable, >> execute it. The subprocess module is the tool of choice here. To use a >> DLL, link against it. >> >> Stefan >> > There's no real reason parts of an exe cannot be exported, same as a > dll. They are in fact the same structure. And in fact many other files > in the Windows environment are also the same structure, from fonts to ocx's > > Saying they're "not supposed to be used" is like saying that a python > module should not have an > > if __name__ == "__main__": > > section. After all, who could want to both run a file, and import the > same file?? A Windows DLL has defined initialization and cleanup per process and per thread. This means that e.g. static variables can be properly initialized when you load the DLL in order to use its functions (I'm skipping discussion of subtle problems, but that's the essence). A Windows EXE has (only) a single entry point which is for process startup. It invokes the EXE's behavior-as-a-program. There is no way to use it to e.g. initialize static variables in order to use exported functions. Hence Mike Lisanke's idea of "not running all of its startup code but enough for its proper operation" is generally not possible. An EXE can be used as a kind of server, /if/ it is designed for that. In particular it can be a COM server, allowing access of its functionality from any COM-enabled binding, which for Python would mean OLE Automation (COM, OLE, Automation: this is Microsoft technology, we're talking Windows EXEs here). But a Python binding to EXEs in general can't, as far as I can see, make assumptions about any particular kind of server being implemented by the EXE. Cheers & hth., - Alf From stefan_ml at behnel.de Wed Mar 17 08:18:33 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 13:18:33 +0100 Subject: Python bindings tutorial In-Reply-To: <4BA0B985.3060501@ieee.org> References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> <4BA0B985.3060501@ieee.org> Message-ID: Dave Angel, 17.03.2010 12:14: > Stefan Behnel wrote: >> I think the point here is that executable binaries are not supposed to >> be used as libraries. Libraries are. That's the difference between a >> DLL and an executable in the first place. To run an executable, >> execute it. The subprocess module is the tool of choice here. To use a >> DLL, link against it. >> > There's no real reason parts of an exe cannot be exported, same as a > dll. They are in fact the same structure. And in fact many other files > in the Windows environment are also the same structure, from fonts to ocx's So, because you can, you'd also try to link against fonts then, I guess? I hope you notice that what you and me said isn't contradictory. But there's a reason why there are libraries and executables, and there's no reason you *should* export anything from an executable - that's what libraries are there for. That's my point. Besides, nothing guarantees that it's safe to call stuff that an executable exports. The executable may well require some setup code that it only executes when it is properly started. Stefan From rps at haystack.mit.edu Wed Mar 17 08:24:03 2010 From: rps at haystack.mit.edu (robert schaefer) Date: Wed, 17 Mar 2010 08:24:03 -0400 Subject: question about tkinter Message-ID: <54C3DEE7-50FE-46D8-B1EA-E2C54E11817F@haystack.mit.edu> Hello, This is my first posting to this list so please be gentle - I am new to python and am using it on red-hat linux (I am new to that too). I am responsible for installing open source packages (including python) onto a distributed system of linux boxes. My question is, on python version 2.6.2 tkinter refuses to install. Without tkinter, I cannot use Idle. I looked at the install/configure script and hacked it a bit, but every fix only caused new problems. There are serious issues with that script for finding necessary libraries. We have a Sun-OS box with python version 2.5.x (I don't know the means of installation) that tkinter installed correctly, and Idle works fine. My question is - has anyone else noticed the problem of tkinter and red-hat linux? Has this been corrected in python 2.6.4 (or 2.6.5)? thanks, bob s. ----------------------------------- robert schaefer Atmospheric Sciences Group MIT Haystack Observatory Westford, MA 01886 email: rps at haystack.mit.edu voice: 781-981-5767 www: http://www.haystack.mit.edu From __peter__ at web.de Wed Mar 17 08:34:51 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 13:34:51 +0100 Subject: Swapping Content of Two Dictionaries. References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Message-ID: Hatem Oraby wrote: > Hello, I want to swap the content of two dictionaries, the obvious way to > do it is: > a = {1:"I'am A"} > b = {2:"I'm B"} > temp = a > a = b > b = temp That can be simplified to a, b = b, a and is almost certainly the right approach. > tempKeys = a.keys() > diffKeys = a.keys() - b.keys() #I do it using set()s > > #item = a > temp = {} > for key in a.keys(): > item[key] = a[key] > > for key in diffKeys: > del a[key] #delete stuff that exist in a but not b. > > for key in b.keys(): > a[key] = b[key] > > b = temp > > This works great as the content referenced by the dictionary is changed > rather than changing the reference of dictionary itself so it's reflected > by any "scope" that references the dictionary. > > My problem is that i need to do this operation a LOT, simply I got a > problem that my program go through a very long loop and inside this loop > this operation is needed to be done twice and the dictionary size ain't > very small. You could try >>> a = {"a": 1, "b": 2} >>> b = {"b": 3, "c": 4} >>> t = a.copy() >>> a.clear() >>> a.update(b) >>> b.clear() >>> b.update(t) >>> a {'c': 4, 'b': 3} >>> b {'a': 1, 'b': 2} > If anyone has a suggestion one how to do it faster then please feel free > and welcome to contribute. > Anyway, I decided to go and implement it in C to gain performance, And Premature optimization? If you explain what you are trying to achieve someone might come up with a way to do it without swapping dict contents. Peter From chambon.pascal at gmail.com Wed Mar 17 08:42:06 2010 From: chambon.pascal at gmail.com (Pascal Chambon) Date: Wed, 17 Mar 2010 13:42:06 +0100 Subject: Castrated traceback in sys.exc_info() In-Reply-To: <20100317124019.7013dfa3@moriz.interne> References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> Message-ID: <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> Hello, traceback functions indeed allow the manipulation of exception tracebacks, but the root problem is that anyway, since that traceback is incomplete, your "traceback.format_exc().splitlines()" will only provide frames for callee (downward) functions, not caller (upward) ones, starting from the exception catching frame. Regards, Pascal 2010/3/17 Michael Ricordeau > Hi, > > to log tracebacks, you can probably try traceback module. > > I use it like this : > > import traceback > .... # your code > > for line in traceback.format_exc().splitlines(): > log.trace(line) > > > > Le Wed, 17 Mar 2010 03:42:44 -0700 (PDT), > Pakal a ?crit : > > > Hello > > > > I've just realized recently that sys.exc_info() didn't return a full > > traceback for exception concerned : it actually only contains the > > frame below the point of exception catching. > > > > That's very annoying to me, because I planned to log such tracebacks > > with logging.critical(*****, exc_info=True), and these partial > > tracebacks, like the one below, are clearly unsufficient to determine > > where the problem comes from. A whole traceback, from program entry > > point to exception raising point, would be much better. > > > > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to > > ensure critical emails are properly sent > > Traceback (most recent call last): > > << HERE, lots of frames missing >> > > File "test_common.py", line 34, in test_email_sending > > os.open("qsdsdqsdsdqsd", "r") > > TypeError: an integer is required > > > > Is there any workaround for this ? I've thought about a custom logging > > formatter, which would take both the exc_info traceback AND its own > > full backtrace, and to connect them together on their relevant part, > > but it's awkward and error prone... why can't we just have all the > > precious traceback info under the hand there (an additional attribute > > might have pointed the precise frame in which the exception was > > caught). > > > > Tanks for the attention, > > Regards, > > Pascal > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Mar 17 09:00:32 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 14:00:32 +0100 Subject: question about tkinter References: Message-ID: robert schaefer wrote: > This is my first posting to this list so please be gentle - > > I am new to python and am using it on red-hat linux (I am new to that > too). I am responsible for installing open source packages (including > python) onto a distributed system of linux boxes. > > My question is, on python version 2.6.2 tkinter refuses to install. Does it say "I'm sorry Bob, I'm afraid I can't do this"? > Without tkinter, I cannot use Idle. > > I looked at the install/configure script and hacked it a bit, but every > fix only caused new problems. > There are serious issues with that script for finding necessary > libraries. If there are serious problems you have to give some details. However, if in the past a newbie had problems with Tkinter support on linux the most frequent problem was that the Tcl/Tk development libraries weren't installed. I don't know how those are called on Red Hat, maybe something like tcl*-dev.rpm Did you install these before running the configure script? Peter From lie.1296 at gmail.com Wed Mar 17 09:16:53 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 18 Mar 2010 00:16:53 +1100 Subject: to pass self or not to pass self In-Reply-To: <4ba09d09$0$21466$426a74cc@news.free.fr> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> Message-ID: <4ba0d65f$1@dnews.tpgi.com.au> On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote: > Patrick Maupin a ?crit : >> On Mar 16, 1:59 pm, Jason Tackaberry wrote: >>> Why not create the bound methods at instantiation time, rather than >>> using the descriptor protocol which has the overhead of creating a new >>> bound method each time the method attribute is accessed? >> >> Well, for one thing, Python classes are open. They can be added to at >> any time. For another thing, you might not ever use most of the >> methods of an instance, so it would be a huge waste to create those. > > A possible optimization would be a simple memoization on first access. But what if, for example, one uses some descriptor/metaclass magic to make it so that each subsequent access to the attribute returns a method bound to different objects? From h.stenstrom at gmail.com Wed Mar 17 09:20:42 2010 From: h.stenstrom at gmail.com (=?ISO-8859-1?Q?Helge_Stenstr=F6m?=) Date: Wed, 17 Mar 2010 06:20:42 -0700 (PDT) Subject: Function that knows its argument's variable name References: <47e725b6-1470-4563-a64b-02630032ef36@g26g2000yqn.googlegroups.com> <80ai5hFh3uU1@mid.individual.net> Message-ID: <02eb7ec7-1e22-43a4-8019-9a154c734669@y17g2000yqd.googlegroups.com> Thank you to all who answered. Inspection is apparently possible, but too complex for me. Greg's solution does what I want, inserting "" is no problem. /Helge > Not exactly, but you can come close with a little hackery. > > import sys > > def print_var(name): > ? ?print name, "=", sys._getframe(1).f_locals[name] > > def f(): > ? ?fred = 42 > ? ?mary = "christmas" > ? ?print_var("fred") > ? ?print_var("mary") > > f() > > -- > Greg From python at bdurham.com Wed Mar 17 09:22:37 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Mar 2010 09:22:37 -0400 Subject: Web Hosting Python 3 In-Reply-To: <0016e64642280288940481f66d5e@google.com> References: <0016e64642280288940481f66d5e@google.com> Message-ID: <1268832157.6206.1365286517@webmail.messagingengine.com> Hidura, > Hello list, i am in a project what need hosting, who give hosting to python3? Check out www.webfaction.com. I'm extremely pleased with this vendor. Highly recommended! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From vinay_sajip at yahoo.co.uk Wed Mar 17 09:24:43 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 17 Mar 2010 06:24:43 -0700 (PDT) Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> Message-ID: <95063943-4a45-42f5-81a2-761cf48daaa8@d27g2000yqf.googlegroups.com> On Mar 17, 10:42?am, Pakal wrote: > Hello > > I've just realized recently that sys.exc_info() didn't return a full > traceback for exception concerned : it actually only contains the > frame below the point of exception catching. > > That's very annoying to me, because I planned to log such tracebacks > withlogging.critical(*****, exc_info=True), and these partial > tracebacks, like the one below, are clearly unsufficient to determine > where the problem comes from. A whole traceback, from program entry > point to exception raising point, would be much better. > > 2010-03-17 09:28:59,184 - pims - CRITICAL - This is just a test to > ensure critical emails are properly sent > Traceback (most recent call last): > << HERE, lots of frames missing >> > ? File "test_common.py", line 34, in test_email_sending > ? ? os.open("qsdsdqsdsdqsd", "r") > TypeError: an integer is required > > Is there any workaround for this ? I've thought about a customlogging > formatter, which would take both the exc_info traceback AND its own > full backtrace, and to connect them together on their relevant part, > but it's awkward and error prone... why can't we just have all the > precious traceback info under the hand there (an additional attribute > might have pointed the precise frame in which the exception was > caught). > > Tanks for the attention, > Regards, > Pascal Do you have a short script which demonstrates the problem? Some more context is needed. For example, if you have multiple threads of execution, the traceback will only go up to the top-level function in the thread. Regards, Vinay Sajip From a_jtim at bellsouth.net Wed Mar 17 09:30:24 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Wed, 17 Mar 2010 06:30:24 -0700 (PDT) Subject: multiprocessing on freebsd Message-ID: Hi, I'm checking to see if multiprocessing works on freebsd for any version of python. My server is about to get upgraded from 6.3 to 8.0 and I'd sure like to be able to use multiprocessing. I think the minimal test would be: --------------------- import multiprocessing q = multiprocessing.Queue() --------------------- with 6.3, I get File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line 212, in Queue from multiprocessing.queues import Queue File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, in from multiprocessing.synchronize import Lock, BoundedSemaphore, Semaphore, Condition File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line 33, in " function, see issue 3770.") ImportError: This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770. thanks for any info, --Tim Arnold From rps at haystack.mit.edu Wed Mar 17 09:32:46 2010 From: rps at haystack.mit.edu (robert schaefer) Date: Wed, 17 Mar 2010 09:32:46 -0400 Subject: question about tkinter In-Reply-To: References: Message-ID: <8C160E0A-D35A-4EA8-822B-8CB5BCD9C529@haystack.mit.edu> Peter, Most of my life has been dealing with recalcitrant HAL's in one guise or another. These days, I think HAL has permanently taken up residence in Toyota's engine and brakes. "Stop the car Dave? Have you changed my oil or even washed me lately?" Some serious "sneak paths" are going on. Anyway - tkinter is in two parts: 1. a python wrapper 2. c code Both are present in the 2.6.2 python download. It appears to be a "I can't find the library" path problem not a file existence problem. 1. gcc can't find the libraries that tkinter c code links to ( I could fix that) 2. the python installer can't find all the library paths to all the pieces - I started fixing this, then determined it would be easier to rewrite from scratch than patch. That is, the given method of building paths in the script are way off from reality, not just an add this one path and everything will now work kind of magic. I felt that the "official" python people would have an easier time of this - so gave up. bob On Mar 17, 2010, at 9:00 AM, Peter Otten wrote: > robert schaefer wrote: > >> This is my first posting to this list so please be gentle - >> >> I am new to python and am using it on red-hat linux (I am new to that >> too). I am responsible for installing open source packages (including >> python) onto a distributed system of linux boxes. >> >> My question is, on python version 2.6.2 tkinter refuses to install. > > Does it say "I'm sorry Bob, I'm afraid I can't do this"? > >> Without tkinter, I cannot use Idle. >> >> I looked at the install/configure script and hacked it a bit, but every >> fix only caused new problems. >> There are serious issues with that script for finding necessary >> libraries. > > If there are serious problems you have to give some details. > > However, if in the past a newbie had problems with Tkinter support on linux > the most frequent problem was that the Tcl/Tk development libraries weren't > installed. I don't know how those are called on Red Hat, maybe something > like > > tcl*-dev.rpm > > Did you install these before running the configure script? > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > > !DSPAM:4ba0d3cd3229021468! > ----------------------------------- robert schaefer Atmospheric Sciences Group MIT Haystack Observatory Westford, MA 01886 email: rps at haystack.mit.edu voice: 781-981-5767 www: http://www.haystack.mit.edu From hidura at gmail.com Wed Mar 17 09:39:21 2010 From: hidura at gmail.com (Hidura) Date: Wed, 17 Mar 2010 09:39:21 -0400 Subject: Web Hosting Python 3 In-Reply-To: <1268832157.6206.1365286517@webmail.messagingengine.com> References: <0016e64642280288940481f66d5e@google.com> <1268832157.6206.1365286517@webmail.messagingengine.com> Message-ID: <4bbf7fb21003170639j1fe53d3fr17524681085b36a0@mail.gmail.com> I've saw last night in the help area they support Python3.1, thanks anyway On Wed, Mar 17, 2010 at 9:22 AM, wrote: > Hidura, > > > Hello list, i am in a project what need hosting, who give hosting to > python3? > > Check out www.webfaction.com. I'm extremely pleased with this vendor. > > Highly recommended! > > Malcolm > -- Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashwiniyal at gmail.com Wed Mar 17 09:54:18 2010 From: ashwiniyal at gmail.com (ashwini yal) Date: Wed, 17 Mar 2010 19:24:18 +0530 Subject: Special characters (^M & ^[[D) when I read pxssh::before and write it to a file Message-ID: <771960b21003170654u1f6bac7bm1c0d7b30e2187f1f@mail.gmail.com> Hi, I am writing a python script which logs into the machine using pxssh, sends a command, reads the response and writes the response to the file. But, when I open the file in the editor like vi, its showing special characters like ^M and ^[[D instead of spaces or newlines. This is how my code looks like ... s = pxssh.pxssh() s.login(ip, username, password) cmd = 'xyz' s.sendline (cmd) s.prompt() output = s.before fileWrite = open(filePath , 'wb') fileWrite.write(output) s.prompt() This is how my filePath looks like when I open it using vi editor. Starting command execution on host xxx.xxx.xxx.xxx D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^M Command executed successfully ^M Executing next command ...^M -- Regards , Ashwini . K -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Mar 17 09:59:40 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Mar 2010 14:59:40 +0100 Subject: question about tkinter References: Message-ID: robert schaefer wrote: > tkinter is in two parts: > 1. a python wrapper > 2. c code > > Both are present in the 2.6.2 python download. > It appears to be a "I can't find the library" path problem not a file > existence problem. > > 1. gcc can't find the libraries that tkinter c code links to ( I could fix > that) 2. the python installer can't find all the library paths to all the > pieces - I started fixing this, then determined it would be easier to > rewrite from scratch than patch. That is, the given method of building > paths in the script are way off from reality, not just an add this one > path and everything will now work kind of magic. I felt that the > "official" python people would have an easier time of this - so gave up. Just to exclude the simple problems (unfortunately I can't help you with the hard ones): Are the tcl development packages installed on your system? Peter From stefan_ml at behnel.de Wed Mar 17 10:10:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Mar 2010 15:10:27 +0100 Subject: Swapping Content of Two Dictionaries. In-Reply-To: <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Message-ID: Hatem Oraby, 17.03.2010 12:26: > However, consider the case in which the dictionary we are referencing lives > in another module: > #external.py > # > #a = {1:"I'am A} > import external > > temp = external.a > external.a = b > b = temp Looks like the interface of your module is broken. It shouldn't export the two dicts. > My problem is that i need to do this operation a LOT, simply I got a problem > that my program go through a very long loop and inside this loop this > operation is needed to be done twice and the dictionary size ain't very > small. Please explain what you use the dicts for and how they are supposed to be used by your own code and by external code. That will allow us to give an advice on how to design your module better. Stefan From pruebauno at latinmail.com Wed Mar 17 10:29:31 2010 From: pruebauno at latinmail.com (nn) Date: Wed, 17 Mar 2010 07:29:31 -0700 (PDT) Subject: Searching for most pythonic/least stupid way to do something simple References: <7xmxy87172.fsf@ruckus.brouhaha.com> <2c39f6d4-3118-43f3-907d-57f733dc7ed8@d27g2000yqf.googlegroups.com> <288bfc27-0c5b-4601-9ceb-dd2614593fb9@m37g2000yqf.googlegroups.com> Message-ID: <40341e67-0609-4da7-b32e-afdf3ea5b6cc@d27g2000yqf.googlegroups.com> Michael Torrie wrote: > david jensen wrote: > > of course, changing nn's to: > > def getOutcomes(myList=[2,5,8,3,5]): > > low_id = int(myList[0]>myList[1]) > > amountToShare = 2*myList[low_id] > > remainder = myList[not low_id]-myList[low_id] > > tail=list(myList[2:]) > > outcomes = [[amountToShare*perc, remainder+amountToShare*(1-perc)]+ > > tail for perc in (1.0, 0.75, 0.5, 0.25, 0.0)] if not low_id else > > [[remainder+amountToShare*perc, amountToShare*(1-perc)]+ tail for perc > > in (1.0, 0.75, 0.5, 0.25, 0.0)] > > return outcomes > > > > > > works, just hides the ugliness in a more compact form > > If Gerard's code works, I would consider it far superior to your code > here. Pythonic does not necessarily mean short and ugly, nor does it > mean that you have to always use list comprehensions. Having a > readable algorithm that's easy to follow in the future is a far better > way than trying to use python's cool features to compact the code to as > small and unreadable section as possible. > > I used to use list comprehension all the time, but I've found that often > an explicit for loop is a much better solution in terms of > maintainability. Especially when you start seeing nested comprehensions > such as you have here. To be fair, that list comprehension was unnecessary complicated. The following version does the same thing and still looks pretty reasonable IMHO: def getOutcomes(myList=[2,5,8,3,5]): low_id = int(myList[0]>myList[1]) high_id = not low_id smaller = myList[low_id] bigger = myList[high_id] amountToShare = 2*smaller remainder = bigger-smaller remain0 = low_id*remainder remain1 = high_id*remainder tail = list(myList[2:]) percents = (1.0, 0.75, 0.5, 0.25, 0.0) outcomes = [[remain0+amountToShare*perc, remain1+amountToShare*(1- perc)] +tail for perc in percents] return outcomes From rps at haystack.mit.edu Wed Mar 17 10:33:41 2010 From: rps at haystack.mit.edu (robert schaefer) Date: Wed, 17 Mar 2010 10:33:41 -0400 Subject: question about tkinter In-Reply-To: References: Message-ID: No, And there's a reason (perhaps not a great one - but I'm got some constraints). I am not the system administrator and the tcl installer wants to be installed as root. I tried it. The rationale for not doing this is that the installation packages that I am administrator for, are all installed in non-root directories. by non-root people. If I have to install any package as root, then that becomes "different". The machines are all linux and intended to be swappable/exchangeable and installed by anyone without root access. This simplifies maintenance when a large number of boxes are involved. Are there any tcl/tk packages that permit re-direction of installation to non-root directories? This problem is just an ongoing irritation, python works fine without tkinter, I just can't get idle to work without it. Related to that I tailored Ipython to work with gtk (ipython's default was tkinter) - tailoring was by a command - is there any way to command idle to use gtk? On Mar 17, 2010, at 9:59 AM, Peter Otten wrote: > robert schaefer wrote: > >> tkinter is in two parts: >> 1. a python wrapper >> 2. c code >> >> Both are present in the 2.6.2 python download. >> It appears to be a "I can't find the library" path problem not a file >> existence problem. >> >> 1. gcc can't find the libraries that tkinter c code links to ( I could fix >> that) 2. the python installer can't find all the library paths to all the >> pieces - I started fixing this, then determined it would be easier to >> rewrite from scratch than patch. That is, the given method of building >> paths in the script are way off from reality, not just an add this one >> path and everything will now work kind of magic. I felt that the >> "official" python people would have an easier time of this - so gave up. > > Just to exclude the simple problems (unfortunately I can't help you with the > hard ones): Are the tcl development packages installed on your system? > > Peter > > -- > http://mail.python.org/mailman/listinfo/python-list > > !DSPAM:4ba0e1dc51621869525538! > ----------------------------------- robert schaefer Atmospheric Sciences Group MIT Haystack Observatory Westford, MA 01886 email: rps at haystack.mit.edu voice: 781-981-5767 www: http://www.haystack.mit.edu From robin at reportlab.com Wed Mar 17 10:38:16 2010 From: robin at reportlab.com (Robin Becker) Date: Wed, 17 Mar 2010 14:38:16 +0000 Subject: bug in bdist_wininst cross compile? Message-ID: <4BA0E958.8050205@chamonix.reportlab.co.uk> has anyone had any success with cross compilation and bdist_wininst; I have modified build_ext very slightly to fix a small bug in cross compilation related to library order. That seems to fix setup.py build --plat-name=win-amd64 however, when I try to do a clean build of an exe ie rm -rf build setup.py bdist_wininst --plat-name=win-amd64 it appears as though build is invoked with the wrong plat-name ie I see this in the output > running bdist_wininst > running build > running build_py > creating build > creating build\lib.win32-2.6 > creating build\lib.win32-2.6\reportlab > copying src\reportlab\rl_config.py -> build\lib.win32-2.6\reportlab ...... > C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nolog followed by errors related to a missing library (the amd64 version won't work with a win32 build). If I build first with setup.py build --plat-name=win-amd64 and then use setup.py bdist_wininst --plat-name=win-amd64 --skip-build then I seem to get a proper amd64 exe. I think the problem can be fixed by modifying distutils/command/bdist_wininst.py using this patch > *** bdist_wininst.py.orig Wed Mar 17 14:00:15 2010 > --- bdist_wininst.py Wed Mar 17 14:29:55 2010 > *************** > *** 79,90 **** > > def finalize_options (self): > if self.bdist_dir is None: > ! if self.skip_build and self.plat_name: > ! # If build is skipped and plat_name is overridden, bdist will > ! # not see the correct 'plat_name' - so set that up manually. > bdist = self.distribution.get_command_obj('bdist') > bdist.plat_name = self.plat_name > ! # next the command will be initialized using that name > bdist_base = self.get_finalized_command('bdist').bdist_base > self.bdist_dir = os.path.join(bdist_base, 'wininst') > if not self.target_version: > --- 79,91 ---- > > def finalize_options (self): > if self.bdist_dir is None: > ! if self.plat_name: > ! #bdist doesn't propagate plat_name so we do it here > ! build = self.distribution.get_command_obj('build') > ! build.plat_name = self.plat_name > bdist = self.distribution.get_command_obj('bdist') > bdist.plat_name = self.plat_name > ! # next the command(s) will be initialized using that name > bdist_base = self.get_finalized_command('bdist').bdist_base > self.bdist_dir = os.path.join(bdist_base, 'wininst') > if not self.target_version: which forces bdist_wininst's version of the plat_name forward onto both build and bdist. -- Robin Becker From pmaupin at gmail.com Wed Mar 17 10:43:50 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 07:43:50 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> Message-ID: <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> On Mar 17, 4:12?am, Bruno Desthuilliers wrote: > Patrick Maupin a ?crit : > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > >> Why not create the bound methods at instantiation time, rather than > >> using the descriptor protocol which has the overhead of creating a new > >> bound method each time the method attribute is accessed? > > > Well, for one thing, Python classes are open. ?They can be added to at > > any time. ?For another thing, you might not ever use most of the > > methods of an instance, so it would be a huge waste to create those. > > A possible optimization would be a simple memoization on first access. I do agree that memoization on access is a good pattern, and I use it frequently. I don't know if I would want the interpreter automagically doing that for everything, though -- it would require some thought to figure out what the overhead cost is for the things that are only used once. Usually, I will have a slight naming difference for the things I want memoized, to get the memoization code to run. For example, if you add an underbar in front of everything you want memoized: class foo(object): def _bar(self): pass def __getattr__(self, aname): if aname.startswith('_'): raise AttributeError value = getattr(self, '_' + aname) self.aname = value return value obj = foo() So then the first time you look up obj.bar, it builds the bound method, and on subsequent accesses it just returns the previously bound method. Regards, Pat From benjamin.kaplan at case.edu Wed Mar 17 10:51:50 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 17 Mar 2010 10:51:50 -0400 Subject: Special characters (^M & ^[[D) when I read pxssh::before and write it to a file In-Reply-To: <771960b21003170654u1f6bac7bm1c0d7b30e2187f1f@mail.gmail.com> References: <771960b21003170654u1f6bac7bm1c0d7b30e2187f1f@mail.gmail.com> Message-ID: On Wed, Mar 17, 2010 at 9:54 AM, ashwini yal wrote: > Hi, > > I am writing a python script which logs into the machine using pxssh, sends > a command, reads the response and writes the response to the file. > > But, when I open the file in the editor like vi, its showing special > characters like ^M and ^[[D instead of spaces or newlines. > > This is how my code looks like ... > > s = pxssh.pxssh() > s.login(ip, username, password) > > cmd = 'xyz' > s.sendline (cmd) > s.prompt() > output = s.before > fileWrite = open(filePath , 'wb') > fileWrite.write(output) > s.prompt() > > > This is how my filePath looks like when I open it using vi editor. > > Starting command execution on host xxx.xxx.xxx.xxx > > > D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^M > > Command executed successfully ^M > > Executing next command ...^M > > I don't know what's going with the ^[[D, but ^M is a carriage return. Your connection is returning CRLF ("\r\n") for the line endings (which is what Windows uses for line endings) instead of the Unix line ending, which is just a line feed "\n". -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 10:51:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 15:51:53 +0100 Subject: to pass self or not to pass self In-Reply-To: <4ba0d65f$1@dnews.tpgi.com.au> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <4ba0d65f$1@dnews.tpgi.com.au> Message-ID: <4ba0ec7a$0$14371$426a74cc@news.free.fr> Lie Ryan a ?crit : > On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote: >> Patrick Maupin a ?crit : >>> On Mar 16, 1:59 pm, Jason Tackaberry wrote: >>>> Why not create the bound methods at instantiation time, rather than >>>> using the descriptor protocol which has the overhead of creating a new >>>> bound method each time the method attribute is accessed? >>> Well, for one thing, Python classes are open. They can be added to at >>> any time. For another thing, you might not ever use most of the >>> methods of an instance, so it would be a huge waste to create those. >> A possible optimization would be a simple memoization on first access. > > But what if, for example, one uses some descriptor/metaclass magic to > make it so that each subsequent access to the attribute returns a method > bound to different objects? Well, that's the whole problem with dynamism vs optimization... From pengyu.ut at gmail.com Wed Mar 17 10:53:42 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 17 Mar 2010 09:53:42 -0500 Subject: highlight words by regex in pdf files using python In-Reply-To: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> References: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> Message-ID: <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> On Tue, Mar 16, 2010 at 11:12 PM, Patrick Maupin wrote: > On Mar 4, 6:57?pm, Peng Yu wrote: >> I don't find a general pdf library in python that can do any >> operations on pdfs. >> >> I want to automatically highlight certain words (using regex) in a >> pdf. Could somebody let me know if there is a tool to do so in python? > > The problem with PDFs is that they can be quite complicated. ?There is > the outer container structure, which isn't too bad (unless the > document author applied encryption or fancy multi-object compression), > but then inside the graphics elements, things could be stored as > regular ASCII, or as fancy indexes into font-specific tables. ?Not > rocket science, but the only industrial-strength solution for this is > probably reportlab's pagecatcher. > > I have a library which works (primarily with the outer container) for > reading and writing, called pdfrw. ?I also maintain a list of other > PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries ?It > may be that pdfminer (link on that page) will do what you want -- it > is certainly trying to be complete as a PDF reader. ?But I've never > personally used pdfminer. > > One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools > will read in preexisting PDFs and write them out to a reportlab > canvas. ?This works quite well on a few very simple ASCII PDFs, but > the font handling needs a lot of work and probably won't work at all > right now on unicode. ?(But if you wanted to improve it, I certainly > would accept patches or give you commit rights!) > > That pdfrw example does graphics reasonably well. ?I was actually > going down that path for getting better vector graphics into rst2pdf > (both uniconvertor and svglib were broken for my purposes), but then I > realized that the PDF spec allows you to include a page from another > PDF quite easily (the spec calls it a form xObject), so you don't > actually need to parse down into the graphics stream for that. ?So, > right now, the best way to do vector graphics with rst2pdf is either > to give it a preexisting PDF (which it passes off to pdfrw for > conversion into a form xObject), or to give it a .svg file and invoke > it with -e inkscape, and then it will use inkscape to convert the svg > to a pdf and then go through the same path. Thank you for your long reply! But I'm not sure if you get my question or not. Acrobat can highlight certain words in pdfs. I could add notes to the highlighted words as well. However, I find that I frequently end up with highlighting some words that can be expressed by a regular expression. To improve my productivity, I don't want do this manually in Acrobat but rather do it in an automatic way, if there is such a tool available. People in reportlab mailing list said this is not possible with reportlab. And I don't see PyPDF can do this. If you know there is an API to for this purpose, please let me know. Thank you! Regards, Peng From wsantee at gmail.com Wed Mar 17 10:57:43 2010 From: wsantee at gmail.com (Wes Santee) Date: Wed, 17 Mar 2010 07:57:43 -0700 (PDT) Subject: Structure accessible by attribute name or index Message-ID: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> I am very new to Python, and trying to figure out how to create an object that has values that are accessible either by attribute name, or by index. For example, the way os.stat() returns a stat_result or pwd.getpwnam() returns a struct_passwd. In trying to figure it out, I've only come across C implementations of the above types. Nothing specifically in Python. What is the Python native way to create this kind of object? I apologize if this has been widely covered already. In searching for an answer, I must be missing some fundamental concept that is excluding me from finding an answer. Cheers, -Wes From pmaupin at gmail.com Wed Mar 17 11:11:40 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 10:11:40 -0500 Subject: highlight words by regex in pdf files using python In-Reply-To: <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> References: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> Message-ID: On Wed, Mar 17, 2010 at 9:53 AM, Peng Yu wrote: > Thank you for your long reply! But I'm not sure if you get my question or not. > > Acrobat can highlight certain words in pdfs. I could add notes to the > highlighted words as well. However, I find that I frequently end up > with highlighting some words that can be expressed by a regular > expression. > > To improve my productivity, I don't want do this manually in Acrobat > but rather do it in an automatic way, if there is such a tool > available. People in reportlab mailing list said this is not possible > with reportlab. And I don't see PyPDF can do this. If you know there > is an API to for this purpose, please let me know. Thank you! I do not know of any API specific to this purpose, no. But I mentioned three libraries (pagecatcher, pdfminer, and pdfrw) that are capable, to a greater or lesser extent, of reading in PDFs and giving you the data from them, which you can then do your replacement on and then write back out. I would imagine this would be a piece of cake with pagecatcher. (I noticed you just posted on the reportlab mailing list, but you did not specifically mention pagecatcher.) It will probably take more work with either of the other two. It is probable that none of them do exactly what you want, but also that any of them is a better starting point than coding what you want from scratch. Regards, Pat From lists at cheimes.de Wed Mar 17 11:14:38 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 17 Mar 2010 16:14:38 +0100 Subject: Structure accessible by attribute name or index In-Reply-To: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: Wes Santee wrote: > I am very new to Python, and trying to figure out how to create an > object that has values that are accessible either by attribute name, > or by index. For example, the way os.stat() returns a stat_result or > pwd.getpwnam() returns a struct_passwd. > > In trying to figure it out, I've only come across C implementations of > the above types. Nothing specifically in Python. What is the Python > native way to create this kind of object? > > I apologize if this has been widely covered already. In searching for > an answer, I must be missing some fundamental concept that is > excluding me from finding an answer. You can't use the same implementation as the result object of os.stat() and others. However Python 2.6 has a new factory that creates a similar datatype called named tuple: http://docs.python.org/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields From sparks.m at gmail.com Wed Mar 17 11:16:49 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Wed, 17 Mar 2010 08:16:49 -0700 (PDT) Subject: Nested Scopes unintended behaviour ? Message-ID: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Hi, Is the following behaviour expected ? Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def Toggler(F, B): ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... >>> def Switcher(A,B): ... on=True ... def swtchfun(msg): ... on_ = on ... if on: ... on = False ... print "Switched to A" ... return A ... else: ... print "Switched to B" ... return B ... # ... return Toggler(swtchfun,True) ... >>> Switcher(1,2) Traceback (most recent call last): File "", line 1, in File "", line 13, in Switcher File "", line 2, in Toggler File "", line 4, in swtchfun UnboundLocalError: local variable 'on' referenced before assignment The reason I ask is because logically it makes sense. The on_ = on statement should resolve "on" to be the value on in the enclosing scope, however it appears that the "on = False" statement is taking priority. The reason I say this is because if you remove the "on = False" line you get the expected name resolution: >>> def Toggler(F, B): ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... >>> def Switcher(A,B): ... on=True ... def swtchfun(msg): ... on_ = on ... if on: ... print "Switched to A" ... return A ... else: ... print "Switched to B" ... return B ... # ... return Toggler(swtchfun,True) ... >>> Switcher(1,2) Switched to A 1 ie it looks like python is not looking at the expected scope in the first instance. To me it looks like a bug, but I can also see a rationale where it's considered a feature (because the "on" is on the left hand side resolving the value to a local, rather than a value in an enclosed scope) I know that you can work around this as follows: Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def Toggler(F, B): ... print F("Hello") ... print F("Hello") ... print F("Hello") ... print F("Hello") ... >>> def Switcher(A,B): ... def switchgen(): ... while True: ... yield A ... yield B ... G = switchgen() ... def swtchfun(msg): ... return G.next() ... # ... return Toggler(swtchfun,True) ... >>> >>> Switcher(1,2) 1 2 1 2 But I'm curious as to whether the nested scope issue above is considered a bug or a feature, so I can deal with it appropriately. Any comments welcome :-) Regards, Michael. -- http://yeoldeclue.com/blog http://www.kamaelia.org/Home.html http://twitter.com/kamaelian From philip at semanchuk.com Wed Mar 17 11:26:51 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Mar 2010 11:26:51 -0400 Subject: multiprocessing on freebsd In-Reply-To: References: Message-ID: <54550297-2B41-4A5B-8A0B-9ABF7B22D4B6@semanchuk.com> On Mar 17, 2010, at 9:30 AM, Tim Arnold wrote: > Hi, > I'm checking to see if multiprocessing works on freebsd for any > version of python. My server is about to get upgraded from 6.3 to 8.0 > and I'd sure like to be able to use multiprocessing. > > I think the minimal test would be: > --------------------- > import multiprocessing > q = multiprocessing.Queue() > --------------------- > > with 6.3, I get > > File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line > 212, in Queue > from multiprocessing.queues import Queue > File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, > in > from multiprocessing.synchronize import Lock, BoundedSemaphore, > Semaphore, Condition > File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line > 33, in > " function, see issue 3770.") > ImportError: This platform lacks a functioning sem_open > implementation, therefore, the required synchronization primitives > needed will not function, see issue 3770. Hi Tim, Under FreeBSD 8/Python 2.6.2 I get the same result, unfortunately. That's a pity because sem_open works under FreeBSD >= 7.2 as we discussed before. Issue 3770 is closed with the note, "we've removed hard-coded platform variables for a better autoconf approach." I'm using the Python built from FreeBSD's ports, and the note makes me think that it's possible that if I built my own Python from the Python.org tarball rather than ports the problem would go away due to autoconf magic. I don't have the time to offer to do this for you, unfortunately. But why not install FreeBSD 8 under VirtualBox or somesuch and give it a go yourself? A couple of quirks I noted related to FreeBSD & POSIX IPC that you might find useful -- - The sem and mqueuefs kernel modules must be loaded, otherwise you'll get a message like this when you try to create a semaphore or message queue: Bad system call: 12 (core dumped) Under 8.0 they're loaded by default, I think. - C apps that want to use message queues must link to the realtime libs (pass -lrt to the linker). This tripped me up for a while. Linking to the realtime libs is required for all POSIX IPC calls under Linux; FreeBSD does not require it for semaphores or shared mem, only message queues. Hope this helps Philip From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 11:34:33 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 16:34:33 +0100 Subject: Structure accessible by attribute name or index In-Reply-To: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: <4ba0f67a$0$17757$426a74cc@news.free.fr> Wes Santee a ?crit : > I am very new to Python, and trying to figure out how to create an > object that has values that are accessible either by attribute name, > or by index. For example, the way os.stat() returns a stat_result or > pwd.getpwnam() returns a struct_passwd. > > In trying to figure it out, I've only come across C implementations of > the above types. Nothing specifically in Python. What is the Python > native way to create this kind of object? Using the appropriate __magicmethods__ for indexed access and computed attributes for the attribute access might be a good solution: # warning : Q&D implementation, would require some sanity checks. class IndexedValueDescriptor(object): def __init__(self, index): self._index = index def __get__(self, instance, cls): if instance is None: return self return instance[self._index] def __set__(self, instance, value): instance[self._index] = value class Structure(object): def __init__(self, value1, value2, value3): self._values = [value1, value2, value3] def __setitem__(self, index, value): self._values[index] = value def __getitem__(self, index): return self._values[index] value1 = IndexedValueDescriptor(0) value2 = IndexedValueDescriptor(1) value3 = IndexedValueDescriptor(2) Note that there are probably other solutions... Don't know how os.stat_result is implemented, might be worth looking at the source code. But anyway : the above should get you started. > I apologize if this has been widely covered already. In searching for > an answer, I must be missing some fundamental concept that is > excluding me from finding an answer. Well, that's not really a FAQ AFAICT !-) From bruno.42.desthuilliers at websiteburo.invalid Wed Mar 17 11:35:41 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Mar 2010 16:35:41 +0100 Subject: Structure accessible by attribute name or index In-Reply-To: References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: <4ba0f6be$0$17757$426a74cc@news.free.fr> Christian Heimes a ?crit : > However Python 2.6 has a new factory that creates a similar > datatype called named tuple: > http://docs.python.org/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields > Duh... Should spend some more time reading 2.6's What's New :( From emile at fenx.com Wed Mar 17 11:44:03 2010 From: emile at fenx.com (Emile van Sebille) Date: Wed, 17 Mar 2010 08:44:03 -0700 Subject: Nested Scopes unintended behaviour ? In-Reply-To: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Message-ID: On 3/17/2010 8:16 AM Michael Sparks said... > Hi, > > > Is the following behaviour expected ? In short, yes. Assignment within a function forces the variable to locals. You can get around it like: > > Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def Toggler(F, B): > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... >>>> def Switcher(A,B): > ... on=True > ... def swtchfun(msg): ---> def swtchfun(msg, on=on): > ... on_ = on > ... if on: > ... on = False > ... print "Switched to A" > ... return A > ... else: > ... print "Switched to B" > ... return B > ... # > ... return Toggler(swtchfun,True) > ... >>>> Switcher(1,2) > Traceback (most recent call last): > File "", line 1, in > File "", line 13, in Switcher > File "", line 2, in Toggler > File "", line 4, in swtchfun > UnboundLocalError: local variable 'on' referenced before assignment > > The reason I ask is because logically it makes sense. The on_ = on > statement should resolve "on" to be the value on in the enclosing > scope, however it appears that the "on = False" statement is taking > priority. The reason I say this is because if you remove the "on = > False" line you get the expected name resolution: > >>>> def Toggler(F, B): > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... >>>> def Switcher(A,B): > ... on=True > ... def swtchfun(msg): > ... on_ = on > ... if on: > ... print "Switched to A" > ... return A > ... else: > ... print "Switched to B" > ... return B > ... # > ... return Toggler(swtchfun,True) > ... >>>> Switcher(1,2) > Switched to A > 1 > > ie it looks like python is not looking at the expected scope in the > first instance. > > To me it looks like a bug, but I can also see a rationale where it's > considered a feature (because the "on" is on the left hand side > resolving the value to a local, rather than a value in an enclosed > scope) > > I know that you can work around this as follows: > Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> def Toggler(F, B): > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... print F("Hello") > ... >>>> def Switcher(A,B): > ... def switchgen(): > ... while True: > ... yield A > ... yield B > ... G = switchgen() > ... def swtchfun(msg): > ... return G.next() > ... # > ... return Toggler(swtchfun,True) > ... >>>> >>>> Switcher(1,2) > 1 > 2 > 1 > 2 > > But I'm curious as to whether the nested scope issue above is > considered a bug or a feature, so I can deal with it appropriately. > > Any comments welcome :-) > > Regards, > > > Michael. > -- > http://yeoldeclue.com/blog > http://www.kamaelia.org/Home.html > http://twitter.com/kamaelian > > > From nobody at nowhere.com Wed Mar 17 11:44:34 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 17 Mar 2010 15:44:34 +0000 Subject: execute bash builtins in python References: Message-ID: On Fri, 12 Mar 2010 08:15:49 -0500, Steve Holden wrote: > For shell=True I believe you should provide the command as a single > string, not a list of arguments. Using shell=True with an argument list is valid. On Unix, it's seldom what you want: it will invoke /bin/sh to execute the first argument with $1, $2, ... set from the remaining arguments. On Windows, a list is converted to a string in the same manner regardless of the value of the "shell" argument. Specifying shell=True causes the command string to be executed via "cmd /c ...". This allows the "program" to be a script, whereas shell=False requires the program to be a binary executable. From python at hope.cz Wed Mar 17 11:47:07 2010 From: python at hope.cz (Johny) Date: Wed, 17 Mar 2010 08:47:07 -0700 (PDT) Subject: pkg-config and Windows Message-ID: I have a program that needs to be installed with setup.py. But there is a problem when I am trying to install the program with setup.py in Windows. When I try to install with python setup.py install it goes like this C:\>python setup.py install running install running build running build_py running build_ext ERROR: Could not find pkg-config! As you can see the installation finishes with the error: Could not find pkg-config! Is there any way how to find out pkg-config in Windows? or how to solve the problem? Thanks L. From tundra at tundraware.com Wed Mar 17 12:32:45 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 11:32:45 -0500 Subject: Win32All On 64-Bit Operating Systems Message-ID: I have a pure-Python program developed on a POSIX platform (FreeBSD) that I'd like to make fully compatible with Windows systems as well. The only conflict arises insofar as this program makes considerable use of the stat UID and GID values, as well as their corresponding user- and group names. Since Windows has not grp and pwd modules, I need to synthesize this. In the past, I've solved this problem by detecting the presence of Win32All. If present, I do the necessary magic to return the true UID/name, GID/name info from Windows itself. If not, I return UID/GID as provided by an os.stat call and use the phoby names "winuser" and "wingroup" respectively. Now for the question: Is there even an instance of Win32All for 64-bit OSs like Vista and Win7? If not, I'm inclined not bother with it at all and just return the phony values as placeholders because I do not want different features on 32- and 64-bit platforms. Thanks, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From wsantee at gmail.com Wed Mar 17 12:40:44 2010 From: wsantee at gmail.com (Wes Santee) Date: Wed, 17 Mar 2010 09:40:44 -0700 (PDT) Subject: Structure accessible by attribute name or index References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> Message-ID: <23c6223c-cc65-44e2-a400-aba5d0a010a6@m37g2000yqf.googlegroups.com> On Mar 17, 11:14?am, Christian Heimes wrote: > Wes Santee wrote: > > I am very new to Python, and trying to figure out how to create an > > object that has values that are accessible either by attribute name, > > or by index. ?For example, the way os.stat() returns a stat_result or > > pwd.getpwnam() returns a struct_passwd. > > > In trying to figure it out, I've only come across C implementations of > > the above types. ?Nothing specifically in Python. ?What is the Python > > native way to create this kind of object? > > > I apologize if this has been widely covered already. ?In searching for > > an answer, I must be missing some fundamental concept that is > > excluding me from finding an answer. > > You can't use the same implementation as the result object of os.stat() > and others. However Python 2.6 has a new factory that creates a similar > datatype called named tuple:http://docs.python.org/library/collections.html#namedtuple-factory-fu... Thanks for the pointer. At least I know there is a reason why I wasn't finding a solution. :) From wsantee at gmail.com Wed Mar 17 12:55:07 2010 From: wsantee at gmail.com (Wes Santee) Date: Wed, 17 Mar 2010 09:55:07 -0700 (PDT) Subject: Structure accessible by attribute name or index References: <189ec016-9c2e-44ac-b01a-c264f165c30d@30g2000yqi.googlegroups.com> <4ba0f67a$0$17757$426a74cc@news.free.fr> Message-ID: <2e0ba087-eb30-460e-a6e2-b29498669107@33g2000yqj.googlegroups.com> On Mar 17, 11:34?am, Bruno Desthuilliers wrote: > Wes Santee a ?crit : > > > I am very new to Python, and trying to figure out how to create an > > object that has values that are accessible either by attribute name, > > or by index. ?For example, the way os.stat() returns a stat_result or > > pwd.getpwnam() returns a struct_passwd. > > > In trying to figure it out, I've only come across C implementations of > > the above types. ?Nothing specifically in Python. ?What is the Python > > native way to create this kind of object? > > Using the appropriate __magicmethods__ for indexed access and computed > attributes for the attribute access might be a good solution: This is as good an excuse as any to get familiar with the rest of the __magicmethods__. :) > > # warning : Q&D implementation, would require some sanity checks. > > class IndexedValueDescriptor(object): > ? ? ?def __init__(self, index): > ? ? ? ? ?self._index = index > ? ? ?def __get__(self, instance, cls): > ? ? ? ? ?if instance is None: > ? ? ? ? ? ? ?return self > ? ? ? ? ?return instance[self._index] > ? ? ?def __set__(self, instance, value): > ? ? ? ? ?instance[self._index] = value > > class Structure(object): > ? ? ?def __init__(self, value1, value2, value3): > ? ? ? ? ?self._values = [value1, value2, value3] > ? ? ?def __setitem__(self, index, value): > ? ? ? ? ?self._values[index] = value > ? ? ?def __getitem__(self, index): > ? ? ? ? ?return self._values[index] > ? ? ?value1 = IndexedValueDescriptor(0) > ? ? ?value2 = IndexedValueDescriptor(1) > ? ? ?value3 = IndexedValueDescriptor(2) > > Note that there are probably other solutions... Don't know how > os.stat_result is implemented, might be worth looking at the source > code. But anyway : the above should get you started. > > > I apologize if this has been widely covered already. ? In searching for > > an answer, I must be missing some fundamental concept that is > > excluding me from finding an answer. > > Well, that's not really a FAQ AFAICT !-) From mail at timgolden.me.uk Wed Mar 17 13:05:48 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Mar 2010 17:05:48 +0000 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: Message-ID: <4BA10BEC.2080802@timgolden.me.uk> On 17/03/2010 16:32, Tim Daneliuk wrote: > I have a pure-Python program developed on a POSIX platform (FreeBSD) that > I'd like to make fully compatible with Windows systems as well. The only > conflict arises insofar as this program makes considerable use of the > stat UID and GID values, as well as their corresponding user- and group > names. Since Windows has not grp and pwd modules, I need to synthesize > this. > > In the past, I've solved this problem by detecting the presence of Win32All. > If present, I do the necessary magic to return the true UID/name, GID/name > info from Windows itself. If not, I return UID/GID as provided by an > os.stat call and use the phoby names "winuser" and "wingroup" respectively. > > Now for the question: Is there even an instance of Win32All for 64-bit > OSs like Vista and Win7? If not, I'm inclined not bother with it at all > and just return the phony values as placeholders because I do not want > different features on 32- and 64-bit platforms. Looks like it: http://sourceforge.net/projects/pywin32/files/ but, frankly, I wouldn't bother with the uid/gid thing on Windows. It's nearly meaningless most of the time. Just return placeholders. TJG From andrej.mitrovich at gmail.com Wed Mar 17 13:41:14 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Mar 2010 10:41:14 -0700 (PDT) Subject: Python Documentation website layout changed? Message-ID: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> Hi, What happened to the sidebar on the left of the documentation website? It seems to be gone: http://docs.python.org/py3k/index.html I found it quite useful since I can quickly swap between Python2/3 documentation, and between other parts of the documentation as well. From a_jtim at bellsouth.net Wed Mar 17 13:57:42 2010 From: a_jtim at bellsouth.net (Tim Arnold) Date: Wed, 17 Mar 2010 10:57:42 -0700 (PDT) Subject: multiprocessing on freebsd References: Message-ID: <4b29e714-df56-49be-a836-51d5833765f8@x12g2000yqx.googlegroups.com> On Mar 17, 11:26?am, Philip Semanchuk wrote: > On Mar 17, 2010, at 9:30 AM, Tim Arnold wrote: > > > > > > > Hi, > > I'm checking to see if multiprocessing works on freebsd for any > > version of python. My server is about to get upgraded from 6.3 to 8.0 > > and I'd sure like to be able to use multiprocessing. > > > I think the minimal test would be: > > --------------------- > > import multiprocessing > > q = multiprocessing.Queue() > > --------------------- > > > with 6.3, I get > > > File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line > > 212, in Queue > > ? ?from multiprocessing.queues import Queue > > ?File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, > > in > > ? ?from multiprocessing.synchronize import Lock, BoundedSemaphore, > > Semaphore, Condition > > ?File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line > > 33, in > > ? ?" function, see issue 3770.") > > ImportError: This platform lacks a functioning sem_open > > implementation, therefore, the required synchronization primitives > > needed will not function, see issue 3770. > > Hi Tim, > Under FreeBSD 8/Python 2.6.2 I get the same result, unfortunately. ? > That's a pity because sem_open works under FreeBSD >= 7.2 as we ? > discussed before. > > Issue 3770 is closed with the note, "we've removed hard-coded platform ? > variables for a better autoconf approach." I'm using the Python built ? > from FreeBSD's ports, and the note makes me think that it's possible ? > that if I built my own Python from the Python.org tarball rather than ? > ports the problem would go away due to autoconf magic. I don't have ? > the time to offer to do this for you, unfortunately. But why not ? > install FreeBSD 8 under VirtualBox or somesuch and give it a go ? > yourself? > > A couple of quirks I noted related to FreeBSD & POSIX IPC that you ? > might find useful -- > - The sem and mqueuefs kernel modules must be loaded, otherwise you'll ? > get a message like this when you try to create a semaphore or message ? > queue: > Bad system call: 12 (core dumped) > > Under 8.0 they're loaded by default, I think. > > - C apps that want to use message queues must link to the realtime ? > libs (pass -lrt to the linker). This tripped me up for a while. ? > Linking to the realtime libs is required for all POSIX IPC calls under ? > Linux; FreeBSD does not require it for semaphores or shared mem, only ? > message queues. > > Hope this helps > Philip Hi Philip, Thanks for that information (esp the linker info). Once the machine is upgraded, I'll try building python from the tarball. I'll post back here with the results. here's hoping! thanks, --Tim From sccolbert at gmail.com Wed Mar 17 14:14:14 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 17 Mar 2010 14:14:14 -0400 Subject: execute bash builtins in python In-Reply-To: References: Message-ID: <7f014ea61003171114j60aa2a2co19e138e46ea4ee4d@mail.gmail.com> On Wed, Mar 17, 2010 at 11:44 AM, Nobody wrote: > On Fri, 12 Mar 2010 08:15:49 -0500, Steve Holden wrote: > > > For shell=True I believe you should provide the command as a single > > string, not a list of arguments. > > Using shell=True with an argument list is valid. > > On Unix, it's seldom what you want: it will invoke /bin/sh to execute the > first argument with $1, $2, ... set from the remaining arguments. > > On Windows, a list is converted to a string in the same manner regardless > of the value of the "shell" argument. Specifying shell=True causes the > command string to be executed via "cmd /c ...". This allows the "program" > to be a script, whereas shell=False requires the program to be a binary > executable. > > -- > http://mail.python.org/mailman/listinfo/python-list > if you can work interactively, save yourself the headache and just use Ipython: brucewayne at broo:~$ ipython Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: alias Total number of aliases: 15 Out[1]: [('cat', 'cat'), ('clear', 'clear'), ('less', 'less'), ('mkdir', 'mkdir'), ('rmdir', 'rmdir'), ('cp', 'cp -i'), ('lc', 'ls -F -o --color'), ('ldir', 'ls -F -o --color %l | grep /$'), ('lf', 'ls -F -o --color %l | grep ^-'), ('lk', 'ls -F -o --color %l | grep ^l'), ('ll', 'ls -lF'), ('ls', 'ls -F'), ('lx', 'ls -F -o --color %l | grep ^-..x'), ('mv', 'mv -i'), ('rm', 'rm -i')] In [2]: -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Wed Mar 17 14:16:42 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Mar 2010 11:16:42 -0700 (PDT) Subject: Python Documentation website layout changed? References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> Message-ID: <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> On Mar 17, 6:41?pm, Andrej Mitrovic wrote: > Hi, > > What happened to the sidebar on the left of the documentation website? > It seems to be gone: > > http://docs.python.org/py3k/index.html > > I found it quite useful since I can quickly swap between Python2/3 > documentation, and between other parts of the documentation as well. Edit: It looks like only the Python 3 pages are affected, the Python 2 pages are the same as before: http://docs.python.org/index.html Might be a bug? From steve at holdenweb.com Wed Mar 17 14:34:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Mar 2010 14:34:17 -0400 Subject: Python Documentation website layout changed? In-Reply-To: <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> Message-ID: <4BA120A9.3060001@holdenweb.com> Andrej Mitrovic wrote: > On Mar 17, 6:41 pm, Andrej Mitrovic > wrote: >> Hi, >> >> What happened to the sidebar on the left of the documentation website? >> It seems to be gone: >> >> http://docs.python.org/py3k/index.html >> >> I found it quite useful since I can quickly swap between Python2/3 >> documentation, and between other parts of the documentation as well. > > Edit: It looks like only the Python 3 pages are affected, the Python 2 > pages are the same as before: > > http://docs.python.org/index.html > > Might be a bug? I'll ask. Georg - is this known behavior or a temporary problem? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From anthra.norell at bluewin.ch Wed Mar 17 14:43:00 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Wed, 17 Mar 2010 19:43:00 +0100 Subject: How to access a web site with an authentication template. Message-ID: <4BA122B4.5030003@bluewin.ch> Hi all, I have spent the better part of this day reading docs and googling archives to no avail. About this: I understand that I can access password protected sites with urllib2. However, the protocol seems to be: I try without password and catch the error coming back. The header will then tell me what the server expects in the line of formats. That doesn't work with a site I am dealing with, because the opening page does not require a password. It presents an id/password entry template and I have no clue how to respond in python. The page source is chock full of java script. The header--if that means anything--is: ... more CSS I don't expect solutions, but rather pointers to relevant reading. Thanks Frederic From tundra at tundraware.com Wed Mar 17 15:07:14 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 14:07:14 -0500 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: Message-ID: <3rl777-q1m2.ln1@ozzie.tundraware.com> On 3/17/2010 12:05 PM, Tim Golden wrote: > On 17/03/2010 16:32, Tim Daneliuk wrote: >> I have a pure-Python program developed on a POSIX platform (FreeBSD) that >> I'd like to make fully compatible with Windows systems as well. The only >> conflict arises insofar as this program makes considerable use of the >> stat UID and GID values, as well as their corresponding user- and group >> names. Since Windows has not grp and pwd modules, I need to synthesize >> this. >> >> In the past, I've solved this problem by detecting the presence of >> Win32All. >> If present, I do the necessary magic to return the true UID/name, >> GID/name >> info from Windows itself. If not, I return UID/GID as provided by an >> os.stat call and use the phoby names "winuser" and "wingroup" >> respectively. >> >> Now for the question: Is there even an instance of Win32All for 64-bit >> OSs like Vista and Win7? If not, I'm inclined not bother with it at all >> and just return the phony values as placeholders because I do not want >> different features on 32- and 64-bit platforms. > > Looks like it: > > http://sourceforge.net/projects/pywin32/files/ Thanks! > > but, frankly, I wouldn't bother with the uid/gid thing on > Windows. It's nearly meaningless most of the time. Just > return placeholders. > > TJG That's not really so. Windows definitely has the notions of users and groups, they just don't quite align with the POSIX model exactly. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From xahlee at gmail.com Wed Mar 17 15:17:28 2010 From: xahlee at gmail.com (Xah Lee) Date: Wed, 17 Mar 2010 12:17:28 -0700 (PDT) Subject: to RG - Lisp lunacy and Perl psychosis References: <19c5b00d-c1e0-4016-9f72-37229cbf42b9@g19g2000yqe.googlegroups.com> <79tk67-rp51.ln1@osiris.mauzo.dyndns.org> Message-ID: <6ede3156-9e9c-45ed-a532-89f5825646ea@p3g2000pra.googlegroups.com> 2010-03-17 On Mar 10, 9:17?am, Ben Morrow wrote: > Also, flamebait language-comparison xposts involving Lisp are one > of Xah Lee's trademarks. You might want to look into not imitating > him/her/it. being a professional programer today, typically you know more than just one language. Practical questions, discussions, involving more than one language is natural, and in fact happens more and more often in online forums over the past 15 years i've seen. Partly due to, of course, the tremendous birth of languages in the past decade. In the 1980s or 1990s, you don't typically use more than one lang in a project. Today, probably majority of projects requires you to use more than one well known general purpose language. In those times, discussion of more than one language is usually academic comparison. Today, honest post as ?i know this in X but how you do in Y? is a common need. The reason they become flame wars is mostly not about the message content. More about tech geeker's sensitivity, with the carried over old school netiquette that any person mentioning lang x in group y must be of no good intentions. If you look at online forums today, in fact most comp lang forums have no problem in mentioning or discussion different languages in context. The problem occur more frequently in free-for-all type of forums where the know-it-all tech geekers reside (the in-group argot is ?hacker?), each thinking they are justice kings and queens, take opportunities to ridicule, flame, any post that mention other lang or any thing that doesn't seem to be protective of their lang. This is comp.lang.* newsgroups, with good as well as mostly bad aspects. Of course, the free-for-all nature is precisely the reason most tech geekers stay in newsgroups. A good percentage of them, if not majority, are old timers. Most newsgroup tech geekers consider cross-posting wrong. I consider such taboo in this convention being a major contribution to the redundant creation of new languages, flaws, and foster the hostile faction nature of programing language groups we see. It is sad to say, comp.lang.lisp today is 90% machine generated spam. You see that each time this is brought up in the past 3 years, the regulars are too busy boasting about how they've set up some tech geek system so that spam don't reach their eyes, and sternly sputter about web browser using idiots, with, profuse suggestions from their infinite knowledge about what newsgroup reading software people should be using. To the comp.lang.python people, i think perhaps it is fruitful now to think about de-coupling the newsgroup from the mailing list... am not very involved in the comp.lang.python or python community in recent years, but my thought is that, i got the feeling that most practical posts happen in the mailing list and the newsgroup ones tend to be more free flow of thoughts... so perhaps de-couple them is good, because python is main stream now and mailing list is sustainable large, is good for more practical, concrete questions and answers, and philosophical free thoughts still have a place to go, in newsgroups. further readings: ? Proliferation of Computing Languages xahlee.org/UnixResource_dir/writ/new_langs.html ? Tech Geekers vs Spammers xahlee.org/UnixResource_dir/writ/tech_geekers_vs_spammers.html ? Cross-posting & Language Factions xahlee.org/Netiquette_dir/cross-post.html Xah ? http://xahlee.org/ ? From martin.hellwig at dcuktec.org Wed Mar 17 15:25:44 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 17 Mar 2010 19:25:44 +0000 Subject: multiprocessing on freebsd In-Reply-To: References: Message-ID: On 03/17/10 13:30, Tim Arnold wrote: > Hi, > I'm checking to see if multiprocessing works on freebsd for any > version of python. My server is about to get upgraded from 6.3 to 8.0 > and I'd sure like to be able to use multiprocessing. > > I think the minimal test would be: > --------------------- > import multiprocessing > q = multiprocessing.Queue() > --------------------- > > with 6.3, I get > > File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line > 212, in Queue > from multiprocessing.queues import Queue > File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, > in > from multiprocessing.synchronize import Lock, BoundedSemaphore, > Semaphore, Condition > File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line > 33, in > " function, see issue 3770.") > ImportError: This platform lacks a functioning sem_open > implementation, therefore, the required synchronization primitives > needed will not function, see issue 3770. > Build mine from ports, with the following options (notice SEM & PTH): [martin at aspire8930 /usr/home/martin]$ cat /var/db/ports/python26/options # This file is auto-generated by 'make config'. # No user-servicable parts inside! # Options for python26-2.6.4 _OPTIONS_READ=python26-2.6.4 WITH_THREADS=true WITHOUT_HUGE_STACK_SIZE=true WITH_SEM=true WITH_PTH=true WITH_UCS4=true WITH_PYMALLOC=true WITH_IPV6=true WITHOUT_FPECTL=true [martin at aspire8930 /usr/home/martin]$ uname -a FreeBSD aspire8930 8.0-STABLE FreeBSD 8.0-STABLE #3: Wed Feb 3 17:01:18 GMT 2010 martin at aspire8930:/usr/obj/usr/src/sys/ASPIRE8930 amd64 [martin at aspire8930 /usr/home/martin]$ python Python 2.6.4 (r264:75706, Mar 17 2010, 18:44:24) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import multiprocessing as mp >>> queue = mp.Queue() >>> hth -- mph From tjreedy at udel.edu Wed Mar 17 15:55:35 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 15:55:35 -0400 Subject: to pass self or not to pass self In-Reply-To: <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: On 3/17/2010 1:35 AM, Patrick Maupin wrote: >>>> def a(s, count, lenfunc): > ... for i in xrange(count): > ... z = lenfunc(s) > ... >>>> >>> a('abcdef', 100000000, len) >>>> >>> a('abcdef', 100000000, str.__len__) > Running cPython 2.6 on my machine, len() runs about 3 times faster > than str.__len__(). The overhead of checking that an object is usable > with a particular class method far outweighs the cost of creating the > bound method! Wow, this so surprised me, that I had to try it with 3.1 (on winxp), and got a similar result (about 2.6x longer with str.__len__). This is a real lesson in measure, don't guess, and how premature 'optimization' may be a pessimization. Thanks. Terry Jan Reedy From mail at timgolden.me.uk Wed Mar 17 15:59:57 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Mar 2010 19:59:57 +0000 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: <3rl777-q1m2.ln1@ozzie.tundraware.com> References: <3rl777-q1m2.ln1@ozzie.tundraware.com> Message-ID: <4BA134BD.8060704@timgolden.me.uk> On 17/03/2010 19:07, Tim Daneliuk wrote: > That's not really so. Windows definitely has the notions of users and groups, > they just don't quite align with the POSIX model exactly. Yes, my comment was a little blase. I know that Windows has users & groups: http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html :) I was thinking that you wanted a naive transfer of the Posix concept. The "owner" of a file does mean something to Windows (while the "group" really doesn't; it's just an artefact of Windows' posix-compatibility) but not as much as it does on Posix systems, because the security system is much more sophisticated. But maybe I'm teaching my grandmother to suck eggs ? TJG From tjreedy at udel.edu Wed Mar 17 16:12:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 16:12:11 -0400 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> <4BA0B985.3060501@ieee.org> Message-ID: On 3/17/2010 8:18 AM, Stefan Behnel wrote: > Dave Angel, 17.03.2010 12:14: >> Stefan Behnel wrote: >>> I think the point here is that executable binaries are not supposed to >>> be used as libraries. Libraries are. That's the difference between a >>> DLL and an executable in the first place. To run an executable, >>> execute it. The subprocess module is the tool of choice here. To use a >>> DLL, link against it. >>> >> There's no real reason parts of an exe cannot be exported, same as a >> dll. They are in fact the same structure. And in fact many other files >> in the Windows environment are also the same structure, from fonts to >> ocx's > > So, because you can, you'd also try to link against fonts then, I guess? > > I hope you notice that what you and me said isn't contradictory. But > there's a reason why there are libraries and executables, and there's no > reason you *should* export anything from an executable - that's what > libraries are there for. That's my point. To put it another way, if an executable has functions that could/should be available as 'library' functions, then they can/should be put in a separate library file for use as such and called from a smaller .exe. This is what python itself does. For 3.1 on winxp, python.exe is only 26 Kb, while python31.dll, with all the builtin functions and classes, (in windows/system32) is 2072 KB. > > Besides, nothing guarantees that it's safe to call stuff that an > executable exports. The executable may well require some setup code that > it only executes when it is properly started. Terry Jan Reedy From tjreedy at udel.edu Wed Mar 17 16:21:08 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 16:21:08 -0400 Subject: question about tkinter In-Reply-To: References: Message-ID: On 3/17/2010 10:33 AM, robert schaefer wrote: > No, And there's a reason (perhaps not a great one - but I'm got some constraints). > Related to that I tailored Ipython to work with gtk (ipython's default was tkinter) - tailoring was by a command > - is there any way to command idle to use gtk? I am pretty sure not, the gui is hard-coded with tkinter. From tjreedy at udel.edu Wed Mar 17 16:29:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Mar 2010 16:29:02 -0400 Subject: Nested Scopes unintended behaviour ? In-Reply-To: References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Message-ID: On 3/17/2010 11:44 AM, Emile van Sebille wrote: > On 3/17/2010 8:16 AM Michael Sparks said... >> Hi, >> >> >> Is the following behaviour expected ? > > In short, yes. Assignment within a function forces the variable to > locals. In 3.x, one can declare names to be nonlocal (ie, local to some outer function, as opposed to local to the current function or module global). In your case, nonlocal on in your inner swtchfun function would give the behavior you wanted. Terry Jan Reedy From python at bdurham.com Wed Mar 17 16:31:39 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Mar 2010 16:31:39 -0400 Subject: Converting Python CGI to WSGI scripts In-Reply-To: <4ba0735b$0$1594$742ec2ed@news.sonic.net> References: <1268759895.28810.1365130739@webmail.messagingengine.com> <4ba0735b$0$1594$742ec2ed@news.sonic.net> Message-ID: <1268857899.13963.1365364051@webmail.messagingengine.com> Sebastian/John, Thank you very much for your feedback. John: I initially missed the nuance of WSGI scripts being function calls. I suspect your tip has saved me a lot of pain :) Regards, Malcolm From tundra at tundraware.com Wed Mar 17 16:43:15 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 15:43:15 -0500 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: <3rl777-q1m2.ln1@ozzie.tundraware.com> Message-ID: <4fr777-43o2.ln1@ozzie.tundraware.com> On 3/17/2010 2:59 PM, Tim Golden wrote: > On 17/03/2010 19:07, Tim Daneliuk wrote: >> That's not really so. Windows definitely has the notions of users and >> groups, >> they just don't quite align with the POSIX model exactly. > > Yes, my comment was a little blase. I know that Windows has users & groups: > > http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html > > :) > > I was thinking that you wanted a naive transfer of the Posix concept. > The "owner" of a file does mean something to Windows (while the "group" > really doesn't; it's just an artefact of Windows' posix-compatibility) > but not as much as it does on Posix systems, because the security system > is much more sophisticated. > > But maybe I'm teaching my grandmother to suck eggs ? > > TJG Naw. The intent is just to provide as similar as possible a user experience. >From a coding POV, it is surely simpler to just use 'winuser' and 'wingroup', but I am sort of philosophically wired to not throw information away if it's a available from the OS. BTW, wanna beta test a really cool CLI mass file renaming tool????? ;) -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From pmaupin at gmail.com Wed Mar 17 17:21:44 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 14:21:44 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> Message-ID: On Mar 17, 2:55?pm, Terry Reedy wrote: > On 3/17/2010 1:35 AM, Patrick Maupin wrote: > > >>>> def a(s, count, lenfunc): > > ... ? ? for i in xrange(count): > > ... ? ? ? ?z = lenfunc(s) > > ... > >>>> >>> ?a('abcdef', 100000000, len) > >>>> >>> ?a('abcdef', 100000000, str.__len__) > > Running cPython 2.6 on my machine, len() runs about 3 times faster > > than str.__len__(). ?The overhead of checking that an object is usable > > with a particular class method far outweighs the cost of creating the > > bound method! > > Wow, this so surprised me, that I had to try it with 3.1 (on winxp), and > got a similar result (about 2.6x longer with str.__len__). This is a > real lesson in measure, don't guess, and how premature 'optimization' > may be a pessimization. Thanks. > > Terry Jan Reedy Actually, I think I overstated my case -- there is some special logic for len and built-in objects, I think. I can see the same thing with normal attributes on subclasses of object(), but not nearly as dramatic. In any case, your conclusion about this being a lesson in "measure, don't guess" holds, with the additional caveat that, if it matters, you need to somehow do some additional measurements to make sure you are measuring what you think you are measuring! Pat From tundra at tundraware.com Wed Mar 17 17:30:19 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Wed, 17 Mar 2010 16:30:19 -0500 Subject: What Does sys.platform Return On 64 Bit Windows Systems? Message-ID: On older 32 bit Windows systems, sys.platform returns: 'win32' What does it return on 64-bit Windows systems? I'd check myself, but I don't have access to 64-bit Windows. TIA, -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From gagsl-py2 at yahoo.com.ar Wed Mar 17 17:37:24 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 17 Mar 2010 18:37:24 -0300 Subject: bug in bdist_wininst cross compile? References: <4BA0E958.8050205@chamonix.reportlab.co.uk> Message-ID: En Wed, 17 Mar 2010 11:38:16 -0300, Robin Becker escribi?: > has anyone had any success with cross compilation and bdist_wininst; I > have modified build_ext very slightly to fix a small bug in cross > compilation related to library order. Please post your bug report + patch at http://bugs.python.org or it will be lost. -- Gabriel Genellina From keirvt at gmail.com Wed Mar 17 18:04:14 2010 From: keirvt at gmail.com (Keir Vaughan-taylor) Date: Wed, 17 Mar 2010 15:04:14 -0700 (PDT) Subject: os.walk restart Message-ID: I am traversing a large set of directories using for root, dirs, files in os.walk(basedir): run program Being a huge directory set the traversal is taking days to do a traversal. Sometimes it is the case there is a crash because of a programming error. As each directory is processed the name of the directory is written to a file I want to be able to restart the walk from the directory where it crashed. Is this possible? From gatoygata2 at gmail.com Wed Mar 17 18:34:53 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Wed, 17 Mar 2010 15:34:53 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> Message-ID: On Mar 17, 3:43?pm, Patrick Maupin wrote: > On Mar 17, 4:12?am, Bruno Desthuilliers > 42.desthuilli... at websiteburo.invalid> wrote: > > Patrick Maupin a ?crit : > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > >> Why not create the bound methods at instantiation time, rather than > > >> using the descriptor protocol which has the overhead of creating a new > > >> bound method each time the method attribute is accessed? > > > > Well, for one thing, Python classes are open. ?They can be added to at > > > any time. ?For another thing, you might not ever use most of the > > > methods of an instance, so it would be a huge waste to create those. > > > A possible optimization would be a simple memoization on first access. > > I do agree that memoization on access is a good pattern, and I use it > frequently. ?I don't know if I would want the interpreter > automagically doing that for everything, though -- it would require > some thought to figure out what the overhead cost is for the things > that are only used once. > > Usually, I will have a slight naming difference for the things I want > memoized, to get the memoization code to run. ?For example, if you add > an underbar in front of everything you want memoized: > > class foo(object): > > ? ? def _bar(self): > ? ? ? ? pass > > ? ? def __getattr__(self, aname): > ? ? ? ? if aname.startswith('_'): > ? ? ? ? ? ? raise AttributeError > ? ? ? ? value = getattr(self, '_' + aname) > ? ? ? ? self.aname = value > ? ? ? ? return value > > obj = foo() > > So then the first time you look up obj.bar, it builds the bound > method, and on subsequent accesses it just returns the previously > bound method. > > Regards, > Pat Patrick, I was trying to understand the way your code was working but I thing I'm not getting it. I tested: from time import time class foo1(object): def _bar(self): pass def __getattr__(self, name): value = getattr(self, '_' + name) self.name = value return value class foo2(object): def bar(self): pass def a(klass, count): ins = klass() for i in xrange(count): z = ins.bar() t0 = time() a(foo1, 10000000) t1 = time() a(foo2, 10000000) t2 = time() print t1-t0 #75 sec print t2-t1 #11 sec foo1 is a lot slower than foo2. I understood that memoization should optimize atribute calls. Maybe I am putting my foot in my mouth... Thanks JA From googler.1.webmaster at spamgourmet.com Wed Mar 17 18:35:06 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Wed, 17 Mar 2010 15:35:06 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> Message-ID: <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> > 1) put the line number information into the message string when you raise > the exception you mean the line and file information of the C code, right? From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 18:38:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 22:38:21 GMT Subject: Swapping Content of Two Dictionaries. References: <779ea7fb1003160146t6fe79d6erc6dc12ea7452f6b3@mail.gmail.com> <779ea7fb1003170426o3dff6f06lade4b90c6a81f265@mail.gmail.com> Message-ID: On Wed, 17 Mar 2010 13:34:51 +0100, Peter Otten wrote: > Hatem Oraby wrote: > >> Hello, I want to swap the content of two dictionaries, the obvious way >> to do it is: >> a = {1:"I'am A"} >> b = {2:"I'm B"} >> temp = a >> a = b >> b = temp > > That can be simplified to > > a, b = b, a > > and is almost certainly the right approach. Unfortunately, it may not, because it doesn't swap the content of two dictionaries (as asked for), but instead swaps the dictionaries bound to two names, which is a very different kettle of fish indeed. It may be that the OP's description of his problem is inaccurate, in which case a simple re-binding is the easiest way, but if the subject line is accurate, then he needs your suggested solution using a temporary dict, clear and update. Wrap it in a function, and you have a one-liner swap operation :) -- Steven From gagsl-py2 at yahoo.com.ar Wed Mar 17 18:39:45 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 17 Mar 2010 19:39:45 -0300 Subject: How to access a web site with an authentication template. References: <4BA122B4.5030003@bluewin.ch> Message-ID: En Wed, 17 Mar 2010 15:43:00 -0300, Anthra Norell escribi?: > I understand that I can access password protected sites with urllib2. > [...] a site I am dealing with, because the opening page does not > require a password. It presents an id/password entry template and I have > no clue how to respond in python. The page source is chock full of java > script. Use an HTTP sniffer (there are plenty) to see the actual request that is sent to the server. Then emulate it using urllib2. -- Gabriel Genellina From david at boddie.org.uk Wed Mar 17 18:40:43 2010 From: david at boddie.org.uk (David Boddie) Date: Wed, 17 Mar 2010 23:40:43 +0100 Subject: highlight words by regex in pdf files using python References: Message-ID: On Wednesday 17 March 2010 00:47, Aahz wrote: > In article > , > Peng Yu wrote: >> >>I don't find a general pdf library in python that can do any >>operations on pdfs. >> >>I want to automatically highlight certain words (using regex) in a >>pdf. Could somebody let me know if there is a tool to do so in python? > > Did you Google at all? "python pdf" finds this as the first link, though > I have no clue whether it does what you want: > > http://pybrary.net/pyPdf/ The original poster might also be interested in displaying the highlighted words without modifying the original file. In which case, the Poppler library is worth investigating: http://poppler.freedesktop.org/ David From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 18:42:35 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 22:42:35 GMT Subject: os.walk restart References: Message-ID: On Wed, 17 Mar 2010 15:04:14 -0700, Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to a > file What, a proper, honest-to-goodness core dump? Or do you mean an exception? > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? Quick and dirty with no error-checking: # Untested last_visited = open("last_visited.txt", 'r').read() for root, dirs, files in os.walk(last_visited or basedir): open("last_visited.txt", 'w').write(root) run program -- Steven From news1234 at free.fr Wed Mar 17 18:47:41 2010 From: news1234 at free.fr (News123) Date: Wed, 17 Mar 2010 23:47:41 +0100 Subject: url2lib (windows 7) does not notice when network reconnects (getaddrinfo problem) Message-ID: <4ba15c0d$0$15456$426a74cc@news.free.fr> Hi, I'd like to write a function, that knows when the 'internet' is reachable. My setup is a windows7 host with a wireless USB modem. The modem might connect / disconnect any time. I thought I write a small function just checking whether I can fetch a url. ######### script starts import time,urllib2 myurl = "http://www.mysite.com" # or "www.google.com" or whatever you like while True: connected = False try: urllib2.urlopen(myurl) connected = True except urllib2.URLError as e: print "urlerr %s" % e print "connected",connected time.sleep(1) ########## end of script if the network is connected when I start the script the first time after reboot, then I receive > connected True As expected If the network is disconnected when I start the script the first time after reboot, then I receive > urlerr > connected False as expected Things are getting weired, when my USB wireless modem connects after I started my script: It happens, that I just continue to receive: > urlerr > connected False however when I use a windows cmd window and I start "ping www.mysite.com", then my python script recovers and reports > connected True My perhaps false conclusion is, that getaddrinfo() is not retrying to resolve an IP address, when it failed once. Is this behaviour known? Can this really be possible? I can reproduce this issue. not every time, but rather often. If yes, is there any way to force a new host name lookup under windows? What else could I be doing wrong? Thanks a lot in advance for any ideas N From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 18:49:20 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Mar 2010 22:49:20 GMT Subject: What Does sys.platform Return On 64 Bit Windows Systems? References: Message-ID: On Wed, 17 Mar 2010 16:30:19 -0500, Tim Daneliuk wrote: > On older 32 bit Windows systems, sys.platform returns: 'win32' > > What does it return on 64-bit Windows systems? I'd check myself, but I > don't have access to 64-bit Windows. According to the docs, it returns win32: http://docs.python.org/library/sys.html If anyone knows different, this should be reported as a documentation bug. But 30 seconds of googling suggests that sys.platform is 'win32' even on 64-bit builds of Windows, by design: http://stackoverflow.com/questions/2144748/is-it-safe-to-use-sys-platformwin32-check-on-64-bit-python -- Steven From gagsl-py2 at yahoo.com.ar Wed Mar 17 19:09:28 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 17 Mar 2010 20:09:28 -0300 Subject: os.walk restart References: Message-ID: En Wed, 17 Mar 2010 19:04:14 -0300, Keir Vaughan-taylor escribi?: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to > a file > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? If the 'dirs' list were guaranteed to be sorted, you could remove at each level all previous directories already traversed. But it's not :( Perhaps a better approach would be, once, collect all directories to be processed and write them on a text file -- these are the pending directories. Then, read from the pending file and process every directory in it. If the process aborts for any reason, manually delete the lines already processed and restart. If you use a database instead of a text file, and mark entries as "done" after processing, you can avoid that last manual step and the whole process may be kept running automatically. In some cases you may want to choose the starting point at random. -- Gabriel Genellina From pmaupin at gmail.com Wed Mar 17 19:11:42 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Wed, 17 Mar 2010 16:11:42 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> Message-ID: <0314849c-f748-4989-ae91-4dd42c95c251@q21g2000yqm.googlegroups.com> On Mar 17, 5:34?pm, Joaquin Abian wrote: > On Mar 17, 3:43?pm, Patrick Maupin wrote: > > > > > On Mar 17, 4:12?am, Bruno Desthuilliers > > 42.desthuilli... at websiteburo.invalid> wrote: > > > Patrick Maupin a ?crit : > > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > > >> Why not create the bound methods at instantiation time, rather than > > > >> using the descriptor protocol which has the overhead of creating a new > > > >> bound method each time the method attribute is accessed? > > > > > Well, for one thing, Python classes are open. ?They can be added to at > > > > any time. ?For another thing, you might not ever use most of the > > > > methods of an instance, so it would be a huge waste to create those. > > > > A possible optimization would be a simple memoization on first access. > > > I do agree that memoization on access is a good pattern, and I use it > > frequently. ?I don't know if I would want the interpreter > > automagically doing that for everything, though -- it would require > > some thought to figure out what the overhead cost is for the things > > that are only used once. > > > Usually, I will have a slight naming difference for the things I want > > memoized, to get the memoization code to run. ?For example, if you add > > an underbar in front of everything you want memoized: > > > class foo(object): > > > ? ? def _bar(self): > > ? ? ? ? pass > > > ? ? def __getattr__(self, aname): > > ? ? ? ? if aname.startswith('_'): > > ? ? ? ? ? ? raise AttributeError > > ? ? ? ? value = getattr(self, '_' + aname) > > ? ? ? ? self.aname = value > > ? ? ? ? return value > > > obj = foo() > > > So then the first time you look up obj.bar, it builds the bound > > method, and on subsequent accesses it just returns the previously > > bound method. > > > Regards, > > Pat > > Patrick, I was trying to understand the way your code was working but > I thing I'm not getting it. > > I tested: > > from time import time > > class foo1(object): > ? ? def _bar(self): > ? ? ? ? pass > ? ? def __getattr__(self, name): > ? ? ? ? value = getattr(self, '_' + name) > ? ? ? ? self.name = value > ? ? ? ? return value > > class foo2(object): > ? ? def bar(self): > ? ? ? ? pass > > def a(klass, count): > ? ? ins = klass() > ? ? for i in xrange(count): > ? ? ? ? z = ins.bar() > > t0 = time() > a(foo1, ?10000000) > t1 = time() > a(foo2, 10000000) > t2 = time() > > print t1-t0 ? #75 sec > print t2-t1 ? #11 sec > > foo1 is a lot slower than foo2. I understood that memoization should > optimize atribute calls. Maybe I am putting my foot in my mouth... > > Thanks > JA I don't think you are putting your foot in your mouth. I always have to test to remember what works faster and what doesn't. Usually when I memoize as I showed, it is not a simple attribute lookup, but something that takes more work to create. As I stated in my response to Terry, I overstated my case earlier, because of some optimizations in len(), I think. Nonetheless, (at least on Python 2.6) I think the advice I gave to the OP holds. One difference is that you are doing an attribute lookup in your inner loop. I do find that performance hit surprising, but to compare with what the OP is describing, you either need to look up an unbound function in a dict and call it with a parameter, or look up a bound method in a dict and call it without the parameter. Since the dict lookup doesn't usually do anything fancy and unexpected like attribute lookup, we pull the dict lookup out of the equation and out of the inner loop, and just do the comparison like this: >>> class foo(object): ... def bar(self): ... pass ... >>> x = foo() >>> >>> def a(func, count): ... for i in xrange(count): ... z=func() ... >>> def b(func, param, count): ... for i in xrange(count): ... z=func(param) ... >>> >>> a(x.bar, 100000000) # 13 seconds >>> b(foo.bar, x, 100000000) # 18 seconds Regards, Pat From lists at cheimes.de Wed Mar 17 19:16:55 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 18 Mar 2010 00:16:55 +0100 Subject: What Does sys.platform Return On 64 Bit Windows Systems? In-Reply-To: References: Message-ID: <4BA162E7.7000503@cheimes.de> Tim Daneliuk schrieb: > On older 32 bit Windows systems, sys.platform returns: 'win32' > > What does it return on 64-bit Windows systems? I'd check myself, but > I don't have access to 64-bit Windows. Do you want to know if the current build of Python is a 32 or 64bit build? >>> import struct >>> struct.calcsize("P") * 8 64 Christian From steven at REMOVE.THIS.cybersource.com.au Wed Mar 17 20:12:14 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 00:12:14 GMT Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> Message-ID: On Mon, 15 Mar 2010 16:34:35 -0700, JLundell wrote: > It's also unfortunate that Python doesn't have an approximately-equal > operator; it'd come in handy for floating-point applications while > preserving hash. If only there were a ~= or ? operator I could overload. > And ~ is unary, so no joy. Not everything needs to be a built-in, or an operator. This might be useful for you: http://code.activestate.com/recipes/577124-approximately-equal/ Feedback welcome. -- Steven From gatoygata2 at gmail.com Wed Mar 17 20:55:41 2010 From: gatoygata2 at gmail.com (Joaquin Abian) Date: Wed, 17 Mar 2010 17:55:41 -0700 (PDT) Subject: to pass self or not to pass self References: <4b9f4984$0$10229$426a74cc@news.free.fr> <4817ed21-61f4-4487-a8d7-399b114284d1@z35g2000yqd.googlegroups.com> <4ba09d09$0$21466$426a74cc@news.free.fr> <503dc9c5-e1ce-4b33-aff4-ee9677839fe0@33g2000yqj.googlegroups.com> <0314849c-f748-4989-ae91-4dd42c95c251@q21g2000yqm.googlegroups.com> Message-ID: On Mar 18, 12:11?am, Patrick Maupin wrote: > On Mar 17, 5:34?pm, Joaquin Abian wrote: > > > > > On Mar 17, 3:43?pm, Patrick Maupin wrote: > > > > On Mar 17, 4:12?am, Bruno Desthuilliers > > > 42.desthuilli... at websiteburo.invalid> wrote: > > > > Patrick Maupin a ?crit : > > > > > > On Mar 16, 1:59 pm, Jason Tackaberry wrote: > > > > >> Why not create the bound methods at instantiation time, rather than > > > > >> using the descriptor protocol which has the overhead of creating a new > > > > >> bound method each time the method attribute is accessed? > > > > > > Well, for one thing, Python classes are open. ?They can be added to at > > > > > any time. ?For another thing, you might not ever use most of the > > > > > methods of an instance, so it would be a huge waste to create those. > > > > > A possible optimization would be a simple memoization on first access. > > > > I do agree that memoization on access is a good pattern, and I use it > > > frequently. ?I don't know if I would want the interpreter > > > automagically doing that for everything, though -- it would require > > > some thought to figure out what the overhead cost is for the things > > > that are only used once. > > > > Usually, I will have a slight naming difference for the things I want > > > memoized, to get the memoization code to run. ?For example, if you add > > > an underbar in front of everything you want memoized: > > > > class foo(object): > > > > ? ? def _bar(self): > > > ? ? ? ? pass > > > > ? ? def __getattr__(self, aname): > > > ? ? ? ? if aname.startswith('_'): > > > ? ? ? ? ? ? raise AttributeError > > > ? ? ? ? value = getattr(self, '_' + aname) > > > ? ? ? ? self.aname = value > > > ? ? ? ? return value > > > > obj = foo() > > > > So then the first time you look up obj.bar, it builds the bound > > > method, and on subsequent accesses it just returns the previously > > > bound method. > > > > Regards, > > > Pat > > > Patrick, I was trying to understand the way your code was working but > > I thing I'm not getting it. > > > I tested: > > > from time import time > > > class foo1(object): > > ? ? def _bar(self): > > ? ? ? ? pass > > ? ? def __getattr__(self, name): > > ? ? ? ? value = getattr(self, '_' + name) > > ? ? ? ? self.name = value > > ? ? ? ? return value > > > class foo2(object): > > ? ? def bar(self): > > ? ? ? ? pass > > > def a(klass, count): > > ? ? ins = klass() > > ? ? for i in xrange(count): > > ? ? ? ? z = ins.bar() > > > t0 = time() > > a(foo1, ?10000000) > > t1 = time() > > a(foo2, 10000000) > > t2 = time() > > > print t1-t0 ? #75 sec > > print t2-t1 ? #11 sec > > > foo1 is a lot slower than foo2. I understood that memoization should > > optimize atribute calls. Maybe I am putting my foot in my mouth... > > > Thanks > > JA > > I don't think you are putting your foot in your mouth. ?I always have > to test to remember what works faster and what doesn't. ?Usually when > I memoize as I showed, it is not a simple attribute lookup, but > something that takes more work to create. ?As I stated in my response > to Terry, I overstated my case earlier, because of some optimizations > in len(), I think. ?Nonetheless, (at least on Python 2.6) I think the > advice I gave to the OP holds. ?One difference is that you are doing > an attribute lookup in your inner loop. ?I do find that performance > hit surprising, but to compare with what the OP is describing, you > either need to look up an unbound function in a dict and call it with > a parameter, or look up a bound method in a dict and call it without > the parameter. ?Since the dict lookup doesn't usually do anything > fancy and unexpected like attribute lookup, we pull the dict lookup > out of the equation and out of the inner loop, and just do the > comparison like this: > > >>> class foo(object): > > ... ? ? def bar(self): > ... ? ? ? ? pass > ...>>> x = foo() > > >>> def a(func, count): > > ... ? ? for i in xrange(count): > ... ? ? ? ? z=func() > ...>>> def b(func, param, count): > > ... ? ? for i in xrange(count): > ... ? ? ? ? z=func(param) > ... > > > > >>> a(x.bar, ? ? ?100000000) ?# 13 seconds > >>> b(foo.bar, x, 100000000) ?# 18 seconds > > Regards, > Pat OK, Thanks. Need to play a little bit with it. Cheers JA From python at bdurham.com Wed Mar 17 22:42:46 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Mar 2010 22:42:46 -0400 Subject: Possible to open a file for shared write mode under Windows? Message-ID: <1268880166.3322.1365412149@webmail.messagingengine.com> Is there a way to open a file for shared write mode under Windows? I have 2 processes that will write to different regions of this shared file. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Wed Mar 17 23:08:48 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Mar 2010 20:08:48 -0700 (PDT) Subject: os.walk restart References: Message-ID: <92b42203-876f-4383-9af6-b0ed775c3d92@w9g2000prb.googlegroups.com> Steven D'Aprano wrote: > # Untested > last_visited = open("last_visited.txt", 'r').read() > for root, dirs, files in os.walk(last_visited or basedir): > ? ? ?open("last_visited.txt", 'w').write(root) > ? ? ?run program Wouldn't this only walk the directory the exception occured in and not the remaining unwalked dirs from basedir? Something like this should work: import os basedir = '.' walked = open('walked.txt','r').read().split() unwalked = ((r,d,f) for r,d,f in os.walk(basedir) if r not in walked) for root, dirs, files in unwalked: # do something print root walked.append(root) open('walked.txt','w').write('\n'.join(walked)) From python at mrabarnett.plus.com Wed Mar 17 23:34:46 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Mar 2010 03:34:46 +0000 Subject: os.walk restart In-Reply-To: References: Message-ID: <4BA19F56.4020302@mrabarnett.plus.com> Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to > a file > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? I would write my own walker which sorts the directory entries it finds before walking them and can skip the entries until it gets to the desired starting path, eg if I want to start at "/foo/bar" then skip over the entries in the root directory which start with a name before "foo" and the entries in the subdirectory "/foo" which start with a name before "bar". From showell30 at yahoo.com Wed Mar 17 23:49:58 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 17 Mar 2010 20:49:58 -0700 (PDT) Subject: os.walk restart References: Message-ID: <68cbed3c-87f6-45c9-ac8e-a536cae20f26@k6g2000prg.googlegroups.com> On Mar 17, 3:04?pm, Keir Vaughan-taylor wrote: > I am traversing a large set of directories using > > for root, dirs, files in os.walk(basedir): > ? ? run program > > Being a huge directory set the traversal is taking days to do a > traversal. > Sometimes it is the case there is a crash because of a programming > error. > As each directory is processed the name of the directory is written to > a file > I want to be able to restart the walk from the directory where it > crashed. > > Is this possible? I assume it's the operation that you are doing on each file that is expensive, not the walk itself. If that's the case, then you might be able to get away with just leaving some kind of breadcrumbs whenever you've successfully processed a directory or a file, so you can quickly short-circuit entire directories or files on the next run, without having to implement any kind of complicated start-where-I-left-off before algorithm. The breadcrumbs could be hidden files in the file system, or an easy- indexable list of files that you persist, etc. What are you doing that takes so long? Also, I can understand why the operations on the files themselves might crash, but can't you catch an exception and keep on chugging? Another option, if you do not do some kind of pruning on the fly, is to persist the list of files that you need to process up front to a file, or a database, and persist the index of the last successfully processed file, so that you can restart as needed from where you left off. From steven at REMOVE.THIS.cybersource.com.au Thu Mar 18 00:04:46 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 04:04:46 GMT Subject: os.walk restart References: <92b42203-876f-4383-9af6-b0ed775c3d92@w9g2000prb.googlegroups.com> Message-ID: On Wed, 17 Mar 2010 20:08:48 -0700, alex23 wrote: > Steven D'Aprano wrote: >> # Untested >> last_visited = open("last_visited.txt", 'r').read() >> for root, dirs, files in os.walk(last_visited or basedir): >> ? ? ?open("last_visited.txt", 'w').write(root) run program > > Wouldn't this only walk the directory the exception occured in and not > the remaining unwalked dirs from basedir? Only if you have some sort of branching file hierarchy with multiple sub- directories in the one directory, instead of a nice simple linear chain of directories a/b/c/d/.../z as nature intended. *wink* Yes, good catch. I said it was untested. You might be able to save the parent of the current directory, and restart from there instead. -- Steven From gagsl-py2 at yahoo.com.ar Thu Mar 18 00:20:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 18 Mar 2010 01:20:31 -0300 Subject: Possible to open a file for shared write mode under Windows? References: <1268880166.3322.1365412149@webmail.messagingengine.com> Message-ID: En Wed, 17 Mar 2010 23:42:46 -0300, escribi?: > Is there a way to open a file for shared write mode under > Windows? > > I have 2 processes that will write to different regions of this > shared file. Using the pywin32 package at sourceforge, you have access to the CreateFile function: http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx You want dwShareMode=FILE_SHARE_WRITE -- Gabriel Genellina From sccolbert at gmail.com Thu Mar 18 00:38:56 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Mar 2010 00:38:56 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: References: <1268880166.3322.1365412149@webmail.messagingengine.com> Message-ID: <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> you could also just have one process do the writing for both processes via pipes. On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina wrote: > En Wed, 17 Mar 2010 23:42:46 -0300, escribi?: > > > Is there a way to open a file for shared write mode under >> Windows? >> >> I have 2 processes that will write to different regions of this >> shared file. >> > > Using the pywin32 package at sourceforge, you have access to the CreateFile > function: http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > You want dwShareMode=FILE_SHARE_WRITE > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Mar 18 00:52:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Mar 2010 00:52:28 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> References: <1268880166.3322.1365412149@webmail.messagingengine.com> <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> Message-ID: Chris Colbert wrote: [top-posting switched to bottom-posting] > > On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina > > wrote: > > En Wed, 17 Mar 2010 23:42:46 -0300, > escribi?: > > > Is there a way to open a file for shared write mode under > Windows? > > I have 2 processes that will write to different regions of this > shared file. > > > Using the pywin32 package at sourceforge, you have access to the > CreateFile function: > http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > You want dwShareMode=FILE_SHARE_WRITE > > you could also just have one process do the writing for both processes > via pipes. You could, but then you'd have to work out how to avoid blocking on one pipe when data was available form the other. Or is this trivially easy, and I just don't know enough about pipes? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at bdurham.com Thu Mar 18 01:15:50 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Mar 2010 01:15:50 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: References: <1268880166.3322.1365412149@webmail.messagingengine.com> Message-ID: <1268889350.21982.1365426663@webmail.messagingengine.com> Hi Gabriel, > Using the pywin32 package at sourceforge, you have access to the CreateFile function: > http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > You want dwShareMode=FILE_SHARE_WRITE Thanks - that was exactly what I was looking for. Regards, Malcolm From sccolbert at gmail.com Thu Mar 18 01:31:33 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Mar 2010 01:31:33 -0400 Subject: Possible to open a file for shared write mode under Windows? In-Reply-To: References: <1268880166.3322.1365412149@webmail.messagingengine.com> <7f014ea61003172138x6482aa87v50c865cb4e51eba5@mail.gmail.com> Message-ID: <7f014ea61003172231m60ec154rda99c31c06d82eb6@mail.gmail.com> It's not too difficult: # subp.py import sys import time for i in range(10): sys.stdout.write('I am subprocess\n') sys.stdout.flush() # this may not be necessary time.sleep(1) # writer.py import subprocess import time subp = subprocess.Popen(['/usr/bin/python', '-u', './subp.py'], stdout=subprocess.PIPE) while True: time.sleep(1) print('I am main process.') # write this to one section of the file if subp.poll() != None: # the subprocess has terminated break stdout = subp.stdout.readline() print(stdout) # write this to the other section brucewayne at broo:~/Documents$ python ./writer.py I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. I am subprocess I am main process. On Thu, Mar 18, 2010 at 12:52 AM, Steve Holden wrote: > Chris Colbert wrote: > [top-posting switched to bottom-posting] > > > > On Thu, Mar 18, 2010 at 12:20 AM, Gabriel Genellina > > > wrote: > > > > En Wed, 17 Mar 2010 23:42:46 -0300, > > escribi?: > > > > > > Is there a way to open a file for shared write mode under > > Windows? > > > > I have 2 processes that will write to different regions of this > > shared file. > > > > > > Using the pywin32 package at sourceforge, you have access to the > > CreateFile function: > > http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx > > You want dwShareMode=FILE_SHARE_WRITE > > > > you could also just have one process do the writing for both processes > > via pipes. > > You could, but then you'd have to work out how to avoid blocking on one > pipe when data was available form the other. Or is this trivially easy, > and I just don't know enough about pipes? > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Thu Mar 18 01:52:14 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 05:52:14 GMT Subject: Understanding the CPython dict implementation References: <4b9f6fab$0$27822$c3e8da3@news.astraweb.com> Message-ID: On Tue, 16 Mar 2010 16:04:22 -0400, Terry Reedy wrote: > On 3/16/2010 7:46 AM, Steven D'Aprano wrote: >> On Sun, 14 Mar 2010 19:39:46 -0400, Terry Reedy wrote: >> >>> I found this PyCon2010 presentation to be excellent: The Mighty >>> Dictionary, Branden Craig Rhodes, 30 min. > > Sorry, > http://pycon.blip.tv/file/3332763/ > > which plays fine in FF3.6 on windows > > >>> http://pycon.blip.tv/file/3264041/ > > wrong file number > >> Unfortunately, that clip seems to be unwatchable, at least for me. It >> crashed the Netscape plugin in Konqueror, and crashed Firefox. > > The flash version does not work for me. This is true of about 1/3 of the > Pycon 2010 videos that I have tried. The .ogv version of this and all > others that I have tried (hit Download under Comments) plays fine within > FF3.6 on my windows xp machine. Perhaps there is a linux-specific bug, > if that is what you are running under. Amusingly, the FLV files play perfectly for me under Linux, while the OGV files don't :) Thanks for the links, the videos are very interesting. -- Steven From zubin.mithra at gmail.com Thu Mar 18 02:28:53 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Thu, 18 Mar 2010 11:58:53 +0530 Subject: D-Bus Message-ID: <8e7c74321003172328s2f22ae87v4c732ff3d33c094e@mail.gmail.com> Hello, I have experience writing scripts to connect to the D-Bus interface provided by different applications but have no experience writing a D-Bus interface for an application. Could someone point me in the right direction? A tutorial or a good example would be nice. Cheers!!! Zubin Mithra http://zubin71.wordpress.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Thu Mar 18 03:49:55 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Mar 2010 20:49:55 +1300 Subject: import antigravity References: Message-ID: In message , Chris Rebert wrote: I see that you published my unobfuscated e-mail address on USENET for all to see. I obfuscated it for a reason, to keep the spammers away. I'm assuming this was a momentary lapse of judgement, for which I expect an apology. Otherwise, it becomes grounds for an abuse complaint to your ISP. From stefan_ml at behnel.de Thu Mar 18 04:13:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 09:13:05 +0100 Subject: C-API PyObject_Call In-Reply-To: <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> Message-ID: moerchendiser2k3, 17.03.2010 23:35: >> 1) put the line number information into the message string when you raise >> the exception > > you mean the line and file information of the C code, right? Funny that you (being the OP) ask *me* what kind of line information *you* want. Stefan From stefan_ml at behnel.de Thu Mar 18 04:17:43 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 09:17:43 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: Lawrence D'Oliveiro, 18.03.2010 08:49: > In message, Chris > Rebert wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. I hope you just had a bad day. Threatening others for figuring out your e-mail address is even worse than posting with an illegal e-mail address. Stefan From alfps at start.no Thu Mar 18 04:53:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 18 Mar 2010 09:53:05 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Lawrence D'Oliveiro: > In message , Chris > Rebert wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Hi. Chris Rebert didn't reveal anything not already present in the posting he replied to, and indeed in the posting I'm replying to here. The headers in the article I'm replying to (yours) look like this: Path: feeder.eternal-september.org!eternal-september.org!feeder.erje.net!newsfeed.straub-nv.de!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail From: Lawrence D'Oliveiro Newsgroups: comp.lang.python Subject: Re: import antigravity Followup-To: comp.lang.python Date: Thu, 18 Mar 2010 20:49:55 +1300 Organization: Geek Central Lines: 7 Message-ID: References: NNTP-Posting-Host: 118-92-14-26.dsl.dyn.ihug.co.nz Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: lust.ihug.co.nz 1268898595 20084 118.92.14.26 (18 Mar 2010 07:49:55 GMT) X-Complaints-To: abuse at ihug.co.nz NNTP-Posting-Date: Thu, 18 Mar 2010 07:49:55 +0000 (UTC) User-Agent: KNode/4.3.4 Xref: eternal-september.org comp.lang.python:51777 One must assume that you were not aware that you're posting your mail address in plaintext in every article? Cheers & hth., - Alf From mail at timgolden.me.uk Thu Mar 18 04:54:58 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 18 Mar 2010 08:54:58 +0000 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: <4fr777-43o2.ln1@ozzie.tundraware.com> References: <3rl777-q1m2.ln1@ozzie.tundraware.com> <4fr777-43o2.ln1@ozzie.tundraware.com> Message-ID: <4BA1EA62.1010401@timgolden.me.uk> On 17/03/2010 20:43, Tim Daneliuk wrote: > The intent is just to provide as similar as possible a user experience. >> From a coding POV, it is surely simpler to just use 'winuser' and 'wingroup', > but I am sort of philosophically wired to not throw information away if > it's a available from the OS. It's hardly worth disputing I suppose, but I would argue that simply presenting the owner & group of a file in Windows is actually doing a disservice to the user of the app. It's cluttering up the display with information which is essentially useless. Pretty much the only time I ever look at a file owner is when I have some knotty security issue and I need to assess who might have WRITE_DAC permission. The group - never; it really is a relic. The file owner & group simply don't play the same role in Windows security that they do in *nix. The trouble is that there isn't a simple alternative: most files, even with default security, will have two or three groups involved in their security at different levels. > BTW, wanna beta test a really cool CLI mass file renaming tool????? ;) Sure -- I'll have a look. But I can't promise any great amount of time at present :) TJG From clp2 at rebertia.com Thu Mar 18 04:56:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Mar 2010 01:56:49 -0700 Subject: Recall: How to add a library path to pythonpath ? In-Reply-To: <7F0503CD69378F49BE0DC30661C6CCF684F3C839@enbmail01.lsi.com> References: <7F0503CD69378F49BE0DC30661C6CCF684F3C839@enbmail01.lsi.com> Message-ID: <50697b2c1003180156q61786c48i122e63caa94514bd@mail.gmail.com> On Tue, Mar 16, 2010 at 4:56 AM, Barak, Ron wrote: > Barak, Ron would like to recall the message, "How to add a library path to pythonpath ?". Good luck with that. :) - Chris From stefan_ml at behnel.de Thu Mar 18 05:19:59 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 10:19:59 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: Alf P. Steinbach, 18.03.2010 09:53: > > Path: > feeder.eternal-september.org!eternal-september.org!feeder.erje.net!newsfeed.straub-nv.de!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail > > From: Lawrence D'Oliveiro > Newsgroups: comp.lang.python > Subject: Re: import antigravity > Followup-To: comp.lang.python > Date: Thu, 18 Mar 2010 20:49:55 +1300 > Organization: Geek Central > Lines: 7 > Message-ID: > References: > > NNTP-Posting-Host: 118-92-14-26.dsl.dyn.ihug.co.nz > Mime-Version: 1.0 > Content-Type: text/plain; charset="ISO-8859-1" > Content-Transfer-Encoding: 7Bit > X-Trace: lust.ihug.co.nz 1268898595 20084 118.92.14.26 (18 Mar 2010 > 07:49:55 GMT) > X-Complaints-To: abuse at ihug.co.nz > NNTP-Posting-Date: Thu, 18 Mar 2010 07:49:55 +0000 (UTC) > User-Agent: KNode/4.3.4 > Xref: eternal-september.org comp.lang.python:51777 > > > > One must assume that you were not aware that you're posting your mail > address in plaintext in every article? Uhm - where? Stefan From news1234 at free.fr Thu Mar 18 05:20:38 2010 From: news1234 at free.fr (News123) Date: Thu, 18 Mar 2010 10:20:38 +0100 Subject: did anybody play with python and window mobile broadband? Message-ID: <4ba1f067$0$4589$426a74cc@news.free.fr> Hi, I'd like to use a mobile broadband device with a windows python app. Did anybody play already with python and the window mobile broadband interface? I'm looking for examples: - how to connect/disconnect a mobile broadband device (currently I use rasdial. not sure it's the best solution) - to obtain the device's current mode (GPRS / EDGE / . . . ) - to obtain the current signal level Thanks a lot for any pointers N From sanjiva at croatia.oracle.in Thu Mar 18 05:26:24 2010 From: sanjiva at croatia.oracle.in (Sanjiva P.) Date: Thu, 18 Mar 2010 10:26:24 +0100 Subject: did anybody play with python and window mobile broadband? References: <4ba1f067$0$4589$426a74cc@news.free.fr> Message-ID: On 03/18/2010 10:20 AM, News123 wrote: > I'm looking for examples: > - how to connect/disconnect a mobile broadband device (currently I use > rasdial. not sure it's the best solution) > - to obtain the device's current mode (GPRS / EDGE / . . . ) > - to obtain the current signal level > > Thanks a lot for any pointers Well no examples,but most or all of it should work through AT commands. Did you try plugging the mobile broadband interface in? From alfps at start.no Thu Mar 18 05:29:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 18 Mar 2010 10:29:04 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Stefan Behnel: > Alf P. Steinbach, 18.03.2010 09:53: >> >> Path: >> feeder.eternal-september.org!eternal-september.org!feeder.erje.net!newsfeed.straub-nv.de!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!lust.ihug.co.nz!ihug.co.nz!not-for-mail >> >> >> From: Lawrence D'Oliveiro >> Newsgroups: comp.lang.python >> Subject: Re: import antigravity >> Followup-To: comp.lang.python >> Date: Thu, 18 Mar 2010 20:49:55 +1300 >> Organization: Geek Central >> Lines: 7 >> Message-ID: >> References: >> >> NNTP-Posting-Host: 118-92-14-26.dsl.dyn.ihug.co.nz >> Mime-Version: 1.0 >> Content-Type: text/plain; charset="ISO-8859-1" >> Content-Transfer-Encoding: 7Bit >> X-Trace: lust.ihug.co.nz 1268898595 20084 118.92.14.26 (18 Mar 2010 >> 07:49:55 GMT) >> X-Complaints-To: abuse at ihug.co.nz >> NNTP-Posting-Date: Thu, 18 Mar 2010 07:49:55 +0000 (UTC) >> User-Agent: KNode/4.3.4 >> Xref: eternal-september.org comp.lang.python:51777 >> >> >> >> One must assume that you were not aware that you're posting your mail >> address in plaintext in every article? > > Uhm - where? Well, at least the one that Chris Rebert quoted, (in the 'From:' header). The point is, if he's upset about Chris quoting that, then he's probably unaware that he's posting it in plaintext himself. Cheers, - Alf From jpiitula at ling.helsinki.fi Thu Mar 18 05:42:30 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Mar 2010 11:42:30 +0200 Subject: import antigravity References: Message-ID: Alf P. Steinbach writes: > The point is, if he's upset about Chris quoting that, then he's > probably unaware that he's posting it in plaintext himself. The complaint was not about quoting but about using in public. Chris sent his piece to three addresses. From his headers, redacted: Newsgroups: comp.lang.python To: "Lawrence D'Oliveiro" Cc: python-list at python.org Can we stop importing red herrings now? From 2ennel.0569 at gmail.com Thu Mar 18 05:54:16 2010 From: 2ennel.0569 at gmail.com (LALITHA N) Date: Thu, 18 Mar 2010 02:54:16 -0700 (PDT) Subject: ARE YOU ARE FAMILIAR WITH ANY COMPUTER LANGUAGE-GET GOOD LUCK Message-ID: <08d44b50-e96a-464f-9645-ce35b17eb1ab@t9g2000prh.googlegroups.com> http://123maza.com/75/expressions From alfps at start.no Thu Mar 18 06:04:21 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 18 Mar 2010 11:04:21 +0100 Subject: import antigravity In-Reply-To: References: Message-ID: * Jussi Piitulainen: > Alf P. Steinbach writes: > >> The point is, if he's upset about Chris quoting that, then he's >> probably unaware that he's posting it in plaintext himself. > > The complaint was not about quoting but about using in public. Chris > sent his piece to three addresses. From his headers, redacted: > > Newsgroups: comp.lang.python > To: "Lawrence D'Oliveiro" > Cc: python-list at python.org > > Can we stop importing red herrings now? Oh, I didn't see that -- it's Bad Practice so I didn't look for it. Cheers, - Alf From eglyph at gmail.com Thu Mar 18 06:07:22 2010 From: eglyph at gmail.com (eglyph at gmail.com) Date: Thu, 18 Mar 2010 03:07:22 -0700 (PDT) Subject: did anybody play with python and window mobile broadband? References: <4ba1f067$0$4589$426a74cc@news.free.fr> Message-ID: <9fa65dc9-e9fc-4a35-a796-2e56980b63ac@t23g2000yqt.googlegroups.com> On 18 ???, 11:20, News123 wrote: > I'd like to use a mobile broadband device with a windows python app. > Did anybody play already with python and the window mobile broadband > interface? > There was a discussion on this subject in some local forum recently. I assume you're using PythonCE, right? The best solution proposed there was to use ctypes and WinAPI. You can find a relatively high level APIs to set up a connection (without need to go too low level with AT commands) and make your own wrapper. A good starting point can be found here: http://msdn.microsoft.com/en-us/library/bb416346.aspx (it's not the only way to to things, btw). -- regards, eGlyph From eglyph at gmail.com Thu Mar 18 06:19:55 2010 From: eglyph at gmail.com (eglyph at gmail.com) Date: Thu, 18 Mar 2010 03:19:55 -0700 (PDT) Subject: url2lib (windows 7) does not notice when network reconnects (getaddrinfo problem) References: <4ba15c0d$0$15456$426a74cc@news.free.fr> Message-ID: <46a27485-cbe9-48e1-9055-f7d4d0d20785@u9g2000yqb.googlegroups.com> On 18 ???, 00:47, News123 wrote: > Hi, > > I'd like to write a function, that knows when the 'internet' is reachable. > > My setup is a windows7 host with a wireless USB modem. The modem might > connect / disconnect any time. > > I thought I write a small function just checking whether I can fetch a url. > ######### script starts > import time,urllib2 > > myurl = "http://www.mysite.com" # or "www.google.com" or whatever you like > > while True: > ? ? connected = False > ? ? try: > ? ? ? ? urllib2.urlopen(myurl) > ? ? ? ? connected = True > ? ? except urllib2.URLError as e: > ? ? ? ? print "urlerr %s" % e > ? ? print "connected",connected > ? ? time.sleep(1) > ########## end of script > > if the network is connected when I start the script the first time after > reboot, then ?I receive> connected True > > As expected > > If the network is disconnected when I start the script the first time > after reboot, then ?I receive> urlerr > > connected False > > as expected > > Things are getting weired, when my USB wireless modem connects after > I started my script: > > It happens, that I just continue to receive: > > > urlerr > > connected False > > however when I use a windows cmd window and I start > "pingwww.mysite.com", then my python script recovers and reports > > > connected True > > My perhaps false conclusion is, that getaddrinfo() is not retrying to > resolve an IP address, when it failed once. > > Is this behaviour known? Can this really be possible? > I can reproduce this issue. not every time, but rather often. > > If yes, is there any way to force a new host name lookup under windows? > > What else could I be doing wrong? > > Thanks a lot in advance for any ideas > > N Actually this should be expected behavior. Windows establishes connection automatically when you start pinging something, your script doesn't. Just check the connection state with winapi (ctypes? pywin32?) and establish it if it isn't already. -- regards, eGlyph From sparks.m at gmail.com Thu Mar 18 06:21:08 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Thu, 18 Mar 2010 03:21:08 -0700 (PDT) Subject: Nested Scopes unintended behaviour ? References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> Message-ID: <921f09da-bf41-4306-aca5-19baa70dd2b2@e7g2000yqf.googlegroups.com> On Mar 17, 8:29?pm, Terry Reedy wrote: > On 3/17/2010 11:44 AM, Emile van Sebille wrote: > > > On 3/17/2010 8:16 AM Michael Sparks said... > >> Hi, > > >> Is the following behaviour expected ? > > > In short, yes. Assignment within a function forces the variable to > > locals. > > In 3.x, one can declare names to be nonlocal (ie, local to some outer > function, as opposed to local to the current function or module global). > In your case, > ? ?nonlocal on > in your inner swtchfun function would give the behavior you wanted. Ah, excellent. That makes python closures work more like I'd expect them to. (A colleague had written the swtchfun I posted, whereas the generator form was the version I wrote, and he was puzzled as to why it didn't work as he expected. When I saw it I also couldn't see why. After hearing it's expected behaviour in 2.6 it's clear that assigning a name to a value declares the variable to be local, and that unlike much of python (but like yield) this appears based on static analysis of the function declaration, rather than dynamic. This does also make sense since it prevents a name "switching scope" in a function, and a "nonlocal" keyword also makes sense as a result. Thanks to Emile for pointing out you can also do this in 2.6: def Toggler(F, B): print F("Hello") print F("Hello") print F("Hello") print F("Hello") print F("Hello") def Switcher(A,B): enclose={"on" : True} def swtchfun(msg, enclose=enclose): if enclose["on"]: enclose["on"] = False print "Switched to A" return A else: enclose["on"] = True print "Switched to B" return B # return Toggler(swtchfun,True) Switcher(1,2) I think personally I'd use the generator form myself, since I think it's clearer (more clearly loops between the two), but this may be a useful thing to know occasionally. Cheers :-) Michael. From python.list at tim.thechases.com Thu Mar 18 06:25:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Mar 2010 05:25:19 -0500 Subject: os.walk restart In-Reply-To: <68cbed3c-87f6-45c9-ac8e-a536cae20f26@k6g2000prg.googlegroups.com> References: <68cbed3c-87f6-45c9-ac8e-a536cae20f26@k6g2000prg.googlegroups.com> Message-ID: <4BA1FF8F.8080402@tim.thechases.com> Steve Howell wrote: > If that's the case, then you might be able to get away with just > leaving some kind of breadcrumbs whenever you've successfully > processed a directory or a file, Unless you're indexing a read-only device (whether hardware read-only like a CD, or permission-wise read-only like a network share or a non-priv user walking system directories)... > Also, I can understand why the operations on the files themselves > might crash, but can't you catch an exception and keep on chugging? I also wondered this one, perhaps logging the directory in which the exception happened to later revisit. :) -tkc From steve at holdenweb.com Thu Mar 18 07:31:46 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Mar 2010 07:31:46 -0400 Subject: import antigravity In-Reply-To: References: Message-ID: Jussi Piitulainen wrote: > Alf P. Steinbach writes: > >> The point is, if he's upset about Chris quoting that, then he's >> probably unaware that he's posting it in plaintext himself. > > The complaint was not about quoting but about using in public. Chris > sent his piece to three addresses. From his headers, redacted: > > Newsgroups: comp.lang.python > To: "Lawrence D'Oliveiro" > Cc: python-list at python.org > > Can we stop importing red herrings now? Surely the point of such an obvious obfuscation is that humans can de-obfuscate is easily. The fact that it was then used in an open newsgroup communication is just part of the shit that happens every day. Complaining to Chris's ISP is unlikely to be anything other than a waste of time. Drawing attention to it the way Lawrence did is much more likely to draw attention to it that simply gracefully letting it pass. Lawrence, if you are so worried perhaps you should consider not using e-mail any more. It's clearly too dangerous to suit you. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Thu Mar 18 07:52:08 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Mar 2010 11:52:08 GMT Subject: import antigravity References: Message-ID: <4ba213e8$0$27806$c3e8da3@news.astraweb.com> On Thu, 18 Mar 2010 09:17:43 +0100, Stefan Behnel wrote: > Lawrence D'Oliveiro, 18.03.2010 08:49: >> In message, Chris >> Rebert wrote: >> >> I see that you published my unobfuscated e-mail address on USENET for >> all to see. I obfuscated it for a reason, to keep the spammers away. >> I'm assuming this was a momentary lapse of judgement, for which I >> expect an apology. Otherwise, it becomes grounds for an abuse complaint >> to your ISP. > > I hope you just had a bad day. Threatening others for figuring out your > e-mail address is even worse than posting with an illegal e-mail > address. No, this is hardly the first time that Lawrence has made such a wankerific threat: http://www.mail-archive.com/python-list%40python.org/msg245012.html I sympathise, because many years ago I lost an email address, made unusable by spam, after using it unobfuscated in Usenet. But I think that the spammers have mostly moved on these days. The pickings are much richer for hijacking people's address books in Hotmail, Facebook or Outlook, and the state of the art of anti-spam is better too. So I think that Lawrence needs to HTFU and stop making empty threats over something so trivial. -- Steven From robin at reportlab.com Thu Mar 18 08:06:16 2010 From: robin at reportlab.com (Robin Becker) Date: Thu, 18 Mar 2010 12:06:16 +0000 Subject: bug in bdist_wininst cross compile? In-Reply-To: References: <4BA0E958.8050205@chamonix.reportlab.co.uk> Message-ID: <4BA21738.9070307@chamonix.reportlab.co.uk> On 17/03/2010 21:37, Gabriel Genellina wrote: > En Wed, 17 Mar 2010 11:38:16 -0300, Robin Becker > escribi?: > >> has anyone had any success with cross compilation and bdist_wininst; I >> have modified build_ext very slightly to fix a small bug in cross >> compilation related to library order. > > Please post your bug report + patch at http://bugs.python.org or it will > be lost. > OK done -- Robin Becker From królewna at ee.pl Thu Mar 18 08:58:32 2010 From: królewna at ee.pl (=?UTF-8?B?a3LDs2xld25h?=) Date: Thu, 18 Mar 2010 13:58:32 +0100 Subject: sqlite3, memory db and multithreading Message-ID: The problem is simple: I have multiple threads within one program. At least 2 threads have to have access to in-memory sqlite database. It is not possible to pass sqlite objects to those threads because an exception is rised: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id -1219066176 and this is thread id -1224475792 Is there any EASY way to use this in-memory db in many threads? Creating another connection is not a solution as it creates completely new db instead of connecting to the existing one. -- Best regards princess From christian at dowski.com Thu Mar 18 09:40:59 2010 From: christian at dowski.com (Christian) Date: Thu, 18 Mar 2010 06:40:59 -0700 (PDT) Subject: Feeding differeent data types to a class instance? References: <3189fde6-bd5e-4ee2-8a8e-41c55cf9f926@q23g2000yqd.googlegroups.com> Message-ID: <72c18de4-0161-435f-a083-01d69151323a@x1g2000prb.googlegroups.com> On Mar 14, 2:16?pm, kuru wrote: > Hi > > Thank you so much for all these great suggestions. I will have time > today to try all these and see which one works best for me Answers to your question have spread onto the Python blogosphere as well. http://pythonconquerstheuniverse.wordpress.com/2010/03/17/multiple-constructors-in-a-python-class/ http://blog.dowski.com/2010/03/17/my-take-on-multiple-constructors/ That second one is my response. Christian From tundra at tundraware.com Thu Mar 18 09:43:14 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Thu, 18 Mar 2010 08:43:14 -0500 Subject: Win32All On 64-Bit Operating Systems In-Reply-To: References: <3rl777-q1m2.ln1@ozzie.tundraware.com> <4fr777-43o2.ln1@ozzie.tundraware.com> Message-ID: On 3/18/2010 3:54 AM, Tim Golden wrote: > On 17/03/2010 20:43, Tim Daneliuk wrote: >> The intent is just to provide as similar as possible a user experience. >>> From a coding POV, it is surely simpler to just use 'winuser' and >>> 'wingroup', >> but I am sort of philosophically wired to not throw information away if >> it's a available from the OS. > > It's hardly worth disputing I suppose, but I would argue that simply > presenting the owner & group of a file in Windows is actually doing > a disservice to the user of the app. It's cluttering up the display > with information which is essentially useless. Pretty much the only > time I ever look at a file owner is when I have some knotty security > issue and I need to assess who might have WRITE_DAC permission. The > group - never; it really is a relic. > > The file owner & group simply don't play the same role in Windows > security that they do in *nix. The trouble is that there isn't a > simple alternative: most files, even with default security, will > have two or three groups involved in their security at different > levels. > >> BTW, wanna beta test a really cool CLI mass file renaming tool????? ;) > > Sure -- I'll have a look. But I can't promise any great amount of > time at present :) > > TJG > I will announce the Beta for 'tren' here and you (and anyone else) can have at it. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From chris at simplistix.co.uk Thu Mar 18 09:44:53 2010 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 18 Mar 2010 13:44:53 +0000 Subject: converting a timezone-less datetime to seconds since the epoch In-Reply-To: <50697b2c1003160713x7641d2cfn52a5e5ca199e26de@mail.gmail.com> References: <4B9F8BE0.2050808@simplistix.co.uk> <50697b2c1003160713x7641d2cfn52a5e5ca199e26de@mail.gmail.com> Message-ID: <4BA22E55.9040006@simplistix.co.uk> Hey Chris, Chris Rebert wrote: >> def timestamp(dttm): >> return time.mktime(dttm.timetuple()) > > from calendar import timegm > > def timestamp(dttm): > return timegm(dttm.utctimetuple()) > #the *utc*timetuple change is just for extra consistency > #it shouldn't actually make a difference here Ah, right. What on earth is timegm doing in calendar? No way I ever would have thought to look there... I wonder what the best way to get this stuff documented in the datetime modules docs is? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From googler.1.webmaster at spamgourmet.com Thu Mar 18 09:58:00 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Thu, 18 Mar 2010 06:58:00 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> Message-ID: <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> > Funny that you (being the OP) ask *me* what kind of line information *you* > want. > > Stefan Well, I need the line/file information of Python : From 1 at depikt.net Thu Mar 18 10:24:52 2010 From: 1 at depikt.net (DreiJane) Date: Thu, 18 Mar 2010 07:24:52 -0700 (PDT) Subject: Python, Reportlabs, Pil and Windows 7 (64bit) References: <4B992FB5.8090207@v.loewis.de> <4B9A2810.9030602@chamonix.reportlab.co.uk> <4B9A614C.1080105@chamonix.reportlab.co.uk> <4B9A9624.7040200@v.loewis.de> <8aa22e57-f152-4dc7-88da-cf6879de41f7@q16g2000yqq.googlegroups.com> Message-ID: Hello, i've used reportlabs over two years now and was content with its quality. These days i have turned to cairo and can only recommend to do so: It is still easier to use (than the well-designed reportlabs tools) and an engine working in a lot of other software too, for example firefox. Reasons for this: reportlabs do not even answer question about the date to upgrade to Python3. Since Platypus isn't complete, i had to do a lot with the primitves in the canvas object after all - that part of my code got even shorter with cairo. For me - working with pygtk - that spares two installations also. To repear myself: I love cairo. Regards, Joost From alt.mcarter at googlemail.com Thu Mar 18 10:45:54 2010 From: alt.mcarter at googlemail.com (Mark Carter) Date: Thu, 18 Mar 2010 07:45:54 -0700 (PDT) Subject: Install 2.6.4 as non-admin on Windows Message-ID: <60c2ac2f-0472-4790-a879-533845bcedb5@q16g2000yqq.googlegroups.com> How do I install python 2.6.4 on Windows without admin privileges? Can I install it on a machine I control, zip up the contents, copy it across to an admin-restricted machine, and set up a couple of environemtn variables? Does python install files to system directories, making this impossible? From 1 at depikt.net Thu Mar 18 10:49:29 2010 From: 1 at depikt.net (DreiJane) Date: Thu, 18 Mar 2010 07:49:29 -0700 (PDT) Subject: sqlite3, memory db and multithreading References: Message-ID: <57dc1ce8-1ac7-4d72-aafc-6fe7920144c2@c16g2000yqd.googlegroups.com> Hello, i cannot help you directly with sqlite2 in the Standardlib, since i am used to work with Roger Binns's apsw. After a short experiment with pysqlite leading to data loss - caused by one of the unclearer exception messages of sqlite3 and me having a bad day - i at once turned back to apsw. And so far i haven't done much with threads. Principally sqlite connections (sqlite3 objects in the C-API) can be used over multiple threads - and connections to :memory: make no difference. There are additional parameters to open() giving fine- tuned control. And apsw is promising a true reflection of sqlite's C- API. Regards, Joost From eglyph at gmail.com Thu Mar 18 11:23:44 2010 From: eglyph at gmail.com (eglyph at gmail.com) Date: Thu, 18 Mar 2010 08:23:44 -0700 (PDT) Subject: Install 2.6.4 as non-admin on Windows References: <60c2ac2f-0472-4790-a879-533845bcedb5@q16g2000yqq.googlegroups.com> Message-ID: <3ab6c32c-3516-407c-8f89-da666fed86a5@z11g2000yqz.googlegroups.com> On 18 ???, 16:45, Mark Carter wrote: > How do I install python 2.6.4 on Windows without admin privileges? > > Can I install it on a machine I control, zip up the contents, copy it > across to an admin-restricted machine, and set up a couple of > environemtn variables? Does python install files to system > directories, making this impossible? The only file written to a system folder is python2x.dll (I think it's not true for python2.6 any longer), so your approach is perfectly valid if you can put this dll into a folder where it can be found by the system. PortablePython does this almost the same. -- regards, eGlyph From alt.mcarter at googlemail.com Thu Mar 18 11:36:11 2010 From: alt.mcarter at googlemail.com (Mark Carter) Date: Thu, 18 Mar 2010 08:36:11 -0700 (PDT) Subject: Install 2.6.4 as non-admin on Windows References: <60c2ac2f-0472-4790-a879-533845bcedb5@q16g2000yqq.googlegroups.com> <3ab6c32c-3516-407c-8f89-da666fed86a5@z11g2000yqz.googlegroups.com> Message-ID: <99e3568c-0d48-46da-8483-6726b9cc9f58@l25g2000yqd.googlegroups.com> On 18 Mar, 15:23, "egl... at gmail.com" wrote: > The only file written to a system folder is python2x.dll (I think it's > not true for python2.6 any longer), so your approach is perfectly > valid if you can put this dll into a folder where it can be found by > the system. Thanks. That sounds easy enough to do. I guess it's the same deal with win32all. From filip.popravi.stojmenovic at fer.hr Thu Mar 18 12:17:11 2010 From: filip.popravi.stojmenovic at fer.hr (drstoka) Date: Thu, 18 Mar 2010 17:17:11 +0100 Subject: Need to create subprocess... Message-ID: Hello, I have to run a program as a child process inside my python program and redirect it's output through a pipe to a parent program process. So, I wrote this: pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout and it works great. Now, in parent program I need to wait for a some time and if a child (example_program) does not finish in that time, kill the child. How do I do that? Please help. From sccolbert at gmail.com Thu Mar 18 12:28:53 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Mar 2010 12:28:53 -0400 Subject: C++ code generation In-Reply-To: <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> References: <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> Message-ID: <7f014ea61003180928q4763a819ic548364e2811952d@mail.gmail.com> I think Stefan was telling you, in a nice way, to stop spamming every thread about code generation with a plug for your project. 2010/3/17 CHEN Guang > >> ----- Original Message ----- > >> From: "Dan Goodman" > >> > >>> I'm doing some C++ code generation using Python, and would be > interested > >>> in any comments on the approach I'm taking. > >> > >> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not > C++) > > > > It would be nice if you could start reading the posts before you answer, > > and then try to give an answer that fits the question. > > > > Stefan > > I have read the post, may be I lost some words and made you misunderstand. > I meant: > PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not > C++), if you find it useful, > welcome to take a look. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.arnold at sas.com Thu Mar 18 12:38:34 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 18 Mar 2010 12:38:34 -0400 Subject: multiprocessing on freebsd References: Message-ID: "Martin P. Hellwig" wrote in message news:hnrabj$c4v$1 at news.eternal-september.org... > On 03/17/10 13:30, Tim Arnold wrote: >> Hi, >> I'm checking to see if multiprocessing works on freebsd for any >> version of python. My server is about to get upgraded from 6.3 to 8.0 >> and I'd sure like to be able to use multiprocessing. >> >> I think the minimal test would be: >> --------------------- >> import multiprocessing >> q = multiprocessing.Queue() >> --------------------- >> >> with 6.3, I get >> >> File "/usr/local/lib/python2.6/multiprocessing/__init__.py", line >> 212, in Queue >> from multiprocessing.queues import Queue >> File "/usr/local/lib/python2.6/multiprocessing/queues.py", line 22, >> in >> from multiprocessing.synchronize import Lock, BoundedSemaphore, >> Semaphore, Condition >> File "/usr/local/lib/python2.6/multiprocessing/synchronize.py", line >> 33, in >> " function, see issue 3770.") >> ImportError: This platform lacks a functioning sem_open >> implementation, therefore, the required synchronization primitives >> needed will not function, see issue 3770. >> > > Build mine from ports, with the following options (notice SEM & PTH): > [martin at aspire8930 /usr/home/martin]$ cat /var/db/ports/python26/options > # This file is auto-generated by 'make config'. > # No user-servicable parts inside! > # Options for python26-2.6.4 > _OPTIONS_READ=python26-2.6.4 > WITH_THREADS=true > WITHOUT_HUGE_STACK_SIZE=true > WITH_SEM=true > WITH_PTH=true > WITH_UCS4=true > WITH_PYMALLOC=true > WITH_IPV6=true > WITHOUT_FPECTL=true > > [martin at aspire8930 /usr/home/martin]$ uname -a > FreeBSD aspire8930 8.0-STABLE FreeBSD 8.0-STABLE #3: Wed Feb 3 17:01:18 > GMT 2010 martin at aspire8930:/usr/obj/usr/src/sys/ASPIRE8930 amd64 > [martin at aspire8930 /usr/home/martin]$ python > Python 2.6.4 (r264:75706, Mar 17 2010, 18:44:24) > [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. > >>> import multiprocessing as mp > >>> queue = mp.Queue() > >>> > > hth > -- > mph Hi Martin, thanks very much for posting that. All I can say is YAY! I'm really looking forward to my machine's upgrade now! thanks, --Tim From stefan_ml at behnel.de Thu Mar 18 12:43:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Mar 2010 17:43:28 +0100 Subject: C-API PyObject_Call In-Reply-To: <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: moerchendiser2k3, 18.03.2010 14:58: >> Funny that you (being the OP) ask *me* what kind of line information *you* >> want. >> >> Stefan > > Well, I need the line/file information of Python : Then please explain what kind of Python line number you expect to find in C code. Hint: providing details often results in getting helpful answers. Stefan From jjposner at optimum.net Thu Mar 18 12:48:35 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 18 Mar 2010 12:48:35 -0400 Subject: Method / Functions - What are the differences? In-Reply-To: References: <4b8c2a34$0$10470$426a74cc@news.free.fr> <4b8cd310$0$4604$426a34cc@news.free.fr> <4b8e4041$0$17447$426a34cc@news.free.fr> <4b8e9660$0$21812$426a34cc@news.free.fr> <4B8EF717.3070701@optimum.net> <4b902338$0$31260$607ed4bc@cv.net> <4b90f5eb$0$9148$426a74cc@news.free.fr> <4b911ee0$0$4988$607ed4bc@cv.net> <4B97B092.4060901@optimum.net> Message-ID: <4BA25963.1060802@optimum.net> On 3/10/2010 8:37 PM, Gabriel Genellina wrote: > En Wed, 10 Mar 2010 11:45:38 -0300, John Posner > escribi?: > >> As I promised/threatened, here's the *start* of a write-up on >> properties, aimed at non-advanced Python programmers: >> >> http://www.jjposner.net/media/python-properties-0310.pdf > > I'd use 'function' instead of 'procedure', as this last word is very > uncommon in Python literature (also, "the procedure's return value..." may > look very strange to some people). I was trying to avoid the function-vs-method swamp, and so I used "procedure". I agree that it was an unfortunate strategy. In a rewrite, I'm using "function" for the most part > > I'm unsure if one should make a distinction 'storage attribute' vs. > 'method attribute', or even if it makes things actually more clear. Agreed -- I was trying too hard to be helpful, and introduced unnecessary terminology. > ... I > think you could present the motivating idea first ("I want to execute some > code when accessing an attribute") and only later talk about properties That was my intention. I hope it comes across more clearly in the rewrite. > and descriptors (as written, the reader still doesn't know how to define a > simple property and you've already talked about deleting attributes...) That doesn't bother me. It's OK to describe capabilities -- but not give how-to's -- in an overview section. And Edward Cherlin wrote: > I find that it will explain things to those who already understand > most of the concepts. However, I felt as though I were being led > through a maze without knowing where we were headed. ... > Who is your expected audience? I was headed toward having the reader *really* understand the @property decorator. And I was intending that reader to be a non-advanced Python user -- say, at the CS 101 level. I'm now convinced that such a goal was "a bridge too far". It has a lot moving parts, including a prerequisite that is a major topic in itself -- the descriptor protocol. That puts the goal way beyond reach. There's another draft at: http://www.jjposner.net/media/python-properties-0318.pdf Many thanks for your comments, John From martin.hellwig at dcuktec.org Thu Mar 18 13:25:33 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 18 Mar 2010 17:25:33 +0000 Subject: Need to create subprocess... In-Reply-To: References: Message-ID: On 03/18/10 16:17, drstoka wrote: > Hello, > > I have to run a program as a child process inside my python program and > redirect it's output through a pipe to a parent program process. > So, I wrote this: > > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout > > and it works great. > > Now, in parent program I need to wait for a some time and if a child > (example_program) does not finish in that time, kill the child. > > How do I do that? Please help. > > Try searching around for "threading.thread python" it should give you some clues, if you can't work through the info (it can be a bit hard to digest), just post here an example of your test code along with what you expected and what didn't happen. -- mph From pmaupin at gmail.com Thu Mar 18 13:30:01 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 18 Mar 2010 10:30:01 -0700 (PDT) Subject: Need to create subprocess... References: Message-ID: <7f37f154-e3f1-4666-8298-0bf352ebc480@r1g2000yqj.googlegroups.com> On Mar 18, 11:17?am, "drstoka" wrote: > Hello, > > I have to run a program as a child process inside my python program and > redirect it's output through a pipe to a parent program process. > So, I wrote this: > > pipe = Popen('example_program', shell=True, bufsize=0, stdout=PIPE).stdout > > and it works great. > > Now, in parent program I need to wait for a some time and if a child > (example_program) does not finish in that time, kill the child. > > How do I do that? Please help. I have a module that does this and more, but it only works on Linux: http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/execmgr.py For usage examples, you can just execute it. Also, see autotest.py in the same directory. Regards, Pat From jlundell at pobox.com Thu Mar 18 14:01:18 2010 From: jlundell at pobox.com (JLundell) Date: Thu, 18 Mar 2010 11:01:18 -0700 (PDT) Subject: class inheritance References: <3db38a5b-4ede-4a14-954e-f5c9be1008ee@a10g2000pri.googlegroups.com> <9bb4c1e7-858e-4ee6-870b-5a6549b6c496@b36g2000pri.googlegroups.com> <05d0d40f-3fa0-4095-875d-777b49122d12@l12g2000prg.googlegroups.com> Message-ID: <25fb9401-74df-44fd-bc91-796a6b128151@a31g2000prd.googlegroups.com> On Mar 17, 5:12?pm, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 16:34:35 -0700,JLundellwrote: > > It's also unfortunate that Python doesn't have an approximately-equal > > operator; it'd come in handy for floating-point applications while > > preserving hash. If only there were a ~= or ? operator I could overload. > > And ~ is unary, so no joy. > > Not everything needs to be a built-in, or an operator. This might be > useful for you: > > http://code.activestate.com/recipes/577124-approximately-equal/ > > Feedback welcome. > > -- > Steven Thanks, Steven. I'd considered and rejected that a while ago, but on reconsideration it's sounding like a better idea. Aside from preserving the semantics of =, it makes the use of approximate equality explicit in the code, and that's a plus for what I'm doing. I'll give it a shot. From news1234 at free.fr Thu Mar 18 15:29:37 2010 From: news1234 at free.fr (News123) Date: Thu, 18 Mar 2010 20:29:37 +0100 Subject: did anybody play with python and window mobile broadband? In-Reply-To: References: <4ba1f067$0$4589$426a74cc@news.free.fr> Message-ID: <4ba27f21$0$23458$426a74cc@news.free.fr> Hi Sanjiva, Sanjiva P. wrote: > On 03/18/2010 10:20 AM, News123 wrote: >> I'm looking for examples: >> - how to connect/disconnect a mobile broadband device (currently I use >> rasdial. not sure it's the best solution) >> - to obtain the device's current mode (GPRS / EDGE / . . . ) >> - to obtain the current signal level >> >> Thanks a lot for any pointers > > Well no examples,but most or all of it should work through AT commands. Thanks, yes AT commands would be fine. How can I send AT commands, while another application / connection mnager is using the modem? I just don't know how to send AT commands to a connected modem. > > Did you try plugging the mobile broadband interface in? What do you mean with pluggging in? ctypes? or something else? bye N From news1234 at free.fr Thu Mar 18 15:32:23 2010 From: news1234 at free.fr (News123) Date: Thu, 18 Mar 2010 20:32:23 +0100 Subject: did anybody play with python and window mobile broadband? In-Reply-To: <9fa65dc9-e9fc-4a35-a796-2e56980b63ac@t23g2000yqt.googlegroups.com> References: <4ba1f067$0$4589$426a74cc@news.free.fr> <9fa65dc9-e9fc-4a35-a796-2e56980b63ac@t23g2000yqt.googlegroups.com> Message-ID: <4ba27fc7$0$23458$426a74cc@news.free.fr> Hy Eglyph, eglyph at gmail.com wrote: > On 18 ???, 11:20, News123 wrote: >> I'd like to use a mobile broadband device with a windows python app. >> Did anybody play already with python and the window mobile broadband >> interface? >> > > There was a discussion on this subject in some local forum recently. I > assume you're using PythonCE, right? No I'm using C-Python on a small windows PC (Atom) with a USB Boradband modem. Could you forward me the discussion in case you remember the forum? > > The best solution proposed there was to use ctypes and WinAPI. You can > find a relatively high level APIs to set up a connection (without need > to go too low level with AT commands) and make your own wrapper. > > A good starting point can be found here: http://msdn.microsoft.com/en-us/library/bb416346.aspx > (it's not the only way to to things, btw). Thanks, I'll read into it. bye N From wingusr at gmail.com Thu Mar 18 15:36:20 2010 From: wingusr at gmail.com (TP) Date: Thu, 18 Mar 2010 12:36:20 -0700 Subject: highlight words by regex in pdf files using python In-Reply-To: <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> References: <1fc72785-e527-4809-b5a1-43d78fe86f87@r27g2000yqn.googlegroups.com> <366c6f341003170753o36316de3ie13f11fad0b29900@mail.gmail.com> Message-ID: On Wed, Mar 17, 2010 at 7:53 AM, Peng Yu wrote: > On Tue, Mar 16, 2010 at 11:12 PM, Patrick Maupin wrote: >> On Mar 4, 6:57?pm, Peng Yu wrote: >>> I don't find a general pdf library in python that can do any >>> operations on pdfs. >>> >>> I want to automatically highlight certain words (using regex) in a >>> pdf. Could somebody let me know if there is a tool to do so in python? >> >> The problem with PDFs is that they can be quite complicated. ?There is >> the outer container structure, which isn't too bad (unless the >> document author applied encryption or fancy multi-object compression), >> but then inside the graphics elements, things could be stored as >> regular ASCII, or as fancy indexes into font-specific tables. ?Not >> rocket science, but the only industrial-strength solution for this is >> probably reportlab's pagecatcher. >> >> I have a library which works (primarily with the outer container) for >> reading and writing, called pdfrw. ?I also maintain a list of other >> PDF tools at http://code.google.com/p/pdfrw/wiki/OtherLibraries ?It >> may be that pdfminer (link on that page) will do what you want -- it >> is certainly trying to be complete as a PDF reader. ?But I've never >> personally used pdfminer. >> >> One of my pdfrw examples at http://code.google.com/p/pdfrw/wiki/ExampleTools >> will read in preexisting PDFs and write them out to a reportlab >> canvas. ?This works quite well on a few very simple ASCII PDFs, but >> the font handling needs a lot of work and probably won't work at all >> right now on unicode. ?(But if you wanted to improve it, I certainly >> would accept patches or give you commit rights!) >> >> That pdfrw example does graphics reasonably well. ?I was actually >> going down that path for getting better vector graphics into rst2pdf >> (both uniconvertor and svglib were broken for my purposes), but then I >> realized that the PDF spec allows you to include a page from another >> PDF quite easily (the spec calls it a form xObject), so you don't >> actually need to parse down into the graphics stream for that. ?So, >> right now, the best way to do vector graphics with rst2pdf is either >> to give it a preexisting PDF (which it passes off to pdfrw for >> conversion into a form xObject), or to give it a .svg file and invoke >> it with -e inkscape, and then it will use inkscape to convert the svg >> to a pdf and then go through the same path. > > Thank you for your long reply! But I'm not sure if you get my question or not. > > Acrobat can highlight certain words in pdfs. I could add notes to the > highlighted words as well. However, I find that I frequently end up > with highlighting some words that can be expressed by a regular > expression. > > To improve my productivity, I don't want do this manually in Acrobat > but rather do it in an automatic way, if there is such a tool > available. People in reportlab mailing list said this is not possible > with reportlab. And I don't see PyPDF can do this. If you know there > is an API to for this purpose, please let me know. Thank you! > > Regards, > Peng > -- > http://mail.python.org/mailman/listinfo/python-list > Take a look at the Acrobat SDK (http://www.adobe.com/devnet/acrobat/?view=downloads). In particular see the Acrobat Interapplication Communication information at http://www.adobe.com/devnet/acrobat/interapplication_communication.html. "Spell-checking a document" shows how to spell check a PDF using visual basic at http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=IAC_DevApp_OLE_Support.100.17.html "Working with annotations" shows how to add an annotation with visual basic at http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=IAC_DevApp_OLE_Support.100.16.html. Presumably combining the two examples with Python's win32com should allow you to do what you want. From bettylive at gmail.com Thu Mar 18 15:51:47 2010 From: bettylive at gmail.com (=?ISO-8859-1?Q?Bet=FCl?=) Date: Thu, 18 Mar 2010 21:51:47 +0200 Subject: importing python project in my application Message-ID: Hello All, I am new this mail list. I try to embedding python in C++. I want to use this project's class http://gamera.informatik.hsnr.de/ It is a framework in python. I want use Gamera 's classes,functions..etc in my c++ project. I have information about embedding python in c++ but i just want to learn that "how can i import to Gamera into the my c++ project"? Please, help me. it can be more questions after this :) Best Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From magicus23REMOVE-THIS at gmail.com Thu Mar 18 16:44:18 2010 From: magicus23REMOVE-THIS at gmail.com (furlan) Date: Thu, 18 Mar 2010 20:44:18 +0000 (UTC) Subject: question about tkinter References: Message-ID: On Wed, 17 Mar 2010 09:32:46 -0400, robert schaefer wrote: > Peter, > > Most of my life has been dealing with recalcitrant HAL's in one guise or > another. These days, I think HAL has permanently taken up residence in > Toyota's engine and brakes. "Stop the car Dave? Have you changed my oil > or even washed me lately?" Some serious "sneak paths" are going on. Don't know if this will help and I had in a file in my Solutions folder from 2008 the following: If Tkinter does not seem to be loaded run: sudo yum -y install python-tools which will install Tkinter and dependencies. HTH ciao, f -- aa #2301 "I often work by avoidance." -- Brian Eno From sluggoster at gmail.com Thu Mar 18 16:52:00 2010 From: sluggoster at gmail.com (Mike Orr) Date: Thu, 18 Mar 2010 13:52:00 -0700 (PDT) Subject: Need advice on starting a Python group References: Message-ID: On Mar 11, 7:57?am, gb345 wrote: > I'm hoping to get advice from anyone with prior experience setting > up a Python group. > > A friend of mine and I have been trying to start a > scientific-programming-oriented Python group in our school (of > medecine and bio research), with not much success. > > The main problem is attendance. ?Even though a *ton* of people have > told us that it's a great idea, that they're *very* interested, > and have asked to be added to our mailing list, the attendance to > our first few meeting has never been more than 5, including my > friend and I. ?Last time just he and I showed up. > > The second problem is getting content. ?The format we'd envisioned > for this group was centered around code review (though not limited > to it). ?The idea was that at every meeting a different member > would show some code. ?This could be for any of a number of reasons, > such as, for example, 1) illustrate a cool module or technique; 2) > present a scientific research problem and how they used Python to > solve it, or get help solving it; 3) get general feedback (e.g. on > code clarity, software usability, module architecture, etc.). ?But > in principle just about anything is OK: e.g. a talk on favorite > Python resources, or a comparison of Python with some other language, > or an overview of Python gotchas would all be fair game. I've been involved in a Python users group since 2000, and have attended or heard about a few others. The ones that have 20+ attendees have a speaker every month. Our group is usually a show-and-tell and open discussion, so we get around six people each month (but not the same six). We've decided to solicit more talks as a way to increase attendance. I have never heard of a Python group focusing on code review, so I don't know what attendance to expect for that. One problem is that much of people's code is private at their workplace, and they can't bring it to a meeting. I'd suggest expanding the focus a bit: code review, writing unit tests for each other, pair programming, some open "How do I do this in Python?" discussions, etc. You're also limiting the pool of potential attendees by targeting one institution. There are only a subset there who are interested in Python, a smaller subset who can attend meetings, and an even smaller subset who are willing to attend meetings even if they can. A citywide group or at least bringing in other institutions would hopefully increase attendance. Although it may be harder to keep the scientific focus with that. But on the other hand, here the specialized groups are getting more attendance than the general groups are. The local Plone and Django groups get more people than the Python group does. --Mike From mail at hellmutweber.de Thu Mar 18 17:05:37 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Thu, 18 Mar 2010 22:05:37 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: Message-ID: <4BA295A1.70207@hellmutweber.de> Am 11.03.2010 12:14, schrieb Peter Otten: > Hellmut Weber wrote: > >> Logging works very well giving the filename and line number of the point >> where it is called. As long as I use the loggers directly. >> BUT when I have to wrap the logger call in some other function, I always >> get file name and line number of the call of the logger inside the >> wrapping function. >> >> Is there a possibility to get this information in this situation too? > > The official way is probably to write a custom Logger class that overrides > the findCaller() method. > > Below is a hack that monkey-patches the logging._srcfile attribute to ignore > user-specified modules in the call stack: > > $ cat wrapper.py > import logging > import os > import sys > > logger = logging.getLogger() > > class SrcFile(object): > def __init__(self, exclude_files): > self.files = set(exclude_files) > def __eq__(self, other): > return other in self.files > > def fixname(filename): > if filename.lower().endswith((".pyc", ".pyo")): > filename = filename[:-4] + ".py" > return os.path.normcase(filename) > > if "--monkey" in sys.argv: > print "patching" > logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) > > def warn(*args, **kw): > logger.warn(*args, **kw) > > $ cat main.py > import logging > logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") > import wrapper > wrapper.warn("foo") > wrapper.warn("bar") > wrapper.warn("baz") > > $ python main.py > wrapper.py<23>: foo > wrapper.py<23>: bar > wrapper.py<23>: baz > > $ python main.py --monkey > patching > main.py<4>: foo > main.py<5>: bar > main.py<6>: baz > > $ python -V > Python 2.6.4 > > Peter Hi Peter, your hack is exactly what I was looking for. It permits to configure my logging messages as I want, e.g. using different colors for different classes of messages. I do not yet understand all details WHY it is working but suppose some study of the logging module will help me to understand. Thank you very much -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From tjreedy at udel.edu Thu Mar 18 17:13:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Mar 2010 17:13:18 -0400 Subject: Nested Scopes unintended behaviour ? In-Reply-To: <921f09da-bf41-4306-aca5-19baa70dd2b2@e7g2000yqf.googlegroups.com> References: <7a110632-d6c5-446b-a34b-95548fadb2f9@r27g2000yqn.googlegroups.com> <921f09da-bf41-4306-aca5-19baa70dd2b2@e7g2000yqf.googlegroups.com> Message-ID: On 3/18/2010 6:21 AM, Michael Sparks wrote: > After hearing it's expected behaviour in 2.6 it's clear that assigning > a name to a value declares the variable to be local, unless there is a global/nonlocal declaration and that unlike > much of python (but like yield) this appears based on static analysis > of the function declaration, rather than dynamic. The language definition requires two passes after parsing. One collects names and determines their scope (and looks for yield). The second generates code. This allows the local namespace to be implemented as an array rather than a dict, so that local name lookup is an array index operation rather than a dict lookup operation. This is somewhat made visible by the dis module >>> from dis import dis >>> a = 1 >>> def f(): b = 2 return a,b >>> dis(f) 2 0 LOAD_CONST 1 (2) 3 STORE_FAST 0 (b) 3 6 LOAD_GLOBAL 0 (a) 9 LOAD_FAST 0 (b) 12 BUILD_TUPLE 2 15 RETURN_VALUE STORE/LOAD_FAST means store/load_local. Constants (2 in this case) are stored in the same array. There is apparently a separate array of global names, as opposed to local values. Terry Jan Reedy From aahz at pythoncraft.com Thu Mar 18 18:06:00 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Mar 2010 15:06:00 -0700 Subject: sqlite3, memory db and multithreading References: Message-ID: In article , =?UTF-8?B?a3LDs2xld25h?= wrote: > >The problem is simple: I have multiple threads within one program. At >least 2 threads have to have access to in-memory sqlite database. It is >not possible to pass sqlite objects to those threads because an >exception is rised: > >ProgrammingError: SQLite objects created in a thread can only be used in >that same thread.The object was created in thread id -1219066176 and >this is thread id -1224475792 > >Is there any EASY way to use this in-memory db in many threads? Creating >another connection is not a solution as it creates completely new db >instead of connecting to the existing one. You probably need to serialize access to the database through one thread. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From slais-www at ucl.ac.uk Thu Mar 18 18:29:41 2010 From: slais-www at ucl.ac.uk (djc) Date: Thu, 18 Mar 2010 22:29:41 +0000 Subject: should writing Unicode files be so slow Message-ID: I have a simple program to read a text (.csv) file and split it into several smaller files. Tonight I decided to write a unicode variant and was surprised at the difference in performance. Is there a better way? > from __future__ import with_statement > import codecs > > def _rowreader(filename, separator='\t'): > """Generator for iteration over potentially large file.""" > with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as tabfile: > for row in tabfile: > yield [v.strip() for v in row.split(separator)] > > def generator_of_output(source_of_lines): > for line in source_of_lines: > for result in some_function(line): > yield result > > def coroutine(outfile_prefix, outfile_suffix, sep='\t'): > outfile = '%s_%s.txt'% (outfile_prefix, outfile_suffix) > with codecs.open(outfile, 'w', 'utf-8') as out_part: > while True: > line = (yield) > out_part.write(sep.join(line) + '\n') > > def _file_to_files(infile, outfile_prefix, column, sep): > column_values = dict() > for line in _rowreader(infile, sep): > outfile_suffix = line[column].strip('\'\"') > if outfile_suffix in column_values: > column_values[outfile_suffix].send(line) > else: > file_writer = coroutine(outfile_prefix, outfile_suffix, sep) > file_writer.next() > file_writer.send(line) > column_values[outfile_suffix] = file_writer > for file_writer in column_values.itervalues(): > file_writer.close() the plain version is the same except for > with open(filename, 'rU') as tabfile: > with open(outfile, 'wt') as out_part: The difference: > "uid","timestamp","taskid","inputid","value" > "15473178739336026589","2010-02-18T20:50:15+0000","11696870405","73827093507","83523277829" > "15473178739336026589","2010-02-18T20:50:15+0000","11696870405","11800677379","12192844803" > "15473178739336026589","2010-02-18T20:50:15+0000","11696870405","31231839235","52725552133" > > sysweb at Bembo:~/UCLC/bbc/wb2$ wc -l wb.csv > 9293271 wb.csv > > normal version > sysweb at Bembo:~/UCLC$ time ~/UCL/toolkit/file_splitter.py -o tt --separator comma -k 2 wb.csv > > real 0m43.714s > user 0m37.370s > sys 0m2.732s > > unicode version > sysweb at Bembo:~/UCLC$ time ./file_splitter.py -o t --separator comma -k 2 wb.csv > > real 4m8.695s > user 3m19.236s > sys 0m39.262s -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From davea at ieee.org Thu Mar 18 19:13:59 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 18 Mar 2010 18:13:59 -0500 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: <4BA2B3B7.70309@ieee.org> Alf P. Steinbach wrote: > * Dave Angel: >> Stefan Behnel wrote: >>>
MikeLisanke at gmail.com, 17.03.2010 10:08: >>>> Its interesting you've mentioned the hard work involved in this >>>> interface (binding to an EXE instead of a DLL). A year or more ago I >>>> was looking at interfacing IPMITOOL to python. Do to the problems >>>> incurred with swig/python I switched to a running the process through >>>> its command-line interface. I always felt the problems in interfacing >>>> python to an EXE should be worked on (to minimize them), making the >>>> direct use of an EXE API's a routine task. I understand some of the >>>> problems using an EXE (not running all of its startup code but >>>> enough for its proper operation). Have you found this a recurring >>>> question? Thanks. >>> >>> I think the point here is that executable binaries are not supposed >>> to be used as libraries. Libraries are. That's the difference >>> between a DLL and an executable in the first place. To run an >>> executable, execute it. The subprocess module is the tool of choice >>> here. To use a DLL, link against it. >>> >>> Stefan >>> >> There's no real reason parts of an exe cannot be exported, same as a >> dll. They are in fact the same structure. And in fact many other >> files in the Windows environment are also the same structure, from >> fonts to ocx's >> >> Saying they're "not supposed to be used" is like saying that a python >> module should not have an >> >> if __name__ == "__main__": >> >> section. After all, who could want to both run a file, and import >> the same file?? > > A Windows DLL has defined initialization and cleanup per process and > per thread. > > This means that e.g. static variables can be properly initialized when > you load the DLL in order to use its functions (I'm skipping > discussion of subtle problems, but that's the essence). > > A Windows EXE has (only) a single entry point which is for process > startup. It invokes the EXE's behavior-as-a-program. There is no way > to use it to e.g. initialize static variables in order to use exported > functions. > > Hence Mike Lisanke's idea of "not running all of its startup code but > enough for its proper operation" is generally not possible. > > An EXE can be used as a kind of server, /if/ it is designed for that. > In particular it can be a COM server, allowing access of its > functionality from any COM-enabled binding, which for Python would > mean OLE Automation (COM, OLE, Automation: this is Microsoft > technology, we're talking Windows EXEs here). But a Python binding to > EXEs in general can't, as far as I can see, make assumptions about any > particular kind of server being implemented by the EXE. > > > Cheers & hth., > > - Alf > > I'm not talking about COM servers, which run in a separate process. Only about calling functionality that happens to be encoded in an .EXE file. You're trying to generalize what I said. I never said you could call into any .EXE file, just that calling into one is not infeasible. You're describing using an .EXE written using the Microsoft C compiler and/or libraries, not a Windows .EXE in general. In any case, whenever you link to a module written in a different environment, you'll have restrictions. Chief among them is the use of a compatible memory model, the stack conventions, the allocators, and so on.. Solving the thread issue is probably the easiest one to fix. I'm not recommending it, just refuting the "not supposed to" quote above. DaveA From alfps at start.no Thu Mar 18 19:56:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 19 Mar 2010 00:56:35 +0100 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: * Dave Angel: > Alf P. Steinbach wrote: >> * Dave Angel: >>> Stefan Behnel wrote: >>>>
MikeLisanke at gmail.com, 17.03.2010 10:08: >>>>> Its interesting you've mentioned the hard work involved in this >>>>> interface (binding to an EXE instead of a DLL). A year or more ago I >>>>> was looking at interfacing IPMITOOL to python. Do to the problems >>>>> incurred with swig/python I switched to a running the process through >>>>> its command-line interface. I always felt the problems in interfacing >>>>> python to an EXE should be worked on (to minimize them), making the >>>>> direct use of an EXE API's a routine task. I understand some of the >>>>> problems using an EXE (not running all of its startup code but >>>>> enough for its proper operation). Have you found this a recurring >>>>> question? Thanks. >>>> >>>> I think the point here is that executable binaries are not supposed >>>> to be used as libraries. Libraries are. That's the difference >>>> between a DLL and an executable in the first place. To run an >>>> executable, execute it. The subprocess module is the tool of choice >>>> here. To use a DLL, link against it. >>>> >>>> Stefan >>>> >>> There's no real reason parts of an exe cannot be exported, same as a >>> dll. They are in fact the same structure. And in fact many other >>> files in the Windows environment are also the same structure, from >>> fonts to ocx's >>> >>> Saying they're "not supposed to be used" is like saying that a python >>> module should not have an >>> >>> if __name__ == "__main__": >>> >>> section. After all, who could want to both run a file, and import >>> the same file?? >> >> A Windows DLL has defined initialization and cleanup per process and >> per thread. >> >> This means that e.g. static variables can be properly initialized when >> you load the DLL in order to use its functions (I'm skipping >> discussion of subtle problems, but that's the essence). >> >> A Windows EXE has (only) a single entry point which is for process >> startup. It invokes the EXE's behavior-as-a-program. There is no way >> to use it to e.g. initialize static variables in order to use exported >> functions. >> >> Hence Mike Lisanke's idea of "not running all of its startup code but >> enough for its proper operation" is generally not possible. >> >> An EXE can be used as a kind of server, /if/ it is designed for that. >> In particular it can be a COM server, allowing access of its >> functionality from any COM-enabled binding, which for Python would >> mean OLE Automation (COM, OLE, Automation: this is Microsoft >> technology, we're talking Windows EXEs here). But a Python binding to >> EXEs in general can't, as far as I can see, make assumptions about any >> particular kind of server being implemented by the EXE. >> > I'm not talking about COM servers, which run in a separate process. > Only about calling functionality that happens to be encoded in an .EXE > file. > > You're trying to generalize what I said. I never said you could call > into any .EXE file, just that calling into one is not infeasible. Well, true. And I'm sorry if my reply sounded as a misrepresentation. I haven't tried this calling-a-function-in-an-exe (since 16-bit Windows, that is!, but that was very different), but I can imagine two such cases: (1) a function f is exported by the EXE, and f doesn't depend on anything but its arguments and does not use any static storage, or (2) a DLL loaded by the EXE calls back into the EXE, which could work because then everything's initialized (however, there are better ways). But these are very special cases where one really has to know what one is doing. As Gabriel Genellina wrote up-thread, "you *could* do that if you work hard enough, but that's not how things are usually done". That said, in Windows the least uncommon reason to load an EXE as a DLL is, IME, to access resource data in the EXE. Tip for that: the module handle, casted to appropriate pointer type, points to the start of the loaded image (great for accessing e.g. version info resource). I think this is still undocumented... > You're describing using an .EXE written using the Microsoft C compiler > and/or libraries, not a Windows .EXE in general. In any case, whenever > you link to a module written in a different environment, you'll have > restrictions. Chief among them is the use of a compatible memory model, > the stack conventions, the allocators, and so on.. Solving the thread > issue is probably the easiest one to fix. > > I'm not recommending it, just refuting the "not supposed to" quote above. Again, I'm sorry if my reply sounded as a misrepresentation. I just tried to make the solution-constraining technical facts available, addressing Mike's "making the direct use of an EXE API's a routine task". I think we're all in (violent?) agreement on this. :-) Cheers, - Alf From clockworksaint at gmail.com Thu Mar 18 20:13:32 2010 From: clockworksaint at gmail.com (Weeble) Date: Thu, 18 Mar 2010 17:13:32 -0700 (PDT) Subject: GC is very expensive: am I doing something wrong? Message-ID: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> I am loading a dictionary from a text file and constructing a trie data structure in memory. However, it takes longer than I'm happy with - about 12 seconds on my computer. I profiled it, came up with some clever ideas to cut down on the work (such as by exploiting the fact that the dictionary is sorted) and was only able to shave a small fraction of the time off. However, then I tried calling gc.disable() before loading the trie and it halved the running time! I was surprised. Is that normal? I thought that the cost of garbage collection would be in some way proportional to the amount of garbage created, but I didn't think I was creating any: as far as I can tell the only objects deallocated during the load are strings, which could not be participating in cycles. I have spent a lot of time in C#, where the standard advice is not to mess about with the garbage collector because you'll probably just make things worse. Does that advice apply in Python? Is it a bad idea to call gc.disable() before loading the trie and then enable it again afterwards? Does the fact that the garbage collector is taking so much time indicate I'm doing something particularly bad here? Is there some way to give the garbage collector a hint that the whole trie is going to be long-lived and get it promoted straight to generation 2 rather than scanning it over and over? $ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> $ time python -c "import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m12.523s user 0m12.380s sys 0m0.140s $ time python -c "import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m12.592s user 0m12.480s sys 0m0.110s $ time python -c "import gc;gc.disable();import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m6.176s user 0m5.980s sys 0m0.190s $ time python -c "import gc;gc.disable();import trie;t=trie.Trie();t.load(open('sowpods.txt'))" real 0m6.331s user 0m5.530s sys 0m0.170s === trie.py === class Trie(object): __slots__=("root", "active") def __init__(self): self.root=[] self.active=False def insert(self, word): if len(word) == 0: self.active=True else: head = word[0] for ch, child in reversed(self.root): if ch == head: child.insert(word[1:]) return child = Trie() self.root.append((head, child)) child.insert(word[1:]) def seek(self, word): if len(word) == 0: return self head = word[0] for ch, child in self.root: if ch == head: return child.seek(word[1:]) return EMPTY_TRIE def load(self, file): for line in file: self.insert(line.strip().lower()) def empty(self): return (not self.root) and not self.active def endings(self, prefix=""): if self.active: yield prefix for ch, child in self.root: for ending in child.endings(prefix+ch): yield ending EMPTY_TRIE = Trie() From contact at xavierho.com Thu Mar 18 20:24:22 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 19 Mar 2010 10:24:22 +1000 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: <2d56febf1003181724t377741eem900a456d73b58cac@mail.gmail.com> Weeble, Try to use the full arguments of insert(i, x), instead of using list slices. Every time you create a slice, Python copies the list into a new memory location with the sliced copy. That's probably a big performance impact there if done recursively. My 2cp, Xav On Fri, Mar 19, 2010 at 10:13 AM, Weeble wrote: > I am loading a dictionary from a text file and constructing a trie > data structure in memory. However, it takes longer than I'm happy with > - about 12 seconds on my computer. I profiled it, came up with some > clever ideas to cut down on the work (such as by exploiting the fact > that the dictionary is sorted) and was only able to shave a small > fraction of the time off. However, then I tried calling gc.disable() > before loading the trie and it halved the running time! I was > surprised. Is that normal? I thought that the cost of garbage > collection would be in some way proportional to the amount of garbage > created, but I didn't think I was creating any: as far as I can tell > the only objects deallocated during the load are strings, which could > not be participating in cycles. > > I have spent a lot of time in C#, where the standard advice is not to > mess about with the garbage collector because you'll probably just > make things worse. Does that advice apply in Python? Is it a bad idea > to call gc.disable() before loading the trie and then enable it again > afterwards? Does the fact that the garbage collector is taking so much > time indicate I'm doing something particularly bad here? Is there some > way to give the garbage collector a hint that the whole trie is going > to be long-lived and get it promoted straight to generation 2 rather > than scanning it over and over? > > $ python > Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55) > [GCC 4.4.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> > $ time python -c "import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m12.523s > user 0m12.380s > sys 0m0.140s > $ time python -c "import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m12.592s > user 0m12.480s > sys 0m0.110s > $ time python -c "import gc;gc.disable();import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m6.176s > user 0m5.980s > sys 0m0.190s > $ time python -c "import gc;gc.disable();import > trie;t=trie.Trie();t.load(open('sowpods.txt'))" > > real 0m6.331s > user 0m5.530s > sys 0m0.170s > > > === trie.py === > > class Trie(object): > __slots__=("root", "active") > def __init__(self): > self.root=[] > self.active=False > def insert(self, word): > if len(word) == 0: > self.active=True > else: > head = word[0] > for ch, child in reversed(self.root): > if ch == head: > child.insert(word[1:]) > return > child = Trie() > self.root.append((head, child)) > child.insert(word[1:]) > def seek(self, word): > if len(word) == 0: > return self > head = word[0] > for ch, child in self.root: > if ch == head: > return child.seek(word[1:]) > return EMPTY_TRIE > def load(self, file): > for line in file: > self.insert(line.strip().lower()) > def empty(self): > return (not self.root) and not self.active > def endings(self, prefix=""): > if self.active: > yield prefix > for ch, child in self.root: > for ending in child.endings(prefix+ch): > yield ending > > EMPTY_TRIE = Trie() > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Mar 18 20:33:40 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Mar 2010 20:33:40 -0400 Subject: GC is very expensive: am I doing something wrong? In-Reply-To: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: On 3/18/2010 8:13 PM, Weeble wrote: > I thought that the cost of garbage > collection would be in some way proportional to the amount of garbage > created, but I didn't think I was creating any: as far as I can tell > the only objects deallocated during the load are strings, which could > not be participating in cycles. > > I have spent a lot of time in C#, where the standard advice is not to > mess about with the garbage collector because you'll probably just > make things worse. Does that advice apply in Python? Is it a bad idea > to call gc.disable() before loading the trie and then enable it again > afterwards? I believe not. It is known that certain patterns of object creation and destruction can lead to bad gc behavior. No one has discovered a setting of the internal tuning parameters for which there are no bad patterns and I suspect there are not any such. This does not negate Xavier's suggestion that a code change might also solve your problem. tjr From brandonc530 at gmail.com Thu Mar 18 21:00:47 2010 From: brandonc530 at gmail.com (Brandon Conner) Date: Thu, 18 Mar 2010 20:00:47 -0500 Subject: Truoble With A Search Script for ImageBin.org Message-ID: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> Hey Pythoners, its my first post here, yay! I'm trying to develop a script that will return the results of a POST request that should list all images uploaded by a user. However, when i run the script, i get returned the HTML of the page with the search form. I am wondering what am i doing incorrectly? Is it something I'm doing or is the imagebin server rejecting my request? here's the code: import urllib import urllib2 url = 'http://imagebin.org/index.php?page=search' values = {'search_for' : 'blah', 'field' : 'Nickname'} data = urllib.urlencode(values) request = urllib2.Request(url, data) response = urllib2.urlopen(request) page = response.read() print page tks, pythons great -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Thu Mar 18 21:49:56 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Mar 2010 12:49:56 +1100 Subject: should writing Unicode files be so slow References: Message-ID: <8739zxw057.fsf@benfinney.id.au> djc writes: > I have a simple program to read a text (.csv) file Could you please: * simplify it further: make a minimal version that demonstrates the difference you're seeing, without any extraneous stuff that doesn't appear to affect the result. * make it complete: the code you've shown doesn't do anything except define some functions. In other words: please reduce it to a complete, minimal example that we can run to see the same behaviour you're seeing. -- \ ?If we ruin the Earth, there is no place else to go. This is | `\ not a disposable world, and we are not yet able to re-engineer | _o__) other planets.? ?Carl Sagan, _Cosmos_, 1980 | Ben Finney From clp2 at rebertia.com Thu Mar 18 22:07:05 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Mar 2010 19:07:05 -0700 Subject: import antigravity In-Reply-To: References: Message-ID: <50697b2c1003181907x515d29bdsad5208b59420a472@mail.gmail.com> On Thu, Mar 18, 2010 at 12:49 AM, Lawrence D'Oliveiro wrote: > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. My apologies to you then. In my own defense, I will say this is the first complaint I can recall getting about unmungeing the "To:" header when replying to someone on python-list. To ensure your address's privacy in the future, either using a disposable address or putting a /completely/ invalid and unrelated address in the "To:" header are some possible options. Regards, Chris -- This is one of the pitfalls of mail-news gateways I suppose. From steve at holdenweb.com Thu Mar 18 22:43:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Mar 2010 22:43:38 -0400 Subject: Truoble With A Search Script for ImageBin.org In-Reply-To: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> References: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> Message-ID: Brandon Conner wrote: > Hey Pythoners, > > its my first post here, yay! > > I'm trying to develop a script that will return the results of a POST > request that should list all images uploaded by a user. However, when i > run the script, i get returned the HTML of the page with the search > form. I am wondering what am i doing incorrectly? Is it something I'm > doing or is the imagebin server rejecting my request? > > here's the code: > > import urllib > import urllib2 > url = 'http://imagebin.org/index.php?page=search' > values = {'search_for' : 'blah', 'field' : 'Nickname'} > data = urllib.urlencode(values) > request = urllib2.Request(url, data) > response = urllib2.urlopen(request) > page = response.read() > print page > > tks, pythons great > You need to tell the browser (in an HTTP header) that what you are sending is HTML. Try putting print "Content-Type: text/html\n" at the start of your script. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From john at castleamber.com Thu Mar 18 22:50:51 2010 From: john at castleamber.com (John Bokma) Date: Thu, 18 Mar 2010 20:50:51 -0600 Subject: import antigravity References: Message-ID: <87iq8tc9dg.fsf@castleamber.com> Lawrence D'Oliveiro writes: > In message , Chris > Rebert wrote: > > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an abuse complaint to your ISP. Ha ha ha! Get a life. You're using a non-existant tld. I recommend to use .invalid instead, e.g. ldo at geek-central.gen.nz.invalid And Chris can make sure that his unobfuscating code doesn't run if the tld is invalid. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From cs at zip.com.au Thu Mar 18 22:57:19 2010 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 19 Mar 2010 13:57:19 +1100 Subject: Truoble With A Search Script for ImageBin.org In-Reply-To: References: Message-ID: <20100319025719.GA20465@cskk.homeip.net> On 18Mar2010 22:43, Steve Holden wrote: | Brandon Conner wrote: | > I'm trying to develop a script that will return the results of a POST | > request that should list all images uploaded by a user. However, when i | > run the script, i get returned the HTML of the page with the search | > form. I am wondering what am i doing incorrectly? Is it something I'm | > doing or is the imagebin server rejecting my request? | > | > here's the code: | > | > import urllib | > import urllib2 | > url = 'http://imagebin.org/index.php?page=search' | > values = {'search_for' : 'blah', 'field' : 'Nickname'} | > data = urllib.urlencode(values) | > request = urllib2.Request(url, data) | > response = urllib2.urlopen(request) | > page = response.read() | > print page | > | > tks, pythons great | > | You need to tell the browser (in an HTTP header) that what you are | sending is HTML. Try putting | | print "Content-Type: text/html\n" | | at the start of your script. I think it may need to be "application/x-www-form-urlencoded", not text/html. But otherwise, yes, missing Content-Type. And the request method needs to be POST; I expect the code above will be using GET unless told not to. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ There's no trick to being a humorist when you have the whole government working for you. - Will Rogers From rowland at river2sea.org Thu Mar 18 23:25:48 2010 From: rowland at river2sea.org (Rowland Smith) Date: Thu, 18 Mar 2010 23:25:48 -0400 Subject: example of ssl with SimpleXMLRPCServer in 2.6? Message-ID: <2010031823254816807-rowland@river2seaorg> Anyone have an example of using the new ssl module with SimpleXMLRPCServer in 2.6? Thanks, -- -Rowland From timr at probo.com Fri Mar 19 00:13:25 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Mar 2010 21:13:25 -0700 Subject: Python bindings tutorial References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: Dave Angel wrote: >> >There's no real reason parts of an exe cannot be exported, same as a >dll. They are in fact the same structure. And in fact many other files >in the Windows environment are also the same structure, from fonts to ocx's Well, there IS a fundamental difference. EXEs and DLLs and the like do all have the same format. They all have a "transfer address", where execution begins. That's the key problem. With a DLL, the transfer address goes to a DllMain, where certain DLL initialization is done, preparing the other entry points for use. With an EXE, the transfer address goes to "main". So, when you load an EXE as a DLL, you will be RUNNING the program. That's is usually not what you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nagle at animats.com Fri Mar 19 00:33:52 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Mar 2010 21:33:52 -0700 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: <4ba2fa0d$0$1598$742ec2ed@news.sonic.net> kr?lewna wrote: > The problem is simple: I have multiple threads within one program. At > least 2 threads have to have access to in-memory sqlite database. It is > not possible to pass sqlite objects to those threads because an > exception is rised: > > ProgrammingError: SQLite objects created in a thread can only be used in > that same thread.The object was created in thread id -1219066176 and > this is thread id -1224475792 > > Is there any EASY way to use this in-memory db in many threads? Creating > another connection is not a solution as it creates completely new db > instead of connecting to the existing one. Recognize that sqlite is for "lite" database work. If you're running some massively concurrent database application, you need something heavier, like MySQL or Postgres. "sqlite" has a simplistic locking strategy. Locking is done by file-level locking, and you can have one UPDATE/INSERT operations, or any numnber of SELECTs, at a time. Lock conflicts are handled by wait and retry, which is slow. The big databases are much smarter about figuring out which operations can safely be done in parallel, do much more query optimization, and handle high transaction volumes much better than sqlite. You use sqlite for configuration files, your personal databases, and other small stuff. You run your Web 2.0 site on MySQL or Postgres. You run your Fortune 1000 company on Oracle. John Nagle From pmaupin at gmail.com Fri Mar 19 00:44:19 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Thu, 18 Mar 2010 21:44:19 -0700 (PDT) Subject: GC is very expensive: am I doing something wrong? References: <9b25b816-20d9-410b-b881-ff51efa51a04@f8g2000yqn.googlegroups.com> Message-ID: <7a3a0709-2325-45a3-9cb5-381a7a1ff31f@t41g2000yqt.googlegroups.com> On Mar 18, 7:13?pm, Weeble wrote: > I am loading a dictionary from a text file and constructing a trie > data structure in memory. However, it takes longer than I'm happy with > - about 12 seconds on my computer. I profiled it, came up with some > clever ideas to cut down on the work (such as by exploiting the fact > that the dictionary is sorted) and was only able to shave a small > fraction of the time off. However, then I tried calling gc.disable() > before loading the trie and it halved the running time! I was > surprised. Is that normal? I thought that the cost of garbage > collection would be in some way proportional to the amount of garbage > created, but I didn't think I was creating any: as far as I can tell > the only objects deallocated during the load are strings, which could > not be participating in cycles. Well, you are creating and destroying a lot of objects in the process, so that will provoke the garbage collector. But you are also doing reversing and searching, and that's slow. Does your application really need to be able to keep things in order like this, or do you just want to know if a word is in the dictionary? If you just want to load up a dictionary and be able to see if words are in it, I would use a dict instead of a list. Even if you want to be able to print out the data in order, you might consider using a dict instead of a list. The print operation could use one sort at the end, instead of searching all the nodes on insertion. You could also use a character that doesn't appear in your data as a sentinel, and then you don't need a separate active indicator -- every leaf node will be empty and be referred to by the sentinel character. You are also doing a lot of recursive operations that could be done without recursing. Finally, do you really need to keep an additional object around for each node in the tree? I have modified your trie code to use a dict and a sentinel, while keeping basically the same API. This may or may not be the best way to do this, depending on your other code which uses this data structure. It could also probably be made faster by removing the setdefault, and not re-building objects when you need them, and even this implementation will load faster if you disable the gc, but in any case, this might give you some ideas about how to make your code go faster. Regards, Pat from collections import defaultdict class TrieTop(object): sentinel = ' ' # Something not in the data def __init__(self, data=None): def defaultrecurse(): return defaultdict(defaultrecurse) if data is None: data = defaultrecurse() self.data = data def insert(self, word): data = self.data for ch in word: data = data[ch] data[self.sentinel] def seek(self, word): data = self.data for ch in word: data = data.get(ch) if data is None: return EMPTY_TRIE return TrieTop(data) def load(self, file): for line in file: self.insert(line.strip().lower()) def empty(self): return (not self.data) def endings(self, prefix=""): def recurse(data, prefix): if not data: yield prefix[:-1] return for ch, data in data.iteritems(): for result in recurse(data, prefix + ch): yield result return sorted(recurse(self.data, prefix)) EMPTY_TRIE = TrieTop() From anand.ibmgsi at gmail.com Fri Mar 19 02:03:21 2010 From: anand.ibmgsi at gmail.com (anand jeyahar) Date: Fri, 19 Mar 2010 11:33:21 +0530 Subject: Bug in Python APscheduler module. Message-ID: <1a3a139e1003182303j218f3dc8x32896e2fe2119c5f@mail.gmail.com> Hi , I looked everywhere and could find no mention of this(might be looking in the wrong places point me please..). the Python package Advanced python scheduler seems to have a bug with the unschedule func. When passing the function of an object it doesn't remove it from the scheduler. but works fine with a normal function. Please find my test script attached and guide me... from apscheduler.scheduler import Scheduler def test_func(): print "test func" class test_class(): def test_class1(self): print "test class" def main(): sched=Scheduler() sched.start() tc=test_class() tc.test_class1() print sched.add_interval_job(test_func,minutes=1) print sched.add_interval_job(tc.test_class1,minutes=1) print sched.add_interval_job(test_func,seconds=20) print "jobs b4 unschedule" print sched.jobs # sched.unschedule_func(test_func) sched.unschedule_func(tc.test_class1) print "jobs after unschedule" print sched.jobs sched.shutdown() if __name__=='__main__': main() ~ ~ ~ ~ ============================================== Anand J http://sites.google.com/a/cbcs.ac.in/students/anand ============================================== The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee Love is a trade with lousy accounting policies. ~Aang Jie -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Mar 19 02:51:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 02:51:20 -0400 Subject: Bug in Python APscheduler module. In-Reply-To: <1a3a139e1003182303j218f3dc8x32896e2fe2119c5f@mail.gmail.com> References: <1a3a139e1003182303j218f3dc8x32896e2fe2119c5f@mail.gmail.com> Message-ID: On 3/19/2010 2:03 AM, anand jeyahar wrote: > Hi , > I looked everywhere and could find no mention of this(might be > looking in the wrong places point me please..). the Python package > Advanced python scheduler seems to have a bug with the unschedule func. The site for that package http://apscheduler.nextday.fi/ has links for Getting Help and Reporting Bugs. From alfps at start.no Fri Mar 19 03:01:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 19 Mar 2010 08:01:46 +0100 Subject: Python bindings tutorial In-Reply-To: References: <31a7ecc9-067d-44ce-8af9-adcc30bb3cfd@o30g2000yqb.googlegroups.com> <98447f7e-64db-4a10-b19e-685f5b079cf6@l25g2000yqd.googlegroups.com> Message-ID: * Tim Roberts: > Dave Angel wrote: >> There's no real reason parts of an exe cannot be exported, same as a >> dll. They are in fact the same structure. And in fact many other files >> in the Windows environment are also the same structure, from fonts to ocx's This is a bit off-topic, but your explanation is incorrect in some key respects, so (no offense) to avoid readers getting an incorrect impression: > Well, there IS a fundamental difference. EXEs and DLLs and the like do all > have the same format. They all have a "transfer address" Commonly called an "entry point". This is the term you need to know about when e.g. linking object files. >, where execution > begins. That's the key problem. With a DLL, the transfer address goes to > a DllMain, where certain DLL initialization is done, preparing the other > entry points for use. Right, modulo terminology: there's only one "entry point" in a PE format file. > With an EXE, the transfer address goes to "main". Sorry, no, the EXE entry point goes to a routine of no arguments. Typically, in C and C++ that's a run time library routine (e.g. with Microsoft's run time library mainCRTStartup or one of its cousins) which in turn calls the C/C++ "main", while in Pascal it runs the main program, so on. Note that the EXE entry point is probably still incorrectly documented as requiring WinMain signature -- it's the most infamous Microsoft documentation screw-up. > So, when you load an EXE as a DLL, you will be RUNNING the program. Sorry, no, that's not what happens. The Windows API LoadLibrary(Ex) knows the difference between an EXE and a DLL. It's documented as handling both sub-formats, and it does. > That's is usually not what you want. If that had happened then it would be a problem, yes. Happily it doesn't happen. I've discussed the real problems else-thread. Cheers & hth., - Alf From daniele.esposti at gmail.com Fri Mar 19 03:20:32 2010 From: daniele.esposti at gmail.com (Expo) Date: Fri, 19 Mar 2010 00:20:32 -0700 (PDT) Subject: sqlite3, memory db and multithreading References: Message-ID: <155a70fb-0e4e-43a8-8e4c-0f4475573035@t20g2000yqe.googlegroups.com> On Mar 18, 1:58?pm, kr?lewna wrote: > The problem is simple: I have multiple threads within one program. At > least 2 threads have to have access to in-memory sqlite database. It is > not possible to pass sqlite objects to those threads because an > exception is rised: > > ProgrammingError: SQLite objects created in a thread can only be used in > that same thread.The object was created in thread id -1219066176 and > this is thread id -1224475792 > > Is there any EASY way to use this in-memory db in many threads? Creating > another connection is not a solution as it creates completely new db > instead of connecting to the existing one. > You can put the SQLite database into a Singleton class and use a semaphore to serialize the access to methods which writes to the database. From dr.cg at 126.com Fri Mar 19 03:49:28 2010 From: dr.cg at 126.com (CHEN Guang) Date: Fri, 19 Mar 2010 15:49:28 +0800 (CST) Subject: C++ code generation In-Reply-To: <7f014ea61003180928q4763a819ic548364e2811952d@mail.gmail.com> References: <7f014ea61003180928q4763a819ic548364e2811952d@mail.gmail.com> <24b7e9.8952.1276b803126.Coremail.dr.cg@126.com> Message-ID: <90858a.6e02.1277565f46c.Coremail.dr.cg@126.com> Plug? Any evidence to say that? As long as this thread concerned, is there any answer more closed to the topic "C++ code generation" than mine? I think Stefan was telling you, in a nice way, to stop spamming every thread about code generation with a plug for your project. 2010/3/17 CHEN Guang >> ----- Original Message ----- >> From: "Dan Goodman" >> >>> I'm doing some C++ code generation using Python, and would be interested >>> in any comments on the approach I'm taking. >> >> PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) > > It would be nice if you could start reading the posts before you answer, > and then try to give an answer that fits the question. > > Stefan I have read the post, may be I lost some words and made you misunderstand. I meant: PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not C++), if you find it useful, welcome to take a look. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Mar 19 03:56:46 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Mar 2010 08:56:46 +0100 Subject: logging: local functions ==> loss of lineno References: Message-ID: Hellmut Weber wrote: > your hack is exactly what I was looking for. > It permits to configure my logging messages as I want, e.g. using > different colors for different classes of messages. > > I do not yet understand all details WHY it is working but suppose some > study of the logging module will help me to understand. Have a look at Logger.findCaller() in logging/__init__.py. To find the calling function it does something like for frame in walk_callstack(): if filename_of(frame) == _srcfile: continue return filename_lineno_and_functionname_of(frame) The _srcfile is normally logging/__init__.py, and it is skipped because a user typically is interested only in what happens outside the logging package. My hack under the hood changes filename_of(frame) == _srcfile from a string comparison to a filename_of(frame) in set_of_files containment test (see SrcFile.__eq__() posted above). Peter From nbvfour at gmail.com Fri Mar 19 04:05:03 2010 From: nbvfour at gmail.com (nbv4) Date: Fri, 19 Mar 2010 01:05:03 -0700 (PDT) Subject: installing something to a virtualenv when it's already in site-packages Message-ID: I have ipython installed via apt. I can go to the command line and type 'ipython' and it will work. If I try to install ipython to a virtualenv, I get this: $ pip install -E env/ ipython Requirement already satisfied: ipython in /usr/share/pyshared Installing collected packages: ipython Successfully installed ipython I want ipython in both site-packages as well as in my virtualenv. This is bad because when I activate the virtualenv, site-packages disappears and ipython is not available. A work around is to uninstall ipython from apt, install to the virtualenv, then reinstall in apt. Is there a better way? From darkrho at gmail.com Fri Mar 19 04:26:56 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 19 Mar 2010 04:26:56 -0400 Subject: installing something to a virtualenv when it's already in site-packages In-Reply-To: References: Message-ID: <4eca3f41003190126mc625306m59608d638253d91c@mail.gmail.com> On Fri, Mar 19, 2010 at 4:05 AM, nbv4 wrote: > I have ipython installed via apt. I can go to the command line and > type 'ipython' and it will work. If I try to install ipython to a > virtualenv, I get this: > > $ pip install -E env/ ipython > Requirement already satisfied: ipython in /usr/share/pyshared > Installing collected packages: ipython > Successfully installed ipython > > I want ipython in both site-packages as well as in my virtualenv. This > is bad because when I activate the virtualenv, site-packages > disappears and ipython is not available. A work around is to uninstall > ipython from apt, install to the virtualenv, then reinstall in apt. Is > there a better way? I use -U (--upgrade) to force the installation within virtualenv. e.g: $ pip install -E env/ -U ipython Regards, Rolando From pankaj.kr at gmail.com Fri Mar 19 05:03:54 2010 From: pankaj.kr at gmail.com (Pankaj) Date: Fri, 19 Mar 2010 02:03:54 -0700 (PDT) Subject: exp_continue Message-ID: <1669b997-c4bf-43fc-a2e0-3d5c99cb0524@v34g2000prm.googlegroups.com> I am using pexpect module in python I would like to know how I can use exp_continue here. what is the alternative of exp_continue of perl/tcl in pexpect. From nilly16 at yahoo.com Fri Mar 19 05:37:35 2010 From: nilly16 at yahoo.com (Jimbo) Date: Fri, 19 Mar 2010 02:37:35 -0700 (PDT) Subject: Why this compile error? Message-ID: Hello Can you help me figure out why I am getting this compile error with my program. The error occurs right at the bottom of my code & I have commented where it occurs. The error is: [QUOTE]Expected an indented block[/QUOTE] [CODE]""" *Stock Data Builder* Algorithm: - Search website for stock - Get website HTML source code - Search code for target stock data(price,dividends) - Add data to text file """ import sys # Functions def getSource(URL, sourceBuffer): """ Retrieve HTML source code from websitr URL & save in sourceBuffer """ return sourceBuffer def getData(targetData, dataBuffer): """ Searches the string dataBuffer for the occurence of target data & returns that whole line """ def writeToFile(textFile, dataBuffer): """ Writes data in string dataBuffer to text file """ # CHANGE this to try except to catch errors fileT = open(textFile,'a') fileT.write(dataBuffer) return True; # function succeeded def writeToFile(textFile, dataList): """ Writes data in List dataList to text file """ # CHANGE this to try except to catch errors fileT = open(textFile,'a') for element in dataList: fileT.write(element) return True; # function succeeded # Main program loop def main(): programEnd = False; while (programEnd == False): #ERROR HERE?? - Error="Expected an indented block" main()[/CODE] From bruno.42.desthuilliers at websiteburo.invalid Fri Mar 19 06:04:11 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Mar 2010 11:04:11 +0100 Subject: Why this compile error? In-Reply-To: References: Message-ID: <4ba34c10$0$29759$426a74cc@news.free.fr> Jimbo a ?crit : > Hello > > Can you help me figure out why I am getting this compile error with my > program. The error occurs right at the bottom of my code & I have > commented where it occurs. > > The error is: > [QUOTE]Expected an indented block[/QUOTE] > > [CODE] (snip) > # Main program loop > def main(): > programEnd = False; > > while (programEnd == False): > #ERROR HERE?? - Error="Expected an indented block" Indeed. You *need* a stamement in the while block. If you want a noop, then use the 'pass' statement: while programEnd == False: pass But note that as-is, this will go into an infinite loop. From eckhardt at satorlaser.com Fri Mar 19 06:11:18 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Fri, 19 Mar 2010 11:11:18 +0100 Subject: Why this compile error? References: Message-ID: <67vb77-sb6.ln1@satorlaser.homedns.org> Jimbo wrote: > Can you help me figure out why I am getting this compile error with my > program. The error occurs right at the bottom of my code & I have > commented where it occurs. [...] > def main(): > programEnd = False; > > while (programEnd == False): > #ERROR HERE?? - Error="Expected an indented block" > main()[/CODE] Was the comment there before or not? In any case, I believe a comment doesn't qualify as indented block, if you want to leave the block empty use 'pass' instead. Also, make sure you don't mix tabs and spaces, which is also a popular way to confuse Python. BTW: "while" doesn't need brackets, that's a C-ism. ;) Cheers! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From jeanmichel at sequans.com Fri Mar 19 06:39:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Mar 2010 11:39:57 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: <4BA295A1.70207@hellmutweber.de> References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BA3547D.7080107@sequans.com> Hellmut Weber wrote: > Am 11.03.2010 12:14, schrieb Peter Otten: >> Hellmut Weber wrote: >> >>> Logging works very well giving the filename and line number of the >>> point >>> where it is called. As long as I use the loggers directly. >>> BUT when I have to wrap the logger call in some other function, I >>> always >>> get file name and line number of the call of the logger inside the >>> wrapping function. >>> >>> Is there a possibility to get this information in this situation too? >> >> The official way is probably to write a custom Logger class that >> overrides >> the findCaller() method. >> >> Below is a hack that monkey-patches the logging._srcfile attribute to >> ignore >> user-specified modules in the call stack: >> >> $ cat wrapper.py >> import logging >> import os >> import sys >> >> logger = logging.getLogger() >> >> class SrcFile(object): >> def __init__(self, exclude_files): >> self.files = set(exclude_files) >> def __eq__(self, other): >> return other in self.files >> >> def fixname(filename): >> if filename.lower().endswith((".pyc", ".pyo")): >> filename = filename[:-4] + ".py" >> return os.path.normcase(filename) >> >> if "--monkey" in sys.argv: >> print "patching" >> logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) >> >> def warn(*args, **kw): >> logger.warn(*args, **kw) >> >> $ cat main.py >> import logging >> logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") >> import wrapper >> wrapper.warn("foo") >> wrapper.warn("bar") >> wrapper.warn("baz") >> >> $ python main.py >> wrapper.py<23>: foo >> wrapper.py<23>: bar >> wrapper.py<23>: baz >> >> $ python main.py --monkey >> patching >> main.py<4>: foo >> main.py<5>: bar >> main.py<6>: baz >> >> $ python -V >> Python 2.6.4 >> >> Peter > > Hi Peter, > your hack is exactly what I was looking for. > It permits to configure my logging messages as I want, e.g. using > different colors for different classes of messages. > > I do not yet understand all details WHY it is working but suppose some > study of the logging module will help me to understand. > > Thank you very much > _scrFile is a private attribute of the logging module. Don't change it. As you said yourself, 'The official way is probably to write a custom Logger class that overrides the findCaller() method' JM From peter_peyman_puk at yahoo.ca Fri Mar 19 06:47:53 2010 From: peter_peyman_puk at yahoo.ca (Peyman Askari) Date: Fri, 19 Mar 2010 03:47:53 -0700 (PDT) Subject: Importing modules Message-ID: <180153.53663.qm@web43402.mail.sp1.yahoo.com> I want to write a function which imports modules the first time, and reloads them afterwards, but I am running into problems with global variables and exec. I will include a full script, but let me elaborate first. Essentially what you need is def import_or_reload(): ?"""assume we want to load or reload sys""" ?if 'sys' in dir(): ? reload(sys) else: ? import sys but this runs into the problem that sys is imported within the local scope of the function, so you insert a global statement def import_or_reload2(): ?"""Add 'global sys'""" ?global sys ?if 'sys' in dir(): ? reload(sys) else: ? import sys 'sys' is still not in dir() as dir() pertains to the local scope of the function, but one can get around this by creating a local modules list and adding the imported modules to it def import_or_reload3(): ?"""Add 'global modules'""" ?global sys ?global modules ?if 'sys' in modules: ? reload(sys) else: ? import sys ? modules.append('sys') now lets add a parameter to the function signature, so any module name can be passed as an argument and loaded def import_or_reload4(module_name): ?"""Add exec""" ? exec 'global %s'%module_name ?global modules ?if module_name in modules: ? exec 'reload(%s)'%module_name else: ? exec 'import %s'%module_name ? exec 'modules.append(\'%s\')'%module_name but this doesn't work as global does not cooperate with exec is there a __reload__('X') function like there is an __import__(?X?) function? Also is there a better way to import modules at run time? Cheers and here is the test script in case you can't access the attachment def a(): ??? global modules ??? global sys ??? import sys ??? modules.append('sys') def b(): ??? global modules ??? global sys ??? reload(sys) def c(module_name): ??? global modules ??? exec 'global %s'%module_name ??? exec 'import %s'%module_name ??? modules.append(module_name) def test(): ??? global modules ??? global sys ??? #create the module list to contain all the modules ??? modules=[] ??? print 'originally dir() returns:' ??? print dir() ??? a() ??? print 'function a() properly imports the following module:' ??? print sys ??? print 'is %s in %s->%s'%('sys',modules,'sys' in modules) ??? ??? b() ??? print 'function b() properly reloads the following module:' ??? print sys ??? print 'is %s still in %s->%s'%('sys',modules,'sys' in modules) ??? try: ??? ??? c('os') ??? ??? print 'function c() properly imports the following module:' ??? except: ??? ??? print 'function c() failed to import module os' ??? ??? print 'is %s in %s->%s'%('os',modules,'os' in modules) ??? try: ??? ??? print os ??? ??? print 'is %s still in %s->%s'%('os',modules,'os' in modules) ??? except: ??? ??? print 'os was loaded, but is not visible outside of the scope of c()' --- On Fri, 3/19/10, python-list-request at python.org wrote: From: python-list-request at python.org Subject: Python-list Digest, Vol 78, Issue 192 To: python-list at python.org Received: Friday, March 19, 2010, 7:05 AM Send Python-list mailing list submissions to ??? python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit ??? http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to ??? python-list-request at python.org You can reach the person managing the list at ??? python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: ???1. Re: import antigravity (John Bokma) ???2. Re: Truoble With A Search Script for ImageBin.org ? ? ? (Cameron Simpson) ???3. example of ssl with SimpleXMLRPCServer in 2.6? (Rowland Smith) ???4. Re: multiprocessing on freebsd (Tim Arnold) ???5. Re: Python bindings tutorial (Tim Roberts) ???6. Re: sqlite3, memory db and multithreading (John Nagle) ???7. Re: GC is very expensive: am I doing something wrong? ? ? ? (Patrick Maupin) ???8. Bug in Python APscheduler module. (anand jeyahar) ???9. Re: Bug in Python APscheduler module. (Terry Reedy) ? 10. Re: Python bindings tutorial (Alf P. Steinbach) -- http://mail.python.org/mailman/listinfo/python-list __________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test5.py Type: text/x-python Size: 1044 bytes Desc: not available URL: From królewna at ee.pl Fri Mar 19 06:55:57 2010 From: królewna at ee.pl (=?ISO-8859-1?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 11:55:57 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: <57dc1ce8-1ac7-4d72-aafc-6fe7920144c2@c16g2000yqd.googlegroups.com> References: <57dc1ce8-1ac7-4d72-aafc-6fe7920144c2@c16g2000yqd.googlegroups.com> Message-ID: W dniu 18.03.2010 15:49, DreiJane pisze: > Principally sqlite connections (sqlite3 objects in the C-API) can be > used over multiple threads - and connections to :memory: make no > difference. There are additional parameters to open() giving fine- > tuned control. And apsw is promising a true reflection of sqlite's C- > API. It's my fault not saying what am I using to connect to sqlite db. It's sqlite3 module. So there is no open() function etc. As for now I'm not interested in rewriting my program to use apsw so is there any possible way of working this out with sqlite3? -- best regards princess From królewna at ee.pl Fri Mar 19 06:56:54 2010 From: królewna at ee.pl (=?UTF-8?B?a3LDs2xld25h?=) Date: Fri, 19 Mar 2010 11:56:54 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: W dniu 18.03.2010 23:06, Aahz pisze: > > You probably need to serialize access to the database through one thread. sqlite3 objects are not pickable so it's not proper way. -- best regards princess From królewna at ee.pl Fri Mar 19 07:04:16 2010 From: królewna at ee.pl (=?ISO-8859-1?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 12:04:16 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: <155a70fb-0e4e-43a8-8e4c-0f4475573035@t20g2000yqe.googlegroups.com> References: <155a70fb-0e4e-43a8-8e4c-0f4475573035@t20g2000yqe.googlegroups.com> Message-ID: W dniu 19.03.2010 08:20, Expo pisze: > > You can put the SQLite database into a Singleton class and use a > semaphore to serialize the access to methods which writes to the > database. I've tried this out but doesnt work. Still gives an error like: ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id -1216280896 and this is thread id -1217107088 -- best regards princess From mail at timgolden.me.uk Fri Mar 19 07:10:29 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 19 Mar 2010 11:10:29 +0000 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: <4BA35BA5.5020805@timgolden.me.uk> On 19/03/2010 10:56, kr?lewna wrote: > W dniu 18.03.2010 23:06, Aahz pisze: >> >> You probably need to serialize access to the database through one thread. > > sqlite3 objects are not pickable so it's not proper way. Is it possible you've misunderstood the meaning of the word "serialize" here? What's being suggested isn't serialising (ie marshalling, pickling) the data; rather, serialising the *access*, ie pushing all db requests into a queue which is read by one thread which manages the only db connection. TJG From królewna at ee.pl Fri Mar 19 07:24:11 2010 From: królewna at ee.pl (=?ISO-8859-1?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 12:24:11 +0100 Subject: sqlite3, memory db and multithreading In-Reply-To: References: Message-ID: W dniu 19.03.2010 12:10, Tim Golden pisze: > Is it possible you've misunderstood the meaning of the word "serialize" > here? It's not possible, it just happened :) > What's being suggested isn't serialising (ie marshalling, pickling) > the data; rather, serialising the *access*, ie pushing all db requests into > a queue which is read by one thread which manages the only db connection. That would make structure of program much more complicated. I would have to create queue for putting there queries and some other extra variables/structure to receive output from db and some more for controlling the execution flow of awaiting threads. -- best regards princess From kamil at lucem.pl Fri Mar 19 07:48:17 2010 From: kamil at lucem.pl (Kamil Wasilewski) Date: Fri, 19 Mar 2010 12:48:17 +0100 Subject: python-daemon PID file Message-ID: Hi all, Im trying to get a daemon up and running but have been tripping on every stone along the way, this last one however i cant manage to get by. versions: Python 2.5.2 python-daemon-1.5.5 Debian Linux 2.6.26-2-686 Some of the problems ive run into: import daemon with daemon.DaemonContext(): do_main_program() doesnt work on my version of Python 2.5.2 so im using import daemon import grp import pwd diablo.uid = pwd.getpwnam('nobody').pw_uid diablo.gid = grp.getgrnam('nogroup').gr_gid daemon.__enter__() main() daemon.__exit__() Next I had problems with Initd starting the daemon because i forgot to chmod it to 755. The final problem is with the PID file and getting a correct PID written. Initially there was no file being created, so i thought i needed the --make-pidfile option in start-stop-daemon, but ive since learned that the daemon should create and edit the file, not s-s-d as it inserts the PID of the parent process, which is not the correct PID of the final daemon. So i added to my daemon: import lockfile daemon.DaemonContext(pidfile=lockfile.FileLock('/var/run/mydaemon.pid'),) which didnt start the daemon at all as i created the pid file as root, and was setting the Daemon to run as nobody,nogroup so it was dieing silently. Im running it as root for now to see if i can get a correct pid in the pid file. However no PID file is created, and if i create one its not populated with a PID. In summary: I cant get a PID file created or pupulated with a PID by python-daemon. Anyone see something that im doing wrong? ive been sitting on this way too long. I looked at the python-daemon source and i cant see where the pid is inserted into the pid file, only where it __enter__'s the lockfile so is this missing? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From slais-www at ucl.ac.uk Fri Mar 19 08:08:19 2010 From: slais-www at ucl.ac.uk (djc) Date: Fri, 19 Mar 2010 12:08:19 +0000 Subject: should writing Unicode files be so slow In-Reply-To: <8739zxw057.fsf@benfinney.id.au> References: <8739zxw057.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > djc writes: > >> I have a simple program to read a text (.csv) file > > Could you please: > > * simplify it further: make a minimal version that demonstrates the > difference you're seeing, without any extraneous stuff that doesn't > appear to affect the result. > > * make it complete: the code you've shown doesn't do anything except > define some functions. > > In other words: please reduce it to a complete, minimal example that we > can run to see the same behaviour you're seeing. > It is the minimal example. The only thing omited is the opt.parse code that calls _file_to_files(infile, outfile_prefix, column, sep): -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From __peter__ at web.de Fri Mar 19 08:24:41 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Mar 2010 13:24:41 +0100 Subject: logging: local functions ==> loss of lineno References: <4BA295A1.70207@hellmutweber.de> Message-ID: Jean-Michel Pichavant wrote: > Hellmut Weber wrote: >> Am 11.03.2010 12:14, schrieb Peter Otten: >>> Hellmut Weber wrote: >>> >>>> Logging works very well giving the filename and line number of the >>>> point >>>> where it is called. As long as I use the loggers directly. >>>> BUT when I have to wrap the logger call in some other function, I >>>> always >>>> get file name and line number of the call of the logger inside the >>>> wrapping function. >>>> >>>> Is there a possibility to get this information in this situation too? >>> >>> The official way is probably to write a custom Logger class that >>> overrides >>> the findCaller() method. >>> >>> Below is a hack that monkey-patches the logging._srcfile attribute to >>> ignore >>> user-specified modules in the call stack: >>> >>> $ cat wrapper.py >>> import logging >>> import os >>> import sys >>> >>> logger = logging.getLogger() >>> >>> class SrcFile(object): >>> def __init__(self, exclude_files): >>> self.files = set(exclude_files) >>> def __eq__(self, other): >>> return other in self.files >>> >>> def fixname(filename): >>> if filename.lower().endswith((".pyc", ".pyo")): >>> filename = filename[:-4] + ".py" >>> return os.path.normcase(filename) >>> >>> if "--monkey" in sys.argv: >>> print "patching" >>> logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) >>> >>> def warn(*args, **kw): >>> logger.warn(*args, **kw) >>> >>> $ cat main.py >>> import logging >>> logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") >>> import wrapper >>> wrapper.warn("foo") >>> wrapper.warn("bar") >>> wrapper.warn("baz") >>> >>> $ python main.py >>> wrapper.py<23>: foo >>> wrapper.py<23>: bar >>> wrapper.py<23>: baz >>> >>> $ python main.py --monkey >>> patching >>> main.py<4>: foo >>> main.py<5>: bar >>> main.py<6>: baz >>> >>> $ python -V >>> Python 2.6.4 >>> >>> Peter >> >> Hi Peter, >> your hack is exactly what I was looking for. >> It permits to configure my logging messages as I want, e.g. using >> different colors for different classes of messages. >> >> I do not yet understand all details WHY it is working but suppose some >> study of the logging module will help me to understand. >> >> Thank you very much >> > _scrFile is a private attribute of the logging module. Don't change it. > > As you said yourself, 'The official way is probably to write a custom > Logger class that overrides > the findCaller() method' OK, I tried the this approach, too: import logging import os import sys from logging import currentframe def fixname(filename): if filename.lower().endswith((".pyc", ".pyo")): filename = filename[:-4] + ".py" return os.path.normcase(filename) class MyLogger(logging.Logger): exclude_files = set([logging._srcfile, fixname(__file__)]) def findCaller(self): """ Find the stack frame of the caller so that we can note the source file name, line number and function name. """ f = currentframe() #On some versions of IronPython, currentframe() returns None if #IronPython isn't run with -X:Frames. if f is not None: f = f.f_back rv = "(unknown file)", 0, "(unknown function)" while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) if filename in self.exclude_files: f = f.f_back continue rv = (filename, f.f_lineno, co.co_name) break return rv if "--custom-logger" in sys.argv: print "setting custom logger" logging.setLoggerClass(MyLogger) logging.root = MyLogger("root", logging.WARNING) logger = logging.getLogger() def warn(*args, **kw): logger.warn(*args, **kw) I had to duplicate the original findCaller() method with only one line changed. This means I have now some code duplication and I still have to monitor future changes in the logging source. In this case the "official way" seems to be more intrusive than the "hack". Peter From davea at ieee.org Fri Mar 19 08:25:15 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Mar 2010 07:25:15 -0500 Subject: Importing modules In-Reply-To: <180153.53663.qm@web43402.mail.sp1.yahoo.com> References: <180153.53663.qm@web43402.mail.sp1.yahoo.com> Message-ID: <4BA36D2B.2000507@ieee.org> Peyman Askari wrote: > I want to write a function which imports modules the first time, and reloads them afterwards, but I am running into problems with global variables and exec. I will include a full script, but let me elaborate first. > > Essentially what you need is > > def import_or_reload(): > """assume we want to load or reload sys""" > if 'sys' in dir(): > reload(sys) > else: > import sys > > but this runs into the problem that sys is imported within the local scope of the function, so you insert a global statement > > > > def import_or_reload2(): > > """Add 'global sys'""" > global sys > > if 'sys' in dir(): > > reload(sys) > > else: > > import sys > > 'sys' is still not in dir() as dir() pertains to the local scope of the function, but one can get around this by creating a local modules list and adding the imported modules to it > > > > > > def import_or_reload3(): > > > """Add 'global modules'""" > > global sys > global modules > > > > if 'sys' in modules: > > > reload(sys) > > > else: > > > import sys > modules.append('sys') > > now lets add a parameter to the function signature, so any module name can be passed as an argument and loaded > > > > > > def import_or_reload4(module_name): > > > > """Add exec""" > > > exec 'global %s'%module_name > > global modules > > > > > > if module_name in modules: > > > > exec 'reload(%s)'%module_name > > > > else: > > > > exec 'import %s'%module_name > > exec 'modules.append(\'%s\')'%module_name > > but this doesn't work as global does not cooperate with exec > is there a __reload__('X') function like there is an __import__(?X?) function? > > Also is there a better way to import modules at run time? > > Cheers and here is the test script in case you can't access the attachment > > def a(): > global modules > global sys > import sys > > modules.append('sys') > > def b(): > global modules > global sys > > reload(sys) > > def c(module_name): > global modules > exec 'global %s'%module_name > exec 'import %s'%module_name > > modules.append(module_name) > > def test(): > global modules > global sys > > #create the module list to contain all the modules > modules=[] > > print 'originally dir() returns:' > print dir() > > a() > print 'function a() properly imports the following module:' > print sys > print 'is %s in %s->%s'%('sys',modules,'sys' in modules) > > b() > print 'function b() properly reloads the following module:' > print sys > print 'is %s still in %s->%s'%('sys',modules,'sys' in modules) > > try: > c('os') > print 'function c() properly imports the following module:' > except: > print 'function c() failed to import module os' > print 'is %s in %s->%s'%('os',modules,'os' in modules) > > try: > print os > print 'is %s still in %s->%s'%('os',modules,'os' in modules) > except: > print 'os was loaded, but is not visible outside of the scope of c()' > --- On Fri, 3/19/10, python-list-request at python.org wrote: > > From: python-list-request at python.org > Subject: Python-list Digest, Vol 78, Issue 192 > To: python-list at python.org > Received: Friday, March 19, 2010, 7:05 AM > > (When starting a new thread, create a new message addressed to python-list at python.org, do not just reply to an existing message, (or digest, which you did here). Some people actually try to follow threads, and the software to do that uses more information than just the message subject) First comment. I would seriously try to avoid using reload() in production code. The problems that can result are subtle. I use it for debugging sessions, but not in real programs. But I'll assume you have a use case (which would have been good to explain), and have rejected the other possibilities. Next, I'll point out that reloading sys isn't desirable, and it's one of the specifically proscribed modules for reloading. But probably you weren't really using sys, you were just sanitizing the code since you knew we all had sys. Next, if your reason for reloading is that you just changed the module programmatically, and it might have been loaded by some other module (as sys is, for example, long before your code starts), then you're not checking in the right place. Instead of looking at your own global space, you should be looking at sys.modules to decide whether something has been loaded. Perhaps the function you're looking for is imp.load_module() DaveA From ben+python at benfinney.id.au Fri Mar 19 08:56:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Mar 2010 23:56:49 +1100 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> Message-ID: <87ljdov59q.fsf@benfinney.id.au> djc writes: > Ben Finney wrote: > > Could you please: > > > > * simplify it further: make a minimal version that demonstrates the > > difference you're seeing, without any extraneous stuff that doesn't > > appear to affect the result. > > > > * make it complete: the code you've shown doesn't do anything except > > define some functions. > > > > In other words: please reduce it to a complete, minimal example that we > > can run to see the same behaviour you're seeing. > > It is the minimal example. The only thing omited is the opt.parse code > that calls _file_to_files(infile, outfile_prefix, column, sep): What happens, then, when you make a smaller program that deals with only one file? What happens when you make a smaller program that only reads the file, and doesn't write any? Or a different program that only writes a file, and doesn't read any? It's these sort of reductions that will help narrow down exactly what the problem is. Do make sure that each example is also complete (i.e. can be run as is by someone who uses only that code with no additions). -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From googler.1.webmaster at spamgourmet.com Fri Mar 19 09:12:34 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 19 Mar 2010 06:12:34 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: In my case I call a funcion and I would like to get the line where the function returned. for instance: def my_function(): return 3 So I would like to get line 2(in C) somehow. From jeanmichel at sequans.com Fri Mar 19 09:49:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Mar 2010 14:49:22 +0100 Subject: logging: local functions ==> loss of lineno In-Reply-To: References: <4BA295A1.70207@hellmutweber.de> Message-ID: <4BA380E2.8060306@sequans.com> Peter Otten wrote: > Jean-Michel Pichavant wrote: > > >> Hellmut Weber wrote: >> >>> Am 11.03.2010 12:14, schrieb Peter Otten: >>> >>>> Hellmut Weber wrote: >>>> >>>> >>>>> Logging works very well giving the filename and line number of the >>>>> point >>>>> where it is called. As long as I use the loggers directly. >>>>> BUT when I have to wrap the logger call in some other function, I >>>>> always >>>>> get file name and line number of the call of the logger inside the >>>>> wrapping function. >>>>> >>>>> Is there a possibility to get this information in this situation too? >>>>> >>>> The official way is probably to write a custom Logger class that >>>> overrides >>>> the findCaller() method. >>>> >>>> Below is a hack that monkey-patches the logging._srcfile attribute to >>>> ignore >>>> user-specified modules in the call stack: >>>> >>>> $ cat wrapper.py >>>> import logging >>>> import os >>>> import sys >>>> >>>> logger = logging.getLogger() >>>> >>>> class SrcFile(object): >>>> def __init__(self, exclude_files): >>>> self.files = set(exclude_files) >>>> def __eq__(self, other): >>>> return other in self.files >>>> >>>> def fixname(filename): >>>> if filename.lower().endswith((".pyc", ".pyo")): >>>> filename = filename[:-4] + ".py" >>>> return os.path.normcase(filename) >>>> >>>> if "--monkey" in sys.argv: >>>> print "patching" >>>> logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) >>>> >>>> def warn(*args, **kw): >>>> logger.warn(*args, **kw) >>>> >>>> $ cat main.py >>>> import logging >>>> logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") >>>> import wrapper >>>> wrapper.warn("foo") >>>> wrapper.warn("bar") >>>> wrapper.warn("baz") >>>> >>>> $ python main.py >>>> wrapper.py<23>: foo >>>> wrapper.py<23>: bar >>>> wrapper.py<23>: baz >>>> >>>> $ python main.py --monkey >>>> patching >>>> main.py<4>: foo >>>> main.py<5>: bar >>>> main.py<6>: baz >>>> >>>> $ python -V >>>> Python 2.6.4 >>>> >>>> Peter >>>> >>> Hi Peter, >>> your hack is exactly what I was looking for. >>> It permits to configure my logging messages as I want, e.g. using >>> different colors for different classes of messages. >>> >>> I do not yet understand all details WHY it is working but suppose some >>> study of the logging module will help me to understand. >>> >>> Thank you very much >>> >>> >> _scrFile is a private attribute of the logging module. Don't change it. >> >> As you said yourself, 'The official way is probably to write a custom >> Logger class that overrides >> the findCaller() method' >> > > OK, I tried the this approach, too: > > import logging > import os > import sys > > from logging import currentframe > > def fixname(filename): > if filename.lower().endswith((".pyc", ".pyo")): > filename = filename[:-4] + ".py" > return os.path.normcase(filename) > > class MyLogger(logging.Logger): > exclude_files = set([logging._srcfile, fixname(__file__)]) > > def findCaller(self): > """ > Find the stack frame of the caller so that we can note the source > file name, line number and function name. > """ > f = currentframe() > #On some versions of IronPython, currentframe() returns None if > #IronPython isn't run with -X:Frames. > if f is not None: > f = f.f_back > rv = "(unknown file)", 0, "(unknown function)" > while hasattr(f, "f_code"): > co = f.f_code > filename = os.path.normcase(co.co_filename) > if filename in self.exclude_files: > f = f.f_back > continue > rv = (filename, f.f_lineno, co.co_name) > break > return rv > > if "--custom-logger" in sys.argv: > print "setting custom logger" > logging.setLoggerClass(MyLogger) > logging.root = MyLogger("root", logging.WARNING) > > logger = logging.getLogger() > def warn(*args, **kw): > logger.warn(*args, **kw) > > I had to duplicate the original findCaller() method with only one line > changed. This means I have now some code duplication and I still have to > monitor future changes in the logging source. > > In this case the "official way" seems to be more intrusive than the "hack". > > Peter You are still accessing the private attribute of the module logging. My previous remark was misleading, in fact there's nothing you can do about it. _srcfile is not meant to be used elsewhere than in the logging module itself. However, I don't wanna sound like I'm rejecting this solution, 1st the OP is satisified with it and since this solution is working, it is still more helpful than anyone noticing that you've accessed a private attribute (some will successfully argue that python allows to do so). At the very begining of this thread I've provided a complete different approach, instead of using the builtin 'filename' and 'lineno' field of the logging, use custom fileds with the extra parameter. It has also some drawbacks but could be a possible alternative. Cheers, JM in test.py: import logging import inspect _logger = logging.getLogger(__name__) class Foo: def __init__(self): self._logger = _logger def info(self, msg): # this is the method you don't want to appear in the logs, instead the lineno and filename of this method caller previousFrame = inspect.currentframe().f_back self._logger.info(msg, extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename}) if __name__ == '__main__': _logger.handlers=[] _logger.addHandler(logging.StreamHandler()) _logger.handlers[-1].setFormatter(logging.Formatter('file %(custom_filename)s line %(custom_lineno)d : %(message)s')) _logger.setLevel(logging.DEBUG) foo = Foo() foo.info('a foo info') In [3]: run test.py file test.py line 20 : a foo info From królewna at ee.pl Fri Mar 19 09:58:22 2010 From: królewna at ee.pl (=?ISO-8859-2?Q?kr=F3lewna?=) Date: Fri, 19 Mar 2010 14:58:22 +0100 Subject: SOLUTION In-Reply-To: References: Message-ID: I have found the solution. I dont know why in python documentation there is not a single word about this option. I've found it in pysqlite doc site. So we have to add a new keyword argument to connection function and we will be able to create cursors out of it in different thread. So use: sqlite.connect(":memory:", check_same_thread = False) works out perfectly for me. Of course from now on me need to take care of safe multithreading access to the db. Anyway thx all for trying to help. -- best regards princess From stefan_ml at behnel.de Fri Mar 19 10:11:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Mar 2010 15:11:42 +0100 Subject: C-API PyObject_Call In-Reply-To: References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: moerchendiser2k3, 19.03.2010 14:12: > In my case I call a funcion and I would like to get the line > where the function returned. > > for instance: > > > def my_function(): > return 3 > > So I would like to get line 2(in C) somehow. Ok, so you're looking for the C-level trace function in CPython, I guess. Could you explain why you want to know the line number? Stefan From python at hope.cz Fri Mar 19 11:32:32 2010 From: python at hope.cz (Johny) Date: Fri, 19 Mar 2010 08:32:32 -0700 (PDT) Subject: What is pkg-config for ? Message-ID: Can anyone explain what is pkg-config for?ANd how can I find it in Windows? Thanks From peter_peyman_puk at yahoo.ca Fri Mar 19 13:09:09 2010 From: peter_peyman_puk at yahoo.ca (Peter Peyman Puk) Date: Fri, 19 Mar 2010 17:09:09 +0000 Subject: Importing v reloading modules modules In-Reply-To: <4BA3A738.1050401@ieee.org> References: <202203.80122.qm@web43401.mail.sp1.yahoo.com> <4BA3A738.1050401@ieee.org> Message-ID: <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> Hello I submitted this earlier today, but I was not clear enough, so I am posting it again. I am running a simulator written in python. The simulator has a small TextView (actually a SourceView) widget which lets the user writes scripts, and when they are satisfied they can execute that script to get results. For arguments sake, we write a simple script and save it as A.py and we import it and execute it more or less like so. import A #assume there is a function called test() in module A A.test() Then the user modifies the contents of A.py and saves it again (to A.py) now all we have to do is the following if 'A' in dir(): reload(A) else: import A A.test() But since the user chooses the file name, and not me, the programmer, the module names will vary. Let's assume the module names are loaded and stored in the list module_names, and we iterate over them, and pass them as arguments to a function to import or reload each model as appropriate def import_or_reload(module_name): if module_name in sys.modules: #somehow reload else: #somehow import does anyone know how to deal with the reload and import as they both present problems since module_name is a string, and to reload something along the lines of the below must be executed exec 'reload(%s)'%module_name and then we also have to deal with the scope issue since the loaded module will be local and not global. I can execute something like so exec 'global %s'%module_name but that does not work very well with exec any suggestions? Cheers Peyman From slais-www at ucl.ac.uk Fri Mar 19 13:18:17 2010 From: slais-www at ucl.ac.uk (djc) Date: Fri, 19 Mar 2010 17:18:17 +0000 Subject: should writing Unicode files be so slow In-Reply-To: <87ljdov59q.fsf@benfinney.id.au> References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > What happens, then, when you make a smaller program that deals with only > one file? > > What happens when you make a smaller program that only reads the file, > and doesn't write any? Or a different program that only writes a file, > and doesn't read any? > > It's these sort of reductions that will help narrow down exactly what > the problem is. Do make sure that each example is also complete (i.e. > can be run as is by someone who uses only that code with no additions). > The program reads one csv file of 9,293,271 lines. 869M wb.csv It creates set of files containing the same lines but where each output file in the set contains only those lines where the value of a particular column is the same, the number of output files will depend on the number of distinct values in that column In the example that results in 19 files 74M tt_11696870405.txt 94M tt_18762175493.txt 15M tt_28668070915.txt 12M tt_28673313795.txt 15M tt_28678556675.txt 11M tt_28683799555.txt 12M tt_28689042435.txt 15M tt_28694285315.txt 7.3M tt_28835845125.txt 6.8M tt_28842136581.txt 12M tt_28848428037.txt 11M tt_28853670917.txt 12M tt_28858913797.txt 15M tt_28864156677.txt 11M tt_28869399557.txt 11M tt_28874642437.txt 283M tt_31002203141.txt 259M tt_33335282691.txt 45 2010-03-19 17:00 tt_taskid.txt changing with open(filename, 'rU') as tabfile: to with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as tabfile: and with open(outfile, 'wt') as out_part: to with codecs.open(outfile, 'w', 'utf-8') as out_part: causes a program that runs in 43 seconds to take 4 minutes to process the same data. In this particular case that is not very important, any unicode strings in the data are not worth troubling over and I have already spent more time satisfying curiousity that will ever be required to process the dataset in future. But I have another project in hand where not only is the unicode significant but the files are very much larger. Scale up the problem and the difference between 4 hours and 24 become a matter worth some attention. -- David Clark, MSc, PhD. UCL Centre for Publishing Gower Str London WCIE 6BT What sort of web animal are you? From incensedprey at gmail.com Fri Mar 19 13:42:53 2010 From: incensedprey at gmail.com (Kevin Adams) Date: Fri, 19 Mar 2010 10:42:53 -0700 (PDT) Subject: [python3] Message-ID: Greetings! Please forgive me if im posting this to the wrong group. I'm new to Python, learning Python3 from the O'rielly "Learning Python" book. Reading about operator overloading, specifically __getitem__. I put together a small bit of code to do some experimenting and threw in a timer so i can see it do its thing. For some reason the time.sleep(x) function doesnt work when my print function includes "end=''". Thanks in advance for any help. ---code--- class TestClass(): def __init__(self): self.data = "I was far from home and the spell of the eastern sea was upon me." def __getitem__(self,i): return self.data[i] import time if __name__ == "__main__": me = TestClass() for x in me: print(x,end='') #if i remove the 'end=''' it performs as i'd expect time.sleep(int(2)) From tjreedy at udel.edu Fri Mar 19 14:02:02 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 14:02:02 -0400 Subject: Importing v reloading modules modules In-Reply-To: <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> References: <202203.80122.qm@web43401.mail.sp1.yahoo.com> <4BA3A738.1050401@ieee.org> <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> Message-ID: Reload is effectively deprecated in 2.x and removed in 3.x, so I recommend not using it. Deleting an entry from sys.modules should force recreation with an import. Just make sure all other references are also gone so that the module object can be deleted. The following shows how to import by name in string and globally from within a function. def f(): global itertools itertools = __import__('itertools') f() print(itertools) # 3.1 # Terry Jan Reedy From steve at holdenweb.com Fri Mar 19 14:17:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Mar 2010 14:17:31 -0400 Subject: [python3] In-Reply-To: References: Message-ID: Kevin Adams wrote: > Greetings! > > Please forgive me if im posting this to the wrong group. > > I'm new to Python, learning Python3 from the O'rielly "Learning > Python" book. Reading > about operator overloading, specifically __getitem__. I put together > a small bit of code to > do some experimenting and threw in a timer so i can see it do its > thing. For some reason > the time.sleep(x) function doesnt work when my print function includes > "end=''". > > Thanks in advance for any help. > > Try the following changes: > ---code--- > > class TestClass(): > def __init__(self): > self.data = "I was far from home and the spell of the eastern > sea was upon me." > > def __getitem__(self,i): > return self.data[i] > > > import time import sys > > if __name__ == "__main__": > > me = TestClass() > for x in me: > print(x,end='') #if i remove the 'end=''' it performs as i'd > expect sys.stdout.flush() > time.sleep(int(2)) > It may just be that the output is being held in buffers until the program terminates. the fluch() methof pushes it straight out. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From krister.svanlund at gmail.com Fri Mar 19 14:19:04 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 19 Mar 2010 19:19:04 +0100 Subject: [python3] In-Reply-To: References: Message-ID: <2cf430a61003191119h688fef20u528f7e154680c00c@mail.gmail.com> On Fri, Mar 19, 2010 at 6:42 PM, Kevin Adams wrote: > Greetings! > > Please forgive me if im posting this to the wrong group. > > I'm new to Python, learning Python3 from the O'rielly "Learning > Python" book. ?Reading > about operator overloading, specifically __getitem__. ? I put together > a small bit of code to > do some experimenting and threw in a timer so i can see it do its > thing. ?For some reason > the time.sleep(x) function doesnt work when my print function includes > "end=''". > > Thanks in advance for any help. > > > ---code--- > > class TestClass(): > ? ?def __init__(self): > ? ? ? ?self.data = "I was far from home and the spell of the eastern > sea was upon me." > > ? ?def __getitem__(self,i): > ? ? ? ?return self.data[i] > > > import time > > if __name__ == "__main__": > > ? ?me = TestClass() > ? ?for x in me: > ? ? ? ?print(x,end='') ?#if i remove the 'end=''' ?it performs as i'd > expect > ? ? ? ?time.sleep(int(2)) > > -- > http://mail.python.org/mailman/listinfo/python-list > I'm guessing wildly here but I think you have to flush the output. Can't remember how right now but it won't take much googling for it. From tjreedy at udel.edu Fri Mar 19 14:21:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 14:21:34 -0400 Subject: [python3] In-Reply-To: References: Message-ID: On 3/19/2010 1:42 PM, Kevin Adams wrote: > Please forgive me if im posting this to the wrong group. Just the right place. I would suggest a more informative title in the future though. 'Problem with print and sleep.', for instance. > > I'm new to Python, learning Python3 from the O'rielly "Learning > Python" book. Reading > about operator overloading, specifically __getitem__. I put together > a small bit of code to > do some experimenting and threw in a timer so i can see it do its > thing. Good idea. Welcome to Python. > For some reason > the time.sleep(x) function doesnt work when my print function includes > "end=''". I cut your code, pasted it into IDLE edit window, and made two minor modifications. For me (3.1, winxp) it works perfectly either way -- chars print at 1 sec intervals either vertically or horizonatally. So I am not sure what you are claiming. > > Thanks in advance for any help. > > > ---code--- > > class TestClass(): > def __init__(self): > self.data = "I was far from home and the spell of the eastern > sea was upon me." I shortened string > > def __getitem__(self,i): > return self.data[i] > > import time > > if __name__ == "__main__": > > me = TestClass() > for x in me: > print(x,end='') #if i remove the 'end=''' it performs as i'd > expect > time.sleep(int(2)) int(2) == 2, so delete irrelevant call, and 1 sec is enough Terry Jan Reedy From incensedprey at gmail.com Fri Mar 19 14:46:40 2010 From: incensedprey at gmail.com (Kevin Adams) Date: Fri, 19 Mar 2010 11:46:40 -0700 (PDT) Subject: [python3] References: Message-ID: <5780a357-08a2-4393-9b2d-e07e4bb14b83@q16g2000yqq.googlegroups.com> On Mar 19, 2:21?pm, Terry Reedy wrote: > On 3/19/2010 1:42 PM, Kevin Adams wrote: > > > Please forgive me if im posting this to the wrong group. > > Just the right place. I would suggest a more informative title in the > future though. 'Problem with print and sleep.', for instance. > > > > > I'm new to Python, learning Python3 from the O'rielly "Learning > > Python" book. ?Reading > > about operator overloading, specifically __getitem__. ? I put together > > a small bit of code to > > do some experimenting and threw in a timer so i can see it do its > > thing. > > Good idea. Welcome to Python. > > > ?For some reason > > the time.sleep(x) function doesnt work when my print function includes > > "end=''". > > I cut your code, pasted it into IDLE edit window, and made two minor > modifications. For me (3.1, winxp) it works perfectly either way -- > chars print at 1 sec intervals either vertically or horizonatally. So I > am not sure what you are claiming. > > > > > Thanks in advance for any help. > > > ---code--- > > > class TestClass(): > > ? ? ?def __init__(self): > > ? ? ? ? ?self.data = "I was far from home and the spell of the eastern > > sea was upon me." > > I shortened string > > > > > ? ? ?def __getitem__(self,i): > > ? ? ? ? ?return self.data[i] > > > import time > > > if __name__ == "__main__": > > > ? ? ?me = TestClass() > > ? ? ?for x in me: > > ? ? ? ? ?print(x,end='') ?#if i remove the 'end=''' ?it performs as i'd > > expect > > ? ? ? ? ?time.sleep(int(2)) > > int(2) == 2, so delete irrelevant call, and 1 sec is enough > > Terry Jan Reedy Thanks to all!!! It did indeed turn out to be a need to flush the stdout. K ps. sorry for the brief subject, i wasnt finish and hit send before comming back to it. From heintest at web.de Fri Mar 19 14:46:45 2010 From: heintest at web.de (=?ISO-8859-15?Q?Hans_M=FCller?=) Date: Fri, 19 Mar 2010 19:46:45 +0100 Subject: Reserving binary Buffer for struct.pack_into() of exact length Message-ID: <4ba3c6ce$0$6990$9b4e6d93@newsspool4.arcor-online.net> Hello, I need some buffers, which are beeing concatenated an then send via the socket() function. My problem is that create_string_buffer() creates a buffer which ist one byte too long (for a \0 char). But when I concatenate some of these buffers to a long one to be transfered, the extra byte is corrupting the resulting buffer. Of course I could slice the buffer before being concatended, but this looks ugly to me. Is there a way to create a writeable buffer object without the \0 byte ? Thanks a lot Hans From tjreedy at udel.edu Fri Mar 19 15:02:56 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Mar 2010 15:02:56 -0400 Subject: [python3] In-Reply-To: References: Message-ID: On 3/19/2010 2:17 PM, Steve Holden wrote: > Kevin Adams wrote: >> Greetings! >> >> Please forgive me if im posting this to the wrong group. >> >> I'm new to Python, learning Python3 from the O'rielly "Learning >> Python" book. Reading >> about operator overloading, specifically __getitem__. I put together >> a small bit of code to >> do some experimenting and threw in a timer so i can see it do its >> thing. For some reason >> the time.sleep(x) function doesnt work when my print function includes >> "end=''". >> >> Thanks in advance for any help. >> >> > Try the following changes: > >> ---code--- >> >> class TestClass(): >> def __init__(self): >> self.data = "I was far from home and the spell of the eastern >> sea was upon me." >> >> def __getitem__(self,i): >> return self.data[i] >> >> >> import time > > import sys >> >> if __name__ == "__main__": >> >> me = TestClass() >> for x in me: >> print(x,end='') #if i remove the 'end=''' it performs as i'd >> expect > sys.stdout.flush() > >> time.sleep(int(2)) > > It may just be that the output is being held in buffers until the > program terminates. the fluch() methof pushes it straight out. The IDLE Shell window must get print output back from the pythonw process without buffering. When I cut and pasted from IDLE editor to standard interpreter window, output was bunched after several seconds. OP should have started with short string and minimal delay so output would not take a whole minute. Flushing fixed problem in standard interpreter. I will have to remember that testing partial line output in IDLE does not show how it will act elsewhere. Kevin: when reporting a problem, be more specific as to what 'does not work' means. Terry Jan Reedy From emile at fenx.com Fri Mar 19 16:33:00 2010 From: emile at fenx.com (Emile van Sebille) Date: Fri, 19 Mar 2010 13:33:00 -0700 Subject: Reserving binary Buffer for struct.pack_into() of exact length In-Reply-To: <4ba3c6ce$0$6990$9b4e6d93@newsspool4.arcor-online.net> References: <4ba3c6ce$0$6990$9b4e6d93@newsspool4.arcor-online.net> Message-ID: On 3/19/2010 11:46 AM Hans M?ller said... > Hello, > > I need some buffers, which are beeing concatenated an then send via the > socket() function. > My problem is that create_string_buffer() creates a buffer which ist one > byte too long (for a \0 char). But when I concatenate some of these > buffers to a long one to be transfered, the extra byte is corrupting the > resulting buffer. > Of course I could slice the buffer before being concatended, but > this looks ugly to me. > Is there a way to create a writeable buffer object without the \0 byte ? > > Thanks a lot > > Hans >>> p = create_string_buffer(5) >>> p.raw='hello' >>> p.value 'hello' From saimapk81 at gmail.com Fri Mar 19 17:03:41 2010 From: saimapk81 at gmail.com (saima81) Date: Fri, 19 Mar 2010 14:03:41 -0700 (PDT) Subject: "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com Message-ID: "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com "Sexy Girls" "Sexy Indian Girls" "Sexy USA Girls" "Sexy RUSSIAN Girls" "Sexy PAKISTANI Girls" "Sexy CHINESE Girls" "Sexy THAI Girls" "Sexy JAPANESE Girls" "Sexy KOREAN Girls" "Sexy MODEL Girls" ON www.sexyandpretty-girls.blogspot.com From brandonc530 at gmail.com Fri Mar 19 17:10:54 2010 From: brandonc530 at gmail.com (Brandon C) Date: Fri, 19 Mar 2010 16:10:54 -0500 Subject: Truoble With A Search Script for ImageBin.org In-Reply-To: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> References: <3020ae661003181800u55a5a654v7be4a524123eec65@mail.gmail.com> Message-ID: <3020ae661003191410i2f5e831et16dbd6fbf9e67e4d@mail.gmail.com> *grumble* *grumble* *grumble* oops, sorry ... my mistake it turns out that i misspelled one of the values and left another one out. here's the working script now for anyone who may care: import urllib import urllib2 url = 'http://imagebin.org/index.php?page=search' values = {'search_for' : 'blah', 'field' : 'nickname', 'mode' : 'search'} data = urllib.urlencode(values) request = urllib2.Request(url, data) response = urllib2.urlopen(request) page = response.read() print page the value of 'field' is 'nickname, not 'Nickname'; and i left out the 'mode' one tks for yalls help -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Mar 19 17:12:14 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 18:12:14 -0300 Subject: What is pkg-config for ? References: Message-ID: En Fri, 19 Mar 2010 12:32:32 -0300, Johny escribi?: > Can anyone explain what is pkg-config for?ANd how can I find it in > Windows? Go to http://www.google.com/ Enter "pkg-config windows" (without quotes) in the input box. Press the Search button. You'll get this site at the top, or near it: http://pkg-config.freedesktop.org/wiki/ I fail to see how is this relevant to Python... -- Gabriel Genellina From brandonc530 at gmail.com Fri Mar 19 18:02:25 2010 From: brandonc530 at gmail.com (Brandon C) Date: Fri, 19 Mar 2010 17:02:25 -0500 Subject: script to upload file using POST form Message-ID: <3020ae661003191502r1b87844fj3af5a0ccd45a3120@mail.gmail.com> got another question for yall wonderful minds; how can i upload a file to a server that uses a POST form? here's the link to the form that i'd like to be able to upload a file: http://imagebin.org/index.php?page=add tks -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Fri Mar 19 18:23:59 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 19:23:59 -0300 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: En Fri, 19 Mar 2010 14:18:17 -0300, djc escribi?: > Ben Finney wrote: > >> What happens, then, when you make a smaller program that deals with only >> one file? >> >> What happens when you make a smaller program that only reads the file, >> and doesn't write any? Or a different program that only writes a file, >> and doesn't read any? >> >> It's these sort of reductions that will help narrow down exactly what >> the problem is. Do make sure that each example is also complete (i.e. >> can be run as is by someone who uses only that code with no additions). >> > > > The program reads one csv file of 9,293,271 lines. > 869M wb.csv > It creates set of files containing the same lines but where > each > output file in the set contains only those lines where the value of a > particular column is the same, the number of output files will depend on > the number of distinct values in that column In the example that results > in 19 files > > changing > with open(filename, 'rU') as tabfile: > to > with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as tabfile: > > and > with open(outfile, 'wt') as out_part: > to > with codecs.open(outfile, 'w', 'utf-8') as out_part: > > causes a program that runs in > 43 seconds to take 4 minutes to process the same data. In this particular > case that is not very important, any unicode strings in the data are > not > worth troubling over and I have already spent more time satisfying > curiousity that will ever be required to process the dataset in > future. But I have another project in hand where not only is the > unicode significant but the files are very much larger. Scale up the > problem and the difference between 4 hours and 24 become a matter worth > some attention. Ok. Your test program is too large to determine what's going on. Try to determine first *which* part is slow: - reading: measure the time it takes only to read a file, with open() and codecs.open() It might be important the density of non-ascii characters and their relative code points (as utf-8 is much more efficient for ASCII data than, say, Hanzi) - processing: measure the time it takes the processing part (fed with str vs unicode data) - writing: measure the time it takes only to write a file, with open() and codecs.open() Only then one can focus on optimizing the bottleneck. -- Gabriel Genellina From barry at python.org Fri Mar 19 18:56:55 2010 From: barry at python.org (Barry Warsaw) Date: Fri, 19 Mar 2010 18:56:55 -0400 Subject: RELEASED Python 2.6.5 Message-ID: <20100319185655.26e1bf1a@heresy> On behalf of the Python community, I'm happy to announce the availability of Python 2.6.5 final. This is the latest production-ready version in the Python 2.6 series. Python 2.6.5 fixes dozens of issues in the core, built-in modules, libraries, and documentation since Python 2.6.4 was released back in October 2009. We highly recommend that you upgrade to Python 2.6.5. Please see the NEWS file for all the gory details. http://www.python.org/download/releases/2.6.5/NEWS.txt Source tarballs and the Windows installers can be downloaded from the Python 2.6.5 page. The Mac OS X disk image will be uploaded soon. http://www.python.org/download/releases/2.6.5/ For more information on Python 2.6 in general, please see http://docs.python.org/whatsnew/2.6.html Please report bugs for any Python version in the Python tracker. http://bugs.python.org Enjoy, -Barry Barry Warsaw barry at python.org Python 2.6 Release Manager (on behalf of the entire python-dev team) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: From ben+python at benfinney.id.au Fri Mar 19 19:01:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Mar 2010 10:01:44 +1100 Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: <87d3yzvrtz.fsf@benfinney.id.au> "Gabriel Genellina" writes: > Ok. Your test program is too large to determine what's going on. Try > to determine first *which* part is slow: Right. This is done by the diagnostic technique of writing *new*, minimal, complete programs that exercise each piece of the functionality separately. You're not tinkering with the existing program that's misbehaving; you're trying to *recreate* the misbehaviour under a simpler environment. Hope that helps. Feel free to continue posting complete minimal programs that exercise one thing and show behaviour you're unsure about. -- \ ?We now have access to so much information that we can find | `\ support for any prejudice or opinion.? ?David Suzuki, 2008-06-27 | _o__) | Ben Finney From gagsl-py2 at yahoo.com.ar Fri Mar 19 19:04:01 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 20:04:01 -0300 Subject: script to upload file using POST form References: <3020ae661003191502r1b87844fj3af5a0ccd45a3120@mail.gmail.com> Message-ID: En Fri, 19 Mar 2010 19:02:25 -0300, Brandon C escribi?: > got another question for yall wonderful minds; how can i upload a file > to a > server that uses a POST form? > > here's the link to the form that i'd like to be able to upload a file: > http://imagebin.org/index.php?page=add Unfortunately it isn't as easy as it should be: http://bugs.python.org/issue3244 -- Gabriel Genellina From steve at holdenweb.com Fri Mar 19 19:32:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 19 Mar 2010 19:32:44 -0400 Subject: Python Documentation website layout changed? In-Reply-To: <4BA120A9.3060001@holdenweb.com> References: <21fcbd63-fd1e-4b53-89b3-393c15591372@m37g2000yqf.googlegroups.com> <27c7e0a7-5a26-40f2-94ba-0af9cb530d67@g28g2000yqh.googlegroups.com> <4BA120A9.3060001@holdenweb.com> Message-ID: Steve Holden wrote: > Andrej Mitrovic wrote: >> On Mar 17, 6:41 pm, Andrej Mitrovic >> wrote: >>> Hi, >>> >>> What happened to the sidebar on the left of the documentation website? >>> It seems to be gone: >>> >>> http://docs.python.org/py3k/index.html >>> >>> I found it quite useful since I can quickly swap between Python2/3 >>> documentation, and between other parts of the documentation as well. >> Edit: It looks like only the Python 3 pages are affected, the Python 2 >> pages are the same as before: >> >> http://docs.python.org/index.html >> >> Might be a bug? > > I'll ask. Georg - is this known behavior or a temporary problem? > It's a bug. Georg is on it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From solipsis at pitrou.net Fri Mar 19 20:19:07 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 20 Mar 2010 00:19:07 +0000 (UTC) Subject: should writing Unicode files be so slow References: <8739zxw057.fsf@benfinney.id.au> <87ljdov59q.fsf@benfinney.id.au> Message-ID: Le Fri, 19 Mar 2010 17:18:17 +0000, djc a ?crit?: > > changing > with open(filename, 'rU') as tabfile: to > with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as > tabfile: > > and > with open(outfile, 'wt') as out_part: to > with codecs.open(outfile, 'w', 'utf-8') as out_part: > > causes a program that runs in > 43 seconds to take 4 minutes to process the same data. codecs.open() (and the object it returns) is slow as it is written in pure Python. Accelerated reading and writing of unicode files is available in Python 2.7 and 3.1, using the new `io` module. Regards Antoine. From speeze.pearson at gmail.com Fri Mar 19 20:20:31 2010 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Fri, 19 Mar 2010 17:20:31 -0700 (PDT) Subject: Tuples vs. variable-length argument lists Message-ID: <843bf1a3-6e9b-48d2-8661-b3f776a6fde2@t32g2000prg.googlegroups.com> Hi! This might be more of a personal-preference question than anything, but here goes: when is it appropriate for a function to take a list or tuple as input, and when should it allow a varying number of arguments? It seems as though the two are always interchangeable. For a simple example... def subtract( x, nums ): return x - sum( nums ) ... works equally well if you define it as "subtract( x, *nums )" and put an asterisk in front of any lists/tuples you pass it. I can't think of any situation where you couldn't convert from one form to the other with just a star or a pair of parentheses. Is there a generally accepted convention for which method to use? Is there ever actually a big difference between the two that I'm not seeing? From gagsl-py2 at yahoo.com.ar Fri Mar 19 21:28:12 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 22:28:12 -0300 Subject: Importing v reloading modules modules References: <202203.80122.qm@web43401.mail.sp1.yahoo.com> <4BA3A738.1050401@ieee.org> <6A6EB8D2-4910-415D-81A5-FB6C004C9AD9@yahoo.ca> Message-ID: En Fri, 19 Mar 2010 14:09:09 -0300, Peter Peyman Puk escribi?: > I am running a simulator written in python. The simulator has a small > TextView (actually a SourceView) widget which lets the user writes > scripts, and when they are satisfied they can execute that script to get > results. For arguments sake, we write a simple script and save it as > A.py and we import it and execute it more or less like so. > > import A > > #assume there is a function called test() in module A > A.test() > > > Then the user modifies the contents of A.py and saves it again (to A.py) > now all we have to do is the following > > if 'A' in dir(): > reload(A) > else: > import A > > A.test() Terry Reedy already gave you an answer for this import problem. I'd like to go one step back and question whether using import/modules is the right thing here. Clearly A.py is not a module but a script (that's the word you used) - and one does not *import* a script but *executes* it. That is, instead of using import/__import__, use exec (or execfile) within a known namespace: import __builtin__ ns = {'__builtins__': __builtin__.__dict__} exec contents_of_textview in ns # any change made to ns is visible here -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Mar 19 21:54:58 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 19 Mar 2010 22:54:58 -0300 Subject: Castrated traceback in sys.exc_info() References: <7866674b-46ba-49e2-9d76-e8259ba22df0@z3g2000yqz.googlegroups.com> <20100317124019.7013dfa3@moriz.interne> <9fd96c3b1003170542t4ea864c6y359107cb747536da@mail.gmail.com> Message-ID: En Wed, 17 Mar 2010 09:42:06 -0300, Pascal Chambon escribi?: > traceback functions indeed allow the manipulation of exception > tracebacks, > but the root problem is that anyway, since that traceback is incomplete, > your "traceback.format_exc().splitlines()" will only provide frames for > callee (downward) functions, not caller (upward) ones, starting from the > exception catching frame. Either I don't understand what you mean, or I can't reproduce it: import logging def a(): return b() def b(): return c() def c(): return d() def d(): raise ValueError def main(): logging.basicConfig(level=logging.DEBUG) try: a() except: logging.exception("An error") main() Output: D:\temp>python test_logging.py ERROR:root:An error Traceback (most recent call last): File "test_logging.py", line 10, in main try: a() File "test_logging.py", line 3, in a def a(): return b() File "test_logging.py", line 4, in b def b(): return c() File "test_logging.py", line 5, in c def c(): return d() File "test_logging.py", line 6, in d def d(): raise ValueError ValueError -- Gabriel Genellina From googler.1.webmaster at spamgourmet.com Fri Mar 19 21:58:28 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 19 Mar 2010 18:58:28 -0700 (PDT) Subject: Simple lock Message-ID: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Hi, I have a common question about locks: class SetPointer { private: void *ptr; MY_LOCK lock; public: void SetPointer(void *p) { Lock(this->lock); this->ptr = p; } void *GetPointer() { Lock(this->lock); return this->ptr; } }; Just a question, is this lock redundant, when the Pointer can be set/ get from different threads? Thanks a lot!! Bye, moerchendiser2k3 From googler.1.webmaster at spamgourmet.com Fri Mar 19 22:01:45 2010 From: googler.1.webmaster at spamgourmet.com (moerchendiser2k3) Date: Fri, 19 Mar 2010 19:01:45 -0700 (PDT) Subject: C-API PyObject_Call References: <67c5d4da-8d45-41b6-b1b0-b76823844aa1@t20g2000yqe.googlegroups.com> <3faff03c-6de5-4872-9f68-c129230f6b22@t41g2000yqt.googlegroups.com> <3592cca0-2a4a-4a19-9e10-d80936e6d200@upsg2000gro.googlegroups.com> <793e5934-bc1b-4023-aa0e-bf6d956177fd@f8g2000yqn.googlegroups.com> Message-ID: <7597f6a5-5fe0-4a69-9f9b-f0d96f4499d1@g26g2000yqn.googlegroups.com> Yes, the user is able to set a file which contains a function that does what the user wants. But in a case, I expect a special return value of this function. So, I need to tell him, in which file/line the error occured, otherwise he dont know where to look. Imagine he set 20 files, and all of them have implemented a special function. So he wouldnt know where to check for the error. Bye, moerchendiser2k3 From ben+python at benfinney.id.au Fri Mar 19 22:24:57 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Mar 2010 13:24:57 +1100 Subject: Simple lock References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Message-ID: <878w9nvifa.fsf@benfinney.id.au> moerchendiser2k3 writes: > I have a common question about locks: You'd be best to ask in a forum related to the language you're using. This (?comp.lang.python?) is a forum for users of the Python language. -- \ ?If you can do no good, at least do no harm.? ?_Slapstick_, | `\ Kurt Vonnegut | _o__) | Ben Finney From clp2 at rebertia.com Fri Mar 19 22:25:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Mar 2010 19:25:27 -0700 Subject: Simple lock In-Reply-To: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Message-ID: <50697b2c1003191925l6fd1c19alf4f8cdf31053b547@mail.gmail.com> On Fri, Mar 19, 2010 at 6:58 PM, moerchendiser2k3 wrote: > > Thanks a lot!! Bye, moerchendiser2k3 This is the **Python** mailinglist/newsgroup; and your question isn't about Python. The C++ one is over there: http://groups.google.com/group/comp.lang.c++.moderated/topics Regards, Chris From python at mrabarnett.plus.com Fri Mar 19 22:31:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Mar 2010 02:31:23 +0000 Subject: Simple lock In-Reply-To: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> References: <9fca30bd-8dd1-4952-a53d-88f44ec2e3ab@z4g2000yqa.googlegroups.com> Message-ID: <4BA4337B.6050301@mrabarnett.plus.com> moerchendiser2k3 wrote: > Hi, > > I have a common question about locks: > > class SetPointer > { > private: > void *ptr; > > MY_LOCK lock; > > > public: > void SetPointer(void *p) > { > Lock(this->lock); > this->ptr = p; > } > > void *GetPointer() > { > Lock(this->lock); > return this->ptr; > } > }; > > > Just a question, is this lock redundant, when the Pointer can be set/ > get from different threads? > Thanks a lot!! Bye, moerchendiser2k3 1. That's C++. What does it have to do with Python? 2. The value you're accessing is a simple pointer which you're either setting or getting, so a lock shouldn't be necessary. 3. You're locking, but never unlocking. The sequence should be: lock, do stuff, unlock. From nilly16 at yahoo.com Fri Mar 19 23:04:08 2010 From: nilly16 at yahoo.com (Jimbo) Date: Fri, 19 Mar 2010 20:04:08 -0700 (PDT) Subject: Best Way to extract Numbers from String Message-ID: Hello I am trying to grab some numbers from a string containing HTML text. Can you suggest any good functions that I could use to do this? What would be the easiest way to extract the following numbers from this string... My String has this layout & I have commented what I want to grab: [CODE] """
43.200 0.040 43.150 43.200 43.130 43.290 43.100 7,450,447 Options Warrants & Structured Products CFDs XD Recent
43.200 0.040 43.150 43.200 43.130 43.200 0.040 43.150 43.200 43.130 43.290 43.100 7,450,447 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/optionPrices.do? > by=underlyingCode&underlyingCode=BHP&expiryDate=&optionType=">Options a> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/warrantPrices.do? > by=underlyingAsxCode&underlyingCode=BHP">Warrants & Structured > Products ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/cfdPrices.do? > by=underlyingAsxCode&underlyingCode=BHP">CFDs< img > src="/images/chart.gif" border="0" height="15" width="15"> > XD > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Recent >
43.200 0.040 43.150 43.200 43.130 43.290 43.100 7,450,447 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/optionPrices.do? > > by=underlyingCode&underlyingCode=BHP&expiryDate=&optionType=">Options > a> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/warrantPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">Warrants & Structured > > Products > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? href="/asx/markets/cfdPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">CFDs< img > > src="/images/chart.gif" border="0" height="15" width="15"> > > XD > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Recent > >
43.200 0.040 > 43.150 43.200 43.130 43.290 43.100 7,450,447 > > href="/asx/markets/optionPrices.do? > > by=underlyingCode&underlyingCode=BHP&expiryDate=&optionType=">Options > a> > > href="/asx/markets/warrantPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">Warrants & Structured > > Products > href="/asx/markets/cfdPrices.do? > > by=underlyingAsxCode&underlyingCode=BHP">CFDs< > img > > src="/images/chart.gif" border="0" height="15" width="15"> > > href="/research/announcements/status_notes.htm#XD">XD > > href="/asx/statistics/announcements.do? > > by=asxCode&asxCode=BHP&timeframe=D&period=W">Recent > >
([\d\.,]+)\s*%s' ASXurl = 'http://www.asx.com.au/asx/markets/priceLookup.do? by=asxCodes&asxCodes=' class stock: code = "" purchasePrice = 0 purchaseQuantity = 0 price = [] # list of recent prices recentBid = [] # list of recent bids for stock recentOffer = [] # list of recent offers for stock stockVol = [] # list of stock quantity available on market def __init__(self): """ Default Constructor """ self.code = "" self.purchasePrice = 0 self.purchaseQuantity = 0 def constructor(self, stockCode, purPrice, purQuant): """ Constructor """ self.code = stockCode self.purchasePrice = purPrice self.purchaseQuantity = purQuant def setData(self, stockCode, purPrice, purQuant, priceList, reBidList, reOffList, popList): """ Defines & implements the objects' public variables """ self.code = stockCode self.purchasePrice = purPrice self.purchaseQuantity = purQuant self.price = priceList self.recentBid = reBidList self.recentOffer = reOffList self.stockVol = popList self.printStats() def updateData(self, priceEle, bidEle, offerEle, populEle): """ Adds data to stock object's lists """ self.price.append(priceEle) self.recentBid.append(bidEle) self.recentOffer.append(offerEle) self.stockVol.append(populEle) def printStats(self): """ Output Stock attributes """ print("Stock Code: "+self.code) print("Stock Purchase Price: "+str(self.purchasePrice)) print("Stock Quantity Owned: "+str(self.purchaseQuantity)) print("***Initial Investment Value: "+str(self.purchasePrice*self.purchaseQuantity)) if not(len(self.price) <= 0): print("Stock Current Price: "+str(self.price[-1])) print("Recent Bid: "+str(self.recentBid[-1])) print("Recent Offer: "+str(self.recentOffer[-1])) print("Total Stock Volume in market: "+str(self.stockVol[-1])) print("***Present Investment Value: "+str(self.price[-1]*self.purchaseQuantity)) print("\n") ### Functions ### def connectDatabase(dbLocation, dbName, tableName): """ Establish & Return connection to SQLite Database """ try: if not (os.path.exists(dbLocation)): os.mkdir(dbLocation) # create folder/dir os.chdir(dbLocation) # change directory focus to dbLocation conn = sqlite3.connect(dbLocation+dbName) cur = conn.cursor() try: createTableQ = "CREATE TABLE IF NOT EXISTS "+tableName +" (code varchar PRIMARY KEY, purchase_price float, purchase_quantity float, purchase_date varchar);" cur.execute(createTableQ) conn.commit() except: pass return conn except IOError or OSError: print "Connection to database failed" return False def retrieveStockDatabase(conn, tableName): """ Read SQLite3 database & extract stock data into StockList """ stockList = [] stockQuery = "select recent_price, recent_offer, recent_bid, stock_volume from ? ;" cur = conn.cursor() cur.execute("select code, purchase_price, purchase_quantity from "+tableName+";") for row in cur.fetchall(): newStock = stock() newStock.code = row[0] newStock.purchasePrice = row[1] newStock.purchaseQuantity = row[2] cur.execute(stockQuery,[newStock.code]) for rw in cur.fetchall(): newStock.price.append(rw[0]) newStock.recentOffer.append(rw[1]) newStock.recentBid.append(rw[2]) newStock.stockVol.append(rw[3]) stockList.append(newStock) return stockList def getDate(): """ Return todays date in format DD:MM:YYYY """ time = datetime.datetime.now() date = time.strftime("%d:%m:%Y") # string format time (%y) return date def newStockDatabase(conn, stockTable, stock): """ Add a new stock to SQLite database if not already there We save the stocks code, purchase price, quantity purchased & date of purchase. """ cur = conn.cursor() try: createTableQ = "create table "+stock.code+" (date varchar PRIMARY KEY, recent_price float, recent_offer float, recent_bid float, stock_volume double);" stockQuery = "insert into "+stockTable+" values(?, ?, ?, ?);" cur.execute(createTableQ) cur.execute(stockQuery, [stock.code,stock.purchasePrice,stock.purchaseQuant,getDate()]) conn.commit() except IOError or OSError: print "Table may already exist or bad SQLite connection." return False def webFormat(URL): if (URL.startswith("http://")==False): URL = "http://"+URL return URL def getSource(URL): """ Retrieve HTML source code from website URL & save in sourceBuffer """ try: URL = webFormat(URL) # make sure URL contains essential "http://" sourceBuffer = urllib2.urlopen(URL) print '\nResponse code = ',sourceBuffer.code print 'Response headers = ',sourceBuffer.info() print 'Actual URL = ',sourceBuffer.geturl() sourceCode = sourceBuffer.read() sourceBuffer.close() return sourceCode except IOError: # URLError print "Function Failed: Reasons could be invalid URL name \nOR \nHTML protocol message transfer failure." return False # function failed def getTargetText(targetStrtData, targetEndData, dataBuffer): """ Grabs target text that lies inside 'dataBuffer' string between targetStrtData & targetEndData """ try: result = dataBuffer.split(targetStrtData) result.pop(0) result = result[0].split(targetEndData) result.pop(1) print result return result except IOError: print "Function Failed: Reasons could be targetStrtData and/or targetEndData is not present in dataBuffer." def getStockData(htmlText, selectedStock): """ Extract stock data(stock code,price,etc) from htmlText """ try: # Here I extract my number data from HTML text tempList = [] for string in htmlText: for i in string.split('>'): for e in i.split(): if ('.' in e and e[0].isdigit()): tempList.append(float(e)) elif (',' in e and e[0].isdigit() ): # remove ',' chars e = e.replace(',','') tempList.append(float(e)) selectedStock.updateData(tempList[0],tempList[2],tempList[3],tempList[7]) except IOError: # is this the correct error I should be trying to catch here?? print "Function Failed: Reasons could be: sites HTML data has changed. Consult author of program." return False def createStockTracker(stockCode,stockPrice,stockQuant, stockList): """ Add a new stock to the database to track """ newStock = stock() newStock.constructor(stockCode,stockPrice,stockQuant) stockList.append(newStock) return stockList def writeStockToDatabase(conn, stock): """ Write ONLY this Stock's attributes to SQLite Database """ cur = conn.cursor() date = getDate() tableName = stock.code stockquery = "insert into "+tableName+" values(?, ?, ?, ?, ?);" cur.execute(query,[date,stock.price[-1], stock.recentOffer[-1], stock.recentBid[-1], stock.stockVol[-1]]) conn.commit() def writeAllToDatabase(conn, stockList): """ Enter recent Stock attributes into SQLite Database """ cur = conn.cursor() date = getDate() for stock in stockList: tableName = stock.code stockquery = "insert into "+tableName+" values(?, ?, ?, ?, ?);" cur.execute(query,[date,stock.price[-1], stock.recentOffer[-1], stock.recentBid[-1], stock.stockVol[-1]]) conn.commit() ### Input Functions ### def inputNewStock(): """ """ print "*Please note only an Australian Securities Exchange(ASX) listed stock can be tracked in Version 1.0." badInput = True while (badInput == True): try: code = raw_input("Please enter the ASX code for the stock you wish to track: ") price = input("Please enter the individual stock value for "+code+": ") quantity = input("Please enter the number/quantity of stocks purchased: ") if (len(code)>3): badInput = True else : badInput = False return True except IOError: if (raw_input("Incorrect input. Note: ASX code cannot be more than 3 chars. Press 'x' to exit or anything else to try again")=='x'): return False badInput = True # this I am not sure if necessary to loop correctly ### Main program loop ### def main(): programEnd = False; dbLocation = "C:\Users\Sam\Desktop\StockApp/" dbName = "stockData.db" stockTable = "stocks" conn = connectDatabase(dbLocation,dbName,stockTable) stockList = retrieveStockDatabase(conn,stockTable) for s in stockList: s.printStats() while (programEnd == False): decision = input(menu) # Print Menu if (decision==1): if not(inputNewStock()==False): stockList = createStockTracker(acode,price,quantity,stockList) newStockDatabase(conn,stockTable,stockList[-1]) print("\n** New Stock **") stockList[-1].printStats() print "The stock "+code+" was successfully added to our database. \nNow every time the program runs it will automatically track this stock & obtain its stock attributes\n\n" # TO DO: # get new stock recent Data from internet etc. # add stock data to data base; elif (decision==2): if (len(stockList)>0): for Stock in stockList: URL = ASXurl+Stock.code sourceCode = getSource(URL) targetData = getTargetText(target % (Stock.code,Stock.code),"
%s' > ASXurl = 'http://www.asx.com.au/asx/markets/priceLookup.do? > by=asxCodes&asxCodes=' > > class stock: > code = "" > purchasePrice = 0 > purchaseQuantity = 0 > price = [] # list of recent prices > recentBid = [] # list of recent bids for stock > recentOffer = [] # list of recent offers for stock > stockVol = [] # list of stock quantity available on > market This will be variables belonging to the class itself, not instances of it. > def __init__(self): > """ Default Constructor """ > self.code = "" > self.purchasePrice = 0 > self.purchaseQuantity = 0 > > def constructor(self, stockCode, purPrice, purQuant): > """ Constructor """ > self.code = stockCode > self.purchasePrice = purPrice > self.purchaseQuantity = purQuant > > def setData(self, stockCode, purPrice, purQuant, priceList, > reBidList, reOffList, popList): > """ Defines & implements the objects' public variables """ > self.code = stockCode > self.purchasePrice = purPrice > self.purchaseQuantity = purQuant > self.price = priceList > self.recentBid = reBidList > self.recentOffer = reOffList > self.stockVol = popList > > self.printStats() > > def updateData(self, priceEle, bidEle, offerEle, populEle): > """ Adds data to stock object's lists """ > self.price.append(priceEle) > self.recentBid.append(bidEle) > self.recentOffer.append(offerEle) > self.stockVol.append(populEle) > > def printStats(self): > """ Output Stock attributes """ > > print("Stock Code: "+self.code) In Python 2 'print' is a statement, so it doesn't need its arguments to be enclosed in (). You could also use Python's string formatting: print "Stock Code: %s" % self.code > print("Stock Purchase Price: "+str(self.purchasePrice)) > print("Stock Quantity Owned: "+str(self.purchaseQuantity)) > print("***Initial Investment Value: > "+str(self.purchasePrice*self.purchaseQuantity)) > if not(len(self.price) <= 0): 'not' has a lower priority than '<=', and this can be simplified anyway: if len(self.price) > 0: or even: if self.price: because empty containers (eg lists) are treated as False, non-empty ones as True, by 'if' and 'while' statements. > print("Stock Current Price: "+str(self.price[-1])) > print("Recent Bid: "+str(self.recentBid[-1])) > print("Recent Offer: "+str(self.recentOffer[-1])) > print("Total Stock Volume in market: > "+str(self.stockVol[-1])) > print("***Present Investment Value: > "+str(self.price[-1]*self.purchaseQuantity)) > print("\n") > > > ### Functions ### > def connectDatabase(dbLocation, dbName, tableName): > """ Establish & Return connection to SQLite Database """ > > try: > if not (os.path.exists(dbLocation)): > os.mkdir(dbLocation) # create folder/dir > > os.chdir(dbLocation) # change directory focus to > dbLocation It's normally easier to use absolute paths instead of changing the current directory. > conn = sqlite3.connect(dbLocation+dbName) It's better to join paths using os.path.join() because that will insert any directory separators for you. > cur = conn.cursor() > try: > createTableQ = "CREATE TABLE IF NOT EXISTS "+tableName > +" (code varchar PRIMARY KEY, purchase_price float, purchase_quantity > float, purchase_date varchar);" > cur.execute(createTableQ) > conn.commit() > except: > pass DON'T USE BARE EXCEPTS, especially if you're just going to ignore the exception. Exceptions can be raised for a variety of reasons, including one you didn't expect due to bugs, so catch only what you expect. > return conn > except IOError or OSError: The result of: IOError or OSError is: IOError What you want is: except (IOError, OSError): Note: the parentheses are necessary here, otherwise it it would mean "catch an IOError exception and then bind it to the name 'OSError'". > print "Connection to database failed" > return False > Some times you return the connection, and other times False. A more usual value than False in such cases is None (unless you're returning True or False). > def retrieveStockDatabase(conn, tableName): > """ Read SQLite3 database & extract stock data into StockList """ > > stockList = [] > stockQuery = "select recent_price, recent_offer, recent_bid, > stock_volume from ? ;" > cur = conn.cursor() > cur.execute("select code, purchase_price, purchase_quantity from > "+tableName+";") > > for row in cur.fetchall(): > newStock = stock() > newStock.code = row[0] > newStock.purchasePrice = row[1] > newStock.purchaseQuantity = row[2] > cur.execute(stockQuery,[newStock.code]) > for rw in cur.fetchall(): > newStock.price.append(rw[0]) > newStock.recentOffer.append(rw[1]) > newStock.recentBid.append(rw[2]) > newStock.stockVol.append(rw[3]) > stockList.append(newStock) > > return stockList > > def getDate(): > """ Return todays date in format DD:MM:YYYY """ > time = datetime.datetime.now() > date = time.strftime("%d:%m:%Y") # string format time (%y) > return date > > def newStockDatabase(conn, stockTable, stock): > """ Add a new stock to SQLite database if not already there > We save the stocks code, purchase price, quantity purchased > & date of purchase. """ > cur = conn.cursor() > try: > createTableQ = "create table "+stock.code+" (date varchar > PRIMARY KEY, recent_price float, recent_offer float, recent_bid float, > stock_volume double);" > stockQuery = "insert into "+stockTable+" > values(?, ?, ?, ?);" > cur.execute(createTableQ) > cur.execute(stockQuery, > [stock.code,stock.purchasePrice,stock.purchaseQuant,getDate()]) > conn.commit() > except IOError or OSError: > print "Table may already exist or bad SQLite connection." > return False > > def webFormat(URL): > > if (URL.startswith("http://")==False): > URL = "http://"+URL > Better as: if not URL.startswith("http://"): The conditions of 'if' and 'while' statements don't need to enclosed in parentheses like in C, Java, etc. > return URL > > def getSource(URL): > """ Retrieve HTML source code from website URL & > save in sourceBuffer """ > > try: > URL = webFormat(URL) # make sure URL contains essential > "http://" > sourceBuffer = urllib2.urlopen(URL) > print '\nResponse code = ',sourceBuffer.code > print 'Response headers = ',sourceBuffer.info() > print 'Actual URL = ',sourceBuffer.geturl() > sourceCode = sourceBuffer.read() > sourceBuffer.close() > return sourceCode > > except IOError: # URLError > print "Function Failed: Reasons could be invalid URL name \nOR > \nHTML protocol message transfer failure." > return False # function failed > > def getTargetText(targetStrtData, targetEndData, dataBuffer): > """ Grabs target text that lies inside 'dataBuffer' string > between targetStrtData & targetEndData """ > > try: > result = dataBuffer.split(targetStrtData) > result.pop(0) > result = result[0].split(targetEndData) > result.pop(1) > print result > return result > except IOError: > print "Function Failed: Reasons could be targetStrtData and/or > targetEndData is not present in dataBuffer." > You haven't given a return statement for when there's an error, so it'll return None. It's probably clearer if you write a function in Python either as a _function_ which _always_ returns a value or as a _procedure_ which _never_ returns a value. In Python the preference is for a function to raise an exception to indicate an error instead of returning a flag. > def getStockData(htmlText, selectedStock): > """ Extract stock data(stock code,price,etc) from htmlText """ > try: > # Here I extract my number data from HTML text > tempList = [] > for string in htmlText: > for i in string.split('>'): > for e in i.split(): > if ('.' in e and e[0].isdigit()): > tempList.append(float(e)) > elif (',' in e and e[0].isdigit() ): > # remove ',' chars > e = e.replace(',','') > tempList.append(float(e)) > > > selectedStock.updateData(tempList[0],tempList[2],tempList[3],tempList[7]) > > except IOError: # is this the correct error I should be trying to > catch here?? > print "Function Failed: Reasons could be: sites HTML data has > changed. Consult author of program." > return False > > def createStockTracker(stockCode,stockPrice,stockQuant, stockList): > """ Add a new stock to the database to track """ > newStock = stock() > newStock.constructor(stockCode,stockPrice,stockQuant) > stockList.append(newStock) > return stockList > > def writeStockToDatabase(conn, stock): > """ Write ONLY this Stock's attributes to SQLite Database """ > > cur = conn.cursor() > date = getDate() > > tableName = stock.code > stockquery = "insert into "+tableName+" values(?, ?, ?, ?, ?);" > cur.execute(query,[date,stock.price[-1], stock.recentOffer[-1], > stock.recentBid[-1], stock.stockVol[-1]]) > conn.commit() > > def writeAllToDatabase(conn, stockList): > """ Enter recent Stock attributes into SQLite Database """ > > cur = conn.cursor() > date = getDate() > > for stock in stockList: > tableName = stock.code > stockquery = "insert into "+tableName+" > values(?, ?, ?, ?, ?);" > cur.execute(query,[date,stock.price[-1], > stock.recentOffer[-1], stock.recentBid[-1], stock.stockVol[-1]]) > conn.commit() > > ### Input Functions ### > def inputNewStock(): > """ """ > print "*Please note only an Australian Securities Exchange(ASX) > listed stock can be tracked in Version 1.0." > badInput = True > > while (badInput == True): Better as: while badInput: > try: > code = raw_input("Please enter the ASX code for the > stock you wish to track: ") If you assign to a name in a function then that name will be treated as a local name (variable) unless you say it's global in the function, therefore 'code', etc, won't been seen outside this function. > price = input("Please enter the individual stock value > for "+code+": ") > quantity = input("Please enter the number/quantity of > stocks purchased: ") > if (len(code)>3): > badInput = True > else : badInput = False > return True This will check the length, setting badInput accordingly, and then return True. > except IOError: I don't see anything in the 'try' block that will raise IOError. > if (raw_input("Incorrect input. Note: ASX code cannot be > more than 3 chars. Press 'x' to exit or anything else to try > again")=='x'): > return False > badInput = True # this I am not sure if necessary to loop > correctly > You're not explicitly returning anything from the function when the loop exits, so it would return None. > > ### Main program loop ### > def main(): > programEnd = False; > dbLocation = "C:\Users\Sam\Desktop\StockApp/" If your string contains literal backslashes then use raw strings instead. Raw strings can end in a backslash, but that shouldn't matter in the script if you're joining paths together using os.path.join(). > dbName = "stockData.db" > stockTable = "stocks" > > conn = connectDatabase(dbLocation,dbName,stockTable) > stockList = retrieveStockDatabase(conn,stockTable) > > for s in stockList: > s.printStats() > > while (programEnd == False): Better as: while not programEnd: > > decision = input(menu) # Print Menu input() is often considered a bad function to use because it's equivalent to eval(raw_input()), so the user could enter any expression. It's better to use int(raw_input()) in this case and then catch the ValueError if what was entered isn't an int. > > if (decision==1): > > if not(inputNewStock()==False): A double-negative, equivalent to: if inputNewStock() != False: It would be more Pythonic if you had inputNewStock() return the code, etc, or raise an exception if there was an error. You could then catch that exception in a 'try' block. > stockList = > createStockTracker(acode,price,quantity,stockList) > newStockDatabase(conn,stockTable,stockList[-1]) > print("\n** New Stock **") > stockList[-1].printStats() > print "The stock "+code+" was successfully added to > our database. \nNow every time the program runs it will automatically > track this stock & obtain its stock attributes\n\n" > # TO DO: > # get new stock recent Data from internet etc. > # add stock data to data base; > elif (decision==2): > if (len(stockList)>0): Better as: if stockList: > for Stock in stockList: > URL = ASXurl+Stock.code > sourceCode = getSource(URL) > targetData = getTargetText(target % > (Stock.code,Stock.code),"